Skip to content

Commit 27aaa0b

Browse files
authored
WarpX class: make zmax_plasma_to_compute_max_step a private member variable and remove do_compute_max_step_from_zmax (#5605)
This PR combines the following static variables of the WarpX class: ``` static amrex::Real zmax_plasma_to_compute_max_step; static bool do_compute_max_step_from_zmax; ``` into a single private member variable: ``` std::optional<amrex::Real> m_zmax_plasma_to_compute_max_step = std::nullopt; ``` This is a small step towards reducing reliance on static class variables.
1 parent 1e82e89 commit 27aaa0b

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

Source/Initialization/WarpXInitData.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ WarpX::InitData ()
530530
// WarpX::computeMaxStepBoostAccelerator
531531
// needs to start from the initial zmin_domain_boost,
532532
// even if restarting from a checkpoint file
533-
if (do_compute_max_step_from_zmax) {
533+
if (m_zmax_plasma_to_compute_max_step.has_value()) {
534534
zmin_domain_boost_step_0 = geom[0].ProbLo(WARPX_ZINDEX);
535535
}
536536
if (restart_chkfile.empty())
@@ -798,7 +798,7 @@ WarpX::ComputePMLFactors ()
798798
void
799799
WarpX::ComputeMaxStep ()
800800
{
801-
if (do_compute_max_step_from_zmax) {
801+
if (m_zmax_plasma_to_compute_max_step.has_value()) {
802802
computeMaxStepBoostAccelerator();
803803
}
804804
}
@@ -831,7 +831,7 @@ WarpX::computeMaxStepBoostAccelerator() {
831831

832832
// End of the plasma: Transform input argument
833833
// zmax_plasma_to_compute_max_step to boosted frame.
834-
const Real len_plasma_boost = zmax_plasma_to_compute_max_step/gamma_boost;
834+
const Real len_plasma_boost = m_zmax_plasma_to_compute_max_step.value()/gamma_boost;
835835
// Plasma velocity
836836
const Real v_plasma_boost = -beta_boost * PhysConst::c;
837837
// Get time at which the lower end of the simulation domain passes the

Source/WarpX.H

+6-8
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,7 @@ public:
356356
static amrex::Real beta_boost;
357357
//! Direction of the Lorentz transform that defines the boosted frame of the simulation
358358
static amrex::Vector<int> boost_direction;
359-
//! If specified, the maximum number of iterations is computed automatically so that
360-
//! the lower end of the simulation domain along z reaches #zmax_plasma_to_compute_max_step
361-
//! in the boosted frame
362-
static amrex::Real zmax_plasma_to_compute_max_step;
363-
//! Set to true if #zmax_plasma_to_compute_max_step is specified, in which case
364-
//! the maximum number of iterations is computed automatically so that the lower end of the
365-
//! simulation domain along z reaches #zmax_plasma_to_compute_max_step in the boosted frame
366-
static bool do_compute_max_step_from_zmax;
359+
367360
//! store initial value of zmin_domain_boost because WarpX::computeMaxStepBoostAccelerator
368361
//! needs the initial value of zmin_domain_boost, even if restarting from a checkpoint file
369362
static amrex::Real zmin_domain_boost_step_0;
@@ -1541,6 +1534,11 @@ private:
15411534
int max_step = std::numeric_limits<int>::max();
15421535
amrex::Real stop_time = std::numeric_limits<amrex::Real>::max();
15431536

1537+
//! If specified, the maximum number of iterations is computed automatically so that
1538+
//! the lower end of the simulation domain along z reaches #zmax_plasma_to_compute_max_step
1539+
//! in the boosted frame
1540+
std::optional<amrex::Real> m_zmax_plasma_to_compute_max_step = std::nullopt;
1541+
15441542
int regrid_int = -1;
15451543

15461544
amrex::Real cfl = amrex::Real(0.999);

Source/WarpX.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ amrex::IntVect WarpX::m_fill_guards_current = amrex::IntVect(0);
111111
Real WarpX::gamma_boost = 1._rt;
112112
Real WarpX::beta_boost = 0._rt;
113113
Vector<int> WarpX::boost_direction = {0,0,0};
114-
bool WarpX::do_compute_max_step_from_zmax = false;
115114
bool WarpX::compute_max_step_from_btd = false;
116-
Real WarpX::zmax_plasma_to_compute_max_step = 0._rt;
117115
Real WarpX::zmin_domain_boost_step_0 = 0._rt;
118116

119117
int WarpX::max_particle_its_in_implicit_scheme = 21;
@@ -491,7 +489,6 @@ WarpX::~WarpX ()
491489
void
492490
WarpX::ReadParameters ()
493491
{
494-
495492
{
496493
const ParmParse pp;// Traditionally, max_step and stop_time do not have prefix.
497494
utils::parser::queryWithParser(pp, "max_step", max_step);
@@ -673,9 +670,9 @@ WarpX::ReadParameters ()
673670

674671
// queryWithParser returns 1 if argument zmax_plasma_to_compute_max_step is
675672
// specified by the user, 0 otherwise.
676-
do_compute_max_step_from_zmax = utils::parser::queryWithParser(
677-
pp_warpx, "zmax_plasma_to_compute_max_step",
678-
zmax_plasma_to_compute_max_step);
673+
if(auto temp = 0.0_rt; utils::parser::queryWithParser(pp_warpx, "zmax_plasma_to_compute_max_step",temp)){
674+
m_zmax_plasma_to_compute_max_step = temp;
675+
}
679676

680677
pp_warpx.query("compute_max_step_from_btd",
681678
compute_max_step_from_btd);

0 commit comments

Comments
 (0)