FDMICCGSolver3.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_SOLVER3_HPP
12 #define CUBBYFLOW_FDM_ICCG_SOLVER3_HPP
13 
14 #include <Core/Array/ArrayView.hpp>
16 
17 namespace CubbyFlow
18 {
24 {
25  public:
27  FDMICCGSolver3(unsigned int maxNumberOfIterations, double tolerance);
28 
30  bool Solve(FDMLinearSystem3* system) override;
31 
33  bool SolveCompressed(FDMCompressedLinearSystem3* 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 FDMMatrix3& matrix);
51 
52  void Solve(const FDMVector3& b, FDMVector3* x);
53 
55  FDMVector3 d;
56  FDMVector3 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  FDMVector3 m_r;
75  FDMVector3 m_d;
76  FDMVector3 m_q;
77  FDMVector3 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 FDMICCGSolver3Ptr = std::shared_ptr<FDMICCGSolver3>;
95 } // namespace CubbyFlow
96 
97 #endif
Abstract base class for 3-D finite difference-type linear system solver.
Definition: FDMLinearSystemSolver3.hpp:19
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
3-D finite difference-type linear system solver using incomplete Cholesky conjugate gradient (ICCG)...
Definition: FDMICCGSolver3.hpp:23
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.
double GetTolerance() const
Returns the max residual tolerance for the Jacobi method.
FDMICCGSolver3(unsigned int maxNumberOfIterations, double tolerance)
Constructs the solver with given parameters.
std::shared_ptr< FDMICCGSolver3 > FDMICCGSolver3Ptr
Shared pointer type for the FDMICCGSolver3.
Definition: FDMICCGSolver3.hpp:94
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
bool SolveCompressed(FDMCompressedLinearSystem3 *system) override
Solves the given compressed linear system.
bool Solve(FDMLinearSystem3 *system) override
Solves the given linear system.
Generic N-dimensional array class interface.
Definition: Array.hpp:32
Compressed linear system (Ax=b) for 3-D finite differencing.
Definition: FDMLinearSystem3.hpp:62
Linear system (Ax=b) for 3-D finite differencing.
Definition: FDMLinearSystem3.hpp:43