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>
22 template<
typename GFS,
typename GFSTraits>
23 class GridFunctionSpaceBase;
27 struct reset_root_space_flag
28 :
public TypeTree::DirectChildrenVisitor
29 ,
public TypeTree::DynamicTraversal
32 template<
typename GFS,
typename Child,
typename TreePath,
typename ChildIndex>
33 void afterChild(
const GFS& gfs, Child& child, TreePath, ChildIndex)
const
35 if (child._initialized && child._is_root_space)
37 DUNE_THROW(GridFunctionSpaceHierarchyError,
"initialized space cannot become part of larger GridFunctionSpace tree");
39 child._is_root_space =
false;
44 template<
typename size_type>
45 struct update_ordering_data;
50 template<
typename size_type>
51 class GridFunctionSpaceOrderingData
52 :
public PartitionInfoProvider
55 template<
typename,
typename>
56 friend class ::Dune::PDELab::GridFunctionSpaceBase;
59 friend struct update_ordering_data;
61 GridFunctionSpaceOrderingData()
66 , _is_root_space(true)
68 , _size_available(true)
72 size_type _block_count;
73 size_type _global_size;
74 size_type _max_local_size;
81 template<
typename size_type>
82 struct update_ordering_data
83 :
public TypeTree::TreeVisitor
84 ,
public TypeTree::DynamicTraversal
87 typedef GridFunctionSpaceOrderingData<size_type> Data;
89 template<
typename Ordering>
90 void update(
const Ordering& ordering,
bool is_root)
92 if (ordering._gfs_data)
94 Data& data = *ordering._gfs_data;
99 data._initialized =
true;
100 data._global_size = _global_size;
101 data._max_local_size = _max_local_size;
102 data._size_available = ordering.update_gfs_data_size(data._size,data._block_count);
103 data.setPartitionSet(ordering);
107 template<
typename Ordering,
typename TreePath>
108 void leaf(
const Ordering& ordering, TreePath tp)
110 update(ordering,tp.size() == 0);
113 template<
typename Ordering,
typename TreePath>
114 void post(
const Ordering& ordering, TreePath tp)
116 update(ordering,tp.size() == 0);
119 template<
typename Ordering>
120 explicit update_ordering_data(
const Ordering& ordering)
121 : _global_size(ordering.size())
122 , _max_local_size(ordering.maxLocalSize())
125 const size_type _global_size;
126 const size_type _max_local_size;
136 template<
typename GFS,
typename GFSTraits>
138 :
public impl::GridFunctionSpaceOrderingData<typename GFSTraits::SizeType>
141 friend struct impl::reset_root_space_flag;
147 template<
typename Backend_,
typename OrderingTag_>
150 , _ordering_tag(
std::forward<OrderingTag_>(ordering_tag))
152 TypeTree::applyToTree(gfs(),impl::reset_root_space_flag());
161 if (!_size_available)
164 "Size cannot be calculated at this point in the GFS tree.");
175 if (!_size_available)
178 "Block count cannot be calculated at this point in the GFS tree.");
199 return _max_local_size;
216 if (!gfs()._ordering)
217 gfs().create_ordering();
221 const std::string&
name()
const
243 return _ordering_tag;
248 return _ordering_tag;
253 return _is_root_space;
258 template<
typename Ordering>
266 TypeTree::applyToTree(ordering,impl::update_ordering_data<typename Traits::SizeType>(ordering));
271 typedef impl::GridFunctionSpaceOrderingData<typename GFSTraits::SizeType> BaseT;
275 return static_cast<GFS&
>(*this);
278 const GFS& gfs()
const
280 return static_cast<const GFS&
>(*this);
284 typename Traits::Backend _backend;
285 typename Traits::OrderingTag _ordering_tag;
288 using BaseT::_block_count;
289 using BaseT::_global_size;
290 using BaseT::_max_local_size;
291 using BaseT::_is_root_space;
292 using BaseT::_initialized;
293 using BaseT::_size_available;
301 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_GRIDFUNCTIONSPACEBASE_HH
Traits::SizeType globalSize() const
Definition: gridfunctionspacebase.hh:183
B Backend
Definition: powercompositegridfunctionspacebase.hh:53
Definition: gridfunctionspacebase.hh:137
void update()
Definition: gridfunctionspacebase.hh:212
const Traits::Backend & backend() const
Definition: gridfunctionspacebase.hh:236
Traits::SizeType maxLocalSize() const
get max dimension of shape function space
Definition: gridfunctionspacebase.hh:193
bool containsPartition(PartitionType partition) const
Returns whether this GridFunctionSpace contains entities with PartitionType partition.
Definition: gridfunctionspacebase.hh:203
void name(const std::string &name)
Definition: gridfunctionspacebase.hh:226
GridFunctionSpaceBase(Backend_ &&backend, OrderingTag_ &&ordering_tag)
Definition: gridfunctionspacebase.hh:148
O OrderingTag
Definition: powercompositegridfunctionspacebase.hh:58
std::size_t _size
Definition: datahandleprovider.hh:45
Traits::OrderingTag & orderingTag()
Definition: gridfunctionspacebase.hh:241
GFSTraits Traits
Definition: gridfunctionspacebase.hh:145
Definition: exceptions.hh:34
const std::string & name() const
Definition: gridfunctionspacebase.hh:221
Traits::Backend & backend()
Definition: gridfunctionspacebase.hh:231
bool isRootSpace() const
Definition: gridfunctionspacebase.hh:251
Definition: adaptivity.hh:27
B::size_type SizeType
short cut for size type exported by Backend
Definition: powercompositegridfunctionspacebase.hh:61
bool containsPartition(PartitionType partition) const
Returns whether this ordering contains entities with PartitionType partition.
Definition: partitioninfoprovider.hh:28
PDELab-specific exceptions.
Called a GridFunctionSpace method that requires initialization of the space.
Definition: exceptions.hh:28
const Traits::OrderingTag & orderingTag() const
Definition: gridfunctionspacebase.hh:246
Traits::SizeType size() const
Definition: gridfunctionspacebase.hh:155
void update(Ordering &ordering) const
Definition: gridfunctionspacebase.hh:259
Traits::SizeType blockCount() const
Definition: gridfunctionspacebase.hh:169