8 #ifndef ERFPC_PARTICLE_TO_MESH_H_
9 #define ERFPC_PARTICLE_TO_MESH_H_
14 template<
typename ValueFunc>
15 void ERFPC::ERFPCParticleToMesh(amrex::MultiFab& a_mf,
16 const amrex::MultiFab& a_z_phys_nd,
17 int a_lev,
int a_comp,
18 ValueFunc&& value_func)
const
20 using namespace amrex;
23 AMREX_ASSERT(numParticlesOutOfRange(*
this, 0) == 0);
25 const auto& geom = Geom(a_lev);
26 const auto plo = geom.ProbLoArray();
27 const auto dxi = geom.InvCellSizeArray();
28 const Real dx = geom.CellSize(0);
29 const Real dy = geom.CellSize(1);
30 const Box domain = geom.Domain();
31 const int k_max = domain.bigEnd(AMREX_SPACEDIM-1);
36 #pragma omp parallel if (Gpu::notInLaunchRegion())
38 for (ParConstIterType pti(*
this, a_lev); pti.isValid(); ++pti)
40 const int grid = pti.index();
41 const auto& ptile = ParticlesAt(a_lev, pti);
42 const auto& aos = ptile.GetArrayOfStructs();
43 const int np = aos.numParticles();
44 if (np == 0) {
continue; }
46 auto rho = a_mf[grid].array();
47 auto zheight = a_z_phys_nd[grid].array();
49 const auto ptd = ptile.getConstParticleTileData();
53 const auto&
p = ptd.m_aos[i];
54 if (
p.id() <= 0) { return; }
56 const Real pval =
static_cast<Real>(value_func(ptd, i));
58 const Real lx =
static_cast<Real>((
p.pos(0) - plo[0]) * dxi[0]) +
Real(0.5);
59 const int ix =
static_cast<int>(Math::floor(lx)) - 1;
60 const Real wx1 = lx -
static_cast<Real>(ix + 1);
63 const Real ly =
static_cast<Real>((
p.pos(1) - plo[1]) * dxi[1]) +
Real(0.5);
64 const int iy =
static_cast<int>(Math::floor(ly)) - 1;
65 const Real wy1 = ly -
static_cast<Real>(iy + 1);
68 const int kz =
static_cast<int>(amrex::Math::floor((
p.pos(AMREX_SPACEDIM-1) - plo[AMREX_SPACEDIM-1])
69 * dxi[AMREX_SPACEDIM-1]));
70 const int ix_p =
static_cast<int>(Math::floor((
p.pos(0) - plo[0]) * dxi[0]));
71 const int iy_p =
static_cast<int>(Math::floor((
p.pos(1) - plo[1]) * dxi[1]));
72 const Real fx =
static_cast<Real>((
p.pos(0) - plo[0]) * dxi[0]) -
static_cast<Real>(ix_p);
73 const Real fy =
static_cast<Real>((
p.pos(1) - plo[1]) * dxi[1]) -
static_cast<Real>(iy_p);
75 auto zface = [=] AMREX_GPU_DEVICE (
int k_face) ->
Real {
76 return zheight(ix_p , iy_p , k_face) * (
Real(1.0)-fx) * (
Real(1.0)-fy)
77 + zheight(ix_p+1, iy_p , k_face) * fx * (
Real(1.0)-fy)
78 + zheight(ix_p , iy_p+1, k_face) * (
Real(1.0)-fx) * fy
79 + zheight(ix_p+1, iy_p+1, k_face) * fx * fy;
88 const int kz_hi_safe = amrex::min(k_max, zheight.end[2] - 2);
89 const int kz_lo_safe = amrex::max(0, zheight.begin[2] + 1);
91 const Real z_lo_k = zface(kz);
92 const Real z_hi_k = zface(kz + 1);
93 const Real z_ctr_k =
Real(0.5) * (z_lo_k + z_hi_k);
99 p.pos(0),
p.pos(1),
p.pos(AMREX_SPACEDIM-1),
104 if (p_z >= z_ctr_k) {
108 if (kz < kz_hi_safe) {
109 const Real z_hi2 = zface(kz + 2);
110 const Real z_ctr_hi =
Real(0.5) * (z_hi_k + z_hi2);
111 span = z_ctr_hi - z_ctr_k;
113 span = z_hi_k - z_lo_k;
115 wz_hi = (p_z - z_ctr_k) / span;
116 wz_lo =
Real(1.0) - wz_hi;
121 if (kz > kz_lo_safe) {
122 const Real z_lo2 = zface(kz - 1);
123 const Real z_ctr_lo =
Real(0.5) * (z_lo2 + z_lo_k);
124 span = z_ctr_k - z_ctr_lo;
126 span = z_hi_k - z_lo_k;
128 wz_lo = (z_ctr_k - p_z) / span;
129 wz_hi =
Real(1.0) - wz_lo;
133 auto dz_cell = [=] AMREX_GPU_DEVICE (
int ic,
int jc,
int kc) ->
Real {
135 zheight(ic , jc , kc+1) - zheight(ic , jc , kc)
136 + zheight(ic+1, jc , kc+1) - zheight(ic+1, jc , kc)
137 + zheight(ic , jc+1, kc+1) - zheight(ic , jc+1, kc)
138 + zheight(ic+1, jc+1, kc+1) - zheight(ic+1, jc+1, kc) );
144 auto deposit = [=] AMREX_GPU_DEVICE (
int ic,
int jc,
int kc,
Real w_horiz,
Real w_z)
147 const int kc_dz = amrex::max(0, amrex::min(k_max, kc));
148 const Real dz = dz_cell(ic, jc, kc_dz);
149 const Real contrib = pval * w_horiz * w_z * inv_dxdy /
dz;
150 Gpu::Atomic::AddNoRet(&
rho(ic, jc, kc, a_comp), contrib);
153 deposit(ix , iy , kz_lo, wx0*wy0, wz_lo);
154 deposit(ix+1, iy , kz_lo, wx1*wy0, wz_lo);
155 deposit(ix , iy+1, kz_lo, wx0*wy1, wz_lo);
156 deposit(ix+1, iy+1, kz_lo, wx1*wy1, wz_lo);
157 deposit(ix , iy , kz_hi, wx0*wy0, wz_hi);
158 deposit(ix+1, iy , kz_hi, wx1*wy0, wz_hi);
159 deposit(ix , iy+1, kz_hi, wx0*wy1, wz_hi);
160 deposit(ix+1, iy+1, kz_hi, wx1*wy1, wz_hi);
164 a_mf.SumBoundary(geom.periodicity());
const Real dy
Definition: ERF_InitCustomPert_ABL.H:24
const Real dx
Definition: ERF_InitCustomPert_ABL.H:23
rho
Definition: ERF_InitCustomPert_Bubble.H:106
const Real dz
Definition: ERF_InitCustomPert_Bubble.H:25
ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { const Real *dx=geomdata.CellSize();const Real x=(i+myhalf) *dx[0];const Real y=(j+myhalf) *dx[1];const Real Omg=erf_vortex_Gaussian(x, y, xc, yc, R, beta, sigma);const Real deltaT=-(gamma - one)/(two *sigma *sigma) *Omg *Omg;const Real rho_norm=std::pow(one+deltaT, inv_gm1);const Real T=(one+deltaT) *T_inf;const Real p=std::pow(rho_norm, Gamma)/Gamma *rho_0 *a_inf *a_inf;const Real rho_theta=rho_0 *rho_norm *(T *std::pow(p_0/p, rdOcp));state_pert(i, j, k, RhoTheta_comp)=rho_theta - getRhoThetagivenP(p_hse(i, j, k));const Real r2d_xy=std::sqrt((x-xc) *(x-xc)+(y-yc) *(y-yc));state_pert(i, j, k, RhoScalar_comp)=fourth *(one+std::cos(PI *std::min(r2d_xy, R)/R));})
Real * p
Definition: ERF_InitCustomPert_SquallLine.H:61
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real z_from_zeta(amrex::Real x, amrex::Real y, amrex::Real zeta, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &plo, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &dxi, amrex::Array4< amrex::Real const > const &height_arr) noexcept
Definition: ERF_TerrainConversion.H:51
Definition: ERF_ConsoleIO.cpp:12