16 #ifndef dealii_polynomial_h 17 #define dealii_polynomial_h 21 #include <deal.II/base/config.h> 23 #include <deal.II/base/exceptions.h> 24 #include <deal.II/base/point.h> 25 #include <deal.II/base/subscriptor.h> 30 DEAL_II_NAMESPACE_OPEN
61 template <
typename number>
88 const unsigned int evaluation_point);
103 value(
const number x)
const;
116 value(
const number x, std::vector<number> &values)
const;
130 value(
const number x,
131 const unsigned int n_derivatives,
132 number * values)
const;
150 scale(
const number factor);
167 template <
typename number2>
169 shift(
const number2 offset);
218 print(std::ostream &out)
const;
224 template <
class Archive>
226 serialize(Archive &ar,
const unsigned int version);
238 template <
typename number2>
292 template <
typename number>
300 Monomial(
const unsigned int n,
const double coefficient = 1.);
308 static std::vector<Polynomial<number>>
315 static std::vector<number>
316 make_vector(
unsigned int n,
const double coefficient);
355 static std::vector<Polynomial<double>>
365 const unsigned int support_point,
366 std::vector<double> &a);
377 std::vector<Polynomial<double>>
411 static std::vector<Polynomial<double>>
443 Lobatto(
const unsigned int p = 0);
449 static std::vector<Polynomial<double>>
520 static std::vector<Polynomial<double>>
534 static const std::vector<double> &
545 static std::vector<std::unique_ptr<const std::vector<double>>>
595 static std::vector<Polynomial<double>>
710 const unsigned int index);
716 static std::vector<Polynomial<double>>
731 template <
typename Number>
733 jacobi_polynomial_value(
const unsigned int degree,
751 template <
typename Number>
765 template <
typename number>
767 : in_lagrange_product_form(false)
768 , lagrange_weight(1.)
773 template <
typename number>
777 if (in_lagrange_product_form ==
true)
779 return lagrange_support_points.size();
784 return coefficients.size() - 1;
790 template <
typename number>
794 if (in_lagrange_product_form ==
false)
799 const unsigned int m = coefficients.size();
800 number value = coefficients.back();
801 for (
int k = m - 2; k >= 0; --k)
802 value = value * x + coefficients[k];
808 const unsigned int m = lagrange_support_points.size();
810 for (
unsigned int j = 0; j < m; ++j)
811 value *= x - lagrange_support_points[j];
812 value *= lagrange_weight;
819 template <
typename number>
820 template <
class Archive>
827 ar &in_lagrange_product_form;
828 ar &lagrange_support_points;
834 template <
typename Number>
836 jacobi_polynomial_value(
const unsigned int degree,
841 Assert(alpha >= 0 && beta >= 0,
848 const Number xeval = Number(-1) + 2. * x;
854 p1 = ((alpha + beta + 2) * xeval + (alpha - beta)) / 2;
858 for (
unsigned int i = 1; i < degree; ++i)
860 const Number v = 2 * i + (alpha + beta);
861 const Number a1 = 2 * (i + 1) * (i + (alpha + beta + 1)) * v;
862 const Number a2 = (v + 1) * (alpha * alpha - beta * beta);
863 const Number a3 = v * (v + 1) * (v + 2);
864 const Number a4 = 2 * (i + alpha) * (i + beta) * (v + 2);
866 const Number pn = ((a2 + a3 * xeval) * p1 - a4 * p0) / a1;
875 template <
typename Number>
881 std::vector<Number> x(degree, 0.5);
892 const Number tolerance =
893 4 * std::max(static_cast<Number>(std::numeric_limits<double>::epsilon()),
894 std::numeric_limits<Number>::epsilon());
902 const unsigned int n_points = (alpha == beta ? degree / 2 : degree);
903 for (
unsigned int k = 0; k < n_points; ++k)
907 Number r = 0.5 - 0.5 * std::cos(static_cast<Number>(2 * k + 1) /
910 r = (r + x[k - 1]) / 2;
913 for (
unsigned int it = 1; it < 1000; ++it)
916 for (
unsigned int i = 0; i < k; ++i)
917 s += 1. / (r - x[i]);
921 (alpha + beta + degree + 1) *
922 jacobi_polynomial_value(degree - 1, alpha + 1, beta + 1, r);
925 const Number f = jacobi_polynomial_value(degree, alpha, beta, r);
926 const Number delta = f / (f * s - J_x);
929 std::abs(delta) < tolerance)
934 if (it == converged + 1)
939 ExcMessage(
"Newton iteration for zero of Jacobi polynomial " 940 "did not converge."));
946 for (
unsigned int k = n_points; k < degree; ++k)
947 x[k] = 1.0 - x[degree - k - 1];
953 DEAL_II_NAMESPACE_CLOSE
static const unsigned int invalid_unsigned_int
void serialize(Archive &ar, const unsigned int version)
Polynomial< number > & operator*=(const double s)
void scale(const number factor)
void transform_into_standard_form()
bool operator==(const Polynomial< number > &p) const
LagrangeEquidistant(const unsigned int n, const unsigned int support_point)
Polynomial< number > derivative() const
void shift(const number2 offset)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int p)
unsigned int degree() const
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
Legendre(const unsigned int p)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
Polynomial< number > & operator-=(const Polynomial< number > &p)
static std::vector< std::unique_ptr< const std::vector< double > > > recursive_coefficients
std::vector< Number > jacobi_polynomial_roots(const unsigned int degree, const int alpha, const int beta)
static void compute_coefficients(const unsigned int n, const unsigned int support_point, std::vector< double > &a)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
Monomial(const unsigned int n, const double coefficient=1.)
bool in_lagrange_product_form
number value(const number x) const
void print(std::ostream &out) const
std::vector< double > compute_coefficients(const unsigned int p)
static ::ExceptionBase & ExcMessage(std::string arg1)
static void multiply(std::vector< number > &coefficients, const number factor)
#define Assert(cond, exc)
Polynomial< number > & operator+=(const Polynomial< number > &p)
HermiteInterpolation(const unsigned int p)
Lobatto(const unsigned int p=0)
static std::vector< Polynomial< number > > generate_complete_basis(const unsigned int degree)
static std::vector< number > make_vector(unsigned int n, const double coefficient)
Hierarchical(const unsigned int p)
HermiteLikeInterpolation(const unsigned int degree, const unsigned int index)
std::vector< number > coefficients
Polynomial< number > primitive() const
static void compute_coefficients(const unsigned int p)
static const std::vector< double > & get_coefficients(const unsigned int p)
std::vector< number > lagrange_support_points
static constexpr double PI
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
static ::ExceptionBase & ExcEmptyObject()
static ::ExceptionBase & ExcNotImplemented()
std::vector< Polynomial< double > > generate_complete_Lagrange_basis(const std::vector< Point< 1 >> &points)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int p)