238 BL_PROFILE(
"Integrator::MakeNewLevelFromCoarse");
240 for (
int n = 0; n < cell.number_of_fabs; n++)
242 const int ncomp = (*cell.fab_array[n])[lev - 1]->nComp();
243 const int nghost = (*cell.fab_array[n])[lev - 1]->nGrow();
245 (*cell.fab_array[n])[lev].reset(
new amrex::MultiFab(cgrids, dm, ncomp, nghost));
247 (*cell.fab_array[n])[lev]->setVal(0.0);
249 FillCoarsePatch(lev, time, *cell.fab_array[n], *cell.physbc_array[n], 0, ncomp);
252 amrex::BoxArray ngrids = cgrids;
253 ngrids.convert(amrex::IntVect::TheNodeVector());
255 for (
int n = 0; n < node.number_of_fabs; n++)
257 const int ncomp = (*node.fab_array[n])[lev - 1]->nComp();
258 const int nghost = (*node.fab_array[n])[lev - 1]->nGrow();
260 (*node.fab_array[n])[lev].reset(
new amrex::MultiFab(ngrids, dm, ncomp, nghost));
261 (*node.fab_array[n])[lev]->setVal(0.0);
263 FillCoarsePatch(lev, time, *node.fab_array[n], *node.physbc_array[n], 0, ncomp);
266 for (
unsigned int n = 0; n < m_basefields.size(); n++)
268 m_basefields[n]->MakeNewLevelFromCoarse(lev, time, cgrids, dm);
270 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
272 m_basefields_cell[n]->MakeNewLevelFromCoarse(lev, time, cgrids, dm);
287 const amrex::BoxArray &cgrids,
288 const amrex::DistributionMapping &dm
291 BL_PROFILE(
"Integrator::RemakeLevel");
292 for (
int n = 0; n < cell.number_of_fabs; n++)
294 const int ncomp = (*cell.fab_array[n])[lev]->nComp();
295 const int nghost = (*cell.fab_array[n])[lev]->nGrow();
297 amrex::MultiFab new_state(cgrids, dm, ncomp, nghost);
299 new_state.setVal(0.0);
300 FillPatch(lev, time, *cell.fab_array[n], new_state, *cell.physbc_array[n], 0);
301 std::swap(new_state, *(*cell.fab_array[n])[lev]);
304 amrex::BoxArray ngrids = cgrids;
305 ngrids.convert(amrex::IntVect::TheNodeVector());
307 for (
int n = 0; n < node.number_of_fabs; n++)
309 const int ncomp = (*node.fab_array[n])[lev]->nComp();
310 const int nghost = (*node.fab_array[n])[lev]->nGrow();
312 amrex::MultiFab new_state(ngrids, dm, ncomp, nghost);
314 new_state.setVal(0.0);
315 FillPatch(lev, time, *node.fab_array[n], new_state, *node.physbc_array[n], 0);
316 std::swap(new_state, *(*node.fab_array[n])[lev]);
319 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
321 m_basefields_cell[n]->RemakeLevel(lev, time, cgrids, dm);
323 for (
unsigned int n = 0; n < m_basefields.size(); n++)
325 m_basefields[n]->RemakeLevel(lev, time, cgrids, dm);
546 BL_PROFILE(
"Integrator::Restart");
548 if (a_nodal && node.fab_array.size() == 0)
553 if (!a_nodal && cell.fab_array.size() == 0)
559 std::string filename = dirname +
"/Header";
560 std::string chkptfilename = dirname +
"/Checkpoint";
561 amrex::VisMF::IO_Buffer io_buffer(amrex::VisMF::GetIOBufferSize());
562 amrex::Vector<char> fileCharPtr, chkptfileCharPtr;
563 amrex::ParallelDescriptor::ReadAndBcastFile(filename, fileCharPtr);
564 amrex::ParallelDescriptor::ReadAndBcastFile(chkptfilename, chkptfileCharPtr);
565 std::string fileCharPtrString(fileCharPtr.dataPtr());
566 std::string chkptfileCharPtrString(chkptfileCharPtr.dataPtr());
567 std::istringstream is(fileCharPtrString, std::istringstream::in);
568 std::istringstream chkpt_is(chkptfileCharPtrString, std::istringstream::in);
570 std::string line, word;
573 std::getline(is, line);
578 std::getline(is, line); tmp_numfabs = std::stoi(line);
580 std::vector<std::string> tmp_name_array;
582 for (
int i = 0; i < tmp_numfabs; i++)
584 std::getline(is, line);
585 tmp_name_array.push_back(line);
589 std::getline(is, line);
594 std::getline(is, line); tmp_time = std::stof(line);
Util::Message(
INFO,
"Current time: ", tmp_time);
595 for (
int i = 0; i < max_level + 1; i++)
597 t_new[i] = tmp_time; t_old[i] = tmp_time;
602 std::getline(is, line); tmp_max_level = std::stoi(line);
Util::Message(
INFO,
"Max AMR level: ", line);
603 if (tmp_max_level > max_level)
604 Util::Abort(
INFO,
"The max level specified (", max_level,
") is smaller than the finest level in the restart file (", tmp_max_level,
")");
605 finest_level = tmp_max_level;
617 std::getline(is, line);
619 if (tmp_iters.size() != (
unsigned int)(finest_level + 1))
Util::Abort(
INFO,
"Error reading in interation counts: line = ", line);
620 for (
int lev = 0; lev <= finest_level; lev++) { istep[lev] = std::stoi(tmp_iters[lev]);
Util::Message(
INFO,
"Iter on level ", lev,
" = ", istep[lev]); }
622 amrex::Vector<amrex::MultiFab> tmpdata(tmp_max_level + 1);
627 for (
unsigned int i = 0; i < node.fab_array.size(); i++)
628 if (node.writeout_array[i])
629 total_ncomp += node.ncomp_array[i];
633 for (
unsigned int i = 0; i < cell.fab_array.size(); i++)
634 if (cell.writeout_array[i])
635 total_ncomp += cell.ncomp_array[i];
638 int total_nghost = a_nodal ? 0 : cell.nghost_array[0];
640 for (
int lev = 0; lev <= finest_level; lev++)
642 amrex::BoxArray tmp_ba;
643 tmp_ba.readFrom(chkpt_is);
644 SetBoxArray(lev, tmp_ba);
645 amrex::DistributionMapping tmp_dm(tmp_ba, amrex::ParallelDescriptor::NProcs());
646 SetDistributionMap(lev, tmp_dm);
650 amrex::BoxArray ngrids = grids[lev];
651 ngrids.convert(amrex::IntVect::TheNodeVector());
662 Util::Message(
INFO,amrex::MultiFabFileFullPrefix(lev, dirname,
"Level_",
"Cell"));
665 amrex::VisMF::Read(tmpdata[lev],
666 amrex::MultiFabFileFullPrefix(lev, dirname,
"Level_",
"Cell"));
669 for (
int i = 0; i < node.number_of_fabs; i++)
671 amrex::BoxArray ngrids = grids[lev];
672 ngrids.convert(amrex::IntVect::TheNodeVector());
673 (*node.fab_array[i])[lev].reset(
new amrex::MultiFab(ngrids, dmap[lev], node.ncomp_array[i], node.nghost_array[i]));
674 (*node.fab_array[i])[lev]->setVal(0.);
677 for (
int i = 0; i < cell.number_of_fabs; i++)
678 (*cell.fab_array[i])[lev].reset(
new amrex::MultiFab(grids[lev], dmap[lev], cell.ncomp_array[i], cell.nghost_array[i]));
679 for (
int i = 0; i < tmp_numfabs; i++)
684 for (
int j = 0; j < node.number_of_fabs; j++)
686 if (tmp_name_array[i] == node.name_array[i][j])
689 Util::Message(
INFO,
"Initializing ", node.name_array[i][j],
"; nghost=", node.nghost_array[j],
" with ", tmp_name_array[i]);
690 amrex::MultiFab::Copy(*((*node.fab_array[j])[lev]).get(), tmpdata[lev], i, 0, 1, total_nghost);
692 for (
int k = 0; k < node.ncomp_array[j]; k++)
694 if (tmp_name_array[i] == node.name_array[j][k])
697 Util::Message(
INFO,
"Initializing ", node.name_array[j][k],
"; ncomp=", node.ncomp_array[j],
"; nghost=", node.nghost_array[j],
" with ", tmp_name_array[i]);
698 amrex::MultiFab::Copy(*((*node.fab_array[j])[lev]).get(), tmpdata[lev], i, k, 1, total_nghost);
706 for (
int j = 0; j < cell.number_of_fabs; j++)
708 for (
int k = 0; k < cell.ncomp_array[j]; k++)
710 if (tmp_name_array[i] == cell.name_array[j][k])
713 Util::Message(
INFO,
"Initializing ", cell.name_array[j][k],
"; ncomp=", cell.ncomp_array[j],
"; nghost=", cell.nghost_array[j],
" with ", tmp_name_array[i]);
714 amrex::MultiFab::Copy(*((*cell.fab_array[j])[lev]).get(), tmpdata[lev], i, k, 1, 0 );
720 if (!match)
Util::Warning(
INFO,
"Fab ", tmp_name_array[i],
" is in the restart file, but there is no fab with that name here.");
723 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
725 m_basefields_cell[n]->MakeNewLevelFromScratch(lev, t_new[lev], grids[lev], dmap[lev]);
727 for (
unsigned int n = 0; n < m_basefields.size(); n++)
729 m_basefields[n]->MakeNewLevelFromScratch(lev, t_new[lev], grids[lev], dmap[lev]);
733 for (
int n = 0; n < cell.number_of_fabs; n++)
735 if (cell.writeout_array[n])
736 FillPatch(lev, t_new[lev], *cell.fab_array[n], *(*cell.fab_array[n])[lev], *cell.physbc_array[n], 0);
741 SetFinestLevel(max_level);
828 BL_PROFILE(
"Integrator::WritePlotFile");
829 int nlevels = finest_level + 1;
830 if (max_plot_level >= 0) nlevels = std::min(nlevels, max_plot_level);
832 int ccomponents = 0, ncomponents = 0, bfcomponents_cell = 0, bfcomponents = 0;
833 amrex::Vector<std::string> cnames, nnames, bfnames_cell, bfnames;
834 for (
int i = 0; i < cell.number_of_fabs; i++)
836 if (!cell.writeout_array[i])
continue;
837 ccomponents += cell.ncomp_array[i];
838 if (cell.ncomp_array[i] > 1)
839 for (
int j = 0; j < cell.ncomp_array[i]; j++)
840 cnames.push_back(cell.name_array[i][j]);
842 cnames.push_back(cell.name_array[i][0]);
844 for (
int i = 0; i < node.number_of_fabs; i++)
846 if (!node.writeout_array[i])
continue;
847 ncomponents += node.ncomp_array[i];
848 if (node.ncomp_array[i] > 1)
849 for (
int j = 0; j < node.ncomp_array[i]; j++)
850 nnames.push_back(node.name_array[i][j]);
852 nnames.push_back(node.name_array[i][0]);
854 for (
unsigned int i = 0; i < m_basefields_cell.size(); i++)
856 if (m_basefields_cell[i]->writeout)
858 bfcomponents_cell += m_basefields_cell[i]->NComp();
859 for (
int j = 0; j < m_basefields_cell[i]->NComp(); j++)
860 bfnames_cell.push_back(m_basefields_cell[i]->Name(j));
863 for (
unsigned int i = 0; i < m_basefields.size(); i++)
865 if (m_basefields[i]->writeout)
867 bfcomponents += m_basefields[i]->NComp();
868 for (
int j = 0; j < m_basefields[i]->NComp(); j++)
869 bfnames.push_back(m_basefields[i]->Name(j));
873 amrex::Vector<amrex::MultiFab> cplotmf(nlevels), nplotmf(nlevels);
875 bool do_cell_plotfile = (ccomponents + bfcomponents_cell > 0 || (ncomponents + bfcomponents > 0 && cell.all)) && cell.any;
876 bool do_node_plotfile = (ncomponents + bfcomponents > 0 || (ccomponents + bfcomponents_cell > 0 && node.all)) && node.any;
878 for (
int ilev = 0; ilev < nlevels; ++ilev)
880 if (do_cell_plotfile)
882 int ncomp = ccomponents + bfcomponents_cell;
883 if (cell.all) ncomp += ncomponents + bfcomponents;
884 amrex::BoxArray cgrids_ghost = grids[ilev];
885 cgrids_ghost.grow(print_ghost_cells);
886 cplotmf[ilev].define(cgrids_ghost, dmap[ilev], ncomp, 0);
890 for (
int i = 0; i < cell.number_of_fabs; i++)
892 if (!cell.writeout_array[i])
continue;
893 if ((*cell.fab_array[i])[ilev]->contains_nan())
895 if (abort_on_nan)
Util::Abort(
INFO, cnames[cnames_cnt],
" contains nan (i=", i,
")");
898 if ((*cell.fab_array[i])[ilev]->contains_inf())
900 if (abort_on_nan)
Util::Abort(
INFO, cnames[cnames_cnt],
" contains inf (i=", i,
")");
904 amrex::MultiFab::Copy(cplotmf[ilev], *(*cell.fab_array[i])[ilev], 0, n, cell.ncomp_array[i], 0);
905 n += cell.ncomp_array[i];
907 for (
unsigned int i = 0; i < m_basefields_cell.size(); i++)
909 if (m_basefields_cell[i]->writeout)
911 m_basefields_cell[i]->Copy(ilev, cplotmf[ilev], n, 0);
912 n += m_basefields_cell[i]->NComp();
919 for (
int i = 0; i < node.number_of_fabs; i++)
921 if (!node.writeout_array[i])
continue;
922 if ((*node.fab_array[i])[ilev]->contains_nan())
924 if (abort_on_nan)
Util::Abort(
INFO, nnames[nnames_cnt],
" contains nan (i=", i,
")");
927 if ((*node.fab_array[i])[ilev]->contains_inf())
929 if (abort_on_nan)
Util::Abort(
INFO, nnames[nnames_cnt],
" contains inf (i=", i,
")");
933 amrex::average_node_to_cellcenter(cplotmf[ilev], n, *(*node.fab_array[i])[ilev], 0, node.ncomp_array[i], 0);
934 n += node.ncomp_array[i];
936 if (bfcomponents > 0)
938 amrex::BoxArray ngrids = grids[ilev];
939 ngrids.convert(amrex::IntVect::TheNodeVector());
940 amrex::MultiFab bfplotmf(ngrids, dmap[ilev], bfcomponents, 0);
942 for (
unsigned int i = 0; i < m_basefields.size(); i++)
944 if (m_basefields[i]->writeout)
946 m_basefields[i]->Copy(ilev, bfplotmf, ctr, 0);
947 ctr += m_basefields[i]->NComp();
950 amrex::average_node_to_cellcenter(cplotmf[ilev], n, bfplotmf, 0, bfcomponents);
956 if (do_node_plotfile)
958 amrex::BoxArray ngrids = grids[ilev];
959 ngrids.convert(amrex::IntVect::TheNodeVector());
960 int ncomp = ncomponents + bfcomponents;
961 if (node.all) ncomp += ccomponents + bfcomponents_cell;
963 amrex::BoxArray ngrids_ghost = ngrids;
964 ngrids_ghost.grow(print_ghost_nodes);
966 nplotmf[ilev].define(ngrids_ghost, dmap[ilev], ncomp, 0);
969 for (
int i = 0; i < node.number_of_fabs; i++)
971 if (!node.writeout_array[i])
continue;
972 if ((*node.fab_array[i])[ilev]->contains_nan())
Util::Warning(
INFO, nnames[i],
" contains nan (i=", i,
"). Resetting to zero.");
973 if ((*node.fab_array[i])[ilev]->contains_inf())
Util::Abort(
INFO, nnames[i],
" contains inf (i=", i,
")");
974 amrex::MultiFab::Copy(nplotmf[ilev], *(*node.fab_array[i])[ilev], 0, n, node.ncomp_array[i], 0);
975 n += node.ncomp_array[i];
977 for (
unsigned int i = 0; i < m_basefields.size(); i++)
979 if (m_basefields[i]->writeout)
981 m_basefields[i]->Copy(ilev, nplotmf[ilev], n, 0);
982 n += m_basefields[i]->NComp();
988 for (
int i = 0; i < cell.number_of_fabs; i++)
990 if (!cell.writeout_array[i])
continue;
991 if ((*cell.fab_array[i])[ilev]->contains_nan())
Util::Warning(
INFO, cnames[i],
" contains nan (i=", i,
"). Resetting to zero.");
992 if ((*cell.fab_array[i])[ilev]->contains_inf())
Util::Abort(
INFO, cnames[i],
" contains inf (i=", i,
")");
993 if ((*cell.fab_array[i])[ilev]->nGrow() < 1)
995 if (initial)
Util::Warning(
INFO, cnames[i],
" has no ghost cells and will not be included in nodal output");
999 n += cell.ncomp_array[i];
1002 if (bfcomponents_cell > 0)
1004 amrex::BoxArray cgrids = grids[ilev];
1005 amrex::MultiFab bfplotmf(cgrids, dmap[ilev], bfcomponents_cell, 0);
1007 for (
unsigned int i = 0; i < m_basefields_cell.size(); i++)
1009 if (m_basefields_cell[i]->writeout)
1011 m_basefields_cell[i]->Copy(ilev, bfplotmf, ctr, 0);
1012 ctr += m_basefields_cell[i]->NComp();
1016 n += bfcomponents_cell;
1022 std::vector<std::string> plotfilename = PlotFileName(istep[0], prefix);
1023 if (initial) plotfilename[1] = plotfilename[1] +
"init";
1025 if (do_cell_plotfile)
1027 amrex::Vector<std::string> allnames = cnames;
1028 allnames.insert(allnames.end(), bfnames_cell.begin(), bfnames_cell.end());
1030 allnames.insert(allnames.end(), nnames.begin(), nnames.end());
1031 allnames.insert(allnames.end(), bfnames.begin(), bfnames.end());
1033 WriteMultiLevelPlotfile(plotfilename[0] + plotfilename[1] +
"cell", nlevels, amrex::GetVecOfConstPtrs(cplotmf), allnames,
1034 Geom(), time, iter, refRatio());
1036 std::ofstream chkptfile;
1037 chkptfile.open(plotfilename[0] + plotfilename[1] +
"cell/Checkpoint");
1038 for (
int i = 0; i <= max_level; i++) boxArray(i).writeOn(chkptfile);
1042 if (do_node_plotfile)
1044 amrex::Vector<std::string> allnames = nnames;
1045 allnames.insert(allnames.end(), bfnames.begin(), bfnames.end());
1046 if (node.all) allnames.insert(allnames.end(), cnames.begin(), cnames.end());
1047 WriteMultiLevelPlotfile(plotfilename[0] + plotfilename[1] +
"node", nlevels, amrex::GetVecOfConstPtrs(nplotmf), allnames,
1048 Geom(), time, iter, refRatio());
1050 std::ofstream chkptfile;
1051 chkptfile.open(plotfilename[0] + plotfilename[1] +
"node/Checkpoint");
1052 for (
int i = 0; i <= max_level; i++) boxArray(i).writeOn(chkptfile);
1056 if (amrex::ParallelDescriptor::IOProcessor())
1058 std::ofstream coutfile, noutfile;
1061 if (do_cell_plotfile) coutfile.open(plot_file +
"/celloutput.visit", std::ios_base::out);
1062 if (do_node_plotfile) noutfile.open(plot_file +
"/nodeoutput.visit", std::ios_base::out);
1066 if (do_cell_plotfile) coutfile.open(plot_file +
"/celloutput.visit", std::ios_base::app);
1067 if (do_node_plotfile) noutfile.open(plot_file +
"/nodeoutput.visit", std::ios_base::app);
1069 if (do_cell_plotfile) coutfile << plotfilename[1] +
"cell" +
"/Header" << std::endl;
1070 if (do_node_plotfile) noutfile << plotfilename[1] +
"node" +
"/Header" << std::endl;
1208 BL_PROFILE(
"Integrator::TimeStep");
1209 if (base_regrid_int <= 0 || istep[0] % base_regrid_int == 0)
1211 if (regrid_int > 0 || base_regrid_int > 0)
1213 static amrex::Vector<int> last_regrid_step(max_level + 1, 0);
1216 if (lev < max_level && istep[lev] > last_regrid_step[lev])
1218 if (istep[lev] % regrid_int == 0)
1220 regrid(lev, time,
false);
1225 SetFinestLevel(finest_level);
1227 if (Verbose() && amrex::ParallelDescriptor::IOProcessor()) {
1228 std::cout <<
"[Level " << lev
1229 <<
" step " << istep[lev] + 1 <<
"] ";
1230 std::cout <<
"ADVANCE with dt = "
1235 for (
int n = 0; n < cell.number_of_fabs; n++)
1236 if (cell.evolving_array[n]) FillPatch(lev, time, *cell.fab_array[n], *(*cell.fab_array[n])[lev], *cell.physbc_array[n], 0);
1237 for (
int n = 0; n < node.number_of_fabs; n++)
1238 if (node.evolving_array[n]) FillPatch(lev, time, *node.fab_array[n], *(*node.fab_array[n])[lev], *node.physbc_array[n], 0);
1239 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
1240 if (m_basefields_cell[n]->evolving) m_basefields_cell[n]->FillPatch(lev, time);
1241 for (
unsigned int n = 0; n < m_basefields.size(); n++)
1242 if (m_basefields[n]->evolving) m_basefields[n]->FillPatch(lev, time);
1244 Advance(lev, time, dt[lev]);
1247 if (Verbose() && amrex::ParallelDescriptor::IOProcessor())
1249 std::cout <<
"[Level " << lev
1250 <<
" step " << istep[lev] <<
"] ";
1251 std::cout <<
"Advanced "
1257 if (lev < finest_level)
1259 for (
int i = 1; i <= nsubsteps[lev + 1]; ++i)
1260 TimeStep(lev + 1, time + (i - 1) * dt[lev + 1], i);
1262 for (
int n = 0; n < cell.number_of_fabs; n++)
1264 amrex::average_down(*(*cell.fab_array[n])[lev + 1], *(*cell.fab_array[n])[lev],
1265 geom[lev + 1], geom[lev],
1266 0, (*cell.fab_array[n])[lev]->nComp(), refRatio(lev));
1268 for (
int n = 0; n < node.number_of_fabs; n++)
1270 amrex::average_down(*(*node.fab_array[n])[lev + 1], *(*node.fab_array[n])[lev],
1271 0, (*node.fab_array[n])[lev]->nComp(), refRatio(lev));
1273 for (
unsigned int n = 0; n < m_basefields_cell.size(); n++)
1275 if (m_basefields_cell[n]->evolving)
1276 m_basefields_cell[n]->AverageDown(lev, refRatio(lev));
1278 for (
unsigned int n = 0; n < m_basefields.size(); n++)
1280 if (m_basefields[n]->evolving)
1281 m_basefields[n]->AverageDown(lev, refRatio(lev));