FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
standard_vertex_refiner.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/vertex_set.hpp>
10#include <kernel/geometry/intern/standard_refinement_traits.hpp>
11
12namespace FEAT
13{
14 namespace Geometry
15 {
17 namespace Intern
18 {
19 template<
20 typename Shape_,
21 typename VertexSet_>
22 struct StandardVertexRefiner;
23
29 template<typename VertexSet_>
30 struct StandardVertexRefiner<Shape::Vertex, VertexSet_>
31 {
32 typedef VertexSet_ VertexSetType;
33
34 static Index refine(
35 Index offset,
36 VertexSetType& vertex_set_out,
37 const VertexSetType& vertex_set_in)
38 {
39 // get the number of coarse mesh vertices
40 const Index num_verts = vertex_set_in.get_num_vertices();
41 XASSERT(vertex_set_out.get_num_vertices() >= offset+num_verts);
42
43 // loop over all vertices
44 FEAT_PRAGMA_OMP(parallel for)
45 for(Index i = 0; i < num_verts; ++i)
46 {
47 // copy source vertex
48 vertex_set_out[offset + i] = vertex_set_in[i];
49 }
50
51 // return number of created vertices
52 return num_verts;
53 }
54 }; // class StandardVertexRefiner<Vertex,...>
55
61 template<
62 int cell_dim_,
63 typename VertexSet_>
64 struct StandardVertexRefiner<Shape::Hypercube<cell_dim_>, VertexSet_>
65 {
66 typedef Shape::Hypercube<cell_dim_> ShapeType;
67 typedef IndexSet<Shape::FaceTraits<ShapeType, 0>::count> IndexSetType;
68 typedef VertexSet_ VertexSetType;
69
70 static Index refine(
71 Index offset,
72 VertexSetType& vertex_set_out,
73 const VertexSetType& vertex_set_in,
74 const IndexSetType& index_set_in)
75 {
76 typedef typename IndexSetType::IndexTupleType IndexTupleType;
77 typedef typename VertexSetType::VertexType VertexType;
78 typedef typename VertexSetType::CoordType CoordType;
79
80 // scaling factor
81 static const CoordType scale = CoordType(1) / CoordType(IndexSetType::num_indices);
82
83 // get number of cells
84 Index num_cells = index_set_in.get_num_entities();
85 XASSERT(vertex_set_out.get_num_vertices() >= offset+num_cells);
86
87 // loop over all cells
88 FEAT_PRAGMA_OMP(parallel for)
89 for(Index i = 0; i < num_cells; ++i)
90 {
91 // get input index vector
92 const IndexTupleType& idx_in = index_set_in[i];
93
94 // get output vertex
95 VertexType& vtx_out = vertex_set_out[offset + i];
96
97 // clear output vertex
98 vtx_out.format();
99
100 // add all other vertices onto it
101 for(int k(0); k < IndexSetType::num_indices; ++k)
102 {
103 vtx_out.axpy(scale, vertex_set_in[idx_in[k]]);
104 }
105 }
106
107 // return number of created vertices
108 return num_cells;
109 }
110 }; // struct StandardVertexRefiner<Hypercube<...>,...>
111
117 template<
118 int cell_dim_,
119 typename VertexSet_>
120 struct StandardVertexRefiner<Shape::Simplex<cell_dim_>, VertexSet_>
121 {
122 typedef Shape::Simplex<cell_dim_> ShapeType;
123 typedef IndexSet<Shape::FaceTraits<ShapeType, 0>::count> IndexSetType;
124 typedef VertexSet_ VertexSetType;
125
126 static Index refine(
127 Index offset,
128 VertexSetType& vertex_set_out,
129 const VertexSetType& vertex_set_in,
130 const IndexSetType& index_set_in)
131 {
132 typedef typename IndexSetType::IndexTupleType IndexTupleType;
133 typedef typename VertexSetType::VertexType VertexType;
134 typedef typename VertexSetType::CoordType CoordType;
135
136 // scaling factor
137 static const CoordType scale = CoordType(1) / CoordType(IndexSetType::num_indices);
138
139 // get number of cells
140 Index num_cells = index_set_in.get_num_entities();
141 XASSERT(vertex_set_out.get_num_vertices() >= offset+num_cells);
142
143 // loop over all cells
144 FEAT_PRAGMA_OMP(parallel for)
145 for(Index i = 0; i < num_cells; ++i)
146 {
147 // get input index vector
148 const IndexTupleType& idx_in = index_set_in[i];
149
150 // get output vertex
151 VertexType& vtx_out = vertex_set_out[offset + i];
152
153 // clear output vertex
154 vtx_out.format();
155
156 // add all other vertices onto it
157 for(int k(0); k < IndexSetType::num_indices; ++k)
158 {
159 vtx_out.axpy(scale, vertex_set_in[idx_in[k]]);
160 }
161 }
162
163 // return number of created vertices
164 return num_cells;
165 }
166 }; // struct VertexRefiner<Simplex<...>,...>
167
173 template<
174 typename VertexSet_>
175 struct StandardVertexRefiner<Shape::Simplex<2>, VertexSet_>
176 {
177 typedef Shape::Simplex<2> ShapeType;
178 typedef IndexSet<Shape::FaceTraits<ShapeType, 0>::count> IndexSetType;
179 typedef VertexSet_ VertexSetType;
180
181 static Index refine(
182 Index /*offset*/,
183 VertexSetType& /*vertex_set_out*/,
184 const VertexSetType& /*vertex_set_in*/,
185 const IndexSetType& /*index_set_in*/)
186 {
187 // return number of created vertices
188 return 0;
189 }
190 }; // struct StandardVertexRefiner<Simplex<...>,...>
191
197 template<
198 typename Shape_,
199 typename VertexSet_>
200 struct StandardVertexRefineWrapper
201 {
202 typedef VertexSet_ VertexSetType;
203 typedef IndexSetHolder<Shape_> IndexSetHolderType;
204 typedef IndexSet<Shape::FaceTraits<Shape_, 0>::count> IndexSetType;
205
206 static Index refine(
207 VertexSetType& vertex_set_out,
208 const VertexSetType& vertex_set_in,
209 const IndexSetHolderType& index_set_holder_in)
210 {
211 typedef typename Shape::FaceTraits<Shape_, Shape_::dimension-1>::ShapeType FacetType;
212
213 // recursive call of VertexRefineWrapper
214 Index offset = StandardVertexRefineWrapper<FacetType, VertexSet_>
215 ::refine(vertex_set_out, vertex_set_in, index_set_holder_in);
216
217 // get index set of current shape
218 const IndexSetType& index_set_in = index_set_holder_in.
219 template get_index_set_wrapper<Shape_::dimension>().template get_index_set<0>();
220
221 // call VertexRefiner
222 Index num_verts = StandardVertexRefiner<Shape_, VertexSet_>
223 ::refine(offset, vertex_set_out, vertex_set_in, index_set_in);
224
225 // validate number of created vertices
226 XASSERTM(num_verts == (StandardRefinementTraits<Shape_, 0>::count * index_set_in.get_num_entities()),
227 "VertexRefiner output does not match StdRefTraits prediction");
228
229 // return new offset
230 return offset + num_verts;
231 }
232 }; // struct StandardVertexRefineWrapper<...>
233
234 template<typename VertexSet_>
235 struct StandardVertexRefineWrapper<Shape::Vertex, VertexSet_>
236 {
237 typedef VertexSet_ VertexSetType;
238 typedef IndexSetHolder<Shape::Vertex> IndexSetHolderType;
239
240 static Index refine(
241 VertexSetType& vertex_set_out,
242 const VertexSetType& vertex_set_in,
243 const IndexSetHolderType& /*index_set_holder_in*/)
244 {
245 // call VertexRefiner
246 Index num_verts = StandardVertexRefiner<Shape::Vertex,VertexSet_>
247 ::refine(0, vertex_set_out, vertex_set_in);
248
249 // validate number of created vertices
250 XASSERTM(num_verts == (StandardRefinementTraits<Shape::Vertex, 0>::count * vertex_set_in.get_num_vertices()),
251 "VertexRefiner output does not match StdRefTraits prediction");
252
253 // return new offset
254 return num_verts;
255 }
256 }; // struct StandardVertexRefineWrapper<Vertex,...>
257 } // namespace Intern
259 } // namespace Geometry
260} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.