dune-pdelab 2.7-git
Loading...
Searching...
No Matches
directleaflocalordering.hh
Go to the documentation of this file.
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>
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>
26 : public TypeTree::LeafNode
27 {
28
29 template<typename>
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
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;
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;
207 }
208
209
210 void collect_used_geometry_types_from_cell(const typename Traits::GridView::template Codim<0>::Entity& cell)
211 {
212 FESwitch::setStore(_fe_store,_fem->find(cell));
213
214 const typename FESwitch::Coefficients& coeffs =
215 FESwitch::coefficients(*_fe_store);
216
217 _max_local_size = std::max(_max_local_size,coeffs.size());
218
219 auto ref_el = ReferenceElements<typename Traits::GridView::ctype,Traits::GridView::dimension>::general(cell.type());
220
221 for (std::size_t i = 0; i < coeffs.size(); ++i)
222 {
223 const LocalKey& key = coeffs.localKey(i);
224 GeometryType gt = ref_el.type(key.subEntity(),key.codim());
225 _gt_used[GlobalGeometryTypeIndex::index(gt)] = true;
226 _codim_used.set(key.codim());
227 }
228 }
229
230
231 template<typename It>
232 void allocate_entity_offset_vector(It it, const It end)
233 {
234 _gt_entity_offsets.assign(GlobalGeometryTypeIndex::size(ES::dimension) + 1,0);
235 for (; it != end; ++it)
236 {
237 if (_gt_used[GlobalGeometryTypeIndex::index(*it)])
238 _gt_entity_offsets[GlobalGeometryTypeIndex::index(*it) + 1] = _es.indexSet().size(*it);
239 }
240 std::partial_sum(_gt_entity_offsets.begin(),_gt_entity_offsets.end(),_gt_entity_offsets.begin());
241 _entity_dof_offsets.assign(_gt_entity_offsets.back() + 1,0);
242
243 // Don't claim fixed size for any codim for now
244 _codim_fixed_size.reset();
245 }
246
247
248 void extract_per_entity_sizes_from_cell(const typename Traits::GridView::template Codim<0>::Entity& cell)
249 {
250 if (this->_fixed_size_possible)
251 std::fill(_local_gt_dof_sizes.begin(),_local_gt_dof_sizes.end(),0);
252
253 FESwitch::setStore(_fe_store,_fem->find(cell));
254
255 const typename FESwitch::Coefficients& coeffs =
256 FESwitch::coefficients(*_fe_store);
257
258 typedef typename Traits::SizeType size_type;
259
260 auto ref_el = ReferenceElements<typename Traits::GridView::ctype,Traits::GridView::dimension>::general(cell.type());
261
262 for (std::size_t i = 0; i < coeffs.size(); ++i)
263 {
264 const LocalKey& key = coeffs.localKey(i);
265 GeometryType gt = ref_el.type(key.subEntity(),key.codim());
266 const size_type geometry_type_index = GlobalGeometryTypeIndex::index(gt);
267
268 const size_type entity_index = _es.indexSet().subIndex(cell,key.subEntity(),key.codim());
269 const size_type index = _gt_entity_offsets[geometry_type_index] + entity_index;
270 _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 }
272
274 {
275 for (size_type i = 0; i < _local_gt_dof_sizes.size(); ++i)
276 {
277 if (_gt_dof_sizes[i] == GT_UNUSED)
279 else if (_gt_dof_sizes[i] != _local_gt_dof_sizes[i])
280 {
281 _fixed_size_possible = false;
282 break;
283 }
284 }
285 }
286 }
287
288
289 void finalize_non_fixed_size_update()
290 {
292 {
293 // set size of unused geometry types to 0
294 for (auto& size : _gt_dof_sizes)
295 if (size == GT_UNUSED)
296 size = 0;
297 // free per-entity offsets
298 _entity_dof_offsets = std::vector<typename Traits::SizeType>();
299 _fixed_size = true;
300 _codim_fixed_size.set();
301 }
302 else
303 {
304 // convert per-entity sizes to offsets
305 std::partial_sum(_entity_dof_offsets.begin(),_entity_dof_offsets.end(),_entity_dof_offsets.begin());
306 _fixed_size = false;
307 _codim_fixed_size.reset();
308 }
309 }
310
311
312 typename Traits::SizeType maxLocalSize() const
313 {
314 return _max_local_size;
315 }
316
317 private:
318
319 bool update_gfs_data_size(typename Traits::SizeType& size, typename Traits::SizeType& block_count) const
320 {
321 return false;
322 }
323
324 protected:
325
326 std::shared_ptr<const FEM> _fem;
327 typename FESwitch::Store _fe_store;
328
329 ES _es;
334
337 std::vector<bool> _gt_used;
338
339 std::vector<typename Traits::SizeType> _gt_entity_offsets;
340 std::vector<typename Traits::SizeType> _gt_dof_sizes;
341 std::vector<typename Traits::SizeType> _entity_dof_offsets;
342 std::vector<typename Traits::SizeType> _local_gt_dof_sizes;
343
344 // This is only here to make the visitor happy that traverses all
345 // Orderings to manipulate the contained GFSData
346 GFSData* _gfs_data;
347
348 };
349
351
352 } // namespace PDELab
353} // namespace Dune
354
355#endif // DUNE_PDELAB_ORDERING_DIRECTLEAFLOCALORDERING_HH
const std::string s
Definition: function.hh:843
static const int dim
Definition: adaptivity.hh:84
std::size_t index
Definition: interpolate.hh:97
STL namespace.
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Definition: directleaflocalordering.hh:27
FESwitch::Store _fe_store
Definition: directleaflocalordering.hh:327
Traits::SizeType offset(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
Definition: directleaflocalordering.hh:126
DirectLeafLocalOrdering(const std::shared_ptr< const FEM > &fem, const ES &es)
Definition: directleaflocalordering.hh:132
Traits::CodimFlag _codim_used
Definition: directleaflocalordering.hh:335
void map_local_index(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, typename Traits::TreeIndexView mi, typename Traits::ContainerIndex &ci) const
Definition: directleaflocalordering.hh:48
std::vector< bool > _gt_used
Definition: directleaflocalordering.hh:337
bool _fixed_size
Definition: directleaflocalordering.hh:330
ES _es
Definition: directleaflocalordering.hh:329
std::vector< typename Traits::SizeType > _gt_dof_sizes
Definition: directleaflocalordering.hh:340
std::vector< typename Traits::SizeType > _entity_dof_offsets
Definition: directleaflocalordering.hh:341
void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
Definition: directleaflocalordering.hh:57
Traits::CodimFlag _codim_fixed_size
Definition: directleaflocalordering.hh:336
std::vector< typename Traits::SizeType > _gt_entity_offsets
Definition: directleaflocalordering.hh:339
Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
Definition: directleaflocalordering.hh:121
std::shared_ptr< const FEM > _fem
Definition: directleaflocalordering.hh:326
bool _fixed_size_possible
Definition: directleaflocalordering.hh:331
const FEM & finiteElementMap() const
Definition: directleaflocalordering.hh:145
GFSData * _gfs_data
Definition: directleaflocalordering.hh:346
const bool _container_blocked
Definition: directleaflocalordering.hh:333
Traits::SizeType size(const typename Traits::DOFIndex::EntityIndex &index) const
Definition: directleaflocalordering.hh:99
Traits::SizeType _max_local_size
Definition: directleaflocalordering.hh:332
LocalOrderingTraits< ES, DI, CI > Traits
Definition: directleaflocalordering.hh:40
Traits::SizeType extract_entity_indices(const typename Traits::DOFIndex::EntityIndex &ei, typename Traits::SizeType child_index, CIOutIterator ci_out, const CIOutIterator ci_end, DIOutIterator di_out=DIOutIterator()) const
Definition: directleaflocalordering.hh:64
const Traits::EntitySet & entitySet() const
Definition: directleaflocalordering.hh:140
Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index) const
Definition: directleaflocalordering.hh:107
Traits::SizeType size(const typename Traits::ContainerIndex &suffix, const typename Traits::DOFIndex::EntityIndex &index) const
Returns the size for a given suffix.
Definition: directleaflocalordering.hh:90
std::vector< typename Traits::SizeType > _local_gt_dof_sizes
Definition: directleaflocalordering.hh:342
Gridview ordering for leaf spaces.
Definition: leafgridviewordering.hh:20
Generic infrastructure for orderings for leaf spaces.
Definition: leaforderingbase.hh:27
std::size_t SizeType
Definition: ordering/utility.hh:178
CI ContainerIndex
Definition: ordering/utility.hh:176
std::bitset< max_dim > CodimFlag
Definition: ordering/utility.hh:211
DI::View::TreeIndex TreeIndexView
Definition: ordering/utility.hh:216
Definition: ordering/utility.hh:224
ES EntitySet
Definition: ordering/utility.hh:226