| 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 <array> | ||
| 10 | #include <cstddef> | ||
| 11 | #include <optional> | ||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | #include "oiseau/mesh/mesh.hpp" | ||
| 15 | |||
| 16 | namespace oiseau::dg { | ||
| 17 | |||
| 18 | /** | ||
| 19 | * @brief Stores geometric factors for top-dimensional cells in a mesh. | ||
| 20 | * @details The mesh is referenced, not copied, and must outlive this object. | ||
| 21 | * Geometry entries are indexed by source mesh cell. Lower-dimensional cells | ||
| 22 | * have no entry. | ||
| 23 | */ | ||
| 24 | class DGGeometry { | ||
| 25 | public: | ||
| 26 | /** @brief Geometric data for one cell face. */ | ||
| 27 | struct FaceGeometry { | ||
| 28 | /** @brief Outward unit normal, padded to three coordinates. */ | ||
| 29 | std::array<double, 3> outward_normal{}; | ||
| 30 | /** | ||
| 31 | * @brief Physical face measure. | ||
| 32 | * @details This is face length in 2D and face area in 3D. In 1D, it is 1. | ||
| 33 | */ | ||
| 34 | double measure = 0.0; | ||
| 35 | /** | ||
| 36 | * @brief Ratio of physical to reference face measure. | ||
| 37 | * @details Multiply reference face weights by this value to scale them. | ||
| 38 | */ | ||
| 39 | double surface_jacobian = 0.0; | ||
| 40 | }; | ||
| 41 | |||
| 42 | /** @brief Geometric data for one top-dimensional mesh cell. */ | ||
| 43 | struct CellGeometry { | ||
| 44 | /** @brief Index of this cell in the source mesh. */ | ||
| 45 | std::size_t mesh_cell_index = 0; | ||
| 46 | /** @brief Topological dimension of this cell. */ | ||
| 47 | std::size_t dimension = 0; | ||
| 48 | /** | ||
| 49 | * @brief Jacobian mapping reference coordinates to physical coordinates. | ||
| 50 | * @details Padded row-major 3 by 3 storage. Entry (row, column) is at | ||
| 51 | * row * 3 + column. | ||
| 52 | */ | ||
| 53 | std::array<double, 9> jacobian{}; | ||
| 54 | /** | ||
| 55 | * @brief Inverse Jacobian in padded row-major 3 by 3 storage. | ||
| 56 | * @details Entry (row, column) is at row * 3 + column. | ||
| 57 | */ | ||
| 58 | std::array<double, 9> inverse_jacobian{}; | ||
| 59 | /** | ||
| 60 | * @brief Signed Jacobian determinant. | ||
| 61 | * @details Use its absolute value to scale volume integrals. | ||
| 62 | */ | ||
| 63 | double determinant = 0.0; | ||
| 64 | /** @brief Face geometry in the cell type's local face order. */ | ||
| 65 | std::vector<FaceGeometry> faces; | ||
| 66 | }; | ||
| 67 | |||
| 68 | /** | ||
| 69 | * @brief Computes geometric factors for the mesh's top-dimensional cells. | ||
| 70 | * @param mesh Source mesh. It must outlive this object. | ||
| 71 | * @throws std::invalid_argument If dimensions, coordinates, or cell geometry | ||
| 72 | * are invalid, or if a cell mapping is non-affine. | ||
| 73 | * @throws std::out_of_range If a cell references a missing mesh vertex. | ||
| 74 | */ | ||
| 75 | explicit DGGeometry(const mesh::Mesh& mesh); | ||
| 76 | |||
| 77 | /** @brief Returns the source mesh. */ | ||
| 78 | 24 | const mesh::Mesh& mesh() const { return m_mesh; } | |
| 79 | /** | ||
| 80 | * @brief Checks whether geometric data exists for a mesh cell. | ||
| 81 | * @param mesh_cell_index Source mesh cell index. | ||
| 82 | * @return True if the cell is top-dimensional and has geometry data. | ||
| 83 | */ | ||
| 84 | bool has_cell(std::size_t mesh_cell_index) const; | ||
| 85 | /** | ||
| 86 | * @brief Returns geometric data for a mesh cell. | ||
| 87 | * @param mesh_cell_index Source mesh cell index. | ||
| 88 | * @return The cell's geometric data. | ||
| 89 | * @throws std::out_of_range If the index is invalid or the cell has no data. | ||
| 90 | */ | ||
| 91 | const CellGeometry& cell(std::size_t mesh_cell_index) const; | ||
| 92 | |||
| 93 | private: | ||
| 94 | const mesh::Mesh& m_mesh; | ||
| 95 | std::vector<std::optional<CellGeometry>> m_cells; | ||
| 96 | }; | ||
| 97 | |||
| 98 | } // namespace oiseau::dg | ||
| 99 |