-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathtime_integrator.cpp
3080 lines (2820 loc) · 109 KB
/
time_integrator.cpp
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
//========================================================================================
// Athena++ astrophysical MHD code
// Copyright(C) 2014 James M. Stone <jmstone@princeton.edu> and other code contributors
// Licensed under the 3-clause BSD License, see LICENSE file for details
//========================================================================================
//! \file time_integrator.cpp
//! \brief derived class for time integrator task list. Can create task lists for one
//! of many different time integrators (e.g. van Leer, RK2, RK3, etc.)
// C headers
// C++ headers
#include <iostream> // endl
#include <sstream> // sstream
#include <stdexcept> // runtime_error
#include <string> // c_str()
// Athena++ headers
#include "../athena.hpp"
#include "../bvals/bvals.hpp"
#include "../chemistry/network/network.hpp"
#include "../cr/cr.hpp"
#include "../cr/integrators/cr_integrators.hpp"
#include "../eos/eos.hpp"
#include "../field/field.hpp"
#include "../field/field_diffusion/field_diffusion.hpp"
#include "../hydro/hydro.hpp"
#include "../hydro/hydro_diffusion/hydro_diffusion.hpp"
#include "../hydro/srcterms/hydro_srcterms.hpp"
#include "../mesh/mesh.hpp"
#include "../nr_radiation/integrators/rad_integrators.hpp"
#include "../nr_radiation/radiation.hpp"
#include "../orbital_advection/orbital_advection.hpp"
#include "../parameter_input.hpp"
#include "../reconstruct/reconstruction.hpp"
#include "../scalars/scalars.hpp"
#include "task_list.hpp"
//----------------------------------------------------------------------------------------
//! TimeIntegratorTaskList constructor
TimeIntegratorTaskList::TimeIntegratorTaskList(ParameterInput *pin, Mesh *pm) {
//! \note
//! First, define each time-integrator by setting weights for each step of
//! the algorithm and the CFL number stability limit when coupled to the single-stage
//! spatial operator.
//! Currently, the explicit, multistage time-integrators must be expressed as 2S-type
//! algorithms as in Ketcheson (2010) Algorithm 3, which incudes 2N (Williamson) and 2R
//! (van der Houwen) popular 2-register low-storage RK methods. The 2S-type integrators
//! depend on a bidiagonally sparse Shu-Osher representation; at each stage l:
//! \f[
//! U^{l} = a_{l,l-2}*U^{l-2} + a_{l-1}*U^{l-1}
//! + b_{l,l-2}*dt*Div(F_{l-2}) + b_{l,l-1}*dt*Div(F_{l-1}),
//! \f]
//! where \f$U^{l-1}\f$ and \f$U^{l-2}\f$ are previous stages and
//! \f$a_{l,l-2}\f$, \f$a_{l,l-1}=(1-a_{l,l-2})\f$,
//! and \f$b_{l,l-2}\f$, \f$b_{l,l-1}\f$
//! are weights that are different for each stage and
//! integrator. Previous timestep \f$U^{0} = U^n\f$ is given, and the integrator solves
//! for \f$U^{l}\f$ for 1 <= l <= nstages.
//!
//! \note
//! The 2x RHS evaluations of Div(F) and source terms per stage is avoided by adding
//! another weighted average / caching of these terms each stage. The API and framework
//! is extensible to three register 3S* methods,
//! although none are currently implemented.
//!
//! \note
//! Notation: exclusively using "stage", equivalent in lit. to "substage" or "substep"
//! (infrequently "step"), to refer to the intermediate values of U^{l} between each
//! "timestep" = "cycle" in explicit, multistage methods. This is to disambiguate the
//! temporal integration from other iterative sequences; generic
//! "Step" is often used for sequences in code, e.g. main.cpp: "Step 1: MPI"
//!
//! \note
//! main.cpp invokes the tasklist in a for () loop from stage=1 to stage=ptlist->nstages
//!
//! \todo (felker):
//! - validate Field and Hydro diffusion with RK3, RK4, SSPRK(5,4)
integrator = pin->GetOrAddString("time", "integrator", "vl2");
// nr_radiation enabled but not implicit_radiation
bool radiation_flag = (NR_RADIATION_ENABLED && (!IM_RADIATION_ENABLED));
// Read a flag for orbital advection
ORBITAL_ADVECTION = (pm->orbital_advection != 0)? true : false;
// Read a flag for shear periodic
SHEAR_PERIODIC = pm->shear_periodic;
if (integrator == "rk4" || integrator == "ssprk5_4") {
// shear periodic not work with rk4 or ssprk5_4
if (SHEAR_PERIODIC) {
std::stringstream msg;
msg << "### FATAL ERROR in TimeIntegratorTaskList constructor" << std::endl
<< "integrator=" << integrator << " does not work with shear periodic boundary."
<< std::endl;
ATHENA_ERROR(msg);
}
// orbital advection + mesh refinement not work with rk4 or ssprk5_4
if (ORBITAL_ADVECTION && pm->multilevel) {
std::stringstream msg;
msg << "### FATAL ERROR in TimeIntegratorTaskList constructor" << std::endl
<< "integrator=" << integrator << " does not work with orbital advection and "
<< "mesh refinement"
<< std::endl;
ATHENA_ERROR(msg);
}
}
if (integrator == "vl2") {
//! \note `integrator == "vl2"`
//! - VL: second-order van Leer integrator (Stone & Gardiner, NewA 14, 139 2009)
//! - Simple predictor-corrector scheme similar to MUSCL-Hancock
//! - Expressed in 2S or 3S* algorithm form
// set number of stages and time coeff.
nstages_main = 2;
if (ORBITAL_ADVECTION) {
// w/ orbital advection
if (SHEAR_PERIODIC || pm->multilevel) {
// w/ shear_periodic or refinements
if (pm->orbital_advection==1) { // first order splitting
nstages = nstages_main+1;
for (int l=0; l<nstages; l++) {
if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].ebeta = 0.0;
}
stage_wghts[l].sbeta = 0.0;
}
stage_wghts[0].beta = 0.5;
stage_wghts[1].beta = 1.0;
stage_wghts[2].beta = 0.0;
} else { // second order splitting
nstages = nstages_main+2;
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.0;
} else if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
}
}
stage_wghts[0].beta = 0.0;
stage_wghts[1].beta = 0.5;
stage_wghts[2].beta = 1.0;
stage_wghts[3].beta = 0.0;
}
} else { // w/o shear periodic and refinements
if (pm->orbital_advection==1) { // first order splitting
nstages = nstages_main;
for (int l=0; l<nstages; l++) {
stage_wghts[l].main_stage = true;
if (l == nstages-1) { // last stage
stage_wghts[l].orbital_stage = true;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].orbital_stage = false;
stage_wghts[l].ebeta = 0.0;
}
stage_wghts[l].sbeta = 0.0;
}
stage_wghts[0].beta = 0.5;
stage_wghts[1].beta = 1.0;
} else { // second order splitting
nstages = nstages_main+1;
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.0;
} else if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
}
}
stage_wghts[0].beta = 0.0;
stage_wghts[1].beta = 0.5;
stage_wghts[2].beta = 1.0;
}
}
} else { // w/o orbital advection
nstages = nstages_main;
for (int l=0; l<nstages; l++) {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
}
stage_wghts[0].sbeta = 0.0;
stage_wghts[0].ebeta = 0.5;
stage_wghts[1].sbeta = 0.5;
stage_wghts[1].ebeta = 1.0;
stage_wghts[0].beta = 0.5;
stage_wghts[1].beta = 1.0;
}
cfl_limit = 1.0;
// Modify VL2 stability limit in 2D, 3D
if (pm->ndim == 2) cfl_limit = 0.5;
if (pm->ndim == 3) cfl_limit = 0.5;
// set delta and gamma at each stage
int n_main = 0;
for (int n=0; n<nstages; n++) {
if (stage_wghts[n].main_stage) {
if (n_main == 0) {
stage_wghts[n].delta = 1.0; // required for consistency
stage_wghts[n].gamma_1 = 0.0;
stage_wghts[n].gamma_2 = 1.0;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
} else if (n_main == 1) {
stage_wghts[n].delta = 0.0;
stage_wghts[n].gamma_1 = 0.0;
stage_wghts[n].gamma_2 = 1.0;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
}
}
}
} else if (integrator == "rk1") {
//! \note `integrator == "rk1"`
//! - RK1: first-order Runge-Kutta / the forward Euler (FE) method
// set number of stages and time coeff.
nstages_main = 1;
if (ORBITAL_ADVECTION) {
// w/ orbital advection
if (SHEAR_PERIODIC || pm->multilevel) {
// w/ shear_periodic or refinements
if (pm->orbital_advection==1) { // first order splitting
nstages = nstages_main+1;
for (int l=0; l<nstages; l++) {
if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].ebeta = 0.0;
}
stage_wghts[l].sbeta = 0.0;
}
stage_wghts[0].beta = 1.0;
stage_wghts[1].beta = 0.0;
} else { // second order splitting
nstages = nstages_main+2;
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.0;
} else if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
}
}
stage_wghts[0].beta = 0.0;
stage_wghts[1].beta = 1.0;
stage_wghts[2].beta = 0.0;
}
} else { // w/o shear periodic and refinements
if (pm->orbital_advection==1) { // first order splitting
nstages = nstages_main;
stage_wghts[0].main_stage = true;
stage_wghts[0].orbital_stage = true;
stage_wghts[0].sbeta = 0.0;
stage_wghts[0].ebeta = 1.0;
stage_wghts[0].beta = 1.0;
} else { // second order splitting
nstages = nstages_main+1;
stage_wghts[0].main_stage = false;
stage_wghts[1].main_stage = true;
stage_wghts[0].orbital_stage = true;
stage_wghts[1].orbital_stage = true;
stage_wghts[0].sbeta = 0.0;
stage_wghts[0].ebeta = 0.5;
stage_wghts[1].sbeta = 0.5;
stage_wghts[1].ebeta = 1.0;
stage_wghts[0].beta = 0.0;
stage_wghts[1].beta = 1.0;
}
}
} else { // w/o orbital advection
nstages = nstages_main;
stage_wghts[0].main_stage = true;
stage_wghts[0].orbital_stage = false;
stage_wghts[0].sbeta = 0.0;
stage_wghts[0].ebeta = 1.0;
stage_wghts[0].beta = 1.0;
}
cfl_limit = 1.0;
// set delta and gamma at each stage
int n_main = 0;
for (int n=0; n<nstages; n++) {
if (stage_wghts[n].main_stage) {
if (n_main == 0) {
stage_wghts[n].delta = 1.0;
stage_wghts[n].gamma_1 = 0.0;
stage_wghts[n].gamma_2 = 1.0;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
}
}
}
} else if (integrator == "rk2") {
//! \note `integrator == "rk2"`
//! - Heun's method / SSPRK (2,2): Gottlieb (2009) equation 3.1
//! - Optimal (in error bounds) explicit two-stage, second-order SSPRK
// set number of stages and time coeff.
nstages_main = 2;
if (ORBITAL_ADVECTION) {
// w/ orbital advection
if (SHEAR_PERIODIC || pm->multilevel) {
// w/ shear_periodic or refinements
if (pm->orbital_advection==1) { // first order splitting
nstages = nstages_main+1;
for (int l=0; l<nstages; l++) {
if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].ebeta = 0.0;
}
stage_wghts[l].sbeta = 0.0;
}
stage_wghts[0].beta = 1.0;
stage_wghts[1].beta = 0.5;
stage_wghts[2].beta = 0.0;
} else { // second order splitting
nstages = nstages_main+2;
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.0;
} else if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
}
}
stage_wghts[0].beta = 0.0;
stage_wghts[1].beta = 1.0;
stage_wghts[2].beta = 0.5;
stage_wghts[3].beta = 0.0;
}
} else { // w/o shear periodic and refinements
if (pm->orbital_advection==1) { // first order splitting
nstages = nstages_main;
for (int l=0; l<nstages; l++) {
stage_wghts[l].main_stage = true;
if (l == nstages-1) { // last stage
stage_wghts[l].orbital_stage = true;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].orbital_stage = false;
stage_wghts[l].ebeta = 0.0;
}
stage_wghts[l].sbeta = 0.0;
}
stage_wghts[0].beta = 1.0;
stage_wghts[1].beta = 0.5;
} else { // second order splitting
nstages = nstages_main+1;
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.0;
} else if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
}
}
stage_wghts[0].beta = 0.0;
stage_wghts[1].beta = 1.0;
stage_wghts[2].beta = 0.5;
}
}
} else { // w/o orbital advection
nstages = nstages_main;
for (int l=0; l<nstages; l++) {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
}
stage_wghts[0].sbeta = 0.0;
stage_wghts[0].ebeta = 1.0;
stage_wghts[1].sbeta = 1.0;
stage_wghts[1].ebeta = 1.0;
stage_wghts[0].beta = 1.0;
stage_wghts[1].beta = 0.5;
}
cfl_limit = 1.0; // c_eff = c/nstages = 1/2 (Gottlieb (2009), pg 271)
// set delta and gamma at each stage
int n_main = 0;
for (int n=0; n<nstages; n++) {
if (stage_wghts[n].main_stage) {
if (n_main == 0) {
stage_wghts[n].delta = 1.0;
stage_wghts[n].gamma_1 = 0.0;
stage_wghts[n].gamma_2 = 1.0;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
} else if (n_main == 1) {
stage_wghts[n].delta = 0.0;
stage_wghts[n].gamma_1 = 0.5;
stage_wghts[n].gamma_2 = 0.5;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
}
}
}
} else if (integrator == "rk3") {
//! \note `integrator == "rk3"`
//! - SSPRK (3,3): Gottlieb (2009) equation 3.2
//! - Optimal (in error bounds) explicit three-stage, third-order SSPRK
// set number of stages and time coeff.
nstages_main = 3;
if (ORBITAL_ADVECTION) {
// w/ orbital advection
if (SHEAR_PERIODIC || pm->multilevel) {
// w/ shear_periodic or refinements
if (pm->orbital_advection==1) { // first order splitting
nstages = nstages_main+1;
for (int l=0; l<nstages; l++) {
if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].ebeta = 0.0;
}
stage_wghts[l].sbeta = 0.0;
}
stage_wghts[0].beta = 1.0;
stage_wghts[1].beta = 0.25;
stage_wghts[2].beta = TWO_3RD;
stage_wghts[3].beta = 0.0;
} else { // second order splitting
nstages = nstages_main+2;
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.0;
} else if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
}
}
stage_wghts[0].beta = 0.0;
stage_wghts[1].beta = 1.0;
stage_wghts[2].beta = 0.25;
stage_wghts[3].beta = TWO_3RD;
stage_wghts[4].beta = 0.0;
}
} else { // w/o shear periodic and refinements
if (pm->orbital_advection==1) { // first order splitting
nstages = nstages_main;
for (int l=0; l<nstages; l++) {
stage_wghts[l].main_stage = true;
if (l == nstages-1) { // last stage
stage_wghts[l].orbital_stage = true;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].orbital_stage = false;
stage_wghts[l].ebeta = 0.0;
}
stage_wghts[l].sbeta = 0.0;
}
stage_wghts[0].beta = 1.0;
stage_wghts[1].beta = 0.25;
stage_wghts[2].beta = TWO_3RD;
} else { // second order splitting
nstages = nstages_main+1;
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.0;
} else if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = true;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
}
}
stage_wghts[0].beta = 0.0;
stage_wghts[1].beta = 1.0;
stage_wghts[2].beta = 0.25;
stage_wghts[3].beta = TWO_3RD;
}
}
} else { // w/o orbital advection
nstages = nstages_main;
for (int l=0; l<nstages; l++) {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
}
stage_wghts[0].sbeta = 0.0;
stage_wghts[0].ebeta = 1.0;
stage_wghts[1].sbeta = 1.0;
stage_wghts[1].ebeta = 0.5;
stage_wghts[2].sbeta = 0.5;
stage_wghts[2].ebeta = 1.0;
stage_wghts[0].beta = 1.0;
stage_wghts[1].beta = 0.25;
stage_wghts[2].beta = TWO_3RD;
}
cfl_limit = 1.0; // c_eff = c/nstages = 1/3 (Gottlieb (2009), pg 271)
// set delta and gamma at each stage
int n_main = 0;
for (int n=0; n<nstages; n++) {
if (stage_wghts[n].main_stage) {
if (n_main == 0) {
stage_wghts[n].delta = 1.0;
stage_wghts[n].gamma_1 = 0.0;
stage_wghts[n].gamma_2 = 1.0;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
} else if (n_main == 1) {
stage_wghts[n].delta = 0.0;
stage_wghts[n].gamma_1 = 0.25;
stage_wghts[n].gamma_2 = 0.75;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
} else if (n_main == 2) {
stage_wghts[n].delta = 0.0;
stage_wghts[n].gamma_1 = TWO_3RD;
stage_wghts[n].gamma_2 = ONE_3RD;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
}
}
}
} else if (integrator == "rk4") {
//! \note `integorator == "rk4"`
//! - RK4()4[2S] from Table 2 of Ketcheson (2010)
//! - Non-SSP, explicit four-stage, fourth-order RK
//! - Stability properties are similar to classical (non-SSP) RK4
//! (but ~2x L2 principal error norm).
//! - Refer to Colella (2011) for linear stability analysis of constant
//! coeff. advection of classical RK4 + 4th or 1st order (limiter engaged) fluxes
nstages_main = 4;
cfl_limit = 1.3925; // Colella (2011) eq 101; 1st order flux is most severe constraint
if (ORBITAL_ADVECTION) {
if (pm->orbital_advection==1) { // first order splitting
nstages = nstages_main;
for (int l=0; l<nstages; l++) {
stage_wghts[l].main_stage = true;
if (l == nstages-1) { // last stage
stage_wghts[l].orbital_stage = true;
} else {
stage_wghts[l].orbital_stage = false;
}
}
stage_wghts[0].beta = 1.193743905974738;
stage_wghts[1].beta = 0.099279895495783;
stage_wghts[2].beta = 1.131678018054042;
stage_wghts[3].beta = 0.310665766509336;
} else { // second order splitting
nstages = nstages_main+1;
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
} else if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = true;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
}
}
stage_wghts[0].beta = 0.0;
stage_wghts[1].beta = 1.193743905974738;
stage_wghts[2].beta = 0.099279895495783;
stage_wghts[3].beta = 1.131678018054042;
stage_wghts[4].beta = 0.310665766509336;
}
} else { // w/o orbital advection
nstages = nstages_main;
for (int l=0; l<nstages; l++) {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
}
stage_wghts[0].beta = 1.193743905974738;
stage_wghts[1].beta = 0.099279895495783;
stage_wghts[2].beta = 1.131678018054042;
stage_wghts[3].beta = 0.310665766509336;
}
// set delta and gamma at each stage
int n_main = 0;
for (int n=0; n<nstages; n++) {
if (stage_wghts[n].main_stage) {
if (n_main == 0) {
stage_wghts[n].delta = 1.0;
stage_wghts[n].gamma_1 = 0.0;
stage_wghts[n].gamma_2 = 1.0;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
} else if (n_main == 1) {
stage_wghts[n].delta = 0.217683334308543;
stage_wghts[n].gamma_1 = 0.121098479554482;
stage_wghts[n].gamma_2 = 0.721781678111411;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
} else if (n_main == 2) {
stage_wghts[n].delta = 1.065841341361089;
stage_wghts[n].gamma_1 = -3.843833699660025;
stage_wghts[n].gamma_2 = 2.121209265338722;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
} else if (n_main == 3) {
stage_wghts[n].delta = 0.0;
stage_wghts[n].gamma_1 = 0.546370891121863;
stage_wghts[n].gamma_2 = 0.198653035682705;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
}
}
}
// set sbeta & ebeta
if (ORBITAL_ADVECTION) {
if (pm->orbital_advection==1) { // first order splitting
for (int l=0; l<nstages; l++) {
if (l == nstages-1) { // last stage
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].ebeta = 0.0;
}
stage_wghts[l].sbeta = 0.0;
}
} else { // second order splitting
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].sbeta = 0.0;
} else if (l == nstages-1) { // last stage
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
}
}
}
} else { // w/o orbital advection ///
Real temp = 0.0;
Real temp_prev = 0.0;
stage_wghts[0].sbeta = 0.0;
for (int l=0; l<nstages-1; l++) {
temp_prev = temp;
temp = temp_prev + stage_wghts[l].delta*stage_wghts[l].sbeta;
stage_wghts[l].ebeta = stage_wghts[l].gamma_1*temp_prev
+ stage_wghts[l].gamma_2*temp
+ stage_wghts[l].gamma_3*0.0
+ stage_wghts[l].beta;
stage_wghts[l+1].sbeta = stage_wghts[l].ebeta;
}
stage_wghts[nstages-1].ebeta = 1.0;
}
} else if (integrator == "ssprk5_4") {
//! \note `integrator == "ssprk5_4"`
//! - SSPRK (5,4): Gottlieb (2009) section 3.1; between eq 3.3 and 3.4
//! - Optimal (in error bounds) explicit five-stage, fourth-order SSPRK
//! 3N method, but there is no 3S* formulation due to irregular sparsity
//! of Shu-Osher form matrix, alpha.
//! - Because it is an SSP method, we can use the SSP coefficient c=1.508 to to
//! trivially relate the CFL constraint to the RK1 CFL=1 (for first-order fluxes).
//! - There is no need to perform stability analysis from scratch
//! (unlike e.g. the linear stability analysis for classical/non-SSP RK4 in
//! Colella (2011)).
//! - However, PLM and PPM w/o the limiter engaged are unconditionally unstable
//! under RK1 integration, so the SSP guarantees do not hold for
//! the Athena++ spatial discretizations.
nstages_main = 5;
cfl_limit = 1.508; // (effective SSP coeff = 0.302) Gottlieb (2009) pg 272
if (ORBITAL_ADVECTION) {
if (pm->orbital_advection==1) { // first order splitting
nstages = nstages_main;
for (int l=0; l<nstages; l++) {
stage_wghts[l].main_stage = true;
if (l == nstages-1) { // last stage
stage_wghts[l].orbital_stage = true;
} else {
stage_wghts[l].orbital_stage = false;
}
}
stage_wghts[0].beta = 0.391752226571890;
stage_wghts[1].beta = 0.368410593050371;
stage_wghts[2].beta = 0.251891774271694;
stage_wghts[3].beta = 0.544974750228521;
stage_wghts[4].beta = 0.226007483236906; // F(u^(4)) coeff.
} else { // second order splitting
nstages = nstages_main+1;
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].main_stage = false;
stage_wghts[l].orbital_stage = true;
} else if (l == nstages-1) { // last stage
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = true;
} else {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
}
}
stage_wghts[0].beta = 0.0;
stage_wghts[1].beta = 0.391752226571890;
stage_wghts[2].beta = 0.368410593050371;
stage_wghts[3].beta = 0.251891774271694;
stage_wghts[4].beta = 0.544974750228521;
stage_wghts[5].beta = 0.226007483236906; // F(u^(4)) coeff.
}
} else { // w/o orbital advection
nstages = nstages_main;
for (int l=0; l<nstages; l++) {
stage_wghts[l].main_stage = true;
stage_wghts[l].orbital_stage = false;
}
stage_wghts[0].beta = 0.391752226571890;
stage_wghts[1].beta = 0.368410593050371;
stage_wghts[2].beta = 0.251891774271694;
stage_wghts[3].beta = 0.544974750228521;
stage_wghts[4].beta = 0.226007483236906; // F(u^(4)) coeff.
}
// set delta and gamma at each stage
int n_main = 0;
for (int n=0; n<nstages; n++) {
if (stage_wghts[n].main_stage) {
if (n_main == 0) {
stage_wghts[n].delta = 1.0; // u1 = u^n
stage_wghts[n].gamma_1 = 0.0;
stage_wghts[n].gamma_2 = 1.0;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
} else if (n_main == 1) {
stage_wghts[n].delta = 0.0; // u1 = u^n
stage_wghts[n].gamma_1 = 0.555629506348765;
stage_wghts[n].gamma_2 = 0.444370493651235;
stage_wghts[n].gamma_3 = 0.0;
n_main++;
} else if (n_main == 2) {
stage_wghts[n].delta = 0.517231671970585; // u1 <- (u^n + d*u^(2))
stage_wghts[n].gamma_1 = 0.379898148511597;
stage_wghts[n].gamma_2 = 0.0;
stage_wghts[n].gamma_3 = 0.620101851488403; // u^(n) coeff = u2
n_main++;
} else if (n_main == 3) {
stage_wghts[n].delta = 0.096059710526147; // u1 <- (u^n + d*u^(2) + d'*u^(3))
stage_wghts[n].gamma_1 = 0.821920045606868;
stage_wghts[n].gamma_2 = 0.0;
stage_wghts[n].gamma_3 = 0.178079954393132; // u^(n) coeff = u2
n_main++;
} else if (n_main == 4) {
stage_wghts[n].delta = 0.0;
// 1 ulp lower than Gottlieb u^(4) coeff
stage_wghts[n].gamma_1 = 0.386708617503268;
// u1 <- (u^n + d*u^(2) + d'*u^(3))
stage_wghts[n].gamma_2 = 1.0;
// partial sum from hardcoded extra stage=4
stage_wghts[n].gamma_3 = 1.0;
n_main++;
}
}
}
// set sbeta & ebeta
if (ORBITAL_ADVECTION) {
if (pm->orbital_advection==1) { // first order splitting
for (int l=0; l<nstages; l++) {
if (l == nstages-1) { // last stage
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].ebeta = 0.0;
}
stage_wghts[l].sbeta = 0.0;
}
} else { // second order splitting
for (int l=0; l<nstages; l++) {
if (l == 0) { // first stage
stage_wghts[l].sbeta = 0.0;
} else if (l == nstages-1) { // last stage
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
stage_wghts[l].ebeta = 1.0;
} else {
stage_wghts[l].sbeta = 0.5;
stage_wghts[l-1].ebeta = stage_wghts[l].sbeta;
}
}
}
} else { // w/o orbital advection ///
Real temp = 0.0;
Real temp_prev = 0.0;
stage_wghts[0].sbeta = 0.0;
for (int l=0; l<nstages-1; l++) {
temp_prev = temp;
temp = temp_prev + stage_wghts[l].delta*stage_wghts[l].sbeta;
stage_wghts[l].ebeta = stage_wghts[l].gamma_1*temp_prev
+ stage_wghts[l].gamma_2*temp
+ stage_wghts[l].gamma_3*0.0
+ stage_wghts[l].beta;
stage_wghts[l+1].sbeta = stage_wghts[l].ebeta;
}
stage_wghts[nstages-1].ebeta = 1.0;
}
} else {
std::stringstream msg;
msg << "### FATAL ERROR in TimeIntegratorTaskList constructor" << std::endl
<< "integrator=" << integrator << " not valid time integrator" << std::endl;
ATHENA_ERROR(msg);
}
// Set cfl_number based on user input and time integrator CFL limit
Real cfl_number = pin->GetReal("time", "cfl_number");
if (cfl_number > cfl_limit
&& pm->fluid_setup == FluidFormulation::evolve) {
std::cout << "### Warning in TimeIntegratorTaskList constructor" << std::endl
<< "User CFL number " << cfl_number << " must be smaller than " << cfl_limit
<< " for integrator=" << integrator << " in " << pm->ndim
<< "D simulation" << std::endl << "Setting to limit" << std::endl;
cfl_number = cfl_limit;
}
// Save to Mesh class
pm->cfl_number = cfl_number;
// Now assemble list of tasks for each stage of time integrator
{using namespace HydroIntegratorTaskNames; // NOLINT (build/namespace)
// calculate hydro/field diffusive fluxes
if (!STS_ENABLED) {
AddTask(DIFFUSE_HYD,NONE);
if (MAGNETIC_FIELDS_ENABLED) {
AddTask(DIFFUSE_FLD,NONE);
// compute hydro fluxes, integrate hydro variables
AddTask(CALC_HYDFLX,(DIFFUSE_HYD|DIFFUSE_FLD));
} else { // Hydro
AddTask(CALC_HYDFLX,DIFFUSE_HYD);
}
if (NSCALARS > 0) {
AddTask(DIFFUSE_SCLR,NONE);
AddTask(CALC_SCLRFLX,(CALC_HYDFLX|DIFFUSE_SCLR));
}
} else { // STS enabled:
AddTask(CALC_HYDFLX,NONE);
if (NSCALARS > 0)
AddTask(CALC_SCLRFLX,CALC_HYDFLX);
}
if (pm->multilevel || SHEAR_PERIODIC) { // SMR or AMR or shear periodic
AddTask(SEND_HYDFLX,CALC_HYDFLX);
AddTask(RECV_HYDFLX,CALC_HYDFLX);
if (SHEAR_PERIODIC) {
AddTask(SEND_HYDFLXSH,RECV_HYDFLX);
AddTask(RECV_HYDFLXSH,(SEND_HYDFLX|RECV_HYDFLX));
AddTask(INT_HYD,RECV_HYDFLXSH);
} else {
AddTask(INT_HYD,RECV_HYDFLX);
}
} else {
AddTask(INT_HYD, CALC_HYDFLX);
}
if (radiation_flag) {
AddTask(CALC_RADFLX,NONE);
if (pm->multilevel || SHEAR_PERIODIC) { // SMR or AMR or shear periodic
AddTask(SEND_RADFLX,CALC_RADFLX);
AddTask(RECV_RADFLX,CALC_RADFLX);
if (SHEAR_PERIODIC) {
AddTask(SEND_RADFLXSH,RECV_RADFLX);
AddTask(RECV_RADFLXSH,(SEND_RADFLX|RECV_RADFLX));
AddTask(INT_RAD,RECV_RADFLXSH);
} else {
AddTask(INT_RAD,RECV_RADFLX);
}
} else {
AddTask(INT_RAD, CALC_RADFLX);
}
AddTask(SRCTERM_RAD,INT_RAD);
AddTask(SEND_RAD,SRCTERM_RAD);
AddTask(RECV_RAD,NONE);
AddTask(SETB_RAD,(RECV_RAD|SRCTERM_RAD));
}
if (CR_ENABLED) {
AddTask(CALC_CRTCFLX,NONE);
if (pm->multilevel) { // SMR or AMR
AddTask(SEND_CRTCFLX,CALC_CRTCFLX);
AddTask(RECV_CRTCFLX,CALC_CRTCFLX);
AddTask(INT_CRTC,RECV_CRTCFLX);
} else {
AddTask(INT_CRTC, CALC_CRTCFLX);
}
AddTask(SRCTERM_CRTC,INT_CRTC);
AddTask(SEND_CRTC,SRCTERM_CRTC);
AddTask(RECV_CRTC,NONE);
AddTask(SETB_CRTC,(RECV_CRTC|SRCTERM_CRTC));
}
if (NSCALARS > 0) {
AddTask(SRC_TERM,(INT_HYD|INT_SCLR|INT_CHM));
} else {
AddTask(SRC_TERM,INT_HYD);
}
// Hydro will also be updated with radiation source term
TaskID src_aterm = SRC_TERM;
if (radiation_flag)
src_aterm = (src_aterm | SRCTERM_RAD);
if (CR_ENABLED)
src_aterm = (src_aterm | SRCTERM_CRTC);
if (ORBITAL_ADVECTION) {
AddTask(SEND_HYDORB,src_aterm);
AddTask(RECV_HYDORB,NONE);
AddTask(CALC_HYDORB,(SEND_HYDORB|RECV_HYDORB));
AddTask(SEND_HYD,CALC_HYDORB);
AddTask(RECV_HYD,NONE);
AddTask(SETB_HYD,(RECV_HYD|CALC_HYDORB));
} else {
AddTask(SEND_HYD,src_aterm);
AddTask(RECV_HYD,NONE);
AddTask(SETB_HYD,(RECV_HYD|SRC_TERM));