source: issm/trunk/src/m/model/contourenvelope.m@ 8298

Last change on this file since 8298 was 8298, checked in by seroussi, 14 years ago

changed grid to node in matlab

File size: 2.7 KB
RevLine 
[2518]1function segments=contourenvelope(md,varargin)
[2517]2%CONTOURENVELOPE - build a set of segments enveloping a contour .exp
3%
4% Usage:
[2518]5% segments=contourenvelope(md,varargin)
6%
7% Example:
8% segments=contourenvelope(md,'Stream.exp');
9% segments=contourenvelope(md);
[2517]10
11%some checks
[2518]12if nargin>2,
13 help contourenvelope
14 error('contourenvelope error message: bad usage');
[2517]15end
[2518]16if nargin==2,
17 file=varargin{1};
18 if ~exist(file),
19 error(['thicknessevolution error message: file ' file ' not found']);
20 end
21end
[2517]22
23%Now, build the connectivity tables for this mesh.
24%Computing connectivity
[8298]25if size(md.nodeconnectivity,1)~=md.numberofnodes,
26 md.nodeconnectivity=NodeConnectivity(md.elements,md.numberofnodes);
[2517]27end
28if size(md.elementconnectivity,1)~=md.numberofelements,
29 md.elementconnectivity=ElementConnectivity(md.elements,md.nodeconnectivity);
30end
31
32%get nodes inside profile
33elementconnectivity=md.elementconnectivity;
[2518]34if nargin==2,
35 %get flag list of elements and nodes inside the contour
[5024]36 nodein=ContourToMesh(md.elements,md.x,md.y,file,'node',1);
[2518]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;
42end
[2517]43
44%Find element on boundary
45%First: find elements on the boundary of the domain
46flag=elementconnectivity;
[2518]47if nargin==2,
48 flag(find(flag))=elemin(flag(find(flag)));
49end
[5602]50elementonboundary=double(prod(flag,2)==0 & sum(flag,2)>0);
[2517]51
52%Find segments on boundary
53pos=find(elementonboundary);
54num_segments=length(pos);
55segments=zeros(num_segments,3);
56count=1;
57
58for 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
[8298]70 %swap segment nodes if necessary
[2517]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
97end
Note: See TracBrowser for help on using the repository browser.