NeoPZ
pzblock.h
Go to the documentation of this file.
1 
6 #ifndef _TBLOCKHH_
7 #define _TBLOCKHH_
8 
9 #include "pzmatrix.h"
10 #include "pzmanvector.h"
11 #include "pzreal.h"
12 #include "TPZSavable.h"
13 
14 
21 template<class TVar>
22 class TPZBlock : public TPZSavable
23 {
24 public:
26  {
27 
28  }
35  TPZBlock(TPZMatrix<TVar> *const matrix_to_represent,const int num_of_blocks = 0,
36  const int initial_blocks_size = 1 );
37 
42  TPZBlock(const TPZBlock<TVar> &bl);
43 
45  virtual ~TPZBlock();
46 
51  void SetMatrix(TPZMatrix<TVar> *const other)
52  {
53  fpMatrix = other;
54  }
55 
58 
63  int SetNBlocks(const int num_of_blocks );
64 
71  int Set(const int index,const int dim,const int pos = -1 );
72 
77  int SetAll( TPZVec<int> & dimensions );
78 
83  int Resequence(const int start=0);
84 
89  int Remove(const int index );
90 
94  int Verify() const;
95 
96  TVar & operator()(const int block_row,const int block_col,const int r,const int c ) const;
97 
99  const TVar & Get(const int block_row,const int block_col,const int r,const int c ) const;
101  int Put(const int block_row,const int block_col,const int r,const int c,const TVar& value );
102 
104  const TVar & Get(const int block_row,const int r,const int c ) const;
106  int Put(const int block_row,const int r,const int c,const TVar& value );
107 
109  const TVar & GetVal(const int bRow,const int bCol,const int r,const int c ) const;
111  int PutVal(const int bRow,const int bCol,const int r,const int c,const TVar& value );
112 
119  int PutBlock(const int block_row,const int block_col,const TPZFMatrix<TVar> & block );
126  int GetBlock(const int block_row,const int block_col, TPZFMatrix<TVar> & block ) const;
133  int AddBlock(const int block_row,const int block_col, const TPZFMatrix<TVar> & block );
134 
143  int InsertBlock(const int block_row,const int block_col,
144  const int row,const int col, TPZMatrix<TVar> &target) const;
145 
147 
155  int PrintBlock(const int block_row,const int block_col,const char *title = "",TPZostream &out = std::cout ) const;
156 
158  void Print(const char *title = "",TPZostream &out = std::cout,TPZMatrix<TVar> *mat=NULL);
159 
160  void PrintSolution(const char *title, TPZostream &out);
161 
163  int MaxBlockSize() const {return fBlock.NElements();}
165  int NBlocks() const {return fBlock.NElements();}
166 
171  int Size(const int block_diagonal) const { return fBlock[block_diagonal].dim; }
172 
177  int Position(const int block_diagonal) const { return fBlock[block_diagonal].pos;}
178 
180  int Dim() const {return fBlock.NElements() ? fBlock[fBlock.NElements()-1].pos+fBlock[fBlock.NElements()-1].dim : 0; }
181 
184  int ClassId() const override;
185 
187  void Write(TPZStream &buf, int withclassid) const override;
188 
190  void Read(TPZStream &buf, void *context) override;
191 
192 private:
193 
198  class TNode : public TPZSavable {
199  public :
200 
201  int pos;
202  int dim;
204  TNode() {
205  pos=0;
206  dim=0;
207  }
208 
209  int ClassId() const override{
210  return Hash("TNode") ^ ClassIdOrHash<TPZBlock<TVar>>() << 1;
211  }
212 
213  void Read(TPZStream &buf, void *context) override;
214  void Write(TPZStream &buf, int withclassid) const override;
215  };
216 
221  static REAL gZero;//zero
222 
223 };
224 
225 template<class TVar>
227  return Hash("TPZBlock") ^ ClassIdOrHash<TVar>() << 1;
228 }
229 
230 #endif
Contains declaration of the TPZSavable class which defines the interface to save and restore objects ...
void Write(TPZStream &buf, int withclassid) const override
Writes this object to the TPZStream buffer. Include the classid if withclassid = true.
Definition: pzblock.cpp:478
int Position(const int block_diagonal) const
Returns the position of first element block dependent on matrix diagonal.
Definition: pzblock.h:177
int Set(const int index, const int dim, const int pos=-1)
Modifies existing block dimensions or creates a new block with given index.
Definition: pzblock.cpp:104
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.
Definition: pzblock.cpp:378
Implements a vector class which allows to use external storage provided by the user. Utility.
Definition: pzquad.h:16
void PrintSolution(const char *title, TPZostream &out)
Definition: pzblock.cpp:451
TVar & operator()(const int block_row, const int block_col, const int r, const int c) const
Definition: pzblock.cpp:312
int GetBlock(const int block_row, const int block_col, TPZFMatrix< TVar > &block) const
Gets a block on current matrix.
Definition: pzblock.cpp:352
const TVar & Get(const int block_row, const int block_col, const int r, const int c) const
Gets a element from matrix verifying.
Definition: pzblock.cpp:191
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.
Definition: pzblock.cpp:329
void Read(TPZStream &buf, void *context) override
Read the element data from a stream.
Definition: pzblock.cpp:504
int Dim() const
Returns matrix dimension pointed by block.
Definition: pzblock.h:180
int Verify() const
Verifies if blocks are sequential and does not overcome matrix size.
Definition: pzblock.cpp:176
int SetAll(TPZVec< int > &dimensions)
Computes blocks sequence.
Definition: pzblock.cpp:124
int ClassId() const override
returns the unique identifier for reading/writing objects to streams
Definition: pzblock.h:226
int PrintBlock(const int block_row, const int block_col, const char *title="", TPZostream &out=std::cout) const
Prints a matrix block.
Definition: pzblock.cpp:405
Free store vector implementation.
#define TPZostream
Definition: TPZStream.h:33
int AddBlock(const int block_row, const int block_col, const TPZFMatrix< TVar > &block)
Adds a block on current matrix.
Definition: pzblock.cpp:368
TPZManVector< TNode > fBlock
Nodes vector.
Definition: pzblock.h:218
int SetNBlocks(const int num_of_blocks)
Sets number of blocks on diagonal matrix.
Definition: pzblock.cpp:91
Full matrix class. Matrix.
Definition: pzfmatrix.h:32
int ClassId() const override
Define the class id associated with the class.
Definition: pzblock.h:209
int32_t Hash(std::string str)
Definition: TPZHash.cpp:10
Contains TPZMatrix<TVar>class, root matrix class.
Defines a node.
Definition: pzblock.h:198
int NBlocks() const
Returns number of blocks on diagonal.
Definition: pzblock.h:165
static REAL gZero
Definition: pzblock.h:221
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.
Definition: pzblock.cpp:217
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.
Definition: pzblock.cpp:297
Implements block matrices. Matrix utility.
TPZMatrix< TVar > * fpMatrix
Pointer to TPZMatrix.
Definition: pzblock.h:220
int Size(const int block_diagonal) const
Returns block dimension.
Definition: pzblock.h:171
void SetMatrix(TPZMatrix< TVar > *const other)
Changes pointer to other.
Definition: pzblock.h:51
TPZBlock< TVar > & operator=(const TPZBlock< TVar > &)
Definition: pzblock.cpp:73
int PutBlock(const int block_row, const int block_col, const TPZFMatrix< TVar > &block)
Puts a block on current matrix.
Definition: pzblock.cpp:342
Defines the interface for saving and reading data. Persistency.
Definition: TPZStream.h:50
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
void Read(TPZStream &buf, void *context) override
read objects from the stream
Definition: pzblock.cpp:472
int MaxBlockSize() const
Returns the max number of blocks on diagonal.
Definition: pzblock.h:163
TPZMatrix< TVar > * Matrix()
Returns a pointer to current matrix.
Definition: pzblock.h:57
void Print(const char *title="", TPZostream &out=std::cout, TPZMatrix< TVar > *mat=NULL)
Prints all the blocks of the matrix.
Definition: pzblock.cpp:424
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
Definition: TPZSavable.h:67
int Remove(const int index)
Removes a block.
Definition: pzblock.cpp:162
void Write(TPZStream &buf, int withclassid) const override
Save the element data to a stream.
Definition: pzblock.cpp:496
virtual ~TPZBlock()
Simple Destrutor.
Definition: pzblock.cpp:83
TPZBlock()
Definition: pzblock.h:25
int Resequence(const int start=0)
Resequences blocks positioning.
Definition: pzblock.cpp:150
Root matrix class (abstract). Matrix.
Definition: pzmatrix.h:60