Skip to content

Commit

Permalink
Feature update (#118)
Browse files Browse the repository at this point in the history
* Add a min_dt limit, triggering a clean exit of the code.

* Extend the checkMessage to enable more actions.

* Update doc.

* small docs fix

Co-authored-by: nickwimer <nicholas.wimer@gmail.com>
  • Loading branch information
esclapez and nickwimer authored Aug 15, 2022
1 parent bb1f6e5 commit c99f3d4
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 13 deletions.
36 changes: 36 additions & 0 deletions Docs/source/LMeXControls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Time stepping parameters
amr.stop_time = 0.001 # Maximum simulation time [s]
amr.cfl = 0.5 # [OPT, DEF=0.7] CFL for advection-controlled dt estimate
amr.fixed_dt = 1e-6 # [OPT] optional fixed dt (override CFL condition)
amr.min_dt = 1e-11 # [OPT, DEF=1e-12] small time step size limit triggering simulation termination
amr.init_dt = 1e-6 # [OPT] optional initial dt (override CFL condition upon initialization)
amr.dt_shrink = 0.0001 # [OPT, DEF=1.0] dt factor upon initialization
amr.dt_change_max = 1.1 # [OPT, DEF=1.1] maximum dt change between consecutive steps
Expand Down Expand Up @@ -277,3 +278,38 @@ the state variables on a 'x','y' or 'z' aligned plane and writting a 2D plotfile
peleLM.ynormal.center = 0.0
peleLM.ynormal.int = 10
peleLM.ynormal.interpolation = Quadratic


Run-time control
--------------------

Following some of AMReX's AmrLevel class implementation, PeleLMeX provides a couple of triggers to interact with the code while
it is running. This can be done by adding an empty file to the folder where the simulation is currently running using for
example:

::

touch plt_and_continue

The list of available triggers is:

.. list-table:: PeleLMeX run-time triggers
:widths: 50 100
:header-rows: 1

* - File
- Function
* - plt_and_continue
- Write a pltfile to disk and pursue the simulation
* - chk_and_continue
- Write a chkfile to disk and pursue the simulation
* - dump_and_stop
- Write both pltfile and chkfile to disk and stop the simulation

By default, the code checks if these files exist every 10 time steps, but the user can either increase or decrease the
frequency using:

::

amr.message_int = 20 # [OPT, DEF=10] Frequency for checking the presence of trigger files
3 changes: 2 additions & 1 deletion Source/PeleLM.H
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class PeleLM : public amrex::AmrCore {
// I/O
void WritePlotFile();
bool writePlotNow();
bool checkMessage();
bool checkMessage(const std::string &a_action);
void WriteCheckPointFile();
void ReadCheckPointFile();
bool writeCheckNow();
Expand Down Expand Up @@ -1105,6 +1105,7 @@ class PeleLM : public amrex::AmrCore {
amrex::Real m_cfl = 0.7;
amrex::Real m_fixed_dt = -1.0;
amrex::Real m_init_dt = -1.0;
amrex::Real m_min_dt = 1.0e-12;
amrex::Real m_dtshrink = 1.0;
amrex::Real m_prev_dt = -1.0;
amrex::Real m_dtChangeMax = 1.1;
Expand Down
39 changes: 27 additions & 12 deletions Source/PeleLMEvolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,25 @@ void PeleLM::Evolve() {
doDiagnostics();

// Check message
bool dump_and_stop = checkMessage();
bool dump_and_stop = checkMessage("dump_and_stop");
bool plt_and_continue = checkMessage("plt_and_continue");
bool chk_and_continue = checkMessage("chk_and_continue");

// Check for plot file
if (writePlotNow() || dump_and_stop) {
if (writePlotNow() || dump_and_stop || plt_and_continue) {
WritePlotFile();
plt_justDidIt = 1;
}

if (writeCheckNow() || dump_and_stop) {
if (writeCheckNow() || dump_and_stop || chk_and_continue) {
WriteCheckPointFile();
chk_justDidIt = 1;
}

// Check for the end of the simulation
do_not_evolve = ( (m_max_step >= 0 && m_nstep >= m_max_step) ||
(m_stop_time >= 0.0 && m_cur_time >= m_stop_time - 1.0e-12 * m_dt) ||
(m_dt < m_min_dt) ||
dump_and_stop );

}
Expand Down Expand Up @@ -156,23 +159,35 @@ PeleLM::doTemporalsNow()
}

bool
PeleLM::checkMessage()
PeleLM::checkMessage(const std::string &a_action)
{
bool dump_and_stop = false;
bool take_action = false;

std::string action_file = "";
if (a_action == "dump_and_stop") {
action_file = "dump_and_stop";
} else if (a_action == "plt_and_continue") {
action_file = "plt_and_continue";
} else if (a_action == "chk_and_continue") {
action_file = "chk_and_continue";
} else {
Abort("Unknown action in checkMessage()");
}

if (m_nstep % m_message_int == 0) {
int dumpclose = 0;
int action_flag = 0;
if (ParallelDescriptor::IOProcessor()) {
FILE *fp;
if ( (fp=fopen("dump_and_stop","r")) != 0 ) {
remove("dump_and_stop");
dumpclose = 1;
if ( (fp=fopen(action_file.c_str(),"r")) != 0 ) {
remove(action_file.c_str());
action_flag = 1;
fclose(fp);
}
}
int packed_data[1];
packed_data[0] = dumpclose;
packed_data[0] = action_flag;
ParallelDescriptor::Bcast(packed_data, 1, ParallelDescriptor::IOProcessorNumber());
dump_and_stop = packed_data[0];
take_action = packed_data[0];
}
return dump_and_stop;
return take_action;
}
1 change: 1 addition & 0 deletions Source/PeleLMSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ void PeleLM::readParameters() {
ppa.query("dt_shrink", m_dtshrink);
ppa.query("dt_change_max", m_dtChangeMax);
ppa.query("max_dt", m_max_dt);
ppa.query("min_dt", m_min_dt);

if ( max_level > 0 ) {
ppa.query("regrid_int", m_regrid_int);
Expand Down
9 changes: 9 additions & 0 deletions Source/PeleLMTimestep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ PeleLM::computeDt(int is_init,
}
}

if (estdt < m_min_dt) {
Print() << "\n";
Print() << " ###################################### \n";
Print() << " Estimated dt " << estdt << " is below allowed dt_min "
<< m_min_dt << ": the simulation will stop ! \n";
Print() << " ###################################### \n";
Print() << "\n";
}

return estdt;
}

Expand Down

0 comments on commit c99f3d4

Please sign in to comment.