Eigen-Contrib  5.0.1
 
Loading...
Searching...
No Matches
Eigen::Stencil< Derivative, Scalar, Size > Class Template Reference

#include <contrib/Eigen/src/NumericalDiff/Stencil.h>

Detailed Description

template<int Derivative, typename Scalar, int Size>
class Eigen::Stencil< Derivative, Scalar, Size >

Finite-difference weights on an arbitrarily spaced grid.

Computes the weights of the order-Derivative finite-difference formula for the grid points, using Fornberg's recursive algorithm:

B. Fornberg, "Generation of Finite Difference Formulas on Arbitrarily Spaced Grids", Math. Comp. 51 (1988), 699-706.

The implementation follows the equivalent, in-place algorithmic form given in the follow-up:

B. Fornberg, "Calculation of Weights in Finite Difference Formulas", SIAM Review 40 (1998), 685-691.

The evaluation point is fixed at 0: points are read as offsets from wherever the derivative is to be evaluated. This is lossless, since shifting every point (and the evaluation point) by the same amount leaves the weights unchanged, so a caller evaluating at x shifts points by -x first. Derivative == 0 is supported and corresponds to interpolation: the weights reproduce f(0) exactly for every polynomial of degree less than Size.

points are used in exactly the order given: this class does not sort or otherwise reorder them. Fornberg's paper notes that the order nodes are introduced in affects the conditioning of the recursion (not the exact result, by uniqueness of the interpolating polynomial), and suggests introducing nodes in order of ascending distance from the evaluation point for stability. Choosing and applying such an ordering, including e.g. a Leja ordering for complex nodes, is the caller's responsibility.

For offsets h * k at a fixed relative layout k and varying step h, the weights scale as w_i(h * k) == h^(-Derivative) * w_i(k): computing weights once on k and scaling by h^(-Derivative) avoids repeating the O(Size^2 * Derivative) recursion for every step. Stencil only produces the weights for the points it is given; choosing or adapting h itself is the caller's responsibility.

Template Parameters
DerivativeThe order of the derivative the weights approximate.
ScalarThe scalar type of the grid points and weights. Must be a non-integer type.
SizeThe number of grid points.

Public Types

using ArrayType
 

Public Member Functions

constexpr const Scalar & point (Index i) const
 
ArrayType points () const
 
template<typename Derived>
constexpr Stencil (const DenseBase< Derived > &points)
 
constexpr Stencil (const Scalar(&points)[Size])
 
constexpr const Scalar & weight (Index i) const
 
ArrayType weights () const
 

Related Symbols

(Note that these are not member symbols.)

template<int Derivative, typename Derived>
constexpr Stencil< Derivative, typename Derived::Scalar, Derived::SizeAtCompileTime > makeStencil (const DenseBase< Derived > &points)
 
template<int Derivative, typename Scalar, int Size>
constexpr Stencil< Derivative, Scalar, Size > makeStencil (const Scalar(&points)[Size])
 

Member Typedef Documentation

◆ ArrayType

template<int Derivative, typename Scalar, int Size>
using Eigen::Stencil< Derivative, Scalar, Size >::ArrayType

The type returned by weights() and points(): a plain, vectorizable array, copied out of the object.

Constructor & Destructor Documentation

◆ Stencil() [1/2]

template<int Derivative, typename Scalar, int Size>
template<typename Derived>
Eigen::Stencil< Derivative, Scalar, Size >::Stencil ( const DenseBase< Derived > & points)
inlineexplicitconstexpr

Computes the weights of the order-Derivative finite-difference formula for points, given as any fixed-size, 1D dense expression of Size coefficients convertible to Scalar.

◆ Stencil() [2/2]

template<int Derivative, typename Scalar, int Size>
Eigen::Stencil< Derivative, Scalar, Size >::Stencil ( const Scalar(&) points[Size])
inlineexplicitconstexpr

Constructs from a plain C array of Size points. Unlike the DenseBase overload above, this constructor does not route through Eigen::Array, so it and weight()/point() remain usable in an actual constant expression on compilers where Array's own fixed-size constructors are not.

Member Function Documentation

◆ point()

template<int Derivative, typename Scalar, int Size>
const Scalar & Eigen::Stencil< Derivative, Scalar, Size >::point ( Index i) const
inlineconstexpr
Returns
points()[i]. Unlike points()[i] (through the Map returned by points()), usable in a constant expression, for the same reason as weight().

◆ points()

template<int Derivative, typename Scalar, int Size>
ArrayType Eigen::Stencil< Derivative, Scalar, Size >::points ( ) const
inline
Returns
the grid points, in the order originally supplied.

◆ weight()

template<int Derivative, typename Scalar, int Size>
const Scalar & Eigen::Stencil< Derivative, Scalar, Size >::weight ( Index i) const
inlineconstexpr
Returns
the weight of points()[i]. Unlike weights()[i], usable in a constant expression: it indexes the underlying storage directly rather than through Map, whose constructor is not constexpr-evaluable on every supported compiler.

◆ weights()

template<int Derivative, typename Scalar, int Size>
ArrayType Eigen::Stencil< Derivative, Scalar, Size >::weights ( ) const
inline
Returns
the weights, in the same order as points().

Friends And Related Symbol Documentation

◆ makeStencil() [1/2]

template<int Derivative, typename Derived>
Stencil< Derivative, typename Derived::Scalar, Derived::SizeAtCompileTime > makeStencil ( const DenseBase< Derived > & points)
related

Deduces Scalar and Size from points; Derivative must still be supplied explicitly, e.g. makeStencil<2>(points). Exists because C++14 has no class template argument deduction.

◆ makeStencil() [2/2]

template<int Derivative, typename Scalar, int Size>
Stencil< Derivative, Scalar, Size > makeStencil ( const Scalar(&) points[Size])
related

As above, deducing Scalar and Size from a plain C array of points.


The documentation for this class was generated from the following file: