FDMICCGSolver3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: FDMICCGSolver3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-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_SOLVER3_H
11 #define CUBBYFLOW_FDM_ICCG_SOLVER3_H
12 
14 
15 namespace CubbyFlow
16 {
22  {
23  public:
25  FDMICCGSolver3(unsigned int maxNumberOfIterations, double tolerance);
26 
28  bool Solve(FDMLinearSystem3* system) override;
29 
31  bool SolveCompressed(FDMCompressedLinearSystem3* 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  FDMVector3 d;
50  FDMVector3 y;
51 
52  void Build(const FDMMatrix3& matrix);
53 
54  void Solve(const FDMVector3& b, FDMVector3* 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  FDMVector3 m_r;
75  FDMVector3 m_d;
76  FDMVector3 m_q;
77  FDMVector3 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 FDMICCGSolver3Ptr = std::shared_ptr<FDMICCGSolver3>;
93 }
94 
95 #endif
Abstract base class for 3-D finite difference-type linear system solver.
Definition: FDMLinearSystemSolver3.h:17
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
3-D finite difference-type linear system solver using incomplete Cholesky conjugate gradient (ICCG)...
Definition: FDMICCGSolver3.h:21
double GetLastResidual() const
Returns the last residual after the Jacobi iterations.
3-D read-only array accessor class.
Definition: ArrayAccessor3.h:269
unsigned int GetLastNumberOfIterations() const
Returns the last number of Jacobi iterations the solver made.
double GetTolerance() const
Returns the max residual tolerance for the Jacobi method.
FDMICCGSolver3(unsigned int maxNumberOfIterations, double tolerance)
Constructs the solver with given parameters.
std::shared_ptr< FDMICCGSolver3 > FDMICCGSolver3Ptr
Shared pointer type for the FDMICCGSolver3.
Definition: FDMICCGSolver3.h:92
Definition: pybind11Utils.h:24
bool SolveCompressed(FDMCompressedLinearSystem3 *system) override
Solves the given compressed linear system.
bool Solve(FDMLinearSystem3 *system) override
Solves the given linear system.
3-D array class.
Definition: Array3.h:45
Compressed linear system (Ax=b) for 3-D finite differencing.
Definition: FDMLinearSystem3.h:61
Linear system (Ax=b) for 3-D finite differencing.
Definition: FDMLinearSystem3.h:42