From 2b0631dacce521722093df211011b2e8be29d1c9 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Fri, 15 Sep 2023 17:06:52 -0700 Subject: [PATCH] do not deposit / gather within +/- deposit and gather box --- .../Particles/Deposition/CurrentDeposition.H | 53 +++++++++++++++++++ .../Particles/PhysicalParticleContainer.cpp | 36 +++++++++++-- Source/Particles/PulsarParameters.H | 4 ++ Source/Particles/PulsarParameters.cpp | 8 +++ 4 files changed, 97 insertions(+), 4 deletions(-) diff --git a/Source/Particles/Deposition/CurrentDeposition.H b/Source/Particles/Deposition/CurrentDeposition.H index 84d696ce4ec..00db08c5cee 100644 --- a/Source/Particles/Deposition/CurrentDeposition.H +++ b/Source/Particles/Deposition/CurrentDeposition.H @@ -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 @@ -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; @@ -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; @@ -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; @@ -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 @@ -825,6 +861,11 @@ void doVayDepositionShapeN (const GetParticlePosition& GetPosition, amrex::Array4 const& Dy_arr = Dy_fab.array(); amrex::Array4 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; @@ -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; diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 780ac82fa53..10aac8c449a 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -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 @@ -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) { @@ -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, @@ -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 @@ -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 }; @@ -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, diff --git a/Source/Particles/PulsarParameters.H b/Source/Particles/PulsarParameters.H index c82d1e4373d..c4fc6d1d839 100644 --- a/Source/Particles/PulsarParameters.H +++ b/Source/Particles/PulsarParameters.H @@ -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: }; diff --git a/Source/Particles/PulsarParameters.cpp b/Source/Particles/PulsarParameters.cpp index b9d236106d3..f37e394a0c9 100644 --- a/Source/Particles/PulsarParameters.cpp +++ b/Source/Particles/PulsarParameters.cpp @@ -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 () { @@ -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); }