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);
80 typename Traits::SizeType size(
const typename Traits::DOFIndex::EntityIndex& index)
const
83 Traits::DOFIndexAccessor::GeometryIndex::geometryType(index),
84 Traits::DOFIndexAccessor::GeometryIndex::entityIndex(index)
88 typename Traits::SizeType size(
const typename Traits::SizeType geometry_type_index,
const typename Traits::SizeType entity_index)
const
90 typedef typename Traits::SizeType size_type;
92 return _gt_dof_sizes[geometry_type_index];
93 else if (_gt_used[geometry_type_index])
95 const size_type index = _gt_entity_offsets[geometry_type_index] + entity_index;
96 return _entity_dof_offsets[index+1] - _entity_dof_offsets[index];
102 typename Traits::SizeType size(
const typename Traits::SizeType geometry_type_index,
const typename Traits::SizeType entity_index,
const typename Traits::SizeType child_index)
const
107 typename Traits::SizeType offset(
const typename Traits::SizeType geometry_type_index,
const typename Traits::SizeType entity_index,
const typename Traits::SizeType child_index)
const
109 assert(child_index == 0);
113 DirectLeafLocalOrdering(
const std::shared_ptr<const FEM>& fem,
const ES& es)
117 , _container_blocked(false)
121 const typename Traits::EntitySet& entitySet()
const
126 const FEM& finiteElementMap()
const
133 static constexpr auto GT_UNUSED =
~std::size_t(0);
135 typedef FiniteElementInterfaceSwitch<
136 typename FEM::Traits::FiniteElement
140 void update_a_priori_fixed_size()
142 _fixed_size = _fem->fixedSize();
145 template<
typename CodimMask>
146 void collect_used_codims(CodimMask& codims)
const
148 for (
typename ES::dim_type codim = 0; codim <= ES::dimension; ++codim)
149 if (_fem->hasDOFs(codim))
153 template<
typename It>
154 void update_fixed_size(It it,
const It end)
158 _max_local_size = _fem->maxLocalSize();
160 typedef typename Traits::SizeType size_type;
161 const size_type dim = Traits::GridView::dimension;
165 for (; it != end; ++it)
167 size_type size = _fem->size(*it);
170 _codim_used[dim - it->dim()] = _codim_used[dim - it->dim()] || (size > 0);
173 _codim_fixed_size.set();
177 void pre_collect_used_geometry_types_from_cell()
179 typedef typename Traits::SizeType size_type;
180 const size_type dim = Traits::GridView::dimension;
187 _fixed_size_possible =
true;
191 void collect_used_geometry_types_from_cell(
const typename Traits::GridView::template Codim<0>::Entity& cell)
198 _max_local_size =
std::max(_max_local_size,coeffs.size());
202 for (std::size_t i = 0; i < coeffs.size(); ++i)
204 const LocalKey& key = coeffs.localKey(i);
207 _codim_used.set(key.codim());
212 template<
typename It>
213 void allocate_entity_offset_vector(It it,
const It end)
216 for (; it != end; ++it)
221 std::partial_sum(_gt_entity_offsets.begin(),_gt_entity_offsets.end(),_gt_entity_offsets.begin());
222 _entity_dof_offsets.assign(_gt_entity_offsets.back() + 1,0);
225 _codim_fixed_size.reset();
229 void extract_per_entity_sizes_from_cell(
const typename Traits::GridView::template Codim<0>::Entity& cell)
231 if (this->_fixed_size_possible)
232 std::fill(_local_gt_dof_sizes.begin(),_local_gt_dof_sizes.end(),0);
239 typedef typename Traits::SizeType size_type;
243 for (std::size_t i = 0; i < coeffs.size(); ++i)
245 const LocalKey& key = coeffs.localKey(i);
249 const size_type entity_index = _es.indexSet().subIndex(cell,key.subEntity(),key.codim());
250 const size_type index = _gt_entity_offsets[geometry_type_index] + entity_index;
251 _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));
254 if (_fixed_size_possible)
256 for (size_type i = 0; i < _local_gt_dof_sizes.size(); ++i)
258 if (_gt_dof_sizes[i] == GT_UNUSED)
259 _gt_dof_sizes[i] = _local_gt_dof_sizes[i];
260 else if (_gt_dof_sizes[i] != _local_gt_dof_sizes[i])
262 _fixed_size_possible =
false;
270 void finalize_non_fixed_size_update()
272 if (_fixed_size_possible)
275 for (
auto& size : _gt_dof_sizes)
276 if (size == GT_UNUSED)
279 _entity_dof_offsets = std::vector<typename Traits::SizeType>();
281 _codim_fixed_size.set();
286 std::partial_sum(_entity_dof_offsets.begin(),_entity_dof_offsets.end(),_entity_dof_offsets.begin());
288 _codim_fixed_size.reset();
293 typename Traits::SizeType maxLocalSize()
const
295 return _max_local_size;
300 bool update_gfs_data_size(
typename Traits::SizeType& size,
typename Traits::SizeType& block_count)
const
307 std::shared_ptr<const FEM> _fem;
312 bool _fixed_size_possible;
313 typename Traits::SizeType _max_local_size;
314 const bool _container_blocked;
316 typename Traits::CodimFlag _codim_used;
317 typename Traits::CodimFlag _codim_fixed_size;
318 std::vector<bool> _gt_used;
320 std::vector<typename Traits::SizeType> _gt_entity_offsets;
321 std::vector<typename Traits::SizeType> _gt_dof_sizes;
322 std::vector<typename Traits::SizeType> _entity_dof_offsets;
323 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:133
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:120
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:180
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:156
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
Dune namespace.
Definition: alignedallocator.hh:14
static const Coefficients & coefficients(const FiniteElement &fe)
access coefficients
Definition: interfaceswitch.hh:42
FiniteElement::Traits::Coefficients Coefficients
export the type of the coefficients
Definition: interfaceswitch.hh:33
static void setStore(Store &store, const FiniteElement &fe)
Store a finite element in the store.
Definition: interfaceswitch.hh:75
std::shared_ptr< const FiniteElement > Store
Type for storing finite elements.
Definition: interfaceswitch.hh:68
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:196