7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_HIERARCHICVECTORWRAPPER_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_HIERARCHICVECTORWRAPPER_HH
10#ifndef DUNE_FUNCTIONS_HIERARCHICVECTORWRAPPER_TEST_NO_DEPRECATION
11#warning The header dune/functions/functionspacebases/hierarchicvectorwrapper.hh is deprecated and will be removed after release 2.10.
14#include <dune/common/concept.hh>
15#include <dune/common/hybridutilities.hh>
16#include <dune/common/indices.hh>
18#include <dune/functions/common/indexaccess.hh>
19#include <dune/functions/common/utility.hh>
20#include <dune/functions/common/type_traits.hh>
21#include <dune/functions/functionspacebases/concepts.hh>
34 template<
class V,
class MultiIndex>
35 struct CoefficientType
37 template<
class E, std::
size_t size>
38 struct DefaultCoefficientTypeHelper
40 using E0 =
decltype(std::declval<E>()[Dune::Indices::_0]);
41 using type =
typename DefaultCoefficientTypeHelper<E0, size-1>::type;
45 struct DefaultCoefficientTypeHelper<E, 0>
50 using type =
typename DefaultCoefficientTypeHelper<V, StaticSizeOrZero<MultiIndex>::value>::type;
58 struct DeducedCoefficientTag {};
86template<
class V,
class CO=Imp::DeducedCoefficientTag>
88[[deprecated(
"HierarchicVectorWrapper is deprecated and will be removed after release 2.10.")]]
91 template<
class MultiIndex>
92 using Coefficient = std::conditional_t< std::is_same_v<Imp::DeducedCoefficientTag,CO> and HasStaticSize_v<MultiIndex>,
93 typename Imp::CoefficientType<V, MultiIndex>::type,
98 using size_type = std::size_t;
100 template<
class C,
class SizeProvider,
101 std::enable_if_t< not models<Concept::HasResize, C>(),
int> = 0,
102 std::enable_if_t< not models<Concept::HasSizeMethod, C>(),
int> = 0>
103 static void resizeHelper(C& c,
const SizeProvider& sizeProvider,
typename SizeProvider::SizePrefix prefix)
105 auto size = sizeProvider.size(prefix);
107 DUNE_THROW(RangeError,
"Can't resize scalar vector entry v[" << prefix <<
"] to size(" << prefix <<
")=" << size);
110 struct StaticResizeHelper
112 template<
class I,
class C,
class SizeProv
ider>
113 static void apply(I&& i, C& c,
const SizeProvider& sizeProvider,
typename SizeProvider::SizePrefix prefix)
116 resizeHelper(c[i], sizeProvider, prefix);
120 template<
class C,
class SizeProvider,
121 std::enable_if_t< not models<Concept::HasResize, C>(),
int> = 0,
122 std::enable_if_t< models<Concept::HasSizeMethod, C>(),
int> = 0>
123 static void resizeHelper(C& c,
const SizeProvider& sizeProvider,
typename SizeProvider::SizePrefix prefix)
125 auto size = sizeProvider.size(prefix);
129 if (c.size() != size)
130 DUNE_THROW(RangeError,
"Can't resize statically sized vector entry v[" << prefix <<
"] of size " << c.size() <<
" to size(" << prefix <<
")=" << size);
132 using namespace Dune::Hybrid;
134 forEach(integralRange(Hybrid::size(c)), [&](
auto&& i) {
135 StaticResizeHelper::apply(i, c, sizeProvider, prefix);
139 template<
class C,
class SizeProvider,
140 std::enable_if_t< models<Concept::HasResize, C>(),
int> = 0>
141 static void resizeHelper(C& c,
const SizeProvider& sizeProvider,
typename SizeProvider::SizePrefix prefix)
143 auto size = sizeProvider.size(prefix);
147 DUNE_THROW(RangeError,
"Can't resize dynamically sized vector entry v[" << prefix <<
"]. Its size is 0 but the target size is unknown due to size(" << prefix <<
")=0.");
154 for(std::size_t i=0; i<size; ++i)
157 resizeHelper(c[i], sizeProvider, prefix);
167 template<
class MultiIndex>
168 using Entry = Coefficient<MultiIndex>;
174 template<
class SizeProv
ider>
175 void resize(
const SizeProvider& sizeProvider)
177 typename SizeProvider::SizePrefix prefix;
179 resizeHelper(*vector_, sizeProvider, prefix);
182 template<
class MultiIndex>
183 const Entry<MultiIndex>& operator[](
const MultiIndex& index)
const
185 static_assert(not std::is_same_v<Imp::DeducedCoefficientTag,Entry<MultiIndex>>,
"Coefficient type for HierarchicVectorWrapper and given multi-index type cannot be determined automatically!");
186 return hybridMultiIndexAccess<const Entry<MultiIndex>&>(*vector_, index);
189 template<
class MultiIndex>
190 Entry<MultiIndex>& operator[](
const MultiIndex& index)
192 static_assert(not std::is_same_v<Imp::DeducedCoefficientTag,Entry<MultiIndex>>,
"Coefficient type for HierarchicVectorWrapper and given multi-index type cannot be determined automatically!");
193 return hybridMultiIndexAccess<Entry<MultiIndex>&>(*vector_, index);
196 template<
class MultiIndex>
197 const Entry<MultiIndex>& operator()(
const MultiIndex& index)
const
199 static_assert(not std::is_same_v<Imp::DeducedCoefficientTag,Entry<MultiIndex>>,
"Coefficient type for HierarchicVectorWrapper and given multi-index type cannot be determined automatically!");
200 return (*
this)[index];
203 template<
class MultiIndex>
204 Entry<MultiIndex>& operator()(
const MultiIndex& index)
206 static_assert(not std::is_same_v<Imp::DeducedCoefficientTag,Entry<MultiIndex>>,
"Coefficient type for HierarchicVectorWrapper and given multi-index type cannot be determined automatically!");
207 return (*
this)[index];
210 const Vector& vector()
const
241template<
class MultiIndex,
class V,
242 std::enable_if_t< models<Concept::HasIndexAccess, V, MultiIndex>(),
int> = 0>
243V& makeHierarchicVectorForMultiIndex(V& v)
253template<
class MultiIndex,
class V,
254 std::enable_if_t< not models<Concept::HasIndexAccess, V, MultiIndex>(),
int> = 0>
255HierarchicVectorWrapper< V > makeHierarchicVectorForMultiIndex(V& v)
257 return HierarchicVectorWrapper<V>(v);
A wrapper providing multiindex access to vector entries.
Definition: hierarchicvectorwrapper.hh:90
Definition: polynomial.hh:17