FDMLinearSystem2.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_FDM_LINEAR_SYSTEM2_HPP
12 #define CUBBYFLOW_FDM_LINEAR_SYSTEM2_HPP
13 
14 #include <Core/Array/Array.hpp>
15 #include <Core/Matrix/Matrix.hpp>
17 
18 namespace CubbyFlow
19 {
22 {
24  double center = 0.0;
25 
27  double right = 0.0;
28 
30  double up = 0.0;
31 };
32 
35 
38 
41 {
43  void Clear();
44 
46  void Resize(const Vector2UZ& size);
47 
50 
53 
56 };
57 
60 {
62  void Clear();
63 
66 
69 
72 };
73 
75 struct FDMBLAS2
76 {
77  using ScalarType = double;
80 
82  static void Set(ScalarType s, VectorType* result);
83 
85  static void Set(const VectorType& v, VectorType* result);
86 
88  static void Set(ScalarType s, MatrixType* result);
89 
91  static void Set(const MatrixType& m, MatrixType* result);
92 
94  static double Dot(const VectorType& a, const VectorType& b);
95 
98  static void AXPlusY(double a, const VectorType& x, const VectorType& y,
99  VectorType* result);
100 
102  static void MVM(const MatrixType& m, const VectorType& v,
103  VectorType* result);
104 
106  static void Residual(const MatrixType& a, const VectorType& x,
107  const VectorType& b, VectorType* result);
108 
110  [[nodiscard]] static ScalarType L2Norm(const VectorType& v);
111 
113  [[nodiscard]] static ScalarType LInfNorm(const VectorType& v);
114 };
115 
118 {
119  using ScalarType = double;
122 
124  static void Set(ScalarType s, VectorType* result);
125 
127  static void Set(const VectorType& v, VectorType* result);
128 
130  static void Set(ScalarType s, MatrixType* result);
131 
133  static void Set(const MatrixType& m, MatrixType* result);
134 
136  static double Dot(const VectorType& a, const VectorType& b);
137 
140  static void AXPlusY(double a, const VectorType& x, const VectorType& y,
141  VectorType* result);
142 
144  static void MVM(const MatrixType& m, const VectorType& v,
145  VectorType* result);
146 
148  static void Residual(const MatrixType& a, const VectorType& x,
149  const VectorType& b, VectorType* result);
150 
152  [[nodiscard]] static ScalarType L2Norm(const VectorType& v);
153 
155  [[nodiscard]] static ScalarType LInfNorm(const VectorType& v);
156 };
157 } // namespace CubbyFlow
158 
159 #endif
Linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:40
BLAS operator wrapper for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:75
Array2< double > FDMVector2
Vector type for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:34
VectorN< double > VectorND
Definition: Matrix.hpp:832
double center
Diagonal component of the matrix (row, row).
Definition: FDMLinearSystem2.hpp:24
double ScalarType
Definition: FDMLinearSystem2.hpp:119
MatrixCSRD A
System matrix.
Definition: FDMLinearSystem2.hpp:65
Definition: Matrix.hpp:27
FDMVector2 x
Solution vector.
Definition: FDMLinearSystem2.hpp:52
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
double ScalarType
Definition: FDMLinearSystem2.hpp:77
The row of FDMMatrix2 where row corresponds to (i, j) grid point.
Definition: FDMLinearSystem2.hpp:21
FDMMatrix2 A
System matrix.
Definition: FDMLinearSystem2.hpp:49
MatrixCSR< double > MatrixCSRD
Double-type CSR matrix.
Definition: MatrixCSR.hpp:448
Compressed linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:59
VectorND x
Solution vector.
Definition: FDMLinearSystem2.hpp:68
double right
Off-diagonal element where column refers to (i+1, j) grid point.
Definition: FDMLinearSystem2.hpp:27
double up
Off-diagonal element where column refers to (i, j+1) grid point.
Definition: FDMLinearSystem2.hpp:30
VectorND b
RHS vector.
Definition: FDMLinearSystem2.hpp:71
Array2< FDMMatrixRow2 > FDMMatrix2
Matrix type for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:37
FDMVector2 b
RHS vector.
Definition: FDMLinearSystem2.hpp:55
BLAS operator wrapper for compressed 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:117