Allocate and fill drag and, optionally, frontal-area-density fields.
Neither argument is defaulted on purpose: every caller must state whether the frontal-area field is needed, so that a new call site cannot silently allocate and fill it when forest biophysics is off, nor report a placeholder level in the coverage warning.
295 const auto&
dx = geom.CellSizeArray();
296 const auto&
prob_lo = geom.ProbLoArray();
298 bool all_boxes_touch_bottom =
true;
299 for (
int i = 0; i < ba.size(); i++) {
300 if (ba[i].smallEnd(2) != geom.Domain().smallEnd(2)) {
301 all_boxes_touch_bottom =
false;
306 "Forest drag needs every box of the level to reach the ground: do not split the grids "
307 "in z (amr.max_grid_size in z at least the number of cells in z), and refine forested "
308 "levels from the ground up");
325 const Real zero_d =
zero;
326 const Real one_d =
one;
327 const Real myhalf_d =
myhalf;
328 const Real fourth_d =
fourth;
348 *
m_forest_drag, geom, grid_xmin, grid_ymin, grid_dx, grid_dy,
349 grid_nx, grid_ny, level);
352 Gpu::DeviceVector<Real> lai_data_d(grid_size);
353 Gpu::DeviceVector<Real> height_data_d(grid_size);
354 Gpu::DeviceVector<Real> cd_data_d;
356 cd_data_d.resize(grid_size);
359 Gpu::copy(Gpu::hostToDevice, lai_data_h, lai_data_h + grid_size,
361 Gpu::copy(Gpu::hostToDevice, height_data_h, height_data_h + grid_size,
362 height_data_d.begin());
364 Gpu::copy(Gpu::hostToDevice, cd_data_h, cd_data_h + grid_size,
368 const Real* lai_data = lai_data_d.data();
369 const Real* height_data = height_data_d.data();
370 const Real* cd_data =
m_use_const_cd ? nullptr : cd_data_d.data();
379 Box gtbx = mfi.growntilebox();
381 const Array4<Real> frontalArea = store_frontal_area
383 const Array4<const Real>& z_cc = z_phys_cc->const_array(mfi);
384 const Array4<const Real>& z_nd = z_phys_nd->const_array(mfi);
386 ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
388 const Real
x =
prob_lo[0] + (i + myhalf_d) *
dx[0];
389 const Real
y =
prob_lo[1] + (j + myhalf_d) *
dx[1];
391 const Real z_sfc = fourth_d * (z_nd(i, j, 0) + z_nd(i + 1, j, 0) +
392 z_nd(i, j + 1, 0) + z_nd(i + 1, j + 1, 0));
393 const Real
z = amrex::max((z_cc(i, j, k) - z_sfc), zero_d);
396 x, grid_xmin, grid_dx, grid_nx);
398 y, grid_ymin, grid_dy, grid_ny);
400 if (x_stencil.inside && y_stencil.inside) {
401 const int ii_c = x_stencil.lower;
402 const int jj_c = y_stencil.lower;
403 const Real wx = x_stencil.weight;
404 const Real wy = y_stencil.weight;
407 Real lai00 = lai_data[jj_c * grid_nx + ii_c];
408 Real lai10 = lai_data[jj_c * grid_nx + (ii_c + 1)];
409 Real lai01 = lai_data[(jj_c + 1) * grid_nx + ii_c];
410 Real lai11 = lai_data[(jj_c + 1) * grid_nx + (ii_c + 1)];
411 Real lai_interp = (lai00 * (one_d - wx) + lai10 * wx) * (one_d - wy) +
412 (lai01 * (one_d - wx) + lai11 * wx) * wy;
415 Real h00 = height_data[jj_c * grid_nx + ii_c];
416 Real h10 = height_data[jj_c * grid_nx + (ii_c + 1)];
417 Real h01 = height_data[(jj_c + 1) * grid_nx + ii_c];
418 Real h11 = height_data[(jj_c + 1) * grid_nx + (ii_c + 1)];
419 Real height_interp = (h00 * (one_d - wx) + h10 * wx) * (one_d - wy) +
420 (h01 * (one_d - wx) + h11 * wx) * wy;
422 Real cd_interp = cd_const;
425 Real cd00 = cd_data[jj_c * grid_nx + ii_c];
426 Real cd10 = cd_data[jj_c * grid_nx + (ii_c + 1)];
427 Real cd01 = cd_data[(jj_c + 1) * grid_nx + ii_c];
428 Real cd11 = cd_data[(jj_c + 1) * grid_nx + (ii_c + 1)];
429 cd_interp = (cd00 * (one_d - wx) + cd10 * wx) * (one_d - wy) +
430 (cd01 * (one_d - wx) + cd11 * wx) * wy;
434 if (z < height_interp && height_interp > zero_d && lai_interp > zero_d) {
438 if (tree_type == 1) {
439 af = lai_interp / height_interp;
441 const Real treeZm = laimax * height_interp;
442 af = lai_interp / (height_interp * lad_normalization);
444 Real ratio = (height_interp - treeZm) / (height_interp -
z);
446 factor = amrex::Math::powi<6>(ratio) *
447 std::exp(Real(6.0) * (one_d - ratio));
449 factor = std::sqrt(ratio) *
450 std::exp(myhalf_d * (one_d - ratio));
454 levelDrag(i, j, k) = cd_interp * af * factor;
455 if (store_frontal_area) {
456 frontalArea(i, j, k) = af * factor;
471 for (
unsigned ii = 0; ii <
m_x_forest.size(); ++ii) {
473 Real treeZm = zero_d;
486 treeZm = laimaxf * hf;
491 Box gtbx = mfi.growntilebox();
493 const Array4<Real> frontalArea = store_frontal_area
495 const Array4<const Real>& z_cc = z_phys_cc->const_array(mfi);
496 const Array4<const Real>& z_nd = z_phys_nd->const_array(mfi);
498 ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
500 const Real
x =
prob_lo[0] + (i + myhalf_d) *
dx[0];
501 const Real
y =
prob_lo[1] + (j + myhalf_d) *
dx[1];
503 const Real z_sfc = fourth_d * (z_nd(i,j ,0) + z_nd(i+1,j ,0)
504 + z_nd(i,j+1,0) + z_nd(i+1,j+1,0));
505 const Real
z = std::max((z_cc(i,j,k)-z_sfc), amrex::Real(0));
507 const Real radius = std::sqrt((
x - xf) * (
x - xf) +
508 (
y - yf) * (
y - yf));
514 if ((
z < hf) && (radius <= (myhalf_d * df))) {
516 Real ratio = (hf - treeZm) / (hf -
z);
518 factor = amrex::Math::powi<6>(ratio) *
519 std::exp(Real(6.0) * (one_d - ratio));
521 factor = std::sqrt(ratio) *
522 std::exp(myhalf_d * (one_d - ratio));
525 levelDrag(i, j, k) += cdf * af * factor;
526 if (store_frontal_area) {
527 frontalArea(i, j, k) += af * factor;
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:34
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);})
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
amrex::Real m_lad_normalization
Definition: ERF_ForestDrag.H:119
bool m_need_frontal_area
Definition: ERF_ForestDrag.H:85
amrex::Real m_grid_xmin
Definition: ERF_ForestDrag.H:110
amrex::Real m_grid_dy
Definition: ERF_ForestDrag.H:109
int m_grid_nx
Definition: ERF_ForestDrag.H:106
amrex::Vector< amrex::Real > m_gridded_lai
Definition: ERF_ForestDrag.H:102
int m_tree_type
Definition: ERF_ForestDrag.H:114
amrex::Vector< amrex::Real > m_gridded_height
Definition: ERF_ForestDrag.H:103
amrex::Real m_grid_dx
Definition: ERF_ForestDrag.H:108
amrex::Real m_laimax
Definition: ERF_ForestDrag.H:115
std::unique_ptr< amrex::MultiFab > m_frontal_area
Definition: ERF_ForestDrag.H:125
amrex::Vector< amrex::Real > m_gridded_cd
Definition: ERF_ForestDrag.H:104
amrex::Real m_cd_const
Definition: ERF_ForestDrag.H:89
bool m_use_gridded_data
Definition: ERF_ForestDrag.H:82
std::unique_ptr< amrex::MultiFab > m_forest_drag
Definition: ERF_ForestDrag.H:122
int m_grid_ny
Definition: ERF_ForestDrag.H:107
bool m_use_const_cd
Definition: ERF_ForestDrag.H:88
amrex::Real m_grid_ymin
Definition: ERF_ForestDrag.H:111
Real compute_lad_normalization(const Real laimax)
Definition: ERF_ForestDrag.cpp:18
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)
Definition: ERF_ForestDrag.cpp:46
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