deal.II version GIT relicensing-2165-gc91f007519 2024-11-20 01:40:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
BlockSparsityPattern Class Reference

#include <deal.II/lac/block_sparsity_pattern.h>

Inheritance diagram for BlockSparsityPattern:
Inheritance graph
[legend]

Public Types

using size_type = types::global_dof_index
 

Public Member Functions

 BlockSparsityPattern ()=default
 
 BlockSparsityPattern (const size_type n_rows, const size_type n_columns)
 
void reinit (const size_type n_block_rows, const size_type n_block_columns)
 
void reinit (const BlockIndices &row_indices, const BlockIndices &col_indices, const std::vector< std::vector< unsigned int > > &row_lengths)
 
bool is_compressed () const
 
void copy_from (const BlockDynamicSparsityPattern &dsp)
 
void collect_sizes ()
 
SparsityPatternblock (const size_type row, const size_type column)
 
const SparsityPatternblock (const size_type row, const size_type column) const
 
const BlockIndicesget_row_indices () const
 
const BlockIndicesget_column_indices () const
 
void compress ()
 
size_type n_block_rows () const
 
size_type n_block_cols () const
 
bool empty () const
 
size_type max_entries_per_row () const
 
void add (const size_type i, const size_type j)
 
void add_entries (const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
 
virtual void add_entries (const ArrayView< const std::pair< size_type, size_type > > &entries)
 
virtual void add_row_entries (const size_type &row, const ArrayView< const size_type > &columns, const bool indices_are_sorted=false) override
 
bool exists (const size_type i, const size_type j) const
 
unsigned int row_length (const size_type row) const
 
size_type n_nonzero_elements () const
 
void print (std::ostream &out) const
 
void print_gnuplot (std::ostream &out) const
 
void print_svg (std::ostream &out) const
 
std::size_t memory_consumption () const
 
size_type n_rows () const
 
size_type n_cols () const
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 
EnableObserverPointer functionality

Classes derived from EnableObserverPointer provide a facility to subscribe to this object. This is mostly used by the ObserverPointer class.

void subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
void unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const
 
unsigned int n_subscriptions () const
 
template<typename StreamType >
void list_subscribers (StreamType &stream) const
 
void list_subscribers () const
 

Static Public Member Functions

static ::ExceptionBaseExcNeedsCollectSizes ()
 
static ::ExceptionBaseExcIncompatibleRowNumbers (int arg1, int arg2, int arg3, int arg4)
 
static ::ExceptionBaseExcIncompatibleColNumbers (int arg1, int arg2, int arg3, int arg4)
 
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 

Static Public Attributes

static const size_type invalid_entry
 

Protected Member Functions

virtual void resize (const size_type rows, const size_type cols)
 

Protected Attributes

size_type block_rows
 
size_type block_columns
 
Table< 2, std::unique_ptr< SparsityPattern > > sub_objects
 
BlockIndices row_indices
 
BlockIndices column_indices
 
size_type rows
 
size_type cols
 

Private Types

using map_value_type = decltype(counter_map)::value_type
 
using map_iterator = decltype(counter_map)::iterator
 

Private Member Functions

size_type compute_n_rows () const
 
size_type compute_n_cols () const
 
void check_no_subscribers () const noexcept
 

Private Attributes

std::vector< size_typecounter_within_block
 
std::vector< std::vector< size_type > > block_column_indices
 
std::atomic< unsigned intcounter
 
std::map< std::string, unsigned intcounter_map
 
std::vector< std::atomic< bool > * > validity_pointers
 
const std::type_info * object_info
 

Static Private Attributes

static std::mutex mutex
 

Detailed Description

This class extends the base class to implement an array of sparsity patterns that can be used by block sparse matrix objects. It only adds a few additional member functions, but the main interface stems from the base class, see there for more information.

This class is an example of the "static" type of Sparsity patterns.

Definition at line 436 of file block_sparsity_pattern.h.

Member Typedef Documentation

◆ size_type

Declare type for container size.

Definition at line 85 of file block_sparsity_pattern.h.

◆ map_value_type

using EnableObserverPointer::map_value_type = decltype(counter_map)::value_type
privateinherited

The data type used in counter_map.

Definition at line 238 of file enable_observer_pointer.h.

◆ map_iterator

using EnableObserverPointer::map_iterator = decltype(counter_map)::iterator
privateinherited

The iterator type used in counter_map.

Definition at line 243 of file enable_observer_pointer.h.

Constructor & Destructor Documentation

◆ BlockSparsityPattern() [1/2]

BlockSparsityPattern::BlockSparsityPattern ( )
default

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.

◆ BlockSparsityPattern() [2/2]

BlockSparsityPattern::BlockSparsityPattern ( const size_type  n_rows,
const size_type  n_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.

Definition at line 367 of file block_sparsity_pattern.cc.

Member Function Documentation

◆ reinit() [1/2]

void BlockSparsityPattern::reinit ( const size_type  n_block_rows,
const size_type  n_block_columns 
)
inline

Forwarding to BlockSparsityPatternBase::reinit().

Definition at line 1079 of file block_sparsity_pattern.h.

◆ reinit() [2/2]

void BlockSparsityPattern::reinit ( const BlockIndices row_indices,
const BlockIndices col_indices,
const std::vector< std::vector< unsigned int > > &  row_lengths 
)

Initialize the pattern with two BlockIndices for the block structures of matrix rows and columns as well as a row length vector.

The row length vector should be in the format produced by DoFTools. Alternatively, there is a simplified version, where each of the inner vectors has length one. Then, the corresponding entry is used as the maximal row length.

For the diagonal blocks, the inner SparsityPattern is initialized with optimized diagonals, while this is not done for the off-diagonal blocks.

Definition at line 374 of file block_sparsity_pattern.cc.

◆ is_compressed()

bool BlockSparsityPattern::is_compressed ( ) const

Return whether the structure is compressed or not, i.e. whether all sub-matrices are compressed.

Definition at line 412 of file block_sparsity_pattern.cc.

◆ copy_from()

void BlockSparsityPattern::copy_from ( const BlockDynamicSparsityPattern dsp)

Copy data from an object of type BlockDynamicSparsityPattern, i.e. resize this object to the size of the given argument, and copy over the contents of each of the subobjects. Previous content of this object is lost.

Definition at line 424 of file block_sparsity_pattern.cc.

◆ collect_sizes()

void BlockSparsityPatternBase< SparsityPattern >::collect_sizes ( )
inherited

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.

Definition at line 151 of file block_sparsity_pattern.cc.

◆ block() [1/2]

SparsityPattern & BlockSparsityPatternBase< SparsityPattern >::block ( const size_type  row,
const size_type  column 
)
inlineinherited

Access the block with the given coordinates.

Definition at line 157 of file block_sparsity_pattern.h.

◆ block() [2/2]

const SparsityPattern & BlockSparsityPatternBase< SparsityPattern >::block ( const size_type  row,
const size_type  column 
) const
inlineinherited

Access the block with the given coordinates. Version for constant objects.

Definition at line 164 of file block_sparsity_pattern.h.

◆ get_row_indices()

const BlockIndices & BlockSparsityPatternBase< SparsityPattern >::get_row_indices ( ) const
inlineinherited

Grant access to the object describing the distribution of row indices to the individual blocks.

Definition at line 171 of file block_sparsity_pattern.h.

◆ get_column_indices()

const BlockIndices & BlockSparsityPatternBase< SparsityPattern >::get_column_indices ( ) const
inlineinherited

Grant access to the object describing the distribution of column indices to the individual blocks.

Definition at line 178 of file block_sparsity_pattern.h.

◆ compress()

void BlockSparsityPatternBase< SparsityPattern >::compress ( )
inherited

This function compresses the sparsity structures that this object represents. It simply calls compress for all sub-objects.

Definition at line 185 of file block_sparsity_pattern.cc.

◆ n_block_rows()

Return the number of blocks in a column.

Definition at line 191 of file block_sparsity_pattern.h.

◆ n_block_cols()

Return the number of blocks in a row.

Definition at line 197 of file block_sparsity_pattern.h.

◆ empty()

bool BlockSparsityPatternBase< SparsityPattern >::empty ( ) const
inherited

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.

Definition at line 206 of file block_sparsity_pattern.cc.

◆ max_entries_per_row()

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.

Definition at line 214 of file block_sparsity_pattern.cc.

◆ add()

void BlockSparsityPatternBase< SparsityPattern >::add ( const size_type  i,
const size_type  j 
)
inlineinherited

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.

Definition at line 226 of file block_sparsity_pattern.h.

◆ add_entries() [1/2]

void BlockSparsityPatternBase< SparsityPattern >::add_entries ( const size_type  row,
ForwardIterator  begin,
ForwardIterator  end,
const bool  indices_are_sorted = false 
)
inherited

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.

Definition at line 240 of file block_sparsity_pattern.h.

◆ add_entries() [2/2]

void SparsityPatternBase::add_entries ( const ArrayView< const std::pair< size_type, size_type > > &  entries)
virtualinherited

General function for adding new entries from an unsorted list of pairs.

This function is useful when multiple entries need to be added which do not correspond to a particular row, e.g., when assembling a flux sparsity pattern.

Reimplemented from SparsityPatternBase.

Definition at line 255 of file sparsity_pattern_base.cc.

◆ add_row_entries()

void BlockSparsityPatternBase< SparsityPattern >::add_row_entries ( const size_type row,
const ArrayView< const size_type > &  columns,
const bool  indices_are_sorted = false 
)
overridevirtualinherited

Add several nonzero entries to the specified matrix row. This function may only be called for non-compressed sparsity patterns and works the same way as the overload which takes iterators.

Implements SparsityPatternBase.

Definition at line 251 of file block_sparsity_pattern.h.

◆ exists()

bool BlockSparsityPatternBase< SparsityPattern >::exists ( const size_type  i,
const size_type  j 
) const
inlineinherited

Check if a value at a certain position may be non-zero.

Definition at line 274 of file block_sparsity_pattern.h.

◆ row_length()

unsigned int BlockSparsityPatternBase< SparsityPattern >::row_length ( const size_type  row) const
inlineinherited

Number of entries in a specific row, added up over all the blocks that form this row.

Definition at line 281 of file block_sparsity_pattern.h.

◆ n_nonzero_elements()

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.

Definition at line 295 of file block_sparsity_pattern.cc.

◆ print()

void BlockSparsityPatternBase< SparsityPattern >::print ( std::ostream &  out) const
inherited

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.

Definition at line 303 of file block_sparsity_pattern.cc.

◆ print_gnuplot()

void BlockSparsityPatternBase< SparsityPattern >::print_gnuplot ( std::ostream &  out) const
inherited

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::print_gnuplot().

Definition at line 313 of file block_sparsity_pattern.cc.

◆ print_svg()

void BlockSparsityPatternBase< SparsityPattern >::print_svg ( std::ostream &  out) const
inherited

Print the sparsity of the matrix in svg format. This is the same functionality implemented for usual sparsity patterns, see SparsityPattern::print_svg().

Definition at line 321 of file block_sparsity_pattern.cc.

◆ memory_consumption()

std::size_t BlockSparsityPatternBase< SparsityPattern >::memory_consumption ( ) const
inherited

Determine an estimate for the memory consumption (in bytes) of this object.

Definition at line 328 of file block_sparsity_pattern.cc.

◆ ExcNeedsCollectSizes()

static ::ExceptionBase & BlockSparsityPatternBase< SparsityPattern >::ExcNeedsCollectSizes ( )
staticinherited

Exception

Note
The message that will be printed by this exception reads:
"The number of rows and columns (returned by n_rows() and n_cols()) does " "not match their directly computed values. This typically means that a " "call to collect_sizes() is missing."

◆ ExcIncompatibleRowNumbers()

static ::ExceptionBase & BlockSparsityPatternBase< SparsityPattern >::ExcIncompatibleRowNumbers ( int  arg1,
int  arg2,
int  arg3,
int  arg4 
)
staticinherited

Exception

Note
The message that will be printed by this exception reads:
<< "The blocks [" << arg1 << ',' << arg2 << "] and [" << arg3 << ',' << arg4 << "] have differing row numbers."

◆ ExcIncompatibleColNumbers()

static ::ExceptionBase & BlockSparsityPatternBase< SparsityPattern >::ExcIncompatibleColNumbers ( int  arg1,
int  arg2,
int  arg3,
int  arg4 
)
staticinherited

Exception

Note
The message that will be printed by this exception reads:
<< "The blocks [" << arg1 << ',' << arg2 << "] and [" << arg3 << ',' << arg4 << "] have differing column numbers."

◆ compute_n_rows()

Internal utility function for computing the number of rows.

Definition at line 399 of file block_sparsity_pattern.cc.

◆ compute_n_cols()

Internal utility function for computing the number of columns.

Definition at line 405 of file block_sparsity_pattern.cc.

◆ n_rows()

size_type SparsityPatternBase::n_rows ( ) const
inherited

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.

◆ n_cols()

size_type SparsityPatternBase::n_cols ( ) const
inherited

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.

◆ resize()

virtual void SparsityPatternBase::resize ( const size_type  rows,
const size_type  cols 
)
protectedvirtualinherited

Internal function for updating the stored size of the sparsity pattern.

◆ subscribe()

void EnableObserverPointer::subscribe ( std::atomic< bool > *const  validity,
const std::string &  identifier = "" 
) const
inherited

Subscribes a user of the object by storing the pointer validity. The subscriber may be identified by text supplied as identifier.

Definition at line 131 of file enable_observer_pointer.cc.

◆ unsubscribe()

void EnableObserverPointer::unsubscribe ( std::atomic< bool > *const  validity,
const std::string &  identifier = "" 
) const
inherited

Unsubscribes a user from the object.

Note
The identifier and the validity pointer must be the same as the one supplied to subscribe().

Definition at line 151 of file enable_observer_pointer.cc.

◆ n_subscriptions()

unsigned int EnableObserverPointer::n_subscriptions ( ) const
inlineinherited

Return the present number of subscriptions to this object. This allows to use this class for reference counted lifetime determination where the last one to unsubscribe also deletes the object.

Definition at line 322 of file enable_observer_pointer.h.

◆ list_subscribers() [1/2]

template<typename StreamType >
void EnableObserverPointer::list_subscribers ( StreamType &  stream) const
inlineinherited

List the subscribers to the input stream.

Definition at line 339 of file enable_observer_pointer.h.

◆ list_subscribers() [2/2]

void EnableObserverPointer::list_subscribers ( ) const
inherited

List the subscribers to deallog.

Definition at line 199 of file enable_observer_pointer.cc.

◆ serialize()

template<class Archive >
void EnableObserverPointer::serialize ( Archive &  ar,
const unsigned int  version 
)
inlineinherited

Read or write the data of this object to or from a stream for the purpose of serialization using the BOOST serialization library.

This function does not actually serialize any of the member variables of this class. The reason is that what this class stores is only who subscribes to this object, but who does so at the time of storing the contents of this object does not necessarily have anything to do with who subscribes to the object when it is restored. Consequently, we do not want to overwrite the subscribers at the time of restoring, and then there is no reason to write the subscribers out in the first place.

Definition at line 331 of file enable_observer_pointer.h.

◆ check_no_subscribers()

void EnableObserverPointer::check_no_subscribers ( ) const
privatenoexceptinherited

Check that there are no objects subscribing to this object. If this check passes then it is safe to destroy the current object. It this check fails then this function will either abort or print an error message to deallog (by using the AssertNothrow mechanism), but will not throw an exception.

Note
Since this function is just a consistency check it does nothing in release mode.
If this function is called when there is an uncaught exception then, rather than aborting, this function prints an error message to the standard error stream and returns.

Definition at line 53 of file enable_observer_pointer.cc.

Member Data Documentation

◆ invalid_entry

const size_type BlockSparsityPatternBase< SparsityPattern >::invalid_entry
staticinherited

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.

Definition at line 95 of file block_sparsity_pattern.h.

◆ block_rows

size_type BlockSparsityPatternBase< SparsityPattern >::block_rows
protectedinherited

Number of block rows.

Definition at line 370 of file block_sparsity_pattern.h.

◆ block_columns

size_type BlockSparsityPatternBase< SparsityPattern >::block_columns
protectedinherited

Number of block columns.

Definition at line 375 of file block_sparsity_pattern.h.

◆ sub_objects

Table<2, std::unique_ptr<SparsityPattern > > BlockSparsityPatternBase< SparsityPattern >::sub_objects
protectedinherited

Array of sparsity patterns.

Definition at line 380 of file block_sparsity_pattern.h.

◆ row_indices

BlockIndices BlockSparsityPatternBase< SparsityPattern >::row_indices
protectedinherited

Object storing and managing the transformation of row indices to indices of the sub-objects.

Definition at line 386 of file block_sparsity_pattern.h.

◆ column_indices

BlockIndices BlockSparsityPatternBase< SparsityPattern >::column_indices
protectedinherited

Object storing and managing the transformation of column indices to indices of the sub-objects.

Definition at line 392 of file block_sparsity_pattern.h.

◆ counter_within_block

std::vector<size_type> BlockSparsityPatternBase< SparsityPattern >::counter_within_block
privateinherited

Temporary vector for counting the elements written into the individual blocks when doing a collective add or set.

Definition at line 411 of file block_sparsity_pattern.h.

◆ block_column_indices

std::vector<std::vector<size_type> > BlockSparsityPatternBase< SparsityPattern >::block_column_indices
privateinherited

Temporary vector for column indices on each block when writing local to global data on each sparse matrix.

Definition at line 417 of file block_sparsity_pattern.h.

◆ rows

size_type SparsityPatternBase::rows
protectedinherited

Number of rows that this sparsity pattern shall represent.

Definition at line 121 of file sparsity_pattern_base.h.

◆ cols

size_type SparsityPatternBase::cols
protectedinherited

Number of columns that this sparsity pattern shall represent.

Definition at line 126 of file sparsity_pattern_base.h.

◆ counter

std::atomic<unsigned int> EnableObserverPointer::counter
mutableprivateinherited

Store the number of objects which subscribed to this object. Initially, this number is zero, and upon destruction it shall be zero again (i.e. all objects which subscribed should have unsubscribed again).

The creator (and owner) of an object is counted in the map below if HE manages to supply identification.

We use the mutable keyword in order to allow subscription to constant objects also.

This counter may be read from and written to concurrently in multithreaded code: hence we use the std::atomic class template.

Definition at line 227 of file enable_observer_pointer.h.

◆ counter_map

std::map<std::string, unsigned int> EnableObserverPointer::counter_map
mutableprivateinherited

In this map, we count subscriptions for each different identification string supplied to subscribe().

Definition at line 233 of file enable_observer_pointer.h.

◆ validity_pointers

std::vector<std::atomic<bool> *> EnableObserverPointer::validity_pointers
mutableprivateinherited

In this vector, we store pointers to the validity bool in the ObserverPointer objects that subscribe to this class.

Definition at line 249 of file enable_observer_pointer.h.

◆ object_info

const std::type_info* EnableObserverPointer::object_info
mutableprivateinherited

Pointer to the typeinfo object of this object, from which we can later deduce the class name. Since this information on the derived class is neither available in the destructor, nor in the constructor, we obtain it in between and store it here.

Definition at line 257 of file enable_observer_pointer.h.

◆ mutex

std::mutex EnableObserverPointer::mutex
staticprivateinherited

A mutex used to ensure data consistency when accessing the mutable members of this class. This lock is used in the subscribe() and unsubscribe() functions, as well as in list_subscribers().

Definition at line 280 of file enable_observer_pointer.h.


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