NeoPZ
pzespmat.h
Go to the documentation of this file.
1 
6 #ifndef TESPMATH
7 #define TESPMATH
8 
9 #include "pzlink.h"
10 #include "pzmatrix.h"
11 #include "pzfmatrix.h"
12 
13 #ifdef WORKPOOL
14 
15 #include "pzworkpool.h"
16 
17 #endif
18 
19 #ifdef OOPARLIB
20 
21 #include "pzsaveable.h"
22 #include "pzmatdefs.h"
23 
24 #endif
25 
26 template<class TVar>
28 
36 template<class TVar>
37 class TPZSpMatrix : public TPZMatrix<TVar>
38 {
39  friend class TPZSSpMatrix<TVar>;
40 
41 public:
42 
49  struct TPZNode
50  {
51  REAL elem;
52  int64_t col;
53  };
54 
55 public:
59  TPZMatrix<TVar>( 0, 0 ) { fElem = NULL; }
65  TPZSpMatrix ( int64_t rows, int64_t cols );
72  TPZMatrix<TVar>( A ) { fCopy( &A ); }
73 
76  ~TPZSpMatrix();
77 
78  int Put(const int64_t row,const int64_t col,const TVar & value ) override;
79  const TVar &Get(const int64_t row,const int64_t col ) const override;
80 
81  // Nao verifica limites da matriz (e' mais rapido).
82  int PutVal(const int64_t row,const int64_t col,const TVar & element ) override;
83  const TVar &GetVal(const int64_t row,const int64_t col ) const override;
84 
92  TPZSpMatrix operator+ (const TPZSpMatrix<TVar> &A ) const;
93  TPZSpMatrix operator- (const TPZSpMatrix<TVar> &A ) const;
96 
104  //TPZSpMatrix & operator= (const TPZMatrix<TVar> & A );
105 
108  virtual void MultAdd(const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z,
109  const REAL alpha ,const REAL beta = 0.,const int opt = 0) const override;
110 
111 
118  TPZSpMatrix operator* (const TVar v ) const;
119  TPZSpMatrix &operator*=(const TVar v );
120 
121  TPZSpMatrix operator-() const { return operator*(-1.0); }
122 
125  TPZSpMatrix &Reset();
127 
129  int Resize(const int64_t newRows,const int64_t newCols ) override;
134  int Resize(const int64_t newDim ) { return Resize( newDim, newDim ); }
135 
137  int Redim(const int64_t newRows,const int64_t newCols ) override;
142  int Redim(const int64_t newDim ) { return Redim( newDim, newDim ); }
143 
145  int Zero() override;
146 
147  /*** Resolucao de sistemas ***/
148 
149 #ifdef OOPARLIB
150 
151  virtual int Unpack( TReceiveStorage *buf );
152  static TSaveable *CreateInstance(TReceiveStorage *buf);
153  inline virtual int Pack( TSendStorage *buf ) const;
154  virtual std::string ClassName() const { return( "TPZSpMatrix" ); }
155  virtual int DerivedFrom(const int64_t Classid) const;
156  virtual int DerivedFrom(const char *classname) const;
157 
158 #endif
159  public:
160 int ClassId() const override;
161 
162 protected:
163 
166  int fAdd(const TPZSpMatrix<TVar> *const A ); // operator +=
167 // int fAdd(const TPZSpMatrix<TVar> *A, TPZSpMatrix<TVar> *B ); // operator +
168 
169  int fSub(const TPZSpMatrix<TVar> *const A ); // operator -=
170 // int fSub( TPZSpMatrix<TVar> *A, TPZSpMatrix<TVar> *B ); // operator -
171 
172  int fCopy(const TPZSpMatrix<TVar> *const A ); // operator =
173 
174  int fMult( TVar val ); // operator *
175 
177  inline void Swap( int64_t *a, int64_t *b );
178 
179  int Clear() override { delete [] fElem; return ( 1 );}
180 
188  REAL ProdEsc( TPZLink<TPZNode> *row_i, TPZLink<TPZNode> *row_j,
189  int64_t k );
190 
191 
193 
194 #ifdef WORKPOOL
195  TPZWorkPool fWp;
196 #endif
197 };
198 
199 /*** Swap ***/
200 template<class TVar>
201 inline void
202 TPZSpMatrix<TVar>::Swap( int64_t *a, int64_t *b )
203 {
204  int64_t c = *a;
205  *a = *b;
206  *b = c;
207 }
208 
209 #include "pzsespmat.h"
210 
211 #endif
TPZSpMatrix & operator-=(const TPZSpMatrix< TVar > &A)
Definition: pzespmat.cpp:232
TPZLink< TPZNode > * fElem
Definition: pzespmat.h:192
void Swap(int64_t *a, int64_t *b)
Definition: pzespmat.h:202
int fSub(const TPZSpMatrix< TVar > *const A)
Definition: pzespmat.cpp:419
int fCopy(const TPZSpMatrix< TVar > *const A)
Definition: pzespmat.cpp:496
const TVar & GetVal(const int64_t row, const int64_t col) const override
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
Definition: pzespmat.cpp:141
int Clear() override
It clears data structure.
Definition: pzespmat.h:179
int fMult(TVar val)
Definition: pzespmat.cpp:517
Contains TPZSSpMatrix class which implements sparse symmetric matrix using a linked list of elements...
TPZSpMatrix()
Simple constructor.
Definition: pzespmat.h:57
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
int Resize(const int64_t newDim)
Redimensions current matrix keeping its elements.
Definition: pzespmat.h:134
Defines sparce matrix class. Matrix.
Definition: pzespmat.h:37
int Redim(const int64_t newDim)
Redimensions matrix deleting all its elements.
Definition: pzespmat.h:142
virtual void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const REAL alpha, const REAL beta=0., const int opt=0) const override
Definition: pzespmat.cpp:597
Implements sparce symmetric matrix using a linked list of elements. Matrix.
Definition: pzespmat.h:27
Defines a node.
Definition: pzespmat.h:49
Contains TPZMatrixclass which implements full matrix (using column major representation).
~TPZSpMatrix()
Simple destructor.
Definition: pzespmat.cpp:49
TPZSpMatrix & operator=(const TPZSpMatrix< TVar > &A)
Generic overloaded operator.
Definition: pzespmat.cpp:174
int Zero() override
Zeroes all elements of the matrix.
Definition: pzespmat.cpp:330
static TPZSavable * CreateInstance(const int &classId)
Definition: TPZSavable.cpp:120
TPZSpMatrix & Reset()
Desallocate all the elements of the matrix.
Definition: pzespmat.cpp:273
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
const TVar & Get(const int64_t row, const int64_t col) const override
Get value with bound checking.
Definition: pzespmat.cpp:75
Contains TPZMatrix<TVar>class, root matrix class.
TPZSpMatrix & operator+=(const TPZSpMatrix< TVar > &A)
Definition: pzespmat.cpp:218
int fAdd(const TPZSpMatrix< TVar > *const A)
Definition: pzespmat.cpp:346
TPZSpMatrix operator+(const TPZSpMatrix< TVar > &A) const
Definition: pzespmat.cpp:188
REAL ProdEsc(TPZLink< TPZNode > *row_i, TPZLink< TPZNode > *row_j, int64_t k)
Computes dot product with respect to lines row_i e row_j using only elements that belongs to columns ...
Definition: pzespmat.cpp:544
int Put(const int64_t row, const int64_t col, const TVar &value) override
Put values with bounds checking if DEBUG variable is defined.
Definition: pzespmat.cpp:60
TPZSpMatrix operator-() const
Definition: pzespmat.h:121
#define CLONEDEF(A)
To create clone matrix.
Definition: pzmatrix.h:28
TPZSpMatrix & operator*=(const TVar v)
Definition: pzespmat.cpp:256
int PutVal(const int64_t row, const int64_t col, const TVar &element) override
Put values without bounds checking This method is faster than "Put" if DEBUG is defined.
Definition: pzespmat.cpp:94
int ClassId() const override
Define the class id associated with the class.
Definition: pzespmat.cpp:714
TPZSpMatrix(const TPZSpMatrix< TVar > &A)
Copy constructor.
Definition: pzespmat.h:70
TPZSpMatrix operator*(const TVar v) const
Numerical values operator.
Definition: pzespmat.cpp:244
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension the matrix to newRows x newCols arrange and zeroes its elements.
Definition: pzespmat.cpp:316
int Resize(const int64_t newRows, const int64_t newCols) override
Redimension the matrix to newRows x newCols arrange.
Definition: pzespmat.cpp:288
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60