1 | function segments=findsegments(md,varargin)
|
---|
2 | %FINDSEGMENTS - build segments model field
|
---|
3 | %
|
---|
4 | % Optional inputs:
|
---|
5 | % 'mesh.elementconnectivity'
|
---|
6 | %
|
---|
7 | % Usage:
|
---|
8 | % segments=findsegments(md,varargin);
|
---|
9 |
|
---|
10 | %get options
|
---|
11 | options=pairoptions(varargin{:});
|
---|
12 |
|
---|
13 | %Get connectivity
|
---|
14 | mesh.elementconnectivity=getfieldvalue(options,'mesh.elementconnectivity',md.mesh.elementconnectivity);
|
---|
15 |
|
---|
16 | %Now, build the connectivity tables for this mesh if not correclty done
|
---|
17 | if size(md.mesh.elementconnectivity,1)~=md.mesh.numberofelements,
|
---|
18 | if exist(options,'mesh.elementconnectivity'),
|
---|
19 | error(' ''mesh.elementconnectivity'' option does not have thge right size.');
|
---|
20 | else
|
---|
21 | mesh.elementconnectivity=ElementConnectivity(md.mesh.elements,md.mesh.vertexconnectivity);
|
---|
22 | end
|
---|
23 | end
|
---|
24 |
|
---|
25 | %Recreate the segments
|
---|
26 | elementonboundary=double(mesh.elementconnectivity(:,3)==0);
|
---|
27 | pos=find(elementonboundary);
|
---|
28 | num_segments=length(pos);
|
---|
29 | segments=zeros(num_segments,3);
|
---|
30 | count=1;
|
---|
31 |
|
---|
32 | %loop over the segments
|
---|
33 | for i=1:num_segments,
|
---|
34 |
|
---|
35 | %get current element on boundary
|
---|
36 | el1=pos(i);
|
---|
37 |
|
---|
38 | %get elements connected to el1
|
---|
39 | els2=mesh.elementconnectivity(el1,find(mesh.elementconnectivity(el1,:)));
|
---|
40 |
|
---|
41 | %el1 is connected to 2 other elements
|
---|
42 | if length(els2)>1,
|
---|
43 |
|
---|
44 | %get nodes of el1
|
---|
45 | nods1=md.mesh.elements(el1,:);
|
---|
46 |
|
---|
47 | %find the common vertices to the two elements connected to el1 (1 or 2)
|
---|
48 | flag=intersect(md.mesh.elements(els2(1),:),md.mesh.elements(els2(2),:));
|
---|
49 |
|
---|
50 | %get the vertices on the boundary and build segment
|
---|
51 | nods1(find(ismember(nods1,flag)))=[];
|
---|
52 | segments(count,:)=[nods1 el1];
|
---|
53 |
|
---|
54 | %swap segment nodes if necessary
|
---|
55 | ord1=find(nods1(1)==md.mesh.elements(el1,:));
|
---|
56 | ord2=find(nods1(2)==md.mesh.elements(el1,:));
|
---|
57 | if ( (ord1==1 & ord2==2) | (ord1==2 & ord2==3) | (ord1==3 & ord2==1) ),
|
---|
58 | temp=segments(count,1);
|
---|
59 | segments(count,1)=segments(count,2);
|
---|
60 | segments(count,2)=temp;
|
---|
61 | end
|
---|
62 | segments(count,1:2)=fliplr(segments(count,1:2));
|
---|
63 | count=count+1;
|
---|
64 |
|
---|
65 | %el1 is connected to only one element
|
---|
66 | else
|
---|
67 | %get nodes of el1
|
---|
68 | nods1=md.mesh.elements(el1,:);
|
---|
69 |
|
---|
70 | %find the vertex the el1 to not share with els2
|
---|
71 | flag=setdiff(nods1,md.mesh.elements(els2,:));
|
---|
72 |
|
---|
73 | for j=1:3,
|
---|
74 | nods=nods1; nods(j)=[];
|
---|
75 | if any(ismember(flag,nods)),
|
---|
76 |
|
---|
77 | segments(count,:)=[nods el1];
|
---|
78 |
|
---|
79 | %swap segment nodes if necessary
|
---|
80 | ord1=find(nods(1)==md.mesh.elements(el1,:));
|
---|
81 | ord2=find(nods(2)==md.mesh.elements(el1,:));
|
---|
82 | if ( (ord1==1 & ord2==2) | (ord1==2 & ord2==3) | (ord1==3 & ord2==1) ),
|
---|
83 | temp=segments(count,1);
|
---|
84 | segments(count,1)=segments(count,2);
|
---|
85 | segments(count,2)=temp;
|
---|
86 | end
|
---|
87 | segments(count,1:2)=fliplr(segments(count,1:2));
|
---|
88 | count=count+1;
|
---|
89 | end
|
---|
90 | end
|
---|
91 | end
|
---|
92 | end
|
---|