FDMGaussSeidelSolver2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: FDMGaussSeidelSolver2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D finite difference-type linear system solver using Gauss-Seidel method.
6 > Created Time: 2017/08/17
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_FDM_GAUSS_SEIDEL_SOLVER2_H
10 #define CUBBYFLOW_FDM_GAUSS_SEIDEL_SOLVER2_H
11 
13 
14 namespace CubbyFlow
15 {
18  {
19  public:
22  unsigned int maxNumberOfIterations,
23  unsigned int residualCheckInterval,
24  double tolerance,
25  double sorFactor = 1.0,
26  bool useRedBlackOrdering = false);
27 
29  bool Solve(FDMLinearSystem2* system) override;
30 
32  bool SolveCompressed(FDMCompressedLinearSystem2* system) override;
33 
35  unsigned int GetMaxNumberOfIterations() const;
36 
38  unsigned int GetLastNumberOfIterations() const;
39 
41  double GetTolerance() const;
42 
44  double GetLastResidual() const;
45 
47  double GetSORFactor() const;
48 
50  bool GetUseRedBlackOrdering() const;
51 
53  static void Relax(const FDMMatrix2& A, const FDMVector2& b, double sorFactor, FDMVector2* x);
54 
56  static void Relax(const MatrixCSRD& A, const VectorND& b, double sorFactor, VectorND* x);
57 
59  static void RelaxRedBlack(const FDMMatrix2& A, const FDMVector2& b, double sorFactor, FDMVector2* x);
60 
61  private:
62  unsigned int m_maxNumberOfIterations;
63  unsigned int m_lastNumberOfIterations;
64  unsigned int m_residualCheckInterval;
65  double m_tolerance;
66  double m_lastResidual;
67  double m_sorFactor;
68  double m_useRedBlackOrdering;
69 
70  // Uncompressed vectors
71  FDMVector2 m_residual;
72 
73  // Compressed vectors
74  VectorND m_residualComp;
75 
76  void ClearUncompressedVectors();
77  void ClearCompressedVectors();
78  };
79 
81  using FDMGaussSeidelSolver2Ptr = std::shared_ptr<FDMGaussSeidelSolver2>;
82 }
83 
84 #endif
Linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.h:39
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.h:24
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.h:58
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 array class.
Definition: Array2.h:42
2-D finite difference-type linear system solver using Gauss-Seidel method.
Definition: FDMGaussSeidelSolver2.h:17
Abstract base class for 2-D finite difference-type linear system solver.
Definition: FDMLinearSystemSolver2.h:17
std::shared_ptr< FDMGaussSeidelSolver2 > FDMGaussSeidelSolver2Ptr
Shared pointer type for the FDMGaussSeidelSolver2.
Definition: FDMGaussSeidelSolver2.h:81