Opm::MonotCubicInterpolator Class Reference

Represents one dimensional function f with single valued argument x that can be interpolated using monotone cubic interpolation. More...

#include <MonotCubicInterpolator.hpp>

Public Member Functions

 MonotCubicInterpolator (const std::string &datafilename) throw (const char*)
 
 MonotCubicInterpolator (const char *datafilename) throw (const char*)
 
 MonotCubicInterpolator (const char *datafilename, int xColumn, int fColumn) throw (const char*)
 
 MonotCubicInterpolator (const std::string &datafilename, int xColumn, int fColumn) throw (const char*)
 
 MonotCubicInterpolator (const std::vector< double > &x, const std::vector< double > &f)
 
 MonotCubicInterpolator ()
 
bool read (const std::string &datafilename)
 
bool read (const std::string &datafilename, int xColumn, int fColumn)
 
double operator() (double x) const
 
double evaluate (double x) const throw (const char*)
 
double evaluate (double x, double &errorestimate_output) const
 
std::pair< double, double > getMinimumX () const
 
std::pair< double, double > getMaximumX () const
 
std::pair< double, double > getMaximumF () const throw (const char*)
 
std::pair< double, double > getMinimumF () const throw (const char*)
 
std::vector< double > get_xVector () const
 
std::vector< double > get_fVector () const
 
void scaleData (double factor)
 
bool isStrictlyMonotone ()
 
bool isMonotone () const
 
bool isStrictlyIncreasing ()
 
bool isMonotoneIncreasing () const
 
bool isStrictlyDecreasing ()
 
bool isMonotoneDecreasing () const
 
void addPair (double newx, double newf) throw (const char*)
 
std::pair< double, double > getMissingX () const throw (const char*)
 
std::string toString () const
 
int getSize () const
 
void chopFlatEndpoints (const double)
 
void chopFlatEndpoints ()
 
void shrinkFlatAreas (const double)
 
void shrinkFlatAreas ()
 

Detailed Description

Represents one dimensional function f with single valued argument x that can be interpolated using monotone cubic interpolation.

Class to represent a one-dimensional function f with single-valued argument x. The function is represented by a table of function values. Interpolation between table values is cubic and monotonicity preserving if input values are monotonous.

Outside x_min and x_max, the class will extrapolate using the constant f(x_min) or f(x_max).

Extra functionality:

  • Can return (x_1+x_2)/2 where x_1 and x_2 are such that abs(f(x_1) - f(x_2)) is maximized. This is used to determine where one should calculate a new value for increased accuracy in the current function

Monotonicity preserving cubic interpolation algorithm is taken from Fritsch and Carlson, "Monotone piecewise cubic interpolation", SIAM J. Numer. Anal. 17, 238–246, no. 2,

$Id$

Algorithm also described here: http://en.wikipedia.org/wiki/Monotone_cubic_interpolation

Author
HÃ¥vard Berland <havb (at) statoil.com>, December 2006

Constructor & Destructor Documentation

Opm::MonotCubicInterpolator::MonotCubicInterpolator ( const std::string &  datafilename)
throw (const char *
)
inline
Parameters
datafilenameA datafile with the x values and the corresponding f(x) values

Accepts a filename as input and parses this file for two-column floating point data, interpreting the data as representing function values x and f(x).

Ignores all lines not conforming to <whitespace><float><whitespace><float><whatever><newline>

References read().

Opm::MonotCubicInterpolator::MonotCubicInterpolator ( const char *  datafilename)
throw (const char *
)
inline
Parameters
datafilenameA datafile with the x values and the corresponding f(x) values

Accepts a filename as input and parses this file for two-column floating point data, interpreting the data as representing function values x and f(x).

Ignores all lines not conforming to <whitespace><float><whitespace><float><whatever><newline>

All commas in the file will be treated as spaces when parsing.

References read().

Opm::MonotCubicInterpolator::MonotCubicInterpolator ( const char *  datafilename,
int  xColumn,
int  fColumn 
)
throw (const char *
)
inline
Parameters
datafilenamedata file
XColumnx values
fColumnf values

Accepts a filename as input, and parses the chosen columns in that file.

References read().

Opm::MonotCubicInterpolator::MonotCubicInterpolator ( const std::string &  datafilename,
int  xColumn,
int  fColumn 
)
throw (const char *
)
inline
Parameters
datafilenamedata file
XColumnx values
fColumnf values

Accepts a filename as input, and parses the chosen columns in that file.

References read().

Opm::MonotCubicInterpolator::MonotCubicInterpolator ( const std::vector< double > &  x,
const std::vector< double > &  f 
)
Parameters
xvector of x values
fvector of corresponding f values

Accepts two equal-length vectors as input for constructing the interpolation object. First vector is the x-values, the second vector is the function values

Opm::MonotCubicInterpolator::MonotCubicInterpolator ( )
inline

No input, an empty function object is created.

This object must be treated with care until populated.

Member Function Documentation

void Opm::MonotCubicInterpolator::addPair ( double  newx,
double  newf 
)
throw (const char *
)
Parameters
newxNew x point
newfNew f(x) point

Adds a new datapoint to the function.

This causes all the derivatives at all points of the functions to be recomputed and then adjusted for monotone cubic interpolation. If this function ever enters a critical part of any code, the locality of the algorithm for monotone adjustment must be exploited.

void Opm::MonotCubicInterpolator::chopFlatEndpoints ( const double  )

Checks if the function curve is flat at the endpoints, chop off endpoint data points if that is the case.

The notion of "flat" is determined by the input parameter "epsilon" Values whose difference are less than epsilon are regarded as equal.

This is implemented to be able to obtain a strictly monotone curve from a data set that is strictly monotone except at the endpoints.

Example: The data points (1,3), (2,3), (3,4), (4,5), (5,5), (6,5) will become (2,3), (3,4), (4,5)

Assumes at least 3 datapoints. If less than three, this function is a noop.

void Opm::MonotCubicInterpolator::chopFlatEndpoints ( )
inline

Wrapper function for chopFlatEndpoints(const double) providing a default epsilon parameter

double Opm::MonotCubicInterpolator::evaluate ( double  x) const
throw (const char *
)
Parameters
xx value

Returns f(x) for given x (input). Interpolates (monotone cubic or linearly) if necessary.

Extrapolates using the constants f(x_min) or f(x_max) if input x is outside (x_min, x_max)

Returns
f(x) for a given x

Referenced by operator()().

double Opm::MonotCubicInterpolator::evaluate ( double  x,
double &  errorestimate_output 
) const
Parameters
xx value
errorestimate_outputReturns f(x) and an error estimate for given x (input).

Interpolates (linearly) if necessary.

Throws an exception if extrapolation would be necessary for evaluation. We do not want to do extrapolation (yet).

The error estimate for x1 < x < x2 is (x2 - x1)^2/8 * f''(x) where f''(x) is evaluated using the stencil (1 -2 1) using either (x0, x1, x2) or (x1, x2, x3);

Throws an exception if the table contains only two x-values.

NOT IMPLEMENTED YET!

std::vector<double> Opm::MonotCubicInterpolator::get_fVector ( ) const

Provide a copy of tghe function data as a vector

Unspecified order, but corresponds to get_xVector

Returns
f values as a vector
std::vector<double> Opm::MonotCubicInterpolator::get_xVector ( ) const

Provide a copy of the x-data as a vector

Unspecified order, but corresponds to get_fVector.

Returns
x values as a vector
std::pair<double,double> Opm::MonotCubicInterpolator::getMaximumF ( ) const
throw (const char *
)

Maximum f-value, returns both x and f in a pair.

Returns
x value corresponding to maximum f value
maximum f value
std::pair<double,double> Opm::MonotCubicInterpolator::getMaximumX ( ) const
inline

Maximum x-value, returns both x and f in a pair.

Returns
maximum x value
f(maximum x value)
std::pair<double,double> Opm::MonotCubicInterpolator::getMinimumF ( ) const
throw (const char *
)

Minimum f-value, returns both x and f in a pair

Returns
x value corresponding to minimal f value
minimum f value
std::pair<double,double> Opm::MonotCubicInterpolator::getMinimumX ( ) const
inline

Minimum x-value, returns both x and f in a pair.

Returns
minimum x value
f(minimum x value)
std::pair<double,double> Opm::MonotCubicInterpolator::getMissingX ( ) const
throw (const char *
)

Returns an x-value that is believed to yield the best improvement in global accuracy for the interpolation if computed.

Searches for the largest jump in f-values, and returns a x value being the average of the two x-values representing the f-value-jump.

Returns
New x value beleived to yield the best improvement in global accuracy
Maximal difference
int Opm::MonotCubicInterpolator::getSize ( ) const
inline
Returns
Number of datapoint pairs in this object
bool Opm::MonotCubicInterpolator::isMonotone ( ) const
inline

Determines if the current function-value-data is monotone.

Returns
True if f(x) is monotone, else False
bool Opm::MonotCubicInterpolator::isMonotoneDecreasing ( ) const
inline

Determines if the current function-value-data is monotone and decreasing

Returns
True if f(x) is monotone and decreasing, else False
bool Opm::MonotCubicInterpolator::isMonotoneIncreasing ( ) const
inline

Determines if the current function-value-data is monotone and increasing.

Returns
True if f(x) is monotone and increasing, else False
bool Opm::MonotCubicInterpolator::isStrictlyDecreasing ( )
inline

Determines if the current function-value-data is strictly decreasing. This is a utility function for outsiders if they want to invert the data for example.

Returns
True if f(x) is strictly decreasing, else False
bool Opm::MonotCubicInterpolator::isStrictlyIncreasing ( )
inline

Determines if the current function-value-data is strictly increasing. This is a utility function for outsiders if they want to invert the data for example.

Returns
True if f(x) is strictly increasing, else False
bool Opm::MonotCubicInterpolator::isStrictlyMonotone ( )
inline

Determines if the current function-value-data is strictly monotone. This is a utility function for outsiders if they want to invert the data for example.

Returns
True if f(x) is strictly monotone, else False
double Opm::MonotCubicInterpolator::operator() ( double  x) const
inline
Parameters
xx value

Returns f(x) for given x (input). Interpolates (monotone cubic or linearly) if necessary.

Extrapolates using the constants f(x_min) or f(x_max) if input x is outside (x_min, x_max)

Returns
f(x) for a given x

References evaluate().

bool Opm::MonotCubicInterpolator::read ( const std::string &  datafilename)
inline
Parameters
datafilenameA datafile with the x values and the corresponding f(x) values

Accepts a filename as input and parses this file for two-column floating point data, interpreting the data as representing function values x and f(x).

returns true on success

All commas in file will be treated as spaces when parsing

Ignores all lines not conforming to <whitespace><float><whitespace><float><whatever><newline>

Referenced by MonotCubicInterpolator().

bool Opm::MonotCubicInterpolator::read ( const std::string &  datafilename,
int  xColumn,
int  fColumn 
)
Parameters
datafilenamedata file
XColumnx values
fColumnf values

Accepts a filename as input, and parses the chosen columns in that file.

void Opm::MonotCubicInterpolator::scaleData ( double  factor)
Parameters
factorScaling constant

Scale all the function value data by a constant

void Opm::MonotCubicInterpolator::shrinkFlatAreas ( const double  )

If function is monotone, but not strictly monotone, this function will remove datapoints from intervals with zero derivative so that the curve become strictly monotone.

Example The data points (1,2), (2,3), (3,4), (4,4), (5,5), (6,6) will become (1,2), (2,3), (3,4), (5,5), (6,6)

Assumes at least two datapoints, if one or zero datapoint, this is a noop.

void Opm::MonotCubicInterpolator::shrinkFlatAreas ( )
inline

Wrapper function for shrinkFlatAreas(const double) providing a default epsilon parameter

std::string Opm::MonotCubicInterpolator::toString ( ) const

Constructs a string containing the data in a table

Returns
a string containing the data in a table

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