FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
target_set.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/shape.hpp>
10#include <kernel/adjacency/permutation.hpp>
11
12// includes, system
13#include <vector>
14
15namespace FEAT
16{
17 namespace Geometry
18 {
27 {
28 protected:
30 std::vector<Index> _indices;
31
33 explicit TargetSet(const std::vector<Index>& idx) :
34 _indices(idx)
35 {
36 }
37
38 public:
41 _indices()
42 {
43 }
44
51 explicit TargetSet(Index num_entities) :
52 _indices(std::size_t(num_entities))
53 {
54 }
55
58 _indices(std::forward<std::vector<Index>>(other._indices))
59 {
60 }
61
64 {
65 // avoid self-move
66 if(this == &other)
67 return *this;
68
69 _indices = std::forward<std::vector<Index>>(other._indices);
70
71 return *this;
72 }
73
75 virtual ~TargetSet()
76 {
77 }
78
81 {
82 return TargetSet(this->_indices);
83 }
84
86 std::size_t bytes() const
87 {
88 return _indices.size() * sizeof(Index);
89 }
90
93 {
94 return Index(_indices.size());
95 }
96
101 {
102 return _indices.data();
103 }
104
106 const Index* get_indices() const
107 {
108 return _indices.data();
109 }
110
121 {
123 return _indices[i];
124 }
125
127 const Index& operator[](Index i) const
128 {
130 return _indices[i];
131 }
132
133 void permute_map(const Adjacency::Permutation& inv_perm)
134 {
135 if(!inv_perm.empty())
136 {
137 for(std::size_t i(0); i < _indices.size(); ++i)
138 _indices.at(i) = inv_perm.map(_indices.at(i));
139 }
140 }
141 }; // class TargetSet
142
144
154 template<typename Shape_>
155 class TargetSetHolder :
156 public TargetSetHolder<typename Shape::FaceTraits<Shape_, Shape_::dimension - 1>::ShapeType>
157 {
158 public:
159 typedef Shape_ ShapeType;
160 static constexpr int shape_dim = ShapeType::dimension;
161
162 protected:
163 typedef TargetSetHolder<typename Shape::FaceTraits<ShapeType, shape_dim - 1>::ShapeType> BaseClass;
164
165 TargetSet _target_set;
166
167 public:
168 TargetSetHolder() :
169 BaseClass(),
170 _target_set()
171 {
172 }
173
174 explicit TargetSetHolder(const Index num_entities[]) :
175 BaseClass(num_entities),
176 _target_set(num_entities[shape_dim])
177 {
178 }
179
180 TargetSetHolder(TargetSetHolder&& other) :
181 BaseClass(std::forward<BaseClass>(other)),
182 _target_set(std::forward<TargetSet>(other._target_set))
183 {
184 }
185
186 TargetSetHolder& operator=(TargetSetHolder&& other)
187 {
188 if(this == &other)
189 return *this;
190 BaseClass::operator=(std::forward<BaseClass>(other));
191 _target_set = std::forward<TargetSet>(other._target_set);
192 return *this;
193 }
194
195 void clone(const TargetSetHolder& other)
196 {
197 BaseClass::clone(other);
198 this->_target_set = other._target_set.clone();
199 }
200
201 TargetSetHolder clone() const
202 {
203 TargetSetHolder tsh;
204 tsh.clone(*this);
205 return tsh;
206 }
207
208 virtual ~TargetSetHolder()
209 {
210 }
211
212 std::size_t bytes() const
213 {
214 return BaseClass::bytes() + _target_set.bytes();
215 }
216
217 template<int dim_>
218 TargetSet& get_target_set()
219 {
220 static_assert(dim_ >= 0, "invalid dimension");
221 static_assert(dim_ <= shape_dim, "invalid dimension");
222 typedef typename Shape::FaceTraits<Shape_, dim_>::ShapeType CellType;
223 return TargetSetHolder<CellType>::_target_set;
224 }
225
226 template<int dim_>
227 const TargetSet& get_target_set() const
228 {
229 static_assert(dim_ >= 0, "invalid dimension");
230 static_assert(dim_ <= shape_dim, "invalid dimension");
231 typedef typename Shape::FaceTraits<Shape_, dim_>::ShapeType CellType;
232 return TargetSetHolder<CellType>::_target_set;
233 }
234
235 Index get_num_entities(int dim) const
236 {
237 XASSERTM(dim <= shape_dim, "invalid dimension parameter");
238 if(dim == shape_dim)
239 {
240 return _target_set.get_num_entities();
241 }
242 return BaseClass::get_num_entities(dim);
243 }
244
245 template<std::size_t np_>
246 void permute_map(const std::array<Adjacency::Permutation, np_>& inv_perms)
247 {
248 BaseClass::permute_map(inv_perms);
249 _target_set.permute_map(inv_perms.at(shape_dim));
250 }
251
252 static String name()
253 {
254 return "TargetSetHolder<" + Shape_::name() + ">";
255 }
256 };
257
261 template<>
262 class TargetSetHolder<Shape::Vertex>
263 {
264 public:
265 typedef Shape::Vertex ShapeType;
266 static constexpr int shape_dim = ShapeType::dimension;
267
268 protected:
269 TargetSet _target_set;
270
271 public:
272 TargetSetHolder() :
273 _target_set()
274 {
275 }
276
277 explicit TargetSetHolder(const Index num_entities[]) :
278 _target_set(num_entities[0])
279 {
280 }
281
282 TargetSetHolder(TargetSetHolder&& other) :
283 _target_set(std::forward<TargetSet>(other._target_set))
284 {
285 }
286
287 TargetSetHolder& operator=(TargetSetHolder&& other)
288 {
289 if(this == &other)
290 return *this;
291 _target_set = std::forward<TargetSet>(other._target_set);
292 return *this;
293 }
294
295 virtual ~TargetSetHolder()
296 {
297 }
298
299 void clone(const TargetSetHolder& other)
300 {
301 this->_target_set = other._target_set.clone();
302 }
303
304 TargetSetHolder clone() const
305 {
306 TargetSetHolder tsh;
307 tsh.clone(*this);
308 return tsh;
309 }
310
311 std::size_t bytes() const
312 {
313 return _target_set.bytes();
314 }
315
316 template<int dim_>
317 TargetSet& get_target_set()
318 {
319 static_assert(dim_ == 0, "invalid dimension");
320 return _target_set;
321 }
322
323 template<int dim_>
324 const TargetSet& get_target_set() const
325 {
326 static_assert(dim_ == 0, "invalid dimension");
327 return _target_set;
328 }
329
330 Index get_num_entities(int dim) const
331 {
332 XASSERTM(dim == 0, "invalid dimension parameter");
333 return _target_set.get_num_entities();
334 }
335
336 template<std::size_t np_>
337 void permute_map(const std::array<Adjacency::Permutation, np_>& inv_perms)
338 {
339 _target_set.permute_map(inv_perms.at(0));
340 }
341
342 static String name()
343 {
344 return "TargetSetHolder<Vertex>";
345 }
346 };
348 } // namespace Geometry
349} // namespace FEAT
#define ASSERT(expr)
Debug-Assertion macro definition.
Definition: assertion.hpp:229
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
bool empty() const
Checks whether the permutation is empty.
Target set class.
Definition: target_set.hpp:27
TargetSet(const std::vector< Index > &idx)
internal clone constructor
Definition: target_set.hpp:33
TargetSet & operator=(TargetSet &&other)
move-assignment operator
Definition: target_set.hpp:63
std::vector< Index > _indices
Index vector. _indices[i] = j means that entity i represents entity j in the parent.
Definition: target_set.hpp:30
const Index * get_indices() const
Definition: target_set.hpp:106
Index & operator[](Index i)
Returns a target index.
Definition: target_set.hpp:120
TargetSet()
standard constructor
Definition: target_set.hpp:40
const Index & operator[](Index i) const
Returns a target index.
Definition: target_set.hpp:127
virtual ~TargetSet()
virtual destructor
Definition: target_set.hpp:75
TargetSet(TargetSet &&other)
move constructor
Definition: target_set.hpp:57
std::size_t bytes() const
Definition: target_set.hpp:86
TargetSet(Index num_entities)
Constructor.
Definition: target_set.hpp:51
TargetSet clone() const
Definition: target_set.hpp:80
Index get_num_entities() const
Returns the number of entities.
Definition: target_set.hpp:92
@ other
generic/other permutation strategy
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.