3 #ifndef DUNE_PDELAB_BACKEND_ISTL_VECTORHELPERS_HH
4 #define DUNE_PDELAB_BACKEND_ISTL_VECTORHELPERS_HH
6 #include <dune/common/typetraits.hh>
8 #include <dune/istl/bvector.hh>
19 #ifndef DOXYGEN // All of the following functions are mere implementation details
23 template<
typename CI,
typename Block>
24 typename Block::field_type&
25 access_vector_element(tags::field_vector_1, Block& b,
const CI& ci,
int i)
30 assert(i == -1 || i == 0);
34 template<
typename CI,
typename Block>
35 typename Block::field_type&
36 access_vector_element(tags::field_vector_n, Block& b,
const CI& ci,
int i)
42 template<
typename CI,
typename Block>
43 typename Block::field_type&
44 access_vector_element(tags::block_vector, Block& b,
const CI& ci,
int i)
46 return access_vector_element(
container_tag(b[ci[i]]),b[ci[i]],ci,i-1);
50 template<
typename CI,
typename Block>
51 const typename Block::field_type&
52 access_vector_element(tags::field_vector_1,
const Block& b,
const CI& ci,
int i)
57 assert(i == -1 || i == 0);
61 template<
typename CI,
typename Block>
62 const typename Block::field_type&
63 access_vector_element(tags::field_vector_n,
const Block& b,
const CI& ci,
int i)
69 template<
typename CI,
typename Block>
70 const typename Block::field_type&
71 access_vector_element(tags::block_vector,
const Block& b,
const CI& ci,
int i)
73 return access_vector_element(
container_tag(b[ci[i]]),b[ci[i]],ci,i-1);
77 template<
typename Vector>
78 void resize_vector(tags::block_vector, Vector& v, std::size_t size,
bool copy_values)
80 v.resize(size,copy_values);
83 template<
typename Vector>
84 void resize_vector(tags::field_vector, Vector& v, std::size_t size,
bool copy_values)
88 template<
typename DI,
typename CI,
typename Container>
89 void allocate_vector(tags::field_vector,
const OrderingBase<DI,CI>& ordering, Container& c)
93 template<
typename DI,
typename CI,
typename Container>
94 void allocate_vector(tags::block_vector,
const OrderingBase<DI,CI>& ordering, Container& c)
96 for (std::size_t i = 0; i < ordering.childOrderingCount(); ++i)
98 if (ordering.containerBlocked())
100 resize_vector(
container_tag(c[i]),c[i],ordering.childOrdering(i).blockCount(),
false);
101 allocate_vector(
container_tag(c[i]),ordering.childOrdering(i),c[i]);
104 allocate_vector(
container_tag(c),ordering.childOrdering(i),c);
108 template<
typename Ordering,
typename Container>
109 void dispatch_vector_allocation(
const Ordering& ordering, Container& c, HierarchicContainerAllocationTag tag)
114 template<
typename Ordering,
typename Container>
115 void dispatch_vector_allocation(
const Ordering& ordering, Container& c, FlatContainerAllocationTag tag)
117 resize_vector(
container_tag(c),c,ordering.blockCount(),
false);
127 struct vector_descriptor_helper
130 typedef typename Node::Traits::Backend type;
135 template<
typename E,
typename Backend>
136 struct leaf_vector_descriptor
140 "Dynamically blocked leaf spaces are not supported by this backend.");
143 static const bool support_no_blocking =
true;
150 static const bool support_cascaded_blocking =
154 static const std::size_t block_size =
156 ? Backend::Traits::block_size
163 static const std::size_t cumulative_block_size = Backend::Traits::block_size;
166 typedef E element_type;
169 typedef BlockVector<FieldVector<E,block_size> > vector_type;
174 template<
typename E,
typename Node,
typename Tag>
175 struct vector_descriptor_helper<E,Node,Tag, true>
177 typedef leaf_vector_descriptor<E,typename Node::Traits::Backend> type;
182 struct extract_vector_descriptor
185 template<
typename Node,
typename TreePath>
189 static const bool value =
true;
192 template<
typename Node,
typename TreePath>
196 typedef typename vector_descriptor_helper<E,Node,typename Node::ImplementationTag>::type type;
202 template<
typename Sibling,
typename Child>
203 struct cascading_vector_descriptor
207 static const bool support_cascaded_blocking =
208 Sibling::support_cascaded_blocking &&
209 Child::support_cascaded_blocking;
214 static const bool support_no_blocking =
215 (Sibling::support_no_blocking &&
217 typename Sibling::vector_type,
218 typename Child::vector_type
222 static const std::size_t block_size =
223 support_no_blocking ? Sibling::block_size : 1;
226 typedef typename Sibling::element_type element_type;
229 static const std::size_t cumulative_block_size =
230 Sibling::cumulative_block_size + Child::cumulative_block_size;
233 typedef BlockVector<FieldVector<element_type,block_size> > vector_type;
240 template<
typename D1,
typename D2>
241 struct initial_reduction_switch
243 typedef cascading_vector_descriptor<D1,D2> type;
247 template<
typename D2>
248 struct initial_reduction_switch<void,D2>
254 struct combine_vector_descriptor_siblings
257 template<
typename D1,
typename D2>
259 :
public initial_reduction_switch<D1,D2>
265 template<
typename Child,
typename Backend>
266 struct parent_child_vector_descriptor_data
271 static const bool support_no_blocking =
272 Child::support_no_blocking;
276 static const bool support_cascaded_blocking =
277 Child::support_cascaded_blocking &&
283 Child::support_cascaded_blocking,
284 "invalid blocking structure.");
288 static const std::size_t block_size =
290 ? Child::cumulative_block_size
294 static const std::size_t cumulative_block_size =
295 Child::cumulative_block_size;
298 typedef typename Child::element_type element_type;
301 typedef typename Child::vector_type child_vector_type;
306 template<
typename Data, ISTLParameters::Blocking>
307 struct parent_child_vector_descriptor;
310 template<
typename Data>
311 struct parent_child_vector_descriptor<
317 dune_static_assert(Data::support_no_blocking,
318 "Cannot combine incompatible child block structures without static blocking. "
319 "Did you want to apply static blocking at this level?");
322 typedef typename Data::child_vector_type vector_type;
326 template<
typename Data>
327 struct parent_child_vector_descriptor<
333 dune_static_assert(Data::support_no_blocking,
334 "Incompatible child block structures detected, cannot perform dynamic blocking. "
335 "Did you want to apply static blocking at this level?");
338 typedef BlockVector<typename Data::child_vector_type> vector_type;
342 template<
typename Data>
343 struct parent_child_vector_descriptor<
352 typename Data::element_type,
359 struct combine_vector_descriptor_parent
362 template<
typename Child,
typename Backend>
367 :
public parent_child_vector_descriptor<parent_child_vector_descriptor_data<
370 Backend::Traits::block_type
379 struct vector_creation_policy
380 :
public TypeTree::TypeAccumulationPolicy<extract_vector_descriptor<E>,
381 combine_vector_descriptor_siblings,
383 combine_vector_descriptor_parent,
384 TypeTree::bottom_up_reduction>
394 #endif // DUNE_PDELAB_BACKEND_ISTL_VECTORHELPERS_HH
Definition: istl/descriptors.hh:21
Definition: istl/descriptors.hh:19
Definition: istl/descriptors.hh:20
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
tags::container< T >::type container_tag(const T &)
Gets instance of container tag associated with T.
Definition: backend/istl/tags.hh:247