-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspatial_discretization.cpp
418 lines (342 loc) · 13.3 KB
/
spatial_discretization.cpp
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
#include"non_uniform_grid.h"
#include"findneighbor.h"
extern OctCell *bodygrid;
extern Node *HeadListAllGrid;
//x,y belong to [-1,1]X[-1,1] 需要将 [x_{i-1/2} x_{i+1/2}] => [-1,1]
double approx_sol(double x, double y, double *doftmp, int n=nDOF );
//直接x,y是原始计算区域的坐标 [x_{i-1/2} x_{i+1/2}]
double n_approx_sol(double x,double y, double xc1, double yc1, double dx, double dy, double *doftmp, int n=nDOF );
double n_approx_sol(const double xi[2], const double xc[2], double dx, double dy, double *doftmp, int n=nDOF );
extern vector<Face> faces_comp;
void spatial_discretize_f(Face &fc)
{
OctCell *un;
OctCell *un1;
// OctCell *unp1x, *unp1y, *unm1x, *unm1y;
// double tmp92=0.0;
// double tmp93=0.0;
// double tmp94=0.0;
// double tmpx=0.0, tmpy=0.0;
un=fc.parent;
un1=fc.neighbor;
double xc1,yc1, xc2,yc2;
double dx1,dy1,dy2,dx2;
// double uapp[4][3][3]={0.0};
// double uapp1[4][3][3]={0.0};
xc1=un->xc1;
yc1=un->yc1;
dx1=un->dx;
dy1=un->dy;
xc2=un1->xc1;
yc2=un1->yc1;
dx2=un1->dx;
dy2=un1->dy;
double fflx[4][6]={0.0};
double rfflx[4][6]={0.0};
for (short j=0; j<4; j++) {
fflx[j][0]=(wei[0]*fc.faceflux[0][j]+wei[1]*fc.faceflux[1][j]+wei[2]*fc.faceflux[2][j])*fc.area*0.5;
fflx[j][1]=(wei[0]*fc.faceflux[0][j]*phix(fc.gs_pt[0][0],xc1,dx1)+wei[1]*fc.faceflux[1][j]*phix(fc.gs_pt[1][0],xc1,dx1)
+wei[2]*fc.faceflux[2][j]*phix(fc.gs_pt[2][0],xc1,dx1))*fc.area*0.5;
fflx[j][2]=(wei[0]*fc.faceflux[0][j]*psiy(fc.gs_pt[0][1],yc1,dy1)+wei[1]*fc.faceflux[1][j]*psiy(fc.gs_pt[1][1],yc1,dy1)
+wei[2]*fc.faceflux[2][j]*psiy(fc.gs_pt[2][1],yc1,dy1))*fc.area*0.5;
// if(nDOF==6) {
fflx[j][3]=(wei[0]*fc.faceflux[0][j]*phix_psiy(fc.gs_pt[0][0], fc.gs_pt[0][1],xc1,yc1,dx1, dy1)
+wei[1]*fc.faceflux[1][j]*phix_psiy(fc.gs_pt[1][0], fc.gs_pt[1][1],xc1,yc1,dx1,dy1)
+wei[2]*fc.faceflux[2][j]*phix_psiy(fc.gs_pt[2][0],fc.gs_pt[2][1],xc1,yc1,dx1, dy1))*fc.area*0.5;
fflx[j][4]=(wei[0]*fc.faceflux[0][j]*phix2m(fc.gs_pt[0][0],xc1,dx1)+wei[1]*fc.faceflux[1][j]*phix2m(fc.gs_pt[1][0],xc1,dx1)
+wei[2]*fc.faceflux[2][j]*phix2m(fc.gs_pt[2][0],xc1,dx1))*fc.area*0.5;
fflx[j][5]=(wei[0]*fc.faceflux[0][j]*psiy2m(fc.gs_pt[0][1],yc1,dy1)+wei[1]*fc.faceflux[1][j]*psiy2m(fc.gs_pt[1][1],yc1,dy1)
+wei[2]*fc.faceflux[2][j]*psiy2m(fc.gs_pt[2][1],yc1,dy1))*fc.area*0.5;
// }
//right face
rfflx[j][0]=fflx[j][0];
rfflx[j][1]=(wei[0]*fc.faceflux[0][j]*phix(fc.gs_pt[0][0],xc2,dx2)+wei[1]*fc.faceflux[1][j]*phix(fc.gs_pt[1][0],xc2,dx2)
+wei[2]*fc.faceflux[2][j]*phix(fc.gs_pt[2][0],xc2,dx2))*fc.area*0.5;
rfflx[j][2]=(wei[0]*fc.faceflux[0][j]*psiy(fc.gs_pt[0][1],yc2,dy2)+wei[1]*fc.faceflux[1][j]*psiy(fc.gs_pt[1][1],yc2,dy2)
+wei[2]*fc.faceflux[2][j]*psiy(fc.gs_pt[2][1],yc2,dy2))*fc.area*0.5;
// if(nDOF==6) {
rfflx[j][3]=(wei[0]*fc.faceflux[0][j]*phix_psiy(fc.gs_pt[0][0], fc.gs_pt[0][1],xc2,yc2,dx2, dy2)
+wei[1]*fc.faceflux[1][j]*phix_psiy(fc.gs_pt[1][0], fc.gs_pt[1][1],xc2,yc2,dx2,dy2)
+wei[2]*fc.faceflux[2][j]*phix_psiy(fc.gs_pt[2][0],fc.gs_pt[2][1],xc2,yc2,dx2, dy2))*fc.area*0.5;
rfflx[j][4]=(wei[0]*fc.faceflux[0][j]*phix2m(fc.gs_pt[0][0],xc2,dx2)+wei[1]*fc.faceflux[1][j]*phix2m(fc.gs_pt[1][0],xc2,dx2)
+wei[2]*fc.faceflux[2][j]*phix2m(fc.gs_pt[2][0],xc2,dx2))*fc.area*0.5;
rfflx[j][5]=(wei[0]*fc.faceflux[0][j]*psiy2m(fc.gs_pt[0][1],yc2,dy2)+wei[1]*fc.faceflux[1][j]*psiy2m(fc.gs_pt[1][1],yc2,dy2)
+wei[2]*fc.faceflux[2][j]*psiy2m(fc.gs_pt[2][1],yc2,dy2))*fc.area*0.5;
// }
}
//face flux
for(short j=0;j<4;++j){
for(short imm=0; imm<6;++imm) {
un->residual[j][imm] += fflx[j][imm];
un1->residual[j][imm] -= rfflx[j][imm];
}
}
//end face flux
}
void spatial_discretize_v(OctCell* un)
{
double tmp92=0.0;
double tmp93=0.0;
double tmp94=0.0;
double tmpx=0.0, tmpy=0.0;
double uapp[4][3][3]={0.0};
double dx,dy, dxpdy;
dx=un->dx;
dy=un->dy;
dxpdy=dx*dy;
for(short j=0; j<4; j++) {
for(short imm=0; imm<3;imm++) {
for(short jmm=0; jmm<3; jmm++) {
uapp[j][jmm][imm]=approx_sol(gspt[jmm], gspt[imm], un->dof[j], nDOF); //u(x,y)
}
}
}
double pre[3][3]={0.0};
double pre1[3][3]={0.0};
for(short imm=0; imm<3;imm++) {
for(short jmm=0; jmm<3; jmm++) {
pre[jmm][imm]=GAM11 *(uapp[3][jmm][imm]-0.5*(uapp[1][jmm][imm]*uapp[1][jmm][imm]/uapp[0][jmm][imm]
+ uapp[2][jmm][imm]*uapp[2][jmm][imm]/uapp[0][jmm][imm]));
}
}
double flxfunx[4][3][3]={0.0};
double flxfuny[4][3][3]={0.0};
for(short imm=0; imm<3;imm++) {
for(short jmm=0; jmm<3; jmm++) {
flxfunx[0][jmm][imm]=uapp[1][jmm][imm];
flxfuny[0][jmm][imm]=uapp[2][jmm][imm];
flxfunx[1][jmm][imm]=uapp[1][jmm][imm]*uapp[1][jmm][imm]/uapp[0][jmm][imm] + pre[jmm][imm];
flxfunx[2][jmm][imm] = flxfuny[1][jmm][imm] = uapp[1][jmm][imm]*uapp[2][jmm][imm]/uapp[0][jmm][imm];
flxfuny[2][jmm][imm]=uapp[2][jmm][imm]*uapp[2][jmm][imm]/uapp[0][jmm][imm] + pre[jmm][imm];
flxfunx[3][jmm][imm] = (uapp[3][jmm][imm] + pre[jmm][imm])* uapp[1][jmm][imm]/uapp[0][jmm][imm];
flxfuny[3][jmm][imm] = (uapp[3][jmm][imm] + pre[jmm][imm])* uapp[2][jmm][imm]/uapp[0][jmm][imm];
}
}
//体积积分项
// euler equation for aerodynamics
//uapp[j][jmm][imm]
for(short j=0; j<4;++j) {
tmp92=0.0;
tmp93=0.0;
tmp94=0.0;
tmpx=tmpy=0.0;
//base function: phi_i(x) & psi_j(y)
for(short imm=0; imm < 3;imm++) {
for(short jmm=0; jmm < 3; jmm++) {
tmp92 += flxfunx[j][jmm][imm]*wei[imm]*wei[jmm];
tmp93 += flxfuny[j][jmm][imm]*wei[imm]*wei[jmm];
}
}
tmp92 *= 0.25*dxpdy;
tmp93 *= 0.25*dxpdy;
un->residual[j][1] -= 2.0/dx * tmp92;
un->residual[j][2] -= 2.0/dy * tmp93;
tmp92=tmp93=0.0;
//base function: phi_i(x)*psi_j(y), phi_i(x)^2-1.0/3.0, & psi_j(y)^2-1.0/3
if(nDOF==6) {
for(short imm=0; imm<3;imm++) {
for(short jmm=0; jmm<3; jmm++) {
tmp93 += flxfuny[j][jmm][imm] *gspt[jmm]*wei[imm]*wei[jmm]; //fy*x
tmp94 += flxfunx[j][jmm][imm] *gspt[imm]*wei[imm]*wei[jmm]; //fx*y
tmpx += flxfunx[j][jmm][imm] *gspt[jmm]*wei[imm]*wei[jmm]; //fx*x
tmpy += flxfuny[j][jmm][imm] *gspt[imm]*wei[imm]*wei[jmm]; //fy*y
}
}
tmp94 *= 0.25*dxpdy;
tmp93 *= 0.25*dxpdy;
tmpx *= 0.25*dxpdy;
tmpy *= 0.25*dxpdy;
un->residual[j][3] -= 2.0/dx * tmp94 + 2.0/dy * tmp93;
un->residual[j][4] -= 4.0/dx * tmpx;
un->residual[j][5] -= 4.0/dy * tmpy;
}
} //end for
//=====
}
void spatial_discretization_all()
{
Node *current;
current = HeadListAllGrid;
OctCell *pcell0;
while(current != NULL)
{
pcell0 = current->cell;
if(pcell0->flag % 2 == 0 && current->flg<=2 ) {
for(int im=0;im<4; ++im){
for(int jm=0;jm<6; ++jm){
pcell0->residual[im][jm]=0.0;
}
}
}
current = current->next;
}
for(vector<Face>::size_type isz=0; isz!=faces_comp.size(); ++isz){
spatial_discretize_f(faces_comp[isz]);
}
current = HeadListAllGrid;
while(current != NULL)
{
pcell0 = current->cell;
if(pcell0->flag == 0 && current->flg<=2 )
spatial_discretize_v(pcell0);
current = current->next;
}
}
#ifdef RES_SMOOTH
const double sm_ep=500.1; //0.5-0.8
void resd_smoothing()
{
OctCell *pc0,*pc1;
Node *current;
current = HeadListAllGrid;
OctCell *pcell0;
double vol0,vol1;
while(current != NULL)
{
pcell0 = current->cell;
if(pcell0->flag == 0 && current->flg<=2 ) {
for(int im=0;im<4; ++im){
for(int jm=0;jm<6; ++jm){
pcell0->resd1[im][jm]=pcell0->residual[im][jm];
// pcell0->resd0[im][jm]=0.0;
}
}
}
current = current->next;
}
OctCell *pcs,*pcn;
double renb[4][6],renb1[4][6];
double renbs[4][6],renbn[4][6];
double rtmx,rtmy;
for(int itm=0;itm<2;++itm){
current = HeadListAllGrid;
while(current != NULL)
{
pcell0 = current->cell;
if(pcell0->flag == 0 && current->flg<=2 ) {
pc0=WestNeighbor(pcell0);
pc1=EastNeighbor(pcell0);
pcs=SouthNeighbor(pcell0);
pcn=NorthNeighbor(pcell0);
rtmx=rtmy=0.0;
if(pc0->reflag==1){
for(int iu=0;iu<4;++iu)
for(int ju=0;ju<6;++ju)
renb[iu][ju]=0.0;
}
else {
++rtmx;
for(int iu=0;iu<4;++iu)
for(int ju=0;ju<6;++ju)
renb[iu][ju]=pc0->resd1[iu][ju];
}
if(pc1->reflag==1){
for(int iu=0;iu<4;++iu)
for(int ju=0;ju<6;++ju)
renb1[iu][ju]=0.0;
}
else {
++rtmx;
for(int iu=0;iu<4;++iu)
for(int ju=0;ju<6;++ju)
renb1[iu][ju]=pc1->resd1[iu][ju];
}
if(pcs->reflag==1){
for(int iu=0;iu<4;++iu)
for(int ju=0;ju<6;++ju)
renbs[iu][ju]=0.0;
}
else {
++rtmy;
for(int iu=0;iu<4;++iu)
for(int ju=0;ju<6;++ju)
renbs[iu][ju]=pcs->resd1[iu][ju];
}
if(pcn->reflag==1){
for(int iu=0;iu<4;++iu)
for(int ju=0;ju<6;++ju)
renbn[iu][ju]=0.0;
}
else {
++rtmy;
for(int iu=0;iu<4;++iu)
for(int ju=0;ju<6;++ju)
renbn[iu][ju]=pcn->resd1[iu][ju];
}
for(int im=0;im<4; ++im){
for(int jm=0;jm<6; ++jm){
pcell0->resd1[im][jm]
=(pcell0->resd1[im][jm]+sm_ep*(renb[im][jm]+renb1[im][jm]))
/(1.0+sm_ep*rtmx);
}
}
for(int im=0;im<4; ++im){
for(int jm=0;jm<6; ++jm){
pcell0->resd1[im][jm]
=(pcell0->resd1[im][jm]+sm_ep*(renbs[im][jm]+renbn[im][jm]))
/(1.0+sm_ep*rtmy);
}
}
}
current = current->next;
}
}
/*
for(int itmp=0;itmp<2;++itmp){
for(vector<Face>::size_type isz=0; isz!=faces_comp.size(); ++isz){
pc0=faces_comp[isz].parent;
vol0=pc0->dx*pc0->dy;
vol0=1.;
pc1=faces_comp[isz].neighbor;
vol1=pc1->dx*pc1->dy;
vol1=1.;
for(int im=0;im<4;++im){
for(int jm=0;jm<6;++jm){
if(pc0->flag==0){
pc0->resd0[im][jm]+=vol0/vol1*pc1->resd1[im][jm]*sm_ep;
}
if(pc1->flag==0){
pc1->resd0[im][jm]+=vol1/vol0*pc0->resd1[im][jm]*sm_ep;
}
}
}
}
current = HeadListAllGrid;
while(current != NULL)
{
pcell0 = current->cell;
if(pcell0->flag == 0 && current->flg<=2 ) {
for(int im=0;im<4; ++im){
for(int jm=0;jm<6; ++jm){
pcell0->resd1[im][jm]
=(pcell0->resd1[im][jm]+pcell0->resd0[im][jm])
/(1.0+sm_ep*pcell0->p_node->n_nb);
}
}
}
current = current->next;
}
*/
current = HeadListAllGrid;
while(current != NULL)
{
pcell0 = current->cell;
if(pcell0->flag == 0 && current->flg<=2 ) {
// for(int im=0;im<4; ++im){
// for(int jm=0;jm<6; ++jm){
// if(fabs(pcell0->resd1[im][jm])
// <fabs(pcell0->residual[im][jm]))
// pcell0->residual[im][jm]=pcell0->resd1[im][jm];
// }
// }
for(int im=0;im<4; ++im){
if(fabs(pcell0->resd1[im][0])
<fabs(pcell0->residual[im][0]))
pcell0->residual[im][0]=pcell0->resd1[im][0];
}
}
current = current->next;
}
//}
}
#endif