Loading...
Searching...
No Matches
FDMMGPCGSolver2.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_FDM_MGPCG_SOLVER2_HPP
12#define CUBBYFLOW_FDM_MGPCG_SOLVER2_HPP
13
15
16namespace CubbyFlow
17{
28{
29 public:
42 FDMMGPCGSolver2(unsigned int numberOfCGIter, size_t maxNumberOfLevels,
43 unsigned int numberOfRestrictionIter = 5,
44 unsigned int numberOfCorrectionIter = 5,
45 unsigned int numberOfCoarsestIter = 20,
46 unsigned int numberOfFinalIter = 20,
47 double maxTolerance = 1e-9, double sorFactor = 1.5,
48 bool useRedBlackOrdering = false);
49
51 bool Solve(FDMMGLinearSystem2* system) override;
52
54 [[nodiscard]] unsigned int GetMaxNumberOfIterations() const;
55
57 [[nodiscard]] unsigned int GetLastNumberOfIterations() const;
58
60 [[nodiscard]] double GetTolerance() const;
61
63 [[nodiscard]] double GetLastResidual() const;
64
65 private:
66 struct Preconditioner final
67 {
68 void Build(FDMMGLinearSystem2* system, MGParameters<FDMBLAS2> mgParams);
69
70 void Solve(const FDMVector2& b, FDMVector2* x) const;
71
72 FDMMGLinearSystem2* system = nullptr;
74 };
75
76 unsigned int m_maxNumberOfIterations;
77 unsigned int m_lastNumberOfIterations;
78 double m_tolerance;
79 double m_lastResidualNorm;
80
81 FDMVector2 m_r;
82 FDMVector2 m_d;
83 FDMVector2 m_q;
84 FDMVector2 m_s;
85 Preconditioner m_precond;
86};
87
89using FDMMGPCGSolver2Ptr = std::shared_ptr<FDMMGPCGSolver2>;
90} // namespace CubbyFlow
91
92#endif
2-D finite difference-type linear system solver using Multigrid Preconditioned conjugate gradient (MG...
Definition FDMMGPCGSolver2.hpp:28
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
double GetLastResidual() const
Returns the last residual after the Jacobi iterations.
unsigned int GetLastNumberOfIterations() const
Returns the last number of Jacobi iterations the solver made.
FDMMGPCGSolver2(unsigned int numberOfCGIter, size_t maxNumberOfLevels, unsigned int numberOfRestrictionIter=5, unsigned int numberOfCorrectionIter=5, unsigned int numberOfCoarsestIter=20, unsigned int numberOfFinalIter=20, double maxTolerance=1e-9, double sorFactor=1.5, bool useRedBlackOrdering=false)
double GetTolerance() const
Returns the max residual tolerance for the Jacobi method.
bool Solve(FDMMGLinearSystem2 *system) override
Solves the given linear system.
2-D finite difference-type linear system solver using Multigrid.
Definition FDMMGSolver2.hpp:22
Definition Matrix.hpp:30
Definition pybind11Utils.hpp:21
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
std::shared_ptr< FDMMGPCGSolver2 > FDMMGPCGSolver2Ptr
Shared pointer type for the FDMMGPCGSolver2.
Definition FDMMGPCGSolver2.hpp:89
Multigrid-syle 2-D linear system.
Definition FDMMGLinearSystem2.hpp:27