FDMGaussSeidelSolver2.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_GAUSS_SEIDEL_SOLVER2_HPP
12 #define CUBBYFLOW_FDM_GAUSS_SEIDEL_SOLVER2_HPP
13 
15 
16 namespace CubbyFlow
17 {
21 {
22  public:
24  FDMGaussSeidelSolver2(unsigned int maxNumberOfIterations,
25  unsigned int residualCheckInterval, double tolerance,
26  double sorFactor = 1.0,
27  bool useRedBlackOrdering = false);
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 
48  [[nodiscard]] double GetSORFactor() const;
49 
51  [[nodiscard]] bool GetUseRedBlackOrdering() const;
52 
54  static void Relax(const FDMMatrix2& A, const FDMVector2& b,
55  double sorFactor, FDMVector2* x);
56 
58  static void Relax(const MatrixCSRD& A, const VectorND& b, double sorFactor,
59  VectorND* x);
60 
62  static void RelaxRedBlack(const FDMMatrix2& A, const FDMVector2& b,
63  double sorFactor, FDMVector2* x);
64 
65  private:
66  void ClearUncompressedVectors();
67  void ClearCompressedVectors();
68 
69  // Uncompressed vectors
70  FDMVector2 m_residual;
71 
72  // Compressed vectors
73  VectorND m_residualComp;
74 
75  unsigned int m_maxNumberOfIterations;
76  unsigned int m_lastNumberOfIterations;
77  unsigned int m_residualCheckInterval;
78  double m_tolerance;
79  double m_lastResidual;
80  double m_sorFactor;
81  bool m_useRedBlackOrdering;
82 };
83 
85 using FDMGaussSeidelSolver2Ptr = std::shared_ptr<FDMGaussSeidelSolver2>;
86 } // namespace CubbyFlow
87 
88 #endif
Linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:40
double GetTolerance() const
Returns the max residual tolerance for the Gauss-Seidel method.
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Gauss-Seidel iterations.
bool GetUseRedBlackOrdering() const
Returns true if red-black ordering is enabled.
bool SolveCompressed(FDMCompressedLinearSystem2 *system) override
Solves the given compressed linear system.
static void RelaxRedBlack(const FDMMatrix2 &A, const FDMVector2 &b, double sorFactor, FDMVector2 *x)
Performs single Red-Black Gauss-Seidel relaxation step.
bool Solve(FDMLinearSystem2 *system) override
Solves the given linear system.
unsigned int GetLastNumberOfIterations() const
Returns the last number of Gauss-Seidel iterations the solver made.
double GetSORFactor() const
Returns the SOR (Successive Over Relaxation) factor.
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
static void Relax(const FDMMatrix2 &A, const FDMVector2 &b, double sorFactor, FDMVector2 *x)
Performs single natural Gauss-Seidel relaxation step.
Compressed linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:59
double GetLastResidual() const
Returns the last residual after the Gauss-Seidel iterations.
FDMGaussSeidelSolver2(unsigned int maxNumberOfIterations, unsigned int residualCheckInterval, double tolerance, double sorFactor=1.0, bool useRedBlackOrdering=false)
Constructs the solver with given parameters.
2-D finite difference-type linear system solver using Gauss-Seidel method.
Definition: FDMGaussSeidelSolver2.hpp:20
Abstract base class for 2-D finite difference-type linear system solver.
Definition: FDMLinearSystemSolver2.hpp:19
std::shared_ptr< FDMGaussSeidelSolver2 > FDMGaussSeidelSolver2Ptr
Shared pointer type for the FDMGaussSeidelSolver2.
Definition: FDMGaussSeidelSolver2.hpp:85