3 #ifndef DUNE_PDELAB_BACKEND_ISTL_VECTORHELPERS_HH 4 #define DUNE_PDELAB_BACKEND_ISTL_VECTORHELPERS_HH 9 #include <dune/common/typetraits.hh> 11 #include <dune/istl/bvector.hh> 22 #ifndef DOXYGEN // All of the following functions are mere implementation details 26 template<
typename CI,
typename Block>
27 typename Block::field_type&
28 access_vector_element(tags::field_vector_1, Block& b,
const CI& ci,
int i)
33 assert(i == -1 || i == 0);
37 template<
typename CI,
typename Block>
38 typename Block::field_type&
39 access_vector_element(tags::field_vector_n, Block& b,
const CI& ci,
int i)
45 template<
typename CI,
typename Block>
46 typename Block::field_type&
47 access_vector_element(tags::block_vector, Block& b,
const CI& ci,
int i)
49 return access_vector_element(
container_tag(b[ci[i]]),b[ci[i]],ci,i-1);
53 template<
typename CI,
typename Block>
54 const typename Block::field_type&
55 access_vector_element(tags::field_vector_1,
const Block& b,
const CI& ci,
int i)
60 assert(i == -1 || i == 0);
64 template<
typename CI,
typename Block>
65 const typename Block::field_type&
66 access_vector_element(tags::field_vector_n,
const Block& b,
const CI& ci,
int i)
72 template<
typename CI,
typename Block>
73 const typename Block::field_type&
74 access_vector_element(tags::block_vector,
const Block& b,
const CI& ci,
int i)
76 return access_vector_element(
container_tag(b[ci[i]]),b[ci[i]],ci,i-1);
80 template<
typename Vector>
81 void resize_vector(tags::block_vector,
Vector& v, std::size_t size,
bool copy_values)
83 v.resize(size,copy_values);
86 template<
typename Vector>
87 void resize_vector(tags::field_vector,
Vector& v, std::size_t size,
bool copy_values)
91 template<
typename DI,
typename CI,
typename Container>
92 void allocate_vector(tags::field_vector,
const OrderingBase<DI,CI>& ordering, Container& c)
96 template<
typename DI,
typename CI,
typename Container>
97 void allocate_vector(tags::block_vector,
const OrderingBase<DI,CI>& ordering, Container& c)
99 for (std::size_t i = 0; i < ordering.childOrderingCount(); ++i)
101 if (ordering.containerBlocked())
103 resize_vector(
container_tag(c[i]),c[i],ordering.childOrdering(i).blockCount(),
false);
104 allocate_vector(
container_tag(c[i]),ordering.childOrdering(i),c[i]);
107 allocate_vector(
container_tag(c),ordering.childOrdering(i),c);
111 template<
typename Ordering,
typename Container>
112 void dispatch_vector_allocation(
const Ordering& ordering, Container& c, HierarchicContainerAllocationTag tag)
117 template<
typename Ordering,
typename Container>
118 void dispatch_vector_allocation(
const Ordering& ordering, Container& c, FlatContainerAllocationTag tag)
120 resize_vector(
container_tag(c),c,ordering.blockCount(),
false);
130 struct vector_descriptor_helper
133 typedef typename Node::Traits::Backend type;
138 template<
typename E,
typename Backend>
139 struct leaf_vector_descriptor
143 "Dynamically blocked leaf spaces are not supported by this backend.");
146 static const bool support_no_blocking =
true;
153 static const bool support_cascaded_blocking =
157 static const std::size_t block_size =
159 ? Backend::Traits::block_size
166 static const std::size_t cumulative_block_size = Backend::Traits::block_size;
169 typedef E element_type;
172 typedef Dune::BlockVector<FieldVector<E,block_size> > vector_type;
177 template<
typename E,
typename Node,
typename Tag>
178 struct vector_descriptor_helper<E,Node,Tag, true>
180 typedef leaf_vector_descriptor<E,typename Node::Traits::Backend> type;
185 struct extract_vector_descriptor
188 template<
typename Node,
typename TreePath>
192 static const bool value =
true;
195 template<
typename Node,
typename TreePath>
199 typedef typename vector_descriptor_helper<E,Node,TypeTree::ImplementationTag<Node>>::type type;
205 template<
typename Sibling,
typename Child>
206 struct cascading_vector_descriptor
210 static const bool support_cascaded_blocking =
211 Sibling::support_cascaded_blocking &&
212 Child::support_cascaded_blocking;
217 static const bool support_no_blocking =
218 (Sibling::support_no_blocking &&
220 typename Sibling::vector_type,
221 typename Child::vector_type
225 static const std::size_t block_size =
226 support_no_blocking ? Sibling::block_size : 1;
229 typedef typename Sibling::element_type element_type;
232 static const std::size_t cumulative_block_size =
233 Sibling::cumulative_block_size + Child::cumulative_block_size;
236 typedef Dune::BlockVector<FieldVector<element_type,block_size> > vector_type;
243 template<
typename D1,
typename D2>
244 struct initial_reduction_switch
246 typedef cascading_vector_descriptor<D1,D2> type;
250 template<
typename D2>
251 struct initial_reduction_switch<void,D2>
257 struct combine_vector_descriptor_siblings
260 template<
typename D1,
typename D2>
262 :
public initial_reduction_switch<D1,D2>
268 template<
typename Child,
typename Backend>
269 struct parent_child_vector_descriptor_data
274 static const bool support_no_blocking =
275 Child::support_no_blocking;
279 static const bool support_cascaded_blocking =
280 Child::support_cascaded_blocking &&
286 Child::support_cascaded_blocking,
287 "invalid blocking structure.");
291 static const std::size_t block_size =
293 ? Child::cumulative_block_size
297 static const std::size_t cumulative_block_size =
298 Child::cumulative_block_size;
301 typedef typename Child::element_type element_type;
304 typedef typename Child::vector_type child_vector_type;
309 template<
typename Data, Blocking>
310 struct parent_child_vector_descriptor;
313 template<
typename Data>
314 struct parent_child_vector_descriptor<
320 static_assert(Data::support_no_blocking,
321 "Cannot combine incompatible child block structures without static blocking. " 322 "Did you want to apply static blocking at this level?");
325 typedef typename Data::child_vector_type vector_type;
329 template<
typename Data>
330 struct parent_child_vector_descriptor<
336 static_assert(Data::support_no_blocking,
337 "Incompatible child block structures detected, cannot perform dynamic blocking. " 338 "Did you want to apply static blocking at this level?");
341 typedef Dune::BlockVector<typename Data::child_vector_type> vector_type;
345 template<
typename Data>
346 struct parent_child_vector_descriptor<
353 typedef Dune::BlockVector<
355 typename Data::element_type,
362 struct combine_vector_descriptor_parent
365 template<
typename Child,
typename Backend>
370 :
public parent_child_vector_descriptor<parent_child_vector_descriptor_data<
373 Backend::Traits::block_type
382 struct vector_creation_policy
383 :
public TypeTree::TypeAccumulationPolicy<extract_vector_descriptor<E>,
384 combine_vector_descriptor_siblings,
386 combine_vector_descriptor_parent,
387 TypeTree::bottom_up_reduction>
397 #endif // DUNE_PDELAB_BACKEND_ISTL_VECTORHELPERS_HH
tags::container< T >::type container_tag(const T &)
Gets instance of container tag associated with T.
Definition: backend/istl/tags.hh:249
typename impl::BackendVectorSelector< GridFunctionSpace, FieldType >::Type Vector
alias of the return type of BackendVectorSelector
Definition: backend/interface.hh:106
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
Blocking
The type of blocking employed at this node in the function space tree.
Definition: istl/descriptors.hh:29
No blocking at this level.
Creates one macro block for each child space, each block is a BlockVector / BCRS matrix.
static const unsigned int value
Definition: gridfunctionspace/tags.hh:139
Create fixed size blocks that each group together a fixed number of DOFs from each child space...