ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ForceRestorePrecipRate Class Reference

The surface precipitation rate of each level's step, for the force-restore hydrology (ERF_ForceRestoreHydrologyState.H) and snow layer (ERF_ForceRestoreSnowState.H), with erf.radiation.seb_precipitation_source. More...

#include <ERF_ForceRestorePrecipRate.H>

Collaboration diagram for ForceRestorePrecipRate:

Public Types

enum  Comp : int { Rain = 0 , Frozen = 1 }
 Components of rate(lev). Frozen exists only with the snow layer. More...
 

Public Member Functions

void resize (int nlevs_max)
 
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. More...
 
bool defined (int lev) const noexcept
 True once define_level allocated lev. More...
 
bool split () const noexcept
 True when the rate is split into rain and frozen precipitation. More...
 
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 previous end_step, the earlier start is kept. More...
 
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 start; never negative. Zero when begin_step has not run for this step. More...
 
ForceRestorePrecipInput rain (int lev, amrex::Real dt) const noexcept
 The rain a step of length dt takes (the total without the snow layer). More...
 
ForceRestorePrecipInput frozen (int lev, amrex::Real dt) const noexcept
 The frozen precipitation a step of length dt takes; none unless split(). More...
 
void mark_used (int lev) noexcept
 The steps of this level took the rate: it is not applied again. More...
 
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. More...
 

Private Member Functions

ForceRestorePrecipInput input (int lev, int comp, amrex::Real dt) const noexcept
 
void fill_accumulation (amrex::MultiFab &accum, const SurfacePrecipAccumulationSources &sources, int klo) const
 

Private Attributes

amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_accum_start
 accumulation at the step start More...
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_accum_now
 work field of end_step More...
 
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_rate
 rate of the last end_step More...
 
amrex::Vector< int > m_started
 begin_step ran this step More...
 
amrex::Vector< int > m_unused
 end_step's rate not yet taken by a step More...
 
amrex::Vector< amrex::Real > m_elapsed
 time since m_accum_start [s] More...
 
bool m_split = false
 rain and frozen apart (seb_snow_enable) More...
 
bool m_noted_no_frozen = false
 the no-frozen-accumulator note was printed More...
 

Detailed Description

The surface precipitation rate of each level's step, for the force-restore hydrology (ERF_ForceRestoreHydrologyState.H) and snow layer (ERF_ForceRestoreSnowState.H), with erf.radiation.seb_precipitation_source.

Owned by TwoStreamRadiation. Per level, and per step:

  • begin_step(...) at the start of ERF::Advance, before the dycore and microphysics, stores the surface precipitation accumulation of every column;
  • end_step(...) after microphysics turns its change since that start into the rate;
  • the hydrology and snow steps take the rate through rain(...) and frozen(...);
  • mark_used(...) after them closes the step. A rate is used once. When no step followed end_step (the balance skips a new level's first step), begin_step keeps the earlier start and the next end_step gives the mean rate over both steps; the scale of rain(...) and frozen(...) is then the time since that start over the step, so the carried precipitation is counted once, in full. When a step runs without a new end_step (a level whose radiation is interpolated has neither begin_step nor end_step), the scale is zero: the rate of an earlier step is not applied again.

Without the snow layer the rate has one component, the total precipitation. With erf.radiation.seb_snow_enable it has two, the rain (Rain) and the frozen part (Frozen), filled in one pass over the accumulators. The rate needs no checkpoint or regrid handling: both captures happen inside one ERF::Advance of the level.

Member Enumeration Documentation

◆ Comp

Components of rate(lev). Frozen exists only with the snow layer.

Enumerator
Rain 
Frozen 
53 : int { Rain = 0, Frozen = 1 };
@ Rain
Definition: ERF_ForceRestorePrecipRate.H:53
@ Frozen
Definition: ERF_ForceRestorePrecipRate.H:53

Member Function Documentation

◆ begin_step()

void ForceRestorePrecipRate::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 previous end_step, the earlier start is kept.

57 {
58  if (!defined(lev)) { return; }
59  if (m_split && !m_noted_no_frozen &&
61  surface_precip_has_source(sources.hail))) {
62  m_noted_no_frozen = true;
63  amrex::Print() << "NOTE: erf.radiation.seb_snow_enable is on, but the microphysics scheme "
64  "has no snow, graupel or hail accumulation at the surface: no snow will "
65  "fall, and the snow is that of erf.radiation.seb_snow_initial_swe_kg_m2\n";
66  }
67  if (m_unused[lev] == 0) { fill_accumulation(*m_accum_start[lev], sources, klo); }
68  m_started[lev] = 1;
69 }
const int klo
Definition: ERF_InitCustomPert_KE.H:9
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_source(const SurfacePrecipAccumulationSource &src) noexcept
Definition: ERF_SurfacePrecipitation.H:50
bool m_split
rain and frozen apart (seb_snow_enable)
Definition: ERF_ForceRestorePrecipRate.H:115
void fill_accumulation(amrex::MultiFab &accum, const SurfacePrecipAccumulationSources &sources, int klo) const
Definition: ERF_ForceRestorePrecipRate.cpp:43
bool defined(int lev) const noexcept
True once define_level allocated lev.
Definition: ERF_ForceRestorePrecipRate.H:65
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_accum_start
accumulation at the step start
Definition: ERF_ForceRestorePrecipRate.H:109
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
SurfacePrecipAccumulationSource snow
Definition: ERF_SurfacePrecipitation.H:43
SurfacePrecipAccumulationSource hail
Definition: ERF_SurfacePrecipitation.H:45
SurfacePrecipAccumulationSource graupel
Definition: ERF_SurfacePrecipitation.H:44
Here is the call graph for this function:

◆ define_level()

void ForceRestorePrecipRate::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.

25 {
26  if (rc.seb_precipitation_source == SEBPrecipitationSource::None) { return; }
27  // The one place that decides what the rate holds: with the snow layer the rain and the
28  // frozen part apart, otherwise the total.
29  m_split = rc.seb_snow_enable;
30  const int ncomp = m_split ? 2 : 1;
31  m_accum_start[lev] = std::make_unique<MultiFab>(ba2d, dm, ncomp, 0);
32  m_accum_now[lev] = std::make_unique<MultiFab>(ba2d, dm, ncomp, 0);
33  m_rate[lev] = std::make_unique<MultiFab>(ba2d, dm, ncomp, 0);
34  m_accum_start[lev]->setVal(0.0);
35  m_accum_now[lev]->setVal(0.0);
36  m_rate[lev]->setVal(0.0);
37  m_started[lev] = 0;
38  m_unused[lev] = 0;
39  m_elapsed[lev] = 0.0;
40 }
amrex::Vector< amrex::Real > m_elapsed
time since m_accum_start [s]
Definition: ERF_ForceRestorePrecipRate.H:114
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_rate
rate of the last end_step
Definition: ERF_ForceRestorePrecipRate.H:111
amrex::Vector< std::unique_ptr< amrex::MultiFab > > m_accum_now
work field of end_step
Definition: ERF_ForceRestorePrecipRate.H:110
@ None
Definition: ERF_LSM_Types.H:6
constexpr std::array< amrex::Real, num_veg_params > rc
Definition: ERF_SLM_DefaultParams.H:22

◆ defined()

bool ForceRestorePrecipRate::defined ( int  lev) const
inlinenoexcept

True once define_level allocated lev.

65  {
66  return lev >= 0 && lev < static_cast<int>(m_rate.size()) && m_rate[lev] != nullptr;
67  }

Referenced by rate().

Here is the caller graph for this function:

◆ end_step()

void ForceRestorePrecipRate::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 start; never negative. Zero when begin_step has not run for this step.

74 {
75  if (!defined(lev)) { return; }
76  if (m_started[lev] == 0) { m_rate[lev]->setVal(0.0); return; }
77  fill_accumulation(*m_accum_now[lev], sources, klo);
78  // The time since the stored start: this step, plus any step whose rate no step took.
79  m_elapsed[lev] += dt;
80  const Real elapsed = m_elapsed[lev];
81  const int ncomp = m_rate[lev]->nComp();
82  for (MFIter mfi(*m_rate[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi) {
83  const Box& bx = mfi.tilebox();
84  Array4<Real> r = m_rate[lev]->array(mfi);
85  Array4<const Real> a0 = m_accum_start[lev]->const_array(mfi);
86  Array4<const Real> a1 = m_accum_now[lev]->const_array(mfi);
87  ParallelFor(bx, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept
88  {
89  // The change of each part over the step, not below zero: the bound is on the
90  // change, never on the accumulation itself.
91  r(i, j, k, n) = force_restore_rain_rate(a1(i, j, k, n), a0(i, j, k, n), elapsed);
92  });
93  }
94  m_started[lev] = 0;
95  m_unused[lev] = 1;
96 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real force_restore_rain_rate(amrex::Real accum_end, amrex::Real accum_start, amrex::Real dt) noexcept
Rain rate [kg/m^2/s] from the change of the surface precipitation accumulation over one step.
Definition: ERF_ForceRestoreHydrology.H:110
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
Here is the call graph for this function:

◆ fill_accumulation()

void ForceRestorePrecipRate::fill_accumulation ( amrex::MultiFab &  accum,
const SurfacePrecipAccumulationSources &  sources,
int  klo 
) const
private
46 {
47  if (m_split) {
49  } else {
51  }
52 }
void surface_precip_accum_k0(amrex::MultiFab &accum_2d, const SurfacePrecipAccumulationSources &sources, int klo, SurfacePrecipPhase phase=SurfacePrecipPhase::Total)
Total liquid-water-equivalent surface precipitation accumulation [kg/m2] of every column,...
Definition: ERF_SurfacePrecipitation.H:207
void surface_precip_liquid_frozen_accum_k0(amrex::MultiFab &accum_2d, const SurfacePrecipAccumulationSources &sources, int klo)
The Liquid accumulation in component 0 and the Frozen one in component 1 of accum_2d (two components)...
Definition: ERF_SurfacePrecipitation.H:220
Here is the call graph for this function:

◆ frozen()

ForceRestorePrecipInput ForceRestorePrecipRate::frozen ( int  lev,
amrex::Real  dt 
) const
inlinenoexcept

The frozen precipitation a step of length dt takes; none unless split().

92  {
93  return m_split ? input(lev, Frozen, dt) : ForceRestorePrecipInput{};
94  }
ForceRestorePrecipInput input(int lev, int comp, amrex::Real dt) const noexcept
Definition: ERF_ForceRestorePrecipRate.cpp:99
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
Here is the call graph for this function:

◆ input()

ForceRestorePrecipInput ForceRestorePrecipRate::input ( int  lev,
int  comp,
amrex::Real  dt 
) const
privatenoexcept
100 {
102  if (!defined(lev)) { return in; }
103  in.rate = m_rate[lev].get();
104  in.comp = comp;
105  // The rate is a mean over m_elapsed, which exceeds dt when an earlier step's
106  // precipitation was carried: the step takes the whole of it. A rate a step already took
107  // (no end_step since) gives nothing.
108  in.scale = (m_unused[lev] != 0 && dt > Real(0.0)) ? m_elapsed[lev] / dt : Real(0.0);
109  return in;
110 }
amrex::Real scale
Definition: ERF_ForceRestorePrecipRate.H:23
int comp
Definition: ERF_ForceRestorePrecipRate.H:22
const amrex::MultiFab * rate
Definition: ERF_ForceRestorePrecipRate.H:21

Referenced by frozen(), and rain().

Here is the caller graph for this function:

◆ mark_used()

void ForceRestorePrecipRate::mark_used ( int  lev)
noexcept

The steps of this level took the rate: it is not applied again.

114 {
115  if (!defined(lev)) { return; }
116  m_unused[lev] = 0;
117  m_elapsed[lev] = 0.0;
118 }

◆ rain()

ForceRestorePrecipInput ForceRestorePrecipRate::rain ( int  lev,
amrex::Real  dt 
) const
inlinenoexcept

The rain a step of length dt takes (the total without the snow layer).

87  {
88  return input(lev, Rain, dt);
89  }
Here is the call graph for this function:

◆ rate()

const amrex::MultiFab* ForceRestorePrecipRate::rate ( int  lev) const
inlinenoexcept

The rate of the last end_step [kg/m^2/s] (Comp components), or nullptr. For output.

100  {
101  return defined(lev) ? m_rate[lev].get() : nullptr;
102  }

Referenced by TwoStreamRadiation::hydrology_rain_rate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize()

void ForceRestorePrecipRate::resize ( int  nlevs_max)
13 {
14  m_accum_start.resize(nlevs_max);
15  m_accum_now.resize(nlevs_max);
16  m_rate.resize(nlevs_max);
17  m_started.resize(nlevs_max, 0);
18  m_unused.resize(nlevs_max, 0);
19  m_elapsed.resize(nlevs_max, 0.0);
20 }

◆ split()

bool ForceRestorePrecipRate::split ( ) const
inlinenoexcept

True when the rate is split into rain and frozen precipitation.

70 { return m_split; }

Member Data Documentation

◆ m_accum_now

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ForceRestorePrecipRate::m_accum_now
private

work field of end_step

◆ m_accum_start

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ForceRestorePrecipRate::m_accum_start
private

accumulation at the step start

◆ m_elapsed

amrex::Vector<amrex::Real> ForceRestorePrecipRate::m_elapsed
private

time since m_accum_start [s]

◆ m_noted_no_frozen

bool ForceRestorePrecipRate::m_noted_no_frozen = false
private

the no-frozen-accumulator note was printed

◆ m_rate

amrex::Vector<std::unique_ptr<amrex::MultiFab> > ForceRestorePrecipRate::m_rate
private

rate of the last end_step

Referenced by defined(), and rate().

◆ m_split

bool ForceRestorePrecipRate::m_split = false
private

rain and frozen apart (seb_snow_enable)

Referenced by frozen(), and split().

◆ m_started

amrex::Vector<int> ForceRestorePrecipRate::m_started
private

begin_step ran this step

◆ m_unused

amrex::Vector<int> ForceRestorePrecipRate::m_unused
private

end_step's rate not yet taken by a step


The documentation for this class was generated from the following files: