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<amrex::IndexType::NODE>(
187  xp, yp, zp, plo, dxi, i, j, k, W);
188  amrex::Real phi_value = ablastr::particles::interp_field_nodal(i, j, k, W, phi);
189 
190  if (phi_value < 0.0)
191  {
192  int ic, jc, kc; // Cell-centered indices
193  amrex::Real Wc[AMREX_SPACEDIM][2]; // Cell-centered weights
194  ablastr::particles::compute_weights<amrex::IndexType::CELL>(
195  xp, yp, zp, plo, dxi, ic, jc, kc, Wc);
196  amrex::RealVect normal = DistanceToEB::interp_normal(i, j, k, W, ic, jc, kc, Wc, phi, dxi);
197  DistanceToEB::normalize(normal);
198  amrex::RealVect pos;
199 #if (defined WARPX_DIM_3D)
200  pos[0] = xp;
201  pos[1] = yp;
202  pos[2] = zp;
203 #elif (defined WARPX_DIM_XZ)
204  pos[0] = xp;
205  pos[1] = zp;
206 #elif (defined WARPX_DIM_RZ)
207  pos[0] = std::sqrt(xp*xp + yp*yp);
208  pos[1] = zp;
209 #elif (defined WARPX_DIM_1D_Z)
210  pos[0] = zp;
211 #endif
212  f(ptd, ip, pos, normal, engine);
213 
214  }
215  });
216  }
217  }
218 }
219 
220 #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:115
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