NeoPZ
pzsfulmat.h
Go to the documentation of this file.
1 
6 #ifndef _TSFULMATHH_
7 #define _TSFULMATHH_
8 
9 #include "pzmatrix.h"
10 #include "pzfmatrix.h"
11 
12 #ifdef OOPARLIB
13 
14 #include "pzsaveable.h"
15 #include "pzmatdefs.h"
16 
17 #endif
18 
23 template<class TVar>
24 class TPZSFMatrix : public TPZMatrix<TVar> {
25 
26 public:
28  TPZMatrix<TVar>( 0,0 ) { fElem = NULL; }
29  TPZSFMatrix (const int64_t dim );
30  TPZSFMatrix (const TPZSFMatrix<TVar> & );
31  // Usa o maior bloco quadrado possivel, comecado em (0,0).
32  // E inicializa com a parte triangular inferior do bloco.
33  TPZSFMatrix (const TPZMatrix<TVar> & );
34 
36 
37  ~TPZSFMatrix();
38 
40  virtual int IsSimetric() const override {
41  return 1;
42  }
43 
44  friend class TPZSFMatrix<float>;
45  friend class TPZSFMatrix<double>;
46 
48  template<class TVar2>
50  {
51  Resize(orig.Rows(), orig.Cols());
53  int64_t nel = (this->Rows()*(this->Rows()+1))/2;
54  for (int64_t el=0; el<nel; el++) {
55  fElem[el] = orig.fElem[el];
56  }
57  }
58 
59 
60  int PutVal(const int64_t row,const int64_t col,const TVar &value ) override;
61  const TVar &GetVal(const int64_t row,const int64_t col ) const override;
62 
68  TPZSFMatrix operator+ (const TPZSFMatrix<TVar> &A ) const;
69  TPZSFMatrix operator- (const TPZSFMatrix<TVar> &A ) const;
79  TPZSFMatrix operator+ (const TPZMatrix<TVar> &A ) const;
80  TPZSFMatrix operator- (const TPZMatrix<TVar> &A ) const;
89  TPZSFMatrix &operator= (const TVar val );
90  TPZSFMatrix operator+ (const TVar val ) const;
91  TPZSFMatrix operator- (const TVar val ) const { return operator+( -val ); }
92  TPZSFMatrix operator* (const TVar val ) const;
93  TPZSFMatrix &operator+=(const TVar val );
94  TPZSFMatrix &operator-=(const TVar val ) { return operator+=( -val ); }
95  TPZSFMatrix &operator*=(const TVar val );
98  TPZSFMatrix operator-() const { return operator*( -1.0 ); }
99 
101  int Resize(const int64_t newDim, const int64_t ) override;
102 
104  int Redim(const int64_t newRows ,const int64_t) override;
105 
106  int Redim(const int64_t newDim) {return Redim(newDim,newDim);}
107 
109  int Zero() override;
110 
111 
112  /***
113  * @name To solve linear systems
114  * @{
115  */
116  virtual int Decompose_Cholesky() override;
117  virtual int Decompose_LDLt() override;
118  virtual int Decompose_Cholesky(std::list<int64_t> &singular) override;
119  virtual int Decompose_LDLt(std::list<int64_t> &singular) override;
120 
121  virtual int Subst_Forward ( TPZFMatrix<TVar> *B ) const override;
122  virtual int Subst_Backward ( TPZFMatrix<TVar> *B ) const override;
123  virtual int Subst_LForward ( TPZFMatrix<TVar> *B ) const override;
124  virtual int Subst_LBackward( TPZFMatrix<TVar> *B ) const override;
125  virtual int Subst_Diag ( TPZFMatrix<TVar> *B ) const override;
128 #ifdef OOPARLIB
129  virtual int Unpack( TReceiveStorage *buf );
130  static TSaveable *Restore(TReceiveStorage *buf);
131  virtual int Pack( TSendStorage *buf ) const;
132  virtual std::string ClassName() const { return( "TPZSFMatrix"); }
133  virtual int DerivedFrom(const int64_t Classid) const;
134  virtual int DerivedFrom(const char *classname) const;
135 
136 #endif
137  public:
138 int ClassId() const override;
139 
140 private:
141 
142  int64_t Size() const { return (this->Dim() * (this->Dim()+1)) >> 1; }
143 
144  int Clear() override;
145 
146  TVar *fElem;
147 };
148 
149 /**************/
150 /*** PutVal ***/
151 template<class TVar>
152 inline int
153 TPZSFMatrix<TVar> ::PutVal(const int64_t row,const int64_t col,const TVar &value )
154 {
155  int64_t locrow = row, loccol = col;
156  if ( locrow < loccol )
157  this->Swap( &locrow, &loccol );
158 
159  this->fDecomposed = 0;
160  this->fElem[ ((locrow*(locrow+1)) >> 1) + loccol ] = value;
161  return( 1 );
162 }
163 
164 /**************/
165 /*** GetVal ***/
166 template<class TVar>
167 inline const TVar &
168 TPZSFMatrix<TVar> ::GetVal(const int64_t row,const int64_t col ) const
169 {
170  int64_t locrow(row),loccol(col);
171  if ( locrow < loccol )
172  this->Swap( &locrow, &loccol );
173 
174  return( fElem[ ((locrow*(locrow+1)) >> 1) + loccol ] );
175 }
176 
177 /**************************/
178 /*** @name Operadores Globais ***/
182 template<class TVar>
183 inline TPZSFMatrix<TVar>
184 operator+( const TVar value, const TPZSFMatrix<TVar> &A )
185 {
186  return( A + value );
187 }
188 
190 template<class TVar>
191 inline TPZSFMatrix<TVar>
192 operator-( const TVar value,const TPZSFMatrix<TVar> &A )
193 {
194  return( A - value );
195 }
196 
198 template<class TVar>
199 inline TPZSFMatrix<TVar>
200 operator*( const TVar value, const TPZSFMatrix<TVar> &A )
201 {
202  return( A * value );
203 }
204 
207 #endif
int64_t Size() const
Definition: pzsfulmat.h:142
int Zero() override
Resets all elements.
Definition: pzsfulmat.cpp:510
virtual int Subst_Forward(TPZFMatrix< TVar > *B) const override
Computes B = Y, where A*Y = B, A is lower triangular.
Definition: pzsfulmat.cpp:635
TPZSFMatrix operator*(const TVar val) const
Definition: pzsfulmat.cpp:390
int Clear() override
It clears data structure.
Definition: pzsfulmat.cpp:820
TPZSFMatrix & operator-=(const TVar val)
Definition: pzsfulmat.h:94
virtual int Decompose_LDLt() override
Decomposes the current matrix using LDLt.
Definition: pzsfulmat.cpp:592
char fDecomposed
Decomposition type used to decompose the current matrix.
Definition: pzmatrix.h:783
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
virtual int Subst_Backward(TPZFMatrix< TVar > *B) const override
Computes B = Y, where A*Y = B, A is upper triangular.
Definition: pzsfulmat.cpp:671
TPZSFMatrix & operator-=(const TPZSFMatrix< TVar > &A)
Definition: pzsfulmat.cpp:206
TPZSFMatrix operator-() const
Definition: pzsfulmat.h:98
int Redim(const int64_t newDim)
Definition: pzsfulmat.h:106
int PutVal(const int64_t row, const int64_t col, const TVar &value) override
Put values without bounds checking This method is faster than "Put" if DEBUG is defined.
Definition: pzsfulmat.h:153
virtual int IsSimetric() const override
Checks if the current matrix is symmetric.
Definition: pzsfulmat.h:40
void CopyFrom(TPZMatrix< TVar2 > &copy)
Definition: pzmatrix.h:96
Contains TPZMatrixclass which implements full matrix (using column major representation).
virtual int Subst_Diag(TPZFMatrix< TVar > *B) const override
Computes B = Y, where A*Y = B, A is diagonal matrix.
Definition: pzsfulmat.cpp:778
TPZSFMatrix & operator*=(const TVar val)
Definition: pzsfulmat.cpp:427
TPZSFMatrix & operator+=(const TPZSFMatrix< TVar > &A)
Definition: pzsfulmat.cpp:184
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
virtual int Subst_LBackward(TPZFMatrix< TVar > *B) const override
Computes B = Y, where A*Y = B, A is upper triangular with A(i,i)=1.
Definition: pzsfulmat.cpp:741
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
virtual int64_t Dim() const
Returns the dimension of the matrix if the matrix is square.
Definition: pzmatrix.h:892
void CopyFrom(TPZSFMatrix< TVar2 > &orig)
copy the values from a matrix with a different precision
Definition: pzsfulmat.h:49
Contains TPZMatrix<TVar>class, root matrix class.
virtual int Decompose_Cholesky() override
Decomposes the current matrix using Cholesky method. The current matrix has to be symmetric...
Definition: pzsfulmat.cpp:533
TPZSFMatrix & operator=(const TPZSFMatrix< TVar > &A)
Definition: pzsfulmat.cpp:102
int Resize(const int64_t newDim, const int64_t) override
Resize the array but keeps its entirety.
Definition: pzsfulmat.cpp:443
static void Swap(int64_t *a, int64_t *b)
Swaps contents of a in b and b in a.
Definition: pzmatrix.h:949
TVar * fElem
Definition: pzsfulmat.h:146
virtual int Subst_LForward(TPZFMatrix< TVar > *B) const override
Computes B = Y, where A*Y = B, A is lower triangular with A(i,i)=1.
Definition: pzsfulmat.cpp:707
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: pzsfulmat.h:168
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
#define CLONEDEF(A)
To create clone matrix.
Definition: pzmatrix.h:28
TPZSFMatrix operator+(const TPZSFMatrix< TVar > &A) const
Definition: pzsfulmat.cpp:137
Implements a symmetric full matrix. Matrix.
Definition: pzsfulmat.h:24
int Redim(const int64_t newRows, const int64_t) override
Resize the array and resets ist entirety.
Definition: pzsfulmat.cpp:483
int ClassId() const override
Define the class id associated with the class.
Definition: pzsfulmat.cpp:873
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60