dune-istl 2.12-git
Loading...
Searching...
No Matches
Dune::Experimental::Matrix< B, P, A > Class Template Reference

Owning matrix container built on top of MatrixView. More...

#include <dune/istl/experimental/matrix.hh>

Inheritance diagram for Dune::Experimental::Matrix< B, P, A >:
Inheritance graph

Public Types

using allocator_type = A
 Allocator type used by this container.
 
using block_iter_type = B
 The iterator type used to access the blocks of the matrix.
 
using pattern_type = P
 The type used for the sparsity pattern.
 
using row_index_range_type = std::ranges::range_value_t< pattern_type >
 The type used for the index set of rows.
 
using block_type = std::iter_value_t< block_iter_type >
 The type of blocks in the matrix.
 
using value_type = block_type
 The type of blocks in the matrix.
 
using size_type = std::ranges::range_size_t< pattern_type >
 The type used to count elements in the row and column index sets.
 
using field_type = typename FieldTraits< block_type >::field_type
 The type of the field.
 
using row_type = VectorView< block_iter_type, row_index_range_type >
 The type representing a mutable matrix row.
 
using const_row_type = VectorView< block_const_iter_type, row_index_range_type >
 The type representing a const matrix row.
 
using iterator = Iterator
 The type of mutable matrix iterators over the rows.
 
using const_iterator = ConstIterator
 The type of const matrix iterators over the rows.
 
using RowIterator = Iterator
 The type of mutable matrix iterators over the rows.
 
using ConstRowIterator = ConstIterator
 The type of const matrix iterators over the rows.
 
using ColIterator = typename row_type::iterator
 The type of mutable row iterators over the column blocks.
 
using ConstColIterator = typename const_row_type::const_iterator
 The type of const row iterators over the column blocks.
 

Public Member Functions

 Matrix (const allocator_type &allocator=allocator_type())
 Construct an empty matrix with allocator allocator.
 
 Matrix (std::shared_ptr< const pattern_type > pattern, const allocator_type &allocator=allocator_type())
 Construct from a shared pattern.
 
 Matrix (pattern_type &&pattern, const allocator_type &allocator=allocator_type())
 Construct from an rvalue pattern.
 
 Matrix (const Matrix &other)
 Copy constructor.
 
 Matrix (const Matrix &other, const allocator_type &allocator)
 Copy constructor.
 
Matrix & operator= (const Matrix &other)
 Copy assignment.
 
 Matrix (Matrix &&other)
 Move constructor.
 
Matrix & operator= (Matrix &&other)
 Move assignment.
 
 Matrix (Matrix &&other, const allocator_type &allocator)
 Move construct with explicit allocator.
 
 ~Matrix ()
 Destructor releases owned block storage.
 
allocator_type get_allocator () const
 Return the allocator currently associated with this matrix.
 
void swap (Matrix &other)
 Swap contents of this matrix with other, honoring allocator swap propagation traits.
 
std::shared_ptr< const pattern_type > patternStorage () const
 Get shared storage of the pattern.
 
template<class Alloc , class ConstructFn >
auto allocateData (const Alloc &alloc, size_type count, ConstructFn &&construct_fn) -> block_iter_type
 
template<class Alloc , class ConstructFn , class RestoreFn >
auto allocateData (const Alloc &alloc, size_type count, ConstructFn &&construct_fn, RestoreFn &&restore_fn) -> block_iter_type
 
row_type operator[] (size_type i)
 Return a mutable view of row i.
 
const_row_type operator[] (size_type i) const
 Return a const view of row i.
 
Iterator begin ()
 Return iterator to the first row.
 
ConstIterator begin () const
 Return const iterator to the first row.
 
Iterator end ()
 Return iterator one past the last row.
 
ConstIterator end () const
 Return const iterator one past the last row.
 
ConstIterator cbegin () const
 Return const iterator to the first row.
 
ConstIterator cend () const
 Return const iterator one past the last row.
 
MatrixView & axpy (field_type alpha, const MatrixView< OtherB, OtherI > &b)
 Compute \(this \leftarrow this + \alpha b\).
 
MatrixView< B, I > & axpy (field_type alpha, const MatrixView< OtherB, OtherI > &b)
 
void mv (const X &x, Y &y) const
 Compute \(y = Ax\).
 
void umv (const X &x, Y &y) const
 Compute \(y \mathrel{+}= Ax\).
 
void mmv (const X &x, Y &y) const
 Compute \(y \mathrel{-}= Ax\).
 
void usmv (const field_type &alpha, const X &x, Y &y) const
 Compute \(y \mathrel{+}= \alpha Ax\).
 
void mtv (const X &x, Y &y) const
 Compute \(y = A^T x\).
 
void umtv (const X &x, Y &y) const
 Compute \(y \mathrel{+}= A^T x\).
 
void mmtv (const X &x, Y &y) const
 Compute \(y \mathrel{-}= A^T x\).
 
void usmtv (const field_type &alpha, const X &x, Y &y) const
 Compute \(y \mathrel{+}= \alpha A^T x\).
 
void umhv (const X &x, Y &y) const
 Compute \(y \mathrel{+}= A^H x\) (Hermitian transpose).
 
void mmhv (const X &x, Y &y) const
 Compute \(y \mathrel{-}= A^H x\) (Hermitian transpose).
 
void usmhv (const field_type &alpha, const X &x, Y &y) const
 Compute \(y \mathrel{+}= \alpha A^H x\) (Hermitian transpose).
 
FieldTraits< field_type >::real_type frobenius_norm2 () const
 Return \(\|A\|_F^2\) (sum of squared block Frobenius norms).
 
FieldTraits< field_type >::real_type frobenius_norm () const
 Return the Frobenius norm \(\|A\|_F\).
 
FieldTraits< field_type >::real_type infinity_norm () const
 Return the block-aware infinity norm.
 
FieldTraits< field_type >::real_type infinity_norm_real () const
 Return simplified infinity norm (Manhattan norm for complex values).
 
bool exists (size_type i, size_type j) const DUNE_ISTL_WITH_CHECKING_NOEXCEPT
 Test whether position \((i,j)\) is present in the sparsity pattern.
 
size_type N () const
 Number of block rows.
 
size_type M () const
 Number of block columns.
 
size_type nonzeroes () const
 Number of stored block entries.
 
MatrixView & operator*= (const field_type &k)
 Scale all stored blocks by k.
 
MatrixView & operator/= (const field_type &k)
 Divide all stored blocks by k.
 
MatrixView & operator+= (const MatrixView< OtherB, OtherI > &b)
 Add another matrix view to this one.
 
MatrixView< B, I > & operator+= (const MatrixView< OtherB, OtherI > &b)
 
MatrixView & operator-= (const MatrixView< OtherB, OtherI > &b)
 Subtract another matrix view from this one.
 
MatrixView< B, I > & operator-= (const MatrixView< OtherB, OtherI > &b)
 
const pattern_type & pattern () const
 

Protected Member Functions

void resetView (block_iter_type block_iter, pattern_type const *pattern_ptr)
 Reset the view to point to block_iter and pattern_ptr.
 
block_iter_type blockIter ()
 Return the underlying block iterator.
 
block_const_iter_type blockIter () const
 Return the underlying block iterator as a const iterator.
 
pattern_type const * patternPtr () const
 Return the underlying pattern pointer.
 

Friends

void swap (Matrix &lhs, Matrix &rhs)
 Swap contents of lhs and rhs, honoring allocator swap propagation traits.
 

Detailed Description

template<class B, class P, class A = std::allocator<B>>
class Dune::Experimental::Matrix< B, P, A >

Owning matrix container built on top of MatrixView.

Matrix stores block values and owns a pattern while exposing the matrix interface from MatrixView.

In contrast to MatrixView, this class owns both resources:

  • block storage for all structurally present entries,
  • a shared pointer to the immutable sparsity pattern.
Template Parameters
BBlock value type.
PPattern type (See MatrixView).
AAllocator type used for block and pattern storage.

Member Typedef Documentation

◆ allocator_type

template<class B , class P , class A = std::allocator<B>>
using Dune::Experimental::Matrix< B, P, A >::allocator_type = A

Allocator type used by this container.

◆ block_iter_type

using Dune::Experimental::MatrixView< B, P >::block_iter_type = B
inherited

The iterator type used to access the blocks of the matrix.

◆ block_type

using Dune::Experimental::MatrixView< B, P >::block_type = std::iter_value_t<block_iter_type>
inherited

The type of blocks in the matrix.

◆ ColIterator

using Dune::Experimental::MatrixView< B, P >::ColIterator = typename row_type::iterator
inherited

The type of mutable row iterators over the column blocks.

◆ const_iterator

using Dune::Experimental::MatrixView< B, P >::const_iterator = ConstIterator
inherited

The type of const matrix iterators over the rows.

◆ const_row_type

using Dune::Experimental::MatrixView< B, P >::const_row_type = VectorView<block_const_iter_type, row_index_range_type>
inherited

The type representing a const matrix row.

◆ ConstColIterator

using Dune::Experimental::MatrixView< B, P >::ConstColIterator = typename const_row_type::const_iterator
inherited

The type of const row iterators over the column blocks.

◆ ConstRowIterator

using Dune::Experimental::MatrixView< B, P >::ConstRowIterator = ConstIterator
inherited

The type of const matrix iterators over the rows.

◆ field_type

using Dune::Experimental::MatrixView< B, P >::field_type = typename FieldTraits<block_type>::field_type
inherited

The type of the field.

◆ iterator

using Dune::Experimental::MatrixView< B, P >::iterator = Iterator
inherited

The type of mutable matrix iterators over the rows.

◆ pattern_type

using Dune::Experimental::MatrixView< B, P >::pattern_type = P
inherited

The type used for the sparsity pattern.

◆ row_index_range_type

using Dune::Experimental::MatrixView< B, P >::row_index_range_type = std::ranges::range_value_t<pattern_type>
inherited

The type used for the index set of rows.

◆ row_type

The type representing a mutable matrix row.

◆ RowIterator

using Dune::Experimental::MatrixView< B, P >::RowIterator = Iterator
inherited

The type of mutable matrix iterators over the rows.

◆ size_type

using Dune::Experimental::MatrixView< B, P >::size_type = std::ranges::range_size_t<pattern_type>
inherited

The type used to count elements in the row and column index sets.

◆ value_type

using Dune::Experimental::MatrixView< B, P >::value_type = block_type
inherited

The type of blocks in the matrix.

Constructor & Destructor Documentation

◆ Matrix() [1/7]

template<class B , class P , class A >
Dune::Experimental::Matrix< B, P, A >::Matrix ( const allocator_type &  allocator = allocator_type())

Construct an empty matrix with allocator allocator.

The resulting matrix has no pattern and no allocated block storage.

◆ Matrix() [2/7]

template<class B , class P , class A >
Dune::Experimental::Matrix< B, P, A >::Matrix ( std::shared_ptr< const pattern_type >  pattern,
const allocator_type &  allocator = allocator_type() 
)

Construct from a shared pattern.

If pattern is non-null, block storage is allocated and value-initialized for pattern->count() entries.

◆ Matrix() [3/7]

template<class B , class P , class A >
Dune::Experimental::Matrix< B, P, A >::Matrix ( pattern_type &&  pattern,
const allocator_type &  allocator = allocator_type() 
)

Construct from an rvalue pattern.

The pattern is moved into shared owned storage and corresponding block storage is allocated and value-initialized.

◆ Matrix() [4/7]

template<class B , class P , class A >
Dune::Experimental::Matrix< B, P, A >::Matrix ( const Matrix< B, P, A > &  other)

Copy constructor.

Shares the sparsity pattern and deep-copies block values.

◆ Matrix() [5/7]

template<class B , class P , class A >
Dune::Experimental::Matrix< B, P, A >::Matrix ( const Matrix< B, P, A > &  other,
const allocator_type &  allocator 
)

Copy constructor.

Shares the pattern and deep-copies block values.

◆ Matrix() [6/7]

template<class B , class P , class A >
Dune::Experimental::Matrix< B, P, A >::Matrix ( Matrix< B, P, A > &&  other)

Move constructor.

Transfers owned resources from other.

◆ Matrix() [7/7]

template<class B , class P , class A >
Dune::Experimental::Matrix< B, P, A >::Matrix ( Matrix< B, P, A > &&  other,
const allocator_type &  allocator 
)

Move construct with explicit allocator.

If allocators compare equal, resources are stolen. Otherwise, pattern is shared and block values are moved into newly allocated storage.

◆ ~Matrix()

template<class B , class P , class A >
Dune::Experimental::Matrix< B, P, A >::~Matrix ( )

Destructor releases owned block storage.

Member Function Documentation

◆ allocateData() [1/2]

template<class B , class P , class A = std::allocator<B>>
template<class Alloc , class ConstructFn >
auto Dune::Experimental::Matrix< B, P, A >::allocateData ( const Alloc &  alloc,
size_type  count,
ConstructFn &&  construct_fn 
) -> block_iter_type

◆ allocateData() [2/2]

template<class B , class P , class A = std::allocator<B>>
template<class Alloc , class ConstructFn , class RestoreFn >
auto Dune::Experimental::Matrix< B, P, A >::allocateData ( const Alloc &  alloc,
size_type  count,
ConstructFn &&  construct_fn,
RestoreFn &&  restore_fn 
) -> block_iter_type

◆ axpy() [1/2]

MatrixView & Dune::Experimental::MatrixView< B, P >::axpy ( field_type  alpha,
const MatrixView< OtherB, OtherI > &  b 
)
inherited

Compute \(this \leftarrow this + \alpha b\).

◆ axpy() [2/2]

MatrixView< B, I > & Dune::Experimental::MatrixView< B, P >::axpy ( field_type  alpha,
const MatrixView< OtherB, OtherI > &  b 
)
inherited

◆ begin() [1/2]

Iterator Dune::Experimental::MatrixView< B, P >::begin ( )
inlineinherited

Return iterator to the first row.

◆ begin() [2/2]

ConstIterator Dune::Experimental::MatrixView< B, P >::begin ( ) const
inlineinherited

Return const iterator to the first row.

◆ blockIter() [1/2]

block_iter_type Dune::Experimental::MatrixView< B, P >::blockIter ( )
inlineprotectedinherited

Return the underlying block iterator.

◆ blockIter() [2/2]

block_const_iter_type Dune::Experimental::MatrixView< B, P >::blockIter ( ) const
inlineprotectedinherited

Return the underlying block iterator as a const iterator.

◆ cbegin()

ConstIterator Dune::Experimental::MatrixView< B, P >::cbegin ( ) const
inlineinherited

Return const iterator to the first row.

◆ cend()

ConstIterator Dune::Experimental::MatrixView< B, P >::cend ( ) const
inlineinherited

Return const iterator one past the last row.

◆ end() [1/2]

Iterator Dune::Experimental::MatrixView< B, P >::end ( )
inlineinherited

Return iterator one past the last row.

◆ end() [2/2]

ConstIterator Dune::Experimental::MatrixView< B, P >::end ( ) const
inlineinherited

Return const iterator one past the last row.

◆ exists()

bool Dune::Experimental::MatrixView< B, P >::exists ( size_type  i,
size_type  j 
) const
inlineinherited

Test whether position \((i,j)\) is present in the sparsity pattern.

This checks structural existence only. It does not inspect value magnitude.

Exceptions
BCRSMatrixErrorif \(i\) or \(j\) is out of range if DUNE_ISTL_WITH_CHECKING is defined.

◆ frobenius_norm()

auto Dune::Experimental::MatrixView< B, I >::frobenius_norm ( ) const
inherited

Return the Frobenius norm \(\|A\|_F\).

◆ frobenius_norm2()

auto Dune::Experimental::MatrixView< B, I >::frobenius_norm2 ( ) const
inherited

Return \(\|A\|_F^2\) (sum of squared block Frobenius norms).

◆ get_allocator()

template<class B , class P , class A >
auto Dune::Experimental::Matrix< B, P, A >::get_allocator ( ) const

Return the allocator currently associated with this matrix.

◆ infinity_norm()

auto Dune::Experimental::MatrixView< B, I >::infinity_norm ( ) const
inherited

Return the block-aware infinity norm.

◆ infinity_norm_real()

auto Dune::Experimental::MatrixView< B, I >::infinity_norm_real ( ) const
inherited

Return simplified infinity norm (Manhattan norm for complex values).

infinity norm (maximum of absolute values of entries)

◆ M()

size_type Dune::Experimental::MatrixView< B, P >::M ( ) const
inlineinherited

Number of block columns.

◆ mmhv()

void Dune::Experimental::MatrixView< B, I >::mmhv ( const X &  x,
Y &  y 
) const
inherited

Compute \(y \mathrel{-}= A^H x\) (Hermitian transpose).

◆ mmtv()

void Dune::Experimental::MatrixView< B, I >::mmtv ( const X &  x,
Y &  y 
) const
inherited

Compute \(y \mathrel{-}= A^T x\).

◆ mmv()

void Dune::Experimental::MatrixView< B, I >::mmv ( const X &  x,
Y &  y 
) const
inherited

Compute \(y \mathrel{-}= Ax\).

◆ mtv()

void Dune::Experimental::MatrixView< B, I >::mtv ( const X &  x,
Y &  y 
) const
inherited

Compute \(y = A^T x\).

◆ mv()

void Dune::Experimental::MatrixView< B, I >::mv ( const X &  x,
Y &  y 
) const
inherited

Compute \(y = Ax\).

◆ N()

size_type Dune::Experimental::MatrixView< B, P >::N ( ) const
inlineinherited

Number of block rows.

◆ nonzeroes()

size_type Dune::Experimental::MatrixView< B, P >::nonzeroes ( ) const
inlineinherited

Number of stored block entries.

This is the number of structurally present entries, i.e., entries that may be nonzero.

◆ operator*=()

MatrixView< B, I > & Dune::Experimental::MatrixView< B, I >::operator*= ( const field_type &  k)
inherited

Scale all stored blocks by k.

◆ operator+=() [1/2]

MatrixView & Dune::Experimental::MatrixView< B, P >::operator+= ( const MatrixView< OtherB, OtherI > &  b)
inherited

Add another matrix view 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.

◆ operator+=() [2/2]

MatrixView< B, I > & Dune::Experimental::MatrixView< B, P >::operator+= ( const MatrixView< OtherB, OtherI > &  b)
inherited

◆ operator-=() [1/2]

MatrixView & Dune::Experimental::MatrixView< B, P >::operator-= ( const MatrixView< OtherB, OtherI > &  b)
inherited

Subtract another matrix view from this one.

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

◆ operator-=() [2/2]

MatrixView< B, I > & Dune::Experimental::MatrixView< B, P >::operator-= ( const MatrixView< OtherB, OtherI > &  b)
inherited

◆ operator/=()

MatrixView< B, I > & Dune::Experimental::MatrixView< B, I >::operator/= ( const field_type &  k)
inherited

Divide all stored blocks by k.

◆ operator=() [1/2]

template<class B , class P , class A >
Matrix< B, P, A > & Dune::Experimental::Matrix< B, P, A >::operator= ( const Matrix< B, P, A > &  other)

Copy assignment.

Provides strong exception safety for block storage replacement.

◆ operator=() [2/2]

template<class B , class P , class A >
Matrix< B, P, A > & Dune::Experimental::Matrix< B, P, A >::operator= ( Matrix< B, P, A > &&  other)

Move assignment.

Transfers owned resources from other according to allocator propagation rules.

◆ operator[]() [1/2]

row_type Dune::Experimental::MatrixView< B, P >::operator[] ( size_type  i)
inlineinherited

Return a mutable view of row i.

◆ operator[]() [2/2]

const_row_type Dune::Experimental::MatrixView< B, P >::operator[] ( size_type  i) const
inlineinherited

Return a const view of row i.

◆ pattern()

const pattern_type & Dune::Experimental::MatrixView< B, P >::pattern ( ) const
inlineinherited

◆ patternPtr()

pattern_type const * Dune::Experimental::MatrixView< B, P >::patternPtr ( ) const
inlineprotectedinherited

Return the underlying pattern pointer.

◆ patternStorage()

template<class B , class P , class A = std::allocator<B>>
std::shared_ptr< const pattern_type > Dune::Experimental::Matrix< B, P, A >::patternStorage ( ) const
inline

Get shared storage of the pattern.

◆ resetView()

void Dune::Experimental::MatrixView< B, P >::resetView ( block_iter_type  block_iter,
pattern_type const *  pattern_ptr 
)
inlineprotectedinherited

Reset the view to point to block_iter and pattern_ptr.

◆ swap()

template<class B , class P , class A >
void Dune::Experimental::Matrix< B, P, A >::swap ( Matrix< B, P, A > &  other)

Swap contents of this matrix with other, honoring allocator swap propagation traits.

◆ umhv()

void Dune::Experimental::MatrixView< B, I >::umhv ( const X &  x,
Y &  y 
) const
inherited

Compute \(y \mathrel{+}= A^H x\) (Hermitian transpose).

◆ umtv()

void Dune::Experimental::MatrixView< B, I >::umtv ( const X &  x,
Y &  y 
) const
inherited

Compute \(y \mathrel{+}= A^T x\).

◆ umv()

void Dune::Experimental::MatrixView< B, I >::umv ( const X &  x,
Y &  y 
) const
inherited

Compute \(y \mathrel{+}= Ax\).

◆ usmhv()

void Dune::Experimental::MatrixView< B, I >::usmhv ( const field_type &  alpha,
const X &  x,
Y &  y 
) const
inherited

Compute \(y \mathrel{+}= \alpha A^H x\) (Hermitian transpose).

◆ usmtv()

void Dune::Experimental::MatrixView< B, I >::usmtv ( const field_type &  alpha,
const X &  x,
Y &  y 
) const
inherited

Compute \(y \mathrel{+}= \alpha A^T x\).

◆ usmv()

void Dune::Experimental::MatrixView< B, I >::usmv ( const field_type &  alpha,
const X &  x,
Y &  y 
) const
inherited

Compute \(y \mathrel{+}= \alpha Ax\).

Friends And Related Symbol Documentation

◆ swap

template<class B , class P , class A = std::allocator<B>>
void swap ( Matrix< B, P, A > &  lhs,
Matrix< B, P, A > &  rhs 
)
friend

Swap contents of lhs and rhs, honoring allocator swap propagation traits.


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