3#ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_DATAHANDLEPROVIDER_HH
4#define DUNE_PDELAB_GRIDFUNCTIONSPACE_DATAHANDLEPROVIDER_HH
11#include <dune/typetree/visitor.hh>
13#include <dune/pdelab/ordering/utility.hh>
20 template<
typename EntityIndex>
21 struct get_size_for_entity
22 :
public TypeTree::TreeVisitor
23 ,
public TypeTree::DynamicTraversal
26 template<
typename Ordering,
typename TreePath>
27 void leaf(
const Ordering& ordering, TreePath tp)
29 _size += ordering.size(_entity_index);
32 get_size_for_entity(
const EntityIndex& entity_index)
34 , _entity_index(entity_index)
37 std::size_t size()
const
45 const EntityIndex& _entity_index;
50 template<
typename EntityIndex,
typename OffsetIterator>
51 struct get_leaf_offsets_for_entity
52 :
public TypeTree::TreeVisitor
53 ,
public TypeTree::DynamicTraversal
56 template<
typename Ordering,
typename TreePath>
57 void leaf(
const Ordering& ordering, TreePath tp)
59 *(++_oit) = ordering.size(_entity_index);
62 get_leaf_offsets_for_entity(
const EntityIndex& entity_index, OffsetIterator oit)
64 , _entity_index(entity_index)
68 OffsetIterator offsetIterator()
const
76 const EntityIndex& _entity_index;
81 template<
typename DOFIndex,
typename ContainerIndex, std::
size_t tree_depth,
bool map_dof_indices = false>
82 struct indices_for_entity
83 :
public TypeTree::TreeVisitor
84 ,
public TypeTree::DynamicTraversal
87 typedef std::size_t size_type;
88 typedef typename DOFIndex::EntityIndex EntityIndex;
89 typedef typename std::vector<ContainerIndex>::iterator CIIterator;
90 typedef typename std::conditional<
92 typename std::vector<DOFIndex>::iterator,
97 template<
typename Ordering,
typename Child,
typename TreePath,
typename ChildIndex>
98 void beforeChild(
const Ordering& ordering,
const Child&
child, TreePath tp, ChildIndex childIndex)
100 _stack.push(std::make_pair(_ci_it,_di_it));
103 template<
typename Ordering,
typename TreePath>
104 void leaf(
const Ordering& ordering, TreePath tp)
106 static_assert(tp.size()>=1,
"Cannot call method 'indices_for_entity::leaf' for empty tree path");
107 size_type size = ordering.extract_entity_indices(_entity_index,
119 template<
typename Ordering,
typename Child,
typename TreePath,
typename ChildIndex>
120 void afterChild(
const Ordering& ordering,
const Child&
child, TreePath tp, ChildIndex childIndex)
123 ordering.extract_entity_indices(_entity_index,
128 if (Ordering::consume_tree_index)
129 for (DIIterator it = _stack.top().second;
132 it->treeIndex().push_back(childIndex);
138 indices_for_entity(
const EntityIndex& entity_index,
140 DIIterator di_begin = DIIterator())
141 : _entity_index(entity_index)
150 CIIterator ci_end()
const
156 DIIterator di_end()
const
163 const EntityIndex& _entity_index;
187 template<
typename GFS>
188 class DataHandleProvider
193 typedef std::size_t size_type;
200 bool dataHandleContains (
int codim)
const
202 return gfs().ordering().contains(codim);
206 bool dataHandleFixedSize (
int codim)
const
208 return gfs().ordering().fixedSize(codim);
226 constexpr bool sendLeafSizes()
const
235 template<
typename Entity>
236 size_type dataHandleSize (
const Entity& e)
const
238 typedef typename GFS::Ordering Ordering;
240 typedef typename Ordering::Traits::DOFIndex::EntityIndex EntityIndex;
243 Ordering::Traits::DOFIndexAccessor::GeometryIndex::store(
246 gfs().gridView().indexSet().index(e)
249 get_size_for_entity<EntityIndex> get_size(ei);
252 return get_size.size();
255 template<
typename V,
typename EntityIndex>
256 void setup_dof_indices(V& v, size_type n,
const EntityIndex& ei, std::integral_constant<bool,true>)
const
259 for (
typename V::iterator it = v.begin(),
264 it->treeIndex().clear();
265 it->entityIndex() = ei;
269 template<
typename V,
typename EntityIndex>
270 void setup_dof_indices(V& v, size_type n,
const EntityIndex& ei, std::integral_constant<bool,false>)
const
274 typename V::iterator dof_indices_begin(V& v, std::integral_constant<bool,true>)
const
280 DummyDOFIndexIterator dof_indices_begin(V& v, std::integral_constant<bool,false>)
const
282 return DummyDOFIndexIterator();
286 template<
typename Entity,
typename ContainerIndex,
typename DOFIndex,
typename OffsetIterator,
bool map_dof_indices>
287 void dataHandleIndices (
const Entity& e,
288 std::vector<ContainerIndex>& container_indices,
289 std::vector<DOFIndex>& dof_indices,
291 std::integral_constant<bool,map_dof_indices> map_dof_indices_value
294 typedef typename GFS::Ordering Ordering;
296 static_assert((std::is_same<ContainerIndex,typename Ordering::Traits::ContainerIndex>::value),
297 "dataHandleContainerIndices() called with invalid ContainerIndex type.");
299 typedef typename Ordering::Traits::DOFIndex::EntityIndex EntityIndex;
302 Ordering::Traits::DOFIndexAccessor::GeometryIndex::store(
305 gfs().entitySet().indexSet().index(e)
308 get_leaf_offsets_for_entity<EntityIndex,OffsetIterator> get_offsets(ei,oit);
313 std::partial_sum(oit,end_oit,oit);
316 container_indices.resize(size);
318 for (
typename std::vector<ContainerIndex>::iterator it = container_indices.begin(),
319 endit = container_indices.end();
324 setup_dof_indices(dof_indices,size,ei,map_dof_indices_value);
330 auto es_visitor = impl::common_entity_set<typename GFS::Traits::EntitySet>{};
339 > extract_indices(ei,container_indices.begin(),dof_indices_begin(dof_indices,map_dof_indices_value));
346 const GFS& gfs()
const
348 return static_cast<const GFS&
>(*this);
Traits for type conversions and type information.
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:237
Dune namespace.
Definition: alignedallocator.hh:11
An stl-compliant random-access container which stores everything on the stack.
static const std::size_t leafCount
The number of leaf nodes in the TypeTree.
Definition: utility.hh:183
static const std::size_t depth
The depth of the TypeTree.
Definition: utility.hh:177