FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
dof_mapping_common.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/space/dof_mapping_base.hpp>
11
12namespace FEAT
13{
14 namespace Space
15 {
29 template<
30 typename Space_,
31 int dofs_per_cell_ = 1>
33 public DofMappingBase<Space_>
34 {
35 protected:
37 explicit DofMappingIdentity(const Space_& space) :
38 DofMappingBase<Space_>(space)
39 {
40 }
41
42 public:
45 {
46 return dofs_per_cell_;
47 }
48
51 {
52 return this->_space.get_trafo().get_mesh().get_num_entities(Space_::shape_dim) * Index(dofs_per_cell_);
53 }
54
56 Index get_index(int local_dof_idx) const
57 {
58 return Index(dofs_per_cell_) * this->_cell_index + Index(local_dof_idx);
59 }
60 }; // class DofMappingIdentity<...>
61
79 template<
80 typename Space_,
81 int codim_,
82 int dofs_per_cell_ = 1>
84 public DofMappingBase<Space_>
85 {
86 public:
88 typedef Space_ SpaceType;
90 typedef typename SpaceType::ShapeType ShapeType;
91
93 static constexpr int shape_dim = ShapeType::dimension;
95 static constexpr int dof_dim = shape_dim - codim_;
96
97 // make sure the dof-dimension is less than the shape dimension
98 static_assert((codim_ >= 0) && (codim_ <= shape_dim), "invalid co-dimension");
99
100 protected:
102 typedef typename SpaceType::TrafoType TrafoType;
104 typedef typename TrafoType::MeshType MeshType;
106 typedef typename MeshType::template IndexSet<shape_dim, dof_dim>::Type IndexSetType;
107
108 protected:
111
112 public:
114 explicit DofMappingSingleEntity(const Space_& space) :
115 DofMappingBase<Space_>(space),
116 _index_set(space.get_trafo().get_mesh().template get_index_set<shape_dim, dof_dim>())
117 {
118 }
119
122 {
123 return IndexSetType::num_indices * dofs_per_cell_;
124 }
125
128 {
129 return this->_space.get_trafo().get_mesh().get_num_entities(dof_dim) * Index(dofs_per_cell_);
130 }
131
133 Index get_index(int local_dof_idx) const
134 {
135 int ldi_q = local_dof_idx / dofs_per_cell_;
136 int ldi_r = local_dof_idx % dofs_per_cell_;
137 return Index(dofs_per_cell_) * _index_set(this->_cell_index, ldi_q) + Index(ldi_r);
138 }
139 };
140
146 template<
147 typename Space_,
148 int dofs_per_cell_>
149 class DofMappingSingleEntity<Space_, 0, dofs_per_cell_> :
150 public DofMappingIdentity<Space_, dofs_per_cell_>
151 {
152 public:
154 explicit DofMappingSingleEntity(const Space_& space) :
155 DofMappingIdentity<Space_, dofs_per_cell_>(space)
156 {
157 }
158 };
159
161 namespace Intern
162 {
163 template<
164 typename Shape_,
165 template<typename, int> class Traits_,
166 typename Tag_,
167 int cell_dim_ = Shape_::dimension,
168 int shape_dim_ = Shape_::dimension>
169 struct UniformDofMappingHelper;
170 } // namespace Intern
172
187 template<
188 typename Space_,
189 template<typename Tag_, int dim_> class DofTraits_,
190 typename DofTag_>
192 : public DofMappingBase<Space_>
193 {
194 public:
198 typedef Space_ SpaceType;
200 typedef typename SpaceType::ShapeType ShapeType;
201
202 // total number of local dofs
203 static constexpr int dof_count = Intern::UniformDofMappingHelper<ShapeType, DofTraits_, DofTag_>::dof_count;
204
205 private:
207 Index dof_idx[dof_count];
208
209 public:
210 explicit DofMappingUniform(const SpaceType& space) :
211 BaseClass(space)
212 {
213 }
214
216 void prepare(Index cell_index)
217 {
218 BaseClass::prepare(cell_index);
219 Index count(0);
220 Intern::UniformDofMappingHelper<ShapeType, DofTraits_, DofTag_>
221 ::assemble(dof_idx, this->_space.get_mesh(), cell_index, count);
222 XASSERTM(count == Index(dof_count), "dof-count mismatch");
223 }
224
227 {
228 return dof_count;
229 }
230
233 {
234 return Intern::UniformDofMappingHelper<ShapeType, DofTraits_, DofTag_>::global_count(this->_space.get_mesh());
235 }
236
238 Index get_index(int local_dof_idx) const
239 {
240 ASSERTM((local_dof_idx >= 0) && (local_dof_idx < dof_count), "local dof-index out-of-range");
241 return dof_idx[local_dof_idx];
242 }
243 };
244
246 namespace Intern
247 {
248 template<typename Shape_, template<typename, int> class Traits_, typename Tag_, int cell_dim_, int shape_dim_>
249 struct UniformDofMappingHelper
250 {
251 static_assert(cell_dim_ < shape_dim_, "invalid cell dimension");
252
253 static constexpr int cell_count = Shape::FaceTraits<Shape_, cell_dim_>::count;
254 // number of dofs per cell
255 static constexpr int dofs_per_cell = Traits_<Tag_, cell_dim_>::count;
256 // number of dofs for all cells of this dimension
257 static constexpr int dof_cell_count = cell_count * dofs_per_cell;
258 // total dof count
259 static constexpr int dof_count = UniformDofMappingHelper<Shape_, Traits_, Tag_, cell_dim_-1>::dof_count + dof_cell_count;
260
261 template<typename MeshType_>
262 static Index assemble(Index dof_idx[], const MeshType_& mesh, Index cell, Index& k)
263 {
264 Index offs(UniformDofMappingHelper<Shape_, Traits_, Tag_, cell_dim_-1>::assemble(dof_idx, mesh, cell, k));
265
266 const auto& index_set(mesh.template get_index_set<shape_dim_, cell_dim_>());
267 for(int i(0); i < cell_count; ++i)
268 {
269 for(int j(0); j < dofs_per_cell; ++j, ++k)
270 {
271 dof_idx[k] = offs + index_set(cell,i) * Index(dofs_per_cell) + Index(j);
272 }
273 }
274 return offs + Index(dofs_per_cell) * mesh.get_num_entities(cell_dim_);
275 }
276
277 template<typename MeshType_>
278 static Index global_count(const MeshType_& mesh)
279 {
280 return UniformDofMappingHelper<Shape_, Traits_, Tag_, cell_dim_-1>::global_count(mesh) +
281 Index(Traits_<Tag_, cell_dim_>::count) * mesh.get_num_entities(cell_dim_);
282 }
283 };
284
285 // specialization for cell_dim_ = shape_dim_
286 template<typename Shape_, template<typename, int> class Traits_, typename Tag_, int cell_dim_>
287 struct UniformDofMappingHelper<Shape_, Traits_, Tag_, cell_dim_, cell_dim_>
288 {
289 // number of dofs per cell
290 static constexpr int dofs_per_cell = Traits_<Tag_, cell_dim_>::count;
291 // number of dofs for all cells of this dimension
292 static constexpr int dof_cell_count = dofs_per_cell;
293 // total dof count
294 static constexpr int dof_count = UniformDofMappingHelper<Shape_, Traits_, Tag_, cell_dim_-1>::dof_count + dof_cell_count;
295
296 template<typename MeshType_>
297 static Index assemble(Index dof_idx[], const MeshType_& mesh, Index cell, Index& k)
298 {
299 Index offs(UniformDofMappingHelper<Shape_, Traits_, Tag_, cell_dim_-1>::assemble(dof_idx, mesh, cell, k));
300
301 for(int j(0); j < dofs_per_cell; ++j, ++k)
302 {
303 dof_idx[k] = offs + cell * dofs_per_cell + Index(j);
304 }
305 return offs + Index(dofs_per_cell) * mesh.get_num_entities(cell_dim_);
306 }
307
308 template<typename MeshType_>
309 static Index global_count(const MeshType_& mesh)
310 {
311 return UniformDofMappingHelper<Shape_, Traits_, Tag_, cell_dim_-1>::global_count(mesh) +
312 Index(Traits_<Tag_, cell_dim_>::count) * mesh.get_num_entities(cell_dim_);
313 }
314 };
315
316 // specialization for cell_dim_ = 0
317 template<typename Shape_, template<typename, int> class Traits_, typename Tag_, int shape_dim_>
318 struct UniformDofMappingHelper<Shape_, Traits_, Tag_, 0, shape_dim_>
319 {
320 static constexpr int cell_count = Shape::FaceTraits<Shape_, 0>::count;
321 // number of dofs per cell
322 static constexpr int dofs_per_cell = Traits_<Tag_, 0>::count;
323 // number of dofs for all cells of this dimension
324 static constexpr int dof_cell_count = cell_count * dofs_per_cell;
325 // total dof count
326 static constexpr int dof_count = dof_cell_count;
327
328 template<typename MeshType_>
329 static Index assemble(Index dof_idx[], const MeshType_& mesh, Index cell, Index& k)
330 {
331 const auto& index_set(mesh.template get_index_set<shape_dim_, 0>());
332
333 k = 0;
334 for(int i(0); i < cell_count; ++i)
335 {
336 for(int j(0); j < dofs_per_cell; ++j, ++k)
337 {
338 dof_idx[k] = index_set(cell,i) * dofs_per_cell + Index(j);
339 }
340 }
341 return Index(dofs_per_cell) * mesh.get_num_entities(0);
342 }
343
344 template<typename MeshType_>
345 static Index global_count(const MeshType_& mesh)
346 {
347 return Index(Traits_<Tag_, 0>::count) * mesh.get_num_entities(0);
348 }
349 };
350 } // namespace Intern
352 } // namespace Space
353} // namespace FEAT
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Mapping from mesh cells to Dof that have support on them.
const SpaceType & _space
space reference
void prepare(Index cell_index)
Prepares the dof-mapping for a given cell.
Index _cell_index
currently active cell index
Identity-Dof-Mapping base-class template.
Index get_index(int local_dof_idx) const
Returns the mapped dof index.
int get_num_local_dofs() const
Returns the number of local dofs.
DofMappingIdentity(const Space_ &space)
constructor
Index get_num_global_dofs() const
Return the number of global dofs.
Single-Entity Dof-Mapping class template.
const IndexSetType & _index_set
dofs-at-cell index set reference
int get_num_local_dofs() const
Returns the number of local dofs.
SpaceType::TrafoType TrafoType
trafo type
MeshType::template IndexSet< shape_dim, dof_dim >::Type IndexSetType
index-set type
SpaceType::ShapeType ShapeType
shape type
static constexpr int shape_dim
shape dimension
static constexpr int dof_dim
dof dimension
TrafoType::MeshType MeshType
mesh type
Index get_index(int local_dof_idx) const
Returns the mapped dof index.
DofMappingSingleEntity(const Space_ &space)
constructor
Index get_num_global_dofs() const
Return the number of global dofs.
Uniform Dof-Mapping class template.
DofMappingBase< Space_ > BaseClass
base-class typedef
int get_num_local_dofs() const
Returns the number of local dofs.
void prepare(Index cell_index)
Prepares the dof-mapping for a given cell.
Index dof_idx[dof_count]
dof index vector
SpaceType::ShapeType ShapeType
shape typedef
Index get_num_global_dofs() const
Return the number of global dofs.
Index get_index(int local_dof_idx) const
Returns the mapped dof index.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.
Face traits tag struct template.
Definition: shape.hpp:106