FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
macro_index_mapping.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/geometry/index_set.hpp>
10#include <kernel/geometry/target_set.hpp>
11#include <kernel/geometry/intern/face_index_mapping.hpp>
12
13namespace FEAT
14{
15 namespace Geometry
16 {
18 namespace Intern
19 {
20 template<
21 typename Shape_,
22 int face_dim_ = Shape_::dimension>
23 struct DynamicNumFaces
24 {
25 static int value(int dim)
26 {
27 ASSERT((dim <= face_dim_) && (dim >= 0));
28 if(dim == face_dim_)
29 return Shape::FaceTraits<Shape_, face_dim_>::count;
30 else
31 return DynamicNumFaces<Shape_, face_dim_ - 1>::value(dim);
32 }
33 };
34
35 template<typename Shape_>
36 struct DynamicNumFaces<Shape_, 0>
37 {
38 static int value(int /*dim*/)
39 {
40 return Shape::FaceTraits<Shape_, 0>::count;
41 }
42 };
43
44 template<
45 typename Shape_,
46 int cell_dim_,
47 int face_dim_,
48 int shape_dim_ = Shape_::dimension>
49 struct MacroIndexBuilder
50 {
51 typedef typename Shape::FaceTraits<Shape_, cell_dim_>::ShapeType CellType;
52 static constexpr int num_cells = Shape::FaceTraits<Shape_, cell_dim_>::count;
53 static constexpr int num_indices = Shape::FaceTraits<CellType, face_dim_>::count;
54
55 static void build(IndexSet<num_indices>& idx)
56 {
57 typedef FaceIndexMapping<Shape_, cell_dim_, face_dim_> FimType;
58 for(Index i(0); i < Index(num_cells); ++i)
59 {
60 for(int j(0); j < num_indices; ++j)
61 {
62 idx(i, j) = Index(FimType::map(int(i), j));
63 }
64 }
65 }
66 };
67
68 template<
69 typename Shape_,
70 int cell_dim_,
71 int face_dim_>
72 struct MacroIndexBuilder<Shape_, cell_dim_, face_dim_, cell_dim_>
73 {
74 static constexpr int num_indices = Shape::FaceTraits<Shape_, face_dim_>::count;
75
76 static void build(IndexSet<num_indices>& idx)
77 {
78 for(int j(0); j < num_indices; ++j)
79 {
80 idx(0, j) = Index(j);
81 }
82 }
83 };
84
85 template<
86 typename Shape_,
87 int cell_dim_,
88 int face_dim_ = cell_dim_ - 1>
89 struct MacroIndexHelper
90 {
91 typedef typename Shape::FaceTraits<Shape_, cell_dim_>::ShapeType CellType;
92 static void build(IndexSetWrapper<CellType, face_dim_>& idx)
93 {
94 // recurse down
95 MacroIndexHelper<Shape_, cell_dim_, face_dim_ - 1>::build(idx);
96
97 // call builder
98 MacroIndexBuilder<Shape_, cell_dim_, face_dim_>::build(idx.template get_index_set<face_dim_>());
99 }
100 };
101
102 template<
103 typename Shape_,
104 int cell_dim_>
105 struct MacroIndexHelper<Shape_, cell_dim_, 0>
106 {
107 typedef typename Shape::FaceTraits<Shape_, cell_dim_>::ShapeType CellType;
108 static void build(IndexSetWrapper<CellType, 0>& idx)
109 {
110 // call builder
111 MacroIndexBuilder<Shape_, cell_dim_, 0>::build(idx.template get_index_set<0>());
112 }
113 };
114
115 template<
116 typename Shape_,
117 int cell_dim_ = Shape_::dimension>
118 struct MacroIndexWrapper
119 {
120 typedef typename Shape::FaceTraits<Shape_, cell_dim_>::ShapeType CellType;
121 static void build(IndexSetHolder<CellType>& idx)
122 {
123 // recurse down
124 MacroIndexWrapper<Shape_, cell_dim_ - 1>::build(idx);
125
126 // call helper
127 MacroIndexHelper<Shape_, cell_dim_>::build(idx.template get_index_set_wrapper<cell_dim_>());
128 }
129 };
130
131 template<typename Shape_>
132 struct MacroIndexWrapper<Shape_, 0>
133 {
134 static void build(IndexSetHolder<Shape::Vertex>&)
135 {
136 // do nothing
137 }
138 };
139
140 template<typename Shape_, int face_dim_ = Shape_::dimension-1>
141 struct MacroTargetWrapper
142 {
143 static void build(TargetSetHolder<Shape_>& trg, const IndexSetHolder<Shape_>& ish, const Index cell_idx)
144 {
145 // get our target set
146 TargetSet& target = trg.template get_target_set<face_dim_>();
147
148 // get our number of local faces
149 static constexpr int num_faces = Shape::FaceTraits<Shape_, face_dim_>::count;
150
151 // validate size
152 XASSERTM(target.get_num_entities() == Index(num_faces), "invalid target set size");
153
154 // get the index set
155 const IndexSet<num_faces>& idx = ish.template get_index_set<Shape_::dimension, face_dim_>();
156
157 // loop over all faces
158 for(int i(0); i < num_faces; ++i)
159 {
160 target[Index(i)] = idx(cell_idx, i);
161 }
162
163 // recurse down
164 MacroTargetWrapper<Shape_, face_dim_-1>::build(trg, ish, cell_idx);
165 }
166 };
167
168 template<typename Shape_>
169 struct MacroTargetWrapper<Shape_, 0>
170 {
171 static void build(TargetSetHolder<Shape_>& trg, const IndexSetHolder<Shape_>& ish, const Index cell_idx)
172 {
173 // get our target set
174 TargetSet& target = trg.template get_target_set<0>();
175
176 // get our number of local faces
177 static constexpr int num_faces = Shape::FaceTraits<Shape_,0>::count;
178
179 // validate size
180 XASSERTM(target.get_num_entities() == Index(num_faces), "invalid target set size");
181
182 // get the index set
183 const IndexSet<num_faces>& idx = ish.template get_index_set<Shape_::dimension, 0>();
184
185 // loop over all faces
186 for(int i(0); i < num_faces; ++i)
187 {
188 target[Index(i)] = idx(cell_idx, i);
189 }
190 }
191 };
192 } // namespace Intern
194 } // namespace Geometry
195} // 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
FEAT namespace.
Definition: adjactor.hpp:12
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.