CG.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_CG_HPP
12 #define CUBBYFLOW_CG_HPP
13 
14 #include <Core/Math/BLAS.hpp>
15 
16 namespace CubbyFlow
17 {
24 template <typename BLASType>
26 {
27  static void Build(const typename BLASType::MatrixType&)
28  {
29  // Do nothing
30  }
31 
32  void Solve(const typename BLASType::VectorType& b,
33  typename BLASType::VectorType* x)
34  {
35  BLASType::Set(b, x);
36  }
37 };
38 
42 template <typename BLASType>
43 void CG(const typename BLASType::MatrixType& A,
44  const typename BLASType::VectorType& b,
45  unsigned int maxNumberOfIterations, double tolerance,
46  typename BLASType::VectorType* x, typename BLASType::VectorType* r,
47  typename BLASType::VectorType* d, typename BLASType::VectorType* q,
48  typename BLASType::VectorType* s, unsigned int* lastNumberOfIterations,
49  double* lastResidualNorm);
50 
54 template <typename BLASType, typename PrecondType>
55 void PCG(const typename BLASType::MatrixType& A,
56  const typename BLASType::VectorType& b,
57  unsigned int maxNumberOfIterations, double tolerance, PrecondType* M,
58  typename BLASType::VectorType* x, typename BLASType::VectorType* r,
59  typename BLASType::VectorType* d, typename BLASType::VectorType* q,
60  typename BLASType::VectorType* s, unsigned int* lastNumberOfIterations,
61  double* lastResidualNorm);
62 } // namespace CubbyFlow
63 
64 #include <Core/Math/CG-Impl.hpp>
65 
66 #endif
static void Build(const typename BLASType::MatrixType &)
Definition: CG.hpp:27
Definition: pybind11Utils.hpp:20
No-op pre-conditioner for conjugate gradient.
Definition: CG.hpp:25
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.hpp:19
void Solve(const typename BLASType::VectorType &b, typename BLASType::VectorType *x)
Definition: CG.hpp:32
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.hpp:36