Loading...
Searching...
No Matches
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
16
17namespace CubbyFlow
18{
24{
25 public:
27 FDMICCGSolver2(unsigned int maxNumberOfIterations, double tolerance);
28
30 bool Solve(FDMLinearSystem2* system) override;
31
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
94using FDMICCGSolver2Ptr = std::shared_ptr<FDMICCGSolver2>;
95} // namespace CubbyFlow
96
97#endif
2-D finite difference-type linear system solver using incomplete Cholesky conjugate gradient (ICCG).
Definition FDMICCGSolver2.hpp:24
double GetLastResidual() const
Returns the last residual after the Jacobi iterations.
bool Solve(FDMLinearSystem2 *system) override
Solves the given linear system.
double GetTolerance() const
Returns the max residual tolerance for the Jacobi method.
FDMICCGSolver2(unsigned int maxNumberOfIterations, double tolerance)
Constructs the solver with given parameters.
unsigned int GetLastNumberOfIterations() const
Returns the last number of Jacobi iterations the solver made.
bool SolveCompressed(FDMCompressedLinearSystem2 *system) override
Solves the given compressed linear system.
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
Abstract base class for 2-D finite difference-type linear system solver.
Definition FDMLinearSystemSolver2.hpp:20
Definition Matrix.hpp:30
Definition pybind11Utils.hpp:21
std::shared_ptr< FDMICCGSolver2 > FDMICCGSolver2Ptr
Shared pointer type for the FDMICCGSolver2.
Definition FDMICCGSolver2.hpp:94
VectorN< double > VectorND
Definition Matrix.hpp:832
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
Array2< double > FDMVector2
Vector type for 2-D finite differencing.
Definition FDMLinearSystem2.hpp:34
Compressed linear system (Ax=b) for 2-D finite differencing.
Definition FDMLinearSystem2.hpp:60
Linear system (Ax=b) for 2-D finite differencing.
Definition FDMLinearSystem2.hpp:41