aboutsummaryrefslogtreecommitdiff
path: root/Source/Particles/WarpXParticleContainer.cpp
diff options
context:
space:
mode:
authorGravatar MaxThevenet <maxence.thevenet@desy.de> 2020-09-24 07:43:03 +0200
committerGravatar GitHub <noreply@github.com> 2020-09-23 22:43:03 -0700
commit8797c599f2c16e33a790300ebb275b7b696df91b (patch)
treec882767138dc023aab07d6e5414f00b2c321c685 /Source/Particles/WarpXParticleContainer.cpp
parent20649677733e0b457def83ff48147facf8268b5c (diff)
downloadWarpX-8797c599f2c16e33a790300ebb275b7b696df91b.tar.gz
WarpX-8797c599f2c16e33a790300ebb275b7b696df91b.tar.zst
WarpX-8797c599f2c16e33a790300ebb275b7b696df91b.zip
Option to have absorbing BC for particles, regardless of field BC (#1334)
* option to have absorbing BC for particles, regarless of field BC * document input parameter particles.absorbing_bc * minor, just add a small comment * clarify doc and use better input parameter * clarify documentation
Diffstat (limited to 'Source/Particles/WarpXParticleContainer.cpp')
-rw-r--r--Source/Particles/WarpXParticleContainer.cpp42
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
+ }
+ );
+ }
+ }
+}