Specialization of a spline with the number of sampling points only known at run time. More...
#include <dumux/common/spline.hh>
Specialization of a spline with the number of sampling points only known at run time.
This class implements a spline \(s(x)\) for which, given \(n\) sampling points \(x_1, \dots, x_n\), the following conditions hold
\begin{align*} s(x_i) & = y_i \quad \forall i \in \{1, \dots, n \}\\ s'(x_1) & = m_1 \\ s'(x_n) & = m_n \end{align*}
for any given boundary slopes \(m_1\) and \(m_n\). Alternatively, natural splines are supported which are defined by
\begin{align*} s(x_i) & = y_i \quad \forall i \in \{1, \dots, n \} \\ s''(x_1) & = 0 \\ s''(x_n) & = 0 \end{align*}
Public Member Functions | |
Spline () | |
Default constructor for a spline. More... | |
template<class ScalarArrayX , class ScalarArrayY > | |
Spline (int nSamples, const ScalarArrayX &x, const ScalarArrayY &y) | |
Convenience constructor for a natural spline. More... | |
template<class PointArray > | |
Spline (int nSamples, const PointArray &points) | |
Convenience constructor for a natural spline. More... | |
template<class ScalarContainer > | |
Spline (const ScalarContainer &x, const ScalarContainer &y) | |
Convenience constructor for a natural spline. More... | |
template<class PointContainer > | |
Spline (const PointContainer &points) | |
Convenience constructor for a natural spline. More... | |
template<class ScalarArray > | |
Spline (int nSamples, const ScalarArray &x, const ScalarArray &y, Scalar m0, Scalar m1) | |
Convenience constructor for a full spline. More... | |
template<class PointArray > | |
Spline (int nSamples, const PointArray &points, Scalar m0, Scalar m1) | |
Convenience constructor for a full spline. More... | |
template<class ScalarContainerX , class ScalarContainerY > | |
Spline (const ScalarContainerX &x, const ScalarContainerY &y, Scalar m0, Scalar m1) | |
Convenience constructor for a full spline. More... | |
template<class PointContainer > | |
Spline (const PointContainer &points, Scalar m0, Scalar m1) | |
Convenience constructor for a full spline. More... | |
int | numSamples () const |
Returns the number of sampling points. More... | |
void | setXYArrays (int nSamples, const ScalarArrayX &x, const ScalarArrayY &y, Scalar m0, Scalar m1) |
Set the sampling points and the boundary slopes of a full spline using C-style arrays. More... | |
void | setXYArrays (int nSamples, const ScalarArrayX &x, const ScalarArrayY &y) |
Set the sampling points natural spline using C-style arrays. More... | |
void | setXYContainers (const ScalarContainerX &x, const ScalarContainerY &y, Scalar m0, Scalar m1) |
Set the sampling points and the boundary slopes of a full spline using STL-compatible containers. More... | |
void | setXYContainers (const ScalarContainerX &x, const ScalarContainerY &y) |
Set the sampling points of a natural spline using STL-compatible containers. More... | |
void | setArrayOfPoints (int nSamples, const PointArray &points, Scalar m0, Scalar m1) |
Set the sampling points and the boundary slopes of a full spline using a C-style array. More... | |
void | setArrayOfPoints (int nSamples, const PointArray &points) |
Set the sampling points of a natural spline using a C-style array. More... | |
void | setContainerOfPoints (const XYContainer &points, Scalar m0, Scalar m1) |
Set the sampling points and the boundary slopes of a full spline using a STL-compatible container of array-like objects. More... | |
void | setContainerOfPoints (const XYContainer &points) |
Set the sampling points of a natural spline using a STL-compatible container of array-like objects. More... | |
void | setContainerOfTuples (const XYContainer &points, Scalar m0, Scalar m1) |
Set the sampling points and the boundary slopes of a full spline using a STL-compatible container of tuple-like objects. More... | |
void | setContainerOfTuples (const XYContainer &points) |
Set the sampling points of a natural spline using a STL-compatible container of tuple-like objects. More... | |
bool | applies (Scalar x) const |
Return true if the given x is in range [x1, xn]. More... | |
Scalar | xMin () const |
Return the x value of the leftmost sampling point. More... | |
Scalar | xMax () const |
Return the x value of the rightmost sampling point. More... | |
void | printCSV (Scalar xi0, Scalar xi1, int k) const |
Prints k tuples of the format (x, y, dx/dy, isMonotonic) to stdout. More... | |
Scalar | eval (Scalar x, bool extrapolate=false) const |
Evaluate the spline at a given position. More... | |
Scalar | evalDerivative (Scalar x, bool extrapolate=false) const |
Evaluate the spline's derivative at a given position. More... | |
Scalar | intersect (Scalar a, Scalar b, Scalar c, Scalar d) const |
Find the intersections of the spline with a cubic polynomial in the whole intervall, throws Dune::MathError exception if there is more or less than one solution. More... | |
Scalar | intersectInterval (Scalar x0, Scalar x1, Scalar a, Scalar b, Scalar c, Scalar d) const |
Find the intersections of the spline with a cubic polynomial in a sub-intervall of the spline, throws Dune::MathError exception if there is more or less than one solution. More... | |
int | monotonic (Scalar x0, Scalar x1) const |
Returns 1 if the spline is monotonically increasing, -1 if the spline is mononously decreasing and 0 if the spline is not monotonous in the interval (x0, x1). More... | |
int | monotonic () const |
Same as monotonic(x0, x1), but with the entire range of the spline as interval. More... | |
Protected Member Functions | |
void | setNumSamples_ (int nSamples) |
Resizes the internal vectors to store the sample points. More... | |
void | makeFullSpline_ (Scalar m0, Scalar m1) |
Create a natural spline from the already set sampling points. More... | |
void | makeNaturalSpline_ () |
Create a natural spline from the already set sampling points. More... | |
Scalar | x_ (int i) const |
Returns the x coordinate of the i-th sampling point. More... | |
Scalar | y_ (int i) const |
Returns the y coordinate of the i-th sampling point. More... | |
Scalar | moment_ (int i) const |
Returns the moment (i.e. second derivative) of the spline at the i-th sampling point. More... | |
void | assignSamplingPoints_ (DestVector &destX, DestVector &destY, const SourceVector &srcX, const SourceVector &srcY, int numSamples) |
Set the sampling point vectors. More... | |
void | assignFromArrayList_ (DestVector &destX, DestVector &destY, const ListIterator &srcBegin, const ListIterator &srcEnd, int numSamples) |
void | assignFromTupleList_ (DestVector &destX, DestVector &destY, ListIterator srcBegin, ListIterator srcEnd, int numSamples) |
Set the sampling points. More... | |
void | makePeriodicSystem_ (Matrix &M, Vector &d) |
Make the linear system of equations Mx = d which results in the moments of the periodic spline. More... | |
void | makeFullSystem_ (Matrix &M, Vector &d, Scalar m0, Scalar m1) |
Make the linear system of equations Mx = d which results in the moments of the full spline. More... | |
void | makeNaturalSystem_ (Matrix &M, Vector &d) |
Make the linear system of equations Mx = d which results in the moments of the natural spline. Stoer 2005: Numerische Mathematik 1, p. 111 [61]. More... | |
Scalar | eval_ (Scalar x, int i) const |
Scalar | evalDerivative_ (Scalar x, int i) const |
int | monotonic_ (int i, Scalar x0, Scalar x1) const |
int | intersectSegment_ (Scalar *sol, int segIdx, Scalar a, Scalar b, Scalar c, Scalar d, Scalar x0=-1e100, Scalar x1=1e100) const |
Find all the intersections of a segment of the spline with a cubic polynomial within a specified interval. More... | |
int | segmentIdx_ (Scalar x) const |
Scalar | h_ (int i) const |
Returns x[i] - x[i - 1]. More... | |
Scalar | a_ (int i) const |
Scalar | b_ (int i) const |
Scalar | c_ (int i) const |
Scalar | d_ (int i) const |
int | numSamples_ () const |
Returns the number of sampling points. More... | |
Protected Attributes | |
Vector | xPos_ |
Vector | yPos_ |
Vector | m_ |
|
inline |
Default constructor for a spline.
To specfiy the acutal curve, use one of the set() methods.
|
inline |
Convenience constructor for a natural spline.
nSamples | The number of sampling points (must be > 2) |
x | An array containing the \(x\) values of the spline's sampling points |
y | An array containing the \(y\) values of the spline's sampling points |
|
inline |
Convenience constructor for a natural spline.
nSamples | The number of sampling points (must be > 2) |
points | An array of \((x,y)\) tuples of the spline's sampling points |
|
inline |
Convenience constructor for a natural spline.
x | An array containing the \(x\) values of the spline's sampling points (must have a size() method) |
y | An array containing the \(y\) values of the spline's sampling points (must have a size() method) |
|
inline |
Convenience constructor for a natural spline.
points | An array of \((x,y)\) tuples of the spline's sampling points (must have a size() method) |
|
inline |
Convenience constructor for a full spline.
nSamples | The number of sampling points (must be >= 2) |
x | An array containing the \(x\) values of the spline's sampling points |
y | An array containing the \(y\) values of the spline's sampling points |
m0 | The slope of the spline at \(x_0\) |
m1 | The slope of the spline at \(x_n\) |
|
inline |
Convenience constructor for a full spline.
nSamples | The number of sampling points (must be >= 2) |
points | An array containing the \(x\) and \(x\) values of the spline's sampling points |
m0 | The slope of the spline at \(x_0\) |
m1 | The slope of the spline at \(x_n\) |
|
inline |
Convenience constructor for a full spline.
x | An array containing the \(x\) values of the spline's sampling points (must have a size() method) |
y | An array containing the \(y\) values of the spline's sampling points (must have a size() method) |
m0 | The slope of the spline at \(x_0\) |
m1 | The slope of the spline at \(x_n\) |
|
inline |
Convenience constructor for a full spline.
points | An array of \((x,y)\) tuples of the spline's sampling points (must have a size() method) |
m0 | The slope of the spline at \(x_0\) |
m1 | The slope of the spline at \(x_n\) |
|
inlineprotectedinherited |
|
inlineinherited |
Return true if the given x is in range [x1, xn].
|
inlineprotectedinherited |
|
inlineprotectedinherited |
Set the sampling points.
Here we assume that the elements of the source vector have an [] operator where v[0] is the x value and v[1] is the y value if the sampling point.
|
inlineprotectedinherited |
Set the sampling point vectors.
This takes care that the order of the x-values is ascending, although the input must be ordered already!
|
inlineprotectedinherited |
|
inlineprotectedinherited |
|
inlineprotectedinherited |
|
inlineinherited |
Evaluate the spline at a given position.
x | The value on the abscissa where the spline ought to be evaluated |
extrapolate | If this parameter is set to true, the spline will be extended beyond its range by straight lines, if false calling extrapolate for \( x \not [x_{min}, x_{max}]\) will cause a failed assertation. |
|
inlineprotectedinherited |
|
inlineinherited |
Evaluate the spline's derivative at a given position.
x | The value on the abscissa where the spline's derivative ought to be evaluated |
extrapolate | If this parameter is set to true, the spline will be extended beyond its range by straight lines, if false calling extrapolate for \( x \not [x_{min}, x_{max}]\) will cause a failed assertation. |
|
inlineprotectedinherited |
|
inlineprotectedinherited |
Returns x[i] - x[i - 1].
|
inlineinherited |
Find the intersections of the spline with a cubic polynomial in the whole intervall, throws Dune::MathError exception if there is more or less than one solution.
|
inlineinherited |
Find the intersections of the spline with a cubic polynomial in a sub-intervall of the spline, throws Dune::MathError exception if there is more or less than one solution.
|
inlineprotectedinherited |
Find all the intersections of a segment of the spline with a cubic polynomial within a specified interval.
|
inlineprotectedinherited |
Create a natural spline from the already set sampling points.
Also creates temporary matrix and right hand side vector.
|
inlineprotectedinherited |
Make the linear system of equations Mx = d which results in the moments of the full spline.
|
inlineprotectedinherited |
Create a natural spline from the already set sampling points.
Also creates temporary matrix and right hand side vector.
|
inlineprotectedinherited |
Make the linear system of equations Mx = d which results in the moments of the natural spline. Stoer 2005: Numerische Mathematik 1, p. 111 [61].
|
inlineprotectedinherited |
Make the linear system of equations Mx = d which results in the moments of the periodic spline.
When solving Mx = d, it should be noted that x[0] is trash and needs to be set to x[n-1]
|
inlineprotectedinherited |
Returns the moment (i.e. second derivative) of the spline at the i-th sampling point.
|
inlineinherited |
Same as monotonic(x0, x1), but with the entire range of the spline as interval.
|
inlineinherited |
Returns 1 if the spline is monotonically increasing, -1 if the spline is mononously decreasing and 0 if the spline is not monotonous in the interval (x0, x1).
In the corner case where the whole spline is flat, it returns 2.
|
inlineprotectedinherited |
|
inlineinherited |
Returns the number of sampling points.
|
inlineprotectedinherited |
Returns the number of sampling points.
|
inlineinherited |
Prints k tuples of the format (x, y, dx/dy, isMonotonic) to stdout.
If the spline does not apply for parts of [x0, x1] it is extrapolated using a straight line. The result can be inspected using the following commands:
--------— snip --------— ./yourProgramm > spline.csv gnuplot
gnuplot> plot "spline.csv" using 1:2 w l ti "Curve", \ "spline.csv" using 1:3 w l ti "Derivative", \ "spline.csv" using 1:4 w p ti "Monotonic" --------— snap --------—
|
inlineprotectedinherited |
|
inlineinherited |
Set the sampling points of a natural spline using a C-style array.
This method uses a single array of sampling points, which are seen as an array-like object which provides access to the X and Y coordinates. In this context 'array-like' means that an access to the members is provided via the [] operator. (e.g. C arrays, std::vector, std::array, etc.) The array containing the sampling points must be of size 'nSamples' at least. Also, the number of sampling points must be larger than 1.
|
inlineinherited |
Set the sampling points and the boundary slopes of a full spline using a C-style array.
This method uses a single array of sampling points, which are seen as an array-like object which provides access to the X and Y coordinates. In this context 'array-like' means that an access to the members is provided via the [] operator. (e.g. C arrays, std::vector, std::array, etc.) The array containing the sampling points must be of size 'nSamples' at least. Also, the number of sampling points must be larger than 1.
|
inlineinherited |
Set the sampling points of a natural spline using a STL-compatible container of array-like objects.
This method uses a single STL-compatible container of sampling points, which are assumed to be array-like objects storing the X and Y coordinates. "STL-compatible" means that the container provides access to iterators using the begin(), end() methods and also provides a size() method. Also, the number of entries in the X and the Y containers must be equal and larger than 1.
|
inlineinherited |
Set the sampling points and the boundary slopes of a full spline using a STL-compatible container of array-like objects.
This method uses a single STL-compatible container of sampling points, which are assumed to be array-like objects storing the X and Y coordinates. "STL-compatible" means that the container provides access to iterators using the begin(), end() methods and also provides a size() method. Also, the number of entries in the X and the Y containers must be equal and larger than 1.
|
inlineinherited |
Set the sampling points of a natural spline using a STL-compatible container of tuple-like objects.
This method uses a single STL-compatible container of sampling points, which are assumed to be tuple-like objects storing the X and Y coordinates. "tuple-like" means that the objects provide access to the x values via std::get<0>(obj) and to the y value via std::get<1>(obj) (e.g. std::tuple or std::pair). "STL-compatible" means that the container provides access to iterators using the begin(), end() methods and also provides a size() method. Also, the number of entries in the X and the Y containers must be equal and larger than 1.
|
inlineinherited |
Set the sampling points and the boundary slopes of a full spline using a STL-compatible container of tuple-like objects.
This method uses a single STL-compatible container of sampling points, which are assumed to be tuple-like objects storing the X and Y coordinates. "tuple-like" means that the objects provide access to the x values via std::get<0>(obj) and to the y value via std::get<1>(obj) (e.g. std::tuple or std::pair). "STL-compatible" means that the container provides access to iterators using the begin(), end() methods and also provides a size() method. Also, the number of entries in the X and the Y containers must be equal and larger than 1.
|
inlineprotectedinherited |
Resizes the internal vectors to store the sample points.
|
inlineinherited |
Set the sampling points natural spline using C-style arrays.
This method uses separate array-like objects for the values of the X and Y coordinates. In this context 'array-like' means that an access to the members is provided via the [] operator. (e.g. C arrays, std::vector, std::array, etc.) Each array must be of size 'nSamples' at least. Also, the number of sampling points must be larger than 1.
|
inlineinherited |
Set the sampling points and the boundary slopes of a full spline using C-style arrays.
This method uses separate array-like objects for the values of the X and Y coordinates. In this context 'array-like' means that an access to the members is provided via the [] operator. (e.g. C arrays, std::vector, std::array, etc.) Each array must be of size 'nSamples' at least. Also, the number of sampling points must be larger than 1.
|
inlineinherited |
Set the sampling points of a natural spline using STL-compatible containers.
This method uses separate STL-compatible containers for the values of the sampling points' X and Y coordinates. "STL-compatible" means that the container provides access to iterators using the begin(), end() methods and also provides a size() method. Also, the number of entries in the X and the Y containers must be equal and larger than 1.
|
inlineinherited |
Set the sampling points and the boundary slopes of a full spline using STL-compatible containers.
This method uses separate STL-compatible containers for the values of the sampling points' X and Y coordinates. "STL-compatible" means that the container provides access to iterators using the begin(), end() methods and also provides a size() method. Also, the number of entries in the X and the Y containers must be equal and larger than 1.
|
inlineprotectedinherited |
Returns the x coordinate of the i-th sampling point.
|
inlineinherited |
Return the x value of the rightmost sampling point.
|
inlineinherited |
Return the x value of the leftmost sampling point.
|
inlineprotectedinherited |
Returns the y coordinate of the i-th sampling point.
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |