FDMMGPCGSolver2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: FDMMGPCGSolver2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D finite difference-type linear system solver using Multigrid
6 > Preconditioned conjugate gradient (MGPCG).
7 > Created Time: 2017/11/05
8 > Copyright (c) 2018, Chan-Ho Chris Ohk
9 *************************************************************************/
10 #ifndef CUBBYFLOW_FDM_MGPCG_SOLVER2_H
11 #define CUBBYFLOW_FDM_MGPCG_SOLVER2_H
12 
14 
15 namespace CubbyFlow
16 {
26  class FDMMGPCGSolver2 final : public FDMMGSolver2
27  {
28  public:
40  unsigned int numberOfCGIter,
41  size_t maxNumberOfLevels,
42  unsigned int numberOfRestrictionIter = 5,
43  unsigned int numberOfCorrectionIter = 5,
44  unsigned int numberOfCoarsestIter = 20,
45  unsigned int numberOfFinalIter = 20,
46  double maxTolerance = 1e-9,
47  double sorFactor = 1.5,
48  bool useRedBlackOrdering = false);
49 
51  bool Solve(FDMMGLinearSystem2* system) override;
52 
54  unsigned int GetMaxNumberOfIterations() const;
55 
57  unsigned int GetLastNumberOfIterations() const;
58 
60  double GetTolerance() const;
61 
63  double GetLastResidual() const;
64 
65  private:
66  struct Preconditioner final
67  {
68  FDMMGLinearSystem2* system;
69  MGParameters<FDMBLAS2> mgParams;
70 
71  void Build(FDMMGLinearSystem2* system, MGParameters<FDMBLAS2> mgParams);
72 
73  void Solve(const FDMVector2& b, FDMVector2* x) const;
74  };
75 
76  unsigned int m_maxNumberOfIterations;
77  unsigned int m_lastNumberOfIterations;
78  double m_tolerance;
79  double m_lastResidualNorm;
80 
81  FDMVector2 m_r;
82  FDMVector2 m_d;
83  FDMVector2 m_q;
84  FDMVector2 m_s;
85  Preconditioner m_precond;
86  };
87 
89  using FDMMGPCGSolver2Ptr = std::shared_ptr<FDMMGPCGSolver2>;
90 }
91 
92 #endif
bool Solve(FDMMGLinearSystem2 *system) override
Solves the given linear system.
2-D finite difference-type linear system solver using Multigrid.
Definition: FDMMGSolver2.h:19
double GetLastResidual() const
Returns the last residual after the Jacobi iterations.
Definition: pybind11Utils.h:24
FDMMGPCGSolver2(unsigned int numberOfCGIter, size_t maxNumberOfLevels, unsigned int numberOfRestrictionIter=5, unsigned int numberOfCorrectionIter=5, unsigned int numberOfCoarsestIter=20, unsigned int numberOfFinalIter=20, double maxTolerance=1e-9, double sorFactor=1.5, bool useRedBlackOrdering=false)
std::shared_ptr< FDMMGPCGSolver2 > FDMMGPCGSolver2Ptr
Shared pointer type for the FDMMGPCGSolver2.
Definition: FDMMGPCGSolver2.h:89
2-D finite difference-type linear system solver using Multigrid Preconditioned conjugate gradient (MG...
Definition: FDMMGPCGSolver2.h:26
double GetTolerance() const
Returns the max residual tolerance for the Jacobi method.
unsigned int GetMaxNumberOfIterations() const
Returns the max number of Jacobi iterations.
Multi-grid input parameter set.
Definition: MG.h:60
2-D array class.
Definition: Array2.h:42
Multigrid-syle 2-D linear system.
Definition: FDMMGLinearSystem2.h:24
unsigned int GetLastNumberOfIterations() const
Returns the last number of Jacobi iterations the solver made.