OISEAU
A modern DGTD framework
Loading...
Searching...
No Matches
dg_integration.hpp
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 <memory>
12#include <span>
13#include <vector>
14#include <xtensor/containers/xarray.hpp>
15#include <xtensor/core/xtensor_forward.hpp>
16
17#include "oiseau/dg/dg_connectivity.hpp"
18#include "oiseau/dg/dg_geometry.hpp"
19#include "oiseau/dg/dg_space.hpp"
20#include "oiseau/mesh/mesh.hpp"
21
22namespace oiseau::dg {
23
30 public:
32 using Matrix = xt::xarray<double>;
33
59
73
77 std::shared_ptr<const QuadratureRule> quadrature;
85 };
86
88 struct FaceRule {
90 std::array<double, 3> outward_normal{};
94 std::shared_ptr<const ReferenceFaceRule> minus;
100 std::shared_ptr<const ReferenceFaceRule> plus;
102 double weight_scale = 0.0;
104 double lift_scale = 0.0;
105
107 std::size_t point_count() const { return minus->quadrature->weights.size(); }
112 double physical_weight(std::size_t q) const {
113 return weight_scale * minus->quadrature->weights(q);
114 }
115
120 double physical_lift(std::size_t q, std::size_t node) const {
121 return lift_scale * minus->lift(q, node);
122 }
123
126 };
127
129 struct CellRule {
133 std::size_t group_cell_index = 0;
135 std::shared_ptr<const ReferenceRule> reference;
137 double volume_jacobian = 0.0;
139 std::array<double, 9> inverse_jacobian{};
140
144 std::size_t node_count() const { return reference ? reference->mass.shape()[0] : 0; }
146 Matrix mass() const;
148 Matrix inverse_mass() const;
156 Matrix stiffness_x() const;
158 Matrix stiffness_y() const;
160 Matrix stiffness_z() const;
162 std::vector<double> weak_derivative_x;
164 std::vector<double> weak_derivative_y;
166 std::vector<double> weak_derivative_z;
168 std::vector<FaceRule> faces;
169 };
170
180 DGIntegration(const mesh::Mesh& mesh, const DGSpace& space, const DGConnectivity& connectivity,
181 const DGGeometry& geometry);
182
186 std::span<const CellRule> cells() const { return m_cells; }
193 const CellRule& cell(std::size_t mesh_cell_index) const;
194
195 private:
196 std::vector<CellRule> m_cells;
197};
198
199} // namespace oiseau::dg
Stores face adjacency for the top-dimensional cells of a 1D, 2D, or 3D mesh.
Definition dg_connectivity.hpp:25
static constexpr std::size_t no_neighbor
Sentinel for missing neighbor cell and face indices.
Definition dg_connectivity.hpp:28
Stores geometric factors for top-dimensional cells in a mesh.
Definition dg_geometry.hpp:24
std::span< const CellRule > cells() const
Definition dg_integration.hpp:186
DGIntegration(const mesh::Mesh &mesh, const DGSpace &space, const DGConnectivity &connectivity, const DGGeometry &geometry)
Builds integration rules for the cells in a DG space.
Definition dg_integration.cpp:388
const CellRule & cell(std::size_t mesh_cell_index) const
Returns the integration rule for a mesh cell.
Definition dg_integration.cpp:434
xt::xarray< double > Matrix
Array type for integration operators and quadrature data.
Definition dg_integration.hpp:32
Stores discontinuous Galerkin nodes grouped by cell kind and order.
Definition dg_space.hpp:24
Definition mesh.hpp:15
Volume and face integration data for one mesh cell.
Definition dg_integration.hpp:129
Matrix mass() const
Definition dg_integration.cpp:412
bool has_group() const
Definition dg_integration.hpp:142
Matrix stiffness_x() const
Returns the physical weak stiffness matrix in the x direction.
Definition dg_integration.cpp:422
Matrix stiffness_y() const
Definition dg_integration.cpp:426
std::array< double, 9 > inverse_jacobian
Padded row-major 3 by 3 inverse Jacobian .
Definition dg_integration.hpp:139
std::vector< double > weak_derivative_z
Physical weak derivative , stored as [test node, trial node].
Definition dg_integration.hpp:166
std::size_t group_cell_index
Index of this cell within its DGSpace group.
Definition dg_integration.hpp:133
std::vector< double > weak_derivative_x
Physical weak derivative , stored as [test node, trial node].
Definition dg_integration.hpp:162
std::size_t group_index
Index of the DGSpace group, or DGConnectivity::no_neighbor for an inactive cell.
Definition dg_integration.hpp:131
std::shared_ptr< const ReferenceRule > reference
Shared reference volume operators, or nullptr for an inactive cell.
Definition dg_integration.hpp:135
std::vector< FaceRule > faces
Face rules in local face order.
Definition dg_integration.hpp:168
std::vector< double > weak_derivative_y
Physical weak derivative , stored as [test node, trial node].
Definition dg_integration.hpp:164
double volume_jacobian
Absolute Jacobian determinant used to scale volume integrals.
Definition dg_integration.hpp:137
Matrix stiffness_z() const
Definition dg_integration.cpp:430
Matrix inverse_mass() const
Definition dg_integration.cpp:417
std::size_t node_count() const
Definition dg_integration.hpp:144
Integration data for one physical cell face.
Definition dg_integration.hpp:88
double lift_scale
The face weight scale divided by to scale the reference lift.
Definition dg_integration.hpp:104
std::shared_ptr< const ReferenceFaceRule > plus
Reference face rule for the neighbor cell, or nullptr on a boundary.
Definition dg_integration.hpp:100
double physical_lift(std::size_t q, std::size_t node) const
Returns an entry of the physical lift for the local cell.
Definition dg_integration.hpp:120
bool is_boundary() const
Definition dg_integration.hpp:125
double physical_weight(std::size_t q) const
Returns a quadrature weight scaled by the physical face measure ratio.
Definition dg_integration.hpp:112
std::array< double, 3 > outward_normal
Outward unit normal, padded to three coordinates.
Definition dg_integration.hpp:90
std::size_t point_count() const
Definition dg_integration.hpp:107
double weight_scale
Ratio of physical face measure to canonical face measure.
Definition dg_integration.hpp:102
std::shared_ptr< const ReferenceFaceRule > minus
Reference face rule for the local cell.
Definition dg_integration.hpp:94
std::size_t neighbor_cell
Mesh index of the neighbor cell, or DGConnectivity::no_neighbor on a boundary.
Definition dg_integration.hpp:92
Weights and nodes on the canonical point, line, triangle, or square.
Definition dg_integration.hpp:67
Matrix weights
Weights in quadrature point order.
Definition dg_integration.hpp:71
Matrix nodes
Coordinates of the quadrature points on the canonical face.
Definition dg_integration.hpp:69
Face operators shared by cell shape, order, local face, quadrature, and orientation.
Definition dg_integration.hpp:75
Matrix trace
Trace interpolation matrix with shape [quadrature point, cell node].
Definition dg_integration.hpp:79
Matrix lift
Reference lift , stored as [quadrature point, test node].
Definition dg_integration.hpp:84
std::shared_ptr< const QuadratureRule > quadrature
Canonical face quadrature used by the operators.
Definition dg_integration.hpp:77
Reference-cell volume operators shared by one cell shape and polynomial order.
Definition dg_integration.hpp:35
Matrix mass
Reference mass matrix.
Definition dg_integration.hpp:37
Matrix stiffness_r
Reference weak stiffness matrix in the r direction.
Definition dg_integration.hpp:41
Matrix derivative_t
Strong nodal derivative matrix in the t direction.
Definition dg_integration.hpp:57
Matrix inverse_mass
Inverse reference mass matrix.
Definition dg_integration.hpp:39
Matrix derivative_s
Strong nodal derivative matrix in the s direction.
Definition dg_integration.hpp:55
Matrix weak_derivative_s
Inverse mass times reference stiffness in the s direction.
Definition dg_integration.hpp:49
Matrix stiffness_s
Reference weak stiffness matrix in the s direction.
Definition dg_integration.hpp:43
Matrix stiffness_t
Reference weak stiffness matrix in the t direction.
Definition dg_integration.hpp:45
Matrix derivative_r
Strong nodal derivative matrix in the r direction.
Definition dg_integration.hpp:53
Matrix weak_derivative_t
Inverse mass times reference stiffness in the t direction.
Definition dg_integration.hpp:51
Matrix weak_derivative_r
Inverse mass times reference stiffness in the r direction.
Definition dg_integration.hpp:47