ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SEBLandMask.H
Go to the documentation of this file.
1 #ifndef ERF_SEB_LAND_MASK_H_
2 #define ERF_SEB_LAND_MASK_H_
3 
4 #include <string>
5 
6 #include <AMReX.H>
7 #include <AMReX_Array4.H>
8 #include <AMReX_FabArrayBase.H>
9 #include <AMReX_GpuQualifiers.H>
10 #include <AMReX_MFIter.H>
11 #include <AMReX_iMultiFab.H>
12 
13 /**
14  * @file ERF_SEBLandMask.H
15  * @brief The one place that says how the two-stream force-restore balance reads the land
16  * mask (ERF::lmask_lev: 0 water, 1 land, 2 a building's column).
17  *
18  * The balance is a model of soil. A column is left out of it when the mask is 0 there.
19  * The balance, its snow and hydrology steps, the albedo with snow, the average-down and
20  * the fill of a new level all ask through this file, so a change of the rule is one edit.
21  */
22 
23 /**
24  * @brief The land mask of one box, for a device kernel. Captured by value.
25  *
26  * With no mask (on == false) no column is water.
27  */
29 {
30  bool on = false;
31  amrex::Array4<const int> arr;
32 
33  /** @brief True when the balance does not run on column (i, j). */
34  [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
35  bool water (int i, int j) const noexcept { return on && arr(i, j, 0) == 0; }
36 };
37 
38 /**
39  * @brief Stop when @p mask is given and is not on the grids of @p field.
40  * @param who the caller, named in the message
41  */
42 inline void
43 seb_assert_land_mask_layout (const amrex::iMultiFab* mask, const amrex::FabArrayBase& field,
44  const char* who)
45 {
46  if (mask == nullptr) { return; }
47  if (mask->boxArray() != field.boxArray() || mask->DistributionMap() != field.DistributionMap()) {
48  amrex::Abort(std::string(who) + ": the land mask is not on the level's 2D grids");
49  }
50 }
51 
52 /** @brief The view of @p mask on the box of @p mfi; off when @p mask is nullptr. */
53 [[nodiscard]] inline SEBLandMaskView
54 seb_land_mask_view (const amrex::iMultiFab* mask, const amrex::MFIter& mfi)
55 {
57  v.on = (mask != nullptr);
58  if (v.on) { v.arr = mask->const_array(mfi); }
59  return v;
60 }
61 
62 /**
63  * @brief True when @p mask holds a water column on any rank; false for nullptr.
64  *
65  * Read from the mask each time it is asked: the mask can be rewritten during a run (the
66  * WW3 coupling does), and a cached answer would then be wrong. One reduction and one MPI
67  * collective per call.
68  */
69 [[nodiscard]] inline bool
70 seb_land_mask_has_water (const amrex::iMultiFab* mask)
71 {
72  return mask != nullptr && mask->min(0) == 0;
73 }
74 
75 #endif
SEBLandMaskView seb_land_mask_view(const amrex::iMultiFab *mask, const amrex::MFIter &mfi)
The view of mask on the box of mfi; off when mask is nullptr.
Definition: ERF_SEBLandMask.H:54
bool seb_land_mask_has_water(const amrex::iMultiFab *mask)
True when mask holds a water column on any rank; false for nullptr.
Definition: ERF_SEBLandMask.H:70
void seb_assert_land_mask_layout(const amrex::iMultiFab *mask, const amrex::FabArrayBase &field, const char *who)
Stop when mask is given and is not on the grids of field.
Definition: ERF_SEBLandMask.H:43
The land mask of one box, for a device kernel. Captured by value.
Definition: ERF_SEBLandMask.H:29
amrex::Array4< const int > arr
Definition: ERF_SEBLandMask.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool water(int i, int j) const noexcept
True when the balance does not run on column (i, j).
Definition: ERF_SEBLandMask.H:35
bool on
Definition: ERF_SEBLandMask.H:30