3 #ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_HIERARCHICVECTORWRAPPER_HH 4 #define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_HIERARCHICVECTORWRAPPER_HH 6 #include <dune/common/concept.hh> 7 #include <dune/common/hybridutilities.hh> 9 #include <dune/typetree/utility.hh> 27 template<
class V,
class MultiIndex>
28 struct CoefficientType
30 template<
class E, std::
size_t size>
31 struct DefaultCoefficientTypeHelper
33 using E0 = decltype(std::declval<E>()[Dune::TypeTree::Indices::_0]);
34 using type =
typename DefaultCoefficientTypeHelper<E0, size-1>::type;
38 struct DefaultCoefficientTypeHelper<E, 0>
44 typename std::enable_if<HasStaticSize<MI>::value,
int>::type = 0>
45 static constexpr std::size_t getStaticSizeOrZero()
47 return StaticSize<MI>::value;
51 typename std::enable_if<not HasStaticSize<MI>::value,
int>::type = 0>
52 static constexpr std::size_t getStaticSizeOrZero()
57 using type =
typename DefaultCoefficientTypeHelper<V, getStaticSizeOrZero<MultiIndex>()>::type;
84 template<
class V,
class CO=
void>
87 template<
class MultiIndex>
89 typename Imp::CoefficientType<V, MultiIndex>::type,
94 using size_type = std::size_t;
96 template<
class C,
class SizeProvider,
97 typename std::enable_if< not models<Concept::HasResize, C>(),
int>::type = 0,
98 typename std::enable_if< not models<Concept::HasSizeMethod, C>(),
int>::type = 0>
99 static void resizeHelper(C& c,
const SizeProvider& sizeProvider,
typename SizeProvider::SizePrefix prefix)
101 auto size = sizeProvider.size(prefix);
103 DUNE_THROW(RangeError,
"Can't resize scalar vector entry v[" << prefix <<
"] to size(" << prefix <<
")=" << size);
106 struct StaticResizeHelper
108 template<
class I,
class C,
class SizeProv
ider>
109 static void apply(I&& i, C& c,
const SizeProvider& sizeProvider,
typename SizeProvider::SizePrefix prefix)
112 resizeHelper(c[i], sizeProvider, prefix);
116 template<
class C,
class SizeProvider,
117 typename std::enable_if< not models<Concept::HasResize, C>(),
int>::type = 0,
118 typename std::enable_if< models<Concept::HasSizeMethod, C>(),
int>::type = 0>
119 static void resizeHelper(C& c,
const SizeProvider& sizeProvider,
typename SizeProvider::SizePrefix prefix)
121 auto size = sizeProvider.size(prefix);
125 if (c.size() != size)
126 DUNE_THROW(RangeError,
"Can't resize statically sized vector entry v[" << prefix <<
"] of size " << c.size() <<
" to size(" << prefix <<
")=" << size);
128 using namespace Dune::Hybrid;
130 forEach(integralRange(Hybrid::size(c)), [&](
auto&& i) {
131 StaticResizeHelper::apply(i, c, sizeProvider, prefix);
135 template<
class C,
class SizeProvider,
136 typename std::enable_if< models<Concept::HasResize, C>(),
int>::type = 0>
137 static void resizeHelper(C& c,
const SizeProvider& sizeProvider,
typename SizeProvider::SizePrefix prefix)
139 auto size = sizeProvider.size(prefix);
143 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.");
150 for(std::size_t i=0; i<size; ++i)
153 resizeHelper(c[i], sizeProvider, prefix);
163 template<
class MultiIndex>
164 using Entry = Coefficient<MultiIndex>;
170 template<
class SizeProv
ider>
171 void resize(
const SizeProvider& sizeProvider)
173 typename SizeProvider::SizePrefix prefix;
175 resizeHelper(*vector_, sizeProvider, prefix);
178 template<
class MultiIndex>
181 return hybridMultiIndexAccess<const Entry<MultiIndex>&>(*vector_, index);
184 template<
class MultiIndex>
187 return hybridMultiIndexAccess<Entry<MultiIndex>&>(*vector_, index);
190 template<
class MultiIndex>
193 return (*
this)[index];
196 template<
class MultiIndex>
199 return (*
this)[index];
228 template<
class MultiIndex,
class V,
229 typename std::enable_if< models<Concept::HasIndexAccess, V, MultiIndex>(),
int>::type = 0>
237 template<
class MultiIndex,
class V,
238 typename std::enable_if< not models<Concept::HasIndexAccess, V, MultiIndex>(),
int>::type = 0>
250 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_HIERARCHICVECTORWRAPPER_HH Check if type is a statically sized container.
Definition: type_traits.hh:81
HierarchicVectorWrapper(Vector &vector)
Definition: hierarchicvectorwrapper.hh:166
HierarchicVectorWrapper< V > hierarchicVector(V &v)
Definition: hierarchicvectorwrapper.hh:221
const Entry< MultiIndex > & operator()(const MultiIndex &index) const
Definition: hierarchicvectorwrapper.hh:191
Coefficient< MultiIndex > Entry
Definition: hierarchicvectorwrapper.hh:164
A wrapper providing multiindex access to vector entries.
Definition: hierarchicvectorwrapper.hh:85
V Vector
Definition: hierarchicvectorwrapper.hh:161
V & makeHierarchicVectorForMultiIndex(V &v)
Definition: hierarchicvectorwrapper.hh:230
const Entry< MultiIndex > & operator[](const MultiIndex &index) const
Definition: hierarchicvectorwrapper.hh:179
Definition: polynomial.hh:7
Entry< MultiIndex > & operator[](const MultiIndex &index)
Definition: hierarchicvectorwrapper.hh:185
Vector & vector()
Definition: hierarchicvectorwrapper.hh:207
Entry< MultiIndex > & operator()(const MultiIndex &index)
Definition: hierarchicvectorwrapper.hh:197
void resize(const SizeProvider &sizeProvider)
Definition: hierarchicvectorwrapper.hh:171
const Vector & vector() const
Definition: hierarchicvectorwrapper.hh:202