Skip to content

Commit

Permalink
Add option to write a smallplotfile as in AmrLevel. A user defined
Browse files Browse the repository at this point in the history
selection of variables can be written at a different interval than
the full plotfile.

Also add the option to specify plotfile variables as a list, e.g.
amr.plotVariables = velx vely velz
  • Loading branch information
cgilet committed Oct 7, 2024
1 parent e8f071a commit 1570173
Show file tree
Hide file tree
Showing 5 changed files with 429 additions and 353 deletions.
31 changes: 30 additions & 1 deletion Docs/sphinx_documentation/source/InputsPlotFiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ as whether the EB geometry should be written out.
+---------------------+-----------------------------------------------------------------------+-------------+-----------+

The following inputs must be preceded by "amr" and control what variables will be written in plotfiles.
By default, incflo plotfiles contain the velocity, pressure gradient, density, tracer, velocity magnitude, vorticity,
and if using EB, volume fraction.

+---------------------+-----------------------------------------------------------------------+-------------+-----------+
| | Description | Type | Default |
+=====================+=======================================================================+=============+===========+
| plt_ccse_regtest | Save all variables to plot file (overrides all other IO flags) | Int | 0 |
| plotVariables | Space separated list of variable names. **Takes precedent over all** | String | see above |
| | **other plotfile options**. Plotfile will contain only this list, | | |
| | e.g. "amr.plotVariables = velx density" will result in plotfiles | | |
| | containing only the x-component of the velocity and the density. | | |
+---------------------+-----------------------------------------------------------------------+-------------+-----------+
| plt_ccse_regtest | Collection of variables for regression test plotfiles (will get | Int | 0 |
| | overwritten by plotVariables or plt_* flags) | | |
+---------------------+-----------------------------------------------------------------------+-------------+-----------+
| plt_velx | Save x-velocity to plot file | Int | 1 |
+---------------------+-----------------------------------------------------------------------+-------------+-----------+
Expand Down Expand Up @@ -62,3 +70,24 @@ The following inputs must be preceded by "amr" and control what variables will b
+---------------------+-----------------------------------------------------------------------+-------------+-----------+
| plt_vfrac | Save EB volume fraction to plot file | Int | 1 |
+---------------------+-----------------------------------------------------------------------+-------------+-----------+

incflo provides the option to write a user defined selection of variables to a "smallplotfile" at an interval that is
different than that of the full plotfile.
The following inputs must be preceded by "amr" and control frequency and naming of smallplotfile generation.

+--------------------------+-----------------------------------------------------------------------+-------------+-----------+
| | Description | Type | Default |
+==========================+=======================================================================+=============+===========+
| smallplot_int | Frequency of smallplotfile output; | Int | -1 |
| | if -1 then no plotfiles will be written at this frequency | | |
| smallplot_per_approx | Time period of smallplotfile output (approximate); does not modify dt | Real | -1 |
| | if -1 then no smallplotfiles will be written at this frequency | | |
+--------------------------+-----------------------------------------------------------------------+-------------+-----------+
+--------------------------+-----------------------------------------------------------------------+-------------+-----------+
| smallplotfile_on_restart | Write smallplotfile when restarting (only used if smallplot_int>0) | Bool | False |
+--------------------------+-----------------------------------------------------------------------+-------------+-----------+
| smallplot_file | Prefix to use for smallplotfile output | String | smallplt |
+--------------------------+-----------------------------------------------------------------------+-------------+-----------+
+--------------------------+-----------------------------------------------------------------------+-------------+-----------+
| smallplotVariables | Space separated list of variable names. | String | none |
+--------------------------+-----------------------------------------------------------------------+-------------+-----------+
32 changes: 29 additions & 3 deletions src/incflo.H
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ private:
amrex::Vector<amrex::Real> tag_region_lo;
amrex::Vector<amrex::Real> tag_region_hi;

// FIXME -- depreciate?
// Flags for saving fluid data in plot files
int m_plt_velx = 1;
int m_plt_vely = 1;
Expand All @@ -592,10 +593,31 @@ private:
int m_plt_error_w = 0;
int m_plt_error_p = 0;
int m_plt_error_mac_p = 0;

#ifdef INCFLO_USE_PARTICLES
int m_plt_particle_count = 0;

// Set default that agrees with m_plt_* defaults above
amrex::Vector<std::string> m_plotVars =
#if (AMREX_SPACEDIM == 3)
{"velx","vely","velz","gpx","gpy","gpz","density","tracer","magvel","vort","vfrac"};
#else
{"velx","vely","gpx","gpy","density","tracer","magvel","vort","vfrac"};
#endif

// smallplotfile allows users to output certain variables at a different frequency.
// Off by default.
int m_smallplot_int = -1;
amrex::Real m_smallplot_per_approx = -1.0;
// No smallplot_per_exact because it requires changing the timestep
int m_last_smallplt = -1;
bool m_smallplotfile_on_restart = false;

std::string m_smallplot_file{"smallplt"};

// Require user to choose smallplotfile variables
amrex::Vector<std::string> m_smallplotVars;


#ifdef INCFLO_USE_PARTICLES
// Particle container with all particle species
ParticleData particleData;

Expand Down Expand Up @@ -887,7 +909,9 @@ private:
void copy_from_old_to_new_tracer (int lev, amrex::IntVect const& ng = amrex::IntVect{0});

void Advance ();
bool writeNow ();
bool writeNow () { return writeNow(m_plot_int, m_plot_per_approx, m_plot_per_exact); }
bool writeNow (int a_plot_int, amrex::Real a_plot_per_approx,
amrex::Real a_plot_per_exact);

///////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -963,6 +987,8 @@ private:
void WriteJobInfo (const std::string& path) const;
void WriteCheckPointFile () const;
void WritePlotFile ();
void WritePlotVariables (amrex::Vector<std::string> vars, const std::string& plotfilename);
virtual void WriteSmallPlotFile ();
void ReadCheckpointFile ();
};

Expand Down
33 changes: 24 additions & 9 deletions src/incflo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ void incflo::InitData ()
WritePlotFile();
m_last_plt = 0;
}
if (m_smallplot_int > 0 || m_smallplot_per_approx > 0)
{
WriteSmallPlotFile();
m_last_smallplt = 0;
}
if (m_KE_int > 0)
{
amrex::Abort("xxxxx m_KE_int todo");
Expand All @@ -116,6 +121,11 @@ void incflo::InitData ()
WritePlotFile();
m_last_plt = 0;
}
if (m_smallplotfile_on_restart)
{
WriteSmallPlotFile();
m_last_smallplt = 0;
}
}

#ifdef AMREX_USE_EB
Expand Down Expand Up @@ -166,6 +176,11 @@ void incflo::Evolve()
WritePlotFile();
m_last_plt = m_nstep;
}
if (writeNow(m_smallplot_int, m_smallplot_per_approx, -1.))
{
WriteSmallPlotFile();
m_last_smallplt = m_nstep;
}

if(m_check_int > 0 && (m_nstep % m_check_int == 0))
{
Expand Down Expand Up @@ -278,28 +293,28 @@ void incflo::MakeNewLevelFromScratch (int lev, Real time, const BoxArray& new_gr
}

bool
incflo::writeNow()
incflo::writeNow(int a_plot_int, Real a_plot_per_approx, Real a_plot_per_exact)
{
bool write_now = false;

if ( ( m_plot_int > 0 && (m_nstep % m_plot_int == 0) ) ||
(m_plot_per_exact > 0 && (std::abs(std::remainder(m_cur_time, m_plot_per_exact)) < 1.e-12) ) ) {
if ( ( a_plot_int > 0 && (m_nstep % a_plot_int == 0) ) ||
(a_plot_per_exact > 0 && (std::abs(std::remainder(m_cur_time, a_plot_per_exact)) < 1.e-12) ) ) {
write_now = true;
} else if (m_plot_per_approx > 0.0) {
// Check to see if we've crossed a m_plot_per_approx interval by comparing
} else if (a_plot_per_approx > 0.0) {
// Check to see if we've crossed a a_plot_per_approx interval by comparing
// the number of intervals that have elapsed for both the current
// time and the time at the beginning of this timestep.

int num_per_old = static_cast<int>(std::round((m_cur_time-m_dt) / m_plot_per_approx));
int num_per_new = static_cast<int>(std::round((m_cur_time ) / m_plot_per_approx));
int num_per_old = static_cast<int>(std::round((m_cur_time-m_dt) / a_plot_per_approx));
int num_per_new = static_cast<int>(std::round((m_cur_time ) / a_plot_per_approx));

// Before using these, however, we must test for the case where we're
// within machine epsilon of the next interval. In that case, increment
// the counter, because we have indeed reached the next m_plot_per_approx interval
// the counter, because we have indeed reached the next a_plot_per_approx interval
// at this point.

const Real eps = std::numeric_limits<Real>::epsilon() * Real(10.0) * std::abs(m_cur_time);
const Real next_plot_time = (num_per_old + 1) * m_plot_per_approx;
const Real next_plot_time = (num_per_old + 1) * a_plot_per_approx;

if ((num_per_new == num_per_old) && std::abs(m_cur_time - next_plot_time) <= eps)
{
Expand Down
124 changes: 76 additions & 48 deletions src/setup/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,69 +233,97 @@ void incflo::ReadIOParameters()

if ( (m_plot_int > 0 && m_plot_per_exact > 0) ||
(m_plot_int > 0 && m_plot_per_approx > 0) ||
(m_plot_per_exact > 0 && m_plot_per_approx > 0) )
amrex::Abort("Must choose only one of plot_int or plot_per_exact or plot_per_approx");
(m_plot_per_exact > 0 && m_plot_per_approx > 0) ) {
amrex::Abort("Must choose only one of plot_int or plot_per_exact or plot_per_approx"); }

// The plt_ccse_regtest resets the defaults,
// but we can over-ride those below
//
// Choose which variables to write to plotfile
//
// The plt_ccse_regtest resets plotfile variables for the regression tests
int plt_ccse_regtest = 0;
pp.query("plt_ccse_regtest", plt_ccse_regtest);

if (plt_ccse_regtest != 0)
{
m_plt_velx = 1;
m_plt_vely = 1;
m_plt_velz = 1;
m_plt_gpx = 1;
m_plt_gpy = 1;
m_plt_gpz = 1;
m_plt_rho = 1;
m_plt_tracer = 1;
m_plt_p = 0;
m_plt_macphi = 0;
m_plt_eta = 0;
m_plt_vort = 0;
m_plt_magvel = 0;
m_plt_strainrate = 0;
m_plt_divu = 0;
m_plt_vfrac = 0;
#if (AMREX_SPACEDIM == 3)
m_plotVars = {"velx","vely","velz","gpx","gpy","gpz","density","tracer"};
#else
m_plotVars = {"velx","vely","gpx","gpy","density","tracer"};
#endif

#ifdef INCFLO_USE_PARTICLES
m_plt_particle_count = 1;
m_plotVars.push_back("particle_count");
#endif
}

// Which variables to write to plotfile

pp.query("plt_velx", m_plt_velx );
pp.query("plt_vely", m_plt_vely );
pp.query("plt_velz", m_plt_velz );
// Helper function to update m_plotVars according to m_plt_* flags
auto update_plotVars = [this] (std::string const& a_name, bool plot_flag) {
for (int n = 0; n < m_plotVars.size(); n++) {
if ( m_plotVars[n] == a_name ) {
if ( plot_flag ) {
return; /* already there */}
else {
//std::erase(m_plotVars, a_name); // Requires c++20
m_plotVars.erase(std::remove(m_plotVars.begin(), m_plotVars.end(), a_name),
m_plotVars.end());
return;
}
}
}
if (plot_flag) { m_plotVars.push_back(a_name); }
};

// Check for flags to change inclusion of individual fields
if ( pp.query("plt_velx", m_plt_velx) ) { update_plotVars("velx", m_plt_velx); }
if ( pp.query("plt_vely", m_plt_vely) ) { update_plotVars("vely", m_plt_vely); }
if ( pp.query("plt_velz", m_plt_velz) ) { update_plotVars("velz", m_plt_velz); }

if ( pp.query("plt_gpx", m_plt_gpx) ) { update_plotVars("gpx", m_plt_gpx); }
if ( pp.query("plt_gpy", m_plt_gpy) ) { update_plotVars("gpy", m_plt_gpy); }
if ( pp.query("plt_gpz", m_plt_gpz) ) { update_plotVars("gpz", m_plt_gpz); }

if ( pp.query("plt_rho", m_plt_rho ) ) { update_plotVars("density",m_plt_rho); }
if ( pp.query("plt_tracer", m_plt_tracer) ) { update_plotVars("tracer",m_plt_tracer); }
if ( pp.query("plt_p ", m_plt_p ) ) { update_plotVars("p",m_plt_p); }
if ( pp.query("plt_macphi", m_plt_macphi) ) { update_plotVars("macphi",m_plt_macphi); }
if ( pp.query("plt_eta", m_plt_eta ) ) { update_plotVars("eta",m_plt_eta); }
if ( pp.query("plt_magvel", m_plt_magvel) ) { update_plotVars("magvel",m_plt_magvel); }
if ( pp.query("plt_vort", m_plt_vort ) ) { update_plotVars("vort",m_plt_vort); }
if ( pp.query("plt_strainrate", m_plt_strainrate) ) { update_plotVars("strainrate",m_plt_strainrate); }
if ( pp.query("plt_divu", m_plt_divu ) ) { update_plotVars("divu",m_plt_divu); }
if ( pp.query("plt_vfrac", m_plt_vfrac ) ) { update_plotVars("vfrac",m_plt_vfrac); }

if ( pp.query("plt_forcing", m_plt_forcing ) ) { update_plotVars("forcing",m_plt_forcing); }

if ( pp.query("plt_error_u", m_plt_error_u ) ) { update_plotVars("error_u",m_plt_error_u); }
if ( pp.query("plt_error_v", m_plt_error_v ) ) { update_plotVars("error_v",m_plt_error_v); }
if ( pp.query("plt_error_w", m_plt_error_w ) ) { update_plotVars("error_w",m_plt_error_w); }
if ( pp.query("plt_error_p", m_plt_error_p ) ) { update_plotVars("error_p",m_plt_error_p); }
if ( pp.query("plt_error_mac_p",m_plt_error_mac_p ) ) { update_plotVars("error_mac_p",m_plt_error_mac_p); }

pp.query("plt_gpx", m_plt_gpx );
pp.query("plt_gpy", m_plt_gpy );
pp.query("plt_gpz", m_plt_gpz );
#ifdef INCFLO_USE_PARTICLES
if ( pp.query("plt_particle_count", m_plt_particle_count ) ) { update_plotVars("particle_count",m_plt_particle_count); }
#endif

pp.query("plt_rho", m_plt_rho );
pp.query("plt_tracer", m_plt_tracer);
pp.query("plt_p ", m_plt_p );
pp.query("plt_macphi", m_plt_macphi);
pp.query("plt_eta", m_plt_eta );
pp.query("plt_magvel", m_plt_magvel);
pp.query("plt_vort", m_plt_vort );
pp.query("plt_strainrate", m_plt_strainrate);
pp.query("plt_divu", m_plt_divu );
pp.query("plt_vfrac", m_plt_vfrac );
// Set according to a variable list
if ( pp.contains("plotVariables") ) {
m_plotVars.clear();
pp.queryarr("plotVariables", m_plotVars);
}

pp.query("plt_forcing", m_plt_forcing );
// Small plot options
pp.query("smallplot_file" , m_smallplot_file);
pp.query("smallplot_int" , m_smallplot_int);
pp.query("smallplot_per_approx", m_smallplot_per_approx);
pp.query("smallplotfile_on_restart", m_smallplotfile_on_restart);

pp.query("plt_error_u", m_plt_error_u );
pp.query("plt_error_v", m_plt_error_v );
pp.query("plt_error_w", m_plt_error_w );
pp.query("plt_error_p", m_plt_error_p );
pp.query("plt_error_mac_p",m_plt_error_mac_p );
if ( m_smallplot_int > 0 && m_smallplot_per_approx > 0 ) {
amrex::Abort("Must choose only one of smallplot_int or smallplot_per_approx"); }

#ifdef INCFLO_USE_PARTICLES
pp.query("plt_particle_count", m_plt_particle_count );
#endif
if ( pp.contains("smallplotVariables") ) {
m_smallplotVars.clear();
pp.queryarr("smallplotVariables", m_smallplotVars);
}
}

//
Expand Down
Loading

0 comments on commit 1570173

Please sign in to comment.