NeoPZ
pzmatrix.h
Go to the documentation of this file.
1 
6 #ifndef _TMATRIXHH_
7 #define _TMATRIXHH_
8 
9 #include "pzvec.h"
10 #include "TPZStream.h"
11 #include "pzreal.h"
12 #include "TPZSavable.h"
13 #include "Hash/TPZHash.h"
14 #include "pzlog.h"
15 
16 #include <list>
17 #include <sstream>
18 
19 #ifdef _AUTODIFF
20 #include "fad.h"
21 #include "tfad.h"
22 #endif
23 
24 template<class TVar>
25 class TPZFMatrix;
26 
28 #define CLONEDEF(A) virtual TPZMatrix<TVar>*Clone() const override { return new A(*this); }
29 
30 
31 template<class TVar>
32 class TPZSolver;
33 
34 #ifndef USING_MKL
35 extern "C"{
37  double ddot(int *N, double *X, int *INCX, double *Y, int *INCY);
38 }
39 #endif
40 
53 
56 
59 template<class TVar=REAL>
60 class TPZMatrix: public TPZSavable
61 
62 {
63 public:
64 
65  //typedef typename TVar;
68  fDecomposed = 0;
69  fDefPositive = 0;
70  fRow = 0;
71  fCol = 0;
72  }
73 
74  TPZMatrix<TVar>(const TPZMatrix<TVar>&cp) : TPZRegisterClassId(&TPZMatrix<TVar>::ClassId), fRow(cp.fRow), fCol(cp.fCol), fDecomposed(cp.fDecomposed),fDefPositive(cp.fDefPositive)
75  {
76  }
78  virtual ~TPZMatrix();
79 
80  virtual TPZMatrix<TVar>*Clone() const = 0;
81 
86  virtual int64_t MemoryFootprint() const {
87  std::cout << __PRETTY_FUNCTION__
88  << ": Please, implement me! (class = " << ClassId()
89  << std::endl;
90  //<< ") (class name = " << ClassName() << ")" << std::endl;
91  //DebugStop();
92  return 0;
93  }
94 
95  template<class TVar2>
97  {
98  fDecomposed = copy.IsDecomposed();
99  fDefPositive = copy.IsDefPositive();
100  fRow = copy.Rows();
101  fCol = copy.Cols();
102 
103  }
104 
107  void AutoFill(int64_t nrow, int64_t ncol, int symmetric);
108 
110  virtual int VerifySymmetry(REAL tol = 1.e-13) const;
111 
118  virtual int Put(const int64_t row,const int64_t col,const TVar & value );
124  virtual const TVar &Get(const int64_t row,const int64_t col ) const;
125 
131  const TVar &g(const int64_t row, const int64_t col) const {return Get(row,col);}
132 
138  TVar &operator() (const int64_t row,const int64_t col );
144  virtual TVar &s(const int64_t row, const int64_t col);
149  TVar &operator()(const int64_t row);
150 
154  virtual int PutVal(const int64_t /*row*/,const int64_t /*col*/,const TVar & val )
155  {
156  if(val != ((TVar)(0.))) DebugStop();
157  return 0;
158  }
162  virtual const TVar &GetVal(const int64_t /*row*/, const int64_t /*col*/ ) const;
163 
175  virtual void Multiply(const TPZFMatrix<TVar>& A,TPZFMatrix<TVar>& res, int opt = 0) const;
181  virtual void Add(const TPZMatrix<TVar>& A,TPZMatrix<TVar>& res) const;
191  virtual void MultAdd(const TPZFMatrix<TVar> & x,const TPZFMatrix<TVar>& y, TPZFMatrix<TVar>& z,
192  const TVar alpha=1., const TVar beta = 0., const int opt = 0) const;
193 
195  virtual void Residual(const TPZFMatrix<TVar>& x,const TPZFMatrix<TVar>& rhs, TPZFMatrix<TVar>& res ) ;
197  virtual void Substract(const TPZMatrix<TVar>& A,TPZMatrix<TVar>& result) const;
198 
200  virtual void Identity();
202  virtual void Transpose(TPZMatrix<TVar>*const T) const;
203 
209  int Inverse(TPZFMatrix<TVar>&Inv, DecomposeType dec);
210 
224  TVar MatrixNorm(int p, int64_t numiter = 2000000, REAL tol = 1.e-10) const; // -<
225 
237  TVar ConditionNumber(int p, int64_t numiter = 2000000, REAL tol = 1.e-10);
238 
248  virtual void Input(std::istream & in = std::cin );
249 
251  template <class TT> friend std::istream & operator >> (std::istream& in,TPZMatrix<TT>& A) ;
252 
253  virtual void Print(std::ostream &out) const
254  {
255  std::string name = __PRETTY_FUNCTION__;
256  Print(name.c_str(),out);
257  }
259  virtual void Print(const char *name, std::ostream &out = std::cout ,const MatrixOutputFormat form = EFormatted) const;
260 
261  //void PrintMath(const char *name, std::ostream &out);
262 
264  int64_t Rows() const;
266  int64_t Cols() const;
267 
270  inline virtual int64_t Dim() const;
271 
272 
278  virtual int Resize(const int64_t newRows, const int64_t newCols ) {
279  fRow = newRows;
280  fCol = newCols;
281  return 0;
282  }
283 
289  virtual int Redim(const int64_t newRows, const int64_t newCols ) {
290  fRow = newRows;
291  fCol = newCols;
292  return 0;
293  }
294 
296  virtual int Zero(){
297  std::cout << "WARNING! TPZMatrix<TVar>::Zero is called\n";
298  DebugStop();
299  return 0; }
300 
315  virtual int PutSub( const int64_t sRow, const int64_t sCol, const TPZFMatrix<TVar>& Source );
316 
325  virtual int GetSub( const int64_t sRow, const int64_t sCol, const int64_t rowSize,
326  const int64_t colSize, TPZFMatrix<TVar>& Target ) const;
327 
334  virtual int AddSub(const int64_t sRow, const int64_t sCol, const TPZFMatrix<TVar>& Source );
335 
347  virtual int InsertSub(const int64_t sRow,const int64_t sCol,const int64_t rowSize,const int64_t colSize,
348  const int64_t pRow,const int64_t pCol, TPZMatrix<TVar>* Target ) const;
349 
360  virtual int AddSub(const int64_t sRow,const int64_t sCol,const int64_t rowSize,
361  const int64_t colSize,const int64_t pRow,const int64_t pCol, TPZMatrix<TVar>* pA ) const;
362 
370  virtual void AddKel(TPZFMatrix<TVar>&elmat, TPZVec<int64_t> &destinationindex);
371 
378  virtual void AddKel(TPZFMatrix<TVar>&elmat, TPZVec<int64_t> &sourceindex, TPZVec<int64_t> &destinationindex);
379 
387  virtual void UpdateFrom(TPZAutoPointer<TPZMatrix<TVar> > /* mat*/)
388  {
389  std::cout << "TPZMatrix<TVar>::UdateFrom is not implemented\n";
390  DebugStop();
391  }
392 
394  virtual int IsSimetric() const { return 0; }
396  inline int IsSquare() const { return fRow == fCol;}
397 
399  virtual void Simetrize();
400 
401 
403  virtual int IsDefPositive() const{ return 0; }
405  int IsDecomposed() const { return fDecomposed; }
406 
410  void SetIsDecomposed(int val) {fDecomposed = (char) val; }
411 
432  virtual void SolveJacobi(int64_t & numiterations, const TPZFMatrix<TVar>& F, TPZFMatrix<TVar>& result,
433  TPZFMatrix<TVar>* residual, TPZFMatrix<TVar>& scratch, REAL & tol, const int FromCurrent = 0);
434 
447  virtual void SolveSOR(int64_t & numiterations, const TPZFMatrix<TVar>& F, TPZFMatrix<TVar>& result,
448  TPZFMatrix<TVar>* residual,TPZFMatrix<TVar>& scratch,const REAL overrelax, REAL & tol,
449  const int FromCurrent = 0,const int direction = 1) ;
461  virtual void SolveSSOR(int64_t & numiterations,const TPZFMatrix<TVar>& F, TPZFMatrix<TVar>& result,
462  TPZFMatrix<TVar>* residual, TPZFMatrix<TVar>& scratch, const REAL overrelax, REAL & tol,
463  const int FromCurrent = 0) ;
464 
475  virtual void SolveCG(int64_t & numiterations, TPZSolver<TVar> & preconditioner,
476  const TPZFMatrix<TVar>& F, TPZFMatrix<TVar>& result,
477  TPZFMatrix<TVar>* residual, REAL & tol,
478  const int FromCurrent = 0) ;
487  virtual void SolveBICG(int64_t & numiterations, TPZSolver<TVar> & preconditioner,
488  const TPZFMatrix<TVar>& F, TPZFMatrix<TVar>& result,
489  REAL & tol) ;
490 
501  virtual void SolveBICGStab(int64_t & numiterations, TPZSolver<TVar> & preconditioner,
502  const TPZFMatrix<TVar>& F, TPZFMatrix<TVar>& result,
503  TPZFMatrix<TVar>* residual, REAL & tol,
504  const int FromCurrent = 0) ;
505 
518  virtual void SolveGMRES(int64_t & numiterations, TPZSolver<TVar> & preconditioner,
519  TPZFMatrix<TVar>& H, int & numvectors,
520  const TPZFMatrix<TVar>& F, TPZFMatrix<TVar>& result,
521  TPZFMatrix<TVar>* residual, REAL & tol,const int FromCurrent) ;
522 
533  virtual void SolveIR(int64_t & numiterations, TPZSolver<TVar> & preconditioner,
534  const TPZFMatrix<TVar>& F, TPZFMatrix<TVar>& result,
535  TPZFMatrix<TVar>* residual, REAL & tol,
536  const int FromCurrent = 0);
537 
545  virtual bool SolveEigenvaluesJacobi(int64_t &numiterations, REAL &tol, TPZVec<TVar> * Sort = 0);
546 
555  virtual bool SolveEigensystemJacobi(int64_t &numiterations, REAL & tol, TPZVec<TVar> & Eigenvalues, TPZFMatrix<TVar>& Eigenvectors) const;
556 
563  virtual int SolveDirect ( TPZFMatrix<TVar>& F , const DecomposeType dt, std::list<int64_t> &singular);
569  virtual int SolveDirect ( TPZFMatrix<TVar>& F , const DecomposeType dt);
570 
572  virtual int Decompose(const DecomposeType dt, std::list<int64_t> &singular)
573  {
574  switch (dt) {
575  case ELU:
576  return Decompose_LU(singular);
577  break;
578  case ELDLt:
579  return Decompose_LDLt(singular);
580  break;
581  case ECholesky:
582  return Decompose_Cholesky(singular);
583  break;
584  default:
585  DebugStop();
586  break;
587  }
588  return -1;
589  }
591  static TVar ReturnNearestValue(TVar val, TPZVec<TVar> &Vec, TVar tol);
592 
598  int Solve_LU ( TPZFMatrix<TVar>* B, std::list<int64_t> &singular );
603  int Solve_LU ( TPZFMatrix<TVar>* B );
604 
609  virtual int Solve_Cholesky( TPZFMatrix<TVar>* B);
615  int Solve_Cholesky( TPZFMatrix<TVar>* B, std::list<int64_t> &singular );
621  int Solve_LDLt ( TPZFMatrix<TVar>* B, std::list<int64_t> &singular );
626  int Solve_LDLt ( TPZFMatrix<TVar>* B);
627 
637  virtual int Decompose_LU(std::list<int64_t> &singular);
638  virtual int Decompose_LU();
639 
641  virtual int Decompose_Cholesky() ;
646  virtual int Decompose_Cholesky(std::list<int64_t> &singular) ;
647 
653  virtual int Decompose_LDLt(std::list<int64_t> &singular);
655  virtual int Decompose_LDLt();
656 
669  virtual int Substitution( TPZFMatrix<TVar>* B ) const;
670 
675  virtual int Subst_Forward( TPZFMatrix<TVar>* b ) const;
676 
681  virtual int Subst_Backward( TPZFMatrix<TVar>* b ) const;
682 
687  virtual int Subst_LForward( TPZFMatrix<TVar>* b ) const;
688 
693  virtual int Subst_LBackward( TPZFMatrix<TVar>* b ) const;
694 
699  virtual int Subst_Diag( TPZFMatrix<TVar>* b ) const;
700 
709  public:
710 int ClassId() const override;
711 
712 
718  void Read(TPZStream &buf, void *context) override;
719 
725  void Write(TPZStream &buf, int withclassid) const override;
726 
729 
734  virtual bool Compare(TPZSavable *copy, bool override = false) override;
736 
740  virtual bool Compare(TPZSavable *copy, bool override = false) const override;
741 
743  virtual void GetSub(const TPZVec<int64_t> &indices,TPZFMatrix<TVar>&block) const;
744 
746  bool CompareValues(TPZMatrix<TVar>&M, TVar tol);
747 
748 protected:
749 
754  void PrepareZ(const TPZFMatrix<TVar>& y, TPZFMatrix<TVar>& z,const TVar beta,const int opt) const;
755 
761  inline TPZMatrix<TVar>(const int64_t row,const int64_t col ) : TPZRegisterClassId(&TPZMatrix<TVar>::ClassId)
762  { fRow = row; fCol = col;fDefPositive=0; fDecomposed = 0;}
763 
764 public:
770  static int Error(const char *msg ,const char *msg2 = 0);
771 
772 protected:
774  virtual int Clear() { return 0; }
775 
777  static void Swap(int64_t *a, int64_t *b);
779  int64_t fRow;
781  int64_t fCol;
786  static TVar gZero;
787 };
788 
792 template <class TVar>
793 TVar TPZMatrix<TVar>::gZero = TVar(0);
794 
796 template<class TVar>
797 std::ostream & operator<<(std::ostream& out, const TPZMatrix<TVar> & A);
798 
799 /******** Inline ********/
800 
801 
802 template<class TVar>
803 inline int64_t TPZMatrix<TVar>::Rows() const {
804  return fRow;
805 }
806 
807 
808 template<class TVar>
809 inline int64_t TPZMatrix<TVar>::Cols() const {
810  return fCol;
811 }
812 
813 #ifdef _AUTODIFF
814 template<class TVar>
816  DebugStop();
817 }
818 
819 
820 template<>
822  MultAdd( x, rhs, res, ((double)-1.0), ((double)1.0) );
823 }
824 
825 #else
826 template<class TVar>
828  MultAdd( x, rhs, res, ((TVar)-1.0), ((TVar)1.0) );
829 }
830 #endif
831 
832 /***********/
833 /*** Put ***/
834 
835 template<class TVar>
836 inline int TPZMatrix<TVar>::Put(const int64_t row,const int64_t col,const TVar & value ) {
837  // verificando se o elemento a inserir esta dentro da matriz
838 #ifdef PZDEBUG
839  if ( row >= Rows() || col >= Cols() || row <0 || col < 0 ) {
840  std::stringstream sout;
841  sout << "TPZMatrix<TVar>::Put" << " Index out of range row = " << row << " col = " << col << " Rows() " << Rows() << " Cols() " << Cols() << std::endl;
842  Error(sout.str().c_str());
843  }
844 #endif
845 
846  return( PutVal( row, col, value ) );
847 }
848 
849 
850 
851 /***********/
852 /*** Get ***/
853 
854 template<class TVar>
855 inline const TVar &TPZMatrix<TVar>::Get(const int64_t row, const int64_t col ) const {
856  // verificando se o elemento pedido esta dentro da matriz
857 #ifdef PZDEBUG
858  if ( (row >= Rows()) || (col >= Cols()) || row <0 || col <0 ) {
859  Error("TPZMatrix::Get", "Index out of range");
860  DebugStop();
861  }
862 #endif
863  return( GetVal( row, col ) );
864 }
865 
866 template<class TVar>
867 inline TVar &TPZMatrix<TVar>::operator()(const int64_t row, const int64_t col) {
868  // verificando se o elemento a inserir esta dentro da matriz
869 #ifndef NODEBUG
870  if ( (row >= Rows()) || (col >= Cols()) || row <0 || col<0 ) {
871  Error("TPZMatrix<TVar>::Operator()","Index out of range");
872  DebugStop();
873  }
874 #endif
875  return s(row,col);
876 }
877 
878 template<class TVar>
879 inline TVar &TPZMatrix<TVar>::s(const int64_t row, const int64_t col) {
880  // verificando se o elemento a inserir esta dentro da matriz
881  DebugStop();
882  throw "TPZMatrix<TVar>::s not implemented\n";
883 
884 }
885 
886 template<class TVar>
887 inline TVar &TPZMatrix<TVar>::operator()(const int64_t row) {
888  return operator()(row,0);
889 }
890 
891 template<class TVar>
892 inline int64_t TPZMatrix<TVar>::Dim() const{
893  if ( IsSquare() ) return Rows();
894  Error( "matrix is not square" );
895  return ( 0 );
896 }
897 //***Solve LU ***/
898 
899 template<class TVar>
900 inline int TPZMatrix<TVar>::Solve_LU( TPZFMatrix<TVar>*B, std::list<int64_t> &singular) {
901  if ( IsSimetric() )
902  Error( "LU decomposition is a not symetric decomposition" );
903  return ( ( !Decompose_LU(singular) )? 0 : Substitution( B ) );
904 }
905 
906 template<class TVar>
908  if ( IsSimetric() )
909  Error( "LU decomposition is a not symetric decomposition" );
910  return ( ( !Decompose_LU() )? 0 : Substitution( B ) );
911 }
912 /**********************/
913 /*** Solve Cholesky ***/
914 //
915 // Se nao conseguir resolver por Cholesky retorna 0 e a matriz
916 // sera' modificada (seu valor perdera' o sentido).
917 //
918 template<class TVar>
920 {
921  return(
922  ( !Decompose_Cholesky() )? 0 :( Subst_Forward( B ) && Subst_Backward( B ) )
923  );
924 }
925 
926 template<class TVar>
927 inline int TPZMatrix<TVar>::Solve_Cholesky( TPZFMatrix<TVar>* B, std::list<int64_t> &singular ) {
928  return(
929  ( !Decompose_Cholesky(singular) )? 0 :( Subst_Forward( B ) && Subst_Backward( B ) )
930  );
931 }
932 
933 /******************/
934 /*** Solve LDLt ***/
935 
936 template<class TVar>
938 
939  return(
940  ( !Decompose_LDLt() )? 0 :
941  ( Subst_LForward( B ) && Subst_Diag( B ) && Subst_LBackward( B ) )
942  );
943 }
944 
945 
946 
947 template<class TVar>
948 inline void
949 TPZMatrix<TVar>::Swap( int64_t *a, int64_t *b )
950 {
951  int64_t aux = *a;
952  *a = *b;
953  *b = aux;
954 }
955 
956 template<class TVar>
958  return Hash("TPZMatrix") ^ ClassIdOrHash<TVar>()<<1;
959 }
960 
961 #include "pzfmatrix.h"
962 #include "pzsolve.h"
963 
964 #endif
virtual void SolveSOR(int64_t &numiterations, const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual, TPZFMatrix< TVar > &scratch, const REAL overrelax, REAL &tol, const int FromCurrent=0, const int direction=1)
Solves the linear system using Successive Over Relaxation method (Gauss Seidel). ...
Definition: pzmatrix.cpp:785
#define INCX
virtual int AddSub(const int64_t sRow, const int64_t sCol, const TPZFMatrix< TVar > &Source)
It adds Source matrix on current matrix from position (sRow, sCol)
Definition: pzmatrix.cpp:625
virtual bool SolveEigenvaluesJacobi(int64_t &numiterations, REAL &tol, TPZVec< TVar > *Sort=0)
Transforms this matrix in a diagonal matrix, where the diagonal values are its eigenvalues. This method is efficient only for small matrices.
Definition: pzmatrix.cpp:1727
Contains declaration of the TPZSavable class which defines the interface to save and restore objects ...
virtual void Transpose(TPZMatrix< TVar > *const T) const
It makes *T the transpose of current matrix.
Definition: pzmatrix.cpp:697
virtual int PutSub(const int64_t sRow, const int64_t sCol, const TPZFMatrix< TVar > &Source)
It puts submatrix Source on actual matrix structure.
Definition: pzmatrix.cpp:574
virtual void Residual(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &rhs, TPZFMatrix< TVar > &res)
Computes res = rhs - this * x.
Definition: pzmatrix.h:827
Definition: pzmatrix.h:52
int Solve_LU(TPZFMatrix< TVar > *B, std::list< int64_t > &singular)
Solves the linear system using LU method .
Definition: pzmatrix.h:900
Contains definitions to LOGPZ_DEBUG, LOGPZ_INFO, LOGPZ_WARN, LOGPZ_ERROR and LOGPZ_FATAL, and the implementation of the inline InitializePZLOG(string) function using log4cxx library or not. It must to be called out of "#ifdef LOG4CXX" scope.
bool CompareValues(TPZMatrix< TVar > &M, TVar tol)
Compare values of this to B, with a precision tolerance tol.
Definition: pzmatrix.cpp:1532
virtual void SolveSSOR(int64_t &numiterations, const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual, TPZFMatrix< TVar > &scratch, const REAL overrelax, REAL &tol, const int FromCurrent=0)
Solves the linear system using Symmetric Successive Over Relaxation method (Gauss Seidel)...
Definition: pzmatrix.cpp:828
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
Definition: pzmatrix.cpp:1420
int IsSquare() const
Checks if current matrix is square.
Definition: pzmatrix.h:396
static TVar ReturnNearestValue(TVar val, TPZVec< TVar > &Vec, TVar tol)
Retorna o valor mais proximo a "val" (exceto valores no intervalo -tol <= val <= +tol) contido no vet...
Definition: pzmatrix.cpp:1560
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
Definition: pzmatrix.cpp:1402
TPZVec< T > & Sort(TPZVec< T > &v)
Sorting the elements into v.
Definition: pzvec_extras.h:142
virtual int64_t MemoryFootprint() const
Returns the approximate size of the memory footprint (amount of memory required to store this object)...
Definition: pzmatrix.h:86
Defines a abstract class of solvers which will be used by matrix classes. Solver. ...
Definition: pzmatrix.h:32
Templated vector implementation.
virtual bool SolveEigensystemJacobi(int64_t &numiterations, REAL &tol, TPZVec< TVar > &Eigenvalues, TPZFMatrix< TVar > &Eigenvectors) const
Compute Eigenvalues and Eigenvectors of this matrix. This method is efficient only for small matrice...
Definition: pzmatrix.cpp:1583
virtual int Zero()
Zeroes the matrix.
Definition: pzmatrix.h:296
MatrixOutputFormat
Defines output format.
Definition: pzmatrix.h:55
virtual void Identity()
Converts the matrix in an identity matrix.
Definition: pzmatrix.cpp:199
virtual int Resize(const int64_t newRows, const int64_t newCols)
Redimensions a matriz keeping the previous values.
Definition: pzmatrix.h:278
int64_t fRow
Number of rows in matrix.
Definition: pzmatrix.h:779
virtual const TVar & Get(const int64_t row, const int64_t col) const
Get value with bound checking.
Definition: pzmatrix.h:855
void SetIsDecomposed(int val)
Sets current matrix to decomposed state.
Definition: pzmatrix.h:410
void PrepareZ(const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar beta, const int opt) const
Is an auxiliar method used by MultiplyAdd.
Definition: pzmatrix.cpp:135
virtual TPZMatrix< TVar > * Clone() const =0
int Inverse(TPZFMatrix< TVar > &Inv, DecomposeType dec)
It makes Inv =[this]. IMPORTANT OBSERVATION –> The original matrix (calling object) no is more equal...
Definition: pzmatrix.cpp:1929
char fDecomposed
Decomposition type used to decompose the current matrix.
Definition: pzmatrix.h:783
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
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
virtual ~TPZMatrix()
Simple destructor.
Definition: pzmatrix.cpp:43
char fDefPositive
Definite Posistiveness of current matrix.
Definition: pzmatrix.h:785
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
It computes z = beta * y + alpha * opt(this)*x but z and x can not overlap in memory.
Definition: pzmatrix.cpp:166
static TVar gZero
Initializing value to static variable.
Definition: pzmatrix.h:786
virtual int GetSub(const int64_t sRow, const int64_t sCol, const int64_t rowSize, const int64_t colSize, TPZFMatrix< TVar > &Target) const
Gets submatrix storing it on Target.
Definition: pzmatrix.cpp:602
virtual int Decompose_LDLt()
Decomposes the current matrix using LDLt.
Definition: pzmatrix.cpp:1184
virtual const TVar & GetVal(const int64_t, const int64_t) const
Get values without bounds checking This method is faster than "Get" if DEBUG is defined.
Definition: pzmatrix.cpp:56
virtual TVar & s(const int64_t row, const int64_t col)
The operators check on the bounds if the DEBUG variable is defined.
Definition: pzmatrix.h:879
virtual int Clear()
It clears data structure.
Definition: pzmatrix.h:774
int Solve_LDLt(TPZFMatrix< TVar > *B, std::list< int64_t > &singular)
Solves the linear system using LDLt method .
Definition: pzmatrix.cpp:1993
static const double tol
Definition: pzgeoprism.cpp:23
void CopyFrom(TPZMatrix< TVar2 > &copy)
Definition: pzmatrix.h:96
virtual void SolveGMRES(int64_t &numiterations, TPZSolver< TVar > &preconditioner, TPZFMatrix< TVar > &H, int &numvectors, const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual, REAL &tol, const int FromCurrent)
Solves the linear system using Generalized Minimal Residual (GMRES) method. .
Definition: pzmatrix.cpp:896
virtual int IsSimetric() const
Checks if the current matrix is symmetric.
Definition: pzmatrix.h:394
int IsDecomposed() const
Checks if current matrix is already decomposed.
Definition: pzmatrix.h:405
virtual void SolveBICGStab(int64_t &numiterations, TPZSolver< TVar > &preconditioner, const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual, REAL &tol, const int FromCurrent=0)
Solves the linear system using Bi-Conjugate Gradient stabilized method. .
Definition: pzmatrix.cpp:1024
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
virtual void Add(const TPZMatrix< TVar > &A, TPZMatrix< TVar > &res) const
It adds itself to TPZMatrix<TVar>A putting the result in res.
Definition: pzmatrix.cpp:64
virtual void SolveIR(int64_t &numiterations, TPZSolver< TVar > &preconditioner, const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual, REAL &tol, const int FromCurrent=0)
Solves the linear system using IR method. .
Definition: pzmatrix.cpp:1070
Definition: pzmatrix.h:52
virtual bool Compare(TPZSavable *copy, bool override=false) override
Compare the object for identity with the object pointed to, eventually copy the object.
Definition: pzmatrix.cpp:1433
virtual void SolveCG(int64_t &numiterations, TPZSolver< TVar > &preconditioner, const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual, REAL &tol, const int FromCurrent=0)
Solves the linear system using Conjugate Gradient method. .
Definition: pzmatrix.cpp:850
virtual void SolveJacobi(int64_t &numiterations, const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, TPZFMatrix< TVar > *residual, TPZFMatrix< TVar > &scratch, REAL &tol, const int FromCurrent=0)
Solves the linear system using Jacobi method. .
Definition: pzmatrix.cpp:743
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
TPZMatrix()
Simple constructor.
Definition: pzmatrix.h:67
virtual int Put(const int64_t row, const int64_t col, const TVar &value)
Put values with bounds checking if DEBUG variable is defined.
Definition: pzmatrix.h:836
virtual void AddKel(TPZFMatrix< TVar > &elmat, TPZVec< int64_t > &destinationindex)
Add a contribution of a stiffness matrix.
Definition: pzmatrix.cpp:506
virtual int InsertSub(const int64_t sRow, const int64_t sCol, const int64_t rowSize, const int64_t colSize, const int64_t pRow, const int64_t pCol, TPZMatrix< TVar > *Target) const
Inserts a submatrix from current object on matrix *Target with no redimentioning.
Definition: pzmatrix.cpp:647
string res
Definition: test.py:151
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
Definition: pzmatrix.cpp:1413
virtual void Input(std::istream &in=std::cin)
Input operation.
Definition: pzmatrix.cpp:227
virtual int Redim(const int64_t newRows, const int64_t newCols)
Redimensions the matrix reinitializing it with zero.
Definition: pzmatrix.h:289
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
virtual void SolveBICG(int64_t &numiterations, TPZSolver< TVar > &preconditioner, const TPZFMatrix< TVar > &F, TPZFMatrix< TVar > &result, REAL &tol)
Solves the linear system using Bi-Conjugate Gradient method. .
Definition: pzmatrix.cpp:974
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
virtual int64_t Dim() const
Returns the dimension of the matrix if the matrix is square.
Definition: pzmatrix.h:892
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
virtual int Decompose(const DecomposeType dt, std::list< int64_t > &singular)
decompose the system of equations acording to the decomposition scheme
Definition: pzmatrix.h:572
int64_t fCol
Number of cols in matrix.
Definition: pzmatrix.h:781
virtual int Decompose_Cholesky()
Decomposes the current matrix using Cholesky method. The current matrix has to be symmetric...
Definition: pzmatrix.cpp:1252
virtual int PutVal(const int64_t, const int64_t, const TVar &val)
Put values without bounds checking This method is faster than "Put" if DEBUG is defined.
Definition: pzmatrix.h:154
virtual void Substract(const TPZMatrix< TVar > &A, TPZMatrix< TVar > &result) const
It substracts A from storing the result in result.
Definition: pzmatrix.cpp:75
virtual int VerifySymmetry(REAL tol=1.e-13) const
Checks if current matrix value is symmetric.
Definition: pzmatrix.cpp:1501
double ddot(int *N, double *X, int *INCX, double *Y, int *INCY)
Extern BLAS FUNCTION.
void AutoFill(int64_t nrow, int64_t ncol, int symmetric)
Fill matrix storage with randomic values.
Definition: pzmatrix.cpp:1960
virtual void Multiply(const TPZFMatrix< TVar > &A, TPZFMatrix< TVar > &res, int opt=0) const
It mutiplies itself by TPZMatrix<TVar>A putting the result in res.
Definition: pzmatrix.cpp:1916
Contains TPZSolver class which defines a abstract class of solvers which will be used by matrix class...
static void Swap(int64_t *a, int64_t *b)
Swaps contents of a in b and b in a.
Definition: pzmatrix.h:949
virtual int Decompose_LU()
Definition: pzmatrix.cpp:1126
int64_t Cols() const
Returns number of cols.
Definition: pzmatrix.h:809
virtual void Print(std::ostream &out) const
Definition: pzmatrix.h:253
Contains declaration of the abstract TPZStream class. TPZStream defines the interface for saving and ...
TPZRegisterClassId()=default
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
virtual int Substitution(TPZFMatrix< TVar > *B) const
Computes Forward and Backward substitution for a "LU" decomposed matrix.
Definition: pzmatrix.cpp:1151
virtual int Solve_Cholesky(TPZFMatrix< TVar > *B)
Solves the linear system using Cholesky method .
Definition: pzmatrix.h:919
virtual int IsDefPositive() const
Checks if current matrix is definite positive.
Definition: pzmatrix.h:403
TVar MatrixNorm(int p, int64_t numiter=2000000, REAL tol=1.e-10) const
Computes the matrix norm of this.
Definition: pzmatrix.cpp:1839
const TVar & g(const int64_t row, const int64_t col) const
Substitution for the () operator when const arguments are needed.
Definition: pzmatrix.h:131
TVar ConditionNumber(int p, int64_t numiter=2000000, REAL tol=1.e-10)
Computes the matrix condition number of this.
Definition: pzmatrix.cpp:1902
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
Definition: TPZSavable.h:67
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > >)
Updates the values of the matrix based on the values of the matrix.
Definition: pzmatrix.h:387
TVar & operator()(const int64_t row, const int64_t col)
The operators check on the bounds if the DEBUG variable is defined.
Definition: pzmatrix.h:867
virtual void Simetrize()
Simetrizes copies upper plan to the lower plan, making its data simetric.
Definition: pzmatrix.cpp:90
friend std::istream & operator>>(std::istream &in, TPZMatrix< TT > &A)
Input operation.
virtual int SolveDirect(TPZFMatrix< TVar > &F, const DecomposeType dt, std::list< int64_t > &singular)
Solves the linear system using Direct methods.
Definition: pzmatrix.cpp:710
int ClassId() const override
Define the class id associated with the class.
Definition: pzmatrix.h:957
DecomposeType
Defines decomposition type for any matrix classes.
Definition: pzmatrix.h:52
virtual int Subst_Backward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is upper triangular.
Definition: pzmatrix.cpp:1309
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60
This class implements a reference counter mechanism to administer a dynamically allocated object...