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_default(
"dynamictimestep.on",value.dynamictimestep.on,
false);
100 if (value.dynamictimestep.on)
103 pp.
query_validate(
"dynamictimestep.verbose",value.dynamictimestep.verbose,{0,1});
105 pp.
query_default(
"dynamictimestep.nprevious",value.dynamictimestep.nprevious,5);
107 pp.
query_default(
"dynamictimestep.cfl",value.dynamictimestep.cfl,1.0);
109 pp.
query_default(
"dynamictimestep.min",value.dynamictimestep.min,value.timestep);
111 pp.
query_default(
"dynamictimestep.max",value.dynamictimestep.max,value.timestep);
119 value.thermo.interval = 1;
120 pp.
query_default(
"amr.thermo.int", value.thermo.interval, 1);
121 pp.
query_default(
"amr.thermo.plot_int", value.thermo.plot_int, -1);
129 pp.
query_default(
"explicitmesh.on", value.explicitmesh.on, 0);
130 if (value.explicitmesh.on)
132 for (
int ilev = 0; ilev < value.maxLevel(); ++ilev)
134 std::string strlo =
"explicitmesh.lo" + std::to_string(ilev + 1);
135 std::string strhi =
"explicitmesh.hi" + std::to_string(ilev + 1);
140 amrex::Vector<int> lodata, hidata;
143 amrex::IntVect lo(AMREX_D_DECL(lodata[0], lodata[1], lodata[2]));
144 amrex::IntVect hi(AMREX_D_DECL(hidata[0], hidata[1], hidata[2]));
146 value.explicitmesh.box.push_back(amrex::Box(lo, hi));
164 pp.
query_validate(
"integration.type", str, {
"ForwardEuler",
"RungeKutta"});
165 if (str ==
"RungeKutta")
173 int nlevs_max = value.maxLevel() + 1;
175 value.istep.resize(nlevs_max, 0);
177 value.t_new.resize(nlevs_max, 0.0);
178 value.t_old.resize(nlevs_max, -1.e100);
179 value.SetTimestep(value.timestep);
536 BL_PROFILE(
"Integrator::Restart");
538 if (a_nodal && node.fab_array.size() == 0)
543 if (!a_nodal && cell.fab_array.size() == 0)
549 std::string filename = dirname +
"/Header";
550 std::string chkptfilename = dirname +
"/Checkpoint";
551 amrex::VisMF::IO_Buffer io_buffer(amrex::VisMF::GetIOBufferSize());
552 amrex::Vector<char> fileCharPtr, chkptfileCharPtr;
553 amrex::ParallelDescriptor::ReadAndBcastFile(filename, fileCharPtr);
554 amrex::ParallelDescriptor::ReadAndBcastFile(chkptfilename, chkptfileCharPtr);
555 std::string fileCharPtrString(fileCharPtr.dataPtr());
556 std::string chkptfileCharPtrString(chkptfileCharPtr.dataPtr());
557 std::istringstream is(fileCharPtrString, std::istringstream::in);
558 std::istringstream chkpt_is(chkptfileCharPtrString, std::istringstream::in);
560 std::string line, word;
563 std::getline(is, line);
568 std::getline(is, line); tmp_numfabs = std::stoi(line);
570 std::vector<std::string> tmp_name_array;
572 for (
int i = 0; i < tmp_numfabs; i++)
574 std::getline(is, line);
575 tmp_name_array.push_back(line);
579 std::getline(is, line);
584 std::getline(is, line); tmp_time = std::stof(line);
Util::Message(
INFO,
"Current time: ", tmp_time);
585 for (
int i = 0; i < max_level + 1; i++)
587 t_new[i] = tmp_time; t_old[i] = tmp_time;
592 std::getline(is, line); tmp_max_level = std::stoi(line);
Util::Message(
INFO,
"Max AMR level: ", line);
593 if (tmp_max_level > max_level)
594 Util::Abort(
INFO,
"The max level specified (", max_level,
") is smaller than the finest level in the restart file (", tmp_max_level,
")");
595 finest_level = tmp_max_level;
607 std::getline(is, line);
609 if (tmp_iters.size() != (
unsigned int)(finest_level + 1))
Util::Abort(
INFO,
"Error reading in interation counts: line = ", line);
610 for (
int lev = 0; lev <= finest_level; lev++) { istep[lev] = std::stoi(tmp_iters[lev]);
Util::Message(
INFO,
"Iter on level ", lev,
" = ", istep[lev]); }
612 amrex::Vector<amrex::MultiFab> tmpdata(tmp_max_level + 1);
617 for (
unsigned int i = 0; i < node.fab_array.size(); i++)
618 if (node.writeout_array[i])
619 total_ncomp += node.ncomp_array[i];
623 for (
unsigned int i = 0; i < cell.fab_array.size(); i++)
624 if (cell.writeout_array[i])
625 total_ncomp += cell.ncomp_array[i];
628 int total_nghost = a_nodal ? 0 : cell.nghost_array[0];
630 for (
int lev = 0; lev <= finest_level; lev++)
632 amrex::BoxArray tmp_ba;
633 tmp_ba.readFrom(chkpt_is);
634 SetBoxArray(lev, tmp_ba);
635 amrex::DistributionMapping tmp_dm(tmp_ba, amrex::ParallelDescriptor::NProcs());
636 SetDistributionMap(lev, tmp_dm);
640 amrex::BoxArray ngrids = grids[lev];
641 ngrids.convert(amrex::IntVect::TheNodeVector());
652 Util::Message(
INFO,amrex::MultiFabFileFullPrefix(lev, dirname,
"Level_",
"Cell"));
655 amrex::VisMF::Read(tmpdata[lev],
656 amrex::MultiFabFileFullPrefix(lev, dirname,
"Level_",
"Cell"));
659 for (
int i = 0; i < node.number_of_fabs; i++)
661 amrex::BoxArray ngrids = grids[lev];
662 ngrids.convert(amrex::IntVect::TheNodeVector());
663 (*node.fab_array[i])[lev].reset(
new amrex::MultiFab(ngrids, dmap[lev], node.ncomp_array[i], node.nghost_array[i]));
664 (*node.fab_array[i])[lev]->setVal(0.);
667 for (
int i = 0; i < cell.number_of_fabs; i++)
668 (*cell.fab_array[i])[lev].reset(
new amrex::MultiFab(grids[lev], dmap[lev], cell.ncomp_array[i], cell.nghost_array[i]));
669 for (
int i = 0; i < tmp_numfabs; i++)
674 for (
int j = 0; j < node.number_of_fabs; j++)
676 if (tmp_name_array[i] == node.name_array[i][j])
679 Util::Message(
INFO,
"Initializing ", node.name_array[i][j],
"; nghost=", node.nghost_array[j],
" with ", tmp_name_array[i]);
680 amrex::MultiFab::Copy(*((*node.fab_array[j])[lev]).get(), tmpdata[lev], i, 0, 1, total_nghost);
682 for (
int k = 0; k < node.ncomp_array[j]; k++)
684 if (tmp_name_array[i] == node.name_array[j][k])
687 Util::Message(
INFO,
"Initializing ", node.name_array[j][k],
"; ncomp=", node.ncomp_array[j],
"; nghost=", node.nghost_array[j],
" with ", tmp_name_array[i]);
688 amrex::MultiFab::Copy(*((*node.fab_array[j])[lev]).get(), tmpdata[lev], i, k, 1, total_nghost);
696 for (
int j = 0; j < cell.number_of_fabs; j++)
698 for (
int k = 0; k < cell.ncomp_array[j]; k++)
700 if (tmp_name_array[i] == cell.name_array[j][k])
703 Util::Message(
INFO,
"Initializing ", cell.name_array[j][k],
"; ncomp=", cell.ncomp_array[j],
"; nghost=", cell.nghost_array[j],
" with ", tmp_name_array[i]);
704 amrex::MultiFab::Copy(*((*cell.fab_array[j])[lev]).get(), tmpdata[lev], i, k, 1, 0 );
710 if (!match)
Util::Warning(
INFO,
"Fab ", tmp_name_array[i],
" is in the restart file, but there is no fab with that name here.");
713 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
715 m_basefields_cell[n]->MakeNewLevelFromScratch(lev, t_new[lev], grids[lev], dmap[lev]);
717 for (
unsigned int n = 0; n < m_basefields.size(); n++)
719 m_basefields[n]->MakeNewLevelFromScratch(lev, t_new[lev], grids[lev], dmap[lev]);
723 for (
int n = 0; n < cell.number_of_fabs; n++)
725 if (cell.writeout_array[n])
726 FillPatch(lev, t_new[lev], *cell.fab_array[n], *(*cell.fab_array[n])[lev], *cell.physbc_array[n], 0);
731 SetFinestLevel(max_level);
818 BL_PROFILE(
"Integrator::WritePlotFile");
819 int nlevels = finest_level + 1;
820 if (max_plot_level >= 0) nlevels = std::min(nlevels, max_plot_level);
822 int ccomponents = 0, ncomponents = 0, bfcomponents_cell = 0, bfcomponents = 0;
823 amrex::Vector<std::string> cnames, nnames, bfnames_cell, bfnames;
824 for (
int i = 0; i < cell.number_of_fabs; i++)
826 if (!cell.writeout_array[i])
continue;
827 ccomponents += cell.ncomp_array[i];
828 if (cell.ncomp_array[i] > 1)
829 for (
int j = 0; j < cell.ncomp_array[i]; j++)
830 cnames.push_back(cell.name_array[i][j]);
832 cnames.push_back(cell.name_array[i][0]);
834 for (
int i = 0; i < node.number_of_fabs; i++)
836 if (!node.writeout_array[i])
continue;
837 ncomponents += node.ncomp_array[i];
838 if (node.ncomp_array[i] > 1)
839 for (
int j = 0; j < node.ncomp_array[i]; j++)
840 nnames.push_back(node.name_array[i][j]);
842 nnames.push_back(node.name_array[i][0]);
844 for (
unsigned int i = 0; i < m_basefields_cell.size(); i++)
846 if (m_basefields_cell[i]->writeout)
848 bfcomponents_cell += m_basefields_cell[i]->NComp();
849 for (
int j = 0; j < m_basefields_cell[i]->NComp(); j++)
850 bfnames_cell.push_back(m_basefields_cell[i]->Name(j));
853 for (
unsigned int i = 0; i < m_basefields.size(); i++)
855 if (m_basefields[i]->writeout)
857 bfcomponents += m_basefields[i]->NComp();
858 for (
int j = 0; j < m_basefields[i]->NComp(); j++)
859 bfnames.push_back(m_basefields[i]->Name(j));
863 amrex::Vector<amrex::MultiFab> cplotmf(nlevels), nplotmf(nlevels);
865 bool do_cell_plotfile = (ccomponents + bfcomponents_cell > 0 || (ncomponents + bfcomponents > 0 && cell.all)) && cell.any;
866 bool do_node_plotfile = (ncomponents + bfcomponents > 0 || (ccomponents + bfcomponents_cell > 0 && node.all)) && node.any;
868 for (
int ilev = 0; ilev < nlevels; ++ilev)
870 if (do_cell_plotfile)
872 int ncomp = ccomponents + bfcomponents_cell;
873 if (cell.all) ncomp += ncomponents + bfcomponents;
874 amrex::BoxArray cgrids_ghost = grids[ilev];
875 cgrids_ghost.grow(print_ghost_cells);
876 cplotmf[ilev].define(cgrids_ghost, dmap[ilev], ncomp, 0);
880 for (
int i = 0; i < cell.number_of_fabs; i++)
882 if (!cell.writeout_array[i])
continue;
883 if ((*cell.fab_array[i])[ilev]->contains_nan())
885 if (abort_on_nan)
Util::Abort(
INFO, cnames[cnames_cnt],
" contains nan (i=", i,
")");
888 if ((*cell.fab_array[i])[ilev]->contains_inf())
890 if (abort_on_nan)
Util::Abort(
INFO, cnames[cnames_cnt],
" contains inf (i=", i,
")");
894 amrex::MultiFab::Copy(cplotmf[ilev], *(*cell.fab_array[i])[ilev], 0, n, cell.ncomp_array[i], 0);
895 n += cell.ncomp_array[i];
897 for (
unsigned int i = 0; i < m_basefields_cell.size(); i++)
899 if (m_basefields_cell[i]->writeout)
901 m_basefields_cell[i]->Copy(ilev, cplotmf[ilev], n, 0);
902 n += m_basefields_cell[i]->NComp();
909 for (
int i = 0; i < node.number_of_fabs; i++)
911 if (!node.writeout_array[i])
continue;
912 if ((*node.fab_array[i])[ilev]->contains_nan())
914 if (abort_on_nan)
Util::Abort(
INFO, nnames[nnames_cnt],
" contains nan (i=", i,
")");
917 if ((*node.fab_array[i])[ilev]->contains_inf())
919 if (abort_on_nan)
Util::Abort(
INFO, nnames[nnames_cnt],
" contains inf (i=", i,
")");
923 amrex::average_node_to_cellcenter(cplotmf[ilev], n, *(*node.fab_array[i])[ilev], 0, node.ncomp_array[i], 0);
924 n += node.ncomp_array[i];
926 if (bfcomponents > 0)
928 amrex::BoxArray ngrids = grids[ilev];
929 ngrids.convert(amrex::IntVect::TheNodeVector());
930 amrex::MultiFab bfplotmf(ngrids, dmap[ilev], bfcomponents, 0);
932 for (
unsigned int i = 0; i < m_basefields.size(); i++)
934 if (m_basefields[i]->writeout)
936 m_basefields[i]->Copy(ilev, bfplotmf, ctr, 0);
937 ctr += m_basefields[i]->NComp();
940 amrex::average_node_to_cellcenter(cplotmf[ilev], n, bfplotmf, 0, bfcomponents);
946 if (do_node_plotfile)
948 amrex::BoxArray ngrids = grids[ilev];
949 ngrids.convert(amrex::IntVect::TheNodeVector());
950 int ncomp = ncomponents + bfcomponents;
951 if (node.all) ncomp += ccomponents + bfcomponents_cell;
953 amrex::BoxArray ngrids_ghost = ngrids;
954 ngrids_ghost.grow(print_ghost_nodes);
956 nplotmf[ilev].define(ngrids_ghost, dmap[ilev], ncomp, 0);
959 for (
int i = 0; i < node.number_of_fabs; i++)
961 if (!node.writeout_array[i])
continue;
962 if ((*node.fab_array[i])[ilev]->contains_nan())
Util::Warning(
INFO, nnames[i],
" contains nan (i=", i,
"). Resetting to zero.");
963 if ((*node.fab_array[i])[ilev]->contains_inf())
Util::Abort(
INFO, nnames[i],
" contains inf (i=", i,
")");
964 amrex::MultiFab::Copy(nplotmf[ilev], *(*node.fab_array[i])[ilev], 0, n, node.ncomp_array[i], 0);
965 n += node.ncomp_array[i];
967 for (
unsigned int i = 0; i < m_basefields.size(); i++)
969 if (m_basefields[i]->writeout)
971 m_basefields[i]->Copy(ilev, nplotmf[ilev], n, 0);
972 n += m_basefields[i]->NComp();
978 for (
int i = 0; i < cell.number_of_fabs; i++)
980 if (!cell.writeout_array[i])
continue;
981 if ((*cell.fab_array[i])[ilev]->contains_nan())
Util::Warning(
INFO, cnames[i],
" contains nan (i=", i,
"). Resetting to zero.");
982 if ((*cell.fab_array[i])[ilev]->contains_inf())
Util::Abort(
INFO, cnames[i],
" contains inf (i=", i,
")");
983 if ((*cell.fab_array[i])[ilev]->nGrow() < 1)
985 if (initial)
Util::Warning(
INFO, cnames[i],
" has no ghost cells and will not be included in nodal output");
989 n += cell.ncomp_array[i];
992 if (bfcomponents_cell > 0)
994 amrex::BoxArray cgrids = grids[ilev];
995 amrex::MultiFab bfplotmf(cgrids, dmap[ilev], bfcomponents_cell, 0);
997 for (
unsigned int i = 0; i < m_basefields_cell.size(); i++)
999 if (m_basefields_cell[i]->writeout)
1001 m_basefields_cell[i]->Copy(ilev, bfplotmf, ctr, 0);
1002 ctr += m_basefields_cell[i]->NComp();
1006 n += bfcomponents_cell;
1012 std::vector<std::string> plotfilename = PlotFileName(istep[0], prefix);
1013 if (initial) plotfilename[1] = plotfilename[1] +
"init";
1015 if (do_cell_plotfile)
1017 amrex::Vector<std::string> allnames = cnames;
1018 allnames.insert(allnames.end(), bfnames_cell.begin(), bfnames_cell.end());
1020 allnames.insert(allnames.end(), nnames.begin(), nnames.end());
1021 allnames.insert(allnames.end(), bfnames.begin(), bfnames.end());
1023 const std::string base = plotfilename[0] + plotfilename[1] +
"cell";
1024#ifdef AMREX_USE_HDF5
1025 WriteMultiLevelPlotfileHDF5(base, nlevels, amrex::GetVecOfConstPtrs(cplotmf), allnames,
1026 Geom(), time, iter, refRatio(),
"ZLIB@" + compression_level);
1027 const std::string chkptfilename = base +
".Checkpoint";
1029 WriteMultiLevelPlotfile(base, nlevels, amrex::GetVecOfConstPtrs(cplotmf), allnames,
1030 Geom(), time, iter, refRatio());
1031 const std::string chkptfilename = base +
"/Checkpoint";
1033 std::ofstream chkptfile(chkptfilename);
1034 if (!chkptfile.good()) amrex::FileOpenFailed(chkptfilename);
1035 for (
int i = 0; i <= max_level; i++) boxArray(i).writeOn(chkptfile);
1037 if (chkptfile.fail()) amrex::FileOpenFailed(chkptfilename);
1040 if (do_node_plotfile)
1042 amrex::Vector<std::string> allnames = nnames;
1043 allnames.insert(allnames.end(), bfnames.begin(), bfnames.end());
1044 if (node.all) allnames.insert(allnames.end(), cnames.begin(), cnames.end());
1045 const std::string base = plotfilename[0] + plotfilename[1] +
"node";
1046#ifdef AMREX_USE_HDF5
1047 WriteMultiLevelPlotfileHDF5(base, nlevels, amrex::GetVecOfConstPtrs(nplotmf), allnames,
1048 Geom(), time, iter, refRatio(),
"ZLIB@" + compression_level);
1049 const std::string chkptfilename = base +
".Checkpoint";
1051 WriteMultiLevelPlotfile(base, nlevels, amrex::GetVecOfConstPtrs(nplotmf), allnames,
1052 Geom(), time, iter, refRatio());
1053 const std::string chkptfilename = base +
"/Checkpoint";
1055 std::ofstream chkptfile(chkptfilename);
1056 if (!chkptfile.good()) amrex::FileOpenFailed(chkptfilename);
1057 for (
int i = 0; i <= max_level; i++) boxArray(i).writeOn(chkptfile);
1059 if (chkptfile.fail()) amrex::FileOpenFailed(chkptfilename);
1062 if (amrex::ParallelDescriptor::IOProcessor())
1064 std::ofstream coutfile, noutfile;
1067 if (do_cell_plotfile) coutfile.open(plot_file +
"/celloutput.visit", std::ios_base::out);
1068 if (do_node_plotfile) noutfile.open(plot_file +
"/nodeoutput.visit", std::ios_base::out);
1072 if (do_cell_plotfile) coutfile.open(plot_file +
"/celloutput.visit", std::ios_base::app);
1073 if (do_node_plotfile) noutfile.open(plot_file +
"/nodeoutput.visit", std::ios_base::app);
1075#ifdef AMREX_USE_HDF5
1076 const std::string header_suffix =
".h5";
1078 const std::string header_suffix =
"/Header";
1080 if (do_cell_plotfile) coutfile << plotfilename[1] +
"cell" + header_suffix << std::endl;
1081 if (do_node_plotfile) noutfile << plotfilename[1] +
"node" + header_suffix << std::endl;
1219 BL_PROFILE(
"Integrator::TimeStep");
1220 if (base_regrid_int <= 0 || istep[0] % base_regrid_int == 0)
1222 if (regrid_int > 0 || base_regrid_int > 0)
1224 static amrex::Vector<int> last_regrid_step(max_level + 1, 0);
1227 if (lev < max_level && istep[lev] > last_regrid_step[lev])
1229 if (istep[lev] % regrid_int == 0)
1231 regrid(lev, time,
false);
1236 SetFinestLevel(finest_level);
1238 if (Verbose() && amrex::ParallelDescriptor::IOProcessor()) {
1239 std::cout <<
"[Level " << lev
1240 <<
" step " << istep[lev] + 1 <<
"] ";
1241 std::cout <<
"ADVANCE with dt = "
1246 for (
int n = 0; n < cell.number_of_fabs; n++)
1247 if (cell.evolving_array[n]) FillPatch(lev, time, *cell.fab_array[n], *(*cell.fab_array[n])[lev], *cell.physbc_array[n], 0);
1248 for (
int n = 0; n < node.number_of_fabs; n++)
1249 if (node.evolving_array[n]) FillPatch(lev, time, *node.fab_array[n], *(*node.fab_array[n])[lev], *node.physbc_array[n], 0);
1250 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
1251 if (m_basefields_cell[n]->evolving) m_basefields_cell[n]->FillPatch(lev, time);
1252 for (
unsigned int n = 0; n < m_basefields.size(); n++)
1253 if (m_basefields[n]->evolving) m_basefields[n]->FillPatch(lev, time);
1255 Advance(lev, time, dt[lev]);
1258 if (Verbose() && amrex::ParallelDescriptor::IOProcessor())
1260 std::cout <<
"[Level " << lev
1261 <<
" step " << istep[lev] <<
"] ";
1262 std::cout <<
"Advanced "
1268 if (lev < finest_level)
1270 for (
int i = 1; i <= nsubsteps[lev + 1]; ++i)
1271 TimeStep(lev + 1, time + (i - 1) * dt[lev + 1], i);
1273 for (
int n = 0; n < cell.number_of_fabs; n++)
1275 amrex::average_down(*(*cell.fab_array[n])[lev + 1], *(*cell.fab_array[n])[lev],
1276 geom[lev + 1], geom[lev],
1277 0, (*cell.fab_array[n])[lev]->nComp(), refRatio(lev));
1279 for (
int n = 0; n < node.number_of_fabs; n++)
1281 amrex::average_down(*(*node.fab_array[n])[lev + 1], *(*node.fab_array[n])[lev],
1282 0, (*node.fab_array[n])[lev]->nComp(), refRatio(lev));
1284 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
1286 if (m_basefields_cell[n]->evolving)
1287 m_basefields_cell[n]->AverageDown(lev, refRatio(lev));
1289 for (
unsigned int n = 0; n < m_basefields.size(); n++)
1291 if (m_basefields[n]->evolving)
1292 m_basefields[n]->AverageDown(lev, refRatio(lev));