Skip to content

Commit bcdc0aa

Browse files
created an ImplicitOptions struct to pass into Evolve(). (BLAST-WarpX#6116)
In future PRs, the PhysicalParticleContainer::Evolve() routine will require more parameters specific to the implicit methods. To avoid bloating the list of parameter passed into Evolve(), this PR creates an ImplicitOptions structure to pass into Evolve() that owns all of the implicit options needed by the particle push and deposit routines. This allows direct and dynamic control of the what goes on in the Evolve() routine from the ImplicitSolver class.
1 parent 8e7b492 commit bcdc0aa

20 files changed

+79
-68
lines changed

Source/Diagnostics/WarpXIO.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,6 @@ WarpX::InitFromCheckpoint ()
410410
if (m_implicit_solver) {
411411

412412
m_implicit_solver->Define(this);
413-
m_implicit_solver->GetParticleSolverParams( max_particle_its_in_implicit_scheme,
414-
particle_tol_in_implicit_scheme );
415413
m_implicit_solver->CreateParticleAttributes();
416414
}
417415

Source/Evolve/WarpXEvolve.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,8 +1212,7 @@ void
12121212
WarpX::PushParticlesandDeposit (
12131213
amrex::Real cur_time,
12141214
bool skip_current,
1215-
bool deposit_mass_matrices,
1216-
PushType push_type
1215+
ImplicitOptions const * implicit_options
12171216
)
12181217
{
12191218
// Evolve particles to p^{n+1/2} and x^{n+1}
@@ -1224,8 +1223,7 @@ WarpX::PushParticlesandDeposit (
12241223
cur_time,
12251224
DtType::Full,
12261225
skip_current,
1227-
deposit_mass_matrices,
1228-
push_type
1226+
implicit_options
12291227
);
12301228
}
12311229
}
@@ -1236,8 +1234,7 @@ WarpX::PushParticlesandDeposit (
12361234
amrex::Real cur_time,
12371235
DtType a_dt_type,
12381236
bool skip_current,
1239-
bool deposit_mass_matrices,
1240-
PushType push_type
1237+
ImplicitOptions const * implicit_options
12411238
)
12421239
{
12431240
using ablastr::fields::Direction;
@@ -1266,8 +1263,7 @@ WarpX::PushParticlesandDeposit (
12661263
dt[lev],
12671264
a_dt_type,
12681265
skip_current,
1269-
deposit_mass_matrices,
1270-
push_type
1266+
implicit_options
12711267
);
12721268

12731269
if (! skip_current) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef IMPLICIT_OPTIONS_H_
2+
#define IMPLICIT_OPTIONS_H_
3+
4+
#include <AMReX_Particles.H>
5+
using namespace amrex::literals;
6+
7+
struct ImplicitOptions {
8+
int max_particle_iterations = 21;
9+
amrex::ParticleReal particle_tolerance = 1.0e-10_prt;
10+
bool deposit_mass_matrices = false;
11+
bool linear_stage_of_jfnk = false;
12+
int nonlinear_iteration = 0;
13+
};
14+
15+
#endif

Source/FieldSolver/ImplicitSolvers/ImplicitSolver.H

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef Implicit_Solver_H_
88
#define Implicit_Solver_H_
99

10+
#include "FieldSolver/ImplicitSolvers/ImplicitOptions.H"
11+
1012
#include "FieldSolver/ImplicitSolvers/WarpXSolverVec.H"
1113
#include "NonlinearSolvers/NonlinearSolverLibrary.H"
1214

@@ -50,13 +52,6 @@ public:
5052

5153
virtual void PrintParameters () const = 0;
5254

53-
void GetParticleSolverParams (int& a_max_particle_iter,
54-
amrex::ParticleReal& a_particle_tol ) const
55-
{
56-
a_max_particle_iter = m_max_particle_iterations;
57-
a_particle_tol = m_particle_tolerance;
58-
}
59-
6055
void CreateParticleAttributes () const;
6156

6257
/**
@@ -145,7 +140,7 @@ protected:
145140
* \brief tolerance used by the iterative method used to obtain a self-consistent
146141
* update of the particle positions and velocities for given E and B on the grid
147142
*/
148-
amrex::ParticleReal m_particle_tolerance = 1.0e-10;
143+
amrex::ParticleReal m_particle_tolerance = amrex::ParticleReal(1.0e-10);
149144

150145
/**
151146
* \brief maximum iterations for the iterative method used to obtain a self-consistent

Source/FieldSolver/ImplicitSolvers/ImplicitSolver.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "ImplicitSolver.H"
22
#include "Fields.H"
33
#include "WarpX.H"
4-
#include "Evolve/WarpXPushType.H"
54
#include "Particles/MultiParticleContainer.H"
65
#include "Utils/WarpXAlgorithmSelection.H"
76

@@ -687,7 +686,6 @@ void ImplicitSolver::PreRHSOp ( const amrex::Real a_cur_time,
687686
BL_PROFILE("ImplicitSolver::PreRHSOp()");
688687

689688
using warpx::fields::FieldType;
690-
amrex::ignore_unused( a_nl_iter );
691689

692690
if (m_WarpX->use_filter) {
693691
int finest_level = 0;
@@ -698,12 +696,18 @@ void ImplicitSolver::PreRHSOp ( const amrex::Real a_cur_time,
698696
// particle velocities by dt, then take average of old and new v,
699697
// deposit currents, giving J at n+1/2
700698
// This uses Efield_fp and Bfield_fp, the field at n+1/2 from the previous iteration.
701-
const PushType push_type = PushType::Implicit;
702699
const bool skip_current = false;
703700

701+
// Set the implict solver options for particles and setting the current density
702+
ImplicitOptions options;
703+
options.nonlinear_iteration = a_nl_iter;
704+
options.max_particle_iterations = m_max_particle_iterations;
705+
options.particle_tolerance = m_particle_tolerance;
706+
options.linear_stage_of_jfnk = a_from_jacobian;
707+
704708
if (m_use_mass_matrices && !a_from_jacobian) { // Called from non-linear stage of JFNK and using mass matrices
705-
bool deposit_mass_matrices = true;
706-
m_WarpX->PushParticlesandDeposit(a_cur_time, skip_current, deposit_mass_matrices, push_type);
709+
options.deposit_mass_matrices = true;
710+
m_WarpX->PushParticlesandDeposit(a_cur_time, skip_current, &options);
707711
if (m_use_mass_matrices_jacobian) { SaveEandJ(); }
708712
if (m_use_mass_matrices_pc) {
709713
SyncMassMatricesPCAndApplyBCs();
@@ -715,8 +719,8 @@ void ImplicitSolver::PreRHSOp ( const amrex::Real a_cur_time,
715719
ComputeJfromMassMatrices();
716720
}
717721
else { // Conventional particle-suppressed JFNK
718-
bool deposit_mass_matrices = false;
719-
m_WarpX->PushParticlesandDeposit(a_cur_time, skip_current, deposit_mass_matrices, push_type);
722+
options.deposit_mass_matrices = false;
723+
m_WarpX->PushParticlesandDeposit(a_cur_time, skip_current, &options);
720724
}
721725

722726
// Apply BCs to J and communicate

Source/Initialization/WarpXInitData.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,6 @@ WarpX::InitFromScratch ()
925925
if (m_implicit_solver) {
926926

927927
m_implicit_solver->Define(this);
928-
m_implicit_solver->GetParticleSolverParams( max_particle_its_in_implicit_scheme,
929-
particle_tol_in_implicit_scheme );
930928
m_implicit_solver->CreateParticleAttributes();
931929
}
932930

Source/Particles/LaserParticleContainer.H

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "Laser/LaserProfiles.H"
1515
#include "WarpXParticleContainer.H"
1616

17+
#include "FieldSolver/ImplicitSolvers/ImplicitOptions.H"
18+
1719
#include <AMReX_Extension.H>
1820
#include <AMReX_Random.H>
1921
#include <AMReX_REAL.H>
@@ -68,8 +70,8 @@ public:
6870
int lev,
6971
const std::string& current_fp_string,
7072
amrex::Real t, amrex::Real dt, DtType a_dt_type=DtType::Full,
71-
bool skip_deposition=false, bool deposit_mass_matrices=false,
72-
PushType push_type=PushType::Explicit) final;
73+
bool skip_deposition=false,
74+
ImplicitOptions const * implicit_options = nullptr) final;
7375

7476
void PushP (int lev, amrex::Real dt,
7577
const amrex::MultiFab& ,

Source/Particles/LaserParticleContainer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ LaserParticleContainer::Evolve (ablastr::fields::MultiFabRegister& fields,
563563
int lev,
564564
const std::string& current_fp_string,
565565
Real t, Real dt, DtType /*a_dt_type*/, bool skip_deposition,
566-
bool /*deposit_mass_matrices*/, PushType push_type)
566+
ImplicitOptions const * implicit_options)
567567
{
568568
using ablastr::fields::Direction;
569569
using warpx::fields::FieldType;
@@ -573,6 +573,8 @@ LaserParticleContainer::Evolve (ablastr::fields::MultiFabRegister& fields,
573573

574574
if (!m_enabled) { return; }
575575

576+
const PushType push_type = (implicit_options == nullptr) ? PushType::Explicit : PushType::Implicit;
577+
576578
Real t_lab = t;
577579
if (WarpX::gamma_boost > 1) {
578580
// Convert time from the boosted to the lab-frame

Source/Particles/MultiParticleContainer.H

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define WARPX_ParticleContainer_H_
1313

1414
#include "MultiParticleContainer_fwd.H"
15+
#include "FieldSolver/ImplicitSolvers/ImplicitOptions.H"
1516

1617
#include "Evolve/WarpXDtType.H"
1718
#include "Evolve/WarpXPushType.H"
@@ -113,8 +114,7 @@ public:
113114
amrex::Real dt,
114115
DtType a_dt_type=DtType::Full,
115116
bool skip_deposition=false,
116-
bool deposit_mass_matrices=false,
117-
PushType push_type=PushType::Explicit
117+
ImplicitOptions const * implicit_options = nullptr
118118
);
119119

120120
/**

Source/Particles/MultiParticleContainer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ MultiParticleContainer::Evolve (ablastr::fields::MultiFabRegister& fields,
455455
int lev,
456456
std::string const& current_fp_string,
457457
Real t, Real dt, DtType a_dt_type, bool skip_deposition,
458-
bool deposit_mass_matrices, PushType push_type)
458+
ImplicitOptions const * implicit_options)
459459
{
460460
if (! skip_deposition) {
461461
using ablastr::fields::Direction;
@@ -468,7 +468,7 @@ MultiParticleContainer::Evolve (ablastr::fields::MultiFabRegister& fields,
468468
if (fields.has(FieldType::current_buf, Direction{2}, lev)) { fields.get(FieldType::current_buf, Direction{2}, lev)->setVal(0.0); }
469469
if (fields.has(FieldType::rho_fp, lev)) { fields.get(FieldType::rho_fp, lev)->setVal(0.0); }
470470
if (fields.has(FieldType::rho_buf, lev)) { fields.get(FieldType::rho_buf, lev)->setVal(0.0); }
471-
if (deposit_mass_matrices) {
471+
if (implicit_options && implicit_options->deposit_mass_matrices) {
472472
fields.get(FieldType::MassMatrices_X, Direction{0}, lev)->setVal(0.0);
473473
fields.get(FieldType::MassMatrices_X, Direction{1}, lev)->setVal(0.0);
474474
fields.get(FieldType::MassMatrices_X, Direction{2}, lev)->setVal(0.0);
@@ -481,7 +481,7 @@ MultiParticleContainer::Evolve (ablastr::fields::MultiFabRegister& fields,
481481
}
482482
}
483483
for (auto& pc : allcontainers) {
484-
pc->Evolve(fields, lev, current_fp_string, t, dt, a_dt_type, skip_deposition, deposit_mass_matrices, push_type);
484+
pc->Evolve(fields, lev, current_fp_string, t, dt, a_dt_type, skip_deposition, implicit_options);
485485
}
486486
}
487487

0 commit comments

Comments
 (0)