| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (C) 2026 Tiago V. L. Amorim (@tiagovla) | ||
| 2 | // | ||
| 3 | // This file is part of oiseau (https://github.com/tiagovla/oiseau) | ||
| 4 | // | ||
| 5 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 6 | |||
| 7 | #pragma once | ||
| 8 | |||
| 9 | #include <cstddef> | ||
| 10 | #include <limits> | ||
| 11 | #include <span> | ||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | #include "oiseau/mesh/mesh.hpp" | ||
| 15 | |||
| 16 | namespace oiseau::dg { | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @brief Stores face adjacency for the top-dimensional cells of a 1D, 2D, or 3D mesh. | ||
| 20 | * @details Mesh topology supplies the neighbor indices. Interior faces also | ||
| 21 | * store a vertex permutation so a numerical flux can align data from both | ||
| 22 | * sides of the interface. Connections follow the cell type's local face order | ||
| 23 | * and are indexed by the original mesh cell index. | ||
| 24 | */ | ||
| 25 | class DGConnectivity { | ||
| 26 | public: | ||
| 27 | /** @brief Sentinel for missing neighbor cell and face indices. */ | ||
| 28 | static constexpr std::size_t no_neighbor = std::numeric_limits<std::size_t>::max(); | ||
| 29 | |||
| 30 | /** @brief Connection from one local face to its neighbor. */ | ||
| 31 | struct FaceConnection { | ||
| 32 | /** @brief Mesh index of the neighboring cell, or @c no_neighbor on a boundary. */ | ||
| 33 | std::size_t neighbor_cell = no_neighbor; | ||
| 34 | /** @brief Local face index on the neighboring cell, or @c no_neighbor on a boundary. */ | ||
| 35 | std::size_t neighbor_face = no_neighbor; | ||
| 36 | /** | ||
| 37 | * @brief Maps local face vertex positions to positions on the neighboring face. | ||
| 38 | * @details @c vertex_permutation[i] gives the position of this face's vertex | ||
| 39 | * @c i in the neighbor's face ordering. A boundary face has an empty permutation. | ||
| 40 | */ | ||
| 41 | std::vector<std::size_t> vertex_permutation; | ||
| 42 | |||
| 43 | /** @return True if this face has no neighboring cell. */ | ||
| 44 | 1167 | bool is_boundary() const { return neighbor_cell == no_neighbor; } | |
| 45 | }; | ||
| 46 | |||
| 47 | /** | ||
| 48 | * @brief Calculates mesh adjacency and builds DG face connections. | ||
| 49 | * @details Updates the source topology through | ||
| 50 | * @c Topology::calculate_connectivity(). Rebuild after changing the mesh topology. | ||
| 51 | * @param mesh Source mesh. It must outlive this object. | ||
| 52 | * @throws std::invalid_argument If the mesh dimension is outside 1 through 3 or its connectivity | ||
| 53 | * is invalid. | ||
| 54 | * @throws std::out_of_range If adjacency references an invalid neighbor cell or face. | ||
| 55 | * @throws std::runtime_error If the topology's adjacency counts differ from the cell's face | ||
| 56 | * count. | ||
| 57 | */ | ||
| 58 | explicit DGConnectivity(mesh::Mesh& mesh); | ||
| 59 | |||
| 60 | /** @return A const reference to the source mesh. */ | ||
| 61 | 25 | const mesh::Mesh& mesh() const { return m_mesh; } | |
| 62 | |||
| 63 | /** | ||
| 64 | * @brief Returns the face connections for a mesh cell in local face order. | ||
| 65 | * @param mesh_cell_index Index in the source mesh. | ||
| 66 | * @return A view of the stored connections. Lower-dimensional cells return an empty span. | ||
| 67 | * @throws std::out_of_range If the mesh cell index is invalid. | ||
| 68 | */ | ||
| 69 | std::span<const FaceConnection> faces(std::size_t mesh_cell_index) const; | ||
| 70 | |||
| 71 | private: | ||
| 72 | const mesh::Mesh& m_mesh; | ||
| 73 | std::vector<std::vector<FaceConnection>> m_faces; | ||
| 74 | }; | ||
| 75 | |||
| 76 | } // namespace oiseau::dg | ||
| 77 |