FDMLinearSystem2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: FDMLinearSystem2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Linear system (Ax=b) for 2-D finite differencing.
6 > Created Time: 2017/08/12
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_FDM_LINEAR_SYSTEM2_H
10 #define CUBBYFLOW_FDM_LINEAR_SYSTEM2_H
11 
12 #include <Core/Array/Array2.h>
13 #include <Core/Matrix/MatrixCSR.h>
14 #include <Core/Size/Size2.h>
15 #include <Core/Vector/VectorN.h>
16 
17 namespace CubbyFlow
18 {
21  {
23  double center = 0.0;
24 
26  double right = 0.0;
27 
29  double up = 0.0;
30  };
31 
34 
37 
40  {
43 
46 
49 
51  void Clear();
52 
54  void Resize(const Size2& size);
55  };
56 
59  {
62 
65 
68 
70  void Clear();
71  };
72 
74  struct FDMBLAS2
75  {
76  using ScalarType = double;
79 
81  static void Set(ScalarType s, VectorType* result);
82 
84  static void Set(const VectorType& v, VectorType* result);
85 
87  static void Set(ScalarType s, MatrixType* result);
88 
90  static void Set(const MatrixType& m, MatrixType* result);
91 
93  static double Dot(const VectorType& a, const VectorType& b);
94 
96  static void AXPlusY(double a, const VectorType& x, const VectorType& y, VectorType* result);
97 
99  static void MVM(const MatrixType& m, const VectorType& v, VectorType* result);
100 
102  static void Residual(const MatrixType& a, const VectorType& x, const VectorType& b, VectorType* result);
103 
105  static ScalarType L2Norm(const VectorType& v);
106 
108  static ScalarType LInfNorm(const VectorType& v);
109  };
110 
113  {
114  using ScalarType = double;
117 
119  static void Set(ScalarType s, VectorType* result);
120 
122  static void Set(const VectorType& v, VectorType* result);
123 
125  static void Set(ScalarType s, MatrixType* result);
126 
128  static void Set(const MatrixType& m, MatrixType* result);
129 
131  static double Dot(const VectorType& a, const VectorType& b);
132 
134  static void AXPlusY(double a, const VectorType& x, const VectorType& y, VectorType* result);
135 
137  static void MVM(const MatrixType& m, const VectorType& v, VectorType* result);
138 
140  static void Residual(const MatrixType& a, const VectorType& x, const VectorType& b, VectorType* result);
141 
143  static ScalarType L2Norm(const VectorType& v);
144 
146  static ScalarType LInfNorm(const VectorType& v);
147  };
148 }
149 
150 #endif
Linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.h:39
static double Dot(const VectorType &a, const VectorType &b)
Performs dot product with vector a and b.
void Clear()
Clears all the data.
void Clear()
Clears all the data.
BLAS operator wrapper for 2-D finite differencing.
Definition: FDMLinearSystem2.h:74
MatrixCSR< double > MatrixCSRD
Double-type CSR matrix.
Definition: MatrixCSR.h:475
Array2< double > FDMVector2
Vector type for 2-D finite differencing.
Definition: FDMLinearSystem2.h:33
VectorN< double > VectorND
Double-type N-D vector.
Definition: VectorN.h:397
static void Set(ScalarType s, VectorType *result)
Sets entire element of given vector result with scalar s.
double center
Diagonal component of the matrix (row, row).
Definition: FDMLinearSystem2.h:23
static ScalarType L2Norm(const VectorType &v)
Returns L2-norm of the given vector v.
static void MVM(const MatrixType &m, const VectorType &v, VectorType *result)
Performs matrix-vector multiplication.
void Resize(const Size2 &size)
Resizes the arrays with given grid size.
2-D point class.
Definition: Point2.h:25
double ScalarType
Definition: FDMLinearSystem2.h:114
MatrixCSRD A
System matrix.
Definition: FDMLinearSystem2.h:61
FDMVector2 x
Solution vector.
Definition: FDMLinearSystem2.h:45
Definition: pybind11Utils.h:24
static void Set(ScalarType s, VectorType *result)
Sets entire element of given vector result with scalar s.
static void AXPlusY(double a, const VectorType &x, const VectorType &y, VectorType *result)
Performs ax + y operation where a is a matrix and x and y are vectors.
double ScalarType
Definition: FDMLinearSystem2.h:76
The row of FDMMatrix2 where row corresponds to (i, j) grid point.
Definition: FDMLinearSystem2.h:20
FDMMatrix2 A
System matrix.
Definition: FDMLinearSystem2.h:42
static ScalarType LInfNorm(const VectorType &v)
Returns Linf-norm of the given vector v.
Compressed linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.h:58
static void Residual(const MatrixType &a, const VectorType &x, const VectorType &b, VectorType *result)
Computes residual vector (b - ax).
static void AXPlusY(double a, const VectorType &x, const VectorType &y, VectorType *result)
Performs ax + y operation where a is a matrix and x and y are vectors.
static double Dot(const VectorType &a, const VectorType &b)
Performs dot product with vector a and b.
2-D array class.
Definition: Array2.h:42
static void Residual(const MatrixType &a, const VectorType &x, const VectorType &b, VectorType *result)
Computes residual vector (b - ax).
VectorND x
Solution vector.
Definition: FDMLinearSystem2.h:64
double right
Off-diagonal element where column refers to (i+1, j) grid point.
Definition: FDMLinearSystem2.h:26
double up
Off-diagonal element where column refers to (i, j+1) grid point.
Definition: FDMLinearSystem2.h:29
static void MVM(const MatrixType &m, const VectorType &v, VectorType *result)
Performs matrix-vector multiplication.
VectorND b
RHS vector.
Definition: FDMLinearSystem2.h:67
Array2< FDMMatrixRow2 > FDMMatrix2
Matrix type for 2-D finite differencing.
Definition: FDMLinearSystem2.h:36
FDMVector2 b
RHS vector.
Definition: FDMLinearSystem2.h:48
BLAS operator wrapper for compressed 2-D finite differencing.
Definition: FDMLinearSystem2.h:112
static ScalarType L2Norm(const VectorType &v)
Returns L2-norm of the given vector v.
static ScalarType LInfNorm(const VectorType &v)
Returns Linf-norm of the given vector v.