Debian Codegraph @

debian/external_deps/fetk/mclite/go.m

raw
1 %GO Controlling driver script for using the MCLite package
2 %
3 % Usage: go
4 %
5 % Author: Michael Holst
6 % rcsid="$Id: go.m,v 1.2 2008/03/12 06:23:07 fetk Exp $"
7
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9
10 %%% global variables: prolongators for all levels
11 global level P_12 P_23 P_34 P_45 P_56 P_67 P_78 P_89;
12
13 %%% setup the MCLite library paths
14 setpath
15
16 %%% visualization parameters
17 igenPS = 0; %%% MATLAB generate postscript (0=no,1=yes)
18 gv = 0; %%% MCsg/Geomview plot of manifold mesh (0=none,1=yes)
19 gvs = 0; %%% MCsg/Geomview plot of solution mesh (0=none,1=yes)
20 socktype = 1; %%% UNIX domain or INET sockets (0=UNIX domain, 1=INET)
21
22 %%% geometry and solver parameters
23 chkkey = 0; %%% conformity check mesh (0=no,1=yes--check is slow)
24 levels = 7; %%% num of refinements plus one
25 solkey = 1; %%% solve key (0=no, 1=yes)
26
27 %%% error estimation parameters
28 estkey = 2; %%% estimator type (0=mark all,1=geom,2=a posteriori)
29 esttol = 0.1; %%% estimator tolerance (if exceeded then refine)
30
31 %%% refinement parameters
32 %%%
33 %%% NOTES: Here are some refinement parameter combinations of importance:
34 %%%
35 %%% Algorithm refkey closeKey markKey
36 %%% --------- ------ -------- -------
37 %%% Rivara/Joe-Liu/Mitchell/etc (recursive bisection) 0 2 0
38 %%% Regular+bisection (regular + recursive bisection) 1 2 0
39 %%% Bank/Bey/etc (regular + pure green closure) 1 1 0
40 %%% Burak's restricted r/g (restricted regular + green) 1 1 1
41 %%% Mike's bordered r/g (bordered regular + green) 2 1 2
42 %%%
43
44 refkey = 2; %%% refinement type
45 %%% 0=bisection (bisect marked guys by longest edge)
46 %%% 1=quadrasection-pure (quadrasect marked guys)
47 %%% 2=quadrasection-patch (quadrasect marked + 1-rings)
48
49 closekey = 1; %%% closure type
50 %%% 0=none (i.e., red refinement)
51 %%% 1=green (pure green closure via quad-/tri-/bi-section)
52 %%% 2=recursive bisection (by longest edge)
53
54 markkey = 2; %%% marking type (has meaning really only for quadrasection)
55 %%% 0=no restriction on marking for refinement
56 %%% 1=mark ONLY elements where were created as the
57 %%% INTERIOR child in a quadrasection in the
58 %%% previous level.
59 %%% 2=mark ONLY elements which were created as
60 %%% ANY child in a quadrasection in the
61 %%% next previous level.
62
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64
65 %%% clear the graphics window
66 clf;
67
68 %%% construct operators for the nested sequence of spaces
69 for level = 1 : levels
70 fprintf('MAIN: -------\n');
71 fprintf('MAIN: LEVEL %g\n',level);
72 fprintf('MAIN: -------\n');
73
74 if (level == 1)
75 %%% create the initial coarse mesh
76 fprintf('MAIN: defining the mesh..');
77 t0 = clock;
78 [VERT,SIMP] = read(0);
79 the_time = etime(clock,t0);
80 [N,eight] = size(VERT);
81 [L,seventeen] = size(SIMP);
82 fprintf('..done. [N=%g,L=%g] [time=%g]\n',N,L,the_time);
83 else
84 %%% build the simplex rings (BOTH mark and refin need them)
85 [VERT,SIMP] = bldsring(VERT,SIMP);
86
87 %%% error estimate and the mark mesh (some uniform refinements first)
88 fprintf('MAIN: marking the mesh..');
89 t0 = clock;
90 [SIMP,QUE] = mark(VERT,SIMP,U,Ug,markkey,level-1,estkey,esttol);
91 the_time = etime(clock,t0);
92 [N,eight] = size(VERT);
93 [L,seventeen] = size(SIMP);
94 fprintf('..done. [N=%g,L=%g] [time=%g]\n',N,L,the_time);
95
96 %%% adaptively refine the mesh based on the marking
97 fprintf('MAIN: refining the mesh..');
98 t0 = clock;
99 [VERT,SIMP,P,ONER] = refin(VERT,SIMP,QUE,refkey,closekey);
100 eval(['P_' num2str(level-1) num2str(level) ' = P;']);
101 the_time = etime(clock,t0);
102 [N,eight] = size(VERT);
103 [L,seventeen] = size(SIMP);
104 fprintf('..done. [N=%g,L=%g] [time=%g]\n',N,L,the_time);
105
106 %%% kill the simplex rings (ONLY mark and refin need them)
107 [VERT,SIMP] = kilring(VERT,SIMP);
108 end;
109
110 %%% check the mesh for "correctness"
111 if (chkkey > 0)
112 %%% simplex rings get created and then destroyed by chkmesh
113 chkmesh(VERT,SIMP);
114 end
115
116 %%% plot the mesh
117 if (gv > 0)
118 writeoff(socktype,2,VERT,SIMP);
119 end;
120 fprintf('MAIN: plotting the mesh..');
121 subplot(2,2,1);
122 draw(VERT,SIMP);
123 title('Finite element mesh');
124 %%% draw1(VERT,SIMP);
125 %%% draw2(VERT,SIMP);
126 if (igenPS > 0)
127 print -depsc mesh.eps
128 end
129 fprintf('..done. [N=%g,L=%g]\n',N,L);
130
131 %%% solve discrete system?
132 if (solkey > 0)
133
134 %%% solve discrete system
135 fprintf('MAIN: algebraic solve starting. [N=%g,L=%g]\n',N,L);
136 t0 = clock;
137 [U,Ug,A,F]=nsolve(VERT,SIMP);
138 [Nn,one] = size(U);
139 n = Nn / N;
140 the_time = etime(clock,t0);
141 fprintf('MAIN: algebraic solve finished. [time=%g]\n',the_time);
142
143 %%% discretization error test
144 U_tt = u_t( VERT(1:N,1), VERT(1:N,2), VERT(1:N,6) );
145 U_t = reshape(U_tt,Nn,1);
146 normUt = norm(U_t);
147 if (normUt == 0.0)
148 normUt = 1.0;
149 end;
150 error = norm(U_t - (U+Ug)) / normUt;
151 fprintf('MAIN: discretization error is = %g\n',error);
152
153 %%% build matrix copy with small entries dropped (for display only)
154 tolZero = 1.0e-5;
155 AA=A .* ( (A > tolZero) | (A < -tolZero) );
156
157 %%% graph the matrix
158 fprintf('MAIN: graphing matrix..');
159 subplot(2,2,3);
160 NODES = [];
161 for i=1:n
162 NODES = [ NODES ; VERT(:,1:2) ];
163 end;
164 subplot(2,2,3);
165 gplot(AA,NODES,'r'); axis('equal'); axis('off');
166 title('Graph of stiffness matrix');
167 if (igenPS > 0)
168 print -depsc gplot.eps
169 end
170 fprintf('..done. [N=%g,L=%g]\n',N,L);
171
172 %%% show matrix structure
173 fprintf('MAIN: showing nonzero structure..');
174 subplot(2,2,4);
175 spy(AA,'r');
176 title('Nonzero structure of stiffness matrix');
177 if (igenPS > 0)
178 print -depsc spy.eps
179 end
180 fprintf('..done. [N=%g,L=%g]\n',N,L);
181
182 %%% plot the solution
183 if (gvs > 0)
184 writeoffs(socktype,2,VERT,SIMP,(U+Ug));
185 end;
186 fprintf('MAIN: plotting FEM solution..');
187 subplot(2,2,2);
188 if (n==2)
189 drawd(VERT,SIMP,(U+Ug));
190 else
191 drawf(VERT,SIMP,(U+Ug));
192 end
193 title('Finite element solution');
194 if (igenPS > 0)
195 print -depsc sol.eps
196 end
197 fprintf('..done. [N=%g,L=%g]\n',N,L);
198
199 else
200 [u_size,dummy] = size(VERT);
201 U = zeros(u_size,1);
202 Ug = zeros(u_size,1);
203 end; %%% solve discrete system
204
205 %%% pause before starting a new refinement level
206 mypaus;
207
208 end; %%% solve-estimate-refine loop
209