CG.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: CG.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Generic CG(conjugate gradient) operator functions.
6 > Created Time: 2017/08/13
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_CG_H
10 #define CUBBYFLOW_CG_H
11 
12 #include <Core/Math/BLAS.h>
13 
14 namespace CubbyFlow
15 {
22  template <typename BLASType>
23  struct NullCGPreconditioner final
24  {
25  void Build(const typename BLASType::MatrixType&)
26  {
27  // Do nothing
28  }
29 
30  void Solve(const typename BLASType::VectorType& b, typename BLASType::VectorType* x)
31  {
32  BLASType::Set(b, x);
33  }
34  };
35 
39  template <typename BLASType>
40  void CG(
41  const typename BLASType::MatrixType& A,
42  const typename BLASType::VectorType& b,
43  unsigned int maxNumberOfIterations,
44  double tolerance,
45  typename BLASType::VectorType* x,
46  typename BLASType::VectorType* r,
47  typename BLASType::VectorType* d,
48  typename BLASType::VectorType* q,
49  typename BLASType::VectorType* s,
50  unsigned int* lastNumberOfIterations,
51  double* lastResidualNorm);
52 
56  template <typename BLASType, typename PrecondType>
57  void PCG(
58  const typename BLASType::MatrixType& A,
59  const typename BLASType::VectorType& b,
60  unsigned int maxNumberOfIterations,
61  double tolerance,
62  PrecondType* M,
63  typename BLASType::VectorType* x,
64  typename BLASType::VectorType* r,
65  typename BLASType::VectorType* d,
66  typename BLASType::VectorType* q,
67  typename BLASType::VectorType* s,
68  unsigned int* lastNumberOfIterations,
69  double* lastResidualNorm);
70 }
71 
72 #include <Core/Math/CG-Impl.h>
73 
74 #endif
void Build(const typename BLASType::MatrixType &)
Definition: CG.h:25
Definition: pybind11Utils.h:24
No-op pre-conditioner for conjugate gradient.
Definition: CG.h:23
void CG(const typename BLASType::MatrixType &A, const typename BLASType::VectorType &b, unsigned int maxNumberOfIterations, double tolerance, typename BLASType::VectorType *x, typename BLASType::VectorType *r, typename BLASType::VectorType *d, typename BLASType::VectorType *q, typename BLASType::VectorType *s, unsigned int *lastNumberOfIterations, double *lastResidualNorm)
Solves conjugate gradient.
Definition: CG-Impl.h:17
void Solve(const typename BLASType::VectorType &b, typename BLASType::VectorType *x)
Definition: CG.h:30
void PCG(const typename BLASType::MatrixType &A, const typename BLASType::VectorType &b, unsigned int maxNumberOfIterations, double tolerance, PrecondType *M, typename BLASType::VectorType *x, typename BLASType::VectorType *r, typename BLASType::VectorType *d, typename BLASType::VectorType *q, typename BLASType::VectorType *s, unsigned int *lastNumberOfIterations, double *lastResidualNorm)
Solves pre-conditioned conjugate gradient.
Definition: CG-Impl.h:49