ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SurfacePrecipitation.H File Reference
#include <AMReX_GpuQualifiers.H>
#include <AMReX_MultiFab.H>
#include <AMReX_MFIter.H>
#include <AMReX_REAL.H>
Include dependency graph for ERF_SurfacePrecipitation.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SurfacePrecipAccumulationSource
 
struct  SurfacePrecipAccumulationSources
 

Enumerations

enum class  SurfacePrecipPhase { Total , Liquid , Frozen }
 Which part of the surface precipitation surface_precip_accum_k0 returns. More...
 

Functions

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_source (const SurfacePrecipAccumulationSource &src) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_total_source (const SurfacePrecipAccumulationSources &src) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_explicit_rain_source (const SurfacePrecipAccumulationSources &src) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_any_source (const SurfacePrecipAccumulationSources &src) noexcept
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_any_frozen_source (const SurfacePrecipAccumulationSources &src) noexcept
 
void surface_precip_fill_k0 (amrex::MultiFab &accum_2d, const SurfacePrecipAccumulationSources &sources, int klo, SurfacePrecipPhase phase, bool frozen_in_comp1)
 The work of surface_precip_accum_k0 and surface_precip_liquid_frozen_accum_k0: component 0 of accum_2d takes the phase part and, with frozen_in_comp1, component 1 takes the frozen part from the same pass over the accumulators. More...
 
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, from the scheme-native accumulators. More...
 
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), from one pass over the accumulators; each as surface_precip_accum_k0 gives it. More...
 

Enumeration Type Documentation

◆ SurfacePrecipPhase

enum SurfacePrecipPhase
strong

Which part of the surface precipitation surface_precip_accum_k0 returns.

Enumerator
Total 
Liquid 
Frozen 

Function Documentation

◆ surface_precip_accum_k0()

void surface_precip_accum_k0 ( amrex::MultiFab &  accum_2d,
const SurfacePrecipAccumulationSources &  sources,
int  klo,
SurfacePrecipPhase  phase = SurfacePrecipPhase::Total 
)
inline

Total liquid-water-equivalent surface precipitation accumulation [kg/m2] of every column, from the scheme-native accumulators.

Fills component 0 of accum_2d, a MultiFab on the level's boxes coarsened to one cell in z (box n of accum_2d is box n of the accumulators, with the same owner), from the k = klo plane of the sources. Schemes that provide a total give it directly; schemes that provide the species give their sum, so nothing is counted twice (the same rule as the 2D plotfile precipitation diagnostics). Without any source the field is zero. A box whose 3D box does not hold the k = klo plane (a fine level that does not span z, or the upper box of a column split in z) has no ground to read and stays zero, so no accumulator is read outside its box. Used by the fire layer's fuel moisture (ERF_FirePrecip.H) and the force-restore precipitation rate (ERF_ForceRestorePrecipRate.H).

With phase = Frozen the field is the frozen part, snow + graupel + hail (zero for a scheme without those accumulators). With phase = Liquid it is the rest: the total minus the frozen part, or without a total the rain accumulator. Frozen plus Liquid is then the Total field for every scheme with a total, including one whose total holds more than its species (Morrison's also counts the cloud water and cloud ice that fell out, and both stay in its Liquid part). Where sources.rest_is_frozen is set (WSM6, WDM6: the rest is cloud ice), Frozen is the total minus the rain and Liquid is the rain. The part that is a difference is not bounded at zero: Liquid where the frozen accumulators exceed the total by round-off, and Frozen (rest_is_frozen) where the rain exceeds the total by round-off. A caller that takes the change over a step bounds that change (force_restore_rain_rate).

211 {
212  surface_precip_fill_k0(accum_2d, sources, klo, phase, false);
213 }
const int klo
Definition: ERF_InitCustomPert_KE.H:9
void surface_precip_fill_k0(amrex::MultiFab &accum_2d, const SurfacePrecipAccumulationSources &sources, int klo, SurfacePrecipPhase phase, bool frozen_in_comp1)
The work of surface_precip_accum_k0 and surface_precip_liquid_frozen_accum_k0: component 0 of accum_2...
Definition: ERF_SurfacePrecipitation.H:94

Referenced by ForceRestorePrecipRate::fill_accumulation(), and fire_surface_precip_accum_k0().

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

◆ surface_precip_fill_k0()

void surface_precip_fill_k0 ( amrex::MultiFab &  accum_2d,
const SurfacePrecipAccumulationSources &  sources,
int  klo,
SurfacePrecipPhase  phase,
bool  frozen_in_comp1 
)
inline

The work of surface_precip_accum_k0 and surface_precip_liquid_frozen_accum_k0: component 0 of accum_2d takes the phase part and, with frozen_in_comp1, component 1 takes the frozen part from the same pass over the accumulators.

97 {
98  using namespace amrex;
99  AMREX_ALWAYS_ASSERT(accum_2d.nComp() >= (frozen_in_comp1 ? 2 : 1));
100  accum_2d.setVal(Real(0.0));
101  if (!surface_precip_has_any_source(sources)) { return; }
102 
103  const bool has_total = surface_precip_has_source(sources.total);
104  const bool has_rain = surface_precip_has_source(sources.rain);
105  const bool has_snow = surface_precip_has_source(sources.snow);
106  const bool has_graupel = surface_precip_has_source(sources.graupel);
107  const bool has_hail = surface_precip_has_source(sources.hail);
108  const Real f_total = sources.total.native_to_kg_m2;
109  const Real f_rain = sources.rain.native_to_kg_m2;
110  const Real f_snow = sources.snow.native_to_kg_m2;
111  const Real f_graupel = sources.graupel.native_to_kg_m2;
112  const Real f_hail = sources.hail.native_to_kg_m2;
113  // The total less the rain is the frozen part, and the rain is the liquid part
114  const bool rest_frozen = sources.rest_is_frozen && has_total;
115  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!rest_frozen || has_rain,
116  "surface_precip_fill_k0: rest_is_frozen needs a rain accumulator");
117 
118  // Whether box n of a source holds the plane k = klo.
119  auto holds_klo = [klo] (const SurfacePrecipAccumulationSource& src, int n) {
120  if (!surface_precip_has_source(src)) { return true; }
121  const Box& b = src.accum->boxArray()[n];
122  return b.smallEnd(2) <= klo && klo <= b.bigEnd(2);
123  };
124 
125  for (MFIter mfi(accum_2d, false); mfi.isValid(); ++mfi) {
126  const int n = mfi.index();
127  if (!(holds_klo(sources.total, n) && holds_klo(sources.rain, n) &&
128  holds_klo(sources.snow, n) && holds_klo(sources.graupel, n) &&
129  holds_klo(sources.hail, n))) { continue; }
130  Array4<Real> a = accum_2d.array(mfi);
131  Array4<const Real> total = has_total ? sources.total.accum->const_array(mfi) : Array4<const Real>{};
132  Array4<const Real> rain = has_rain ? sources.rain.accum->const_array(mfi) : Array4<const Real>{};
133  Array4<const Real> snow = has_snow ? sources.snow.accum->const_array(mfi) : Array4<const Real>{};
134  Array4<const Real> graupel = has_graupel ? sources.graupel.accum->const_array(mfi) : Array4<const Real>{};
135  Array4<const Real> hail = has_hail ? sources.hail.accum->const_array(mfi) : Array4<const Real>{};
136  ParallelFor(mfi.tilebox(), [=] AMREX_GPU_DEVICE (const IntVect& iv) noexcept
137  {
138  const int i = iv[0], j = iv[1];
139  Real frozen = Real(0.0);
140  if (phase != SurfacePrecipPhase::Total || frozen_in_comp1) {
141  if (rest_frozen) {
142  frozen = total(i, j, klo) * f_total - rain(i, j, klo) * f_rain;
143  } else {
144  if (has_snow) { frozen += snow(i, j, klo) * f_snow; }
145  if (has_graupel) { frozen += graupel(i, j, klo) * f_graupel; }
146  if (has_hail) { frozen += hail(i, j, klo) * f_hail; }
147  }
148  }
149  Real v;
150  if (phase == SurfacePrecipPhase::Frozen) {
151  v = frozen;
152  } else if (phase == SurfacePrecipPhase::Liquid) {
153  // No bound here: this is an accumulation, and a bound on it would change the
154  // difference of two of its values. The user bounds that difference.
155  if (rest_frozen) {
156  v = rain(i, j, klo) * f_rain;
157  } else if (has_total) {
158  v = total(i, j, klo) * f_total - frozen;
159  } else {
160  v = has_rain ? rain(i, j, klo) * f_rain : Real(0.0);
161  }
162  } else if (has_total) {
163  v = total(i, j, klo) * f_total;
164  } else {
165  v = Real(0.0);
166  if (has_rain) { v += rain(i, j, klo) * f_rain; }
167  if (has_snow) { v += snow(i, j, klo) * f_snow; }
168  if (has_graupel) { v += graupel(i, j, klo) * f_graupel; }
169  if (has_hail) { v += hail(i, j, klo) * f_hail; }
170  }
171  a(i, j, 0, 0) = v;
172  if (frozen_in_comp1) { a(i, j, 0, 1) = frozen; }
173  });
174  }
175 }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
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);})
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_source(const SurfacePrecipAccumulationSource &src) noexcept
Definition: ERF_SurfacePrecipitation.H:50
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_any_source(const SurfacePrecipAccumulationSources &src) noexcept
Definition: ERF_SurfacePrecipitation.H:68
@ graupel
Definition: ERF_NOAHMP_Fields.H:140
@ rain
Definition: ERF_NOAHMP_Fields.H:138
@ total
Definition: ERF_NOAHMP_Fields.H:137
@ hail
Definition: ERF_NOAHMP_Fields.H:141
@ snow
Definition: ERF_NOAHMP_Fields.H:139
Definition: ERF_ConsoleIO.cpp:17
Definition: ERF_SurfacePrecipitation.H:21
const amrex::MultiFab * accum
Definition: ERF_SurfacePrecipitation.H:22
amrex::Real native_to_kg_m2
Definition: ERF_SurfacePrecipitation.H:23
bool rest_is_frozen
Definition: ERF_SurfacePrecipitation.H:46
SurfacePrecipAccumulationSource rain
Definition: ERF_SurfacePrecipitation.H:42
SurfacePrecipAccumulationSource snow
Definition: ERF_SurfacePrecipitation.H:43
SurfacePrecipAccumulationSource hail
Definition: ERF_SurfacePrecipitation.H:45
SurfacePrecipAccumulationSource total
Definition: ERF_SurfacePrecipitation.H:41
SurfacePrecipAccumulationSource graupel
Definition: ERF_SurfacePrecipitation.H:44

Referenced by surface_precip_accum_k0(), and surface_precip_liquid_frozen_accum_k0().

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

◆ surface_precip_has_any_frozen_source()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_any_frozen_source ( const SurfacePrecipAccumulationSources &  src)
noexcept
79 {
80  // Public frozen precipitation is available whenever the scheme has any
81  // precipitation source, because the IO layer can derive the frozen field
82  // from the total or species accumulators and fill zero for warm-rain cases.
84 }

Referenced by plotfile2d::selected_precipitation_accumulation_components().

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

◆ surface_precip_has_any_source()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_any_source ( const SurfacePrecipAccumulationSources &  src)
noexcept

◆ surface_precip_has_explicit_rain_source()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_explicit_rain_source ( const SurfacePrecipAccumulationSources &  src)
noexcept
63 {
64  return surface_precip_has_source(src.rain);
65 }
Here is the call graph for this function:

◆ surface_precip_has_source()

◆ surface_precip_has_total_source()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_total_source ( const SurfacePrecipAccumulationSources &  src)
noexcept
57 {
58  return surface_precip_has_source(src.total);
59 }

Referenced by ERF::ReadCheckpointFile(), plotfile2d::selected_precipitation_accumulation_components(), and erf_detail_AdvanceLSM::update_slm_precipitation().

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

◆ surface_precip_liquid_frozen_accum_k0()

void surface_precip_liquid_frozen_accum_k0 ( amrex::MultiFab &  accum_2d,
const SurfacePrecipAccumulationSources &  sources,
int  klo 
)
inline

The Liquid accumulation in component 0 and the Frozen one in component 1 of accum_2d (two components), from one pass over the accumulators; each as surface_precip_accum_k0 gives it.

223 {
224  surface_precip_fill_k0(accum_2d, sources, klo, SurfacePrecipPhase::Liquid, true);
225 }

Referenced by FloodCoupler::advance(), ForceRestorePrecipRate::fill_accumulation(), and FloodCoupler::set_precip_reference().

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