40 #ifndef INTEGRATOR_INTEGRATOR_H
41 #define INTEGRATOR_INTEGRATOR_H
53 #include <AMReX_ParallelDescriptor.H>
54 #include <AMReX_ParmParse.H>
55 #include <AMReX_MultiFabUtil.H>
56 #include <AMReX_FillPatchUtil.H>
57 #include <AMReX_BC_TYPES.H>
58 #include <AMReX_AmrCore.H>
59 #include <AMReX_FluxRegister.H>
60 #include <AMReX_Utility.H>
61 #include <AMReX_PlotFileUtil.H>
74 :
public amrex::AmrCore
102 void Restart(std::string restartfile,
bool a_node =
false);
108 void SetFilename(std::string _plot_file) { plot_file = _plot_file; };
113 if (!explicitmesh.on)
114 AmrCore::regrid(lbase, time, initial);
119 if (!explicitmesh.on) AmrCore::InitFromScratch(time);
125 const amrex::BoxArray& ba = MakeBaseGrids();
126 amrex::DistributionMapping dm(ba);
127 const auto old_num_setdm = num_setdm;
128 const auto old_num_setba = num_setba;
129 MakeNewLevelFromScratch(0, time, ba, dm);
130 if (old_num_setba == num_setba) SetBoxArray(0, ba);
131 if (old_num_setdm == num_setdm) SetDistributionMap(0, dm);
134 for (
int ilev = 0; ilev < maxLevel(); ++ilev)
136 finest_level = ilev + 1;
137 amrex::BoxArray grids(explicitmesh.box[ilev]);
138 ChopGrids(ilev + 1, grids, amrex::ParallelDescriptor::NProcs());
139 amrex::DistributionMapping dmap(grids);
140 SetBoxArray(ilev + 1, grids);
141 SetDistributionMap(ilev + 1, dmap);
142 MakeNewLevelFromScratch(ilev + 1, time, grids, dmap);
166 virtual void Advance(
int lev,
178 virtual void TagCellsForRefinement(
int lev, amrex::TagBoxArray& tags, amrex::Real time,
214 const amrex::MFIter&,
const amrex::Box&)
216 if (thermo.number > 0)
217 Util::Warning(
INFO,
"integrated variables registered, but no integration implemented!");
230 void RegisterNodalFab(
Set::Field<Set::Scalar>& new_fab,
int ncomp,
int nghost, std::string name,
bool writeout);
233 void RegisterGeneralFab(
Set::Field<T>& new_fab,
int ncomp,
int nghost,
bool evolving =
true);
235 void RegisterGeneralFab(
Set::Field<T>& new_fab,
int ncomp,
int nghost, std::string a_name,
bool evolving =
true);
237 void RegisterGeneralFab(
Set::Field<T>& new_fab,
int ncomp,
int nghost,
bool writeout, std::string a_name,
bool evolving =
true);
239 template<
class T,
int d>
240 void AddField(
Set::Field<T>& new_field,
BC::BC<T>* new_bc,
int ncomp,
int nghost, std::string,
bool writeout,
bool evolving);
244 for (
unsigned int i = 0; i < cell.fab_array.size(); i++)
245 cell.fab_array[i]->finest_level = a_finestlevel;
246 for (
unsigned int i = 0; i < node.fab_array.size(); i++)
247 node.fab_array[i]->finest_level = a_finestlevel;
248 for (
unsigned int i = 0; i < m_basefields_cell.size(); i++)
249 m_basefields_cell[i]->SetFinestLevel(finest_level);
250 for (
unsigned int i = 0; i < m_basefields.size(); i++)
251 m_basefields[i]->SetFinestLevel(finest_level);
254 void RegisterIntegratedVariable(
Set::Scalar* integrated_variable, std::string name,
bool extensive=
true);
257 void SetPlotInt(
int plot_int);
258 void SetThermoInt(
int a_thermo_int) { thermo.interval = a_thermo_int; }
265 std::string plot_file{
"plt" };
268 virtual void MakeNewLevelFromScratch(
int lev, amrex::Real time,
const amrex::BoxArray& ba,
269 const amrex::DistributionMapping& dm)
override;
270 virtual void MakeNewLevelFromCoarse(
int lev, amrex::Real time,
const amrex::BoxArray& ba,
271 const amrex::DistributionMapping& dm)
override;
272 virtual void RemakeLevel(
int lev, amrex::Real time,
const amrex::BoxArray& ba,
273 const amrex::DistributionMapping& dm)
override;
274 virtual void ClearLevel(
int lev)
override;
275 virtual void ErrorEst(
int lev, amrex::TagBoxArray& tags, amrex::Real time,
int ngrow)
override;
278 void FillPatch(
int lev, amrex::Real time,
280 amrex::MultiFab& destination_multifab,
283 long CountCells(
int lev);
284 void TimeStep(
int lev, amrex::Real time,
int iteration);
286 void GetData(
const int lev,
const amrex::Real time, amrex::Vector<amrex::MultiFab*>& data, amrex::Vector<amrex::Real>& datatime);
288 std::vector<std::string> PlotFileName(
int lev, std::string prefix =
"")
const;
290 void IntegrateVariables(
Set::Scalar cur_time,
int step);
291 void WritePlotFile(
bool initial =
false)
const;
292 void WritePlotFile(std::string prefix,
Set::Scalar time,
int step)
const;
293 void WritePlotFile(
Set::Scalar time, amrex::Vector<int> iter,
bool initial =
false, std::string prefix =
"")
const;
301 amrex::Real timestep = NAN;
303 amrex::Vector<amrex::Real>
dt;
305 int max_plot_level = -1;
308 int max_step = std::numeric_limits<int>::max();
309 amrex::Real tstart = 0;
310 amrex::Real stop_time = NAN;
313 bool integrate_variables_before_advance =
true;
314 bool integrate_variables_after_advance =
false;
318 int number_of_fabs = 0;
330 int number_of_fabs = 0;
331 std::vector<Set::Field<Set::Scalar>*> fab_array;
332 std::vector<int> ncomp_array;
333 std::vector<int> nghost_array;
334 std::vector<std::string> name_array;
335 std::vector<BC::BC<Set::Scalar>*> physbc_array;
336 std::vector<bool> writeout_array;
353 std::vector<Set::Scalar*>
vars;
360 int base_regrid_int = -1;
362 std::string restart_file_cell =
"";
363 std::string restart_file_node =
"";
367 std::vector<amrex::Box>
box;
374 int abort_on_nan =
true;
388 int nlevs_max = maxLevel() + 1;
389 new_field.resize(nlevs_max);
390 cell.fab_array.push_back(&new_field);
391 if (new_bc !=
nullptr) cell.physbc_array.push_back(new_bc);
392 else cell.physbc_array.push_back(&bcnothing);
393 cell.ncomp_array.push_back(ncomp);
394 cell.nghost_array.push_back(nghost);
395 cell.name_array.push_back(name);
396 cell.writeout_array.push_back(writeout);
397 cell.number_of_fabs++;
410 BL_PROFILE(
"Integrator::RegisterNodalFab");
412 int nlevs_max = maxLevel() + 1;
413 new_field.resize(nlevs_max);
414 node.fab_array.push_back(&new_field);
415 node.physbc_array.push_back(&bcnothing);
416 node.ncomp_array.push_back(ncomp);
417 node.nghost_array.push_back(nghost);
418 node.name_array.push_back(name);
419 node.writeout_array.push_back(writeout);
420 node.number_of_fabs++;
423 template<
class T,
int d>
425 void Integrator::AddField(
Set::Field<T>& new_field,
BC::BC<T>* new_bc,
int ncomp,
int nghost, std::string name,
bool writeout,
bool evolving)
430 int nlevs_max = maxLevel() + 1;
431 new_field.resize(nlevs_max);
432 m_basefields.push_back(
new Field<T>(new_field, geom, refRatio(), ncomp, nghost));
433 m_basefields.back()->evolving = evolving;
434 m_basefields.back()->writeout = writeout;
435 m_basefields.back()->setName(name);
436 m_basefields.back()->evolving = evolving;
441 int nlevs_max = maxLevel() + 1;
442 new_field.resize(nlevs_max);
443 m_basefields_cell.push_back(
new Field<T>(new_field, geom, refRatio(), ncomp, nghost));
444 m_basefields_cell.back()->evolving = evolving;
445 m_basefields_cell.back()->writeout = writeout;
446 m_basefields_cell.back()->setName(name);
447 m_basefields_cell.back()->evolving = evolving;
448 if (new_bc) m_basefields_cell.back()->setBC(new_bc);
449 else m_basefields_cell.back()->setBC(&bcnothing);
454 Util::Abort(
INFO,
"Only node and cell based fields can be added at this time");
462 void Integrator::RegisterGeneralFab(
Set::Field<T>& new_fab,
int ncomp,
int nghost,
bool evolving)
465 AddField<T, Set::Hypercube::Node>(new_fab,
nullptr, ncomp, nghost,
"",
true, evolving);
469 void Integrator::RegisterGeneralFab(
Set::Field<T>& new_fab,
int ncomp,
int nghost, std::string a_name,
bool evolving)
472 AddField<T, Set::Hypercube::Node>(new_fab,
nullptr, ncomp, nghost, a_name,
true, evolving);
476 void Integrator::RegisterGeneralFab(
Set::Field<T>& new_fab,
int ncomp,
int nghost,
bool writeout, std::string a_name,
bool evolving)
479 AddField<T, Set::Hypercube::Node>(new_fab,
nullptr, ncomp, nghost, a_name, writeout, evolving);