deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
polynomials_integrated_legendre_sz.cc
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2017 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14#include <deal.II/base/config.h>
15
18
19#include <vector>
20
22
24 : Polynomials::Polynomial<double>(get_coefficients(k))
25{}
26
27
28
29std::vector<double>
31{
32 std::vector<double> coefficients(k + 1);
33
34 // first two polynomials are hard-coded:
35 if (k == 0)
36 {
37 coefficients[0] = -1.;
38 return coefficients;
39 }
40 else if (k == 1)
41 {
42 coefficients[0] = 0.;
43 coefficients[1] = 1.;
44 return coefficients;
45 }
46
47 // General formula is:
48 // k*L_{k}(x) = (2*k-3)*x*L_{k-1} - (k-3)*L_{k-2}.
49 std::vector<double> coefficients_km2 = get_coefficients(k - 2);
50 std::vector<double> coefficients_km1 = get_coefficients(k - 1);
51
52 const double a = 1.0 / k;
53 const double b = 2.0 * k - 3.0;
54 const double c = k - 3.0;
55
56 // To maintain stability, delay the division (multiplication by a) until the
57 // end.
58 for (unsigned int i = 1; i <= k - 2; ++i)
59 {
60 coefficients[i] = b * coefficients_km1[i - 1] - c * coefficients_km2[i];
61 }
62
63 coefficients[0] = -c * coefficients_km2[0];
64 coefficients[k] = b * coefficients_km1[k - 1];
65 coefficients[k - 1] = b * coefficients_km1[k - 2];
66
67 for (double &coefficient : coefficients)
68 {
69 coefficient *= a;
70 }
71
72 return coefficients;
73}
74
75
76
77std::vector<Polynomials::Polynomial<double>>
79{
80 std::vector<Polynomials::Polynomial<double>> v;
81 v.reserve(degree + 1);
82 for (unsigned int i = 0; i <= degree; ++i)
83 {
84 v.push_back(IntegratedLegendreSZ(i));
85 }
86 return v;
87}
88
89
90
static std::vector< Polynomials::Polynomial< double > > generate_complete_basis(const unsigned int degree)
static std::vector< double > get_coefficients(const unsigned int k)
std::vector< double > coefficients
Definition polynomial.h:323
unsigned int degree() const
Definition polynomial.h:918
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39