source: issm/trunk/src/m/contrib/ecco/PropagateFlagsUntilDistance.m@ 17806

Last change on this file since 17806 was 17806, checked in by Mathieu Morlighem, 11 years ago

merged trunk-jpl and trunk for revision 17804

File size: 1.7 KB
Line 
1function new_flags=PropagateFlagsUntilDistance(md,flags,distance)
2%PROPAGATEFLAGSUNTILDISTANCE
3%
4% Usage:
5% flags=PropagateFlagsUntilDistance(md,flags,distance)
6%
7%
8
9new_flags=flags;
10
11%make 3d work in 2d:
12if dimension(md.mesh)==3,
13 md.mesh.x=md.mesh.x2d;
14 md.mesh.y=md.mesh.y2d;
15 md.mesh.elements=md.mesh.elements2d;
16end
17
18%find elements that are at the border of flags:
19flag_elements=find(flags);
20conn=md.mesh.elementconnectivity(flag_elements,:);
21pos=find(conn);conn(pos)=~flags(conn(pos));
22sum_conn=sum(conn,2);
23border_elements=flag_elements(find(sum_conn>=1));
24
25%average x and y over elements:
26x_elem=md.mesh.x(md.mesh.elements)*[1;1;1]/3;
27y_elem=md.mesh.y(md.mesh.elements)*[1;1;1]/3;
28
29while 1,
30
31 %keep copy of new_flags for this loop:
32 new_flags_bak=new_flags;
33
34 %extend new flags by connectivity
35 pos=find(new_flags);
36
37 connected_elements=md.mesh.elementconnectivity(pos,:);
38 connected_elements=connected_elements(find(connected_elements));
39 new_flags(connected_elements)=1;
40
41 %get new elements:
42 new_elements=find(new_flags & ~new_flags_bak);
43 if ~length(new_elements),
44 %we are done!
45 break;
46 end
47
48 %check which of these new elements are more than distance away from the border elements
49 for i=1:length(new_elements),
50 dist=sqrt( (x_elem(border_elements)-x_elem(new_elements(i))).^2 + (y_elem(border_elements)-y_elem(new_elements(i))).^2)-distance;
51 if ~any(dist<0)
52 %none of the border elements are within distance, this element is outside out area of interest.
53 %ensure this element never gets found again in the connectivity.
54 pos=find(md.mesh.elementconnectivity==new_elements(i));
55 md.mesh.elementconnectivity(pos)=0;
56 %exclude this new element from the new_flags!
57 new_flags(new_elements(i))=0;
58 end
59 end
60end
Note: See TracBrowser for help on using the repository browser.