9#include <kernel/geometry/intern/congruency_mapping.hpp>
10#include <kernel/geometry/intern/congruency_sampler.hpp>
11#include <kernel/geometry/intern/congruency_trafo.hpp>
12#include <kernel/geometry/intern/face_index_mapping.hpp>
13#include <kernel/geometry/raw_refinement_templates.hpp>
14#include <kernel/geometry/refinement_types.hpp>
15#include <kernel/shape.hpp>
17#include <kernel/util/string.hpp>
18#include <kernel/util/tiny_algebra.hpp>
23#include <unordered_map>
34 template<
typename Shape_>
35 constexpr int orientations()
37 if constexpr(std::is_same_v<Shape_, Shape::Hypercube<1>>)
42 if constexpr(std::is_same_v<Shape_, Shape::Hypercube<2>>)
59 bool is_same_vertex(
const Tiny::Vector<Real, n_>& a,
const Tiny::Vector<Real, n_>& b)
64 for(
int i(0); i < n_; ++i)
88 template<
typename Shape_,
int num_coords_ = Shape_::dimension>
89 bool is_same_raw_entity(
const RawEntity<Shape_, num_coords_>& a,
const RawEntity<Shape_, num_coords_>& b)
91 return std::is_permutation(a.coords.begin(), a.coords.end(), b.coords.begin(), Intern::is_same_vertex<num_coords_>);
102 template<
typename Shape_,
int num_coords_ = Shape_::dimension>
103 std::vector<Tiny::Vector<Real, num_coords_>> all_vertices(
const std::vector<RawEntity<Shape_, num_coords_>>& entities)
105 std::vector<Tiny::Vector<Real, num_coords_>> vertices;
107 for(
const auto& entity : entities)
109 for(
const auto& vertex : entity.coords)
111 vertices.push_back(vertex);
130 bool is_internal_vertex(Tiny::Vector<Real, n_> vertex)
135 bool is_internal =
true;
136 for(
int i(0); i < n_; ++i)
138 if(vertex[i] < tol || (1 - tol) < vertex[i])
158 template<
typename Shape_,
int num_coords_ = Shape_::dimension>
159 bool is_internal_entity(
const RawEntity<Shape_, num_coords_>& entity)
161 Tiny::Vector<Real, num_coords_> centroid(0);
162 for(
const auto& vertex : entity.coords)
166 return is_internal_vertex((1.0 / entity.coords.size()) * centroid);
170 template<
typename T_,
typename Comp>
171 std::vector<T_> deduplicate(Comp comparison,
const std::vector<T_>& list)
173 std::vector<T_> deduplicated;
174 for(
const T_& current : list)
176 auto pred = [&](T_& t) {
return comparison(current, t); };
177 bool is_new = !std::any_of(deduplicated.begin(), deduplicated.end(), pred);
180 deduplicated.push_back(current);
187 template<
typename T_,
typename Predicate_>
188 std::vector<T_> filter(Predicate_ predicate,
const std::vector<T_>& list)
190 std::vector<T_> filtered;
191 for(
const T_& current : list)
193 if(predicate(current))
195 filtered.push_back(current);
202 template<
typename Shape_>
203 std::vector<Tiny::Vector<Real, Shape_::dimension>> internal_vertices(
const RawTemplate<Shape_>& tmplt)
205 std::vector<Tiny::Vector<Real, Shape_::dimension>> vertices;
207 for(
const auto& entity : tmplt.entities)
209 for(
const auto& vertex : entity.coords)
211 vertices.push_back(vertex);
215 vertices = filter([](
auto vertex) {
return is_internal_vertex(vertex); }, vertices);
216 vertices = deduplicate([](
auto a,
auto b) {
return Intern::is_same_vertex(a, b); }, vertices);
222 template<
typename Shape_,
int face_dim_,
int num_coords_ = Shape_::dimension>
223 std::vector<RawEntity<typename Shape::FaceTraits<Shape_, face_dim_>::ShapeType, num_coords_>>
224 internal_entities(
const std::vector<RawEntity<Shape_, num_coords_>>& entities)
226 if constexpr(Shape_::dimension == face_dim_)
232 static constexpr const int faces_per_entity = Shape::FaceTraits<Shape_, face_dim_>::count;
234 std::vector<RawEntity<typename Shape::FaceTraits<Shape_, face_dim_>::ShapeType, num_coords_>> result;
236 for(
const auto& entity : entities)
238 for(
int i(0); i < faces_per_entity; ++i)
240 result.push_back(entity.template face<face_dim_>(i));
244 result = filter([](
auto& entity) {
return is_internal_entity(entity); }, result);
245 result = deduplicate([](
auto& a,
auto& b) {
return Intern::is_same_raw_entity(a, b); }, result);
252 template<
typename Shape_>
253 static Tiny::Vector<Real, Shape_::dimension>
254 orient_vertex(
const Tiny::Vector<Real, Shape_::dimension>& vertex,
int orientation)
256 static constexpr int num_coords = Shape_::dimension;
257 using Trafo = Intern::CongruencyTrafo<Shape_>;
259 Tiny::Vector<Real, num_coords> offset(0.5);
261 Tiny::Matrix<Real, num_coords, num_coords> transform(0.0);
262 Tiny::Vector<Real, num_coords> unused(0.0);
263 Trafo::compute(transform, unused, orientation);
265 Tiny::Vector<Real, num_coords> result;
266 result.set_mat_vec_mult(transform, (vertex - offset));
268 return result + offset;
272 template<
typename Shape_,
int num_coords_ = Shape_::dimension>
273 static RawEntity<Shape_, num_coords_> orient_raw_entity(
const RawEntity<Shape_, num_coords_>& entity,
int orientation)
275 RawEntity<Shape_, num_coords_> result;
276 for(
int i(0); i < entity.coords.size(); i++)
278 result.coords[i] = Intern::orient_vertex<Shape_>(entity.coords[i], orientation);
293 template<
typename Shape_,
int source_dim_>
325 XABORTM(
"Invalid face-edge index.");
373 XABORTM(
"Invalid cell-edge index.");
409 XABORTM(
"Invalid cell-edge index.");
415 template<
typename Shape_>
418 static constexpr int num_coords = Shape_::dimension;
421 std::array<Tiny::Vector<Real, num_coords>, num_vertices> vertices;
423 for(
int i(0); i < num_vertices; i++)
427 for(
int j(0); j < num_coords; ++j)
431 vertices[i] = vertex;
458 inline std::ostream& operator<<(std::ostream& stream,
EntitySource source)
460 static std::unordered_map<EntitySource, String> mapping{
466 stream << mapping[source];
500 bool operator!=(
const EntityReference& rhs)
const
502 return !(*
this == rhs);
507 inline std::ostream& operator<<(std::ostream& stream,
const EntityReference& reference)
509 stream <<
"EntityReference {"
525 template<
typename Shape_,
int reference_dim_ = Shape_::dimension - 1>
540 std::array<EntityReference, Shape::FaceTraits<Shape_, dim_>::count>&
get_references()
551 const std::array<EntityReference, Shape::FaceTraits<Shape_, dim_>::count>&
get_references()
const
574 template<
typename Shape_>
591 static_assert(dim_ == 0,
"invalid reference dimension");
603 static_assert(dim_ == 0,
"invalid reference dimension");
625 template<
typename Shape_,
typename CoShape_ = Shape_>
627 :
RefinementTemplate<Shape_, typename Shape::FaceTraits<CoShape_, CoShape_::dimension - 1>::ShapeType>
673 if constexpr(dim_ > Shape_::dimension)
677 else if constexpr(dim_ > 0 && dim_ <= Shape_::dimension)
701 template<
typename Shape_>
708 std::vector<Tiny::Vector<Real, Shape_::dimension>>
vertices;
719 const std::vector<Tiny::Vector<Real, Shape_::dimension>>&
get_vertices()
const
727 return vertex_coefficients;
733 return vertex_coefficients;
744 static_assert(dim_ == 0);
746 return vertices.size();
812 template<
typename RawData_,
typename Shape_,
int dim_ = Shape_::dimension>
815 static constexpr int num_orientations = Intern::orientations<Shape_>();
818 using RefinementTypeByShape =
typename RawData_::template RefinementTypeByShape<S>;
820 std::unordered_map<RefinementTypeByShape<Shape_>, std::array<OrientationMapping, num_orientations>> mappings = {};
825 static_assert(n_ <= dim_);
827 ASSERT(orientation < num_orientations);
830 if(mappings_n.find(type) == mappings_n.end())
832 mappings_n[type] = {};
835 return mappings_n.at(type)[orientation];
839 const OrientationMapping& get_mapping(RefinementTypeByShape<Shape_> type,
int orientation)
const
841 static_assert(n_ <= dim_);
843 ASSERT(mappings.find(type) != mappings.end());
844 ASSERT(orientation < num_orientations);
847 return mappings_n.at(type)[orientation];
857 template<
typename RawData_,
typename Shape_>
860 static constexpr int num_orientations = Intern::orientations<Shape_>();
863 using RefinementTypeByShape =
typename RawData_::template RefinementTypeByShape<S>;
865 std::unordered_map<RefinementTypeByShape<Shape_>, std::array<OrientationMapping, num_orientations>> mappings = {};
870 static_assert(n_ == 0);
872 ASSERT(mappings.find(type) != mappings.end());
873 ASSERT(orientation < num_orientations);
879 const OrientationMapping& get_mapping(RefinementTypeByShape<Shape_> type,
int orientation)
const
881 static_assert(n_ == 0);
883 ASSERT(mappings.find(type) != mappings.end());
884 ASSERT(orientation < num_orientations);
895 template<
typename RawData_,
typename Shape_>
902 using RefinementTypeByDim =
typename RawData_::template RefinementTypeByDim<dim_>;
904 template<
int dim_,
int codim_>
906 get_mapping(RefinementTypeByDim<dim_> type,
int orientation)
914 template<
int dim_,
int codim_>
916 get_mapping(RefinementTypeByDim<dim_> type,
int orientation)
const
931 template<
typename RawData_>
942 template<
typename Shape_,
int num_coords_>
958 template<
typename Shape_,
int num_coords_>
961 stream <<
"EntitySearchEntry<" << Shape_::name() <<
", " << num_coords_ <<
"> { raw_entity: " << entry.
raw_entity
962 <<
", reference: " << entry.
reference <<
" }";
980 template<
typename Shape_,
int num_coords_ = Shape_::dimension>
982 :
public TemplateSearchSpace<typename Shape::FaceTraits<Shape_, Shape_::dimension - 1>::ShapeType, num_coords_>
990 static const constexpr int num_coords = num_coords_;
1008 static_assert(dim_ <= Shape_::dimension);
1009 static_assert(dim_ >= 0);
1017 const std::vector<EntryByDim<dim_>>&
entries()
const
1019 static_assert(dim_ <= Shape_::dimension);
1020 static_assert(dim_ >= 0);
1036 template<
typename Shape__>
1052 template<
typename Shape__>
1067 template<
typename EntityShape_,
int dim_ = EntityShape_::dimension>
1070 static_assert(EntityShape_::dimension <= ShapeType::dimension);
1079 if constexpr(dim_ == 0)
1081 auto& vertices = this->
template entries<0>();
1082 Index vertex_index = 0;
1083 for(
const auto& vertex : Intern::internal_vertices(tmplt))
1086 vertices.emplace_back(entity,
EntityReference{source, vertex_index++, 0, parent_index});
1093 auto&
entries = this->
template entries<dim_>();
1097 for(
const auto& entity : Intern::internal_entities<EntityShape_, dim_>(tmplt.entities))
1101 for(
int i(0); i < num_vertices; i++)
1103 embedded.coords[i] = Embedder::embed(parent_index, entity.coords[i]);
1117 template<
int dim_ = ShapeType::dimension - 1>
1122 std::array<Tiny::Vector<Real, num_coords>, num_vertices> vertices = Intern::topology_vertices<ShapeType>();
1129 template<
int dim_ = ShapeType::dimension - 1>
1133 if constexpr(dim_ == 0)
1137 auto&
entries = this->
template entries<0>();
1139 for(
int vertex(0); vertex < num_vertices; vertex++)
1142 entity.coords[0] = vertices[vertex];
1149 using FaceMapping = Intern::FaceIndexMapping<ShapeType, dim_, 0>;
1154 auto&
entries = this->
template entries<dim_>();
1155 for(
int face(0); face < num_faces; face++)
1159 for(
int vertex(0); vertex < num_vertices; vertex++)
1161 entity.coords[vertex] = vertices[FaceMapping::map(face, vertex)];
1173 auto comp = [&](
auto entry) {
return Intern::is_same_raw_entity(entry.raw_entity, entity); };
1178 std::cout <<
"Searching for entity " << entity <<
"\n";
1179 XABORTM(
"Entity not in search space");
1185 using CongruencySampler = Intern::CongruencySampler<Shape_>;
1187 int orientation = CongruencySampler::compare_with(entity.coords.data(), it->raw_entity.coords.data(), Intern::is_same_vertex<num_coords_>);
1192 if constexpr(num_coords_ < 3)
1218 template<
int num_coords_>
1229 static const constexpr int num_coords = num_coords_;
1235 static_assert(dim_ == 0);
1243 static_assert(dim_ == 0);
1260 for(
const auto& entry : _entries)
1262 if(Intern::is_same_vertex(vertex, entry.raw_entity.coords[0]))
1264 return entry.reference;
1267 std::cout <<
"Vertex: " << vertex <<
" not found\n";
1268 XABORTM(
"Vertex not in search space");
1296 for(
const auto& entry : _entries)
1298 if(entry.reference == reference)
1300 return entry.raw_entity.coords[0];
1303 XABORTM(
"EntifyReference not in search space!");
1321 template<
class RawData_>
1368 std::array<std::array<std::uint64_t, 2>, 4> _edge_type_adjustments = {};
1370 std::array<std::array<std::uint64_t, 4>, 16> _face_type_adjustments = {};
1372 std::array<std::array<std::uint64_t, 8>, 256> _cell_type_adjustments = {};
1375 std::array<bool, 4> _type_adjustment_initialized = {
false,
false,
false,
false};
1380 if(_edge_templates.empty())
1382 _edge_templates = _build<1>(RawData_::raw_edges());
1384 return _edge_templates;
1390 if(_face_templates.empty())
1392 _face_templates = _build<2>(RawData_::raw_faces());
1394 return _face_templates;
1400 if(_cell_templates.empty())
1402 _cell_templates = _build<3>(RawData_::raw_cells());
1404 return _cell_templates;
1409 const RefinementTemplateByDim<dim_>& get_template(RefinementTypeByDim<dim_> type)
1411 if constexpr(dim_ == 1)
1413 return edges().at(type);
1415 else if constexpr(dim_ == 2)
1417 return faces().at(type);
1419 else if constexpr(dim_ == 3)
1421 return cells().at(type);
1423 XABORTM(
"Unsupported template dimension!");
1427 bool has_template(RefinementTypeByDim<dim_> type)
1429 if constexpr(dim_ == 1)
1431 return edges().find(type) != edges().end();
1433 else if constexpr(dim_ == 2)
1435 return faces().find(type) != faces().end();
1437 else if constexpr(dim_ == 3)
1439 return cells().find(type) != cells().end();
1441 XABORTM(
"Unsupported template dimension!");
1447 template<
int dim_,
int codim_>
1450 return _orientation_mappings.template get_mapping<dim_, codim_>(type, orientation)(idx);
1470 const std::array<std::uint64_t, Shape::FaceTraits<Shape::Hypercube<dim_>, 0>::count>&
1471 type_adjustment(
Index type)
1473 if constexpr(dim_ == 1)
1475 if(!_type_adjustment_initialized[1])
1477 _create_type_adjustments<Shape::Hypercube<dim_>>(edges());
1479 return _edge_type_adjustments.at(type);
1481 else if constexpr(dim_ == 2)
1483 if(!_type_adjustment_initialized[2])
1485 _create_type_adjustments<Shape::Hypercube<dim_>>(faces());
1487 return _face_type_adjustments.at(type);
1489 else if constexpr(dim_ == 3)
1491 if(!_type_adjustment_initialized[3])
1493 _create_type_adjustments<Shape::Hypercube<dim_>>(cells());
1495 return _cell_type_adjustments.at(type);
1497 XABORTM(
"Unsupported template dimension!");
1503 std::array<Index, 4> maxima = {0, 0, 0, 0};
1505 for(
const auto& entry : edges())
1507 maxima[0] =
Math::max(maxima[0], entry.second.template num_entities<0>());
1508 maxima[1] =
Math::max(maxima[1], entry.second.template num_entities<1>());
1510 std::cout <<
"Edges:\n";
1511 std::cout <<
" Max Vertices: " <<
stringify(
unsigned(maxima[0])) <<
"\n";
1512 std::cout <<
" Max Edges: " <<
stringify(
unsigned(maxima[1])) <<
"\n";
1514 maxima = {0, 0, 0, 0};
1515 for(
const auto& entry : faces())
1517 maxima[0] =
Math::max(maxima[0], entry.second.template num_entities<0>());
1518 maxima[1] =
Math::max(maxima[1], entry.second.template num_entities<1>());
1519 maxima[2] =
Math::max(maxima[2], entry.second.template num_entities<2>());
1521 std::cout <<
"Faces:\n";
1522 std::cout <<
" Max Vertices: " <<
stringify(
unsigned(maxima[0])) <<
"\n";
1523 std::cout <<
" Max Edges: " <<
stringify(
unsigned(maxima[1])) <<
"\n";
1524 std::cout <<
" Max Faces: " <<
stringify(
unsigned(maxima[2])) <<
"\n";
1526 maxima = {0, 0, 0, 0};
1527 for(
const auto& entry : cells())
1529 maxima[0] =
Math::max(maxima[0], entry.second.template num_entities<0>());
1530 maxima[1] =
Math::max(maxima[1], entry.second.template num_entities<1>());
1531 maxima[2] =
Math::max(maxima[2], entry.second.template num_entities<2>());
1532 maxima[3] =
Math::max(maxima[3], entry.second.template num_entities<3>());
1534 std::cout <<
"Faces:\n";
1535 std::cout <<
" Max Vertices: " <<
stringify(
unsigned(maxima[0])) <<
"\n";
1536 std::cout <<
" Max Edges: " <<
stringify(
unsigned(maxima[1])) <<
"\n";
1537 std::cout <<
" Max Faces: " <<
stringify(
unsigned(maxima[2])) <<
"\n";
1538 std::cout <<
" Max Cells: " <<
stringify(
unsigned(maxima[3])) <<
"\n";
1546 auto pred = [&](
auto v) {
return Intern::is_same_vertex(vertex, v); };
1547 return std::distance(vertices.begin(), std::find_if(vertices.begin(), vertices.end(), pred));
1554 if constexpr(dim_ == 1)
1556 return _edge_type_adjustments;
1558 else if constexpr(dim_ == 2)
1560 return _face_type_adjustments;
1562 else if constexpr(dim_ == 3)
1564 return _cell_type_adjustments;
1566 XABORTM(
"Unsupported template dimension!");
1580 template<
typename TemplateShape_,
typename TopologyShape_,
int dim_ = TopologyShape_::dimension - 1>
1587 if constexpr(dim_ == 0)
1589 auto& vertex_refs = topo.template get_references<0>();
1590 for(
int i(0); i < num_entities; i++)
1592 vertex_refs[i] = search_space.search_vertex(raw_entity.coords[i]);
1597 auto& refs = topo.template get_references<dim_>();
1598 for(
int i(0); i < num_entities; i++)
1600 refs[i] = search_space.
search(raw_entity.template face<dim_>(i));
1603 _build_topology<TemplateShape_, TopologyShape_, dim_ - 1>(raw_entity, search_space, topo);
1617 template<
typename TemplateShape_,
int dim_ = TemplateShape_::dimension>
1623 if constexpr(dim_ == 0)
1625 for(
const auto& vertex : Intern::internal_vertices(raw_template))
1628 tmplt.get_vertices().push_back(vertex);
1629 tmplt.get_vertex_coefficients().push_back(Intern::vertex_coefficients<TemplateShape_>(vertex));
1632 search_space.add_sibling_vertex(vertex, tmplt.get_vertices().size() - 1);
1637 _build_template<TemplateShape_, dim_ - 1>(raw_template, tmplt, search_space);
1641 auto& topologies = tmplt.template get_topologies<dim_>();
1642 for(
const auto& entity : Intern::internal_entities<TemplateShape_, dim_>(raw_template.entities))
1645 _build_topology<TemplateShape_, TopologyShape>(entity, search_space, topology);
1646 topologies.push_back(topology);
1648 search_space.
add_sibling(entity, topologies.size() - 1);
1692 template<
typename TemplateShape_,
int dim_ = TemplateShape_::dimension>
1695 const int orientation,
1704 if constexpr(dim_ == 0)
1707 _orientation_mappings.template get_mapping<TemplateShape_::dimension, 0>(oriented_type, orientation);
1713 for(
const VertexType& local_vertex : local_template.get_vertices())
1715 VertexType oriented_vertex = Intern::orient_vertex<TemplateShape_>(local_vertex, orientation);
1716 Index mapped = _find_vertex(oriented_template.get_vertices(), oriented_vertex);
1717 vertex_mapping.
get_mapping().emplace_back(mapped, 0);
1722 _fill_orientation_mappings<TemplateShape_, dim_ - 1>(
1728 oriented_search_space);
1734 _orientation_mappings.template get_mapping<TemplateShape_::dimension, dim_>(oriented_type, orientation);
1736 for(
const auto& local_topo : local_template.template get_topologies<dim_>())
1739 std::array<VertexType, num_vertices> local = {};
1741 const auto& local_refs = local_topo.template get_references<0>();
1742 for(
int i(0); i < num_vertices; i++)
1745 Intern::orient_vertex<TemplateShape_>(local_search_space.vertex_by_reference(local_refs[i]), orientation);
1748 Index entity_idx = 0;
1749 for(
const auto& oriented_topo : oriented_template.template get_topologies<dim_>())
1752 std::array<VertexType, num_vertices> oriented = {};
1754 const auto& oriented_refs = oriented_topo.template get_references<0>();
1755 for(
int i(0); i < num_vertices; i++)
1757 oriented[i] = oriented_search_space.vertex_by_reference(oriented_refs[i]);
1762 ent_local.coords = local;
1765 ent_oriented.coords = oriented;
1767 if(Intern::is_same_raw_entity(ent_local, ent_oriented))
1776 using CongruencySampler = Intern::CongruencySampler<CurrentShape>;
1777 int o = CongruencySampler::compare_with(
1778 ent_local.coords.data(),
1779 ent_oriented.coords.data(),
1780 Intern::is_same_vertex<TemplateShape_::dimension>);
1782 mapping.
get_mapping().emplace_back(entity_idx, o);
1810 for(
const auto& entry : raw_templates)
1815 _build_template(entry.second, tmplt, search_space);
1817 result.insert({entry.first, tmplt});
1818 search_spaces.insert({entry.first, search_space});
1827 if constexpr(dim_ <= 2)
1829 for(
const auto& entry : raw_templates)
1832 auto& search_space = search_spaces[local_type];
1834 for(
int orientation = 0; orientation < Intern::orientations<Shape::Hypercube<dim_>>(); orientation++)
1837 auto& oriented_search_space = search_spaces[oriented_type];
1839 const auto& local_tmplt = result.at(local_type);
1840 const auto& oriented_tmplt = result.at(oriented_type);
1842 _fill_orientation_mappings<TemplateShape>(
1848 oriented_search_space);
1865 template<
typename Shape_>
1872 if constexpr(Shape_::dimension > 1)
1875 for(
int i(0); i < num_edges; ++i)
1877 auto edge_type = type.template face_type<1>(i);
1883 if constexpr(Shape_::dimension > 2)
1886 for(
int i(0); i < num_faces; ++i)
1888 auto face_type = type.template face_type<2>(i);
1913 template<
typename Shape_,
typename TemplateMap_>
1916 auto& adjustments = type_adjustments<Shape_::dimension>();
1919 for(
Index type(0); type < (1 << num_verts); ++type)
1923 std::size_t closest_count = num_verts;
1926 for(
auto& entry : available_templates)
1931 if(!entry_marking.covers(type_marking))
1935 std::size_t distance = type_marking.distance(entry_marking);
1937 if(distance < closest_count)
1939 closest_count = distance;
1940 closest_marking = entry_marking;
1947 auto& adjustment = adjustments.at(type);
1948 for(
int i(0); i < num_verts; ++i)
1950 if(closest_marking.is_vertex_marked(i) && !type_marking.is_vertex_marked(i))
#define ASSERT(expr)
Debug-Assertion macro definition.
#define XABORTM(msg)
Abortion macro definition with custom message.
Mapping between different orientations of a refinement template.
std::pair< Index, int > operator()(Index idx) const
Apply operator.
const std::vector< std::pair< Index, int > > & get_mapping() const
Const accessor for full orientation mapping.
std::vector< std::pair< Index, int > > _mapping
Index -> Index mapping.
std::vector< std::pair< Index, int > > & get_mapping()
Accessor for full orientation mapping.
Constructs RefinementTemplates from RawTemplates.
TemplateMapByDim< dim_ > _build(const RawTemplateMapByDim< dim_ > &raw_templates)
Build all templates of a certain dimension.
TemplateMapByDim< 1 > EdgeMap
Map type from refinement types to edge templates.
std::pair< Index, int > correct_for_orientation(RefinementTypeByDim< dim_ > type, int orientation, Index idx)
Correct an index for orientation.
const EdgeMap & edges()
Edge-template accessor.
typename RawData_::template TemplateMapByDim< dim_ > RawTemplateMapByDim
Accessor for raw template maps.
TemplateSearchSpace< Shape_ > _setup_search_space(RefinementTypeByDim< Shape_::dimension > type) const
Helper function for creating a search space with boundary and topology entities.
typename RawData_::CellMap RawCellMap
Map type from refinement types to raw cell templates.
void _build_topology(const RawEntity< TopologyShape_, TemplateShape_::dimension > &raw_entity, const TemplateSearchSpace< TemplateShape_ > &search_space, TopologyTemplate< TopologyShape_ > &topo)
Constructs a TopologyTemplate for the given RawEntity.
typename RawData_::template RefinementTypeByDim< dim_ > RefinementTypeByDim
Accessor for refinement types.
typename RawData_::FaceMap RawFaceMap
Map type from refinement types to raw face templates.
const FaceMap & faces()
Face-template accessor.
void _create_type_adjustments(const TemplateMap_ &available_templates)
Calculate adjustments of the subdivision levels.
std::unordered_map< RefinementTypeByDim< dim_ >, RefinementTemplate< Shape::Hypercube< dim_ > > > TemplateMapByDim
Accessor for template map types.
TemplateMapByDim< 3 > CellMap
Map type from refinement types to cell templates.
typename RawData_::MaxShape MaxShape
Maximum shape supported by the raw data.
Index _find_vertex(const std::vector< Tiny::Vector< Real, n_ > > &vertices, const Tiny::Vector< Real, n_ > &vertex)
Determines the index of a vertex in a list of vertices.
void stats()
print some stats about maximum children in the raw data
void _build_template(const RawTemplate< TemplateShape_ > &raw_template, RefinementTemplate< TemplateShape_ > &tmplt, TemplateSearchSpace< TemplateShape_ > &search_space)
Constructs a RefinementTemplate from the given RawTemplate.
typename RawData_::EdgeMap RawEdgeMap
Map type from refinement types to raw edge templates.
auto & type_adjustments()
dim-based accessor for type adjustment arrays
TemplateMapByDim< 2 > FaceMap
Map type from refinement types to face templates.
void _fill_orientation_mappings(const RefinementTypeByDim< TemplateShape_::dimension > &oriented_type, const int orientation, const RefinementTemplate< TemplateShape_ > &local_template, const TemplateSearchSpace< TemplateShape_ > &local_search_space, const RefinementTemplate< TemplateShape_ > &oriented_template, const TemplateSearchSpace< TemplateShape_ > &oriented_search_space)
Fill orientation mappings for a given template.
const CellMap & cells()
Cell-template accessor.
EntityReference search_vertex(const Tiny::Vector< Real, num_coords > &vertex) const
Search for a vertex in this search space.
std::vector< Entry > _entries
Vector of search space entries.
Tiny::Vector< Real, num_coords_ > vertex_by_reference(const EntityReference &reference) const
Search for a vertex given a EntityReference.
std::vector< Entry > & entries()
Accessor for search space entries.
void add_sibling_vertex(const Tiny::Vector< Real, num_coords > &vertex, Index idx)
Add a sibling vertex to the search space.
const std::vector< Entry > & entries() const
Const accessor for search space entries.
Mapping between RawEntities and EntityReferences.
EntityReference _search(const RawEntity< Shape_, num_coords_ > &entity) const
Inner search logic for the current shape.
void add_boundary_entity(int parent_index, const RawTemplate< EntityShape_ > &tmplt)
Adds boundary entities to the search space.
std::vector< EntryByDim< dim_ > > & entries()
Accessor for search space entries.
void _add_sibling(const RawEntity< Shape_, num_coords_ > &entity, Index idx)
Inner add_sibling logic for the current shape.
void add_topology()
Adds topology entities to a TemplateSearchSpace.
const std::vector< EntryByDim< dim_ > > & entries() const
Const accessor for search space entries.
EntityReference search(const RawEntity< Shape__, num_coords_ > &entity) const
Search for a RawEntity in this search space.
std::vector< Entry > _entries
Vector of search space entries.
Shape_ ShapeType
Current shape.
void _add_topology_rec(const std::array< Tiny::Vector< Real, num_coords >, Shape::FaceTraits< ShapeType, 0 >::count > &vertices)
Helper-function for add_topology_to_search_space.
void add_sibling(const RawEntity< Shape__, num_coords_ > &entity, Index idx)
Add a sibling entity to the search space.
Tiny Vector class template.
EntitySource
Enumeration of possible entity sources.
@ BoundaryEdge
Entity is part of a boundary edge, i.e. a child of one of the parents edges.
@ ParentTopology
Entity is part of the parents topology.
@ BoundaryFace
Entity is part of a boundary face, i.e. a child of one of the parents faces.
@ Sibling
Entity is a sibling in the refinement tree.
T_ abs(T_ x)
Returns the absolute value.
T_ pow(T_ x, T_ y)
Returns x raised to the power of y.
T_ max(T_ a, T_ b)
Returns the maximum of two values.
double Real
Real data type.
String stringify(const T_ &item)
Converts an item into a String.
std::uint64_t Index
Index data type.
Reference to another local mesh entity.
EntitySource source
Where to retrieve the entity from.
int entity
Index of boundary entity to retrieve entity from. Only set for boundary entities.
int orientation
Orientation of the retrieved entity relative to the retrieving entity. Only set for sibling entities.
Tuple of raw entity and corresponding reference.
EntityReference reference
EntityReference refering to the raw entity.
RawEntity< Shape_, num_coords_ > raw_entity
Raw entity.
EntitySearchEntry(RawEntity< Shape_, num_coords_ > ent, EntityReference ref)
Constructor.
static TargetVertex embed(int elem, const SourceVertex &vertex)
Embed an edge vertex into a Hexahedron.
static TargetVertex embed(int elem, const SourceVertex &vertex)
Embed a face vertex into a Hexahedron.
static TargetVertex embed(int elem, const SourceVertex &vertex)
Embed an edge vertex into a Quadrilateral.
Embeds a vertex of a lower dimensional shape in a higher dimensional shape.
Dimension-recursive container for OrientationMappingWrappers.
Dimension-recursive container for OrientationMappings.
std::vector< std::array< Real, num_coefficients > > & get_vertex_coefficients()
Vertex coefficient accessor.
const std::vector< Tiny::Vector< Real, Shape_::dimension > > & get_vertices() const
const Vertex-accessor
std::vector< Tiny::Vector< Real, Shape_::dimension > > vertices
Vertices added by this template.
Index num_entities() const
Returns the number of vertices in this template.
const std::vector< std::array< Real, num_coefficients > > & get_vertex_coefficients() const
const Vertex coefficient accessor
std::vector< std::array< Real, num_coefficients > > vertex_coefficients
Vertices added by this template. Precomputed as coefficients for linear interpolation.
std::vector< Tiny::Vector< Real, Shape_::dimension > > & get_vertices()
Vertex-accessor.
Template for refining a mesh entity.
std::vector< TopologyTemplate< CoShape_ > > topologies
Entities of shape CoShape_ added by this template.
Index num_entities() const
Returns the number of entities of dimension dim_ in this template.
const std::vector< TopologyTemplateByDim< dim_ > > & get_topologies() const
const TopologyTemplate accessor
std::vector< TopologyTemplateByDim< dim_ > > & get_topologies()
TopologyTemplate accessor.
const std::array< EntityReference, num_entities > & get_references() const
Const reference-array accessor.
std::array< EntityReference, num_entities > references
Array of vertex references.
std::array< EntityReference, num_entities > & get_references()
Reference-array accessor.
Construction rule for a single entities topology.
const std::array< EntityReference, Shape::FaceTraits< Shape_, dim_ >::count > & get_references() const
Const reference-array accessor.
std::array< EntityReference, num_entities > references
Array of references.
static constexpr int num_entities
Number of references of dimension reference_dim_.
std::array< EntityReference, Shape::FaceTraits< Shape_, dim_ >::count > & get_references()
Reference-array accessor.
Face traits tag struct template.
Reference cell traits structure.