dune-istl  2.3.0
Public Types | Public Member Functions | List of all members
Dune::BDMatrix< B, A > Class Template Reference

A block-diagonal matrix. More...

#include <dune/istl/bdmatrix.hh>

Inheritance diagram for Dune::BDMatrix< B, A >:
Dune::BCRSMatrix< B, A >

Public Types

enum  { blocklevel = B::blocklevel+1 }
 increment block level counter More...
 
typedef B::field_type field_type
 export the type representing the field More...
 
typedef B block_type
 export the type representing the components More...
 
typedef A allocator_type
 export the allocator type More...
 
typedef A::size_type size_type
 implement row_type with compressed vector More...
 
enum  BuildStage {
  notbuilt =0, notAllocated =0, building =1, rowSizesBuilt =2,
  built =3
}
 
enum  { blocklevel = B::blocklevel+1 }
 increment block level counter More...
 
enum  BuildMode { row_wise, random, implicit, unknown }
 we support two modes More...
 
typedef
CompressedBlockVectorWindow< B,
A
row_type
 implement row_type with compressed vector More...
 
typedef
::Dune::CompressionStatistics
< size_type
CompressionStatistics
 The type for the statistics object returned by compress() More...
 
typedef RealRowIterator< row_typeiterator
 The iterator over the (mutable matrix rows. More...
 
typedef RealRowIterator< row_typeIterator
 
typedef Iterator RowIterator
 rename the iterators for easier access More...
 
typedef row_type::Iterator ColIterator
 Iterator for the entries of each row. More...
 
typedef RealRowIterator< const
row_type
const_iterator
 The const iterator over the matrix rows. More...
 
typedef RealRowIterator< const
row_type
ConstIterator
 
typedef ConstIterator ConstRowIterator
 rename the const row iterator for easier access More...
 
typedef row_type::ConstIterator ConstColIterator
 Const iterator to the entries of a row. More...
 

Public Member Functions

 BDMatrix ()
 Default constructor. More...
 
 BDMatrix (int size)
 
BDMatrixoperator= (const BDMatrix &other)
 assignment More...
 
BDMatrixoperator= (const field_type &k)
 assignment from scalar More...
 
void invert ()
 Inverts the matrix. More...
 
row_typeoperator[] (size_type i)
 random access to the rows More...
 
const row_typeoperator[] (size_type i) const
 same for read only access More...
 
Iterator begin ()
 Get iterator to first row. More...
 
ConstIterator begin () const
 Get const iterator to first row. More...
 
Iterator end ()
 Get iterator to one beyond last row. More...
 
ConstIterator end () const
 Get const iterator to one beyond last row. More...
 
Iterator beforeEnd ()
 
ConstIterator beforeEnd () const
 
Iterator beforeBegin ()
 
ConstIterator beforeBegin () const
 
void setBuildMode (BuildMode bm)
 Sets the build mode of the matrix. More...
 
void setSize (size_type rows, size_type columns, size_type nnz=0)
 Set the size of the matrix. More...
 
void setImplicitBuildModeParameters (size_type _avg, double _overflow)
 Set parameters needed for creation in implicit build mode. More...
 
CreateIterator createbegin ()
 get initial create iterator More...
 
CreateIterator createend ()
 get create iterator pointing to one after the last block More...
 
size_type getrowsize (size_type i) const
 get current number of indices in row i More...
 
void incrementrowsize (size_type i, size_type s=1)
 increment size of row i by s (1 by default) More...
 
template<typename It >
void setIndices (size_type row, It begin, It end)
 Set all column indices for row from the given iterator range. More...
 
B & entry (size_type row, size_type col)
 Returns reference to entry (row,col) of the matrix. More...
 
CompressionStatistics compress ()
 Finishes the buildstage in implicit mode. More...
 
BCRSMatrixoperator*= (const field_type &k)
 vector space multiplication with scalar More...
 
BCRSMatrixoperator/= (const field_type &k)
 vector space division by scalar More...
 
BCRSMatrixoperator+= (const BCRSMatrix &b)
 Add the entries of another matrix to this one. More...
 
BCRSMatrixoperator-= (const BCRSMatrix &b)
 Substract the entries of another matrix to this one. More...
 
BCRSMatrixaxpy (field_type alpha, const BCRSMatrix &b)
 Add the scaled entries of another matrix to this one. More...
 
template<class X , class Y >
void mv (const X &x, Y &y) const
 y = A x More...
 
template<class X , class Y >
void umv (const X &x, Y &y) const
 y += A x More...
 
template<class X , class Y >
void mmv (const X &x, Y &y) const
 y -= A x More...
 
template<class X , class Y >
void usmv (const field_type &alpha, const X &x, Y &y) const
 y += alpha A x More...
 
template<class X , class Y >
void mtv (const X &x, Y &y) const
 y = A^T x More...
 
template<class X , class Y >
void umtv (const X &x, Y &y) const
 y += A^T x More...
 
template<class X , class Y >
void mmtv (const X &x, Y &y) const
 y -= A^T x More...
 
template<class X , class Y >
void usmtv (const field_type &alpha, const X &x, Y &y) const
 y += alpha A^T x More...
 
template<class X , class Y >
void umhv (const X &x, Y &y) const
 y += A^H x More...
 
template<class X , class Y >
void mmhv (const X &x, Y &y) const
 y -= A^H x More...
 
template<class X , class Y >
void usmhv (const field_type &alpha, const X &x, Y &y) const
 y += alpha A^H x More...
 
FieldTraits< field_type >
::real_type 
frobenius_norm2 () const
 square of frobenius norm, need for block recursion More...
 
FieldTraits< field_type >
::real_type 
frobenius_norm () const
 frobenius norm: sqrt(sum over squared values of entries) More...
 
FieldTraits< field_type >
::real_type 
infinity_norm () const
 infinity norm (row sum norm, how to generalize for blocks?) More...
 
FieldTraits< field_type >
::real_type 
infinity_norm_real () const
 simplified infinity norm (uses Manhattan norm for complex values) More...
 
size_type N () const
 number of rows (counted in blocks) More...
 
size_type M () const
 number of columns (counted in blocks) More...
 
size_type nonzeroes () const
 number of blocks that are stored (the number of blocks that possibly are nonzero) More...
 
BuildStage buildStage () const
 The current build stage of the matrix. More...
 
BuildMode buildMode () const
 The currently selected build mode of the matrix. More...
 
bool exists (size_type i, size_type j) const
 return true if (i,j) is in pattern More...
 

Detailed Description

template<class B, class A = std::allocator<B>>
class Dune::BDMatrix< B, A >

A block-diagonal matrix.

Todo:
It would be safer and more efficient to have a real implementation of a block-diagonal matrix and not just subclassing from BCRSMatrix. But that's quite a lot of work for that little advantage.

Member Typedef Documentation

template<class B , class A = std::allocator<B>>
typedef A Dune::BDMatrix< B, A >::allocator_type

export the allocator type

template<class B , class A = std::allocator<B>>
typedef B Dune::BDMatrix< B, A >::block_type

export the type representing the components

template<class B, class A = std::allocator<B>>
typedef row_type::Iterator Dune::BCRSMatrix< B, A >::ColIterator
inherited

Iterator for the entries of each row.

template<class B, class A = std::allocator<B>>
typedef ::Dune::CompressionStatistics<size_type> Dune::BCRSMatrix< B, A >::CompressionStatistics
inherited

The type for the statistics object returned by compress()

template<class B, class A = std::allocator<B>>
typedef RealRowIterator<const row_type> Dune::BCRSMatrix< B, A >::const_iterator
inherited

The const iterator over the matrix rows.

template<class B, class A = std::allocator<B>>
typedef row_type::ConstIterator Dune::BCRSMatrix< B, A >::ConstColIterator
inherited

Const iterator to the entries of a row.

template<class B, class A = std::allocator<B>>
typedef RealRowIterator<const row_type> Dune::BCRSMatrix< B, A >::ConstIterator
inherited
template<class B, class A = std::allocator<B>>
typedef ConstIterator Dune::BCRSMatrix< B, A >::ConstRowIterator
inherited

rename the const row iterator for easier access

template<class B , class A = std::allocator<B>>
typedef B::field_type Dune::BDMatrix< B, A >::field_type

export the type representing the field

template<class B, class A = std::allocator<B>>
typedef RealRowIterator<row_type> Dune::BCRSMatrix< B, A >::iterator
inherited

The iterator over the (mutable matrix rows.

template<class B, class A = std::allocator<B>>
typedef RealRowIterator<row_type> Dune::BCRSMatrix< B, A >::Iterator
inherited
template<class B, class A = std::allocator<B>>
typedef CompressedBlockVectorWindow<B,A> Dune::BCRSMatrix< B, A >::row_type
inherited

implement row_type with compressed vector

template<class B, class A = std::allocator<B>>
typedef Iterator Dune::BCRSMatrix< B, A >::RowIterator
inherited

rename the iterators for easier access

template<class B , class A = std::allocator<B>>
typedef A::size_type Dune::BDMatrix< B, A >::size_type

implement row_type with compressed vector

The type for the index access and the size

Member Enumeration Documentation

template<class B, class A = std::allocator<B>>
anonymous enum
inherited

increment block level counter

Enumerator
blocklevel 

The number of blocklevels the matrix contains.

template<class B , class A = std::allocator<B>>
anonymous enum

increment block level counter

Enumerator
blocklevel 
template<class B, class A = std::allocator<B>>
enum Dune::BCRSMatrix::BuildMode
inherited

we support two modes

Enumerator
row_wise 

Build in a row-wise manner.

Rows are built up in sequential order. Size of the row and the column indices are defined. A row can be used as soon as it is initialized. With respect to memory there are two variants of this scheme: (a) number of non-zeroes known in advance (application finite difference schemes), (b) number of non-zeroes not known in advance (application: Sparse LU, ILU(n)).

random 

Build entries randomly.

For general finite element implementations the number of rows n is known, the number of non-zeroes might also be known (e.g. #edges + #nodes for P1) but the size of a row and the indices of a row can not be defined in sequential order.

implicit 

Build entries randomly with an educated guess on entries per row.

Allows random order generation as in random mode, but row sizes do not need to be given first. Instead an average number of non-zeroes per row is passed to the constructor. Matrix setup is finished with compress(), full data access during build stage is possible.

unknown 

Build mode not set!

template<class B, class A = std::allocator<B>>
enum Dune::BCRSMatrix::BuildStage
inherited
Enumerator
notbuilt 

Matrix is not built at all, no memory has been allocated, build mode and size can still be set.

notAllocated 

Matrix is not built at all, no memory has been allocated, build mode and size can still be set.

building 

Matrix is currently being built, some memory has been allocated, build mode and size are fixed.

rowSizesBuilt 

The row sizes of the matrix are known.

Only used in random mode.

built 

The matrix structure is fully built.

Constructor & Destructor Documentation

template<class B , class A = std::allocator<B>>
Dune::BDMatrix< B, A >::BDMatrix ( )
inline

Default constructor.

template<class B , class A = std::allocator<B>>
Dune::BDMatrix< B, A >::BDMatrix ( int  size)
inlineexplicit

Member Function Documentation

template<class B, class A = std::allocator<B>>
BCRSMatrix& Dune::BCRSMatrix< B, A >::axpy ( field_type  alpha,
const BCRSMatrix< B, A > &  b 
)
inlineinherited

Add the scaled entries of another matrix to this one.

Matrix axpy operation: *this += alpha * b

Parameters
alphaScaling factor.
bThe matrix to add to this one. Its sparsity pattern has to be subset of the sparsity pattern of this matrix.

References Dune::BCRSMatrix< B, A >::begin(), Dune::BCRSMatrix< B, A >::built, Dune::BCRSMatrix< B, A >::end(), Dune::BCRSMatrix< B, A >::M(), and Dune::BCRSMatrix< B, A >::N().

template<class B, class A = std::allocator<B>>
Iterator Dune::BCRSMatrix< B, A >::beforeBegin ( )
inlineinherited
Returns
an iterator that is positioned before the first row of the matrix.
template<class B, class A = std::allocator<B>>
ConstIterator Dune::BCRSMatrix< B, A >::beforeBegin ( ) const
inlineinherited
Returns
an iterator that is positioned before the first row of the matrix.
template<class B, class A = std::allocator<B>>
Iterator Dune::BCRSMatrix< B, A >::beforeEnd ( )
inlineinherited
Returns
an iterator that is positioned before the end iterator of the rows, i.e. at the last row.
template<class B, class A = std::allocator<B>>
ConstIterator Dune::BCRSMatrix< B, A >::beforeEnd ( ) const
inlineinherited
Returns
an iterator that is positioned before the end iterator of the rows. i.e. at the last row.
template<class B, class A = std::allocator<B>>
Iterator Dune::BCRSMatrix< B, A >::begin ( )
inlineinherited
template<class B, class A = std::allocator<B>>
ConstIterator Dune::BCRSMatrix< B, A >::begin ( ) const
inlineinherited

Get const iterator to first row.

template<class B, class A = std::allocator<B>>
BuildMode Dune::BCRSMatrix< B, A >::buildMode ( ) const
inlineinherited

The currently selected build mode of the matrix.

template<class B, class A = std::allocator<B>>
BuildStage Dune::BCRSMatrix< B, A >::buildStage ( ) const
inlineinherited

The current build stage of the matrix.

template<class B, class A = std::allocator<B>>
CompressionStatistics Dune::BCRSMatrix< B, A >::compress ( )
inlineinherited
template<class B, class A = std::allocator<B>>
CreateIterator Dune::BCRSMatrix< B, A >::createbegin ( )
inlineinherited

get initial create iterator

References Dune::BCRSMatrix< B, A >::CreateIterator.

Referenced by test_IO(), and test_Iter().

template<class B, class A = std::allocator<B>>
CreateIterator Dune::BCRSMatrix< B, A >::createend ( )
inlineinherited

get create iterator pointing to one after the last block

References Dune::BCRSMatrix< B, A >::CreateIterator.

Referenced by test_IO(), and test_Iter().

template<class B, class A = std::allocator<B>>
Iterator Dune::BCRSMatrix< B, A >::end ( )
inlineinherited
template<class B, class A = std::allocator<B>>
ConstIterator Dune::BCRSMatrix< B, A >::end ( ) const
inlineinherited

Get const iterator to one beyond last row.

template<class B, class A = std::allocator<B>>
B& Dune::BCRSMatrix< B, A >::entry ( size_type  row,
size_type  col 
)
inlineinherited

Returns reference to entry (row,col) of the matrix.

This method can only be used when the matrix is in implicit building mode.

A reference to entry (row, col) of the matrix is returned. If entry (row, col) is accessed for the first time, it is created on the fly.

This method can only be used while building the matrix, after compression operator[] gives a much better performance.

References Dune::BCRSMatrix< B, A >::begin(), Dune::BCRSMatrix< B, A >::building, Dune::BCRSMatrix< B, A >::built, col, Dune::BCRSMatrix< B, A >::end(), Dune::CompressedBlockVectorWindow< B, A >::getindexptr(), Dune::CompressedBlockVectorWindow< B, A >::getptr(), Dune::CompressedBlockVectorWindow< B, A >::getsize(), Dune::BCRSMatrix< B, A >::implicit, Dune::BCRSMatrix< B, A >::notAllocated, row, and Dune::CompressedBlockVectorWindow< B, A >::setsize().

template<class B, class A = std::allocator<B>>
bool Dune::BCRSMatrix< B, A >::exists ( size_type  i,
size_type  j 
) const
inlineinherited

return true if (i,j) is in pattern

References Dune::BCRSMatrix< B, A >::end().

template<class B, class A = std::allocator<B>>
FieldTraits<field_type>::real_type Dune::BCRSMatrix< B, A >::frobenius_norm ( ) const
inlineinherited

frobenius norm: sqrt(sum over squared values of entries)

References Dune::BCRSMatrix< B, A >::frobenius_norm2().

template<class B, class A = std::allocator<B>>
FieldTraits<field_type>::real_type Dune::BCRSMatrix< B, A >::frobenius_norm2 ( ) const
inlineinherited
template<class B, class A = std::allocator<B>>
size_type Dune::BCRSMatrix< B, A >::getrowsize ( size_type  i) const
inlineinherited

get current number of indices in row i

References Dune::CompressedBlockVectorWindow< B, A >::getsize().

template<class B, class A = std::allocator<B>>
void Dune::BCRSMatrix< B, A >::incrementrowsize ( size_type  i,
size_type  s = 1 
)
inlineinherited
template<class B, class A = std::allocator<B>>
FieldTraits<field_type>::real_type Dune::BCRSMatrix< B, A >::infinity_norm ( ) const
inlineinherited

infinity norm (row sum norm, how to generalize for blocks?)

References Dune::BCRSMatrix< B, A >::begin(), Dune::BCRSMatrix< B, A >::built, and Dune::BCRSMatrix< B, A >::end().

template<class B, class A = std::allocator<B>>
FieldTraits<field_type>::real_type Dune::BCRSMatrix< B, A >::infinity_norm_real ( ) const
inlineinherited

simplified infinity norm (uses Manhattan norm for complex values)

References Dune::BCRSMatrix< B, A >::begin(), Dune::BCRSMatrix< B, A >::built, and Dune::BCRSMatrix< B, A >::end().

template<class B , class A = std::allocator<B>>
void Dune::BDMatrix< B, A >::invert ( )
inline

Inverts the matrix.

References Dune::BCRSMatrix< B, A >::N().

template<class B, class A = std::allocator<B>>
size_type Dune::BCRSMatrix< B, A >::M ( ) const
inlineinherited
template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::mmhv ( const X &  x,
Y &  y 
) const
inlineinherited
template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::mmtv ( const X &  x,
Y &  y 
) const
inlineinherited
template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::mmv ( const X &  x,
Y &  y 
) const
inlineinherited
template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::mtv ( const X &  x,
Y &  y 
) const
inlineinherited
template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::mv ( const X &  x,
Y &  y 
) const
inlineinherited
template<class B, class A = std::allocator<B>>
size_type Dune::BCRSMatrix< B, A >::N ( ) const
inlineinherited
template<class B, class A = std::allocator<B>>
size_type Dune::BCRSMatrix< B, A >::nonzeroes ( ) const
inlineinherited

number of blocks that are stored (the number of blocks that possibly are nonzero)

template<class B, class A = std::allocator<B>>
BCRSMatrix& Dune::BCRSMatrix< B, A >::operator*= ( const field_type k)
inlineinherited
template<class B, class A = std::allocator<B>>
BCRSMatrix& Dune::BCRSMatrix< B, A >::operator+= ( const BCRSMatrix< B, A > &  b)
inlineinherited

Add the entries of another matrix to this one.

Parameters
bThe matrix to add to this one. Its sparsity pattern has to be subset of the sparsity pattern of this matrix.

References Dune::BCRSMatrix< B, A >::begin(), Dune::BCRSMatrix< B, A >::built, Dune::BCRSMatrix< B, A >::end(), Dune::BCRSMatrix< B, A >::M(), and Dune::BCRSMatrix< B, A >::N().

template<class B, class A = std::allocator<B>>
BCRSMatrix& Dune::BCRSMatrix< B, A >::operator-= ( const BCRSMatrix< B, A > &  b)
inlineinherited

Substract the entries of another matrix to this one.

Parameters
bThe matrix to add to this one. Its sparsity pattern has to be subset of the sparsity pattern of this matrix.

References Dune::BCRSMatrix< B, A >::begin(), Dune::BCRSMatrix< B, A >::built, Dune::BCRSMatrix< B, A >::end(), Dune::BCRSMatrix< B, A >::M(), and Dune::BCRSMatrix< B, A >::N().

template<class B, class A = std::allocator<B>>
BCRSMatrix& Dune::BCRSMatrix< B, A >::operator/= ( const field_type k)
inlineinherited
template<class B , class A = std::allocator<B>>
BDMatrix& Dune::BDMatrix< B, A >::operator= ( const BDMatrix< B, A > &  other)
inline

assignment

References Dune::BCRSMatrix< B, A >::operator=().

template<class B , class A = std::allocator<B>>
BDMatrix& Dune::BDMatrix< B, A >::operator= ( const field_type k)
inline

assignment from scalar

References Dune::BCRSMatrix< B, A >::operator=().

template<class B, class A = std::allocator<B>>
row_type& Dune::BCRSMatrix< B, A >::operator[] ( size_type  i)
inlineinherited

random access to the rows

References Dune::BCRSMatrix< B, A >::built, and Dune::BCRSMatrix< B, A >::implicit.

template<class B, class A = std::allocator<B>>
const row_type& Dune::BCRSMatrix< B, A >::operator[] ( size_type  i) const
inlineinherited

same for read only access

References Dune::BCRSMatrix< B, A >::built, and Dune::BCRSMatrix< B, A >::implicit.

template<class B, class A = std::allocator<B>>
void Dune::BCRSMatrix< B, A >::setBuildMode ( BuildMode  bm)
inlineinherited
template<class B, class A = std::allocator<B>>
void Dune::BCRSMatrix< B, A >::setImplicitBuildModeParameters ( size_type  _avg,
double  _overflow 
)
inlineinherited

Set parameters needed for creation in implicit build mode.

Use this method before setSize() to define storage behaviour of a matrix in implicit build mode

Parameters
_avgexpected average number of entries per row
_overflowsizefraction of _n*_avg which is expected to be needed for elements that exceed _avg entries per row.

References Dune::BCRSMatrix< B, A >::notAllocated.

template<class B, class A = std::allocator<B>>
template<typename It >
void Dune::BCRSMatrix< B, A >::setIndices ( size_type  row,
It  begin,
It  end 
)
inlineinherited

Set all column indices for row from the given iterator range.

The iterator range has to be of the same length as the previously set row size. The entries in the iterator range do not have to be in any particular order, but must not contain duplicate values.

Calling this method overwrites any previously set column indices!

References Dune::CompressedBlockVectorWindow< B, A >::getindexptr(), row, and Dune::compressed_base_array_unmanaged< B, A >::size().

template<class B, class A = std::allocator<B>>
void Dune::BCRSMatrix< B, A >::setSize ( size_type  rows,
size_type  columns,
size_type  nnz = 0 
)
inlineinherited

Set the size of the matrix.

Sets the number of rows and columns of the matrix and allocates the memory needed for the storage of the matrix entries.

Warning
After calling this methods on an already allocated (and probably setup matrix) results in all the structure and data being deleted. I.~e. one has to setup the matrix again.
Parameters
rowsThe number of rows the matrix should contain.
columnsthe number of columns the matrix should contain.
nnzThe number of nonzero entries the matrix should hold (if omitted defaults to 0). Must be omitted in implicit mode.

References Dune::BCRSMatrix< B, A >::implicit.

template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::umhv ( const X &  x,
Y &  y 
) const
inlineinherited
template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::umtv ( const X &  x,
Y &  y 
) const
inlineinherited
template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::umv ( const X &  x,
Y &  y 
) const
inlineinherited
template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::usmhv ( const field_type alpha,
const X &  x,
Y &  y 
) const
inlineinherited
template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::usmtv ( const field_type alpha,
const X &  x,
Y &  y 
) const
inlineinherited
template<class B, class A = std::allocator<B>>
template<class X , class Y >
void Dune::BCRSMatrix< B, A >::usmv ( const field_type alpha,
const X &  x,
Y &  y 
) const
inlineinherited

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