-
Notifications
You must be signed in to change notification settings - Fork 7
/
fluxctstag.c
2444 lines (1787 loc) · 105 KB
/
fluxctstag.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
//////////////////
// all things related to FLUXB==FLUXCTSTAG
// Except fluxcalc_standard_4fluxctstag() (and its interpolate_prim_cent2face()) that could be generally used to replace standard method
// and except more general functions with simple FLUXB==FLUXCTSTAG conditions like getplpr()
// and except functions that call these things, of course
#include "decs.h"
///////////////////////////////////////////////////////
//
// OUTLINE of entire staggered field procedure:
//
//
// 1) init.c has user set A_i at CORN_i (and user can control whether A_i set or B^i set via fieldfrompotential[])
// 2) initbase.c computes B^i @ FACE_i and unew=\detg B^i at FACE_i using vpot2field() and B^i and \detg B^i at CENT through interpolation:
// a) Creates higher-order A_i or flux using:
// i) vectorpot_useflux() when using flux
// ii) vectorpot_fluxreconorfvavg() for FV and FLUXRECON methods otherwise
// b) Obtains point field and conserved field using:
// i) vpot2field_staggeredfield() if higher-order method involves higher-order field evolution
// ii) vpot2field_useflux() if higher-order method involves evolving point fields
// c) Obtains de-averaged point conserved staggered conserved field using deaverage_ustag2pstag()
// d) Interpolates staggered FACE1,2,3 field to CENT using interpolate_pfield_face2cent()
// 3) advance.c: Uses Ui=unew, and flux-updates unew and uf, which are used to obtain B^i and \detg B^i at cent:
// a) Computes \detg B^i [ui] at FACE1,2,3 for ui at FACE1,2,3 for field in advance_standard() (Ui at CENT from pi for non-field)
// b) Computes pstag at FACE1,2,3 from updated unew/uf at FACE1,2,3 using deaverage_ustag2pstag() in advance_standard()
// c) Computes \detg B^i [upoint] at CENT from pstag at FACE1,2,3 using interpolate_pfield_face2cent() in advance_standard()
//
// So updating conserved \detg B^i at FACE1,2,3 and keeping pstag consistent with this using de-averaging function
// Inversion is peformed on interpolated B^i at CENT obtained from face pstag
// NOTES:
// 1) Presently bound pstag because corner regions need EMF and interpolate face to edge so need boundary face values
// For example, for EMF3 we need B1 along dir=2 and B2 along dir=1 so can reconstruct field to corner. This requires (a limited) bounding of pstag. I don't see a way around this without using CENT to get everything and then violating locality of pstag with the EMFs.
// In non-staggered scheme those face values could come from centered values. Would be inconsistent to do that for stag method, so need to find another way if want to only bound CENT primitives.
//
// 2) Note that boundary conditions are applied to staggered field in logical way similar to CENT field (with one exception).
// For MPI this is correct. For periodic this is correct. For reflecting BC this is correct as long as boundary conditions supplied and (for polar axis) \gdetg=0.0 exactly. For analytical setting of BCs this is correct. For outflow this is *sufficient* since don't really need to evolve that last cell
// This makes code simpler with this assumption so don't have to extra-evolve the last upper face field value
// For FLUXRECON, this means bound_flux() must set upper flux so staggered field is set by boundary conditions
// For IF3DSPCTHENMPITRANSFERATPOLE, this is no longer true. In this case must evolve that outer cell to evolve B2 at outer pole for any-all i,k,myid.
// 3) Note that for some problems the staggered method reaches nearly 0 field so that the normalized divb is erroneously large due to hitting machine errors relative to the dominate field strength evolved. Maybe should output unnormalized divb too
// TOTH doesn't have this problem because diffusion is high enough to keep field value large. In 0-field regions TOTH generates checkerboard pattern with much higher field values and so divb appears to stay small.
// 4) If A_\phi\propto r^{-p} \theta^0 near the pole, then B2\propto 1/\theta near the pole. But that would imply infinite energy density because B2hat \propto 1/\theta as well.
static void rescale_calc_stagfield_full(int *Nvec, FTYPE (*pstag)[NSTORE2][NSTORE3][NPR2INTERP],FTYPE (*p2interp)[NSTORE2][NSTORE3][NPR2INTERP]);
// This vpot2field function is for staggered method to evolve quasi-deaveraged fields (i.e. not point fields) when doing higher order
// compute field at FACE1,2,3 from vector potential A at CORN1,2,3
// assumes normal field p
// assume if 1D then along the 1D direction the field doesn't change and input pfield and ufield are already correct and set
int vpot2field_staggeredfield(FTYPE (*A)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3],FTYPE (*pfield)[NSTORE2][NSTORE3][NPR],FTYPE (*ufield)[NSTORE2][NSTORE3][NPR])
{
int Nvec[NDIM];
#if(FIELDSTAGMEM==0)
dualfprintf(fail_file,"Set FIELDSTAGMEM==1 to do FLUXCTSTAG\n");
myexit(7158915);
#endif
/* flux-staggered */
// note A_i is always at CORN1,2,3 (edges) for any method, so init.c remains the same
// all comments same as for centered field -- only change is no averaging of A_i to faces from edges (CORN1,2,3)
Nvec[0]=0;
Nvec[1]=N1;
Nvec[2]=N2;
Nvec[3]=N3;
////////////////////////
//
// now with double-quasi-deaveraged A_i compute B^i
//
// use Nvec in case 1-D then if Nvec[odir1]==1 && Nvec[odir2]==1 then don't assign dir field since constant in time and not zero as would be determined here
// pfield should be from de-(laterally)-averaged ufield at FACE1,2,3
//
////////////////////////
// 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;
int dir;
FTYPE igdetgnosing[NDIM];
int odir1,odir2;
int jj;
struct of_gdetgeom geomfdontuse[NDIM];
struct of_gdetgeom *ptrgeomf[NDIM];
OPENMP3DLOOPVARSDEFINE; OPENMP3DLOOPSETUPFULL; // doesn't depend upon dir, but blockijk must be private
// generally ptr's are different inside parallel block
DLOOPA(jj) ptrgeomf[jj]=&(geomfdontuse[jj]);
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(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize)) nowait
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
// ufield doesn't require geometry
MACP0A1(ufield,i,j,k,B1) = +(NOAVGCORN_1(A[3],i,jp1mac(j),k)-NOAVGCORN_1(A[3],i,j,k))/(dx[2]);
MACP0A1(ufield,i,j,k,B1) += -(NOAVGCORN_1(A[2],i,j,kp1mac(k))-NOAVGCORN_1(A[2],i,j,k))/(dx[3]);
get_geometry_gdetonly(i, j, k, FACE1-1+dir, ptrgeomf[dir]);
set_igdetsimple(ptrgeomf[dir]);
igdetgnosing[dir] = ptrgeomf[dir]->igdetnosing;
MACP0A1(pfield,i,j,k,B1-1+dir) = MACP0A1(ufield,i,j,k,B1-1+dir)*igdetgnosing[dir];
}/// end 3D LOOP
}// end if
dir=2;
get_odirs(dir,&odir1,&odir2);
if(!(Nvec[odir1]==1 && Nvec[odir2]==1)){
///////COMPFULLLOOP{
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize)) nowait
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
MACP0A1(ufield,i,j,k,B2) = +(NOAVGCORN_2(A[1],i,j,kp1mac(k))-NOAVGCORN_2(A[1],i,j,k))/(dx[3]);
MACP0A1(ufield,i,j,k,B2) += -(NOAVGCORN_2(A[3],ip1mac(i),j,k)-NOAVGCORN_2(A[3],i,j,k))/(dx[1]);
get_geometry_gdetonly(i, j, k, FACE1-1+dir, ptrgeomf[dir]);
set_igdetsimple(ptrgeomf[dir]);
igdetgnosing[dir] = ptrgeomf[dir]->igdetnosing;
MACP0A1(pfield,i,j,k,B1-1+dir) = MACP0A1(ufield,i,j,k,B1-1+dir)*igdetgnosing[dir];
}
}
dir=3;
get_odirs(dir,&odir1,&odir2);
if(!(Nvec[odir1]==1 && Nvec[odir2]==1)){
////////// COMPFULLLOOP{
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize)) nowait
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
MACP0A1(ufield,i,j,k,B3) = +(NOAVGCORN_3(A[2],ip1mac(i),j,k)-NOAVGCORN_3(A[2],i,j,k))/(dx[1]);
MACP0A1(ufield,i,j,k,B3) += -(NOAVGCORN_3(A[1],i,jp1mac(j),k)-NOAVGCORN_3(A[1],i,j,k))/(dx[2]);
get_geometry_gdetonly(i, j, k, FACE1-1+dir, ptrgeomf[dir]);
set_igdetsimple(ptrgeomf[dir]);
igdetgnosing[dir] = ptrgeomf[dir]->igdetnosing;
MACP0A1(pfield,i,j,k,B1-1+dir) = MACP0A1(ufield,i,j,k,B1-1+dir)*igdetgnosing[dir];
}
}
}// end full parallel region (with implied barrier)
#if(0)
bound_prim(STAGEM1,t,ufield, 0);
bound_prim(STAGEM1,t,pfield, 0);
#endif
return(0);
}
// wrapper for:
// 1) interpolate FACE 2 CORN
// 2) loop over dimensions setting field flux dimension-by-dimension using multi-D interpolated CORN quantities
// At present, original flux as emf is computed like normal flux even if overwritten here, and shouldn't be much more expensive doing that there since primary cost is interpolation whose results are required and used here
int fluxcalc_fluxctstag(int stage,
int initialstep, int finalstep,
FTYPE (*pr)[NSTORE2][NSTORE3][NPR], FTYPE (*pstag)[NSTORE2][NSTORE3][NPR], FTYPE (*pl_ct)[NSTORE1][NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*pr_ct)[NSTORE1][NSTORE2][NSTORE3][NPR2INTERP],
// FTYPE (*pbcorn)[COMPDIM][NUMCS][NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3],
FTYPE (*pvbcorn)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3][COMPDIM][NUMCS+1][NUMCS],
FTYPE (*wspeed)[NUMCS][NSTORE1][NSTORE2][NSTORE3],
FTYPE (*prc)[NSTORE2][NSTORE3][NPR2INTERP],
FTYPE (*pleft)[NSTORE2][NSTORE3][NPR2INTERP],
FTYPE (*pright)[NSTORE2][NSTORE3][NPR2INTERP],
struct of_state (*fluxstatecent)[NSTORE2][NSTORE3],
struct of_state (*fluxstate)[NSTORE1][NSTORE2][NSTORE3][NUMLEFTRIGHT],
FTYPE (*geomcorn)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3],
int *Nvec, FTYPE (*dqvec[NDIM])[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*fluxvec[NDIM])[NSTORE2][NSTORE3][NPR],
FTYPE (*vpot)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3],
FTYPE *CUf, FTYPE *CUnew, SFTYPE fluxdt, SFTYPE fluxtime, struct of_loop *cent2faceloop, struct of_loop (*face2cornloop)[NDIM][NDIM]
)
{
int interpolate_prim_face2corn(FTYPE (*pr)[NSTORE2][NSTORE3][NPR], FTYPE (*primface_l)[NSTORE1][NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*primface_r)[NSTORE1][NSTORE2][NSTORE3][NPR2INTERP],
// FTYPE (*pbcorn)[COMPDIM][NUMCS][NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3],
FTYPE (*pvbcorn)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3][COMPDIM][NUMCS+1][NUMCS],
struct of_loop *cent2faceloop, struct of_loop (*face2cornloop)[NDIM][NDIM],
FTYPE (*prc)[NSTORE2][NSTORE3][NPR2INTERP],
FTYPE (*pleft)[NSTORE2][NSTORE3][NPR2INTERP],
FTYPE (*pright)[NSTORE2][NSTORE3][NPR2INTERP],
int *Nvec, FTYPE (*dqvec[NDIM])[NSTORE2][NSTORE3][NPR2INTERP]);
int dir;
int idel, jdel, kdel, face;
int is, ie, js, je, ks, ke;
int fluxcalc_fluxctstag_emf_1d(int stage, FTYPE (*pr)[NSTORE2][NSTORE3][NPR], int dir, int odir1, int odir2, int is, int ie, int js, int je, int ks, int ke, FTYPE (*fluxvec[NDIM])[NSTORE2][NSTORE3][NPR], FTYPE CUf, struct of_loop (*face2cornloop)[NDIM],
// FTYPE (*pbcorn)[COMPDIM][NUMCS][NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3],
FTYPE (*pvbcorn)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3][COMPDIM][NUMCS+1][NUMCS],
FTYPE (*wspeed)[NUMCS][NSTORE1][NSTORE2][NSTORE3]);
int edgedir, odir1,odir2;
// static int firsttime=1;
int i,j,k;
int enerregion;
int *localenerpos;
// forCOMPZSLOOP:
// avoid looping over region outside active+ghost grid
// good because somewhat general and avoid bad inversions, etc.
enerregion=TRUEGLOBALWITHBNDENERREGION;
localenerpos=enerposreg[enerregion];
//////////////////////////
//
// first obtain pbinterp and pvinterp (point CORN1,2,3 quantities) from pl_ct and pr_ct (FACE1,2,3 quantities)
// This can't be done per dimension since flux needs multi-D quantities for 2D Riemann problem...hence why stored and outside dimenloop
//
////////////////////////////
interpolate_prim_face2corn(pr, pl_ct, pr_ct, pvbcorn, cent2faceloop, face2cornloop,prc,pleft,pright,Nvec,dqvec);
///////////////////////////////////////////////
//
// LOOP OVER EDGES (corresponds to EMF,edge directions, NOT face directions)
//
///////////////////////////////////////////////
DIMENLOOP(dir){
edgedir=dir;
///////////////////////////////////////////////
//
// other dimensions
// will be setting flux associated with d_t(Bodir1) and d_t(Bodir2) and setting flux(Bdir)->0
get_odirs(dir,&odir1,&odir2);
// skip to next dir if 1D such that EMF[dir] not needed since always cancels with itself
// assumes set to 0 and if set to 0 once then always 0 (assume set to 0 in
if(Nvec[odir1]==1 && Nvec[odir2]==1){
// if(firsttime){
// then ensure that really 0 and should remain 0 for entire evolution
// don't need to set this except once assuming no other code sets to non-zero
// No! If those directions are 0 then flux isn't defined nor used
//COMPZSLOOP( -N1BND, N1-1+N1BND, -N2BND, N2-1+N2BND, -N3BND, N3-1+N3BND ){
// MACP1A1(fluxvec,odir1,i,j,k,B1-1+odir2)=MACP1A1(fluxvec,odir2,i,j,k,B1-1+odir1)=MACP1A1(fluxvec,dir,i,j,k,B1-1+dir)=0.0;
// }
// }
continue;
}
//loop over the interfaces where fluxes are computed -- atch, useCOMPZSLOOP( is, ie, js, je, ks, ke ) { ... }
// since looping over edges (emfs) and flux loop different than emf loop, then expand loops so consistent with both fluxes corresponding to that emf
is=emffluxloop[dir][FIS];
ie=emffluxloop[dir][FIE];
js=emffluxloop[dir][FJS];
je=emffluxloop[dir][FJE];
ks=emffluxloop[dir][FKS];
ke=emffluxloop[dir][FKE];
// dir corrsponds to *edge,emf* NOT face
// CUf[2] is for flux updates
MYFUN(fluxcalc_fluxctstag_emf_1d(stage, pr, dir, odir1, odir2, is, ie, js, je, ks, ke, fluxvec, CUf[2], face2cornloop[edgedir],pvbcorn,wspeed),"flux.c:fluxcalc()", "fluxcalc_fluxctstag_1d", dir);
#if(PRODUCTION==0)
trifprintf("%d",dir);
#endif
}// end DIMENLOOP(dir)
#if(0)
bound_flux(STAGEM1,t,fluxvec[1],fluxvec[2],fluxvec[3], 0);
if(N1>1) bound_prim(STAGEM1,t,fluxvec[1], 0);
if(N2>1) bound_prim(STAGEM1,t,fluxvec[2], 0);
if(N3>1) bound_prim(STAGEM1,t,fluxvec[3], 0);
#endif
#if(0)
// SUPERDEBUG: shouldn't be needed -- test
dualfprintf(fail_file,"nstep=%ld steppart=%d\n",nstep,steppart);
LOOPF_23{ // debug only
dualfprintf(fail_file,"j=%d emf[0]=%21.15g emf[N1]=%21.15g diff=%21.15g\n",j,MACP1A1(fluxvec,1,0,j,k,B2),MACP1A1(fluxvec,1,N1,j,k,B2),MACP1A1(fluxvec,1,0,j,k,B2)-MACP1A1(fluxvec,1,N1,j,k,B2));
//MACP1A1(fluxvec,1,N1,j,k,B2)=MACP1A1(fluxvec,1,0,j,k,B2);
// MACP1A1(fluxvec,2,N1,j,k,B1)=-MACP1A1(fluxvec,1,0,j,k,B2);
// MACP1A1(fluxvec,1,N1,j,k,B2)=-MACP1A1(fluxvec,2,N1,j,k,B1);
//=-MACP1A1(fluxvec,2,N1,j,k,B1)=
}
#endif
if(EVOLVEWITHVPOT>0 || TRACKVPOT>0){
// Evolve A_i
evolve_vpotgeneral(FLUXB, stage, initialstep, finalstep, pr, Nvec, fluxvec, NULL, 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/FLUXes
adjust_fluxctstag_emfs(fluxtime,pr,Nvec,fluxvec);
}
// firsttime=0;
return(0);
}
/////////////////////////
//
// use global pbcorninterp and pvcorninterp at CORN1,2,3 to obtain EMFs at CORN1,2,3
// NO interpolation of quantities (except kinda wavespeeds) done here
//
// assumes 2-D Riemann problem
//
// When time for flux calculation:
//
// 1) Wavespeed calculation:
//
// MACP2A0(wspeed,dir,CMIN/CMAX,i,j,k) : Use global wspeed located at FACE (as computed by flux_standard() and put at FACE by global_vchar())
//
// CMIN,CMAX correspond to left,right going waves at FACEdir
// In Del Zanna et al. (2003) equation 43-45, we have
// alpha_x^+ = max(0,wspeed[dir corresponding to x][CMAX][index],wspeed[dir corresponding to x][CMAX][index-1 in y direction])
// That is, wspeed located at FACE means only need to take max over 2 remaining speeds since already got wspeed by max,min of CENT speeds -- so realy are going over all 4 states for max,min each for each direction
//
// 2) Flux calculation
//
// F1[B1]=F2[B2]=F3[B3]=0
// F2[B3]=-F3[B2] (+-E1)
// F1[B3]=-F3[B1] (+-E2)
// F1[B2]=-F2[B1] (+-E3)
//
// So only really 3 fluxes to be set corresponding to EMFs E1,E2,E3.
// If 3D, then all fields use E in orthogonal plane (e.g. Bx uses d_2(E3) and d_3(E2), etc.)
// If 2D in (say) x-y plane, then B1 only evolves by d_2(E3), B2 only evolves by d_1(E3), and B3 evolves by d_1(E2) and d_2(E1)
// If 1D in (say) x-dir, then d_1(E3) evolves B2 and d_1(E2) evolves B3 and B1 doesn't evolve. Hence if 1-D in x-dir don't need to compute E1
//
// pvcorninterp and pbcorninterp are defined to be used like below initializaiton in set_arrays.c
// for(pl2=1;pl2<=COMPDIM;pl2++) for(pl=1;pl<=COMPDIM;pl++) for(m=0;m<NUMCS+1;m++) for(l=0;l<NUMCS;l++) GLOBALMACP1A3(pvbcorninterp,pl2,i,j,k,pl,m,l)=valueinit;
int fluxcalc_fluxctstag_emf_1d(int stage, FTYPE (*pr)[NSTORE2][NSTORE3][NPR], int dir, int odir1, int odir2, int is, int ie, int js, int je, int ks, int ke, FTYPE (*fluxvec[NDIM])[NSTORE2][NSTORE3][NPR], FTYPE CUf, struct of_loop (*face2cornloop)[NDIM],
// FTYPE (*pbcorn)[COMPDIM][NUMCS][NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3],
FTYPE (*pvbcorn)[NSTORE1+SHIFTSTORE1][NSTORE2+SHIFTSTORE2][NSTORE3+SHIFTSTORE3][COMPDIM][NUMCS+1][NUMCS],
FTYPE (*wspeed)[NUMCS][NSTORE1][NSTORE2][NSTORE3])
{
int idel1,jdel1,kdel1;
int idel2,jdel2,kdel2;
int Nvec[NDIM];
///////////////////////////////////////////////
//
// get direction offsets for array accesses
//
///////////////////////////////////////////////
Nvec[0]=0;
Nvec[1]=N1;
Nvec[2]=N2;
Nvec[3]=N3;
idel1 = fluxloop[odir1][FIDEL];
jdel1 = fluxloop[odir1][FJDEL];
kdel1 = fluxloop[odir1][FKDEL];
idel2 = fluxloop[odir2][FIDEL];
jdel2 = fluxloop[odir2][FJDEL];
kdel2 = fluxloop[odir2][FKDEL];
//////////////////////////////////////
//
// flux loop : Extra "expand" zone for the purpose of averaging flux to get emf at corner. Only used by field components, see flux_ct().
// This loop is over interfaces where fluxes are evaluated -- atch
//
////////////////////////////////////////
//#if((SIMULBCCALC==2)&&(TYPE2==1))
// COMPFZLOOP(is,js,ks)
//#else
//#endif
///// COMPZSLOOP( is, ie, js, je, ks, ke ){ // slightly expanded compared to normal flux calculation due to needing emf that is for 2 different fluxes
#pragma omp parallel
{
int i,j,k,pl,pliter;
struct of_gdetgeom gdetgeomdontuse;
struct of_gdetgeom *ptrgdetgeom=&gdetgeomdontuse;
int m,l;
FTYPE emf2d[COMPDIM-1][COMPDIM-1],c2d[NUMCS][COMPDIM-1];
FTYPE dB[COMPDIM-1],ctop[COMPDIM-1];
FTYPE emffinal;
FTYPE geomcornodir1,geomcornodir2;
FTYPE topwave[COMPDIM-1],bottomwave[COMPDIM-1];
OPENMP3DLOOPVARSDEFINE; OPENMP3DLOOPSETUP(is,ie,js,je,ks,ke);
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize))
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
// pvcorninterp and pbcorninterp are defined to be used like below initializaiton in set_arrays.c
// for(pl2=1;pl2<=COMPDIM;pl2++) for(pl=1;pl<=COMPDIM;pl++) for(m=0;m<NUMCS+1;m++) for(l=0;l<NUMCS;l++) GLOBALMACP1A3(pvbcorninterp,pl2,i,j,k,pl,m,l)=valueinit;
/////////////////////////////////
//
// pvcorn must contain velocity in same frame as field primitive in order to avoid interpolating yet another set of quantities (even can't do just 1 extra since 2 directions to interpolate from and no way to keep symmetry of interpolations without doing 2 extras and (e.g.) averaging)
// assume final EMF being too large for the local field ($B^2-E^2>0$ or $\gamma^2\sim B^2/(B^2-E^2)$) will not be a problem since extra EMF at CORN would only increase field
// not formally inconsistent since didn't interpolate other velocity or field to same location
//
// for each edge/EMF (dir):
// 1) There are 2 values for fields in each directions (odir1,odir2)
// 2) There are 2x2 values for velocities in directions (odir1,odir2)
//
// 3) Need to work out where interpolated quantities go
//
// unsure if signature and overall sign will be right -- GODMARK
// i,j,k should already be taken into account (i.e. no offsets to add)
// emf in dir direction
for(m=0;m<NUMCS;m++) for(l=0;l<NUMCS;l++){
// emf[+- in odir1][+- in odir2]
// velocity in same positions as emf
// for example, emf3[+-x][+-y] = By[+-x]*vx[+-x][+-y] - Bx[+-y]*vy[+-x][+-y]
// below requires velocity to be lab-frame 3-velocity consistent with lab-frame 3-field primitive
// see fluxct.c for signature definition of EMF and flux
// m%3+1 gives next 1->2,2->3,3->1
// 3-(4-m)%3 = (dir+1)%3+1 gives previous 1->3,2->1,3->2
// so odir1 is forward cyclic
// so odir2 is backward cyclic
// notice that the emf in total uses 4 fields and 4*2 velocities for 12 total quantities
// not all pbcorn[][?] positions are used (have 3 only need 2 per dir)
// pvcorn[which corner][which component in pl form][+-odir1][+-odir2]
// pbcorn[which corner][which component in pl form][+-remaining direction that is not corn nor pl-dir]
emf2d[m][l] =
// + MACP3A0(pbcorn,dir,B1-1+odir2,m,i,j,k)*MACP4A0(pvcorn,dir,U1-1+odir1,m,l,i,j,k)
// - MACP3A0(pbcorn,dir,B1-1+odir1,l,i,j,k)*MACP4A0(pvcorn,dir,U1-1+odir2,m,l,i,j,k);
+ MACP1A3(pvbcorn,dir,i,j,k,odir2,NUMCS,m)*MACP1A3(pvbcorn,dir,i,j,k,odir1,m,l)
- MACP1A3(pvbcorn,dir,i,j,k,odir1,NUMCS,l)*MACP1A3(pvbcorn,dir,i,j,k,odir2,m,l);
}
///////////////////////////
//
// get wave speeds (these are not interpolated yet to CORNER, they start at FACE regardless of STOREWAVESPEEDS==1,2)
// note wspeed has NO sign information (for any case, including as set by global_vchar())
// c[CMIN,CMAX][0=odir1,1=odir2]
// need to determine i,j,k to choose based upon odir value
// -?del? since going from FACE to CORN
// del2 for c2d[][0] since wspeed[odir1] is wave going in odir1-direction, whereas other wavespeed to MAX with is in other (odir2) direction
if(Nvec[odir1]>1){
c2d[CMIN][0] = fabs(MAX(0.,MAX(+MACP2A0(wspeed,odir1,CMIN,i,j,k),+MACP2A0(wspeed,odir1,CMIN,i-idel2,j-jdel2,k-kdel2))));
c2d[CMAX][0] = fabs(MAX(0.,MAX(+MACP2A0(wspeed,odir1,CMAX,i,j,k),+MACP2A0(wspeed,odir1,CMAX,i-idel2,j-jdel2,k-kdel2))));
}
else{
// GODMARK: shoud just set the offending wavespeed (associated with non-existing dimensional direction) to 1.0 so don't have this conditional
// then speed doesn't matter, not set, so scale-out
c2d[CMIN][0] = 1.0;
c2d[CMAX][0] = 1.0;
}
if(Nvec[odir2]>1){
c2d[CMIN][1] = fabs(MAX(0.,MAX(+MACP2A0(wspeed,odir2,CMIN,i,j,k),+MACP2A0(wspeed,odir2,CMIN,i-idel1,j-jdel1,k-kdel1))));
c2d[CMAX][1] = fabs(MAX(0.,MAX(+MACP2A0(wspeed,odir2,CMAX,i,j,k),+MACP2A0(wspeed,odir2,CMAX,i-idel1,j-jdel1,k-kdel1))));
}
else{
// then speed doesn't matter, not set, so scale-out
c2d[CMIN][1] = 1.0;
c2d[CMAX][1] = 1.0;
}
ctop[0] = MAX(c2d[CMIN][0],c2d[CMAX][0]);
ctop[1] = MAX(c2d[CMIN][1],c2d[CMAX][1]);
//////////////////////////////////
//
// compute conserved dissipation term
//
/////////////////////////////////
// "upper" minus "lower" fields
// dB[?] corresponds to ? meaning field direction, not interpolation or any other direction
// dB[0] corresponds to dB["odir1"]
// dB[0] = MACP3A0(pbcorn,dir,B1-1+odir1,1,i,j,k) - MACP3A0(pbcorn,dir,B1-1+odir1,0,i,j,k) ;
dB[0] = MACP1A3(pvbcorn,dir,i,j,k,odir1,NUMCS,1) - MACP1A3(pvbcorn,dir,i,j,k,odir1,NUMCS,0) ;
// dB[1] corresponds to dB["odir2"]
// dB[1] = MACP3A0(pbcorn,dir,B1-1+odir2,1,i,j,k) - MACP3A0(pbcorn,dir,B1-1+odir2,0,i,j,k) ;
dB[1] = MACP1A3(pvbcorn,dir,i,j,k,odir2,NUMCS,1) - MACP1A3(pvbcorn,dir,i,j,k,odir2,NUMCS,0) ;
//////////////////////////////////
//
// compute emf
//
/////////////////////////////////
// Del Zanna et al. (2003) has opposite sign in equations 44,45 since they define the electric field (E_i) whereas we define EMF=-gdet E_i
// see fluxct.c comments
// Sign of dissipative term is as for HLL flux, which since EMF and flux have different sign relationships for each direction/field, we have:
//
// emf_1 = B^3 v^2 - B^2 v^3 = F2[B3] or -F3[B2] : Dissipative terms: -(dB3) and +(dB2)
// emf_2 = B^1 v^3 - B^3 v^1 = F3[B1] or -F1[B3] : Dissipative terms: -(dB1) and +(dB3)
// emf_3 = B^2 v^1 - B^1 v^2 = F1[B2] or -F2[B1] : Dissipative terms: -(dB2) and +(dB1)
//
// So since dissipative term order is EMF[edgedir] += dB[odir1] + dB[odir2]
// then we have:
// edgedir=1 odir1=2 odir2=3 , so need -dB[1] and +dB[0]
// edgedir=2 odir1=3 odir2=1 , so need -dB[1] and +dB[0]
// edgedir=3 odir1=1 odir2=2 , so need -dB[1] and +dB[0]
// so same formula for all EMFs
// below topwave[] are positive definite but could be 0.0 and then HLLFLUX formula not right
topwave[0]=c2d[CMIN][0] + c2d[CMAX][0];
topwave[1]=c2d[CMIN][1] + c2d[CMAX][1];
if( (fluxmethod==HLLFLUX) && (topwave[0]>SMALL) && (topwave[1]>SMALL) ){
bottomwave[0]=1.0/topwave[0];
bottomwave[1]=1.0/topwave[1];
// HLL
emffinal =
// non-dissipative term
+ (
+c2d[CMAX][0]*c2d[CMAX][1]*emf2d[0][0] // emf has -odir1 -odir2, so wavespeed has +odir1 +odir2
+c2d[CMAX][0]*c2d[CMIN][1]*emf2d[0][1] // emf has -odir1 +odir2, so wavespeed has +odir1 -odir2
+c2d[CMIN][0]*c2d[CMAX][1]*emf2d[1][0] // emf has +odir1 -odir2, so wavespeed has -odir1 +odir2
+c2d[CMIN][0]*c2d[CMIN][1]*emf2d[1][1] // emf has +odir1 +odir2, so wavespeed has -odir1 -odir2
)*bottomwave[0]*bottomwave[1]
// dissipative terms
- (
// dB has d(B[odir2]) so wavespeed has +-odir1 (note d(B[odir1]) for +-odir1 is 0 due to divb=0) (i.e. otherwise would be 4 dissipation terms for 2D Riemann problem)
c2d[CMIN][0]*c2d[CMAX][0]*bottomwave[0]*dB[1]
)
+ (
// dB has d(B[odir1]) so wavespeed has +-odir2 (note d(B[odir2]) for +-odir2 is 0 due to divb=0) (i.e. otherwise would be 4 dissipation terms for 2D Riemann problem)
c2d[CMIN][1]*c2d[CMAX][1]*bottomwave[1]*dB[0]
)
;
}
else{ // assume if not HLL then LAXF since only 2 methods for this routine
// LAXF
// dB and ctop flip odir's due to divb=0(i.e. otherwise would be 4 dissipation terms for 2D Riemann problem)
emffinal =
+ 0.25*(emf2d[0][0]+emf2d[0][1]+emf2d[1][0]+emf2d[1][1])
- 0.50*(ctop[0]*dB[1] - ctop[1]*dB[0]);
}
//////////////////////////////////
//
// set the fluxes (final flux is expected to have geometry on it)
//
/////////////////////////////////
// B inside pbcorn was setup with geometry
// assume that if on singularity where gdet=0 then interpolation gave good value on singularity
// GODMARK: seems like issue with choice of how to treat gdet is related to presence (or not) of line current on singularity
// For example, for POLARAXIS E_z will not be 0 if first used gdet and then interpolated, while if used gdet afterwards then will be 0
// Same ambiguity exists in fluxct.c
#if(CORNGDETVERSION==1)
// even though only want geom.e, geom.e calculation could depend upon many things
get_geometry_geomeonly(i, j, k, CORN1-1+dir, ptrgdetgeom); // get geometry at CORN[dir] where emf is located
// GODMARK: why use ptrgeom->e here and ptrgeom->g in most other places?
geomcornodir1=ptrgdetgeom->EOMFUNCMAC(B1-1+odir1); // which field ptrgeom->e doesn't matter as mentioned below
geomcornodir2=ptrgdetgeom->EOMFUNCMAC(B1-1+odir2);
#else
geomcornodir1=1.0;
geomcornodir2=1.0;
#endif
#if(0) // DEBUG:
if(i==26 && j==40 && k==0){
dualfprintf(fail_file,"ORIG: emf2d[1][1]=%21.15g emf2d[1][0]=%21.15g emf2d[0][1]=%21.15g emf2d[0][0]=%21.15g ctop[0]=%21.15g ctop[1]=%21.15g dB[0]=%21.15g dB[1]=%21.15g emffinal=%21.15g gdetcorn3=%21.15g\n",emf2d[1][1],emf2d[1][0],emf2d[0][1],emf2d[0][0],ctop[0],ctop[1],dB[0],dB[1],emffinal,ptrgdetgeom->gdet);
dualfprintf(fail_file,"ORIG: c2d[CMIN][0]=%21.15g c2d[CMAX][0]=%21.15g c2d[CMIN][1]=%21.15g c2d[CMAX][1]=%21.15g\n",c2d[CMIN][0],c2d[CMAX][0],c2d[CMIN][1],c2d[CMAX][1]);
}
#endif
// see fluxct.c for definitions of signature
// e.g. edgedir=3 gives F[1][B2]=E3 and F[2][B1]=-E3 F[3][B3]=0, which is correct.
// Checked that correct for all edgedir's
// notice that geometries for field-type primitive must all be same for field since otherwise emf ptrgeom->e factor has a mixed association
if(Nvec[odir1]>1) MACP1A1(fluxvec,odir1,i,j,k,B1-1+odir2) = + emffinal*geomcornodir2;
if(Nvec[odir2]>1) MACP1A1(fluxvec,odir2,i,j,k,B1-1+odir1) = - emffinal*geomcornodir1;
if(Nvec[dir]>1) MACP1A1(fluxvec,dir,i,j,k,B1-1+dir) = 0.0;
#if((WHICHEOM==WITHNOGDET)&&(NOGDETB1>0)||(NOGDETB2>0)||(NOGDETB3>0))
dualfprintf(fail_file,"Makes no sense to have field with different geometry factor since flux,emf mixes those factors\n");
myexit(196826);
#endif
// done!
}// end 3D LOOP
}// end parallel region
#if(0)
bound_flux(STAGEM1,t,fluxvec[1],fluxvec[2],fluxvec[3], 0);
if(N1>1) bound_prim(STAGEM1,t,fluxvec[1], 0);
if(N2>1) bound_prim(STAGEM1,t,fluxvec[2], 0);
if(N3>1) bound_prim(STAGEM1,t,fluxvec[3], 0);
#endif
return (0);
}
// wrapper for *continuous* interpolation for FACE_to_CENT
void slope_lim_continuous_e2z(int realisinterp, int dir, int idel, int jdel, int kdel, FTYPE (*primreal)[NSTORE2][NSTORE3][NPR], FTYPE (*p2interp)[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*dq)[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*pleft)[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*pright)[NSTORE2][NSTORE3][NPR2INTERP], struct of_loop *face2centloop)
{
extern void slope_lim_linetype_c2e(int realisinterp, int whichprimtype, int interporflux, int dir, int idel, int jdel, int kdel, FTYPE (*primreal)[NSTORE2][NSTORE3][NPR], FTYPE (*stencilvar)[NSTORE2][NSTORE3][NPR], FTYPE (*p2interp)[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*pleft)[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*pright)[NSTORE2][NSTORE3][NPR2INTERP]);
extern void slope_lim_pointtype(int interporflux, int realisinterp, int pl, int dir, int idel, int jdel, int kdel, FTYPE (*primreal)[NSTORE2][NSTORE3][NPR], FTYPE (*p2interp)[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*dq)[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*pleft)[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*pright)[NSTORE2][NSTORE3][NPR2INTERP]);
int pl,pliter;
// TODOMARK: Can take discrete derivative so edge quantity at center, then c2e fully correct, and correctly interpolates as continuous.
// TODOMARK: Then after interpolation, just sum-up from left-most-edge-value using derivative at edge to get centered quantities
if( LINEINTERPTYPE(lim[dir]) ){ // this overrides lim, but lim must still be set properly
get_loop(INTERPLINETYPE, ENOINTERPTYPE, dir, face2centloop);
// 1 below means primitives instead of conserved quantities (used for loops)
// GODMARK: ENOMARK: pstag below may only contain field so can't be used for pressure indicator
// GODMARK: set_interppoint() inside this function sets starting and ending position for loops, and as set c2e always needs more than e2c for obtaining flux, so leaving as for c2e is fine for now
slope_lim_linetype_c2e(realisinterp, ENOPRIMITIVE, ENOINTERPTYPE, dir, idel, jdel, kdel, primreal, NULL, p2interp, pleft, pright);
// ENOMARK: for ENO should really use special _e2c_cont() function that assumes continuity is required GODMARK
// slope_lim_linetype_e2c_cont(realisinterp, ENOPRIMITIVE, ENOINTERPTYPE, dir, idel, jdel, kdel, primreal, NULL, p2interp, pcent);
}
else{
// Should really interpolate such that continuous GODMARK
// GODMARK: set_interppoint() inside this function sets starting and ending position for loops, and as set c2e always needs more than e2c for obtaining flux, so leaving as for c2e is fine for now
get_loop(INTERPPOINTTYPE, ENOINTERPTYPE, dir, face2centloop);
PINTERPLOOP(pliter,pl){
slope_lim_pointtype(ENOINTERPTYPE, realisinterp, pl, dir, idel, jdel, kdel, primreal, p2interp, dq, pleft, pright); // GODMARK: overwritting dq from other type of interpolation
}
}
#if(0)
bound_prim(STAGEM1,t,pleft, 0);
bound_prim(STAGEM1,t,pright, 0);
#endif
}
// wrapper for taking staggered conserved field quantity and obtaining centered field quantity
// upoint enters as stag and leaves as CENT
// once this function is done we have:
// 1) pstag will have correct staggered point value
// 2) upoint (if needed) will be replaced with center conserved value
// 3) pfield will contain centered field primitive value
// Note that no averaging or deaveraging occurs in this function -- everything is points
int interpolate_ustag2fieldcent(int stage, SFTYPE boundtime, int timeorder, int numtimeorders, FTYPE (*preal)[NSTORE2][NSTORE3][NPR], FTYPE (*pstag)[NSTORE2][NSTORE3][NPR],FTYPE (*upoint)[NSTORE2][NSTORE3][NPR],FTYPE (*pcent)[NSTORE2][NSTORE3][NPR])
{
int ustagpoint2pstag(FTYPE (*upoint)[NSTORE2][NSTORE3][NPR], FTYPE (*pstag)[NSTORE2][NSTORE3][NPR]);
int interpolate_pfield_face2cent(FTYPE (*preal)[NSTORE2][NSTORE3][NPR], FTYPE (*pstag)[NSTORE2][NSTORE3][NPR],FTYPE (*ucent)[NSTORE2][NSTORE3][NPR],FTYPE (*pcent)[NSTORE2][NSTORE3][NPR], struct of_loop *face2centloop, FTYPE (*dqvec[NDIM])[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*prc)[NSTORE2][NSTORE3][NPR], FTYPE (*pleft)[NSTORE2][NSTORE3][NPR2INTERP], FTYPE (*pright)[NSTORE2][NSTORE3][NPR2INTERP], int *Nvec);
struct of_loop face2cent[NDIM];
int finalstep;
FTYPE (*dqvec[NDIM])[NSTORE2][NSTORE3][NPR2INTERP];
int Nvec[NDIM];
#if(0)
bound_prim(STAGEM1,boundtime,upoint, 0);
#endif
// setup spatial sizes
Nvec[0]=0;
Nvec[1]=N1;
Nvec[2]=N2;
Nvec[3]=N3;
// setup dq's if needed
// called by advance() that doesn't have dq1,dq2,dq3 passed to it (yet), so access global dq1,dq2,dq3
dqvec[1]=GLOBALPOINT(dq1);
dqvec[2]=GLOBALPOINT(dq2);
dqvec[3]=GLOBALPOINT(dq3);
// Actually updates field using conserved update (and inverts field)
// next use of pstagscratch by fluxcalc() will be correct (see setup_rktimestep() commends for RK4)
ustagpoint2pstag(upoint,pstag);
if(timeorder==numtimeorders-1) finalstep=1; else finalstep=0;
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// Bound pstag
//
// must bound pstag at FACE1,2,3 so enough boundary zones to interpolate to get field at CENT
// note that unlike other conserved quantities, since field trivially inverted there is no issue with possible failure modes or fixups, so only need to bound once
// That is, we always update field as required for divb=0
// bound_pstag() takes care of which quantities to bound (only bounding B1,B2,B3)
bound_pstag(stage, finalstep, boundtime, preal, pstag, upoint, USEMPI);
// note that ustag isn't bounded, but is used for divb calculation, which is thus only valid at active CENT cells -- but that's all that's in normal dumps unless FULLOUTPUT is used
// pstagescratch should contain result of deaverage_ustag2pstag() -- gets utoinvert ready for inversion using guess pb
// other quantities in utoinvert are unchanged by this function (and if needed de-averaging this didn't do it!)
interpolate_pfield_face2cent(preal,pstag,upoint,pcent,face2cent,dqvec,GLOBALPOINT(prc),GLOBALPOINT(pleft),GLOBALPOINT(pright),Nvec);
#if(0)
bound_prim(STAGEM1,boundtime,pcent);
#endif
// pstagscratch is at FACE1,2,3 and is primary field variable
// pfield is at CENT and is dependent field variable
//
// This means pstagscratch must be bounded as a flux1,2,3
// In MPI use pstag with boundflux()
// In user bound, user must treat field differently knowing where field is located
// pfield at CENT does NOT need to be bounded itself since pstag is bounded and then interpolated in extended off-dir range in interpolate_pfield_face2cent() that uses slope_lim_continuous_e2z()
// So only need to bound pstag like a flux -- need to bound before FACE_2_CENT interpolation
// now have field at CENT wherever needed for both EMF at CORN1,2,3 AND have enough for normal fluxes at faces
// Note don't use CENT field to get field in direction of flux of any quantity -- revert to existing staggered value
// This is why don't need to bound the field at CENT
return(0);
}
#define USTAG2PSTAGCONSTRAINEDLOOP 1 // should be 1
// this function called in initbase.c and during advance()
// here ustag is point value
// if dimension doesn't exist, then ustag and pstag are really at CENT effectively
int ustagpoint2pstag(FTYPE (*ustag)[NSTORE2][NSTORE3][NPR], FTYPE (*pstag)[NSTORE2][NSTORE3][NPR])
{
int Nvec[NDIM];
Nvec[0]=0;
Nvec[1]=N1;
Nvec[2]=N2;
Nvec[3]=N3;
//////////////////////////
//
// get pstag from unew
// p should be de-averaged field at FACE1,2,3
//
////////////////////////////
#pragma omp parallel
{
void ustag2pstag(int dir, int i, int j, int k, FTYPE (*ustag)[NSTORE2][NSTORE3][NPR], FTYPE (*pstag)[NSTORE2][NSTORE3][NPR]);
extern void get_stag_startendindices(int *loop, int dir, int *is,int *ie,int *js,int *je,int *ks,int *ke);
int i,j,k,pl,pliter;
int dir;
FTYPE igdetgnosing;
int is,ie,js,je,ks,ke;
struct of_gdetgeom gdetgeomfdontuse[NDIM];
struct of_gdetgeom *ptrgdetgeomf[NDIM];
int jj;
OPENMP3DLOOPVARSDEFINE;
// generally ptr's are different inside parallel block
DLOOPA(jj) ptrgdetgeomf[jj]=&(gdetgeomfdontuse[jj]);
#if(USTAG2PSTAGCONSTRAINEDLOOP==0)
// Not well-constrained
DIMENLOOP(dir){
pl=B1-1+dir;
OPENMP3DLOOPSETUPFULL;
///////// COMPFULLLOOP{
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize)) nowait // "nowait" ok because each pstag[B1,B2,B3] set independently
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
// get geometry for face pre-interpolated values
get_geometry_gdetonly(i, j, k, FACE1-1+dir, ptrgdetgeomf[dir]); // FACE1,FACE2,FACE3 each
set_igdetsimple(ptrgdetgeomf[dir]);
igdetgnosing = ptrgdetgeomf[dir]->igdetnosing;
MACP0A1(pstag,i,j,k,pl) = MACP0A1(ustag,i,j,k,pl)*igdetgnosing;
}
}
#else // else if constrained loops
// well-constrained to only update pstag where really want update
// This ensures don't modify pstag outside well-defined box that defines current computational space
// do pl==B1
pl=B1;
dir=1;
get_stag_startendindices(Uconsevolveloop, dir, &is,&ie,&js,&je,&ks,&ke);
// dualfprintf(fail_file,"dir=%d is=%d ie=%d js=%d je=%d ks=%d ke=%d\n",dir,is,ie,js,je,ks,ke);
////// COMPZSLOOP(is,ie,js,je,ks,ke){
OPENMP3DLOOPSETUP(is,ie,js,je,ks,ke);
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize)) nowait // "nowait" ok because each pstag[B1,B2,B3] set independently
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
ustag2pstag(dir, i, j, k, ustag,pstag);
}
// do pl==B2
pl=B2;
dir=2;
get_stag_startendindices(Uconsevolveloop, dir, &is,&ie,&js,&je,&ks,&ke);
// dualfprintf(fail_file,"dir=%d is=%d ie=%d js=%d je=%d ks=%d ke=%d\n",dir,is,ie,js,je,ks,ke);
////// COMPZSLOOP(is,ie,js,je,ks,ke){
OPENMP3DLOOPSETUP(is,ie,js,je,ks,ke);
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize)) nowait
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
ustag2pstag(dir, i, j, k, ustag,pstag);
}
// do pl==B3
pl=B3;
dir=3;
get_stag_startendindices(Uconsevolveloop, dir, &is,&ie,&js,&je,&ks,&ke);
// dualfprintf(fail_file,"dir=%d is=%d ie=%d js=%d je=%d ks=%d ke=%d\n",dir,is,ie,js,je,ks,ke);
////// COMPZSLOOP(is,ie,js,je,ks,ke){
OPENMP3DLOOPSETUP(is,ie,js,je,ks,ke);
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize)) nowait
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
ustag2pstag(dir, i, j, k, ustag,pstag);
}
#endif
}// end parallel region (with implicit barrier)
#if(0)
bound_prim(STAGEM1,t,pstag);
#endif
return(0);
}
// OPTMARK: presume this function gets inlined
void ustag2pstag(int dir, int i, int j, int k, FTYPE (*ustag)[NSTORE2][NSTORE3][NPR], FTYPE (*pstag)[NSTORE2][NSTORE3][NPR])
{
FTYPE igdetgnosing;
int pl,pliter;
struct of_gdetgeom gdetgeomfdontuse[NDIM];
struct of_gdetgeom *ptrgdetgeomf[NDIM];
int jj;
// assign memory
DLOOPA(jj) ptrgdetgeomf[jj]=&(gdetgeomfdontuse[jj]);
pl=B1-1+dir;
// get geometry for face pre-interpolated values
get_geometry_gdetonly(i, j, k, FACE1-1+dir, ptrgdetgeomf[dir]); // FACE1,FACE2,FACE3 each
set_igdetsimple(ptrgdetgeomf[dir]);
igdetgnosing = ptrgdetgeomf[dir]->igdetnosing;