CoolProp

The base class for all Polynomials.
A clear and straight forward implementation of polynomial operations. Still very basic, but serves its purpose.
#include <PolyMath.h>
Public Member Functions  
Polynomial2D ()  
Constructors.  
virtual  ~Polynomial2D () 
Destructor. No implementation.  
Eigen::MatrixXd  convertCoefficients (const std::vector< double > &coefficients) 
Convert the coefficient vector. More...  
Eigen::MatrixXd  convertCoefficients (const std::vector< std::vector< double > > &coefficients) 
Convert the coefficient matrix. More...  
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 ×) 
Integration functions. More...  
Eigen::MatrixXd  deriveCoeffs (const Eigen::MatrixXd &coefficients, const int &axis=1, const int ×=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) 
Returns a vector with ALL the real roots of p(x_in,y_in)z_in. More...  
double  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. More...  
double  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. More...  
Protected Member Functions  
double  solve_limits (Poly2DResidual *res, const double &min, const double &max) 
Uses the Brent solver to find the roots of p(x_in,y_in)z_in. More...  
double  solve_guess (Poly2DResidual *res, const double &guess) 
Uses the Newton solver to find the roots of p(x_in,y_in)z_in. More...  
double  simplePolynomial (const std::vector< double > &coefficients, double x) 
Simple polynomial function generator. < Deprecated due to poor performance, use Hornerscheme 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) 

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.
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.
coefficients  matrix containing the ordered coefficients 
rows  unsigned integer value that represents the desired degree of the polynomial in the 1st dimension 
columns  unsigned integer value that represents the desired degree of the polynomial in the 2nd dimension 
Starts with only the first coefficient dimension and checks the matrix size against the parameters rows and columns.
coefficients  matrix containing the ordered coefficients 
rows  unsigned integer value that represents the desired degree of the polynomial in the 1st dimension 
columns  unsigned integer value that represents the desired degree of the polynomial in the 2nd dimension 

inline 
Convert the coefficient vector.
coefficients  vector containing the ordered coefficients 

inline 
Convert the coefficient matrix.
coefficients  matrix containing the ordered coefficients 
double CoolProp::Polynomial2D::derivative  (  const Eigen::MatrixXd &  coefficients, 
const double &  x_in,  
const double &  y_in,  
const int &  axis = 1 

) 
coefficients  vector containing the ordered coefficients 
x_in  double value that represents the current input in the 1st dimension 
y_in  double value that represents the current input in the 2nd dimension 
axis  unsigned integer value that represents the axis to derive for (0=x, 1=y) 
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.
coefficients  matrix containing the ordered coefficients 
axis  unsigned integer value that represents the desired direction of derivation 
times  integer 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.
coefficients  matrix containing the ordered coefficients 
axis  integer value that represents the desired direction of derivation 
times  integer value that represents the desired order of integration 
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.
coefficients  vector containing the ordered coefficients 
x_in  double 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...
coefficients  vector containing the ordered coefficients 
x_in  double value that represents the current input 
double CoolProp::Polynomial2D::evaluate  (  const Eigen::MatrixXd &  coefficients, 
const double &  x_in,  
const double &  y_in  
) 
coefficients  vector containing the ordered coefficients 
x_in  double value that represents the current input in the 1st dimension 
y_in  double value that represents the current input in the 2nd dimension 
double CoolProp::Polynomial2D::integral  (  const Eigen::MatrixXd &  coefficients, 
const double &  x_in,  
const double &  y_in,  
const int &  axis = 1 

) 
coefficients  vector containing the ordered coefficients 
x_in  double value that represents the current input in the 1st dimension 
y_in  double value that represents the current input in the 2nd dimension 
axis  unsigned integer value that represents the axis to integrate for (0=x, 1=y) 
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 xaxis. In the brine/solution equations, reordering of the parameters avoids this expensive operation. However, it is included for the sake of completeness.
coefficients  matrix containing the ordered coefficients 
axis  unsigned integer value that represents the desired direction of integration 
times  integer 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 xaxis. In the brine/solution equations, reordering of the parameters avoids this expensive operation. However, it is included for the sake of completeness.
coefficients  matrix containing the ordered coefficients 
axis  integer value that represents the desired direction of integration 
times  integer value that represents the desired order of integration 

protected 
Simple polynomial function generator. < Deprecated due to poor performance, use Hornerscheme instead.
Base function to produce nth order polynomials based on the length of the coefficient vector. Starts with only the first coefficient at x^0.
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.
coefficients  vector containing the ordered coefficients 
in  double value that represents the current input in x (1st dimension) or y (2nd dimension) 
z_in  double value that represents the current output in the 3rd dimension 
axis  unsigned integer value that represents the axis to solve for (0=x, 1=y) 

protected 
Uses the Newton solver to find the roots of p(x_in,y_in)z_in.
res  Poly2DResidual object to calculate residuals and derivatives 
guess  double value that represents the start value 
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.
coefficients  vector containing the ordered coefficients 
in  double value that represents the current input in x (1st dimension) or y (2nd dimension) 
z_in  double value that represents the current output in the 3rd dimension 
guess  double value that represents the start value 
axis  unsigned integer value that represents the axis to solve for (0=x, 1=y) 
in  double value that represents the current input in x (1st dimension) or y (2nd dimension) 
z_in  double value that represents the current output in the 3rd dimension 
guess  double value that represents the start value 
axis  unsigned integer value that represents the axis to solve for (0=x, 1=y) 

protected 
Uses the Brent solver to find the roots of p(x_in,y_in)z_in.
res  Poly2DResidual object to calculate residuals and derivatives 
min  double value that represents the minimum value 
max  double value that represents the maximum value 
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.
coefficients  vector containing the ordered coefficients 
in  double value that represents the current input in x (1st dimension) or y (2nd dimension) 
z_in  double value that represents the current output in the 3rd dimension 
min  double value that represents the minimum value 
max  double value that represents the maximum value 
axis  unsigned integer value that represents the axis to solve for (0=x, 1=y) 
in  double value that represents the current input in x (1st dimension) or y (2nd dimension) 
z_in  double value that represents the current output in the 3rd dimension 
axis  unsigned integer value that represents the axis to solve for (0=x, 1=y) 