28 #define CLONEDEF(A) virtual TPZMatrix<TVar>*Clone() const override { return new A(*this); } 37 double ddot(
int *N,
double *X,
int *
INCX,
double *Y,
int *INCY);
59 template<
class TVar=REAL>
87 std::cout << __PRETTY_FUNCTION__
88 <<
": Please, implement me! (class = " <<
ClassId()
107 void AutoFill(int64_t nrow, int64_t ncol,
int symmetric);
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;
131 const TVar &
g(
const int64_t row,
const int64_t col)
const {
return Get(row,col);}
138 TVar &
operator() (
const int64_t row,
const int64_t col );
144 virtual TVar &
s(
const int64_t row,
const int64_t col);
154 virtual int PutVal(
const int64_t ,
const int64_t ,
const TVar &
val )
162 virtual const TVar &
GetVal(
const int64_t ,
const int64_t )
const;
192 const TVar alpha=1.,
const TVar beta = 0.,
const int opt = 0)
const;
224 TVar
MatrixNorm(
int p, int64_t numiter = 2000000, REAL
tol = 1.e-10)
const;
248 virtual void Input(std::istream & in = std::cin );
253 virtual void Print(std::ostream &out)
const 255 std::string name = __PRETTY_FUNCTION__;
256 Print(name.c_str(),out);
264 int64_t
Rows()
const;
266 int64_t
Cols()
const;
270 inline virtual int64_t
Dim()
const;
278 virtual int Resize(
const int64_t newRows,
const int64_t newCols ) {
289 virtual int Redim(
const int64_t newRows,
const int64_t newCols ) {
297 std::cout <<
"WARNING! TPZMatrix<TVar>::Zero is called\n";
325 virtual int GetSub(
const int64_t sRow,
const int64_t sCol,
const int64_t rowSize,
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;
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;
389 std::cout <<
"TPZMatrix<TVar>::UdateFrom is not implemented\n";
449 const int FromCurrent = 0,
const int direction = 1) ;
463 const int FromCurrent = 0) ;
478 const int FromCurrent = 0) ;
504 const int FromCurrent = 0) ;
536 const int FromCurrent = 0);
770 static int Error(
const char *msg ,
const char *msg2 = 0);
777 static void Swap(int64_t *a, int64_t *b);
792 template <
class TVar>
797 std::ostream & operator<<(std::ostream& out, const TPZMatrix<TVar> & A);
822 MultAdd( x, rhs, res, ((
double)-1.0), ((
double)1.0) );
828 MultAdd( x, rhs, res, ((TVar)-1.0), ((TVar)1.0) );
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());
846 return(
PutVal( row, col, value ) );
858 if ( (row >=
Rows()) || (col >=
Cols()) || row <0 || col <0 ) {
859 Error(
"TPZMatrix::Get",
"Index out of range");
863 return(
GetVal( row, col ) );
870 if ( (row >=
Rows()) || (col >=
Cols()) || row <0 || col<0 ) {
871 Error(
"TPZMatrix<TVar>::Operator()",
"Index out of range");
882 throw "TPZMatrix<TVar>::s not implemented\n";
894 Error(
"matrix is not square" );
902 Error(
"LU decomposition is a not symetric decomposition" );
909 Error(
"LU decomposition is a not symetric decomposition" );
958 return Hash(
"TPZMatrix") ^ ClassIdOrHash<TVar>()<<1;
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). ...
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)
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.
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.
virtual int PutSub(const int64_t sRow, const int64_t sCol, const TPZFMatrix< TVar > &Source)
It puts submatrix Source on actual matrix structure.
virtual void Residual(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &rhs, TPZFMatrix< TVar > &res)
Computes res = rhs - this * x.
int Solve_LU(TPZFMatrix< TVar > *B, std::list< int64_t > &singular)
Solves the linear system using LU method .
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.
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)...
void Write(TPZStream &buf, int withclassid) const override
Packs the object structure in a stream of bytes.
int IsSquare() const
Checks if current matrix is square.
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...
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
TPZVec< T > & Sort(TPZVec< T > &v)
Sorting the elements into v.
virtual int64_t MemoryFootprint() const
Returns the approximate size of the memory footprint (amount of memory required to store this object)...
Defines a abstract class of solvers which will be used by matrix classes. Solver. ...
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...
virtual int Zero()
Zeroes the matrix.
MatrixOutputFormat
Defines output format.
virtual void Identity()
Converts the matrix in an identity matrix.
virtual int Resize(const int64_t newRows, const int64_t newCols)
Redimensions a matriz keeping the previous values.
int64_t fRow
Number of rows in matrix.
virtual const TVar & Get(const int64_t row, const int64_t col) const
Get value with bound checking.
void SetIsDecomposed(int val)
Sets current matrix to decomposed state.
void PrepareZ(const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar beta, const int opt) const
Is an auxiliar method used by MultiplyAdd.
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...
char fDecomposed
Decomposition type used to decompose the current matrix.
virtual int Subst_LBackward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is upper triangular with A(i,i)=1.
REAL val(STATE &number)
Returns value of the variable.
virtual int Subst_Forward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is lower triangular.
virtual ~TPZMatrix()
Simple destructor.
char fDefPositive
Definite Posistiveness of current matrix.
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.
static TVar gZero
Initializing value to static variable.
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.
virtual int Decompose_LDLt()
Decomposes the current matrix using LDLt.
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.
virtual TVar & s(const int64_t row, const int64_t col)
The operators check on the bounds if the DEBUG variable is defined.
virtual int Clear()
It clears data structure.
int Solve_LDLt(TPZFMatrix< TVar > *B, std::list< int64_t > &singular)
Solves the linear system using LDLt method .
void CopyFrom(TPZMatrix< TVar2 > ©)
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. .
virtual int IsSimetric() const
Checks if the current matrix is symmetric.
int IsDecomposed() const
Checks if current matrix is already decomposed.
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. .
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
virtual void Add(const TPZMatrix< TVar > &A, TPZMatrix< TVar > &res) const
It adds itself to TPZMatrix<TVar>A putting the result in res.
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. .
virtual bool Compare(TPZSavable *copy, bool override=false) override
Compare the object for identity with the object pointed to, eventually copy the object.
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. .
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. .
int64_t Rows() const
Returns number of rows.
virtual int Subst_Diag(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is diagonal matrix.
TPZMatrix()
Simple constructor.
virtual int Put(const int64_t row, const int64_t col, const TVar &value)
Put values with bounds checking if DEBUG variable is defined.
virtual void AddKel(TPZFMatrix< TVar > &elmat, TPZVec< int64_t > &destinationindex)
Add a contribution of a stiffness matrix.
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.
void Read(TPZStream &buf, void *context) override
Unpacks the object structure from a stream of bytes.
virtual void Input(std::istream &in=std::cin)
Input operation.
virtual int Redim(const int64_t newRows, const int64_t newCols)
Redimensions the matrix reinitializing it with zero.
Full matrix class. Matrix.
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. .
virtual int Subst_LForward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is lower triangular with A(i,i)=1.
virtual int64_t Dim() const
Returns the dimension of the matrix if the matrix is square.
int32_t Hash(std::string str)
virtual int Decompose(const DecomposeType dt, std::list< int64_t > &singular)
decompose the system of equations acording to the decomposition scheme
int64_t fCol
Number of cols in matrix.
virtual int Decompose_Cholesky()
Decomposes the current matrix using Cholesky method. The current matrix has to be symmetric...
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.
virtual void Substract(const TPZMatrix< TVar > &A, TPZMatrix< TVar > &result) const
It substracts A from storing the result in result.
virtual int VerifySymmetry(REAL tol=1.e-13) const
Checks if current matrix value is symmetric.
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.
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.
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.
virtual int Decompose_LU()
int64_t Cols() const
Returns number of cols.
virtual void Print(std::ostream &out) const
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.
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.
virtual int Solve_Cholesky(TPZFMatrix< TVar > *B)
Solves the linear system using Cholesky method .
virtual int IsDefPositive() const
Checks if current matrix is definite positive.
TVar MatrixNorm(int p, int64_t numiter=2000000, REAL tol=1.e-10) const
Computes the matrix norm of this.
const TVar & g(const int64_t row, const int64_t col) const
Substitution for the () operator when const arguments are needed.
TVar ConditionNumber(int p, int64_t numiter=2000000, REAL tol=1.e-10)
Computes the matrix condition number of this.
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > >)
Updates the values of the matrix based on the values of the matrix.
TVar & operator()(const int64_t row, const int64_t col)
The operators check on the bounds if the DEBUG variable is defined.
virtual void Simetrize()
Simetrizes copies upper plan to the lower plan, making its data simetric.
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.
int ClassId() const override
Define the class id associated with the class.
DecomposeType
Defines decomposition type for any matrix classes.
virtual int Subst_Backward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is upper triangular.
Root matrix class (abstract). Matrix.
This class implements a reference counter mechanism to administer a dynamically allocated object...