DUNE PDELab (git)

directleaflocalordering.hh
1// -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=8 sw=2 sts=2:
3
4#ifndef DUNE_PDELAB_ORDERING_DIRECTLEAFLOCALORDERING_HH
5#define DUNE_PDELAB_ORDERING_DIRECTLEAFLOCALORDERING_HH
6
7#include <dune/typetree/leafnode.hh>
8
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>
14
15#include <vector>
16#include <numeric>
17
18namespace Dune {
19 namespace PDELab {
20
23
24 template<typename OrderingTag, typename FEM, typename ES, typename DI, typename CI>
25 class DirectLeafLocalOrdering
26 : public TypeTree::LeafNode
27 {
28
29 template<typename>
30 friend class LeafGridViewOrdering;
31
32 template<typename>
33 friend class LeafOrderingBase;
34
35 template<typename size_type>
36 friend struct ::Dune::PDELab::impl::update_ordering_data;
37
38 public:
39
40 typedef LocalOrderingTraits<ES,DI,CI> Traits;
41
42 private:
43
44 typedef impl::GridFunctionSpaceOrderingData<typename Traits::SizeType> GFSData;
45
46 public:
47
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
52 {
53 DUNE_THROW(NotImplemented,"not implemented");
54 }
55
56 template<typename ItIn, typename ItOut>
57 void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
58 {
59 // don't do anything - this is handled by the specialized GridViewOrdering
60 }
61
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
68 {
69 const typename Traits::SizeType s = size(ei);
70
71 // Handle DOF indices
72 for (typename Traits::SizeType i = 0; i < s; ++i, ++di_out)
73 di_out->treeIndex().push_back(i);
74
75 // only return the size, as the tree visitor expects that from all leaf nodes.
76 // The actual index processing is done by the specialized GridViewOrdering.
77 return s;
78 }
79
89 typename Traits::SizeType
90 size(const typename Traits::ContainerIndex& suffix,
91 const typename Traits::DOFIndex::EntityIndex &index) const {
92 if (suffix.size() == 0) {
93 return size(index);
94 } else{
95 return 0; // Assume leaf local orderings are always field vectors
96 }
97 }
98
99 typename Traits::SizeType size(const typename Traits::DOFIndex::EntityIndex& index) const
100 {
101 return size(
102 Traits::DOFIndexAccessor::GeometryIndex::geometryType(index),
103 Traits::DOFIndexAccessor::GeometryIndex::entityIndex(index)
104 );
105 }
106
107 typename Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index) const
108 {
109 typedef typename Traits::SizeType size_type;
110 if (_fixed_size)
111 return _gt_dof_sizes[geometry_type_index];
112 else if (_gt_used[geometry_type_index])
113 {
114 const size_type index = _gt_entity_offsets[geometry_type_index] + entity_index;
115 return _entity_dof_offsets[index+1] - _entity_dof_offsets[index];
116 }
117 else
118 return 0;
119 }
120
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
122 {
123 DUNE_THROW(NotImplemented,"not implemented");
124 }
125
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
127 {
128 assert(child_index == 0);
129 return 0;
130 }
131
132 DirectLeafLocalOrdering(const std::shared_ptr<const FEM>& fem, const ES& es)
133 : _fem(fem)
134 , _es(es)
135 , _fixed_size(false)
136 , _container_blocked(false)
137 , _gfs_data(nullptr)
138 {}
139
140 const typename Traits::EntitySet& entitySet() const
141 {
142 return _es;
143 }
144
145 const FEM& finiteElementMap() const
146 {
147 return *_fem;
148 }
149
150 private:
151
152 static constexpr auto GT_UNUSED = ~std::size_t(0);
153
154 typedef FiniteElementInterfaceSwitch<
155 typename FEM::Traits::FiniteElement
156 > FESwitch;
157
158
159 void update_a_priori_fixed_size()
160 {
161 _fixed_size = _fem->fixedSize();
162 }
163
164 template<typename CodimMask>
165 void collect_used_codims(CodimMask& codims) const
166 {
167 for (typename ES::dim_type codim = 0; codim <= ES::dimension; ++codim)
168 if (_fem->hasDOFs(codim))
169 codims.set(codim);
170 }
171
172 template<typename It>
173 void update_fixed_size(It it, const It end)
174 {
175 assert(_fixed_size);
176
177 _max_local_size = _fem->maxLocalSize();
178
179 typedef typename Traits::SizeType size_type;
180 const size_type dim = Traits::GridView::dimension;
181 _codim_used.reset();
182 _gt_used.assign(GlobalGeometryTypeIndex::size(dim),false);
183 _gt_dof_sizes.assign(GlobalGeometryTypeIndex::size(dim),0);
184 for (; it != end; ++it)
185 {
186 size_type size = _fem->size(*it);
187 _gt_dof_sizes[GlobalGeometryTypeIndex::index(*it)] = size;
188 _gt_used[GlobalGeometryTypeIndex::index(*it)] = size > 0;
189 _codim_used[dim - it->dim()] = _codim_used[dim - it->dim()] || (size > 0);
190 }
191
192 _codim_fixed_size.set();
193 }
194
195
196 void pre_collect_used_geometry_types_from_cell()
197 {
198 typedef typename Traits::SizeType size_type;
199 const size_type dim = Traits::GridView::dimension;
200
201 _codim_used.reset();
202 _gt_used.assign(GlobalGeometryTypeIndex::size(dim),false);
203 _gt_dof_sizes.assign(GlobalGeometryTypeIndex::size(dim),GT_UNUSED);
204 _local_gt_dof_sizes.resize(GlobalGeometryTypeIndex::size(dim));
205 _max_local_size = 0;
206 _fixed_size_possible = true;
207 }
208
209
210 void collect_used_geometry_types_from_cell(const typename Traits::GridView::template Codim<0>::Entity& cell)
211 {
212 // notice that we keep the finite element alive on this scope (important if rvalue)
213 const auto& fe = _fem->find(cell);
214 const typename FESwitch::Coefficients& coeffs = FESwitch::coefficients(fe);
215
216 _max_local_size = std::max(_max_local_size,coeffs.size());
217
219
220 for (std::size_t i = 0; i < coeffs.size(); ++i)
221 {
222 const LocalKey& key = coeffs.localKey(i);
223 GeometryType gt = ref_el.type(key.subEntity(),key.codim());
224 _gt_used[GlobalGeometryTypeIndex::index(gt)] = true;
225 _codim_used.set(key.codim());
226 }
227 }
228
229
230 template<typename It>
231 void allocate_entity_offset_vector(It it, const It end)
232 {
233 _gt_entity_offsets.assign(GlobalGeometryTypeIndex::size(ES::dimension) + 1,0);
234 for (; it != end; ++it)
235 {
236 if (_gt_used[GlobalGeometryTypeIndex::index(*it)])
237 _gt_entity_offsets[GlobalGeometryTypeIndex::index(*it) + 1] = _es.indexSet().size(*it);
238 }
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);
241
242 // Don't claim fixed size for any codim for now
243 _codim_fixed_size.reset();
244 }
245
246
247 void extract_per_entity_sizes_from_cell(const typename Traits::GridView::template Codim<0>::Entity& cell)
248 {
249 if (this->_fixed_size_possible)
250 std::fill(_local_gt_dof_sizes.begin(),_local_gt_dof_sizes.end(),0);
251
252 // notice that we keep the finite element alive on this scope (important if rvalue)
253 const auto& fe = _fem->find(cell);
254 const typename FESwitch::Coefficients& coeffs = FESwitch::coefficients(fe);
255
256 typedef typename Traits::SizeType size_type;
257
259
260 for (std::size_t i = 0; i < coeffs.size(); ++i)
261 {
262 const LocalKey& key = coeffs.localKey(i);
263 GeometryType gt = ref_el.type(key.subEntity(),key.codim());
264 const size_type geometry_type_index = GlobalGeometryTypeIndex::index(gt);
265
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));
269 }
270
271 if (_fixed_size_possible)
272 {
273 for (size_type i = 0; i < _local_gt_dof_sizes.size(); ++i)
274 {
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])
278 {
279 _fixed_size_possible = false;
280 break;
281 }
282 }
283 }
284 }
285
286
287 void finalize_non_fixed_size_update()
288 {
289 if (_fixed_size_possible)
290 {
291 // set size of unused geometry types to 0
292 for (auto& size : _gt_dof_sizes)
293 if (size == GT_UNUSED)
294 size = 0;
295 // free per-entity offsets
296 _entity_dof_offsets = std::vector<typename Traits::SizeType>();
297 _fixed_size = true;
298 _codim_fixed_size.set();
299 }
300 else
301 {
302 // convert per-entity sizes to offsets
303 std::partial_sum(_entity_dof_offsets.begin(),_entity_dof_offsets.end(),_entity_dof_offsets.begin());
304 _fixed_size = false;
305 _codim_fixed_size.reset();
306 }
307 }
308
309
310 typename Traits::SizeType maxLocalSize() const
311 {
312 return _max_local_size;
313 }
314
315 private:
316
317 bool update_gfs_data_size(typename Traits::SizeType& size, typename Traits::SizeType& block_count) const
318 {
319 return false;
320 }
321
322 protected:
323
324 std::shared_ptr<const FEM> _fem;
325
326 ES _es;
327 bool _fixed_size;
328 bool _fixed_size_possible;
329 typename Traits::SizeType _max_local_size;
330 const bool _container_blocked;
331
332 typename Traits::CodimFlag _codim_used;
333 typename Traits::CodimFlag _codim_fixed_size;
334 std::vector<bool> _gt_used;
335
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;
340
341 // This is only here to make the visitor happy that traverses all
342 // Orderings to manipulate the contained GFSData
343 GFSData* _gfs_data;
344
345 };
346
348
349 } // namespace PDELab
350} // namespace Dune
351
352#endif // DUNE_PDELAB_ORDERING_DIRECTLEAFLOCALORDERING_HH
static constexpr std::size_t index(const GeometryType &gt)
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
STL namespace.
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)