dune-pdelab 2.10-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 <type_traits>
8
10
16
17#include <vector>
18#include <numeric>
19
20namespace Dune {
21 namespace PDELab {
22
25
26 template<typename OrderingTag, typename FEM, typename ES, typename DI, typename CI>
28 : public TypeTree::LeafNode
29 {
30
31 template<typename>
33
34 template<typename>
35 friend class LeafOrderingBase;
36
37 template<typename size_type>
38 friend struct ::Dune::PDELab::impl::update_ordering_data;
39
40 public:
41
43
44 private:
45
46 typedef impl::GridFunctionSpaceOrderingData<typename Traits::SizeType> GFSData;
47
48 public:
49
50 void map_local_index(const typename Traits::SizeType geometry_type_index,
51 const typename Traits::SizeType entity_index,
52 typename Traits::TreeIndexView mi,
53 typename Traits::ContainerIndex& ci) const
54 {
55 DUNE_THROW(NotImplemented,"not implemented");
56 }
57
58 template<typename ItIn, typename ItOut>
59 void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
60 {
61 // don't do anything - this is handled by the specialized GridViewOrdering
62 }
63
64 template<typename CIOutIterator, typename DIOutIterator = DummyDOFIndexIterator>
65 typename Traits::SizeType
66 extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
67 typename Traits::SizeType child_index,
68 CIOutIterator ci_out, const CIOutIterator ci_end,
69 DIOutIterator di_out = DIOutIterator()) const
70 {
71 const typename Traits::SizeType s = size(ei);
72
73 // Handle DOF indices
74 for (typename Traits::SizeType i = 0; i < s; ++i, ++di_out)
75 di_out->treeIndex().push_back(i);
76
77 // only return the size, as the tree visitor expects that from all leaf nodes.
78 // The actual index processing is done by the specialized GridViewOrdering.
79 return s;
80 }
81
91 typename Traits::SizeType
92 size(const typename Traits::ContainerIndex& suffix,
93 const typename Traits::DOFIndex::EntityIndex &index) const {
94 if (suffix.size() == 0) {
95 return size(index);
96 } else{
97 return 0; // Assume leaf local orderings are always field vectors
98 }
99 }
100
101 typename Traits::SizeType size(const typename Traits::DOFIndex::EntityIndex& index) const
102 {
103 return size(
104 Traits::DOFIndexAccessor::GeometryIndex::geometryType(index),
105 Traits::DOFIndexAccessor::GeometryIndex::entityIndex(index)
106 );
107 }
108
109 typename Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index) const
110 {
111 typedef typename Traits::SizeType size_type;
112 if (_fixed_size)
113 return _gt_dof_sizes[geometry_type_index];
114 else if (_gt_used[geometry_type_index])
115 {
116 const size_type index = _gt_entity_offsets[geometry_type_index] + entity_index;
118 }
119 else
120 return 0;
121 }
122
123 typename Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
124 {
125 DUNE_THROW(NotImplemented,"not implemented");
126 }
127
128 typename Traits::SizeType offset(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
129 {
130 assert(child_index == 0);
131 return 0;
132 }
133
135 : _fem(fem)
136 , _es(es)
137 , _fixed_size(false)
138 , _container_blocked(false)
139 , _gfs_data(nullptr)
140 {}
141
142 const typename Traits::EntitySet& entitySet() const
143 {
144 return _es;
145 }
146
147 const FEM& finiteElementMap() const
148 {
149 return *_fem;
150 }
151
152 private:
153
154 static constexpr auto GT_UNUSED = ~std::size_t(0);
155
157 typename FEM::Traits::FiniteElement
158 > FESwitch;
159
160
161 void update_a_priori_fixed_size()
162 {
163 _fixed_size = _fem->fixedSize();
164 }
165
166 template<typename CodimMask>
167 void collect_used_codims(CodimMask& codims) const
168 {
169 for (typename ES::dim_type codim = 0; codim <= ES::dimension; ++codim)
170 if (_fem->hasDOFs(codim))
171 codims.set(codim);
172 }
173
174 template<typename It>
175 void update_fixed_size(It it, const It end)
176 {
177 assert(_fixed_size);
178
179 _max_local_size = _fem->maxLocalSize();
180
181 typedef typename Traits::SizeType size_type;
182 const size_type dim = Traits::GridView::dimension;
186 for (; it != end; ++it)
187 {
188 size_type size = _fem->size(*it);
191 _codim_used[dim - it->dim()] = _codim_used[dim - it->dim()] || (size > 0);
192 }
193
195 }
196
197
198 void pre_collect_used_geometry_types_from_cell()
199 {
200 typedef typename Traits::SizeType size_type;
201 const size_type dim = Traits::GridView::dimension;
202
207 _max_local_size = 0;
209 }
210
211
212 void collect_used_geometry_types_from_cell(const typename Traits::GridView::template Codim<0>::Entity& cell)
213 {
214 // notice that we keep the finite element alive on this scope (important if rvalue)
215 const auto& fe = _fem->find(cell);
216 const typename FESwitch::Coefficients& coeffs = FESwitch::coefficients(fe);
217
218 using CommonSizeType = std::common_type_t<typename Traits::SizeType, std::decay_t<decltype(coeffs.size())>>;
219 _max_local_size = std::max(CommonSizeType(_max_local_size), CommonSizeType(coeffs.size()));
220
221 auto ref_el = ReferenceElements<typename Traits::GridView::ctype,Traits::GridView::dimension>::general(cell.type());
222
223 for (std::size_t i = 0; i < coeffs.size(); ++i)
224 {
225 const LocalKey& key = coeffs.localKey(i);
226 GeometryType gt = ref_el.type(key.subEntity(),key.codim());
228 _codim_used.set(key.codim());
229 }
230 }
231
232
233 template<typename It>
234 void allocate_entity_offset_vector(It it, const It end)
235 {
237 for (; it != end; ++it)
238 {
240 _gt_entity_offsets[GlobalGeometryTypeIndex::index(*it) + 1] = _es.indexSet().size(*it);
241 }
244
245 // Don't claim fixed size for any codim for now
247 }
248
249
250 void extract_per_entity_sizes_from_cell(const typename Traits::GridView::template Codim<0>::Entity& cell)
251 {
252 if (this->_fixed_size_possible)
254
255 // notice that we keep the finite element alive on this scope (important if rvalue)
256 const auto& fe = _fem->find(cell);
257 const typename FESwitch::Coefficients& coeffs = FESwitch::coefficients(fe);
258
259 typedef typename Traits::SizeType size_type;
260
261 auto ref_el = ReferenceElements<typename Traits::GridView::ctype,Traits::GridView::dimension>::general(cell.type());
262
263 for (std::size_t i = 0; i < coeffs.size(); ++i)
264 {
265 const LocalKey& key = coeffs.localKey(i);
266 GeometryType gt = ref_el.type(key.subEntity(),key.codim());
267 const size_type geometry_type_index = GlobalGeometryTypeIndex::index(gt);
268
269 const size_type entity_index = _es.indexSet().subIndex(cell,key.subEntity(),key.codim());
270 const size_type index = _gt_entity_offsets[geometry_type_index] + entity_index;
271 _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));
272 }
273
275 {
276 for (size_type i = 0; i < _local_gt_dof_sizes.size(); ++i)
277 {
278 if (_gt_dof_sizes[i] == GT_UNUSED)
280 else if (_gt_dof_sizes[i] != _local_gt_dof_sizes[i])
281 {
282 _fixed_size_possible = false;
283 break;
284 }
285 }
286 }
287 }
288
289
290 void finalize_non_fixed_size_update()
291 {
293 {
294 // set size of unused geometry types to 0
295 for (auto& size : _gt_dof_sizes)
296 if (size == GT_UNUSED)
297 size = 0;
298 // free per-entity offsets
300 _fixed_size = true;
302 }
303 else
304 {
305 // convert per-entity sizes to offsets
307 _fixed_size = false;
309 }
310 }
311
312
313 typename Traits::SizeType maxLocalSize() const
314 {
315 return _max_local_size;
316 }
317
318 private:
319
320 bool update_gfs_data_size(typename Traits::SizeType& size, typename Traits::SizeType& block_count) const
321 {
322 return false;
323 }
324
325 protected:
326
328
329 ES _es;
334
338
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
BCRSMatrix< FieldMatrix< T, n, m >, A >::size_type size_type
int size() const
iterator end()
iterator begin()
static const int dim
Definition adaptivity.hh:84
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon=DefaultEpsilon< T, style >::value())
#define DUNE_THROW(E,...)
std::size_t index
Definition interpolate.hh:97
size_t() const
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:29
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:128
DirectLeafLocalOrdering(const std::shared_ptr< const FEM > &fem, const ES &es)
Definition directleaflocalordering.hh:134
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:50
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:59
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:123
std::shared_ptr< const FEM > _fem
Definition directleaflocalordering.hh:327
bool _fixed_size_possible
Definition directleaflocalordering.hh:331
const FEM & finiteElementMap() const
Definition directleaflocalordering.hh:147
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:101
Traits::SizeType _max_local_size
Definition directleaflocalordering.hh:332
LocalOrderingTraits< ES, DI, CI > Traits
Definition directleaflocalordering.hh:42
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:66
const Traits::EntitySet & entitySet() const
Definition directleaflocalordering.hh:142
Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index) const
Definition directleaflocalordering.hh:109
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:92
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
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)