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

Functions

Real compute_lad_normalization (const Real laimax)
 
void warn_if_forest_grid_does_not_cover_targets (const MultiFab &target_field, const Geometry &geom, Real grid_xmin, Real grid_ymin, Real grid_dx, Real grid_dy, int grid_nx, int grid_ny, int level)
 

Variables

constexpr int lad_quadrature_points = 100
 

Function Documentation

◆ compute_lad_normalization()

Real erf_detail_ForestDrag::compute_lad_normalization ( const Real  laimax)
19 {
20  const std::string error = erf_forest_utils::validate_laimax(
21  laimax, "erf.forest_laimax");
22  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(error.empty(), error.c_str());
23 
24  const Real inv_n = Real(1.0) / Real(lad_quadrature_points);
25  Real profile_sum = Real(0.0);
26  for (int kk = 0; kk < lad_quadrature_points; ++kk) {
27  const Real eta = Real(kk) * inv_n;
28  const Real ratio = (Real(1.0) - laimax) / (Real(1.0) - eta);
29  if (eta < laimax) {
30  profile_sum += amrex::Math::powi<6>(ratio) *
31  std::exp(Real(6.0) * (Real(1.0) - ratio));
32  } else {
33  profile_sum += std::sqrt(ratio) *
34  std::exp(Real(0.5) * (Real(1.0) - ratio));
35  }
36  }
37 
38  const Real normalization = profile_sum * inv_n;
40  std::isfinite(normalization) && normalization > Real(0.0),
41  "Lalic--Mihailovic LAD normalization must be finite and positive");
42  return normalization;
43 }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
constexpr int lad_quadrature_points
Definition: ERF_ForestDrag.cpp:15
std::string validate_laimax(const amrex::Real laimax, const std::string &source)
Definition: ERF_ForestUtils.H:36

Referenced by ForestDrag::define_drag_field().

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

◆ warn_if_forest_grid_does_not_cover_targets()

void erf_detail_ForestDrag::warn_if_forest_grid_does_not_cover_targets ( const MultiFab &  target_field,
const Geometry &  geom,
Real  grid_xmin,
Real  grid_ymin,
Real  grid_dx,
Real  grid_dy,
int  grid_nx,
int  grid_ny,
int  level 
)
52 {
53  ReduceOps<ReduceOpSum, ReduceOpSum> reduce_op;
54  ReduceData<Long, Long> reduce_data(reduce_op);
55  const auto dx = geom.CellSizeArray();
56  const auto prob_lo = geom.ProbLoArray();
57  const int source_xmax = grid_nx - 1;
58  const int source_ymax = grid_ny - 1;
59 
60  // The coverage test is purely horizontal, so count each target column
61  // once: reduce over a single k plane rather than the full 3-D box. Tiles
62  // partition the valid box, so restricting to the one tile that contains
63  // k_ref visits every (i,j) column exactly once. Note also that the box
64  // must come from tilebox(), not validbox(): with TilingIfNotGPU() true on
65  // CPU the iterator yields one entry per tile while validbox() always
66  // returns the whole FAB, which would re-count the entire box per tile.
67  const int k_ref = geom.Domain().smallEnd(2);
68 
69  for (MFIter mfi(target_field, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
70  Box box = mfi.tilebox();
71  if (box.smallEnd(2) > k_ref || box.bigEnd(2) < k_ref) { continue; }
72  box.setSmall(2, k_ref);
73  box.setBig(2, k_ref);
74  reduce_op.eval(box, reduce_data,
75  [=] AMREX_GPU_DEVICE (int i, int j, int /*k*/) -> GpuTuple<Long, Long> {
76  const Real x = prob_lo[0] + (static_cast<Real>(i) + Real(0.5)) * dx[0];
77  const Real y = prob_lo[1] + (static_cast<Real>(j) + Real(0.5)) * dx[1];
78  const auto x_stencil = erf_grid_utils::uniform_interpolation_stencil(
79  x, grid_xmin, grid_dx, grid_nx);
80  const auto y_stencil = erf_grid_utils::uniform_interpolation_stencil(
81  y, grid_ymin, grid_dy, grid_ny);
82  const Long outside = (x_stencil.inside && y_stencil.inside) ? Long(0) : Long(1);
83  return {Long(1), outside};
84  });
85  }
86 
87  const auto local = reduce_data.value();
88  Long total_targets = amrex::get<0>(local);
89  Long outside_targets = amrex::get<1>(local);
90  ParallelDescriptor::ReduceLongSum(total_targets);
91  ParallelDescriptor::ReduceLongSum(outside_targets);
92  if (ParallelDescriptor::IOProcessor() && outside_targets > 0) {
93  const Real source_xhi = grid_xmin + static_cast<Real>(source_xmax) * grid_dx;
94  const Real source_yhi = grid_ymin + static_cast<Real>(source_ymax) * grid_dy;
95  const Real target_xlo = geom.ProbLo(0) + Real(0.5) * geom.CellSize(0);
96  const Real target_ylo = geom.ProbLo(1) + Real(0.5) * geom.CellSize(1);
97  const Real target_xhi = geom.ProbHi(0) - Real(0.5) * geom.CellSize(0);
98  const Real target_yhi = geom.ProbHi(1) - Real(0.5) * geom.CellSize(1);
99  const Real percentage = total_targets > 0
100  ? Real(100.0) * static_cast<Real>(outside_targets) /
101  static_cast<Real>(total_targets) : Real(0.0);
102  Print() << "WARNING: Forest source grid does not cover ERF target cell centers"
103  << " at level " << level << ": outside " << outside_targets << " of "
104  << total_targets << " (" << percentage << "%). Source extent x=["
105  << grid_xmin << ", " << source_xhi << "] y=[" << grid_ymin << ", "
106  << source_yhi << "]; target extent x=[" << target_xlo << ", "
107  << target_xhi << "] y=[" << target_ylo << ", " << target_yhi << "].\n";
108  }
109 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:34
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE InterpolationStencil uniform_interpolation_stencil(amrex::Real coordinate, amrex::Real origin, amrex::Real spacing, int point_count) noexcept
Definition: ERF_GridUtils.H:305

Referenced by ForestDrag::define_drag_field().

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

Variable Documentation

◆ lad_quadrature_points

constexpr int erf_detail_ForestDrag::lad_quadrature_points = 100
constexpr