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
85 Real m_residualScale = 1.0;
86
90 KrylovGMRES() noexcept = default;
91
95 ~KrylovGMRES() noexcept;
96
102 void
103 define(AMRMultigridKrylovOp<T>* a_op, const Vector<LevelData<T>*>& a_template) noexcept;
104
108 void
109 undefine() noexcept;
110
115 bool
116 isDefined() const noexcept;
117
124 bool
125 solve(Vector<LevelData<T>*>& a_phi, const Vector<LevelData<T>*>& a_rhs) noexcept;
126
127protected:
132
136 bool m_isDefined = false;
137
142
146 Vector<Vector<LevelData<T>*>> m_basis;
147
151 Vector<LevelData<T>*> m_w;
152
156 Vector<LevelData<T>*> m_z;
157
161 Vector<LevelData<T>*> m_c;
162
166 Vector<LevelData<T>*> m_r;
167
171 Vector<Real> m_H;
172
176 Vector<Real> m_cs;
177
181 Vector<Real> m_sn;
182
186 Vector<Real> m_g;
187
191 Vector<Real> m_y;
192
196 Vector<Real> m_hcol;
197
201 Vector<Real> m_corr;
202};
203
204#include <CD_NamespaceFooter.H>
205
206#include <CD_KrylovGMRESImplem.H>
207
208#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:136
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:156
Vector< Real > m_corr
Persistent scratch for the reorthogonalization correction row (size m_allocRestart).
Definition CD_KrylovGMRES.H:201
Vector< Real > m_cs
Givens cosines.
Definition CD_KrylovGMRES.H:176
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:146
AMRMultigridKrylovOp< T > * m_op
Operator/adapter (not owned).
Definition CD_KrylovGMRES.H:131
Real m_eps
Relative residual tolerance (against the initial residual norm).
Definition CD_KrylovGMRES.H:43
int m_allocRestart
Restart length the persistent storage was sized for.
Definition CD_KrylovGMRES.H:141
Vector< Real > m_g
Rotated residual right-hand side.
Definition CD_KrylovGMRES.H:186
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:181
Vector< Real > m_H
Hessenberg matrix, column-major, leading dimension m_allocRestart + 1.
Definition CD_KrylovGMRES.H:171
Vector< LevelData< T > * > m_c
Accumulated unpreconditioned solution update (sum y_k v_k).
Definition CD_KrylovGMRES.H:161
Vector< Real > m_hcol
Persistent scratch for one Gram-Schmidt projection row (size m_allocRestart).
Definition CD_KrylovGMRES.H:196
Vector< Real > m_y
Least-squares solution.
Definition CD_KrylovGMRES.H:191
Vector< LevelData< T > * > m_r
Residual.
Definition CD_KrylovGMRES.H:166
int m_maxIter
Maximum number of iterations (total Arnoldi steps across restart cycles).
Definition CD_KrylovGMRES.H:48
Real m_residualScale
Display normalization for printed residuals (set to the zero-residual by the driver; 1 = print absolu...
Definition CD_KrylovGMRES.H:85
Vector< LevelData< T > * > m_w
A*K^{-1}*v_j scratch.
Definition CD_KrylovGMRES.H:151
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