45 #define GETVAL(MAT,rows,row,col) MAT->fElem[((unsigned)col)*rows+row] 47 #define PUTVAL(MAT,rows,row,col,val) MAT->fElem[((unsigned)col)*rows+row]=val 49 #define SELECTEL(ptr,rows,row,col) ptr[col*rows+row] 68 template<
class TVar=REAL>
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) :
99 if(rows*columns)
fElem =
new TVar[rows*columns];
123 inline TPZFMatrix(
const std::initializer_list<TVar>& list);
129 inline TPZFMatrix(
const std::initializer_list< std::initializer_list<TVar> > &list);
137 return (
sizeof(TVar)*this->
Rows()*this->
Cols());
149 template<
class TVar2>
154 int64_t nel = orig.
Rows()*orig.
Cols();
155 for (int64_t el=0; el<nel; el++) {
170 std::cout <<
"TPZMatrix<TVar>::UdateFrom is not implemented\n";
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;
178 virtual TVar &
s(
const int64_t row,
const int64_t col)
override;
180 TVar &
g(
const int64_t row,
const int64_t col)
const;
206 const TVar alpha=1.,
const TVar beta = 0.,
const int opt = 0)
const override;
210 const TVar alpha=1.,
const TVar beta = 0.,
const int opt = 0);
216 TVar &
operator()(
const int64_t row,
const int64_t col);
273 int Resize(
const int64_t newRows,
const int64_t wCols )
override;
276 int SetSize(int64_t newRows, int64_t newCols);
279 int Remodel(
const int64_t newRows,
const int64_t wCols );
282 int Redim(
const int64_t newRows,
const int64_t newCols )
override;
289 void InitializePivot();
318 virtual int Decompose_LU(std::list<int64_t> &singular)
override;
382 virtual int SolveEigenProblem(
TPZVec < std::complex<double> > &w,
TPZFMatrix < std::complex<double> > &eigenVectors);
386 virtual int SolveEigenProblem(
TPZVec < std::complex<double> > &w);
422 operator const TVar*()
const {
return fElem; }
428 static int Error(
const char *msg1,
const char *msg2=0 );
429 int Clear()
override;
448 int64_t size = rows * cols;
455 fElem=
new TVar[size];
457 if (
fElem == NULL && size)
Error(
"Constructor <memory allocation error>." );
465 int64_t size = rows * cols;
467 fElem=
new TVar[size];
469 if (
fElem == NULL && size)
Error(
"Constructor <memory allocation error>." );
471 for(int64_t i=0;i<size;i++)
fElem[i] = val;
478 if (list.size() > 0) {
479 this->
fElem =
new TVar[list.size()];
482 auto it = list.begin();
483 auto it_end = list.end();
485 for (; it != it_end; it++, aux++)
489 template<
class TVar >
493 this->
fRow = list.size();
495 auto row_it = list.begin();
496 auto row_it_end = list.end();
499 bool col_n_found =
false;
500 for (
auto it = row_it; it != row_it_end; it++) {
502 this->
fCol = it->size();
505 if (this->
fCol != it->size())
506 Error(
"TPZFMatrix constructor: inconsistent number of columns in initializer list");
510 this->
fCol = row_it->size();
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;
537 Error(
"Operator* <matrixs with incompatible dimensions>" );
549 fElem[ ((unsigned)col) * this->
Rows() + row ] = value;
568 if(row >= this->
Rows() || row<0 || col >= this->
Cols() || col<0) {
569 Error(
"TPZFMatrix::operator() ",
" Index out of bounds");
579 if(row >= this->
Rows() || row<0 || col >= this->
Cols() || col<0) {
580 Error(
"TPZFMatrix<TVar>::operator() ",
" Index out of bounds");
584 return *(this->
fElem+col*this->
fRow+row);
596 if(row >= this->
Rows() || row<0 || col >= this->
Cols() || col<0) {
597 Error(
"TPZFMatrix<TVar>::operator() ",
" Index out of bounds");
601 return *(this->
fElem+col*this->
fRow+row);
607 if(row >= this->
Rows() || row<0) {
608 Error(
"TPZFMatrix<TVar>::operator() ",
" Index out of bounds");
612 return *(this->
fElem+row);
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;
629 }
else if(newsize == 0) {
632 this->
fElem =
new TVar[ newsize ] ;
635 if (newsize && this->
fElem == NULL )
636 Error(
"Resize <memory allocation error>." );
639 this->
fRow = newRows;
640 this->fCol = newCols;
652 int64_t size = this->
fRow * this->
fCol *
sizeof(TVar);
653 memset(((
void*)this->
fElem),
'\0',size);
662 return (int64_t)
sqrt((REAL)
Dot(A,A));
666 return (
int)
sqrt((REAL)
Dot(A,A));
715 template<
int N,
class TVar=REAL>
777 template<
int N,
class TVar>
782 template<
int N,
class TVar>
788 template<
int N,
class TVar>
791 buf.
Write(fBuf, N+1);
virtual TVar & s(const int64_t row, const int64_t col) override
The operators check on the bounds if the DEBUG variable is defined.
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
TPZFNMatrix(const TPZFMatrix< TVar > ©)
TPZFMatrix< TVar > operator*(TPZFMatrix< TVar > A) const
void ZAXPY(const TVar alpha, const TPZFMatrix< TVar > &p)
Performs an ZAXPY operation being *this += alpha * p.
TVar & operator()(const int64_t row, const int64_t col)
void GramSchmidt(TPZFMatrix< TVar > &Orthog, TPZFMatrix< TVar > &TransfToOrthog)
This method implements a Gram Schimidt method. this = Orthog.TransfToOrthog.
void AddFel(TPZFMatrix< TVar > &rhs, TPZVec< int64_t > &destination)
Performs a right hand side assemblage.
TPZFMatrix< TVar > & operator*=(const TVar val)
Templated vector implementation.
int64_t MemoryFootprint() const override
Returns the approximate size of the memory footprint (amount of memory required to store this object)...
TPZFMatrix< TVar > & operator-=(const TPZFMatrix< TVar > &A)
MatrixOutputFormat
Defines output format.
TPZFNMatrix(int64_t row, int64_t col)
int64_t fRow
Number of rows in matrix.
static int Error(const char *msg1, const char *msg2=0)
virtual int Decompose_LU() override
char fDecomposed
Decomposition type used to decompose the current matrix.
int ClassId() const override
Routines to send and receive messages.
TVar Dot(const TPZFMatrix< TVar > &A, const TPZFMatrix< TVar > &B)
Returns a dot product to matrices.
virtual int Subst_LBackward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is upper triangular with A(i,i)=1.
TPZFMatrix< TVar > & operator+=(const TPZFMatrix< TVar > &A)
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > > mat) override
Updates the values of the matrix based on the values of the matrix.
This class implements a simple vector storage scheme for a templated class T. Utility.
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.
int ClassId() const override
Routines to send and receive messages.
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.
TPZFMatrix< TVar > & operator=(const TPZFMatrix< TVar > ©) override
Generic operator with FULL matrices.
TPZFMatrix(const int64_t rows, const int64_t columns=1)
Constructor with initialization parameters.
TPZFMatrix< TVar > operator-(const TPZFMatrix< TVar > &A) const
int Zero() override
Makes Zero all the elements.
virtual ~TPZFMatrix()
Simple destructor.
void Read(TPZStream &buf, void *context) override
read objects from the stream
void CopyFrom(TPZMatrix< TVar2 > ©)
virtual void Write(const bool val)
TVar Norm(const TPZFMatrix< TVar > &A)
Returns the norm of the matrix A.
#define DebugStop()
Returns a message to user put a breakpoint in.
Implements a matrix whose nonzero elements are stored in binary tree. Matrix.
Free store vector implementation.
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.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
virtual TPZFMatrix & operator=(const TPZFMatrix< TVar > &A)
Generic operator with FULL matrices.
Contains declaration of the TPZAutoPointer class which has Increment and Decrement actions are mutexe...
TPZFNMatrix< N, TVar > & operator=(const TPZFNMatrix< N, TVar > ©)
TPZFMatrix< TVar > & operator-=(const TVar val)
static int Substitution(const TVar *ptr, int64_t rows, TPZFMatrix< TVar > *B)
Full matrix class. Matrix.
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
virtual int Subst_LForward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is lower triangular with A(i,i)=1.
int32_t Hash(std::string str)
Contains TPZMatrix<TVar>class, root matrix class.
int64_t fCol
Number of cols in matrix.
void Read(TPZStream &buf, void *context) override
read objects from the stream
int Clear() override
It clears data structure.
void CopyFrom(TPZFMatrix< TVar2 > &orig)
copy the values from a matrix with a different precision
void TimesBetaPlusZ(const TVar beta, const TPZFMatrix< TVar > &z)
Performs an operation *this = this * beta + z.
int Remodel(const int64_t newRows, const int64_t wCols)
Remodel the shape of the matrix, but keeping the same dimension.
This class implements floating point number associated with a counter of the operations performed wit...
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.
int64_t Cols() const
Returns number of cols.
int Resize(const int64_t newRows, const int64_t wCols) override
Redimension a matrix, but maintain your elements.
TPZRegisterClassId()=default
virtual int Decompose_Cholesky() override
Cholesky Decomposition Optmized. for walks in the direction of the vector that composes the matrix...
Defines the interface for saving and reading data. Persistency.
#define CLONEDEF(A)
To create clone matrix.
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
void DeterminantInverse(TVar &determinant, TPZFMatrix< TVar > &inverse)
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
int SetSize(int64_t newRows, int64_t newCols)
Redimension the matrix doing nothing with the elements.
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
static void PrintStatic(const TVar *ptr, int64_t rows, int64_t cols, const char *name, std::ostream &out, const MatrixOutputFormat form)
virtual bool Compare(TPZSavable *copy, bool override=false) override
Compare the object for identity with the object pointed to, eventually copy the object.
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.
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.
TVar & g(const int64_t row, const int64_t col) const
TPZFMatrix< TVar > operator+(const TPZFMatrix< TVar > &A) const
TPZFNMatrix(const TPZFNMatrix< N, TVar > ©)
Non abstract class which implements full matrices with preallocated storage with (N+1) entries...
virtual void Read(bool &val)
virtual int Subst_Backward(TPZFMatrix< TVar > *b) const
Computes B = Y, where A*Y = B, A is upper triangular.
TPZFMatrix()
Simple constructor.
Root matrix class (abstract). Matrix.
This class implements a reference counter mechanism to administer a dynamically allocated object...