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... | |
CRDoubleMatrix * | replacement_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) |
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. More... | |
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... | |
CRDoubleMatrix * | Replacement_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. P.M.: The address of a null pointer on a Mac is 0x0 but for self-tests the address needs to be simply 0. Easy (but hacky) check sorts that out... More... | |
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 123 of file block_preconditioner.h.
|
inline |
Default constructor, initialise block index i, j to 0 and bool to false.
Definition at line 128 of file block_preconditioner.h.
References build(), and Replacement_block_pt.
|
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 141 of file block_preconditioner.h.
References build(), column_index(), replacement_block_pt(), Replacement_block_pt, and wanted().
|
inlinevirtual |
Default destructor.
Definition at line 168 of file block_preconditioner.h.
References Column_index, Replacement_block_pt, and Row_index.
|
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 326 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().
|
inline |
returns the column index.
Definition at line 290 of file block_preconditioner.h.
References Column_index.
Referenced by BlockSelector(), build(), select_block(), and set_column_index().
|
inline |
Indicate that we do not want the block (set Wanted to false).
Definition at line 218 of file block_preconditioner.h.
References Column_index, null_replacement_block_pt(), Replacement_block_pt, Row_index, and Wanted.
|
inline |
Set Replacement_block_pt to null.
Definition at line 241 of file block_preconditioner.h.
References Replacement_block_pt.
Referenced by do_not_want_block().
|
inline |
Returns Replacement_block_pt.
Definition at line 266 of file block_preconditioner.h.
References Replacement_block_pt.
Referenced by BlockSelector(), build(), select_block(), and set_replacement_block_pt().
|
inline |
returns the row index.
Definition at line 278 of file block_preconditioner.h.
References Row_index.
Referenced by build(), select_block(), and set_row_index().
|
inline |
Select a block.
Definition at line 188 of file block_preconditioner.h.
References build(), column_index(), replacement_block_pt(), row_index(), and wanted().
|
inline |
Set the column index.
Definition at line 284 of file block_preconditioner.h.
References column_index(), and Column_index.
|
inline |
set Replacement_block_pt.
Definition at line 247 of file block_preconditioner.h.
References Column_index, replacement_block_pt(), Replacement_block_pt, Row_index, and Wanted.
|
inline |
Set the row index.
Definition at line 272 of file block_preconditioner.h.
References row_index(), and Row_index.
|
inline |
Indicate that we require the block (set Wanted to true).
Definition at line 212 of file block_preconditioner.h.
References Wanted.
|
inline |
returns whether the block is wanted or not.
Definition at line 296 of file block_preconditioner.h.
References Wanted.
Referenced by BlockSelector(), build(), and select_block().
|
friend |
Output function, outputs the Row_index, Column_index, Wanted and the address of the Replacement_block_pt. P.M.: The address of a null pointer on a Mac is 0x0 but for self-tests the address needs to be simply 0. Easy (but hacky) check sorts that out...
Definition at line 307 of file block_preconditioner.h.
|
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().
|
private |
Pointer to the block.
Definition at line 369 of file block_preconditioner.h.
Referenced by BlockSelector(), build(), do_not_want_block(), null_replacement_block_pt(), replacement_block_pt(), set_replacement_block_pt(), and ~BlockSelector().
|
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().
|
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().