NeoPZ
pzskylnsymmat.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 
3 #ifndef pzskylnsymmatH
4 #define pzskylnsymmatH
5 
6 //
7 // Author: Nathan Shauer.
8 //
9 // File: pzskylnsymmat
10 //
11 // Class: TPZSkylMatrix
12 //
13 // Obs.: This class manages non symmetric skylyne type matrix
14 //
15 //
16 // Versao: 12 / 2011.
17 //
18 
19 
20 #include "pzmatrix.h"
21 #include "pzfmatrix.h"
22 #include "pzvec.h"
23 #include "pzmanvector.h"
24 
25 
32 template<class TVar=REAL>
33 class TPZSkylNSymMatrix : public TPZMatrix<TVar>
34 {
35  public:
37  TPZMatrix<TVar>(0,0),fElem(0), fElemb(0), fStorage(0), fStorageb(0) { }
38 
39  TPZSkylNSymMatrix(const int64_t nrow, const int64_t ncol);
44  TPZSkylNSymMatrix(const int64_t dim ,const TPZVec<int64_t> &skyline);
45 
48  {
49  Copy(A);
50  }
51 
57  void SetSkyline(const TPZVec<int64_t> &skyline);
58 
62  int SkyHeight(int64_t col) { return fElem[col+1]-fElem[col] - 1; }
63 
67  //void AddSameStruct(TPZSkylNSymMatrix &B, double k = 1.);
68 
70  virtual int IsSimetric() const override {return 0;}
71 
72  virtual ~TPZSkylNSymMatrix() { Clear(); }
73 
74  int PutVal(const int64_t row,const int64_t col,const TVar &element ) override;
75 
76  const TVar &GetVal(const int64_t row,const int64_t col ) const override;
77 
78 
80  const TVar &GetValSup(const int64_t row,const int64_t col ) const;
81 
83  const TVar &GetValB(const int64_t row,const int64_t col ) const;
84 
85 
86  TVar &operator()(const int64_t row, const int64_t col);
87  virtual TVar &s(const int64_t row, const int64_t col) override;
88 
89 
90  TVar &operator()(const int64_t row);
91 
92  virtual void MultAdd(const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z,
93  const TVar alpha,const TVar beta ,const int opt = 0) const override;
94 
95 
97  virtual void UpdateFrom(TPZAutoPointer<TPZMatrix<TVar> > mat) override;
98 
99  // Operadores com matrizes SKY LINE.
100  //TPZSkylNSymMatrix &operator= (const TPZSkylNSymMatrix &A );
101  //TPZSkylMatrix &operator= (TTempMat<TPZSkylMatrix> A);
102 
103  //TPZSkylNSymMatrix operator+ (const TPZSkylNSymMatrix &A ) const;
104  //TPZSkylNSymMatrix operator- (const TPZSkylNSymMatrix &A ) const;
105 
106  //TPZSkylNSymMatrix &operator+=(const TPZSkylNSymMatrix &A );
107  //TPZSkylNSymMatrix &operator-=(const TPZSkylNSymMatrix &A );
108 
109  // Operadores com valores NUMERICOS.
110  //TPZSkylNSymMatrix operator* (const REAL v ) const;
111  //TPZSkylNSymMatrix &operator*=( REAL v );
112 
113  //TPZSkylNSymMatrix operator-() const;// { return operator*(-1.0); }
114 
115  // Redimensiona a matriz, mas mantem seus elementos.
116  // o segundo parametro � o tamanho das colunas
117  //int Resize(const int newDim ,const int );
118 
119  // Redimensiona a matriz e ZERA seus elementos.
120  // o segundo parametro � o tamanho das colunas
121  //int Redim(const int newDim ,const int );
122  //int Redim(const int newDim) {return Redim(newDim,newDim);}
123 
124  // Zera os Elementos da matriz
125  //int Zero();
126 
127 
128  /*** Resolucao de sistemas ***/
129 
130  int Decompose_LU() override; // Faz A = LU.
131 
132  //virtual void SolveSOR(int &numiterations,const TPZFMatrix &F, TPZFMatrix &result,
133  // TPZFMatrix *residual,TPZFMatrix &scratch,const REAL overrelax, REAL &tol,
134  // const int FromCurrent = 0,const int direction = 1) ;
135 
136 
137  //int Subst_Forward ( TPZFMatrix *b ) const override;
138  int Subst_Backward ( TPZFMatrix<TVar> *b ) const override;
139  int Subst_LForward ( TPZFMatrix<TVar> *b ) const override;
140  //int Subst_LBackward( TPZFMatrix *b ) const override;
141  //int Subst_Diag ( TPZFMatrix *b ) const override;
142 
143  //void TestSpeed(int col, int prevcol);
144 
148  public:
149 int ClassId() const override;
150 
156  void Read(TPZStream &buf, void *context) override;
162  void Write(TPZStream &buf, int withclassid) const override;
163 
166  void AutoFill(int64_t nrow, int64_t ncol, int symmetric);
167 
168 
169  protected:
170 
174  TVar *Diag(int64_t col) { return fElem[col];}
175 
176  //void DecomposeColumn(int col, int prevcol);
177  //void DecomposeColumn(int col, int prevcol, std::list<int64_t> &singular);
178 
179  //void DecomposeColumn2(int col, int prevcol);
180  private:
181 
182  // Aloca uma nova coluna. 'fDiag[col].pElem' deve ser NULL.
183 
184 //static int Error(const char *msg1,const char* msg2="" );
185  int Clear() override;
186  void Copy (const TPZSkylNSymMatrix & );
187  int Size(const int64_t column) const {return fElem[column+1]-fElem[column];}
188  static int64_t NumElements(const TPZVec<int64_t> &skyline);
189  static void InitializeElem(const TPZVec<int64_t> &skyline, TPZManVector<TVar> &storage, TPZVec<TVar *> &elem);
193  static void ComputeMaxSkyline(const TPZSkylNSymMatrix &first, const TPZSkylNSymMatrix &second, TPZVec<int> &res);
194 
196  virtual int Zero() override {
197  fStorage.Fill(0.);
198  fStorageb.Fill(0.);
199  return 1;
200  }
201 
202 
203 protected:
210 
218 
219 private:
224 
229 };
230 
231 /*
232 template<int N>
233 inline REAL TemplateSum(const REAL *p1, const REAL *p2){
234  return *p1* *p2 + TemplateSum<N-1>(p1+1,p2+1);
235 
236 }
237 
238 
239 template<>
240 inline REAL TemplateSum<1>(const REAL *p1, const REAL *p2){
241  return *p1 * *p2;
242 }
243 
244 */
245 
246 //---------------------------------------------------------------------------
247 
248 template<class TVar>
250  return Hash("TPZSkylNSymMatrix") ^ TPZMatrix<TVar>::ClassId() << 1;
251 }
252 #endif
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
virtual TVar & s(const int64_t row, const int64_t col) override
The operators check on the bounds if the DEBUG variable is defined.
const TVar & GetValB(const int64_t row, const int64_t col) const
Pega o valor abaixo da diagonal (below)
TVar & operator()(const int64_t row, const int64_t col)
int ClassId() const override
Return the id of the matrix defined pzmatrixid.h.
const TVar & GetValSup(const int64_t row, const int64_t col) const
Pega o valor na diagonal ou parte de cima da diagonal.
Templated vector implementation.
virtual void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar alpha, const TVar beta, const int opt=0) const override
It computes z = beta * y + alpha * opt(this)*x but z and x can not overlap in memory.
void Copy(const TPZSkylNSymMatrix &)
Implements a skyline storage format.
Definition: pzskylnsymmat.h:33
int Clear() override
const TVar & GetVal(const int64_t row, const int64_t col) const override
int Decompose_LU() override
TPZManVector< TVar > fStorage
TPZSkylNSymMatrix(const TPZSkylNSymMatrix &A)
Definition: pzskylnsymmat.h:46
int SkyHeight(int64_t col)
Definition: pzskylnsymmat.h:62
int PutVal(const int64_t row, const int64_t col, const TVar &element) override
void SetSkyline(const TPZVec< int64_t > &skyline)
Contains TPZMatrixclass which implements full matrix (using column major representation).
virtual int Zero() override
Zeroes the matrix.
Free store vector implementation.
static int64_t NumElements(const TPZVec< int64_t > &skyline)
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > > mat) override
Updates the values of the matrix based on the values of the matrix.
virtual int IsSimetric() const override
Definition: pzskylnsymmat.h:70
string res
Definition: test.py:151
static void ComputeMaxSkyline(const TPZSkylNSymMatrix &first, const TPZSkylNSymMatrix &second, TPZVec< int > &res)
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.
TPZVec< TVar * > fElem
int Subst_Backward(TPZFMatrix< TVar > *b) const override
TPZVec< TVar * > fElemb
void AutoFill(int64_t nrow, int64_t ncol, int symmetric)
Fill matrix storage with randomic values.
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
TVar * Diag(int64_t col)
void Fill(const T &copy, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Definition: pzvec.h:460
int Size(const int64_t column) const
TPZManVector< TVar > fStorageb
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 ~TPZSkylNSymMatrix()
Definition: pzskylnsymmat.h:72
static void InitializeElem(const TPZVec< int64_t > &skyline, TPZManVector< TVar > &storage, TPZVec< TVar *> &elem)
int Subst_LForward(TPZFMatrix< TVar > *b) const override
int ClassId() const override
Define the class id associated with the class.
Definition: pzmatrix.h:957
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60
This class implements a reference counter mechanism to administer a dynamically allocated object...