/
bounds.fishmon.c
executable file
·408 lines (338 loc) · 11.2 KB
/
bounds.fishmon.c
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
#include "decs.h"
/* bound array containing entire set of primitive variables */
// GODMARK: something seriously wrong with EXTRAP=1 (EOMFFDE)
#define EXTRAP 0
// 0: just copy
// 1: gdet or other extrapolation
// 2: copy (with rescale())
// to help protect the pole from death blows to the computational grid
// a sort of crushing regularization
#define POLEDEATH 1
// causes problems with stability at just beyond pole
// for field line plots, can just set B^\theta=0 along pole
// in order to avoid accessing undefined data, but still fill corner
// zones, the ORDER of boundary LOOPS is as follows:
// X1 in&out: LOOPN2 LOOPN3 LOOPBOUNDIN1 & LOOPBOUNDOUT1
// X2 in&out: LOOPF1 LOOPN3 LOOPBOUNDIN2 & LOOPBOUNDOUT2 // LOOPF1 ok if X1 dimension not there, then LOOPF1->LOOPN1
// X3 in&out: LOOPF1 LOOPF2 LOOPBOUNDIN3 & LOOPBOUNDOUT3 // as above
int bound_prim_user(int boundstage, FTYPE prim[][N2M][N3M][NPR])
{
int i, j, k, pl;
struct of_geom geom,rgeom;
FTYPE vcon[NDIM]; // coordinate basis vcon
#if(WHICHVEL==VEL3)
int failreturn;
#endif
int ri, rj, rk; // reference i,j,k
FTYPE prescale[NPR];
///////////////////////////
//
// X1 inner OUTFLOW/FIXEDOUTFLOW
//
///////////////////////////
if (mycpupos[1] == 0) {
if((BCtype[X1DN]==OUTFLOW)||(BCtype[X1DN]==FIXEDOUTFLOW)){
/* inner r boundary condition: u, just copy */
LOOPN2 LOOPN3{
#if(EXTRAP==0)
ri=0;
rj=j;
rk=k;
LOOPBOUND1IN PBOUNDLOOP(pl) prim[i][j][k][pl] = prim[ri][rj][rk][pl];
#elif(EXTRAP==1)
ri=0;
rj=j;
rk=k;
LOOPBOUND1IN{
for(pl=RHO;pl<=UU;pl++){
prim[i][j][k][pl] = prim[ri][rj][rk][pl] * gdet[ri][rj][rk][CENT]/gdet[i][j][k][CENT] ;
}
pl=U1; // treat U1 as special
prim[i][j][k][pl] = prim[ri][rj][rk][pl] * (1. - (i-ri)*dx[1]) ;
for(pl=U2;pl<=U3;pl++){
prim[i][j][k][pl] = prim[ri][rj][rk][pl] * (1. + (i-ri)*dx[1]) ;
}
pl=B1; // treat B1 special
prim[i][j][k][pl] = prim[ri][rj][rk][pl] * gdet[ri][rj][rk][CENT]/gdet[i][j][k][CENT] ;
for(pl=B2;pl<=B3;pl++){
prim[i][j][k][pl] = prim[ri][rj][rk][pl] * (1. + (i-ri)*dx[1]) ;
}
}
#elif(EXTRAP==2)
ri=0;
rj=j;
rk=k;
get_geometry(ri, rj, rk, CENT, &rgeom);
rescale(1,1,prim[ri][rj][rk],&rgeom,prescale);
LOOPBOUND1IN{
// set guess
PBOUNDLOOP(pl) prim[i][j][k][pl]=prim[ri][rj][k][pl];
get_geometry(i, j, k, CENT, &geom);
rescale(-1,1,prim[i][j][k],&geom,prescale);
}
#endif
LOOPBOUND1IN{
#if(WHICHVEL==VEL4)
get_geometry(i, j, k, CENT, &geom);
inflow_check_4vel(1,prim[i][j][k],&geom, 0) ;
#elif(WHICHVEL==VEL3)
get_geometry(i, j, k, CENT, &geom);
inflow_check_3vel(1,prim[i][j][k],&geom, 0) ;
// projection may not preserve u^t to be real and rho>rhoscal u>uuscal
#if(JONCHECKS)
if(jonchecks){
//fixup1zone(prim[i][j][k],&geom,0);
failreturn=check_pr(prim[i][j][k],prim[i][j][k],&geom,-3);
if(failreturn){
dualfprintf(fail_file,"Bad boundary zone, couldn't fix: i=%d j=%d k=%d\n",startpos[1]+i,startpos[2]+j,startpos[3]+k);
if (fail(FAIL_BCFIX) >= 1) return (1);
}
}
#endif
#elif(WHICHVEL==VELREL4)
get_geometry(i,j,k,CENT,&geom) ;
inflow_check_rel4vel(1,prim[i][j][k],&geom,0) ;
if(limit_gamma(GAMMAMAX,prim[i][j][k],&geom,0)>=1)
FAILSTATEMENT("bounds.c:bound_prim()", "limit_gamma()", 1);
#endif
}
}// end 2 3
}// end if correct bound type
}// end if mycpupos[1]==0
///////////////////////////
//
// X1 outer OUTFLOW/FIXEDOUTFLOW
//
///////////////////////////
// outer r BC:
if (mycpupos[1] == ncpux1 - 1) {
if((BCtype[X1UP]==OUTFLOW)||(BCtype[X1UP]==FIXEDOUTFLOW)){
/* outer r BC: outflow */
LOOPN2 LOOPN3{
#if(EXTRAP==0)
ri=N1-1;
rj=j;
rk=k;
LOOPBOUND1OUT PBOUNDLOOP(pl) prim[i][j][k][pl] = prim[ri][rj][rk][pl];
#elif(EXTRAP==1)
ri=N1-1;
rj=j;
rk=k;
LOOPBOUND1OUT{
for(pl=RHO;pl<=UU;pl++){
prim[i][j][k][pl] = prim[ri][rj][rk][pl] * gdet[ri][rj][rk][CENT]/gdet[i][j][k][CENT] ;
}
pl=U1; // treat U1 as special
prim[i][j][k][pl] = prim[ri][rj][rk][pl] * (1. - 2*(i-ri)*dx[1]) ;
for(pl=U2;pl<=U3;pl++){
prim[i][j][k][pl] = prim[ri][rj][rk][pl] * (1. - (i-ri)*dx[1]) ;
}
pl=B1; // treat B1 special
prim[i][j][k][pl] = prim[ri][rj][rk][pl] * gdet[ri][rj][rk][CENT]/gdet[i][j][k][CENT] ;
for(pl=B2;pl<=B3;pl++){
prim[i][j][k][pl] = prim[ri][rj][rk][pl] * (1. - (i-ri)*dx[1]) ;
}
}
#elif(EXTRAP==2)
ri=N1-1;
rj=j;
rk=k;
get_geometry(ri, rj, rk, CENT, &rgeom);
rescale(1,1,prim[ri][rj][rk],&rgeom,prescale);
LOOPBOUND1OUT{
// set guess
PBOUNDLOOP(pl) prim[i][j][k][pl]=prim[ri][rj][rk][pl];
get_geometry(i, j, k, CENT, &geom);
rescale(-1,1,prim[i][j][k],&geom,prescale);
}
#endif
LOOPBOUND1OUT{
#if(WHICHVEL==VEL4)
get_geometry(i, j, k, CENT, &geom);
inflow_check_4vel(1,prim[i][j][k],&geom,0) ;
#elif(WHICHVEL==VEL3)
get_geometry(i, j, k, CENT, &geom);
inflow_check_3vel(1,prim[i][j][k],&geom,0) ;
// projection may not preserve u^t to be real and rho>rhoscal u>uuscal
#if(JONCHECKS)
if(jonchecks){
//fixup1zone(prim[i][j][k],&geom,0);
failreturn=check_pr(prim[i][j][k],prim[i][j][k],&geom,-3);
if(failreturn){
dualfprintf(fail_file,"Bad boundary zone, couldn't fix: i=%d j=%d k=%d\n",startpos[1]+i,startpos[2]+j,startpos[3]+k);
if (fail(FAIL_BCFIX) >= 1) return (1);
}
}
#endif
#elif(WHICHVEL==VELREL4)
get_geometry(i,j,k,CENT,&geom) ;
inflow_check_rel4vel(1,prim[i][j][k],&geom,0) ;
if(limit_gamma(GAMMAMAX,prim[i][j][k],&geom, 0)>=1)
FAILSTATEMENT("bounds.c:bound_prim()", "limit_gamma()", 2);
#endif
}
}// end 2 3
}// end if correct bound type
}// end if mycpu is correct
///////////////////////////
//
// X2 inner POLARAXIS
//
///////////////////////////
/* inner polar BC (preserves u^t rho and u) */
if (mycpupos[2] == 0) {
if((BCtype[X2DN]==POLARAXIS)||(BCtype[X2DN]==SYMM)||(BCtype[X2DN]==ASYMM) ){
LOOPF1 LOOPN3{
ri=i;
rj=0;
rk=k;
LOOPBOUND2IN PBOUNDLOOP(pl) prim[i][j][k][pl] = prim[ri][rj+(rj-j-1)][rk][pl];
}
}
if((BCtype[X2DN]==POLARAXIS)||(BCtype[X2DN]==ASYMM) ){
/* make sure b and u are antisymmetric at the poles (preserves u^t rho and u) */
LOOPF1 LOOPN3{
LOOPBOUND2IN {
if(POSDEFMETRIC==0){
// u^t must be symmetric across pole, which is functions of u2 and u3 as well as their squares and othe products. u2 in KS happens to be independent of sign, but in general is could be for some other metric.
// for now, assume KS-like metric where u2 is antisymmetric and u^t dep only on u2^2, not u2
prim[i][j][k][U2] *= 1.;
prim[i][j][k][U3] *= 1.;
prim[i][j][k][B2] *= 1.;
prim[i][j][k][B3] *= 1.;
}
else{
prim[i][j][k][U2] *= -1.;
prim[i][j][k][U3] *= 1.;
prim[i][j][k][B2] *= -1.;
prim[i][j][k][B3] *= 1.;
}
}
}// end loop 13
#if(POLEDEATH)
// fixup
LOOPF1 LOOPN3 {
for (j = -N2BND; j < 0+POLEDEATH; j++) {
if(POSDEFMETRIC==0){
// u^t must be symmetric across pole, which is functions of u2 and u3 as well as their squares and othe products. u2 in KS happens to be independent of sign, but in general is could be for some other metric.
// for now, assume KS-like metric where u2 is antisymmetric and u^t dep only on u2^2, not u2
prim[i][j][k][U2] *= 0;
prim[i][j][k][B2] *= 0.;
}
else{
prim[i][j][k][U2] *= 0.;
prim[i][j][k][B2] *= 0.;
}
}
}// end loop 13
#endif
} // end if POLARXIS or ASYMM
}// end if mycpupos[2]==0
///////////////////////////
//
// X2 outer POLARAXIS
//
///////////////////////////
if (mycpupos[2] == ncpux2-1) {
if((BCtype[X2UP]==POLARAXIS)||(BCtype[X2UP]==SYMM)||(BCtype[X2UP]==ASYMM) ){
LOOPF1 LOOPN3{
ri=i;
rj=N2-1;
rk=k;
LOOPBOUND2OUT PBOUNDLOOP(pl) prim[i][j][k][pl] = prim[ri][rj+(rj-j+1)][rk][pl];
}
}
if((BCtype[X2UP]==POLARAXIS)||(BCtype[X2UP]==ASYMM) ){
/* make sure b and u are antisymmetric at the poles (preserves u^t rho and u) */
LOOPF1 LOOPF3{
LOOPBOUND2OUT {
if(POSDEFMETRIC==0){
// u^t must be symmetric across pole, which is functions of u2 and u3 as well as their squares and othe products. u2 in KS happens to be independent of sign, but in general is could be for some other metric.
// for now, assume KS-like metric where u2 is antisymmetric and u^t dep only on u2^2, not u2
prim[i][j][k][U2] *= 1.;
prim[i][j][k][U3] *= 1.;
prim[i][j][k][B2] *= 1.;
prim[i][j][k][B3] *= 1.;
}
else{
prim[i][j][k][U2] *= -1.;
prim[i][j][k][U3] *= 1.;
prim[i][j][k][B2] *= -1.;
prim[i][j][k][B3] *= 1.;
}
}
}// end loop 13
#if(POLEDEATH)
// fixup
LOOPF1 LOOPN3 {
for (j = N2-POLEDEATH; j <= N2-1+N2BND; j++) {
if(POSDEFMETRIC==0){
// u^t must be symmetric across pole, which is functions of u2 and u3 as well as their squares and othe products. u2 in KS happens to be independent of sign, but in general is could be for some other metric.
// for now, assume KS-like metric where u2 is antisymmetric and u^t dep only on u2^2, not u2
prim[i][j][k][U2] *= 0;
prim[i][j][k][B2] *= 0.;
}
else{
prim[i][j][k][U2] *= 0.;
prim[i][j][k][B2] *= 0.;
}
}
}// end loop 13
#endif
} // end if POLARXIS or ASYMM
}// end if mycpupos[2]==ncpux2-1
// periodic x3
if ( (mycpupos[3] == 0)&&(mycpupos[3] == ncpux3 - 1) ) {
if( (BCtype[X3DN]==PERIODIC)&&(BCtype[X3UP]==PERIODIC) ){
// just copy from one side to another
LOOPF1 LOOPF2{
// copy from upper side to lower boundary zones
ri=i;
rj=j;
rk=N3;
LOOPBOUND3IN PBOUNDLOOP(pl) prim[i][j][k][pl] = prim[ri][rj][rk+k][pl];
// copy from lower side to upper boundary zones
ri=i;
rj=j;
rk=0;
LOOPBOUND3OUT PBOUNDLOOP(pl) prim[i][j][k][pl] = prim[ri][rj][rk+(k-N3)][pl];
}
}
}
return (0);
}
// see interpline.c
int apply_bc_line(int doinverse, int iterglobal, int recontype, int bs, int be, FTYPE (*yin)[2][NBIGM], FTYPE (*yout)[2][NBIGM])
{
int flip_y(int iterglobal, int recontype, int bs, int be, FTYPE (*y)[2][NBIGM]);
if(doinverse==0){
flip_y(iterglobal, recontype, bs, be, yin);
}
else{
flip_y(iterglobal, recontype, bs, be, yin);
flip_y(iterglobal, recontype, bs, be, yout);
}
return(0);
}
#include "reconstructeno.h"
int flip_y(int iterglobal, int recontype, int bs, int be, FTYPE (*y)[2][NBIGM])
{
int pl,myi;
#if( WENO_DIR_FLIP_CONS_SIGN_DN ) //flip the sign of the consrved quantities at the cylindrical axis so that they do not have a kink due to multiplication by gdet = |R|
if( iterglobal == WENO_DIR_FLIP_CONS_SIGN_DN && (recontype == CVT_C2A || recontype == CVT_A2C) && mycpupos[iterglobal] == 0 ) {
PLOOP(pl)
for( myi = bs; myi < 0; myi++ ) {
y[pl][0][myi] = - y[pl][0][myi];
}
}
#endif
#if( WENO_DIR_FLIP_CONS_SIGN_UP ) //flip the sign of the consrved quantities at the cylindrical axis so that they do not have a kink due to multiplication by gdet = |R|
if( iterglobal == WENO_DIR_FLIP_CONS_SIGN_UP && (recontype == CVT_C2A || recontype == CVT_A2C) && mycpupos[iterglobal] == numbercpu[iterglobal] - 1 ) {
PLOOP(pl)
for( myi = N1*(iterglobal==1) + N2*(iterglobal==2) + N3*(iterglobal==3); myi <= be; myi++ ) {
y[pl][0][myi] = - y[pl][0][myi];
}
}
#endif
return(0);
}