From a4c2b99651cbac22ccbf2b0f3e1441c61e639009 Mon Sep 17 00:00:00 2001 From: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com> Date: Fri, 27 Aug 2021 11:39:37 -0700 Subject: Functionality to save particle positions from the previous step (#2206) * added functionality to save particle positions from the previous step * copied WarpX variable to local variable to fix issue with GPU and DPC++ compilation * switched to using a species attribute to toggle whether previous positions are saved so it can be turned on for only a subset of species if desired * changed variable name to be more verbose * added CI test of saving the previous particle positions * start of a table in the documentation to describe commonly used runtime attributes * generate test benchmark data from results obtained with a 2 processor run - the same as what is done during the test * relaxed tolerance on test * regenerate CI test reference data with USE_PSATD=TRUE * Update Docs/source/developers/particles.rst Co-authored-by: Phil Miller Co-authored-by: Axel Huebl --- Source/Particles/PhysicalParticleContainer.cpp | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index d489cddfe..c704e824a 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -230,6 +230,19 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp } #endif + // If old particle positions should be saved add the needed components + pp_species_name.query("save_previous_position", m_save_previous_position); + if (m_save_previous_position) { + AddRealComp("prev_x"); +#if (AMREX_SPACEDIM == 3) + AddRealComp("prev_y"); +#endif + AddRealComp("prev_z"); +#ifdef WARPX_DIM_RZ + amrex::Abort("Saving previous particle positions not yet implemented in RZ"); +#endif + } + // Get Galilean velocity ParmParse pp_psatd("psatd"); bool use_default_v_galilean = false; @@ -2317,6 +2330,20 @@ PhysicalParticleContainer::PushPX (WarpXParIter& pti, ion_lev = pti.GetiAttribs(particle_icomps["ionization_level"]).dataPtr(); } + const bool save_previous_position = m_save_previous_position; + ParticleReal* x_old = nullptr; + ParticleReal* y_old = nullptr; + ParticleReal* z_old = nullptr; + if (save_previous_position) { + x_old = pti.GetAttribs(particle_comps["prev_x"]).dataPtr(); +#if (AMREX_SPACEDIM == 3) + y_old = pti.GetAttribs(particle_comps["prev_y"]).dataPtr(); +#else + amrex::ignore_unused(y_old); +#endif + z_old = pti.GetAttribs(particle_comps["prev_z"]).dataPtr(); + } + // Loop over the particles and update their momentum const amrex::Real q = this->charge; const amrex::Real m = this-> mass; @@ -2344,6 +2371,14 @@ PhysicalParticleContainer::PushPX (WarpXParIter& pti, amrex::ParticleReal xp, yp, zp; getPosition(ip, xp, yp, zp); + if (save_previous_position) { + x_old[ip] = xp; +#if (AMREX_SPACEDIM == 3) + y_old[ip] = yp; +#endif + z_old[ip] = zp; + } + amrex::ParticleReal Exp = 0._rt, Eyp = 0._rt, Ezp = 0._rt; amrex::ParticleReal Bxp = 0._rt, Byp = 0._rt, Bzp = 0._rt; -- cgit v1.2.3