MG.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_MULTI_GRID_HPP
12 #define CUBBYFLOW_MULTI_GRID_HPP
13 
14 #include <functional>
15 
16 namespace CubbyFlow
17 {
19 template <typename BlasType>
20 struct MGMatrix
21 {
22  std::vector<typename BlasType::MatrixType> levels;
23  const typename BlasType::MatrixType& operator[](size_t i) const;
24  typename BlasType::MatrixType& operator[](size_t i);
25  [[nodiscard]] const typename BlasType::MatrixType& Finest() const;
26  [[nodiscard]] typename BlasType::MatrixType& Finest();
27 };
28 
30 template <typename BlasType>
31 struct MGVector
32 {
33  std::vector<typename BlasType::VectorType> levels;
34  const typename BlasType::VectorType& operator[](size_t i) const;
35  typename BlasType::VectorType& operator[](size_t i);
36  [[nodiscard]] const typename BlasType::VectorType& Finest() const;
37  [[nodiscard]] typename BlasType::VectorType& Finest();
38 };
39 
41 template <typename BlasType>
42 using MGRelaxFunc = std::function<void(
43  const typename BlasType::MatrixType& A,
44  const typename BlasType::VectorType& b, unsigned int numberOfIterations,
45  double maxTolerance, typename BlasType::VectorType* x,
46  typename BlasType::VectorType* buffer)>;
47 
49 template <typename BlasType>
50 using MGRestrictFunc =
51  std::function<void(const typename BlasType::VectorType& finer,
52  typename BlasType::VectorType* coarser)>;
53 
55 template <typename BlasType>
56 using MGCorrectFunc =
57  std::function<void(const typename BlasType::VectorType& coarser,
58  typename BlasType::VectorType* finer)>;
59 
61 template <typename BlasType>
63 {
65  size_t maxNumberOfLevels = 1;
66 
68  unsigned int numberOfRestrictionIter = 5;
69 
71  unsigned int numberOfCorrectionIter = 5;
72 
74  unsigned int numberOfCoarsestIter = 20;
75 
77  unsigned int numberOfFinalIter = 20;
78 
81 
84 
87 
89  double maxTolerance = 1e-9;
90 };
91 
93 struct MGResult
94 {
97 };
98 
105 template <typename BlasType>
108  MGVector<BlasType>* buffer);
109 } // namespace CubbyFlow
110 
111 #include <Core/Utils/MG-Impl.hpp>
112 
113 #endif
std::vector< typename BlasType::VectorType > levels
Definition: MG.hpp:33
std::function< void(const typename BlasType::VectorType &finer, typename BlasType::VectorType *coarser)> MGRestrictFunc
Multi-grid restriction function type.
Definition: MG.hpp:52
std::vector< typename BlasType::MatrixType > levels
Definition: MG.hpp:22
MGResult MGVCycle(const MGMatrix< BlasType > &A, MGParameters< BlasType > params, MGVector< BlasType > *x, MGVector< BlasType > *b, MGVector< BlasType > *buffer)
Performs Multi-grid with V-cycle.
Definition: MG-Impl.hpp:131
MGRelaxFunc< BlasType > relaxFunc
Relaxation function such as Jacobi or Gauss-Seidel.
Definition: MG.hpp:80
const BlasType::MatrixType & Finest() const
Definition: MG-Impl.hpp:94
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.hpp:46
std::function< void(const typename BlasType::VectorType &coarser, typename BlasType::VectorType *finer)> MGCorrectFunc
Multi-grid correction function type.
Definition: MG.hpp:58
Multi-grid matrix wrapper.
Definition: MG.hpp:20
Multi-grid result type.
Definition: MG.hpp:93
Definition: pybind11Utils.hpp:20
double lastResidualNorm
Lastly measured norm of residual.
Definition: MG.hpp:96
Multi-grid vector wrapper.
Definition: MG.hpp:31
Multi-grid input parameter set.
Definition: MG.hpp:62
MGCorrectFunc< BlasType > correctFunc
Correction function that maps coarser to finer grid.
Definition: MG.hpp:86
const BlasType::MatrixType & operator[](size_t i) const
Definition: MG-Impl.hpp:81
MGRestrictFunc< BlasType > restrictFunc
Restrict function that maps finer to coarser grid.
Definition: MG.hpp:83