FDMCGSolver3.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_CG_SOLVER3_HPP
12 #define CUBBYFLOW_FDM_CG_SOLVER3_HPP
13 
15 
16 namespace CubbyFlow
17 {
21 {
22  public:
24  FDMCGSolver3(unsigned int maxNumberOfIterations, double tolerance);
25 
27  bool Solve(FDMLinearSystem3* system) override;
28 
30  bool SolveCompressed(FDMCompressedLinearSystem3* system) override;
31 
33  [[nodiscard]] unsigned int GetMaxNumberOfIterations() const;
34 
36  [[nodiscard]] unsigned int GetLastNumberOfIterations() const;
37 
39  [[nodiscard]] double GetTolerance() const;
40 
42  [[nodiscard]] double GetLastResidual() const;
43 
44  private:
45  void ClearUncompressedVectors();
46  void ClearCompressedVectors();
47 
48  // Uncompressed vectors
49  FDMVector3 m_r;
50  FDMVector3 m_d;
51  FDMVector3 m_q;
52  FDMVector3 m_s;
53 
54  // Compressed vectors
55  VectorND m_rComp;
56  VectorND m_dComp;
57  VectorND m_qComp;
58  VectorND m_sComp;
59 
60  unsigned int m_maxNumberOfIterations;
61  unsigned int m_lastNumberOfIterations;
62  double m_tolerance;
63  double m_lastResidual;
64 };
65 
67 using FDMCGSolver3Ptr = std::shared_ptr<FDMCGSolver3>;
68 } // namespace CubbyFlow
69 
70 #endif
bool Solve(FDMLinearSystem3 *system) override
Solves the given linear system.
Abstract base class for 3-D finite difference-type linear system solver.
Definition: FDMLinearSystemSolver3.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.
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
std::shared_ptr< FDMCGSolver3 > FDMCGSolver3Ptr
Shared pointer type for the FDMCGSolver3.
Definition: FDMCGSolver3.hpp:67
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
FDMCGSolver3(unsigned int maxNumberOfIterations, double tolerance)
Constructs the solver with given parameters.
double GetLastResidual() const
Returns the last residual after the Jacobi iterations.
bool SolveCompressed(FDMCompressedLinearSystem3 *system) override
Solves the given compressed linear system.
Compressed linear system (Ax=b) for 3-D finite differencing.
Definition: FDMLinearSystem3.hpp:62
3-D finite difference-type linear system solver using conjugate gradient.
Definition: FDMCGSolver3.hpp:20
Linear system (Ax=b) for 3-D finite differencing.
Definition: FDMLinearSystem3.hpp:43