oomph::BlockSelector Class Reference

#include <block_preconditioner.h>

Public Member Functions

 BlockSelector ()
 
 BlockSelector (const unsigned &row_index, const unsigned &column_index, const bool &wanted, CRDoubleMatrix *replacement_block_pt=0)
 
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 unsignedrow_index () const
 returns the row index. More...
 
void set_column_index (const unsigned &column_index)
 Set the column index. More...
 
const unsignedcolumn_index () const
 returns the column index. More...
 
const boolwanted () 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)
 

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 ]

Constructor & Destructor Documentation

◆ BlockSelector() [1/2]

oomph::BlockSelector::BlockSelector ( )
inline

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

129  {
130  // Needs to be set to zero because if the build function leaves the
131  // Replacement_block_pt alone if replacement_block_pt = 0 (the default
132  // argument).
134  this->build(0, 0, false);
135  }
void build(const unsigned &row_index, const unsigned &column_index, const bool &wanted, CRDoubleMatrix *replacement_block_pt=0)
Definition: block_preconditioner.h:326
CRDoubleMatrix * Replacement_block_pt
Pointer to the block.
Definition: block_preconditioner.h:369

References build(), and Replacement_block_pt.

◆ BlockSelector() [2/2]

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.

145  {
146 #ifdef PARANOID
147  if ((wanted == false) && (replacement_block_pt != 0))
148  {
149  std::ostringstream err_msg;
150  err_msg << "Trying to construct a BlockSelector object with:\n"
151  << "replacement_block_pt != 0 and wanted == false"
152  << "If you require the block, please set wanted == true.\n";
153  throw OomphLibError(
155  }
156 #endif
157 
158  // Needs to be set to zero because if the build function leaves the
159  // Replacement_block_pt alone if replacement_block_pt = 0 (the default
160  // argument). Thus if it is not set here, it would not be initialised to
161  // null.
163 
164  this->build(row_index, column_index, wanted, replacement_block_pt);
165  }
const unsigned & column_index() const
returns the column index.
Definition: block_preconditioner.h:290
const bool & wanted() const
returns whether the block is wanted or not.
Definition: block_preconditioner.h:296
CRDoubleMatrix * replacement_block_pt() const
Returns Replacement_block_pt.
Definition: block_preconditioner.h:266
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References build(), column_index(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, replacement_block_pt(), Replacement_block_pt, and wanted().

◆ ~BlockSelector()

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

Default destructor.

169  {
170 #ifdef PARANOID
171  if (Replacement_block_pt != 0)
172  {
173  std::ostringstream warning_msg;
174  warning_msg << "Warning: BlockSelector destructor is called but...\n"
175  << "replacement_block_pt() is not null.\n"
176  << "Please remember to null this via the function\n"
177  << "BlockSelector::null_replacement_block_pt()\n"
178  << "Row_index: " << Row_index << "\n"
179  << "Column_index: " << Column_index << std::endl;
180 
181  OomphLibWarning(
183  }
184 #endif
185  }
unsigned Column_index
Column index of the block.
Definition: block_preconditioner.h:363
unsigned Row_index
Row index of the block.
Definition: block_preconditioner.h:360

References Column_index, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, Replacement_block_pt, and Row_index.

Member Function Documentation

◆ build()

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.

330  {
333  Wanted = wanted;
334 
335  // Only set the replacement_block_pt if it is wanted. Otherwise we leave
336  // it alone. All constructors should set Replacement_block_pt to 0.
337  if (replacement_block_pt != 0)
338  {
339 #ifdef PARANOID
340  if (Wanted == false)
341  {
342  std::ostringstream err_msg;
343  err_msg
344  << "Trying to set replacement_block_pt, but Wanted == false.\n"
345  << "Please either not set the replacement_block_pt or call the "
346  "function\n"
347  << "do_not_want_block()\n"
348  << "Row_index: " << Row_index << "\n"
349  << "Column_index: " << Column_index << "\n";
350  throw OomphLibError(
352  }
353 #endif
354 
356  }
357  }
const unsigned & row_index() const
returns the row index.
Definition: block_preconditioner.h:278
bool Wanted
Bool to indicate if we require this block.
Definition: block_preconditioner.h:366

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

Referenced by BlockSelector(), and select_block().

◆ column_index()

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

returns the column index.

291  {
292  return Column_index;
293  }

References Column_index.

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

◆ do_not_want_block()

void oomph::BlockSelector::do_not_want_block ( )
inline

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

219  {
220 #ifdef PARANOID
221  if (Replacement_block_pt != 0)
222  {
223  std::ostringstream warning_msg;
224  warning_msg << "Trying to set Wanted = false, but replacement_block_pt "
225  "is not null.\n"
226  << "Please call null_replacement_block_pt()\n"
227  << "(remember to free memory if necessary)\n"
228  << "Row_index: " << Row_index << "\n"
229  << "Column_index: " << Column_index << "\n";
230  OomphLibWarning(
232  }
233 #endif
234 
236 
237  Wanted = false;
238  }
void null_replacement_block_pt()
Set Replacement_block_pt to null.
Definition: block_preconditioner.h:241

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

Referenced by main().

◆ null_replacement_block_pt()

void oomph::BlockSelector::null_replacement_block_pt ( )
inline

Set Replacement_block_pt to null.

242  {
244  }

References Replacement_block_pt.

Referenced by do_not_want_block(), and main().

◆ replacement_block_pt()

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

Returns Replacement_block_pt.

267  {
268  return Replacement_block_pt;
269  }

References Replacement_block_pt.

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

◆ row_index()

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

returns the row index.

279  {
280  return Row_index;
281  }

References Row_index.

Referenced by build(), select_block(), and set_row_index().

◆ select_block()

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.

192  {
193 #ifdef PARANOID
194  if ((wanted == false) && (replacement_block_pt != 0))
195  {
196  std::ostringstream err_msg;
197  err_msg << "Trying to select block with:\n"
198  << "replacement_block_pt != 0 and wanted == false"
199  << "If you require the block, please set wanted == true.\n"
200  << "row_index: " << row_index << "\n"
201  << "column_index: " << column_index << "\n";
202  throw OomphLibError(
204  }
205 #endif
206 
207  this->build(row_index, column_index, wanted, replacement_block_pt);
208  }

References build(), column_index(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, replacement_block_pt(), row_index(), and wanted().

Referenced by main().

◆ set_column_index()

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

Set the column index.

285  {
287  }

References column_index(), and Column_index.

Referenced by main().

◆ set_replacement_block_pt()

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

set Replacement_block_pt.

248  {
249 #ifdef PARANOID
250  if (Wanted == false)
251  {
252  std::ostringstream err_msg;
253  err_msg << "Trying to set replacement_block_pt, but Wanted == false.\n"
254  << "Please call want_block()\n"
255  << "Row_index: " << Row_index << "\n"
256  << "Column_index: " << Column_index << "\n";
257  throw OomphLibError(
259  }
260 #endif
261 
263  }

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

◆ set_row_index()

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

Set the row index.

273  {
275  }

References row_index(), and Row_index.

Referenced by main().

◆ want_block()

void oomph::BlockSelector::want_block ( )
inline

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

213  {
214  Wanted = true;
215  }

References Wanted.

Referenced by main().

◆ wanted()

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

returns whether the block is wanted or not.

297  {
298  return Wanted;
299  }

References Wanted.

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

Friends And Related Function Documentation

◆ operator<<

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. 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...

309  {
310  o_stream << "Row_index = " << block_selector.row_index() << "\n"
311  << "Column_index = " << block_selector.column_index() << "\n"
312  << "Wanted = " << block_selector.wanted() << "\n"
313  << "Replacement_block_pt = ";
314  if (block_selector.replacement_block_pt() == 0)
315  {
316  o_stream << 0;
317  }
318 
319  return o_stream;
320  }

Member Data Documentation

◆ Column_index

unsigned oomph::BlockSelector::Column_index
private

◆ Replacement_block_pt

CRDoubleMatrix* oomph::BlockSelector::Replacement_block_pt
private

◆ Row_index

unsigned oomph::BlockSelector::Row_index
private

◆ Wanted

bool oomph::BlockSelector::Wanted
private

Bool to indicate if we require this block.

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: