Jet  v1.3.3
mg.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_MG_H_
8 #define INCLUDE_JET_MG_H_
9 
10 #include <jet/blas.h>
11 
12 #include <functional>
13 #include <vector>
14 
15 namespace jet {
16 
18 template <typename BlasType>
19 struct MgMatrix {
20  std::vector<typename BlasType::MatrixType> levels;
21  const typename BlasType::MatrixType& operator[](size_t i) const;
22  typename BlasType::MatrixType& operator[](size_t i);
23  const typename BlasType::MatrixType& finest() const;
24  typename BlasType::MatrixType& finest();
25 };
26 
28 template <typename BlasType>
29 struct MgVector {
30  std::vector<typename BlasType::VectorType> levels;
31  const typename BlasType::VectorType& operator[](size_t i) const;
32  typename BlasType::VectorType& operator[](size_t i);
33  const typename BlasType::VectorType& finest() const;
34  typename BlasType::VectorType& finest();
35 };
36 
38 template <typename BlasType>
39 using MgRelaxFunc = std::function<void(
40  const typename BlasType::MatrixType& A,
41  const typename BlasType::VectorType& b, unsigned int numberOfIterations,
42  double maxTolerance, typename BlasType::VectorType* x,
43  typename BlasType::VectorType* buffer)>;
44 
46 template <typename BlasType>
48  std::function<void(const typename BlasType::VectorType& finer,
49  typename BlasType::VectorType* coarser)>;
50 
52 template <typename BlasType>
54  std::function<void(const typename BlasType::VectorType& coarser,
55  typename BlasType::VectorType* finer)>;
56 
58 template <typename BlasType>
59 struct MgParameters {
61  size_t maxNumberOfLevels = 1;
62 
64  unsigned int numberOfRestrictionIter = 5;
65 
67  unsigned int numberOfCorrectionIter = 5;
68 
70  unsigned int numberOfCoarsestIter = 20;
71 
73  unsigned int numberOfFinalIter = 20;
74 
77 
80 
83 
85  double maxTolerance = 1e-9;
86 };
87 
89 struct MgResult {
92 };
93 
100 template <typename BlasType>
103  MgVector<BlasType>* buffer);
104 } // namespace jet
105 
106 #include "detail/mg-inl.h"
107 
108 #endif // INCLUDE_JET_MG_H_
jet::MgParameters::relaxFunc
MgRelaxFunc< BlasType > relaxFunc
Relaxation function such as Jacobi or Gauss-Seidel.
Definition: mg.h:76
jet::MgResult
Multigrid result type.
Definition: mg.h:89
jet::MgMatrix::finest
const BlasType::MatrixType & finest() const
jet::MgParameters::maxTolerance
double maxTolerance
Max error tolerance.
Definition: mg.h:85
jet::MgRelaxFunc
std::function< void(const typename BlasType::MatrixType &A, const typename BlasType::VectorType &b, unsigned int numberOfIterations, double maxTolerance, typename BlasType::VectorType *x, typename BlasType::VectorType *buffer)> MgRelaxFunc
Multigrid relax function type.
Definition: mg.h:43
jet::MgResult::lastResidualNorm
double lastResidualNorm
Lastly measured norm of residual.
Definition: mg.h:91
jet::MgMatrix::levels
std::vector< typename BlasType::MatrixType > levels
Definition: mg.h:20
jet::MgMatrix::operator[]
const BlasType::MatrixType & operator[](size_t i) const
jet::MgParameters::correctFunc
MgCorrectFunc< BlasType > correctFunc
Correction function that maps coarser to finer grid.
Definition: mg.h:82
jet::mgVCycle
MgResult mgVCycle(const MgMatrix< BlasType > &A, MgParameters< BlasType > params, MgVector< BlasType > *x, MgVector< BlasType > *b, MgVector< BlasType > *buffer)
Performs Multigrid with V-cycle.
jet::MgMatrix::finest
BlasType::MatrixType & finest()
jet::MgVector::operator[]
BlasType::VectorType & operator[](size_t i)
jet
Definition: advection_solver2.h:18
jet::MgVector::finest
BlasType::VectorType & finest()
jet::MgParameters::numberOfFinalIter
unsigned int numberOfFinalIter
Number of iteration at final step.
Definition: mg.h:73
jet::MgParameters::maxNumberOfLevels
size_t maxNumberOfLevels
Max number of multigrid levels.
Definition: mg.h:61
jet::MgParameters::numberOfRestrictionIter
unsigned int numberOfRestrictionIter
Number of iteration at restriction step.
Definition: mg.h:64
jet::MgParameters::numberOfCoarsestIter
unsigned int numberOfCoarsestIter
Number of iteration at coarsest step.
Definition: mg.h:70
jet::MgMatrix
Multigrid matrix wrapper.
Definition: mg.h:19
blas.h
jet::MgParameters::restrictFunc
MgRestrictFunc< BlasType > restrictFunc
Restrict function that maps finer to coarser grid.
Definition: mg.h:79
jet::MgMatrix::operator[]
BlasType::MatrixType & operator[](size_t i)
jet::MgVector::levels
std::vector< typename BlasType::VectorType > levels
Definition: mg.h:30
jet::MgParameters
Multigrid input parameter set.
Definition: mg.h:59
jet::MgVector
Multigrid vector wrapper.
Definition: mg.h:29
jet::MgParameters::numberOfCorrectionIter
unsigned int numberOfCorrectionIter
Number of iteration at correction step.
Definition: mg.h:67
jet::MgRestrictFunc
std::function< void(const typename BlasType::VectorType &finer, typename BlasType::VectorType *coarser)> MgRestrictFunc
Multigrid restriction function type.
Definition: mg.h:49
jet::MgVector::operator[]
const BlasType::VectorType & operator[](size_t i) const
jet::MgVector::finest
const BlasType::VectorType & finest() const
jet::MgCorrectFunc
std::function< void(const typename BlasType::VectorType &coarser, typename BlasType::VectorType *finer)> MgCorrectFunc
Multigrid correction function type.
Definition: mg.h:55