15 static LoggerPtr logger(Logger::getLogger(
"pz.matrix.tpzblock"));
32 if(pMatrix) MaxBlocks = ( nBlocks ? nBlocks : pMatrix->
Rows() );
33 else MaxBlocks = nBlocks;
36 if(MaxBlocks)
fBlock.Resize(MaxBlocks);
48 mat_size = pMatrix->
Rows();
49 if ( (dim*nBlocks!=mat_size) )
50 dim2 = mat_size/MaxBlocks;
55 for (
int i = 0; i <
fBlock.NElements(); i++, pos += dim2 )
60 if(MaxBlocks && dim2)
fBlock[MaxBlocks-1].dim = dim2 + mat_size%dim2;
61 else if(MaxBlocks)
fBlock[MaxBlocks-1].dim = mat_size-dim2;
74 if(
this == &bl)
return *
this;
95 int MaxBlocks =
fBlock.NAlloc();
96 if(num_of_blocks >= MaxBlocks)
fBlock.Expand((
int) (num_of_blocks*1.2));
98 fBlock.Resize(num_of_blocks,copy);
99 if(num_of_blocks == MaxBlocks)
return 1;
105 if ( b >=
fBlock.NElements() ) {
106 cout <<
"TPZBlock::Set called with parameter out of range\n";
128 for(i=0;i<nel;i++) total_dim += dimensions[i];
129 if ( total_dim !=
fpMatrix->Rows() ||
131 TPZMatrix<TVar>::Error(__PRETTY_FUNCTION__,
"SetAll <new block dimensions not compatible whit matrix dimension>");
141 pos=pos+(
fBlock[i].dim=dimensions[i]);
151 int MaxBlocks =
fBlock.NElements();
152 if (start>=MaxBlocks)
return 0;
153 for (
int i= start+1; i < MaxBlocks; i++)
164 int MaxBlocks =
fBlock.NElements();
165 if ( index >= MaxBlocks )
178 int MaxBlocks =
fBlock.NElements();
179 for (
int i = 0; i < MaxBlocks-1; i++ )
194 int MaxBlocks =
fBlock.NElements();
195 if ( (bRow >= MaxBlocks) || (bCol >= MaxBlocks) )
198 int rowDim =
fBlock[bRow].dim;
199 int colDim =
fBlock[bCol].dim;
202 if ( !rowDim || !colDim )
205 if ( (row >= rowDim) || (col >= colDim) )
210 return(
fpMatrix->Get( row, col ) );
220 int MaxBlocks =
fBlock.NElements();
222 if ( (bRow >= MaxBlocks) || (bCol >= MaxBlocks) )
225 int rowDim =
fBlock[bRow].dim;
226 int colDim =
fBlock[bCol].dim;
228 if ( !rowDim || !colDim )
231 if ( (row >= rowDim) || (col >= colDim) )
236 return(
fpMatrix->Put( row, col, value ) );
246 int MaxBlocks =
fBlock.NElements();
247 if ( (bRow >= MaxBlocks) )
252 int rowDim =
fBlock[bRow].dim;
260 if ( (row >= rowDim) || (col >=
fpMatrix->Cols()) )
266 return(
fpMatrix->Get( row, col ) );
276 int MaxBlocks =
fBlock.NElements();
278 if ( (bRow >= MaxBlocks) )
281 int rowDim =
fBlock[bRow].dim;
286 if ( (row >= rowDim) || (col >=
fpMatrix->Cols()) )
290 return(
fpMatrix->Put( row, col, value ) );
299 int MaxBlocks =
fBlock.NElements();
301 if(bRow <0 || bRow >= MaxBlocks || bCol <0 || bCol >= MaxBlocks || row < 0 || row >=
fBlock[bRow].dim) {
302 cout <<
"TPZBlock::GetVal indexes out of range\n";
307 return(
fpMatrix->Get( row, col ) );
314 int MaxBlocks =
fBlock.NElements();
316 if(bRow <0 || bRow >= MaxBlocks || bCol <0 || bCol >= MaxBlocks || row < 0 || row >=
fBlock[bRow].dim) {
317 cout <<
"TPZBlock::operator() indexes out of range\n";
335 return(
fpMatrix->Put( row, col, value ) );
345 fBlock[bCol].pos, block ) );
354 int row =
fBlock[bRow].pos;
355 int col =
fBlock[bCol].pos;
356 int rowDim =
fBlock[bRow].dim;
357 int colDim =
fBlock[bCol].dim;
358 if ( rowDim && colDim )
359 return(
fpMatrix->GetSub( row, col, rowDim, colDim, block ) );
371 fBlock[bCol].pos, block ) );
379 const int target_row,
const int target_col,
TPZMatrix<TVar> &target)
const 381 int rowDim =
fBlock[block_row].dim;
382 int colDim =
fBlock[block_col].dim;
383 int row = target_row;
384 int col = target_col;
386 if ( ((target_row + rowDim) > target.
Rows()) ||
387 ((target_col + colDim) > target.
Cols()) ) {
392 for (
int r = 0; r < rowDim; r++,row++){
394 for (
int c = 0; c < colDim; c++,pcol++ )
395 target.
PutVal( row, pcol,
GetVal(block_row , block_col , r, c ) );
410 for (
int r = 0; r <
fBlock[bRow].dim; r++ )
413 for (
int c = 0; c <
fBlock[bCol].dim; c++ )
414 out <<
GetVal( bRow, bCol, r, c ) <<
" ";
427 char block_title[58];
429 int MaxBlocks =
fBlock.NElements();
430 out << title <<
":\n";
431 for (
int bRow = 0; bRow < MaxBlocks; bRow++ )
433 out <<
"row block " << bRow <<
" pos " <<
fBlock[bRow].pos <<
" dim " <<
fBlock[bRow].dim <<
"\n";
434 for (
int bCol = 0; bCol < MaxBlocks; bCol++ )
436 out <<
"col block " << bCol <<
" pos " <<
fBlock[bCol].pos <<
" dim " <<
fBlock[bCol].dim <<
"\n";
438 sprintf( block_title,
"Block (%d,%d) of %dX%d:", bRow, bCol,
454 char block_title[32];
456 int MaxBlocks =
fBlock.NElements();
458 for (
int bRow = 0; bRow < MaxBlocks; bRow++ )
461 sprintf( block_title,
"Block (%d,%d) of %dX%d:", bRow, 0,
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
int Set(const int index, const int dim, const int pos=-1)
Modifies existing block dimensions or creates a new block with given index.
int InsertBlock(const int block_row, const int block_col, const int row, const int col, TPZMatrix< TVar > &target) const
Inserts a block (block_row , block_col) on current matrix target.
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.
void PrintSolution(const char *title, TPZostream &out)
TVar & operator()(const int block_row, const int block_col, const int r, const int c) const
static int Error(const char *msg, const char *msg2=0)
Returns error messages.
int GetBlock(const int block_row, const int block_col, TPZFMatrix< TVar > &block) const
Gets a block on current matrix.
const TVar & Get(const int block_row, const int block_col, const int r, const int c) const
Gets a element from matrix verifying.
int PutVal(const int bRow, const int bCol, const int r, const int c, const TVar &value)
Puts a element to matrix but not verify the existence.
static TPZSavable * GetInstance(const int64_t &objId)
void Read(TPZStream &buf, void *context) override
Read the element data from a stream.
int Verify() const
Verifies if blocks are sequential and does not overcome matrix size.
virtual void Write(const bool val)
int SetAll(TPZVec< int > &dimensions)
Computes blocks sequence.
#define DebugStop()
Returns a message to user put a breakpoint in.
int ClassId() const override
returns the unique identifier for reading/writing objects to streams
int PrintBlock(const int block_row, const int block_col, const char *title="", TPZostream &out=std::cout) const
Prints a matrix block.
int64_t Rows() const
Returns number of rows.
int AddBlock(const int block_row, const int block_col, const TPZFMatrix< TVar > &block)
Adds a block on current matrix.
TPZManVector< TNode > fBlock
Nodes vector.
int SetNBlocks(const int num_of_blocks)
Sets number of blocks on diagonal matrix.
Full matrix class. 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.
int Put(const int block_row, const int block_col, const int r, const int c, const TVar &value)
Puts a element to matrix verifying.
const TVar & GetVal(const int bRow, const int bCol, const int r, const int c) const
Gets a element from matrix but not verify the existence.
Implements block matrices. Matrix utility.
TPZMatrix< TVar > * fpMatrix
Pointer to TPZMatrix.
void SetMatrix(TPZMatrix< TVar > *const other)
Changes pointer to other.
TPZBlock< TVar > & operator=(const TPZBlock< TVar > &)
int64_t Cols() const
Returns number of cols.
Contains declaration of the abstract TPZStream class. TPZStream defines the interface for saving and ...
int PutBlock(const int block_row, const int block_col, const TPZFMatrix< TVar > &block)
Puts a block on current matrix.
Defines the interface for saving and reading data. Persistency.
int64_t NElements() const
Returns the number of elements of the vector.
void Read(TPZStream &buf, void *context) override
read objects from the stream
void Print(const char *title="", TPZostream &out=std::cout, TPZMatrix< TVar > *mat=NULL)
Prints all the blocks of the matrix.
int Remove(const int index)
Removes a block.
static void WritePointer(const TPZSavable *obj, TPZStream *stream)
void Write(TPZStream &buf, int withclassid) const override
Save the element data to a stream.
virtual ~TPZBlock()
Simple Destrutor.
Implements an interface to register a class id and a restore function. Persistence.
int Resequence(const int start=0)
Resequences blocks positioning.
virtual void Read(bool &val)
Root matrix class (abstract). Matrix.