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::Polynomial2D Class Reference

Detailed Description

The base class for all Polynomials.

A clear and straight forward implementation of polynomial operations. Still very basic, but serves its purpose.

Definition at line 24 of file PolyMath.h.

#include <PolyMath.h>

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

Public Member Functions

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

◆ Polynomial2D()

CoolProp::Polynomial2D::Polynomial2D ( )
inline

Constructors.

Definition at line 29 of file PolyMath.h.

◆ ~Polynomial2D()

virtual CoolProp::Polynomial2D::~Polynomial2D ( )
inlinevirtual

Destructor. No implementation.

Definition at line 32 of file PolyMath.h.

Member Function Documentation

◆ baseHorner()

double CoolProp::Polynomial2D::baseHorner ( const std::vector< double > &  coefficients,
double  x 
)
protected

Horner function generator implementations.

Represent polynomials according to Horner's scheme. This avoids unnecessary multiplication and thus speeds up calculation. Deprecated since we moved everything to the Eigen framework.

Represent polynomials according to Horner's scheme. This avoids unnecessary multiplication and thus speeds up calculation.

Definition at line 313 of file PolyMath.cpp.

◆ checkCoefficients()

bool CoolProp::Polynomial2D::checkCoefficients ( const Eigen::MatrixXd &  coefficients,
const unsigned int  rows,
const unsigned int  columns 
)

Basic checks for coefficient vectors.

Starts with only the first coefficient dimension and checks the matrix size against the parameters rows and columns.

Parameters
coefficientsmatrix containing the ordered coefficients
rowsunsigned integer value that represents the desired degree of the polynomial in the 1st dimension
columnsunsigned integer value that represents the desired degree of the polynomial in the 2nd dimension

Definition at line 30 of file PolyMath.cpp.

◆ convertCoefficients() [1/2]

Eigen::MatrixXd CoolProp::Polynomial2D::convertCoefficients ( const std::vector< double > &  coefficients)
inline

Convert the coefficient vector.

Parameters
coefficientsvector containing the ordered coefficients

Definition at line 37 of file PolyMath.h.

◆ convertCoefficients() [2/2]

Eigen::MatrixXd CoolProp::Polynomial2D::convertCoefficients ( const std::vector< std::vector< double >> &  coefficients)
inline

Convert the coefficient matrix.

Parameters
coefficientsmatrix containing the ordered coefficients

Definition at line 42 of file PolyMath.h.

◆ DEPRECATED() [1/2]

CoolProp::Polynomial2D::DEPRECATED ( double   baseHornerconst std::vector< std::vector< double >> &coefficients, double x, double y)
protected

◆ DEPRECATED() [2/2]

CoolProp::Polynomial2D::DEPRECATED ( double   simplePolynomialconst std::vector< std::vector< double >> &coefficients, double x, double y)
protected

◆ derivative()

double CoolProp::Polynomial2D::derivative ( const Eigen::MatrixXd &  coefficients,
const double &  x_in,
const double &  y_in,
const int &  axis = -1 
)
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)

Definition at line 193 of file PolyMath.cpp.

◆ deriveCoeffs()

Eigen::MatrixXd CoolProp::Polynomial2D::deriveCoeffs ( const Eigen::MatrixXd &  coefficients,
const int &  axis = -1,
const int &  times = 1 
)

Derivative coefficients calculation.

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

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

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

Parameters
coefficientsmatrix containing the ordered coefficients
axisinteger value that represents the desired direction of derivation
timesinteger value that represents the desired order of integration

Definition at line 109 of file PolyMath.cpp.

◆ do_debug()

bool CoolProp::Polynomial2D::do_debug ( void  )
inlineprotected

Definition at line 167 of file PolyMath.h.

◆ evaluate() [1/2]

double CoolProp::Polynomial2D::evaluate ( const Eigen::MatrixXd &  coefficients,
const double &  x_in 
)

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

It is here we implement the different special functions that allow us to specify certain types of polynomials. The derivative might bee needed during the solution process of the solver. It could also be a protected function...

Parameters
coefficientsvector containing the ordered coefficients
x_indouble value that represents the current input

Definition at line 167 of file PolyMath.cpp.

◆ evaluate() [2/2]

double CoolProp::Polynomial2D::evaluate ( const Eigen::MatrixXd &  coefficients,
const double &  x_in,
const double &  y_in 
)
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

Definition at line 176 of file PolyMath.cpp.

◆ integral()

double CoolProp::Polynomial2D::integral ( const Eigen::MatrixXd &  coefficients,
const double &  x_in,
const double &  y_in,
const int &  axis = -1 
)
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)

Definition at line 201 of file PolyMath.cpp.

◆ integrateCoeffs()

Eigen::MatrixXd CoolProp::Polynomial2D::integrateCoeffs ( const Eigen::MatrixXd &  coefficients,
const int &  axis = -1,
const int &  times = 1 
)

Integration functions.

Integrating coefficients for polynomials is done by dividing the original coefficients by (i+1) and elevating the order by 1 through adding a zero as first coefficient. Some reslicing needs to be applied to integrate along the x-axis. In the brine/solution equations, reordering of the parameters avoids this expensive operation. However, it is included for the sake of completeness.

Parameters
coefficientsmatrix containing the ordered coefficients
axisunsigned integer value that represents the desired direction of integration
timesinteger value that represents the desired order of integration

Integrating coefficients for polynomials is done by dividing the original coefficients by (i+1) and elevating the order by 1 through adding a zero as first coefficient. Some reslicing needs to be applied to integrate along the x-axis. In the brine/solution equations, reordering of the parameters avoids this expensive operation. However, it is included for the sake of completeness.

Parameters
coefficientsmatrix containing the ordered coefficients
axisinteger value that represents the desired direction of integration
timesinteger value that represents the desired order of integration

Definition at line 55 of file PolyMath.cpp.

◆ simplePolynomial()

double CoolProp::Polynomial2D::simplePolynomial ( const std::vector< double > &  coefficients,
double  x 
)
protected

Simple polynomial function generator. <- Deprecated due to poor performance, use Horner-scheme instead.

Base function to produce n-th order polynomials based on the length of the coefficient vector. Starts with only the first coefficient at x^0.

Definition at line 288 of file PolyMath.cpp.

◆ solve()

Eigen::VectorXd CoolProp::Polynomial2D::solve ( const Eigen::MatrixXd &  coefficients,
const double &  in,
const double &  z_in,
const int &  axis = -1 
)

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

Definition at line 236 of file PolyMath.cpp.

◆ solve_guess() [1/2]

double CoolProp::Polynomial2D::solve_guess ( const Eigen::MatrixXd &  coefficients,
const double &  in,
const double &  z_in,
const double &  guess,
const int &  axis 
)

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

Definition at line 279 of file PolyMath.cpp.

◆ solve_guess() [2/2]

double CoolProp::Polynomial2D::solve_guess ( Poly2DResidual res,
const double &  guess 
)
protected

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

Parameters
resPoly2DResidual object to calculate residuals and derivatives
guessdouble value that represents the start value

Definition at line 222 of file PolyMath.cpp.

◆ solve_limits() [1/2]

double CoolProp::Polynomial2D::solve_limits ( const Eigen::MatrixXd &  coefficients,
const double &  in,
const double &  z_in,
const double &  min,
const double &  max,
const int &  axis 
)

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

Definition at line 269 of file PolyMath.cpp.

◆ solve_limits() [2/2]

double CoolProp::Polynomial2D::solve_limits ( Poly2DResidual res,
const double &  min,
const double &  max 
)
protected

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

Parameters
resPoly2DResidual object to calculate residuals and derivatives
mindouble value that represents the minimum value
maxdouble value that represents the maximum value

Definition at line 209 of file PolyMath.cpp.


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