Reference documentation for deal.II version 8.1.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
CompressedSimpleSparsityPattern Class Reference

#include <compressed_simple_sparsity_pattern.h>

Inheritance diagram for CompressedSimpleSparsityPattern:
[legend]

Classes

struct  Line
 

Public Types

typedef types::global_dof_index size_type
 
typedef std::vector< size_type >::const_iterator row_iterator
 

Public Member Functions

 CompressedSimpleSparsityPattern ()
 
 CompressedSimpleSparsityPattern (const CompressedSimpleSparsityPattern &)
 
 CompressedSimpleSparsityPattern (const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
 
 CompressedSimpleSparsityPattern (const IndexSet &indexset)
 
 CompressedSimpleSparsityPattern (const size_type n)
 
CompressedSimpleSparsityPatternoperator= (const CompressedSimpleSparsityPattern &)
 
void reinit (const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
 
void compress ()
 
bool empty () const
 
size_type max_entries_per_row () const
 
void add (const size_type i, const size_type j)
 
template<typename ForwardIterator >
void add_entries (const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_unique_and_sorted=false)
 
bool exists (const size_type i, const size_type j) const
 
void symmetrize ()
 
void print (std::ostream &out) const
 
void print_gnuplot (std::ostream &out) const
 
size_type n_rows () const
 
size_type n_cols () const
 
size_type row_length (const size_type row) const
 
size_type column_number (const size_type row, const size_type index) const
 
row_iterator row_begin (const size_type row) const
 
row_iterator row_end (const size_type row) const
 
size_type bandwidth () const
 
size_type n_nonzero_elements () const
 
const IndexSetrow_index_set () const
 
size_type memory_consumption () const
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
void subscribe (const char *identifier=0) const
 
void unsubscribe (const char *identifier=0) const
 
unsigned int n_subscriptions () const
 
void list_subscribers () const
 
 DeclException3 (ExcInUse, int, char *, std::string &,<< "Object of class "<< arg2<< " is still used by "<< arg1<< " other objects.\n"<< "(Additional information: "<< arg3<< ")\n"<< "Note the entry in the Frequently Asked Questions of "<< "deal.II (linked to from http://www.dealii.org/) for "<< "more information on what this error means.")
 
 DeclException2 (ExcNoSubscriber, char *, char *,<< "No subscriber with identifier \""<< arg2<< "\" did subscribe to this object of class "<< arg1)
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Static Public Member Functions

static bool stores_only_added_elements ()
 

Private Attributes

size_type rows
 
size_type cols
 
IndexSet rowset
 
std::vector< Linelines
 

Detailed Description

This class acts as an intermediate form of the SparsityPattern class. From the interface it mostly represents a SparsityPattern object that is kept compressed at all times. However, since the final sparsity pattern is not known while constructing it, keeping the pattern compressed at all times can only be achieved at the expense of either increased memory or run time consumption upon use. The main purpose of this class is to avoid some memory bottlenecks, so we chose to implement it memory conservative. The chosen data format is too unsuited to be used for actual matrices, though. It is therefore necessary to first copy the data of this object over to an object of type SparsityPattern before using it in actual matrices.

Another viewpoint is that this class does not need up front allocation of a certain amount of memory, but grows as necessary. An extensive description of sparsity patterns can be found in the documentation of the Sparsity patterns module.

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

Interface

Since this class is intended as an intermediate replacement of the SparsityPattern class, it has mostly the same interface, with small changes where necessary. In particular, the add() function, and the functions inquiring properties of the sparsity pattern are the same.

Usage

Use this class as follows:

CompressedSimpleSparsityPattern compressed_pattern (dof_handler.n_dofs());
compressed_pattern);
constraints.condense (compressed_pattern);
sp.copy_from (compressed_pattern);

Notes

There are several, exchangeable variations of this class, see Sparsity patterns, section '"Dynamic" or "compressed" sparsity patterns' for more information.

Author
Timo Heister, 2008

Definition at line 92 of file compressed_simple_sparsity_pattern.h.

Member Typedef Documentation

Declare the type for container size.

Definition at line 98 of file compressed_simple_sparsity_pattern.h.

typedef std::vector<size_type>::const_iterator CompressedSimpleSparsityPattern::row_iterator

An iterator that can be used to iterate over the elements of a single row. The result of dereferencing such an iterator is a column index.

Definition at line 106 of file compressed_simple_sparsity_pattern.h.

Constructor & Destructor Documentation

CompressedSimpleSparsityPattern::CompressedSimpleSparsityPattern ( )

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.

CompressedSimpleSparsityPattern::CompressedSimpleSparsityPattern ( const CompressedSimpleSparsityPattern )

Copy constructor. This constructor is only allowed to be called if the matrix structure to be copied is empty. This is so in order to prevent involuntary copies of objects for temporaries, which can use large amounts of computing time. However, copy constructors are needed if you want to use the STL data types on classes like this, e.g. to write such statements like v.push_back (CompressedSparsityPattern());, with v a vector of CompressedSparsityPattern objects.

CompressedSimpleSparsityPattern::CompressedSimpleSparsityPattern ( const size_type  m,
const size_type  n,
const IndexSet rowset = IndexSet() 
)

Initialize a rectangular matrix with m rows and n columns. The rowset restricts the storage to elements in rows of this set. Adding elements outside of this set has no effect. The default argument keeps all entries.

CompressedSimpleSparsityPattern::CompressedSimpleSparsityPattern ( const IndexSet indexset)

Create a square SparsityPattern using the index set.

CompressedSimpleSparsityPattern::CompressedSimpleSparsityPattern ( const size_type  n)

Initialize a square matrix of dimension n.

Member Function Documentation

CompressedSimpleSparsityPattern& CompressedSimpleSparsityPattern::operator= ( const CompressedSimpleSparsityPattern )

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.

void CompressedSimpleSparsityPattern::reinit ( const size_type  m,
const size_type  n,
const IndexSet rowset = IndexSet() 
)

Reallocate memory and set up data structures for a new matrix with m rows and n columns, with at most max_entries_per_row() nonzero entries per row. The rowset restricts the storage to elements in rows of this set. Adding elements outside of this set has no effect. The default argument keeps all entries.

void CompressedSimpleSparsityPattern::compress ( )

Since this object is kept compressed at all times anway, this function does nothing, but is declared to make the interface of this class as much alike as that of the SparsityPattern class.

bool CompressedSimpleSparsityPattern::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.

size_type CompressedSimpleSparsityPattern::max_entries_per_row ( ) const

Return the maximum number of entries per row. Note that this number may change as entries are added.

void CompressedSimpleSparsityPattern::add ( const size_type  i,
const size_type  j 
)
inline

Add a nonzero entry to the matrix. If the entry already exists, nothing bad happens.

Definition at line 521 of file compressed_simple_sparsity_pattern.h.

template<typename ForwardIterator >
void CompressedSimpleSparsityPattern::add_entries ( const size_type  row,
ForwardIterator  begin,
ForwardIterator  end,
const bool  indices_are_unique_and_sorted = false 
)
inline

Add several nonzero entries to the specified row of the matrix. If the entries already exist, nothing bad happens.

Definition at line 540 of file compressed_simple_sparsity_pattern.h.

bool CompressedSimpleSparsityPattern::exists ( const size_type  i,
const size_type  j 
) const

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

void CompressedSimpleSparsityPattern::symmetrize ( )

Make the sparsity pattern symmetric by adding the sparsity pattern of the transpose object.

This function throws an exception if the sparsity pattern does not represent a square matrix.

void CompressedSimpleSparsityPattern::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 CompressedSimpleSparsityPattern::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. The format consists of pairs i j of nonzero elements, each representing one entry of this matrix, one per line of the output file. Indices are counted from zero on, as usual. Since sparsity patterns are printed in the same way as matrices are displayed, we print the negative of the column index, which means that the (0,0) element is in the top left rather than in the bottom left corner.

Print the sparsity pattern in gnuplot by setting the data style to dots or points and use the plot command.

CompressedSimpleSparsityPattern::size_type CompressedSimpleSparsityPattern::n_rows ( ) const
inline

Return number of rows of this matrix, which equals the dimension of the image space.

Definition at line 503 of file compressed_simple_sparsity_pattern.h.

types::global_dof_index CompressedSimpleSparsityPattern::n_cols ( ) const
inline

Return number of columns of this matrix, which equals the dimension of the range space.

Definition at line 512 of file compressed_simple_sparsity_pattern.h.

types::global_dof_index CompressedSimpleSparsityPattern::row_length ( const size_type  row) const
inline

Number of entries in a specific row. This function can only be called if the given row is a member of the index set of rows that we want to store.

Definition at line 565 of file compressed_simple_sparsity_pattern.h.

types::global_dof_index CompressedSimpleSparsityPattern::column_number ( const size_type  row,
const size_type  index 
) const
inline

Access to column number field. Return the column number of the indexth entry in row.

Definition at line 580 of file compressed_simple_sparsity_pattern.h.

CompressedSimpleSparsityPattern::row_iterator CompressedSimpleSparsityPattern::row_begin ( const size_type  row) const
inline

Return an iterator that can loop over all entries in the given row. Dereferencing the iterator yields a column index.

Definition at line 596 of file compressed_simple_sparsity_pattern.h.

CompressedSimpleSparsityPattern::row_iterator CompressedSimpleSparsityPattern::row_end ( const size_type  row) const
inline

Returns the end of the current row.

Definition at line 607 of file compressed_simple_sparsity_pattern.h.

size_type CompressedSimpleSparsityPattern::bandwidth ( ) const

Compute the bandwidth of the matrix represented by this structure. The bandwidth is the maximum of $|i-j|$ for which the index pair $(i,j)$ represents a nonzero entry of the matrix.

size_type CompressedSimpleSparsityPattern::n_nonzero_elements ( ) const

Return the number of nonzero elements allocated through this sparsity pattern.

const IndexSet & CompressedSimpleSparsityPattern::row_index_set ( ) const
inline

Return the IndexSet that sets which rows are active on the current processor. It corresponds to the IndexSet given to this class in the constructor or in the reinit function.

Definition at line 618 of file compressed_simple_sparsity_pattern.h.

bool CompressedSimpleSparsityPattern::stores_only_added_elements ( )
inlinestatic

return whether this object stores only those entries that have been added explicitly, or if the sparsity pattern contains elements that have been added through other means (implicitly) while building it. For the current class, the result is always true.

This function mainly serves the purpose of describing the current class in cases where several kinds of sparsity patterns can be passed as template arguments.

Definition at line 627 of file compressed_simple_sparsity_pattern.h.

size_type CompressedSimpleSparsityPattern::memory_consumption ( ) const

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

Member Data Documentation

size_type CompressedSimpleSparsityPattern::rows
private

Number of rows that this sparsity structure shall represent.

Definition at line 396 of file compressed_simple_sparsity_pattern.h.

size_type CompressedSimpleSparsityPattern::cols
private

Number of columns that this sparsity structure shall represent.

Definition at line 402 of file compressed_simple_sparsity_pattern.h.

IndexSet CompressedSimpleSparsityPattern::rowset
private

A set that contains the valid rows.

Definition at line 408 of file compressed_simple_sparsity_pattern.h.

std::vector<Line> CompressedSimpleSparsityPattern::lines
private

Actual data: store for each row the set of nonzero entries.

Definition at line 462 of file compressed_simple_sparsity_pattern.h.


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