SparsityPattern Class Reference
[Sparsity patterns]

Inheritance diagram for SparsityPattern:
Inheritance graph
[legend]

List of all members.

Classes

class  ExcDiagonalNotOptimized
class  ExcEmptyObject
class  ExcInvalidArraySize
class  ExcInvalidConstructorCall
class  ExcInvalidIndex
class  ExcInvalidNumber
class  ExcInvalidNumberOfPartitions
class  ExcIteratorRange
class  ExcMatrixIsCompressed
class  ExcNotCompressed
class  ExcNotEnoughSpace

Public Types

typedef
internals::SparsityPatternIterators::Iterator 
const_iterator
typedef
internals::SparsityPatternIterators::Iterator 
iterator

Public Member Functions

 SparsityPattern ()
 SparsityPattern (const SparsityPattern &)
 SparsityPattern (const unsigned int m, const unsigned int n, const unsigned int max_per_row, const bool optimize_diagonal=true)
 SparsityPattern (const unsigned int m, const unsigned int n, const std::vector< unsigned int > &row_lengths, const bool optimize_diagonal=true)
 SparsityPattern (const unsigned int n, const unsigned int max_per_row)
 SparsityPattern (const unsigned int m, const std::vector< unsigned int > &row_lengths, const bool optimize_diagonal=true)
 SparsityPattern (const SparsityPattern &original, const unsigned int max_per_row, const unsigned int extra_off_diagonals)
 ~SparsityPattern ()
SparsityPatternoperator= (const SparsityPattern &)
void reinit (const unsigned int m, const unsigned int n, const unsigned int max_per_row, const bool optimize_diagonal=true)
void reinit (const unsigned int m, const unsigned int n, const std::vector< unsigned int > &row_lengths, const bool optimize_diagonal=true)
void reinit (const unsigned int m, const unsigned int n, const VectorSlice< const std::vector< unsigned int > > &row_lengths, const bool optimize_diagonal=true)
void compress ()
iterator begin () const
iterator end () const
iterator begin (const unsigned int r) const
iterator end (const unsigned int r) const
template<typename ForwardIterator >
void copy_from (const unsigned int n_rows, const unsigned int n_cols, const ForwardIterator begin, const ForwardIterator end, const bool optimize_diagonal=true)
void copy_from (const CompressedSparsityPattern &csp, const bool optimize_diagonal=true)
void copy_from (const CompressedSetSparsityPattern &csp, const bool optimize_diagonal=true)
void copy_from (const CompressedSimpleSparsityPattern &csp, const bool optimize_diagonal=true)
template<typename number >
void copy_from (const FullMatrix< number > &matrix, const bool optimize_diagonal=true)
bool empty () const
unsigned int max_entries_per_row () const
unsigned int operator() (const unsigned int i, const unsigned int j) const
std::pair< unsigned int,
unsigned int
matrix_position (const unsigned int global_index) const
void add (const unsigned int i, const unsigned int j)
template<typename ForwardIterator >
void add_entries (const unsigned int row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
void symmetrize ()
unsigned int n_rows () const
unsigned int n_cols () const
bool exists (const unsigned int i, const unsigned int j) const
unsigned int row_length (const unsigned int row) const
unsigned int column_number (const unsigned int row, const unsigned int index) const
unsigned int bandwidth () const
unsigned int n_nonzero_elements () const
bool is_compressed () const
bool optimize_diagonal () const
bool stores_only_added_elements () const
void partition (const unsigned int n_partitions, std::vector< unsigned int > &partition_indices) const
void block_write (std::ostream &out) const
void block_read (std::istream &in)
void print (std::ostream &out) const
void print_gnuplot (std::ostream &out) const
unsigned int memory_consumption () const
const std::size_t * get_rowstart_indices () const
const unsigned intget_column_numbers () const

Static Public Attributes

static const unsigned int invalid_entry = numbers::invalid_unsigned_int

Private Attributes

unsigned int max_dim
unsigned int rows
unsigned int cols
std::size_t max_vec_len
unsigned int max_row_length
std::size_t * rowstart
unsigned intcolnums
bool compressed
bool diagonal_optimized

Friends

class SparseMatrix
class ChunkSparseMatrix
class ChunkSparsityPattern

Detailed Description

Structure representing the sparsity pattern of a sparse matrix.

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

It uses the compressed row storage (CSR) format to store data.

Author:
Wolfgang Bangerth, Guido Kanschat and others

Member Typedef Documentation

Typedef an iterator class that allows to walk over all nonzero elements of a sparsity pattern.

Typedef an iterator class that allows to walk over all nonzero elements of a sparsity pattern.

Since the iterator does not allow to modify the sparsity pattern, this type is the same as that for const_iterator.


Constructor & Destructor Documentation

SparsityPattern::SparsityPattern (  ) 

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.

SparsityPattern::SparsityPattern ( const SparsityPattern  ) 

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 yo want to use the STL data types on classes like this, e.g. to write such statements like v.push_back (SparsityPattern());, with v a vector of SparsityPattern objects.

Usually, it is sufficient to use the explicit keyword to disallow unwanted temporaries, but for the STL vectors, this does not work. Since copying a structure like this is not useful anyway because multiple matrices can use the same sparsity structure, copies are only allowed for empty objects, as described above.

SparsityPattern::SparsityPattern ( const unsigned int  m,
const unsigned int  n,
const unsigned int  max_per_row,
const bool  optimize_diagonal = true 
)

Initialize a rectangular matrix.

  • m number of rows
  • n number of columns
  • max_per_row maximum number of nonzero entries per row
  • optimize_diagonal store diagonal entries first in row; see optimize_diagonal(). This takes effect for quadratic matrices only.
SparsityPattern::SparsityPattern ( const unsigned int  m,
const unsigned int  n,
const std::vector< unsigned int > &  row_lengths,
const bool  optimize_diagonal = true 
)

Initialize a rectangular matrix.

  • m number of rows
  • n number of columns
  • row_lengths possible number of nonzero entries for each row. This vector must have one entry for each row.
  • optimize_diagonal store diagonal entries first in row; see optimize_diagonal(). This takes effect for quadratic matrices only.
SparsityPattern::SparsityPattern ( const unsigned int  n,
const unsigned int  max_per_row 
)

Initialize a quadratic matrix of dimension n with at most max_per_row nonzero entries per row.

This constructor automatically enables optimized storage of diagonal elements. To avoid this, use the constructor taking row and column numbers separately.

SparsityPattern::SparsityPattern ( const unsigned int  m,
const std::vector< unsigned int > &  row_lengths,
const bool  optimize_diagonal = true 
)

Initialize a quadratic matrix.

  • m number of rows and columns
  • row_lengths possible number of nonzero entries for each row. This vector must have one entry for each row.
SparsityPattern::SparsityPattern ( const SparsityPattern original,
const unsigned int  max_per_row,
const unsigned int  extra_off_diagonals 
)

Make a copy with extra off-diagonals.

This constructs objects intended for the application of the ILU(n)-method or other incomplete decompositions. Therefore, additional to the original entry structure, space for extra_off_diagonals side-diagonals is provided on both sides of the main diagonal.

max_per_row is the maximum number of nonzero elements per row which this structure is to hold. It is assumed that this number is sufficiently large to accomodate both the elements in original as well as the new off-diagonal elements created by this constructor. You will usually want to give the same number as you gave for original plus the number of side diagonals times two. You may however give a larger value if you wish to add further nonzero entries for the decomposition based on other criteria than their being on side-diagonals.

This function requires that original refers to a quadratic matrix structure. It must be compressed. The matrix structure is not compressed after this function finishes.

SparsityPattern::~SparsityPattern (  ) 

Destructor.


Member Function Documentation

SparsityPattern& SparsityPattern::operator= ( const SparsityPattern  ) 

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 SparsityPattern::reinit ( const unsigned int  m,
const unsigned int  n,
const unsigned int  max_per_row,
const bool  optimize_diagonal = true 
)

Reallocate memory and set up data structures for a new matrix with m rows and n columns, with at most max_per_row nonzero entries per row.

This function simply maps its operations to the other reinit function.

void SparsityPattern::reinit ( const unsigned int  m,
const unsigned int  n,
const std::vector< unsigned int > &  row_lengths,
const bool  optimize_diagonal = true 
)

Reallocate memory for a matrix of size m x n. The number of entries for each row is taken from the array row_lengths which has to give this number of each row i=1...m.

If m*n==0 all memory is freed, resulting in a total reinitialization of the object. If it is nonzero, new memory is only allocated if the new size extends the old one. This is done to save time and to avoid fragmentation of the heap.

If the number of rows equals the number of columns and the last parameter is true, diagonal elements are stored first in each row to allow optimized access in relaxation methods of SparseMatrix.

void SparsityPattern::reinit ( const unsigned int  m,
const unsigned int  n,
const VectorSlice< const std::vector< unsigned int > > &  row_lengths,
const bool  optimize_diagonal = true 
)

Same as above, but with a VectorSlice argument instead.

void SparsityPattern::compress (  ) 

This function compresses the sparsity structure that this object represents. It does so by eliminating unused entries and sorting the remaining ones to allow faster access by usage of binary search algorithms. A special sorting scheme is used for the diagonal entry of quadratic matrices, which is always the first entry of each row.

The memory which is no more needed is released.

SparseMatrix objects require the SparsityPattern objects they are initialized with to be compressed, to reduce memory requirements.

iterator SparsityPattern::begin (  )  const [inline]

STL-like iterator with the first entry of the matrix. The resulting iterator can be used to walk over all nonzero entries of the sparsity pattern.

iterator SparsityPattern::end (  )  const [inline]

Final iterator.

iterator SparsityPattern::begin ( const unsigned int  r  )  const [inline]

STL-like iterator with the first entry of row r.

Note that if the given row is empty, i.e. does not contain any nonzero entries, then the iterator returned by this function equals end(r). Note also that the iterator may not be dereferencable in that case.

iterator SparsityPattern::end ( const unsigned int  r  )  const [inline]

Final iterator of row r. It points to the first element past the end of line r, or past the end of the entire sparsity pattern.

Note that the end iterator is not necessarily dereferencable. This is in particular the case if it is the end iterator for the last row of a matrix.

template<typename ForwardIterator >
void SparsityPattern::copy_from ( const unsigned int  n_rows,
const unsigned int  n_cols,
const ForwardIterator  begin,
const ForwardIterator  end,
const bool  optimize_diagonal = true 
) [inline]

This function can be used as a replacement for reinit(), subsequent calls to add() and a final call to close() if you know exactly in advance the entries that will form the matrix sparsity pattern.

The first two parameters determine the size of the matrix. For the two last ones, note that a sparse matrix can be described by a sequence of rows, each of which is represented by a sequence of pairs of column indices and values. In the present context, the begin() and end() parameters designate iterators (of forward iterator type) into a container, one representing one row. The distance between begin() and end() should therefore be equal to n_rows(). These iterators may be iterators of std::vector, std::list, pointers into a C-style array, or any other iterator satisfying the requirements of a forward iterator. The objects pointed to by these iterators (i.e. what we get after applying operator* or operator-> to one of these iterators) must be a container itself that provides functions begin and end designating a range of iterators that describe the contents of one line. Dereferencing these inner iterators must either yield a pair of an unsigned integer as column index and a value of arbitrary type (such a type would be used if we wanted to describe a sparse matrix with one such object), or simply an unsigned integer (of we only wanted to describe a sparsity pattern). The function is able to determine itself whether an unsigned integer or a pair is what we get after dereferencing the inner iterators, through some template magic.

While the order of the outer iterators denotes the different rows of the matrix, the order of the inner iterator denoting the columns does not matter, as they are sorted internal to this function anyway.

Since that all sounds very complicated, consider the following example code, which may be used to fill a sparsity pattern:

 std::vector<std::vector<unsigned int> > column_indices (n_rows);
 for (unsigned int row=0; row<n_rows; ++row)
         // generate necessary columns in this row
   fill_row (column_indices[row]);

 sparsity.copy_from (n_rows, n_cols,
                     column_indices.begin(),
                     column_indices.end());

Note that this example works since the iterators dereferenced yield containers with functions begin and end (namely std::vectors), and the inner iterators dereferenced yield unsigned integers as column indices. Note that we could have replaced each of the two std::vector occurrences by std::list, and the inner one by std::set as well.

Another example would be as follows, where we initialize a whole matrix, not only a sparsity pattern:

 std::vector<std::map<unsigned int,double> > entries (n_rows);
 for (unsigned int row=0; row<n_rows; ++row)
         // generate necessary pairs of columns
         // and corresponding values in this row
   fill_row (entries[row]);

 sparsity.copy_from (n_rows, n_cols,
                     column_indices.begin(),
                     column_indices.end());
 matrix.reinit (sparsity);
 matrix.copy_from (column_indices.begin(),
                   column_indices.end());

This example works because dereferencing iterators of the inner type yields a pair of unsigned integers and a value, the first of which we take as column index. As previously, the outer std::vector could be replaced by std::list, and the inner std::map<unsigned int,double> could be replaced by std::vector<std::pair<unsigned int,double> >, or a list or set of such pairs, as they all return iterators that point to such pairs.

void SparsityPattern::copy_from ( const CompressedSparsityPattern csp,
const bool  optimize_diagonal = true 
)

Copy data from an object of type CompressedSparsityPattern. Previous content of this object is lost, and the sparsity pattern is in compressed mode afterwards.

void SparsityPattern::copy_from ( const CompressedSetSparsityPattern csp,
const bool  optimize_diagonal = true 
)

Copy data from an object of type CompressedSetSparsityPattern. Previous content of this object is lost, and the sparsity pattern is in compressed mode afterwards.

void SparsityPattern::copy_from ( const CompressedSimpleSparsityPattern csp,
const bool  optimize_diagonal = true 
)

Copy data from an object of type CompressedSimpleSparsityPattern. Previous content of this object is lost, and the sparsity pattern is in compressed mode afterwards.

template<typename number >
void SparsityPattern::copy_from ( const FullMatrix< number > &  matrix,
const bool  optimize_diagonal = true 
) [inline]

Take a full matrix and use its nonzero entries to generate a sparse matrix entry pattern for this object.

Previous content of this object is lost, and the sparsity pattern is in compressed mode afterwards.

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

unsigned int SparsityPattern::max_entries_per_row (  )  const

Return the maximum number of entries per row. Before compression, this equals the number given to the constructor, while after compression, it equals the maximum number of entries actually allocated by the user.

unsigned int SparsityPattern::operator() ( const unsigned int  i,
const unsigned int  j 
) const

Return the index of the matrix element with row number i and column number j. If the matrix element is not a nonzero one, return SparsityPattern::invalid_entry.

This function is usually called by the SparseMatrix::operator()(). It may only be called for compressed sparsity patterns, since in this case searching whether the entry exists can be done quite fast with a binary sort algorithm because the column numbers are sorted.

If m is the number of entries in row, then the complexity of this function is log(m) if the sparsity pattern is compressed.

Deprecated:
Use SparseMatrix::const_iterator
std::pair<unsigned int, unsigned int> SparsityPattern::matrix_position ( const unsigned int  global_index  )  const

This is the inverse operation to operator()(): given a global index, find out row and column of the matrix entry to which it belongs. The returned value is the pair composed of row and column index.

This function may only be called if the sparsity pattern is closed. The global index must then be between zero and n_nonzero_elements().

If N is the number of rows of this matrix, then the complexity of this function is log(N).

void SparsityPattern::add ( const unsigned int  i,
const unsigned int  j 
)

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.

template<typename ForwardIterator >
void SparsityPattern::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.

void SparsityPattern::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 quadratic matrix.

unsigned int SparsityPattern::n_rows (  )  const [inline]

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

unsigned int SparsityPattern::n_cols (  )  const [inline]

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

bool SparsityPattern::exists ( const unsigned int  i,
const unsigned int  j 
) const

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

unsigned int SparsityPattern::row_length ( const unsigned int  row  )  const [inline]

Number of entries in a specific row.

unsigned int SparsityPattern::column_number ( const unsigned int  row,
const unsigned int  index 
) const

Access to column number field. Return the column number of the indexth entry in row. Note that if diagonal elements are optimized, the first element in each row is the diagonal element, i.e. column_number(row,0)==row.

If the sparsity pattern is already compressed, then (except for the diagonal element), the entries are sorted by columns, i.e. column_number(row,i) < column_number(row,i+1).

unsigned int SparsityPattern::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. Consequently, the maximum bandwidth a $n\times m$ matrix can have is $\max\{n-1,m-1\}$.

unsigned int SparsityPattern::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.

bool SparsityPattern::is_compressed (  )  const

Return whether the structure is compressed or not.

bool SparsityPattern::optimize_diagonal (  )  const

Determine whether the matrix uses special convention for quadratic matrices.

A return value true means that diagonal elements are stored first in each row. A number of functions in this class and the library in general, for example relaxation methods like Jacobi() and SOR(), require this to make their operations more efficient, since they need to quickly access the diagonal elements and do not have to search for them if they are the first element of each row. A side effect of this scheme is that each row contains at least one element, even if the row is empty (i.e. the diagonal element exists, but has value zero).

A return value false means that diagonal elements are stored anywhere in the row, or not at all. In particular, a row or even the whole matrix may be empty. This can be used if you have block matrices where the off-diagonal blocks are quadratic but are never used for operations like the ones mentioned above. In this case, some memory can be saved by not using the diagonal storage optimization.

bool SparsityPattern::stores_only_added_elements (  )  const

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 true iff optimize_diag in the constructor or reinit() calls has been set to false, or if the represented matrix is not square.

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.

void SparsityPattern::partition ( const unsigned int  n_partitions,
std::vector< unsigned int > &  partition_indices 
) const
Deprecated:

This function is deprecated. Use SparsityTools::partition instead.

Use the METIS partitioner to generate a partitioning of the degrees of freedom represented by this sparsity pattern. In effect, we view this sparsity pattern as a graph of connections between various degrees of freedom, where each nonzero entry in the sparsity pattern corresponds to an edge between two nodes in the connection graph. The goal is then to decompose this graph into groups of nodes so that a minimal number of edges are cut by the boundaries between node groups. This partitioning is done by METIS. Note that METIS can only partition symmetric sparsity patterns, and that of course the sparsity pattern has to be square. We do not check for symmetry of the sparsity pattern, since this is an expensive operation, but rather leave this as the responsibility of caller of this function.

After calling this function, the output array will have values between zero and n_partitions-1 for each node (i.e. row or column of the matrix).

This function will generate an error if METIS is not installed unless n_partitions is one. I.e., you can write a program so that it runs in the single-processor single-partition case without METIS installed, and only requires METIS when multiple partitions are required.

Note that the sparsity pattern itself is not changed by calling this function. However, you will likely use the information generated by calling this function to renumber degrees of freedom, after which you will of course have to regenerate the sparsity pattern.

This function will rarely be called separately, since in finite element methods you will want to partition the mesh, not the matrix. This can be done by calling GridTools::partition_triangulation.

void SparsityPattern::block_write ( std::ostream &  out  )  const

Write the data of this object en bloc to a file. This is done in a binary mode, so the output is neither readable by humans nor (probably) by other computers using a different operating system of number format.

The purpose of this function is that you can swap out matrices and sparsity pattern if you are short of memory, want to communicate between different programs, or allow objects to be persistent across different runs of the program.

void SparsityPattern::block_read ( std::istream &  in  ) 

Read data that has previously been written by block_write() from a file. This is done using the inverse operations to the above function, so it is reasonably fast because the bitstream is not interpreted except for a few numbers up front.

The object is resized on this operation, and all previous contents are lost.

A primitive form of error checking is performed which will recognize the bluntest attempts to interpret some data as a vector stored bitwise to a file, but not more.

void SparsityPattern::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 SparsityPattern::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.

unsigned int SparsityPattern::memory_consumption (  )  const

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

const std::size_t* SparsityPattern::get_rowstart_indices (  )  const [inline]

This is kind of an expert mode. Get access to the rowstart array, but read-only.

Use of this function is highly deprecated. Use row_length and column_number instead. Also, using iterators may get you most of the information you may want.

Though the return value is declared const, you should be aware that it may change if you call any nonconstant function of objects which operate on it.

You should use this interface very carefully and only if you are absolutely sure to know what you do. You should also note that the structure of these arrays may change over time. If you change the layout yourself, you should also rename this function to avoid programs relying on outdated information!

const unsigned int* SparsityPattern::get_column_numbers (  )  const [inline]
Deprecated:
. Use row_length and column_number instead. Also, using iterators may get you most of the information you may want.

This is kind of an expert mode: get access to the colnums array, but readonly.

Though the return value is declared const, you should be aware that it may change if you call any nonconstant function of objects which operate on it.

You should use this interface very carefully and only if you are absolutely sure to know what you do. You should also note that the structure of these arrays may change over time. If you change the layout yourself, you should also rename this function to avoid programs relying on outdated information!


Friends And Related Function Documentation

friend class SparseMatrix [friend]

Make all sparse matrices friends of this class.

friend class ChunkSparseMatrix [friend]
friend class ChunkSparsityPattern [friend]

Member Data Documentation

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.

Indices with this invalid value are used to insert new entries to the sparsity pattern using the add() member function, and are removed when calling compress().

You should not assume that the variable declared here has a certain value. The initialization is given here only to enable the compiler to perform some optimizations, but the actual value of the variable may change over time.

Maximum number of rows that can be stored in the rowstart array. Since reallocation of that array only happens if the present one is too small, but never when the size of this matrix structure shrinks, max_dim might be larger than rows and in this case rowstart has more elements than are used.

Number of rows that this sparsity structure shall represent.

Number of columns that this sparsity structure shall represent.

std::size_t SparsityPattern::max_vec_len [private]

Size of the actually allocated array colnums. Here, the same applies as for the rowstart array, i.e. it may be larger than the actually used part of the array.

Maximum number of elements per row. This is set to the value given to the reinit() function (or to the constructor), or to the maximum row length computed from the vectors in case the more flexible constructors or reinit versions are called. Its value is more or less meaningsless after compress() has been called.

std::size_t* SparsityPattern::rowstart [private]

Array which hold for each row which is the first element in colnums belonging to that row. Note that the size of the array is one larger than the number of rows, because the last element is used for row=rows, i.e. the row past the last used one. The value of rowstart[rows]} equals the index of the element past the end in colnums; this way, we are able to write loops like for (i=rowstart[k]; i<rowstart[k+1]; ++i) also for the last row.

Note that the actual size of the allocated memory may be larger than the region that is used. The actual number of elements that was allocated is stored in max_dim.

Array of column numbers. In this array, we store for each non-zero element its column number. The column numbers for the elements in row r are stored within the index range rowstart[r]...rowstart[r+1]. Therefore to find out whether a given element (r,c) exists, we have to check whether the column number c exists in the abovementioned range within this array. If it exists, say at position p within this array, the value of the respective element in the sparse matrix will also be at position p of the values array of that class.

At the beginning, all elements of this array are set to -1 indicating invalid (unused) column numbers (diagonal elements are preset if optimized storage is requested, though). Now, if nonzero elements are added, one column number in the row's respective range after the other is set to the column number of the added element. When compress is called, unused elements (indicated by column numbers -1) are eliminated by copying the column number of subsequent rows and the column numbers within each row (with possible exception of the diagonal element) are sorted, such that finding whether an element exists and determining its position can be done by a binary search.

Store whether the compress() function was called for this object.

Is special treatment of diagonals enabled?


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

deal.II documentation generated on Mon Nov 23 22:58:09 2009 by doxygen 1.6.1