WarpX
ParticleScraper.H
Go to the documentation of this file.
1 /* Copyright 2021 Andrew Myers
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef WARPX_PARTICLESCRAPER_H_
8 #define WARPX_PARTICLESCRAPER_H_
9 
12 
13 
15 
16 #include <AMReX.H>
17 #include <AMReX_MultiFab.H>
18 #include <AMReX_Particle.H>
19 #include <AMReX_RandomEngine.H>
20 #include <AMReX_REAL.H>
21 #include <AMReX_TypeTraits.H>
22 #include <AMReX_Vector.H>
23 
24 #include <type_traits>
25 #include <utility>
26 
27 
28 
67 void
68 scrapeParticlesAtEB (PC& pc, const amrex::Vector<const amrex::MultiFab*>& distance_to_eb, int lev, F&& f)
69 {
70  scrapeParticlesAtEB(pc, distance_to_eb, lev, lev, std::forward<F>(f));
71 }
72 
110 void
111 scrapeParticlesAtEB (PC& pc, const amrex::Vector<const amrex::MultiFab*>& distance_to_eb, F&& f)
112 {
113  scrapeParticlesAtEB(pc, distance_to_eb, 0, pc.finestLevel(), std::forward<F>(f));
114 }
115 
155 void
157  int lev_min, int lev_max, F&& f)
158 {
159  BL_PROFILE("scrapeParticlesAtEB");
160 
161  for (int lev = lev_min; lev <= lev_max; ++lev)
162  {
163  const auto plo = pc.Geom(lev).ProbLoArray();
164  const auto dxi = pc.Geom(lev).InvCellSizeArray();
165 #ifdef AMREX_USE_OMP
166 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
167 #endif
168  for(WarpXParIter pti(pc, lev); pti.isValid(); ++pti)
169  {
170  const auto getPosition = GetParticlePosition<PIdx>(pti);
171  auto& tile = pti.GetParticleTile();
172  auto ptd = tile.getParticleTileData();
173  const auto np = tile.numParticles();
174  auto phi = (*distance_to_eb[lev])[pti].array(); // signed distance function
176  [=] AMREX_GPU_DEVICE (const int ip, amrex::RandomEngine const& engine) noexcept
177  {
178  // skip particles that are already flagged for removal
179  if (!amrex::ParticleIDWrapper{ptd.m_idcpu[ip]}.is_valid()) return;
180 
181  amrex::ParticleReal xp, yp, zp;
182  getPosition(ip, xp, yp, zp);
183 
184  int i, j, k;
185  amrex::Real W[AMREX_SPACEDIM][2];
186  ablastr::particles::compute_weights(xp, yp, zp, plo, dxi, i, j, k, W);
187  amrex::Real phi_value = ablastr::particles::interp_field_nodal(i, j, k, W, phi);
188 
189  if (phi_value < 0.0)
190  {
191  int ic, jc, kc; // Cell-centered indices
192  [[maybe_unused]] int nodal;
193  amrex::Real Wc[AMREX_SPACEDIM][2]; // Cell-centered weights
194  ablastr::particles::compute_weights(xp, yp, zp, plo, dxi, ic, jc, kc, Wc, nodal=0);
195  amrex::RealVect normal = DistanceToEB::interp_normal(i, j, k, W, ic, jc, kc, Wc, phi, dxi);
196  DistanceToEB::normalize(normal);
197  amrex::RealVect pos;
198 #if (defined WARPX_DIM_3D)
199  pos[0] = xp;
200  pos[1] = yp;
201  pos[2] = zp;
202 #elif (defined WARPX_DIM_XZ)
203  pos[0] = xp;
204  pos[1] = zp;
205 #elif (defined WARPX_DIM_RZ)
206  pos[0] = std::sqrt(xp*xp + yp*yp);
207  pos[1] = zp;
208 #elif (defined WARPX_DIM_1D_Z)
209  pos[0] = zp;
210 #endif
211  f(ptd, ip, pos, normal, engine);
212 
213  }
214  });
215  }
216  }
217 }
218 
219 #endif //WARPX_PARTICLESCRAPER_H_
#define BL_PROFILE(a)
#define AMREX_GPU_DEVICE
void scrapeParticlesAtEB(PC &pc, const amrex::Vector< const amrex::MultiFab * > &distance_to_eb, int lev, F &&f)
Interact particles with the embedded boundary walls.
Definition: ParticleScraper.H:68
Definition: WarpXParticleContainer.H:53
bool isValid() const noexcept
AMREX_GPU_HOST_DEVICE AMREX_INLINE amrex::Real interp_field_nodal(int i, int j, int k, const amrex::Real W[AMREX_SPACEDIM][2], amrex::Array4< const amrex::Real > const &scalar_field) noexcept
Interpolate nodal field value based on surrounding indices and weights.
Definition: NodalFieldGather.H:99
AMREX_GPU_HOST_DEVICE AMREX_INLINE void compute_weights(const amrex::ParticleReal xp, const amrex::ParticleReal yp, const amrex::ParticleReal zp, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &plo, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &dxi, int &i, int &j, int &k, amrex::Real W[AMREX_SPACEDIM][2], int nodal=1) noexcept
Compute weight of each surrounding node (or cell-centered nodes) in interpolating a nodal ((or a cell...
Definition: NodalFieldGather.H:34
AMREX_ATTRIBUTE_FLATTEN_FOR void ParallelForRNG(T n, L const &f) noexcept
i
Definition: check_interp_points_and_weights.py:174
value
Definition: updateAMReX.py:141
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool is_valid() const noexcept