FDMICCGSolver2.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_ICCG_SOLVER2_HPP
12 #define CUBBYFLOW_FDM_ICCG_SOLVER2_HPP
13 
14 #include <Core/Array/ArrayView.hpp>
16 
17 namespace CubbyFlow
18 {
24 {
25  public:
27  FDMICCGSolver2(unsigned int maxNumberOfIterations, double tolerance);
28 
30  bool Solve(FDMLinearSystem2* system) override;
31 
33  bool SolveCompressed(FDMCompressedLinearSystem2* system) override;
34 
36  [[nodiscard]] unsigned int GetMaxNumberOfIterations() const;
37 
39  [[nodiscard]] unsigned int GetLastNumberOfIterations() const;
40 
42  [[nodiscard]] double GetTolerance() const;
43 
45  [[nodiscard]] double GetLastResidual() const;
46 
47  private:
48  struct Preconditioner final
49  {
50  void Build(const FDMMatrix2& matrix);
51 
52  void Solve(const FDMVector2& b, FDMVector2* x);
53 
55  FDMVector2 d;
56  FDMVector2 y;
57  };
58 
59  struct PreconditionerCompressed final
60  {
61  void Build(const MatrixCSRD& matrix);
62 
63  void Solve(const VectorND& b, VectorND* x);
64 
65  const MatrixCSRD* A = nullptr;
66  VectorND d;
67  VectorND y;
68  };
69 
70  void ClearUncompressedVectors();
71  void ClearCompressedVectors();
72 
73  // Uncompressed vectors and preconditioner
74  FDMVector2 m_r;
75  FDMVector2 m_d;
76  FDMVector2 m_q;
77  FDMVector2 m_s;
78  Preconditioner m_precond;
79 
80  // Compressed vectors and preconditioner
81  VectorND m_rComp;
82  VectorND m_dComp;
83  VectorND m_qComp;
84  VectorND m_sComp;
85  PreconditionerCompressed m_precondComp;
86 
87  unsigned int m_maxNumberOfIterations;
88  unsigned int m_lastNumberOfIterations;
89  double m_tolerance;
90  double m_lastResidualNorm;
91 };
92 
94 using FDMICCGSolver2Ptr = std::shared_ptr<FDMICCGSolver2>;
95 } // namespace CubbyFlow
96 
97 #endif
Linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:40
double GetTolerance() const
Returns the max residual tolerance for the Jacobi method.
bool Solve(FDMLinearSystem2 *system) override
Solves the given linear system.
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
FDMICCGSolver2(unsigned int maxNumberOfIterations, double tolerance)
Constructs the solver with given parameters.
Definition: pybind11Utils.hpp:20
bool SolveCompressed(FDMCompressedLinearSystem2 *system) override
Solves the given compressed linear system.
Definition: Array-Impl.hpp:19
2-D finite difference-type linear system solver using incomplete Cholesky conjugate gradient (ICCG)...
Definition: FDMICCGSolver2.hpp:23
Compressed linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:59
Generic N-dimensional array class interface.
Definition: Array.hpp:32
std::shared_ptr< FDMICCGSolver2 > FDMICCGSolver2Ptr
Shared pointer type for the FDMICCGSolver2.
Definition: FDMICCGSolver2.hpp:94
double GetLastResidual() const
Returns the last residual after the Jacobi iterations.
Abstract base class for 2-D finite difference-type linear system solver.
Definition: FDMLinearSystemSolver2.hpp:19
unsigned int GetLastNumberOfIterations() const
Returns the last number of Jacobi iterations the solver made.