Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to write a smallplotfile as in AmrLevel. A user defined #136

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
+--------------------------+-----------------------------------------------------------------------+-------------+-----------+
52 changes: 26 additions & 26 deletions src/incflo.H
Original file line number Diff line number Diff line change
Expand Up @@ -569,33 +569,29 @@ private:
amrex::Vector<amrex::Real> tag_region_lo;
amrex::Vector<amrex::Real> tag_region_hi;

// Flags for saving fluid data in plot files
int m_plt_velx = 1;
int m_plt_vely = 1;
int m_plt_velz = 1;
int m_plt_gpx = 1;
int m_plt_gpy = 1;
int m_plt_gpz = 1;
int m_plt_rho = 1;
int m_plt_tracer = 1;
int m_plt_p = 0;
int m_plt_macphi = 0;
int m_plt_eta = 0;
int m_plt_magvel = 1;
int m_plt_vort = 1;
int m_plt_forcing = 0;
int m_plt_strainrate = 0;
int m_plt_divu = 0;
int m_plt_vfrac = 1;
int m_plt_error_u = 0;
int m_plt_error_v = 0;
int m_plt_error_w = 0;
int m_plt_error_p = 0;
int m_plt_error_mac_p = 0;
// Specify fluid data in plot files
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

#ifdef INCFLO_USE_PARTICLES
int m_plt_particle_count = 0;
// 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 +883,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 +961,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
Loading