My Project
|
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. | |
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:
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
Represents one dimensional function f with single valued argument x that can be interpolated using monotone cubic interpolation
|
inlineexplicit |
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>
|
inlineexplicit |
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.
|
inline |
datafilename | data file |
XColumn | x values |
fColumn | f values |
Accepts a filename as input, and parses the chosen columns in that file.
|
inline |
datafilename | data file |
XColumn | x values |
fColumn | f values |
Accepts a filename as input, and parses the chosen columns in that file.
Opm::MonotCubicInterpolator::MonotCubicInterpolator | ( | const std::vector< double > & | x, |
const std::vector< double > & | f | ||
) |
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
|
inline |
No input, an empty function object is created.
This object must be treated with care until populated.
void Opm::MonotCubicInterpolator::addPair | ( | double | newx, |
double | newf | ||
) |
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.
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.
double Opm::MonotCubicInterpolator::evaluate | ( | double | x | ) | const |
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)
double Opm::MonotCubicInterpolator::evaluate | ( | double | x, |
double & | errorestimate_output | ||
) | const |
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!
vector< double > Opm::MonotCubicInterpolator::get_fVector | ( | ) | const |
Provide a copy of tghe function data as a vector.
Unspecified order, but corresponds to 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.
pair< double, double > Opm::MonotCubicInterpolator::getMaximumF | ( | ) | const |
Maximum f-value, returns both x and f in a pair.
|
inline |
Maximum x-value, returns both x and f in a pair.
pair< double, double > Opm::MonotCubicInterpolator::getMinimumF | ( | ) | const |
Minimum f-value, returns both x and f in a pair.
|
inline |
Minimum x-value, returns both x and f in a pair.
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.
|
inline |
|
inline |
Determines if the current function-value-data is monotone.
|
inline |
Determines if the current function-value-data is monotone and decreasing.
|
inline |
Determines if the current function-value-data is monotone and increasing.
|
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.
|
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.
|
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.
|
inline |
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)
|
inline |
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>
bool Opm::MonotCubicInterpolator::read | ( | const std::string & | datafilename, |
int | xColumn, | ||
int | fColumn | ||
) |
datafilename | data file |
XColumn | x values |
fColumn | f values |
Accepts a filename as input, and parses the chosen columns in that file.
void Opm::MonotCubicInterpolator::scaleData | ( | double | factor | ) |
factor | Scaling constant |
Scale all the function value data by a constant
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.
string Opm::MonotCubicInterpolator::toString | ( | ) | const |
Constructs a string containing the data in a table.