26 BL_PROFILE(
"Integrator::Integrator()");
45 pp.
query_default(
"compression_level", value.compression_level,
"6");
52 pp.
query_default(
"amr.base_regrid_int", value.base_regrid_int, 0);
65 pp.
query_default(
"amr.abort_on_nan",value.abort_on_nan,
true);
70 pp.
query_default(
"amr.max_plot_level", value.max_plot_level, -1);
72 pp.
query_default(
"amr.print_ghost_nodes", value.print_ghost_nodes, 0);
73 pp.
query_default(
"amr.print_ghost_cells", value.print_ghost_cells, 0);
77 value.nsubsteps.resize(value.maxLevel() + 1, 1);
78 int cnt = pp.countval(
"amr.nsubsteps");
80 if (cnt == value.maxLevel()) {
81 pp.
queryarr(
"amr.nsubsteps", value.nsubsteps);
82 value.nsubsteps.insert(value.nsubsteps.begin(), 1);
83 value.nsubsteps.pop_back();
89 for (
int lev = 1; lev <= value.maxLevel(); ++lev) value.nsubsteps[lev] = nsubsteps_all;
92 Util::Abort(
INFO,
"number of nsubsteps input must equal either 1 or amr.max_level");
94 for (
int lev = 1; lev <= value.maxLevel(); ++lev)
95 value.nsubsteps[lev] = value.MaxRefRatio(lev - 1);
99 pp.
query_if(
"dynamictimestep.on", [&](){
100 value.dynamictimestep.on =
true;
102 pp.
query_validate(
"dynamictimestep.verbose",value.dynamictimestep.verbose,{0,1});
104 pp.
query_default(
"dynamictimestep.nprevious",value.dynamictimestep.nprevious,5);
106 pp.
query_default(
"dynamictimestep.cfl",value.dynamictimestep.cfl,1.0);
108 pp.
query_default(
"dynamictimestep.min",value.dynamictimestep.min,value.timestep);
110 pp.
query_default(
"dynamictimestep.max",value.dynamictimestep.max,value.timestep);
116 pp.
query_default(
"amr.thermo.int", value.thermo.interval, 1);
117 pp.
query_default(
"amr.thermo.plot_int", value.thermo.plot_int, -1);
124 pp.
query_if(
"explicitmesh.on", [&] () {
125 std::vector<std::vector<int>> los, his;
132 value.explicitmesh.on =
true;
133 for (
int ilev = 0; ilev < value.maxLevel(); ++ilev)
135 amrex::IntVect lo(AMREX_D_DECL(los[ilev][0], los[ilev][1], los[ilev][2]));
136 amrex::IntVect hi(AMREX_D_DECL(his[ilev][0], his[ilev][1], his[ilev][2]));
137 value.explicitmesh.box.push_back(amrex::Box(lo, hi));
153 pp.
query_validate(
"integration.type", str, {
"ForwardEuler",
"RungeKutta"});
155 {
"ForwardEuler", [&]() {}},
156 {
"RungeKutta", [&]() {
164 int nlevs_max = value.maxLevel() + 1;
166 value.istep.resize(nlevs_max, 0);
168 value.t_new.resize(nlevs_max, 0.0);
169 value.t_old.resize(nlevs_max, -1.e100);
170 value.SetTimestep(value.timestep);
533 BL_PROFILE(
"Integrator::Restart");
535 if (a_nodal && node.fab_array.size() == 0)
540 if (!a_nodal && cell.fab_array.size() == 0)
546 std::string filename = dirname +
"/Header";
547 std::string chkptfilename = dirname +
"/Checkpoint";
548 amrex::VisMF::IO_Buffer io_buffer(amrex::VisMF::GetIOBufferSize());
549 amrex::Vector<char> fileCharPtr, chkptfileCharPtr;
550 amrex::ParallelDescriptor::ReadAndBcastFile(filename, fileCharPtr);
551 amrex::ParallelDescriptor::ReadAndBcastFile(chkptfilename, chkptfileCharPtr);
552 std::string fileCharPtrString(fileCharPtr.dataPtr());
553 std::string chkptfileCharPtrString(chkptfileCharPtr.dataPtr());
554 std::istringstream is(fileCharPtrString, std::istringstream::in);
555 std::istringstream chkpt_is(chkptfileCharPtrString, std::istringstream::in);
557 std::string line, word;
560 std::getline(is, line);
565 std::getline(is, line); tmp_numfabs = std::stoi(line);
567 std::vector<std::string> tmp_name_array;
569 for (
int i = 0; i < tmp_numfabs; i++)
571 std::getline(is, line);
572 tmp_name_array.push_back(line);
576 std::getline(is, line);
581 std::getline(is, line); tmp_time = std::stof(line);
Util::Message(
INFO,
"Current time: ", tmp_time);
582 for (
int i = 0; i < max_level + 1; i++)
584 t_new[i] = tmp_time; t_old[i] = tmp_time;
589 std::getline(is, line); tmp_max_level = std::stoi(line);
Util::Message(
INFO,
"Max AMR level: ", line);
590 if (tmp_max_level > max_level)
591 Util::Abort(
INFO,
"The max level specified (", max_level,
") is smaller than the finest level in the restart file (", tmp_max_level,
")");
592 finest_level = tmp_max_level;
604 std::getline(is, line);
606 if (tmp_iters.size() != (
unsigned int)(finest_level + 1))
Util::Abort(
INFO,
"Error reading in interation counts: line = ", line);
607 for (
int lev = 0; lev <= finest_level; lev++) { istep[lev] = std::stoi(tmp_iters[lev]);
Util::Message(
INFO,
"Iter on level ", lev,
" = ", istep[lev]); }
609 amrex::Vector<amrex::MultiFab> tmpdata(tmp_max_level + 1);
614 for (
unsigned int i = 0; i < node.fab_array.size(); i++)
615 if (node.writeout_array[i])
616 total_ncomp += node.ncomp_array[i];
620 for (
unsigned int i = 0; i < cell.fab_array.size(); i++)
621 if (cell.writeout_array[i])
622 total_ncomp += cell.ncomp_array[i];
625 int total_nghost = a_nodal ? 0 : cell.nghost_array[0];
627 for (
int lev = 0; lev <= finest_level; lev++)
629 amrex::BoxArray tmp_ba;
630 tmp_ba.readFrom(chkpt_is);
631 SetBoxArray(lev, tmp_ba);
632 amrex::DistributionMapping tmp_dm(tmp_ba, amrex::ParallelDescriptor::NProcs());
633 SetDistributionMap(lev, tmp_dm);
637 amrex::BoxArray ngrids = grids[lev];
638 ngrids.convert(amrex::IntVect::TheNodeVector());
649 Util::Message(
INFO,amrex::MultiFabFileFullPrefix(lev, dirname,
"Level_",
"Cell"));
652 amrex::VisMF::Read(tmpdata[lev],
653 amrex::MultiFabFileFullPrefix(lev, dirname,
"Level_",
"Cell"));
656 for (
int i = 0; i < node.number_of_fabs; i++)
658 amrex::BoxArray ngrids = grids[lev];
659 ngrids.convert(amrex::IntVect::TheNodeVector());
660 (*node.fab_array[i])[lev].reset(
new amrex::MultiFab(ngrids, dmap[lev], node.ncomp_array[i], node.nghost_array[i]));
661 (*node.fab_array[i])[lev]->setVal(0.);
664 for (
int i = 0; i < cell.number_of_fabs; i++)
665 (*cell.fab_array[i])[lev].reset(
new amrex::MultiFab(grids[lev], dmap[lev], cell.ncomp_array[i], cell.nghost_array[i]));
666 for (
int i = 0; i < tmp_numfabs; i++)
671 for (
int j = 0; j < node.number_of_fabs; j++)
673 if (tmp_name_array[i] == node.name_array[i][j])
676 Util::Message(
INFO,
"Initializing ", node.name_array[i][j],
"; nghost=", node.nghost_array[j],
" with ", tmp_name_array[i]);
677 amrex::MultiFab::Copy(*((*node.fab_array[j])[lev]).get(), tmpdata[lev], i, 0, 1, total_nghost);
679 for (
int k = 0; k < node.ncomp_array[j]; k++)
681 if (tmp_name_array[i] == node.name_array[j][k])
684 Util::Message(
INFO,
"Initializing ", node.name_array[j][k],
"; ncomp=", node.ncomp_array[j],
"; nghost=", node.nghost_array[j],
" with ", tmp_name_array[i]);
685 amrex::MultiFab::Copy(*((*node.fab_array[j])[lev]).get(), tmpdata[lev], i, k, 1, total_nghost);
693 for (
int j = 0; j < cell.number_of_fabs; j++)
695 for (
int k = 0; k < cell.ncomp_array[j]; k++)
697 if (tmp_name_array[i] == cell.name_array[j][k])
700 Util::Message(
INFO,
"Initializing ", cell.name_array[j][k],
"; ncomp=", cell.ncomp_array[j],
"; nghost=", cell.nghost_array[j],
" with ", tmp_name_array[i]);
701 amrex::MultiFab::Copy(*((*cell.fab_array[j])[lev]).get(), tmpdata[lev], i, k, 1, 0 );
707 if (!match)
Util::Warning(
INFO,
"Fab ", tmp_name_array[i],
" is in the restart file, but there is no fab with that name here.");
710 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
712 m_basefields_cell[n]->MakeNewLevelFromScratch(lev, t_new[lev], grids[lev], dmap[lev]);
714 for (
unsigned int n = 0; n < m_basefields.size(); n++)
716 m_basefields[n]->MakeNewLevelFromScratch(lev, t_new[lev], grids[lev], dmap[lev]);
720 for (
int n = 0; n < cell.number_of_fabs; n++)
722 if (cell.writeout_array[n])
723 FillPatch(lev, t_new[lev], *cell.fab_array[n], *(*cell.fab_array[n])[lev], *cell.physbc_array[n], 0);
728 SetFinestLevel(max_level);
815 BL_PROFILE(
"Integrator::WritePlotFile");
816 int nlevels = finest_level + 1;
817 if (max_plot_level >= 0) nlevels = std::min(nlevels, max_plot_level);
819 int ccomponents = 0, ncomponents = 0, bfcomponents_cell = 0, bfcomponents = 0;
820 amrex::Vector<std::string> cnames, nnames, bfnames_cell, bfnames;
821 for (
int i = 0; i < cell.number_of_fabs; i++)
823 if (!cell.writeout_array[i])
continue;
824 ccomponents += cell.ncomp_array[i];
825 if (cell.ncomp_array[i] > 1)
826 for (
int j = 0; j < cell.ncomp_array[i]; j++)
827 cnames.push_back(cell.name_array[i][j]);
829 cnames.push_back(cell.name_array[i][0]);
831 for (
int i = 0; i < node.number_of_fabs; i++)
833 if (!node.writeout_array[i])
continue;
834 ncomponents += node.ncomp_array[i];
835 if (node.ncomp_array[i] > 1)
836 for (
int j = 0; j < node.ncomp_array[i]; j++)
837 nnames.push_back(node.name_array[i][j]);
839 nnames.push_back(node.name_array[i][0]);
841 for (
unsigned int i = 0; i < m_basefields_cell.size(); i++)
843 if (m_basefields_cell[i]->writeout)
845 bfcomponents_cell += m_basefields_cell[i]->NComp();
846 for (
int j = 0; j < m_basefields_cell[i]->NComp(); j++)
847 bfnames_cell.push_back(m_basefields_cell[i]->Name(j));
850 for (
unsigned int i = 0; i < m_basefields.size(); i++)
852 if (m_basefields[i]->writeout)
854 bfcomponents += m_basefields[i]->NComp();
855 for (
int j = 0; j < m_basefields[i]->NComp(); j++)
856 bfnames.push_back(m_basefields[i]->Name(j));
860 amrex::Vector<amrex::MultiFab> cplotmf(nlevels), nplotmf(nlevels);
862 bool do_cell_plotfile = (ccomponents + bfcomponents_cell > 0 || (ncomponents + bfcomponents > 0 && cell.all)) && cell.any;
863 bool do_node_plotfile = (ncomponents + bfcomponents > 0 || (ccomponents + bfcomponents_cell > 0 && node.all)) && node.any;
865 for (
int ilev = 0; ilev < nlevels; ++ilev)
867 if (do_cell_plotfile)
869 int ncomp = ccomponents + bfcomponents_cell;
870 if (cell.all) ncomp += ncomponents + bfcomponents;
871 amrex::BoxArray cgrids_ghost = grids[ilev];
872 cgrids_ghost.grow(print_ghost_cells);
873 cplotmf[ilev].define(cgrids_ghost, dmap[ilev], ncomp, 0);
877 for (
int i = 0; i < cell.number_of_fabs; i++)
879 if (!cell.writeout_array[i])
continue;
880 if ((*cell.fab_array[i])[ilev]->contains_nan())
882 if (abort_on_nan)
Util::Abort(
INFO, cnames[cnames_cnt],
" contains nan (i=", i,
")");
885 if ((*cell.fab_array[i])[ilev]->contains_inf())
887 if (abort_on_nan)
Util::Abort(
INFO, cnames[cnames_cnt],
" contains inf (i=", i,
")");
891 amrex::MultiFab::Copy(cplotmf[ilev], *(*cell.fab_array[i])[ilev], 0, n, cell.ncomp_array[i], 0);
892 n += cell.ncomp_array[i];
894 for (
unsigned int i = 0; i < m_basefields_cell.size(); i++)
896 if (m_basefields_cell[i]->writeout)
898 m_basefields_cell[i]->Copy(ilev, cplotmf[ilev], n, 0);
899 n += m_basefields_cell[i]->NComp();
906 for (
int i = 0; i < node.number_of_fabs; i++)
908 if (!node.writeout_array[i])
continue;
909 if ((*node.fab_array[i])[ilev]->contains_nan())
911 if (abort_on_nan)
Util::Abort(
INFO, nnames[nnames_cnt],
" contains nan (i=", i,
")");
914 if ((*node.fab_array[i])[ilev]->contains_inf())
916 if (abort_on_nan)
Util::Abort(
INFO, nnames[nnames_cnt],
" contains inf (i=", i,
")");
920 amrex::average_node_to_cellcenter(cplotmf[ilev], n, *(*node.fab_array[i])[ilev], 0, node.ncomp_array[i], 0);
921 n += node.ncomp_array[i];
923 if (bfcomponents > 0)
925 amrex::BoxArray ngrids = grids[ilev];
926 ngrids.convert(amrex::IntVect::TheNodeVector());
927 amrex::MultiFab bfplotmf(ngrids, dmap[ilev], bfcomponents, 0);
929 for (
unsigned int i = 0; i < m_basefields.size(); i++)
931 if (m_basefields[i]->writeout)
933 m_basefields[i]->Copy(ilev, bfplotmf, ctr, 0);
934 ctr += m_basefields[i]->NComp();
937 amrex::average_node_to_cellcenter(cplotmf[ilev], n, bfplotmf, 0, bfcomponents);
943 if (do_node_plotfile)
945 amrex::BoxArray ngrids = grids[ilev];
946 ngrids.convert(amrex::IntVect::TheNodeVector());
947 int ncomp = ncomponents + bfcomponents;
948 if (node.all) ncomp += ccomponents + bfcomponents_cell;
950 amrex::BoxArray ngrids_ghost = ngrids;
951 ngrids_ghost.grow(print_ghost_nodes);
953 nplotmf[ilev].define(ngrids_ghost, dmap[ilev], ncomp, 0);
956 for (
int i = 0; i < node.number_of_fabs; i++)
958 if (!node.writeout_array[i])
continue;
959 if ((*node.fab_array[i])[ilev]->contains_nan())
Util::Warning(
INFO, nnames[i],
" contains nan (i=", i,
"). Resetting to zero.");
960 if ((*node.fab_array[i])[ilev]->contains_inf())
Util::Abort(
INFO, nnames[i],
" contains inf (i=", i,
")");
961 amrex::MultiFab::Copy(nplotmf[ilev], *(*node.fab_array[i])[ilev], 0, n, node.ncomp_array[i], 0);
962 n += node.ncomp_array[i];
964 for (
unsigned int i = 0; i < m_basefields.size(); i++)
966 if (m_basefields[i]->writeout)
968 m_basefields[i]->Copy(ilev, nplotmf[ilev], n, 0);
969 n += m_basefields[i]->NComp();
975 for (
int i = 0; i < cell.number_of_fabs; i++)
977 if (!cell.writeout_array[i])
continue;
978 if ((*cell.fab_array[i])[ilev]->contains_nan())
Util::Warning(
INFO, cnames[i],
" contains nan (i=", i,
"). Resetting to zero.");
979 if ((*cell.fab_array[i])[ilev]->contains_inf())
Util::Abort(
INFO, cnames[i],
" contains inf (i=", i,
")");
980 if ((*cell.fab_array[i])[ilev]->nGrow() < 1)
982 if (initial)
Util::Warning(
INFO, cnames[i],
" has no ghost cells and will not be included in nodal output");
986 n += cell.ncomp_array[i];
989 if (bfcomponents_cell > 0)
991 amrex::BoxArray cgrids = grids[ilev];
992 amrex::MultiFab bfplotmf(cgrids, dmap[ilev], bfcomponents_cell, 0);
994 for (
unsigned int i = 0; i < m_basefields_cell.size(); i++)
996 if (m_basefields_cell[i]->writeout)
998 m_basefields_cell[i]->Copy(ilev, bfplotmf, ctr, 0);
999 ctr += m_basefields_cell[i]->NComp();
1003 n += bfcomponents_cell;
1009 std::vector<std::string> plotfilename = PlotFileName(istep[0], prefix);
1010 if (initial) plotfilename[1] = plotfilename[1] +
"init";
1012 if (do_cell_plotfile)
1014 amrex::Vector<std::string> allnames = cnames;
1015 allnames.insert(allnames.end(), bfnames_cell.begin(), bfnames_cell.end());
1017 allnames.insert(allnames.end(), nnames.begin(), nnames.end());
1018 allnames.insert(allnames.end(), bfnames.begin(), bfnames.end());
1020 const std::string base = plotfilename[0] + plotfilename[1] +
"cell";
1021#ifdef AMREX_USE_HDF5
1022 WriteMultiLevelPlotfileHDF5(base, nlevels, amrex::GetVecOfConstPtrs(cplotmf), allnames,
1023 Geom(), time, iter, refRatio(),
"ZLIB@" + compression_level);
1024 const std::string chkptfilename = base +
".Checkpoint";
1026 WriteMultiLevelPlotfile(base, nlevels, amrex::GetVecOfConstPtrs(cplotmf), allnames,
1027 Geom(), time, iter, refRatio());
1028 const std::string chkptfilename = base +
"/Checkpoint";
1030 std::ofstream chkptfile(chkptfilename);
1031 if (!chkptfile.good()) amrex::FileOpenFailed(chkptfilename);
1032 for (
int i = 0; i <= max_level; i++) boxArray(i).writeOn(chkptfile);
1034 if (chkptfile.fail()) amrex::FileOpenFailed(chkptfilename);
1037 if (do_node_plotfile)
1039 amrex::Vector<std::string> allnames = nnames;
1040 allnames.insert(allnames.end(), bfnames.begin(), bfnames.end());
1041 if (node.all) allnames.insert(allnames.end(), cnames.begin(), cnames.end());
1042 const std::string base = plotfilename[0] + plotfilename[1] +
"node";
1043#ifdef AMREX_USE_HDF5
1044 WriteMultiLevelPlotfileHDF5(base, nlevels, amrex::GetVecOfConstPtrs(nplotmf), allnames,
1045 Geom(), time, iter, refRatio(),
"ZLIB@" + compression_level);
1046 const std::string chkptfilename = base +
".Checkpoint";
1048 WriteMultiLevelPlotfile(base, nlevels, amrex::GetVecOfConstPtrs(nplotmf), allnames,
1049 Geom(), time, iter, refRatio());
1050 const std::string chkptfilename = base +
"/Checkpoint";
1052 std::ofstream chkptfile(chkptfilename);
1053 if (!chkptfile.good()) amrex::FileOpenFailed(chkptfilename);
1054 for (
int i = 0; i <= max_level; i++) boxArray(i).writeOn(chkptfile);
1056 if (chkptfile.fail()) amrex::FileOpenFailed(chkptfilename);
1059 if (amrex::ParallelDescriptor::IOProcessor())
1061 std::ofstream coutfile, noutfile;
1064 if (do_cell_plotfile) coutfile.open(plot_file +
"/celloutput.visit", std::ios_base::out);
1065 if (do_node_plotfile) noutfile.open(plot_file +
"/nodeoutput.visit", std::ios_base::out);
1069 if (do_cell_plotfile) coutfile.open(plot_file +
"/celloutput.visit", std::ios_base::app);
1070 if (do_node_plotfile) noutfile.open(plot_file +
"/nodeoutput.visit", std::ios_base::app);
1072#ifdef AMREX_USE_HDF5
1073 const std::string header_suffix =
".h5";
1075 const std::string header_suffix =
"/Header";
1077 if (do_cell_plotfile) coutfile << plotfilename[1] +
"cell" + header_suffix << std::endl;
1078 if (do_node_plotfile) noutfile << plotfilename[1] +
"node" + header_suffix << std::endl;
1218 BL_PROFILE(
"Integrator::TimeStep");
1219 if (base_regrid_int <= 0 || istep[0] % base_regrid_int == 0)
1221 if (regrid_int > 0 || base_regrid_int > 0)
1223 static amrex::Vector<int> last_regrid_step(max_level + 1, 0);
1226 if (lev < max_level && istep[lev] > last_regrid_step[lev])
1228 if (istep[lev] % regrid_int == 0)
1230 regrid(lev, time,
false);
1235 SetFinestLevel(finest_level);
1237 if (Verbose() && amrex::ParallelDescriptor::IOProcessor()) {
1238 std::cout <<
"[Level " << lev
1239 <<
" step " << istep[lev] + 1 <<
"] ";
1240 std::cout <<
"ADVANCE with dt = "
1245 for (
int n = 0; n < cell.number_of_fabs; n++)
1246 if (cell.evolving_array[n]) FillPatch(lev, time, *cell.fab_array[n], *(*cell.fab_array[n])[lev], *cell.physbc_array[n], 0);
1247 for (
int n = 0; n < node.number_of_fabs; n++)
1248 if (node.evolving_array[n]) FillPatch(lev, time, *node.fab_array[n], *(*node.fab_array[n])[lev], *node.physbc_array[n], 0);
1249 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
1250 if (m_basefields_cell[n]->evolving) m_basefields_cell[n]->FillPatch(lev, time);
1251 for (
unsigned int n = 0; n < m_basefields.size(); n++)
1252 if (m_basefields[n]->evolving) m_basefields[n]->FillPatch(lev, time);
1254 Advance(lev, time, dt[lev]);
1257 if (Verbose() && amrex::ParallelDescriptor::IOProcessor())
1259 std::cout <<
"[Level " << lev
1260 <<
" step " << istep[lev] <<
"] ";
1261 std::cout <<
"Advanced "
1267 if (lev < finest_level)
1269 for (
int i = 1; i <= nsubsteps[lev + 1]; ++i)
1270 TimeStep(lev + 1, time + (i - 1) * dt[lev + 1], i);
1272 for (
int n = 0; n < cell.number_of_fabs; n++)
1274 amrex::average_down(*(*cell.fab_array[n])[lev + 1], *(*cell.fab_array[n])[lev],
1275 geom[lev + 1], geom[lev],
1276 0, (*cell.fab_array[n])[lev]->nComp(), refRatio(lev));
1278 for (
int n = 0; n < node.number_of_fabs; n++)
1280 amrex::average_down(*(*node.fab_array[n])[lev + 1], *(*node.fab_array[n])[lev],
1281 0, (*node.fab_array[n])[lev]->nComp(), refRatio(lev));
1283 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
1285 if (m_basefields_cell[n]->evolving)
1286 m_basefields_cell[n]->AverageDown(lev, refRatio(lev));
1288 for (
unsigned int n = 0; n < m_basefields.size(); n++)
1290 if (m_basefields[n]->evolving)
1291 m_basefields[n]->AverageDown(lev, refRatio(lev));