8#include <kernel/geometry/intern/refinement_field.hpp>
9#include <kernel/geometry/mesh_part.hpp>
11#include <kernel/geometry/intern/adaptive_mesh_storage.hpp>
12#include <kernel/geometry/subdivision_levels.hpp>
13#include <kernel/shape.hpp>
15namespace FEAT::Geometry::Intern
27 template<
typename AdaptiveMesh_,
typename ConformalMesh_,
typename Shape_>
42 template<
typename AdaptiveMesh_,
typename ConformalMesh_,
typename Shape_>
43 struct ConformalMeshWriter;
53 template<
typename AdaptiveMesh_,
typename ConformalMesh_>
59 auto& vertices = target.get_vertex_set();
61 Index num_vertices = source.get_num_entities(layer, 0);
62 for(
Index i = 0; i < num_vertices; i++)
64 vertices[i] = source.vertex(layer, i);
76 template<
typename AdaptiveMesh_,
typename ConformalMesh_>
85 auto& v_at_e = target.template get_index_set<1, 0>();
87 Index num_edges = source.get_num_entities(layer, 1);
88 for(
Index i = 0; i < num_edges; i++)
90 v_at_e[i][0] = source.template get_face_index<1, 0>(layer, i, 0);
91 v_at_e[i][1] = source.template get_face_index<1, 0>(layer, i, 1);
103 template<
typename AdaptiveMesh_,
typename ConformalMesh_>
112 auto& v_at_f = target.template get_index_set<2, 0>();
113 auto& e_at_f = target.template get_index_set<2, 1>();
115 Index num_faces = source.get_num_entities(layer, 2);
116 for(
Index i = 0; i < num_faces; i++)
118 for(
int j = 0; j < v_at_f.get_num_indices(); j++)
120 v_at_f[i][j] = source.template get_face_index<2, 0>(layer, i, j);
123 for(
int j = 0; j < e_at_f.get_num_indices(); j++)
125 e_at_f[i][j] = source.template get_face_index<2, 1>(layer, i, j);
138 template<
typename AdaptiveMesh_,
typename ConformalMesh_>
147 auto& v_at_c = target.template get_index_set<3, 0>();
148 auto& e_at_c = target.template get_index_set<3, 1>();
149 auto& f_at_c = target.template get_index_set<3, 2>();
151 Index num_cells = source.get_num_entities(layer, 3);
152 for(
Index i = 0; i < num_cells; i++)
154 for(
int j = 0; j < v_at_c.get_num_indices(); j++)
156 v_at_c[i][j] = source.template get_face_index<3, 0>(layer, i, j);
158 for(
int j = 0; j < e_at_c.get_num_indices(); j++)
160 e_at_c[i][j] = source.template get_face_index<3, 1>(layer, i, j);
162 for(
int j = 0; j < f_at_c.get_num_indices(); j++)
164 f_at_c[i][j] = source.template get_face_index<3, 2>(layer, i, j);
177 template<
typename MeshStorage_>
186 if(storage[key].layer <= layer)
188 vertices.push_back(key);
194 if(storage[key].layer == layer || storage[key].type.is_zero_refinement())
196 edges.push_back(key);
202 if(storage[key].layer == layer || storage[key].type.is_zero_refinement())
204 faces.push_back(key);
210 if(storage[key].layer == layer || storage[key].type.is_zero_refinement())
212 cells.push_back(key);
216 const MeshStorage_& storage;
219 std::vector<Intern::VertexKey> vertices;
220 std::vector<Intern::EdgeKey> edges;
221 std::vector<Intern::FaceKey> faces;
222 std::vector<Intern::CellKey> cells;
239 template<
typename AdaptiveMesh_,
typename TargetMeshType_,
typename Shape_>
242 using FoundationMesh =
typename AdaptiveMesh_::FoundationMeshType;
243 using Roots =
typename AdaptiveMesh_::MeshRoots;
244 using Storage =
typename AdaptiveMesh_::MeshStorage;
261 const Storage& storage)
277 template<
typename AdaptiveMesh_,
typename TargetMeshType_,
typename Shape_>
278 struct MeshPartProjector;
288 template<
typename AdaptiveMesh_,
typename TargetMeshType_>
291 using FoundationMesh =
typename AdaptiveMesh_::FoundationMeshType;
292 using Roots =
typename AdaptiveMesh_::MeshRoots;
293 using Storage =
typename AdaptiveMesh_::MeshStorage;
301 const Storage& storage)
303 auto& reg_vertices = source.template get_target_set<0>();
304 auto& root_vertices = roots.template by_dim<0>();
305 for(
Index i(0); i < reg_vertices.get_num_entities(); ++i)
307 auto iter = root_vertices.find(reg_vertices[i]);
308 if(iter != root_vertices.end())
310 storage.walk_subtree(iter->second, visitor, layer);
317 auto& result_verts = target.template get_target_set<0>();
318 for(
Index i(0); i < visitor.vertices.size(); ++i)
320 result_verts[i] = storage.get_index(visitor.vertices[i]);
332 template<
typename AdaptiveMesh_,
typename TargetMeshType_>
335 using FoundationMesh =
typename AdaptiveMesh_::FoundationMeshType;
336 using Roots =
typename AdaptiveMesh_::MeshRoots;
337 using Storage =
typename AdaptiveMesh_::MeshStorage;
345 const Storage& storage)
354 auto& reg_edges = source.template get_target_set<1>();
355 auto& root_edges = roots.template by_dim<1>();
356 for(
Index i(0); i < reg_edges.get_num_entities(); ++i)
358 auto iter = root_edges.find(reg_edges[i]);
359 if(iter != root_edges.end())
361 storage.walk_subtree(iter->second, visitor, layer);
370 auto& result_edges = target.template get_target_set<1>();
371 for(
Index i(0); i < visitor.edges.size(); ++i)
373 result_edges[i] = storage.get_index(visitor.edges[i]);
385 template<
typename AdaptiveMesh_,
typename TargetMeshType_>
388 using FoundationMesh =
typename AdaptiveMesh_::FoundationMeshType;
389 using Roots =
typename AdaptiveMesh_::MeshRoots;
390 using Storage =
typename AdaptiveMesh_::MeshStorage;
398 const Storage& storage)
407 auto& reg_faces = source.template get_target_set<2>();
408 auto& root_faces = roots.template by_dim<2>();
409 for(
Index i(0); i < reg_faces.get_num_entities(); ++i)
411 auto iter = root_faces.find(reg_faces[i]);
412 if(iter != root_faces.end())
414 storage.walk_subtree(iter->second, visitor, layer);
423 auto& result_faces = target.template get_target_set<2>();
424 for(
Index i(0); i < visitor.faces.size(); ++i)
426 result_faces[i] = storage.get_index(visitor.faces[i]);
438 template<
typename AdaptiveMesh_,
typename TargetMeshType_>
441 using FoundationMesh =
typename AdaptiveMesh_::FoundationMeshType;
442 using Roots =
typename AdaptiveMesh_::MeshRoots;
443 using Storage =
typename AdaptiveMesh_::MeshStorage;
451 const Storage& storage)
460 auto& reg_cells = source.template get_target_set<3>();
461 auto& root_cells = roots.template by_dim<3>();
462 for(
Index i(0); i < reg_cells.get_num_entities(); ++i)
464 auto iter = root_cells.find(reg_cells[i]);
465 if(iter != root_cells.end())
467 storage.walk_subtree(iter->second, visitor, layer);
476 auto& result_cells = target.template get_target_set<3>();
477 for(
Index i(0); i < visitor.cells.size(); ++i)
479 result_cells[i] = storage.get_index(visitor.cells[i]);
491 std::set<Index> vertices;
492 std::set<Index> edges;
493 std::set<Index> faces;
494 std::set<Index> cells;
497 const std::set<Index>& by_dim()
const
499 if constexpr(dim_ == 0)
503 else if constexpr(dim_ == 1)
507 else if constexpr(dim_ == 2)
528 template<
typename Shape_,
typename TemplateSet,
typename MeshType_>
544 template<
typename Shape_,
typename TemplateSet,
typename MeshType_>
545 struct EntityCollector;
555 template<
typename TemplateSet,
typename MeshType_>
561 auto& v_at_f = mesh.template get_index_set<2, 0>();
562 auto& e_at_f = mesh.template get_index_set<2, 1>();
566 for(
Index face = 0; face < v_at_f.get_num_entities(); face++)
568 auto face_levels = levels.get_tuple(v_at_f[face]);
570 if(import_all || !
typename TemplateSet::template RefinementTypeByDim<2>(face_levels).is_zero_refinement())
572 set.faces.insert(face);
574 set.edges.insert(e_at_f[face][0]);
575 set.edges.insert(e_at_f[face][1]);
576 set.edges.insert(e_at_f[face][2]);
577 set.edges.insert(e_at_f[face][3]);
579 set.vertices.insert(v_at_f[face][0]);
580 set.vertices.insert(v_at_f[face][1]);
581 set.vertices.insert(v_at_f[face][2]);
582 set.vertices.insert(v_at_f[face][3]);
595 template<
typename TemplateSet,
typename MeshType_>
601 auto& f_at_c = mesh.template get_index_set<3, 2>();
602 auto& e_at_c = mesh.template get_index_set<3, 1>();
603 auto& v_at_c = mesh.template get_index_set<3, 0>();
607 for(
Index cell = 0; cell < v_at_c.get_num_entities(); cell++)
609 auto cell_levels = levels.get_tuple(v_at_c[cell]);
611 if(import_all || !
typename TemplateSet::template RefinementTypeByDim<3>(cell_levels).is_zero_refinement())
613 set.cells.insert(cell);
615 for(
int i = 0; i < f_at_c.num_indices; i++)
617 set.faces.insert(f_at_c[cell][i]);
620 for(
int i = 0; i < e_at_c.num_indices; i++)
622 set.edges.insert(e_at_c[cell][i]);
625 for(
int i = 0; i < v_at_c.num_indices; i++)
627 set.vertices.insert(v_at_c[cell][i]);
643 template<
typename MeshType_,
int cell_dim,
int face_dim>
644 int congruency(
const MeshType_& mesh,
Index cell,
int face)
646 using ShapeType =
typename MeshType_::ShapeType;
649 using IndexMapping = Intern::FaceIndexMapping<CellShape, face_dim, 0>;
650 using Sampler = Intern::CongruencySampler<FaceShape>;
654 auto& face_at_cell = mesh.template get_index_set<cell_dim, face_dim>();
655 auto& v_at_face = mesh.template get_index_set<face_dim, 0>();
656 auto& v_at_cell = mesh.template get_index_set<cell_dim, 0>();
658 std::array<Index, face_verts> local;
660 for(
int i = 0; i < face_verts; i++)
662 local[std::size_t(i)] = v_at_cell[cell][IndexMapping::map(face, i)];
665 return Sampler::compare(local, v_at_face[face_at_cell(cell, face)]);
680 template<
typename AdaptiveMeshType_,
int topology_dim_,
int collection_dim_>
685 template<
typename AdaptiveMeshType_,
int topology_dim_,
int collection_dim_>
696 template<
typename AdaptiveMeshType_,
int topology_dim_>
710 static void collect(Topology& topology,
Index entity,
const AdaptiveMeshType_& a_mesh)
712 auto& foundation_entity_vertices = a_mesh._foundation_mesh.template get_index_set<topology_dim_, 0>();
714 auto& topology_vertices = topology.template by_dim<0>();
715 auto& root_vertices = a_mesh._roots.template by_dim<0>();
716 for(
int vert = 0; vert < num_vertices; vert++)
718 Index vertex_index = foundation_entity_vertices(entity, vert);
731 template<
typename AdaptiveMeshType_,
int topology_dim_>
735 using ShapeType =
typename AdaptiveMeshType_::ShapeType;
746 static void collect(Topology& topology,
Index entity,
const AdaptiveMeshType_& a_mesh)
751 using FoundationMeshType =
typename AdaptiveMeshType_::FoundationMeshType;
752 auto& foundation_entity_edges = a_mesh._foundation_mesh.template get_index_set<topology_dim_, 1>();
754 auto& topology_edges = topology.template by_dim<1>();
755 auto& root_edges = a_mesh._roots.template by_dim<1>();
756 for(
int edge = 0; edge < num_edges; edge++)
758 int orientation = congruency<FoundationMeshType, topology_dim_, 1>(a_mesh._foundation_mesh, entity, edge);
759 Index edge_index = foundation_entity_edges(entity, edge);
760 topology_edges[std::size_t(edge)] =
Intern::OrientedEdge(orientation, root_edges.at(edge_index));
772 template<
typename AdaptiveMeshType_,
int topology_dim_>
776 using ShapeType =
typename AdaptiveMeshType_::ShapeType;
787 static void collect(Topology& topology,
Index entity,
const AdaptiveMeshType_& a_mesh)
792 using FoundationMeshType =
typename AdaptiveMeshType_::FoundationMeshType;
793 auto& foundation_entity_faces = a_mesh._foundation_mesh.template get_index_set<topology_dim_, 2>();
795 auto& topology_faces = topology.template by_dim<2>();
796 auto& root_faces = a_mesh._roots.template by_dim<2>();
797 for(
int face = 0; face < num_faces; face++)
799 int orientation = congruency<FoundationMeshType, topology_dim_, 2>(a_mesh._foundation_mesh, entity, face);
800 Index face_index = foundation_entity_faces(entity, face);
801 topology_faces[std::size_t(face)] =
Intern::OrientedFace(orientation, root_faces.at(face_index));
Class template for partial meshes.
Subdivision level markings for meshes.
std::uint64_t Index
Index data type.
SlotMap key for use by the AdaptiveMeshStorage class.
Surrounding elements of a mesh element.
static void collect(MeshIndexSet &set, const MeshType_ &mesh, const RefinementField< typename TemplateSet::VertexMarkerType > &levels, bool import_all)
Collect all entities of current dimension with non zero refinement type.
static void collect(MeshIndexSet &set, const MeshType_ &mesh, const RefinementField< typename TemplateSet::VertexMarkerType > &levels, bool import_all)
Collect all entities of current dimension with non zero refinement type.
Alorithm for collecting mesh entities that must be adaptively refined.
static void collect(MeshIndexSet &set, const MeshType_ &mesh, const SubdivisionLevels &levels, bool import_all)
Collect all entities of current dimension with non zero refinement type.
static void collect(Topology &topology, Index entity, const AdaptiveMeshType_ &a_mesh)
Collect vertices of foundation mesh for topologies.
static void collect(Topology &topology, Index entity, const AdaptiveMeshType_ &a_mesh)
Collect edges of foundation mesh for topologies.
static void collect(Topology &topology, Index entity, const AdaptiveMeshType_ &a_mesh)
Collect faces of foundation mesh for topologies.
Algorithm for collecting topologies from the foundation mesh.
Newtype wrapper for mesh layers.
Algorithm for projecting MeshParts of an underlying mesh onto its adaptive mesh.
static void collect_keys(Visitor &visitor, const MeshPart< FoundationMesh > &source, Layer layer, const Roots &roots, const Storage &storage)
Collect mesh entities stemming from one of the entities in the source meshpart.
static void write_meshpart(Visitor &visitor, MeshPart< TargetMeshType_ > &target, const Storage &storage)
Write collected references into a new target meshpart.
Visitor class for mesh part projection.
Orientation-aware reference to another mesh element.
Face traits tag struct template.