VERB4D
|
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 () |
Represents one dimensional function f with single valued argument x that can be interpolated using monotone cubic interpolation.
|
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).
Ignores all lines not conforming to <whitespace><float><whitespace><float><whatever><newline>
|
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).
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 | ||
) | |||
throw | ( | const char * | |
) |
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 loop.
|
inline |
Wrapper function for chopFlatEndpoints(const double) providing a default epsilon parameter
double Opm::MonotCubicInterpolator::evaluate | ( | double | x | ) | const |
throw | ( | const char * | |||
) |
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 | |
throw | ( | const char * | ||
) |
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 | |
throw | ( | const char * | ||
) |
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 | |
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.
|
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.
|
inline |
Wrapper function for shrinkFlatAreas(const double) providing a default epsilon parameter
string Opm::MonotCubicInterpolator::toString | ( | ) | const |
Constructs a string containing the data in a table