ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_FixedDtCFLLimit.H
Go to the documentation of this file.
1 #ifndef ERF_FIXED_DT_CFL_LIMIT_H_
2 #define ERF_FIXED_DT_CFL_LIMIT_H_
3 
4 #include <AMReX_Algorithm.H>
5 #include <AMReX_BoxArray.H>
6 #include <AMReX_REAL.H>
7 
8 /**
9  * Courant number a fixed step may not exceed (erf-model/ERF#5238): min(erf.cfl, 0.8). An
10  * erf.cfl below 0.8 is honored; a larger one is capped at 0.8, a margin below the stability
11  * limit.
12  *
13  * @param[in] cfl erf.cfl
14  */
15 inline double
17 {
18  return amrex::min(cfl, 0.8);
19 }
20 
21 /**
22  * Factor by which to scale erf.fixed_dt (and erf.fixed_fast_dt) on a level so that the fixed
23  * step respects the CFL limit (erf-model/ERF#5238). The fixed step exceeds the limit when its
24  * Courant number fixed_dt * cfl_rate is above FixedDtCFLLimitValue(erf.cfl) = min(erf.cfl, 0.8),
25  * and is then scaled to exactly that Courant number, so the scaled step is continuous in the
26  * Courant number. Returns 1 when the fixed step is within the limit, or when there is no fixed
27  * step, no CFL limit (cfl <= 0) or no constraining rate on the level.
28  *
29  * @param[in] fixed_dt fixed time step of the level
30  * @param[in] cfl_rate inverse time step at a Courant number of one on the level (the rate the
31  * adaptive dt of estTimeStep is based on)
32  * @param[in] cfl erf.cfl
33  */
34 inline double
35 FixedDtCFLScale (double fixed_dt, double cfl_rate, double cfl)
36 {
37  if (fixed_dt <= 0.0 || cfl_rate <= 0.0 || cfl <= 0.0) { return 1.0; }
38  const double limit = FixedDtCFLLimitValue(cfl);
39  const double courant = fixed_dt * cfl_rate;
40  // Relative tolerance, so a step already set to the limit is not scaled again by round-off
41  if (courant <= limit * (1.0 + 1.e-10)) { return 1.0; }
42  return limit / courant;
43 }
44 
45 /**
46  * Whether two sets of grids cover the same cells, whatever their box layout. A level whose
47  * grids only change layout (re-chopped by a new amr.max_grid_size or rank count, as a restart
48  * may do) keeps the CFL check of a fixed dt it had, so the dt does not depend on the layout and
49  * a restart takes the steps the uninterrupted run takes (erf-model/ERF#5238, #5228).
50  *
51  * @param[in] a grids the CFL limit was last checked on
52  * @param[in] b current grids
53  */
54 inline bool
55 FixedDtSameCells (const amrex::BoxArray& a, const amrex::BoxArray& b)
56 {
57  if (a == b) { return true; }
58  // ERF grids are disjoint, so the same number of cells and one covering the other is equality
59  return a.numPts() == b.numPts() && (a.empty() || a.contains(b, true));
60 }
61 
62 #endif
double FixedDtCFLScale(double fixed_dt, double cfl_rate, double cfl)
Definition: ERF_FixedDtCFLLimit.H:35
double FixedDtCFLLimitValue(double cfl)
Definition: ERF_FixedDtCFLLimit.H:16
bool FixedDtSameCells(const amrex::BoxArray &a, const amrex::BoxArray &b)
Definition: ERF_FixedDtCFLLimit.H:55