WarpX
ImplicitSolver.H
Go to the documentation of this file.
1 /* Copyright 2024 Justin Angus
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef Implicit_Solver_H_
8 #define Implicit_Solver_H_
9 
12 
13 #include <AMReX_Array.H>
14 #include <AMReX_REAL.H>
15 
22 class WarpX;
24 {
25 public:
26 
27  ImplicitSolver() = default;
28 
29  virtual ~ImplicitSolver() = default;
30 
31  // Prohibit Move and Copy operations
32  ImplicitSolver(const ImplicitSolver&) = delete;
36 
37  //
38  // the following routines are called by WarpX
39  //
40 
45  virtual void Define ( WarpX* a_WarpX ) = 0;
46 
47  [[nodiscard]] bool IsDefined () const { return m_is_defined; }
48 
49  virtual void PrintParameters () const = 0;
50 
51  void GetParticleSolverParams (int& a_max_particle_iter,
52  amrex::ParticleReal& a_particle_tol ) const
53  {
54  a_max_particle_iter = m_max_particle_iterations;
55  a_particle_tol = m_particle_tolerance;
56  }
57 
61  virtual void OneStep ( amrex::Real a_time,
62  amrex::Real a_dt,
63  int a_step ) = 0;
64 
65  //
66  // the following routines are called by the linear and nonlinear solvers
67  //
68 
81  virtual void ComputeRHS ( WarpXSolverVec& a_RHS,
82  const WarpXSolverVec& a_E,
83  amrex::Real a_time,
84  amrex::Real a_dt,
85  int a_nl_iter,
86  bool a_from_jacobian ) = 0;
87 
88 protected:
89 
94 
95  bool m_is_defined = false;
96 
101  std::unique_ptr<NonlinearSolver<WarpXSolverVec,ImplicitSolver>> m_nlsolver;
102 
107  amrex::ParticleReal m_particle_tolerance = 1.0e-10;
108 
114 
119  {
120 
121  std::string nlsolver_type_str;
122  pp.get("nonlinear_solver", nlsolver_type_str);
123 
124  if (nlsolver_type_str=="picard") {
126  m_nlsolver = std::make_unique<PicardSolver<WarpXSolverVec,ImplicitSolver>>();
128  m_particle_tolerance = 0.0;
129  }
130  else if (nlsolver_type_str=="newton") {
132  m_nlsolver = std::make_unique<NewtonSolver<WarpXSolverVec,ImplicitSolver>>();
133  pp.query("max_particle_iterations", m_max_particle_iterations);
134  pp.query("particle_tolerance", m_particle_tolerance);
135  }
136  else {
138  "invalid nonlinear_solver specified. Valid options are picard and newton.");
139  }
140 
141  }
142 
143 };
144 
145 #endif
amrex::ParmParse pp
NonlinearSolverType
struct to select the nonlinear solver for implicit schemes
Definition: NonlinearSolverLibrary.H:10
@ Newton
Definition: NonlinearSolverLibrary.H:12
@ Picard
Definition: NonlinearSolverLibrary.H:11
#define WARPX_ABORT_WITH_MESSAGE(MSG)
Definition: TextMsg.H:15
Definition: ImplicitSolver.H:24
amrex::ParticleReal m_particle_tolerance
tolerance used by the iterative method used to obtain a self-consistent update of the particle positi...
Definition: ImplicitSolver.H:107
int m_max_particle_iterations
maximum iterations for the iterative method used to obtain a self-consistent update of the particle p...
Definition: ImplicitSolver.H:113
virtual void OneStep(amrex::Real a_time, amrex::Real a_dt, int a_step)=0
Advance fields and particles by one time step using the specified implicit algorithm.
ImplicitSolver & operator=(ImplicitSolver &&)=delete
bool m_is_defined
Definition: ImplicitSolver.H:95
void parseNonlinearSolverParams(const amrex::ParmParse &pp)
parse nonlinear solver parameters (if one is used)
Definition: ImplicitSolver.H:118
ImplicitSolver()=default
WarpX * m_WarpX
Pointer back to main WarpX class.
Definition: ImplicitSolver.H:93
NonlinearSolverType m_nlsolver_type
Nonlinear solver type and object.
Definition: ImplicitSolver.H:100
virtual void Define(WarpX *a_WarpX)=0
Read user-provided parameters that control the implicit solver. Allocate internal arrays for intermed...
void GetParticleSolverParams(int &a_max_particle_iter, amrex::ParticleReal &a_particle_tol) const
Definition: ImplicitSolver.H:51
bool IsDefined() const
Definition: ImplicitSolver.H:47
virtual void PrintParameters() const =0
ImplicitSolver(ImplicitSolver &&)=delete
ImplicitSolver(const ImplicitSolver &)=delete
virtual void ComputeRHS(WarpXSolverVec &a_RHS, const WarpXSolverVec &a_E, amrex::Real a_time, amrex::Real a_dt, int a_nl_iter, bool a_from_jacobian)=0
Computes the RHS of the equation corresponding to the specified implicit algorithm....
ImplicitSolver & operator=(const ImplicitSolver &)=delete
std::unique_ptr< NonlinearSolver< WarpXSolverVec, ImplicitSolver > > m_nlsolver
Definition: ImplicitSolver.H:101
virtual ~ImplicitSolver()=default
Definition: WarpX.H:85
This is a wrapper class around a Vector of array of pointers to MultiFabs that contains basic math op...
Definition: WarpXSolverVec.H:48
void get(const char *name, bool &ref, int ival=FIRST) const
int query(const char *name, bool &ref, int ival=FIRST) const