23using Tag = std::int32_t;
62 static_assert(Dim == 2 || Dim == 3,
"Mesh is implemented for Dim = 2 and Dim = 3");
67 using CellVertices = std::array<Index, static_cast<std::size_t>(Dim + 1)>;
101 return static_cast<Index>(faces_.size());
105 if constexpr (Dim == 2) {
119 [[nodiscard]] std::span<const Vertex>
vertices() const noexcept {
return vertices_; }
133 [[nodiscard]] std::span<const CellVertices>
cells() const noexcept {
return cells_; }
138 return cell_edges_[
as_size(c)];
144 return cell_edge_flipped_[
as_size(c)];
152 return cell_faces_[
as_size(c)];
160 return cell_face_permutations_[
as_size(c)];
165 if constexpr (Dim == 2) {
179 [[nodiscard]] std::span<const EdgeVertices>
edges() const noexcept {
return edges_; }
188 [[nodiscard]] std::span<const FaceVertices>
faces() const noexcept
196 if constexpr (Dim == 2) {
209 return facet_cells_[
as_size(f)];
214 return facet_local_indices_[
as_size(f)];
221 [[nodiscard]] std::span<const Index>
boundary_facets() const noexcept {
return boundary_facets_; }
223 return static_cast<Index>(boundary_facets_.size());
228 return cell_neighbors_[
as_size(c)];
235 return std::span<const Index>(edge_cell_data_).subspan(begin, end - begin);
262 return hanging_edges_;
265 return hanging_faces_;
268 [[nodiscard]]
bool is_conforming() const noexcept {
return hanging_edges_.empty(); }
300 [[nodiscard]] std::span<const Tag>
cell_tags() const noexcept {
return cell_tags_; }
307 return facet_tags_[
as_size(f)];
309 [[nodiscard]] std::span<const Tag>
facet_tags() const noexcept {
return facet_tags_; }
318 void set_facet_tags(std::span<const FacetVertices> facets, std::span<const Tag> tags);
328 [[nodiscard]]
int geometry_order() const noexcept {
return edge_nodes_.empty() ? 1 : 2; }
339 return edge_nodes_[
as_size(e)];
341 [[nodiscard]] std::span<const Vertex>
edge_nodes() const noexcept {
return edge_nodes_; }
347 [[nodiscard]]
const std::string&
tag_name(
int dim,
Tag tag)
const;
348 [[nodiscard]] std::optional<Tag>
tag_by_name(
int dim, std::string_view name)
const;
350 [[nodiscard]]
const std::map<Tag, std::string>&
tag_names(
int dim)
const {
351 return tag_names_[names_slot(dim)];
356 [[nodiscard]]
static std::size_t names_slot(
int dim);
357 void validate()
const;
360 void derive_connectivity();
362 std::vector<Vertex> vertices_;
363 std::vector<CellVertices> cells_;
365 std::vector<EdgeVertices> edges_;
366 std::vector<CellEdges> cell_edges_;
367 std::vector<CellEdgeFlags> cell_edge_flipped_;
369 std::vector<FaceVertices> faces_;
370 std::vector<CellFaces> cell_faces_;
371 std::vector<CellFacePermutations> cell_face_permutations_;
373 std::vector<FacetCells> facet_cells_;
374 std::vector<FacetLocalIndices> facet_local_indices_;
375 std::vector<CellNeighbors> cell_neighbors_;
376 std::vector<Index> boundary_facets_;
377 std::vector<Index> edge_cell_offsets_;
378 std::vector<Index> edge_cell_data_;
380 std::vector<HangingEdge> hanging_edges_;
381 std::vector<HangingFace> hanging_faces_;
382 std::vector<std::uint8_t> facet_hanging_role_;
383 std::vector<Index> facet_hanging_link_;
385 std::vector<Tag> cell_tags_;
386 std::vector<Tag> facet_tags_;
387 std::vector<Vertex> edge_nodes_;
388 std::array<std::map<Tag, std::string>, 2> tag_names_;
391extern template class Mesh<2>;
392extern template class Mesh<3>;
const std::string & tag_name(int dim, Tag tag) const
Index num_faces() const noexcept
Definition mesh.hpp:98
void set_tag_name(int dim, Tag tag, std::string name)
const Vertex & edge_node(Index e) const
Second-order node of edge e; requires geometry_order() == 2.
Definition mesh.hpp:336
std::span< const Vertex > edge_nodes() const noexcept
Definition mesh.hpp:341
const EdgeVertices & edge_vertices(Index e) const
Global vertex indices of edge e, ascending; the edge is oriented from [0] to [1].
Definition mesh.hpp:175
const std::map< Tag, std::string > & tag_names(int dim) const
All named tags of entity dimension dim.
Definition mesh.hpp:350
Index num_cells() const noexcept
Definition mesh.hpp:111
void set_edge_nodes(std::vector< Vertex > nodes)
std::vector< Index > cells_with_tag(Tag tag) const
Ids of all cells / facets carrying tag, ascending. O(N).
Tag cell_tag(Index c) const
Definition mesh.hpp:296
std::span< const FaceVertices > faces() const noexcept
Definition mesh.hpp:188
void set_facet_tags(std::span< const FacetVertices > facets, std::span< const Tag > tags)
std::vector< Index > facets_with_tag(Tag tag) const
CellFacets CellNeighbors
Definition mesh.hpp:82
Mesh(std::vector< Vertex > vertices, std::vector< CellVertices > cells, std::vector< Tag > cell_tags)
const CellNeighbors & cell_neighbors(Index c) const
Neighbour of cell c across its local facet k, kInvalidIndex on the boundary.
Definition mesh.hpp:226
void set_cell_tag(Index c, Tag tag)
Definition mesh.hpp:301
const CellFacePermutations & cell_face_permutations(Index c) const
Definition mesh.hpp:156
std::span< const CellVertices > cells() const noexcept
Definition mesh.hpp:133
std::span< const Index > edge_cells(Index e) const
All cells containing edge e, ascending (one or two in 2D, any number in 3D).
Definition mesh.hpp:231
std::array< Index, static_cast< std::size_t >(Dim+1)> CellVertices
Definition mesh.hpp:67
Tag facet_tag(Index f) const
Definition mesh.hpp:305
Mesh(std::vector< Vertex > vertices, std::vector< CellVertices > cells)
bool is_conforming() const noexcept
True if the mesh has no hanging entities.
Definition mesh.hpp:268
void set_vertex(Index v, const Vertex &x)
std::span< const EdgeVertices > edges() const noexcept
Definition mesh.hpp:179
int geometry_order() const noexcept
1: affine cells (vertices only); 2: one extra node per edge (set_edge_nodes).
Definition mesh.hpp:328
std::array< Index, 2 > EdgeVertices
Definition mesh.hpp:68
const CellEdgeFlags & cell_edge_flipped(Index c) const
Definition mesh.hpp:142
static constexpr LocalIndex kFacetsPerCell
Definition mesh.hpp:75
const CellFacets & cell_facets(Index c) const
Global facet ids of cell c: cell_edges(c) in 2D, cell_faces(c) in 3D.
Definition mesh.hpp:164
const CellFaces & cell_faces(Index c) const
Global face ids of cell c, indexed by local face number (3D only).
Definition mesh.hpp:148
std::array< std::uint8_t, static_cast< std::size_t >(kFacesPerCell)> CellFacePermutations
Definition mesh.hpp:80
static constexpr LocalIndex kFacesPerCell
meaningful for Dim = 3 only
Definition mesh.hpp:74
Index num_edges() const noexcept
Definition mesh.hpp:97
HangingRole
Definition mesh.hpp:253
static constexpr LocalIndex kEdgesPerCell
Definition mesh.hpp:73
std::span< const Tag > facet_tags() const noexcept
Definition mesh.hpp:309
std::span< const Tag > cell_tags() const noexcept
Definition mesh.hpp:300
const FacetVertices & facet_vertices(Index f) const
Global vertex indices of facet f, ascending: an edge in 2D, a face in 3D.
Definition mesh.hpp:195
std::span< const Index > hanging_child_facets(Index f) const
Index num_boundary_facets() const noexcept
Definition mesh.hpp:222
static constexpr LocalIndex kVerticesPerCell
Definition mesh.hpp:72
Index hanging_parent_facet(Index f) const
Parent facet of a hanging child facet, kInvalidIndex for any other facet.
Definition mesh.hpp:276
std::array< Index, static_cast< std::size_t >(kFacetsPerCell)> CellFacets
Definition mesh.hpp:81
std::optional< Tag > tag_by_name(int dim, std::string_view name) const
void set_facet_tag(Index f, Tag tag)
Definition mesh.hpp:310
std::span< const HangingEdge > hanging_edges() const noexcept
Definition mesh.hpp:261
void set_hanging(std::vector< HangingEdge > edges, std::vector< HangingFace > faces)
const FacetCells & facet_cells(Index f) const
Definition mesh.hpp:207
std::span< const HangingFace > hanging_faces() const noexcept
Definition mesh.hpp:264
const CellVertices & cell_vertices(Index c) const
Global vertex indices of cell c in local order (SimplexTopology<Dim>).
Definition mesh.hpp:129
std::array< Index, static_cast< std::size_t >(kFacesPerCell)> CellFaces
Definition mesh.hpp:79
std::array< bool, static_cast< std::size_t >(kEdgesPerCell)> CellEdgeFlags
Definition mesh.hpp:78
std::span< const Vertex > vertices() const noexcept
Definition mesh.hpp:119
std::array< Index, static_cast< std::size_t >(kEdgesPerCell)> CellEdges
Definition mesh.hpp:77
std::span< const Index > boundary_facets() const noexcept
Ids of all boundary facets, ascending.
Definition mesh.hpp:221
Index tag_boundary(Tag tag)
Assigns tag to every boundary facet that is still untagged; returns how many.
Index num_facets() const noexcept
Number of codimension-1 entities: edges in 2D, faces in 3D.
Definition mesh.hpp:104
std::array< Index, 3 > FaceVertices
Definition mesh.hpp:69
Index face_id(Index a, Index b, Index c) const
Id of the face with vertices {a, b, c} in any order, kInvalidIndex if absent (3D).
Index edge_id(Index a, Index b) const
Id of the edge with vertices {a, b} in any order, kInvalidIndex if absent. O(log E).
const Vertex & vertex(Index v) const
Definition mesh.hpp:115
const FaceVertices & face_vertices(Index f) const
Global vertex indices of face f, ascending (3D only).
Definition mesh.hpp:182
bool is_boundary_facet(Index f) const
A facet with one cell that is neither a hanging parent nor a hanging child.
Definition mesh.hpp:217
std::array< LocalIndex, 2 > FacetLocalIndices
Definition mesh.hpp:84
const CellEdges & cell_edges(Index c) const
Global edge ids of cell c, indexed by local edge number.
Definition mesh.hpp:136
HangingRole facet_hanging_role(Index f) const
Role of facet f: hanging parent (coarse side), hanging child (fine side) or none.
Definition mesh.hpp:270
const FacetLocalIndices & facet_local_indices(Index f) const
Local facet number of facet f inside facet_cells(f)[0] and [1] (-1 if absent).
Definition mesh.hpp:212
std::array< Index, 2 > FacetCells
Definition mesh.hpp:83
std::array< Index, static_cast< std::size_t >(Dim)> FacetVertices
Definition mesh.hpp:70
Index num_vertices() const noexcept
Definition mesh.hpp:96
Point< Dim > Vertex
Definition mesh.hpp:66
Index facet_id(FacetVertices vertices) const
Id of the facet with the given vertices in any order, kInvalidIndex if absent.
#define HPFEM_ASSERT(cond, msg)
Definition error.hpp:48
Definition adaptive_mesh.hpp:19
std::int32_t Tag
Integer tag of a physical group (Gmsh convention: positive; 0 means untagged).
Definition mesh.hpp:23
constexpr Tag kNoTag
Definition mesh.hpp:24
Eigen::Matrix< Real, Dim, 1 > Point
Definition types.hpp:27
constexpr std::size_t as_size(Index i) noexcept
Converts a non-negative global or local index to a container index.
Definition types.hpp:34
std::int64_t Index
global indices (DoFs, entities)
Definition types.hpp:17
std::int32_t LocalIndex
element-local indices
Definition types.hpp:18
constexpr Index kInvalidIndex
"No entity" marker, e.g. the neighbour across a boundary facet.
Definition types.hpp:31
std::array< Index, 2 > children
Definition mesh.hpp:244
Index parent
Definition mesh.hpp:243
Index vertex
Definition mesh.hpp:245
std::array< Index, 4 > children
Definition mesh.hpp:251
Index parent
Definition mesh.hpp:250
Local topology tables of the reference simplex in Dim dimensions.
Definition simplex_topology.hpp:27