forked from AMReX-Astro/Castro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCastro.cpp
More file actions
4604 lines (3534 loc) · 135 KB
/
Castro.cpp
File metadata and controls
4604 lines (3534 loc) · 135 KB
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
#ifndef WIN32
#include <unistd.h>
#endif
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <iostream>
#include <string>
#include <ctime>
#include <memory>
#include <AMReX_Utility.H>
#include <AMReX_CONSTANTS.H>
#include <Castro.H>
#include <global.H>
#include <runtime_parameters.H>
#include <AMReX_VisMF.H>
#include <AMReX_TagBox.H>
#include <AMReX_FillPatchUtil.H>
#include <AMReX_ParmParse.H>
#ifdef RADIATION
#include <Radiation.H>
#endif
#ifdef AMREX_PARTICLES
#include <AMReX_Particles.H>
#endif
#ifdef GRAVITY
#include <Gravity.H>
#endif
#ifdef DIFFUSION
#include <Diffusion.H>
#endif
#ifdef AMREX_USE_OMP
#include <omp.h>
#endif
#include <extern_parameters.H>
#include <prob_parameters.H>
#include <problem_initialize.H>
#include <problem_initialize_state_data.H>
#ifdef MHD
#include <problem_initialize_mhd_data.H>
#endif
#ifdef RADIATION
#include <problem_initialize_rad_data.H>
#endif
#include <problem_tagging.H>
#include <ambient.H>
#include <castro_limits.H>
#include <riemann_constants.H>
using namespace amrex;
bool Castro::signalStopJob = false;
#ifdef REACTIONS
std::vector<std::string> Castro::burn_weight_names;
#endif
std::vector<std::string> Castro::err_list_names;
std::vector<int> Castro::err_list_ng;
int Castro::num_err_list_default = 0;
int Castro::radius_grow = 1;
BCRec Castro::phys_bc;
int Castro::lastDtPlotLimited = 0;
Real Castro::lastDtBeforePlotLimiting = 0.0;
params_t Castro::params;
Real Castro::num_zones_advanced = 0.0;
Vector<std::string> Castro::source_names;
Vector<AMRErrorTag> Castro::error_tags;
Vector<std::unique_ptr<std::fstream>> Castro::data_logs;
Vector<std::unique_ptr<std::fstream>> Castro::problem_data_logs;
#ifdef TRUE_SDC
int Castro::SDC_NODES;
Vector<Real> Castro::dt_sdc;
Vector<Real> Castro::node_weights;
#endif
#ifdef GRAVITY
// the gravity object
Gravity* Castro::gravity = nullptr;
#endif
#ifdef DIFFUSION
// the diffusion object
Diffusion* Castro::diffusion = nullptr;
#endif
#ifdef RADIATION
// the radiation object
Radiation* Castro::radiation = nullptr;
#endif
#if AMREX_SPACEDIM == 1
#ifndef AMREX_USE_GPU
IntVect Castro::hydro_tile_size(1024);
#else
IntVect Castro::hydro_tile_size(1048576);
#endif
IntVect Castro::no_tile_size(1024);
#elif AMREX_SPACEDIM == 2
#ifndef AMREX_USE_GPU
IntVect Castro::hydro_tile_size(1024,16);
#else
IntVect Castro::hydro_tile_size(1048576,1048576);
#endif
IntVect Castro::no_tile_size(1024,1024);
#else
#ifndef AMREX_USE_GPU
IntVect Castro::hydro_tile_size(1024,16,16);
#else
IntVect Castro::hydro_tile_size(1048576,1048576,1048576);
#endif
IntVect Castro::no_tile_size(1024,1024,1024);
#endif
// this records whether we have done tuning on the hydro tile size
int Castro::hydro_tile_size_has_been_tuned = 0;
Long Castro::largest_box_from_hydro_tile_size_tuning = 0;
// this will be reset upon restart
Real Castro::previousCPUTimeUsed = 0.0;
Real Castro::startCPUTime = 0.0;
int Castro::SDC_Source_Type = -1;
int Castro::num_state_type = 0;
int Castro::do_cxx_prob_initialize = 0;
// Castro::variableSetUp is in Castro_setup.cpp
// variableCleanUp is called once at the end of a simulation
void
Castro::variableCleanUp ()
{
#ifdef GRAVITY
if (gravity != nullptr) {
if (verbose > 1 && ParallelDescriptor::IOProcessor()) {
std::cout << "Deleting gravity in variableCleanUp..." << '\n';
}
delete gravity;
gravity = nullptr;
}
#endif
#ifdef DIFFUSION
if (diffusion != nullptr) {
if (verbose > 1 && ParallelDescriptor::IOProcessor()) {
std::cout << "Deleting diffusion in variableCleanUp..." << '\n';
}
delete diffusion;
diffusion = nullptr;
}
#endif
#ifdef RADIATION
if (radiation != nullptr) {
int report = (verbose || radiation->verbose);
if (report && ParallelDescriptor::IOProcessor()) {
std::cout << "Deleting radiation in variableCleanUp..." << '\n';
}
delete radiation;
radiation = nullptr;
if (report && ParallelDescriptor::IOProcessor()) {
std::cout << " done" << std::endl;
}
}
#endif
#ifdef AMREX_PARTICLES
delete TracerPC;
TracerPC = 0;
#endif
desc_lst.clear();
// C++ cleaning
eos_finalize();
}
void
Castro::read_params ()
{
static bool done = false;
if (done) {
return;
}
done = true;
// this gets all of the parameters defined in _cpp_params, regardless of
// namespace
initialize_cpp_runparams();
ParmParse pp("castro");
ParmParse ppa("amr");
using namespace castro;
// Get boundary conditions
Vector<int> lo_bc(AMREX_SPACEDIM), hi_bc(AMREX_SPACEDIM);
pp.getarr("lo_bc",lo_bc,0,AMREX_SPACEDIM);
pp.getarr("hi_bc",hi_bc,0,AMREX_SPACEDIM);
for (int i = 0; i < AMREX_SPACEDIM; i++)
{
phys_bc.setLo(i,lo_bc[i]);
phys_bc.setHi(i,hi_bc[i]);
}
const Geometry& dgeom = DefaultGeometry();
//
// Check phys_bc against possible periodic geometry
// if periodic, must have internal BC marked.
//
if (dgeom.isAnyPeriodic())
{
//
// Do idiot check. Periodic means interior in those directions.
//
for (int dir = 0; dir<AMREX_SPACEDIM; dir++)
{
if (dgeom.isPeriodic(dir))
{
if (lo_bc[dir] != amrex::PhysBCType::interior)
{
std::cerr << "Castro::read_params:periodic in direction "
<< dir
<< " but low BC is not Interior\n";
amrex::Error();
}
if (hi_bc[dir] != amrex::PhysBCType::interior)
{
std::cerr << "Castro::read_params:periodic in direction "
<< dir
<< " but high BC is not Interior\n";
amrex::Error();
}
}
}
}
else
{
//
// Do idiot check. If not periodic, should be no interior.
//
for (int dir=0; dir<AMREX_SPACEDIM; dir++)
{
if (lo_bc[dir] == amrex::PhysBCType::interior)
{
std::cerr << "Castro::read_params:interior bc in direction "
<< dir
<< " but not periodic\n";
amrex::Error();
}
if (hi_bc[dir] == amrex::PhysBCType::interior)
{
std::cerr << "Castro::read_params:interior bc in direction "
<< dir
<< " but not periodic\n";
amrex::Error();
}
}
}
if ( dgeom.IsRZ() && (lo_bc[0] != amrex::PhysBCType::symmetry) ) {
std::cerr << "ERROR:Castro::read_params: must set r=0 boundary condition to Symmetry for r-z\n";
amrex::Error();
}
#if (AMREX_SPACEDIM == 1)
if ( dgeom.IsSPHERICAL() )
{
if ( (lo_bc[0] != amrex::PhysBCType::symmetry) && (dgeom.ProbLo(0) == 0.0) )
{
std::cerr << "ERROR:Castro::read_params: must set r=0 boundary condition to Symmetry for spherical\n";
amrex::Error();
}
}
#elif (AMREX_SPACEDIM == 2)
if ( dgeom.IsSPHERICAL() )
{
if ( (lo_bc[1] != amrex::PhysBCType::symmetry) && (dgeom.ProbLo(1) == 0.0) )
{
std::cerr << "ERROR:Castro::read_params: must set theta=0 boundary condition to Symmetry for spherical\n";
amrex::Error();
}
if ( (hi_bc[1] != amrex::PhysBCType::symmetry) && (std::abs(dgeom.ProbHi(1) - M_PI) <= 1.e-4_rt) )
{
std::cerr << "ERROR:Castro::read_params: must set theta=pi boundary condition to Symmetry for spherical\n";
amrex::Error();
}
if ( (dgeom.ProbLo(1) < 0.0_rt) && (dgeom.ProbHi(1) > M_PI) )
{
amrex::Abort("ERROR:Castro::read_params: Theta must be within [0, Pi] for spherical coordinate system in 2D");
}
Vector<int> n_cell(AMREX_SPACEDIM);
ppa.queryarr("n_cell",n_cell,0,AMREX_SPACEDIM);
Real ngrow_size = static_cast<Real>(NUM_GROW) * (dgeom.ProbHi(0) - dgeom.ProbLo(0)) / static_cast<Real>(n_cell[0]);
if ( dgeom.ProbLo(0) < ngrow_size )
{
amrex::Abort("ERROR:Castro::read_params: R-min must be large enough so ghost cells doesn't extend to negative R");
}
}
#elif (AMREX_SPACEDIM == 3)
if ( dgeom.IsRZ() )
{
amrex::Abort("We don't support cylindrical coordinate systems in 3D");
}
else if ( dgeom.IsSPHERICAL() )
{
amrex::Abort("We don't support spherical coordinate systems in 3D");
}
#endif
#ifdef HYBRID_MOMENTUM
// We do not support hybrid advection when using the HLLC solver.
if (riemann_solver == 2) {
amrex::Abort("HLLC Riemann solver unsupported when using hybrid momentum.");
}
#endif
// sanity checks
if (grown_factor < 1) {
amrex::Error("grown_factor must be integer >= 1");
}
if (cfl <= 0.0 || cfl > 1.0) {
amrex::Error("Invalid CFL factor; must be between zero and one.");
}
// SDC does not support GPUs yet
#ifdef AMREX_USE_GPU
if (time_integration_method == SpectralDeferredCorrections) {
amrex::Error("SDC is currently not enabled on GPUs.");
}
#endif
// Simplified SDC currently requires USE_SIMPLIFIED_SDC to be defined.
// Also, if we have USE_SIMPLIFIED_SDC defined, we can't use the other
// time integration_methods, because only the SDC burner
// interface is available in Microphysics in this case.
#ifndef SIMPLIFIED_SDC
if (time_integration_method == SimplifiedSpectralDeferredCorrections) {
amrex::Error("Simplified SDC currently requires USE_SIMPLIFIED_SDC=TRUE when compiling.");
}
#else
if (time_integration_method != SimplifiedSpectralDeferredCorrections) {
amrex::Error("When building with USE_SIMPLIFIED_SDC=TRUE, only simplified SDC can be used.");
}
#endif
#ifdef TRUE_SDC
int max_level;
ppa.query("max_level", max_level);
if (max_level > 0) {
amrex::Error("True SDC does not work with AMR.");
}
#endif
#ifndef TRUE_SDC
if (time_integration_method == SpectralDeferredCorrections) {
amrex::Error("True SDC currently requires USE_TRUE_SDC=TRUE when compiling.");
}
#else
if (time_integration_method != SpectralDeferredCorrections) {
amrex::Error("When building with USE_TRUE_SDC=TRUE, only true SDC can be used.");
}
#endif
#ifndef AMREX_USE_GPU
#ifdef RADIATION
if (hybrid_riemann == 1) {
amrex::Error("ERROR: hybrid Riemann not supported for radiation");
}
if (riemann_solver > 0) {
amrex::Error("ERROR: only the CGF Riemann solver is supported for radiation");
}
#endif
#if AMREX_SPACEDIM == 1
if (riemann_solver > 1) {
amrex::Error("ERROR: HLLC not implemented for 1-d");
}
#endif
#ifndef SHOCK_VAR
if (disable_shock_burning != 0) {
amrex::Error("ERROR: disable_shock_burning requires compiling with USE_SHOCK_VAR=TRUE");
}
#endif
if (riemann_solver == 1) {
if (riemann_shock_maxiter > riemann_constants::HISTORY_SIZE) {
amrex::Error("riemann_shock_maxiter > HISTORY_SIZE");
}
if (riemann_cg_blend == 2 && riemann_shock_maxiter < 5) {
amrex::Error("Error: need riemann_shock_maxiter >= 5 to do a bisection search on secant iteration failure.");
}
}
#endif
if (hybrid_riemann && AMREX_SPACEDIM == 1)
{
std::cerr << "hybrid_riemann only implemented in 2- and 3-d\n";
amrex::Error();
}
if (hybrid_riemann && (dgeom.IsSPHERICAL() || dgeom.IsRZ() ))
{
std::cerr << "hybrid_riemann should only be used for Cartesian coordinates\n";
amrex::Error();
}
// Make sure not to call refluxing if we're not actually doing any hydro.
if (!do_hydro) {
do_reflux = false;
}
if (max_dt < fixed_dt)
{
std::cerr << "cannot have max_dt < fixed_dt\n";
amrex::Error();
}
if (change_max <= 1.0)
{
std::cerr << "change_max must be greater than 1.0\n";
amrex::Error();
}
// This interpolation is not currently implemented for some geometries
if (lin_limit_state_interp == 2) {
if (dgeom.IsSPHERICAL()) {
amrex::Error("lin_limit_state_interp == 2 is not currently implemented for spherical geometries");
}
else if (dgeom.IsRZ()) {
amrex::Error("lim_limit_state_interp == 2 is not currently implemented for cylindrical geometries");
}
}
// Post-timestep regrids only make sense if we're subcycling.
std::string subcycling_mode;
ppa.query("subcycling_mode", subcycling_mode);
if (use_post_step_regrid == 1 && subcycling_mode == "None") {
amrex::Error("castro.use_post_step_regrid == 1 is not consistent with amr.subcycling_mode = None.");
}
#ifdef AMREX_PARTICLES
read_particle_params();
#endif
#ifdef RADIATION
// Some radiation parameters are initialized here because they
// may be used in variableSetUp, well before the call to the
// Radiation constructor,
if (do_radiation == 1) {
Radiation::read_static_params();
}
// radiation is only supported with CTU
if (do_radiation && time_integration_method != CornerTransportUpwind) {
amrex::Error("Radiation is currently only supported for CTU time advancement.");
}
#endif
#ifdef ROTATION
if (do_rotation == 1) {
if (rotational_period <= 0.0) {
std::cerr << "Error:Castro::Rotation enabled but rotation period less than zero\n";
amrex::Error();
}
}
if (dgeom.IsRZ() == 1) {
rot_axis = 2;
}
#if (AMREX_SPACEDIM == 1)
if (do_rotation == 1) {
std::cerr << "ERROR:Castro::Rotation not implemented in 1d\n";
amrex::Error();
}
#endif
#endif
#ifdef SPONGE
if (do_sponge == 1) {
if (sponge_timescale <= 0.0) {
amrex::Error("If using the sponge, the sponge_timescale must be positive.");
}
if (amrex::max(sponge_upper_radius, sponge_upper_density, sponge_upper_pressure) < 0.0) {
amrex::Error("If using the sponge, at least one of the upper radius, density, "
"or pressure must be non-negative.");
}
if (amrex::max(sponge_lower_radius, sponge_lower_density, sponge_lower_pressure) < 0.0) {
amrex::Error("If using the sponge, at least one of the lower radius, density, "
"or pressure must be non-negative.");
}
}
#endif
// SCF initial model construction can only be done if both
// rotation and gravity have been compiled in.
#if !defined(GRAVITY) || !defined(ROTATION)
if (do_scf_initial_model) {
amrex::Error("SCF initial model construction is only permitted if USE_GRAV=TRUE and USE_ROTATION=TRUE at compile time.");
}
#endif
StateDescriptor::setBndryFuncThreadSafety(bndry_func_thread_safe);
// Open up Castro data logs
// Note that this functionality also exists in the Amr class
// but we implement it on our own to have a little more control.
// Some of these will only be filled for certain ifdefs, but
// we should use consistent indexing regardless of ifdefs (so some
// logs may be unused in a given run).
if (sum_interval > 0 && ParallelDescriptor::IOProcessor()) {
data_logs.resize(4);
data_logs[0] = std::make_unique<std::fstream>();
data_logs[0]->open("grid_diag.out", std::ios::out | std::ios::app);
if (!data_logs[0]->good()) {
amrex::FileOpenFailed("grid_diag.out");
}
data_logs[1] = std::make_unique<std::fstream>();
#ifdef GRAVITY
data_logs[1]->open("gravity_diag.out", std::ios::out | std::ios::app);
if (!data_logs[1]->good()) {
amrex::FileOpenFailed("gravity_diag.out");
}
#endif
data_logs[2] = std::make_unique<std::fstream>();
data_logs[2]->open("species_diag.out", std::ios::out | std::ios::app);
if (!data_logs[2]->good()) {
amrex::FileOpenFailed("species_diag.out");
}
data_logs[3] = std::make_unique<std::fstream>();
data_logs[3]->open("amr_diag.out", std::ios::out | std::ios::app);
if (!data_logs[3]->good()) {
amrex::FileOpenFailed("amr_diag.out");
}
}
Vector<int> tilesize(AMREX_SPACEDIM);
if (pp.queryarr("hydro_tile_size", tilesize, 0, AMREX_SPACEDIM))
{
for (int i=0; i<AMREX_SPACEDIM; i++) {
hydro_tile_size[i] = tilesize[i];
}
}
// Override Amr defaults. Note: this function is called after Amr::Initialize()
// in Amr::InitAmr(), right before the ParmParse checks, so if the user opts to
// override our overriding, they can do so.
Amr::setComputeNewDtOnRegrid(true);
// Read in custom refinement scheme.
Vector<std::string> refinement_indicators;
ppa.queryarr("refinement_indicators", refinement_indicators, 0, ppa.countval("refinement_indicators"));
for (const auto & ref_indicator : refinement_indicators) {
std::string ref_prefix = "amr.refine." + ref_indicator;
ParmParse ppr(ref_prefix);
AMRErrorTagInfo info;
if (ppr.countval("start_time") > 0) {
Real min_time;
ppr.get("start_time", min_time);
info.SetMinTime(min_time);
}
if (ppr.countval("end_time") > 0) {
Real max_time;
ppr.get("end_time", max_time);
info.SetMaxTime(max_time);
}
if (ppr.countval("max_level") > 0) {
int max_level;
ppr.get("max_level", max_level);
BL_ASSERT(max_level <= MAX_LEV);
info.SetMaxLevel(max_level);
} else {
// the default max_level of AMRErrorTagInfo is 1000, but make sure
// that it is reasonable for Castro
info.SetMaxLevel(MAX_LEV);
}
if (ppr.countval("volume_weighting") > 0) {
int volume_weighting;
ppr.get("volume_weighting", volume_weighting);
info.SetVolumeWeighting(volume_weighting);
}
if (ppr.countval("derefine") > 0) {
int derefine;
ppr.get("derefine", derefine);
info.SetDerefine(derefine);
}
if (ppr.countval("value_greater")) {
Vector<Real> value;
ppr.getarr("value_greater", value, 0, ppr.countval("value_greater"));
std::string field;
ppr.get("field_name", field);
error_tags.emplace_back(value, AMRErrorTag::GREATER, field, info);
}
else if (ppr.countval("value_less")) {
Vector<Real> value;
ppr.getarr("value_less", value, 0, ppr.countval("value_less"));
std::string field;
ppr.get("field_name", field);
error_tags.emplace_back(value, AMRErrorTag::LESS, field, info);
}
else if (ppr.countval("gradient")) {
Vector<Real> value;
ppr.getarr("gradient", value, 0, ppr.countval("gradient"));
std::string field;
ppr.get("field_name", field);
error_tags.emplace_back(value, AMRErrorTag::GRAD, field, info);
}
else if (ppr.countval("relative_gradient")) {
Vector<Real> value;
ppr.getarr("relative_gradient", value, 0, ppr.countval("relative_gradient"));
std::string field;
ppr.get("field_name", field);
error_tags.emplace_back(value, AMRErrorTag::RELGRAD, field, info);
}
else {
amrex::Abort("Unrecognized refinement indicator for " + ref_indicator);
}
}
}
Castro::Castro ()
:
prev_state(num_state_type)
{
}
Castro::Castro (Amr& papa,
int lev,
const Geometry& level_geom,
const BoxArray& bl,
const DistributionMapping& dm,
Real time)
:
AmrLevel(papa,lev,level_geom,bl,dm,time),
prev_state(num_state_type)
{
BL_PROFILE("Castro::Castro()");
MultiFab::RegionTag amrlevel_tag("AmrLevel_Level_" + std::to_string(lev));
buildMetrics();
initMFs();
// Coterminous AMR boundaries are not supported in Castro if we're doing refluxing.
if (do_hydro == 1 && do_reflux == 1) {
for (int ilev = 0; ilev <= parent->maxLevel(); ++ilev) {
if (parent->nErrorBuf(ilev) == 0) {
amrex::Error("n_error_buf = 0 is unsupported when using hydro.");
}
}
}
// initialize all the new time level data to zero
for (int k = 0; k < num_state_type; k++) {
MultiFab& data = get_new_data(k);
data.setVal(0.0, data.nGrow());
}
#ifdef GRAVITY
if (do_grav == 1) {
// gravity is a static object, only alloc if not already there
if (gravity == nullptr) {
gravity = new Gravity(parent,parent->finestLevel(),&phys_bc, URHO);
}
// Passing numpts_1d at level 0
if (!level_geom.isAllPeriodic() && gravity != nullptr)
{
int numpts_1d = get_numpts();
// For 1D, we need to add ghost cells to the numpts
// given to us by Castro.
#if (AMREX_SPACEDIM == 1)
numpts_1d += 2 * NUM_GROW;
#endif
gravity->set_numpts_in_gravity(numpts_1d);
}
gravity->install_level(level,this,volume,area.data());
if (verbose && level == 0 && ParallelDescriptor::IOProcessor()) {
std::cout << "Setting the gravity type to " << gravity->get_gravity_type() << std::endl;
}
}
#endif
#ifdef DIFFUSION
// diffusion is a static object, only alloc if not already there
if (diffusion == nullptr) {
diffusion = new Diffusion(parent,&phys_bc);
}
diffusion->install_level(level,this,volume,area.data());
#endif
#ifdef RADIATION
if (do_radiation) {
if (radiation == nullptr) {
// radiation is a static object, only alloc if not already there
radiation = new Radiation(parent, this);
global::the_radiation_ptr = radiation;
}
radiation->regrid(level, grids, dmap);
rad_solver = std::make_unique<RadSolve>(parent, level, grids, dmap);
}
#endif
// now check the runtime parameters to warn / abort if the user set
// anything that isn't known to Castro
validate_runparams();
}
Castro::~Castro () // NOLINT(modernize-use-equals-default)
{
#ifdef RADIATION
if (radiation != nullptr) {
//radiation->cleanup(level);
radiation->close(level);
}
#endif
}
void
Castro::buildMetrics ()
{
BL_PROFILE("Castro::buildMetrics()");
const int ngrd = static_cast<int>(grids.size());
radius.resize(ngrd);
const Real* dx = geom.CellSize();
for (int i = 0; i < ngrd; i++)
{
const Box& b = grids[i];
int ilo = b.smallEnd(0)-radius_grow;
int ihi = b.bigEnd(0)+radius_grow;
int len = ihi - ilo + 1;
radius[i].resize(len);
Real* rad = radius[i].dataPtr();
if (Geom().IsCartesian())
{
for (int j = 0; j < len; j++)
{
rad[j] = 1.0;
}
}
else
{
RealBox gridloc = RealBox(grids[i],geom.CellSize(),geom.ProbLo());
const Real xlo = gridloc.lo(0) + (0.5 - radius_grow)*dx[0];
for (int j = 0; j < len; j++)
{
rad[j] = xlo + j*dx[0];
}
}
}
volume.clear();
volume.define(grids,dmap,1,NUM_GROW);
geom.GetVolume(volume);
for (int dir = 0; dir < AMREX_SPACEDIM; dir++)
{
area[dir].clear();
area[dir].define(getEdgeBoxArray(dir),dmap,1,NUM_GROW);
geom.GetFaceArea(area[dir],dir);
}
for (int dir = AMREX_SPACEDIM; dir < 3; dir++)
{
area[dir].clear();
area[dir].define(grids, dmap, 1, 0);
area[dir].setVal(0.0);
}
#if (AMREX_SPACEDIM <= 2)
for (int dir = 0; dir < AMREX_SPACEDIM; dir++)
{
dLogArea[dir].clear();
geom.GetDLogA(dLogArea[dir],grids,dmap,dir,NUM_GROW);
}
#if (AMREX_SPACEDIM == 1)
dLogArea[1].clear();
dLogArea[1].define(grids, dmap, 1, 0);
dLogArea[1].setVal(0.0);
#endif
#endif
wall_time_start = 0.0;
}
// Initialize the MultiFabs and flux registers that live as class members.
void
Castro::initMFs()
{
BL_PROFILE("Castro::initMFs()");
fluxes.resize(3);
for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
fluxes[dir] = std::make_unique<MultiFab>(MultiFab(getEdgeBoxArray(dir), dmap, NUM_STATE, 0));
}
for (int dir = AMREX_SPACEDIM; dir < 3; ++dir) {
fluxes[dir] = std::make_unique<MultiFab>(MultiFab(get_new_data(State_Type).boxArray(), dmap, NUM_STATE, 0));
}
mass_fluxes.resize(3);
for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
mass_fluxes[dir] = std::make_unique<MultiFab>(MultiFab(getEdgeBoxArray(dir), dmap, 1, 0));
}
for (int dir = AMREX_SPACEDIM; dir < 3; ++dir) {
mass_fluxes[dir] = std::make_unique<MultiFab>(MultiFab(get_new_data(State_Type).boxArray(), dmap, 1, 0));
}
#if (AMREX_SPACEDIM <= 2)
if (!Geom().IsCartesian()) {
P_radial.define(getEdgeBoxArray(0), dmap, 1, 0);
}
#endif
#ifdef RADIATION
if (Radiation::rad_hydro_combined) {
rad_fluxes.resize(AMREX_SPACEDIM);
for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
rad_fluxes[dir] = std::make_unique<MultiFab>(MultiFab(getEdgeBoxArray(dir), dmap, Radiation::nGroups, 0));
}
}
#endif
if (do_reflux && level > 0) {
flux_reg.define(grids, dmap, crse_ratio, level, NUM_STATE);
flux_reg.setVal(0.0);
#if (AMREX_SPACEDIM < 3)
if (!Geom().IsCartesian()) {
pres_reg.define(grids, dmap, crse_ratio, level, 1);
pres_reg.setVal(0.0);
}
#endif
#ifdef RADIATION
if (Radiation::rad_hydro_combined) {
rad_flux_reg.define(grids, dmap, crse_ratio, level, Radiation::nGroups);
rad_flux_reg.setVal(0.0);
}
#endif
#ifdef GRAVITY
if (do_grav && gravity->get_gravity_type() == "PoissonGrav" && gravity->NoSync() == 0) {
phi_reg.define(grids, dmap, crse_ratio, level, 1);
phi_reg.setVal(0.0);
}
#endif
}
#ifdef REACTIONS
if (store_burn_weights) {
if (castro::time_integration_method == CornerTransportUpwind) {
// we have 2 components: first half and second half
burn_weights.define(grids, dmap, 2, 0);
}
else if (castro::time_integration_method == SimplifiedSpectralDeferredCorrections) {
// we have a component for each sdc iteration + 1 extra for retries
burn_weights.define(grids, dmap, sdc_iters+1, 0);
}
burn_weights.setVal(0.0);
}
#endif
// Set the flux register scalings.
if (do_reflux) {
flux_crse_scale = -1.0;
flux_fine_scale = 1.0;
// The fine pressure scaling depends on dimensionality,
// as the dimensionality determines the number of
// adjacent zones. In 1D the face is a point so
// there's only one fine neighbor for a given coarse
// face; in 2D there's crse_ratio[1] faces adjacent
// to a face perpendicular to the radial dimension;
// and in 3D there would be crse_ratio**2, though
// we do not separate the pressure out in 3D. Note
// that the scaling by dt has already been handled
// in the construction of the P_radial array.
// The coarse pressure scaling is the same as for the
// fluxes, we want the total refluxing contribution
// over the full set of fine timesteps to equal P_radial.
#if (AMREX_SPACEDIM == 1)
pres_crse_scale = -1.0;
pres_fine_scale = 1.0;
#elif (AMREX_SPACEDIM == 2)
pres_crse_scale = -1.0;
pres_fine_scale = 1.0 / crse_ratio[1];
#endif
}
post_step_regrid = 0;
lastDt = 1.e200;
if (do_cxx_prob_initialize == 0) {
// sync up some C++ values of the runtime parameters
do_cxx_prob_initialize = 1;
// If we're doing C++ problem initialization, do it here. We have to make
// sure it's done after the above call to init_prob_parameters() in case
// any changes are made to the problem parameters.
problem_initialize();