8#include <kernel/geometry/intern/adaptive_refinement_utils.hpp>
9#include <kernel/shape.hpp>
10#include <kernel/util/tiny_algebra.hpp>
11#include <kernel/geometry/intern/face_index_mapping.hpp>
19 template<
typename Shape_,
int num_coords_ = Shape_::dimension>
22 static const constexpr int num_coords = num_coords_;
27 std::array<Tiny::Vector<Real, num_coords>, num_vertices> coords;
29 template<
typename... Vector>
30 explicit RawEntity(Vector... vectors) : coords{vectors...}
37 using Mapping = Intern::FaceIndexMapping<Shape_, dim_, 0>;
43 for(
int i(0); i < num_verts; ++i)
45 result.coords.at(std::size_t(i)) = coords[std::size_t(Mapping::map(idx, i))];
52 template<
typename Shape_,
int num_coords_>
55 stream <<
"RawEntity<" << Shape_::name() <<
", " <<
stringify(num_coords_) <<
"> { coords: [ ";
56 for(
const auto& vertex : entity.coords)
64 template<
typename Shape_>
71 std::vector<RawEntity<Shape_>> entities;
73 template<
typename... Vector>
76 entities.emplace_back(vectors...);
83 entity.coords = vertices;
84 entities.push_back(entity);
89 RawTemplate& axis_aligned(
const VertexType& a,
const VertexType& b)
91 static_assert(Shape_::dimension <= 3);
95 static std::array<std::array<Real, 3>, 8> coeffs {{
106 VertexType diff = b - a;
108 std::array<VertexType, num_verts> vertices;
109 for(
int i(0); i < num_verts; ++i)
111 auto& c = coeffs[std::size_t(i)];
113 for(
int j(0); j < Shape_::dimension; ++j)
115 v[j] += c[std::size_t(j)] * diff[j];
117 for (
int j(0); j < v.n; ++j)
119 ASSERTM(v[j] >= 0.0 && v[j] <= 1.0,
"Invalid vertex in axis_aligned");
121 vertices[std::size_t(i)] = v;
123 add_entity(vertices);
128 RawTemplate& grid(std::array<Index, Shape_::dimension> size, VertexType stepsize)
130 std::array<Index, Shape_::dimension> coords = {};
131 _grid(size, stepsize, 0, coords);
143 typedef typename std::vector<RawEntity<Shape_>>::difference_type DiffType;
145 entities.erase(entities.begin() + DiffType(face));
147 for(
const EntityType& entity : tmplt.entities)
151 for(
Index i(0); i < entity.coords.size(); ++i)
153 const auto coeffs = Intern::vertex_coefficients<Shape_>(entity.coords[i]);
154 mapped.coords[i] = Intern::interpolate(parent.coords, coeffs);
156 entities.push_back(mapped);
164 const std::array<Index, Shape_::dimension>& size,
167 std::array<Index, Shape_::dimension>& coords)
169 if (dim == Shape_::dimension)
172 for (
int i = 0; i < Shape_::dimension; ++i)
174 v[i] =
typename VertexType::ValueType(coords[std::size_t(i)]) * stepsize[i];
176 axis_aligned(v, v + stepsize);
180 for(
Index i(0); i < size[std::size_t(dim)]; i++)
182 coords[std::size_t(dim)] = i;
183 _grid(size, stepsize, dim + 1, coords);
190 template<
typename Shape_,
typename FnVert,
typename FnEntity>
191 static RawTemplate<Shape_> transform_template_vertices(FnVert vertex_transform, FnEntity entity_transform, RawTemplate<Shape_>& tmplt)
194 RawTemplate<Shape_> result;
195 for(
auto& entity : tmplt.entities)
197 RawEntity<Shape_> new_entity;
199 for(std::size_t i(0); i < std::size_t(entity.num_vertices); ++i)
201 new_entity.coords.at(i) = vertex_transform(entity.coords.at(i));
204 entity_transform(new_entity);
205 result.entities.push_back(new_entity);
213 template<
typename Shape_>
216 static_assert(Shape_::dimension == 2,
"rotate_template_2d called for non 2D template!");
226 entity.coords = Intern::rotate_arraylike_2d(entity.coords);
229 return transform_template_vertices(rotate, rotate_indices, tmplt);
239 template<
typename Shape_>
242 static_assert(Shape_::dimension == 3,
"rotate_template_2d called for non 2D template!");
251 entity.coords = Intern::rotate_arraylike_xaxis(entity.coords);
254 return transform_template_vertices(rotate, rotate_indices, tmplt);
264 template<
typename Shape_>
267 static_assert(Shape_::dimension == 3,
"rotate_template_2d called for non 2D template!");
276 entity.coords = Intern::rotate_arraylike_yaxis(entity.coords);
279 return transform_template_vertices(rotate, rotate_indices, tmplt);
289 template<
typename Shape_>
292 static_assert(Shape_::dimension == 3,
"rotate_template_2d called for non 2D template!");
301 entity.coords = Intern::rotate_arraylike_zaxis(entity.coords);
304 return transform_template_vertices(rotate, rotate_indices, tmplt);
308 template<
typename TemplateMap,
typename RefinementType_>
309 int create_2dtemplate_rotations(TemplateMap& map,
const RefinementType_& base_type)
312 int templates_created = 1;
314 RefinementType_ type = base_type;
315 auto tmplt = map[type];
317 for(
int i = 0; i < 4; i++)
319 if(map.find(type) == map.end())
322 templates_created += 1;
325 type = type.rotate_2d();
329 return templates_created;
332 template<
typename TemplateMap,
typename RefinementType_>
333 int create_3dtemplate_rotations(TemplateMap& map,
const RefinementType_& base_type)
335 enum class Rotation : std::uint8_t
342 static constexpr std::array<Rotation, 6> rotations = {{
352 int templates_created = 1;
354 RefinementType_ outer_type = base_type;
355 auto outer_template = map[outer_type];
357 for(std::size_t outer_rotation(0); outer_rotation < 6u; outer_rotation++)
359 const Rotation next_outer_rotation = rotations[outer_rotation];
360 if (next_outer_rotation == Rotation::X)
362 outer_type = outer_type.rotate_xaxis();
365 else if (next_outer_rotation == Rotation::Y)
367 outer_type = outer_type.rotate_yaxis();
371 RefinementType_ inner_type = outer_type;
372 auto inner_template = outer_template;
373 for(
int inner_rotation(0); inner_rotation < 4; inner_rotation++)
375 if(map.find(inner_type) == map.end())
377 map[inner_type] = inner_template;
378 templates_created += 1;
381 inner_type = inner_type.rotate_zaxis();
385 return templates_created;
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Tiny Vector class template.
static RawTemplate< Shape_ > rotate_template_yaxis(RawTemplate< Shape_ > &tmplt)
Rotates a raw template 90 degrees counterclockwise around the y-axis.
static RawTemplate< Shape_ > rotate_template_zaxis(RawTemplate< Shape_ > &tmplt)
Rotates a raw template 90 degrees counterclockwise around the z-axis.
static RawTemplate< Shape_ > rotate_template_2d(RawTemplate< Shape_ > &tmplt)
Rotates a raw template 90 degrees counterclockwise around (0.5, 0.5)
static RawTemplate< Shape_ > rotate_template_xaxis(RawTemplate< Shape_ > &tmplt)
Rotates a raw template 90 degrees counterclockwise around the x-axis.
String stringify(const T_ &item)
Converts an item into a String.
std::uint64_t Index
Index data type.
RawTemplate & recurse(Index face, const RawTemplate &tmplt)
Recursively applies a template to a face of this template.
Face traits tag struct template.