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);
 
  193      if(storage[key].layer == layer || storage[key].type.is_zero_refinement())
 
  195        edges.push_back(key);
 
  200      if(storage[key].layer == layer || storage[key].type.is_zero_refinement())
 
  202        faces.push_back(key);
 
  207      if(storage[key].layer == layer || storage[key].type.is_zero_refinement())
 
  209        cells.push_back(key);
 
  213    const MeshStorage_& storage;
 
  216    std::vector<Intern::VertexKey> vertices;
 
  217    std::vector<Intern::EdgeKey> edges;
 
  218    std::vector<Intern::FaceKey> faces;
 
  219    std::vector<Intern::CellKey> cells;
 
  236  template<
typename AdaptiveMesh_, 
typename TargetMeshType_, 
typename Shape_>
 
  239    using FoundationMesh = 
typename AdaptiveMesh_::FoundationMeshType;
 
  240    using Roots = 
typename AdaptiveMesh_::MeshRoots;
 
  241    using Storage = 
typename AdaptiveMesh_::MeshStorage;
 
  258      const Storage& storage)
 
  274  template<
typename AdaptiveMesh_, 
typename TargetMeshType_, 
typename Shape_>
 
  275  struct MeshPartProjector;
 
  285  template<
typename AdaptiveMesh_, 
typename TargetMeshType_>
 
  288    using FoundationMesh = 
typename AdaptiveMesh_::FoundationMeshType;
 
  289    using Roots = 
typename AdaptiveMesh_::MeshRoots;
 
  290    using Storage = 
typename AdaptiveMesh_::MeshStorage;
 
  298      const Storage& storage)
 
  300      auto& reg_vertices = source.template get_target_set<0>();
 
  301      auto& root_vertices = roots.template by_dim<0>();
 
  302      for(
Index i(0); i < reg_vertices.get_num_entities(); ++i)
 
  304        auto iter = root_vertices.find(reg_vertices[i]);
 
  305        if(iter != root_vertices.end())
 
  307          storage.walk_subtree(iter->second, visitor, layer);
 
  314      auto& result_verts = target.template get_target_set<0>();
 
  315      for(
Index i(0); i < visitor.vertices.size(); ++i)
 
  317        result_verts[i] = storage.get_index(visitor.vertices[i]);
 
  329  template<
typename AdaptiveMesh_, 
typename TargetMeshType_>
 
  332    using FoundationMesh = 
typename AdaptiveMesh_::FoundationMeshType;
 
  333    using Roots = 
typename AdaptiveMesh_::MeshRoots;
 
  334    using Storage = 
typename AdaptiveMesh_::MeshStorage;
 
  342      const Storage& storage)
 
  351      auto& reg_edges = source.template get_target_set<1>();
 
  352      auto& root_edges = roots.template by_dim<1>();
 
  353      for(
Index i(0); i < reg_edges.get_num_entities(); ++i)
 
  355        auto iter = root_edges.find(reg_edges[i]);
 
  356        if(iter != root_edges.end())
 
  358          storage.walk_subtree(iter->second, visitor, layer);
 
  367      auto& result_edges = target.template get_target_set<1>();
 
  368      for(
Index i(0); i < visitor.edges.size(); ++i)
 
  370        result_edges[i] = storage.get_index(visitor.edges[i]);
 
  382  template<
typename AdaptiveMesh_, 
typename TargetMeshType_>
 
  385    using FoundationMesh = 
typename AdaptiveMesh_::FoundationMeshType;
 
  386    using Roots = 
typename AdaptiveMesh_::MeshRoots;
 
  387    using Storage = 
typename AdaptiveMesh_::MeshStorage;
 
  395      const Storage& storage)
 
  404      auto& reg_faces = source.template get_target_set<2>();
 
  405      auto& root_faces = roots.template by_dim<2>();
 
  406      for(
Index i(0); i < reg_faces.get_num_entities(); ++i)
 
  408        auto iter = root_faces.find(reg_faces[i]);
 
  409        if(iter != root_faces.end())
 
  411          storage.walk_subtree(iter->second, visitor, layer);
 
  420      auto& result_faces = target.template get_target_set<2>();
 
  421      for(
Index i(0); i < visitor.faces.size(); ++i)
 
  423        result_faces[i] = storage.get_index(visitor.faces[i]);
 
  435  template<
typename AdaptiveMesh_, 
typename TargetMeshType_>
 
  438    using FoundationMesh = 
typename AdaptiveMesh_::FoundationMeshType;
 
  439    using Roots = 
typename AdaptiveMesh_::MeshRoots;
 
  440    using Storage = 
typename AdaptiveMesh_::MeshStorage;
 
  448      const Storage& storage)
 
  457      auto& reg_cells = source.template get_target_set<3>();
 
  458      auto& root_cells = roots.template by_dim<3>();
 
  459      for(
Index i(0); i < reg_cells.get_num_entities(); ++i)
 
  461        auto iter = root_cells.find(reg_cells[i]);
 
  462        if(iter != root_cells.end())
 
  464          storage.walk_subtree(iter->second, visitor, layer);
 
  473      auto& result_cells = target.template get_target_set<3>();
 
  474      for(
Index i(0); i < visitor.cells.size(); ++i)
 
  476        result_cells[i] = storage.get_index(visitor.cells[i]);
 
  488    std::set<Index> vertices;
 
  489    std::set<Index> edges;
 
  490    std::set<Index> faces;
 
  491    std::set<Index> cells;
 
  494    const std::set<Index>& by_dim()
 const 
  496      if constexpr(dim_ == 0)
 
  500      else if constexpr(dim_ == 1)
 
  504      else if constexpr(dim_ == 2)
 
  525  template<
typename Shape_, 
typename TemplateSet, 
typename MeshType_>
 
  541  template<
typename Shape_, 
typename TemplateSet, 
typename MeshType_>
 
  542  struct EntityCollector;
 
  552  template<
typename TemplateSet, 
typename MeshType_>
 
  558      auto& v_at_f = mesh.template get_index_set<2, 0>();
 
  559      auto& e_at_f = mesh.template get_index_set<2, 1>();
 
  563      for(
Index face = 0; face < v_at_f.get_num_entities(); face++)
 
  565        auto face_levels = levels.get_tuple(v_at_f[face]);
 
  567        if(import_all || ! 
typename TemplateSet::template RefinementTypeByDim<2>(face_levels).is_zero_refinement())
 
  569          set.faces.insert(face);
 
  571          set.edges.insert(e_at_f[face][0]);
 
  572          set.edges.insert(e_at_f[face][1]);
 
  573          set.edges.insert(e_at_f[face][2]);
 
  574          set.edges.insert(e_at_f[face][3]);
 
  576          set.vertices.insert(v_at_f[face][0]);
 
  577          set.vertices.insert(v_at_f[face][1]);
 
  578          set.vertices.insert(v_at_f[face][2]);
 
  579          set.vertices.insert(v_at_f[face][3]);
 
  592  template<
typename TemplateSet, 
typename MeshType_>
 
  598      auto& f_at_c = mesh.template get_index_set<3, 2>();
 
  599      auto& e_at_c = mesh.template get_index_set<3, 1>();
 
  600      auto& v_at_c = mesh.template get_index_set<3, 0>();
 
  604      for(
Index cell = 0; cell < v_at_c.get_num_entities(); cell++)
 
  606        auto cell_levels = levels.get_tuple(v_at_c[cell]);
 
  608        if(import_all || ! 
typename TemplateSet::template RefinementTypeByDim<3>(cell_levels).is_zero_refinement())
 
  610          set.cells.insert(cell);
 
  612          for(
int i = 0; i < f_at_c.num_indices; i++)
 
  614            set.faces.insert(f_at_c[cell][i]);
 
  617          for(
int i = 0; i < e_at_c.num_indices; i++)
 
  619            set.edges.insert(e_at_c[cell][i]);
 
  622          for(
int i = 0; i < v_at_c.num_indices; i++)
 
  624            set.vertices.insert(v_at_c[cell][i]);
 
  640  template<
typename MeshType_, 
int cell_dim, 
int face_dim>
 
  641  int congruency(
const MeshType_& mesh, 
Index cell, 
int face)
 
  643    using ShapeType = 
typename MeshType_::ShapeType;
 
  646    using IndexMapping = Intern::FaceIndexMapping<CellShape, face_dim, 0>;
 
  647    using Sampler = Intern::CongruencySampler<FaceShape>;
 
  651    auto& face_at_cell = mesh.template get_index_set<cell_dim, face_dim>();
 
  652    auto& v_at_face = mesh.template get_index_set<face_dim, 0>();
 
  653    auto& v_at_cell = mesh.template get_index_set<cell_dim, 0>();
 
  655    std::array<Index, face_verts> local;
 
  657    for(
int i = 0; i < face_verts; i++)
 
  659      local[i] = v_at_cell[cell][IndexMapping::map(face, i)];
 
  662    return Sampler::compare(local, v_at_face[face_at_cell(cell, face)]);
 
  677  template<
typename AdaptiveMeshType_, 
int topology_dim_, 
int collection_dim_>
 
  682  template<
typename AdaptiveMeshType_, 
int topology_dim_, 
int collection_dim_>
 
  693  template<
typename AdaptiveMeshType_, 
int topology_dim_>
 
  707    static void collect(Topology& topology, 
Index entity, 
const AdaptiveMeshType_& a_mesh)
 
  709      auto& foundation_entity_vertices = a_mesh._foundation_mesh.template get_index_set<topology_dim_, 0>();
 
  711      auto& topology_vertices = topology.template by_dim<0>();
 
  712      auto& root_vertices = a_mesh._roots.template by_dim<0>();
 
  713      for(
int vert = 0; vert < num_vertices; vert++)
 
  715        Index vertex_index = foundation_entity_vertices(entity, vert);
 
  728  template<
typename AdaptiveMeshType_, 
int topology_dim_>
 
  732    using ShapeType = 
typename AdaptiveMeshType_::ShapeType;
 
  743    static void collect(Topology& topology, 
Index entity, 
const AdaptiveMeshType_& a_mesh)
 
  748      using FoundationMeshType = 
typename AdaptiveMeshType_::FoundationMeshType;
 
  749      auto& foundation_entity_edges = a_mesh._foundation_mesh.template get_index_set<topology_dim_, 1>();
 
  751      auto& topology_edges = topology.template by_dim<1>();
 
  752      auto& root_edges = a_mesh._roots.template by_dim<1>();
 
  753      for(
int edge = 0; edge < num_edges; edge++)
 
  755        int orientation = congruency<FoundationMeshType, topology_dim_, 1>(a_mesh._foundation_mesh, entity, edge);
 
  756        Index edge_index = foundation_entity_edges(entity, (
int)edge);
 
  769  template<
typename AdaptiveMeshType_, 
int topology_dim_>
 
  773    using ShapeType = 
typename AdaptiveMeshType_::ShapeType;
 
  784    static void collect(Topology& topology, 
Index entity, 
const AdaptiveMeshType_& a_mesh)
 
  789      using FoundationMeshType = 
typename AdaptiveMeshType_::FoundationMeshType;
 
  790      auto& foundation_entity_faces = a_mesh._foundation_mesh.template get_index_set<topology_dim_, 2>();
 
  792      auto& topology_faces = topology.template by_dim<2>();
 
  793      auto& root_faces = a_mesh._roots.template by_dim<2>();
 
  794      for(
int face = 0; face < num_faces; face++)
 
  796        int orientation = congruency<FoundationMeshType, topology_dim_, 2>(a_mesh._foundation_mesh, entity, face);
 
  797        Index face_index = foundation_entity_faces(entity, face);
 
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.