14 #ifndef _SPARSE_MATRIX_H
15 #define _SPARSE_MATRIX_H
22 typedef std::pair<size_t,size_t>
IJPair;
69 void resize(
size_t r,
size_t c = 0,
bool forceEditable =
false);
73 bool redim(
size_t r,
size_t c);
84 virtual size_t dim(
int idim = 1)
const;
123 virtual void preAssemble(
const std::vector<IntVec>& MMNPC,
size_t nel = 0);
212 virtual bool add(
Real sigma,
int ieq);
231 bool split(std::array<SparseMatrix,4>& Asub,
const IntVec& meqn2)
const;
253 bool optimiseCols(
const std::vector< std::set<int> >& dofc);
274 virtual std::ostream&
write(std::ostream& os)
const;
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:29
ValueMap::const_iterator ValueIter
Iterator over matrix elements.
Definition: SparseMatrix.h:24
std::pair< size_t, size_t > IJPair
1-based matrix indices
Definition: SparseMatrix.h:22
std::map< IJPair, Real > ValueMap
Index to matrix value mapping.
Definition: SparseMatrix.h:23
General representation of system matrices and vectors.
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
SparseMatrix(SparseSolver eqSolver=NONE, int nt=1)
Default constructor creating an empty matrix.
Definition: SparseMatrix.C:141
virtual SystemMatrix * copy() const
Creates a copy of the system matrix and returns a pointer to it.
Definition: SparseMatrix.h:56
virtual bool truncate(Real threshold=Real(1.0e-16))
Truncates all small matrix elements to zero.
Definition: SparseMatrix.C:483
virtual size_t dim(int idim=1) const
Returns the dimension of the system matrix.
Definition: SparseMatrix.C:256
void printFull(std::ostream &os) const
Print the matrix in full rectangular form.
Definition: SparseMatrix.C:450
virtual LinAlg::MatrixType getType() const
Returns the matrix type.
Definition: SparseMatrix.C:190
bool optimiseRows(bool transposed=false)
Converts the matrix to an optimized row-oriented format.
Definition: SparseMatrix.C:875
const ValueMap & getValues() const
For traversal of the non-zero elements of an editable matrix.
Definition: SparseMatrix.h:92
size_t ncol
Number of matrix columns.
Definition: SparseMatrix.h:287
char editable
Flag for the editability of the matrix elements.
Definition: SparseMatrix.h:284
size_t nrow
Number of matrix rows.
Definition: SparseMatrix.h:286
size_t size() const
Query total matrix size in terms of number of non-zero elements.
Definition: SparseMatrix.h:80
SparseSolver solver
Which equation solver to use.
Definition: SparseMatrix.h:290
void calcCSR(IntVec &iA, IntVec &jA) const
Calculates compressed-sparse-row arrays from the element map.
Definition: SparseMatrix.C:1426
Vector A
Stores the nonzero matrix elements.
Definition: SparseMatrix.h:300
void printSparsity(std::ostream &os) const
Print sparsity pattern - for inspection purposes.
Definition: SparseMatrix.C:417
void preAssemble(const SAM &sam, bool delayLocking)
Initializes the element sparsity pattern based on node connections.
Definition: SparseMatrix.C:734
virtual std::ostream & write(std::ostream &os) const
Writes the system matrix to the given output stream.
Definition: SparseMatrix.C:398
bool solveSLU(Vector &B)
Invokes the SuperLU equation solver for a given right-hand-side.
Definition: SparseMatrix.C:1049
virtual ~SparseMatrix()
The destructor frees the dynamically allocated arrays.
Definition: SparseMatrix.C:180
virtual void initAssembly(const SAM &sam, char preAssembly)
Initializes the element assembly process.
Definition: SparseMatrix.C:720
virtual void compressPattern()
Compresses the sparsity pattern.
Definition: SparseMatrix.C:792
virtual Real Linfnorm() const
Returns the L-infinity norm of the matrix.
Definition: SparseMatrix.C:1404
bool solveSAMG(Vector &B)
Invokes the SAMG equation solver for a given right-hand-side.
Definition: SparseMatrix.C:1338
virtual bool augment(const SystemMatrix &B, size_t r0, size_t c0)
Augments a similar matrix symmetrically to the current matrix.
Definition: SparseMatrix.C:460
static bool printSLUstat
Print solution statistics for SuperLU?
Definition: SparseMatrix.h:277
bool solveUMF(Vector &B, Real *rcond)
Invokes the UMFPACK equation solver for a given right-hand-side.
Definition: SparseMatrix.C:1298
Real & operator()(size_t r, size_t c)
Index-1 based element access.
Definition: SparseMatrix.C:267
void * umfSymbolic
Symbolically factored matrix for UMFPACK.
Definition: SparseMatrix.h:293
void resize(size_t r, size_t c=0, bool forceEditable=false)
Resizes the matrix to dimension .
Definition: SparseMatrix.C:204
bool split(std::array< SparseMatrix, 4 > &Asub, const IntVec &meqn2) const
Splits the matrix into four sub-matrices, A11, A12, A21, A22.
Definition: SparseMatrix.C:1443
virtual bool solve(SystemVector &b, Real *rc=nullptr)=0
Solves the linear system of equations for a given right-hand-side.
virtual void dump(std::ostream &os, LinAlg::StorageFormat format, const char *label)
Dumps the system matrix on a specified format.
Definition: SparseMatrix.C:341
virtual bool multiply(const SystemVector &B, SystemVector &C) const
Performs the matrix-vector multiplication C = *this * B.
Definition: SparseMatrix.C:581
bool factored
Set to true when the matrix is factorized.
Definition: SparseMatrix.h:296
size_t cols() const
Query number of matrix columns.
Definition: SparseMatrix.h:78
ValueMap elem
Stores nonzero matrix elements with index pairs.
Definition: SparseMatrix.h:289
bool optimiseCols()
Converts the matrix to an optimized column-oriented format.
Definition: SparseMatrix.C:935
bool assembleCol(const RealArray &V, const SAM &sam, int n, size_t col)
Adds a nodal vector into columns of a non-symmetric sparse matrix.
Definition: SparseMatrix.C:861
IntVec JA
Specifies column/row index of each nonzero element.
Definition: SparseMatrix.h:299
size_t rows() const
Query number of matrix rows.
Definition: SparseMatrix.h:76
SparseSolver
Available equation solvers for this matrix type.
Definition: SparseMatrix.h:41
int numThreads
Number of threads to use for the SuperLU_MT solver.
Definition: SparseMatrix.h:292
bool redim(size_t r, size_t c)
Resizes the matrix to dimension .
Definition: SparseMatrix.C:237
virtual bool lockPattern(bool doLock)
Locks or unlocks the sparsity pattern.
Definition: SparseMatrix.C:196
bool isFactored() const
Returns whether the matrix has been factored or not.
Definition: SparseMatrix.h:242
IntVec IA
Identifies the beginning of each row or column.
Definition: SparseMatrix.h:298
SuperLUdata * slu
Matrix data for the SuperLU equation solver.
Definition: SparseMatrix.h:291
bool getColumn(size_t c, Vector &col) const
Extracts a specified column from the matrix.
Definition: SparseMatrix.C:1499
virtual bool add(const SystemMatrix &B, Real alpha)
Adds a matrix with similar sparsity pattern to the current matrix.
Definition: SparseMatrix.C:525
bool assembleCol(Real val, const SAM &sam, int n, size_t col)
Adds a scalar value into columns of a non-symmetric sparse matrix.
Definition: SparseMatrix.h:188
bool solveSLUx(Vector &B, Real *rcond)
Invokes the SuperLU equation solver for a given right-hand-side.
Definition: SparseMatrix.C:1146
virtual void init()
Initializes the matrix to zero assuming it is properly dimensioned.
Definition: SparseMatrix.C:801
virtual void mult(Real alpha)
Multiplication with a scalar.
Definition: SparseMatrix.C:515
virtual bool assemble(const Matrix &eM, const SAM &sam, int e)
Adds an element matrix into the associated system matrix.
Definition: SparseMatrix.C:807
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
size_t size() const
Size of the vector.
Definition: matrix.h:88
MatrixType
The available system matrix formats and associated solvers.
Definition: LinAlgenums.h:22
StorageFormat
Enumeration of matrix storage formats.
Definition: LinAlgenums.h:43
Data structures for the SuperLU equation solver.
Definition: SparseMatrix.C:45