14 #ifndef _SYSTEM_MATRIX_H
15 #define _SYSTEM_MATRIX_H
52 virtual size_t dim()
const = 0;
55 virtual void redim(
size_t n) = 0;
58 virtual void resize(
size_t n,
bool =
false) { this->
redim(n); }
61 bool empty()
const {
return this->
dim() == 0; }
83 const IntVec& meqn,
int neq) = 0;
105 const char* =
nullptr)
const {}
109 virtual std::ostream&
write(std::ostream& os)
const {
return os; }
150 virtual size_t dim()
const {
return this->
size(); }
161 virtual void resize(
size_t n,
bool forceClear =
false)
196 const char* label)
const {
dump(*
this,label,format,os); }
199 static void dump(
const Vector& x,
const char* label,
204 virtual std::ostream&
write(std::ostream& os)
const
206 return os << static_cast<const Vector&>(*
this);
224 int num_thread_SLU = 1);
249 virtual bool empty()
const {
return this->
dim(0) == 0; }
254 virtual size_t dim(
int idim = 1)
const = 0;
263 virtual void preAssemble(
const std::vector<IntVec>&,
size_t = 0) {}
331 virtual bool add(
Real,
int = 0) {
return false; }
355 const char* =
nullptr) {}
358 virtual void dump(
const char* fileName, std::streamsize precision = 0,
361 virtual bool load(
const char*,
bool =
false) {
return false; }
371 virtual std::ostream&
write(std::ostream& os)
const {
return os; }
std::vector< int > IntVec
General integer vector.
Definition: ASMbase.h:25
#define Real
The floating point type to use.
Definition: ImmersedBoundaries.h:18
Various enums for linear algebra scope.
Global algebraic operations on index 1-based matrices and vectors.
std::vector< Vector > Vectors
An array of real-valued vectors with algebraic operations.
Definition: MatVec.h:37
Class for linear solver parameters.
Definition: LinSolParams.h:67
Class for administration of MPI processes in IFEM library.
Definition: ProcessAdm.h:33
This class contains data and functions for the assembly of FE matrices.
Definition: SAM.h:39
Standard system vector stored as a single continuous array.
Definition: SystemMatrix.h:124
virtual void resize(size_t n, bool forceClear=false)
Resizes the vector to length n.
Definition: SystemMatrix.h:161
virtual size_t dim() const
Returns the dimension of the system vector.
Definition: SystemMatrix.h:150
virtual void dump(std::ostream &os, LinAlg::StorageFormat format, const char *label) const
Dumps the system vector on a specified format.
Definition: SystemMatrix.h:195
virtual const Vector & vec() const
Reference to underlying utl::vector.
Definition: SystemMatrix.h:171
virtual std::ostream & write(std::ostream &os) const
Writes the system vector to the given output stream.
Definition: SystemMatrix.h:204
virtual Real Linfnorm() const
Linfinity-norm of the vector.
Definition: SystemMatrix.h:192
virtual Real L2norm() const
L2-norm of the vector.
Definition: SystemMatrix.h:189
virtual SystemVector * copy() const
Creates a copy of the system vector and returns a pointer to it.
Definition: SystemMatrix.h:137
virtual void init(Real value=Real(0))
Initializes the vector to a given scalar value.
Definition: SystemMatrix.h:174
virtual void assemble(const Vectors &vecs, const IntVec &meqn, int neq)
Adds element vectors into the system vector.
Definition: SystemMatrix.C:64
StdVector(const std::vector< Real > &vec)
Overloaded copy constructor.
Definition: SystemMatrix.h:131
virtual const Real * getRef() const
Reference through pointer.
Definition: SystemMatrix.h:169
StdVector(const Real *values, size_t n)
Constructor creating a vector from an array.
Definition: SystemMatrix.h:129
virtual Real * getPtr()
Access through pointer.
Definition: SystemMatrix.h:167
virtual Real L1norm() const
L1-norm of the vector.
Definition: SystemMatrix.h:186
virtual LinAlg::MatrixType getType() const
Returns the vector type.
Definition: SystemMatrix.h:134
virtual void redim(size_t n)
Sets the dimension of the system vector while retaining content.
Definition: SystemMatrix.h:153
virtual void mult(Real alpha)
Multiplication with a scalar.
Definition: SystemMatrix.h:177
virtual void add(const SystemVector &vec, Real scale)
Addition of another system vector to this one.
Definition: SystemMatrix.h:180
StdVector(size_t n=0)
Default constructor creating a vector of length n.
Definition: SystemMatrix.h:127
Base class for representing a system matrix on different formats.
Definition: SystemMatrix.h:220
virtual bool assemble(const Matrix &eM, const IntVec &meq)=0
Adds an element matrix into the associated system matrix.
static SystemMatrix * create(const ProcessAdm *adm, LinAlg::MatrixType mType, int num_thread_SLU=1)
Static method creating a matrix of the given type.
Definition: SystemMatrix.C:121
bool isZero() const
Checks if the matrix have no non-zero contributions.
Definition: SystemMatrix.C:217
virtual void preAssemble(const std::vector< IntVec > &, size_t=0)
Initializes the element sparsity pattern based on node connections.
Definition: SystemMatrix.h:263
StdVector operator*(const SystemVector &b) const
Calculates a matrix-vector product.
Definition: SystemMatrix.C:244
virtual ~SystemMatrix()
Empty destructor.
Definition: SystemMatrix.h:237
virtual void dump(std::ostream &, LinAlg::StorageFormat, const char *=nullptr)
Dumps the system matrix on a specified format.
Definition: SystemMatrix.h:354
friend std::ostream & operator<<(std::ostream &os, const SystemMatrix &A)
Global stream operator printing the matrix contents.
Definition: SystemMatrix.h:374
void initNonZeroEqs()
Initializes the nonZeroEqs flags.
Definition: SystemMatrix.C:176
bool flagNonZeroEqs(const IntVec &meq={})
Flags the equations meq as pivots with non-zero contributions.
Definition: SystemMatrix.C:183
StdVector operator/(const SystemVector &b)
Solves a linear equation system.
Definition: SystemMatrix.C:252
virtual bool multiply(const SystemVector &, SystemVector &) const
Performs a matrix-vector multiplication.
Definition: SystemMatrix.h:334
virtual void compressPattern()
Compresses the sparsity pattern.
Definition: SystemMatrix.h:266
virtual void init()=0
Initializes the matrix to zero assuming it is properly dimensioned.
SystemMatrix()
Default constructor.
Definition: SystemMatrix.h:231
virtual bool endAssembly()
Finalizes the system matrix assembly.
Definition: SystemMatrix.C:233
virtual std::ostream & write(std::ostream &os) const
Writes the system matrix to the given output stream.
Definition: SystemMatrix.h:371
virtual bool empty() const
Checks if the matrix is empty.
Definition: SystemMatrix.h:249
virtual bool solve(const SystemVector &b, SystemVector &x)
Solves the linear system of equations for a given right-hand-side.
Definition: SystemMatrix.h:345
virtual SystemMatrix * copy() const =0
Creates a copy of the system matrix and returns a pointer to it.
virtual void initAssembly(const SAM &sam, char=0)=0
Initializes the element assembly process.
virtual bool assemble(const Matrix &eM, const SAM &sam, SystemVector &B, int e)=0
Adds an element matrix into the associated system matrix.
virtual LinAlg::MatrixType getType() const =0
Returns the matrix type.
virtual bool solve(SystemVector &b, Real *rc=nullptr)=0
Solves the linear system of equations for a given right-hand-side.
virtual bool truncate(Real=Real(1.0e-16))
Truncates all small matrix elements to zero.
Definition: SystemMatrix.h:322
virtual bool assemble(const Matrix &eM, const SAM &sam, SystemVector &B, const IntVec &meq)=0
Adds an element matrix into the associated system matrix.
virtual bool augment(const SystemMatrix &, size_t, size_t)
Augments a similar matrix symmetrically to the current matrix.
Definition: SystemMatrix.h:319
virtual bool add(const SystemMatrix &, Real=Real(1))
Adds a matrix with similar structure to the current matrix.
Definition: SystemMatrix.h:328
virtual bool load(const char *, bool=false)
Loads the system matrix from specified file.
Definition: SystemMatrix.h:361
virtual Real Linfnorm() const =0
Returns the L-infinity norm of the matrix.
virtual void mult(Real alpha)=0
Multiplication with a scalar.
SystemMatrix(const SystemMatrix &a)
Copy constructor.
Definition: SystemMatrix.h:233
std::vector< bool > nonZeroEqs
Flags equations with non-zero contributions.
Definition: SystemMatrix.h:380
virtual size_t dim(int idim=1) const =0
Returns the dimension of the system matrix.
virtual bool lockPattern(bool)
Locks or unlocks the sparsity pattern.
Definition: SystemMatrix.h:246
virtual bool assemble(const Matrix &eM, const SAM &sam, int e)=0
Adds an element matrix into the associated system matrix.
virtual bool add(Real, int=0)
Adds a constant to the diagonal of current matrix.
Definition: SystemMatrix.h:331
Base class for representing a system vector on different formats.
Definition: SystemMatrix.h:32
virtual void add(const SystemVector &vec, Real scale=Real(1))=0
Addition of another system vector to this one.
virtual SystemVector * copy() const =0
Creates a copy of the system vector and returns a pointer to it.
virtual size_t dim() const =0
Returns the dimension/size of the system vector.
virtual void assemble(const Vectors &vecs, const IntVec &meqn, int neq)=0
Adds element vectors into the system vector.
virtual void init(Real value=Real(0))=0
Initializes the vector assuming it is properly dimensioned.
virtual const Real * getRef() const =0
Reference through pointer.
virtual Real Linfnorm() const =0
Linfinity-norm of the vector.
virtual void mult(Real alpha)=0
Multiplication with a scalar.
virtual LinAlg::MatrixType getType() const =0
Returns the vector type.
friend std::ostream & operator<<(std::ostream &os, const SystemVector &X)
Global stream operator printing the vector contents.
Definition: SystemMatrix.h:112
virtual std::ostream & write(std::ostream &os) const
Writes the system vector to the given output stream.
Definition: SystemMatrix.h:109
virtual Real L2norm() const =0
L2-norm of the vector.
bool empty() const
Checks if the vector is empty.
Definition: SystemMatrix.h:61
virtual ~SystemVector()
Empty destructor.
Definition: SystemMatrix.h:43
virtual void resize(size_t n, bool=false)
Resizes the vector to length n.
Definition: SystemMatrix.h:58
virtual Real * getPtr()=0
Access through pointer.
virtual Real L1norm() const =0
L1-norm of the vector.
virtual void dump(std::ostream &, LinAlg::StorageFormat, const char *=nullptr) const
Dumps the system vector on a specified format.
Definition: SystemMatrix.h:104
virtual const Vector & vec() const =0
Reference to underlying utl::vector, if any.
virtual bool endAssembly()
Finalizes the system vector assembly.
Definition: SystemMatrix.h:86
static SystemVector * create(const ProcessAdm *adm, LinAlg::MatrixType vtype)
Static method creating a vector of the given type.
Definition: SystemMatrix.C:29
SystemVector()
The default constructor is protected to allow sub-classes only.
Definition: SystemMatrix.h:39
virtual void redim(size_t n)=0
Sets the dimension of the system vector.
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
T asum(size_t off=0, int inc=1) const
Return the sum of the absolute value of the vector elements.
Definition: matrix.h:1550
vector< T > & add(const std::vector< T > &X, const T &alfa=T(1), unsigned int ofsx=0, int stridex=1, unsigned int ofsy=0, int stridey=1)
Add the given vector X scaled by alfa to *this.
Definition: matrix.h:1562
T norm2(size_t off=0, int inc=1) const
Return the Euclidean norm of the vector.
Definition: matrix.h:1513
bool resize(size_t n, char forceClear=0)
Resize the vector to length n.
Definition: matrix.h:277
vector< T > & operator*=(T c)
Multiplication with a scalar.
Definition: matrix.h:1494
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:1526
T * ptr()
Access through pointer.
Definition: matrix.h:83
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
@ FLAT
Flat format.
Definition: LinAlgenums.h:45
const char RETAIN
Flag for vector::resize() method telling it to retain its content.
Definition: matrix.h:55