Loading...
Searching...
No Matches
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
16namespace CubbyFlow
17{
24template <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
42template <typename BLASType>
43void 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
71template <typename BLASType>
72void CR(const typename BLASType::MatrixType& A,
73 const typename BLASType::VectorType& b,
74 unsigned int maxNumberOfIterations, double tolerance,
75 typename BLASType::VectorType* x, typename BLASType::VectorType* r,
76 typename BLASType::VectorType* d, typename BLASType::VectorType* q,
77 typename BLASType::VectorType* s, unsigned int* lastNumberOfIterations,
78 double* lastResidualNorm);
79
83template <typename BLASType, typename PrecondType>
84void PCG(const typename BLASType::MatrixType& A,
85 const typename BLASType::VectorType& b,
86 unsigned int maxNumberOfIterations, double tolerance, PrecondType* M,
87 typename BLASType::VectorType* x, typename BLASType::VectorType* r,
88 typename BLASType::VectorType* d, typename BLASType::VectorType* q,
89 typename BLASType::VectorType* s, unsigned int* lastNumberOfIterations,
90 double* lastResidualNorm);
91} // namespace CubbyFlow
92
93#include <Core/Math/CG-Impl.hpp>
94
95#endif
Definition Matrix.hpp:30
Definition pybind11Utils.hpp:22
void CR(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 a symmetric linear system with conjugate residual.
Definition CG-Impl.hpp:38
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:648
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:107
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:21
No-op pre-conditioner for conjugate gradient.
Definition CG.hpp:26
void Solve(const typename BLASType::VectorType &b, typename BLASType::VectorType *x)
Definition CG.hpp:32
static void Build(const typename BLASType::MatrixType &)
Definition CG.hpp:27