FDMJacobiSolver2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: FDMJacobiSolver2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D finite difference-type linear system solver using Jacobi method.
6 > Created Time: 2017/08/17
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_FDM_JACOBI_SOLVER2_H
10 #define CUBBYFLOW_FDM_JACOBI_SOLVER2_H
11 
13 
14 namespace CubbyFlow
15 {
18  {
19  public:
22  unsigned int maxNumberOfIterations,
23  unsigned int residualCheckInterval,
24  double tolerance);
25 
27  bool Solve(FDMLinearSystem2* system) override;
28 
30  bool SolveCompressed(FDMCompressedLinearSystem2* system) override;
31 
33  unsigned int GetMaxNumberOfIterations() const;
34 
36  unsigned int GetLastNumberOfIterations() const;
37 
39  double GetTolerance() const;
40 
42  double GetLastResidual() const;
43 
45  static void Relax(const FDMMatrix2& A, const FDMVector2& b, FDMVector2* x, FDMVector2* xTemp);
46 
48  static void Relax(const MatrixCSRD& A, const VectorND& b, VectorND* x, VectorND* xTemp);
49 
50  private:
51  unsigned int m_maxNumberOfIterations;
52  unsigned int m_lastNumberOfIterations;
53  unsigned int m_residualCheckInterval;
54  double m_tolerance;
55  double m_lastResidual;
56 
57  // Uncompressed vectors
58  FDMVector2 m_xTemp;
59  FDMVector2 m_residual;
60 
61  // Compressed vectors
62  VectorND m_xTempComp;
63  VectorND m_residualComp;
64 
65  void ClearUncompressedVectors();
66  void ClearCompressedVectors();
67  };
68 
70  using FDMJacobiSolver2Ptr = std::shared_ptr<FDMJacobiSolver2>;
71 }
72 
73 #endif
Linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.h:39
bool SolveCompressed(FDMCompressedLinearSystem2 *system) override
Solves the given compressed linear system.
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
unsigned int GetLastNumberOfIterations() const
Returns the last number of Jacobi iterations the solver made.
static void Relax(const FDMMatrix2 &A, const FDMVector2 &b, FDMVector2 *x, FDMVector2 *xTemp)
Performs single Jacobi relaxation step.
FDMJacobiSolver2(unsigned int maxNumberOfIterations, unsigned int residualCheckInterval, double tolerance)
Constructs the solver with given parameters.
Definition: pybind11Utils.h:24
bool Solve(FDMLinearSystem2 *system) override
Solves the given linear system.
std::shared_ptr< FDMJacobiSolver2 > FDMJacobiSolver2Ptr
Shared pointer type for the FDMJacobiSolver2.
Definition: FDMJacobiSolver2.h:70
Compressed linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.h:58
2-D array class.
Definition: Array2.h:42
Abstract base class for 2-D finite difference-type linear system solver.
Definition: FDMLinearSystemSolver2.h:17
2-D finite difference-type linear system solver using Jacobi method.
Definition: FDMJacobiSolver2.h:17
double GetTolerance() const
Returns the max residual tolerance for the Jacobi method.
double GetLastResidual() const
Returns the last residual after the Jacobi iterations.