Skip to content

Commit

Permalink
do not deposit / gather within +/- deposit and gather box
Browse files Browse the repository at this point in the history
  • Loading branch information
RevathiJambunathan committed Sep 16, 2023
1 parent 9ef441c commit 2b0631d
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
53 changes: 53 additions & 0 deletions Source/Particles/Deposition/CurrentDeposition.H
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Parallelization/KernelTimer.H"
#include "Particles/Pusher/GetAndSetPosition.H"
#include "Particles/ShapeFactors.H"
#include "Particles/PulsarParameters.H"
#include "Utils/WarpXAlgorithmSelection.H"
#include "Utils/WarpXConst.H"
#ifdef WARPX_DIM_RZ
Expand Down Expand Up @@ -113,6 +114,11 @@ void doDepositionShapeN(const GetParticlePosition& GetPosition,
constexpr int NODE = amrex::IndexType::NODE;
constexpr int CELL = amrex::IndexType::CELL;

#ifdef PULSAR
amrex::Real deposit_buffer_boxmin = Pulsar::m_depositbuffer_min;
amrex::Real deposit_buffer_boxmax = Pulsar::m_depositbuffer_max;
#endif

// Loop over particles and deposit into jx_fab, jy_fab and jz_fab
#if defined(WARPX_USE_GPUCLOCK)
amrex::Real* cost_real = nullptr;
Expand Down Expand Up @@ -141,6 +147,18 @@ void doDepositionShapeN(const GetParticlePosition& GetPosition,
amrex::ParticleReal xp, yp, zp;
GetPosition(ip, xp, yp, zp);

#ifdef PULSAR
if ( ((xp > deposit_buffer_boxmin) && (xp < deposit_buffer_boxmax))
|| ((yp > deposit_buffer_boxmin) && (yp < deposit_buffer_boxmax))
|| ((zp > deposit_buffer_boxmin) && (zp < deposit_buffer_boxmax))
|| ((xp < -deposit_buffer_boxmin) && (xp > -deposit_buffer_boxmax))
|| ((yp < -deposit_buffer_boxmin) && (yp > -deposit_buffer_boxmax))
|| ((zp < -deposit_buffer_boxmin) && (zp > -deposit_buffer_boxmax)))
{
wq = 0.;
}
#endif

const amrex::Real vx = uxp[ip]*gaminv;
const amrex::Real vy = uyp[ip]*gaminv;
const amrex::Real vz = uzp[ip]*gaminv;
Expand Down Expand Up @@ -429,6 +447,12 @@ void doEsirkepovDepositionShapeN (const GetParticlePosition& GetPosition,
Real constexpr one_sixth = 1.0_rt / 6.0_rt;
#endif


#ifdef PULSAR
amrex::Real deposit_buffer_boxmin = Pulsar::m_depositbuffer_min;
amrex::Real deposit_buffer_boxmax = Pulsar::m_depositbuffer_max;
#endif

// Loop over particles and deposit into Jx_arr, Jy_arr and Jz_arr
#if defined(WARPX_USE_GPUCLOCK)
amrex::Real* cost_real = nullptr;
Expand Down Expand Up @@ -459,6 +483,18 @@ void doEsirkepovDepositionShapeN (const GetParticlePosition& GetPosition,
ParticleReal xp, yp, zp;
GetPosition(ip, xp, yp, zp);

#ifdef PULSAR
if ( ((xp > deposit_buffer_boxmin) && (xp < deposit_buffer_boxmax))
|| ((yp > deposit_buffer_boxmin) && (yp < deposit_buffer_boxmax))
|| ((zp > deposit_buffer_boxmin) && (zp < deposit_buffer_boxmax))
|| ((xp < -deposit_buffer_boxmin) && (xp > -deposit_buffer_boxmax))
|| ((yp < -deposit_buffer_boxmin) && (yp > -deposit_buffer_boxmax))
|| ((zp < -deposit_buffer_boxmin) && (zp > -deposit_buffer_boxmax)))
{
wq = 0.;
}
#endif

#if !defined(WARPX_DIM_1D_Z)
Real const wqx = wq*invdtdx;
#endif
Expand Down Expand Up @@ -825,6 +861,11 @@ void doVayDepositionShapeN (const GetParticlePosition& GetPosition,
amrex::Array4<amrex::Real> const& Dy_arr = Dy_fab.array();
amrex::Array4<amrex::Real> const& Dz_arr = Dz_fab.array();

#ifdef PULSAR
amrex::Real deposit_buffer_boxmin = Pulsar::m_depositbuffer_min;
amrex::Real deposit_buffer_boxmax = Pulsar::m_depositbuffer_max;
#endif

// Loop over particles and deposit (Dx,Dy,Dz) into Dx_fab, Dy_fab and Dz_fab
#if defined(WARPX_USE_GPUCLOCK)
amrex::Real* cost_real = nullptr;
Expand Down Expand Up @@ -852,6 +893,18 @@ void doVayDepositionShapeN (const GetParticlePosition& GetPosition,
amrex::ParticleReal xp, yp, zp;
GetPosition(ip, xp, yp, zp);

#ifdef PULSAR
if ( ((xp > deposit_buffer_boxmin) && (xp < deposit_buffer_boxmax))
|| ((yp > deposit_buffer_boxmin) && (yp < deposit_buffer_boxmax))
|| ((zp > deposit_buffer_boxmin) && (zp < deposit_buffer_boxmax))
|| ((xp < -deposit_buffer_boxmin) && (xp > -deposit_buffer_boxmax))
|| ((yp < -deposit_buffer_boxmin) && (yp > -deposit_buffer_boxmax))
|| ((zp < -deposit_buffer_boxmin) && (zp > -deposit_buffer_boxmax)))
{
wq = 0.;
}
#endif

// Particle velocities
const amrex::Real vx = uxp[ip] * invgam;
const amrex::Real vy = uyp[ip] * invgam;
Expand Down
36 changes: 32 additions & 4 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2852,6 +2852,8 @@ PhysicalParticleContainer::PushP (int lev, Real dt,
int use_BC_smoothening = Pulsar::m_use_BC_smoothening;
amrex::Real min_BC_radius = Pulsar::m_min_BC_radius;
amrex::Real BC_width = Pulsar::m_BC_width;
amrex::Real gather_buffer_boxmin = Pulsar::m_gatherbuffer_min;
amrex::Real gather_buffer_boxmax = Pulsar::m_gatherbuffer_max;
#endif

#ifdef AMREX_USE_OMP
Expand Down Expand Up @@ -2919,7 +2921,7 @@ PhysicalParticleContainer::PushP (int lev, Real dt,
const auto pusher_algo = WarpX::particle_pusher_algo;
const auto do_crr = do_classical_radiation_reaction;

const auto t_do_not_gather = do_not_gather;
auto t_do_not_gather = do_not_gather;

amrex::ParallelFor( np, [=] AMREX_GPU_DEVICE (long ip)
{
Expand All @@ -2928,8 +2930,20 @@ PhysicalParticleContainer::PushP (int lev, Real dt,

amrex::ParticleReal Exp = 0._rt, Eyp = 0._rt, Ezp = 0._rt;
amrex::ParticleReal Bxp = 0._rt, Byp = 0._rt, Bzp = 0._rt;
#ifdef PULSAR
bool in_gather_buffer_box = false;
if ( ((xp > gather_buffer_boxmin) && (xp < gather_buffer_boxmax))
|| ((yp > gather_buffer_boxmin) && (yp < gather_buffer_boxmax))
|| ((zp > gather_buffer_boxmin) && (zp < gather_buffer_boxmax))
|| ((xp < -gather_buffer_boxmin) && (xp > -gather_buffer_boxmax))
|| ((yp < -gather_buffer_boxmin) && (yp > -gather_buffer_boxmax))
|| ((zp < -gather_buffer_boxmin) && (zp > -gather_buffer_boxmax)))
{
in_gather_buffer_box = true;
}
#endif

if (!t_do_not_gather){
if (!t_do_not_gather || !in_gather_buffer_box){
// first gather E and B to the particle positions
doGatherShapeN(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
Expand Down Expand Up @@ -3142,6 +3156,8 @@ PhysicalParticleContainer::PushPX (WarpXParIter& pti,
int use_BC_smoothening = Pulsar::m_use_BC_smoothening;
amrex::Real min_BC_radius = Pulsar::m_min_BC_radius;
amrex::Real BC_width = Pulsar::m_BC_width;
amrex::Real gather_buffer_boxmin = Pulsar::m_gatherbuffer_min;
amrex::Real gather_buffer_boxmax = Pulsar::m_gatherbuffer_max;
#endif


Expand Down Expand Up @@ -3220,7 +3236,7 @@ PhysicalParticleContainer::PushPX (WarpXParIter& pti,
}
#endif

const auto t_do_not_gather = do_not_gather;
auto t_do_not_gather = do_not_gather;

enum exteb_flags : int { no_exteb, has_exteb };
enum qed_flags : int { no_qed, has_qed };
Expand Down Expand Up @@ -3256,8 +3272,20 @@ PhysicalParticleContainer::PushPX (WarpXParIter& pti,

amrex::ParticleReal Exp = 0._rt, Eyp = 0._rt, Ezp = 0._rt;
amrex::ParticleReal Bxp = 0._rt, Byp = 0._rt, Bzp = 0._rt;
#ifdef PULSAR
bool in_gather_buffer_box = false;
if ( ((xp > gather_buffer_boxmin) && (xp < gather_buffer_boxmax))
|| ((yp > gather_buffer_boxmin) && (yp < gather_buffer_boxmax))
|| ((zp > gather_buffer_boxmin) && (zp < gather_buffer_boxmax))
|| ((xp < -gather_buffer_boxmin) && (xp > -gather_buffer_boxmax))
|| ((yp < -gather_buffer_boxmin) && (yp > -gather_buffer_boxmax))
|| ((zp < -gather_buffer_boxmin) && (zp > -gather_buffer_boxmax)))
{
in_gather_buffer_box = true;
}
#endif

if(!t_do_not_gather){
if(!t_do_not_gather || !in_gather_buffer_box){
// first gather E and B to the particle positions
doGatherShapeN(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp,
ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr,
Expand Down
4 changes: 4 additions & 0 deletions Source/Particles/PulsarParameters.H
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,10 @@ public:
static int m_use_BC_smoothening;
static amrex::Real m_min_BC_radius;
static amrex::Real m_BC_width;
static amrex::Real m_gatherbuffer_min;
static amrex::Real m_gatherbuffer_max;
static amrex::Real m_depositbuffer_min;
static amrex::Real m_depositbuffer_max;
private:
};

Expand Down
8 changes: 8 additions & 0 deletions Source/Particles/PulsarParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ amrex::Real Pulsar::m_limit_GJfactor = 1.;
int Pulsar::m_use_BC_smoothening;
amrex::Real Pulsar::m_min_BC_radius;
amrex::Real Pulsar::m_BC_width;
amrex::Real Pulsar::m_gatherbuffer_min;
amrex::Real Pulsar::m_gatherbuffer_max;
amrex::Real Pulsar::m_depositbuffer_min;
amrex::Real Pulsar::m_depositbuffer_max;

Pulsar::Pulsar ()
{
Expand Down Expand Up @@ -364,6 +368,10 @@ Pulsar::ReadParameters () {
pp.get("use_BC_smoothening",m_use_BC_smoothening);
pp.get("min_BC_radius", m_min_BC_radius);
pp.get("BC_width", m_BC_width);
pp.query("gatherbuffer_min",m_gatherbuffer_min);
pp.query("gatherbuffer_max",m_gatherbuffer_max);
pp.query("depositbuffer_min",m_depositbuffer_min);
pp.query("depositbuffer_max",m_depositbuffer_max);
}


Expand Down

0 comments on commit 2b0631d

Please sign in to comment.