1 | function band=meshband(mh,outerdomain,varargin)
|
---|
2 |
|
---|
3 | %process options:
|
---|
4 | options=pairoptions(varargin{:});
|
---|
5 |
|
---|
6 | %some checks on the mesh:
|
---|
7 | if (isempty(mh.x) | isempty(mh.y) )
|
---|
8 | error('meshband error message: mesh has one of the following empty: ''x'',''y''');
|
---|
9 | end
|
---|
10 |
|
---|
11 | %give ourselves a unique temporary directory:
|
---|
12 | temproot=tempname; mkdir(temproot);
|
---|
13 |
|
---|
14 | %align external segments on internal mesh:
|
---|
15 | mh.segments=alignsegments(mh.segments);
|
---|
16 |
|
---|
17 | %figure out domain outline:
|
---|
18 | meshtodomain(mh,[temproot '/innerdomain.exp']);
|
---|
19 |
|
---|
20 | %create domain outine from inner and outer domain
|
---|
21 | inner=expread([temproot '/innerdomain.exp']);
|
---|
22 | if inner.closed==0,
|
---|
23 | inner.nods=inner.nods+1;
|
---|
24 | inner.x(end+1)=inner.x(1);
|
---|
25 | inner.y(end+1)=inner.y(1);
|
---|
26 | inner.closed=1;
|
---|
27 | if getfieldvalue(options,'invert',0),
|
---|
28 | inner.x=flipud(inner.x);
|
---|
29 | inner.y=flipud(inner.y);
|
---|
30 | end
|
---|
31 | end
|
---|
32 |
|
---|
33 | [path,name,ext]=fileparts(outerdomain);
|
---|
34 | if strcmpi(ext,'.shp'),
|
---|
35 | outer=shpread(outerdomain);
|
---|
36 | else
|
---|
37 | outer=expread(outerdomain);
|
---|
38 | end
|
---|
39 | if outer.closed==0,
|
---|
40 | outer.nods=outer.nods+1;
|
---|
41 | outer.x(end+1)=outer.x(1);
|
---|
42 | outer.y(end+1)=outer.y(1);
|
---|
43 | outer.closed=1;
|
---|
44 | end
|
---|
45 |
|
---|
46 | domain(1).x=outer.x;
|
---|
47 | domain(1).y=outer.y;
|
---|
48 | domain(1).density=outer.density;
|
---|
49 | domain(1).nods=outer.nods;
|
---|
50 | domain(1).closed=outer.closed;
|
---|
51 |
|
---|
52 |
|
---|
53 | domain(2).x=inner.x;
|
---|
54 | domain(2).y=inner.y;
|
---|
55 | domain(2).density=inner.density;
|
---|
56 | domain(2).nods=inner.nods;
|
---|
57 | domain(2).closed=inner.closed;
|
---|
58 |
|
---|
59 |
|
---|
60 | expwrite(domain,[temproot '/Band.exp']);
|
---|
61 |
|
---|
62 | if getfieldvalue(options,'plot',0),
|
---|
63 | figure(1),clf,hold on,axis image;
|
---|
64 | expdisp([temproot '/Band.exp'],'linestyle','k-*');
|
---|
65 | end
|
---|
66 |
|
---|
67 | %mesh:
|
---|
68 | md=bamg(model(),'domain',[temproot '/Band.exp'],'MaxCornerAngle',1e-15,'gradation',10000); band=md.mesh; clear md;
|
---|
69 |
|
---|
70 | if getfieldvalue(options,'plot',0),
|
---|
71 | figure(2),clf,trisurf(band.elements,band.x,band.y,band.x),view(2),shading faceted;
|
---|
72 | hold on,expdisp([temproot '/Band.exp'],'linestyle','k-*');
|
---|
73 | end
|
---|
74 |
|
---|
75 | %check that the domain vertices = the number of segments:
|
---|
76 | if abs(length(band.segments) - (length(domain(1).x)+length(domain(2).x)-2))>=2,
|
---|
77 | disp(sprintf('band mesh not consistent: %i!=%i+%i\n',length(band.segments), length(domain(1).x), length(domain(2).x)));
|
---|
78 |
|
---|
79 | figure(3),clf,expdisp([temproot '/Band.exp'],'linestyle','r*');
|
---|
80 | hold on;
|
---|
81 | for i=1:length(band.segments),
|
---|
82 | i1=band.segments(i,1); i2=band.segments(i,2);
|
---|
83 | plot([band.x(i1) band.x(i2)],[band.y(i1) band.y(i2)],'k*-');
|
---|
84 | plot([band.x(i1)+ band.x(i2)]/2,[band.y(i1)+ band.y(i2)]/2,'g*');
|
---|
85 | end
|
---|
86 | %error('band mesh not consistent');
|
---|
87 | end
|
---|
88 |
|
---|
89 | %erase temporary directory:
|
---|
90 | system(['rm -rf ' temproot]);
|
---|
91 |
|
---|
92 | end
|
---|