IFEM  90A354
MatVec.h
Go to the documentation of this file.
1 // $Id$
2 //==============================================================================
12 //==============================================================================
13 
14 #ifndef UTL_MATVEC_H
15 #define UTL_MATVEC_H
16 
17 #include "matrixnd.h"
18 
19 // Some convenience type definitions:
20 
29 
31 typedef std::vector<Real> RealArray;
33 typedef std::vector<RealArray> Real2DMat;
35 typedef std::vector<Real2DMat> Real3DMat;
37 typedef std::vector<Vector> Vectors;
39 typedef std::vector<Matrix> Matrices;
40 
41 
42 namespace utl
43 {
46  Vector operator*(const Vector& X, Real c);
49  inline Vector operator*(Real c, const Vector& X) { return X*c; }
52  inline Vector operator/(const Vector& X, Real d) { return X*(Real(1)/d); }
53 
56  Vector operator+(const Vector& X, const Vector& Y);
59  Vector operator-(const Vector& X, const Vector& Y);
60 
63  Matrix operator*(const Matrix& A, Real c);
66  inline Matrix operator*(Real c, const Matrix& A) { return A*c; }
67 
70  inline Real operator*(const Vector& X, const Vector& Y) { return X.dot(Y); }
71 
74  RealArray operator*(const Matrix& A, const Vector& X);
77  RealArray operator*(const Vector& X, const Matrix& A);
78 
81  Matrix operator*(const Matrix& A, const Matrix& B);
82 
86  bool transform(Matrix& A, const Matrix& Tn);
87 
92  bool transform(Vector& V, const Matrix& Tn, bool transpose = false);
93 
95  bool invert(Matrix& A);
97  bool solve(Matrix& A, RealArray& b, std::vector<int>* iPivot = nullptr);
98 
100  void debugPrint(const char* label, const Vector& V, int level = 2);
101 }
102 
103 #if HAS_CEREAL
104 namespace cereal
105 {
107  template<class Archive, class T>
108  void load(Archive& archive, utl::vector<T>& vec)
109  {
110  archive(static_cast<std::vector<T>&>(vec));
111  }
112 
114  template<class Archive, class T>
115  void save(Archive& archive, const utl::vector<T>& vec)
116  {
117  archive(static_cast<const std::vector<T>&>(vec));
118  }
119 }
120 #endif
121 #endif
#define Real
The floating point type to use.
Definition: ImmersedBoundaries.h:18
std::vector< Real > RealArray
A real-valued array without algebraic operations.
Definition: ImmersedBoundaries.h:29
utl::matrix< Real > Matrix
A real-valued matrix with algebraic operations.
Definition: MatVec.h:24
utl::matrix3d< Real > Matrix3D
A real-valued three-dimensional matrix with algebraic operations.
Definition: MatVec.h:26
utl::vector< Real > Vector
A real-valued vector with algebraic operations.
Definition: MatVec.h:22
utl::matrix4d< Real > Matrix4D
A real-valued four-dimensional matrix with algebraic operations.
Definition: MatVec.h:28
std::vector< RealArray > Real2DMat
A real-valued two-dimensional array without algebraic operations.
Definition: MatVec.h:33
std::vector< Real > RealArray
A real-valued array without algebraic operations.
Definition: MatVec.h:31
std::vector< Vector > Vectors
An array of real-valued vectors with algebraic operations.
Definition: MatVec.h:37
std::vector< Matrix > Matrices
An array of real-valued matrices with algebraic operations.
Definition: MatVec.h:39
std::vector< Real2DMat > Real3DMat
A real-valued three-dimensional array without algebraic operations.
Definition: MatVec.h:35
A vector class with some added algebraic operations.
Definition: matrix.h:64
T dot(const T *v, size_t nv, size_t off1=0, int inc1=1, size_t off2=0, int inc2=1) const
Dot product between *this and another vector.
Definition: matrix.h:1502
Simple template classes for dense multi-dimensional matrices.
General utility classes and functions.
Definition: SIMoptions.h:22
Vector operator*(const Vector &X, Real c)
Multiplication of a vector and a scalar.
Definition: MatVec.C:29
void debugPrint(const char *label, const Vector &V, int level=2)
Debug print of given vector V, if SP_DEBUG ≥ level.
Definition: MatVec.C:256
Vector operator/(const Vector &X, Real d)
Division of a vector by a scalar.
Definition: MatVec.h:52
bool solve(Matrix &A, RealArray &b, std::vector< int > *iPivot=nullptr)
Solves the linear system of equations .
Definition: MatVec.C:195
Vector operator+(const Vector &X, const Vector &Y)
Addition of two vectors.
Definition: MatVec.C:36
bool invert(Matrix &A)
Inverts the square matrix A.
Definition: MatVec.C:151
bool transform(Matrix &A, const Matrix &Tn)
Congruence transformation of a symmetric matrix.
Definition: MatVec.C:88
Vector operator-(const Vector &X, const Vector &Y)
Subtraction of two vectors.
Definition: MatVec.C:43