Skip to content

Commit

Permalink
Pass gamma_boost as argument to AcceleratorLattice, `LatticeEleme…
Browse files Browse the repository at this point in the history
…ntFinder` (#5541)

This PR is a small step towards the goal of reducing the usage of static variables in the WarpX class.

---------

Co-authored-by: Edoardo Zoni <[email protected]>
  • Loading branch information
lucafedeli88 and EZoni authored Jan 14, 2025
1 parent a203655 commit c666e75
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
7 changes: 6 additions & 1 deletion Source/AcceleratorLattice/AcceleratorLattice.H
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ public:
* \brief Initialize the element finder instance at the given level of refinement
*
* @param[in] lev the level of refinement
* @param[in] gamma_boost the Lorentz factor of the boosted frame
* @param[in] ba the box array at the level of refinement
* @param[in] dm the distribution map at the level of refinement
*/
void InitElementFinder (int lev, amrex::BoxArray const & ba, amrex::DistributionMapping const & dm);
void InitElementFinder (
int lev,
amrex::Real gamma_boost,
amrex::BoxArray const & ba,
amrex::DistributionMapping const & dm);

/**
* \brief Update the element finder, needed when the simulation frame has moved relative to the lab frame
Expand Down
6 changes: 4 additions & 2 deletions Source/AcceleratorLattice/AcceleratorLattice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ AcceleratorLattice::ReadLattice (std::string const & root_name, amrex::ParticleR
}

void
AcceleratorLattice::InitElementFinder (int const lev, amrex::BoxArray const & ba, amrex::DistributionMapping const & dm)
AcceleratorLattice::InitElementFinder (
int const lev, amrex::Real const gamma_boost,
amrex::BoxArray const & ba, amrex::DistributionMapping const & dm)
{
if (m_lattice_defined) {
m_element_finder = std::make_unique<amrex::LayoutData<LatticeElementFinder>>(ba, dm);
for (amrex::MFIter mfi(*m_element_finder); mfi.isValid(); ++mfi)
{
(*m_element_finder)[mfi].InitElementFinder(lev, mfi, *this);
(*m_element_finder)[mfi].InitElementFinder(lev, gamma_boost, mfi, *this);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Source/AcceleratorLattice/LatticeElementFinder.H
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ struct LatticeElementFinder
* \brief Initialize the element finder at the level and grid
*
* @param[in] lev the refinement level
* @param[in] gamma_boost the Lorentz factor of the boosted frame
* @param[in] a_mfi specifies the grid where the finder is defined
* @param[in] accelerator_lattice a reference to the accelerator lattice at the refinement level
*/
void InitElementFinder (int lev, amrex::MFIter const& a_mfi,
void InitElementFinder (int lev, amrex::Real gamma_boost,
amrex::MFIter const& a_mfi,
AcceleratorLattice const& accelerator_lattice);

/**
Expand Down
7 changes: 4 additions & 3 deletions Source/AcceleratorLattice/LatticeElementFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
using namespace amrex::literals;

void
LatticeElementFinder::InitElementFinder (int const lev, amrex::MFIter const& a_mfi,
LatticeElementFinder::InitElementFinder (int const lev, const amrex::Real gamma_boost,
amrex::MFIter const& a_mfi,
AcceleratorLattice const& accelerator_lattice)
{

Expand All @@ -26,8 +27,8 @@ LatticeElementFinder::InitElementFinder (int const lev, amrex::MFIter const& a_m

m_dz = WarpX::CellSize(lev)[2];

m_gamma_boost = WarpX::gamma_boost;
m_uz_boost = std::sqrt(WarpX::gamma_boost*WarpX::gamma_boost - 1._prt)*PhysConst::c;
m_gamma_boost = gamma_boost;
m_uz_boost = std::sqrt(m_gamma_boost*m_gamma_boost - 1._prt)*PhysConst::c;

AllocateIndices(accelerator_lattice);

Expand Down
2 changes: 1 addition & 1 deletion Source/Parallelization/WarpXRegrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ WarpX::RemakeLevel (int lev, Real /*time*/, const BoxArray& ba, const Distributi
}

// Re-initialize the lattice element finder with the new ba and dm.
m_accelerator_lattice[lev]->InitElementFinder(lev, ba, dm);
m_accelerator_lattice[lev]->InitElementFinder(lev, gamma_boost, ba, dm);

if (costs[lev] != nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ WarpX::AllocLevelData (int lev, const BoxArray& ba, const DistributionMapping& d
guard_cells.ng_alloc_Rho, guard_cells.ng_alloc_F, guard_cells.ng_alloc_G, aux_is_nodal);

m_accelerator_lattice[lev] = std::make_unique<AcceleratorLattice>();
m_accelerator_lattice[lev]->InitElementFinder(lev, ba, dm);
m_accelerator_lattice[lev]->InitElementFinder(lev, gamma_boost, ba, dm);

}

Expand Down

0 comments on commit c666e75

Please sign in to comment.