16#ifndef dealii_polynomial_h
17#define dealii_polynomial_h
64 template <
typename number>
91 const unsigned int evaluation_point);
121 value(
const number x, std::vector<number> &values)
const;
141 template <
typename Number2>
144 const unsigned int n_derivatives,
145 Number2 * values)
const;
159 template <std::
size_t n_entries,
typename Number2>
162 const unsigned int n_derivatives,
163 std::array<Number2, n_entries> * values)
const;
181 scale(
const number factor);
198 template <
typename number2>
200 shift(
const number2 offset);
249 print(std::ostream &out)
const;
256 template <
class Archive>
276 template <
typename number2>
328 template <
typename number>
336 Monomial(
const unsigned int n,
const double coefficient = 1.);
344 static std::vector<Polynomial<number>>
351 static std::vector<number>
352 make_vector(
unsigned int n,
const double coefficient);
389 static std::vector<Polynomial<double>>
399 const unsigned int support_point,
400 std::vector<double> &a);
411 std::vector<Polynomial<double>>
443 static std::vector<Polynomial<double>>
473 Lobatto(
const unsigned int p = 0);
479 static std::vector<Polynomial<double>>
548 static std::vector<Polynomial<double>>
562 static const std::vector<double> &
573 static std::vector<std::unique_ptr<const std::vector<double>>>
620 static std::vector<Polynomial<double>>
735 const unsigned int index);
741 static std::vector<Polynomial<double>>
756 template <
typename Number>
776 template <
typename Number>
790 template <
typename number>
792 : in_lagrange_product_form(false)
793 , lagrange_weight(1.)
798 template <
typename number>
802 if (in_lagrange_product_form ==
true)
804 return lagrange_support_points.size();
809 return coefficients.size() - 1;
815 template <
typename number>
819 if (in_lagrange_product_form ==
false)
824 const unsigned int m = coefficients.size();
825 number value = coefficients.back();
826 for (
int k = m - 2; k >= 0; --k)
827 value = value * x + coefficients[k];
833 const unsigned int m = lagrange_support_points.size();
835 for (
unsigned int j = 0; j < m; ++j)
836 value *= x - lagrange_support_points[j];
837 value *= lagrange_weight;
844 template <
typename number>
845 template <
typename Number2>
848 const unsigned int n_derivatives,
849 Number2 * values)
const
851 values_of_array(std::array<Number2, 1ul>{{x}},
853 reinterpret_cast<std::array<Number2, 1ul> *
>(values));
858 template <
typename number>
859 template <std::
size_t n_entries,
typename Number2>
862 const std::array<Number2, n_entries> &x,
863 const unsigned int n_derivatives,
864 std::array<Number2, n_entries> * values)
const
867 if (in_lagrange_product_form ==
true)
872 const unsigned int n_supp = lagrange_support_points.size();
873 const number weight = lagrange_weight;
874 switch (n_derivatives)
877 for (
unsigned int e = 0; e < n_entries; ++e)
878 values[0][e] = weight;
879 for (
unsigned int k = 1; k <= n_derivatives; ++k)
880 for (
unsigned int e = 0; e < n_entries; ++e)
882 for (
unsigned int i = 0; i < n_supp; ++i)
884 std::array<Number2, n_entries> v = x;
885 for (
unsigned int e = 0; e < n_entries; ++e)
886 v[e] -= lagrange_support_points[i];
894 for (
unsigned int k = n_derivatives; k > 0; --k)
895 for (
unsigned int e = 0; e < n_entries; ++e)
896 values[k][e] = (values[k][e] * v[e] + values[k - 1][e]);
897 for (
unsigned int e = 0; e < n_entries; ++e)
898 values[0][e] *= v[e];
903 number k_factorial = 2;
904 for (
unsigned int k = 2; k <= n_derivatives; ++k)
906 for (
unsigned int e = 0; e < n_entries; ++e)
907 values[k][e] *= k_factorial;
908 k_factorial *=
static_cast<number
>(k + 1);
920 std::array<Number2, n_entries> value;
921 for (
unsigned int e = 0; e < n_entries; ++e)
923 for (
unsigned int i = 0; i < n_supp; ++i)
924 for (
unsigned int e = 0; e < n_entries; ++e)
925 value[e] *= (x[e] - lagrange_support_points[i]);
927 for (
unsigned int e = 0; e < n_entries; ++e)
928 values[0][e] = value[e];
934 std::array<Number2, n_entries> value, derivative = {};
935 for (
unsigned int e = 0; e < n_entries; ++e)
937 for (
unsigned int i = 0; i < n_supp; ++i)
938 for (
unsigned int e = 0; e < n_entries; ++e)
940 const Number2 v = x[e] - lagrange_support_points[i];
941 derivative[e] = derivative[e] * v + value[e];
945 for (
unsigned int e = 0; e < n_entries; ++e)
947 values[0][e] = value[e];
948 values[1][e] = derivative[e];
955 std::array<Number2, n_entries> value, derivative = {},
957 for (
unsigned int e = 0; e < n_entries; ++e)
959 for (
unsigned int i = 0; i < n_supp; ++i)
960 for (
unsigned int e = 0; e < n_entries; ++e)
962 const Number2 v = x[e] - lagrange_support_points[i];
964 derivative[e] = derivative[e] * v + value[e];
968 for (
unsigned int e = 0; e < n_entries; ++e)
970 values[0][e] = value[e];
971 values[1][e] = derivative[e];
972 values[2][e] =
static_cast<number
>(2) *
second[e];
984 const unsigned int m = coefficients.size();
985 std::vector<std::array<Number2, n_entries>> a(coefficients.size());
986 for (
unsigned int i = 0; i < coefficients.size(); ++i)
987 for (
unsigned int e = 0; e < n_entries; ++e)
988 a[i][e] = coefficients[i];
990 unsigned int j_factorial = 1;
995 const unsigned int min_valuessize_m =
std::min(n_derivatives + 1, m);
996 for (
unsigned int j = 0; j < min_valuessize_m; ++j)
998 for (
int k = m - 2; k >=
static_cast<int>(j); --k)
999 for (
unsigned int e = 0; e < n_entries; ++e)
1000 a[k][e] += x[e] * a[k + 1][e];
1001 for (
unsigned int e = 0; e < n_entries; ++e)
1002 values[j][e] =
static_cast<number
>(j_factorial) * a[j][e];
1004 j_factorial *= j + 1;
1008 for (
unsigned int j = min_valuessize_m; j <= n_derivatives; ++j)
1009 for (
unsigned int e = 0; e < n_entries; ++e)
1015 template <
typename number>
1016 template <
class Archive>
1023 ar &in_lagrange_product_form;
1024 ar &lagrange_support_points;
1025 ar &lagrange_weight;
1030 template <
typename Number>
1037 Assert(alpha >= 0 && beta >= 0,
1044 const Number xeval = Number(-1) + 2. * x;
1050 p1 = ((alpha + beta + 2) * xeval + (alpha - beta)) / 2;
1054 for (
unsigned int i = 1; i < degree; ++i)
1056 const Number v = 2 * i + (alpha + beta);
1057 const Number a1 = 2 * (i + 1) * (i + (alpha + beta + 1)) * v;
1058 const Number a2 = (v + 1) * (alpha * alpha - beta * beta);
1059 const Number a3 = v * (v + 1) * (v + 2);
1060 const Number a4 = 2 * (i + alpha) * (i + beta) * (v + 2);
1062 const Number pn = ((a2 + a3 * xeval) * p1 - a4 * p0) / a1;
1071 template <
typename Number>
1077 std::vector<Number> x(degree, 0.5);
1088 const Number tolerance =
1089 4 *
std::max(
static_cast<Number
>(std::numeric_limits<double>::epsilon()),
1090 std::numeric_limits<Number>::epsilon());
1098 const unsigned int n_points = (alpha == beta ? degree / 2 : degree);
1099 for (
unsigned int k = 0; k < n_points; ++k)
1103 Number r = 0.5 - 0.5 *
std::cos(
static_cast<Number
>(2 * k + 1) /
1106 r = (r + x[k - 1]) / 2;
1109 for (
unsigned int it = 1; it < 1000; ++it)
1112 for (
unsigned int i = 0; i < k; ++i)
1113 s += 1. / (r - x[i]);
1117 (alpha + beta + degree + 1) *
1122 const Number delta = f / (f * s - J_x);
1130 if (it == converged + 1)
1135 ExcMessage(
"Newton iteration for zero of Jacobi polynomial "
1136 "did not converge."));
1142 for (
unsigned int k = n_points; k < degree; ++k)
1143 x[k] = 1.0 - x[degree - k - 1];
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int p)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
static std::vector< std::unique_ptr< const std::vector< double > > > recursive_coefficients
static void compute_coefficients(const unsigned int p)
static const std::vector< double > & get_coefficients(const unsigned int p)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
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)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
std::vector< double > compute_coefficients(const unsigned int p)
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int p)
static std::vector< Polynomial< number > > generate_complete_basis(const unsigned int degree)
static std::vector< number > make_vector(unsigned int n, const double coefficient)
number value(const number x) const
bool operator==(const Polynomial< number > &p) const
std::vector< number > coefficients
Polynomial< number > primitive() const
Polynomial< number > & operator+=(const Polynomial< number > &p)
void values_of_array(const std::array< Number2, n_entries > &points, const unsigned int n_derivatives, std::array< Number2, n_entries > *values) const
Polynomial< number > derivative() const
void transform_into_standard_form()
void scale(const number factor)
Polynomial< number > & operator-=(const Polynomial< number > &p)
std::vector< number > lagrange_support_points
void shift(const number2 offset)
void print(std::ostream &out) const
bool in_lagrange_product_form
void serialize(Archive &ar, const unsigned int version)
static void multiply(std::vector< number > &coefficients, const number factor)
void value(const Number2 x, const unsigned int n_derivatives, Number2 *values) const
Polynomial< number > & operator*=(const double s)
virtual std::size_t memory_consumption() const
unsigned int degree() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcEmptyObject()
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
Number jacobi_polynomial_value(const unsigned int degree, const int alpha, const int beta, const Number x)
std::vector< Polynomial< double > > generate_complete_Lagrange_basis(const std::vector< Point< 1 > > &points)
std::vector< Number > jacobi_polynomial_roots(const unsigned int degree, const int alpha, const int beta)
static constexpr double PI
static const unsigned int invalid_unsigned_int
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)