Loading...
Searching...
No Matches
bdmatrix.hh
Go to the documentation of this file.
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_ISTL_BDMATRIX_HH
#define DUNE_ISTL_BDMATRIX_HH
#include <memory>
#include <dune/common/rangeutilities.hh>
#include <dune/common/scalarmatrixview.hh>
#include <dune/istl/bcrsmatrix.hh>
#include <dune/istl/blocklevel.hh>
namespace Dune {
template <class B, class A=std::allocator<B> >
class BDMatrix : public BCRSMatrix<B,A>
{
public:
//===== type definitions and constants
using field_type = typename Imp::BlockTraits<B>::field_type;
typedef B block_type;
typedef A allocator_type;
//typedef BCRSMatrix<B,A>::row_type row_type;
typedef typename A::size_type size_type;
BDMatrix() : BCRSMatrix<B,A>() {}
explicit BDMatrix(int size)
: BCRSMatrix<B,A>(size, size, BCRSMatrix<B,A>::random) {
for (int i=0; i<size; i++)
this->BCRSMatrix<B,A>::setrowsize(i, 1);
this->BCRSMatrix<B,A>::endrowsizes();
for (int i=0; i<size; i++)
this->BCRSMatrix<B,A>::addindex(i, i);
this->BCRSMatrix<B,A>::endindices();
}
BDMatrix (std::initializer_list<B> const &list)
: BDMatrix(list.size())
{
size_t i=0;
for (auto it = list.begin(); it != list.end(); ++it, ++i)
(*this)[i][i] = *it;
}
void setSize(size_type size)
{
this->BCRSMatrix<B,A>::setSize(size, // rows
size, // columns
size); // nonzeros
for (auto i : range(size))
this->BCRSMatrix<B,A>::setrowsize(i, 1);
this->BCRSMatrix<B,A>::endrowsizes();
for (auto i : range(size))
this->BCRSMatrix<B,A>::addindex(i, i);
this->BCRSMatrix<B,A>::endindices();
}
BDMatrix& operator= (const BDMatrix& other) {
this->BCRSMatrix<B,A>::operator=(other);
return *this;
}
BDMatrix& operator= (const field_type& k) {
this->BCRSMatrix<B,A>::operator=(k);
return *this;
}
template <class V>
void solve (V& x, const V& rhs) const {
for (size_type i=0; i<this->N(); i++)
{
auto&& xv = Impl::asVector(x[i]);
auto&& rhsv = Impl::asVector(rhs[i]);
Impl::asMatrix((*this)[i][i]).solve(xv,rhsv);
}
}
void invert() {
for (size_type i=0; i<this->N(); i++)
Impl::asMatrix((*this)[i][i]).invert();
}
private:
// ////////////////////////////////////////////////////////////////////////////
// The following methods from the base class should now actually be called
// ////////////////////////////////////////////////////////////////////////////
// createbegin and createend should be in there, too, but I can't get it to compile
// BCRSMatrix<B,A>::CreateIterator createbegin () {}
// BCRSMatrix<B,A>::CreateIterator createend () {}
void setrowsize (size_type i, size_type s) {}
void incrementrowsize (size_type i) {}
void endrowsizes () {}
void addindex (size_type row, size_type col) {}
void endindices () {}
};
template<typename B, typename A>
struct FieldTraits< BDMatrix<B, A> >
{
using field_type = typename BDMatrix<B, A>::field_type;
using real_type = typename FieldTraits<field_type>::real_type;
};
} // end namespace Dune
#endif
bcrsmatrix.hh
Implementation of the BCRSMatrix class.
blocklevel.hh
Helper functions for determining the vector/matrix block level.
Dune
Definition allocator.hh:11
Dune::col
MatrixSparsityPatternGatherScatter< M, I >::ColIter MatrixSparsityPatternGatherScatter< M, I >::col
Definition matrixredistribute.hh:591
Dune::size_type
Dune::BCRSMatrix::BCRSMatrix
BCRSMatrix()
an empty matrix
Definition bcrsmatrix.hh:746
Dune::BCRSMatrix::endrowsizes
void endrowsizes()
indicate that size of all rows is defined
Definition bcrsmatrix.hh:1149
Dune::BCRSMatrix::setrowsize
void setrowsize(size_type i, size_type s)
Set number of indices in row i to s.
Definition bcrsmatrix.hh:1117
Dune::BCRSMatrix::random
@ random
Build entries randomly.
Definition bcrsmatrix.hh:527
Dune::BCRSMatrix::addindex
void addindex(size_type row, size_type col)
add index (row,col) to the matrix
Definition bcrsmatrix.hh:1191
Dune::BCRSMatrix::endindices
void endindices()
indicate that all indices are defined, check consistency
Definition bcrsmatrix.hh:1272
Dune::BCRSMatrix::N
size_type N() const
number of rows (counted in blocks)
Definition bcrsmatrix.hh:2004
Dune::BCRSMatrix::setSize
void setSize(size_type rows, size_type columns, size_type nnz=0)
Set the size of the matrix.
Definition bcrsmatrix.hh:859
Dune::BCRSMatrix::operator=
BCRSMatrix & operator=(const BCRSMatrix &Mat)
assignment
Definition bcrsmatrix.hh:909
Dune::BDMatrix
A block-diagonal matrix.
Definition bdmatrix.hh:33
Dune::BDMatrix::field_type
typename Imp::BlockTraits< B >::field_type field_type
export the type representing the field
Definition bdmatrix.hh:39
Dune::BDMatrix::size_type
A::size_type size_type
implement row_type with compressed vector
Definition bdmatrix.hh:51
Dune::BDMatrix::BDMatrix
BDMatrix()
Default constructor.
Definition bdmatrix.hh:54
Dune::BDMatrix::BDMatrix
BDMatrix(std::initializer_list< B > const &list)
Construct from a std::initializer_list.
Definition bdmatrix.hh:72
Dune::BDMatrix::block_type
B block_type
export the type representing the components
Definition bdmatrix.hh:42
Dune::BDMatrix::solve
void solve(V &x, const V &rhs) const
Solve the system Ax=b in O(n) time.
Definition bdmatrix.hh:116
Dune::BDMatrix::allocator_type
A allocator_type
export the allocator type
Definition bdmatrix.hh:45
Dune::BDMatrix::BDMatrix
BDMatrix(int size)
Definition bdmatrix.hh:56
Dune::BDMatrix::operator=
BDMatrix & operator=(const BDMatrix &other)
assignment
Definition bdmatrix.hh:99
Dune::BDMatrix::setSize
void setSize(size_type size)
Resize the matrix. Invalidates the content!
Definition bdmatrix.hh:81
Dune::BDMatrix::invert
void invert()
Inverts the matrix.
Definition bdmatrix.hh:126
Dune::FieldTraits< BDMatrix< B, A > >::field_type
typename BDMatrix< B, A >::field_type field_type
Definition bdmatrix.hh:150
Dune::FieldTraits< BDMatrix< B, A > >::real_type
typename FieldTraits< field_type >::real_type real_type
Definition bdmatrix.hh:151