MG.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: MultiGrid.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Multi-grid wrapper functions for CubbyFlow.
6 > Created Time: 2017/09/26
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_MULTI_GRID_H
10 #define CUBBYFLOW_MULTI_GRID_H
11 
12 #include <functional>
13 
14 namespace CubbyFlow
15 {
17  template <typename BlasType>
18  struct MGMatrix
19  {
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  {
31  std::vector<typename BlasType::VectorType> levels;
32  const typename BlasType::VectorType& operator[](size_t i) const;
33  typename BlasType::VectorType& operator[](size_t i);
34  const typename BlasType::VectorType& Finest() const;
35  typename BlasType::VectorType& Finest();
36  };
37 
39  template <typename BlasType>
40  using MGRelaxFunc = std::function<void(
41  const typename BlasType::MatrixType& A,
42  const typename BlasType::VectorType& b, unsigned int numberOfIterations,
43  double maxTolerance, typename BlasType::VectorType* x,
44  typename BlasType::VectorType* buffer)>;
45 
47  template <typename BlasType>
48  using MGRestrictFunc = std::function<void(
49  const typename BlasType::VectorType& finer,
50  typename BlasType::VectorType* coarser)>;
51 
53  template <typename BlasType>
54  using MGCorrectFunc = std::function<void(
55  const typename BlasType::VectorType& coarser,
56  typename BlasType::VectorType* finer)>;
57 
59  template <typename BlasType>
60  struct MGParameters
61  {
63  size_t maxNumberOfLevels = 1;
64 
66  unsigned int numberOfRestrictionIter = 5;
67 
69  unsigned int numberOfCorrectionIter = 5;
70 
72  unsigned int numberOfCoarsestIter = 20;
73 
75  unsigned int numberOfFinalIter = 20;
76 
79 
82 
85 
87  double maxTolerance = 1e-9;
88  };
89 
91  struct MGResult
92  {
95  };
96 
103  template <typename BlasType>
107  MGVector<BlasType>* buffer);
108 }
109 
110 #include <Core/Utils/MG-Impl.h>
111 
112 #endif
unsigned int numberOfRestrictionIter
Number of iteration at restriction step.
Definition: MG.h:66
std::vector< typename BlasType::VectorType > levels
Definition: MG.h:31
size_t maxNumberOfLevels
Max number of multi-grid levels.
Definition: MG.h:63
std::vector< typename BlasType::MatrixType > levels
Definition: MG.h:20
MGRelaxFunc< BlasType > relaxFunc
Relaxation function such as Jacobi or Gauss-Seidel.
Definition: MG.h:78
const BlasType::VectorType & Finest() const
Definition: MG-Impl.h:113
const BlasType::VectorType & operator[](size_t i) const
Definition: MG-Impl.h:101
const BlasType::MatrixType & Finest() const
Definition: MG-Impl.h:89
std::function< void(const typename BlasType::VectorType &finer, typename BlasType::VectorType *coarser)> MGRestrictFunc
Multi-grid restriction function type.
Definition: MG.h:50
std::function< void(const typename BlasType::VectorType &coarser, typename BlasType::VectorType *finer)> MGCorrectFunc
Multi-grid correction function type.
Definition: MG.h:56
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
Multi-grid relax function type.
Definition: MG.h:44
Multi-grid matrix wrapper.
Definition: MG.h:18
unsigned int numberOfCoarsestIter
Number of iteration at coarsest step.
Definition: MG.h:72
double maxTolerance
Max error tolerance.
Definition: MG.h:87
Multi-grid result type.
Definition: MG.h:91
MGResult MGCycle(const MGMatrix< BlasType > &A, MGParameters< BlasType > params, MGVector< BlasType > *x, MGVector< BlasType > *b, MGVector< BlasType > *buffer)
Performs Multi-grid with V-cycle.
unsigned int numberOfFinalIter
Number of iteration at final step.
Definition: MG.h:75
Definition: pybind11Utils.h:24
unsigned int numberOfCorrectionIter
Number of iteration at correction step.
Definition: MG.h:69
double lastResidualNorm
Lastly measured norm of residual.
Definition: MG.h:94
Multi-grid vector wrapper.
Definition: MG.h:29
Multi-grid input parameter set.
Definition: MG.h:60
MGCorrectFunc< BlasType > correctFunc
Correction function that maps coarser to finer grid.
Definition: MG.h:84
const BlasType::MatrixType & operator[](size_t i) const
Definition: MG-Impl.h:77
MGRestrictFunc< BlasType > restrictFunc
Restrict function that maps finer to coarser grid.
Definition: MG.h:81