FDMICCGSolver2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: FDMICCGSolver2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D finite difference-type linear system solver using incomplete
6 > Cholesky conjugate gradient (ICCG).
7 > Created Time: 2017/08/12
8 > Copyright (c) 2018, Chan-Ho Chris Ohk
9 *************************************************************************/
10 #ifndef CUBBYFLOW_FDM_ICCG_SOLVER2_H
11 #define CUBBYFLOW_FDM_ICCG_SOLVER2_H
12 
14 
15 namespace CubbyFlow
16 {
22  {
23  public:
25  FDMICCGSolver2(unsigned int maxNumberOfIterations, double tolerance);
26 
28  bool Solve(FDMLinearSystem2* system) override;
29 
31  bool SolveCompressed(FDMCompressedLinearSystem2* system) override;
32 
34  unsigned int GetMaxNumberOfIterations() const;
35 
37  unsigned int GetLastNumberOfIterations() const;
38 
40  double GetTolerance() const;
41 
43  double GetLastResidual() const;
44 
45  private:
46  struct Preconditioner final
47  {
49  FDMVector2 d;
50  FDMVector2 y;
51 
52  void Build(const FDMMatrix2& matrix);
53 
54  void Solve(const FDMVector2& b, FDMVector2* x);
55  };
56 
57  struct PreconditionerCompressed final
58  {
59  const MatrixCSRD* A;
60  VectorND d;
61  VectorND y;
62 
63  void Build(const MatrixCSRD& matrix);
64 
65  void Solve(const VectorND& b, VectorND* x);
66  };
67 
68  unsigned int m_maxNumberOfIterations;
69  unsigned int m_lastNumberOfIterations;
70  double m_tolerance;
71  double m_lastResidualNorm;
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  void ClearUncompressedVectors();
88  void ClearCompressedVectors();
89  };
90 
92  using FDMICCGSolver2Ptr = std::shared_ptr<FDMICCGSolver2>;
93 }
94 
95 #endif
2-D read-only array accessor class.
Definition: ArrayAccessor2.h:261
Linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.h:39
double GetTolerance() const
Returns the max residual tolerance for the Jacobi method.
bool Solve(FDMLinearSystem2 *system) override
Solves the given linear system.
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
FDMICCGSolver2(unsigned int maxNumberOfIterations, double tolerance)
Constructs the solver with given parameters.
Definition: pybind11Utils.h:24
bool SolveCompressed(FDMCompressedLinearSystem2 *system) override
Solves the given compressed linear system.
2-D finite difference-type linear system solver using incomplete Cholesky conjugate gradient (ICCG)...
Definition: FDMICCGSolver2.h:21
Compressed linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.h:58
std::shared_ptr< FDMICCGSolver2 > FDMICCGSolver2Ptr
Shared pointer type for the FDMICCGSolver2.
Definition: FDMICCGSolver2.h:92
double GetLastResidual() const
Returns the last residual after the Jacobi iterations.
2-D array class.
Definition: Array2.h:42
Abstract base class for 2-D finite difference-type linear system solver.
Definition: FDMLinearSystemSolver2.h:17
unsigned int GetLastNumberOfIterations() const
Returns the last number of Jacobi iterations the solver made.