FDMGaussSeidelSolver3.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_SOLVER3_HPP
12 #define CUBBYFLOW_FDM_GAUSS_SEIDEL_SOLVER3_HPP
13 
15 
16 namespace CubbyFlow
17 {
21 {
22  public:
24  FDMGaussSeidelSolver3(unsigned int maxNumberOfIterations,
25  unsigned int residualCheckInterval, double tolerance,
26  double sorFactor = 1.0,
27  bool useRedBlackOrdering = false);
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 
48  [[nodiscard]] double GetSORFactor() const;
49 
51  [[nodiscard]] bool GetUseRedBlackOrdering() const;
52 
54  static void Relax(const FDMMatrix3& A, const FDMVector3& b,
55  double sorFactor, FDMVector3* x);
56 
58  static void Relax(const MatrixCSRD& A, const VectorND& b, double sorFactor,
59  VectorND* x);
60 
62  static void RelaxRedBlack(const FDMMatrix3& A, const FDMVector3& b,
63  double sorFactor, FDMVector3* x);
64 
65  private:
66  void ClearUncompressedVectors();
67  void ClearCompressedVectors();
68 
69  // Uncompressed vectors
70  FDMVector3 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 FDMGaussSeidelSolver3Ptr = std::shared_ptr<FDMGaussSeidelSolver3>;
86 } // namespace CubbyFlow
87 
88 #endif
Abstract base class for 3-D finite difference-type linear system solver.
Definition: FDMLinearSystemSolver3.hpp:19
double GetSORFactor() const
Returns the SOR (Successive Over Relaxation) factor.
std::shared_ptr< FDMGaussSeidelSolver3 > FDMGaussSeidelSolver3Ptr
Shared pointer type for the FDMGaussSeidelSolver3.
Definition: FDMGaussSeidelSolver3.hpp:85
unsigned int GetLastNumberOfIterations() const
Returns the last number of Gauss-Seidel iterations the solver made.
bool SolveCompressed(FDMCompressedLinearSystem3 *system) override
Solves the given compressed linear system.
FDMGaussSeidelSolver3(unsigned int maxNumberOfIterations, unsigned int residualCheckInterval, double tolerance, double sorFactor=1.0, bool useRedBlackOrdering=false)
Constructs the solver with given parameters.
static void Relax(const FDMMatrix3 &A, const FDMVector3 &b, double sorFactor, FDMVector3 *x)
Performs single natural Gauss-Seidel relaxation step.
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Gauss-Seidel iterations.
double GetLastResidual() const
Returns the last residual after the Gauss-Seidel iterations.
3-D finite difference-type linear system solver using Gauss-Seidel method.
Definition: FDMGaussSeidelSolver3.hpp:20
static void RelaxRedBlack(const FDMMatrix3 &A, const FDMVector3 &b, double sorFactor, FDMVector3 *x)
Performs single Red-Black Gauss-Seidel relaxation step.
Compressed linear system (Ax=b) for 3-D finite differencing.
Definition: FDMLinearSystem3.hpp:62
bool Solve(FDMLinearSystem3 *system) override
Solves the given linear system.
double GetTolerance() const
Returns the max residual tolerance for the Gauss-Seidel method.
bool GetUseRedBlackOrdering() const
Returns true if red-black ordering is enabled.
Linear system (Ax=b) for 3-D finite differencing.
Definition: FDMLinearSystem3.hpp:43