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>
135 :
public impl::GridFunctionSpaceOrderingData<typename GFSTraits::SizeType>
138 friend struct impl::reset_root_space_flag;
144 template<
typename Backend_,
typename OrderingTag_>
146 : _backend(
std::forward<Backend_>(backend))
147 , _ordering_tag(
std::forward<OrderingTag_>(ordering_tag))
149 TypeTree::applyToTree(gfs(),impl::reset_root_space_flag());
158 if (!_size_available)
161 "Size cannot be calculated at this point in the GFS tree.");
172 if (!_size_available)
175 "Block count cannot be calculated at this point in the GFS tree.");
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)
238 return _ordering_tag;
243 return _ordering_tag;
248 return _is_root_space;
253 template<
typename Ordering>
261 TypeTree::applyToTree(ordering,impl::update_ordering_data<typename Traits::SizeType>(ordering));
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);
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;
296 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_GRIDFUNCTIONSPACEBASE_HH Traits::Backend & backend()
Definition: gridfunctionspacebase.hh:226
void name(const std::string &name)
Definition: gridfunctionspacebase.hh:221
O OrderingTag
Definition: powercompositegridfunctionspacebase.hh:60
const Traits::Backend & backend() const
Definition: gridfunctionspacebase.hh:231
GFSTraits Traits
Definition: gridfunctionspacebase.hh:142
Traits::SizeType maxLocalSize() const
get max dimension of shape function space
Definition: gridfunctionspacebase.hh:190
Traits::SizeType globalSize() const
Definition: gridfunctionspacebase.hh:180
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
const std::string & name() const
Definition: gridfunctionspacebase.hh:216
Definition: gridfunctionspacebase.hh:134
PDELab-specific exceptions.
void update(Ordering &ordering) const
Definition: gridfunctionspacebase.hh:254
bool isRootSpace() const
Definition: gridfunctionspacebase.hh:246
B Backend
Definition: powercompositegridfunctionspacebase.hh:55
Called a GridFunctionSpace method that requires initialization of the space.
Definition: exceptions.hh:28
void update(bool force=false)
Update the indexing information of the GridFunctionSpace.
Definition: gridfunctionspacebase.hh:205
Traits::SizeType size() const
Definition: gridfunctionspacebase.hh:152
Traits::SizeType blockCount() const
Definition: gridfunctionspacebase.hh:166
GridFunctionSpaceBase(Backend_ &&backend, OrderingTag_ &&ordering_tag)
Definition: gridfunctionspacebase.hh:145
Definition: exceptions.hh:34
const Traits::OrderingTag & orderingTag() const
Definition: gridfunctionspacebase.hh:241
B::size_type SizeType
short cut for size type exported by Backend
Definition: powercompositegridfunctionspacebase.hh:63
Traits::OrderingTag & orderingTag()
Definition: gridfunctionspacebase.hh:236