diff options
Diffstat (limited to 'Source/Particles/WarpXParticleContainer.cpp')
-rw-r--r-- | Source/Particles/WarpXParticleContainer.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 10ff7f19c..a50345f4b 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -889,3 +889,45 @@ WarpXParticleContainer::particlePostLocate(ParticleType& p, // to lower level. } } + +void +WarpXParticleContainer::ApplyBoundaryConditions (ParticleBC boundary_conditions){ + WARPX_PROFILE("WarpXParticleContainer::ApplyBoundaryConditions()"); + for (int lev = 0; lev <= finestLevel(); ++lev) + { + for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) + { + auto GetPosition = GetParticlePosition(pti); + const Real xmin = Geom(lev).ProbLo(0); + const Real xmax = Geom(lev).ProbHi(0); +#ifdef WARPX_DIM_3D + const Real ymin = Geom(lev).ProbLo(1); + const Real ymax = Geom(lev).ProbHi(1); +#endif + const Real zmin = Geom(lev).ProbLo(AMREX_SPACEDIM-1); + const Real zmax = Geom(lev).ProbHi(AMREX_SPACEDIM-1); + + ParticleTileType& ptile = ParticlesAt(lev, pti); + ParticleType * const pp = ptile.GetArrayOfStructs()().data(); + + // Loop over particles and apply BC to each particle + amrex::ParallelFor( + pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + ParticleType& p = pp[i]; + ParticleReal x, y, z; + GetPosition(i, x, y, z); +#ifdef WARPX_DIM_3D + if (x < xmin || x > xmax || y < ymin || y > ymax || z < zmin || z > zmax){ + if (boundary_conditions == ParticleBC::absorbing) p.id() = -1; + } +#else + if (x < xmin || x > xmax || z < zmin || z > zmax){ + if (boundary_conditions == ParticleBC::absorbing) p.id() = -1; + } +#endif + } + ); + } + } +} |