Jet  v1.3.3
cg.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_CG_H_
8 #define INCLUDE_JET_CG_H_
9 
10 #include <jet/blas.h>
11 
12 namespace jet {
13 
20 template <typename BlasType>
21 struct NullCgPreconditioner final {
22  void build(const typename BlasType::MatrixType&) {}
23 
24  void solve(
25  const typename BlasType::VectorType& b,
26  typename BlasType::VectorType* x) {
27  BlasType::set(b, x);
28  }
29 };
30 
34 template <typename BlasType>
35 void cg(
36  const typename BlasType::MatrixType& A,
37  const typename BlasType::VectorType& b,
38  unsigned int maxNumberOfIterations,
39  double tolerance,
40  typename BlasType::VectorType* x,
41  typename BlasType::VectorType* r,
42  typename BlasType::VectorType* d,
43  typename BlasType::VectorType* q,
44  typename BlasType::VectorType* s,
45  unsigned int* lastNumberOfIterations,
46  double* lastResidualNorm);
47 
51 template <
52  typename BlasType,
53  typename PrecondType>
54 void pcg(
55  const typename BlasType::MatrixType& A,
56  const typename BlasType::VectorType& b,
57  unsigned int maxNumberOfIterations,
58  double tolerance,
59  PrecondType* M,
60  typename BlasType::VectorType* x,
61  typename BlasType::VectorType* r,
62  typename BlasType::VectorType* d,
63  typename BlasType::VectorType* q,
64  typename BlasType::VectorType* s,
65  unsigned int* lastNumberOfIterations,
66  double* lastResidualNorm);
67 
68 } // namespace jet
69 
70 #include "detail/cg-inl.h"
71 
72 #endif // INCLUDE_JET_CG_H_
jet::cg
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.
jet::pcg
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.
jet
Definition: advection_solver2.h:18
blas.h
jet::NullCgPreconditioner::solve
void solve(const typename BlasType::VectorType &b, typename BlasType::VectorType *x)
Definition: cg.h:24
jet::NullCgPreconditioner
No-op preconditioner for conjugate gradient.
Definition: cg.h:21
jet::NullCgPreconditioner::build
void build(const typename BlasType::MatrixType &)
Definition: cg.h:22