FDMCGSolver2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: FDMCGSolver2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D finite difference-type linear system solver using conjugate gradient.
6 > Created Time: 2017/08/16
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_FDM_CG_SOLVER2_H
10 #define CUBBYFLOW_FDM_CG_SOLVER2_H
11 
13 
14 namespace CubbyFlow
15 {
17  class FDMCGSolver2 final : public FDMLinearSystemSolver2
18  {
19  public:
21  FDMCGSolver2(unsigned int maxNumberOfIterations, double tolerance);
22 
24  bool Solve(FDMLinearSystem2* system) override;
25 
27  bool SolveCompressed(FDMCompressedLinearSystem2* system) override;
28 
30  unsigned int GetMaxNumberOfIterations() const;
31 
33  unsigned int GetLastNumberOfIterations() const;
34 
36  double GetTolerance() const;
37 
39  double GetLastResidual() const;
40 
41  private:
42  unsigned int m_maxNumberOfIterations;
43  unsigned int m_lastNumberOfIterations;
44  double m_tolerance;
45  double m_lastResidual;
46 
47  // Uncompressed vectors
48  FDMVector2 m_r;
49  FDMVector2 m_d;
50  FDMVector2 m_q;
51  FDMVector2 m_s;
52 
53  // Compressed vectors
54  VectorND m_rComp;
55  VectorND m_dComp;
56  VectorND m_qComp;
57  VectorND m_sComp;
58 
59  void ClearUncompressedVectors();
60  void ClearCompressedVectors();
61  };
62 
64  using FDMCGSolver2Ptr = std::shared_ptr<FDMCGSolver2>;
65 }
66 
67 #endif
Linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.h:39
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
bool Solve(FDMLinearSystem2 *system) override
Solves the given linear system.
Definition: pybind11Utils.h:24
unsigned int GetLastNumberOfIterations() const
Returns the last number of Jacobi iterations the solver made.
Compressed linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.h:58
std::shared_ptr< FDMCGSolver2 > FDMCGSolver2Ptr
Shared pointer type for the FDMCGSolver2.
Definition: FDMCGSolver2.h:64
bool SolveCompressed(FDMCompressedLinearSystem2 *system) override
Solves the given compressed linear system.
FDMCGSolver2(unsigned int maxNumberOfIterations, double tolerance)
Constructs the solver with given parameters.
2-D array class.
Definition: Array2.h:42
double GetTolerance() const
Returns the max residual tolerance for the Jacobi method.
2-D finite difference-type linear system solver using conjugate gradient.
Definition: FDMCGSolver2.h:17
Abstract base class for 2-D finite difference-type linear system solver.
Definition: FDMLinearSystemSolver2.h:17
double GetLastResidual() const
Returns the last residual after the Jacobi iterations.