17 static LoggerPtr logger(Logger::getLogger(
"pz.matrix.tpzspmatrix"));
40 for(int64_t i=0; i<rows; i++)
fElem[i].SetWorkPool(&fWp);
62 if ( (row >= this->
Rows()) || (col >= this->
Cols()) || row <0 || col<0)
65 return(
PutVal( row, col, value ) );
77 if ( (row >= this->
Rows()) || (col >= this->
Cols()) || row<0 || col<0)
80 return(
GetVal( row, col ) );
104 while ( pRow->
Get( &node ) && (node.
col < col) )
110 if ( node.
col == col )
122 else if ( !
IsZero( value ) )
151 while ( pRow->
Get( &node ) && (node.
col < col) )
155 if ( node.
col == col )
191 if ( ! res.
fAdd( &A ) )
207 if ( ! res.
fSub( &A ) )
275 for ( int64_t i = 0; i < this->
Rows(); i++ )
290 if ( newRows == this->
Rows() )
297 int64_t min =
MIN( newRows, this->
Rows() );
298 for ( int64_t i = 0; i < min; i++ )
299 newDiag[i] =
fElem[i];
305 this->
fRow=newRows;this->
fCol=newCols;
318 this->
fCol = newCols;
355 for ( int64_t row = 0; row < this->
Rows(); row++, pm++, pa++ )
360 int64_t mOk = pm->Get( &mNode );
361 int64_t aOk = pa->
Get( &aNode );
367 if ( mNode.
col == aNode.
col )
373 mOk = pm->Get( &mNode );
374 aOk = pa->
Get( &aNode );
379 else if ( mNode.
col > aNode.
col )
387 aOk = pa->
Get( &aNode );
395 mOk = pm->Get( &mNode );
403 while ( pa->
Get( &aNode ) )
428 for ( int64_t row = 0; row < this->
Rows(); row++, pm++, pa++ )
433 int64_t mOk = pm->Get( &mNode );
434 int64_t aOk = pa->
Get( &aNode );
440 if ( mNode.
col == aNode.
col )
446 mOk = pm->Get( &mNode );
447 aOk = pa->
Get( &aNode );
452 else if ( mNode.
col > aNode.
col )
461 aOk = pa->
Get( &aNode );
469 mOk = pm->Get( &mNode );
477 while ( pa->
Get( &aNode ) )
507 for ( int64_t i = 0; i < this->
fRow; i++ )
522 for ( int64_t row = 0; row < this->
Rows(); row++, pm++ )
525 while ( pm->
Get( &node ) )
554 int64_t again_i = row_i->
Get( &node_i ) && (node_i.
col < k);
555 int64_t again_j = row_j->
Get( &node_j ) && (node_j.
col < k);
557 while ( again_i && again_j )
559 if ( node_i.
col > node_j.
col )
562 again_j = row_j->
Get( &node_j ) && (node_j.
col < k);
564 else if ( node_i.
col < node_j.
col )
567 again_i = row_i->
Get( &node_i ) && (node_i.
col < k);
569 else if ( node_i.
col == node_j.
col )
574 again_i = row_i->
Get( &node_i ) && (node_i.
col < k);
575 again_j = row_j->
Get( &node_j ) && (node_j.
col < k);
583 again_i = row_i->
Get( &node_i ) && (node_i.
col < k);
590 again_j = row_j->
Get( &node_j ) && (node_j.
col < k);
598 const REAL alpha,
const REAL beta,
const int opt)
const {
600 TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,
"TPZSpMatrix::MultAdd <matrixs with incompatible dimensions>" );
604 int64_t rows = this->
Rows();
605 int64_t xcols = x.
Cols();
609 for (ic = 0; ic < xcols; ic++) {
611 const REAL* firstel = &x.
g(0,ic);
613 for ( r = 0; r < rows; r++ ) {
615 if(!runner->
Head())
continue;
617 currentnode = runner->
GetNode();
619 val += *(firstel+(currentnode->
col)) * currentnode->
elem;
621 currentnode = runner->
GetNode();
623 z(r,ic) += alpha*
val;
626 TVar * firstelz = &z(0,ic);
628 for (r = 0; r<rows; r++) {
629 TVar elx = x.
g(r,ic);
631 if(!runner->
Head())
continue;
633 currentnode = runner->
GetNode();
634 *(firstelz+(currentnode->
col)) += alpha* elx * currentnode->
elem;
635 }
while (runner->
Next());
646 TMatrix::Unpack(buf);
653 for(int64_t i=0;i<rows;i++) {
655 buf->UpkDouble(&val);
675 int64_t rows =
Rows();
677 for ( int64_t row = 0; row < rows; row++, pm++ )
681 while ( pm->
Get( &node ) )
688 while ( pm->
Get( &node ) )
691 buf->PkDouble(&node.
elem);
692 buf->PkInt(&node.
col);
701 return TMatrix::DerivedFrom(Classid);
707 if(!strcmp(ClassName(),classname))
return 1;
708 return TMatrix::DerivedFrom(classname);
int Update(ElemType &elem)
Updates the current list.
TPZSpMatrix & operator-=(const TPZSpMatrix< TVar > &A)
TPZLink< TPZNode > * fElem
int fSub(const TPZSpMatrix< TVar > *const A)
const int64_t numel
Number of elements to test.
bool IsZero(long double a)
Returns if the value a is close Zero as the allowable tolerance.
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.
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
int fCopy(const TPZSpMatrix< TVar > *const A)
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.
int Remove()
Removes an element from the list.
int Clear() override
It clears data structure.
ElemType * GetNode()
Returns the node's element type.
int64_t fRow
Number of rows in matrix.
void PrepareZ(const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const TVar beta, const int opt) const
Is an auxiliar method used by MultiplyAdd.
TPZSpMatrix()
Simple constructor.
int Next()
Moves to the next element on list.
char fDecomposed
Decomposition type used to decompose the current matrix.
REAL val(STATE &number)
Returns value of the variable.
int Insert(ElemType &elem)
Inserts a element on the list.
Implements a linked list of ElemType elements. Matrix utility.
Defines sparce matrix class. Matrix.
virtual void MultAdd(const TPZFMatrix< TVar > &x, const TPZFMatrix< TVar > &y, TPZFMatrix< TVar > &z, const REAL alpha, const REAL beta=0., const int opt=0) const override
int Get(ElemType *pElem)
Returns an element from the list.
Contains TPZMatrixclass which implements full matrix (using column major representation).
~TPZSpMatrix()
Simple destructor.
TPZSpMatrix & operator=(const TPZSpMatrix< TVar > &A)
Generic overloaded operator.
int Zero() override
Zeroes all elements of the matrix.
Contains TPZSpMatrix class which defines sparse matrix class.
int64_t Rows() const
Returns number of rows.
static TPZSavable * CreateInstance(const int &classId)
TPZSpMatrix & Reset()
Desallocate all the elements of the matrix.
#define MIN(a, b)
Gets minime value between a and b.
Full matrix class. Matrix.
const TVar & Get(const int64_t row, const int64_t col) const override
Get value with bound checking.
int32_t Hash(std::string str)
TPZSpMatrix & operator+=(const TPZSpMatrix< TVar > &A)
int64_t fCol
Number of cols in matrix.
int fAdd(const TPZSpMatrix< TVar > *const A)
TPZSpMatrix operator+(const TPZSpMatrix< TVar > &A) const
REAL ProdEsc(TPZLink< TPZNode > *row_i, TPZLink< TPZNode > *row_j, int64_t k)
Computes dot product with respect to lines row_i e row_j using only elements that belongs to columns ...
int Put(const int64_t row, const int64_t col, const TVar &value) override
Put values with bounds checking if DEBUG variable is defined.
TPZSpMatrix operator-() const
int64_t Cols() const
Returns number of cols.
TPZSpMatrix & operator*=(const TVar v)
int PutVal(const int64_t row, const int64_t col, const TVar &element) override
Put values without bounds checking This method is faster than "Put" if DEBUG is defined.
int ClassId() const override
Define the class id associated with the class.
clarg::argString m("-m", "input matrix file name (text format)", "matrix.txt")
Contains TPZLink class which implements a linked list of ElemType elements.
int Head()
Returns to the head of the list.
TVar & g(const int64_t row, const int64_t col) const
TPZSpMatrix operator*(const TVar v) const
Numerical values operator.
int ClassId() const override
Define the class id associated with the class.
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension the matrix to newRows x newCols arrange and zeroes its elements.
int Resize(const int64_t newRows, const int64_t newCols) override
Redimension the matrix to newRows x newCols arrange.
Root matrix class (abstract). Matrix.