CoolProp  6.6.0
An open-source fluid property and humid air property database
Public Member Functions | Protected Member Functions | List of all members
CoolProp::Polynomial2DFrac Class Reference

Detailed Description

A class for polynomials starting at an arbitrary degree.

It is implemented for the incompressibles and is a little messy, but seems to work fine for now. Besides handling arbitrary starting exponents for the polynomials, it can also calculate polynomials with a base value. This means that the independent variable no longer is x, but (x-x_base). For fitted functions, we often see such a design to enhance the fit quality/stability.

Definition at line 215 of file PolyMath.h.

#include <PolyMath.h>

Inheritance diagram for CoolProp::Polynomial2DFrac:
CoolProp::Polynomial2D

Public Member Functions

 Polynomial2DFrac ()
 Constructors. More...
 
virtual ~Polynomial2DFrac ()
 Destructor. No implementation. More...
 
Eigen::MatrixXd deriveCoeffs (const Eigen::MatrixXd &coefficients, const int &axis, const int &times, const int &firstExponent)
 Derivative coefficients calculation. More...
 
double evaluate (const Eigen::MatrixXd &coefficients, const double &x_in, const int &firstExponent=0, const double &x_base=0.0)
 The core functions to evaluate the polynomial. More...
 
double evaluate (const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0)
 
double derivative (const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0)
 
double integral (const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0, const double &ax_val=0.0)
 
Eigen::VectorXd solve (const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0)
 
double solve_limits (const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &min, const double &max, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0)
 
double solve_guess (const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &guess, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0)
 
double solve_limitsInt (const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &min, const double &max, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0, const int &int_axis=0)
 
double solve_guessInt (const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &guess, const int &axis, const int &x_exp, const int &y_exp, const double &x_base=0.0, const double &y_base=0.0, const int &int_axis=0)
 
- Public Member Functions inherited from CoolProp::Polynomial2D
 Polynomial2D ()
 Constructors. More...
 
virtual ~Polynomial2D ()
 Destructor. No implementation. More...
 
Eigen::MatrixXd convertCoefficients (const std::vector< double > &coefficients)
 
Eigen::MatrixXd convertCoefficients (const std::vector< std::vector< double >> &coefficients)
 
bool checkCoefficients (const Eigen::MatrixXd &coefficients, const unsigned int rows, const unsigned int columns)
 Basic checks for coefficient vectors. More...
 
Eigen::MatrixXd integrateCoeffs (const Eigen::MatrixXd &coefficients, const int &axis, const int &times)
 Integration functions. More...
 
Eigen::MatrixXd deriveCoeffs (const Eigen::MatrixXd &coefficients, const int &axis=-1, const int &times=1)
 Derivative coefficients calculation. More...
 
double evaluate (const Eigen::MatrixXd &coefficients, const double &x_in)
 The core functions to evaluate the polynomial. More...
 
double evaluate (const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in)
 
double derivative (const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &axis)
 
double integral (const Eigen::MatrixXd &coefficients, const double &x_in, const double &y_in, const int &axis)
 
Eigen::VectorXd solve (const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const int &axis)
 
double solve_limits (const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &min, const double &max, const int &axis)
 
double solve_guess (const Eigen::MatrixXd &coefficients, const double &in, const double &z_in, const double &guess, const int &axis)
 

Protected Member Functions

double factorial (const int &nValue)
 
double binom (const int &nValue, const int &nValue2)
 
Eigen::MatrixXd fracIntCentralDvector (const int &m, const double &x_in, const double &x_base)
 
double fracIntCentral (const Eigen::MatrixXd &coefficients, const double &x_in, const double &x_base)
 
- Protected Member Functions inherited from CoolProp::Polynomial2D
double solve_limits (Poly2DResidual *res, const double &min, const double &max)
 
double solve_guess (Poly2DResidual *res, const double &guess)
 
double simplePolynomial (const std::vector< double > &coefficients, double x)
 Simple polynomial function generator. <- Deprecated due to poor performance, use Horner-scheme instead. More...
 
 DEPRECATED (double simplePolynomial(const std::vector< std::vector< double >> &coefficients, double x, double y))
 
double baseHorner (const std::vector< double > &coefficients, double x)
 Horner function generator implementations. More...
 
 DEPRECATED (double baseHorner(const std::vector< std::vector< double >> &coefficients, double x, double y))
 
bool do_debug (void)
 

Constructor & Destructor Documentation

◆ Polynomial2DFrac()

CoolProp::Polynomial2DFrac::Polynomial2DFrac ( )
inline

Constructors.

Definition at line 220 of file PolyMath.h.

◆ ~Polynomial2DFrac()

virtual CoolProp::Polynomial2DFrac::~Polynomial2DFrac ( )
inlinevirtual

Destructor. No implementation.

Definition at line 223 of file PolyMath.h.

Member Function Documentation

◆ binom()

double CoolProp::Polynomial2DFrac::binom ( const int &  nValue,
const int &  nValue2 
)
protected
Parameters
nValueinteger value that represents the upper part of the factorial
nValue2integer value that represents the lower part of the factorial

Definition at line 861 of file PolyMath.cpp.

◆ derivative()

double CoolProp::Polynomial2DFrac::derivative ( const Eigen::MatrixXd &  coefficients,
const double &  x_in,
const double &  y_in,
const int &  axis,
const int &  x_exp,
const int &  y_exp,
const double &  x_base = 0.0,
const double &  y_base = 0.0 
)
Parameters
coefficientsvector containing the ordered coefficients
x_indouble value that represents the current input in the 1st dimension
y_indouble value that represents the current input in the 2nd dimension
axisunsigned integer value that represents the axis to derive for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension
coefficientsvector containing the ordered coefficients
x_indouble value that represents the current input in the 1st dimension
y_indouble value that represents the current input in the 2nd dimension
axisinteger value that represents the axis to derive for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension

Definition at line 581 of file PolyMath.cpp.

◆ deriveCoeffs()

Eigen::MatrixXd CoolProp::Polynomial2DFrac::deriveCoeffs ( const Eigen::MatrixXd &  coefficients,
const int &  axis,
const int &  times,
const int &  firstExponent 
)

Derivative coefficients calculation.

Deriving coefficients for polynomials is done by multiplying the original coefficients with i and lowering the order by 1.

Remember that the first exponent might need to be adjusted after derivation. It has to be lowered by times: derCoeffs = deriveCoeffs(coefficients, axis, times, firstExponent); firstExponent -= times;

Parameters
coefficientsmatrix containing the ordered coefficients
axisunsigned integer value that represents the desired direction of derivation
timesinteger value that represents the desired order of derivation
firstExponentinteger value that represents the lowest exponent of the polynomial in axis direction

Definition at line 397 of file PolyMath.cpp.

◆ evaluate() [1/2]

double CoolProp::Polynomial2DFrac::evaluate ( const Eigen::MatrixXd &  coefficients,
const double &  x_in,
const double &  y_in,
const int &  x_exp,
const int &  y_exp,
const double &  x_base = 0.0,
const double &  y_base = 0.0 
)
Parameters
coefficientsmatrix containing the ordered coefficients
x_indouble value that represents the current input in the 1st dimension
y_indouble value that represents the current input in the 2nd dimension
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centered fit in the 1st dimension
y_basedouble value that represents the base value for a centered fit in the 2nd dimension
coefficientsvector containing the ordered coefficients
x_indouble value that represents the current input in the 1st dimension
y_indouble value that represents the current input in the 2nd dimension
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension

Definition at line 514 of file PolyMath.cpp.

◆ evaluate() [2/2]

double CoolProp::Polynomial2DFrac::evaluate ( const Eigen::MatrixXd &  coefficients,
const double &  x_in,
const int &  firstExponent = 0,
const double &  x_base = 0.0 
)

The core functions to evaluate the polynomial.

It is here we implement the different special functions that allow us to specify certain types of polynomials.

Try to avoid many calls to the derivative and integral functions. Both of them have to calculate the new coefficients internally, which slows things down. Instead, you should use the deriveCoeffs and integrateCoeffs functions and store the coefficient matrix you need for future calls to evaluate derivative and integral.

Parameters
coefficientsvector containing the ordered coefficients
x_indouble value that represents the current input in the 1st dimension
firstExponentinteger value that represents the lowest exponent of the polynomial
x_basedouble value that represents the base value for a centered fit in the 1st dimension

It is here we implement the different special functions that allow us to specify certain types of polynomials.

Try to avoid many calls to the derivative and integral functions. Both of them have to calculate the new coefficients internally, which slows things down. Instead, you should use the deriveCoeffs and integrateCoeffs functions and store the coefficient matrix you need for future calls to evaluate derivative and integral.

Parameters
coefficientsvector containing the ordered coefficients
x_indouble value that represents the current input in the 1st dimension
firstExponentinteger value that represents the lowest exponent of the polynomial
x_basedouble value that represents the base value for a centred fit in the 1st dimension

Definition at line 460 of file PolyMath.cpp.

◆ factorial()

double CoolProp::Polynomial2DFrac::factorial ( const int &  nValue)
protected
Parameters
nValueinteger value that represents the order of the factorial

Simple integrated centred(!) polynomial function generator divided by independent variable. We need to rewrite some of the functions in order to use central fit. Having a central temperature xbase allows for a better fit, but requires a different formulation of the fracInt function group. Other functions are not affected. Starts with only the first coefficient at x^0

Parameters
nValueinteger value that represents the order of the factorial

Definition at line 853 of file PolyMath.cpp.

◆ fracIntCentral()

double CoolProp::Polynomial2DFrac::fracIntCentral ( const Eigen::MatrixXd &  coefficients,
const double &  x_in,
const double &  x_base 
)
protected

Indefinite integral of a centred polynomial divided by its independent variable

Parameters
coefficientsvector containing the ordered coefficients
x_indouble value that represents the current input
x_basedouble value that represents the basis for the fit

Definition at line 888 of file PolyMath.cpp.

◆ fracIntCentralDvector()

Eigen::MatrixXd CoolProp::Polynomial2DFrac::fracIntCentralDvector ( const int &  m,
const double &  x_in,
const double &  x_base 
)
protected

Helper function to calculate the D vector:

Parameters
minteger value that represents order
x_indouble value that represents the current input
x_basedouble value that represents the basis for the fit

Definition at line 869 of file PolyMath.cpp.

◆ integral()

double CoolProp::Polynomial2DFrac::integral ( const Eigen::MatrixXd &  coefficients,
const double &  x_in,
const double &  y_in,
const int &  axis,
const int &  x_exp,
const int &  y_exp,
const double &  x_base = 0.0,
const double &  y_base = 0.0,
const double &  ax_val = 0.0 
)
Parameters
coefficientsvector containing the ordered coefficients
x_indouble value that represents the current input in the 1st dimension
y_indouble value that represents the current input in the 2nd dimension
axisunsigned integer value that represents the axis to integrate for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension
ax_valdouble value that represents the base value for the definite integral on the chosen axis.
coefficientsvector containing the ordered coefficients
x_indouble value that represents the current input in the 1st dimension
y_indouble value that represents the current input in the 2nd dimension
axisinteger value that represents the axis to integrate for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension
ax_valdouble value that represents the base value for the definite integral on the chosen axis.

Definition at line 629 of file PolyMath.cpp.

◆ solve()

Eigen::VectorXd CoolProp::Polynomial2DFrac::solve ( const Eigen::MatrixXd &  coefficients,
const double &  in,
const double &  z_in,
const int &  axis,
const int &  x_exp,
const int &  y_exp,
const double &  x_base = 0.0,
const double &  y_base = 0.0 
)

Returns a vector with ALL the real roots of p(x_in,y_in)-z_in

Parameters
coefficientsvector containing the ordered coefficients
indouble value that represents the current input in x (1st dimension) or y (2nd dimension)
z_indouble value that represents the current output in the 3rd dimension
axisunsigned integer value that represents the axis to solve for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension

Returns a vector with ALL the real roots of p(x_in,y_in)-z_in

Parameters
coefficientsvector containing the ordered coefficients
indouble value that represents the current input in x (1st dimension) or y (2nd dimension)
z_indouble value that represents the current output in the 3rd dimension
axisinteger value that represents the axis to solve for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension

Definition at line 710 of file PolyMath.cpp.

◆ solve_guess()

double CoolProp::Polynomial2DFrac::solve_guess ( const Eigen::MatrixXd &  coefficients,
const double &  in,
const double &  z_in,
const double &  guess,
const int &  axis,
const int &  x_exp,
const int &  y_exp,
const double &  x_base = 0.0,
const double &  y_base = 0.0 
)

Uses the Newton solver to find the roots of p(x_in,y_in)-z_in

Parameters
coefficientsvector containing the ordered coefficients
indouble value that represents the current input in x (1st dimension) or y (2nd dimension)
z_indouble value that represents the current output in the 3rd dimension
guessdouble value that represents the start value
axisunsigned integer value that represents the axis to solve for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension

Definition at line 796 of file PolyMath.cpp.

◆ solve_guessInt()

double CoolProp::Polynomial2DFrac::solve_guessInt ( const Eigen::MatrixXd &  coefficients,
const double &  in,
const double &  z_in,
const double &  guess,
const int &  axis,
const int &  x_exp,
const int &  y_exp,
const double &  x_base = 0.0,
const double &  y_base = 0.0,
const int &  int_axis = 0 
)

Uses the Newton solver to find the roots of Int(p(x_in,y_in))-z_in

Parameters
coefficientsvector containing the ordered coefficients
indouble value that represents the current input in x (1st dimension) or y (2nd dimension)
z_indouble value that represents the current output in the 3rd dimension
guessdouble value that represents the start value
axisunsigned integer value that represents the axis to solve for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension
int_axisaxis for the integration (0=x, 1=y)

Definition at line 835 of file PolyMath.cpp.

◆ solve_limits()

double CoolProp::Polynomial2DFrac::solve_limits ( const Eigen::MatrixXd &  coefficients,
const double &  in,
const double &  z_in,
const double &  min,
const double &  max,
const int &  axis,
const int &  x_exp,
const int &  y_exp,
const double &  x_base = 0.0,
const double &  y_base = 0.0 
)

Uses the Brent solver to find the roots of p(x_in,y_in)-z_in

Parameters
coefficientsvector containing the ordered coefficients
indouble value that represents the current input in x (1st dimension) or y (2nd dimension)
z_indouble value that represents the current output in the 3rd dimension
mindouble value that represents the minimum value
maxdouble value that represents the maximum value
axisunsigned integer value that represents the axis to solve for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension

Uses the Brent solver to find the roots of p(x_in,y_in)-z_in

Parameters
coefficientsvector containing the ordered coefficients
indouble value that represents the current input in x (1st dimension) or y (2nd dimension)
z_indouble value that represents the current output in the 3rd dimension
mindouble value that represents the minimum value
maxdouble value that represents the maximum value
axisinteger value that represents the axis to solve for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension

Definition at line 777 of file PolyMath.cpp.

◆ solve_limitsInt()

double CoolProp::Polynomial2DFrac::solve_limitsInt ( const Eigen::MatrixXd &  coefficients,
const double &  in,
const double &  z_in,
const double &  min,
const double &  max,
const int &  axis,
const int &  x_exp,
const int &  y_exp,
const double &  x_base = 0.0,
const double &  y_base = 0.0,
const int &  int_axis = 0 
)

Uses the Brent solver to find the roots of Int(p(x_in,y_in))-z_in

Parameters
coefficientsvector containing the ordered coefficients
indouble value that represents the current input in x (1st dimension) or y (2nd dimension)
z_indouble value that represents the current output in the 3rd dimension
mindouble value that represents the minimum value
maxdouble value that represents the maximum value
axisunsigned integer value that represents the axis to solve for (0=x, 1=y)
x_expinteger value that represents the lowest exponent of the polynomial in the 1st dimension
y_expinteger value that represents the lowest exponent of the polynomial in the 2nd dimension
x_basedouble value that represents the base value for a centred fit in the 1st dimension
y_basedouble value that represents the base value for a centred fit in the 2nd dimension
int_axisaxis for the integration (0=x, 1=y)

Definition at line 817 of file PolyMath.cpp.


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