diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/Initialization/InjectorPosition.H | 20 | ||||
-rw-r--r-- | Source/Particles/PhysicalParticleContainer.cpp | 17 | ||||
-rw-r--r-- | Source/Utils/ParticleUtils.H | 16 |
3 files changed, 45 insertions, 8 deletions
diff --git a/Source/Initialization/InjectorPosition.H b/Source/Initialization/InjectorPosition.H index 059590979..012ea0ffc 100644 --- a/Source/Initialization/InjectorPosition.H +++ b/Source/Initialization/InjectorPosition.H @@ -175,7 +175,11 @@ struct InjectorPosition }; } - // bool: whether position specified is within bounds. + /* \brief Flags whether the point (x, y, z) is inside the plasma region + * or on the lower boundary + * \param x, y, z the point to check + * \returns bool flag + */ AMREX_GPU_HOST_DEVICE bool insideBounds (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept @@ -185,6 +189,20 @@ struct InjectorPosition z < zmax and z >= zmin); } + /* \brief Flags whether the point (x, y, z) is inside the plasma region + * or on the lower or upper boundary + * \param x, y, z the point to check + * \returns bool flag + */ + AMREX_GPU_HOST_DEVICE + bool + insideBoundsInclusive (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept + { + return (x <= xmax and x >= xmin and + y <= ymax and y >= ymin and + z <= zmax and z >= zmin); + } + // bool: whether the region defined by lo and hi overaps with the plasma region AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index cbb0a6932..18cf17162 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -32,6 +32,7 @@ #include "Particles/SpeciesPhysicalProperties.H" #include "Particles/WarpXParticleContainer.H" #include "Utils/Parser/ParserUtils.H" +#include "Utils/ParticleUtils.H" #include "Utils/Physics/IonizationEnergiesTable.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" @@ -1682,29 +1683,31 @@ PhysicalParticleContainer::AddPlasmaFlux (amrex::Real dt) pu.y *= PhysConst::c; pu.z *= PhysConst::c; + // The containsInclusive is used to allow the case of the flux surface + // being on the boundary of the domain. After the UpdatePosition below, + // the particles will be within the domain. #if defined(WARPX_DIM_3D) - if (!tile_realbox.contains(XDim3{ppos.x,ppos.y,ppos.z})) { + if (!ParticleUtils::containsInclusive(tile_realbox, XDim3{ppos.x,ppos.y,ppos.z})) { p.id() = -1; continue; } #elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) amrex::ignore_unused(k); - if (!tile_realbox.contains(XDim3{ppos.x,ppos.z,0.0_prt})) { + if (!ParticleUtils::containsInclusive(tile_realbox, XDim3{ppos.x,ppos.z,0.0_prt})) { p.id() = -1; continue; } #else amrex::ignore_unused(j,k); - if (!tile_realbox.contains(XDim3{ppos.z,0.0_prt,0.0_prt})) { + if (!ParticleUtils::containsInclusive(tile_realbox, XDim3{ppos.z,0.0_prt,0.0_prt})) { p.id() = -1; continue; } #endif // Lab-frame simulation - // If the particle is not within the species's - // xmin, xmax, ymin, ymax, zmin, zmax, go to - // the next generated particle. - if (!inj_pos->insideBounds(ppos.x, ppos.y, ppos.z)) { + // If the particle's initial position is not within or on the species's + // xmin, xmax, ymin, ymax, zmin, zmax, go to the next generated particle. + if (!inj_pos->insideBoundsInclusive(ppos.x, ppos.y, ppos.z)) { p.id() = -1; continue; } diff --git a/Source/Utils/ParticleUtils.H b/Source/Utils/ParticleUtils.H index b9d8aa0ec..a997412f6 100644 --- a/Source/Utils/ParticleUtils.H +++ b/Source/Utils/ParticleUtils.H @@ -169,6 +169,22 @@ namespace ParticleUtils { uy = y * vp; uz = z * vp; } + + /* \brief Determines whether the point is within the tilebox, inclusive of the boundaries. + * Note that this routine is needed since tilebox.contains excludes the boundaries. + * \param[in] tilebox The tilebox being checked + * \param[in] point The point being checked + * \result true if the point with within the boundary, otherwise false + */ + AMREX_GPU_HOST_DEVICE AMREX_INLINE + bool containsInclusive (amrex::RealBox const& tilebox, amrex::XDim3 const point) { + const auto xlo = tilebox.lo(); + const auto xhi = tilebox.hi(); + return AMREX_D_TERM((xlo[0] <= point.x) && (point.x <= xhi[0]), + && (xlo[1] <= point.y) && (point.y <= xhi[1]), + && (xlo[2] <= point.z) && (point.z <= xhi[2])); + } + } #endif // WARPX_PARTICLE_UTILS_H_ |