-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdiag.c
2549 lines (1951 loc) · 87.8 KB
/
diag.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"
/* diagnostics subroutine */
#define DIAGREPORT {trifprintf("t=%21.15g to do: tener=%21.15g (dt=%21.15g): dump_cnt=%ld @ t=%21.15g (dt=%21.15g) : avg_cnt=%ld @ t=%21.15g (dt=%21.15g) : debug_cnt=%ld @ t=%21.15g (dt=%21.15g) : image_cnt=%ld @ t=%21.15g (dt=%21.15g): restart=%d @ nstep=%ld (dt=%ld) dtfake=%ld\n",t,tdumpgen[ENERDUMPTYPE],DTdumpgen[ENERDUMPTYPE],dumpcntgen[MAINDUMPTYPE],tdumpgen[MAINDUMPTYPE],DTdumpgen[MAINDUMPTYPE],dumpcntgen[AVG1DUMPTYPE],tdumpgen[AVG1DUMPTYPE],DTdumpgen[AVG1DUMPTYPE],dumpcntgen[DEBUGDUMPTYPE],tdumpgen[DEBUGDUMPTYPE],DTdumpgen[DEBUGDUMPTYPE],dumpcntgen[IMAGEDUMPTYPE],tdumpgen[IMAGEDUMPTYPE],DTdumpgen[IMAGEDUMPTYPE],whichrestart,nrestart,DTr,DTfake);}
static int get_dodumps(int call_code, int firsttime, SFTYPE localt, long localnstep, long localrealnstep, FTYPE *tdumpgen, FTYPE *tlastgen, FTYPE tlastareamap
,long long int nlastrestart, long long int nrestart
,long long int nlastfake, long long int nfake
,int *doareamap, int *dodumpgen);
static int pre_dump(int whichDT, FTYPE t, FTYPE localt, FTYPE *DTdumpgen, long int *dumpcntgen, long long int *dumpcgen, FTYPE *tdumpgen, FILE **dumpcnt_filegen, FTYPE *tlastgen
,int whichrestart, long long int restartc, long long int localrealnstep, long long int nrestart,long DTr, long long int nlastrestart
,int whichfake, long long int fakec, long long int nfake,long DTfake, long long int nlastfake
);
static int post_dump(int whichDT, FTYPE localt, FTYPE *DTdumpgen, long int *dumpcntgen, long long int *dumpcgen, FTYPE *tdumpgen, FILE **dumpcnt_filegen, FTYPE *tlastgen
,long *restartsteps, int *whichrestart, long long int *restartc, long localrealnstep,long long int *nrestart, long DTr, long long int *nlastrestart
,long *fakesteps, int *whichfake, long long int *fakec, long long int *nfake, long DTfake, long long int *nlastfake
);
// OPENMPNOTE: Assume diag() not called by multiple threads, so static's are ok (including firsttime)
int diag(int call_code, FTYPE localt, long localnstep, long localrealnstep)
{
//////////////////
//
// BEGIN DIAG VARS
//
static int firsttime = 1;
int pl,pliter;
FTYPE asym[NPR], norm[NPR], maxasym[NPR];
FILE *dumpcnt_filegen[NUMDUMPTYPES];
static SFTYPE tlastgen[NUMDUMPTYPES];
static SFTYPE tlastareamap;
static long long int dumpcgen[NUMDUMPTYPES];
static SFTYPE tdumpgen[NUMDUMPTYPES];
int dodumpgen[NUMDUMPTYPES];
// restart stuff
static long long int restartc;
static long long int nlastrestart,nrestart;
// fake stuff
static long long int fakec;
static long long int nlastfake,nfake;
// other stuff
int doareamap;
int dtloop;
int dir,interpi,enodebugi;
int dissloop;
int indexfinalstep;
int enodebugdump(long dump_cnt);
int asym_compute_1(FTYPE (*prim)[NSTORE2][NSTORE3][NPR]);
int whichDT;
int (*dumpfuncgen[NUMDUMPTYPES])(long dump_cnt);
if(DODIAGS==0){
// then shouldn't be here, so just return without error
return(0);
}
///////////////////////
//
// Setup pointers to dump functions
//
///////////////////////
dumpfuncgen[IMAGEDUMPTYPE]=&image_dump;
dumpfuncgen[RESTARTDUMPTYPE]=&restart_write;
dumpfuncgen[RESTARTUPPERPOLEDUMPTYPE]=&restartupperpole_write;
dumpfuncgen[RESTARTMETRICDUMPTYPE]=&restartmetric_write;
dumpfuncgen[MAINDUMPTYPE]=&dump;
dumpfuncgen[GRIDDUMPTYPE]=&gdump;
dumpfuncgen[AVG1DUMPTYPE]=&avgdump;
dumpfuncgen[AVG2DUMPTYPE]=&avg2dump;
dumpfuncgen[DEBUGDUMPTYPE]=&debugdump;
dumpfuncgen[FIELDLINEDUMPTYPE]=&fieldlinedump;
dumpfuncgen[ENODEBUGDUMPTYPE]=&enodebugdump;
dumpfuncgen[DISSDUMPTYPE]=&dissdump;
dumpfuncgen[OTHERDUMPTYPE]=&dumpother;
dumpfuncgen[FLUXDUMPTYPE]=&fluxdumpdump;
dumpfuncgen[EOSDUMPTYPE]=&eosdump;
dumpfuncgen[VPOTDUMPTYPE]=&vpotdump;
dumpfuncgen[FAILFLOORDUDUMPTYPE]=&failfloordudump;
// ENERDUMPTYPE : not standard spatial dump file and not standard prototype
dumpfuncgen[ENERDUMPTYPE]=NULL;
if(USEMPI && USEROMIO==1 && MPIVERSION==2){
// then do restart-like dumping of fakedump so ROMIO non-blocking writes are eventually put to disk on reasonable timestep scale.
dumpfuncgen[FAKEDUMPTYPE]=&fakedump;
}
else{
// then no need to call fakedump()
dumpfuncgen[FAKEDUMPTYPE]=NULL;
}
///////////////////////////
//
// setup timing of writes to files
//
///////////////////////////
if ((call_code == INIT_OUT) || (firsttime == 1)) {
// no need to repeat if restarting
nlastrestart = (long) (DTr*(SFTYPE)((localrealnstep/DTr))-1);
nlastfake = (long) (DTfake*(SFTYPE)((localrealnstep/DTfake))-1);
tlastareamap = localt-SMALL;
for(dtloop=0;dtloop<NUMDUMPTYPES;dtloop++){
tlastgen[dtloop] = DTdumpgen[dtloop]*(SFTYPE)((long long int)(t/DTdumpgen[dtloop]))-SMALL;
}
for(dtloop=0;dtloop<NUMDUMPTYPES;dtloop++){
dumpcgen[dtloop]=0;
}
if (RESTARTMODE == 0) {
for(dtloop=0;dtloop<NUMDUMPTYPES;dtloop++){
tdumpgen[dtloop]=localt;
}
nrestart = localnstep;
// override defaults:
tdumpgen[AVG1DUMPTYPE]=localt+DTdumpgen[AVG1DUMPTYPE]; // do next time
tdumpgen[AVG2DUMPTYPE]=localt+DTdumpgen[AVG2DUMPTYPE]; // do next time
for(dtloop=0;dtloop<NUMDUMPTYPES;dtloop++){
dumpcntgen[dtloop]=0;
}
appendold = 0;
}
else{
setrestart(&appendold);
// assuming started at t=0 and localnstep=0 for original run
// time to dump NEXT
nrestart = (long)(DTr*(SFTYPE)((localrealnstep/DTr)+1));
nfake = (long)(DTfake*(SFTYPE)((localrealnstep/DTfake)+1));
for(dtloop=0;dtloop<NUMDUMPTYPES;dtloop++){
tdumpgen[dtloop]=DTdumpgen[dtloop]*(SFTYPE)((long long int)(localt/DTdumpgen[dtloop])+1);
}
DIAGREPORT;
}
}// end if firsttime or diag(INIT_OUT) called
///////////////////////
//
// setup what we will dump this call to diag()
//
////////////////////////
get_dodumps(call_code, firsttime, localt, localnstep, localrealnstep, tdumpgen, tlastgen, tlastareamap, nlastrestart, nrestart, nlastfake, nfake, &doareamap, dodumpgen);
//////////////////
//
// check if only wanted to know if next time would lead to making a dump file
// used so only compute expensive things during step for diagnostics if outputting diagnostics
//
//////////////////
if(call_code==FUTURE_OUT){
if(dodumpgen[MAINDUMPTYPE]) return(DOINGFUTUREOUT);
else return(0);
}
//////////////////////////////////////////////////////////////////////
//
////////////////// NOW WRITE TO FILES and update tdumpgen and tlastgen
//
// For non-blocking ROMIO to be effective as written, need to have largest dumps last
//
//////////////////////////////////////////////////////////////////////
#if(ASYMDIAGCHECK)
asym_compute_1(GLOBALPOINT(pdump));
#endif
////////////////////////////////////////
//
// extra bounding for diagnostics
//
////////////////////////////////////////
if(
// if doing simulbccalc type loop in step_ch.c then need to bound when doing diagnostics since not done yet
(SIMULBCCALC>=1 && (dodumpgen[MAINDUMPTYPE]||dodumpgen[RESTARTDUMPTYPE]||dodumpgen[ENERDUMPTYPE]))
// assume if PRODUCTION>0 then user knows divB won't be computed at MPI boundaries and that's ok. Don't want to compute so avoid bounding that slows things down. Assume ok to still compute dump file version, just not ener version that may be too often
|| (PRODUCTION==0 && (dodumpgen[MAINDUMPTYPE]||dodumpgen[ENERDUMPTYPE]))
|| (PRODUCTION>0 && (dodumpgen[MAINDUMPTYPE]))
){
// for dump, rdump, and divb in ener
int finalstep=0; // only for diagnostics, no accounting.
bound_allprim(STAGEM1,finalstep, localt,GLOBALPOINT(pdump),GLOBALPOINT(pstagdump),GLOBALPOINT(udump), USEMPI);
if(DOENOFLUX != NOENOFLUX){
// bound GLOBALPOINT(udump) (unew) so divb can be computed at MPI boundaries (still real boundaries won't be computed correctly for OUTFLOW types)
// Notice only need to bound 1 cell layer (BOUNDPRIMSIMPLETYPE) since divb computation only will need 1 extra cell
int fakedir=0;
bound_mpi(STAGEM1,finalstep,fakedir,BOUNDPRIMSIMPLETYPE,GLOBALPOINT(udump),NULL,NULL,NULL,NULL);
}
}
#if(PRODUCTION==0)
// DEBUG:
// GODMARK: need to disable to see if hurts internal solution since bounding this may help algorithm itself and we don't want that
// so far don't see problem with stag + FV or FLUXRECON
// bound conserved quantities so divb is computed correctly when doing higher-order methods
// note that divb will always be in error at boundary since uses unew
// don't need ustag in boundary cells, but do this to check divb on boundary when testing
// not generally a good idea
// bound_uavg(STAGEM1,localt,GLOBALPOINT(udump), 1, USEMPI);
#endif
///////////////////////
//
// Things to compute before creating dumping
//
///////////////////////
if(DOAVGDIAG){
// do every time step
// assume can't fail, but can apparently
if(average_calc(dodumpgen[AVG1DUMPTYPE]||dodumpgen[AVG2DUMPTYPE])>=1) return(1);
}
//////////////////////
//
// ener dump (integrated quantities: integrate and possibly dump them too (if dodumpgen[ENERDUMPTYPE]==1))
// need integratd quantities for restart dump, but don't write them to ener file.
// (not part of standard NUMDUMPTYPES array)
/////////////////////
if(DOENERDIAG&&(dodumpgen[ENERDUMPTYPE]||dodumpgen[RESTARTDUMPTYPE])){
// get integrated quantities and possiblly dump them to files
dump_ener(dodumpgen[ENERDUMPTYPE],dodumpgen[RESTARTDUMPTYPE],call_code);
}
///////////////////
//
// output other things not put into restart file AND update time to output to ener files
//
// (not part of standard NUMDUMPTYPES array)
///////////////////
if(DOENERDIAG&&dodumpgen[ENERDUMPTYPE]){
if(COMPUTEFRDOT){
frdotout(); // need to include all terms and theta fluxes on horizon/outer edge at some point GODMARK
}
// only update DT if wrote upon ener-type file period
whichDT=ENERDUMPTYPE;
// below is really floor to nearest integer plus 1
dumpcgen[whichDT] = 1 + MAX(0,(long long int)((localt-tdumpgen[whichDT])/DTdumpgen[whichDT]));
tdumpgen[whichDT] = (ROUND2LONGLONGINT(tdumpgen[whichDT]/DTdumpgen[whichDT]) + dumpcgen[whichDT])*DTdumpgen[whichDT];
tlastgen[ENERDUMPTYPE]=localt;
}
///////////////////////
//
// AREA MAP (not part of standard NUMDUMPTYPES array)
//
///////////////////////
if(doareamap){
if(area_map(call_code, TIMESERIESAREAMAP, 20, ifail, jfail, kfail, GLOBALPOINT(pdump))>=1) return(1);
tlastareamap=t;
}
///////////////////////
//
// Loop over dumps creation
//
///////////////////////
long int dumpcntmain;
int dumptypeiter;
for(dumptypeiter=0;dumptypeiter<NUMDUMPTYPES;dumptypeiter++){
if(dodumpgen[dumptypeiter]&&dumpfuncgen[dumptypeiter]!=NULL){
// pre_dump:
pre_dump(dumptypeiter,t,localt,DTdumpgen,dumpcntgen,dumpcgen,tdumpgen,dumpcnt_filegen,tlastgen
,whichrestart,restartc,localrealnstep,nrestart,DTr,nlastrestart
,whichfake,fakec,nfake,DTfake,nlastfake
);
if((*(dumpfuncgen[dumptypeiter]))(dumpcntgen[dumptypeiter]) >= 1){
dualfprintf(fail_file,"unable to print %s file\n",dumpnamelist[dumptypeiter]);
return (1);
}
// get main dump count for additional types below
if(dodumpgen[dumptypeiter] && dumptypeiter==MAINDUMPTYPE) dumpcntmain=dumpcntgen[dumptypeiter];
// post_dump:
post_dump(dumptypeiter,localt,DTdumpgen,dumpcntgen,dumpcgen,tdumpgen,dumpcnt_filegen,tlastgen
,restartsteps, &whichrestart, &restartc, localrealnstep, &nrestart, DTr, &nlastrestart
,fakesteps, &whichfake, &fakec, &nfake, DTfake, &nlastfake
);
}
}
///////////////////
// additional types of dumps linked to normal sequence of dump types
///////////////////
dumptypeiter=MAINDUMPTYPE;
if(dodumpgen[dumptypeiter]){
// MAINDUMPTYPE period for restart files is here instead of part of main loop since the "dodumpgen[]" condition is setup for the frequent restart dumps and want the below restart dumps to be in synch with main dump files
// so can restart at a dump without reconstructing the rdump from a dump.
// Also, if run out of disk space then normal rdump's can be corrupted
// avoid upperpole restart file since this is called inside restart_write() itself, since always want these to be in synch
// if(FLUXB==FLUXCTSTAG && special3dspc==1) restartupperpole_write(-(long)dumpcntgen[dumptypeiter]-1);
// NOTEMARK: This maindump-type-restart file is done after all other dump types are done so the dump type file numbers are fully updated for this dumping time.
restart_write(-(long)dumpcntmain-1);
if(DOEVOLVEMETRIC) restartmetric_write(-(long)dumpcntmain-1);
}
///////////////////
// special cases
///////////////////
// GRIDDUMPTYPE special case
// Only done at t=0 or for 1D on synch with MAINDUMPTYPE
// output grid (probaly want both fullgrid (to make sure ok) and compute grid to compare with data dumps
if((DOGDUMPDIAG)&&(!GAMMIEDUMP)&&(firsttime&&(RESTARTMODE==0))){
// -1 means no file number on filename
gdump(-1);
// NOTEMARK: if want to, e.g., stop right after gdump, then have to add MPI barrier. If forcing gdump output, then put 1|| in conditional above .
// #if(USEMPI)
// MPI_Barrier(MPI_COMM_WORLD);
// #endif
// myexit(0); // stop after gdump.bin created
//
// If want to create gdump and continue computing even after having previously restarted...
// Then add a static int firsttimegdump=1; before conditional and a firsttimegdump=0 inside conditional at the end of the conditional.
}
///////////////////////
//
// DIAG clearings
//
// finally some clearing based upon what called
//
////////////////////////
if(DODEBUG){ // shouldn't clear these till after ener and debug dump done so both have all timescale data.
#pragma omp parallel // need no global non-arrays
{
int i,j,k,floor;
OPENMP3DLOOPVARSDEFINE; OPENMP3DLOOPSETUPZLOOP; // constant loop parameters for entire region, so can be shared
if(dodumpgen[ENERDUMPTYPE]){
// cleanse the ener time scale for the failure diag
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize)) nowait
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
//// ZLOOP{
FINALSTEPLOOP(indexfinalstep) FLOORLOOP(floor) GLOBALMACP0A3(failfloorcount,i,j,k,indexfinalstep,ENERTS,floor) =0;
}// end 3D loop
}// end if
if(dodumpgen[DEBUGDUMPTYPE]){
// clense failure diag
////ZLOOP
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize)) nowait
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
FINALSTEPLOOP(indexfinalstep) FLOORLOOP(floor) GLOBALMACP0A3(failfloorcount,i,j,k,indexfinalstep,DEBUGTS,floor) =0;
}// end 3D loop
}// end if
if(dodumpgen[IMAGEDUMPTYPE]){
// clense the failure counts for this time scale
/////ZLOOP
#pragma omp for schedule(OPENMPSCHEDULE(),OPENMPCHUNKSIZE(blocksize)) nowait
OPENMP3DLOOPBLOCK{
OPENMP3DLOOPBLOCK2IJK(i,j,k);
FINALSTEPLOOP(indexfinalstep) FLOORLOOP(floor) GLOBALMACP0A3(failfloorcount,i,j,k,indexfinalstep,IMAGETS,floor) =0;
}// end 3D loop
}// end if
}// end parallel region (and implied barrier)
}// end if DODEBUG
if(DOENODEBUG){
if(dodumpgen[DEBUGDUMPTYPE]){
int i,j,k;
FULLLOOP DIMENLOOP(dir) INTERPENOTYPELOOP(interpi) PDIAGLOOP(pl) ENODEBUGLOOP(enodebugi){
if(dir<=2 && pl<=U2){
GLOBALMACP0A4(enodebugarray,i,j,k,dir-1,interpi,pl,enodebugi)=0;
}
}
}
}
if(0&&DODISS){
// clear diss (I don't see why one should do this and tie results to dump frequency)
if(dodumpgen[MAINDUMPTYPE]){
int i,j,k;
FULLLOOP{
for(dissloop=0;dissloop<NUMDISSVERSIONS;dissloop++){
// clear failures too
GLOBALMACP0A1(dissfunpos,i,j,k,dissloop)=0.0;
}
}
}
}
/* //symmetry check
j = 0;
k = 0;
PDIAGLOOP(pl) maxasym[pl] = 0.0;
PDIAGLOOP(pl) {
if( pl >= U1 && pl <= U3 ) {
norm[pl] = coordparams.timescalefactor;
}
else if( pl == UU ) {
norm[pl] = coordparams.timescalefactor * coordparams.timescalefactor;
}
else {
norm[pl] = 1.;
}
norm[pl] = 1 / norm[pl];
}
for( i = 0; i < N1; i++ ) {
PDIAGLOOP( pl ) {
if( pl == U1 ) {
asym[pl] = fabs( MACP0A1(p,i,j,k,pl) +MACP0A1(p,N1 - 1 - i,j,k,pl) );
}
else {
asym[pl] = fabs(MACP0A1(p,i,j,k,pl) -MACP0A1(p,N1 - 1 - i,j,k,pl) );
}
asym[pl] /= norm[pl];
maxasym[pl] = MAX( asym[pl], maxasym[pl] );
}
}
dualfprintf( fail_file, "asym %ld ", localrealnstep );
PDIAGLOOP(pl) if( pl <= U1 ) dualfprintf( fail_file, " %22.16g", maxasym[pl] );
dualfprintf( fail_file, "\n" );
*/
firsttime = 0;
return (0);
}
static int pre_dump(
int whichDT, FTYPE t, FTYPE localt, FTYPE *DTdumpgen, long int *dumpcntgen, long long int *dumpcgen, FTYPE *tdumpgen, FILE **dumpcnt_filegen, FTYPE *tlastgen
,int whichrestart, long long int restartc, long long int localrealnstep, long long int nrestart,long DTr, long long int nlastrestart
,int whichfake, long long int fakec, long long int nfake,long DTfake, long long int nlastfake
)
{
DIAGREPORT;
if(whichDT==RESTARTDUMPTYPE || whichDT==RESTARTMETRICDUMPTYPE){
// integer based period
trifprintf("dumping: restart: %d localnstep: %ld nlastrestart: %ld nrestart: %ld restartc: %d\n", whichrestart,localrealnstep,nlastrestart,nrestart,restartc);
}
else{
trifprintf("dumping: dump_cnt=%ld : t=%21.15g tlastdump=%21.15g tdump=%21.15g dumpc=%d\n", dumpcntgen[whichDT],localt,tlastgen[whichDT],tdumpgen[whichDT],dumpcgen[whichDT]);
}
return(0);
}
static int post_dump(
int whichDT, FTYPE localt, FTYPE *DTdumpgen, long int *dumpcntgen, long long int *dumpcgen, FTYPE *tdumpgen, FILE **dumpcnt_filegen, FTYPE *tlastgen
,long *restartsteps, int *whichrestart, long long int *restartc, long localrealnstep,long long int *nrestart, long DTr, long long int *nlastrestart
,long *fakesteps, int *whichfake, long long int *fakec, long long int *nfake, long DTfake, long long int *nlastfake
)
{
char temps[MAXFILENAME];
char temps2[MAXFILENAME];
char temps3[MAXFILENAME];
if(whichDT==RESTARTDUMPTYPE || whichDT==RESTARTMETRICDUMPTYPE){
// integer based period
// 0 1 0 1 0 1 ...
restartsteps[*whichrestart] = localrealnstep;
*whichrestart = !(*whichrestart);
// set "counter"
dumpcntgen[whichDT]=(long int)(*whichrestart);
*restartc = 1 + MAX(0,(long long int)(((FTYPE)localrealnstep-(FTYPE)(*nrestart))/((FTYPE)DTr)));
*nrestart = (ROUND2LONGLONGINT((FTYPE)localrealnstep/((FTYPE)DTr)) + (*restartc)) * DTr;
*nlastrestart=localrealnstep;
}
else if(whichDT==FAKEDUMPTYPE){
fakesteps[*whichfake] = localrealnstep;
*whichfake = !(*whichfake); // go ahead and oscillate this, even if not used.
// set "counter"
dumpcntgen[whichDT]=(long int)(*whichfake); // counter not currently used, but ok to set this to something.
*fakec = 1 + MAX(0,(long long int)(((FTYPE)localrealnstep-(FTYPE)(*nfake))/((FTYPE)DTfake)));
*nfake = (ROUND2LONGLONGINT((FTYPE)localrealnstep/((FTYPE)DTfake)) + (*fakec)) * DTfake;
*nlastfake=localrealnstep;
}
else{
// iterate counter
dumpcntgen[whichDT]++;
// below is really floor to nearest integer plus 1
dumpcgen[whichDT] = 1 + MAX(0,(long long int)((localt-tdumpgen[whichDT])/DTdumpgen[whichDT]));
tdumpgen[whichDT] = (ROUND2LONGLONGINT(tdumpgen[whichDT]/DTdumpgen[whichDT]) + dumpcgen[whichDT])*DTdumpgen[whichDT];
// output number of dumps
sprintf(temps, "dumps/0_num%d_%s_dumps.dat",whichDT,dumpnamelist[whichDT]);
sprintf(temps2, "error opening %d %s dump count file\n",whichDT,dumpnamelist[whichDT]);
sprintf(temps3, "Couldn't close %d %s dumpcnt_file",whichDT,dumpnamelist[whichDT]);
myfopen(temps,"w",temps2,&dumpcnt_filegen[whichDT]);
myfprintf(dumpcnt_filegen[whichDT], "# Number of %d %s dumps\n%ld\n",whichDT,dumpnamelist[whichDT],dumpcntgen[whichDT]);
myfclose(&dumpcnt_filegen[whichDT],temps3);
tlastgen[whichDT]=localt;
}
return(0);
}
static int get_dodumps(int call_code, int firsttime, SFTYPE localt, long localnstep, long localrealnstep, FTYPE *tdumpgen, FTYPE *tlastgen, FTYPE tlastareamap, long long int nlastrestart, long long int nrestart, long long int nlastfake, long long int nfake, int *doareamap, int *dodumpgen)
{
if((DOAREAMAPDIAG)&&(localt != tlastareamap)&&(dofailmap)&&(localnstep>=steptofailmap)){
*doareamap=1;
}
else *doareamap=0;
////////////////////////////
//
// rest are on NUMDUMPTYPES list
//
////////////////////////////
// IMAGEDUMPTYPE
if((dnumcolumns[IMAGEDUMPTYPE]>0)&&((DOIMAGEDIAG)&&(DODIAGEVERYSUBSTEP||((localt!=tlastgen[IMAGEDUMPTYPE])&&(localt >= tdumpgen[IMAGEDUMPTYPE] || call_code==FINAL_OUT))) )){
dodumpgen[IMAGEDUMPTYPE]=1;
}
else dodumpgen[IMAGEDUMPTYPE]=0;
// upperpole restart is (for now) always called inside normal restart dump call, so avoid extra call that this would create
// RESTARTUPPERPOLEDUMPTYPE
// if((FLUXB==FLUXCTSTAG&&special3dspc==1)&&((DORDUMPDIAG)&&( ((nlastrestart!=nrestart)&&(failed == 0) && (localrealnstep >= nrestart ))||(call_code==FINAL_OUT) ) ) ){
// dodumpgen[RESTARTUPPERPOLEDUMPTYPE]=1;
// }
// else dodumpgen[RESTARTUPPERPOLEDUMPTYPE]=0;
dodumpgen[RESTARTUPPERPOLEDUMPTYPE]=0;
// RESTARTDUMPTYPE
if((DORDUMPDIAG)&&( ((nlastrestart!=nrestart)&&(failed == 0) && (localrealnstep >= nrestart ))||(call_code==FINAL_OUT) ) ){
dodumpgen[RESTARTDUMPTYPE]=1;
}
else dodumpgen[RESTARTDUMPTYPE]=0;
// RESTARTMETRICDUMPTYPE
if(DOEVOLVEMETRIC&&((DORDUMPDIAG)&&( ((nlastrestart!=nrestart)&&(failed == 0) && (localrealnstep >= nrestart ))||(call_code==FINAL_OUT) ) ) ){
dodumpgen[RESTARTMETRICDUMPTYPE]=1;
}
else dodumpgen[RESTARTMETRICDUMPTYPE]=0;
// MAINDUMPTYPE
if((dnumcolumns[MAINDUMPTYPE]>0)&&( ((DODUMPDIAG)&&(DODIAGEVERYSUBSTEP||((localt!=tlastgen[MAINDUMPTYPE])&&(localt >= tdumpgen[MAINDUMPTYPE] || (RESTARTMODE&&dofaildump&&(localnstep>=steptofaildump)) || call_code==FINAL_OUT ))) ) )){
dodumpgen[MAINDUMPTYPE]=1;
}
else dodumpgen[MAINDUMPTYPE]=0;
// GRIDDUMPTYPE
// output grid (probaly want both fullgrid (to make sure ok) and compute grid to compare with data dumps
// only reasonable to do if 1-D
if((DOGDUMPDIAG)&&(!GAMMIEDUMP)&&(DOEVOLVEMETRIC&&(N2==1)&&(N3==1)&&(DOGDUMPDIAG)&&(!GAMMIEDUMP)&&(RESTARTMODE==0)&&(localt >= tdumpgen[GRIDDUMPTYPE] || call_code==FINAL_OUT))){
dodumpgen[GRIDDUMPTYPE]=1;
}
else dodumpgen[GRIDDUMPTYPE]=0;
// AVG1DUMPTYPE
if((dnumcolumns[AVG1DUMPTYPE]>0)&&((DOAVGDIAG)&&((localt!=tlastgen[AVG1DUMPTYPE])&&(localt >= tdumpgen[AVG1DUMPTYPE] || call_code==FINAL_OUT)))){
dodumpgen[AVG1DUMPTYPE]=1;
}
else dodumpgen[AVG1DUMPTYPE]=0;
// AVG2DUMPTYPE
if((DOAVG2&&dnumcolumns[AVG2DUMPTYPE]>0)&&((DOAVGDIAG)&&((localt!=tlastgen[AVG2DUMPTYPE])&&(localt >= tdumpgen[AVG2DUMPTYPE] || call_code==FINAL_OUT)))){
dodumpgen[AVG2DUMPTYPE]=1;
}
else dodumpgen[AVG2DUMPTYPE]=0;
// DEBUGDUMPTYPE
if((dnumcolumns[DEBUGDUMPTYPE]>0)&&( ((DODEBUG)&&(DOENODEBUGEVERYSUBSTEP||DODIAGEVERYSUBSTEP||((localt!=tlastgen[DEBUGDUMPTYPE])&&(localt >= tdumpgen[DEBUGDUMPTYPE] || call_code==FINAL_OUT))) ) )){
dodumpgen[DEBUGDUMPTYPE]=1;
}
else dodumpgen[DEBUGDUMPTYPE]=0;
// FIELDLINEDUMPTYPE
if((dnumcolumns[FIELDLINEDUMPTYPE]>0)&&((DOFIELDLINE)&&(DODIAGEVERYSUBSTEP||((localt!=tlastgen[FIELDLINEDUMPTYPE])&&(localt >= tdumpgen[FIELDLINEDUMPTYPE] || call_code==FINAL_OUT))) )){
dodumpgen[FIELDLINEDUMPTYPE]=1;
}
else dodumpgen[FIELDLINEDUMPTYPE]=0;
// ENODEBUGDUMPTYPE
if((DOENODEBUG&&dnumcolumns[ENODEBUGDUMPTYPE]>0)&&( ((DODEBUG)&&(DOENODEBUGEVERYSUBSTEP||DODIAGEVERYSUBSTEP||((localt!=tlastgen[ENODEBUGDUMPTYPE])&&(localt >= tdumpgen[ENODEBUGDUMPTYPE] || call_code==FINAL_OUT))) ) )){
dodumpgen[ENODEBUGDUMPTYPE]=1;
}
else dodumpgen[ENODEBUGDUMPTYPE]=0;
// DISSDUMPTYPE
if((dnumcolumns[DISSDUMPTYPE]>0)&&( ((DODUMPDIAG)&&(DODIAGEVERYSUBSTEP||((localt!=tlastgen[DISSDUMPTYPE])&&(localt >= tdumpgen[DISSDUMPTYPE] || (RESTARTMODE&&dofaildump&&(localnstep>=steptofaildump)) || call_code==FINAL_OUT ))) ) )){
dodumpgen[DISSDUMPTYPE]=1;
}
else dodumpgen[DISSDUMPTYPE]=0;
// OTHERDUMPTYPE
if((dnumcolumns[OTHERDUMPTYPE]>0)&&( ((DODUMPDIAG)&&(DODIAGEVERYSUBSTEP||((localt!=tlastgen[OTHERDUMPTYPE])&&(localt >= tdumpgen[OTHERDUMPTYPE] || (RESTARTMODE&&dofaildump&&(localnstep>=steptofaildump)) || call_code==FINAL_OUT ))) ) )){
dodumpgen[OTHERDUMPTYPE]=1;
}
else dodumpgen[OTHERDUMPTYPE]=0;
// FLUXDUMPTYPE
if((dnumcolumns[FLUXDUMPTYPE]>0)&&( ((DODUMPDIAG)&&(DODIAGEVERYSUBSTEP||((localt!=tlastgen[FLUXDUMPTYPE])&&(localt >= tdumpgen[FLUXDUMPTYPE] || (RESTARTMODE&&dofaildump&&(localnstep>=steptofaildump)) || call_code==FINAL_OUT ))) ) )){
dodumpgen[FLUXDUMPTYPE]=1;
}
else dodumpgen[FLUXDUMPTYPE]=0;
// EOSDUMPTYPE
if( (dnumcolumns[EOSDUMPTYPE]>0)&&( ((DODUMPDIAG)&&(DODIAGEVERYSUBSTEP||((localt!=tlastgen[EOSDUMPTYPE])&&(localt >= tdumpgen[EOSDUMPTYPE] || (RESTARTMODE&&dofaildump&&(localnstep>=steptofaildump)) || call_code==FINAL_OUT ))) ) )){
dodumpgen[EOSDUMPTYPE]=1;
}
else dodumpgen[EOSDUMPTYPE]=0;
// VPOTDUMPTYPE
if((dnumcolumns[VPOTDUMPTYPE]>0)&&( (((DOVPOTDUMP)&&(DODIAGEVERYSUBSTEP||((localt!=tlastgen[VPOTDUMPTYPE])&&(localt >= tdumpgen[VPOTDUMPTYPE] || (RESTARTMODE&&dofaildump&&(localnstep>=steptofaildump)) || call_code==FINAL_OUT ) ) ) ))) ){
dodumpgen[VPOTDUMPTYPE]=1;
}
else dodumpgen[VPOTDUMPTYPE]=0;
// FAILFLOORDUDUMPTYPE
if((dnumcolumns[FAILFLOORDUDUMPTYPE]>0)&&( ((DODUMPDIAG)&&(DODIAGEVERYSUBSTEP||((localt!=tlastgen[FAILFLOORDUDUMPTYPE])&&(localt >= tdumpgen[FAILFLOORDUDUMPTYPE] || (RESTARTMODE&&dofaildump&&(localnstep>=steptofaildump)) || call_code==FINAL_OUT ))) ) )){
dodumpgen[FAILFLOORDUDUMPTYPE]=1;
}
else dodumpgen[FAILFLOORDUDUMPTYPE]=0;
// ENERDUMPTYPE (dnumcolumns[ENERDUMPTYPE]==0 is normal)
// t!=tlast avoids duplicate entries
if(DOENERDIAG&&(DODIAGEVERYSUBSTEP||((localt!=tlastgen[ENERDUMPTYPE])&&( (localt >= tdumpgen[ENERDUMPTYPE])||(call_code==INIT_OUT)||(call_code==FINAL_OUT)||firsttime)))){
dodumpgen[ENERDUMPTYPE]=1;
}
else dodumpgen[ENERDUMPTYPE]=0;
// FAKEDUMPTYPE
if((USEMPI && USEROMIO==1 && MPIVERSION==2)&&( ((nlastfake!=nfake)&&(failed == 0) && (localrealnstep >= nfake ))||(call_code==FINAL_OUT) ) ){
dodumpgen[FAKEDUMPTYPE]=1;
}
else dodumpgen[FAKEDUMPTYPE]=0;
// DEBUG:
// if(t>2.45E4 || realnstep>28000){
// dodumpgen[ENERDUMPTYPE]=1;
// dodumpgen[EOSDUMPTYPE]=1;
// dodumpgen[DISSDUMPTYPE]=1;
// dodumpgen[MAINDUMPTYPE]=1;
// dodumpgen[GRIDDUMPTYPE]=1;
// dodumpgen[FAILFLOORDUDUMPTYPE]=1;
// dodumpgen[DEBUGDUMPTYPE]=1;
// }
return(0);
}
/** some diagnostic routines **/
int asym_compute_1(FTYPE (*prim)[NSTORE2][NSTORE3][NPR])
{
int i,j,k;
int pl,pliter;
#if(0)
// for implosion problem
FULLLOOP{
if(MACP0A1(prim,i,j,k,RHO)!=MACP0A1(prim,j,i,k,RHO)){
dualfprintf(fail_file,"ASYM in RHO %d %d %d : %23.16g %23.16g\n",i,j,k,MACP0A1(prim,i,j,k,RHO),MACP0A1(prim,j,i,k,RHO));
}
if(MACP0A1(prim,i,j,k,UU)!=MACP0A1(prim,j,i,k,UU)){
dualfprintf(fail_file,"ASYM in UU %d %d %d : %23.16g %23.16g\n",i,j,k,MACP0A1(prim,i,j,k,UU),MACP0A1(prim,j,i,k,UU));
}
if(MACP0A1(prim,i,j,k,U1)!=MACP0A1(prim,j,i,k,U2)){
dualfprintf(fail_file,"ASYM in U1 %d %d %d : %23.16g %23.16g\n",i,j,k,MACP0A1(prim,i,j,k,U1),MACP0A1(prim,j,i,k,U2));
}
}
#endif
#if(1)
// for any periodic boundary conditions
FULLLOOP{
if(i<N1/2 && j<N2/2 && k<N3/2){
PLOOP(pliter,pl){
if(MACP0A1(prim,i,j,k,pl)!=MACP0A1(prim,i+N1,j,k,pl)){
dualfprintf(fail_file,"ASYM nstep=%ld steppart=%d in pl=%d dir=1 :: %d %d %d : %23.16g %23.16g\n",nstep,steppart,pl,i,j,k,MACP0A1(prim,i,j,k,pl),MACP0A1(prim,i+N1,j,k,pl));
}
if(MACP0A1(prim,i,j,k,pl)!=MACP0A1(prim,i,j+N2,k,pl)){
dualfprintf(fail_file,"ASYM nstep=%ld steppart=%d in pl=%d dir=2 :: %d %d %d : %23.16g %23.16g\n",nstep,steppart,pl,i,j,k,MACP0A1(prim,i,j,k,pl),MACP0A1(prim,i,j+N2,k,pl));
}
}
}
}
// for any periodic boundary conditions
FULLLOOP{
if(i<N1/2 && j<N2/2 && k<N3/2){
PLOOP(pliter,pl){
if(GLOBALMACP0A1(udump,i,j,k,pl)!=GLOBALMACP0A1(udump,i+N1,j,k,pl)){
dualfprintf(fail_file,"ASYMUDUMP nstep=%ld steppart=%d in pl=%d dir=1 :: %d %d %d : %23.16g %23.16g\n",nstep,steppart,pl,i,j,k,GLOBALMACP0A1(udump,i,j,k,pl),GLOBALMACP0A1(udump,i+N1,j,k,pl));
}
if(GLOBALMACP0A1(udump,i,j,k,pl)!=GLOBALMACP0A1(udump,i,j+N2,k,pl)){
dualfprintf(fail_file,"ASYMUDUMP nstep=%ld steppart=%d in pl=%d dir=2 :: %d %d %d : %23.16g %23.16g\n",nstep,steppart,pl,i,j,k,GLOBALMACP0A1(udump,i,j,k,pl),GLOBALMACP0A1(udump,i,j+N2,k,pl));
}
}
}
}
#endif
return(0);
}
// for implosion problem
int asym_compute_2(FTYPE (*prim)[NSTORE2][NSTORE3][NPR])
{
int i,j,k;
int pl,pliter;
#if(0)
ZLOOP{
if(MACP0A1(prim,i,j,k,RHO)!=MACP0A1(prim,j,i,k,RHO)){
dualfprintf(fail_file,"ASYM in RHO %d %d %d : %23.16g %23.16g\n",i,j,k,MACP0A1(prim,i,j,k,RHO),MACP0A1(prim,j,i,k,RHO));
}
if(MACP0A1(prim,i,j,k,UU)!=MACP0A1(prim,j,i,k,UU)){
dualfprintf(fail_file,"ASYM in UU %d %d %d : %23.16g %23.16g\n",i,j,k,MACP0A1(prim,i,j,k,UU),MACP0A1(prim,j,i,k,UU));
}
if(MACP0A1(prim,i,j,k,U1)!=MACP0A1(prim,j,i,k,U2)){
dualfprintf(fail_file,"ASYM in U1 %d %d %d : %23.16g %23.16g\n",i,j,k,MACP0A1(prim,i,j,k,U1),MACP0A1(prim,j,i,k,U2));
}
}
#endif
#if(1)
// for any periodic boundary conditions
ZLOOP{
if(i<N1/2 && j<N2/2 && k<N3/2){
PLOOP(pliter,pl){
if(MACP0A1(prim,i,j,k,pl)!=MACP0A1(prim,i+N1,j,k,pl)){
dualfprintf(fail_file,"ASYM nstep=%ld steppart=%d in pl=%d dir=1 :: %d %d %d : %23.16g %23.16g\n",nstep,steppart,pl,i,j,k,MACP0A1(prim,i,j,k,pl),MACP0A1(prim,i+N1,j,k,pl));
}
if(MACP0A1(prim,i,j,k,pl)!=MACP0A1(prim,i,j+N2,k,pl)){
dualfprintf(fail_file,"ASYM nstep=%ld steppart=%d in pl=%d dir=2 :: %d %d %d : %23.16g %23.16g\n",nstep,steppart,pl,i,j,k,MACP0A1(prim,i,j,k,pl),MACP0A1(prim,i,j+N2,k,pl));
}
}
}
}
#endif
return(0);
}
// 2D only for now since really only useful for 2D imaging
/* map out region around failure point */
// OPENMPNOTE: Assume area_map() not called by multiple threads, so static's are ok (including firsttime)
int area_map(int call_code, int type, int size, int i, int j, int k, FTYPE (*prim)[NSTORE2][NSTORE3][NPR])
{
int pl,pliter;
int l,m,ll,mm;
FTYPE vmin1, vmax1, vmin2, vmax2;
int ignorecourant;
struct of_state q;
FTYPE X[NDIM],V[NDIM];
FTYPE divb;
FTYPE tens_em[NDIM][NDIM], tens_matt[NDIM][NDIM], b[NDIM],
ucon[NDIM];
FTYPE U[NPR];
int lowersizex1,uppersizex1;
int lowersizex2,uppersizex2;
int lowersizex3,uppersizex3;
static FILE* fileptr;
static int firsttime=1;
static int domap=0;
static int doclose=0;
struct of_geom geomdontuse;
struct of_geom *ptrgeom=&geomdontuse;
int loc=CENT;
trifprintf("\nStart area_map function ... ");
if(i-(-N1BND)<size/2) lowersizex1=i-(-N1BND);
else lowersizex1=size/2;
if((N1-1+N1BND)-i<size/2) uppersizex1=(N1-1+N1BND)-i;
else uppersizex1=size/2;
if(j-(-N2BND)<size/2) lowersizex2=j-(-N2BND);
else lowersizex2=size/2;
if((N2-1+N2BND)-j<size/2) uppersizex2=(N2-1+N2BND)-j;
else uppersizex2=size/2;
if(k-(-N3BND)<size/2) lowersizex3=k-(-N3BND);
else lowersizex3=size/2;
if((N3-1+N3BND)-k<size/2) uppersizex3=(N3-1+N3BND)-k;
else uppersizex3=size/2;
if(firsttime){
if((type==TIMESERIESAREAMAP)&&(dofailmap)){
if((fileptr=fopen("areamap","wt"))==NULL){
dualfprintf(fail_file,"Cannot open ./areamap on proc=%d\n",myid);
domap=0;
}
else domap=1;
}
}
if((type==TIMESERIESAREAMAP)&&domap&&(call_code==2)){
doclose=1;
}
else doclose=0;
if(type==FINALTDUMPAREAMAP){
dualfprintf(fail_file, "area map\n");
dualfprintf(fail_file, "areamap at: i=%d j=%d k=%d\n",i+startpos[1],j+startpos[2],k+startpos[3]);
coord(i,j,k,loc,X);
dualfprintf(fail_file, "areamap at: i=%d j=%d k=%d\n",i+startpos[1],j+startpos[2],k+startpos[3]);
PDIAGLOOP(pl) {// all vars
dualfprintf(fail_file, "variable %d \n", pl);
// ONLY 2D map for now
dualfprintf(fail_file, "i = \t ");
for(l=i-lowersizex1;l<=i+uppersizex1;l++){
ll=l+startpos[1];
dualfprintf(fail_file, "%21d", ll);
}