-
Notifications
You must be signed in to change notification settings - Fork 7
/
fluxct.c
1315 lines (919 loc) · 48 KB
/
fluxct.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"
////////////////////////////////
//
// Notes on sign conventions:
//
///////////////////////////////
// flux part is just average of same emf term at 4 different edge locations of (B^2 v^1 - B^1 v^2)
// COMPEMFZLOOP{
//COMPCOMPLOOPINFP1{ // constrain or control better? GODMARK
// B^i = \dF^{it}
// E_i = - [ijk] v^j B^k , such that (\detg B^i),t = - (\detg(B^i v^j - B^j v^i)),j = - (\detg [ijk] E_k),j = ([ijk] emf[k]),j
// -> E_1 = v^3 B^2 - v^2 B^3
// -> E_2 = v^1 B^3 - v^3 B^1
// -> E_3 = v^2 B^1 - v^1 B^2
// emf[i] = - \detg E_i
// And notice that Fj[Bi] = \dF^{ij} = B^i v^j - B^j v^i , where j=dir
// so:
// emf_1 = B^3 v^2 - B^2 v^3 = F2[B3] or -F3[B2]
// emf_2 = B^1 v^3 - B^3 v^1 = F3[B1] or -F1[B3]
// emf_3 = B^2 v^1 - B^1 v^2 = F1[B2] or -F2[B1]
// Notice only 6 independent ways. The diagonal terms vanish (e.g. Fi[Bi]=0).
// compute field at CENT from vector potential A at CORN1,2,3
// assumes normal field p
int vpot2field_centeredfield(FTYPE (*A)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3],FTYPE (*pfield)[NSTORE2][NSTORE3][NPR],FTYPE (*ufield)[NSTORE2][NSTORE3][NPR])
{
int Nvec[NDIM];
Nvec[0]=0;
Nvec[1]=N1;
Nvec[2]=N2;
Nvec[3]=N3;
/* flux-ct */
// A[1] located at CORN1
// A[2] located at CORN2
// A[3] located at CORN3
// F_{\mu\nu} \equiv A_{\nu,\mu} - A_{\mu,\nu}
// B^i \equiv \dF^{it}
// F_{ij} = \detg B^k [ijk]
// F_{\theta\phi} = \detg B^r
// F_{\phi r} = \detg B^\theta
// F_{r\theta} = \detg B^\phi
// \detg B^x = A_{z,y} - A_{y,z}
// \detg B^y = A_{x,z} - A_{z,x}
// \detg B^z = A_{y,x} - A_{x,y}
// loop optimized for filling cells rather than for speed
// can do full loop since A[1,2,3] are defined even on their plus parts (redundant but simpler than messing with B's post-hoc by linear extrapolation or something)
// puts burden on computing A[1,2,3] (such as having radius or anything at plus part)
// this burden is easier since coord() and bl_coord() have no limits on the i,j,k they are given.
// so in principle one can give an analytic expression
// however, depends on metric and such things if converting expression from one basis to another.
// however, this way is more correct than post-hoc extrapolation.
// only an issue for fixed boundary conditions, where one could just specify the flux directly.
// ufield explicitly needed for FV method
// since nowait'ed above (because each loop sets ufield,pfield for each dir that don't depend upon eachother), need barrier here at end to stop before continuing (implied in parallel reigon)
#pragma omp parallel
{
int i,j,k;
struct of_geom geomdontuse;
struct of_geom *ptrgeom=&geomdontuse;
FTYPE igdetgnosing;
int dir;
int odir1,odir2;
OPENMP3DLOOPVARSDEFINE; OPENMP3DLOOPSETUPFULL; // doesn't depend upon dir, but blockijk must be private, so put in parallel loop
// generally ptr's are different inside parallel block
ptrgeom=&geomdontuse;
/////////////////
//
// B^1
//
/////////////////
dir=1;
get_odirs(dir,&odir1,&odir2);
if(!(Nvec[odir1]==1 && Nvec[odir2]==1)){
//// COMPFULLLOOP{ // COMPFULLLOOP allows since A_i exists at COMPFULLLOOPP1 and so always accessing valid A_i
#pragma omp for schedule(OPENMPFULLNOVARYSCHEDULE()) nowait // nowait valid because each next loop writes to independent memory regions (or to local temporary variables like igdetgnosing that is overwritten for each iteration and so doesn't matter). And also don't require result of one loop for next loop (this is often not true!)
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
// ufield doesn't require geometry
MACP0A1(ufield,i,j,k,B1) = +(AVGCORN_1(A[3],i,jp1mac(j),k)-AVGCORN_1(A[3],i,j,k))/(dx[2]);
MACP0A1(ufield,i,j,k,B1) += -(AVGCORN_1(A[2],i,j,kp1mac(k))-AVGCORN_1(A[2],i,j,k))/(dx[3]);
get_geometry(i, j, k, CENT, ptrgeom);
igdetgnosing = sign(ptrgeom->gdet)/(fabs(ptrgeom->gdet)+SMALL); // avoids 0.0 for any sign of ptrgeom->gdet
MACP0A1(pfield,i,j,k,B1-1+dir) = MACP0A1(ufield,i,j,k,B1-1+dir)*igdetgnosing;
}
}// end if doing this dir
/////////////////
//
// B^2
//
/////////////////
dir=2;
get_odirs(dir,&odir1,&odir2);
if(!(Nvec[odir1]==1 && Nvec[odir2]==1)){
//// COMPFULLLOOP{
#pragma omp for schedule(OPENMPFULLNOVARYSCHEDULE()) nowait
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
MACP0A1(ufield,i,j,k,B2) = +(AVGCORN_2(A[1],i,j,kp1mac(k))-AVGCORN_2(A[1],i,j,k))/(dx[3]);
MACP0A1(ufield,i,j,k,B2) += -(AVGCORN_2(A[3],ip1mac(i),j,k)-AVGCORN_2(A[3],i,j,k))/(dx[1]);
get_geometry(i, j, k, CENT, ptrgeom);
igdetgnosing = sign(ptrgeom->gdet)/(fabs(ptrgeom->gdet)+SMALL); // avoids 0.0 for any sign of ptrgeom->gdet
MACP0A1(pfield,i,j,k,B1-1+dir) = MACP0A1(ufield,i,j,k,B1-1+dir)*igdetgnosing;
}
} // end if dir
/////////////////
//
// B^3
//
/////////////////
dir=3;
get_odirs(dir,&odir1,&odir2);
if(!(Nvec[odir1]==1 && Nvec[odir2]==1)){
//// COMPFULLLOOP{
#pragma omp for schedule(OPENMPFULLNOVARYSCHEDULE()) nowait
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
MACP0A1(ufield,i,j,k,B3) = +(AVGCORN_3(A[2],ip1mac(i),j,k)-AVGCORN_3(A[2],i,j,k))/(dx[1]);
MACP0A1(ufield,i,j,k,B3) += -(AVGCORN_3(A[1],i,jp1mac(j),k)-AVGCORN_3(A[1],i,j,k))/(dx[2]);
get_geometry(i, j, k, CENT, ptrgeom);
igdetgnosing = sign(ptrgeom->gdet)/(fabs(ptrgeom->gdet)+SMALL); // avoids 0.0 for any sign of ptrgeom->gdet
MACP0A1(pfield,i,j,k,B1-1+dir) = MACP0A1(ufield,i,j,k,B1-1+dir)*igdetgnosing;
}
}// end if dir
}// end full parallel region (with implied barrier)
return(0);
}
// compute flux for FLUXCTTOTH method
int flux_ct(int stage,
int initialstep, int finalstep,
FTYPE (*pb)[NSTORE2][NSTORE3][NPR], FTYPE (*emf)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3], FTYPE (*vconemf)[NSTORE2][NSTORE3][NDIM-1], FTYPE (*dq1)[NSTORE2][NSTORE3][NPR], FTYPE (*dq2)[NSTORE2][NSTORE3][NPR], FTYPE (*dq3)[NSTORE2][NSTORE3][NPR], FTYPE (*F1)[NSTORE2][NSTORE3][NPR], FTYPE (*F2)[NSTORE2][NSTORE3][NPR], FTYPE (*F3)[NSTORE2][NSTORE3][NPR],FTYPE (*vpot)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3], int *Nvec, FTYPE *CUf, FTYPE *CUnew, SFTYPE fluxdt, SFTYPE fluxtime)
{
int flux_ct_computeemf(int stage, FTYPE (*pb)[NSTORE2][NSTORE3][NPR], FTYPE (*emf)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3], FTYPE (*vconemf)[NSTORE2][NSTORE3][NDIM-1], FTYPE (*dq1)[NSTORE2][NSTORE3][NPR], FTYPE (*dq2)[NSTORE2][NSTORE3][NPR], FTYPE (*dq3)[NSTORE2][NSTORE3][NPR], FTYPE (*F1)[NSTORE2][NSTORE3][NPR], FTYPE (*F2)[NSTORE2][NSTORE3][NPR], FTYPE (*F3)[NSTORE2][NSTORE3][NPR]);
int flux_ct_diffusivecorrections(int stage, FTYPE (*pb)[NSTORE2][NSTORE3][NPR], FTYPE (*emf)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3], FTYPE (*vconemf)[NSTORE2][NSTORE3][NDIM-1], FTYPE (*dq1)[NSTORE2][NSTORE3][NPR], FTYPE (*dq2)[NSTORE2][NSTORE3][NPR], FTYPE (*dq3)[NSTORE2][NSTORE3][NPR], FTYPE (*F1)[NSTORE2][NSTORE3][NPR], FTYPE (*F2)[NSTORE2][NSTORE3][NPR], FTYPE (*F3)[NSTORE2][NSTORE3][NPR]);
int flux_ct_emf2flux(int stage, FTYPE (*pb)[NSTORE2][NSTORE3][NPR], FTYPE (*emf)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3], FTYPE (*vconemf)[NSTORE2][NSTORE3][NDIM-1], FTYPE (*dq1)[NSTORE2][NSTORE3][NPR], FTYPE (*dq2)[NSTORE2][NSTORE3][NPR], FTYPE (*dq3)[NSTORE2][NSTORE3][NPR], FTYPE (*F1)[NSTORE2][NSTORE3][NPR], FTYPE (*F2)[NSTORE2][NSTORE3][NPR], FTYPE (*F3)[NSTORE2][NSTORE3][NPR]);
MYFUN(flux_ct_computeemf(stage, pb, emf, vconemf, dq1, dq2, dq3, F1, F2, F3),"step_ch.c:advance()", "flux_ct",1);
MYFUN(flux_ct_diffusivecorrections(stage, pb, emf, vconemf, dq1, dq2, dq3, F1, F2, F3),"step_ch.c:advance()", "flux_ct",1);
if(EVOLVEWITHVPOT>0 || TRACKVPOT>0){
// Evolve A_i
// Had to be here where EMFs are at standard CORN1,2,3 positions and before final F assigned
// TOTH CT method doesn't cleanly differentiate between point update and average update of A_i, so just stick to TOTH CT EMF itself
evolve_vpotgeneral(FLUXB, stage, initialstep, finalstep, pb, Nvec, NULL, emf, CUf, CUnew, fluxdt, fluxtime, vpot);
}
int fluxvpot_modifyemfsuser=0;
fluxvpot_modifyemfsuser=(EVOLVEWITHVPOT>0 || TRACKVPOT>0)&&(MODIFYEMFORVPOT==MODIFYEMF || MODIFYEMFORVPOT==MODIFYVPOT);
if(fluxvpot_modifyemfsuser==0){// if didn't already call adjust_emfs() in fluxvpot above, have to allow user to be able to still modify emfs calling function directly
// User "boundary conditions" to modify EMFs before used to get fluxes
adjust_fluxcttoth_emfs(fluxtime,pb,emf);
}
//////////////
//
// must come last for FLUXCTTOTH to produce correct fluxes from point corner EMFs
//
//////////////
MYFUN(flux_ct_emf2flux(stage, pb, emf, vconemf, dq1, dq2, dq3, F1, F2, F3),"step_ch.c:advance()", "flux_ct",1);
return(0);
}
// OPENMPMARK: Apparently the below loops are expensive due to OpenMP overhead. Using static schedule helps overhead a bit
int flux_ct_computeemf(int stage, FTYPE (*pb)[NSTORE2][NSTORE3][NPR], FTYPE (*emf)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3], FTYPE (*vconemf)[NSTORE2][NSTORE3][NDIM-1], FTYPE (*dq1)[NSTORE2][NSTORE3][NPR], FTYPE (*dq2)[NSTORE2][NSTORE3][NPR], FTYPE (*dq3)[NSTORE2][NSTORE3][NPR], FTYPE (*F1)[NSTORE2][NSTORE3][NPR], FTYPE (*F2)[NSTORE2][NSTORE3][NPR], FTYPE (*F3)[NSTORE2][NSTORE3][NPR])
{
// full-type geometry below
FTYPE coefemf[NDIM];
extern int choose_limiter(int dir, int i, int j, int k, int pl);
// Note that Toth method needs off-direction flux beyond where normal-flux needed. For example, for dir=1 setting F1(i) needs F23[i-1],F23[i]. So fluxloop needs to define F2/F3 as if cell centered quantity.
// Also, if modify flux[B1,B2,B3] after set by flux calculation, then that information can propagate from outer boundaries to active region
// When FLUXCTTOTH method used, must not modify fluxes within ghost region (say setting F1[B2]=-F2[B1]) since info will move to active region
// e.g. if put NaN in EMF3 at very outer edge, then reaches active domain by this method
if(FLUXB==FLUXCTHLL){
dualfprintf(fail_file,"Makes no sense to call flux_ct with FLUXB==FLUXCTHLL\n");
myexit(9176325);
}
///////////////////////
//
// COMPUTE PRE-FUNCTIONS used by Athena method
//
///////////////////////
if((FLUXB==ATHENA1)||(FLUXB==ATHENA2)){
// compute v^i
// loop must go over COMPEMFZLOOP's range minus 1 for i and j and k
// COMPPREEMFZLOOP{
// COMPFULLLOOP{ // GODMARK: could try to be more constrained
// use ucon_calc() to get v^i
#pragma omp parallel
{
int i, j, k, l;
struct of_geom geomcfulldontuse;
struct of_geom *ptrgeomcfull=&geomcfulldontuse;
FTYPE ucon[NDIM];
FTYPE others[NUMOTHERSTATERESULTS];
OPENMP3DLOOPVARSDEFINE; OPENMP3DLOOPSETUPFULL;
#pragma omp for schedule(OPENMPFULLNOVARYSCHEDULE())
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
// EMF below is based upon averaging of zone-centered quantities, so use CENT here (i.e. not CORN)
get_geometry(i, j, k, CENT, ptrgeomcfull);
MYFUN(ucon_calc(MAC(pb,i,j,k), ptrgeomcfull, ucon, others),"fluxct.c:flux_ct()", "ucon_calc() dir=0", 1);
// ptrgeom->gdet is \detg for EMF flux (ptrgeom->e is EOM factor for flux equation)
#if(CORNGDETVERSION)
for(l=U1;l<=U3;l++) MACP0A1(vconemf,i,j,k,l)=(ucon[l-U1+1]/ucon[TT]); // put in at end
#else
for(l=U1;l<=U3;l++) MACP0A1(vconemf,i,j,k,l)=(ucon[l-U1+1]/ucon[TT])*(ptrgeomcfull->EOMFUNCMAC(l));
#endif
}// end 3D LOOP
}// end parallel region
}// end if ATHENA1||ATHENA2
#if(CORNGDETVERSION)
if((FLUXB==ATHENA1)||(FLUXB==ATHENA2)||(FLUXB==FLUXCTTOTH)||(FLUXB==FLUXCD)){
/////////////
//
// strip off geometry factor, which is added when computing the EMF
//
////////////
// COMPFULLLOOP{ // GODMARK: could try to be more constrained
#pragma omp parallel
{
int i,j,k;
// gdet-type geometry below
struct of_gdetgeom geomf1dontuse,geomf2dontuse,geomf3dontuse;
struct of_gdetgeom *ptrgeomf1=&geomf1dontuse,*ptrgeomf2=&geomf2dontuse,*ptrgeomf3=&geomf3dontuse;
OPENMP3DLOOPVARSDEFINE; OPENMP3DLOOPSETUPFULL;
#pragma omp for schedule(OPENMPFULLNOVARYSCHEDULE())
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
////////////////////
// F1
////////////////////
#if(N1>1)
get_geometry_gdetmix(i,j,k,FACE1,ptrgeomf1);
MACP0A1(F1,i,j,k,B1)*=(ptrgeomf1->IEOMFUNCNOSINGMAC(B1));
MACP0A1(F1,i,j,k,B2)*=(ptrgeomf1->IEOMFUNCNOSINGMAC(B2));
MACP0A1(F1,i,j,k,B3)*=(ptrgeomf1->IEOMFUNCNOSINGMAC(B3));
#endif
////////////////////
// F2
////////////////////
#if(N2>1)
get_geometry_gdetmix(i,j,k,FACE2,ptrgeomf2);
MACP0A1(F2,i,j,k,B1)*=(ptrgeomf2->IEOMFUNCNOSINGMAC(B1));
MACP0A1(F2,i,j,k,B2)*=(ptrgeomf2->IEOMFUNCNOSINGMAC(B2));
MACP0A1(F2,i,j,k,B3)*=(ptrgeomf2->IEOMFUNCNOSINGMAC(B3));
#endif
////////////////////
// F3
////////////////////
#if(N3>1)
get_geometry_gdetmix(i,j,k,FACE3,ptrgeomf3);
MACP0A1(F3,i,j,k,B1)*=(ptrgeomf3->IEOMFUNCNOSINGMAC(B1));
MACP0A1(F3,i,j,k,B2)*=(ptrgeomf3->IEOMFUNCNOSINGMAC(B2));
MACP0A1(F3,i,j,k,B3)*=(ptrgeomf3->IEOMFUNCNOSINGMAC(B3));
#endif
}// end 3D loop
}// end parallel region
// don't need to put back geometry factor since in the end the EMF defines the Flux completely (except for FLUXB==FLUXCTHLL)
}// end if ATHENA1||ATHENA2||FLUXCTTOTH||FLUXCD
#endif // end if CORNGDETVERSION
// GODMARK: strange one has to do this. Related to FLUXCT not reducing correctly for plane-parallel grid-aligned flows?
if((N2>1)&&(N3>1)) coefemf[1]=0.25;
else coefemf[1]=0.5; // or 0 if neither as controlled by below
if((N1>1)&&(N3>1)) coefemf[2]=0.25;
else coefemf[2]=0.5; // or 0 if neither as controlled by below
if((N1>1)&&(N2>1)) coefemf[3]=0.25;
else coefemf[3]=0.5; // or 0 if neither as controlled by below
/////////////////////////
//
// COMPUTE EMF
//
//////////////////////////
if((FLUXB==FLUXCTTOTH)||(FLUXB==ATHENA1)||(FLUXB==ATHENA2)){
/* calculate EMFs */
/* Toth approach: just average */
// emf_i centered on corner of plane with normal direction i
// Note, do need F1[-N1BND] but don't need F2[-N2BND] or F3[-N3BND] in averaging process, which makes normally need to be complicated.
// Note: As discussed in superdefs.h, superdefs.pointers.h, and set_arrays_multidimen.c, F1,F2,F3,F1EM,F2EM,F3EM pointers are normal arrays, but their BASE arrays have extra memory at *bottom* so can access F[-NBND-1] without segfaulting. Resulting data not used, but makes loops simpler.
#pragma omp parallel // globalprivate stuff needed for final CORNGDET setting if doing that method
{
int i,j,k;
// gdet-type geometry below
struct of_gdetgeom geomf1dontuse,geomf2dontuse,geomf3dontuse;
struct of_gdetgeom *ptrgeomf1=&geomf1dontuse,*ptrgeomf2=&geomf2dontuse,*ptrgeomf3=&geomf3dontuse;
OPENMP3DLOOPVARSDEFINE;
// // COMPLOOPINFP1dir1full
// OPENMP3DLOOPSETUP(-N1BND,N1-1+N1BND,INFULLP12,OUTFULL2,INFULLP13,OUTFULL3);
//// COMPLOOPINFP1dir2full
//// OPENMP3DLOOPSETUP(INFULLP11,OUTFULL1,-N2BND,N2-1+N2BND,INFULLP13,OUTFULL3);
//// COMPLOOPINFP1dir3full
// OPENMP3DLOOPSETUP(INFULLP11,OUTFULL1,INFULLP12,OUTFULL2,-N3BND,N3-1+N3BND);
OPENMP3DLOOPSETUPFULL;
#pragma omp for schedule(OPENMPFULLNOVARYSCHEDULE()) ///nowait // Can use "nowait" because each emf[{1,2,3}] set independently in each successive loop
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
////////////////////
// EMF1
////////////////////
#if((N2>1)||(N3>1))
MACP1A0(emf,1,i,j,k) =
coefemf[1] * (
#if(N2>1)
+ MACP0A1(F2,i,j,k,B3) + MACP0A1(F2,i,j,km1mac(k),B3)
#endif
#if(N3>1)
- MACP0A1(F3,i,j,k,B2) - MACP0A1(F3,i,jm1mac(j),k,B2)
#endif
);
#else // end if doing EMF1
MACP1A0(emf,1,i,j,k)=0.0; // not really 0, but differences in emf will be 0, and that's all that matters
#endif // end if not doing EMF1
#if(CORNGDETVERSION)// then tack on geometry
get_geometry_gdetmix(i,j,k,CORN1,ptrgeomf1);
// obviously ptrgeom->EOMFUNCMAC(B2) has to be equal to ptrgeom->EOMFUNCMAC(B3) for this method
MACP1A0(emf,1,i,j,k) *= (ptrgeomf1->EOMFUNCMAC(B2));
#endif // end if CORNGDETVERSION
////////////////////
// EMF2
////////////////////
#if((N1>1)||(N3>1))
MACP1A0(emf,2,i,j,k) =
coefemf[2] * (
#if(N3>1)
+ MACP0A1(F3,i,j,k,B1) + MACP0A1(F3,im1mac(i),j,k,B1)
#endif
#if(N1>1)
- MACP0A1(F1,i,j,k,B3) - MACP0A1(F1,i,j,km1mac(k),B3)
#endif
);
#else // end if doing EMF2
MACP1A0(emf,2,i,j,k)=0.0; // not really 0, but differences in emf will be 0, and that's all that matters
#endif // end if not doing EMF2
#if(CORNGDETVERSION)// then tack on geometry
get_geometry_gdetmix(i,j,k,CORN2,ptrgeomf2);
// obviously ptrgeom->EOMFUNCMAC(B1) has to be equal to ptrgeom->EOMFUNCMAC(B2) for this method
MACP1A0(emf,2,i,j,k) *=(ptrgeomf2->EOMFUNCMAC(B1));
#endif // end if CORNGDETVERSION
////////////////////
// EMF3
////////////////////
#if((N1>1)||(N2>1))
MACP1A0(emf,3,i,j,k) =
coefemf[3] * (
#if(N1>1)
+ MACP0A1(F1,i,j,k,B2) + MACP0A1(F1,i,jm1mac(j),k,B2)
#endif
#if(N2>1)
- MACP0A1(F2,i,j,k,B1) - MACP0A1(F2,im1mac(i),j,k,B1)
#endif
);
#else // end if doing EMF3
MACP1A0(emf,3,i,j,k)=0.0; // not really 0, but differences in emf will be 0, and that's all that matters
#endif // end if not doing EMF3
#if(CORNGDETVERSION)// then tack on geometry
get_geometry_gdetmix(i,j,k,CORN3,ptrgeomf3);
// obviously ptrgeom->EOMFUNCMAC(B1) has to be equal to ptrgeom->EOMFUNCMAC(B2) for this method
MACP1A0(emf,3,i,j,k) *=(ptrgeomf3->EOMFUNCMAC(B1));
#endif // end if CORNGDETVERSION
}// end 3D LOOP
}// end parallel region (and implied barrier)
}// end if FLUXCT TOTH
else if(FLUXB==FLUXCD){
// Centered Difference (CD)
// here emf is actually electric field
// in Toth 2000, the F1=f^x F2=f^y
// see Toth 2000 equation 28/29
// 0.125 here takes care of larger differencing used in advance() in advance.c
// all emf's end up at CENT
// COMPEMFZLOOP{
// COMPLOOPOUTFM1{ // constrain or control better? GODMARK
// GODMARK: Why did Charles change sign in front of F's (see old code) ? He changed it as if real sign such that emf[i] = \detg E_i but then later flux was wrong sign since he set flux=emf
// GODMARK: should just compute F with diffusive term at CENT directly instead of averaging flux
#pragma omp parallel // globalprivate stuff needed for final CORNGDET setting if doing that method
{
int i,j,k;
struct of_gdetgeom geomcdontuse;
struct of_gdetgeom *ptrgeomc=&geomcdontuse;
OPENMP3DLOOPVARSDEFINE;
//// COMPLOOPOUTFM1dir1full
//OPENMP3DLOOPSETUP(-N1BND,N1-1+N1BND,INFULL2,OUTFULLM12,INFULL3,OUTFULLM13);
//// COMPLOOPOUTFM1dir2full
//// OPENMP3DLOOPSETUP(INFULL1,OUTFULLM11,-N2BND,N2-1+N2BND,INFULL3,OUTFULLM13);
//// COMPLOOPOUTFM1dir3full
////OPENMP3DLOOPSETUP(INFULL1,OUTFULLM11,INFULL2,OUTFULLM12,-N3BND,N3-1+N3BND);
OPENMP3DLOOPSETUPFULL;
#pragma omp for schedule(OPENMPFULLNOVARYSCHEDULE()) /////nowait // Can use "nowait" since each emf[{1,2,3}] set independently in each successive loop
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
////////////////////
// EMF1
////////////////////
#if((N2>1)||(N3>1))
MACP1A0(emf,1,i,j,k) =
0.125 * (
+ MACP0A1(F2,i,j,k,B3) + MACP0A1(F2,i,jp1mac(j),k,B3)
- MACP0A1(F3,i,j,k,B2) - MACP0A1(F3,i,j,kp1mac(k),B2)
);
#if(CORNGDETVERSION)// then tack on geometry
get_geometry_gdetmix(i,j,k,CENT,ptrgeomc);
// obviously ptrgeom->EOMFUNCMAC(B2) has to be equal to ptrgeom->EOMFUNCMAC(B3) for this method
MACP1A0(emf,1,i,j,k) *=(ptrgeomc->EOMFUNCMAC(B2));
#endif // end if CORNGDETVERSION
#endif // end if doing EMF1
////////////////////
// EMF2
////////////////////
#if((N1>1)||(N3>1))
MACP1A0(emf,2,i,j,k) =
0.125 * (
+ MACP0A1(F3,i,j,k,B1) + MACP0A1(F3,i,j,kp1mac(k),B1)
- MACP0A1(F1,i,j,k,B3) - MACP0A1(F1,ip1mac(i),j,k,B3)
);
#if(CORNGDETVERSION)// then tack on geometry
get_geometry_gdetmix(i,j,k,CENT,ptrgeomc);
// obviously ptrgeom->EOMFUNCMAC(B1) has to be equal to ptrgeom->EOMFUNCMAC(B2) for this method
MACP1A0(emf,2,i,j,k) *=(ptrgeomc->EOMFUNCMAC(B1));
#endif // end if CORNGDETVERSION
#endif // end if doing EMF2
////////////////////
// EMF3
////////////////////
#if((N1>1)||(N2>1))
MACP1A0(emf,3,i,j,k) =
0.125 * (
+ MACP0A1(F1,i,j,k,B2) + MACP0A1(F1,ip1mac(i),j,k,B2)
- MACP0A1(F2,i,j,k,B1) - MACP0A1(F2,i,jp1mac(j),k,B1)
);
#if(CORNGDETVERSION)// then tack on geometry
get_geometry_gdetmix(i,j,k,CENT,ptrgeomc);
// obviously ptrgeom->EOMFUNCMAC(B1) has to be equal to ptrgeom->EOMFUNCMAC(B2) for this method
MACP1A0(emf,3,i,j,k) *=(ptrgeomc->EOMFUNCMAC(B1));
#endif // end if CORNGDETVERSION
#endif // end if doing EMF3
}// end 3D LOOP
}// end parallel region (and implied barrier)
}// end if FLUXCD
return(0);
}
// OPENMPMARK: Apparently the below loops are expensive due to OpenMP overhead. Using static schedule helps overhead a bit
int flux_ct_diffusivecorrections(int stage, FTYPE (*pb)[NSTORE2][NSTORE3][NPR], FTYPE (*emf)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3], FTYPE (*vconemf)[NSTORE2][NSTORE3][NDIM-1], FTYPE (*dq1)[NSTORE2][NSTORE3][NPR], FTYPE (*dq2)[NSTORE2][NSTORE3][NPR], FTYPE (*dq3)[NSTORE2][NSTORE3][NPR], FTYPE (*F1)[NSTORE2][NSTORE3][NPR], FTYPE (*F2)[NSTORE2][NSTORE3][NPR], FTYPE (*F3)[NSTORE2][NSTORE3][NPR])
{
// full-type geometry below
FTYPE coefemf[NDIM];
extern int choose_limiter(int dir, int i, int j, int k, int pl);
///////////////////////////////////////////////////////
//
// ADD DIFFUSIVE CORRECTIONS
//
///////////////////////////////////////////////////////
// add diffusive term
// must come after FLUXCT
if((FLUXB==ATHENA1)||(FLUXB==ATHENA2)){
// Stone & Gardiner point out that Toth FLUXCT and FLUXCD not consistent with underlying integration algorithm for plane-parallel, grid-aligned flows.
// fix is to change 0.25 to 0.5 and use a diffusive term as in ATHENA1
/* Stone & Gardiner eq. 39 */
// Charles Gammie (8/17/05) says this is simple, but repairs HARM defect that 2D does not reduce to 1D when waves are along coordinate lines
//// COMPLOOPINFP1 // constrain or control better? GODMARK
// COMPEMFZLOOP{
#pragma omp parallel
{
int i,j,k,l;
// gdet-type geometry below
struct of_gdetgeom geomf1dontuse,geomf2dontuse,geomf3dontuse;
struct of_gdetgeom *ptrgeomf1=&geomf1dontuse,*ptrgeomf2=&geomf2dontuse,*ptrgeomf3=&geomf3dontuse;
FTYPE diffusiveterm[NDIM];
FTYPE emfmm[NDIM],emfpm[NDIM],emfmp[NDIM],emfpp[NDIM],alpha[NDIM] ;
OPENMP3DLOOPVARSDEFINE; OPENMP3DLOOPSETUP(INFULLP11,OUTFULL1,INFULLP12,OUTFULL2,INFULLP13,OUTFULL3);
// generally ptr's are different inside parallel block
ptrgeomf1=&geomf1dontuse;
ptrgeomf2=&geomf2dontuse;
ptrgeomf3=&geomf3dontuse;
#pragma omp for schedule(OPENMPFULLNOVARYSCHEDULE())
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
// {emf}_i=-\epsilon_{ijk} v^i B^k
// average of the below results in averaged emf located at corner (CORN)
// same sign as F's (B^2 v^1 - B^1 v^2) with gdet built into vconemf
// could remove gdet from vconemf and F1/F2 and put gdet at CORN for final result! Avoids axis problems?
// applies to above Toth version as well!
// GODMARK
#if((N2>1)||(N3>1))
// emf_1
emfmp[1] =
MACP0A1(pb,i ,jm1mac(j),k ,B3)*MACP0A1(vconemf,i ,jm1mac(j),k ,U2) -
MACP0A1(pb,i ,jm1mac(j),k ,B2)*MACP0A1(vconemf,i ,jm1mac(j),k ,U3) ;
emfmm[1] =
MACP0A1(pb,i ,jm1mac(j),km1mac(k),B3)*MACP0A1(vconemf,i ,jm1mac(j),km1mac(k),U2) -
MACP0A1(pb,i ,jm1mac(j),km1mac(k),B2)*MACP0A1(vconemf,i ,jm1mac(j),km1mac(k),U3) ;
emfpm[1] =
MACP0A1(pb,i ,j ,km1mac(k),B3)*MACP0A1(vconemf,i ,j ,km1mac(k),U2) -
MACP0A1(pb,i ,j ,km1mac(k),B2)*MACP0A1(vconemf,i ,j ,km1mac(k),U3) ;
emfpp[1] =
MACP0A1(pb,i ,j ,k ,B3)*MACP0A1(vconemf,i ,j ,k ,U2) -
MACP0A1(pb,i ,j ,k ,B2)*MACP0A1(vconemf,i ,j ,k ,U3) ;
#endif
#if((N1>1)||(N3>1))
// emf_2
emfmp[2] =
MACP0A1(pb,im1mac(i),j ,k ,B1)*MACP0A1(vconemf,im1mac(i),j ,k ,U3) -
MACP0A1(pb,im1mac(i),j ,k ,B3)*MACP0A1(vconemf,im1mac(i),j ,k ,U1) ;
emfmm[2] =
MACP0A1(pb,im1mac(i),j ,km1mac(k),B1)*MACP0A1(vconemf,im1mac(i),j ,km1mac(k),U3) -
MACP0A1(pb,im1mac(i),j ,km1mac(k),B3)*MACP0A1(vconemf,im1mac(i),j ,km1mac(k),U1) ;
emfpm[2] =
MACP0A1(pb,i ,j ,km1mac(k),B1)*MACP0A1(vconemf,i ,j ,km1mac(k),U3) -
MACP0A1(pb,i ,j ,km1mac(k),B3)*MACP0A1(vconemf,i ,j ,km1mac(k),U1) ;
emfpp[2] =
MACP0A1(pb,i ,j ,k ,B1)*MACP0A1(vconemf,i ,j ,k ,U3) -
MACP0A1(pb,i ,j ,k ,B3)*MACP0A1(vconemf,i ,j ,k ,U1) ;
#endif
#if((N1>1)||(N2>1))
// emf_3 (same sign as FLUXCT method as emf[3])
emfmp[3] =
MACP0A1(pb,im1mac(i),j ,k ,B2)*MACP0A1(vconemf,im1mac(i),j ,k ,U1) -
MACP0A1(pb,im1mac(i),j ,k ,B1)*MACP0A1(vconemf,im1mac(i),j ,k ,U2) ;
emfmm[3] =
MACP0A1(pb,im1mac(i),jm1mac(j),k ,B2)*MACP0A1(vconemf,im1mac(i),jm1mac(j),k ,U1) -
MACP0A1(pb,im1mac(i),jm1mac(j),k ,B1)*MACP0A1(vconemf,im1mac(i),jm1mac(j),k ,U2) ;
emfpm[3] =
MACP0A1(pb,i ,jm1mac(j),k ,B2)*MACP0A1(vconemf,i ,jm1mac(j),k ,U1) -
MACP0A1(pb,i ,jm1mac(j),k ,B1)*MACP0A1(vconemf,i ,jm1mac(j),k ,U2) ;
emfpp[3] =
MACP0A1(pb,i ,j ,k ,B2)*MACP0A1(vconemf,i ,j ,k ,U1) -
MACP0A1(pb,i ,j ,k ,B1)*MACP0A1(vconemf,i ,j ,k ,U2) ;
#endif
for(l=1;l<=3;l++){
diffusiveterm[l]= 0.25*(emfmp[l] + emfmm[l] + emfpm[l] + emfpp[l]);
}
#if(CORNGDETVERSION)// then tack on geometry
get_geometry_gdetmix(i,j,k,CORN1,ptrgeomf1);
get_geometry_gdetmix(i,j,k,CORN2,ptrgeomf2);
get_geometry_gdetmix(i,j,k,CORN3,ptrgeomf3);
// obviously ptrgeom->EOMFUNCMAC(B2) has to be equal to ptrgeom->EOMFUNCMAC(B3) for this method
diffusiveterm[1] *=(ptrgeomf1->EOMFUNCMAC(B2));
// obviously ptrgeom->EOMFUNCMAC(B1) has to be equal to ptrgeom->EOMFUNCMAC(B2) for this method
diffusiveterm[2] *=(ptrgeomf2->EOMFUNCMAC(B1));
// obviously ptrgeom->EOMFUNCMAC(B1) has to be equal to ptrgeom->EOMFUNCMAC(B2) for this method
diffusiveterm[3] *=(ptrgeomf3->EOMFUNCMAC(B1));
#endif
// now add diffusive term to emf
// notice original emf multiplied by 2 to account for diffusive term being subtracted, so result is consistent
for(l=1;l<=3;l++){
MACP1A0(emf,l,i,j,k) = 2.0*MACP1A0(emf,l,i,j,k) - diffusiveterm[l];
}
}// end COMPEMFZLOOP
}// end parallel region
}// end ATHENA1
// add another diffusive flux correction
// must come after ATHENA1
if(FLUXB==ATHENA2){
if(LIMADJUST>0 || DODQMEMORY==0 || choose_limiter(1, 0,0,0,RHO)>=PARA || choose_limiter(2, 0,0,0,RHO)>=PARA || choose_limiter(3, 0,0,0,RHO)>=PARA){ // note only look at one point and one variable here for test
dualfprintf(fail_file,"Cannot use Athena2 with limadjust since dq's not defined\n");
myexit(11);
}
// GODMARK
// should just use unrescaled p2interp stored, but need one for each direction.
// should also use wave speeds from edges?
/* Stone & Gardiner eq. 48 */
// Charles Gammie (8/17/05) says does much better on flux loop advection test than ordinary HARM
// COMPLOOPINFP1{ // constrain or control better? GODMARK
// COMPEMFZLOOP{
#pragma omp parallel OPENMPGLOBALPRIVATEFORSTATEANDGEOM // requires full copyin()
{
// Below stuff is for Athena 1 and Athena 2
int dir;
int i,j,k,l,pl,pliter;
// gdet-type geometry below
struct of_gdetgeom geomf1dontuse,geomf2dontuse,geomf3dontuse;
struct of_gdetgeom *ptrgeomf1=&geomf1dontuse,*ptrgeomf2=&geomf2dontuse,*ptrgeomf3=&geomf3dontuse;
FTYPE diffusiveterm[NDIM];
FTYPE emfmm[NDIM],emfpm[NDIM],emfmp[NDIM],emfpp[NDIM],alpha[NDIM] ;
// Gammie stuff
FTYPE B1pp,B1pm,B1mp,B1mm;
FTYPE B2pp,B2pm,B2mp,B2mm ;
FTYPE B3pp,B3pm,B3mp,B3mm ;
FTYPE U1pp,U1pm,U1mp,U1mm;
FTYPE U2pp,U2pm,U2mp,U2mm ;
FTYPE U3pp,U3pm,U3mp,U3mm ;
// FTYPE cms_func(FTYPE *prim_var) ;
FTYPE B1d,B1u,B1l,B1r;
FTYPE B2d,B2u,B2l,B2r;
FTYPE B3d,B3u,B3l,B3r;
FTYPE pbavg[NPR];
struct of_state state;
int ignorecourant;
FTYPE cmax1,cmin1,cmax2,cmin2,ctop1,ctop2;
struct of_geom geomco1dontuse,geomco2dontuse,geomco3dontuse;
struct of_geom *ptrgeomco1=&geomco1dontuse,*ptrgeomco2=&geomco2dontuse,*ptrgeomco3=&geomco3dontuse;
OPENMP3DLOOPVARSDEFINE; OPENMP3DLOOPSETUP(INFULLP11,OUTFULL1,INFULLP12,OUTFULL2,INFULLP13,OUTFULL3);
// generally ptr's are different inside parallel block
ptrgeomf1=&geomf1dontuse;
ptrgeomf2=&geomf2dontuse;
ptrgeomf3=&geomf3dontuse;
ptrgeomco1=&geomco1dontuse;
ptrgeomco2=&geomco2dontuse;
ptrgeomco3=&geomco3dontuse;
#pragma omp for schedule(OPENMPFULLNOVARYSCHEDULE())
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
// dq1 and dq2 and dq3 are well-defined from fluxcalc() (both directions)
// simple average of 1-D linear extrapolation here, where could use p2interp data saved from step_ch.c? still available by this function call?
#if((N2>1)||(N3>1))
// for emf_1
// B2 located at FACE2 @ (k-1)
B2d = 0.5*(
MACP0A1(pb,i,jm1mac(j),km1mac(k),B2) + 0.5*MACP0A1(dq2,i,jm1mac(j),km1mac(k),B2) +
MACP0A1(pb,i,j ,km1mac(k),B2) - 0.5*MACP0A1(dq2,i,j ,km1mac(k),B2)
) ;
// B2 located at FACE2 @ (k)
B2u = 0.5*(
MACP0A1(pb,i,jm1mac(j),k,B2) + 0.5*MACP0A1(dq2,i,jm1mac(j),k,B2) +
MACP0A1(pb,i,j ,k,B2) - 0.5*MACP0A1(dq2,i,j ,k,B2)
) ;
// B3 located at FACE3 @ (j-1)
B3l = 0.5*(
MACP0A1(pb,i,jm1mac(j),km1mac(k),B3) + 0.5*MACP0A1(dq3,i,jm1mac(j),km1mac(k),B3) +
MACP0A1(pb,i,jm1mac(j),k ,B3) - 0.5*MACP0A1(dq3,i,jm1mac(j),k ,B3)
) ;
// B3 located at FACE3 @ j
B3r = 0.5*(
MACP0A1(pb,i,j,km1mac(k),B3) + 0.5*MACP0A1(dq3,i,j,km1mac(k),B3) +
MACP0A1(pb,i,j,k ,B3) - 0.5*MACP0A1(dq3,i,j,k ,B3)
) ;
// B2 for all centers around CORN1
// B2[j - mp][k - mp]
B2mm = MACP0A1(pb,i,jm1mac(j),km1mac(k),B2) ;
B2mp = MACP0A1(pb,i,jm1mac(j),k ,B2) ;
B2pm = MACP0A1(pb,i,j ,km1mac(k),B2) ;
B2pp = MACP0A1(pb,i,j ,k ,B2) ;
// B3 for all centers around CORN1
// B3[j - mp][k - mp]
B3mm = MACP0A1(pb,i,jm1mac(j),km1mac(k),B3) ;
B3mp = MACP0A1(pb,i,jm1mac(j),k ,B3) ;
B3pm = MACP0A1(pb,i,j ,km1mac(k),B3) ;
B3pp = MACP0A1(pb,i,j ,k ,B3) ;
// compute characteristic velocity -- only for Athena2 method
// average pb to CORN1 for average phase speed there
PLOOP(pliter,pl) pbavg[pl]=0.25*(MACP0A1(pb,i,j,k,pl)+MACP0A1(pb,i,jm1mac(j),k,pl)+MACP0A1(pb,i,j,km1mac(k),pl)+MACP0A1(pb,i,jm1mac(j),km1mac(k),pl));
get_geometry(i, j, k, CORN1, ptrgeomco1); // used here and below emf's
MYFUN(get_state(pbavg, ptrgeomco1, &state),"step_ch.c:flux_ct()", "get_state()", 1);
dir=2; MYFUN(vchar(pbavg, &state, dir, ptrgeomco1, &cmax1, &cmin1,&ignorecourant),"step_ch.c:flux_ct()", "vchar() dir=1", 1);
dir=3; MYFUN(vchar(pbavg, &state, dir, ptrgeomco1, &cmax2, &cmin2,&ignorecourant),"step_ch.c:flux_ct()", "vchar() dir=2", 2);
ctop1 = max(fabs(cmax1), fabs(cmin1));
ctop2 = max(fabs(cmax2), fabs(cmin2));
// alpha=0.5*(ctop1+ctop2); // use average?
// alpha=max(ctop1,ctop2); // use maximum?
// seems alpha can be arbitrary since 0 is ATHENA1
// alpha = dx1/dt ; /* crude approx */
// GODMARK: seems to have left/right and up/down asymmetry due to subtraction
// if fabs were around each sutracted term, then would be ok (e.g. fabs(B1d-B1u))
// notice that ctop1 and ctop2 have different "units", so cannot use with B2/B3 arbitrarily, must be consistent.
diffusiveterm[1] = 0.125*(
+ctop1*(
+ B2d - B2mm - B2u + B2mp
+ B2d - B2pm - B2u + B2pp
)
+ctop2*(
+ B3r - B3pm - B3l + B3mm
+ B3r - B3pp - B3l + B3mp
)
) ;
#endif
#if((N1>1)||(N3>1))
// for emf_2
// B3 located at FACE3 @ (i-1)
B3d = 0.5*(
MACP0A1(pb,im1mac(i),j,km1mac(k),B3) + 0.5*MACP0A1(dq3,im1mac(i),j,km1mac(k),B3) +
MACP0A1(pb,im1mac(i),j,k ,B3) - 0.5*MACP0A1(dq3,im1mac(i),j,k ,B3)
) ;
// B3 located at FACE3 @ (i)
B3u = 0.5*(
MACP0A1(pb,i,j,km1mac(k),B3) + 0.5*MACP0A1(dq3,i,j,km1mac(k),B3) +
MACP0A1(pb,i,j,k ,B3) - 0.5*MACP0A1(dq3,i,j,k ,B3)
) ;
// B3 located at FACE1 @ (k-1)
B1l = 0.5*(
MACP0A1(pb,im1mac(i),j,km1mac(k),B1) + 0.5*MACP0A1(dq1,im1mac(i),j,km1mac(k),B1) +
MACP0A1(pb,i ,j,km1mac(k),B1) - 0.5*MACP0A1(dq1,i ,j,km1mac(k),B1)
) ;
// B1 located at FACE1 @ k
B1r = 0.5*(
MACP0A1(pb,im1mac(i),j,k,B1) + 0.5*MACP0A1(dq1,im1mac(i),j,k,B1) +
MACP0A1(pb,i ,j,k,B1) - 0.5*MACP0A1(dq1,i ,j,k,B1)
) ;
// B3 for all centers around CORN1
// B3[k - mp][i - mp]
B3mm = MACP0A1(pb,im1mac(i),j,km1mac(k),B3) ;
B3mp = MACP0A1(pb,i ,j,km1mac(k),B3) ;
B3pm = MACP0A1(pb,im1mac(i),j,k ,B3) ;
B3pp = MACP0A1(pb,i ,j,k ,B3) ;
// B1 for all centers around CORN1
// B1[k - mp][i - mp]
B1mm = MACP0A1(pb,im1mac(i),j,km1mac(k),B1) ;
B1mp = MACP0A1(pb,i ,j,km1mac(k),B1) ;
B1pm = MACP0A1(pb,im1mac(i),j,k ,B1) ;
B1pp = MACP0A1(pb,i ,j,k ,B1) ;
// compute characteristic velocity -- only for Athena2 method
// average pb to CORN1 for average phase speed there
PLOOP(pliter,pl) pbavg[pl]=0.25*(MACP0A1(pb,i,j,k,pl)+MACP0A1(pb,im1mac(i),j,k,pl)+MACP0A1(pb,i,j,km1mac(k),pl)+MACP0A1(pb,im1mac(i),j,km1mac(k),pl));
get_geometry(i, j, k, CORN2, ptrgeomco2); // used here and below emf's
MYFUN(get_state(pbavg, ptrgeomco2, &state),"step_ch.c:flux_ct()", "get_state()", 1);
dir=3; MYFUN(vchar(pbavg, &state, dir, ptrgeomco2, &cmax1, &cmin1,&ignorecourant),"step_ch.c:flux_ct()", "vchar() dir=1", 1);
dir=1; MYFUN(vchar(pbavg, &state, dir, ptrgeomco2, &cmax2, &cmin2,&ignorecourant),"step_ch.c:flux_ct()", "vchar() dir=2", 2);
ctop1 = max(fabs(cmax1), fabs(cmin1));
ctop2 = max(fabs(cmax2), fabs(cmin2));