-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodal-dg.patch
329 lines (319 loc) · 8.65 KB
/
nodal-dg.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
From 6bb42367e100e38c29adf7a075724ec506cf4042 Mon Sep 17 00:00:00 2001
From: Jeremy Edward Kozdon <[email protected]>
Date: Wed, 13 Jun 2018 19:47:12 -0700
Subject: [PATCH] Files needed for gddg code
---
Codes1.1/Codes2D/MakeCylinder2D.m | 11 +-
Codes1.1/ServiceRoutines/MeshReaderGmshBC2D.m | 163 ++++++++++++++++++
Codes1.1/ServiceRoutines/PlotField2D.m | 7 +-
Codes1.1/ServiceRoutines/PlotMesh2D.m | 10 +-
Codes1.1/ServiceRoutines/WriteVTK2D.m | 74 ++++++++
5 files changed, 254 insertions(+), 11 deletions(-)
create mode 100644 Codes1.1/ServiceRoutines/MeshReaderGmshBC2D.m
create mode 100644 Codes1.1/ServiceRoutines/WriteVTK2D.m
diff --git a/Codes1.1/Codes2D/MakeCylinder2D.m b/Codes1.1/Codes2D/MakeCylinder2D.m
index 338ce6d..05c655e 100755
--- a/Codes1.1/Codes2D/MakeCylinder2D.m
+++ b/Codes1.1/Codes2D/MakeCylinder2D.m
@@ -52,9 +52,14 @@ for n=1:NCurveFaces % deform specified faces
% move vertices at end points of this face to the cylinder
theta1 = atan2(y1-yo, x1-xo); theta2 = atan2(y2-yo, x2-xo);
- % check to make sure they are in the same quadrant
- if ((theta2 > 0) & (theta1 < 0)), theta1 = theta1 + 2*pi; end;
- if ((theta1 > 0) & (theta2 < 0)), theta2 = theta2 + 2*pi; end;
+ % choose the smallest angle between the points
+ while abs(theta1 - theta2) > pi
+ if (theta1 > theta2)
+ theta1 = theta1 - 2*pi;
+ else
+ theta2 = theta2 - 2*pi;
+ end
+ end
% distribute N+1 nodes by arc-length along edge
theta = 0.5*theta1*(1-fr) + 0.5*theta2*(1+fr);
diff --git a/Codes1.1/ServiceRoutines/MeshReaderGmshBC2D.m b/Codes1.1/ServiceRoutines/MeshReaderGmshBC2D.m
new file mode 100644
index 0000000..2938d6a
--- /dev/null
+++ b/Codes1.1/ServiceRoutines/MeshReaderGmshBC2D.m
@@ -0,0 +1,163 @@
+function [Nv, VX, VY, K, EToV, BCType] = MeshReaderGmshBC2D(FileName)
+
+% function [Nv, VX, VY, K, EToV, BCType] = MeshReaderGmshBC2D(FileName)
+% Purpose : Read in basic grid information to build grid
+% NOTE : gmsh *.gmsh format is assumed
+
+Globals2D;
+
+vnum = [1 2; 2 3; 3 1];
+
+Fid = fopen(FileName, 'rt');
+fline = fgetl(Fid);
+
+while ~strcmp(fline,'$PhysicalNames')
+ fline = fgetl(Fid);
+end
+
+fline = fgetl(Fid);
+
+npn = sscanf(fline, '%d');
+
+PhyToBCType = zeros(npn, 1);
+
+for i = 1:npn
+ fline = fgetl(Fid);
+ bck = sscanf(fline, '%d %*d %*s');
+ bct = sscanf(fline, '%*d %d %*s');
+ bcn = sscanf(fline, '%*s %*s %s');
+
+ if bck == 1
+ bcflag = bct;
+ else
+ bcflag = 0;
+ end
+
+ if strfind(bcn, 'In'), bcflag = In; end;
+ if strfind(bcn, 'Out'), bcflag = Out; end;
+ if strfind(bcn, 'Wall'), bcflag = Wall; end;
+ if strfind(bcn, 'Far'), bcflag = Far; end;
+ if strfind(bcn, 'Cyl'), bcflag = Cyl; end;
+ if strfind(bcn, 'Dirichlet'), bcflag = Dirichlet; end;
+ if strfind(bcn, 'Neuman'), bcflag = Neuman; end;
+ if strfind(bcn, 'Slip'), bcflag = Slip; end;
+
+ PhyToBCType(i) = bcflag;
+end
+
+while ~strcmp(fline,'$Nodes')
+ fline = fgetl(Fid);
+end
+
+fline = fgetl(Fid);
+
+Nv = sscanf(fline, '%d');
+
+VX = (1:Nv);
+VY = (1:Nv);
+for i = 1:Nv
+ fline = fgetl(Fid);
+ tmpx = sscanf(fline, '%lf');
+ VX(tmpx(1)) = tmpx(2);
+ VY(tmpx(1)) = tmpx(3);
+end
+
+while (~strcmp(fline,'$Elements'))
+ fline = fgetl(Fid);
+end
+fline = fgetl(Fid);
+
+ka = sscanf(fline, '%d');
+
+EToV = zeros(ka, 3);
+BCType = zeros(ka,3);
+
+BCToV = zeros(ka, 2);
+BCToPhy = zeros(ka, 1);
+
+bc = 1;
+k = 1;
+for i = 1:ka
+ fline = fgetl(Fid);
+ tmpcon = sscanf(fline, '%d');
+ elm_number = tmpcon(1);
+ elm_type = tmpcon(2);
+ number_of_tags = tmpcon(3);
+ tags = tmpcon(4:3+number_of_tags);
+ node_number_list = tmpcon(4+number_of_tags:length(tmpcon));
+ phy = tags(1);
+
+ if (elm_type == 1)
+ % bc
+ ntags = tmpcon(3);
+ BCToV(bc,:) = node_number_list;
+ BCToPhy(bc) = phy;
+ bc = bc + 1;
+ elseif (elm_type == 2)
+ % triangle
+ EToV(k,:) = node_number_list;
+ k = k + 1;
+ else
+ error('Unkown element');
+ end
+end
+
+K = k - 1;
+EToV = EToV(1:K,:);
+BCType = BCType(1:K,:);
+
+Nbc = bc - 1;
+BCToV = BCToV(1:Nbc,:);
+BCToPhy = BCToPhy(1:Nbc,:);
+
+% Reorder elements to ensure counter clockwise orientation
+ax = VX(EToV(:,1)); ay = VY(EToV(:,1));
+bx = VX(EToV(:,2)); by = VY(EToV(:,2));
+cx = VX(EToV(:,3)); cy = VY(EToV(:,3));
+
+D = (ax-cx).*(by-cy)-(bx-cx).*(ay-cy);
+i = find(D<0);
+EToV(i,:) = EToV(i,[1 3 2]);
+
+% Find BCtypes
+for i = 1:Nbc
+ va = BCToV(i, 1);
+ vb = BCToV(i, 2);
+ p = BCToPhy(i);
+
+ [rows, cols] = find(EToV == va);
+
+ for j = 1:size(rows)
+ f = 0;
+ k = rows(j);
+ ca = cols(j);
+ cb = find(EToV(k,:) == vb);
+
+ if(cb)
+ for ftry = 1:3
+ if(isempty(setdiff(vnum(ftry,:), [ca cb])))
+ f = ftry;
+ end
+ end
+
+ BCType(k, f) = PhyToBCType(p);
+ end
+ end
+end
+
+%% i = 1;
+%% for k = 1:K
+%% for f = 1:3
+%% if(BCType(k, f))
+%% va = EToV(k, vnum(f,:))(1);
+%% vb = EToV(k, vnum(f,:))(2);
+%%
+%% fprintf(1, '%d (%g, %g)--(%g, %g) == %d\n', ...
+%% i, VX(va), VY(va), VX(vb), VY(vb), BCType(k, f));
+%% i = i + 1;
+%% end
+%% end
+%% end
+
+st = fclose(Fid);
+return
diff --git a/Codes1.1/ServiceRoutines/PlotField2D.m b/Codes1.1/ServiceRoutines/PlotField2D.m
index 91b27d5..1406269 100755
--- a/Codes1.1/ServiceRoutines/PlotField2D.m
+++ b/Codes1.1/ServiceRoutines/PlotField2D.m
@@ -44,7 +44,8 @@ end
xout = interp*xin; yout = interp*yin; uout = interp*uin;
% render and format solution field
-trisurf(TRI, xout(:), yout(:), uout(:));
-shading interp, material shiny, lighting gouraud
-camlight headlight
+trisurf(TRI, xout(:), yout(:), zeros(size(uout(:))), uout(:));
+shading interp;
+% shading interp, material shiny, lighting gouraud
+% camlight headlight
return
diff --git a/Codes1.1/ServiceRoutines/PlotMesh2D.m b/Codes1.1/ServiceRoutines/PlotMesh2D.m
index f4e2a19..85a1b5c 100644
--- a/Codes1.1/ServiceRoutines/PlotMesh2D.m
+++ b/Codes1.1/ServiceRoutines/PlotMesh2D.m
@@ -14,14 +14,14 @@ Ly = ymax-ymin;
xmax = xmax+.1*Lx; xmin = xmin-.1*Lx;
ymax = ymax+.1*Ly; ymin = ymin-.1*Ly;
-axis([xmin xmax ymin ymax])
-drawnow; pause(.05);
+% axis([xmin xmax ymin ymax])
+% drawnow; pause(.05);
oFx = reshape(Fx, Nfp, Nfaces*K); oFy = reshape(Fy, Nfp, Nfaces*K);
plot(oFx, oFy, 'k-')
-axis equal
-axis([xmin xmax ymin ymax])
+% axis equal
+% axis([xmin xmax ymin ymax])
-drawnow; pause(.05);
+% drawnow; pause(.05);
return;
diff --git a/Codes1.1/ServiceRoutines/WriteVTK2D.m b/Codes1.1/ServiceRoutines/WriteVTK2D.m
new file mode 100644
index 0000000..8f0eb83
--- /dev/null
+++ b/Codes1.1/ServiceRoutines/WriteVTK2D.m
@@ -0,0 +1,74 @@
+function WriteVTK2D(filename, Nout, vnames, varargin)
+ nfields = nargin - 3;
+
+ Globals2D;
+
+ % build equally spaced grid on reference triangle
+ Npout = (Nout+1)*(Nout+2)/2;
+ rout = zeros(Npout,1); sout = zeros(Npout,1);
+ sk = 1;
+ for n=1:Nout+1
+ for m=1:Nout+2-n
+ rout(sk) = -1 + 2*(m-1)/Nout;
+ sout(sk) = -1 + 2*(n-1)/Nout;
+ counter(n,m) = sk; sk = sk+1;
+ end
+ end
+
+ % build matrix to interpolate field data to equally spaced nodes
+ interp = InterpMatrix2D(rout, sout);
+
+ % build triangulation of equally spaced nodes on reference triangle
+ tri = [];
+ for n=1:Nout+1
+ for m=1:Nout+1-n,
+ v1 = counter(n,m); v2 = counter(n,m+1);
+ v3 = counter(n+1,m); v4 = counter(n+1,m+1);
+ if(v4)
+ tri = [tri;[[v1 v2 v3];[v2 v4 v3]]];
+ else
+ tri = [tri;[[v1 v2 v3]]];
+ end
+ end
+ end
+
+ % build triangulation for all equally spaced nodes on all elements
+ TRI = [];
+ for k=1:K
+ TRI = [TRI; tri+(k-1)*Npout];
+ end
+
+ % interpolate node coordinates and field to equally spaced nodes
+ xout = interp*x;
+ yout = interp*y;
+ zout = zeros(size(xout));
+
+ uout = cell(1, nfields);
+ for n=1:nfields
+ uout{n} = interp*varargin{n};
+ end
+
+ Ntotal = length(xout(:));
+ [nTRI, nVERT] = size(TRI);
+
+ fid = fopen(filename, 'w');
+ fprintf(fid, '# vtk DataFile Version 4.0');
+ fprintf(fid, '\nNUDG simulation');
+ fprintf(fid, '\nASCII');
+ fprintf(fid, '\nDATASET UNSTRUCTURED_GRID\n');
+ fprintf(fid, '\nPOINTS %d double', Ntotal);
+ fprintf(fid, '\n%25.16e %25.16e %25.16e', [xout(:) yout(:) zout(:)]');
+ fprintf(fid, '\nCELLS %d %d', nTRI, nTRI*4);
+ fprintf(fid, '\n3 %10d %10d %10d', (TRI-1)');
+ fprintf(fid, '\nCELL_TYPES %d', nTRI);
+ fprintf(fid, '\n%d', repmat([5], nTRI, 1));
+ if(nfields > 0)
+ fprintf(fid, '\nPOINT_DATA %d', Ntotal);
+ end
+ for n=1:nfields
+ fprintf(fid, '\nSCALARS %s double 1', vnames{n});
+ fprintf(fid, '\nLOOKUP_TABLE default');
+ fprintf(fid, '\n%25.16e', uout{n});
+ end
+ fclose(fid);
+end
--
2.17.0