hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
gauss_lobatto_legendre.cc
Go to the documentation of this file.
2
3#include <cassert>
4#include <stdexcept>
5
7
8namespace hummingbird {
14
16 const size_t n_points) {
17 if (n_points < 2)
18 throw std::runtime_error(
19 "n_points in GaussLobattoLegendre must be at least 2.");
20 std::vector<double> abscissas(n_points);
21
22 abscissas[0] = -1.0;
23 abscissas.back() = 1.0;
24
25 auto legendre_derivative_roots = AllLegendrePrimeRoots(n_points - 1);
26 for (auto i = 1; i < abscissas.size() - 1; i++)
27 abscissas[i] = legendre_derivative_roots[i - 1];
28 return abscissas;
29}
30
32 auto n_points = this->n_points();
34 for (auto i = 0; i < n_points; i++) {
35 for (auto k = 0; k < n_points; k++) {
36 if (i == 0 && k == 0)
37 lagrange_derivatives_.push_back(-(n_points * (n_points - 1) / 4.0));
38 else if (i == (n_points - 1) && k == (n_points - 1))
39 lagrange_derivatives_.push_back(n_points * (n_points - 1) / 4.0);
40 else if (i != k) {
41 auto abscissa_i = abscissas_.at(i);
42 auto abscissa_k = abscissas_.at(k);
43 double legendre_ratio = LegendrePolynomial(n_points - 1, abscissa_i) /
44 LegendrePolynomial(n_points - 1, abscissa_k);
45 double abscissa_difference = abscissa_i - abscissa_k;
46 lagrange_derivatives_.push_back(legendre_ratio / abscissa_difference);
47 } else {
48 lagrange_derivatives_.push_back(0.0);
49 }
50 }
51 }
52}
53
54double GaussLobattoLegendre::ComputeWeight(const size_t k, const size_t n) {
55 double double_n = static_cast<double>(n);
56 double leading_coefficient = 2.0 / (double_n * (double_n - 1.0));
57 double legendre_weight = LegendrePolynomial(n - 1, abscissas_.at(k));
58 double weight = leading_coefficient / legendre_weight / legendre_weight;
59 return weight;
60}
61
63 const std::valarray<double>& grid_function_vals) {
64 assert(grid_function_vals.size() == abscissas_.size());
65 double sum = 0.0;
66 for (auto i = 0; i < grid_function_vals.size(); i++)
67 sum += grid_function_vals[i] * weight_map_.at(i);
68 return sum;
69}
70} // namespace hummingbird
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.
const std::vector< double > & abscissas() const
std::map< unsigned int, double > weight_map_
std::vector< double > AllLegendrePrimeRoots(const int n)
Computes all roots of the polynomial. A total of n-1 roots will be computed and returned.
double LegendrePolynomial(const int n, const double x)
Computes the Legendre polynomial of degree n at a point x using the formula: