3#ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_GRIDFUNCTIONSPACEBASE_HH
4#define DUNE_PDELAB_GRIDFUNCTIONSPACE_GRIDFUNCTIONSPACEBASE_HH
6#include <dune/typetree/visitor.hh>
7#include <dune/typetree/traversal.hh>
21 template<
typename GFS,
typename GFSTraits>
22 class GridFunctionSpaceBase;
26 struct reset_root_space_flag
27 :
public TypeTree::DirectChildrenVisitor
28 ,
public TypeTree::DynamicTraversal
31 template<
typename GFS,
typename Child,
typename TreePath,
typename ChildIndex>
32 void afterChild(
const GFS& gfs,
Child&
child, TreePath, ChildIndex)
const
34 if (
child._initialized &&
child._is_root_space)
36 DUNE_THROW(GridFunctionSpaceHierarchyError,
"initialized space cannot become part of larger GridFunctionSpace tree");
38 child._is_root_space =
false;
43 template<
typename size_type>
44 struct update_ordering_data;
49 template<
typename size_type>
50 class GridFunctionSpaceOrderingData
53 template<
typename,
typename>
54 friend class ::Dune::PDELab::GridFunctionSpaceBase;
57 friend struct update_ordering_data;
59 GridFunctionSpaceOrderingData()
64 , _is_root_space(true)
66 , _size_available(true)
70 size_type _block_count;
71 size_type _global_size;
72 size_type _max_local_size;
79 template<
typename size_type>
80 struct update_ordering_data
81 :
public TypeTree::TreeVisitor
82 ,
public TypeTree::DynamicTraversal
85 typedef GridFunctionSpaceOrderingData<size_type> Data;
87 template<
typename Ordering>
88 void update(
const Ordering& ordering,
bool is_root)
90 if (ordering._gfs_data)
92 Data& data = *ordering._gfs_data;
97 data._initialized =
true;
98 data._global_size = _global_size;
99 data._max_local_size = _max_local_size;
100 data._size_available = ordering.update_gfs_data_size(data._size,data._block_count);
104 template<
typename Ordering,
typename TreePath>
105 void leaf(
const Ordering& ordering, TreePath tp)
107 update(ordering,tp.size() == 0);
110 template<
typename Ordering,
typename TreePath>
111 void post(
const Ordering& ordering, TreePath tp)
113 update(ordering,tp.size() == 0);
116 template<
typename Ordering>
117 explicit update_ordering_data(
const Ordering& ordering)
118 : _global_size(ordering.size())
119 , _max_local_size(ordering.maxLocalSize())
122 const size_type _global_size;
123 const size_type _max_local_size;
133 template<
typename GFS,
typename GFSTraits>
134 class GridFunctionSpaceBase
135 :
public impl::GridFunctionSpaceOrderingData<typename GFSTraits::SizeType>
138 friend struct impl::reset_root_space_flag;
142 typedef GFSTraits Traits;
144 template<
typename Backend_,
typename OrderingTag_>
145 GridFunctionSpaceBase(Backend_&& backend, OrderingTag_&& ordering_tag)
146 : _backend(
std::forward<Backend_>(backend))
147 , _ordering_tag(
std::forward<OrderingTag_>(ordering_tag))
152 typename Traits::SizeType size()
const
156 DUNE_THROW(UninitializedGridFunctionSpaceError,
"space is not initialized");
158 if (!_size_available)
161 "Size cannot be calculated at this point in the GFS tree.");
166 typename Traits::SizeType blockCount()
const
170 DUNE_THROW(UninitializedGridFunctionSpaceError,
"space is not initialized");
172 if (!_size_available)
175 "Block count cannot be calculated at this point in the GFS tree.");
180 typename Traits::SizeType globalSize()
const
184 DUNE_THROW(UninitializedGridFunctionSpaceError,
"space is not initialized");
196 return _max_local_size;
207 auto entity_set = gfs().entitySet();
208 entity_set.update(force);
211 if (!gfs()._ordering)
212 gfs().create_ordering();
213 update(*gfs()._ordering);
216 const std::string& name()
const
221 void name(
const std::string& name)
226 typename Traits::Backend& backend()
231 const typename Traits::Backend& backend()
const
236 typename Traits::OrderingTag& orderingTag()
238 return _ordering_tag;
241 const typename Traits::OrderingTag& orderingTag()
const
243 return _ordering_tag;
246 bool isRootSpace()
const
248 return _is_root_space;
253 template<
typename Ordering>
254 void update(Ordering& ordering)
const
258 DUNE_THROW(GridFunctionSpaceHierarchyError,
"update() may only be called on the root of the function space hierarchy");
266 typedef impl::GridFunctionSpaceOrderingData<typename GFSTraits::SizeType> BaseT;
270 return static_cast<GFS&
>(*this);
273 const GFS& gfs()
const
275 return static_cast<const GFS&
>(*this);
279 typename Traits::Backend _backend;
280 typename Traits::OrderingTag _ordering_tag;
283 using BaseT::_block_count;
284 using BaseT::_global_size;
285 using BaseT::_max_local_size;
286 using BaseT::_is_root_space;
287 using BaseT::_initialized;
288 using BaseT::_size_available;
Called a GridFunctionSpace method that requires initialization of the space.
Definition: exceptions.hh:30
PDELab-specific exceptions.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Traits::SizeType maxLocalSize() const
get max dimension of shape function space
Definition: gridfunctionspacebase.hh:190
void update(bool force=false)
Update the indexing information of the GridFunctionSpace.
Definition: gridfunctionspacebase.hh:205
void applyToTree(Tree &&tree, Visitor &&visitor)
Apply visitor to TypeTree.
Definition: traversal.hh:213
Dune namespace.
Definition: alignedallocator.hh:14