dune-pdelab 2.9
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
8
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
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
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;
184 for (; it != end; ++it)
185 {
186 size_type size = _fem->size(*it);
189 _codim_used[dim - it->dim()] = _codim_used[dim - it->dim()] || (size > 0);
190 }
191
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
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 // 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
217
218 auto ref_el = ReferenceElements<typename Traits::GridView::ctype,Traits::GridView::dimension>::general(cell.type());
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());
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 {
234 for (; it != end; ++it)
235 {
237 _gt_entity_offsets[GlobalGeometryTypeIndex::index(*it) + 1] = _es.indexSet().size(*it);
238 }
241
242 // Don't claim fixed size for any codim for now
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)
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
258 auto ref_el = ReferenceElements<typename Traits::GridView::ctype,Traits::GridView::dimension>::general(cell.type());
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
272 {
273 for (size_type i = 0; i < _local_gt_dof_sizes.size(); ++i)
274 {
275 if (_gt_dof_sizes[i] == GT_UNUSED)
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 {
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
297 _fixed_size = true;
299 }
300 else
301 {
302 // convert per-entity sizes to offsets
304 _fixed_size = false;
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
325
326 ES _es;
331
335
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
BCRSMatrix< FieldMatrix< T, n, m >, A >::size_type size_type
int size() const
iterator end()
iterator begin()
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon=DefaultEpsilon< T, style >::value())
#define DUNE_THROW(E, m)
size_t() const
static const int dim
Definition adaptivity.hh:84
std::size_t index
Definition interpolate.hh:97
const std::string s
Definition function.hh:843
STL namespace.
For backward compatibility – Do not use this!
static constexpr std::size_t index(const GeometryType &gt)
static constexpr std::size_t size(std::size_t maxdim)
static const Coefficients & coefficients(const FiniteElement &fe)
FiniteElement::Traits::Coefficients Coefficients
Definition directleaflocalordering.hh:27
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:332
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:334
bool _fixed_size
Definition directleaflocalordering.hh:327
ES _es
Definition directleaflocalordering.hh:326
std::vector< typename Traits::SizeType > _gt_dof_sizes
Definition directleaflocalordering.hh:337
std::vector< typename Traits::SizeType > _entity_dof_offsets
Definition directleaflocalordering.hh:338
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:333
std::vector< typename Traits::SizeType > _gt_entity_offsets
Definition directleaflocalordering.hh:336
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:324
bool _fixed_size_possible
Definition directleaflocalordering.hh:328
const FEM & finiteElementMap() const
Definition directleaflocalordering.hh:145
GFSData * _gfs_data
Definition directleaflocalordering.hh:343
const bool _container_blocked
Definition directleaflocalordering.hh:330
Traits::SizeType size(const typename Traits::DOFIndex::EntityIndex &index) const
Definition directleaflocalordering.hh:99
Traits::SizeType _max_local_size
Definition directleaflocalordering.hh:329
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:339
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
DI::View::TreeIndex TreeIndexView
Definition ordering/utility.hh:216
Definition ordering/utility.hh:224
ES EntitySet
Definition ordering/utility.hh:226
T assign(T... args)
T back(T... args)
T begin(T... args)
T end(T... args)
T fill(T... args)
T max(T... args)
T partial_sum(T... args)
T reset(T... args)
T resize(T... args)
T set(T... args)
T size(T... args)