19 static LoggerPtr logger(Logger::getLogger(
"pz.StrMatrix"));
27 int64_t firstpos = fBlockPos[i];
28 int64_t bsize = fBlockSize[i];
31 for(r=0; r<bsize; r++) {
32 for(c=0; c<bsize; c++) {
33 fStorage[firstpos+r+bsize*c] += block(r,c);
40 int64_t firstpos = fBlockPos[i];
41 int64_t bsize = fBlockSize[i];
44 for(r=0; r<bsize; r++) {
45 for(c=0; c<bsize; c++) {
46 fStorage[firstpos+r+bsize*c] = block(r,c);
53 int64_t firstpos = fBlockPos[i];
54 int64_t bsize = fBlockSize[i];
55 block.
Redim(bsize,bsize);
57 for(r=0; r<bsize; r++) {
58 for(c=0; c<bsize; c++) {
59 block(r,c) = fStorage[firstpos+r+bsize*c];
67 if (logger->isDebugEnabled())
69 std::stringstream sout;
70 sout <<
"Number of blocks \t" << nblock;
74 fBlockSize = blocksize;
75 fBlockPos.
Resize(nblock+1,0);
80 for(b=0; b<nblock; b++) {
82 fBlockPos[b+1] = fBlockPos[b]+bsize*bsize;
89 std::stringstream sout;
90 sout <<
"Calling fStorage.Resize(ndata,0.) with ndata = " << ndata;
96 fStorage.Resize(ndata,0.);
97 this->fDecomposed = 0;
104 if(mat.
Rows() != this->Rows()) {
105 cout <<
"TPZBlockDiagonal::BuildFromMatrix wrong data structure\n";
108 int64_t nblock = fBlockSize.NElements();
110 for(b=0; b<nblock; b++) {
111 int r,c,bsize = fBlockSize[b];
112 int64_t pos = fBlockPos[b];
113 for(r=0; r<bsize; r++){
114 for(c=0; c<bsize; c++) {
115 fStorage[pos+r+c*bsize] = mat.
GetVal(eq+r,eq+c);
128 TPZMatrix<TVar>(), fStorage(), fBlockPos(1,0),fBlockSize()
155 for(b=0; b<nblock; b++) {
156 bsize = blocksizes[b];
158 ndata += bsize*bsize;
165 int64_t eq = 0, r, c;
166 for(b=0; b<nblock; b++) {
169 for(r=0; r<bsize; r++) {
170 for(c=0; c<bsize; c++) {
202 if ( (row >=
Dim()) || (col >=
Dim()) || row<0 || col<0)
204 cout <<
"TPZBlockDiagonal::Put: " << row <<
"," << col <<
"," <<
Dim();
209 return(
PutVal( row, col, value ) );
220 cout <<
"TPZBlockDiagonal::PutVal called with parameters out of range\n";
225 while(eq+bsize <= row && b < nb) {
231 cout <<
"TPZBlockDiagonal::PutVal wrong data structure\n";
234 if(col < eq || col >= eq+bsize) {
235 if(value != TVar(0.)) {
236 cout <<
"TPZBlockDiagonal::PutVal, indices row col out of range\n";
255 if ( (row >=
Dim()) || (col >=
Dim()) )
258 return(
GetVal( row, col ) );
268 cout <<
"TPZBlockDiagonal::operator() called with parameters out of range\n";
269 static TVar zero = 0.;
274 while(eq+bsize <= row && b < nb) {
280 cout <<
"TPZBlockDiagonal::operator() wrong data structure\n";
281 static TVar zero = 0.;
284 if(col < eq || col >= eq+bsize) {
285 cout <<
"TPZBlockDiagonal::operator(), indices row col out of range\n";
286 static TVar zero = 0.;
300 cout <<
"TPZBlockDiagonal::GetVal called with parameters out of range\n";
304 while(eq+bsize <= row && b < nb) {
310 cout <<
"TPZBlockDiagonal::GetVal wrong data structure\n";
312 if(col < eq || col >= eq+bsize) {
314 static TVar zero = 0.;
331 const TVar alpha,
const TVar beta ,
const int opt)
const {
336 TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,
"TPZBlockDiagonal::MultAdd <matrixs with incompatible dimensions>" );
342 int64_t xcols = x.
Cols();
347 for (ic = 0; ic < xcols; ic++) {
349 for(b=0; b<nb; b++) {
352 for(r=0; r<bsize; r++) {
353 for(c=0; c<bsize; c++) {
361 cout <<
"xcols \t" << xcols <<
"\n";
362 for (ic = 0; ic < xcols; ic++) {
364 for(b=0; b<nb; b++) {
367 for(r=0; r<bsize; r++) {
368 for(c=0; c<bsize; c++) {
400 int64_t b, eq = 0, pos;
403 for ( b=0; b<nb; b++) {
406 for(r=0; r<bsize; r++) {
407 for(c=0; c<bsize; c++) {
429 LOGPZ_DEBUG(logger,
"TPZBlockDiagonal::Decompose_LU");
434 TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,
"TPZBlockDiagonal::Decompose_LU is already decomposed with other scheme");
446 if (logger->isDebugEnabled())
448 std::stringstream mess;
449 mess <<
"TPZBlockDiagonal::Decompose_LU() - bsize = " << bsize <<
", bsize*bsize = " << bsize*bsize;
455 std::list<int64_t> singular;
456 temp.Decompose_LU(singular);
467 TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,
"TPZBlockDiagonal::Decompose_LU is decomposed with other scheme");
470 int64_t b,nb,pos,bsize,eq=0;
472 int64_t c, nc = B->
Cols();
473 for(c=0; c<nc; c++) {
507 cout <<
"Entering the main program\n";
513 ref(r,c) = ((TVar)(
float)(5+r*c+3*r));
515 ref(r,r) += (TVar)1000;
523 ref.
Print(
"original matrix",std::cout);
526 ref.
Print(
"after inverting the diagonal",std::cout);
530 ref.
Print(
"restoring the original matrix",std::cout);
543 out <<
"TPZBlockDiagonal matrix ";
548 out <<
"Number of blocks " << nblock << std::endl;
550 for(b=0; b<nblock; b++) {
552 out <<
"block number " << b <<
" size : " << bsize << std::endl;
555 for(c=0; c<bsize; c++) {
556 for(r=0; r<bsize ; r++) {
557 out <<
fStorage[pos+r+bsize*c] <<
' ';
572 cout <<
"TPZBlockDiagonal::UpdateFrom" <<
" called with zero argument\n";
577 int64_t b,bsize,pos,firsteq = 0;
578 for(b=0; b<nblock; b++) {
583 mat->GetSub(firsteq,firsteq,bsize,bsize,block);
596 int64_t totalsize = 0;
597 while (totalsize < neq) {
598 int64_t blsize = (neq*rand())/RAND_MAX;
599 blsize = blsize < neq-totalsize ? blsize : neq-totalsize;
600 blsizes.
Push(blsize);
605 int64_t b, bsize, eq = 0, pos;
607 for ( b=0; b<nb; b++) {
610 for(c=0; c<bsize; c++) {
613 if (symmetric == 1) {
614 for (r=0; r<c; r++) {
619 for(; r<bsize; r++) {
620 float val = ((float)rand())/RAND_MAX;
621 fStorage[pos+c+r*bsize] = (TVar)(val);
622 if(c!= r) sum +=
fabs(val);
630 fStorage[pos+c+c*bsize] = (TVar)(sum + (
float)1.);
virtual void UpdateFrom(TPZAutoPointer< TPZMatrix< TVar > > mat) override
Updates the values of the matrix based on the values of the matrix.
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
Computes z = alpha * opt(this)*x + beta * y.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
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.
virtual int Substitution(TPZFMatrix< TVar > *B) const override
Makes the backward and forward substitutions whether the matrix was LU decomposed.
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
void Transpose(TPZMatrix< TVar > *const T) const override
It makes *T the transpose of current matrix.
MatrixOutputFormat
Defines output format.
virtual int Resize(const int64_t newRows, const int64_t newCols)
Redimensions a matriz keeping the previous values.
void BuildFromMatrix(TPZMatrix< TVar > &matrix)
Builds a block from matrix.
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.
char fDecomposed
Decomposition type used to decompose the current matrix.
REAL val(STATE &number)
Returns value of the variable.
Contains TPZBlockDiagonal class which defines block diagonal matrices.
int Clear() override
Clean data matrix. Zeroes number of columns and rows.
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.
~TPZBlockDiagonal()
Simple destructor.
virtual void Print(const char *message, std::ostream &out=std::cout, const MatrixOutputFormat format=EFormatted) const override
Prints current matrix data.
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
int Put(const int64_t row, const int64_t col, const TVar &value) override
Put values with bounds checking if DEBUG variable is defined.
void Push(const T object)
Pushes a copy of the object on the stack.
Contains TPZMatrixclass which implements full matrix (using column major representation).
#define DebugStop()
Returns a message to user put a breakpoint in.
#define LOGPZ_DEBUG(A, B)
Define log for debug info.
int64_t Rows() const
Returns number of rows.
TPZVec< int > fBlockSize
Stores block sizes data.
void SetBlock(int64_t i, TPZFMatrix< TVar > &block)
Sets a block in the current matrix.
void AutoFill(int64_t dim, int64_t dimj, int symmetric)
static int Substitution(const TVar *ptr, int64_t rows, TPZFMatrix< TVar > *B)
T * begin() const
Casting operator. Returns The fStore pointer.
virtual int Decompose_LU() override
const TVar & GetVal(const int64_t row, const int64_t col) const override
This method don't make verification if the element exist. It is fast than Get.
void AddBlock(int64_t i, TPZFMatrix< TVar > &block)
Adds a block to current matrix.
Full matrix class. Matrix.
int Redim(const int64_t newRows, const int64_t newCols) override
Redimension a matrix and ZERO your elements.
int32_t Hash(std::string str)
const TVar & Get(const int64_t row, const int64_t col) const override
Get value with bound checking.
int64_t fCol
Number of cols in matrix.
void Initialize(const TPZVec< int > &blocksize)
Initializes current matrix based on blocksize.
Defines block diagonal matrices. Matrix.
int Zero() override
Zeroes all the elements of the matrix.
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.
TPZVec< TVar > fStorage
Stores matrix data.
int PutVal(const int64_t row, const int64_t col, const TVar &value) override
This method don't make verification if the element exist. It is fast than Put.
TPZBlockDiagonal()
Simple constructor.
void GetBlock(int64_t i, TPZFMatrix< TVar > &block)
Gets a block from current matrix.
TVar & operator()(const int64_t row, const int64_t col)
static int main()
This method checks the working of the class.
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.
TPZVec< int64_t > fBlockPos
Stores blocks data.
void Fill(const T ©, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
int64_t Cols() const
Returns number of cols.
virtual void Print(std::ostream &out) const
int64_t NElements() const
Returns the number of elements of the vector.
int64_t Dim() const override
Returns the dimension of the matrix if the matrix is square.
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 ClassId() const override
Define the class id associated with the class.
Root matrix class (abstract). Matrix.
This class implements a reference counter mechanism to administer a dynamically allocated object...
int ClassId() const override
Define the class id associated with the class.