16 #ifndef dealii_polynomial_h 17 #define dealii_polynomial_h 21 #include <deal.II/base/config.h> 22 #include <deal.II/base/exceptions.h> 23 #include <deal.II/base/subscriptor.h> 24 #include <deal.II/base/point.h> 29 DEAL_II_NAMESPACE_OPEN
61 template <
typename number>
88 const unsigned int evaluation_point);
102 number
value (
const number x)
const;
114 void value (
const number x,
115 std::vector<number> &values)
const;
128 void value (
const number x,
129 const unsigned int n_derivatives,
130 number *values)
const;
137 unsigned int degree ()
const;
146 void scale (
const number factor);
163 template <
typename number2>
164 void shift (
const number2 offset);
205 void print(std::ostream &out)
const;
211 template <
class Archive>
212 void serialize (Archive &ar,
const unsigned int version);
220 const number factor);
225 template <
typename number2>
227 const number2
shift);
233 const number factor);
278 template <
typename number>
287 const double coefficient = 1.);
296 std::vector<Polynomial<number> >
303 static std::vector<number>
make_vector(
unsigned int n,
304 const double coefficient);
334 const unsigned int support_point);
345 std::vector<Polynomial<double> >
357 const unsigned int support_point,
358 std::vector<double> &a);
369 std::vector<Polynomial<double> >
404 std::vector<Polynomial<double> >
436 Lobatto (
const unsigned int p = 0);
442 static std::vector<Polynomial<double> >
513 std::vector<Polynomial<double> >
526 static const std::vector<double> &
586 static std::vector<Polynomial<double> >
701 const unsigned int index);
707 static std::vector<Polynomial<double> >
722 template <
typename Number>
724 jacobi_polynomial_value(
const unsigned int degree,
742 template <
typename Number>
756 template <
typename number>
760 in_lagrange_product_form (false),
766 template <
typename number>
771 if (in_lagrange_product_form ==
true)
773 return lagrange_support_points.size();
778 return coefficients.size() - 1;
784 template <
typename number>
789 if (in_lagrange_product_form ==
false)
794 const unsigned int m=coefficients.size();
795 number value = coefficients.back();
796 for (
int k=m-2; k>=0; --k)
797 value = value*x + coefficients[k];
803 const unsigned int m = lagrange_support_points.size();
805 for (
unsigned int j=0; j<m; ++j)
806 value *= x-lagrange_support_points[j];
807 value *= lagrange_weight;
814 template <
typename number>
815 template <
class Archive>
823 ar &in_lagrange_product_form;
824 ar &lagrange_support_points;
830 template <
typename Number>
832 jacobi_polynomial_value(
const unsigned int degree,
837 Assert(alpha >=0 && beta >= 0,
844 const Number xeval = Number(-1) + 2. * x;
850 p1 = ((alpha+beta+2)*xeval + (alpha-beta))/2;
854 for (
unsigned int i=1; i<degree; ++i)
856 const Number v = 2*i + (alpha + beta);
857 const Number a1 = 2*(i+1)*(i + (alpha + beta + 1))*v;
858 const Number a2 = (v + 1)*(alpha*alpha - beta*beta);
859 const Number a3 = v*(v + 1)*(v + 2);
860 const Number a4 = 2*(i+alpha)*(i+beta)*(v + 2);
862 const Number pn = ((a2 + a3*xeval)*p1 - a4*p0)/a1;
871 template <
typename Number>
877 std::vector<Number> x(degree, 0.5);
888 const Number tolerance
889 = 4 * std::max(static_cast<Number>(std::numeric_limits<double>::epsilon()),
890 std::numeric_limits<Number>::epsilon());
898 const unsigned int n_points = (alpha == beta ? degree/2 : degree);
899 for (
unsigned int k=0; k<n_points; ++k)
903 Number r = 0.5-0.5*std::cos(static_cast<Number> (2*k+1)/(2*degree) *
909 for (
unsigned int it=1; it<1000; ++it)
912 for (
unsigned int i=0; i<k; ++i)
916 const Number J_x = (alpha+beta+degree+1)*
917 jacobi_polynomial_value(degree-1, alpha+1,
921 const Number f = jacobi_polynomial_value(degree, alpha, beta, r);
922 const Number delta = f/(f*s - J_x);
925 std::abs(delta) < tolerance)
930 if (it == converged + 1)
935 ExcMessage(
"Newton iteration for zero of Jacobi polynomial " 936 "did not converge."));
942 for (
unsigned int k=n_points; k<degree; ++k)
943 x[k] = 1.0-x[degree-k-1];
949 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< 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 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 std::vector< Polynomial< double > > generate_complete_basis(const unsigned int degree)
static ::ExceptionBase & ExcEmptyObject()
static ::ExceptionBase & ExcNotImplemented()
static std::vector< Polynomial< double > > generate_complete_basis(const unsigned int p)