IFEM 90A354
DiagMatrix.h
Go to the documentation of this file.
1// $Id$
2//==============================================================================
12//==============================================================================
13
14#ifndef _DIAG_MATRIX_H
15#define _DIAG_MATRIX_H
16
17#include "SystemMatrix.h"
18
19
25{
26public:
28 DiagMatrix(size_t m = 0) : myMat(m) {}
32 DiagMatrix(const RealArray& data, size_t nrows = 0);
34 virtual ~DiagMatrix() {}
35
37 virtual LinAlg::MatrixType getType() const { return LinAlg::DIAG; }
38
40 virtual SystemMatrix* copy() const { return new DiagMatrix(*this); }
41
44 bool redim(size_t r) { return myMat.resize(r,utl::RETAIN); }
45
47 virtual size_t dim(int) const { return myMat.size(); }
48
50 Vector& getMat() { return myMat; }
52 Real& operator()(size_t r) { return myMat(r); }
54 const Real& operator()(size_t r) const { return myMat(r); }
55
57 virtual void dump(std::ostream& os, LinAlg::StorageFormat format,
58 const char* label);
59
62 virtual void initAssembly(const SAM& sam, char);
63
65 virtual void init() { myMat.fill(Real(0)); }
66
72 virtual bool assemble(const Matrix& eM, const SAM& sam, int e);
82 virtual bool assemble(const Matrix& eM, const SAM& sam,
83 SystemVector& B, int e);
93 virtual bool assemble(const Matrix& eM, const SAM& sam,
94 SystemVector& B, const IntVec& meq);
95
100 virtual bool assemble(const Matrix& eM, const IntVec& meq);
101
108 bool assembleStruct(int val, const SAM& sam, const IntVec& meq);
109
111 virtual void mult(Real alpha) { myMat *= alpha; }
112
116 virtual bool add(const SystemMatrix& B, Real alpha);
117
119 virtual bool add(Real sigma, int ieq);
120
122 virtual bool multiply(const SystemVector& B, SystemVector& C) const;
123
127 virtual bool solve(SystemVector& B, Real*);
128
130 virtual Real Linfnorm() const { return myMat.normInf(); }
131
132protected:
134 virtual std::ostream& write(std::ostream& os) const { return os << myMat; }
135
136private:
138};
139
140#endif
std::vector< int > IntVec
General integer vector.
Definition ASMbase.h:25
#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:32
General representation of system matrices and vectors.
Class for representing a diagonal system matrix.
Definition DiagMatrix.h:25
Vector & getMat()
Access to the matrix itself.
Definition DiagMatrix.h:50
virtual void mult(Real alpha)
Multiplication with a scalar.
Definition DiagMatrix.h:111
virtual bool assemble(const Matrix &eM, const SAM &sam, int e)
Adds an element matrix into the associated system matrix.
Definition DiagMatrix.C:63
DiagMatrix(const DiagMatrix &A)
Copy constructor.
Definition DiagMatrix.h:30
virtual bool multiply(const SystemVector &B, SystemVector &C) const
Performs the matrix-vector multiplication C = *this * B.
Definition DiagMatrix.C:188
const Real & operator()(size_t r) const
Index-1 based element reference.
Definition DiagMatrix.h:54
virtual ~DiagMatrix()
Empty destructor.
Definition DiagMatrix.h:34
virtual SystemMatrix * copy() const
Creates a copy of the system matrix and returns a pointer to it.
Definition DiagMatrix.h:40
virtual void initAssembly(const SAM &sam, char)
Initializes the element assembly process.
Definition DiagMatrix.C:27
bool redim(size_t r)
Resizes the matrix to dimension .
Definition DiagMatrix.h:44
DiagMatrix(size_t m=0)
Default constructor.
Definition DiagMatrix.h:28
virtual std::ostream & write(std::ostream &os) const
Writes the system matrix to the given output stream.
Definition DiagMatrix.h:134
virtual void init()
Initializes the matrix to zero assuming it is properly dimensioned.
Definition DiagMatrix.h:65
virtual bool solve(SystemVector &B, Real *)
Solves the linear system of equations for a given right-hand-side.
Definition DiagMatrix.C:201
Real & operator()(size_t r)
Index-1 based element access.
Definition DiagMatrix.h:52
virtual size_t dim(int) const
Returns the dimension of the system matrix.
Definition DiagMatrix.h:47
virtual void dump(std::ostream &os, LinAlg::StorageFormat format, const char *label)
Dumps the system matrix on a specified format.
Definition DiagMatrix.C:33
virtual bool add(const SystemMatrix &B, Real alpha)
Adds a matrix with similar dimension to the current matrix.
Definition DiagMatrix.C:163
virtual LinAlg::MatrixType getType() const
Returns the matrix type.
Definition DiagMatrix.h:37
Vector myMat
The actual diagonal matrix.
Definition DiagMatrix.h:137
bool assembleStruct(int val, const SAM &sam, const IntVec &meq)
Assembles a validation matrix assuming unit element contributions.
Definition DiagMatrix.C:114
virtual Real Linfnorm() const
Returns the L-infinity norm of the matrix.
Definition DiagMatrix.h:130
This class contains data and functions for the assembly of FE matrices.
Definition SAM.h:39
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
A vector class with some added algebraic operations.
Definition matrix.h:64
void fill(T s)
Fill the vector with a scalar value.
Definition matrix.h:137
bool resize(size_t n, char forceClear=0)
Resize the vector to length n.
Definition matrix.h:277
size_t size() const
Size of the vector.
Definition matrix.h:88
T normInf(size_t &off, int inc=1, bool sign=false) const
Return the infinite norm of the vector, or signed max value.
Definition matrix.h:1583
MatrixType
The available system matrix formats and associated solvers.
Definition LinAlgenums.h:22
@ DIAG
Diagonal matrices / Trivial solver.
Definition LinAlgenums.h:30
StorageFormat
Enumeration of matrix storage formats.
Definition LinAlgenums.h:43
const char RETAIN
Flag for vector::resize() method telling it to retain its content.
Definition matrix.h:55