Skip to content

Commit b2d3787

Browse files
authored
Reorganize checkPoint logic into checkPointNow functions (#4567)
1. Put the checkPoint output logic in `Amr::coarseTimeStep` into a separate `Amr::checkPointNow` function 2. Add member function `AmrLevel::checkPointNow` so users can control the checkPoint output
1 parent 3b5f539 commit b2d3787

File tree

4 files changed

+58
-43
lines changed

4 files changed

+58
-43
lines changed

Src/Amr/AMReX_Amr.H

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ protected:
379379
void ClearLevel (int /*lev*/) override
380380
{ amrex::Abort("How did we get here!"); }
381381

382+
bool checkPointNow () noexcept;
382383
//! Whether to write a plotfile now
383384
bool writePlotNow () noexcept;
384385
bool writeSmallPlotNow () noexcept;

Src/Amr/AMReX_Amr.cpp

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,47 +2212,6 @@ Amr::coarseTimeStep (Real stop_time)
22122212
runlog_terse.flush();
22132213
}
22142214

2215-
int check_test = 0;
2216-
2217-
if (check_per > 0.0)
2218-
{
2219-
2220-
// Check to see if we've crossed a check_per interval by comparing
2221-
// the number of intervals that have elapsed for both the current
2222-
// time and the time at the beginning of this timestep.
2223-
2224-
int num_per_old = static_cast<int>((cumtime-dt_level[0]) / check_per);
2225-
int num_per_new = static_cast<int>((cumtime ) / check_per);
2226-
2227-
// Before using these, however, we must test for the case where we're
2228-
// within machine epsilon of the next interval. In that case, increment
2229-
// the counter, because we have indeed reached the next check_per interval
2230-
// at this point.
2231-
2232-
const Real eps = std::numeric_limits<Real>::epsilon() * 10.0_rt * std::abs(cumtime);
2233-
const Real next_chk_time = static_cast<Real>(num_per_old + 1) * check_per;
2234-
2235-
if ((num_per_new == num_per_old) && std::abs(cumtime - next_chk_time) <= eps)
2236-
{
2237-
num_per_new += 1;
2238-
}
2239-
2240-
// Similarly, we have to account for the case where the old time is within
2241-
// machine epsilon of the beginning of this interval, so that we don't double
2242-
// count that time threshold -- we already plotted at that time on the last timestep.
2243-
2244-
if ((num_per_new != num_per_old) && std::abs((cumtime - dt_level[0]) - next_chk_time) <= eps)
2245-
{
2246-
num_per_old += 1;
2247-
}
2248-
2249-
if (num_per_old != num_per_new)
2250-
{
2251-
check_test = 1;
2252-
}
2253-
2254-
}
2255-
22562215
int to_stop = 0;
22572216
int to_checkpoint = 0;
22582217
int to_plot = 0;
@@ -2323,8 +2282,7 @@ Amr::coarseTimeStep (Real stop_time)
23232282
to_small_plot = 1;
23242283
}
23252284

2326-
if ((check_int > 0 && level_steps[0] % check_int == 0) || check_test == 1
2327-
|| to_checkpoint)
2285+
if (checkPointNow() || to_checkpoint)
23282286
{
23292287
checkPoint();
23302288
}
@@ -2359,6 +2317,54 @@ Amr::coarseTimeStep (Real stop_time)
23592317
}
23602318
}
23612319

2320+
bool
2321+
Amr::checkPointNow () noexcept
2322+
{
2323+
int check_test = 0;
2324+
2325+
if (check_per > 0.0)
2326+
{
2327+
2328+
// Check to see if we've crossed a check_per interval by comparing
2329+
// the number of intervals that have elapsed for both the current
2330+
// time and the time at the beginning of this timestep.
2331+
2332+
int num_per_old = static_cast<int>((cumtime-dt_level[0]) / check_per);
2333+
int num_per_new = static_cast<int>((cumtime ) / check_per);
2334+
2335+
// Before using these, however, we must test for the case where we're
2336+
// within machine epsilon of the next interval. In that case, increment
2337+
// the counter, because we have indeed reached the next check_per interval
2338+
// at this point.
2339+
2340+
const Real eps = std::numeric_limits<Real>::epsilon() * 10.0_rt * std::abs(cumtime);
2341+
const Real next_chk_time = static_cast<Real>(num_per_old + 1) * check_per;
2342+
2343+
if ((num_per_new == num_per_old) && std::abs(cumtime - next_chk_time) <= eps)
2344+
{
2345+
num_per_new += 1;
2346+
}
2347+
2348+
// Similarly, we have to account for the case where the old time is within
2349+
// machine epsilon of the beginning of this interval, so that we don't double
2350+
// count that time threshold -- we already plotted at that time on the last timestep.
2351+
2352+
if ((num_per_new != num_per_old) && std::abs((cumtime - dt_level[0]) - next_chk_time) <= eps)
2353+
{
2354+
num_per_old += 1;
2355+
}
2356+
2357+
if (num_per_old != num_per_new)
2358+
{
2359+
check_test = 1;
2360+
}
2361+
2362+
}
2363+
2364+
return ((check_int > 0 && level_steps[0] % check_int == 0) ||
2365+
check_test == 1 ||
2366+
amr_level[0]->checkPointNow());
2367+
}
23622368
bool
23632369
Amr::writePlotNow() noexcept
23642370
{

Src/Amr/AMReX_AmrLevel.H

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ public:
370370
*/
371371
TimeLevel which_time (int state_indx, Real time) const noexcept;
372372

373+
virtual bool checkPointNow ();
374+
373375
//! Does the AmrLevel want Amr to write a plotfile now?
374376
virtual bool writePlotNow ();
375377

Src/Amr/AMReX_AmrLevel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,12 @@ AmrLevel::estimateWork ()
20552055
return static_cast<Real>(countCells());
20562056
}
20572057

2058+
bool
2059+
AmrLevel::checkPointNow ()
2060+
{
2061+
return false;
2062+
}
2063+
20582064
bool
20592065
AmrLevel::writePlotNow ()
20602066
{

0 commit comments

Comments
 (0)