|
hp-FEM
Adaptive hp-FEM suite for nano-optics
|
#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 |
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.
| using hpfem::mesh::Mesh< Dim >::CellEdgeFlags = std::array<bool, static_cast<std::size_t>(kEdgesPerCell)> |
| using hpfem::mesh::Mesh< Dim >::CellEdges = std::array<Index, static_cast<std::size_t>(kEdgesPerCell)> |
| using hpfem::mesh::Mesh< Dim >::CellFacePermutations = std::array<std::uint8_t, static_cast<std::size_t>(kFacesPerCell)> |
| using hpfem::mesh::Mesh< Dim >::CellFaces = std::array<Index, static_cast<std::size_t>(kFacesPerCell)> |
| using hpfem::mesh::Mesh< Dim >::CellFacets = std::array<Index, static_cast<std::size_t>(kFacetsPerCell)> |
| using hpfem::mesh::Mesh< Dim >::CellNeighbors = CellFacets |
| using hpfem::mesh::Mesh< Dim >::CellVertices = std::array<Index, static_cast<std::size_t>(Dim + 1)> |
| using hpfem::mesh::Mesh< Dim >::EdgeVertices = std::array<Index, 2> |
| using hpfem::mesh::Mesh< Dim >::FacetCells = std::array<Index, 2> |
| using hpfem::mesh::Mesh< Dim >::FacetLocalIndices = std::array<LocalIndex, 2> |
| using hpfem::mesh::Mesh< Dim >::FacetVertices = std::array<Index, static_cast<std::size_t>(Dim)> |
| using hpfem::mesh::Mesh< Dim >::FaceVertices = std::array<Index, 3> |
| using hpfem::mesh::Mesh< Dim >::Topology = SimplexTopology<Dim> |
| using hpfem::mesh::Mesh< Dim >::Vertex = Point<Dim> |
|
strong |
| 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.
| InvalidArgument | if a cell references a vertex out of range or twice. |
| 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.
| InvalidArgument | if cell_tags is neither empty nor of size cells.size(). |
|
inlinenoexcept |
Ids of all boundary facets, ascending.
|
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.
|
inline |
Global edge ids of cell c, indexed by local edge number.
|
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]].
|
inline |
Global face ids of cell c, indexed by local face number (3D only).
|
inline |
Global facet ids of cell c: cell_edges(c) in 2D, cell_faces(c) in 3D.
|
inline |
Neighbour of cell c across its local facet k, kInvalidIndex on the boundary.
|
inline |
|
inlinenoexcept |
|
inline |
Global vertex indices of cell c in local order (SimplexTopology<Dim>).
|
inlinenoexcept |
| std::vector< Index > hpfem::mesh::Mesh< Dim >::cells_with_tag | ( | Tag | tag | ) | const |
Ids of all cells / facets carrying tag, ascending. O(N).
|
inline |
All cells containing edge e, ascending (one or two in 2D, any number in 3D).
| 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).
|
inline |
Second-order node of edge e; requires geometry_order() == 2.
|
inlinenoexcept |
|
inline |
Global vertex indices of edge e, ascending; the edge is oriented from [0] to [1].
|
inlinenoexcept |
| 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).
|
inline |
Global vertex indices of face f, ascending (3D only).
|
inlinenoexcept |
|
inline |
The one or two cells incident to facet f, ascending by cell id. A boundary facet has [1] == kInvalidIndex.
|
inline |
Role of facet f: hanging parent (coarse side), hanging child (fine side) or none.
| Index hpfem::mesh::Mesh< Dim >::facet_id | ( | FacetVertices | vertices | ) | const |
Id of the facet with the given vertices in any order, kInvalidIndex if absent.
|
inline |
Local facet number of facet f inside facet_cells(f)[0] and [1] (-1 if absent).
|
inline |
|
inlinenoexcept |
|
inline |
Global vertex indices of facet f, ascending: an edge in 2D, a face in 3D.
| std::vector< Index > hpfem::mesh::Mesh< Dim >::facets_with_tag | ( | Tag | tag | ) | const |
|
inlinenoexcept |
1: affine cells (vertices only); 2: one extra node per edge (set_edge_nodes).
| 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.
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
Parent facet of a hanging child facet, kInvalidIndex for any other facet.
|
inline |
A facet with one cell that is neither a hanging parent nor a hanging child.
|
inlinenoexcept |
True if the mesh has no hanging entities.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Number of codimension-1 entities: edges in 2D, faces in 3D.
|
inlinenoexcept |
|
inline |
| 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.
| InvalidArgument | if nodes.size() is neither 0 nor num_edges(). |
|
inline |
| 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).
| InvalidArgument | if the sizes differ or a tuple is not a facet of this mesh (the message names the vertices). |
| 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.
| InvalidArgument | if an entity is out of range, a parent or child facet has two cells, or a facet is both parent and child. |
| 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.
| InvalidArgument | for any other 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.
| InvalidArgument | for an index out of range. |
| Index hpfem::mesh::Mesh< Dim >::tag_boundary | ( | Tag | tag | ) |
Assigns tag to every boundary facet that is still untagged; returns how many.
| std::optional< Tag > hpfem::mesh::Mesh< Dim >::tag_by_name | ( | int | dim, |
| std::string_view | name | ||
| ) | const |
| const std::string & hpfem::mesh::Mesh< Dim >::tag_name | ( | int | dim, |
| Tag | tag | ||
| ) | const |
|
inline |
All named tags of entity dimension dim.
|
inline |
|
inlinenoexcept |
|
staticconstexpr |
|
staticconstexpr |
meaningful for Dim = 3 only
|
staticconstexpr |
|
staticconstexpr |