4#ifndef DUNE_PDELAB_ORDERING_DIRECTLEAFLOCALORDERING_HH
5#define DUNE_PDELAB_ORDERING_DIRECTLEAFLOCALORDERING_HH
7#include <dune/typetree/leafnode.hh>
9#include <dune/geometry/referenceelements.hh>
10#include <dune/localfunctions/common/interfaceswitch.hh>
11#include <dune/localfunctions/common/localkey.hh>
12#include <dune/pdelab/ordering/utility.hh>
13#include <dune/pdelab/gridfunctionspace/gridfunctionspacebase.hh>
24 template<
typename OrderingTag,
typename FEM,
typename ES,
typename DI,
typename CI>
25 class DirectLeafLocalOrdering
26 :
public TypeTree::LeafNode
30 friend class LeafGridViewOrdering;
33 friend class LeafOrderingBase;
35 template<
typename size_type>
36 friend struct ::Dune::PDELab::impl::update_ordering_data;
40 typedef LocalOrderingTraits<ES,DI,CI> Traits;
44 typedef impl::GridFunctionSpaceOrderingData<typename Traits::SizeType> GFSData;
48 void map_local_index(
const typename Traits::SizeType geometry_type_index,
49 const typename Traits::SizeType entity_index,
50 typename Traits::TreeIndexView mi,
51 typename Traits::ContainerIndex& ci)
const
56 template<
typename ItIn,
typename ItOut>
57 void map_lfs_indices(
const ItIn begin,
const ItIn end, ItOut out)
const
62 template<
typename CIOutIterator,
typename DIOutIterator = DummyDOFIndexIterator>
63 typename Traits::SizeType
64 extract_entity_indices(
const typename Traits::DOFIndex::EntityIndex& ei,
65 typename Traits::SizeType child_index,
66 CIOutIterator ci_out,
const CIOutIterator ci_end,
67 DIOutIterator di_out = DIOutIterator())
const
69 const typename Traits::SizeType s =
size(ei);
72 for (
typename Traits::SizeType i = 0; i < s; ++i, ++di_out)
73 di_out->treeIndex().push_back(i);
89 typename Traits::SizeType
90 size(
const typename Traits::ContainerIndex& suffix,
91 const typename Traits::DOFIndex::EntityIndex &index)
const {
92 if (suffix.size() == 0) {
99 typename Traits::SizeType
size(
const typename Traits::DOFIndex::EntityIndex& index)
const
102 Traits::DOFIndexAccessor::GeometryIndex::geometryType(index),
103 Traits::DOFIndexAccessor::GeometryIndex::entityIndex(index)
107 typename Traits::SizeType
size(
const typename Traits::SizeType geometry_type_index,
const typename Traits::SizeType entity_index)
const
109 typedef typename Traits::SizeType size_type;
111 return _gt_dof_sizes[geometry_type_index];
112 else if (_gt_used[geometry_type_index])
114 const size_type index = _gt_entity_offsets[geometry_type_index] + entity_index;
115 return _entity_dof_offsets[index+1] - _entity_dof_offsets[index];
121 typename Traits::SizeType
size(
const typename Traits::SizeType geometry_type_index,
const typename Traits::SizeType entity_index,
const typename Traits::SizeType child_index)
const
126 typename Traits::SizeType offset(
const typename Traits::SizeType geometry_type_index,
const typename Traits::SizeType entity_index,
const typename Traits::SizeType child_index)
const
128 assert(child_index == 0);
132 DirectLeafLocalOrdering(
const std::shared_ptr<const FEM>& fem,
const ES& es)
136 , _container_blocked(false)
140 const typename Traits::EntitySet& entitySet()
const
145 const FEM& finiteElementMap()
const
152 static constexpr auto GT_UNUSED =
~std::size_t(0);
154 typedef FiniteElementInterfaceSwitch<
155 typename FEM::Traits::FiniteElement
159 void update_a_priori_fixed_size()
161 _fixed_size = _fem->fixedSize();
164 template<
typename CodimMask>
165 void collect_used_codims(CodimMask& codims)
const
167 for (
typename ES::dim_type codim = 0; codim <= ES::dimension; ++codim)
168 if (_fem->hasDOFs(codim))
172 template<
typename It>
173 void update_fixed_size(It it,
const It end)
177 _max_local_size = _fem->maxLocalSize();
179 typedef typename Traits::SizeType size_type;
180 const size_type dim = Traits::GridView::dimension;
184 for (; it != end; ++it)
186 size_type
size = _fem->size(*it);
189 _codim_used[dim - it->dim()] = _codim_used[dim - it->dim()] || (
size > 0);
192 _codim_fixed_size.set();
196 void pre_collect_used_geometry_types_from_cell()
198 typedef typename Traits::SizeType size_type;
199 const size_type dim = Traits::GridView::dimension;
206 _fixed_size_possible =
true;
210 void collect_used_geometry_types_from_cell(
const typename Traits::GridView::template Codim<0>::Entity& cell)
213 const auto& fe = _fem->find(cell);
216 _max_local_size =
std::max(_max_local_size,coeffs.size());
220 for (std::size_t i = 0; i < coeffs.size(); ++i)
222 const LocalKey& key = coeffs.localKey(i);
225 _codim_used.set(key.codim());
230 template<
typename It>
231 void allocate_entity_offset_vector(It it,
const It end)
234 for (; it != end; ++it)
239 std::partial_sum(_gt_entity_offsets.begin(),_gt_entity_offsets.end(),_gt_entity_offsets.begin());
240 _entity_dof_offsets.assign(_gt_entity_offsets.back() + 1,0);
243 _codim_fixed_size.reset();
247 void extract_per_entity_sizes_from_cell(
const typename Traits::GridView::template Codim<0>::Entity& cell)
249 if (this->_fixed_size_possible)
250 std::fill(_local_gt_dof_sizes.begin(),_local_gt_dof_sizes.end(),0);
253 const auto& fe = _fem->find(cell);
256 typedef typename Traits::SizeType size_type;
260 for (std::size_t i = 0; i < coeffs.size(); ++i)
262 const LocalKey& key = coeffs.localKey(i);
266 const size_type entity_index = _es.indexSet().subIndex(cell,key.subEntity(),key.codim());
267 const size_type index = _gt_entity_offsets[geometry_type_index] + entity_index;
268 _local_gt_dof_sizes[geometry_type_index] = _entity_dof_offsets[index+1] =
std::max(_entity_dof_offsets[index+1],
static_cast<size_type
>(key.index() + 1));
271 if (_fixed_size_possible)
273 for (size_type i = 0; i < _local_gt_dof_sizes.size(); ++i)
275 if (_gt_dof_sizes[i] == GT_UNUSED)
276 _gt_dof_sizes[i] = _local_gt_dof_sizes[i];
277 else if (_gt_dof_sizes[i] != _local_gt_dof_sizes[i])
279 _fixed_size_possible =
false;
287 void finalize_non_fixed_size_update()
289 if (_fixed_size_possible)
292 for (
auto&
size : _gt_dof_sizes)
293 if (
size == GT_UNUSED)
296 _entity_dof_offsets = std::vector<typename Traits::SizeType>();
298 _codim_fixed_size.set();
303 std::partial_sum(_entity_dof_offsets.begin(),_entity_dof_offsets.end(),_entity_dof_offsets.begin());
305 _codim_fixed_size.reset();
310 typename Traits::SizeType maxLocalSize()
const
312 return _max_local_size;
317 bool update_gfs_data_size(
typename Traits::SizeType&
size,
typename Traits::SizeType& block_count)
const
324 std::shared_ptr<const FEM> _fem;
328 bool _fixed_size_possible;
329 typename Traits::SizeType _max_local_size;
330 const bool _container_blocked;
332 typename Traits::CodimFlag _codim_used;
333 typename Traits::CodimFlag _codim_fixed_size;
334 std::vector<bool> _gt_used;
336 std::vector<typename Traits::SizeType> _gt_entity_offsets;
337 std::vector<typename Traits::SizeType> _gt_dof_sizes;
338 std::vector<typename Traits::SizeType> _entity_dof_offsets;
339 std::vector<typename Traits::SizeType> _local_gt_dof_sizes;
static constexpr std::size_t index(const GeometryType >)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:138
static constexpr std::size_t size(std::size_t maxdim)
Compute total number of geometry types up to and including the given dimension.
Definition: typeindex.hh:125
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
static const Coefficients & coefficients(const FiniteElement &fe)
access coefficients
Definition: interfaceswitch.hh:45
FiniteElement::Traits::Coefficients Coefficients
export the type of the coefficients
Definition: interfaceswitch.hh:36
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156