hp-FEM
Adaptive hp-FEM suite for nano-optics
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
hpfem::mesh::Mesh< Dim > Class Template Reference

#include <mesh.hpp>

Classes

struct  HangingEdge
 
struct  HangingFace
 

Public Types

enum class  HangingRole : std::uint8_t { kNone , kParent , kChild }
 
using Topology = SimplexTopology< Dim >
 
using Vertex = Point< Dim >
 
using CellVertices = std::array< Index, static_cast< std::size_t >(Dim+1)>
 
using EdgeVertices = std::array< Index, 2 >
 
using FaceVertices = std::array< Index, 3 >
 
using FacetVertices = std::array< Index, static_cast< std::size_t >(Dim)>
 
using CellEdges = std::array< Index, static_cast< std::size_t >(kEdgesPerCell)>
 
using CellEdgeFlags = std::array< bool, static_cast< std::size_t >(kEdgesPerCell)>
 
using CellFaces = std::array< Index, static_cast< std::size_t >(kFacesPerCell)>
 
using CellFacePermutations = std::array< std::uint8_t, static_cast< std::size_t >(kFacesPerCell)>
 
using CellFacets = std::array< Index, static_cast< std::size_t >(kFacetsPerCell)>
 
using CellNeighbors = CellFacets
 
using FacetCells = std::array< Index, 2 >
 
using FacetLocalIndices = std::array< LocalIndex, 2 >
 

Public Member Functions

 Mesh (std::vector< Vertex > vertices, std::vector< CellVertices > cells)
 
 Mesh (std::vector< Vertex > vertices, std::vector< CellVertices > cells, std::vector< Tag > cell_tags)
 
Index num_vertices () const noexcept
 
Index num_edges () const noexcept
 
Index num_faces () const noexcept
 
Index num_facets () const noexcept
 Number of codimension-1 entities: edges in 2D, faces in 3D.
 
Index num_cells () const noexcept
 
const Vertex & vertex (Index v) const
 
std::span< const Vertex > vertices () const noexcept
 
void set_vertex (Index v, const Vertex &x)
 
const CellVertices & cell_vertices (Index c) const
 Global vertex indices of cell c in local order (SimplexTopology<Dim>).
 
std::span< const CellVertices > cells () const noexcept
 
const CellEdges & cell_edges (Index c) const
 Global edge ids of cell c, indexed by local edge number.
 
const CellEdgeFlags & cell_edge_flipped (Index c) const
 
const CellFaces & cell_faces (Index c) const
 Global face ids of cell c, indexed by local face number (3D only).
 
const CellFacePermutations & cell_face_permutations (Index c) const
 
const CellFacets & cell_facets (Index c) const
 Global facet ids of cell c: cell_edges(c) in 2D, cell_faces(c) in 3D.
 
const EdgeVertices & edge_vertices (Index e) const
 Global vertex indices of edge e, ascending; the edge is oriented from [0] to [1].
 
std::span< const EdgeVertices > edges () const noexcept
 
const FaceVertices & face_vertices (Index f) const
 Global vertex indices of face f, ascending (3D only).
 
std::span< const FaceVertices > faces () const noexcept
 
const FacetVertices & facet_vertices (Index f) const
 Global vertex indices of facet f, ascending: an edge in 2D, a face in 3D.
 
const FacetCells & facet_cells (Index f) const
 
const FacetLocalIndices & facet_local_indices (Index f) const
 Local facet number of facet f inside facet_cells(f)[0] and [1] (-1 if absent).
 
bool is_boundary_facet (Index f) const
 A facet with one cell that is neither a hanging parent nor a hanging child.
 
std::span< const Index > boundary_facets () const noexcept
 Ids of all boundary facets, ascending.
 
Index num_boundary_facets () const noexcept
 
const CellNeighbors & cell_neighbors (Index c) const
 Neighbour of cell c across its local facet k, kInvalidIndex on the boundary.
 
std::span< const Index > edge_cells (Index e) const
 All cells containing edge e, ascending (one or two in 2D, any number in 3D).
 
void set_hanging (std::vector< HangingEdge > edges, std::vector< HangingFace > faces)
 
std::span< const HangingEdge > hanging_edges () const noexcept
 
std::span< const HangingFace > hanging_faces () const noexcept
 
bool is_conforming () const noexcept
 True if the mesh has no hanging entities.
 
HangingRole facet_hanging_role (Index f) const
 Role of facet f: hanging parent (coarse side), hanging child (fine side) or none.
 
Index hanging_parent_facet (Index f) const
 Parent facet of a hanging child facet, kInvalidIndex for any other facet.
 
std::span< const Index > hanging_child_facets (Index f) const
 
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).
 
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 facet_id (FacetVertices vertices) const
 Id of the facet with the given vertices in any order, kInvalidIndex if absent.
 
Tag cell_tag (Index c) const
 
std::span< const Tag > cell_tags () const noexcept
 
void set_cell_tag (Index c, Tag tag)
 
Tag facet_tag (Index f) const
 
std::span< const Tag > facet_tags () const noexcept
 
void set_facet_tag (Index f, Tag tag)
 
void set_facet_tags (std::span< const FacetVertices > facets, std::span< const Tag > tags)
 
Index tag_boundary (Tag tag)
 Assigns tag to every boundary facet that is still untagged; returns how many.
 
std::vector< Index > cells_with_tag (Tag tag) const
 Ids of all cells / facets carrying tag, ascending. O(N).
 
std::vector< Index > facets_with_tag (Tag tag) const
 
int geometry_order () const noexcept
 1: affine cells (vertices only); 2: one extra node per edge (set_edge_nodes).
 
void set_edge_nodes (std::vector< Vertex > nodes)
 
const Vertex & edge_node (Index e) const
 Second-order node of edge e; requires geometry_order() == 2.
 
std::span< const Vertex > edge_nodes () const noexcept
 
void set_tag_name (int dim, Tag tag, std::string name)
 
const std::string & tag_name (int dim, Tag tag) const
 
std::optional< Tag > tag_by_name (int dim, std::string_view name) const
 
const std::map< Tag, std::string > & tag_names (int dim) const
 All named tags of entity dimension dim.
 

Static Public Attributes

static constexpr LocalIndex kVerticesPerCell = Dim + 1
 
static constexpr LocalIndex kEdgesPerCell = Topology::kNumEdges
 
static constexpr LocalIndex kFacesPerCell = 4
 meaningful for Dim = 3 only
 
static constexpr LocalIndex kFacetsPerCell = Dim + 1
 

Detailed Description

template<int Dim>
class hpfem::mesh::Mesh< Dim >

Conforming simplicial mesh in Dim dimensions: triangles for Dim = 2, tetrahedra for Dim = 3. Stores vertices and cells as given and derives edges (and faces in 3D) with a global orientation that does not depend on the mesh generator (ADR-0003):

Per cell and local entity (numbering from SimplexTopology<Dim>) the mesh records how the local orientation relates to the global one: a flip flag per edge and a permutation code (kFacePermutations) per face. fespace::DofMap applies the resulting sign flips and permutations to high-order shape functions.

Connectivity tables derived at construction: cell → edges/faces (above), facet → cells with local facet numbers, cell → neighbours across facets, edge → cells (CSR), and the sorted list of boundary facets. A facet shared by more than two cells (non-manifold mesh) is rejected.

Geometry order: by default cells are affine (order 1). set_edge_nodes installs one extra node per global edge (order 2, curved boundaries); cell_geometry() in mesh/geometry.hpp evaluates either representation behind one interface.

Tags (physical groups): one material tag per cell and one tag per facet (boundary facets for boundary conditions, interior facets for interfaces or flux surfaces), optional names per tag. Tags do not influence topology and may be changed later.

Locally refined meshes (AdaptiveMesh) are one-irregular: a coarse edge or face may face the two half edges / four child faces of refined neighbours. Such hanging entities are registered with set_hanging; the parent and child facets then have one cell each but are not boundary facets, and cell_neighbors stays kInvalidIndex across them. The DoF maps constrain the child DoFs to the parent ones (docs/theory/hp-adaptivity.md).

Construction costs O(N log N) in the number of cells.

Member Typedef Documentation

◆ CellEdgeFlags

template<int Dim>
using hpfem::mesh::Mesh< Dim >::CellEdgeFlags = std::array<bool, static_cast<std::size_t>(kEdgesPerCell)>

◆ CellEdges

template<int Dim>
using hpfem::mesh::Mesh< Dim >::CellEdges = std::array<Index, static_cast<std::size_t>(kEdgesPerCell)>

◆ CellFacePermutations

template<int Dim>
using hpfem::mesh::Mesh< Dim >::CellFacePermutations = std::array<std::uint8_t, static_cast<std::size_t>(kFacesPerCell)>

◆ CellFaces

template<int Dim>
using hpfem::mesh::Mesh< Dim >::CellFaces = std::array<Index, static_cast<std::size_t>(kFacesPerCell)>

◆ CellFacets

template<int Dim>
using hpfem::mesh::Mesh< Dim >::CellFacets = std::array<Index, static_cast<std::size_t>(kFacetsPerCell)>

◆ CellNeighbors

template<int Dim>
using hpfem::mesh::Mesh< Dim >::CellNeighbors = CellFacets

◆ CellVertices

template<int Dim>
using hpfem::mesh::Mesh< Dim >::CellVertices = std::array<Index, static_cast<std::size_t>(Dim + 1)>

◆ EdgeVertices

template<int Dim>
using hpfem::mesh::Mesh< Dim >::EdgeVertices = std::array<Index, 2>

◆ FacetCells

template<int Dim>
using hpfem::mesh::Mesh< Dim >::FacetCells = std::array<Index, 2>

◆ FacetLocalIndices

template<int Dim>
using hpfem::mesh::Mesh< Dim >::FacetLocalIndices = std::array<LocalIndex, 2>

◆ FacetVertices

template<int Dim>
using hpfem::mesh::Mesh< Dim >::FacetVertices = std::array<Index, static_cast<std::size_t>(Dim)>

◆ FaceVertices

template<int Dim>
using hpfem::mesh::Mesh< Dim >::FaceVertices = std::array<Index, 3>

◆ Topology

template<int Dim>
using hpfem::mesh::Mesh< Dim >::Topology = SimplexTopology<Dim>

◆ Vertex

template<int Dim>
using hpfem::mesh::Mesh< Dim >::Vertex = Point<Dim>

Member Enumeration Documentation

◆ HangingRole

template<int Dim>
enum class hpfem::mesh::Mesh::HangingRole : std::uint8_t
strong
Enumerator
kNone 
kParent 
kChild 

Constructor & Destructor Documentation

◆ Mesh() [1/2]

template<int Dim>
hpfem::mesh::Mesh< Dim >::Mesh ( std::vector< Vertex >  vertices,
std::vector< CellVertices >  cells 
)

Builds the mesh from vertex coordinates (SI metres) and cells given as global vertex indices in local order; derives edges and faces.

Exceptions
InvalidArgumentif a cell references a vertex out of range or twice.

◆ Mesh() [2/2]

template<int Dim>
hpfem::mesh::Mesh< Dim >::Mesh ( std::vector< Vertex >  vertices,
std::vector< CellVertices >  cells,
std::vector< Tag >  cell_tags 
)

As above, with one material tag per cell. An empty cell_tags means all untagged.

Exceptions
InvalidArgumentif cell_tags is neither empty nor of size cells.size().

Member Function Documentation

◆ boundary_facets()

template<int Dim>
std::span< const Index > hpfem::mesh::Mesh< Dim >::boundary_facets ( ) const
inlinenoexcept

Ids of all boundary facets, ascending.

◆ cell_edge_flipped()

template<int Dim>
const CellEdgeFlags & hpfem::mesh::Mesh< Dim >::cell_edge_flipped ( Index  c) const
inline

true where the local edge direction of cell c runs against the global (ascending-vertex) direction, i.e. the edge shape functions need a sign flip.

◆ cell_edges()

template<int Dim>
const CellEdges & hpfem::mesh::Mesh< Dim >::cell_edges ( Index  c) const
inline

Global edge ids of cell c, indexed by local edge number.

◆ cell_face_permutations()

template<int Dim>
const CellFacePermutations & hpfem::mesh::Mesh< Dim >::cell_face_permutations ( Index  c) const
inline

Per local face i of cell c, the code k into kFacePermutations such that local face vertex j equals face_vertices(cell_faces(c)[i])[kFacePermutations[k][j]].

◆ cell_faces()

template<int Dim>
const CellFaces & hpfem::mesh::Mesh< Dim >::cell_faces ( Index  c) const
inline

Global face ids of cell c, indexed by local face number (3D only).

◆ cell_facets()

template<int Dim>
const CellFacets & hpfem::mesh::Mesh< Dim >::cell_facets ( Index  c) const
inline

Global facet ids of cell c: cell_edges(c) in 2D, cell_faces(c) in 3D.

◆ cell_neighbors()

template<int Dim>
const CellNeighbors & hpfem::mesh::Mesh< Dim >::cell_neighbors ( Index  c) const
inline

Neighbour of cell c across its local facet k, kInvalidIndex on the boundary.

◆ cell_tag()

template<int Dim>
Tag hpfem::mesh::Mesh< Dim >::cell_tag ( Index  c) const
inline

◆ cell_tags()

template<int Dim>
std::span< const Tag > hpfem::mesh::Mesh< Dim >::cell_tags ( ) const
inlinenoexcept

◆ cell_vertices()

template<int Dim>
const CellVertices & hpfem::mesh::Mesh< Dim >::cell_vertices ( Index  c) const
inline

Global vertex indices of cell c in local order (SimplexTopology<Dim>).

◆ cells()

template<int Dim>
std::span< const CellVertices > hpfem::mesh::Mesh< Dim >::cells ( ) const
inlinenoexcept

◆ cells_with_tag()

template<int Dim>
std::vector< Index > hpfem::mesh::Mesh< Dim >::cells_with_tag ( Tag  tag) const

Ids of all cells / facets carrying tag, ascending. O(N).

◆ edge_cells()

template<int Dim>
std::span< const Index > hpfem::mesh::Mesh< Dim >::edge_cells ( Index  e) const
inline

All cells containing edge e, ascending (one or two in 2D, any number in 3D).

◆ edge_id()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::edge_id ( Index  a,
Index  b 
) const

Id of the edge with vertices {a, b} in any order, kInvalidIndex if absent. O(log E).

◆ edge_node()

template<int Dim>
const Vertex & hpfem::mesh::Mesh< Dim >::edge_node ( Index  e) const
inline

Second-order node of edge e; requires geometry_order() == 2.

◆ edge_nodes()

template<int Dim>
std::span< const Vertex > hpfem::mesh::Mesh< Dim >::edge_nodes ( ) const
inlinenoexcept

◆ edge_vertices()

template<int Dim>
const EdgeVertices & hpfem::mesh::Mesh< Dim >::edge_vertices ( Index  e) const
inline

Global vertex indices of edge e, ascending; the edge is oriented from [0] to [1].

◆ edges()

template<int Dim>
std::span< const EdgeVertices > hpfem::mesh::Mesh< Dim >::edges ( ) const
inlinenoexcept

◆ face_id()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::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).

◆ face_vertices()

template<int Dim>
const FaceVertices & hpfem::mesh::Mesh< Dim >::face_vertices ( Index  f) const
inline

Global vertex indices of face f, ascending (3D only).

◆ faces()

template<int Dim>
std::span< const FaceVertices > hpfem::mesh::Mesh< Dim >::faces ( ) const
inlinenoexcept

◆ facet_cells()

template<int Dim>
const FacetCells & hpfem::mesh::Mesh< Dim >::facet_cells ( Index  f) const
inline

The one or two cells incident to facet f, ascending by cell id. A boundary facet has [1] == kInvalidIndex.

◆ facet_hanging_role()

template<int Dim>
HangingRole hpfem::mesh::Mesh< Dim >::facet_hanging_role ( Index  f) const
inline

Role of facet f: hanging parent (coarse side), hanging child (fine side) or none.

◆ facet_id()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::facet_id ( FacetVertices  vertices) const

Id of the facet with the given vertices in any order, kInvalidIndex if absent.

◆ facet_local_indices()

template<int Dim>
const FacetLocalIndices & hpfem::mesh::Mesh< Dim >::facet_local_indices ( Index  f) const
inline

Local facet number of facet f inside facet_cells(f)[0] and [1] (-1 if absent).

◆ facet_tag()

template<int Dim>
Tag hpfem::mesh::Mesh< Dim >::facet_tag ( Index  f) const
inline

◆ facet_tags()

template<int Dim>
std::span< const Tag > hpfem::mesh::Mesh< Dim >::facet_tags ( ) const
inlinenoexcept

◆ facet_vertices()

template<int Dim>
const FacetVertices & hpfem::mesh::Mesh< Dim >::facet_vertices ( Index  f) const
inline

Global vertex indices of facet f, ascending: an edge in 2D, a face in 3D.

◆ facets_with_tag()

template<int Dim>
std::vector< Index > hpfem::mesh::Mesh< Dim >::facets_with_tag ( Tag  tag) const

◆ geometry_order()

template<int Dim>
int hpfem::mesh::Mesh< Dim >::geometry_order ( ) const
inlinenoexcept

1: affine cells (vertices only); 2: one extra node per edge (set_edge_nodes).

◆ hanging_child_facets()

template<int Dim>
std::span< const Index > hpfem::mesh::Mesh< Dim >::hanging_child_facets ( Index  f) const

Child facets of a hanging parent facet (two edges in 2D, four faces in 3D), empty for any other facet.

◆ hanging_edges()

template<int Dim>
std::span< const HangingEdge > hpfem::mesh::Mesh< Dim >::hanging_edges ( ) const
inlinenoexcept

◆ hanging_faces()

template<int Dim>
std::span< const HangingFace > hpfem::mesh::Mesh< Dim >::hanging_faces ( ) const
inlinenoexcept

◆ hanging_parent_facet()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::hanging_parent_facet ( Index  f) const
inline

Parent facet of a hanging child facet, kInvalidIndex for any other facet.

◆ is_boundary_facet()

template<int Dim>
bool hpfem::mesh::Mesh< Dim >::is_boundary_facet ( Index  f) const
inline

A facet with one cell that is neither a hanging parent nor a hanging child.

◆ is_conforming()

template<int Dim>
bool hpfem::mesh::Mesh< Dim >::is_conforming ( ) const
inlinenoexcept

True if the mesh has no hanging entities.

◆ num_boundary_facets()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::num_boundary_facets ( ) const
inlinenoexcept

◆ num_cells()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::num_cells ( ) const
inlinenoexcept

◆ num_edges()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::num_edges ( ) const
inlinenoexcept

◆ num_faces()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::num_faces ( ) const
inlinenoexcept

◆ num_facets()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::num_facets ( ) const
inlinenoexcept

Number of codimension-1 entities: edges in 2D, faces in 3D.

◆ num_vertices()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::num_vertices ( ) const
inlinenoexcept

◆ set_cell_tag()

template<int Dim>
void hpfem::mesh::Mesh< Dim >::set_cell_tag ( Index  c,
Tag  tag 
)
inline

◆ set_edge_nodes()

template<int Dim>
void hpfem::mesh::Mesh< Dim >::set_edge_nodes ( std::vector< Vertex >  nodes)

Installs second-order geometry: nodes[e] is the image of the midpoint of edge e, e.g. its projection onto a curved boundary; straight edges keep their midpoint. Shared between the cells of the edge, hence orientation-free. An empty vector returns to affine geometry.

Exceptions
InvalidArgumentif nodes.size() is neither 0 nor num_edges().

◆ set_facet_tag()

template<int Dim>
void hpfem::mesh::Mesh< Dim >::set_facet_tag ( Index  f,
Tag  tag 
)
inline

◆ set_facet_tags()

template<int Dim>
void hpfem::mesh::Mesh< Dim >::set_facet_tags ( std::span< const FacetVertices >  facets,
std::span< const Tag >  tags 
)

Tags facets given by their vertices in any order, e.g. the boundary elements of a Gmsh file. O(n log F).

Exceptions
InvalidArgumentif the sizes differ or a tuple is not a facet of this mesh (the message names the vertices).

◆ set_hanging()

template<int Dim>
void hpfem::mesh::Mesh< Dim >::set_hanging ( std::vector< HangingEdge >  edges,
std::vector< HangingFace >  faces 
)

Registers the hanging entities of a one-irregular mesh (replacing earlier ones) and recomputes the boundary facets. Edges of hanging faces must be listed among the hanging edges as well.

Exceptions
InvalidArgumentif an entity is out of range, a parent or child facet has two cells, or a facet is both parent and child.

◆ set_tag_name()

template<int Dim>
void hpfem::mesh::Mesh< Dim >::set_tag_name ( int  dim,
Tag  tag,
std::string  name 
)

Names of physical groups, keyed by entity dimension (Dim for cells, Dim - 1 for facets) and tag. tag_name returns an empty string for unnamed tags.

Exceptions
InvalidArgumentfor any other dim.

◆ set_vertex()

template<int Dim>
void hpfem::mesh::Mesh< Dim >::set_vertex ( Index  v,
const Vertex &  x 
)

Moves a vertex (e.g. snapping a mesh line onto a material interface). The topology is untouched; point locators and cell geometries created before are stale afterwards, and the control points of curved cells are not adjusted.

Exceptions
InvalidArgumentfor an index out of range.

◆ tag_boundary()

template<int Dim>
Index hpfem::mesh::Mesh< Dim >::tag_boundary ( Tag  tag)

Assigns tag to every boundary facet that is still untagged; returns how many.

◆ tag_by_name()

template<int Dim>
std::optional< Tag > hpfem::mesh::Mesh< Dim >::tag_by_name ( int  dim,
std::string_view  name 
) const

◆ tag_name()

template<int Dim>
const std::string & hpfem::mesh::Mesh< Dim >::tag_name ( int  dim,
Tag  tag 
) const

◆ tag_names()

template<int Dim>
const std::map< Tag, std::string > & hpfem::mesh::Mesh< Dim >::tag_names ( int  dim) const
inline

All named tags of entity dimension dim.

◆ vertex()

template<int Dim>
const Vertex & hpfem::mesh::Mesh< Dim >::vertex ( Index  v) const
inline

◆ vertices()

template<int Dim>
std::span< const Vertex > hpfem::mesh::Mesh< Dim >::vertices ( ) const
inlinenoexcept

Member Data Documentation

◆ kEdgesPerCell

template<int Dim>
constexpr LocalIndex hpfem::mesh::Mesh< Dim >::kEdgesPerCell = Topology::kNumEdges
staticconstexpr

◆ kFacesPerCell

template<int Dim>
constexpr LocalIndex hpfem::mesh::Mesh< Dim >::kFacesPerCell = 4
staticconstexpr

meaningful for Dim = 3 only

◆ kFacetsPerCell

template<int Dim>
constexpr LocalIndex hpfem::mesh::Mesh< Dim >::kFacetsPerCell = Dim + 1
staticconstexpr

◆ kVerticesPerCell

template<int Dim>
constexpr LocalIndex hpfem::mesh::Mesh< Dim >::kVerticesPerCell = Dim + 1
staticconstexpr

The documentation for this class was generated from the following file: