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
10#include "ImplicitSolver_fwd.H"
11
13
16
17#include <AMReX_Array.H>
18#include <AMReX_INT.H>
19#include <AMReX_REAL.H>
20#include <AMReX_LO_BCTYPES.H>
21
22#include <map>
23#include <string>
24
30
31class WarpX;
32enum class FieldBoundaryType;
34{
35public:
36
37 ImplicitSolver() = default;
38
39 virtual ~ImplicitSolver() = default;
40
41 // Prohibit Move and Copy operations
46
47 //
48 // the following routines are called by WarpX
49 //
50
55 virtual void Define (WarpX* a_WarpX, bool from_restart) = 0;
56
57 [[nodiscard]] bool IsDefined () const { return m_is_defined; }
58
59 virtual void PrintParameters () const = 0;
60
61 void CreateParticleAttributes () const;
62
63 bool DoParticleSuborbits () const { return m_particle_suborbits; }
64
68 virtual int OneStep (amrex::Real a_time,
69 amrex::Real a_dt,
70 int a_step) = 0;
71
72 //
73 // the following routines are called by the linear and nonlinear solvers
74 //
75
88 virtual void ComputeRHS ( WarpXSolverVec& a_RHS,
89 const WarpXSolverVec& a_E,
90 amrex::Real a_time,
91 int a_nl_iter,
92 bool a_from_jacobian ) = 0;
93
97 void PreLinearSolve ();
98
99 [[nodiscard]] int numAMRLevels () const { return m_num_amr_levels; }
100
101 [[nodiscard]] const amrex::Geometry& GetGeometry (int) const;
106
112 else { return nullptr; }
113 }
114
118 [[nodiscard]] virtual const amrex::MultiFab* GetCurl2BCmask (const int lev, const int dir) const
119 {
120 amrex::ignore_unused(lev,dir);
121 return nullptr;
122 }
123
128 int GetMassMatricesPCnComp (const int field_dir, const int space_dir) const
129 {
130 if (field_dir == 0) { return m_ncomp_pc_xx[space_dir]; }
131 else if (field_dir == 1) { return m_ncomp_pc_yy[space_dir]; }
132 else if (field_dir == 2) { return m_ncomp_pc_zz[space_dir]; }
133 else { return -1; }
134 }
135
136 // This parameter is used for the time-step fraction in the PC for implicit
137 // treatment of light waves in the curl-curl MLMG solver.
138 // This function should return zero if light waves are not treated implicitly
139 [[nodiscard]] virtual amrex::Real GetThetaForPC () const = 0;
140
151 void ApplyMassMatrices (
154 const ablastr::fields::MultiLevelVectorField* a_in_ref = nullptr,
155 const ablastr::fields::MultiLevelVectorField* a_baseline = nullptr,
156 amrex::Real a_scale = 1.0,
157 bool a_zero_out_first = false );
158
159 void ComputeJfromMassMatrices (bool a_J_from_MM_only);
160
164 void FinishMassMatrices ();
165
169 void FinishImplicitParticleUpdate (amrex::Real time, int step);
170
171protected:
172
177
178 bool m_is_defined = false;
179
184
188 mutable amrex::Real m_dt = 0.0;
189
194
199 std::unique_ptr<NonlinearSolver<WarpXSolverVec,ImplicitSolver>> m_nlsolver;
200
206
212
218
221 std::map<std::string, amrex::Long> m_accumulated_suborbit_counts;
223
225 std::map<std::string, amrex::Long> const& local_suborbit_counts,
226 int step);
227
233
238
243
248
253
258
271
279
284
289
290 void SaveEoldMultifab ();
291
296
298
302 void PreRHSOp ( amrex::Real a_cur_time,
303 int a_nl_iter,
304 bool a_from_jacobian );
305
310
314 void SetMassMatricesForPC ( amrex::Real a_theta_dt );
315
319 void CumulateJ ();
320
324 void SaveE ();
325
330
331};
332
333#endif
amrex::ParmParse pp
NonlinearSolverType
struct to select the nonlinear solver for implicit schemes
Definition NonlinearSolverLibrary.H:17
FieldBoundaryType
Definition WarpXAlgorithmSelection.H:128
const amrex::Array< FieldBoundaryType, 3 > & GetFieldBoundaryLo() const
Definition ImplicitSolver.cpp:131
std::map< std::string, amrex::Long > m_accumulated_suborbit_counts
Definition ImplicitSolver.H:221
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:205
amrex::IntVect m_ncomp_zz
Definition ImplicitSolver.H:270
amrex::Real m_theta
Time-biasing parameter for fields used on RHS to advance system.
Definition ImplicitSolver.H:193
bool m_print_unconverged_particle_details
whether the details of unconverged particles are printed out during the particle evolve loops
Definition ImplicitSolver.H:232
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:211
amrex::Array< amrex::LinOpBCType, 3 > convertFieldBCToLinOpBC(const amrex::Array< FieldBoundaryType, 3 > &, int bdry_side) const
Convert from WarpX FieldBoundaryType to amrex::LinOpBCType.
Definition ImplicitSolver.cpp:151
amrex::Real m_dt
Time step.
Definition ImplicitSolver.H:188
bool m_use_mass_matrices_pc
Whether to use mass matrices in the preconditioner.
Definition ImplicitSolver.H:252
virtual amrex::Real GetThetaForPC() const =0
amrex::IntVect m_ncomp_pc_xx
Direction-dependent component number of mass matrices elements used for the preconditioner.
Definition ImplicitSolver.H:276
bool m_use_mass_matrices_jacobian
Whether to use mass matrices to compute J during linear stage of JFNK.
Definition ImplicitSolver.H:247
void PrintBaseImplicitSolverParameters() const
Definition ImplicitSolver.cpp:1307
virtual int 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.
amrex::IntVect m_ncomp_zx
Definition ImplicitSolver.H:268
bool m_is_defined
Definition ImplicitSolver.H:178
amrex::Vector< amrex::Array< amrex::MultiFab *, 3 > > m_mmpc_mfarrvec
Array of multifab pointers to mass matrix preconditioner.
Definition ImplicitSolver.H:283
void CreateParticleAttributes() const
Definition ImplicitSolver.cpp:98
void parseNonlinearSolverParams(const amrex::ParmParse &pp)
parse nonlinear solver parameters (if one is used)
Definition ImplicitSolver.cpp:592
virtual const amrex::MultiFab * GetCurl2BCmask(const int lev, const int dir) const
Return reference to the multifabs for curl curl mask.
Definition ImplicitSolver.H:118
amrex::IntVect m_ncomp_yy
Definition ImplicitSolver.H:266
ImplicitSolver()=default
void ApplyMassMatrices(ablastr::fields::MultiLevelVectorField &a_out, const ablastr::fields::MultiLevelVectorField &a_in, const ablastr::fields::MultiLevelVectorField *a_in_ref=nullptr, const ablastr::fields::MultiLevelVectorField *a_baseline=nullptr, amrex::Real a_scale=1.0, bool a_zero_out_first=false)
Apply deposited mass matrices to a vector field. Computes a_out += a_scale * S * (a_in - a_in_ref) [+...
Definition ImplicitSolver.cpp:232
int m_num_amr_levels
Number of AMR levels.
Definition ImplicitSolver.H:183
bool m_use_mass_matrices
Whether to use mass matrices for the implicit solver.
Definition ImplicitSolver.H:242
WarpX * m_WarpX
Pointer back to main WarpX class.
Definition ImplicitSolver.H:176
amrex::Array< amrex::LinOpBCType, 3 > GetLinOpBCHi() const
Definition ImplicitSolver.cpp:146
bool DoParticleSuborbits() const
Definition ImplicitSolver.H:63
int m_suborbit_statistics_interval
Definition ImplicitSolver.H:220
int GetMassMatricesPCnComp(const int field_dir, const int space_dir) const
Return the space_dir number of components for the mass matrices used in the preconditioner for field ...
Definition ImplicitSolver.H:128
void SyncMassMatricesPCAndApplyBCs()
Communicate Mass Matrices used for PC and apply boundary conditions.
Definition ImplicitSolver.cpp:1005
amrex::IntVect m_ncomp_pc_yy
Definition ImplicitSolver.H:277
amrex::IntVect m_ncomp_zy
Definition ImplicitSolver.H:269
ImplicitSolver & operator=(ImplicitSolver &&)=delete
void PreRHSOp(amrex::Real a_cur_time, int a_nl_iter, bool a_from_jacobian)
Perform operations needed before computing the Right Hand Side.
Definition ImplicitSolver.cpp:932
void PreLinearSolve()
Definition ImplicitSolver.cpp:909
NonlinearSolverType m_nlsolver_type
Nonlinear solver type and object.
Definition ImplicitSolver.H:198
amrex::IntVect m_ncomp_xy
Definition ImplicitSolver.H:263
void SaveEoldMultifab()
Definition ImplicitSolver.cpp:668
void InitializeMassMatrices()
Initialize the Mass Matrices used for plasma response in nonlinear Newton solver.
Definition ImplicitSolver.cpp:681
amrex::IntVect m_ncomp_xz
Definition ImplicitSolver.H:264
void SaveE()
Save E at start of each Newton step.
Definition ImplicitSolver.cpp:216
void AccumulateSuborbitStatistics(std::map< std::string, amrex::Long > const &local_suborbit_counts, int step)
Definition ImplicitSolver.cpp:58
void ComputeJfromMassMatrices(bool a_J_from_MM_only)
Definition ImplicitSolver.cpp:566
int m_mass_matrices_pc_width
Width for mass matrices in the preconditioner.
Definition ImplicitSolver.H:257
int m_suborbit_statistics_start_step
Definition ImplicitSolver.H:222
const amrex::Array< FieldBoundaryType, 3 > & GetFieldBoundaryHi() const
Definition ImplicitSolver.cpp:136
amrex::IntVect m_ncomp_yx
Definition ImplicitSolver.H:265
amrex::IntVect m_ncomp_xx
Direction-dependent component number of mass matrices elements.
Definition ImplicitSolver.H:262
bool IsDefined() const
Definition ImplicitSolver.H:57
bool m_skip_particle_picard_init
whether to skip the full Picard update of particles on the initial newton step
Definition ImplicitSolver.H:237
bool m_particle_suborbits
whether to use suborbits for particles that fail to converge in m_max_particle_iterations iterations
Definition ImplicitSolver.H:217
virtual void PrintParameters() const =0
ImplicitSolver(ImplicitSolver &&)=delete
virtual void Define(WarpX *a_WarpX, bool from_restart)=0
Read user-provided parameters that control the implicit solver. Allocate internal arrays for intermed...
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:110
void FinishMassMatrices()
Finish filling the mass matrices after deposit.
Definition ImplicitSolver.cpp:1115
amrex::IntVect m_ncomp_yz
Definition ImplicitSolver.H:267
void FinishImplicitParticleUpdate(amrex::Real time, int step)
Finish the implicit particle update after the converged time-centered solve.
Definition ImplicitSolver.cpp:17
amrex::Array< amrex::LinOpBCType, 3 > GetLinOpBCLo() const
Definition ImplicitSolver.cpp:141
void CumulateJ()
Add J from particles included in mass matrices at start of each Newton step.
Definition ImplicitSolver.cpp:193
ImplicitSolver & operator=(const ImplicitSolver &)=delete
int numAMRLevels() const
Definition ImplicitSolver.H:99
std::unique_ptr< NonlinearSolver< WarpXSolverVec, ImplicitSolver > > m_nlsolver
Definition ImplicitSolver.H:199
void SetMassMatricesForPC(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:1081
int m_suborbit_warning_threshold
Definition ImplicitSolver.H:219
amrex::IntVect m_ncomp_pc_zz
Definition ImplicitSolver.H:278
const amrex::Geometry & GetGeometry(int) const
Definition ImplicitSolver.cpp:125
virtual ~ImplicitSolver()=default
Definition WarpX.H:88
This is a wrapper class around a Vector of pointers to MultiFabs that contains basic math operators a...
Definition WarpXSolverVec.H:56
amrex_real Real
amrex_particle_real ParticleReal
std::array< T, N > Array
amrex::Vector< VectorField > MultiLevelVectorField
Definition MultiFabRegister.H:218
__host__ __device__ void ignore_unused(const Ts &...)
IntVectND< 3 > IntVect