-
Notifications
You must be signed in to change notification settings - Fork 7
/
bounds.tools.c
4050 lines (2986 loc) · 136 KB
/
bounds.tools.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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "decs.h"
#define ADJUSTFLUXCT 0 // whether to adjust fluxCT
// GODMARK: something seriously wrong with OUTEREXTRAP=1 (EOMFFDE)
#define DEBUGINOUTLOOPS 0
#define OUTEREXTRAP 3
// 0: just copy
// 1: gdet or other extrapolation
// 2: copy (with rescale())
// 3: Treat same as HORIZONEXTRAP==3
// how to bound near horizon
#define HORIZONEXTRAP 3
// as above and also:
// 3: jon version
// number of iterations to get v^\phi\sim constant
#define NUMITERVPHI 5
//////////////////////////////
// number of zones to use pole crushing regularizations
// to help protect the pole from death blows to the computational grid
// a sort of crushing regularization
// causes problems with stability at just beyond pole
// for field line plots, can just set B^\theta=0 along pole
#define POLEDEATH (MIN(DOPOLEDEATH,N2BND)) // with expansion by 1 point if detects jumps in densities or Lorentz factor (see poldeath())
//#define MAXPOLEDEATH N2BND // can't be larger than N2BND
#define MAXPOLEDEATH (MIN(DOPOLEDEATH+1,N2BND)) // can't be larger than N2BND
#define DEATHEXPANDAMOUNT 0
#define POLEINTERPTYPE 3 // 0=set uu2=bu2=0, 1=linearly interpolate uu2,bu2 2=interpolate B_\phi into pole 3 =linearly for uu2 unless sucking on pole
//////////////////////////////////////////
// number of zones to enforce Lorentz factor to be small
// notice that at pole uu1 and uu2 are artificially large and these regions can lead to runaway low densities and so even higher uu1,uu3
// problem with POLEGAMMADEATH is that at large radius as fluid converges toward pole the fluid stagnates and can fall back at larger angles for no reason -- even for simple torus problem this happens when GAMMAPOLE=1.001
#define POLEGAMMADEATH (MIN(DOPOLEGAMMADEATH,N2BND))
// maximum allowed Lorentz factor near the pole (set to something large that should be allowed by solution -- problem and grid dependent)
//#define GAMMAPOLE (2.0)
#define GAMMAPOLEOUTGOING 1.1 // keep low
#define GAMMAPOLEOUTGOINGPOWER 1.0
#define GAMMAPOLEOUTGOINGRADIUS 10.0 // very model dependent
#define GAMMAPOLEINGOING GAMMAMAX
// factor by which to allow quantities to jump near pole
#define POLEDENSITYDROPFACTOR 5.0
#define POLEGAMMAJUMPFACTOR 2.0
///////////////////////////////////////////
// whether to average in radius for poledeath
#define AVERAGEINRADIUS 0 // not correct across MPI boundaries since have to shift near boundary yet need that last cell to be consistent with as if no MPI boundary // OPENNPMARK: Also not correct for OpenMP
#define RADIUSTOSTARTAVERAGING 7 // should be beyond horizon so doesn't diffuse across horizon
#define RADIUSTOAVOIDRADIALSUCK (2.0*Rhor)
// whether if doing full special 3d (i.e. special3dspc==1) that should only do poledeath for inflow
// 0 : no limit
// 1 : limit to poledeath acting if radial inflow
// 2 : limit to poledeath acting on flow within r=RADIUSLIMITPOLEDEATHIN
// 3 : limit if inflow OR out to r=RADIUSLIMITPOLEDEATHIN (in case inflow only starts near horizon, still poledeath out to that radius
#define IFLIMITPOLEDEATH 0
// radius within which to use poledeath if have IFLIMITPOLEDEATH==3
#define RADIUSLIMITPOLEDEATHIN (3.0) // choose r=3M since always close to BH but always slightly outside horizon to help control stability.
// how many zones to use poledeath at outer *physical* edge
#define IFLIMITPOLEDEATHIOUT (-100)
///////////////////////////////////////////
// number of zones to smooth pole
#define POLESMOOTH (MIN(DOPOLESMOOTH,N2BND))
// X1DN FIXEDUSINGPANALYTIC
//
///////////////////////////
// Currently assume completely general situation where
// only triggers on BCs, but across all CPUs. Use grid sectioning to enforce per-CPU dependence if desired. Any other CPUs that have BCs set will have BCs overwritten by MPI routines
// SUPERGODMARK: Should be able to use set_boundloop()'s result if included FIXED version, but currently it only handles OUTFLOW types for grid sectioning
int bound_x1dn_analytic(int boundstage, int finalstep, SFTYPE boundtime, int whichdir, int boundvartype, int *dirprim, int ispstag, FTYPE (*prim)[NSTORE2][NSTORE3][NPR])
{
int i,j,k;
int pl,pliter;
#if(ANALYTICMEMORY==0)
dualfprintf(fail_file,"ANALYTICMEMORY==0 but called bound_x1dn_analytic\n");
myexit(786752);
#endif
// then no need to set pglobal or pstagglobal since evolution sets appropriately in constrained way on a well-defined computational box
dualfprintf(fail_file,"No use for this currently\n");
myexit(34269834);
if(ispstag){
COMPFULLLOOP{
// note we assume "i=0" is boundary cell to be fixed
// This ensures divb=0, but may be inconsistent with code's treatement of true i=0 if doing OUTFLOW
if(WITHINACTIVESTAGBNDSECTIONX1DN(i,j,k)){
pl=B1; MACP0A1(prim,i,j,k,pl) = GLOBALMACP0A1(pstaganalytic,i,j,k,pl);
}
if(WITHINACTIVEBNDSECTIONX1DN(i,j,k)){
PLOOP(pliter,pl) if(pl!=B1) MACP0A1(prim,i,j,k,pl) = GLOBALMACP0A1(pstaganalytic,i,j,k,pl);
}
}
}
else{
COMPFULLLOOP{
if(WITHINACTIVEBNDSECTIONX1DN(i,j,k)){
PLOOP(pliter,pl) MACP0A1(prim,i,j,k,pl) = GLOBALMACP0A1(panalytic,i,j,k,pl);
}
}
}
return(0);
}
// X1UP FIXEDUSINGPANALYTIC
//
///////////////////////////
// Currently assume completely general situation where
// only triggers on BCs, but across all CPUs. Use grid sectioning to enforce per-CPU dependence if desired. Any other CPUs that have BCs set will have BCs overwritten by MPI routines
// SUPERGODMARK: Should be able to use set_boundloop()'s result if included FIXED version, but currently it only handles OUTFLOW types for grid sectioning
int bound_x1up_analytic(int boundstage, int finalstep, SFTYPE boundtime, int whichdir, int boundvartype, int *dirprim, int ispstag, FTYPE (*prim)[NSTORE2][NSTORE3][NPR])
{
int i,j,k;
int pl,pliter;
#if(ANALYTICMEMORY==0)
dualfprintf(fail_file,"ANALYTICMEMORY==0 but called bound_x1dn_analytic\n");
myexit(786753);
#endif
// then no need to set pglobal or pstagglobal since evolution sets appropriately in constrained way on a well-defined computational box
dualfprintf(fail_file,"No use for this currently\n");
myexit(34269834);
if(ispstag){
COMPFULLLOOP{
if(WITHINACTIVESTAGBNDSECTIONX1UP(i,j,k)){
pl=B1; MACP0A1(prim,i,j,k,pl) = GLOBALMACP0A1(pstaganalytic,i,j,k,pl);
}
if(WITHINACTIVEBNDSECTIONX1UP(i,j,k)){
PLOOP(pliter,pl) if(pl!=B1) MACP0A1(prim,i,j,k,pl) = GLOBALMACP0A1(pstaganalytic,i,j,k,pl);
}
}
}
else{
COMPFULLLOOP{
if(WITHINACTIVEBNDSECTIONX1UP(i,j,k)){
PLOOP(pliter,pl) MACP0A1(prim,i,j,k,pl) = GLOBALMACP0A1(panalytic,i,j,k,pl);
}
}
}
return(0);
}
// X1 inner OUTFLOW/FIXEDOUTFLOW
int bound_x1dn_outflow(
int boundstage, int finalstep, SFTYPE boundtime, int whichdir, int boundvartype, int *dirprim, int ispstag, FTYPE (*prim)[NSTORE2][NSTORE3][NPR],
int *inboundloop,
int *outboundloop,
int *innormalloop,
int *outnormalloop,
int (*inoutlohi)[NUMUPDOWN][NDIM],
int riin, int riout, int rjin, int rjout, int rkin, int rkout,
int *dosetbc,
int enerregion,
int *localenerpos
)
{
#pragma omp parallel // assume don't require EOS
{
int i,j,k,pl,pliter;
int locali1,globali1;
int locali2,globali2;
int ri1,ri2;
struct of_geom geom[NPR],rgeom[NPR];
FTYPE vcon[NDIM]; // coordinate basis vcon
#if(WHICHVEL==VEL3)
int failreturn;
#endif
int ri, rj, rk; // reference i,j,k
FTYPE prescale[NPR];
int horizonti;
int jj,kk;
struct of_geom geomdontuse[NPR];
struct of_geom *ptrgeom[NPR];
struct of_geom rgeomdontuse[NPR];
struct of_geom *ptrrgeom[NPR];
// assign memory
PALLLOOP(pl){
ptrgeom[pl]=&(geomdontuse[pl]);
ptrrgeom[pl]=&(rgeomdontuse[pl]);
}
if((BCtype[X1DN]==OUTFLOW)||(BCtype[X1DN]==FIXEDOUTFLOW)||(BCtype[X1DN]==FREEOUTFLOW)){
if ( (totalsize[1]>1) && (mycpupos[1] <= horizoncpupos1)) { // now all CPUs inside CPU with horizon will be using this (GODMARK: reference value needs to be chosen somehow for CPUs not on active grid)
/* inner r boundary condition: u, just copy */
OPENMPBCLOOPVARSDEFINELOOPX1DIR; OPENMPBCLOOPSETUPLOOPX1DIR;
//////// LOOPX1dir{
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
OPENMPBCLOOPBLOCK{
OPENMPBCLOOPBLOCK2IJKLOOPX1DIR(j,k);
ri=riin;
rj=j;
rk=k;
#if(HORIZONEXTRAP==0)
PALLLOOP(pl) get_geometry(ri, rj, rk, dirprim[pl], ptrrgeom[pl]);
LOOPBOUND1INSPECIAL{ // bound entire region inside non-evolved portion of grid
PBOUNDLOOP(pliter,pl) MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl);
}
#elif(HORIZONEXTRAP==1)
PALLLOOP(pl) get_geometry(ri, rj, rk, dirprim[pl], ptrrgeom[pl]);
LOOPBOUND1INSPECIAL{ // bound entire region inside non-evolved portion of grid
PALLLOOP(pl) get_geometry(i, j, k, dirprim[pl], ptrgeom[pl]);
for(pl=RHO;pl<=UU;pl++){
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (ptrrgeom[pl]->gdet/ptrgeom[pl]) ;
}
pl=U1; // treat U1 as special
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (1. - (i-ri)*dx[1]) ;
for(pl=U2;pl<=U3;pl++){
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (1. + (i-ri)*dx[1]) ;
}
pl=B1; // treat B1 special
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (ptrrgeom[pl]->gdet/ptrgeom[pl]);
for(pl=B2;pl<=B3;pl++){
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (1. + (i-ri)*dx[1]) ;
}
for(pl=B3+1;pl<NPRBOUND;pl++){
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (ptrrgeom[pl]->gdet/ptrgeom[pl]);
}
}
#elif(HORIZONEXTRAP==2)
get_geometry(ri, rj, rk, dirprim[0], ptrrgeom[0]);
rescale(1,1,MAC(prim,ri,rj,rk),ptrrgeom[0],prescale);
LOOPBOUND1INSPECIAL{
// set guess
PBOUNDLOOP(pliter,pl) MACP0A1(prim,i,j,k,pl)=MACP0A1(prim,ri,rj,k,pl);
get_geometry(i, j, k, dirprim[0], ptrgeom[0]);
rescale(-1,1,MAC(prim,i,j,k),ptrgeom[0],prescale);
}
#elif(HORIZONEXTRAP==3)
extrapfunc(X1DN,j,k,boundstage,finalstep,boundtime,whichdir,boundvartype,dirprim,ispstag,prim,inboundloop,outboundloop,innormalloop,outnormalloop,inoutlohi,riin,riout,rjin,rjout,rkin,rkout,dosetbc,enerregion,localenerpos);
#endif
if(ispstag==0){
if((BCtype[X1DN]==OUTFLOW)||(BCtype[X1DN]==FIXEDOUTFLOW)){
// GODMARK: assume all velocities at same location when doing inflow check
LOOPBOUND1INSPECIAL{
#if(WHICHVEL==VEL4)
get_geometry(i, j, k, dirprim[U1], ptrgeom[U1]);
inflow_check_4vel(1,MAC(prim,i,j,k),NULL,ptrgeom[U1], 0) ;
#elif(WHICHVEL==VEL3)
get_geometry(i, j, k, dirprim[U1], ptrgeom[U1]);
inflow_check_3vel(1,MAC(prim,i,j,k),NULL,ptrgeom[U1], 0) ;
// projection may not preserve u^t to be real and rho>rhoscal u>uuscal
#if(JONCHECKS)
if(jonchecks){
//fixup1zone(MAC(prim,i,j,k),ptrgeom[U1],0);
failreturn=check_pr(MAC(prim,i,j,k),MAC(prim,i,j,k),ptrgeom[U1],-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(i,j,k,FAIL_BCFIX) >= 1) return (1);
}
}
#endif
#elif(WHICHVEL==VELREL4)
get_geometry(i,j,k,dirprim[U1],ptrgeom[U1]) ;
inflow_check_rel4vel(1,MAC(prim,i,j,k),NULL,ptrgeom[U1],0) ;
if(limit_gamma(GAMMAMAX,MAC(prim,i,j,k),NULL,ptrgeom[U1],0)>=1)
FAILSTATEMENT("bounds.c:bound_prim()", "limit_gamma()", 1);
#endif
}
} // end if not allowing inflow
}
}// end 2 3
}// end if mycpupos[1]==0
}
else{
dualfprintf(fail_file,"Shouldn't be here in bounds\n");
myexit(3946836);
}
}// end parallel region
return(0);
}
// X1 outer OUTFLOW/FIXEDOUTFLOW
int bound_x1up_outflow(
int boundstage, int finalstep, SFTYPE boundtime, int whichdir, int boundvartype, int *dirprim, int ispstag, FTYPE (*prim)[NSTORE2][NSTORE3][NPR],
int *inboundloop,
int *outboundloop,
int *innormalloop,
int *outnormalloop,
int (*inoutlohi)[NUMUPDOWN][NDIM],
int riin, int riout, int rjin, int rjout, int rkin, int rkout,
int *dosetbc,
int enerregion,
int *localenerpos
)
{
#pragma omp parallel // assume don't require EOS
{
int i,j,k,pl,pliter;
int locali1,globali1;
int locali2,globali2;
int ri1,ri2;
FTYPE vcon[NDIM]; // coordinate basis vcon
#if(WHICHVEL==VEL3)
int failreturn;
#endif
int ri, rj, rk; // reference i,j,k
FTYPE prescale[NPR];
int horizonti;
int jj,kk;
struct of_geom geomdontuse[NPR];
struct of_geom *ptrgeom[NPR];
struct of_geom rgeomdontuse[NPR];
struct of_geom *ptrrgeom[NPR];
// assign memory
PALLLOOP(pl){
ptrgeom[pl]=&(geomdontuse[pl]);
ptrrgeom[pl]=&(rgeomdontuse[pl]);
}
if((BCtype[X1UP]==OUTFLOW)||(BCtype[X1UP]==FIXEDOUTFLOW)||(BCtype[X1UP]==FREEOUTFLOW)){
// outer r BC:
if ( (totalsize[1]>1) && (mycpupos[1] == ncpux1 - 1) ) {
OPENMPBCLOOPVARSDEFINELOOPX1DIR; OPENMPBCLOOPSETUPLOOPX1DIR;
//////// LOOPX1dir{
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
OPENMPBCLOOPBLOCK{
OPENMPBCLOOPBLOCK2IJKLOOPX1DIR(j,k);
ri=riout;
rj=j;
rk=k;
#if(OUTEREXTRAP==0)
PALLLOOP(pl) get_geometry(ri, rj, rk, dirprim[pl], ptrrgeom[pl]);
LOOPBOUND1OUT PBOUNDLOOP(pliter,pl) MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl);
#elif(OUTEREXTRAP==1)
PALLLOOP(pl) get_geometry(ri, rj, rk, dirprim[pl], ptrrgeom[pl]);
LOOPBOUND1OUT{
PALLLOOP(pl) get_geometry(i, j, k, dirprim[pl], ptrgeom[pl]);
for(pl=RHO;pl<=UU;pl++){
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (ptrrgeom[pl]->gdet/ptrgeom[pl]) ;
}
pl=U1; // treat U1 as special
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (1. - 2*(i-ri)*dx[1]) ;
for(pl=U2;pl<=U3;pl++){
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (1. - (i-ri)*dx[1]) ;
}
pl=B1; // treat B1 special
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (ptrrgeom[pl]->gdet/ptrgeom[pl]) ;
for(pl=B2;pl<=B3;pl++){
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (1. - (i-ri)*dx[1]) ;
}
for(pl=B3+1;pl<NPRBOUND;pl++){
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl) * (ptrrgeom[pl]->gdet/ptrgeom[pl]) ;
}
}
#elif(OUTEREXTRAP==2)
get_geometry(ri, rj, rk, dirprim[0], ptrrgeom[0]);
rescale(1,1,MAC(prim,ri,rj,rk),ptrrgeom[0],prescale);
LOOPBOUND1OUT{
// set guess
PBOUNDLOOP(pliter,pl) MACP0A1(prim,i,j,k,pl)=MACP0A1(prim,ri,rj,rk,pl);
get_geometry(i, j, k, dirprim[0], ptrgeom[0]);
rescale(-1,1,MAC(prim,i,j,k),ptrgeom[0],prescale);
}
#elif(OUTEREXTRAP==3)
extrapfunc(X1UP,j,k,boundstage,finalstep,boundtime,whichdir,boundvartype,dirprim,ispstag,prim,inboundloop,outboundloop,innormalloop,outnormalloop,inoutlohi,riin,riout,rjin,rjout,rkin,rkout,dosetbc,enerregion,localenerpos);
#endif
if(ispstag==0){
if((BCtype[X1UP]==OUTFLOW)||(BCtype[X1UP]==FIXEDOUTFLOW)){
LOOPBOUND1OUT{
#if(WHICHVEL==VEL4)
get_geometry(i, j, k, dirprim[U1], ptrgeom[U1]);
inflow_check_4vel(1,MAC(prim,i,j,k),NULL,ptrgeom[U1],0) ;
#elif(WHICHVEL==VEL3)
get_geometry(i, j, k, dirprim[U1], ptrgeom[U1]);
inflow_check_3vel(1,MAC(prim,i,j,k),NULL,ptrgeom[U1],0) ;
// projection may not preserve u^t to be real and rho>rhoscal u>uuscal
#if(JONCHECKS)
if(jonchecks){
//fixup1zone(MAC(prim,i,j,k),ptrgeom[U1],0);
failreturn=check_pr(MAC(prim,i,j,k),MAC(prim,i,j,k),ptrgeom[U1],-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(i,j,k,FAIL_BCFIX) >= 1) return (1);
}
}
#endif
#elif(WHICHVEL==VELREL4)
get_geometry(i,j,k,dirprim[U1],ptrgeom[U1]) ;
// dualfprintf(fail_file,"JUST BEFORE INFLOWCHECK: i=%d j=%d k=%d prim[U1]=%21.15g prim[U2]=%21.15g prim[U3]=%21.15g\n",i,j,k,MACP0A1(prim,i,j,k,U1) *sqrt(geom[U1].gcov[GIND(1,1)]),MACP0A1(prim,i,j,k,U2) *sqrt(geom[U1].gcov[GIND(2,2)]),MACP0A1(prim,i,j,k,U3) *sqrt(geom[U1].gcov[GIND(3,3)]));
// dualfprintf(fail_file,"JUST BEFORE INFLOWCHECK: i=%d j=%d k=%d prim[U1]=%21.15g prim[U2]=%21.15g prim[U3]=%21.15g\n",i,j,k,MACP0A1(prim,i,j,k,U1),MACP0A1(prim,i,j,k,U2),MACP0A1(prim,i,j,k,U3));
// DLOOP(jj,kk) dualfprintf(fail_file,"gcov[%d][%d]=%21.15g\n",jj,kk,geom[U1].gcov[GIND(jj,kk)]);
inflow_check_rel4vel(1,MAC(prim,i,j,k),NULL,ptrgeom[U1],0) ;
// dualfprintf(fail_file,"JUST BEFORE LIMIT: i=%d j=%d k=%d prim[U1]=%21.15g prim[U2]=%21.15g prim[U3]=%21.15g\n",i,j,k,MACP0A1(prim,i,j,k,U1) *sqrt(geom[U1].gcov[GIND(1,1)]),MACP0A1(prim,i,j,k,U2) *sqrt(geom[U1].gcov[GIND(2,2)]),MACP0A1(prim,i,j,k,U3) *sqrt(geom[U1].gcov[GIND(3,3)]));
// dualfprintf(fail_file,"JUST BEFORE LIMIT: i=%d j=%d k=%d prim[U1]=%21.15g prim[U2]=%21.15g prim[U3]=%21.15g\n",i,j,k,MACP0A1(prim,i,j,k,U1),MACP0A1(prim,i,j,k,U2),MACP0A1(prim,i,j,k,U3));
if(limit_gamma(GAMMAMAX,MAC(prim,i,j,k),NULL,ptrgeom[U1], 0)>=1)
FAILSTATEMENT("bounds.c:bound_prim()", "limit_gamma()", 2);
// dualfprintf(fail_file,"JUST AFTER LIMIT: i=%d j=%d k=%d prim[U1]=%21.15g prim[U2]=%21.15g prim[U3]=%21.15g\n",i,j,k,MACP0A1(prim,i,j,k,U1) *sqrt(geom[U1].gcov[GIND(1,1)]),MACP0A1(prim,i,j,k,U2) *sqrt(geom[U1].gcov[GIND(2,2)]),MACP0A1(prim,i,j,k,U3) *sqrt(geom[U1].gcov[GIND(3,3)]));
// dualfprintf(fail_file,"JUST AFTER LIMIT: i=%d j=%d k=%d prim[U1]=%21.15g prim[U2]=%21.15g prim[U3]=%21.15g\n",i,j,k,MACP0A1(prim,i,j,k,U1),MACP0A1(prim,i,j,k,U2),MACP0A1(prim,i,j,k,U3));
#endif
}// end over i
}// end if not allowing inflow
}
}// end 2 3
}// end if mycpu is correct
}
else{
dualfprintf(fail_file,"Shouldn't be here in bounds\n");
myexit(3946838);
}
}// end parallel region
return(0);
}
// X1 inner R0SING
int bound_x1dn_sym(
int boundstage, int finalstep, SFTYPE boundtime, int whichdir, int boundvartype, int *dirprim, int ispstag, FTYPE (*prim)[NSTORE2][NSTORE3][NPR],
int *inboundloop,
int *outboundloop,
int *innormalloop,
int *outnormalloop,
int (*inoutlohi)[NUMUPDOWN][NDIM],
int riin, int riout, int rjin, int rjout, int rkin, int rkout,
int *dosetbc,
int enerregion,
int *localenerpos
)
{
#pragma omp parallel // assume don't require EOS
{
int i,j,k,pl,pliter;
int locali1,globali1;
int locali2,globali2;
int ri1,ri2;
FTYPE vcon[NDIM]; // coordinate basis vcon
#if(WHICHVEL==VEL3)
int failreturn;
#endif
int ri, rj, rk; // reference i,j,k
FTYPE prescale[NPR];
int horizonti;
int jj,kk;
if((BCtype[X1DN]==R0SING)||(BCtype[X1DN]==SYMM)||(BCtype[X1DN]==ASYMM) ){
/* inner radial BC (preserves u^t rho and u) */
if ( (totalsize[1]>1) && (mycpupos[1] == 0) ) {
//////// LOOPX1dir{
{ // start block
OPENMPBCLOOPVARSDEFINELOOPX1DIR; OPENMPBCLOOPSETUPLOOPX1DIR;
//////// LOOPX1dir{
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
OPENMPBCLOOPBLOCK{
OPENMPBCLOOPBLOCK2IJKLOOPX1DIR(j,k);
rj=j;
rk=k;
LOOPBOUND1IN{
PBOUNDLOOP(pliter,pl){
// SECTIONMARK: assume r=0 singularity can't move
if(dirprim[pl]==FACE1 || dirprim[pl]==CORN3 || dirprim[pl]==CORN2 || dirprim[pl]==CORNT ) ri = -i; // FACE1 values
else ri=-i-1; // "CENT" values for purposes of this BC
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl);
}// over pl
}// over boundary zones
}
}// end block
if((BCtype[X1DN]==R0SING)||(BCtype[X1DN]==ASYMM) ){
/* make sure b and u are antisymmetric at the poles (preserves u^t rho and u) */
//// LOOPX1dir{
OPENMPBCLOOPVARSDEFINELOOPX1DIR; OPENMPBCLOOPSETUPLOOPX1DIR;
//////// LOOPX1dir{
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
OPENMPBCLOOPBLOCK{
OPENMPBCLOOPBLOCK2IJKLOOPX1DIR(j,k);
// SECTIONMARK: assume r=0 singularity can't move
i=0;
PBOUNDLOOP(pliter,pl){
if(pl==U1 || pl==B1){
if(dirprim[pl]==FACE1 || dirprim[pl]==CORN3 || dirprim[pl]==CORN2 || dirprim[pl]==CORNT ){
MACP0A1(prim,i,j,k,pl) = 0.0;
}
}// else don't do this pl
} // end over pl
LOOPBOUND1IN {
PBOUNDLOOP(pliter,pl){
if(pl==U1 || pl==B1){
MACP0A1(prim,i,j,k,pl) *= -1.;
}// end if right pl
} // end over pl
} // end over boundary zones
}// end loop 23
}
} //end if inner CPU wall
}
else{
dualfprintf(fail_file,"Shouldn't be here in bounds\n");
myexit(3946839);
}
} // end parallel region
if(BCtype[X1DN]==R0SING){
bound_x1dn_r0singfixinterior(boundstage,finalstep, boundtime, whichdir, boundvartype, dirprim,ispstag, prim,inboundloop,outboundloop,innormalloop,outnormalloop,inoutlohi,riin,riout,rjin,rjout,rkin,rkout,dosetbc,enerregion,localenerpos);
}
return(0);
}
// X2 inner POLARAXIS
// with full3d, flip sign of both B2 and B3
// Flip B2 because ghost cells will then be same sign if pointing in same physical location, and opposite sign if pointing opposite physical location across the pole.
// Flip B3 because RBhat3\propto \theta (as growing enclosed current from pole) gives Bhat3\propto constant near pole and so Bhat3\propto \theta B3 and so B3\propto \constant 1/\theta.
// So can either interpolation (e.g.) \detg B3 and \detg v3 and obtain higher-order accuracy near pole. Or can flip sign of B3 and v3 and keep more stable but still no diffusive term that otherwise B3 and v3 would have due to their sign change across the pole.
int bound_x2dn_polaraxis_full3d(
int whichcall,
int boundstage, int finalstep, SFTYPE boundtime, int whichdir, int boundvartype, int *dirprim, int ispstag, FTYPE (*prim)[NSTORE2][NSTORE3][NPR],
int *inboundloop,
int *outboundloop,
int *innormalloop,
int *outnormalloop,
int (*inoutlohi)[NUMUPDOWN][NDIM],
int riin, int riout, int rjin, int rjout, int rkin, int rkout,
int *dosetbc,
int enerregion,
int *localenerpos
)
{
#pragma omp parallel // assume don't require EOS
{
int i,j,k,pl,pliter;
int locali1,globali1;
int locali2,globali2;
int ri1,ri2;
FTYPE vcon[NDIM]; // coordinate basis vcon
#if(WHICHVEL==VEL3)
int failreturn;
#endif
int ri, rj, rk; // reference i,j,k
FTYPE prescale[NPR];
int horizonti;
int jj,kk;
if(BCtype[X2DN]==POLARAXIS && special3dspc){
/* inner polar BC (preserves u^t rho and u) */
if ( (totalsize[2]>1) && (mycpupos[2] == 0) ) {
if(whichcall==1 && ncpux3==1){
// if ncpux3>1 then this is handled by MPI
//////// LOOPX2dir{
OPENMPBCLOOPVARSDEFINELOOPX2DIR; OPENMPBCLOOPSETUPLOOPX2DIR;
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
OPENMPBCLOOPBLOCK{
OPENMPBCLOOPBLOCK2IJKLOOPX2DIR(i,k);
ri=i;
rk=(k+(int)N3/2)%N3;
LOOPBOUND2IN{
PBOUNDLOOP(pliter,pl){
// assume polar axis can't move SECTIONMARK
if(dirprim[pl]==FACE2 || dirprim[pl]==CORN3 || dirprim[pl]==CORN1 || dirprim[pl]==CORNT ) rj = -j; // FACE2 values
else rj=-j-1; // "CENT" values for purposes of this BC
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl);
// flip sign
if(pl==U1) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU1;
if(pl==B1) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB1;
if(pl==U2) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU2;
if(pl==B2) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB2;
if(pl==U3) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU3;
if(pl==B3) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB3;
#if(DEBUGINOUTLOOPS)
dualfprintf(fail_file,"INNER pole1: ispstag=%d pl=%d :: ri=%d rj=%d rk=%d i=%d j=%d k=%d\n",ispstag,pl,ri,rj,rk,i,j,k);
if(!isfinite(MACP0A1(prim,ri,rj,rk,pl))){
dualfprintf(fail_file,"INNER pole1: caught copying nan ri=%d rj=%d rk=%d pl=%d\n",ri,rj,rk,pl);
}
#endif
}// end over pl
}// end over j
// also do j=0 (this just makes B2 @ FACE2-type location at j=0 at k and rk the same in correct sense)
j=0;
PBOUNDLOOP(pliter,pl){
if(dirprim[pl]==FACE2 || dirprim[pl]==CORN3 || dirprim[pl]==CORN1 || dirprim[pl]==CORNT ){
// only do j=0 if at pole exactly
rj = -j; // FACE2 values
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl);
if(pl==U1) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU1;
if(pl==B1) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB1;
// flip sign
if(pl==U2) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU2;
if(pl==B2) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB2;
// NOTEMARK: No U3,B3 staggered yet, so below not used
if(pl==U3) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU3;
if(pl==B3) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB3;
#if(DEBUGINOUTLOOPS)
dualfprintf(fail_file,"INNER pole2: ispstag=%d pl=%d :: ri=%d rj=%d rk=%d i=%d j=%d k=%d\n",ispstag,pl,ri,rj,rk,i,j,k);
if(!isfinite(MACP0A1(prim,ri,rj,rk,pl))){
dualfprintf(fail_file,"INNER pole2: caught copying nan ri=%d rj=%d rk=%d pl=%d\n",ri,rj,rk,pl);
}
#endif
}
}
}// end over i,k
}// end if ncpux3==1
// SUPERGODMARK: continue to use for now
// only do poledeath() after MPI call (i.e. whichcall==2)
if(BCtype[X2DN]==POLARAXIS && (whichcall==2 && ncpux3>1 || whichcall==1 && ncpux3==1) ){
if(POLEDEATH || POLEGAMMADEATH) poledeath(X2DN,boundstage,finalstep,boundtime,whichdir,boundvartype,dirprim,ispstag,prim,inboundloop,outboundloop,innormalloop,outnormalloop,inoutlohi,riin,riout,rjin,rjout,rkin,rkout,dosetbc,enerregion,localenerpos);
if(POLESMOOTH) polesmooth(X2DN,boundstage,finalstep,boundtime,whichdir,boundvartype,dirprim,ispstag,prim,inboundloop,outboundloop,innormalloop,outnormalloop,inoutlohi,riin,riout,rjin,rjout,rkin,rkout,dosetbc,enerregion,localenerpos);
}
}//end if inner CPU wall
}
else{
dualfprintf(fail_file,"Shouldn't be here in bounds\n");
myexit(3946840);
}
} // end parallel region
//end if special transmissive BCs at poles
return(0);
}
// X2 inner POLARAXIS
int bound_x2dn_polaraxis(
int boundstage, int finalstep, SFTYPE boundtime, int whichdir, int boundvartype, int *dirprim, int ispstag, FTYPE (*prim)[NSTORE2][NSTORE3][NPR],
int *inboundloop,
int *outboundloop,
int *innormalloop,
int *outnormalloop,
int (*inoutlohi)[NUMUPDOWN][NDIM],
int riin, int riout, int rjin, int rjout, int rkin, int rkout,
int *dosetbc,
int enerregion,
int *localenerpos
)
{
#pragma omp parallel // assume don't require EOS
{
int i,j,k,pl,pliter;
int locali1,globali1;
int locali2,globali2;
int ri1,ri2;
FTYPE vcon[NDIM]; // coordinate basis vcon
#if(WHICHVEL==VEL3)
int failreturn;
#endif
int ri, rj, rk; // reference i,j,k
FTYPE prescale[NPR];
int horizonti;
int jj,kk;
if((BCtype[X2DN]==POLARAXIS)||(BCtype[X2DN]==SYMM)||(BCtype[X2DN]==ASYMM) ){
if ( (totalsize[2]>1) && (mycpupos[2] == 0) ){
///// LOOPX2dir{
{// block region
OPENMPBCLOOPVARSDEFINELOOPX2DIR; OPENMPBCLOOPSETUPLOOPX2DIR;
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
OPENMPBCLOOPBLOCK{
OPENMPBCLOOPBLOCK2IJKLOOPX2DIR(i,k);
ri=i;
rk=k;
LOOPBOUND2IN{
PBOUNDLOOP(pliter,pl){
// assume polar axis can't move SECTIONMARK
if(dirprim[pl]==FACE2 || dirprim[pl]==CORN3 || dirprim[pl]==CORN1 || dirprim[pl]==CORNT ) rj = -j; // FACE2 values
else rj=-j-1; // "CENT" values for purposes of this BC
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl);
}
}
}
}// end blocked region
if((BCtype[X2DN]==POLARAXIS)||(BCtype[X2DN]==ASYMM) ){
/* make sure b and u are antisymmetric at the poles (preserves u^t rho and u) */
//// LOOPX2dir{
OPENMPBCLOOPVARSDEFINELOOPX2DIR; OPENMPBCLOOPSETUPLOOPX2DIR;
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
OPENMPBCLOOPBLOCK{
OPENMPBCLOOPBLOCK2IJKLOOPX2DIR(i,k);
// assume polar axis can't move SECTIONMARK
j=0;
PBOUNDLOOP(pliter,pl){
if(pl==U2 || pl==B2){
if(dirprim[pl]==FACE2 || dirprim[pl]==CORN3 || dirprim[pl]==CORN1 || dirprim[pl]==CORNT ){
MACP0A1(prim,i,j,k,pl) = 0.0;
}
}// else don't do this pl
} // end over pl
LOOPBOUND2IN {
PBOUNDLOOP(pliter,pl){
if(pl==U1) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU1;
if(pl==B1) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB1;
if(pl==U2) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU2;
if(pl==B2) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB2;
if(pl==U3) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU3;
if(pl==B3) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB3;
} // end over pl
} // end over boundary cells
}// end loop 13
}// end if polar or asym condition
if(BCtype[X2DN]==POLARAXIS){
if(POLEDEATH || POLEGAMMADEATH) poledeath(X2DN,boundstage,finalstep,boundtime,whichdir,boundvartype,dirprim,ispstag,prim,inboundloop,outboundloop,innormalloop,outnormalloop,inoutlohi,riin,riout,rjin,rjout,rkin,rkout,dosetbc,enerregion,localenerpos);
if(POLESMOOTH) polesmooth(X2DN,boundstage,finalstep,boundtime,whichdir,boundvartype,dirprim,ispstag,prim,inboundloop,outboundloop,innormalloop,outnormalloop,inoutlohi,riin,riout,rjin,rjout,rkin,rkout,dosetbc,enerregion,localenerpos);
}
}// end if inner CPU wall
}// end if polar asym or asym
else{
dualfprintf(fail_file,"Shouldn't be here in bounds\n");
myexit(3946841);
}
}// end parallel region
return(0);
}
// X2 outer POLARAXIS full3d
int bound_x2up_polaraxis_full3d(
int whichcall,
int boundstage, int finalstep, SFTYPE boundtime, int whichdir, int boundvartype, int *dirprim, int ispstag, FTYPE (*prim)[NSTORE2][NSTORE3][NPR],
int *inboundloop,
int *outboundloop,
int *innormalloop,
int *outnormalloop,
int (*inoutlohi)[NUMUPDOWN][NDIM],
int riin, int riout, int rjin, int rjout, int rkin, int rkout,
int *dosetbc,
int enerregion,
int *localenerpos
)
{
#pragma omp parallel // assume don't require EOSs
{
int i,j,k,pl,pliter;
int locali1,globali1;
int locali2,globali2;
int ri1,ri2;
FTYPE vcon[NDIM]; // coordinate basis vcon
#if(WHICHVEL==VEL3)
int failreturn;
#endif
int ri, rj, rk; // reference i,j,k
FTYPE prescale[NPR];
int horizonti;
int jj,kk;
if(BCtype[X2UP]==POLARAXIS && special3dspc){
if ( (totalsize[2]>1) && (mycpupos[2] == ncpux2-1) ) {
if(whichcall==1 && ncpux3==1){
// if ncpux3>1 then this is handled by MPI
////// LOOPX2dir{
OPENMPBCLOOPVARSDEFINELOOPX2DIR; OPENMPBCLOOPSETUPLOOPX2DIR;
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
OPENMPBCLOOPBLOCK{
OPENMPBCLOOPBLOCK2IJKLOOPX2DIR(i,k);
ri=i;
rk=(k+(int)N3/2)%N3;
LOOPBOUND2OUT{
PBOUNDLOOP(pliter,pl){
// assume polar axis can't move SECTIONMARK
if(dirprim[pl]==FACE2 || dirprim[pl]==CORN3 || dirprim[pl]==CORN1 || dirprim[pl]==CORNT ) rj = 2*N2-j; // FACE2 values
else rj=2*(N2-1)-j+1; // "CENT" values for purposes of this BC
MACP0A1(prim,i,j,k,pl) = MACP0A1(prim,ri,rj,rk,pl);
// flip sign
if(pl==U1) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU1;
if(pl==B1) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB1;
if(pl==U2) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU2;
if(pl==B2) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB2;
if(pl==U3) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPU3;
if(pl==B3) MACP0A1(prim,i,j,k,pl) *= SIGNFLIPB3;
#if(DEBUGINOUTLOOPS)
dualfprintf(fail_file,"OUTER pole1: ispstag=%d pl=%d :: ri=%d rj=%d rk=%d i=%d j=%d k=%d\n",ispstag,pl,ri,rj,rk,i,j,k);
if(!isfinite(MACP0A1(prim,ri,rj,rk,pl))){
dualfprintf(fail_file,"OUTER pole1: caught copying nan ri=%d rj=%d rk=%d pl=%d\n",ri,rj,rk,pl);
}
#endif
}// end over pl
}// end over j
// also do j=N2 (this just makes B2 @ FACE2-type location at j=N2 at k and rk the same in correct sense)
j=N2;
PBOUNDLOOP(pliter,pl){
if(dirprim[pl]==FACE2 || dirprim[pl]==CORN3 || dirprim[pl]==CORN1 || dirprim[pl]==CORNT ){
// only do j=0 if at pole exactly