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