This is the base class for block versions of the sparsity pattern and compressed sparsity pattern classes. It has not much functionality, but only administrates an array of sparsity pattern objects and delegates work to them. It has mostly the same interface as has the SparsityPattern, CompressedSparsityPattern, and CompressedSetSparsityPattern classes, and simply transforms calls to its member functions to calls to the respective member functions of the member sparsity patterns.
The largest difference between the SparsityPattern and CompressedSparsityPattern classes and this class is that mostly, the matrices have different properties and you will want to work on the blocks making up the matrix rather than the whole matrix. You can access the different blocks using the block(row,col)
function.
Attention: this object is not automatically notified if the size of one of its subobjects' size is changed. After you initialize the sizes of the subobjects, you will therefore have to call the collect_sizes()
function of this class! Note that, of course, all sub-matrices in a (block-)row have to have the same number of rows, and that all sub-matrices in a (block-)column have to have the same number of columns.
You will in general not want to use this class, but one of the derived classes.
BlockSparsityPatternBase< SparsityPatternBase >::BlockSparsityPatternBase | ( | ) |
Initialize the matrix empty, that is with no memory allocated. This is useful if you want such objects as member variables in other classes. You can make the structure usable by calling the reinit() function.
BlockSparsityPatternBase< SparsityPatternBase >::BlockSparsityPatternBase | ( | const unsigned int | n_block_rows, | |
const unsigned int | n_block_columns | |||
) |
Initialize the matrix with the given number of block rows and columns. The blocks themselves are still empty, and you have to call collect_sizes() after you assign them sizes.
BlockSparsityPatternBase< SparsityPatternBase >::BlockSparsityPatternBase | ( | const BlockSparsityPatternBase< SparsityPatternBase > & | bsp | ) |
Copy constructor. This constructor is only allowed to be called if the sparsity pattern to be copied is empty, i.e. there are no block allocated at present. This is for the same reason as for the SparsityPattern, see there for the details.
BlockSparsityPatternBase< SparsityPatternBase >::~BlockSparsityPatternBase | ( | ) |
Destructor.
void BlockSparsityPatternBase< SparsityPatternBase >::reinit | ( | const unsigned int | n_block_rows, | |
const unsigned int | n_block_columns | |||
) |
Resize the matrix, by setting the number of block rows and columns. This deletes all blocks and replaces them by unitialized ones, i.e. ones for which also the sizes are not yet set. You have to do that by calling the reinit() functions of the blocks themselves. Do not forget to call collect_sizes() after that on this object.
The reason that you have to set sizes of the blocks yourself is that the sizes may be varying, the maximum number of elements per row may be varying, etc. It is simpler not to reproduce the interface of the SparsityPattern class here but rather let the user call whatever function she desires.
Reimplemented in BlockSparsityPattern.
BlockSparsityPatternBase& BlockSparsityPatternBase< SparsityPatternBase >::operator= | ( | const BlockSparsityPatternBase< SparsityPatternBase > & | ) |
Copy operator. For this the same holds as for the copy constructor: it is declared, defined and fine to be called, but the latter only for empty objects.
Reimplemented from Subscriptor.
void BlockSparsityPatternBase< SparsityPatternBase >::collect_sizes | ( | ) |
This function collects the sizes of the sub-objects and stores them in internal arrays, in order to be able to relay global indices into the matrix to indices into the subobjects. You *must* call this function each time after you have changed the size of the sub-objects.
SparsityPatternBase & BlockSparsityPatternBase< SparsityPatternBase >::block | ( | const unsigned int | row, | |
const unsigned int | column | |||
) | [inline] |
Access the block with the given coordinates.
References Assert, BlockSparsityPatternBase< SparsityPatternBase >::columns, BlockSparsityPatternBase< SparsityPatternBase >::rows, and BlockSparsityPatternBase< SparsityPatternBase >::sub_objects.
const SparsityPatternBase & BlockSparsityPatternBase< SparsityPatternBase >::block | ( | const unsigned int | row, | |
const unsigned int | column | |||
) | const [inline] |
Access the block with the given coordinates. Version for constant objects.
References Assert, BlockSparsityPatternBase< SparsityPatternBase >::columns, BlockSparsityPatternBase< SparsityPatternBase >::rows, and BlockSparsityPatternBase< SparsityPatternBase >::sub_objects.
const BlockIndices & BlockSparsityPatternBase< SparsityPatternBase >::get_row_indices | ( | ) | const [inline] |
Grant access to the object describing the distribution of row indices to the individual blocks.
References BlockSparsityPatternBase< SparsityPatternBase >::row_indices.
const BlockIndices & BlockSparsityPatternBase< SparsityPatternBase >::get_column_indices | ( | ) | const [inline] |
Grant access to the object describing the distribution of column indices to the individual blocks.
References BlockSparsityPatternBase< SparsityPatternBase >::column_indices.
void BlockSparsityPatternBase< SparsityPatternBase >::compress | ( | ) |
This function compresses the sparsity structures that this object represents. It simply calls compress
for all sub-objects.
unsigned int BlockSparsityPatternBase< SparsityPatternBase >::n_block_rows | ( | ) | const [inline] |
Return the number of blocks in a column.
References BlockSparsityPatternBase< SparsityPatternBase >::rows.
unsigned int BlockSparsityPatternBase< SparsityPatternBase >::n_block_cols | ( | ) | const [inline] |
Return the number of blocks in a row.
References BlockSparsityPatternBase< SparsityPatternBase >::columns.
Referenced by BlockSparsityPatternBase< SparsityPatternBase >::add_entries().
bool BlockSparsityPatternBase< SparsityPatternBase >::empty | ( | ) | const |
Return whether the object is empty. It is empty if no memory is allocated, which is the same as that both dimensions are zero. This function is just the concatenation of the respective call to all sub-matrices.
unsigned int BlockSparsityPatternBase< SparsityPatternBase >::max_entries_per_row | ( | ) | const |
Return the maximum number of entries per row. It returns the maximal number of entries per row accumulated over all blocks in a row, and the maximum over all rows.
void BlockSparsityPatternBase< SparsityPatternBase >::add | ( | const unsigned int | i, | |
const unsigned int | j | |||
) | [inline] |
Add a nonzero entry to the matrix. This function may only be called for non-compressed sparsity patterns.
If the entry already exists, nothing bad happens.
This function simply finds out to which block (i,j)
belongs and then relays to that block.
References BlockSparsityPatternBase< SparsityPatternBase >::column_indices, BlockIndices::global_to_local(), BlockSparsityPatternBase< SparsityPatternBase >::row_indices, and BlockSparsityPatternBase< SparsityPatternBase >::sub_objects.
void BlockSparsityPatternBase< SparsityPatternBase >::add_entries | ( | const unsigned int | row, | |
ForwardIterator | begin, | |||
ForwardIterator | end, | |||
const bool | indices_are_sorted = false | |||
) | [inline] |
Add several nonzero entries to the specified matrix row. This function may only be called for non-compressed sparsity patterns.
If some of the entries already exist, nothing bad happens.
This function simply finds out to which blocks (row,col)
for col
in the iterator range belong and then relays to those blocks.
References Assert, BlockSparsityPatternBase< SparsityPatternBase >::block_column_indices, BlockSparsityPatternBase< SparsityPatternBase >::column_indices, BlockSparsityPatternBase< SparsityPatternBase >::counter_within_block, BlockIndices::global_to_local(), BlockSparsityPatternBase< SparsityPatternBase >::n_block_cols(), BlockSparsityPatternBase< SparsityPatternBase >::n_cols(), BlockSparsityPatternBase< SparsityPatternBase >::row_indices, and BlockSparsityPatternBase< SparsityPatternBase >::sub_objects.
unsigned int BlockSparsityPatternBase< SparsityPatternBase >::n_rows | ( | ) | const |
Return number of rows of this matrix, which equals the dimension of the image space. It is the sum of rows of the (block-)rows of sub-matrices.
unsigned int BlockSparsityPatternBase< SparsityPatternBase >::n_cols | ( | ) | const |
Return number of columns of this matrix, which equals the dimension of the range space. It is the sum of columns of the (block-)columns of sub-matrices.
Referenced by BlockSparsityPatternBase< SparsityPatternBase >::add_entries().
bool BlockSparsityPatternBase< SparsityPatternBase >::exists | ( | const unsigned int | i, | |
const unsigned int | j | |||
) | const [inline] |
Check if a value at a certain position may be non-zero.
References BlockSparsityPatternBase< SparsityPatternBase >::column_indices, BlockIndices::global_to_local(), BlockSparsityPatternBase< SparsityPatternBase >::row_indices, and BlockSparsityPatternBase< SparsityPatternBase >::sub_objects.
unsigned int BlockSparsityPatternBase< SparsityPatternBase >::row_length | ( | const unsigned int | row | ) | const [inline] |
Number of entries in a specific row, added up over all the blocks that form this row.
References BlockIndices::global_to_local(), BlockSparsityPatternBase< SparsityPatternBase >::row_indices, BlockSparsityPatternBase< SparsityPatternBase >::rows, and BlockSparsityPatternBase< SparsityPatternBase >::sub_objects.
unsigned int BlockSparsityPatternBase< SparsityPatternBase >::n_nonzero_elements | ( | ) | const |
Return the number of nonzero elements of this matrix. Actually, it returns the number of entries in the sparsity pattern; if any of the entries should happen to be zero, it is counted anyway.
This function may only be called if the matrix struct is compressed. It does not make too much sense otherwise anyway.
In the present context, it is the sum of the values as returned by the sub-objects.
void BlockSparsityPatternBase< SparsityPatternBase >::print | ( | std::ostream & | out | ) | const |
Print the sparsity of the matrix. The output consists of one line per row of the format [i,j1,j2,j3,...]
. i is the row number and jn are the allocated columns in this row.
void BlockSparsityPatternBase< SparsityPatternBase >::print_gnuplot | ( | std::ostream & | out | ) | const |
Print the sparsity of the matrix in a format that gnuplot
understands and which can be used to plot the sparsity pattern in a graphical way. This is the same functionality implemented for usual sparsity patterns, see SparsityPattern.
friend class BlockSparseMatrix [friend] |
Make the block sparse matrix a friend, so that it can use our row_indices and column_indices objects.
const unsigned int BlockSparsityPatternBase< SparsityPatternBase >::invalid_entry = SparsityPattern::invalid_entry [static] |
Define a value which is used to indicate that a certain value in the colnums
array is unused, i.e. does not represent a certain column number index.
This value is only an alias to the respective value of the SparsityPattern class.
unsigned int BlockSparsityPatternBase< SparsityPatternBase >::rows [protected] |
Number of block rows.
Referenced by BlockSparsityPatternBase< SparsityPatternBase >::block(), BlockSparsityPatternBase< SparsityPatternBase >::n_block_rows(), and BlockSparsityPatternBase< SparsityPatternBase >::row_length().
unsigned int BlockSparsityPatternBase< SparsityPatternBase >::columns [protected] |
Number of block columns.
Referenced by BlockSparsityPatternBase< SparsityPatternBase >::block(), and BlockSparsityPatternBase< SparsityPatternBase >::n_block_cols().
Table<2,SmartPointer<SparsityPatternBase> > BlockSparsityPatternBase< SparsityPatternBase >::sub_objects [protected] |
Array of sparsity patterns.
Referenced by BlockSparsityPatternBase< SparsityPatternBase >::add(), BlockSparsityPatternBase< SparsityPatternBase >::add_entries(), BlockSparsityPatternBase< SparsityPatternBase >::block(), BlockSparsityPatternBase< SparsityPatternBase >::exists(), and BlockSparsityPatternBase< SparsityPatternBase >::row_length().
BlockIndices BlockSparsityPatternBase< SparsityPatternBase >::row_indices [protected] |
Object storing and managing the transformation of row indices to indices of the sub-objects.
Referenced by BlockSparsityPatternBase< SparsityPatternBase >::add(), BlockSparsityPatternBase< SparsityPatternBase >::add_entries(), BlockSparsityPatternBase< SparsityPatternBase >::exists(), BlockSparsityPatternBase< SparsityPatternBase >::get_row_indices(), and BlockSparsityPatternBase< SparsityPatternBase >::row_length().
BlockIndices BlockSparsityPatternBase< SparsityPatternBase >::column_indices [protected] |
Object storing and managing the transformation of column indices to indices of the sub-objects.
Referenced by BlockSparsityPatternBase< SparsityPatternBase >::add(), BlockSparsityPatternBase< SparsityPatternBase >::add_entries(), BlockSparsityPatternBase< SparsityPatternBase >::exists(), and BlockSparsityPatternBase< SparsityPatternBase >::get_column_indices().
std::vector<unsigned int> BlockSparsityPatternBase< SparsityPatternBase >::counter_within_block [private] |
Temporary vector for counting the elements written into the individual blocks when doing a collective add or set.
Referenced by BlockSparsityPatternBase< SparsityPatternBase >::add_entries().
std::vector<std::vector<unsigned int> > BlockSparsityPatternBase< SparsityPatternBase >::block_column_indices [private] |
Temporary vector for column indices on each block when writing local to global data on each sparse matrix.
Referenced by BlockSparsityPatternBase< SparsityPatternBase >::add_entries().