1 | function segments=contourenvelope(md,varargin)
|
---|
2 | %CONTOURENVELOPE - build a set of segments enveloping a contour .exp
|
---|
3 | %
|
---|
4 | % Usage:
|
---|
5 | % segments=contourenvelope(md,varargin)
|
---|
6 | %
|
---|
7 | % Example:
|
---|
8 | % segments=contourenvelope(md,'Stream.exp');
|
---|
9 | % segments=contourenvelope(md);
|
---|
10 |
|
---|
11 | %some checks
|
---|
12 | if nargin>2,
|
---|
13 | help contourenvelope
|
---|
14 | error('contourenvelope error message: bad usage');
|
---|
15 | end
|
---|
16 | if nargin==2,
|
---|
17 | file=varargin{1};
|
---|
18 | if ~exist(file),
|
---|
19 | error(['thicknessevolution error message: file ' file ' not found']);
|
---|
20 | end
|
---|
21 | end
|
---|
22 |
|
---|
23 | %Now, build the connectivity tables for this mesh.
|
---|
24 | %Computing connectivity
|
---|
25 | if size(md.nodeconnectivity,1)~=md.numberofnodes,
|
---|
26 | md.nodeconnectivity=NodeConnectivity(md.elements,md.numberofnodes);
|
---|
27 | end
|
---|
28 | if size(md.elementconnectivity,1)~=md.numberofelements,
|
---|
29 | md.elementconnectivity=ElementConnectivity(md.elements,md.nodeconnectivity);
|
---|
30 | end
|
---|
31 |
|
---|
32 | %get nodes inside profile
|
---|
33 | elementconnectivity=md.elementconnectivity;
|
---|
34 | if nargin==2,
|
---|
35 | %get flag list of elements and nodes inside the contour
|
---|
36 | nodein=ContourToMesh(md.elements,md.x,md.y,file,'node',1);
|
---|
37 | elemin=(sum(nodein(md.elements),2)==size(md.elements,2));
|
---|
38 | %modify element connectivity
|
---|
39 | elemout=find(~elemin);
|
---|
40 | elementconnectivity(elemout,:)=0;
|
---|
41 | elementconnectivity(find(ismember(elementconnectivity,elemout)))=0;
|
---|
42 | end
|
---|
43 |
|
---|
44 | %Find element on boundary
|
---|
45 | %First: find elements on the boundary of the domain
|
---|
46 | flag=elementconnectivity;
|
---|
47 | if nargin==2,
|
---|
48 | flag(find(flag))=elemin(flag(find(flag)));
|
---|
49 | end
|
---|
50 | elementonboundary=double(prod(flag,2)==0 & sum(flag,2)>0);
|
---|
51 |
|
---|
52 | %Find segments on boundary
|
---|
53 | pos=find(elementonboundary);
|
---|
54 | num_segments=length(pos);
|
---|
55 | segments=zeros(num_segments,3);
|
---|
56 | count=1;
|
---|
57 |
|
---|
58 | for i=1:num_segments,
|
---|
59 | el1=pos(i);
|
---|
60 | els2=elementconnectivity(el1,find(elementconnectivity(el1,:)));
|
---|
61 | if length(els2)>1,
|
---|
62 | flag=intersect(md.elements(els2(1),:),md.elements(els2(2),:));
|
---|
63 | nods1=md.elements(el1,:);
|
---|
64 | nods1(find(nods1==flag))=[];
|
---|
65 | segments(count,:)=[nods1 el1];
|
---|
66 |
|
---|
67 | ord1=find(nods1(1)==md.elements(el1,:));
|
---|
68 | ord2=find(nods1(2)==md.elements(el1,:));
|
---|
69 |
|
---|
70 | %swap segment nodes if necessary
|
---|
71 | if ( (ord1==1 & ord2==2) | (ord1==2 & ord2==3) | (ord1==3 & ord2==1) ),
|
---|
72 | temp=segments(count,1);
|
---|
73 | segments(count,1)=segments(count,2);
|
---|
74 | segments(count,2)=temp;
|
---|
75 | end
|
---|
76 | segments(count,1:2)=fliplr(segments(count,1:2));
|
---|
77 | count=count+1;
|
---|
78 | else
|
---|
79 | nods1=md.elements(el1,:);
|
---|
80 | flag=setdiff(nods1,md.elements(els2,:));
|
---|
81 | for j=1:3,
|
---|
82 | nods=nods1; nods(j)=[];
|
---|
83 | if any(ismember(flag,nods)),
|
---|
84 | segments(count,:)=[nods el1];
|
---|
85 | ord1=find(nods(1)==md.elements(el1,:));
|
---|
86 | ord2=find(nods(2)==md.elements(el1,:));
|
---|
87 | if ( (ord1==1 & ord2==2) | (ord1==2 & ord2==3) | (ord1==3 & ord2==1) ),
|
---|
88 | temp=segments(count,1);
|
---|
89 | segments(count,1)=segments(count,2);
|
---|
90 | segments(count,2)=temp;
|
---|
91 | end
|
---|
92 | segments(count,1:2)=fliplr(segments(count,1:2));
|
---|
93 | count=count+1;
|
---|
94 | end
|
---|
95 | end
|
---|
96 | end
|
---|
97 | end
|
---|