WarpX
Loading...
Searching...
No Matches
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
66template <class PC, class F, std::enable_if_t<amrex::IsParticleContainer<PC>::value, int> foo = 0>
67void
68scrapeParticlesAtEB (PC& pc, ablastr::fields::MultiLevelScalarField const& distance_to_eb, int lev, F&& f)
69{
70 scrapeParticlesAtEB(pc, distance_to_eb, lev, lev, std::forward<F>(f));
71}
72
109template <class PC, class F, std::enable_if_t<amrex::IsParticleContainer<PC>::value, int> foo = 0>
110void
112{
113 scrapeParticlesAtEB(pc, distance_to_eb, 0, pc.finestLevel(), std::forward<F>(f));
114}
115
154template <class PC, class F, std::enable_if_t<amrex::IsParticleContainer<PC>::value, int> foo = 0>
155void
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];
187 xp, yp, zp, plo, dxi, i, j, k, W);
188 amrex::Real const 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
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);
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, ablastr::fields::MultiLevelScalarField const &distance_to_eb, int lev, F &&f)
Interact particles with the embedded boundary walls.
Definition ParticleScraper.H:68
Definition WarpXParticleContainer.H:117
bool isValid() const noexcept
AMREX_GPU_HOST_DEVICE AMREX_INLINE void normalize(amrex::RealVect &a) noexcept
Definition DistanceToEB.H:27
AMREX_GPU_HOST_DEVICE AMREX_INLINE amrex::RealVect interp_normal(int i, int j, int k, const amrex::Real W[3][2], int ic, int jc, int kc, const amrex::Real Wc[3][2], amrex::Array4< const amrex::Real > const &phi, amrex::GpuArray< amrex::Real, 3 > const &dxi) noexcept
Definition DistanceToEB.H:43
amrex::Vector< ScalarField > MultiLevelScalarField
Definition MultiFabRegister.H:200
AMREX_GPU_HOST_DEVICE AMREX_INLINE amrex::Real interp_field_nodal(int i, int j, int k, const amrex::Real W[3][2], amrex::Array4< const amrex::Real > const &scalar_field) noexcept
Interpolate nodal field value based on surrounding indices and weights.
Definition NodalFieldGather.H:139
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, 3 > const &plo, amrex::GpuArray< amrex::Real, 3 > const &dxi, int &i, int &j, int &k, amrex::Real W[3][2]) noexcept
Compute weight of each surrounding node (or cell-centered nodes) in interpolating a nodal ((or a cell...
Definition NodalFieldGather.H:37
RealVectND< 3 > RealVect
AMREX_ATTRIBUTE_FLATTEN_FOR void ParallelForRNG(T n, L const &f) noexcept
Functor that can be used to extract the positions of the macroparticles inside a ParallelFor kernel.
Definition GetAndSetPosition.H:75
__host__ __device__ bool is_valid() const noexcept