ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ForceRestorePrecipRate.H
Go to the documentation of this file.
1 #ifndef ERF_FORCE_RESTORE_PRECIP_RATE_H_
2 #define ERF_FORCE_RESTORE_PRECIP_RATE_H_
3 
4 #include <memory>
5 
6 #include <AMReX_MultiFab.H>
7 #include <AMReX_REAL.H>
8 #include <AMReX_Vector.H>
9 
11 
12 struct RadChoice;
13 
14 /**
15  * @brief The precipitation one force-restore step takes from a rate field: the rate
16  * [kg/m^2/s] in component @p comp of @p rate, times @p scale. A null @p rate, or a
17  * zero @p scale, is no precipitation.
18  */
20 {
21  const amrex::MultiFab* rate = nullptr;
22  int comp = 0;
23  amrex::Real scale = amrex::Real(0.0);
24 };
25 
26 /**
27  * @brief The surface precipitation rate of each level's step, for the force-restore
28  * hydrology (ERF_ForceRestoreHydrologyState.H) and snow layer
29  * (ERF_ForceRestoreSnowState.H), with erf.radiation.seb_precipitation_source.
30  *
31  * Owned by TwoStreamRadiation. Per level, and per step:
32  * - begin_step(...) at the start of ERF::Advance, before the dycore and microphysics,
33  * stores the surface precipitation accumulation of every column;
34  * - end_step(...) after microphysics turns its change since that start into the rate;
35  * - the hydrology and snow steps take the rate through rain(...) and frozen(...);
36  * - mark_used(...) after them closes the step.
37  * A rate is used once. When no step followed end_step (the balance skips a new level's
38  * first step), begin_step keeps the earlier start and the next end_step gives the mean rate
39  * over both steps; the scale of rain(...) and frozen(...) is then the time since that start
40  * over the step, so the carried precipitation is counted once, in full. When a step runs
41  * without a new end_step (a level whose radiation is interpolated has neither begin_step
42  * nor end_step), the scale is zero: the rate of an earlier step is not applied again.
43  *
44  * Without the snow layer the rate has one component, the total precipitation. With
45  * erf.radiation.seb_snow_enable it has two, the rain (Rain) and the frozen part (Frozen),
46  * filled in one pass over the accumulators. The rate needs no checkpoint or regrid
47  * handling: both captures happen inside one ERF::Advance of the level.
48  */
50 {
51 public:
52  /** @brief Components of rate(lev). Frozen exists only with the snow layer. */
53  enum Comp : int { Rain = 0, Frozen = 1 };
54 
55  void resize (int nlevs_max);
56 
57  /**
58  * @brief Allocate the level's fields; a no-op without
59  * erf.radiation.seb_precipitation_source.
60  */
61  void define_level (int lev, const RadChoice& rc, const amrex::BoxArray& ba2d,
62  const amrex::DistributionMapping& dm);
63 
64  /** @brief True once define_level allocated @p lev. */
65  [[nodiscard]] bool defined (int lev) const noexcept {
66  return lev >= 0 && lev < static_cast<int>(m_rate.size()) && m_rate[lev] != nullptr;
67  }
68 
69  /** @brief True when the rate is split into rain and frozen precipitation. */
70  [[nodiscard]] bool split () const noexcept { return m_split; }
71 
72  /**
73  * @brief Store the accumulation [kg/m^2] at the start of the level's step. When no step
74  * used the rate of the previous end_step, the earlier start is kept.
75  */
76  void begin_step (int lev, const SurfacePrecipAccumulationSources& sources, int klo);
77 
78  /**
79  * @brief The rate [kg/m^2/s]: the accumulation now minus the one begin_step stored,
80  * over the time since that start; never negative. Zero when begin_step has not run for
81  * this step.
82  */
83  void end_step (int lev, const SurfacePrecipAccumulationSources& sources, int klo,
84  amrex::Real dt);
85 
86  /** @brief The rain a step of length @p dt takes (the total without the snow layer). */
87  [[nodiscard]] ForceRestorePrecipInput rain (int lev, amrex::Real dt) const noexcept {
88  return input(lev, Rain, dt);
89  }
90 
91  /** @brief The frozen precipitation a step of length @p dt takes; none unless split(). */
92  [[nodiscard]] ForceRestorePrecipInput frozen (int lev, amrex::Real dt) const noexcept {
93  return m_split ? input(lev, Frozen, dt) : ForceRestorePrecipInput{};
94  }
95 
96  /** @brief The steps of this level took the rate: it is not applied again. */
97  void mark_used (int lev) noexcept;
98 
99  /** @brief The rate of the last end_step [kg/m^2/s] (Comp components), or nullptr. For output. */
100  [[nodiscard]] const amrex::MultiFab* rate (int lev) const noexcept {
101  return defined(lev) ? m_rate[lev].get() : nullptr;
102  }
103 
104 private:
105  [[nodiscard]] ForceRestorePrecipInput input (int lev, int comp, amrex::Real dt) const noexcept;
106  void fill_accumulation (amrex::MultiFab& accum, const SurfacePrecipAccumulationSources& sources,
107  int klo) const;
108 
109  amrex::Vector<std::unique_ptr<amrex::MultiFab>> m_accum_start; ///< accumulation at the step start
110  amrex::Vector<std::unique_ptr<amrex::MultiFab>> m_accum_now; ///< work field of end_step
111  amrex::Vector<std::unique_ptr<amrex::MultiFab>> m_rate; ///< rate of the last end_step
112  amrex::Vector<int> m_started; ///< begin_step ran this step
113  amrex::Vector<int> m_unused; ///< end_step's rate not yet taken by a step
114  amrex::Vector<amrex::Real> m_elapsed; ///< time since m_accum_start [s]
115  bool m_split = false; ///< rain and frozen apart (seb_snow_enable)
116  bool m_noted_no_frozen = false; ///< the no-frozen-accumulator note was printed
117 };
118 
119 #endif // ERF_FORCE_RESTORE_PRECIP_RATE_H_
const int klo
Definition: ERF_InitCustomPert_KE.H:9
The surface precipitation rate of each level's step, for the force-restore hydrology (ERF_ForceRestor...
Definition: ERF_ForceRestorePrecipRate.H:50
bool m_split
rain and frozen apart (seb_snow_enable)
Definition: ERF_ForceRestorePrecipRate.H:115
amrex::Vector< amrex::Real > m_elapsed
time since m_accum_start [s]
Definition: ERF_ForceRestorePrecipRate.H:114
ForceRestorePrecipInput rain(int lev, amrex::Real dt) const noexcept
The rain a step of length dt takes (the total without the snow layer).
Definition: ERF_ForceRestorePrecipRate.H:87
void resize(int nlevs_max)
Definition: ERF_ForceRestorePrecipRate.cpp:12
void end_step(int lev, const SurfacePrecipAccumulationSources &sources, int klo, amrex::Real dt)
The rate [kg/m^2/s]: the accumulation now minus the one begin_step stored, over the time since that s...
Definition: ERF_ForceRestorePrecipRate.cpp:72
void begin_step(int lev, const SurfacePrecipAccumulationSources &sources, int klo)
Store the accumulation [kg/m^2] at the start of the level's step. When no step used the rate of the p...
Definition: ERF_ForceRestorePrecipRate.cpp:55
void define_level(int lev, const RadChoice &rc, const amrex::BoxArray &ba2d, const amrex::DistributionMapping &dm)
Allocate the level's fields; a no-op without erf.radiation.seb_precipitation_source.
Definition: ERF_ForceRestorePrecipRate.cpp:23
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_rate
rate of the last end_step
Definition: ERF_ForceRestorePrecipRate.H:111
void fill_accumulation(amrex::MultiFab &accum, const SurfacePrecipAccumulationSources &sources, int klo) const
Definition: ERF_ForceRestorePrecipRate.cpp:43
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_accum_now
work field of end_step
Definition: ERF_ForceRestorePrecipRate.H:110
ForceRestorePrecipInput frozen(int lev, amrex::Real dt) const noexcept
The frozen precipitation a step of length dt takes; none unless split().
Definition: ERF_ForceRestorePrecipRate.H:92
bool defined(int lev) const noexcept
True once define_level allocated lev.
Definition: ERF_ForceRestorePrecipRate.H:65
ForceRestorePrecipInput input(int lev, int comp, amrex::Real dt) const noexcept
Definition: ERF_ForceRestorePrecipRate.cpp:99
Comp
Components of rate(lev). Frozen exists only with the snow layer.
Definition: ERF_ForceRestorePrecipRate.H:53
@ Rain
Definition: ERF_ForceRestorePrecipRate.H:53
@ Frozen
Definition: ERF_ForceRestorePrecipRate.H:53
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_accum_start
accumulation at the step start
Definition: ERF_ForceRestorePrecipRate.H:109
bool split() const noexcept
True when the rate is split into rain and frozen precipitation.
Definition: ERF_ForceRestorePrecipRate.H:70
bool m_noted_no_frozen
the no-frozen-accumulator note was printed
Definition: ERF_ForceRestorePrecipRate.H:116
amrex::Vector< int > m_started
begin_step ran this step
Definition: ERF_ForceRestorePrecipRate.H:112
amrex::Vector< int > m_unused
end_step's rate not yet taken by a step
Definition: ERF_ForceRestorePrecipRate.H:113
const amrex::MultiFab * rate(int lev) const noexcept
The rate of the last end_step [kg/m^2/s] (Comp components), or nullptr. For output.
Definition: ERF_ForceRestorePrecipRate.H:100
void mark_used(int lev) noexcept
The steps of this level took the rate: it is not applied again.
Definition: ERF_ForceRestorePrecipRate.cpp:113
constexpr std::array< amrex::Real, num_veg_params > rc
Definition: ERF_SLM_DefaultParams.H:22
The precipitation one force-restore step takes from a rate field: the rate [kg/m^2/s] in component co...
Definition: ERF_ForceRestorePrecipRate.H:20
amrex::Real scale
Definition: ERF_ForceRestorePrecipRate.H:23
int comp
Definition: ERF_ForceRestorePrecipRate.H:22
const amrex::MultiFab * rate
Definition: ERF_ForceRestorePrecipRate.H:21
Container holding radiation-related choices and parameters.
Definition: ERF_RadStruct.H:142
Definition: ERF_SurfacePrecipitation.H:40