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 #if HAVE_RVALUE_REFERENCES
149 template<
typename Backend_,
typename OrderingTag_>
151 : _backend(std::forward<Backend_>(
backend))
152 , _ordering_tag(std::forward<OrderingTag_>(ordering_tag))
154 TypeTree::applyToTree(gfs(),impl::reset_root_space_flag());
161 , _ordering_tag(ordering_tag)
164 , _is_root_space(true)
165 , _initialized(false)
167 TypeTree::applyToTree(gfs(),impl::reset_root_space_flag());
178 if (!_size_available)
181 "Size cannot be calculated at this point in the GFS tree.");
192 if (!_size_available)
195 "Block count cannot be calculated at this point in the GFS tree.");
216 return _max_local_size;
233 if (!gfs()._ordering)
234 gfs().create_ordering();
238 const std::string&
name()
const
260 return _ordering_tag;
265 return _ordering_tag;
270 return _is_root_space;
275 template<
typename Ordering>
283 TypeTree::applyToTree(ordering,impl::update_ordering_data<typename Traits::SizeType>(ordering));
288 typedef impl::GridFunctionSpaceOrderingData<typename GFSTraits::SizeType> BaseT;
292 return static_cast<GFS&
>(*this);
295 const GFS& gfs()
const
297 return static_cast<const GFS&
>(*this);
301 typename Traits::Backend _backend;
302 typename Traits::OrderingTag _ordering_tag;
305 using BaseT::_block_count;
306 using BaseT::_global_size;
307 using BaseT::_max_local_size;
308 using BaseT::_is_root_space;
309 using BaseT::_initialized;
310 using BaseT::_size_available;
318 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_GRIDFUNCTIONSPACEBASE_HH
GFSTraits Traits
Definition: gridfunctionspacebase.hh:145
void name(const std::string &name)
Definition: gridfunctionspacebase.hh:243
B::size_type SizeType
short cut for size type exported by Backend
Definition: powercompositegridfunctionspacebase.hh:60
bool containsPartition(PartitionType partition) const
Returns whether this GridFunctionSpace contains entities with PartitionType partition.
Definition: gridfunctionspacebase.hh:220
const std::string & name() const
Definition: gridfunctionspacebase.hh:238
PDELab-specific exceptions.
Traits::SizeType size() const
Definition: gridfunctionspacebase.hh:172
Definition: gridfunctionspacebase.hh:137
const Traits::Backend & backend() const
Definition: gridfunctionspacebase.hh:253
bool isRootSpace() const
Definition: gridfunctionspacebase.hh:268
Called a GridFunctionSpace method that requires initialization of the space.
Definition: exceptions.hh:28
B Backend
Definition: powercompositegridfunctionspacebase.hh:52
std::size_t _size
Definition: datahandleprovider.hh:46
bool containsPartition(PartitionType partition) const
Returns whether this ordering contains entities with PartitionType partition.
Definition: partitioninfoprovider.hh:28
const Traits::OrderingTag & orderingTag() const
Definition: gridfunctionspacebase.hh:263
Traits::Backend & backend()
Definition: gridfunctionspacebase.hh:248
Traits::OrderingTag & orderingTag()
Definition: gridfunctionspacebase.hh:258
Traits::SizeType maxLocalSize() const
get max dimension of shape function space
Definition: gridfunctionspacebase.hh:210
Traits::SizeType globalSize() const
Definition: gridfunctionspacebase.hh:200
void update()
Definition: gridfunctionspacebase.hh:229
GridFunctionSpaceBase(const B &backend, const OrderingTag &ordering_tag)
Definition: gridfunctionspacebase.hh:159
Definition: exceptions.hh:34
void update(Ordering &ordering) const
Definition: gridfunctionspacebase.hh:276
O OrderingTag
Definition: powercompositegridfunctionspacebase.hh:57
Traits::SizeType blockCount() const
Definition: gridfunctionspacebase.hh:186