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

#include <ERF_TypedInterp.H>

Inheritance diagram for TypedConsLinear:
Collaboration diagram for TypedConsLinear:

Public Member Functions

 TypedConsLinear (int nind=1)
 
amrex::Box CoarseBox (const amrex::Box &fine, const amrex::IntVect &ratio) override
 
amrex::Box CoarseBox (const amrex::Box &fine, int ratio) override
 
void interp (const amrex::FArrayBox &crse, int crse_comp, amrex::FArrayBox &fine, int fine_comp, int ncomp, const amrex::Box &fine_region, const amrex::IntVect &ratio, const amrex::Geometry &crse_geom, const amrex::Geometry &, amrex::Vector< amrex::BCRec > const &bcr, int, int, amrex::RunOn runon) override
 

Private Attributes

int m_nind
 

Detailed Description

Conservative linear interpolation that does not mix cells of different types, in the spirit of WRF's land/water-masked nest interpolation (erf-model/ERF#4390). Every cell is interpolated; a cell's type decides only which neighbors its slopes and limiter may see. The types are whatever the caller encodes: land and water (SLM's state), a valid value and the lsm_undefined sentinel (Noah-MP), or both at once (SLM's fluxes).

The coarse data carries nfield fields followed by nind type indicators (one value per type; NaN, no type, outside the domain). With nind == 1 every field shares the one indicator; with nind == nfield field n has indicator n. In each direction the slope of a coarse cell is taken only if both of its neighbors are of the same type as the cell; otherwise it is zero, as it is at a domain boundary. The min/max limiter likewise looks only at neighbors of the same type. Where every neighbor is of the same type this is exactly AMReX's cell_cons_interp (CellConservativeLinear without linear limiting), so the result changes only next to a type boundary. Each coarse cell's mean is kept, and the indicator is copied (piecewise constant), so a cell whose neighbors are all of other types (an isolated sentinel, say) comes through exactly.

Constructor & Destructor Documentation

◆ TypedConsLinear()

TypedConsLinear::TypedConsLinear ( int  nind = 1)
inlineexplicit
33 : m_nind(nind) {}
int m_nind
Definition: ERF_TypedInterp.H:57

Member Function Documentation

◆ CoarseBox() [1/2]

amrex::Box TypedConsLinear::CoarseBox ( const amrex::Box &  fine,
const amrex::IntVect &  ratio 
)
inlineoverride
36  {
37  amrex::Box crse = amrex::coarsen(fine, ratio);
38  for (int dim = 0; dim < AMREX_SPACEDIM; ++dim) {
39  if (ratio[dim] > 1) { crse.grow(dim, 1); }
40  }
41  return crse;
42  }

Referenced by CoarseBox(), and interp().

Here is the caller graph for this function:

◆ CoarseBox() [2/2]

amrex::Box TypedConsLinear::CoarseBox ( const amrex::Box &  fine,
int  ratio 
)
inlineoverride
45  {
46  return CoarseBox(fine, amrex::IntVect(ratio));
47  }
amrex::Box CoarseBox(const amrex::Box &fine, const amrex::IntVect &ratio) override
Definition: ERF_TypedInterp.H:35
Here is the call graph for this function:

◆ interp()

void TypedConsLinear::interp ( const amrex::FArrayBox &  crse,
int  crse_comp,
amrex::FArrayBox &  fine,
int  fine_comp,
int  ncomp,
const amrex::Box &  fine_region,
const amrex::IntVect &  ratio,
const amrex::Geometry &  crse_geom,
const amrex::Geometry &  ,
amrex::Vector< amrex::BCRec > const &  bcr,
int  ,
int  ,
amrex::RunOn  runon 
)
inlineoverride
143 {
144  using namespace amrex;
145  const int nind = m_nind;
146  const int nfield = ncomp - nind;
147  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(nfield >= 1 && (nind == 1 || nind == nfield),
148  "TypedConsLinear interpolates nfield fields followed by 1 or nfield type indicators");
149  AMREX_ASSERT(fine.box().contains(fine_region));
150  AMREX_ASSERT(!bcr.empty());
151 
152  const Box& cdomain = crse_geom.Domain();
153  Array4<Real const> const& crsearr = crse.const_array();
154  Array4<Real> const& finearr = fine.array();
155 
156  Box cslope_bx = CoarseBox(fine_region, ratio);
157  for (int dim = 0; dim < AMREX_SPACEDIM; ++dim) {
158  if (ratio[dim] > 1) { cslope_bx.grow(dim, -1); }
159  }
160  const bool run_on_gpu = (runon == RunOn::Gpu && Gpu::inLaunchRegion());
161  FArrayBox ccfab(cslope_bx, AMREX_SPACEDIM*nfield, run_on_gpu ? The_Async_Arena() : The_Cpu_Arena());
162  Array4<Real> const& tmp = ccfab.array();
163  Array4<Real const> const& ctmp = ccfab.const_array();
164 
165  // Every field shares the boundary condition of the first
166  const BCRec bc = bcr[0];
167  const int ind_comp = crse_comp + nfield;
168 
169  AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(runon, cslope_bx, nfield, i, j, k, n,
170  {
171  const int nm = ind_comp + (nind == 1 ? 0 : n);
172  typed_mcslope(i, j, k, tmp, n, nfield, crsearr, crse_comp+n, nm, cdomain, ratio, bc);
173  });
174 
175  AMREX_HOST_DEVICE_PARALLEL_FOR_4D_FLAG(runon, fine_region, ncomp, i, j, k, n,
176  {
177  if (n < nfield) {
178  mf_cell_cons_lin_interp(i, j, k, n, finearr, fine_comp, ctmp, crsearr, crse_comp,
179  nfield, ratio);
180  } else {
181  finearr(i,j,k,fine_comp+n) = crsearr(amrex::coarsen(i,ratio[0]),
182  amrex::coarsen(j,ratio[1]),
183  amrex::coarsen(k,ratio[2]), crse_comp+n);
184  }
185  });
186 }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void typed_mcslope(int i, int j, int k, amrex::Array4< amrex::Real > const &slope, int ns, int nslope, amrex::Array4< amrex::Real const > const &u, int nu, int nm, amrex::Box const &domain, amrex::IntVect const &ratio, amrex::BCRec const &bc) noexcept
Definition: ERF_TypedInterp.H:66
@ tmp
Definition: ERF_AdvanceWSM6.cpp:116
Definition: ERF_ConsoleIO.cpp:17
real(c_double), private bc
Definition: ERF_module_mp_morr_two_moment.F90:182
Here is the call graph for this function:

Member Data Documentation

◆ m_nind

int TypedConsLinear::m_nind
private

Referenced by interp().


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