![]() |
deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
|
#include <deal.II/base/polynomial.h>
Base class for all 1d polynomials. A polynomial is represented in this class by its coefficients, which are set through the constructor or by derived classes.
There are two paths for evaluation of polynomials. One is based on the coefficients which are evaluated through the Horner scheme which is a robust general-purpose scheme. An alternative and more stable evaluation of high-degree polynomials with roots in the unit interval is provided by a product in terms of the roots. This form is available for special polynomials such as Lagrange polynomials or Legendre polynomials and used with the respective constructor. To obtain this more stable evaluation form, the constructor with the roots in form of a Lagrange polynomial must be used. In case a manipulation is done that changes the roots, the representation is switched to the coefficient form. The more stable Lagrange form inherits the stability properties from the related barycentric form, a popular form of polynomial interpolation formulas. However, deal.II does not have a dedicated class for an entire basis, so the overall O(n) efficiency characteristic for the barycentric form is not achieved.
This class is a typical example of a possible template argument for the TensorProductPolynomials class.
Definition at line 70 of file polynomial.h.
Public Member Functions | |
| Polynomial (const std::vector< number > &coefficients) | |
| Polynomial (const unsigned int n) | |
| Polynomial (const std::vector< Point< 1 > > &lagrange_support_points, const unsigned int j) | |
| Polynomial () | |
| number | value (const number x) const |
| void | value (const number x, std::vector< number > &values) const |
| template<typename Number2 > | |
| void | value (const Number2 x, const unsigned int n_derivatives, Number2 *values) const |
| template<std::size_t n_entries, typename Number2 > | |
| void | values_of_array (const std::array< Number2, n_entries > &points, const unsigned int n_derivatives, std::array< Number2, n_entries > *values) const |
| unsigned int | degree () const |
| void | scale (const number factor) |
| template<typename number2 > | |
| void | shift (const number2 offset) |
| Polynomial< number > | derivative () const |
| Polynomial< number > | primitive () const |
| Polynomial< number > & | operator*= (const double s) |
| Polynomial< number > & | operator*= (const Polynomial< number > &p) |
| Polynomial< number > & | operator+= (const Polynomial< number > &p) |
| Polynomial< number > & | operator-= (const Polynomial< number > &p) |
| bool | operator== (const Polynomial< number > &p) const |
| void | print (std::ostream &out) const |
| template<class Archive > | |
| void | serialize (Archive &ar, const unsigned int version) |
| virtual std::size_t | memory_consumption () const |
Querying the observer pointers an object has. | |
| unsigned int | n_subscriptions () const |
| template<typename StreamType > | |
| void | list_subscribers (StreamType &stream) const |
| void | list_subscribers () const |
Static Public Member Functions | |
| static ::ExceptionBase & | ExcInUse (int arg1, std::string arg2, std::string arg3) |
| static ::ExceptionBase & | ExcNoSubscriber (std::string arg1, std::string arg2) |
Protected Member Functions | |
| void | transform_into_standard_form () |
Static Protected Member Functions | |
| static void | scale (std::vector< number > &coefficients, const number factor) |
| template<typename number2 > | |
| static void | shift (std::vector< number > &coefficients, const number2 shift) |
| static void | multiply (std::vector< number > &coefficients, const number factor) |
Protected Attributes | |
| std::vector< number > | coefficients |
| bool | in_lagrange_product_form |
| std::vector< number > | lagrange_support_points |
| number | lagrange_weight |
Private Member Functions | |
EnableObserverPointer functionality | |
Classes derived from EnableObserverPointer provide a facility to subscribe to this object. This is mostly used by the ObserverPointer class. | |
| void | subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
| void | unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
| void | check_no_subscribers () const noexcept |
Private Attributes | |
| std::atomic< unsigned int > | counter |
| std::map< std::string, unsigned int > | counter_map |
| std::vector< std::atomic< bool > * > | validity_pointers |
| const std::type_info * | object_info |
Static Private Attributes | |
| static std::mutex | mutex |
| Polynomials::Polynomial< number >::Polynomial | ( | const std::vector< number > & | coefficients | ) |
Constructor creating a polynomial in monomial form, i.e. a polynomial that is represented in the form \(p(x) = a_0 + a_1x + a_2 x^2 + \cdots + a_n x^n = \sum_{i=0}^n a_i x^i\).
The coefficients \(a_i\) of the polynomial are passed as argument to this constructor, i.e. the first element of the array denotes the constant term, the second the linear one, and so on. The degree \(n\) of the polynomial represented by this object is thus the number of elements in the coefficient array minus one.
| coefficients | The vector of coefficients \(a_i\) in the formula above. |
Definition at line 36 of file polynomial.cc.
| Polynomials::Polynomial< number >::Polynomial | ( | const unsigned int | n | ) |
Constructor creating a zero polynomial of degree n.
Definition at line 45 of file polynomial.cc.
| Polynomials::Polynomial< number >::Polynomial | ( | const std::vector< Point< 1 > > & | lagrange_support_points, |
| const unsigned int | j | ||
| ) |
Constructor for a poynomial in Lagrange form.
Lagrange polynomials are defined via their "support points" \(x_i\) as passed via the first argument to this constructor. For a given set of support points, there is a complete basis of polynomials that all have the form
\[ p_j(x) = \prod_{i\neq j} \frac{x-x_i}{x_j-x_i} \]
where \(j=0,\ldots,n-1\) where \(n\) is the number of support points and the degree of the polynomials is \(n-1\). The second argument of this constructor, \(j\), then selects which of these polynomials you want.
Definition at line 54 of file polynomial.cc.
|
inline |
Default constructor creating an illegal object.
Definition at line 909 of file polynomial.h.
|
inline |
Return the value of this polynomial at the given point.
This function uses the most numerically stable evaluation algorithm for the provided form of the polynomial. If the polynomial is in the product form of roots, the evaluation is based on products of the form (x - x_i), whereas the Horner scheme is used for polynomials in the coefficient form.
Definition at line 935 of file polynomial.h.
| void Polynomials::Polynomial< number >::value | ( | const number | x, |
| std::vector< number > & | values | ||
| ) | const |
Return the values and the derivatives of the Polynomial at point x. values[i], i=0,...,values.size()-1 includes the ith derivative. The number of derivatives to be computed is thus determined by the size of the array passed.
This function uses the Horner scheme for numerical stability of the evaluation for polynomials in the coefficient form or the product of terms involving the roots if that representation is used.
Definition at line 83 of file polynomial.cc.
|
inline |
Return the values and the derivatives of the Polynomial at point x. values[i], i=0,...,n_derivatives includes the ith derivative. The number of derivatives to be computed is determined by n_derivatives and values has to provide sufficient space for n_derivatives + 1 values.
This function uses the most numerically stable evaluation algorithm for the provided form of the polynomial. If the polynomial is in the product form of roots, the evaluation is based on products of the form (x - x_i), whereas the Horner scheme is used for polynomials in the coefficient form.
The template type Number2 must implement arithmetic operations such as additions or multiplication with the type number of the polynomial, and must be convertible from number by operator=.
Definition at line 965 of file polynomial.h.
|
inline |
Similar to the function above, but evaluate the polynomials on several positions at once, as described by the array argument points. This function is can be faster than the other function when the same polynomial should be evaluated on several positions at once, e.g., the x,y,z coordinates of a point for tensor-product polynomials.
The template type Number2 must implement arithmetic operations such as additions or multiplication with the type number of the polynomial, and must be convertible from number by operator=.
Definition at line 983 of file polynomial.h.
|
inline |
Degree of the polynomial. This is the degree reflected by the number of coefficients provided by the constructor. Leading non-zero coefficients are not treated separately.
Definition at line 918 of file polynomial.h.
| void Polynomials::Polynomial< number >::scale | ( | const number | factor | ) |
Scale the abscissa of the polynomial. Given the polynomial p(t) and the scaling t = ax, then the result of this operation is the polynomial q, such that q(x) = p(t).
The operation is performed in place.
Definition at line 148 of file polynomial.cc.
| void Polynomials::Polynomial< number >::shift | ( | const number2 | offset | ) |
Shift the abscissa oft the polynomial. Given the polynomial p(t) and the shift t = x + a, then the result of this operation is the polynomial q, such that q(x) = p(t).
The template parameter allows to compute the new coefficients with higher accuracy, since all computations are performed with type number2. This may be necessary, since this operation involves a big number of additions. On a Sun Sparc Ultra with Solaris 2.8, the difference between double and long double was not significant, though.
The operation is performed in place, i.e. the coefficients of the present object are changed.
Definition at line 422 of file polynomial.cc.
| Polynomial< number > Polynomials::Polynomial< number >::derivative | ( | ) | const |
Compute the derivative of a polynomial.
Definition at line 441 of file polynomial.cc.
| Polynomial< number > Polynomials::Polynomial< number >::primitive | ( | ) | const |
Compute the primitive of a polynomial. the coefficient of the zero order term of the polynomial is zero.
Definition at line 470 of file polynomial.cc.
| Polynomial< number > & Polynomials::Polynomial< number >::operator*= | ( | const double | s | ) |
Multiply with a scalar.
Definition at line 186 of file polynomial.cc.
| Polynomial< number > & Polynomials::Polynomial< number >::operator*= | ( | const Polynomial< number > & | p | ) |
Multiply with another polynomial.
Definition at line 204 of file polynomial.cc.
| Polynomial< number > & Polynomials::Polynomial< number >::operator+= | ( | const Polynomial< number > & | p | ) |
Add a second polynomial.
Definition at line 251 of file polynomial.cc.
| Polynomial< number > & Polynomials::Polynomial< number >::operator-= | ( | const Polynomial< number > & | p | ) |
Subtract a second polynomial.
Definition at line 293 of file polynomial.cc.
| bool Polynomials::Polynomial< number >::operator== | ( | const Polynomial< number > & | p | ) | const |
Test for equality of two polynomials.
Definition at line 329 of file polynomial.cc.
| void Polynomials::Polynomial< number >::print | ( | std::ostream & | out | ) | const |
Print coefficients.
Definition at line 497 of file polynomial.cc.
|
inline |
Write or read the data of this object to or from a stream for the purpose of serialization using the BOOST serialization library.
Definition at line 1140 of file polynomial.h.
|
virtual |
Return an estimate (in bytes) for the memory consumption of this object.
Definition at line 516 of file polynomial.cc.
|
staticprotected |
This function performs the actual scaling.
Definition at line 131 of file polynomial.cc.
|
staticprotected |
This function performs the actual shift
Definition at line 360 of file polynomial.cc.
|
staticprotected |
Multiply polynomial by a factor.
Definition at line 173 of file polynomial.cc.
|
protected |
Transform polynomial form of product of linear factors into standard form, \(\sum_i a_i x^i\). Deletes all data structures related to the product form.
Definition at line 94 of file polynomial.cc.
|
inlineinherited |
Return the present number of subscriptions to this object. This allows to use this class for reference counted lifetime determination where the last one to unsubscribe also deletes the object.
Definition at line 318 of file enable_observer_pointer.h.
|
inlineinherited |
List the subscribers to the input stream.
Definition at line 335 of file enable_observer_pointer.h.
|
inherited |
List the subscribers to deallog.
Definition at line 200 of file enable_observer_pointer.cc.
|
privateinherited |
Subscribes a user of the object by storing the pointer validity. The subscriber may be identified by text supplied as identifier.
Definition at line 136 of file enable_observer_pointer.cc.
|
privateinherited |
Unsubscribes a user from the object.
identifier and the validity pointer must be the same as the one supplied to subscribe(). Definition at line 154 of file enable_observer_pointer.cc.
|
privatenoexceptinherited |
Check that there are no objects subscribing to this object. If this check passes then it is safe to destroy the current object. It this check fails then this function will either abort or print an error message to deallog (by using the AssertNothrow mechanism), but will not throw an exception.
Definition at line 58 of file enable_observer_pointer.cc.
|
protected |
Coefficients of the polynomial \(\sum_i a_i x^i\). This vector is filled by the constructor of this class and may be passed down by derived classes.
This vector cannot be constant since we want to allow copying of polynomials.
Definition at line 323 of file polynomial.h.
|
protected |
Stores whether the polynomial is in Lagrange product form, i.e., constructed as a product \((x-x_0) (x-x_1) \ldots (x-x_n)/c\), or not.
Definition at line 329 of file polynomial.h.
|
protected |
If the polynomial is in Lagrange product form, i.e., constructed as a product \((x-x_0) (x-x_1) \ldots (x-x_n)/c\), store the shifts \(x_i\).
Definition at line 335 of file polynomial.h.
|
protected |
If the polynomial is in Lagrange product form, i.e., constructed as a product \((x-x_0) (x-x_1) \ldots (x-x_n)/c\), store the weight c.
Definition at line 341 of file polynomial.h.
|
mutableprivateinherited |
Store the number of objects which subscribed to this object. Initially, this number is zero, and upon destruction it shall be zero again (i.e. all objects which subscribed should have unsubscribed again).
The creator (and owner) of an object is counted in the map below if HE manages to supply identification.
We use the mutable keyword in order to allow subscription to constant objects also.
This counter may be read from and written to concurrently in multithreaded code: hence we use the std::atomic class template.
Definition at line 212 of file enable_observer_pointer.h.
|
mutableprivateinherited |
In this map, we count subscriptions for each different identification string supplied to subscribe().
Definition at line 218 of file enable_observer_pointer.h.
|
mutableprivateinherited |
In this vector, we store pointers to the validity bool in the ObserverPointer objects that subscribe to this class.
Definition at line 224 of file enable_observer_pointer.h.
|
mutableprivateinherited |
Pointer to the typeinfo object of this object, from which we can later deduce the class name. Since this information on the derived class is neither available in the destructor, nor in the constructor, we obtain it in between and store it here.
Definition at line 232 of file enable_observer_pointer.h.
|
staticprivateinherited |
A mutex used to ensure data consistency when accessing the mutable members of this class. This lock is used in the subscribe() and unsubscribe() functions, as well as in list_subscribers().
Definition at line 239 of file enable_observer_pointer.h.