hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
gauss_lobatto_legendre.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2// Copyright (c) 2026, Liam Pohlmann
3
4#ifndef HUMMINGBIRD_QUADRATURE_GAUSS_LOBATTO_LEGENDRE_H_
5#define HUMMINGBIRD_QUADRATURE_GAUSS_LOBATTO_LEGENDRE_H_
6
7#include <valarray>
8
11namespace hummingbird {
12
13/**
14 * @brief Class defining a 1D Gauss-Legendre-Lobatto quadrature set on [-1,1].
15 * The quadrature set approximates the integral using a set of weights
16 * (\f$w_k\f$) and abscissas (\f$\xi_k\f$):
17 *
18 * \f[
19 * \int_{-1}^{1}u(x)dx \approx \sum_{i=0}^{N-1}w_k u(\xi_k).
20 * \f]
21 *
22 * Formulae for this class were taken from the textbook "High-Order Methods for
23 * Incompressible Fluid Flow" by Deville, Fischer, and Mund.
24 * https://doi.org/10.1017/CBO9780511546792
25 *
26 */
27class GaussLobattoLegendre : public QuadratureBase<double> {
28 public:
29 /**
30 * @brief Construct a new GaussLobattoLegendre object
31 *
32 * @param n_points Number of quadrature points to be created
33 */
34 GaussLobattoLegendre(const size_t n_points);
35
36 /**
37 * @brief Get the derivative of the specific Lagrange polynomial at the
38 * specified node. Note that both the node index and the polynomial index are
39 * zero-indexed.
40 *
41 * @param node_idx GLL node index
42 * @param polynomial_idx Lagrange polynomial index
43 * @return double
44 */
45 double GetLagrangeDerivative(const size_t node_idx,
46 const size_t polynomial_idx) const {
47 size_t flattened_idx = node_idx * this->n_points() + polynomial_idx;
48 return lagrange_derivatives_.at(flattened_idx);
49 };
50
51 /**
52 * @brief Integrate a function defined on the abscissae given in the order the
53 * abscissae are stored.
54 *
55 * @param grid_function_vals Grid function values on the abscissae
56 * @return double
57 */
58 double IntegrateGridFunction(const std::valarray<double>& grid_function_vals);
59
60 private:
61 /// @brief Derivatives of the Lagrange polynomials at the GLL nodes. These
62 /// are stored as a flattened array and are indexed using the node number
63 /// and the polynomial number in GetLagrangeDerivative. See the extended
64 /// description in ComputeLagrangeDerivatives().
65 std::vector<double> lagrange_derivatives_;
66
67 /**
68 * @brief Computes and sets the Lagrange polynomial derivatives at the GLL
69 * nodes. The vector lagrange_derivatives_ is constructed with the
70 * polynomial index being the "fast" counting index, and the node number
71 * being the "slow" counting index. That is, the derivative of the N=1
72 * polynomial at the 3rd GLL node of 5 has a flattened index of 16.
73 *
74 */
76
77 /**
78 * @brief Computes the abscissa values, given by:
79 *
80 * \f[
81 * \xi_k = \begin{cases}
82 * -1, & k=0\\
83 * \text{zeros of } P'_{N-1}, & 1\leq k\leq N-2\\
84 * 1,& k=N-1
85 * \end{cases}
86 * \f]
87 *
88 * @param n_points Total number of abscissa points
89 * @return std::vector<double>
90 */
91 std::vector<double> ComputeAbscissas(const size_t n_points);
92
93 /**
94 * @brief Computes the weights for a Gauss-Legendre-Lobatto quadrature scheme
95 * using:
96 *
97 * \f[
98 * w_k=\frac{2}{(N-1)N}\frac{1}{[P_{N-1}(\xi_k)]^2}
99 * \f]
100 *
101 * @param k Abscissa index
102 * @param n Total number of points
103 * @return Quadrature weight associated with abscissa k
104 */
105 double ComputeWeight(const size_t k, const size_t n) override;
106};
107} // namespace hummingbird
108
109#endif // HUMMINGBIRD_QUADRATURE_GAUSS_LOBATTO_LEGENDRE_H_
double GetLagrangeDerivative(const size_t node_idx, const size_t polynomial_idx) const
Get the derivative of the specific Lagrange polynomial at the specified node. Note that both the node...
std::vector< double > lagrange_derivatives_
Derivatives of the Lagrange polynomials at the GLL nodes. These are stored as a flattened array and a...
double ComputeWeight(const size_t k, const size_t n) override
Computes the weights for a Gauss-Legendre-Lobatto quadrature scheme using:
std::vector< double > ComputeAbscissas(const size_t n_points)
Computes the abscissa values, given by:
GaussLobattoLegendre(const size_t n_points)
Construct a new GaussLobattoLegendre object.
void ComputeLagrangeDerivatives()
Computes and sets the Lagrange polynomial derivatives at the GLL nodes. The vector lagrange_derivativ...
double IntegrateGridFunction(const std::valarray< double > &grid_function_vals)
Integrate a function defined on the abscissae given in the order the abscissae are stored.