IFEM  90A354
DenseMatrix.h
Go to the documentation of this file.
1 // $Id$
2 //==============================================================================
12 //==============================================================================
13 
14 #ifndef _DENSE_MATRIX_H
15 #define _DENSE_MATRIX_H
16 
17 #include "SystemMatrix.h"
18 
19 class SparseMatrix;
20 
21 
26 class DenseMatrix : public SystemMatrix
27 {
28 public:
30  DenseMatrix(size_t m = 0, size_t n = 0, bool s = false);
32  DenseMatrix(const DenseMatrix& A);
34  explicit DenseMatrix(const RealArray& data, size_t nrows = 0);
36  explicit DenseMatrix(const Matrix& A, bool s = false);
38  virtual ~DenseMatrix() { delete[] ipiv; }
39 
41  virtual LinAlg::MatrixType getType() const { return LinAlg::DENSE; }
42 
44  virtual SystemMatrix* copy() const { return new DenseMatrix(*this); }
45 
48  bool redim(size_t r, size_t c);
49 
52  void setSymmetric(bool s = true) { symm = s && myMat.rows() == myMat.cols(); }
53 
56  virtual size_t dim(int idim) const
57  {
58  return idim > 0 && idim < 3 ? myMat.dim(idim) : myMat.size();
59  }
60 
62  Matrix& getMat() { return myMat; }
64  Real& operator()(size_t r, size_t c) { return myMat(r,c); }
66  const Real& operator()(size_t r, size_t c) const { return myMat(r,c); }
67 
69  virtual void dump(std::ostream& os, LinAlg::StorageFormat format,
70  const char* label);
71 
74  virtual void initAssembly(const SAM& sam, char);
75 
77  virtual void init();
78 
84  virtual bool assemble(const Matrix& eM, const SAM& sam, int e);
95  virtual bool assemble(const Matrix& eM, const SAM& sam,
96  SystemVector& B, int e);
106  virtual bool assemble(const Matrix& eM, const SAM& sam,
107  SystemVector& B, const std::vector<int>& meq);
108 
115  virtual bool assemble(const Matrix& eM, const IntVec& meq);
116 
121  virtual bool augment(const SystemMatrix& B, size_t r0, size_t c0);
122 
124  virtual void mult(Real alpha) { myMat.multiply(alpha); }
125 
129  virtual bool add(const SystemMatrix& B, Real alpha);
130 
132  virtual bool add(Real sigma, int ieq);
133 
135  virtual bool multiply(const SystemVector& B, SystemVector& C) const;
136 
137  using SystemMatrix::solve;
141  virtual bool solve(SystemVector& B, Real* rc = nullptr);
144  bool solve(Matrix& B);
145 
157  bool solveEig(RealArray& eigVal, Matrix& eigVec, int nev);
158 
170  bool solveEigNon(RealArray& r_val, RealArray& c_val);
171 
185  bool solveEig(DenseMatrix& B, RealArray& eigVal, Matrix& eigVec, int nev,
186  Real shift = Real(0));
187 
189  virtual Real Linfnorm() const { return myMat.normInf(); }
190 
192  virtual bool load(const char* fileName, bool binary);
193 
194 protected:
199  bool augment(const Matrix& B, size_t r0, size_t c0);
200 
205  bool augment(const SparseMatrix& B, size_t r0, size_t c0);
206 
215  bool solve(Real* B, size_t nrhs, Real* rcond = nullptr);
216 
218  virtual std::ostream& write(std::ostream& os) const { return os << myMat; }
219 
220 private:
222  int* ipiv;
223  bool symm;
224 };
225 
229 DenseMatrix operator*(Real alpha, const DenseMatrix& A);
230 
234 DenseMatrix operator*(const DenseMatrix& A, Real alpha);
235 
236 #endif
std::vector< int > IntVec
General integer vector.
Definition: ASMbase.h:25
DenseMatrix operator*(Real alpha, const DenseMatrix &A)
Multiply a matrix with a scalar.
Definition: DenseMatrix.C:708
#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
General representation of system matrices and vectors.
Class for representing a dense system matrix.
Definition: DenseMatrix.h:27
virtual bool assemble(const Matrix &eM, const SAM &sam, int e)
Adds an element matrix into the associated system matrix.
Definition: DenseMatrix.C:312
bool redim(size_t r, size_t c)
Resizes the matrix to dimension .
Definition: DenseMatrix.C:450
DenseMatrix(size_t m=0, size_t n=0, bool s=false)
Default constructor.
Definition: DenseMatrix.C:42
Matrix myMat
The actual dense matrix.
Definition: DenseMatrix.h:221
virtual ~DenseMatrix()
The destructor frees the dynamically allocated arrays.
Definition: DenseMatrix.h:38
const Real & operator()(size_t r, size_t c) const
Index-1 based element reference.
Definition: DenseMatrix.h:66
virtual bool add(const SystemMatrix &B, Real alpha)
Adds a matrix with similar dimension to the current matrix.
Definition: DenseMatrix.C:472
virtual bool augment(const SystemMatrix &B, size_t r0, size_t c0)
Augments a similar matrix symmetrically to the current matrix.
Definition: DenseMatrix.C:400
virtual void mult(Real alpha)
Multiplication with a scalar.
Definition: DenseMatrix.h:124
bool solveEig(RealArray &eigVal, Matrix &eigVec, int nev)
Solves a standard symmetric-definite eigenproblem.
Definition: DenseMatrix.C:581
virtual bool solve(SystemVector &b, Real *rc=nullptr)=0
Solves the linear system of equations for a given right-hand-side.
bool solveEigNon(RealArray &r_val, RealArray &c_val)
Solves a non-symmetric eigenproblem.
Definition: DenseMatrix.C:675
virtual std::ostream & write(std::ostream &os) const
Writes the system matrix to the given output stream.
Definition: DenseMatrix.h:218
virtual bool load(const char *fileName, bool binary)
Loads the system matrix from specified file.
Definition: DenseMatrix.C:151
virtual void initAssembly(const SAM &sam, char)
Initializes the element assembly process.
Definition: DenseMatrix.C:79
virtual size_t dim(int idim) const
Returns the dimension of the system matrix.
Definition: DenseMatrix.h:56
virtual Real Linfnorm() const
Returns the L-infinity norm of the matrix.
Definition: DenseMatrix.h:189
virtual LinAlg::MatrixType getType() const
Returns the matrix type.
Definition: DenseMatrix.h:41
int * ipiv
Pivot indices used in solve.
Definition: DenseMatrix.h:222
virtual SystemMatrix * copy() const
Creates a copy of the system matrix and returns a pointer to it.
Definition: DenseMatrix.h:44
virtual void dump(std::ostream &os, LinAlg::StorageFormat format, const char *label)
Dumps the system matrix on a specified format.
Definition: DenseMatrix.C:95
void setSymmetric(bool s=true)
Marks the matrix as symmetric.
Definition: DenseMatrix.h:52
bool symm
Flags whether the matrix is symmetric or not.
Definition: DenseMatrix.h:223
Matrix & getMat()
Access to the matrix itself.
Definition: DenseMatrix.h:62
virtual bool multiply(const SystemVector &B, SystemVector &C) const
Performs the matrix-vector multiplication C = *this * B.
Definition: DenseMatrix.C:503
virtual void init()
Initializes the matrix to zero assuming it is properly dimensioned.
Definition: DenseMatrix.C:85
Real & operator()(size_t r, size_t c)
Index-1 based element access.
Definition: DenseMatrix.h:64
This class contains data and functions for the assembly of FE matrices.
Definition: SAM.h:39
Class for representing a system matrix on an unstructured sparse form.
Definition: SparseMatrix.h:38
Base class for representing a system matrix on different formats.
Definition: SystemMatrix.h:220
virtual bool solve(SystemVector &b, Real *rc=nullptr)=0
Solves the linear system of equations for a given right-hand-side.
Base class for representing a system vector on different formats.
Definition: SystemMatrix.h:32
size_t dim(short int d=1) const
Query dimensions.
Definition: matrix.h:376
size_t size() const
Query total matrix size.
Definition: matrix.h:378
size_t cols() const
Query number of matrix columns.
Definition: matrix.h:560
T normInf() const
Return the infinite norm of the matrix.
Definition: matrix.h:921
matrix< T > & multiply(T c)
Multiplication of this matrix by a scalar c.
Definition: matrix.h:844
size_t rows() const
Query number of matrix rows.
Definition: matrix.h:558
MatrixType
The available system matrix formats and associated solvers.
Definition: LinAlgenums.h:22
@ DENSE
Dense matrices / LAPack solver.
Definition: LinAlgenums.h:23
StorageFormat
Enumeration of matrix storage formats.
Definition: LinAlgenums.h:43