2#ifndef DUNE_PDELAB_BACKEND_ISTL_BCRSMATRIX_HH
3#define DUNE_PDELAB_BACKEND_ISTL_BCRSMATRIX_HH
7#if DUNE_VERSION_GTE(ISTL,2,8)
11#include <dune/pdelab/backend/common/uncachedmatrixview.hh>
12#include <dune/pdelab/backend/common/aliasedmatrixview.hh>
13#include <dune/pdelab/backend/istl/matrixhelpers.hh>
14#include <dune/pdelab/backend/istl/descriptors.hh>
21 template<
typename GFSV,
typename GFSU,
typename C,
typename Stats>
23 :
public Backend::impl::Wrapper<C>
26 friend Backend::impl::Wrapper<C>;
30 typedef typename C::field_type ElementType;
31 typedef ElementType E;
33 typedef typename C::field_type field_type;
34 typedef typename C::block_type block_type;
35 typedef typename C::size_type size_type;
37 typedef GFSU TrialGridFunctionSpace;
38 typedef GFSV TestGridFunctionSpace;
40 typedef typename GFSV::Ordering::Traits::ContainerIndex RowIndex;
41 typedef typename GFSU::Ordering::Traits::ContainerIndex ColIndex;
43 typedef typename ISTL::build_pattern_type<C,GFSV,GFSU,typename GFSV::Ordering::ContainerAllocationTag>::type Pattern;
45 typedef Stats PatternStatistics;
53 typedef typename std::conditional<
54#if DUNE_VERSION_LT(DUNE_ISTL,2,8)
57 (blockLevel<C>() > 2),
59 std::vector<PatternStatistics>,
61 >::type StatisticsReturnType;
65 template<
typename RowCache,
typename ColCache>
66 using LocalView = UncachedMatrixView<BCRSMatrix,RowCache,ColCache>;
68 template<
typename RowCache,
typename ColCache>
69 using ConstLocalView = ConstUncachedMatrixView<const BCRSMatrix,RowCache,ColCache>;
71 template<
typename RowCache,
typename ColCache>
72 using AliasedLocalView = AliasedMatrixView<BCRSMatrix,RowCache,ColCache>;
74 template<
typename RowCache,
typename ColCache>
75 using ConstAliasedLocalView = ConstAliasedMatrixView<const BCRSMatrix,RowCache,ColCache>;
78 explicit BCRSMatrix (
const GO& go)
79 : _container(
std::make_shared<Container>())
81 _stats = go.matrixBackend().buildPattern(go,*
this);
94 BCRSMatrix (
const GO& go, Container& container)
97 _stats = go.matrixBackend().buildPattern(go,*
this);
100 template<
typename GO>
101 BCRSMatrix (
const GO& go,
const E& e)
102 : _container(
std::make_shared<Container>())
104 _stats = go.matrixBackend().buildPattern(go,*
this);
109 explicit BCRSMatrix (Backend::unattached_container = Backend::unattached_container())
113 explicit BCRSMatrix (Backend::attached_container)
114 : _container(
std::make_shared<Container>())
117 BCRSMatrix(
const BCRSMatrix& rhs)
118 : _container(
std::make_shared<Container>(*(rhs._container)))
121 BCRSMatrix& operator=(
const BCRSMatrix& rhs)
128 (*_container) = (*(rhs._container));
132 _container = std::make_shared<Container>(*(rhs._container));
138 const StatisticsReturnType& patternStatistics()
const
140#if DUNE_VERSION_LT(DUNE_ISTL,2,8)
141 return patternStatistics(std::integral_constant<
bool,(C::blocklevel > 2)>());
143 return patternStatistics(std::integral_constant<
bool,(blockLevel<C>() > 2)>());
151 const PatternStatistics& patternStatistics(std::false_type multiple)
const
154 DUNE_THROW(InvalidStateException,
"no pattern statistics available");
158 const std::vector<PatternStatistics>& patternStatistics(std::true_type multiple)
const
161 DUNE_THROW(InvalidStateException,
"no pattern statistics available");
175 void attach(std::shared_ptr<Container> container)
177 _container = container;
180 bool attached()
const
182 return bool(_container);
185 const std::shared_ptr<Container>& storage()
const
192 return _container->N();
197 return _container->M();
200 BCRSMatrix& operator= (
const E& e)
206 BCRSMatrix& operator*= (
const E& e)
212 E& operator()(
const RowIndex& ri,
const ColIndex& ci)
214 return ISTL::access_matrix_element(ISTL::container_tag(*_container),*_container,ri,ci,ri.size()-1,ci.size()-1);
217 const E& operator()(
const RowIndex& ri,
const ColIndex& ci)
const
219 return ISTL::access_matrix_element(ISTL::container_tag(*_container),*_container,ri,ci,ri.size()-1,ci.size()-1);
224 const Container& native()
const
236 template<
typename RowCache,
typename ColCache>
237 value_type* data(
const RowCache& row_cache,
const ColCache& col_cache)
239 return &((*this)(row_cache.containerIndex(0),col_cache.containerIndex(0)));
242 template<
typename RowCache,
typename ColCache>
243 const value_type* data(
const RowCache& row_cache,
const ColCache& col_cache)
const
245 return &((*this)(row_cache.containerIndex(0),col_cache.containerIndex(0)));
254 void clear_row(
const RowIndex& ri,
const E& diagonal_entry)
256 ISTL::clear_matrix_row(ISTL::container_tag(*_container),*_container,ri,ri.size()-1);
257 ISTL::write_matrix_element_if_exists(diagonal_entry,ISTL::container_tag(*_container),*_container,ri,ri,ri.size()-1,ri.size()-1);
260 void clear_row_block(
const RowIndex& ri,
const E& diagonal_entry)
262 ISTL::clear_matrix_row_block(ISTL::container_tag(*_container),*_container,ri,ri.size()-1);
263 ISTL::write_matrix_element_if_exists_to_block(diagonal_entry,ISTL::container_tag(*_container),*_container,ri,ri,ri.size()-1,ri.size()-1);
268 std::shared_ptr<Container> _container;
269 std::vector<PatternStatistics> _stats;
Helper functions for determining the vector/matrix block level.
Traits for type conversions and type information.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
This file implements several utilities related to std::shared_ptr.