NeoPZ
tpzverysparsematrix.h
Go to the documentation of this file.
1 
5 #ifndef TPZVERYSPARSEMATRIX_H
6 #define TPZVERYSPARSEMATRIX_H
7 
8 #include <iostream>
9 #include <map>
10 
11 #include "pzmatrix.h"
12 
14 #define TPZVERYSPARSEMATRIX_ID 28291001;
15 
16 template <class TVar>
17 class TPZFMatrix;
18 
19 template <class TVar>
20 class TPZFYsmpMatrix;
21 
27 template<class TVar>
28 class TPZVerySparseMatrix: public TPZMatrix<TVar>
29 {
30 public:
31 
32  friend class TPZFYsmpMatrix<TVar>;
33 
35 
36  TPZVerySparseMatrix(int64_t rows, int64_t cols) :
38  TPZMatrix<TVar>(rows, cols)
39  {
40  }
41  TPZVerySparseMatrix(int64_t rows, int64_t cols, TVar val) :
43  TPZMatrix<TVar>(rows, cols)
44  {
45  }
46 
47  virtual ~TPZVerySparseMatrix();
48 
52  {
53  }
54 
56 
58  void Simetrize() override;
59 
61  int PutVal(const int64_t row, const int64_t col, const TVar &val) override;
62 
64  virtual const TVar &GetVal(const int64_t row, const int64_t col) const override;
65 
71  virtual TVar &s(const int64_t row, const int64_t col) override
72  {
73 #ifdef PZDEBUG
74  if(row >= this->Rows() || row<0 || col >= this->Cols() || col<0)
75  {
76  this->Error("TPZFMatrix::operator() "," Index out of bounds");
77  DebugStop();
78  }
79 #endif
80  return fExtraSparseData[std::pair<int64_t, int64_t>(row, col)];
81  }
82 
84 
85 
94  virtual void MultAdd(const TPZFMatrix<TVar> & x, const TPZFMatrix<TVar> & y,
95  TPZFMatrix<TVar> & z, const TVar alpha = 1, const TVar beta = 0,
96  const int opt = 0) const override;
97 
99  virtual void Transpose(TPZVerySparseMatrix<TVar>* T) const;
100  virtual void Transpose(TPZMatrix<TVar>*const T) const override {
102  }
103 
105  public:
106 int ClassId() const override;
107 
108  void Write(TPZStream &buf, int withclassid) const override;
109  void Read(TPZStream &buf, void *context) override;
110 
111  typename std::map <std::pair<int64_t, int64_t>, TVar>::const_iterator MapBegin() const { return fExtraSparseData.begin(); }
112  typename std::map <std::pair<int64_t, int64_t>, TVar>::const_iterator MapEnd() const { return fExtraSparseData.end(); }
113 
114 private:
116  void WriteMap(TPZStream &buf, int withclassid, const std::map<std::pair<int64_t, int64_t>, TVar> & TheMap) const;
117  void ReadMap(TPZStream &buf, void *context, std::map<std::pair<int64_t, int64_t>, TVar> & TheMap);
118 
119 protected:
120 
122  std::map<std::pair<int64_t, int64_t>, TVar> fExtraSparseData;
123 
124 };
125 
126 template<class TVar>
128  return Hash("TPZVerySparseMatrix") ^ TPZMatrix<TVar>::ClassId() << 1;
129 }
130 
131 #endif
TPZVerySparseMatrix(int64_t rows, int64_t cols, TVar val)
virtual void Transpose(TPZMatrix< TVar > *const T) const
It makes *T the transpose of current matrix.
Definition: pzmatrix.cpp:697
void WriteMap(TPZStream &buf, int withclassid, const std::map< std::pair< int64_t, int64_t >, TVar > &TheMap) const
Auxiliary functions only reading and writing a map as the third paremeter.
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
Definition: pzmatrix.cpp:1402
std::map< std::pair< int64_t, int64_t >, TVar > fExtraSparseData
Save elements different from zero, of Sparse matrix.
Implements a non symmetric sparse matrix (Yale Sparse Matrix Storage). Matrix.
Definition: pzysmp.h:45
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
virtual void Transpose(TPZMatrix< TVar > *const T) const override
It makes *T the transpose of current matrix.
virtual const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values checking bounds.
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
void ReadMap(TPZStream &buf, void *context, std::map< std::pair< int64_t, int64_t >, TVar > &TheMap)
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
Implements a matrix whose nonzero elements are stored in binary tree. Matrix.
Definition: pzfmatrix.h:33
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
TPZVerySparseMatrix(int64_t rows, int64_t cols)
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
Contains TPZMatrix<TVar>class, root matrix class.
void Simetrize() override
Simetrizes copies the data of the matrix to make its data simetric.
int PutVal(const int64_t row, const int64_t col, const TVar &val) override
Put values checking bounds.
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
#define CLONEDEF(A)
To create clone matrix.
Definition: pzmatrix.h:28
virtual void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha=1, const TVar beta=0, const int opt=0) const override
It computes z = beta * y + alpha * opt(this)*x but z and x can not overlap in memory.
virtual TVar & s(const int64_t row, const int64_t col) override
The operators check on the bounds if the DEBUG variable is defined.
std::map< std::pair< int64_t, int64_t >, TVar >::const_iterator MapEnd() const
TPZVerySparseMatrix(const TPZVerySparseMatrix< TVar > &copy)
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
int ClassId() const override
Saveable methods.
std::map< std::pair< int64_t, int64_t >, TVar >::const_iterator MapBegin() const
int ClassId() const override
Define the class id associated with the class.
Definition: pzmatrix.h:957
virtual void Transpose(TPZVerySparseMatrix< TVar > *T) const
It makes *T the transpose of current matrix.
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60