ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_actuator::erf_detail_ActuatorSampling Namespace Reference

Classes

struct  ColumnWork
 

Functions

void check_layout (const MultiFab &ref, const MultiFab *other, int ngrow, const std::string &what)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real column_value (Array4< Real const > const &f, int dir, int i, int j, int klo, int khi, Real z, Array4< Real const > const &znd, bool has_znd, Real zlo, Real dz)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real sample_component (int dir, Array4< Real const > const &f, Real x, Real y, Real z, const GpuArray< Real, AMREX_SPACEDIM > &plo, const GpuArray< Real, AMREX_SPACEDIM > &dxi, int klo, int khi, Array4< Real const > const &znd, bool has_znd, Real dz)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real centre_height (int i, int j, int k, Array4< Real const > const &znd, bool has_znd, Real zlo, Real dz)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real centre_column_value (Array4< Real const > const &f, int comp, int i, int j, int klo, int khi, Real z, Array4< Real const > const &znd, bool has_znd, Real zlo, Real dz)
 
void node_level_table (const MultiFab &z_phys_nd, const Geometry &geom, ZBounds &b)
 
void horizontal_node_ranges (const Real *b, const Geometry &geom, std::array< std::vector< std::array< int, 2 >>, 2 > &ranges)
 

Function Documentation

◆ centre_column_value()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_actuator::erf_detail_ActuatorSampling::centre_column_value ( Array4< Real const > const &  f,
int  comp,
int  i,
int  j,
int  klo,
int  khi,
Real  z,
Array4< Real const > const &  znd,
bool  has_znd,
Real  zlo,
Real  dz 
)
267 {
268  int k0 = klo;
269  for (int k = klo; k < khi; ++k) {
270  if (z >= centre_height(i, j, k, znd, has_znd, zlo, dz)) { k0 = k; } else { break; }
271  }
272  const Real h0 = centre_height(i, j, k0, znd, has_znd, zlo, dz);
273  const Real h1 = centre_height(i, j, k0+1, znd, has_znd, zlo, dz);
274  const Real w = (z - h0) / (h1 - h0);
275  return (Real(1.0) - w) * f(i,j,k0,comp) + w * f(i,j,k0+1,comp);
276 }
bool has_znd
Definition: ERF_ActuatorSpreading.cpp:134
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real centre_height(int i, int j, int k, Array4< Real const > const &znd, bool has_znd, Real zlo, Real dz)
Definition: ERF_ActuatorSampling.cpp:257

Referenced by erf_actuator::sample_cell_scalar().

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

◆ centre_height()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_actuator::erf_detail_ActuatorSampling::centre_height ( int  i,
int  j,
int  k,
Array4< Real const > const &  znd,
bool  has_znd,
Real  zlo,
Real  dz 
)
258 {
259  return Real(0.5) * (face_height(2, i, j, k, znd, has_znd, zlo, dz) + face_height(2, i, j, k+1, znd, has_znd, zlo, dz));
260 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real face_height(int dir, int i, int j, int k, amrex::Array4< amrex::Real const > const &znd, bool has_znd, amrex::Real zlo, amrex::Real dz)
Definition: ERF_ActuatorGeometry.H:20

Referenced by centre_column_value().

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

◆ check_layout()

void erf_actuator::erf_detail_ActuatorSampling::check_layout ( const MultiFab &  ref,
const MultiFab *  other,
int  ngrow,
const std::string &  what 
)
33 {
34  if (other == nullptr) { return; }
35  if (!(other->nGrow() >= ngrow && other->DistributionMap() == ref.DistributionMap() && other->boxArray().CellEqual(ref.boxArray()))) {
36  Abort(what + " must have " + std::to_string(ngrow) + " ghost cell(s) and the boxes and distribution of the field sampled");
37  }
38 }

Referenced by erf_actuator::sample_cell_scalar(), and erf_actuator::sample_velocity_local().

Here is the caller graph for this function:

◆ column_value()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_actuator::erf_detail_ActuatorSampling::column_value ( Array4< Real const > const &  f,
int  dir,
int  i,
int  j,
int  klo,
int  khi,
Real  z,
Array4< Real const > const &  znd,
bool  has_znd,
Real  zlo,
Real  dz 
)
47 {
48  int k0 = klo;
49  for (int k = klo; k < khi; ++k) {
50  if (z >= face_height(dir, i, j, k, znd, has_znd, zlo, dz)) { k0 = k; } else { break; }
51  }
52  const Real h0 = face_height(dir, i, j, k0, znd, has_znd, zlo, dz);
53  const Real h1 = face_height(dir, i, j, k0+1, znd, has_znd, zlo, dz);
54  const Real w = (z - h0) / (h1 - h0);
55  return (Real(1.0) - w) * f(i,j,k0) + w * f(i,j,k0+1);
56 }

Referenced by sample_component().

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

◆ horizontal_node_ranges()

void erf_actuator::erf_detail_ActuatorSampling::horizontal_node_ranges ( const Real *  b,
const Geometry &  geom,
std::array< std::vector< std::array< int, 2 >>, 2 > &  ranges 
)
586 {
587  const auto plo = geom.ProbLoArray();
588  const auto dxi = geom.InvCellSizeArray();
589  const Box& domain = geom.Domain();
590  for (int d = 0; d < 2; ++d) {
591  ranges[d].clear();
592  const int dlo = domain.smallEnd(d), dhi = domain.bigEnd(d), nc = dhi - dlo + 1;
593  // a bound more than a domain length outside (a diverged point) is clamped there, so the
594  // index stays an int; such a region already covers or misses the whole domain
595  const Real len = Real(nc) / dxi[d];
596  const Real blo = amrex::Clamp(b[d], plo[d] - len, plo[d] + Real(2.0) * len);
597  const Real bhi = amrex::Clamp(b[d+3], plo[d] - len, plo[d] + Real(2.0) * len);
598  const int clo = static_cast<int>(std::floor((blo - plo[d]) * dxi[d]));
599  const int chi = static_cast<int>(std::floor((bhi - plo[d]) * dxi[d]));
600  if (geom.isPeriodic(d)) {
601  const int nnodes = chi + 2 - clo; // nodes clo .. chi + 1
602  if (nnodes >= nc) {
603  ranges[d].push_back({{dlo, dhi + 1}});
604  } else {
605  const int a = dlo + (((clo - dlo) % nc) + nc) % nc;
606  const int e = a + nnodes - 1;
607  if (e <= dhi + 1) {
608  ranges[d].push_back({{a, e}});
609  } else {
610  ranges[d].push_back({{a, dhi + 1}});
611  ranges[d].push_back({{dlo, e - nc}});
612  }
613  }
614  } else {
615  const int a = std::max(clo, dlo), e = std::min(chi + 1, dhi + 1);
616  if (a <= e) { ranges[d].push_back({{a, e}}); }
617  }
618  }
619 }
GpuArray< int, AMREX_SPACEDIM > dhi
Definition: ERF_ActuatorSpreading.cpp:132
GpuArray< int, AMREX_SPACEDIM > dlo
Definition: ERF_ActuatorSpreading.cpp:132
GpuArray< Real, AMREX_SPACEDIM > plo
Definition: ERF_ActuatorSpreading.cpp:131
@ nc
Definition: ERF_Morrison.H:47

Referenced by erf_actuator::column_cell_ranges().

Here is the caller graph for this function:

◆ node_level_table()

void erf_actuator::erf_detail_ActuatorSampling::node_level_table ( const MultiFab &  z_phys_nd,
const Geometry &  geom,
ZBounds &  b 
)
462 {
463  const Real big = std::numeric_limits<Real>::max();
464  const Box& dom = geom.Domain();
465  b.k0 = dom.smallEnd(2);
466  const int nnode = dom.length(2) + 1;
467  const Box dom_nodes = amrex::surroundingNodes(dom);
468  Gpu::DeviceVector<Real> lo(nnode, big), hi(nnode, -big);
469  Real* plo = lo.data();
470  Real* phi = hi.data();
471  const int k0 = b.k0;
472  b.has_cell.assign(nnode - 1, 0);
473  for (MFIter mfi(z_phys_nd, false); mfi.isValid(); ++mfi) {
474  const Box nbx = mfi.validbox();
475  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(dom_nodes.contains(nbx), "mesh_z_bounds: z_phys_nd's boxes must lie in geom's domain");
476  Array4<Real const> const& znd = z_phys_nd.const_array(mfi);
477  const int ilo = nbx.smallEnd(0), ihi = nbx.bigEnd(0);
478  const int jlo = nbx.smallEnd(1), jhi = nbx.bigEnd(1);
479  const int klo = nbx.smallEnd(2);
480  ParallelFor(nbx.length(2), [=] AMREX_GPU_DEVICE (int n) noexcept
481  {
482  const int k = klo + n;
483  Real mn = big;
484  Real mx = -big;
485  for (int j = jlo; j <= jhi; ++j) {
486  for (int i = ilo; i <= ihi; ++i) {
487  mn = amrex::min(mn, znd(i,j,k));
488  mx = amrex::max(mx, znd(i,j,k));
489  }
490  }
491  Gpu::Atomic::Min(plo + (k - k0), mn);
492  Gpu::Atomic::Max(phi + (k - k0), mx);
493  });
494  // the box's cells: between its lowest and highest node levels
495  for (int k = nbx.smallEnd(2); k < nbx.bigEnd(2); ++k) { b.has_cell[k - b.k0] = 1; }
496  }
497  b.node_lo.resize(nnode);
498  b.node_hi.resize(nnode);
499  Gpu::copyAsync(Gpu::deviceToHost, lo.begin(), lo.end(), b.node_lo.begin());
500  Gpu::copyAsync(Gpu::deviceToHost, hi.begin(), hi.end(), b.node_hi.begin());
501  Gpu::streamSynchronize();
502 }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
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 amrex::Real phi(amrex::Real d, amrex::Real z0, amrex::Real psi) noexcept
Definition: ERF_ImmersedWallCell.H:176

Referenced by erf_actuator::mesh_z_bounds(), and erf_actuator::mesh_z_levels().

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

◆ sample_component()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real erf_actuator::erf_detail_ActuatorSampling::sample_component ( int  dir,
Array4< Real const > const &  f,
Real  x,
Real  y,
Real  z,
const GpuArray< Real, AMREX_SPACEDIM > &  plo,
const GpuArray< Real, AMREX_SPACEDIM > &  dxi,
int  klo,
int  khi,
Array4< Real const > const &  znd,
bool  has_znd,
Real  dz 
)
66 {
67  // fractional index on the component's own grid: whole numbers on faces, half on centers
68  const Real xi = (x - plo[0]) * dxi[0] - ((dir == 0) ? Real(0.0) : Real(0.5));
69  const Real yi = (y - plo[1]) * dxi[1] - ((dir == 1) ? Real(0.0) : Real(0.5));
70  const int i0 = static_cast<int>(std::floor(xi));
71  const int j0 = static_cast<int>(std::floor(yi));
72  const Real wx = xi - i0;
73  const Real wy = yi - j0;
74  const Real f00 = column_value(f, dir, i0, j0, klo, khi, z, znd, has_znd, plo[2], dz);
75  const Real f10 = column_value(f, dir, i0+1, j0, klo, khi, z, znd, has_znd, plo[2], dz);
76  const Real f01 = column_value(f, dir, i0, j0+1, klo, khi, z, znd, has_znd, plo[2], dz);
77  const Real f11 = column_value(f, dir, i0+1, j0+1, klo, khi, z, znd, has_znd, plo[2], dz);
78  return (Real(1.0) - wy) * ((Real(1.0) - wx) * f00 + wx * f10)
79  + wy * ((Real(1.0) - wx) * f01 + wx * f11);
80 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real column_value(Array4< Real const > const &f, int dir, int i, int j, int klo, int khi, Real z, Array4< Real const > const &znd, bool has_znd, Real zlo, Real dz)
Definition: ERF_ActuatorSampling.cpp:45
real(c_double), private f11
Definition: ERF_module_mp_morr_two_moment.F90:232

Referenced by erf_sbm::erf_detail_SBMTransport::fill_coarse_parent_ghosts(), and erf_actuator::sample_velocity_local().

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