Loading...
Searching...
No Matches
Opm::MonotCubicInterpolator Class Reference

Class to represent a one-dimensional function f with single-valued argument x. More...

`#include <MonotCubicInterpolator.hpp>`

## Public Member Functions

| MonotCubicInterpolator (const std::string &datafilename)
| MonotCubicInterpolator (const char *datafilename)
| MonotCubicInterpolator (const char *datafilename, int xColumn, int fColumn)
| MonotCubicInterpolator (const std::string &datafilename, int xColumn, int fColumn)
| MonotCubicInterpolator (const std::vector< double > &x, const std::vector< double > &f)
| MonotCubicInterpolator ()
| No input, an empty function object is created.
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
double | evaluate (double x, double &errorestimate_output) const
std::pair< double, double > | getMinimumX () const
| Minimum x-value, returns both x and f in a pair.
std::pair< double, double > | getMaximumX () const
| Maximum x-value, returns both x and f in a pair.
std::pair< double, double > | getMaximumF () const
| Maximum f-value, returns both x and f in a pair.
std::pair< double, double > | getMinimumF () const
| Minimum f-value, returns both x and f in a pair.
std::vector< double > | get_xVector () const
| Provide a copy of the x-data as a vector.
std::vector< double > | get_fVector () const
| Provide a copy of tghe function data as a vector.
void | scaleData (double factor)
bool | isStrictlyMonotone ()
| Determines if the current function-value-data is strictly monotone.
bool | isMonotone () const
| Determines if the current function-value-data is monotone.
bool | isStrictlyIncreasing ()
| Determines if the current function-value-data is strictly increasing.
bool | isMonotoneIncreasing () const
| Determines if the current function-value-data is monotone and increasing.
bool | isStrictlyDecreasing ()
| Determines if the current function-value-data is strictly decreasing.
bool | isMonotoneDecreasing () const
| Determines if the current function-value-data is monotone and decreasing.
void | addPair (double newx, double newf)
std::pair< double, double > | getMissingX () const
| Returns an x-value that is believed to yield the best improvement in global accuracy for the interpolation if computed.
std::string | toString () const
| Constructs a string containing the data in a table.
int | getSize () const
void | chopFlatEndpoints (const double)
| Checks if the function curve is flat at the endpoints, chop off endpoint data points if that is the case.
void | chopFlatEndpoints ()
| Wrapper function for chopFlatEndpoints(const double) providing a default epsilon parameter.
void | 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.
void | shrinkFlatAreas ()
| Wrapper function for shrinkFlatAreas(const double) providing a default epsilon parameter.

## Detailed Description

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

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

## Constructor & Destructor Documentation

## MonotCubicInterpolator() [1/6]

Opm::MonotCubicInterpolator::MonotCubicInterpolator | ( | const std::string & | datafilename | ) |

inline explicit

Parameters

  datafilename | A 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>

## MonotCubicInterpolator() [2/6]

Opm::MonotCubicInterpolator::MonotCubicInterpolator | ( | const char * | datafilename | ) |

inline explicit

Parameters

  datafilename | A 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.

## MonotCubicInterpolator() [3/6]

Opm::MonotCubicInterpolator::MonotCubicInterpolator | ( | const char * | datafilename,
|  | int | xColumn,
|  | int | fColumn
| ) |  |

inline

Parameters

  datafilename | data file
  XColumn | x values
  fColumn | f values

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

## MonotCubicInterpolator() [4/6]

Opm::MonotCubicInterpolator::MonotCubicInterpolator | ( | const std::string & | datafilename,
|  | int | xColumn,
|  | int | fColumn
| ) |  |

inline

Parameters

  datafilename | data file
  XColumn | x values
  fColumn | f values

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

## MonotCubicInterpolator() [5/6]

Opm::MonotCubicInterpolator::MonotCubicInterpolator | ( | const std::vector< double > & | x,
|  | const std::vector< double > & | f
| ) |  |

Parameters

  x | vector of x values
  f | vector 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

## MonotCubicInterpolator() [6/6]

Opm::MonotCubicInterpolator::MonotCubicInterpolator | ( |  | ) |

inline

No input, an empty function object is created.

This object must be treated with care until populated.

## Member Function Documentation

## addPair()

void Opm::MonotCubicInterpolator::addPair | ( | double | newx,
|  | double | newf
| ) |  |

Parameters

  newx | New x point
  newf | New 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.

## chopFlatEndpoints()

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

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.

## evaluate() [1/2]

double Opm::MonotCubicInterpolator::evaluate | ( | double | x | ) | const

Parameters

  x | x 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

## evaluate() [2/2]

double Opm::MonotCubicInterpolator::evaluate | ( | double | x,
|  | double & | errorestimate_output
| ) |  | const

Parameters

  x | x value
  errorestimate_output |

Returns 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!

## get_fVector()

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

## get_xVector()

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

## getMaximumF()

pair< double, double > Opm::MonotCubicInterpolator::getMaximumF | ( |  | ) | const

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

Returns
  x value corresponding to maximum f value
  maximum f value

## getMaximumX()

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)

## getMinimumF()

pair< double, double > Opm::MonotCubicInterpolator::getMinimumF | ( |  | ) | const

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

Returns
  x value corresponding to minimal f value
  minimum f value

## getMinimumX()

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)

## getMissingX()

pair< double, double > Opm::MonotCubicInterpolator::getMissingX | ( |  | ) | const

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

## getSize()

int Opm::MonotCubicInterpolator::getSize | ( |  | ) | const

inline

Returns
  Number of datapoint pairs in this object

## isMonotone()

bool Opm::MonotCubicInterpolator::isMonotone | ( |  | ) | const

inline

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

Returns
  True if f(x) is monotone, else False

## isMonotoneDecreasing()

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

## isMonotoneIncreasing()

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

## isStrictlyDecreasing()

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

## isStrictlyIncreasing()

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

## isStrictlyMonotone()

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

## operator()()

double Opm::MonotCubicInterpolator::operator() | ( | double | x | ) | const

inline

Parameters

  x | x 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

## read() [1/2]

bool Opm::MonotCubicInterpolator::read | ( | const std::string & | datafilename | ) |

inline

Parameters

  datafilename | A 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>

## read() [2/2]

bool Opm::MonotCubicInterpolator::read | ( | const std::string & | datafilename,
|  | int | xColumn,
|  | int | fColumn
| ) |  |

Parameters

  datafilename | data file
  XColumn | x values
  fColumn | f values

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

## scaleData()

void Opm::MonotCubicInterpolator::scaleData | ( | double | factor | ) |

Parameters

  factor | Scaling constant

Scale all the function value data by a constant

## shrinkFlatAreas()

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

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.

## toString()

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 files:

- opm/common/utility/numeric/MonotCubicInterpolator.hpp
- opm/common/utility/numeric/MonotCubicInterpolator.cpp