Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Remove temporary particle container #5571

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ struct SelectParticles
* \brief Constructor of SelectParticles functor.
*
* @param[in] a_pti WarpX particle iterator
* @param[in] tmp_particle_data temporary particle data
* @param[in] current_z_boost current z-position of the slice in boosted frame
* @param[in] old_z_boost previous z-position of the slice in boosted frame
* @param[in] a_offset index offset for particles to be selected
*/
SelectParticles( const WarpXParIter& a_pti, TmpParticles& tmp_particle_data,
SelectParticles (const WarpXParticleContainer& pc,
const WarpXParIter& a_pti,
amrex::Real current_z_boost, amrex::Real old_z_boost,
int a_offset = 0);

Expand Down Expand Up @@ -83,15 +83,15 @@ struct LorentzTransformParticles
* \brief Constructor of the LorentzTransformParticles functor.
*
* @param[in] a_pti WarpX particle iterator
* @param[in] tmp_particle_data temporary particle data
* @param[in] t_boost time in boosted frame
* @param[in] dt timestep in boosted-frame
* @param[in] t_lab time in lab-frame
* @param[in] a_offset index offset for particles to be transformed
*/
LorentzTransformParticles ( const WarpXParIter& a_pti, TmpParticles& tmp_particle_data,
amrex::Real t_boost, amrex::Real dt,
amrex::Real t_lab, int a_offset = 0);
LorentzTransformParticles (const WarpXParticleContainer& pc,
const WarpXParIter& a_pti,
amrex::Real t_boost, amrex::Real dt,
amrex::Real t_lab, int a_offset = 0);

/**
* \brief Functor call. This method computes the Lorentz-transform for particle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,37 @@
#include <AMReX_Print.H>
#include <AMReX_BaseFwd.H>

SelectParticles::SelectParticles (const WarpXParIter& a_pti, TmpParticles& tmp_particle_data,
amrex::Real current_z_boost, amrex::Real old_z_boost,
int a_offset)
SelectParticles::SelectParticles (
const WarpXParticleContainer& pc,
const WarpXParIter& a_pti,
amrex::Real current_z_boost,
amrex::Real old_z_boost,
int a_offset
)
: m_current_z_boost(current_z_boost), m_old_z_boost(old_z_boost)
{
m_get_position = GetParticlePosition<PIdx>(a_pti, a_offset);

const auto lev = a_pti.GetLevel();
const auto index = a_pti.GetPairIndex();

zpold = tmp_particle_data[lev][index][TmpIdx::zold].dataPtr();
auto particle_comps = pc.getParticleComps();
zpold = a_pti.GetAttribs(particle_comps["z_n_btd"]).dataPtr();
}


LorentzTransformParticles::LorentzTransformParticles ( const WarpXParIter& a_pti,
TmpParticles& tmp_particle_data,
amrex::Real t_boost, amrex::Real dt,
amrex::Real t_lab, int a_offset)
LorentzTransformParticles::LorentzTransformParticles (
const WarpXParticleContainer& pc,
const WarpXParIter& a_pti,
amrex::Real t_boost,
amrex::Real dt,
amrex::Real t_lab,
int a_offset
)
: m_t_boost(t_boost), m_dt(dt), m_t_lab(t_lab)
{
using namespace amrex::literals;

if (tmp_particle_data.empty()) { return; }
// FIXME
//if (tmp_particle_data.empty()) { return; }

m_get_position = GetParticlePosition<PIdx>(a_pti, a_offset);

const auto& attribs = a_pti.GetAttribs();
Expand All @@ -46,15 +54,13 @@ LorentzTransformParticles::LorentzTransformParticles ( const WarpXParIter& a_pti
m_uypnew = attribs[PIdx::uy].dataPtr();
m_uzpnew = attribs[PIdx::uz].dataPtr();

const auto lev = a_pti.GetLevel();
const auto index = a_pti.GetPairIndex();

m_xpold = tmp_particle_data[lev][index][TmpIdx::xold].dataPtr();
m_ypold = tmp_particle_data[lev][index][TmpIdx::yold].dataPtr();
m_zpold = tmp_particle_data[lev][index][TmpIdx::zold].dataPtr();
m_uxpold = tmp_particle_data[lev][index][TmpIdx::uxold].dataPtr();
m_uypold = tmp_particle_data[lev][index][TmpIdx::uyold].dataPtr();
m_uzpold = tmp_particle_data[lev][index][TmpIdx::uzold].dataPtr();
auto particle_comps = pc.getParticleComps();
m_xpold = a_pti.GetAttribs(particle_comps["x_n_btd"]).dataPtr();
m_ypold = a_pti.GetAttribs(particle_comps["y_n_btd"]).dataPtr();
m_zpold = a_pti.GetAttribs(particle_comps["z_n_btd"]).dataPtr();
m_uxpold = a_pti.GetAttribs(particle_comps["ux_n_btd"]).dataPtr();
m_uypold = a_pti.GetAttribs(particle_comps["uy_n_btd"]).dataPtr();
m_uzpold = a_pti.GetAttribs(particle_comps["uz_n_btd"]).dataPtr();

m_betaboost = WarpX::beta_boost;
m_gammaboost = WarpX::gamma_boost;
Expand Down Expand Up @@ -84,7 +90,6 @@ BackTransformParticleFunctor::operator () (PinnedMemoryParticleContainer& pc_dst
auto &warpx = WarpX::GetInstance();
// get particle slice
const int nlevs = std::max(0, m_pc_src->finestLevel()+1);
auto tmp_particle_data = m_pc_src->getTmpParticleData();
for (int lev = 0; lev < nlevs; ++lev) {
const amrex::Real t_boost = warpx.gett_new(0);
const amrex::Real dt = warpx.getdt(0);
Expand All @@ -107,13 +112,19 @@ BackTransformParticleFunctor::operator () (PinnedMemoryParticleContainer& pc_dst

auto index = std::make_pair(pti.index(), pti.LocalTileIndex());

const auto GetParticleFilter = SelectParticles(pti, tmp_particle_data,
m_current_z_boost[i_buffer],
m_old_z_boost[i_buffer]);
const auto GetParticleFilter = SelectParticles(
*m_pc_src,
pti,
m_current_z_boost[i_buffer],
m_old_z_boost[i_buffer]
);
const auto GetParticleLorentzTransform = LorentzTransformParticles(
pti, tmp_particle_data,
t_boost, dt,
m_t_lab[i_buffer]);
*m_pc_src,
pti,
t_boost,
dt,
m_t_lab[i_buffer]
);

long const np = pti.numParticles();

Expand Down
22 changes: 22 additions & 0 deletions Source/Initialization/WarpXInitData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,28 @@ WarpX::InitFromScratch ()
m_implicit_solver->CreateParticleAttributes();
}

if (m_do_back_transformed_particles)
{
// Set comm to false so that the attributes are not communicated
// nor written to the checkpoint files
int const comm = 0;

// Add space to save the positions and velocities at the start of the time steps
for (auto const& pc : m_WarpX->GetPartContainer())
{
#if (AMREX_SPACEDIM >= 2)
pc->NewRealComp("x_n_btd", comm);
#endif
#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ)
pc->NewRealComp("y_n_btd", comm);
#endif
pc->NewRealComp("z_n_btd", comm);
pc->NewRealComp("ux_n_btd", comm);
pc->NewRealComp("uy_n_btd", comm);
pc->NewRealComp("uz_n_btd", comm);
}
}

mypc->AllocData();
mypc->InitData();

Expand Down
5 changes: 0 additions & 5 deletions Source/Particles/WarpXParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,8 @@ public:
TmpIdx::nattribs>;
using TmpParticles = amrex::Vector<std::map<PairIndex, TmpParticleTile> >;

TmpParticles getTmpParticleData () const noexcept {return tmp_particle_data;}

int getIonizationInitialLevel () const noexcept {return ionization_initial_level;}

protected:
TmpParticles tmp_particle_data;

private:
void particlePostLocate(ParticleType& p, const amrex::ParticleLocData& pld, int lev) override;

Expand Down