ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ThinBodyWallDist.cpp File Reference
#include <AMReX.H>
#include <AMReX_MultiFab.H>
Include dependency graph for ERF_ThinBodyWallDist.cpp:

Functions

void thinbody_wall_dist (std::unique_ptr< MultiFab > &wdist, Vector< IntVect > &xfaces, Vector< IntVect > &yfaces, Vector< IntVect > &zfaces, const Geometry &geomdata, std::unique_ptr< MultiFab > &z_phys_cc)
 

Function Documentation

◆ thinbody_wall_dist()

void thinbody_wall_dist ( std::unique_ptr< MultiFab > &  wdist,
Vector< IntVect > &  xfaces,
Vector< IntVect > &  yfaces,
Vector< IntVect > &  zfaces,
const Geometry &  geomdata,
std::unique_ptr< MultiFab > &  z_phys_cc 
)
18 {
19  BL_PROFILE("thinbody_wall_dist()");
20 
21  const auto prob_lo = geomdata.ProbLoArray();
22  const auto dx = geomdata.CellSizeArray();
23 
24  const bool use_terrain = (z_phys_cc != nullptr);
25  if (use_terrain) {
26  Error("Thinbody wall dist calc not implemented for terrain yet");
27  }
28 
29  Gpu::DeviceVector<IntVect> xfaces_d(xfaces.size());
30  Gpu::DeviceVector<IntVect> yfaces_d(yfaces.size());
31  Gpu::DeviceVector<IntVect> zfaces_d(zfaces.size());
32  Gpu::copyAsync(Gpu::hostToDevice, xfaces.begin(), xfaces.end(), xfaces_d.begin());
33  Gpu::copyAsync(Gpu::hostToDevice, yfaces.begin(), yfaces.end(), yfaces_d.begin());
34  Gpu::copyAsync(Gpu::hostToDevice, zfaces.begin(), zfaces.end(), zfaces_d.begin());
35  auto const* xfaces_d_ptr = xfaces_d.data();
36  auto const* yfaces_d_ptr = yfaces_d.data();
37  auto const* zfaces_d_ptr = zfaces_d.data();
38  const auto n_xfaces = xfaces_d.size();
39  const auto n_yfaces = yfaces_d.size();
40  const auto n_zfaces = zfaces_d.size();
41 
42  for (MFIter mfi(*wdist); mfi.isValid(); ++mfi) {
43  const Box& bx = mfi.validbox();
44 
45  //const auto& z_cc = (use_terrain) ? z_phys_cc->const_array(mfi) : Array4<const Real>{};
46  auto wd_arr = wdist->array(mfi);
47 
48  if (!use_terrain) {
49  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
50  Real xr = prob_lo[0] + (i + Real(0.5)) * dx[0];
51  Real yr = prob_lo[1] + (j + Real(0.5)) * dx[1];
52  Real zr = prob_lo[2] + (k + Real(0.5)) * dx[2];
53 
54  for (std::size_t iface=0; iface < n_xfaces; ++iface) {
55  int ii = xfaces_d_ptr[iface][0];
56  int jj = xfaces_d_ptr[iface][1];
57  int kk = xfaces_d_ptr[iface][2];
58  Real xfc = prob_lo[0] + ii * dx[0];
59  Real y0 = prob_lo[1] + jj * dx[1];
60  Real y1 = prob_lo[1] + (jj+1) * dx[1];
61  Real z0 = prob_lo[2] + kk * dx[2];
62  Real z1 = prob_lo[2] + (kk+1) * dx[2];
63  // Nearest point of the face: the cell centre clamped onto the rectangle
64  Real yn = amrex::min(amrex::max(yr, y0), y1);
65  Real zn = amrex::min(amrex::max(zr, z0), z1);
66  Real wd2 = wd_arr(i, j, k) * wd_arr(i, j, k);
67  wd2 = min(wd2, (xfc-xr)*(xfc-xr) + (yn-yr)*(yn-yr) + (zn-zr)*(zn-zr));
68  wd_arr(i, j, k) = std::sqrt(wd2);
69  }
70 
71  for (std::size_t iface=0; iface < n_yfaces; ++iface) {
72  int ii = yfaces_d_ptr[iface][0];
73  int jj = yfaces_d_ptr[iface][1];
74  int kk = yfaces_d_ptr[iface][2];
75  Real yfc = prob_lo[1] + jj * dx[1];
76  Real x0 = prob_lo[0] + ii * dx[0];
77  Real x1 = prob_lo[0] + (ii+1) * dx[0];
78  Real z0 = prob_lo[2] + kk * dx[2];
79  Real z1 = prob_lo[2] + (kk+1) * dx[2];
80  // Nearest point of the face: the cell centre clamped onto the rectangle
81  Real xn = amrex::min(amrex::max(xr, x0), x1);
82  Real zn = amrex::min(amrex::max(zr, z0), z1);
83  Real wd2 = wd_arr(i, j, k) * wd_arr(i, j, k);
84  wd2 = min(wd2, (xn-xr)*(xn-xr) + (yfc-yr)*(yfc-yr) + (zn-zr)*(zn-zr));
85  wd_arr(i, j, k) = std::sqrt(wd2);
86  }
87 
88  for (std::size_t iface=0; iface < n_zfaces; ++iface) {
89  int ii = zfaces_d_ptr[iface][0];
90  int jj = zfaces_d_ptr[iface][1];
91  int kk = zfaces_d_ptr[iface][2];
92  Real zfc = prob_lo[2] + kk * dx[2];
93  Real x0 = prob_lo[0] + ii * dx[0];
94  Real x1 = prob_lo[0] + (ii+1) * dx[0];
95  Real y0 = prob_lo[1] + jj * dx[1];
96  Real y1 = prob_lo[1] + (jj+1) * dx[1];
97  // Nearest point of the face: the cell centre clamped onto the rectangle
98  Real xn = amrex::min(amrex::max(xr, x0), x1);
99  Real yn = amrex::min(amrex::max(yr, y0), y1);
100  Real wd2 = wd_arr(i, j, k) * wd_arr(i, j, k);
101  wd2 = min(wd2, (xn-xr)*(xn-xr) + (yn-yr)*(yn-yr) + (zfc-zr)*(zfc-zr));
102  wd_arr(i, j, k) = std::sqrt(wd2);
103  }
104  });
105  }
106  }
107 }
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
const Real dx
Definition: ERF_InitCustomPert_ABL.H:44
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:33
const bool use_terrain
Definition: ERF_InitCustomPert_SLM.H:19
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::Real Real
Definition: ERF_ShocInterface.H:19

Referenced by ERF::make_wall_dist().

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