Opm::Tabulated1DFunction< Scalar > Class Template Reference

Implements a linearly interpolated scalar function that depends on one variable. More...

#include <Tabulated1DFunction.hpp>

Inheritance diagram for Opm::Tabulated1DFunction< Scalar >:
Inheritance graph

Public Member Functions

 Tabulated1DFunction ()
 Default constructor for a piecewise linear function. More...
 
template<class ScalarArrayX , class ScalarArrayY >
 Tabulated1DFunction (size_t nSamples, const ScalarArrayX &x, const ScalarArrayY &y, bool sortInputs=true)
 Convenience constructor for a piecewise linear function. More...
 
template<class ScalarContainer >
 Tabulated1DFunction (const ScalarContainer &x, const ScalarContainer &y, bool sortInputs=true)
 Convenience constructor for a piecewise linear function. More...
 
template<class PointContainer >
 Tabulated1DFunction (const PointContainer &points, bool sortInputs=true)
 Convenience constructor for a piecewise linear function. More...
 
template<class ScalarArrayX , class ScalarArrayY >
void setXYArrays (size_t nSamples, const ScalarArrayX &x, const ScalarArrayY &y, bool sortInputs=true)
 Set the sampling points for the piecewise linear function. More...
 
template<class ScalarContainerX , class ScalarContainerY >
void setXYContainers (const ScalarContainerX &x, const ScalarContainerY &y, bool sortInputs=true)
 Set the sampling points for the piecewise linear function. More...
 
template<class PointArray >
void setArrayOfPoints (size_t nSamples, const PointArray &points, bool sortInputs=true)
 Set the sampling points for the piecewise linear function. More...
 
template<class XYContainer >
void setContainerOfTuples (const XYContainer &points, bool sortInputs=true)
 Set the sampling points of the piecewise linear function using a STL-compatible container of tuple-like objects. More...
 
size_t numSamples () const
 Returns the number of sampling points. 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...
 
Scalar xAt (size_t i) const
 Return the x value of the a sample point with a given index. More...
 
const std::vector< Scalar > & xValues () const
 
const std::vector< Scalar > & yValues () const
 
Scalar valueAt (size_t i) const
 Return the value of the a sample point with a given index. More...
 
template<class Evaluation >
bool applies (const Evaluation &x) const
 Return true iff the given x is in range [x1, xn]. More...
 
template<class Evaluation >
Evaluation eval (const Evaluation &x, bool extrapolate=false) const
 Evaluate the spline at a given position. More...
 
template<class Evaluation >
Evaluation evalDerivative (const Evaluation &x, bool extrapolate=false) const
 Evaluate the spline's derivative at a given position. More...
 
template<class Evaluation >
Evaluation evalSecondDerivative (const Evaluation &, bool=false) const
 Evaluate the function's second derivative at a given position. More...
 
template<class Evaluation >
Evaluation evalThirdDerivative (const Evaluation &, bool=false) const
 Evaluate the function's third derivative at a given position. More...
 
int monotonic (Scalar x0, Scalar x1, bool extrapolate=false) const
 Returns 1 if the function is monotonically increasing, -1 if the function is mononously decreasing and 0 if the function is not monotonous in the interval (x0, x1). More...
 
int monotonic () const
 Same as monotonic(x0, x1), but with the entire range of the function as interval. More...
 
void printCSV (Scalar xi0, Scalar xi1, unsigned k, std::ostream &os=std::cout) const
 Prints k tuples of the format (x, y, dx/dy, isMonotonic) to stdout. More...
 
bool operator== (const Tabulated1DFunction< Scalar > &data) const
 

Detailed Description

template<class Scalar>
class Opm::Tabulated1DFunction< Scalar >

Implements a linearly interpolated scalar function that depends on one variable.

Constructor & Destructor Documentation

◆ Tabulated1DFunction() [1/4]

template<class Scalar >
Opm::Tabulated1DFunction< Scalar >::Tabulated1DFunction ( )
inline

Default constructor for a piecewise linear function.

To specfiy the acutal curve, use one of the set() methods.

◆ Tabulated1DFunction() [2/4]

template<class Scalar >
template<class ScalarArrayX , class ScalarArrayY >
Opm::Tabulated1DFunction< Scalar >::Tabulated1DFunction ( size_t  nSamples,
const ScalarArrayX &  x,
const ScalarArrayY &  y,
bool  sortInputs = true 
)
inline

Convenience constructor for a piecewise linear function.

Parameters
nSamplesThe number of sampling points (must be >= 2)
xAn array containing the $x$ values of the spline's sampling points
yAn array containing the $y$ values of the spline's sampling points

References Opm::Tabulated1DFunction< Scalar >::setXYArrays().

◆ Tabulated1DFunction() [3/4]

template<class Scalar >
template<class ScalarContainer >
Opm::Tabulated1DFunction< Scalar >::Tabulated1DFunction ( const ScalarContainer &  x,
const ScalarContainer &  y,
bool  sortInputs = true 
)
inline

Convenience constructor for a piecewise linear function.

Parameters
xAn array containing the $x$ values of the spline's sampling points (must have a size() method)
yAn array containing the $y$ values of the spline's sampling points (must have a size() method)

References Opm::Tabulated1DFunction< Scalar >::setXYContainers().

◆ Tabulated1DFunction() [4/4]

template<class Scalar >
template<class PointContainer >
Opm::Tabulated1DFunction< Scalar >::Tabulated1DFunction ( const PointContainer &  points,
bool  sortInputs = true 
)
inline

Convenience constructor for a piecewise linear function.

Parameters
pointsA container of $(x,y)$ tuples of the spline's sampling points (must have a size() method)

References Opm::Tabulated1DFunction< Scalar >::setContainerOfTuples().

Member Function Documentation

◆ applies()

template<class Scalar >
template<class Evaluation >
bool Opm::Tabulated1DFunction< Scalar >::applies ( const Evaluation &  x) const
inline

Return true iff the given x is in range [x1, xn].

References Opm::Tabulated1DFunction< Scalar >::numSamples().

Referenced by Opm::Tabulated1DFunction< Scalar >::printCSV().

◆ eval()

template<class Scalar >
template<class Evaluation >
Evaluation Opm::Tabulated1DFunction< Scalar >::eval ( const Evaluation &  x,
bool  extrapolate = false 
) const
inline

Evaluate the spline at a given position.

Parameters
xThe value on the abscissa where the function ought to be evaluated
extrapolateIf this parameter is set to true, the function 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.

Referenced by Opm::Tabulated1DFunction< Scalar >::printCSV(), Opm::WetGasPvt< Scalar >::setSaturatedGasFormationVolumeFactor(), Opm::DryHumidGasPvt< Scalar >::setSaturatedGasViscosity(), and Opm::WetGasPvt< Scalar >::setSaturatedGasViscosity().

◆ evalDerivative()

template<class Scalar >
template<class Evaluation >
Evaluation Opm::Tabulated1DFunction< Scalar >::evalDerivative ( const Evaluation &  x,
bool  extrapolate = false 
) const
inline

Evaluate the spline's derivative at a given position.

Parameters
xThe value on the abscissa where the function's derivative ought to be evaluated
extrapolateIf 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.

Referenced by Opm::Tabulated1DFunction< Scalar >::printCSV().

◆ evalSecondDerivative()

template<class Scalar >
template<class Evaluation >
Evaluation Opm::Tabulated1DFunction< Scalar >::evalSecondDerivative ( const Evaluation &  ,
bool  = false 
) const
inline

Evaluate the function's second derivative at a given position.

Since this class represents a piecewise linear function, this method will always return 0.

Parameters
xThe value on the abscissa where the function's derivative ought to be evaluated
extrapolateIf this parameter is set to true, the function 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.

◆ evalThirdDerivative()

template<class Scalar >
template<class Evaluation >
Evaluation Opm::Tabulated1DFunction< Scalar >::evalThirdDerivative ( const Evaluation &  ,
bool  = false 
) const
inline

Evaluate the function's third derivative at a given position.

Since this class represents a piecewise linear function, this method will always return 0.

Parameters
xThe value on the abscissa where the function's derivative ought to be evaluated
extrapolateIf this parameter is set to true, the function 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.

◆ monotonic() [1/2]

template<class Scalar >
int Opm::Tabulated1DFunction< Scalar >::monotonic ( ) const
inline

Same as monotonic(x0, x1), but with the entire range of the function as interval.

References Opm::Tabulated1DFunction< Scalar >::monotonic(), Opm::Tabulated1DFunction< Scalar >::xMax(), and Opm::Tabulated1DFunction< Scalar >::xMin().

Referenced by Opm::Tabulated1DFunction< Scalar >::monotonic().

◆ monotonic() [2/2]

template<class Scalar >
int Opm::Tabulated1DFunction< Scalar >::monotonic ( Scalar  x0,
Scalar  x1,
bool  extrapolate = false 
) const
inline

Returns 1 if the function is monotonically increasing, -1 if the function is mononously decreasing and 0 if the function is not monotonous in the interval (x0, x1).

In the corner case that the function is constant within the given interval, this method returns 3.

References Opm::Tabulated1DFunction< Scalar >::numSamples(), Opm::Tabulated1DFunction< Scalar >::xMax(), and Opm::Tabulated1DFunction< Scalar >::xMin().

◆ numSamples()

◆ operator==()

template<class Scalar >
bool Opm::Tabulated1DFunction< Scalar >::operator== ( const Tabulated1DFunction< Scalar > &  data) const
inline

◆ printCSV()

template<class Scalar >
void Opm::Tabulated1DFunction< Scalar >::printCSV ( Scalar  xi0,
Scalar  xi1,
unsigned  k,
std::ostream &  os = std::cout 
) const
inline

Prints k tuples of the format (x, y, dx/dy, isMonotonic) to stdout.

If the function 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 > function.csv gnuplot

gnuplot> plot "function.csv" using 1:2 w l ti "Curve", \ "function.csv" using 1:3 w l ti "Derivative" --------— snap --------—

References Opm::Tabulated1DFunction< Scalar >::applies(), Opm::Tabulated1DFunction< Scalar >::eval(), Opm::Tabulated1DFunction< Scalar >::evalDerivative(), Opm::max(), Opm::min(), and Opm::Tabulated1DFunction< Scalar >::numSamples().

◆ setArrayOfPoints()

template<class Scalar >
template<class PointArray >
void Opm::Tabulated1DFunction< Scalar >::setArrayOfPoints ( size_t  nSamples,
const PointArray &  points,
bool  sortInputs = true 
)
inline

Set the sampling points for the piecewise linear function.

References Opm::Tabulated1DFunction< Scalar >::numSamples().

◆ setContainerOfTuples()

template<class Scalar >
template<class XYContainer >
void Opm::Tabulated1DFunction< Scalar >::setContainerOfTuples ( const XYContainer &  points,
bool  sortInputs = true 
)
inline

Set the sampling points of the piecewise linear function 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.

References Opm::Tabulated1DFunction< Scalar >::numSamples().

Referenced by Opm::WetGasPvt< Scalar >::setSaturatedGasFormationVolumeFactor(), Opm::DryHumidGasPvt< Scalar >::setSaturatedGasViscosity(), Opm::WetGasPvt< Scalar >::setSaturatedGasViscosity(), and Opm::Tabulated1DFunction< Scalar >::Tabulated1DFunction().

◆ setXYArrays()

template<class Scalar >
template<class ScalarArrayX , class ScalarArrayY >
void Opm::Tabulated1DFunction< Scalar >::setXYArrays ( size_t  nSamples,
const ScalarArrayX &  x,
const ScalarArrayY &  y,
bool  sortInputs = true 
)
inline

Set the sampling points for the piecewise linear function.

This method takes C-style arrays (pointers) as arguments.

References Opm::Tabulated1DFunction< Scalar >::numSamples().

Referenced by Opm::Tabulated1DFunction< Scalar >::Tabulated1DFunction().

◆ setXYContainers()

template<class Scalar >
template<class ScalarContainerX , class ScalarContainerY >
void Opm::Tabulated1DFunction< Scalar >::setXYContainers ( const ScalarContainerX &  x,
const ScalarContainerY &  y,
bool  sortInputs = true 
)
inline

Set the sampling points for the piecewise linear function.

This method takes STL compatible containers as arguments.

References Opm::Tabulated1DFunction< Scalar >::numSamples().

Referenced by Opm::EclSpecrockLawParams< ScalarT >::setHeatCapacities(), and Opm::Tabulated1DFunction< Scalar >::Tabulated1DFunction().

◆ valueAt()

template<class Scalar >
Scalar Opm::Tabulated1DFunction< Scalar >::valueAt ( size_t  i) const
inline

Return the value of the a sample point with a given index.

◆ xAt()

template<class Scalar >
Scalar Opm::Tabulated1DFunction< Scalar >::xAt ( size_t  i) const
inline

Return the x value of the a sample point with a given index.

◆ xMax()

template<class Scalar >
Scalar Opm::Tabulated1DFunction< Scalar >::xMax ( ) const
inline

Return the x value of the rightmost sampling point.

References Opm::Tabulated1DFunction< Scalar >::numSamples().

Referenced by Opm::Tabulated1DFunction< Scalar >::monotonic().

◆ xMin()

template<class Scalar >
Scalar Opm::Tabulated1DFunction< Scalar >::xMin ( ) const
inline

Return the x value of the leftmost sampling point.

Referenced by Opm::Tabulated1DFunction< Scalar >::monotonic().

◆ xValues()

template<class Scalar >
const std::vector< Scalar > & Opm::Tabulated1DFunction< Scalar >::xValues ( ) const
inline

◆ yValues()

template<class Scalar >
const std::vector< Scalar > & Opm::Tabulated1DFunction< Scalar >::yValues ( ) const
inline

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