NeoPZ
pzfmatrix.h
Go to the documentation of this file.
1 
7 #ifndef _TFULLMATRIXH_
8 #define _TFULLMATRIXH_
9 
10 #include <math.h> // for sqrt
11 #include <string.h> // for NULL, memset
12 #include <complex> // for complex
13 #include <iostream> // for operator<<, ostream, cout
14 #include <list> // for list
15 #include <sstream> // for basic_stringbuf<>::int_type, basic_strin...
16 #include "pzmatrix.h" // for TPZMatrix
17 #include "pzerror.h" // for DebugStop
18 #include "pzmanvector.h" // for TPZManVector
19 #include "pzreal.h" // for TPZFlopCounter, IsZero, REAL, sqrt, fabs
20 #include "pzvec.h" // for TPZVec
21 #include "tpzautopointer.h" // for TPZAutoPointer
22 #include <cstdlib>
23 
24 #ifdef _AUTODIFF
25 #include "tfad.h"
26 #include "fad.h"
27 #include "pzextractval.h"
28 #endif
29 
30 class TPZSavable;
31 class TPZStream;
32 template <class TVar> class TPZFMatrix;
33 template <class TVar> class TPZVerySparseMatrix;
34 
35 
36 template <class T>
37 class TPZVec;
38 
45 #define GETVAL(MAT,rows,row,col) MAT->fElem[((unsigned)col)*rows+row]
46 
47 #define PUTVAL(MAT,rows,row,col,val) MAT->fElem[((unsigned)col)*rows+row]=val
48 
49 #define SELECTEL(ptr,rows,row,col) ptr[col*rows+row]
50 
51 
53 template<class TVar>
54 TVar Dot(const TPZFMatrix<TVar> &A,const TPZFMatrix<TVar> &B);
55 
57 template<class TVar>
58 TVar Norm(const TPZFMatrix<TVar> &A);
59 
60 
68 template<class TVar=REAL>
69 class TPZFMatrix: public TPZMatrix<TVar> {
70 
71 public:
72 
75  TPZMatrix<TVar>( 0, 0 ), fElem(0),fGiven(0),fSize(0) {}
83  TPZFMatrix(const int64_t rows ,const int64_t columns, TVar* buf,const int64_t size);
90  TPZFMatrix(const int64_t rows ,const int64_t columns,const TVar & val );
96  inline TPZFMatrix(const int64_t rows ,const int64_t columns = 1) :
98  TPZMatrix<TVar>(rows,columns), fElem(0),fGiven(0),fSize(0) {
99  if(rows*columns) fElem = new TVar[rows*columns];
100  }
101 
107 
112  TPZFMatrix(const TPZFMatrix<TVar> & refmat);
113 
114 
115 
117  TPZFMatrix(const TPZMatrix<TVar> & refmat);
118 
123  inline TPZFMatrix(const std::initializer_list<TVar>& list);
124 
129  inline TPZFMatrix(const std::initializer_list< std::initializer_list<TVar> > &list);
130 
131 
133  virtual ~TPZFMatrix();
134 
135  int64_t MemoryFootprint() const override
136  {
137  return (sizeof(TVar)*this->Rows()*this->Cols());
138  }
139 
140  TVar *Adress()
141  {
142  return fElem;
143  }
144 
145  friend class TPZFMatrix<float>;
146  friend class TPZFMatrix<double>;
147 
149  template<class TVar2>
151  {
152  Resize(orig.Rows(), orig.Cols());
154  int64_t nel = orig.Rows()*orig.Cols();
155  for (int64_t el=0; el<nel; el++) {
156  fElem[el] = orig.fElem[el];
157  }
158  }
159 
161  virtual void UpdateFrom(TPZAutoPointer<TPZMatrix<TVar> > mat) override
162  {
163  TPZMatrix<TVar> *matptr = mat.operator->();
164  TPZFMatrix<TVar> *from = dynamic_cast<TPZFMatrix<TVar> *>(matptr);
165  if (from) {
166  *this = *from;
167  }
168  else
169  {
170  std::cout << "TPZMatrix<TVar>::UdateFrom is not implemented\n";
171  DebugStop();
172  }
173  }
174 
175  int PutVal(const int64_t row,const int64_t col,const TVar & value ) override;
176  const TVar &GetVal(const int64_t row,const int64_t col ) const override;
177 
178  virtual TVar &s(const int64_t row, const int64_t col) override;
179 
180  TVar &g(const int64_t row, const int64_t col) const;
186  void AddFel(TPZFMatrix<TVar> &rhs,TPZVec<int64_t> &destination);
193  void AddFel(TPZFMatrix<TVar> &rhs,TPZVec<int64_t> &source, TPZVec<int64_t> &destination);
194 
195 
205  virtual void MultAdd(const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z,
206  const TVar alpha=1.,const TVar beta = 0.,const int opt = 0) const override;
207 
208 
209  static void MultAdd(const TVar *ptr, int64_t rows, int64_t cols, const TPZFMatrix<TVar> &x,const TPZFMatrix<TVar> &y, TPZFMatrix<TVar> &z,
210  const TVar alpha=1.,const TVar beta = 0.,const int opt = 0);
211 
216  TVar &operator()(const int64_t row,const int64_t col);
217  TVar &operator()(const int64_t row);
226  virtual TPZFMatrix&operator= (const TPZFMatrix<TVar> &A );
227  TPZFMatrix<TVar>& operator= (const std::initializer_list<TVar>& list);
228  TPZFMatrix<TVar>& operator= (const std::initializer_list< std::initializer_list<TVar> >& list);
234 
242  void ZAXPY(const TVar alpha, const TPZFMatrix<TVar> &p);
248  void TimesBetaPlusZ(const TVar beta, const TPZFMatrix<TVar> &z);
249 
252 
260  TPZFMatrix<TVar> &operator= (const TVar val );
261  TPZFMatrix<TVar> operator+ (const TVar val ) const;
262  TPZFMatrix<TVar> operator- (const TVar val ) const;
263  TPZFMatrix<TVar> operator* (const TVar val ) const;
264  TPZFMatrix<TVar> &operator+=(const TVar val );
265  TPZFMatrix<TVar> &operator-=(const TVar val ) { return operator+=( -val ); }
266  TPZFMatrix<TVar> &operator*=(const TVar val );
267 
268  // TPZFMatrix<TVar> operator-() const;// { return operator*( -1.0 ); }
269 
273  int Resize(const int64_t newRows,const int64_t wCols ) override;
274 
276  int SetSize(int64_t newRows, int64_t newCols);
277 
279  int Remodel(const int64_t newRows,const int64_t wCols );
280 
282  int Redim(const int64_t newRows,const int64_t newCols ) override;
283 
285  int Zero() override;
286 
287 #ifdef USING_LAPACK
288 
289  void InitializePivot();
290 #endif
291 
292 
300  void GramSchmidt(TPZFMatrix<TVar> &Orthog, TPZFMatrix<TVar> &TransfToOrthog);
301 
302  void DeterminantInverse(TVar &determinant, TPZFMatrix<TVar> &inverse);
303 
304  void Transpose(TPZMatrix<TVar> *const T) const override;
305 
308  void Transpose();
309 
310  /*** @name Solve linear system of equations ***/
314  virtual int Decompose_Cholesky() override;
315  virtual int Decompose_Cholesky(std::list<int64_t> &singular) override;
316 
318  virtual int Decompose_LU(std::list<int64_t> &singular) override;
319  virtual int Decompose_LU() override;
320 
326  virtual int Decompose_LDLt() override;
327 
328  static int Substitution(const TVar *ptr, int64_t rows, TPZFMatrix<TVar> *B);
329 
330  virtual int Substitution( TPZFMatrix<TVar> *B ) const override;
331 
333  virtual int Decompose_LU(TPZVec<int> &index);
334 
336  virtual int Substitution( TPZFMatrix<TVar> *B, const TPZVec<int> &index ) const;
337 
339  static int Substitution(const TVar *ptr, int64_t rows, TPZFMatrix<TVar> *B, const TPZVec<int> &index );
340 
341 #ifdef USING_LAPACK
342 
346  virtual int Subst_Forward( TPZFMatrix<TVar>* b ) const override;
347 
352  virtual int Subst_Backward( TPZFMatrix<TVar>* b ) const override;
353 
358  virtual int Subst_LForward( TPZFMatrix<TVar>* b ) const override;
359 
364  virtual int Subst_LBackward( TPZFMatrix<TVar>* b ) const override;
365 
370  virtual int Subst_Diag( TPZFMatrix<TVar>* b ) const override;
371 #endif
372 
375 #ifdef USING_LAPACK
376  /*** @name Solve eigenvalues ***/
382  virtual int SolveEigenProblem(TPZVec < std::complex<double> > &w, TPZFMatrix < std::complex<double> > &eigenVectors);
386  virtual int SolveEigenProblem(TPZVec < std::complex<double> > &w);
387 
392  virtual int SolveGeneralisedEigenProblem(TPZFMatrix< TVar > &B , TPZVec < std::complex<double> > &w, TPZFMatrix < std::complex<double> > &eigenVectors);
396  virtual int SolveGeneralisedEigenProblem(TPZFMatrix< TVar > &B , TPZVec < std::complex<double> > &w);
398 #endif
399 
401  public:
402 int ClassId() const override;
403 
404 
405  void Read(TPZStream &buf, void *context ) override;
406  void Write(TPZStream &buf, int withclassid ) const override;
407 
413  virtual bool Compare(TPZSavable *copy, bool override = false) override;
414 
420  virtual bool Compare(TPZSavable *copy, bool override = false) const override;
421 
422  operator const TVar*() const { return fElem; }
423 
424  static void PrintStatic(const TVar *ptr, int64_t rows, int64_t cols, const char *name, std::ostream& out,const MatrixOutputFormat form);
425 
426 private:
427 
428  static int Error(const char *msg1,const char *msg2=0 );
429  int Clear() override;
430 
431  TVar *fElem;
432  TVar *fGiven;
433  int64_t fSize;
434 
435 #ifdef USING_LAPACK
436  TPZManVector<int,5> fPivot;
437 
438  TPZVec<TVar> fWork;
439 #endif
440 };
441 
444 template<class TVar>
445 inline TPZFMatrix<TVar>::TPZFMatrix(const int64_t rows,const int64_t cols,TVar * buf,const int64_t sz)
446 : TPZRegisterClassId(&TPZFMatrix<TVar>::ClassId),TPZMatrix<TVar>( rows, cols ),
447 fElem(buf),fGiven(buf),fSize(sz) {
448  int64_t size = rows * cols;
449  if(size == 0)
450  {
451  fElem = NULL;
452  }
453  else if(size > sz)
454  {
455  fElem=new TVar[size];
456 #ifndef NODEBUG
457  if ( fElem == NULL && size) Error( "Constructor <memory allocation error>." );
458 #endif
459  }
460 }
461 template<class TVar>
462 inline TPZFMatrix<TVar>::TPZFMatrix(const int64_t rows,const int64_t cols,const TVar & val )
463 : TPZRegisterClassId(&TPZFMatrix<TVar>::ClassId), TPZMatrix<TVar>( rows, cols ),
464  fElem(0), fGiven(0), fSize(0) {
465  int64_t size = rows * cols;
466  if(!size) return;
467  fElem=new TVar[size];
468 #ifdef PZDEBUG
469  if ( fElem == NULL && size) Error( "Constructor <memory allocation error>." );
470 #endif
471  for(int64_t i=0;i<size;i++) fElem[i] = val;
472 }
473 
474 template<class TVar>
475 inline TPZFMatrix<TVar>::TPZFMatrix(const std::initializer_list<TVar>& list)
476 : TPZRegisterClassId(&TPZFMatrix<TVar>::ClassId), TPZMatrix<TVar>(list.size(), 1)
477 {
478  if (list.size() > 0) {
479  this->fElem = new TVar[list.size()];
480  }
481 
482  auto it = list.begin();
483  auto it_end = list.end();
484  TVar* aux = fElem;
485  for (; it != it_end; it++, aux++)
486  *aux = *it;
487 }
488 
489 template< class TVar >
490 inline TPZFMatrix<TVar>::TPZFMatrix(const std::initializer_list<std::initializer_list<TVar>> &list)
492 {
493  this->fRow = list.size();
494 
495  auto row_it = list.begin();
496  auto row_it_end = list.end();
497 
498 #ifdef PZDEBUG
499  bool col_n_found = false;
500  for (auto it = row_it; it != row_it_end; it++) {
501  if (!col_n_found) {
502  this->fCol = it->size();
503  col_n_found = true;
504  } else {
505  if (this->fCol != it->size())
506  Error("TPZFMatrix constructor: inconsistent number of columns in initializer list");
507  }
508  }
509 #else
510  this->fCol = row_it->size();
511 #endif
512 
513  this->fElem = new TVar[this->fRow * this->fCol];
514 
515  for (uint32_t row_n = 0; row_it != row_it_end; row_it++, row_n++) {
516  auto col_it = row_it->begin();
517  auto col_it_end = row_it->end();
518  for (uint32_t col_n = 0; col_it != col_it_end; col_it++, col_n++) {
519  this->fElem[col_n * this->fRow + row_n] = *col_it;
520  }
521  }
522 }
523 
524 template<class TVar>
527 {
528  return A*val;
529 }
530 
531 
532 /*******************************/
533 /*** Operator*( TPZMatrix<TVar> & ) ***/
534 template<class TVar>
536  if ( this->Cols() != A.Rows() )
537  Error( "Operator* <matrixs with incompatible dimensions>" );
538 
540  res.Redim( this->Rows(), A.Cols() );
541  MultAdd(A,A,res,1.,0.,0);
542  return( res );
543 }
544 
545 /**************/
546 /*** PutVal ***/
547 template<class TVar>
548 inline int TPZFMatrix<TVar>::PutVal(const int64_t row, const int64_t col,const TVar & value ) {
549  fElem[ ((unsigned)col) * this->Rows() + row ] = value;
550  return( 1 );
551 }
552 
553 /******************/
554 /*** Destructor ***/
555 template<class TVar>
557  if(fElem && fElem != fGiven) delete[]( fElem );
558  fElem = 0;
559  fSize = 0;
560 }
561 
562 
563 /**************/
564 /*** GetVal ***/
565 template<class TVar>
566 inline const TVar &TPZFMatrix<TVar>::GetVal( const int64_t row, const int64_t col ) const {
567 #ifdef PZDEBUG
568  if(row >= this->Rows() || row<0 || col >= this->Cols() || col<0) {
569  Error("TPZFMatrix::operator() "," Index out of bounds");
570  DebugStop();
571  }
572 #endif
573  return( fElem[ col*this->fRow + row ] );
574 }
575 
576 template<class TVar>
577 inline TVar &TPZFMatrix<TVar>::operator()( const int64_t row, const int64_t col) {
578 #ifndef NODEBUG
579  if(row >= this->Rows() || row<0 || col >= this->Cols() || col<0) {
580  Error("TPZFMatrix<TVar>::operator() "," Index out of bounds");
581  DebugStop();
582  }
583 #endif
584  return *(this->fElem+col*this->fRow+row);
585 }
586 
587 template<class TVar>
588 inline TVar &TPZFMatrix<TVar>::s(const int64_t row, const int64_t col) {
589  // verificando se o elemento a inserir esta dentro da matriz
590  return operator()(row,col);
591 }
592 
593 template<class TVar>
594 inline TVar &TPZFMatrix<TVar>::g( const int64_t row, const int64_t col) const {
595 #ifdef PZDEBUG
596  if(row >= this->Rows() || row<0 || col >= this->Cols() || col<0) {
597  Error("TPZFMatrix<TVar>::operator() "," Index out of bounds");
598  DebugStop();
599  }
600 #endif
601  return *(this->fElem+col*this->fRow+row);
602 }
603 
604 template<class TVar>
605 inline TVar &TPZFMatrix<TVar>::operator()(const int64_t row) {
606 #ifdef PZDEBUG
607  if(row >= this->Rows() || row<0) {
608  Error("TPZFMatrix<TVar>::operator() "," Index out of bounds");
609  DebugStop();
610  }
611 #endif
612  return *(this->fElem+row);
613 }
614 
615 template<class TVar>
616 inline int TPZFMatrix<TVar>::Redim(const int64_t newRows,const int64_t newCols) {
617  int64_t newsize = newRows*newCols;
618  int64_t size = this->fRow*this->fCol;
619  if ( newsize == size) {
620  this->fRow = newRows;
621  this->fCol = newCols;
622  Zero();
623  return( 1 );
624  }
625  if(this->fElem && this->fElem != this->fGiven) delete []this->fElem;
626 
627  if(this->fGiven && newsize <= this->fSize) {
628  this->fElem = this->fGiven;
629  } else if(newsize == 0) {
630  this->fElem = NULL;
631  } else {
632  this->fElem = new TVar[ newsize ] ;
633  }
634 #ifndef NODEBUG
635  if (newsize && this->fElem == NULL )
636  Error( "Resize <memory allocation error>." );
637 #endif
638 
639  this->fRow = newRows;
640  this->fCol = newCols;
641 
642  Zero();
643 
644  return( 1 );
645 }
646 
647 /***************/
648 /****Zero*******/
649 
650 template<class TVar>
652  int64_t size = this->fRow * this->fCol * sizeof(TVar);
653  memset(((void*)this->fElem),'\0',size);
654  this->fDecomposed = 0;
655  return( 1 );
656 }
657 
658 /**************************/
659 /*** Operations Global ****/
660 
661 inline int64_t Norm(const TPZFMatrix<int64_t> &A) {
662  return (int64_t)sqrt((REAL)Dot(A,A));
663 }
664 
665 inline int Norm(const TPZFMatrix<int> &A) {
666  return (int)sqrt((REAL)Dot(A,A));
667 }
668 
669 inline float Norm(const TPZFMatrix<float> &A) {
670  return sqrt(Dot(A,A));
671 }
672 
673 inline double Norm(const TPZFMatrix<double> &A) {
674  return sqrt(Dot(A,A));
675 }
676 
677 inline long double Norm(const TPZFMatrix<long double> &A) {
678  return sqrt(Dot(A,A));
679 }
680 
681 inline float Norm(const TPZFMatrix< std::complex <float> > &A) {
682  return sqrt(Dot(A,A).real());
683 }
684 
685 inline double Norm(const TPZFMatrix< std::complex <double> > &A) {
686  return sqrt(Dot(A,A).real());
687 }
688 
689 inline long double Norm(const TPZFMatrix< std::complex <long double> > &A) {
690  return sqrt(Dot(A,A).real());
691 }
692 
693 #ifdef _AUTODIFF
694 inline float Norm(const TPZFMatrix< Fad <float> > &A) {
695  return (float)TPZExtractVal::val(sqrt(Dot(A,A)));
696 }
697 
698 inline double Norm(const TPZFMatrix< Fad <double> > &A) {
699  return TPZExtractVal::val(sqrt(Dot(A,A)));
700 }
701 
702 inline long double Norm(const TPZFMatrix< Fad <long double> > &A) {
703  return TPZExtractVal::val(sqrt(Dot(A,A)));
704 }
705 #endif
706 
708 {
709  return sqrt(Dot(A, A));
710 }
715 template<int N, class TVar=REAL>
716 class TPZFNMatrix : public TPZFMatrix<TVar> {
717 
718  TVar fBuf[N+1];
719 
720 public:
721  /*
722  * @brief Constructor which does not initialize the data. \n
723  * WARNING : this class will dynamically allocate memory if the template parameter N is smaller than row*col
724  * @param row Number of rows
725  * @param col Number of cols
726  */
727  inline TPZFNMatrix(int64_t row, int64_t col) : TPZRegisterClassId(&TPZFNMatrix<N,TVar>::ClassId),
728  TPZFMatrix<TVar>(row,col,fBuf,N) {}
729 
730  inline TPZFNMatrix() : TPZRegisterClassId(&TPZFNMatrix<N,TVar>::ClassId), TPZFMatrix<TVar>(0,0,fBuf,N)
731  {
732  }
733 
735  TPZFMatrix<TVar>(0,0,fBuf,N)
736  {
737  *this = copy;
738  }
739 
741  TPZFMatrix<TVar>(0,0,fBuf,N)
742  {
743  *this = copy;
744  }
745 
746  virtual ~TPZFNMatrix()
747  {
748  }
749 
751  /*
752  * @brief Constructor which initializes the data. \n
753  * WARNING : this class will dynamically allocate memory if the template parameter N is smaller than row*col
754  * @param row Number of rows
755  * @param col Number of cols
756  * @param val initial value of the matrix elements
757  */
758  inline TPZFNMatrix(int64_t row, int64_t col, const TVar &val) : TPZRegisterClassId(&TPZFNMatrix<N,TVar>::ClassId),
759  TPZFMatrix<TVar>(row,col,fBuf,N) {
761  }
762 
763  inline TPZFMatrix<TVar> &operator=(const TPZFMatrix<TVar> &copy) override {
764  return TPZFMatrix<TVar>::operator=(copy);
765  }
768  return *this;
769  }
770 
771  int ClassId() const override;
772  void Read(TPZStream &buf, void *context) override;
773  void Write(TPZStream &buf, int withclassid) const override;
774 
775 };
776 
777 template<int N, class TVar>
779  return Hash("TPZFNMatrix") ^ TPZFMatrix<TVar>::ClassId() << 1 ^ (N << 2);
780 }
781 
782 template<int N, class TVar>
783 void TPZFNMatrix<N, TVar>::Read(TPZStream& buf, void* context) {
784  TPZFMatrix<TVar>::Read(buf, context);
785  buf.Read(fBuf, N+1);
786 }
787 
788 template<int N, class TVar>
789 void TPZFNMatrix<N, TVar>::Write(TPZStream& buf, int withclassid) const {
790  TPZFMatrix<TVar>::Write(buf, withclassid);
791  buf.Write(fBuf, N+1);
792 }
793 
794 #endif
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: pzfmatrix.h:588
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzfmatrix.h:789
TPZFNMatrix(const TPZFMatrix< TVar > &copy)
Definition: pzfmatrix.h:734
TPZFMatrix< TVar > operator*(TPZFMatrix< TVar > A) const
Definition: pzfmatrix.h:535
void ZAXPY(const TVar alpha, const TPZFMatrix< TVar > &p)
Performs an ZAXPY operation being *this += alpha * p.
Definition: pzfmatrix.cpp:879
TVar & operator()(const int64_t row, const int64_t col)
Definition: pzfmatrix.h:577
void GramSchmidt(TPZFMatrix< TVar > &Orthog, TPZFMatrix< TVar > &TransfToOrthog)
This method implements a Gram Schimidt method. this = Orthog.TransfToOrthog.
Definition: pzfmatrix.cpp:341
void AddFel(TPZFMatrix< TVar > &rhs, TPZVec< int64_t > &destination)
Performs a right hand side assemblage.
Definition: pzfmatrix.cpp:209
TPZFMatrix< TVar > & operator*=(const TVar val)
Definition: pzfmatrix.cpp:1006
Templated vector implementation.
int64_t MemoryFootprint() const override
Returns the approximate size of the memory footprint (amount of memory required to store this object)...
Definition: pzfmatrix.h:135
TPZFMatrix< TVar > & operator-=(const TPZFMatrix< TVar > &A)
Definition: pzfmatrix.cpp:856
void Transpose()
Definition: pzfmatrix.cpp:1086
MatrixOutputFormat
Defines output format.
Definition: pzmatrix.h:55
Defines PZError.
TPZFNMatrix(int64_t row, int64_t col)
Definition: pzfmatrix.h:727
int64_t fRow
Number of rows in matrix.
Definition: pzmatrix.h:779
static int Error(const char *msg1, const char *msg2=0)
Definition: pzfmatrix.cpp:2161
virtual int Decompose_LU() override
Definition: pzfmatrix.cpp:1307
char fDecomposed
Decomposition type used to decompose the current matrix.
Definition: pzmatrix.h:783
int ClassId() const override
Routines to send and receive messages.
Definition: pzfmatrix.h:778
TVar Dot(const TPZFMatrix< TVar > &A, const TPZFMatrix< TVar > &B)
Returns a dot product to matrices.
Definition: pzfmatrix.cpp:2083
virtual int Subst_LBackward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is upper triangular with A(i,i)=1.
Definition: pzmatrix.cpp:1358
TPZFMatrix< TVar > & operator+=(const TPZFMatrix< TVar > &A)
Definition: pzfmatrix.cpp:842
Definition: fad.h:54
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > > mat) override
Updates the values of the matrix based on the values of the matrix.
Definition: pzfmatrix.h:161
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
REAL val(STATE &number)
Returns value of the variable.
Definition: pzartdiff.h:23
virtual int Subst_Forward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is lower triangular.
Definition: pzmatrix.cpp:1284
TVar * fGiven
Definition: pzfmatrix.h:432
int ClassId() const override
Routines to send and receive messages.
Definition: pzfmatrix.cpp:2371
int64_t fSize
Definition: pzfmatrix.h:433
virtual int Decompose_LDLt() override
Decomposes the current matrix using LDLt. The current matrix has to be symmetric. "L" is lower triangular with 1.0 in its diagonal and "D" is a Diagonal matrix.
Definition: pzfmatrix.cpp:1792
TPZFMatrix< TVar > & operator=(const TPZFMatrix< TVar > &copy) override
Generic operator with FULL matrices.
Definition: pzfmatrix.h:763
TPZFMatrix(const int64_t rows, const int64_t columns=1)
Constructor with initialization parameters.
Definition: pzfmatrix.h:96
TPZFMatrix< TVar > operator-(const TPZFMatrix< TVar > &A) const
Definition: pzfmatrix.cpp:303
int Zero() override
Makes Zero all the elements.
Definition: pzfmatrix.h:651
virtual ~TPZFMatrix()
Simple destructor.
Definition: pzfmatrix.h:556
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzfmatrix.h:783
void CopyFrom(TPZMatrix< TVar2 > &copy)
Definition: pzmatrix.h:96
virtual void Write(const bool val)
Definition: TPZStream.cpp:8
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
TVar * fElem
Definition: pzfmatrix.h:431
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
Implements a matrix whose nonzero elements are stored in binary tree. Matrix.
Definition: pzfmatrix.h:33
Free store vector implementation.
int64_t Rows() const
Returns number of rows.
Definition: pzmatrix.h:803
virtual int Subst_Diag(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is diagonal matrix.
Definition: pzmatrix.cpp:1384
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
virtual TPZFMatrix & operator=(const TPZFMatrix< TVar > &A)
Generic operator with FULL matrices.
Definition: pzfmatrix.cpp:131
string res
Definition: test.py:151
Contains declaration of the TPZAutoPointer class which has Increment and Decrement actions are mutexe...
TPZFNMatrix< N, TVar > & operator=(const TPZFNMatrix< N, TVar > &copy)
Definition: pzfmatrix.h:766
TPZFMatrix< TVar > & operator-=(const TVar val)
Definition: pzfmatrix.h:265
static int Substitution(const TVar *ptr, int64_t rows, TPZFMatrix< TVar > *B)
Definition: pzfmatrix.cpp:1323
static REAL val(const int number)
Definition: pzextractval.h:21
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
Definition: pzfmatrix.h:616
virtual int Subst_LForward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is lower triangular with A(i,i)=1.
Definition: pzmatrix.cpp:1333
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
Contains TPZMatrix<TVar>class, root matrix class.
int64_t fCol
Number of cols in matrix.
Definition: pzmatrix.h:781
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzfmatrix.cpp:2205
int Clear() override
It clears data structure.
Definition: pzfmatrix.cpp:2175
void CopyFrom(TPZFMatrix< TVar2 > &orig)
copy the values from a matrix with a different precision
Definition: pzfmatrix.h:150
void TimesBetaPlusZ(const TVar beta, const TPZFMatrix< TVar > &z)
Performs an operation *this = this * beta + z.
Definition: pzfmatrix.cpp:898
int Remodel(const int64_t newRows, const int64_t wCols)
Remodel the shape of the matrix, but keeping the same dimension.
Definition: pzfmatrix.cpp:1063
This class implements floating point number associated with a counter of the operations performed wit...
Definition: pzreal.h:261
virtual 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: pzfmatrix.cpp:757
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
Definition: pzfmatrix.cpp:1016
TPZRegisterClassId()=default
TVar * Adress()
Definition: pzfmatrix.h:140
virtual int Decompose_Cholesky() override
Cholesky Decomposition Optmized. for walks in the direction of the vector that composes the matrix...
Definition: pzfmatrix.cpp:1574
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
#define CLONEDEF(A)
To create clone matrix.
Definition: pzmatrix.h:28
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
void DeterminantInverse(TVar &determinant, TPZFMatrix< TVar > &inverse)
Definition: pzfmatrix.cpp:507
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzfmatrix.cpp:2225
int SetSize(int64_t newRows, int64_t newCols)
Redimension the matrix doing nothing with the elements.
Definition: pzfmatrix.cpp:2376
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
Definition: TPZSavable.h:67
static void PrintStatic(const TVar *ptr, int64_t rows, int64_t cols, const char *name, std::ostream &out, const MatrixOutputFormat form)
Definition: pzfmatrix.cpp:2321
virtual ~TPZFNMatrix()
Definition: pzfmatrix.h:746
virtual bool Compare(TPZSavable *copy, bool override=false) override
Compare the object for identity with the object pointed to, eventually copy the object.
Definition: pzfmatrix.cpp:2236
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: pzfmatrix.h:548
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: pzfmatrix.h:566
TVar & g(const int64_t row, const int64_t col) const
Definition: pzfmatrix.h:594
TPZFMatrix< TVar > operator+(const TPZFMatrix< TVar > &A) const
Definition: pzfmatrix.cpp:284
TPZFNMatrix(const TPZFNMatrix< N, TVar > &copy)
Definition: pzfmatrix.h:740
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
Definition: pzfmatrix.h:716
virtual void Read(bool &val)
Definition: TPZStream.cpp:91
virtual int Subst_Backward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is upper triangular.
Definition: pzmatrix.cpp:1309
TPZFMatrix()
Simple constructor.
Definition: pzfmatrix.h:74
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60
This class implements a reference counter mechanism to administer a dynamically allocated object...