NeoPZ
pzsbndmat.h
Go to the documentation of this file.
1 
7 #ifndef TSBNDMATH
8 #define TSBNDMATH
9 
10 #include "pzmatrix.h"
11 #include "pzfmatrix.h"
12 
13 #ifdef OOPARLIB
14 
15 #include "pzsaveable.h"
16 #include "pzmatdefs.h"
17 
18 #endif
19 
24 template<class TVar>
25 class TPZSBMatrix : public TPZMatrix<TVar>
26 {
27 public:
29  TPZMatrix<TVar>() , fDiag() { fBand = 0; }
30  TPZSBMatrix(const int64_t dim,const int64_t band );
32  TPZMatrix<TVar>(A) { Copy(A); }
33 
35 
37 
38  int PutVal(const int64_t row,const int64_t col,const TVar& element ) override;
39  const TVar &GetVal(const int64_t row,const int64_t col ) const override;
40 
41  TVar &operator()(int64_t row, int64_t col);
42 
44  virtual int IsSimetric() const override
45  {
46  return 1;
47  }
48 
49  friend class TPZSBMatrix<float>;
50  friend class TPZSBMatrix<double>;
51 
53  template<class TVar2>
55  {
57  fDiag.resize(orig.fDiag.size());
58  int64_t nel = fDiag.size();
59  for (int64_t el=0; el<nel; el++) {
60  fDiag[el] = orig.fDiag[el];
61  }
62  }
63 
66  void MultAdd(const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z,
67  const TVar alpha=1.,const TVar beta = 0.,const int opt = 0) const override;
68 
69  void Print(const char *name = NULL, std::ostream &out = std::cout ,const MatrixOutputFormat form = EFormatted) const override;
70  //friend std::ostream & operator<< <>(std::ostream& out,const TPZSBMatrix<TVar> &A); Leonardo removendo o '<>' antes do (std...
71  template<class TT>friend std::ostream & operator<< (std::ostream& out,const TPZSBMatrix<TT> &A);
72 
74  void AutoFill(int64_t nrow, int64_t ncol, int symmetric);
75 
76 
78  // @{
80  TPZSBMatrix operator+ (const TPZSBMatrix<TVar> &A ) const;
81  TPZSBMatrix operator- (const TPZSBMatrix<TVar> &A ) const;
84  // @}
85  TPZSBMatrix<TVar> operator* (const TVar v ) const;
86  TPZSBMatrix<TVar> &operator*=(const TVar v );
87 
88  TPZSBMatrix<TVar> operator-() const { return operator*(-1.0); }
89 
91  int Resize(const int64_t newDim ,const int64_t) override;
92 
94  int Redim(const int64_t newDim) {return Redim(newDim,newDim);}
95  int Redim(const int64_t newRows ,const int64_t newCols) override;
96 
98  int Zero() override;
99 
100  int64_t GetBand() const { return fBand; }
101  int SetBand(const int64_t newBand );
102 
104  // @{
105 #ifdef USING_LAPACK
106  int Decompose_Cholesky() override; // Faz A = GGt.
107  int Decompose_Cholesky(std::list<int64_t> &singular) override;
108 #endif
109 
110  int Subst_Forward( TPZFMatrix<TVar>*B ) const override;
111  int Subst_Backward ( TPZFMatrix<TVar> *b ) const override;
112 
113  int Decompose_LDLt(std::list<int64_t> &singular) override;
114  int Decompose_LDLt() override;
115  int Subst_LForward( TPZFMatrix<TVar> *B ) const override;
116  int Subst_LBackward( TPZFMatrix<TVar> *B ) const override;
117  int Subst_Diag( TPZFMatrix<TVar> *B ) const override;
118 // int Subst_Forward( TPZFMatrix<TVar>*B ) const;
119 // int Subst_Backward( TPZFMatrix<TVar> *B ) const;
120 
121  // @}
122 
123 #ifdef USING_LAPACK
124  /*** @name Solve eigenvalues ***/
127  // on exit the matrix contains the eigenvectors
133  int SolveEigenProblem(TPZVec < std::complex<double> > &w, TPZFMatrix < std::complex<double> > &eigenVectors);
137  int SolveEigenProblem(TPZVec < std::complex<double> > &w);
142  int SolveGeneralisedEigenProblem(TPZSBMatrix< TVar > &B , TPZVec < std::complex<double> > &w, TPZFMatrix < std::complex<double> > &eigenVectors);
146  int SolveGeneralisedEigenProblem(TPZSBMatrix< TVar > &B , TPZVec < std::complex<double> > &w);
147 
149 #endif
150  public:
151 int ClassId() const override;
152 
153 private:
154 
155  int64_t Size() const
156  {
157  return( this->Dim() * (fBand + 1) );
158  }
159 // int PutZero();
160  //static int Error(const char *msg1,const char* msg2="" ) ;
161  int Clear() override;
162  void Copy (const TPZSBMatrix<TVar> & );
163 
164  int64_t Index(int64_t i, int64_t j) const
165  {
166 #ifdef PZDEBUG
167  if (i>j) {
168  DebugStop();
169  }
170 #endif
171  return fBand+i-j+(fBand+1)*j;
172  }
174  int64_t fBand;
175 };
176 
177 #endif
int ClassId() const override
Define the class id associated with the class.
Definition: pzsbndmat.cpp:1989
void Copy(const TPZSBMatrix< TVar > &)
Definition: pzsbndmat.cpp:1288
int Redim(const int64_t newDim)
Redimension the matrix and zeroes its elements.
Definition: pzsbndmat.h:94
Implements symmetric band matrices. Matrix.
Definition: pzsbndmat.h:25
int Decompose_LDLt() override
Decomposes the current matrix using LDLt.
Definition: pzsbndmat.cpp:772
int64_t Size() const
Definition: pzsbndmat.h:155
TPZSBMatrix & operator-=(const TPZSBMatrix< TVar > &A)
Definition: pzsbndmat.cpp:445
~TPZSBMatrix()
Definition: pzsbndmat.h:36
virtual void resize(const int64_t newsize)
Definition: pzvec.h:213
void CopyFrom(TPZSBMatrix< TVar2 > &orig)
copy the values from a matrix with a different precision
Definition: pzsbndmat.h:54
TPZSBMatrix & operator=(const TPZSBMatrix< TVar > &A)
Operadores com matrizes SKY LINE.
Definition: pzsbndmat.cpp:380
int Clear() override
It clears data structure.
Definition: pzsbndmat.cpp:1275
MatrixOutputFormat
Defines output format.
Definition: pzmatrix.h:55
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
int64_t GetBand() const
Definition: pzsbndmat.h:100
TPZSBMatrix(const TPZSBMatrix< TVar > &A)
Definition: pzsbndmat.h:31
TVar & operator()(int64_t row, int64_t col)
Definition: pzsbndmat.cpp:311
TPZSBMatrix< TVar > & operator*=(const TVar v)
Definition: pzsbndmat.cpp:530
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
int Resize(const int64_t newDim, const int64_t) override
Redimension the matrix keeping original elements.
Definition: pzsbndmat.cpp:548
int64_t fBand
Definition: pzsbndmat.h:174
void CopyFrom(TPZMatrix< TVar2 > &copy)
Definition: pzmatrix.h:96
Contains TPZMatrixclass which implements full matrix (using column major representation).
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: pzsbndmat.cpp:244
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
TPZSBMatrix & operator+=(const TPZSBMatrix< TVar > &A)
Definition: pzsbndmat.cpp:427
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: pzsbndmat.cpp:1242
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: pzsbndmat.cpp:163
void AutoFill(int64_t nrow, int64_t ncol, int symmetric)
Definition: pzsbndmat.cpp:63
TPZVec< TVar > fDiag
Definition: pzsbndmat.h:173
int Subst_Forward(TPZFMatrix< TVar > *B) const override
To solve linear systems.
Definition: pzsbndmat.cpp:1163
TPZSBMatrix operator+(const TPZSBMatrix< TVar > &A) const
Definition: pzsbndmat.cpp:392
int SetBand(const int64_t newBand)
Definition: pzsbndmat.cpp:605
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
int Subst_Backward(TPZFMatrix< TVar > *b) const override
Computes B = Y, where A*Y = B, A is upper triangular.
Definition: pzsbndmat.cpp:1231
Contains TPZMatrix<TVar>class, root matrix class.
TPZSBMatrix< TVar > operator*(const TVar v) const
Definition: pzsbndmat.cpp:510
void Print(const char *name=NULL, std::ostream &out=std::cout, const MatrixOutputFormat form=EFormatted) const override
It prints the matrix data in a MatrixFormat Rows X Cols.
Definition: pzsbndmat.cpp:330
virtual int Decompose_Cholesky()
Decomposes the current matrix using Cholesky method. The current matrix has to be symmetric...
Definition: pzmatrix.cpp:1252
virtual int IsSimetric() const override
Checks if the current matrix is symmetric.
Definition: pzsbndmat.h:44
int Subst_Diag(TPZFMatrix< TVar > *B) const override
Computes B = Y, where A*Y = B, A is diagonal matrix.
Definition: pzsbndmat.cpp:1215
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: pzsbndmat.cpp:1178
#define CLONEDEF(A)
To create clone matrix.
Definition: pzmatrix.h:28
TPZSBMatrix< TVar > operator-() const
Definition: pzsbndmat.h:88
int Zero() override
Zeroes the elements of the matrix.
Definition: pzsbndmat.cpp:587
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
Computes z = beta * y + alpha * opt(this)*x.
Definition: pzsbndmat.cpp:460
int64_t Index(int64_t i, int64_t j) const
Definition: pzsbndmat.h:164
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60