1 #ifndef AMREX_GMRES_MLMG_H_
2 #define AMREX_GMRES_MLMG_H_
3 #include <AMReX_Config.H>
18 template <
typename MF>
36 void solve (MF& a_sol, MF
const& a_rhs,
RT a_tol_rel,
RT a_tol_abs);
73 static void scale (MF& mf,
RT scale_factor);
81 static void assign (MF& lhs, MF
const& rhs);
84 static void increment (MF& lhs, MF
const& rhs,
RT a);
87 static void linComb (MF& lhs,
RT a, MF
const& rhs_a,
RT b, MF
const& rhs_b);
90 void apply (MF& lhs, MF
const& rhs)
const;
92 void precond (MF& lhs, MF
const& rhs)
const;
109 template <
typename MF>
111 : m_mlmg(&mlmg), m_linop(&mlmg.getLinOp())
114 "Only support single level solve");
121 template <
typename MF>
124 return m_linop->make(0, 0,
IntVect(0));
127 template <
typename MF>
130 auto mf = m_linop->make(0, 0,
IntVect(1));
135 template <
typename MF>
138 auto r = m_linop->xdoty(0, 0, mf, mf,
false);
142 template <
typename MF>
148 template <
typename MF>
151 return m_linop->xdoty(0, 0, mf1, mf2,
false);
154 template <
typename MF>
160 template <
typename MF>
166 template <
typename MF>
172 template <
typename MF>
178 template <
typename MF>
181 m_linop->apply(0, 0, lhs,
const_cast<MF&
>(rhs),
186 template <
typename MF>
190 m_mlmg->prepareMGcycle();
192 for (
int icycle = 0; icycle < m_precond_niters; ++icycle) {
196 m_mlmg->computeResOfCorrection(0,0);
200 m_mlmg->mgVcycle(0,0);
205 increment(lhs, m_mlmg->cor[0][0],
RT(1));
213 template <
typename MF>
217 auto rhs = makeVecRHS();
219 m_linop->setDirichletNodesToZero(0,0,rhs);
220 m_gmres.solve(a_sol, rhs, a_tol_rel, a_tol_abs);
222 auto res = makeVecRHS();
223 m_mlmg->apply({&res}, {&a_sol});
224 increment(res, a_rhs,
RT(-1));
225 auto cor = makeVecLHS();
226 m_linop->setDirichletNodesToZero(0,0,res);
227 m_gmres.solve(cor, res, a_tol_rel, a_tol_abs);
228 increment(a_sol, cor,
RT(-1));
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition: AMReX_BLassert.H:49
Solve using GMRES with multigrid as preconditioner.
Definition: AMReX_GMRES_MLMG.H:20
void solve(MF &a_sol, MF const &a_rhs, RT a_tol_rel, RT a_tol_abs)
Solve the linear system.
Definition: AMReX_GMRES_MLMG.H:214
MF makeVecRHS() const
Make MultiFab without ghost cells.
Definition: AMReX_GMRES_MLMG.H:122
int m_precond_niters
Definition: AMReX_GMRES_MLMG.H:106
GMRESMLMGT(MG &mlmg)
Definition: AMReX_GMRES_MLMG.H:110
GM m_gmres
Definition: AMReX_GMRES_MLMG.H:101
static void increment(MF &lhs, MF const &rhs, RT a)
lhs += a*rhs
Definition: AMReX_GMRES_MLMG.H:167
int getNumIters() const
Gets the number of iterations.
Definition: AMReX_GMRES_MLMG.H:45
RT dotProduct(MF const &mf1, MF const &mf2) const
Definition: AMReX_GMRES_MLMG.H:149
static void assign(MF &lhs, MF const &rhs)
lhs = rhs
Definition: AMReX_GMRES_MLMG.H:161
void setPrecondNumIters(int precond_niters)
Set the number of MLMG preconditioner iterations per GMRES iteration.
Definition: AMReX_GMRES_MLMG.H:98
GM & getGMRES()
Get the GMRES object.
Definition: AMReX_GMRES_MLMG.H:51
void setVerbose(int v)
Sets verbosity.
Definition: AMReX_GMRES_MLMG.H:39
void setPropertyOfZero(bool b)
Set MLMG's multiplicative property of zero.
Definition: AMReX_GMRES_MLMG.H:63
typename MG::RT RT
Definition: AMReX_GMRES_MLMG.H:23
void apply(MF &lhs, MF const &rhs) const
lhs = L(rhs)
Definition: AMReX_GMRES_MLMG.H:179
static void linComb(MF &lhs, RT a, MF const &rhs_a, RT b, MF const &rhs_b)
lhs = a*rhs_a + b*rhs_b
Definition: AMReX_GMRES_MLMG.H:173
MF makeVecLHS() const
Make MultiFab with ghost cells and set ghost cells to zero.
Definition: AMReX_GMRES_MLMG.H:128
static void setToZero(MF &lhs)
lhs = 0
Definition: AMReX_GMRES_MLMG.H:155
MLLinOpT< MF > * m_linop
Definition: AMReX_GMRES_MLMG.H:103
bool m_use_precond
Definition: AMReX_GMRES_MLMG.H:104
static void scale(MF &mf, RT scale_factor)
Definition: AMReX_GMRES_MLMG.H:143
MG * m_mlmg
Definition: AMReX_GMRES_MLMG.H:102
RT norm2(MF const &mf) const
Definition: AMReX_GMRES_MLMG.H:136
RT getResidualNorm() const
Gets the 2-norm of the residual.
Definition: AMReX_GMRES_MLMG.H:48
bool usePrecond(bool new_flag)
Control whether or not to use MLMG as preconditioner.
Definition: AMReX_GMRES_MLMG.H:95
bool m_prop_zero
Definition: AMReX_GMRES_MLMG.H:105
void setMaxIters(int niters)
Sets the max number of iterations.
Definition: AMReX_GMRES_MLMG.H:42
void precond(MF &lhs, MF const &rhs) const
Definition: AMReX_GMRES_MLMG.H:187
int getNumIters() const
Gets the number of iterations.
Definition: AMReX_GMRES.H:113
void define(M &linop)
Definition: AMReX_GMRES.H:187
void setVerbose(int v)
Sets verbosity.
Definition: AMReX_GMRES.H:104
void setMaxIters(int niters)
Sets the max number of iterations.
Definition: AMReX_GMRES.H:110
RT getResidualNorm() const
Gets the 2-norm of the residual.
Definition: AMReX_GMRES.H:119
Definition: AMReX_MLLinOp.H:98
Definition: AMReX_MLMG.H:12
void setBottomVerbose(int v) noexcept
Definition: AMReX_MLMG.H:129
void setVerbose(int v) noexcept
Definition: AMReX_MLMG.H:117
typename MLLinOpT< MF >::RT RT
Definition: AMReX_MLMG.H:27
void prepareForGMRES()
Definition: AMReX_MLMG.H:1132
Definition: AMReX_Amr.cpp:49
int nComp(FabArrayBase const &fa)
void Saxpy(MF &dst, typename MF::value_type a, MF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst += a * src
Definition: AMReX_FabArrayUtility.H:1646
void LocalCopy(DMF &dst, SMF const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
dst = src
Definition: AMReX_FabArrayUtility.H:1630
IntVectND< AMREX_SPACEDIM > IntVect
Definition: AMReX_BaseFwd.H:30
void LinComb(MF &dst, typename MF::value_type a, MF const &src_a, int acomp, typename MF::value_type b, MF const &src_b, int bcomp, int dcomp, int ncomp, IntVect const &nghost)
dst = a*src_a + b*src_b
Definition: AMReX_FabArrayUtility.H:1662
void setBndry(MF &dst, typename MF::value_type val, int scomp, int ncomp)
dst = val in ghost cells.
Definition: AMReX_FabArrayUtility.H:1614
void Scale(MF &dst, typename MF::value_type val, int scomp, int ncomp, int nghost)
dst *= val
Definition: AMReX_FabArrayUtility.H:1621
void setVal(MF &dst, typename MF::value_type val)
dst = val
Definition: AMReX_FabArrayUtility.H:1607
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition: AMReX_GpuComplex.H:373