From 8cbf1436377ad6702911e68d1c13ed8b8c72ff91 Mon Sep 17 00:00:00 2001 From: Lucas Esclapez <13371051+esclapez@users.noreply.github.com> Date: Tue, 8 Mar 2022 16:43:04 -0800 Subject: [PATCH] Add message checking lifted from AmrLevel. (#59) --- Source/PeleLM.H | 2 ++ Source/PeleLMEvolve.cpp | 32 +++++++++++++++++++++++++++++--- Source/PeleLMSetup.cpp | 1 + 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Source/PeleLM.H b/Source/PeleLM.H index 019cbd09..13314fc4 100644 --- a/Source/PeleLM.H +++ b/Source/PeleLM.H @@ -420,6 +420,7 @@ class PeleLM : public amrex::AmrCore { // I/O void WritePlotFile(); bool writePlotNow(); + bool checkMessage(); void WriteCheckPointFile(); void ReadCheckPointFile(); bool writeCheckNow(); @@ -920,6 +921,7 @@ class PeleLM : public amrex::AmrCore { int m_plotStateSpec = 0; int m_plot_int = 0; int m_check_int = 0; + int m_message_int = 10; int m_evaluatePlotVarCount = 0; amrex::Vector m_evaluatePlotVars; diff --git a/Source/PeleLMEvolve.cpp b/Source/PeleLMEvolve.cpp index 5ac231df..0c40dea4 100644 --- a/Source/PeleLMEvolve.cpp +++ b/Source/PeleLMEvolve.cpp @@ -37,20 +37,24 @@ void PeleLM::Evolve() { writeTemporals(); } + // Check message + bool dump_and_stop = checkMessage(); + // Check for plot file - if (writePlotNow()) { + if (writePlotNow() || dump_and_stop) { WritePlotFile(); plt_justDidIt = 1; } - if (writeCheckNow()) { + if (writeCheckNow() || dump_and_stop) { 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_stop_time >= 0.0 && m_cur_time >= m_stop_time - 1.0e-12 * m_dt) || + dump_and_stop ); } @@ -103,3 +107,25 @@ PeleLM::doTemporalsNow() return write_now; } + +bool +PeleLM::checkMessage() +{ + bool dump_and_stop = false; + if (m_nstep % m_message_int == 0) { + int dumpclose = 0; + if (ParallelDescriptor::IOProcessor()) { + FILE *fp; + if ( (fp=fopen("dump_and_stop","r")) != 0 ) { + remove("dump_and_stop"); + dumpclose = 1; + fclose(fp); + } + } + int packed_data[1]; + packed_data[0] = dumpclose; + ParallelDescriptor::Bcast(packed_data, 1, ParallelDescriptor::IOProcessorNumber()); + dump_and_stop = packed_data[0]; + } + return dump_and_stop; +} diff --git a/Source/PeleLMSetup.cpp b/Source/PeleLMSetup.cpp index 22e51f29..1a7d37a1 100644 --- a/Source/PeleLMSetup.cpp +++ b/Source/PeleLMSetup.cpp @@ -355,6 +355,7 @@ void PeleLM::readParameters() { ParmParse ppa("amr"); ppa.query("max_step", m_max_step); ppa.query("stop_time", m_stop_time); + ppa.query("message_int", m_message_int); ppa.query("fixed_dt", m_fixed_dt); ppa.query("cfl", m_cfl); ppa.query("dt_shrink", m_dtshrink);