Block-Structured AMR Software Framework
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
AMReX_GMRES_MV.H
Go to the documentation of this file.
1#ifndef AMREX_GMRES_MV_H_
2#define AMREX_GMRES_MV_H_
3
4#include <AMReX_GMRES.H>
5#include <AMReX_Algebra.H>
6#include <AMReX_Smoother_MV.H>
7#include <functional>
8
9namespace amrex {
10
11template <typename T>
13{
14public:
15 using RT = Real; // double or float
19 using PC = std::function<void(VEC&,VEC const&)>;
20
21 GMRES_MV (MAT const* a_mat);
22
23 void setPrecond (PC a_pc) { m_pc = std::move(a_pc); }
24
33 void solve (VEC& a_sol, VEC const& a_rhs, T a_tol_rel, T a_tol_abs);
34
36 void setVerbose (int v) { m_gmres.setVerbose(v); }
37
39 GM& getGMRES () { return m_gmres; }
40
42 [[nodiscard]] VEC makeVecRHS () const;
43
45 [[nodiscard]] VEC makeVecLHS () const;
46
47 static T norm2 (VEC const& vec);
48
49 static void scale (VEC& vec, T scale_factor);
50
51 static T dotProduct (VEC const& vec1, VEC const& vec2);
52
54 static void setToZero (VEC& lhs);
55
57 static void assign (VEC& lhs, VEC const& rhs);
58
60 static void increment (VEC& lhs, VEC const& rhs, T a);
61
63 static void linComb (VEC& lhs, T a, VEC const& rhs_a, T b, VEC const& rhs_b);
64
66 void apply (VEC& lhs, VEC& rhs) const;
67
68 void precond (VEC& lhs, VEC const& rhs) const;
69
70private:
72 MAT const* m_mat = nullptr;
74};
75
76template <typename T>
78 : m_mat(a_mat)
79{
80 m_gmres.define(*this);
81}
82
83template <typename T>
84void GMRES_MV<T>::solve (VEC& a_sol, VEC const& a_rhs, T a_tol_rel, T a_tol_abs)
85{
86 m_gmres.solve(a_sol, a_rhs, a_tol_rel, a_tol_abs);
87}
88
89template <typename T>
91{
92 return VEC(m_mat->partition());
93}
94
95template <typename T>
97{
98 return VEC(m_mat->partition());
99}
100
101template <typename T>
103{
104 return vec.norm2();
105}
106
107template <typename T>
108void GMRES_MV<T>::scale (VEC& vec, T scale_factor)
109{
110 vec.scaleAsync(scale_factor);
111}
112
113template <typename T>
114T GMRES_MV<T>::dotProduct (VEC const& vec1, VEC const& vec2)
115{
116 return amrex::Dot(vec1,vec2);
117}
118
119template <typename T>
121{
122 lhs.setValAsync(0);
123}
124
125template <typename T>
126void GMRES_MV<T>::assign (VEC& lhs, VEC const& rhs)
127{
128 lhs.copyAsync(rhs);
129}
130
131template <typename T>
132void GMRES_MV<T>::increment (VEC& lhs, VEC const& rhs, T a)
133{
134 amrex::Axpy(lhs, a, rhs, true);
135}
136
137template <typename T>
138void GMRES_MV<T>::linComb (VEC& lhs, T a, VEC const& rhs_a, T b, VEC const& rhs_b)
139{
140 amrex::LinComb(lhs, a, rhs_a, b, rhs_b, true);
141}
142
143template <typename T>
144void GMRES_MV<T>::apply (VEC& lhs, VEC& rhs) const
145{
146 amrex::SpMV(lhs, *m_mat, rhs);
147}
148
149template <typename T>
150void GMRES_MV<T>::precond (VEC& lhs, VEC const& rhs) const
151{
152 if (m_pc) {
153 m_pc(lhs, rhs);
154 } else {
155 lhs.copyAsync(rhs);
156 }
157}
158
159}
160#endif
Definition AMReX_AlgVector.H:19
void setValAsync(T val)
Definition AMReX_AlgVector.H:153
T norm2(bool local=false) const
Definition AMReX_AlgVector.H:244
void scaleAsync(T scale_factor)
Definition AMReX_AlgVector.H:206
void copyAsync(AlgVector< T > const &rhs)
Definition AMReX_AlgVector.H:168
Definition AMReX_GMRES_MV.H:13
GM & getGMRES()
Get the GMRES object.
Definition AMReX_GMRES_MV.H:39
static void assign(VEC &lhs, VEC const &rhs)
lhs = rhs
Definition AMReX_GMRES_MV.H:126
PC m_pc
Definition AMReX_GMRES_MV.H:73
std::function< void(VEC &, VEC const &)> PC
Definition AMReX_GMRES_MV.H:19
static T norm2(VEC const &vec)
Definition AMReX_GMRES_MV.H:102
void setVerbose(int v)
Sets verbosity.
Definition AMReX_GMRES_MV.H:36
VEC makeVecLHS() const
Make MultiFab with ghost cells and set ghost cells to zero.
Definition AMReX_GMRES_MV.H:96
AlgVector< T > VEC
Definition AMReX_GMRES_MV.H:16
void apply(VEC &lhs, VEC &rhs) const
lhs = L(rhs)
Definition AMReX_GMRES_MV.H:144
static void scale(VEC &vec, T scale_factor)
Definition AMReX_GMRES_MV.H:108
void solve(VEC &a_sol, VEC const &a_rhs, T a_tol_rel, T a_tol_abs)
Solve the linear system.
Definition AMReX_GMRES_MV.H:84
static void linComb(VEC &lhs, T a, VEC const &rhs_a, T b, VEC const &rhs_b)
lhs = a*rhs_a + b*rhs_b
Definition AMReX_GMRES_MV.H:138
Real RT
Definition AMReX_GMRES_MV.H:15
static void setToZero(VEC &lhs)
lhs = 0
Definition AMReX_GMRES_MV.H:120
static void increment(VEC &lhs, VEC const &rhs, T a)
lhs += a*rhs
Definition AMReX_GMRES_MV.H:132
void precond(VEC &lhs, VEC const &rhs) const
Definition AMReX_GMRES_MV.H:150
GM m_gmres
Definition AMReX_GMRES_MV.H:71
GMRES_MV(MAT const *a_mat)
Definition AMReX_GMRES_MV.H:77
static T dotProduct(VEC const &vec1, VEC const &vec2)
Definition AMReX_GMRES_MV.H:114
MAT const * m_mat
Definition AMReX_GMRES_MV.H:72
VEC makeVecRHS() const
Make MultiFab without ghost cells.
Definition AMReX_GMRES_MV.H:90
void setPrecond(PC a_pc)
Definition AMReX_GMRES_MV.H:23
void define(M &linop)
Definition AMReX_GMRES.H:187
void setVerbose(int v)
Sets verbosity.
Definition AMReX_GMRES.H:104
Definition AMReX_SpMatrix.H:19
Definition AMReX_Amr.cpp:49
void SpMV(AlgVector< T > &y, SpMatrix< T > const &A, AlgVector< T > const &x)
Definition AMReX_SpMV.H:20
void Axpy(AlgVector< T > &y, T a, AlgVector< T > const &x, bool async=false)
Definition AMReX_AlgVector.H:436
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:1863
FAB::value_type Dot(FabArray< FAB > const &x, int xcomp, FabArray< FAB > const &y, int ycomp, int ncomp, IntVect const &nghost, bool local=false)
Compute dot products of two FabArrays.
Definition AMReX_FabArrayUtility.H:1554