IFEM  90A354
SPRMatrix.h
Go to the documentation of this file.
1 // $Id$
2 //==============================================================================
13 //==============================================================================
14 
15 #ifndef _SPR_MATRIX_H
16 #define _SPR_MATRIX_H
17 
18 #include "SystemMatrix.h"
20 #ifdef USE_INT64
21 #include <cstdint>
22 #define Int_ std::int64_t
23 #else
24 #define Int_ int
25 #endif
26 #define NS 60
28 
29 
36 class SPRMatrix : public SystemMatrix
37 {
38 public:
40  SPRMatrix();
42  SPRMatrix(const SPRMatrix& A);
44  virtual ~SPRMatrix();
45 
47  virtual LinAlg::MatrixType getType() const { return LinAlg::SPR; }
48 
50  virtual SystemMatrix* copy() const { return new SPRMatrix(*this); }
51 
53  SPRMatrix& operator=(const SPRMatrix&) = delete;
54 
56  virtual size_t dim(int idim) const;
57 
60  virtual void initAssembly(const SAM& sam, char);
61 
63  virtual void init();
64 
71  virtual bool assemble(const Matrix& eM, const SAM& sam, int e);
81  virtual bool assemble(const Matrix& eM, const SAM& sam,
82  SystemVector& B, int e);
92  virtual bool assemble(const Matrix& eM, const SAM& sam,
93  SystemVector& B, const IntVec& meq);
94 
101  virtual bool assemble(const Matrix& eM, const IntVec& meq);
102 
104  virtual void mult(Real alpha);
105 
109  virtual bool add(const SystemMatrix& B, Real alpha);
110 
112  virtual bool add(Real sigma, int ieq);
113 
115  virtual bool multiply(const SystemVector& B, SystemVector& C) const;
116 
117  using SystemMatrix::solve;
120  virtual bool solve(SystemVector& B, Real*);
121 
129  bool solveEig(SPRMatrix& B, RealArray& val, Matrix& vec, int nev,
130  Real shift = 0.0, int iop = 1);
131 
133  virtual Real Linfnorm() const;
134 
136  bool convert(Matrix& fullMat) const;
137 
139  virtual void dump(std::ostream& os, LinAlg::StorageFormat fmt, const char*);
141  virtual bool load(const char* fileName, bool binary);
142 
143 protected:
150  bool assemble(int e, const Matrix& eM, const SAM& sam, Real* B = nullptr);
152  bool multiply(size_t n, const Real* b, Real* c);
153 
155  virtual std::ostream& write(std::ostream& os) const;
156 
157 private:
158  Int_ ierr;
159  Int_ mpar[NS];
160  Int_* msica;
161  Int_* msifa;
162  Int_* mtrees;
163  Int_* mvarnc;
165 
166  std::vector<Int_> iWork;
167  std::vector<Int_>* jWork;
168  std::vector<Real> rWork;
169 
170 #ifdef USE_INT64
172  struct SAM64
173  {
174  Int_* mpar;
175  Int_* mpmnpc;
176  Int_* mmnpc;
177  Int_* madof;
178  Int_* mpmceq;
179  Int_* mmceq;
180  Int_* meqn;
181  int* minex;
182 
184  SAM64(const SAM& sam);
186  ~SAM64();
188  std::pair<int,int> getNodeAndLocalDof(int ieq, bool) const;
189  };
190 
191  bool sharedSam = false;
192 #else
193  using SAM64 = SAM;
194 #endif
196 };
197 
198 #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:29
General representation of system matrices and vectors.
This class contains data and functions for the assembly of FE matrices.
Definition: SAM.h:39
int mpar[50]
Matrix of parameters.
Definition: SAM.h:326
std::pair< int, int > getNodeAndLocalDof(int idof, bool eqno=false) const
Returns the internal node number and local index for a global DOF.
Definition: SAM.C:101
int * madof
Matrix of accumulated DOFs.
Definition: SAM.h:344
int * minex
Matrix of internal to external node numbers.
Definition: SAM.h:349
int * mmnpc
Matrix of matrices of nodal point correspondances.
Definition: SAM.h:343
int * mpmceq
Matrix of pointers to MCEQs in MMCEQ.
Definition: SAM.h:346
int * mpmnpc
Matrix of pointers to MNPCs in MMNPC.
Definition: SAM.h:342
int * mmceq
Matrix of matrices of constraint equation definitions.
Definition: SAM.h:347
int * meqn
Matrix of equation numbers.
Definition: SAM.h:350
Class for representing the system matrix on the SPR-format.
Definition: SPRMatrix.h:37
Int_ * msifa
Matrix of Storage Information for FA.
Definition: SPRMatrix.h:161
SPRMatrix()
Default constructor.
Definition: SPRMatrix.C:167
virtual LinAlg::MatrixType getType() const
Returns the matrix type.
Definition: SPRMatrix.h:47
virtual Real Linfnorm() const
Returns the L-infinity norm of the matrix.
Definition: SPRMatrix.C:762
Real * values
The actual matrix VALUES.
Definition: SPRMatrix.h:164
bool convert(Matrix &fullMat) const
Converts to a dense matrix.
Definition: SPRMatrix.C:804
SAM SAM64
Convenience alias when using 32-bit int version.
Definition: SPRMatrix.h:193
Int_ ierr
Internal error flag.
Definition: SPRMatrix.h:158
virtual void initAssembly(const SAM &sam, char)
Initializes the element assembly process.
Definition: SPRMatrix.C:296
Int_ * mvarnc
Matrix of VARiable to Node Correspondence.
Definition: SPRMatrix.h:163
virtual bool add(const SystemMatrix &B, Real alpha)
Adds a matrix with similar sparsity pattern to the current matrix.
Definition: SPRMatrix.C:627
virtual bool multiply(const SystemVector &B, SystemVector &C) const
Performs the matrix-vector multiplication C = *this * B.
Definition: SPRMatrix.C:673
virtual SystemMatrix * copy() const
Creates a copy of the system matrix and returns a pointer to it.
Definition: SPRMatrix.h:50
virtual std::ostream & write(std::ostream &os) const
Writes the system matrix to the given output stream.
Definition: SPRMatrix.C:776
virtual void init()
Initializes the matrix to zero assuming it is properly dimensioned.
Definition: SPRMatrix.C:440
Int_ mpar[NS]
Matrix of sparse PARameters.
Definition: SPRMatrix.h:159
SAM64 * mySam
Possibly 64-bit integer version of SAM arrays.
Definition: SPRMatrix.h:195
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 fmt, const char *)
Dumps the system matrix on a specified format.
Definition: SPRMatrix.C:449
Int_ * msica
Matrix of Storage Information for CA.
Definition: SPRMatrix.h:160
virtual size_t dim(int idim) const
Returns the dimension of the system matrix.
Definition: SPRMatrix.C:276
virtual bool load(const char *fileName, bool binary)
Loads the system matrix from specified file.
Definition: SPRMatrix.C:504
std::vector< Real > rWork
Real work array.
Definition: SPRMatrix.h:168
std::vector< Int_ > iWork
Integer work array.
Definition: SPRMatrix.h:166
SPRMatrix & operator=(const SPRMatrix &)=delete
This class is not copyable.
Int_ * mtrees
Matrix of elimination assembly TREES.
Definition: SPRMatrix.h:162
std::vector< Int_ > * jWork
Integer work arrays for multi-threaded assembly.
Definition: SPRMatrix.h:167
virtual ~SPRMatrix()
The destructor frees the dynamically allocated arrays.
Definition: SPRMatrix.C:207
virtual void mult(Real alpha)
Multiplication with a scalar.
Definition: SPRMatrix.C:621
virtual bool assemble(const Matrix &eM, const SAM &sam, int e)=0
Adds an element matrix into the associated system matrix.
bool solveEig(SPRMatrix &B, RealArray &val, Matrix &vec, int nev, Real shift=0.0, int iop=1)
Solves a generalized symmetric-definite eigenproblem.
Definition: SPRMatrix.C:726
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.
virtual bool assemble(const Matrix &eM, const SAM &sam, int e)=0
Adds an element matrix into the associated system matrix.
Base class for representing a system vector on different formats.
Definition: SystemMatrix.h:32
MatrixType
The available system matrix formats and associated solvers.
Definition: LinAlgenums.h:22
@ SPR
Sparse matrices / SPR solver.
Definition: LinAlgenums.h:24
StorageFormat
Enumeration of matrix storage formats.
Definition: LinAlgenums.h:43