From ae12df60f57f92259854db9326dab3e5aff17d8e Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Tue, 24 Sep 2019 11:21:55 -0700 Subject: Implement new gather option --- Source/Utils/WarpXAlgorithmSelection.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Source/Utils/WarpXAlgorithmSelection.cpp') diff --git a/Source/Utils/WarpXAlgorithmSelection.cpp b/Source/Utils/WarpXAlgorithmSelection.cpp index 8a6ff6dbf..f04cdd449 100644 --- a/Source/Utils/WarpXAlgorithmSelection.cpp +++ b/Source/Utils/WarpXAlgorithmSelection.cpp @@ -33,8 +33,9 @@ const std::map charge_deposition_algo_to_int = { }; const std::map gathering_algo_to_int = { - {"standard", GatheringAlgo::Standard }, - {"default", GatheringAlgo::Standard } + {"energy-conserving", GatheringAlgo::EnergyConserving }, + {"momentum-conserving", GatheringAlgo::MomentumConserving }, + {"default", GatheringAlgo::EnergyConserving } }; -- cgit v1.2.3 From 8e2ecfe27b9d464dcd40031ae5ebc4e3781963e2 Mon Sep 17 00:00:00 2001 From: Yin-YinjianZhao Date: Mon, 14 Oct 2019 10:28:20 -0700 Subject: Add Higuera-Cary pusher --- Source/Particles/PhysicalParticleContainer.cpp | 21 ++++++++ Source/Particles/Pusher/Make.package | 1 + .../Particles/Pusher/UpdateMomentumHigueraCary.H | 56 ++++++++++++++++++++++ .../Particles/RigidInjectedParticleContainer.cpp | 8 ++++ Source/Utils/WarpXAlgorithmSelection.H | 3 +- Source/Utils/WarpXAlgorithmSelection.cpp | 1 + 6 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 Source/Particles/Pusher/UpdateMomentumHigueraCary.H (limited to 'Source/Utils/WarpXAlgorithmSelection.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index d10803320..82aacbda8 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -17,6 +17,7 @@ #include #include #include +#include using namespace amrex; @@ -1604,6 +1605,19 @@ PhysicalParticleContainer::PushPX(WarpXParIter& pti, ux[i], uy[i], uz[i], dt ); } ); + } else if (WarpX::particle_pusher_algo == ParticlePusherAlgo::HigueraCary) { + amrex::ParallelFor( + pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + Real qp = q; + if (ion_lev){ qp *= ion_lev[i]; } + UpdateMomentumHigueraCary( ux[i], uy[i], uz[i], + Ex[i], Ey[i], Ez[i], Bx[i], + By[i], Bz[i], qp, m, dt); + UpdatePosition( x[i], y[i], z[i], + ux[i], uy[i], uz[i], dt ); + } + ); } else { amrex::Abort("Unknown particle pusher"); }; @@ -1699,6 +1713,13 @@ PhysicalParticleContainer::PushP (int lev, Real dt, Expp[i], Eypp[i], Ezpp[i], Bxpp[i], Bypp[i], Bzpp[i], q, m, dt); } ); + } else if (WarpX::particle_pusher_algo == ParticlePusherAlgo::HigueraCary) { + amrex::ParallelFor( pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + UpdateMomentumHigueraCary( ux[i], uy[i], uz[i], + Expp[i], Eypp[i], Ezpp[i], Bxpp[i], Bypp[i], Bzpp[i], q, m, dt); + } + ); } else { amrex::Abort("Unknown particle pusher"); }; diff --git a/Source/Particles/Pusher/Make.package b/Source/Particles/Pusher/Make.package index 45886702e..b033bfb57 100644 --- a/Source/Particles/Pusher/Make.package +++ b/Source/Particles/Pusher/Make.package @@ -2,6 +2,7 @@ CEXE_headers += GetAndSetPosition.H CEXE_headers += UpdatePosition.H CEXE_headers += UpdateMomentumBoris.H CEXE_headers += UpdateMomentumVay.H +CEXE_headers += UpdateMomentumHigueraCary.H CEXE_headers += UpdatePositionPhoton.H INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Particles/Pusher VPATH_LOCATIONS += $(WARPX_HOME)/Source/Particles/Pusher diff --git a/Source/Particles/Pusher/UpdateMomentumHigueraCary.H b/Source/Particles/Pusher/UpdateMomentumHigueraCary.H new file mode 100644 index 000000000..11bd1d233 --- /dev/null +++ b/Source/Particles/Pusher/UpdateMomentumHigueraCary.H @@ -0,0 +1,56 @@ +#ifndef WARPX_PARTICLES_PUSHER_UPDATEMOMENTUM_HIGUERACARY_H_ +#define WARPX_PARTICLES_PUSHER_UPDATEMOMENTUM_HIGUERACARY_H_ + +#include +#include +#include + +/* \brief Push the particle's positions over one timestep, + * given the value of its momenta `ux`, `uy`, `uz` */ +AMREX_GPU_HOST_DEVICE AMREX_INLINE +void UpdateMomentumHigueraCary( + amrex::ParticleReal& ux, amrex::ParticleReal& uy, amrex::ParticleReal& uz, + const amrex::ParticleReal Ex, const amrex::ParticleReal Ey, const amrex::ParticleReal Ez, + const amrex::ParticleReal Bx, const amrex::ParticleReal By, const amrex::ParticleReal Bz, + const amrex::Real q, const amrex::Real m, const amrex::Real dt ) +{ + // Constants + const amrex::Real qmt = 0.5*q*dt/m; + constexpr amrex::Real invclight = 1./PhysConst::c; + constexpr amrex::Real invclightsq = 1./(PhysConst::c*PhysConst::c); + // Compute u_minus + const amrex::Real umx = ux + qmt*Ex; + const amrex::Real umy = uy + qmt*Ey; + const amrex::Real umz = uz + qmt*Ez; + // Compute gamma squared of u_minus + const amrex::Real gamma = 1. + (umx*umx + umy*umy + umz*umz)*invclightsq; + // Compute beta and betam squared + const amrex::Real betax = qmt*Bx; + const amrex::Real betay = qmt*By; + const amrex::Real betaz = qmt*Bz; + const amrex::Real betam = betax*betax + betay*betay + betaz*betaz; + // Compute sigma + const amrex::Real sigma = gamma - betam; + // Get u* + const amrex::Real ust = (umx*betax + umy*betay + umz*betaz)*invclight; + // Get new gamma inversed + gamma = 1./std::sqrt(0.5*(sigma + std::sqrt(sigma*sigma + 4.*(betam + ust*ust)) )); + // Compute t + const amrex::Real tx = gamma*betax; + const amrex::Real ty = gamma*betay; + const amrex::Real tz = gamma*betaz; + // Compute s + const amrex::Real s = 1./(1.+(tx*tx + ty*ty + tz*tz)); + // Compute um dot t + const amrex::Real umt = umx*tx + umy*ty + umz*tz; + // Compute u_plus + const amrex::Real upx = s*( umx + umt*tx + umy*tz - umz*ty ); + const amrex::Real upy = s*( umy + umt*ty + umz*tx - umx*tz ); + const amrex::Real upz = s*( umz + umt*tz + umx*ty - umy*tx ); + // Get new u + ux = upx + qmt*Ex + upy*tz - upz*ty; + uy = upy + qmt*Ey + upz*tx - upx*tz; + uz = upz + qmt*Ez + upx*ty - upy*tx; +} + +#endif // WARPX_PARTICLES_PUSHER_UPDATEMOMENTUM_HIGUERACARY_H_ diff --git a/Source/Particles/RigidInjectedParticleContainer.cpp b/Source/Particles/RigidInjectedParticleContainer.cpp index 891ade76d..aeaac7194 100644 --- a/Source/Particles/RigidInjectedParticleContainer.cpp +++ b/Source/Particles/RigidInjectedParticleContainer.cpp @@ -13,6 +13,7 @@ #include #include #include +#include using namespace amrex; @@ -443,6 +444,13 @@ RigidInjectedParticleContainer::PushP (int lev, Real dt, Expp[i], Eypp[i], Ezpp[i], Bxpp[i], Bypp[i], Bzpp[i], q, m, dt); } ); + } else if (WarpX::particle_pusher_algo == ParticlePusherAlgo::HigueraCary) { + amrex::ParallelFor( pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + UpdateMomentumHigueraCary( uxpp[i], uypp[i], uzpp[i], + Expp[i], Eypp[i], Ezpp[i], Bxpp[i], Bypp[i], Bzpp[i], q, m, dt); + } + ); } else { amrex::Abort("Unknown particle pusher"); }; diff --git a/Source/Utils/WarpXAlgorithmSelection.H b/Source/Utils/WarpXAlgorithmSelection.H index 54c721abf..c29cb7224 100644 --- a/Source/Utils/WarpXAlgorithmSelection.H +++ b/Source/Utils/WarpXAlgorithmSelection.H @@ -14,7 +14,8 @@ struct MaxwellSolverAlgo { struct ParticlePusherAlgo { enum { Boris = 0, - Vay = 1 + Vay = 1, + HigueraCary = 0 }; }; diff --git a/Source/Utils/WarpXAlgorithmSelection.cpp b/Source/Utils/WarpXAlgorithmSelection.cpp index 8a6ff6dbf..4ad07f4f1 100644 --- a/Source/Utils/WarpXAlgorithmSelection.cpp +++ b/Source/Utils/WarpXAlgorithmSelection.cpp @@ -18,6 +18,7 @@ const std::map maxwell_solver_algo_to_int = { const std::map particle_pusher_algo_to_int = { {"boris", ParticlePusherAlgo::Boris }, {"vay", ParticlePusherAlgo::Vay }, + {"hc", ParticlePusherAlgo::HigueraCary }, {"default", ParticlePusherAlgo::Boris } }; -- cgit v1.2.3 From 2ba67328ac041fd63204359ba10a868a383e29c7 Mon Sep 17 00:00:00 2001 From: Yin-YinjianZhao Date: Fri, 18 Oct 2019 10:58:14 -0700 Subject: Modified according to MaxThevenet's comments --- Docs/source/running_cpp/parameters.rst | 2 +- Examples/Tests/particle_pusher/analysis_pusher.py | 2 ++ Examples/Tests/particle_pusher/inputs | 2 +- Regression/WarpX-tests.ini | 4 ++-- Source/Particles/Pusher/UpdateMomentumHigueraCary.H | 9 ++++++--- Source/Utils/WarpXAlgorithmSelection.cpp | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) (limited to 'Source/Utils/WarpXAlgorithmSelection.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 4a82c3637..8690d134d 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -621,7 +621,7 @@ Numerics and algorithms - ``boris``: Boris pusher. - ``vay``: Vay pusher (see `Vay, Phys. Plasmas (2008) `__) - - ``hc``: Higuera-Cary pusher (see `Higuera and Cary, Phys. Plasmas (2017) `__) + - ``higuera``: Higuera-Cary pusher (see `Higuera and Cary, Phys. Plasmas (2017) `__) If ``algo.particle_pusher`` is not specified, ``boris`` is the default. diff --git a/Examples/Tests/particle_pusher/analysis_pusher.py b/Examples/Tests/particle_pusher/analysis_pusher.py index 90c86dc8b..0d9fc24c5 100755 --- a/Examples/Tests/particle_pusher/analysis_pusher.py +++ b/Examples/Tests/particle_pusher/analysis_pusher.py @@ -1,3 +1,5 @@ +#! /usr/bin/env python + # This script tests the particle pusher (HC) # using a force-free field, # in which position x should remain 0. diff --git a/Examples/Tests/particle_pusher/inputs b/Examples/Tests/particle_pusher/inputs index 0aa11f4a5..45c075f51 100755 --- a/Examples/Tests/particle_pusher/inputs +++ b/Examples/Tests/particle_pusher/inputs @@ -22,7 +22,7 @@ warpx.do_pml = 0 # Algorithms algo.charge_deposition = standard algo.field_gathering = standard -algo.particle_pusher = "hc" +algo.particle_pusher = "higuera" # CFL warpx.cfl = 1.0 diff --git a/Regression/WarpX-tests.ini b/Regression/WarpX-tests.ini index 39dd776fc..eb7083a60 100644 --- a/Regression/WarpX-tests.ini +++ b/Regression/WarpX-tests.ini @@ -669,9 +669,9 @@ inputFile = Examples/Tests/particle_pusher/inputs dim = 3 restartTest = 0 useMPI = 1 -numprocs = 2 +numprocs = 1 useOMP = 1 -numthreads = 2 +numthreads = 1 compileTest = 0 doVis = 0 compareParticles = 0 diff --git a/Source/Particles/Pusher/UpdateMomentumHigueraCary.H b/Source/Particles/Pusher/UpdateMomentumHigueraCary.H index f2accd760..51d7fd620 100644 --- a/Source/Particles/Pusher/UpdateMomentumHigueraCary.H +++ b/Source/Particles/Pusher/UpdateMomentumHigueraCary.H @@ -1,12 +1,15 @@ #ifndef WARPX_PARTICLES_PUSHER_UPDATEMOMENTUM_HIGUERACARY_H_ #define WARPX_PARTICLES_PUSHER_UPDATEMOMENTUM_HIGUERACARY_H_ +#include "WarpXConst.H" #include -#include #include -/* \brief Push the particle's positions over one timestep, - * given the value of its momenta `ux`, `uy`, `uz` */ +/** + * \brief Push the particle's positions over one timestep, + * given the value of its momenta `ux`, `uy`, `uz` + */ + AMREX_GPU_HOST_DEVICE AMREX_INLINE void UpdateMomentumHigueraCary( amrex::ParticleReal& ux, amrex::ParticleReal& uy, amrex::ParticleReal& uz, diff --git a/Source/Utils/WarpXAlgorithmSelection.cpp b/Source/Utils/WarpXAlgorithmSelection.cpp index 4ad07f4f1..be9cdd118 100644 --- a/Source/Utils/WarpXAlgorithmSelection.cpp +++ b/Source/Utils/WarpXAlgorithmSelection.cpp @@ -18,7 +18,7 @@ const std::map maxwell_solver_algo_to_int = { const std::map particle_pusher_algo_to_int = { {"boris", ParticlePusherAlgo::Boris }, {"vay", ParticlePusherAlgo::Vay }, - {"hc", ParticlePusherAlgo::HigueraCary }, + {"higuera", ParticlePusherAlgo::HigueraCary }, {"default", ParticlePusherAlgo::Boris } }; -- cgit v1.2.3