DUNE PDELab (git)

leaforderingbase.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_LEAFORDERINGBASE_HH
5#define DUNE_PDELAB_ORDERING_LEAFORDERINGBASE_HH
6
7#include <dune/typetree/typetree.hh>
8
9#include <dune/pdelab/ordering/utility.hh>
10#include <dune/pdelab/ordering/orderingbase.hh>
11#include <dune/pdelab/ordering/directleaflocalordering.hh>
12
13namespace Dune {
14 namespace PDELab {
15
18
20 template<typename LocalOrdering>
22 : public TypeTree::CompositeNode<LocalOrdering>
23 , public VirtualOrderingBase<typename LocalOrdering::Traits::DOFIndex,
24 typename LocalOrdering::Traits::ContainerIndex>
25 , public OrderingBase<typename LocalOrdering::Traits::DOFIndex,
26 typename LocalOrdering::Traits::ContainerIndex>
27 {
28 public:
29 typedef typename LocalOrdering::Traits Traits;
30
31 static const bool has_dynamic_ordering_children = false;
32
33 static const bool consume_tree_index = false;
34
35 protected:
36
38
39 typedef OrderingBase<typename LocalOrdering::Traits::DOFIndex,
40 typename LocalOrdering::Traits::ContainerIndex> BaseT;
41
42 public:
43
44 LocalOrdering& localOrdering()
45 {
46 return this->template child<0>();
47 }
48
49 const LocalOrdering& localOrdering() const
50 {
51 return this->template child<0>();
52 }
53
54
55 LeafOrderingBase(const typename NodeT::NodeStorage& local_ordering, bool container_blocked, typename BaseT::GFSData* gfs_data)
56 : NodeT(local_ordering)
57 , BaseT(*this,container_blocked,gfs_data,this)
58 {}
59
60#ifndef DOXYGEN
61
62// we need to override the default copy / move ctor to fix the delegate pointer, but that is
63// hardly interesting to our users...
64
66 : NodeT(r.nodeStorage())
67 , BaseT(r)
68 , _gt_dof_offsets(r._gt_dof_offsets)
69 {
70 this->setDelegate(this);
71 }
72
74 : NodeT(r.nodeStorage())
75 , BaseT(std::move(r))
76 , _gt_dof_offsets(std::move(r._gt_dof_offsets))
77 {
78 this->setDelegate(this);
79 }
80
81#endif // DOXYGEN
82
83 virtual ~LeafOrderingBase() override = default;
84
85 virtual void map_index_dynamic(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const override
86 {
87 mapIndex(di,ci);
88 }
89
90 typename Traits::ContainerIndex mapIndex(const typename Traits::DOFIndex& di) const
91 {
92 typename Traits::ContainerIndex ci;
93 mapIndex(di.view(),ci);
94 return ci;
95 }
96
97 void mapIndex(typename Traits::DOFIndexView di, typename Traits::ContainerIndex& ci) const
98 {
99
100 const typename Traits::SizeType geometry_type_index = Traits::DOFIndexAccessor::geometryType(di);
101 const typename Traits::SizeType entity_index = Traits::DOFIndexAccessor::entityIndex(di);
102 assert (di.treeIndex().size() == 1);
103 ci.push_back(di.treeIndex().back());
104
105 if (localOrdering()._fixed_size)
106 {
107 if (_container_blocked)
108 {
109 // This check is needed to avoid a horrid stream of compiler warnings about
110 // exceeding array bounds in ReservedVector!
111 if (ci.size() < ci.capacity())
112 ci.push_back(_gt_dof_offsets[geometry_type_index] + entity_index);
113 else
114 {
115 DUNE_THROW(Dune::Exception,"Container blocking incompatible with backend structure");
116 }
117 }
118 else
119 {
120 ci.back() += _gt_dof_offsets[geometry_type_index] + entity_index * localOrdering()._gt_dof_sizes[geometry_type_index];
121 }
122 }
123 else
124 {
125 if (_container_blocked)
126 {
127 // This check is needed to avoid a horrid stream of compiler warnings about
128 // exceeding array bounds in ReservedVector!
129 if (ci.size() < ci.capacity())
130 ci.push_back(localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index);
131 else
132 {
133 DUNE_THROW(Dune::Exception,"Container blocking incompatible with backend structure");
134 }
135 }
136 else
137 {
138 ci.back() += localOrdering()._entity_dof_offsets[localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index];
139 }
140 }
141 }
142
143
144 template<typename ItIn, typename ItOut>
145 void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
146 {
147 typedef typename Traits::SizeType size_type;
148
149 if (localOrdering()._fixed_size)
150 {
151 if (_container_blocked)
152 {
153 for (ItIn in = begin; in != end; ++in, ++out)
154 {
155 assert(in->treeIndex().size() == 1);
156 out->push_back(in->treeIndex().back());
157 const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
158 const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
159 assert(localOrdering()._gt_used[geometry_type_index]);
160 out->push_back(_gt_dof_offsets[geometry_type_index] + entity_index);
161 }
162 }
163 else
164 {
165 for (ItIn in = begin; in != end; ++in, ++out)
166 {
167 assert(in->treeIndex().size() == 1);
168 out->push_back(in->treeIndex().back());
169 const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
170 const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
171 assert(localOrdering()._gt_used[geometry_type_index]);
172 out->back() += _gt_dof_offsets[geometry_type_index] + entity_index * localOrdering()._gt_dof_sizes[geometry_type_index];
173 }
174 }
175 }
176 else
177 {
178 if (_container_blocked)
179 {
180 for (ItIn in = begin; in != end; ++in, ++out)
181 {
182 assert(in->treeIndex().size() == 1);
183 out->push_back(in->treeIndex().back());
184 const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
185 const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
186 assert(localOrdering()._gt_used[geometry_type_index]);
187 out->push_back(localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index);
188 }
189 }
190 else
191 {
192 for (ItIn in = begin; in != end; ++in, ++out)
193 {
194 assert(in->treeIndex().size() == 1);
195 out->push_back(in->treeIndex().back());
196 const size_type geometry_type_index = Traits::DOFIndexAccessor::geometryType(*in);
197 const size_type entity_index = Traits::DOFIndexAccessor::entityIndex(*in);
198 assert(localOrdering()._gt_used[geometry_type_index]);
199 out->back() += localOrdering()._entity_dof_offsets[localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index];
200 }
201 }
202 }
203 }
204
205 template<typename CIOutIterator>
206 typename Traits::SizeType
207 extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
208 typename Traits::SizeType child_index,
209 CIOutIterator ci_out, const CIOutIterator ci_end) const
210 {
211 typedef typename Traits::SizeType size_type;
212
213 const size_type geometry_type_index = Traits::DOFIndexAccessor::GeometryIndex::geometryType(ei);
214 const size_type entity_index = Traits::DOFIndexAccessor::GeometryIndex::entityIndex(ei);
215
216 if (!localOrdering()._gt_used[geometry_type_index])
217 return 0;
218
219 if (localOrdering()._fixed_size)
220 {
221 size_type size = localOrdering()._gt_dof_sizes[geometry_type_index];
222 if (_container_blocked)
223 {
224 for (size_type i = 0; i < size; ++i, ++ci_out)
225 {
226 ci_out->push_back(i);
227 ci_out->push_back(_gt_dof_offsets[geometry_type_index] + entity_index);
228 }
229 }
230 else
231 {
232 for (size_type i = 0; i < size; ++i, ++ci_out)
233 {
234 ci_out->push_back(i);
235 ci_out->back() += _gt_dof_offsets[geometry_type_index] + entity_index * localOrdering()._gt_dof_sizes[geometry_type_index];
236 }
237 }
238 return 0;
239 }
240 else
241 {
242 size_type index = localOrdering()._gt_entity_offsets[geometry_type_index] + entity_index;
243 size_type size = localOrdering()._entity_dof_offsets[index+1] - localOrdering()._entity_dof_offsets[index];
244 if (_container_blocked)
245 {
246 for (size_type i = 0; i < size; ++i, ++ci_out)
247 {
248 ci_out->push_back(i);
249 ci_out->push_back(index);
250 }
251 }
252 else
253 {
254 for (size_type i = 0; i < size; ++i, ++ci_out)
255 {
256 ci_out->push_back(i);
257 ci_out->back() += localOrdering()._entity_dof_offsets[index];
258 }
259 }
260 return 0;
261 }
262 }
263
267 virtual void update() = 0;
268
269 using BaseT::fixedSize;
270
271 protected:
272
273 using BaseT::_max_local_size;
274 using BaseT::_size;
275 using BaseT::_block_count;
276 using BaseT::_container_blocked;
277 using BaseT::_fixed_size;
278 using BaseT::_codim_used;
279 using BaseT::_codim_fixed_size;
280
281 std::vector<typename Traits::SizeType> _gt_dof_offsets;
282
283 };
284
286 } // namespace PDELab
287} // namespace Dune
288
289#endif // DUNE_PDELAB_ORDERING_LEAFORDERINGBASE_HH
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
Generic infrastructure for orderings for leaf spaces.
Definition: leaforderingbase.hh:27
Base class for composite nodes based on variadic templates.
Definition: compositenode.hh:28
std::tuple< std::shared_ptr< Children >... > NodeStorage
The type used for storing the children.
Definition: compositenode.hh:36
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
std::size_t fixedSize
The number of data items per index if it is fixed, 0 otherwise.
Definition: variablesizecommunicator.hh:264
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)