WarpX
Loading...
Searching...
No Matches
ImplicitSolver.H
Go to the documentation of this file.
1/* Copyright 2024 Justin Angus, Debojyoti Ghosh
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
11
14
15#include <AMReX_Array.H>
16#include <AMReX_REAL.H>
17#include <AMReX_LO_BCTYPES.H>
18
24
25class WarpX;
26enum class FieldBoundaryType;
28{
29public:
30
31 ImplicitSolver() = default;
32
33 virtual ~ImplicitSolver() = default;
34
35 // Prohibit Move and Copy operations
40
41 //
42 // the following routines are called by WarpX
43 //
44
49 virtual void Define ( WarpX* a_WarpX ) = 0;
50
51 [[nodiscard]] bool IsDefined () const { return m_is_defined; }
52
53 virtual void PrintParameters () const = 0;
54
55 void CreateParticleAttributes () const;
56
58
62 virtual void OneStep ( amrex::Real a_time,
63 amrex::Real a_dt,
64 int a_step ) = 0;
65
66 //
67 // the following routines are called by the linear and nonlinear solvers
68 //
69
82 virtual void ComputeRHS ( WarpXSolverVec& a_RHS,
83 const WarpXSolverVec& a_E,
84 amrex::Real a_time,
85 int a_nl_iter,
86 bool a_from_jacobian ) = 0;
87
88 [[nodiscard]] int numAMRLevels () const { return m_num_amr_levels; }
89
90 [[nodiscard]] const amrex::Geometry& GetGeometry (int) const;
95
101 else { return nullptr; }
102 }
103
104 // This parameter is used for the time-step fraction in the PC for implicit
105 // treatment of light waves in the curl-curl MLMG solver.
106 // This function should return zero if light waves are not treated implicitly
107 [[nodiscard]] virtual amrex::Real GetThetaForPC () const = 0;
108
109 void ComputeJfromMassMatrices (const bool a_J_from_MM_only);
110
111protected:
112
117
118 bool m_is_defined = false;
119
124
128 mutable amrex::Real m_dt = 0.0;
129
133 amrex::Real m_theta = 0.5;
134
139 std::unique_ptr<NonlinearSolver<WarpXSolverVec,ImplicitSolver>> m_nlsolver;
140
145 amrex::ParticleReal m_particle_tolerance = amrex::ParticleReal(1.0e-10);
146
152
158
164
169
174
179
184
197
202
207
212
214
218 void PreRHSOp ( const amrex::Real a_cur_time,
219 const int a_nl_iter,
220 const bool a_from_jacobian );
221
226
230 void SetMassMatricesForPC ( const amrex::Real a_theta_dt );
231
235 void CumulateJ ();
236
240 void SaveE ();
241
246
247};
248
249#endif
amrex::ParmParse pp
NonlinearSolverType
struct to select the nonlinear solver for implicit schemes
Definition NonlinearSolverLibrary.H:15
FieldBoundaryType
Definition WarpXAlgorithmSelection.H:138
const amrex::Array< FieldBoundaryType, 3 > & GetFieldBoundaryLo() const
Definition ImplicitSolver.cpp:43
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:145
amrex::IntVect m_ncomp_zz
Definition ImplicitSolver.H:196
amrex::Real m_theta
Time-biasing parameter for fields used on RHS to advance system.
Definition ImplicitSolver.H:133
bool m_print_unconverged_particle_details
whether the details of unconverged particles are printed out during the particle evolve loops
Definition ImplicitSolver.H:163
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:151
amrex::Real m_dt
Time step.
Definition ImplicitSolver.H:128
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.
bool m_use_mass_matrices_pc
Whether to use mass matrices in the preconditioner.
Definition ImplicitSolver.H:183
virtual amrex::Real GetThetaForPC() const =0
bool m_use_mass_matrices_jacobian
Whether to use mass matrices to compute J during linear stage of JFNK.
Definition ImplicitSolver.H:178
void PrintBaseImplicitSolverParameters() const
Definition ImplicitSolver.cpp:842
amrex::IntVect m_ncomp_zx
Definition ImplicitSolver.H:194
bool m_is_defined
Definition ImplicitSolver.H:118
amrex::Vector< amrex::Array< amrex::MultiFab *, 3 > > m_mmpc_mfarrvec
Array of multifab pointers to mass matrix preconditioner.
Definition ImplicitSolver.H:201
void CreateParticleAttributes() const
Definition ImplicitSolver.cpp:10
void ComputeJfromMassMatrices(const bool a_J_from_MM_only)
Definition ImplicitSolver.cpp:139
void parseNonlinearSolverParams(const amrex::ParmParse &pp)
parse nonlinear solver parameters (if one is used)
Definition ImplicitSolver.cpp:443
amrex::IntVect m_ncomp_yy
Definition ImplicitSolver.H:192
ImplicitSolver()=default
int m_num_amr_levels
Number of AMR levels.
Definition ImplicitSolver.H:123
bool m_use_mass_matrices
Whether to use mass matrices for the implicit solver.
Definition ImplicitSolver.H:173
void SetMassMatricesForPC(const amrex::Real a_theta_dt)
Scale mass matrices used for PC by c^2*mu0*theta*dt and add 1 to diagonal terms.
Definition ImplicitSolver.cpp:820
WarpX * m_WarpX
Pointer back to main WarpX class.
Definition ImplicitSolver.H:116
amrex::Array< amrex::LinOpBCType, 3 > GetLinOpBCHi() const
Definition ImplicitSolver.cpp:58
amrex::Array< amrex::LinOpBCType, 3 > convertFieldBCToLinOpBC(const amrex::Array< FieldBoundaryType, 3 > &) const
Convert from WarpX FieldBoundaryType to amrex::LinOpBCType.
Definition ImplicitSolver.cpp:63
void SyncMassMatricesPCAndApplyBCs()
Communicate Mass Matrices used for PC and apply boundary conditions.
Definition ImplicitSolver.cpp:785
amrex::IntVect m_ncomp_zy
Definition ImplicitSolver.H:195
ImplicitSolver & operator=(ImplicitSolver &&)=delete
NonlinearSolverType m_nlsolver_type
Nonlinear solver type and object.
Definition ImplicitSolver.H:138
amrex::IntVect m_ncomp_xy
Definition ImplicitSolver.H:189
void InitializeMassMatrices()
Initialize the Mass Matrices used for plasma response in nonlinear Newton solver.
Definition ImplicitSolver.cpp:510
amrex::IntVect m_ncomp_xz
Definition ImplicitSolver.H:190
void SaveE()
Save E at start of each Newton step.
Definition ImplicitSolver.cpp:123
virtual void Define(WarpX *a_WarpX)=0
Read user-provided parameters that control the implicit solver. Allocate internal arrays for intermed...
void PreRHSOp(const amrex::Real a_cur_time, const int a_nl_iter, const bool a_from_jacobian)
Perform operations needed before computing the Right Hand Side.
Definition ImplicitSolver.cpp:719
const amrex::Array< FieldBoundaryType, 3 > & GetFieldBoundaryHi() const
Definition ImplicitSolver.cpp:48
amrex::IntVect m_ncomp_yx
Definition ImplicitSolver.H:191
amrex::IntVect m_ncomp_xx
Direction-dependent component number of mass matrices elements.
Definition ImplicitSolver.H:188
bool IsDefined() const
Definition ImplicitSolver.H:51
bool m_skip_particle_picard_init
whether to skip the full Picard update of particles on the initial newton step
Definition ImplicitSolver.H:168
bool m_particle_suborbits
whether to use suborbits for particles that fail to converge in m_max_particle_iterations iterations
Definition ImplicitSolver.H:157
virtual void PrintParameters() const =0
bool DoParticleSuborbits()
Definition ImplicitSolver.H:57
ImplicitSolver(ImplicitSolver &&)=delete
virtual void ComputeRHS(WarpXSolverVec &a_RHS, const WarpXSolverVec &a_E, amrex::Real a_time, int a_nl_iter, bool a_from_jacobian)=0
Computes the RHS of the equation corresponding to the specified implicit algorithm....
ImplicitSolver(const ImplicitSolver &)=delete
const amrex::Vector< amrex::Array< amrex::MultiFab *, 3 > > * GetMassMatricesCoeff() const
Return pointer to MultiFab array for mass matrix.
Definition ImplicitSolver.H:99
amrex::IntVect m_ncomp_yz
Definition ImplicitSolver.H:193
amrex::Array< amrex::LinOpBCType, 3 > GetLinOpBCLo() const
Definition ImplicitSolver.cpp:53
void CumulateJ()
Add J from particles included in mass matrices at start of each Newton step.
Definition ImplicitSolver.cpp:100
ImplicitSolver & operator=(const ImplicitSolver &)=delete
int numAMRLevels() const
Definition ImplicitSolver.H:88
std::unique_ptr< NonlinearSolver< WarpXSolverVec, ImplicitSolver > > m_nlsolver
Definition ImplicitSolver.H:139
const amrex::Geometry & GetGeometry(int) const
Definition ImplicitSolver.cpp:37
virtual ~ImplicitSolver()=default
Definition WarpX.H:85
This is a wrapper class around a Vector of pointers to MultiFabs that contains basic math operators a...
Definition WarpXSolverVec.H:58
IntVectND< 3 > IntVect
std::array< T, N > Array