chombo-discharge
Loading...
Searching...
No Matches
CD_KrylovGMRES.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
13#ifndef CD_KRYLOVGMRES_H
14#define CD_KRYLOVGMRES_H
15
16// Chombo includes
17#include <LevelData.H>
18#include <Vector.H>
19
20// Our includes
22#include <CD_NamespaceHeader.H>
23
36template <class T>
38{
39public:
43 Real m_eps = 1.E-10;
44
48 int m_maxIter = 50;
49
53 int m_restart = 30;
54
58 bool m_reorthogonalize = true;
59
63 int m_verbosity = -1;
64
68 int m_exitStatus = -1;
69
73 Real m_residualNorm = -1.0;
74
78 int m_iterations = 0;
79
90 Real m_residualScale = 0.0;
91
95 KrylovGMRES() noexcept = default;
96
100 ~KrylovGMRES() noexcept;
101
107 void
108 define(AMRMultigridKrylovOp<T>* a_op, const Vector<LevelData<T>*>& a_template) noexcept;
109
113 void
114 undefine() noexcept;
115
120 bool
121 isDefined() const noexcept;
122
129 bool
130 solve(Vector<LevelData<T>*>& a_phi, const Vector<LevelData<T>*>& a_rhs) noexcept;
131
132protected:
137
141 bool m_isDefined = false;
142
147
151 Vector<Vector<LevelData<T>*>> m_basis;
152
156 Vector<LevelData<T>*> m_w;
157
161 Vector<LevelData<T>*> m_z;
162
166 Vector<LevelData<T>*> m_c;
167
171 Vector<LevelData<T>*> m_r;
172
176 Vector<Real> m_H;
177
181 Vector<Real> m_cs;
182
186 Vector<Real> m_sn;
187
191 Vector<Real> m_g;
192
196 Vector<Real> m_y;
197
201 Vector<Real> m_hcol;
202
206 Vector<Real> m_corr;
207};
208
209#include <CD_NamespaceFooter.H>
210
211#include <CD_KrylovGMRESImplem.H>
212
213#endif
Linear-operator adapter that exposes an AMR-multigrid cycle as a Krylov preconditioner.
Implementation of CD_KrylovGMRES.H.
Adapter presenting an already-defined AMRMultiGrid as a LinearOp over the AMR hierarchy.
Definition CD_AMRMultigridKrylovOp.H:78
Restarted GMRES(m) acting on an AMR hierarchy through AMRMultigridKrylovOp.
Definition CD_KrylovGMRES.H:38
KrylovGMRES() noexcept=default
Default constructor. Call define() before use.
bool m_isDefined
Whether the basis/scratch are allocated.
Definition CD_KrylovGMRES.H:141
int m_verbosity
Verbosity; at >= 4 a terse one-line-per-iteration residual history is printed.
Definition CD_KrylovGMRES.H:63
Vector< LevelData< T > * > m_z
K^{-1}*v_j and final preconditioned-update scratch.
Definition CD_KrylovGMRES.H:161
Vector< Real > m_corr
Persistent scratch for the reorthogonalization correction row (size m_allocRestart).
Definition CD_KrylovGMRES.H:206
Vector< Real > m_cs
Givens cosines.
Definition CD_KrylovGMRES.H:181
int m_restart
Restart length m in GMRES(m). Must be set before define() (sizes the persistent basis).
Definition CD_KrylovGMRES.H:53
bool isDefined() const noexcept
Whether define() has been called.
Definition CD_KrylovGMRESImplem.H:87
int m_exitStatus
Exit status after solve(): 1 = converged, 3 = max iterations, -1 = not run.
Definition CD_KrylovGMRES.H:68
Real m_residualNorm
Final residual norm after solve() (in the adapter inner-product norm).
Definition CD_KrylovGMRES.H:73
Vector< Vector< LevelData< T > * > > m_basis
Arnoldi basis, size m_allocRestart + 1.
Definition CD_KrylovGMRES.H:151
AMRMultigridKrylovOp< T > * m_op
Operator/adapter (not owned).
Definition CD_KrylovGMRES.H:136
Real m_eps
Relative residual tolerance, measured against m_residualScale.
Definition CD_KrylovGMRES.H:43
int m_allocRestart
Restart length the persistent storage was sized for.
Definition CD_KrylovGMRES.H:146
Vector< Real > m_g
Rotated residual right-hand side.
Definition CD_KrylovGMRES.H:191
void define(AMRMultigridKrylovOp< T > *a_op, const Vector< LevelData< T > * > &a_template) noexcept
Allocate the persistent basis (m_restart + 1 vectors) and scratch. Call once per regrid.
Definition CD_KrylovGMRESImplem.H:36
bool solve(Vector< LevelData< T > * > &a_phi, const Vector< LevelData< T > * > &a_rhs) noexcept
Solve a_op(a_phi) = a_rhs (homogeneous operator) with restarted GMRES(m_restart).
Definition CD_KrylovGMRESImplem.H:94
Vector< Real > m_sn
Givens sines.
Definition CD_KrylovGMRES.H:186
Vector< Real > m_H
Hessenberg matrix, column-major, leading dimension m_allocRestart + 1.
Definition CD_KrylovGMRES.H:176
Vector< LevelData< T > * > m_c
Accumulated unpreconditioned solution update (sum y_k v_k).
Definition CD_KrylovGMRES.H:166
Vector< Real > m_hcol
Persistent scratch for one Gram-Schmidt projection row (size m_allocRestart).
Definition CD_KrylovGMRES.H:201
Vector< Real > m_y
Least-squares solution.
Definition CD_KrylovGMRES.H:196
Vector< LevelData< T > * > m_r
Residual.
Definition CD_KrylovGMRES.H:171
int m_maxIter
Maximum number of iterations (total Arnoldi steps across restart cycles).
Definition CD_KrylovGMRES.H:48
Real m_residualScale
Norm that both the printed residual and the convergence test are measured against.
Definition CD_KrylovGMRES.H:90
Vector< LevelData< T > * > m_w
A*K^{-1}*v_j scratch.
Definition CD_KrylovGMRES.H:156
bool m_reorthogonalize
Whether to do one classical Gram-Schmidt reorthogonalization pass (robustness; on by default).
Definition CD_KrylovGMRES.H:58
int m_iterations
Number of Arnoldi iterations performed by the last solve().
Definition CD_KrylovGMRES.H:78
void undefine() noexcept
Free the persistent basis and scratch.
Definition CD_KrylovGMRESImplem.H:67