NeoPZ
pzbndmat.h
Go to the documentation of this file.
1 
6 #ifndef _TBNDMATHH_
7 #define _TBNDMATHH_
8 
9 #include "pzmatrix.h"
10 
11 #ifdef OOPARLIB
12 
13 #include "pzsaveable.h"
14 #include "pzmatdefs.h"
15 
16 #endif
17 
24 template<class TVar>
25 class TPZFBMatrix : public TPZMatrix<TVar>
26 {
27 
28 public:
29  virtual int Substitution(TPZFMatrix<TVar> *B) const override;
31  TPZFBMatrix ();
37  TPZFBMatrix (const int64_t dim,const int64_t band_width = 0 );
39  TPZFBMatrix (const TPZFBMatrix<TVar> & );
40 
43  ~TPZFBMatrix();
44 
45  friend class TPZFBMatrix<float>;
46  friend class TPZFBMatrix<double>;
47 
49  template<class TVar2>
51  {
53  fBandLower = orig.fBandLower;
54  fBandUpper = orig.fBandUpper;
55  fElem.resize(orig.fElem.size());
56  int64_t nel = fElem.size();
57  for (int64_t el=0; el<nel; el++) {
58  fElem[el] = orig.fElem[el];
59  }
60 #ifdef USING_LAPACK
61  fPivot = orig.fPivot;
62  int64_t nwork = orig.fWork.size();
63  for (int64_t el=0; el<nwork; el++) {
64  fWork[el] = orig.fWork[el];
65  }
66 #endif
67 
68  }
69 
70 
71 
72  void AutoFill(int64_t nrow, int64_t ncol, int symmetric);
73 
74 
75  int Put(const int64_t row,const int64_t col,const TVar& value ) override;
76  const TVar &Get(const int64_t row,const int64_t col ) const override;
77 
78  TVar &operator()(const int64_t row, const int64_t col);
79  virtual TVar &s(const int64_t row, const int64_t col) override;
80 
81  inline int PutVal(const int64_t row,const int64_t col,const TVar& value ) override;
82  inline const TVar &GetVal(const int64_t row,const int64_t col ) const override;
83 
84  void MultAdd(const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z,
85  const TVar alpha=1,const TVar beta = 0,const int opt = 0) const override;
86  // Computes z = beta * y + alpha * opt(this)*x
87  // z and x cannot overlap in memory
88 
89  // Peforms the product (*this)T x D x (*this).
90  // TPZFBMatrix InnerProd(TPZFBMatrix &D );
91 
93  TPZFBMatrix operator+ (const TPZFBMatrix<TVar> & A ) const;
94  TPZFBMatrix operator- (const TPZFBMatrix<TVar> & A ) const;
97 
98  TPZFBMatrix operator* (const TVar val ) const;
99  TPZFBMatrix &operator*=(const TVar val );
100 
101  TPZFBMatrix operator-() const;
102 
103  int64_t Dim() const override { return this->Rows(); }
105  int64_t GetBandLower() const
106  {
107  return fBandLower;
108  }
109  int64_t GetBandUpper() const
110  {
111  return fBandUpper;
112  }
113  int64_t GetBand() const
114  {
115  if (fBandLower != fBandUpper) {
116  DebugStop();
117  }
118  return fBandUpper;
119  }
124  int SetBand(const int64_t newBand );
125 
127  int Resize(const int64_t newRows,const int64_t newCols ) override;
128 
130  int Redim(const int64_t newRows,const int64_t newCols ) override;
131 
132  // Zeroes the elements of the matrix
133  int Zero() override;
134 
135  void Transpose(TPZMatrix<TVar> *const T) const override;
136 
137 #ifdef USING_LAPACK
138  int Decompose_LU(std::list<int64_t> &singular) override;
139  int Decompose_LU() override;
140 #endif
141 
142  public:
143 int ClassId() const override;
144 
145 
146 private:
147 
148  int64_t Index(int64_t i, int64_t j) const
149  {
150  return fBandLower+fBandUpper+i-j+(fBandUpper+2*fBandLower+1)*j;
151  }
152  int Clear() override;
153 
156 #ifdef USING_LAPACK
157  TPZManVector<int,5> fPivot;
158 
159  TPZVec<TVar> fWork;
160 #endif
161 
162 };
163 
164 
165 
166 /**************/
167 /*** PutVal ***/
168 template<class TVar>
169 inline int
170 TPZFBMatrix<TVar>::PutVal(const int64_t row,const int64_t col,const TVar& value )
171 {
172  if ( (col-row <=fBandUpper) && (row-col <= fBandLower) )
173  {
174  int64_t index = Index(row,col);
175  fElem[index] = value;
176  }
177  else if(!IsZero(value))
178  {
179  DebugStop();
180  }
181  return( 1 );
182 }
183 
184 
185 
186 /**************/
187 /*** GetVal ***/
188 template<class TVar>
189 inline const TVar &
190 TPZFBMatrix<TVar>::GetVal(const int64_t row,const int64_t col ) const {
191 #ifdef PZDEBUG
192  if (row <0 || row > this->fRow || col < 0 || col >= this->fCol) {
193  DebugStop();
194  }
195 #endif
196  if ( (col-row <=fBandUpper) && (row-col <= fBandLower) )
197  {
198  return fElem[Index(row,col)];
199  }
200  static TVar Zero;
201  Zero = TVar(0);
202  return( Zero );
203 }
204 
205 template<class TVar>
206 inline TVar &TPZFBMatrix<TVar>::operator()(const int64_t row, const int64_t col){
207  if ( (col-row <=fBandUpper) && (row-col <= fBandLower) )
208  {
209  return( fElem[Index(row,col)] );
210  }
211  DebugStop();
212  static TVar Zero = (TVar)(0);
213  return( Zero );
214 }
215 template<class TVar>
216 inline TVar &TPZFBMatrix<TVar>::s(const int64_t row, const int64_t col) {
217  // verificando se o elemento a inserir esta dentro da matriz
218  return operator()(row,col);
219 }
220 
221 #endif
222 
223 
void Transpose(TPZMatrix< TVar > *const T) const override
It makes *T the transpose of current matrix.
Definition: pzbndmat.cpp:477
virtual TVar & s(const int64_t row, const int64_t col) override
The operators check on the bounds if the DEBUG variable is defined.
Definition: pzbndmat.h:216
const TVar & Get(const int64_t row, const int64_t col) const override
Get value with bound checking.
Definition: pzbndmat.cpp:93
bool IsZero(long double a)
Returns if the value a is close Zero as the allowable tolerance.
Definition: pzreal.h:668
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.
Definition: pzbndmat.cpp:221
int SetBand(const int64_t newBand)
Sets band size.
Definition: pzbndmat.cpp:458
void AutoFill(int64_t nrow, int64_t ncol, int symmetric)
Definition: pzbndmat.cpp:351
virtual void resize(const int64_t newsize)
Definition: pzvec.h:213
int Resize(const int64_t newRows, const int64_t newCols) override
Redimension the matrix preserving its elements.
Definition: pzbndmat.cpp:396
TPZVec< TVar > fElem
Definition: pzbndmat.h:154
TPZFBMatrix & operator+=(const TPZFBMatrix< TVar > &A)
Definition: pzbndmat.cpp:177
int64_t fRow
Number of rows in matrix.
Definition: pzmatrix.h:779
TPZFBMatrix & operator*=(const TVar val)
Definition: pzbndmat.cpp:337
TPZFBMatrix operator*(const TVar val) const
Definition: pzbndmat.cpp:285
int64_t Dim() const override
Returns the dimension of the matrix if the matrix is square.
Definition: pzbndmat.h:103
TPZFBMatrix()
Simple constructor.
Definition: pzbndmat.cpp:27
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
virtual int Substitution(TPZFMatrix< TVar > *B) const override
Computes Forward and Backward substitution for a "LU" decomposed matrix.
Definition: pzbndmat.cpp:624
int64_t GetBand() const
Definition: pzbndmat.h:113
int64_t fBandUpper
Definition: pzbndmat.h:155
int64_t size() const
Returns the number of elements of the vector.
Definition: pzvec.h:196
TPZFBMatrix & operator-=(const TPZFBMatrix< TVar > &A)
Definition: pzbndmat.cpp:197
void CopyFrom(TPZMatrix< TVar2 > &copy)
Definition: pzmatrix.h:96
int ClassId() const override
Define the class id associated with the class.
Definition: pzbndmat.cpp:634
int64_t GetBandLower() const
Returns band size.
Definition: pzbndmat.h:105
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
int64_t fBandLower
Definition: pzbndmat.h:155
TPZFBMatrix operator+(const TPZFBMatrix< TVar > &A) const
Definition: pzbndmat.cpp:129
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension the matrix and make zero its elements.
Definition: pzbndmat.cpp:412
~TPZFBMatrix()
Simple destructor.
Definition: pzbndmat.cpp:62
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
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: pzbndmat.cpp:73
int Clear() override
It clears data structure.
Definition: pzbndmat.cpp:645
int64_t GetBandUpper() const
Definition: pzbndmat.h:109
TPZFBMatrix & operator=(const TPZFBMatrix< TVar > &A)
Definition: pzbndmat.cpp:111
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
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: pzbndmat.h:170
Contains TPZMatrix<TVar>class, root matrix class.
int Zero() override
Zeroes the matrix.
Definition: pzbndmat.cpp:439
int64_t fCol
Number of cols in matrix.
Definition: pzmatrix.h:781
TVar & operator()(const int64_t row, const int64_t col)
Definition: pzbndmat.h:206
Defines a non symmetric banded matrix. Matrix.
Definition: pzbndmat.h:25
void CopyFrom(TPZFBMatrix< TVar2 > &orig)
copy the values from a matrix with a different precision
Definition: pzbndmat.h:50
virtual int Decompose_LU()
Definition: pzmatrix.cpp:1126
TPZFBMatrix operator-() const
Definition: pzbndmat.cpp:269
#define CLONEDEF(A)
To create clone matrix.
Definition: pzmatrix.h:28
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: pzbndmat.h:190
int64_t Index(int64_t i, int64_t j) const
Definition: pzbndmat.h:148
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60