FDMMGPCGSolver3.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_SOLVER3_HPP
12 #define CUBBYFLOW_FDM_MGPCG_SOLVER3_HPP
13 
15 
16 namespace CubbyFlow
17 {
27 class FDMMGPCGSolver3 final : public FDMMGSolver3
28 {
29  public:
42  FDMMGPCGSolver3(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(FDMMGLinearSystem3* 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(FDMMGLinearSystem3* system, MGParameters<FDMBLAS3> mgParams);
69 
70  void Solve(const FDMVector3& b, FDMVector3* x) const;
71 
72  FDMMGLinearSystem3* system = nullptr;
73  MGParameters<FDMBLAS3> mgParams;
74  };
75 
76  unsigned int m_maxNumberOfIterations;
77  unsigned int m_lastNumberOfIterations;
78  double m_tolerance;
79  double m_lastResidualNorm;
80 
81  FDMVector3 m_r;
82  FDMVector3 m_d;
83  FDMVector3 m_q;
84  FDMVector3 m_s;
85  Preconditioner m_precond;
86 };
87 
89 using FDMMGPCGSolver3Ptr = std::shared_ptr<FDMMGPCGSolver3>;
90 } // namespace CubbyFlow
91 
92 #endif
double GetLastResidual() const
Returns the last residual after the Jacobi iterations.
FDMMGPCGSolver3(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)
3-D finite difference-type linear system solver using Multigrid.
Definition: FDMMGSolver3.hpp:21
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
std::shared_ptr< FDMMGPCGSolver3 > FDMMGPCGSolver3Ptr
Shared pointer type for the FDMMGPCGSolver3.
Definition: FDMMGPCGSolver3.hpp:89
bool Solve(FDMMGLinearSystem3 *system) override
Solves the given linear system.
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
unsigned int GetLastNumberOfIterations() const
Returns the last number of Jacobi iterations the solver made.
double GetTolerance() const
Returns the max residual tolerance for the Jacobi method.
Multi-grid input parameter set.
Definition: MG.hpp:62
Multigrid-syle 3-D linear system.
Definition: FDMMGLinearSystem3.hpp:26
3-D finite difference-type linear system solver using Multigrid Preconditioned conjugate gradient (MG...
Definition: FDMMGPCGSolver3.hpp:27