Loading...
Searching...
No Matches
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
16namespace CubbyFlow
17{
19template <typename BlasType>
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
30template <typename BlasType>
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
41template <typename BlasType>
42using 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
49template <typename BlasType>
51 std::function<void(const typename BlasType::VectorType& finer,
52 typename BlasType::VectorType* coarser)>;
53
55template <typename BlasType>
57 std::function<void(const typename BlasType::VectorType& coarser,
58 typename BlasType::VectorType* finer)>;
59
61template <typename BlasType>
91
94{
97};
98
105template <typename BlasType>
109} // namespace CubbyFlow
110
111#include <Core/Utils/MG-Impl.hpp>
112
113#endif
Definition Matrix.hpp:30
Definition pybind11Utils.hpp:21
std::function< void(const typename BlasType::VectorType &finer, typename BlasType::VectorType *coarser)> MGRestrictFunc
Multi-grid restriction function type.
Definition MG.hpp:52
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
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
std::function< void(const typename BlasType::VectorType &coarser, typename BlasType::VectorType *finer)> MGCorrectFunc
Multi-grid correction function type.
Definition MG.hpp:58
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
Multi-grid matrix wrapper.
Definition MG.hpp:21
std::vector< typename BlasType::MatrixType > levels
Definition MG.hpp:22
const BlasType::MatrixType & Finest() const
Definition MG-Impl.hpp:94
const BlasType::MatrixType & operator[](size_t i) const
Definition MG-Impl.hpp:81
Multi-grid input parameter set.
Definition MG.hpp:63
unsigned int numberOfCorrectionIter
Number of iteration at correction step.
Definition MG.hpp:71
double maxTolerance
Max error tolerance.
Definition MG.hpp:89
unsigned int numberOfCoarsestIter
Number of iteration at coarsest step.
Definition MG.hpp:74
size_t maxNumberOfLevels
Max number of multi-grid levels.
Definition MG.hpp:65
unsigned int numberOfFinalIter
Number of iteration at final step.
Definition MG.hpp:77
MGRestrictFunc< BlasType > restrictFunc
Restrict function that maps finer to coarser grid.
Definition MG.hpp:83
MGRelaxFunc< BlasType > relaxFunc
Relaxation function such as Jacobi or Gauss-Seidel.
Definition MG.hpp:80
MGCorrectFunc< BlasType > correctFunc
Correction function that maps coarser to finer grid.
Definition MG.hpp:86
unsigned int numberOfRestrictionIter
Number of iteration at restriction step.
Definition MG.hpp:68
Multi-grid result type.
Definition MG.hpp:94
double lastResidualNorm
Lastly measured norm of residual.
Definition MG.hpp:96
Multi-grid vector wrapper.
Definition MG.hpp:32
const BlasType::VectorType & operator[](size_t i) const
Definition MG-Impl.hpp:106
const BlasType::VectorType & Finest() const
Definition MG-Impl.hpp:119
std::vector< typename BlasType::VectorType > levels
Definition MG.hpp:33