Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
oomph::BlockSelector Class Reference

Data structure to store information about a certain "block" or sub-matrix from the overall matrix in the block preconditioning framework. More...

#include <block_preconditioner.h>

Public Member Functions

 BlockSelector ()
 Default constructor, initialise block index i, j to 0 and bool to false. More...
 
 BlockSelector (const unsigned &row_index, const unsigned &column_index, const bool &wanted, CRDoubleMatrix *replacement_block_pt=0)
 Constructor, takes the row and column indices and a boolean indicating if the block is required or not. The optional parameter replacement_block_pt is set to null. If the block is not required a block of the correct dimensions full of 0s is used. More...
 
virtual ~BlockSelector ()
 Default destructor. More...
 
void select_block (const unsigned &row_index, const unsigned &column_index, const bool &wanted, CRDoubleMatrix *replacement_block_pt=0)
 Select a block. More...
 
void want_block ()
 Indicate that we require the block (set Wanted to true). More...
 
void do_not_want_block ()
 Indicate that we do not want the block (set Wanted to false). More...
 
void null_replacement_block_pt ()
 Set Replacement_block_pt to null. More...
 
void set_replacement_block_pt (CRDoubleMatrix *replacement_block_pt)
 set Replacement_block_pt. More...
 
CRDoubleMatrixreplacement_block_pt () const
 Returns Replacement_block_pt. More...
 
void set_row_index (const unsigned &row_index)
 Set the row index. More...
 
const unsigned & row_index () const
 returns the row index. More...
 
void set_column_index (const unsigned &column_index)
 Set the column index. More...
 
const unsigned & column_index () const
 returns the column index. More...
 
const bool & wanted () const
 returns whether the block is wanted or not. More...
 

Private Member Functions

void build (const unsigned &row_index, const unsigned &column_index, const bool &wanted, CRDoubleMatrix *replacement_block_pt=0)
 

Private Attributes

unsigned Row_index
 Row index of the block. More...
 
unsigned Column_index
 Column index of the block. More...
 
bool Wanted
 Bool to indicate if we require this block. More...
 
CRDoubleMatrixReplacement_block_pt
 Pointer to the block. More...
 

Friends

std::ostream & operator<< (std::ostream &o_stream, const BlockSelector &block_selector)
 Output function, outputs the Row_index, Column_index, Wanted and the address of the Replacement_block_pt. More...
 

Detailed Description

Data structure to store information about a certain "block" or sub-matrix from the overall matrix in the block preconditioning framework.

Example of use: Let's assume we want to form a concatenated matrix from the blocks of a Jacobian matrix that contains the following blocks:

[J_00, J_01, J_02 J_10, J_11, J_12 J_20, J_21, J_22]

so that the new matrix has the entries

[ J_01, J_00 J_21, 0 ]

where "0" indicates zero matrix of the required size.

To do this we create a 2x2 (the block size of the new concatenated matrix) VectorMatrix of BlockSelectors and then declare for each entry the block indices in the original matrix and if the entry is to be included (and copied from the corresponding entry in the Jacobian (final boolean argument true) or if the block is to be omitted and replaced by an appropriately sized zero matrix. For the example above this would be done as follows:

VectorMatrix<BlockSelector> required_block(2,2); required_block[0][0].select_block(0,1,true); required_block[0][1].select_block(0,0,true); required_block[1][0].select_block(2,1,true); required_block[1][1].select_block(2,0,false);

and the concatenated matrix would then be built as

CRDoubleMatrix concatenated_block1 = get_concatenated_block(required_block);

Note that it is necessary to identify the row and column indices of any omitted blocks (here block J_20 in the original matrix) to enable the correct setup of the sparse matrix storage.

The initial assignment of the boolean may be over-written with the do_not_want_block() member function; this can again be reversed with the want_block() counterpart. So if we call

required_block[0][0].do_not_want_block();

and the build a new conctatenated matrix with

CRDoubleMatrix concatenated_block2 = get_concatenated_block(required_block);

the resulting matrix would the anti-diagonal matrix

[ 0 , J_00 J_21 , 0 ]

Finally it is possible to specify a replacement block by specifying a pointer to an appropriately sized matrix that is to be used instead of the block in the Jacobian matrix, so if replacement_block_pt points to a matrix, R, say, of the same size as J_01, then

selected_block[0][0].select_block(0,1,true,replacement_block_pt);

then the resulting concatenated matrix would contain

[ R , J_00 J_21 , 0 ]

Definition at line 128 of file block_preconditioner.h.

Constructor & Destructor Documentation

oomph::BlockSelector::BlockSelector ( )
inline

Default constructor, initialise block index i, j to 0 and bool to false.

Definition at line 134 of file block_preconditioner.h.

References build(), and Replacement_block_pt.

oomph::BlockSelector::BlockSelector ( const unsigned &  row_index,
const unsigned &  column_index,
const bool &  wanted,
CRDoubleMatrix replacement_block_pt = 0 
)
inline

Constructor, takes the row and column indices and a boolean indicating if the block is required or not. The optional parameter replacement_block_pt is set to null. If the block is not required a block of the correct dimensions full of 0s is used.

Definition at line 146 of file block_preconditioner.h.

References build(), replacement_block_pt(), and Replacement_block_pt.

virtual oomph::BlockSelector::~BlockSelector ( )
inlinevirtual

Default destructor.

Definition at line 173 of file block_preconditioner.h.

References Column_index, Replacement_block_pt, and Row_index.

Member Function Documentation

void oomph::BlockSelector::build ( const unsigned &  row_index,
const unsigned &  column_index,
const bool &  wanted,
CRDoubleMatrix replacement_block_pt = 0 
)
inlineprivate

Build function, sets the Row_index, Column_index and Wanted variables. the Replacement_block_pt is only set if it is not null. Otherwise it is left alone.

Definition at line 327 of file block_preconditioner.h.

References column_index(), Column_index, replacement_block_pt(), Replacement_block_pt, row_index(), Row_index, wanted(), and Wanted.

Referenced by BlockSelector(), and select_block().

const unsigned& oomph::BlockSelector::column_index ( ) const
inline

returns the column index.

Definition at line 298 of file block_preconditioner.h.

References Column_index.

Referenced by build(), and set_column_index().

void oomph::BlockSelector::do_not_want_block ( )
inline

Indicate that we do not want the block (set Wanted to false).

Definition at line 225 of file block_preconditioner.h.

References Column_index, null_replacement_block_pt(), Replacement_block_pt, Row_index, and Wanted.

void oomph::BlockSelector::null_replacement_block_pt ( )
inline

Set Replacement_block_pt to null.

Definition at line 248 of file block_preconditioner.h.

References Replacement_block_pt.

Referenced by do_not_want_block().

CRDoubleMatrix* oomph::BlockSelector::replacement_block_pt ( ) const
inline

Returns Replacement_block_pt.

Definition at line 274 of file block_preconditioner.h.

References Replacement_block_pt.

Referenced by BlockSelector(), build(), select_block(), and set_replacement_block_pt().

const unsigned& oomph::BlockSelector::row_index ( ) const
inline

returns the row index.

Definition at line 286 of file block_preconditioner.h.

References Row_index.

Referenced by build(), and set_row_index().

void oomph::BlockSelector::select_block ( const unsigned &  row_index,
const unsigned &  column_index,
const bool &  wanted,
CRDoubleMatrix replacement_block_pt = 0 
)
inline

Select a block.

Definition at line 194 of file block_preconditioner.h.

References build(), and replacement_block_pt().

void oomph::BlockSelector::set_column_index ( const unsigned &  column_index)
inline

Set the column index.

Definition at line 292 of file block_preconditioner.h.

References column_index(), and Column_index.

void oomph::BlockSelector::set_replacement_block_pt ( CRDoubleMatrix replacement_block_pt)
inline

set Replacement_block_pt.

Definition at line 254 of file block_preconditioner.h.

References Column_index, replacement_block_pt(), Replacement_block_pt, Row_index, and Wanted.

void oomph::BlockSelector::set_row_index ( const unsigned &  row_index)
inline

Set the row index.

Definition at line 280 of file block_preconditioner.h.

References row_index(), and Row_index.

void oomph::BlockSelector::want_block ( )
inline

Indicate that we require the block (set Wanted to true).

Definition at line 219 of file block_preconditioner.h.

References Wanted.

const bool& oomph::BlockSelector::wanted ( ) const
inline

returns whether the block is wanted or not.

Definition at line 304 of file block_preconditioner.h.

References Wanted.

Referenced by build().

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o_stream,
const BlockSelector block_selector 
)
friend

Output function, outputs the Row_index, Column_index, Wanted and the address of the Replacement_block_pt.

Definition at line 312 of file block_preconditioner.h.

Member Data Documentation

unsigned oomph::BlockSelector::Column_index
private

Column index of the block.

Definition at line 363 of file block_preconditioner.h.

Referenced by build(), column_index(), do_not_want_block(), set_column_index(), set_replacement_block_pt(), and ~BlockSelector().

CRDoubleMatrix* oomph::BlockSelector::Replacement_block_pt
private
unsigned oomph::BlockSelector::Row_index
private

Row index of the block.

Definition at line 360 of file block_preconditioner.h.

Referenced by build(), do_not_want_block(), row_index(), set_replacement_block_pt(), set_row_index(), and ~BlockSelector().

bool oomph::BlockSelector::Wanted
private

Bool to indicate if we require this block.

Definition at line 366 of file block_preconditioner.h.

Referenced by build(), do_not_want_block(), set_replacement_block_pt(), want_block(), and wanted().


The documentation for this class was generated from the following file: