CoolProp  6.6.0
An open-source fluid property and humid air property database
Classes | Macros | Functions
CPnumerics.h File Reference
#include <vector>
#include <set>
#include <cfloat>
#include <stdlib.h>
#include <algorithm>
#include <numeric>
#include <cmath>
#include "PlatformDetermination.h"
#include "CPstrings.h"
#include "Exceptions.h"

Go to the source code of this file.

Classes

class  Spline< X, Y >
 
class  Spline< X, Y >::Element
 
class  SplineClass
 

Macros

#define M_PI   3.14159265358979323846
 
#define COOLPROP_OK   1
 
#define POW5(x)   ((x) * (x) * (x) * (x) * (x))
 
#define POW6(x)   ((x) * (x) * (x) * (x) * (x) * (x))
 
#define POW7(x)   ((x) * (x) * (x) * (x) * (x) * (x) * (x))
 

Functions

bool ValidNumber (double x)
 
template<typename T >
maxvectordiff (const std::vector< T > &z1, const std::vector< T > &z2)
 Return the maximum difference between elements in two vectors where comparing z1[i] and z2[i]. More...
 
template<typename T >
std::vector< T > linspace (T xmin, T xmax, std::size_t n)
 Make a linearly spaced vector of points. More...
 
template<typename T >
std::vector< T > log10space (T xmin, T xmax, std::size_t n)
 Make a base-10 logarithmically spaced vector of points. More...
 
template<typename T >
std::vector< T > logspace (T xmin, T xmax, std::size_t n)
 Make a base-e logarithmically spaced vector of points. More...
 
template<typename T >
void bisect_vector (const std::vector< T > &vec, T val, std::size_t &i)
 Use bisection to find the inputs that bisect the value you want, the trick here is that this function is allowed to have "holes" where parts of the the array are also filled with invalid numbers for which ValidNumber(x) is false. More...
 
template<typename T >
void bisect_segmented_vector_slice (const std::vector< std::vector< T >> &mat, std::size_t j, T val, std::size_t &i)
 Use bisection to find the inputs that bisect the value you want, the trick here is that this function is allowed to have "holes" where parts of the the array are also filled with invalid numbers for which ValidNumber(x) is false. More...
 
std::size_t powerset_dereference (std::set< std::size_t >::const_iterator v)
 
std::set< std::set< std::size_t > > powerset (std::set< std::size_t > const &set)
 
bool check_abs (double A, double B, double D)
 Some functions related to testing and comparison of values. More...
 
bool check_abs (double A, double B)
 
template<class T >
void normalize_vector (std::vector< T > &x)
 
template<class T >
factorial (T n)
 from http://stackoverflow.com/a/5721830/1360263 More...
 
template<class T1 , class T2 >
T1 nth_derivative_of_x_to_m (T1 x, T2 n, T2 m)
 
void MatInv_2 (double A[2][2], double B[2][2])
 
double root_sum_square (const std::vector< double > &x)
 
double interp1d (const std::vector< double > *x, const std::vector< double > *y, double x0)
 
double powInt (double x, int y)
 
template<class T >
POW2 (T x)
 
template<class T >
POW3 (T x)
 
template<class T >
POW4 (T x)
 
template<class T >
LinearInterp (T x0, T x1, T y0, T y1, T x)
 
template<class T1 , class T2 >
T2 LinearInterp (const std::vector< T1 > &x, const std::vector< T1 > &y, std::size_t i0, std::size_t i1, T2 val)
 
template<class T >
QuadInterp (T x0, T x1, T x2, T f0, T f1, T f2, T x)
 
template<class T1 , class T2 >
T2 QuadInterp (const std::vector< T1 > &x, const std::vector< T1 > &y, std::size_t i0, std::size_t i1, std::size_t i2, T2 val)
 
template<class T >
CubicInterp (T x0, T x1, T x2, T x3, T f0, T f1, T f2, T f3, T x)
 
template<class T >
CubicInterpFirstDeriv (T x0, T x1, T x2, T x3, T f0, T f1, T f2, T f3, T x)
 
template<class T1 , class T2 >
T2 CubicInterp (const std::vector< T1 > &x, const std::vector< T1 > &y, std::size_t i0, std::size_t i1, std::size_t i2, std::size_t i3, T2 val)
 
template<class T >
is_in_closed_range (T x1, T x2, T x)
 
void solve_cubic (double a, double b, double c, double d, int &N, double &x0, double &x1, double &x2)
 Solve a cubic with coefficients in decreasing order. More...
 
void solve_quartic (double a, double b, double c, double d, double e, int &N, double &x0, double &x1, double &x2, double &x3)
 
template<class T >
min3 (T x1, T x2, T x3)
 
template<class T >
max3 (T x1, T x2, T x3)
 
template<class T >
min4 (T x1, T x2, T x3, T x4)
 
template<class T >
max4 (T x1, T x2, T x3, T x4)
 
bool double_equal (double a, double b)
 
template<class T >
max_abs_value (const std::vector< T > &x)
 
template<class T >
min_abs_value (const std::vector< T > &x)
 
int Kronecker_delta (std::size_t i, std::size_t j)
 
int Kronecker_delta (int i, int j)
 
template<typename T >
void sort3 (T &a, T &b, T &c)
 Sort three values in place; see http://codereview.stackexchange.com/a/64763. More...
 
template<class T >
angle_difference (T angle1, T angle2)
 
double get_HUGE ()
 A simple function for use in wrappers where macros cause problems. More...
 

Macro Definition Documentation

◆ COOLPROP_OK

#define COOLPROP_OK   1

Definition at line 34 of file CPnumerics.h.

◆ M_PI

#define M_PI   3.14159265358979323846

Definition at line 30 of file CPnumerics.h.

◆ POW5

#define POW5 (   x)    ((x) * (x) * (x) * (x) * (x))

Definition at line 488 of file CPnumerics.h.

◆ POW6

#define POW6 (   x)    ((x) * (x) * (x) * (x) * (x) * (x))

Definition at line 489 of file CPnumerics.h.

◆ POW7

#define POW7 (   x)    ((x) * (x) * (x) * (x) * (x) * (x) * (x))

Definition at line 490 of file CPnumerics.h.

Function Documentation

◆ angle_difference()

template<class T >
T angle_difference ( angle1,
angle2 
)

Due to the periodicity of angles, you need to handle the case where the angles wrap around - suppose theta_d is 6.28 and you are at an angles of 0.1 rad, the difference should be around 0.1, not -6.27

This brilliant method is from http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign and the comment of user tk

Originally implemented in PDSim

Definition at line 660 of file CPnumerics.h.

◆ bisect_segmented_vector_slice()

template<typename T >
void bisect_segmented_vector_slice ( const std::vector< std::vector< T >> &  mat,
std::size_t  j,
val,
std::size_t &  i 
)

Use bisection to find the inputs that bisect the value you want, the trick here is that this function is allowed to have "holes" where parts of the the array are also filled with invalid numbers for which ValidNumber(x) is false.

Parameters
matrixThe vector to be bisected
jThe index of the matric in the off-grain dimension
valThe value to be found
iThe index to the left of the final point; i and i+1 bound the value

Definition at line 303 of file CPnumerics.h.

◆ bisect_vector()

template<typename T >
void bisect_vector ( const std::vector< T > &  vec,
val,
std::size_t &  i 
)

Use bisection to find the inputs that bisect the value you want, the trick here is that this function is allowed to have "holes" where parts of the the array are also filled with invalid numbers for which ValidNumber(x) is false.

Parameters
vecThe vector to be bisected
valThe value to be found
iThe index to the left of the final point; i and i+1 bound the value

Definition at line 223 of file CPnumerics.h.

◆ check_abs() [1/2]

bool check_abs ( double  A,
double  B 
)
inline

Definition at line 419 of file CPnumerics.h.

◆ check_abs() [2/2]

bool check_abs ( double  A,
double  B,
double  D 
)
inline

Some functions related to testing and comparison of values.

Definition at line 406 of file CPnumerics.h.

◆ CubicInterp() [1/2]

template<class T1 , class T2 >
T2 CubicInterp ( const std::vector< T1 > &  x,
const std::vector< T1 > &  y,
std::size_t  i0,
std::size_t  i1,
std::size_t  i2,
std::size_t  i3,
T2  val 
)

Definition at line 547 of file CPnumerics.h.

◆ CubicInterp() [2/2]

template<class T >
T CubicInterp ( x0,
x1,
x2,
x3,
f0,
f1,
f2,
f3,
x 
)

Definition at line 519 of file CPnumerics.h.

◆ CubicInterpFirstDeriv()

template<class T >
T CubicInterpFirstDeriv ( x0,
x1,
x2,
x3,
f0,
f1,
f2,
f3,
x 
)

/brief Calculate the first derivative of the function using a cubic interpolation form

Definition at line 534 of file CPnumerics.h.

◆ double_equal()

bool double_equal ( double  a,
double  b 
)
inline

Definition at line 590 of file CPnumerics.h.

◆ factorial()

template<class T >
T factorial ( n)

◆ get_HUGE()

double get_HUGE ( )
inline

A simple function for use in wrappers where macros cause problems.

Definition at line 665 of file CPnumerics.h.

◆ interp1d()

double interp1d ( const std::vector< double > *  x,
const std::vector< double > *  y,
double  x0 
)

Definition at line 12 of file CPnumerics.cpp.

◆ is_in_closed_range()

template<class T >
T is_in_closed_range ( x1,
x2,
x 
)

Definition at line 552 of file CPnumerics.h.

◆ Kronecker_delta() [1/2]

int Kronecker_delta ( int  i,
int  j 
)
inline

Definition at line 627 of file CPnumerics.h.

◆ Kronecker_delta() [2/2]

int Kronecker_delta ( std::size_t  i,
std::size_t  j 
)
inline

Definition at line 620 of file CPnumerics.h.

◆ LinearInterp() [1/2]

template<class T1 , class T2 >
T2 LinearInterp ( const std::vector< T1 > &  x,
const std::vector< T1 > &  y,
std::size_t  i0,
std::size_t  i1,
T2  val 
)

Definition at line 497 of file CPnumerics.h.

◆ LinearInterp() [2/2]

template<class T >
T LinearInterp ( x0,
x1,
y0,
y1,
x 
)

Definition at line 493 of file CPnumerics.h.

◆ linspace()

template<typename T >
std::vector<T> linspace ( xmin,
xmax,
std::size_t  n 
)

Make a linearly spaced vector of points.

Definition at line 183 of file CPnumerics.h.

◆ log10space()

template<typename T >
std::vector<T> log10space ( xmin,
xmax,
std::size_t  n 
)

Make a base-10 logarithmically spaced vector of points.

Definition at line 193 of file CPnumerics.h.

◆ logspace()

template<typename T >
std::vector<T> logspace ( xmin,
xmax,
std::size_t  n 
)

Make a base-e logarithmically spaced vector of points.

Definition at line 204 of file CPnumerics.h.

◆ MatInv_2()

void MatInv_2 ( double  A[2][2],
double  B[2][2] 
)

Definition at line 70 of file CPnumerics.cpp.

◆ max3()

template<class T >
T max3 ( x1,
x2,
x3 
)
inline

Definition at line 578 of file CPnumerics.h.

◆ max4()

template<class T >
T max4 ( x1,
x2,
x3,
x4 
)
inline

Definition at line 586 of file CPnumerics.h.

◆ max_abs_value()

template<class T >
T max_abs_value ( const std::vector< T > &  x)

Definition at line 595 of file CPnumerics.h.

◆ maxvectordiff()

template<typename T >
T maxvectordiff ( const std::vector< T > &  z1,
const std::vector< T > &  z2 
)

Return the maximum difference between elements in two vectors where comparing z1[i] and z2[i].

Definition at line 170 of file CPnumerics.h.

◆ min3()

template<class T >
T min3 ( x1,
x2,
x3 
)
inline

Definition at line 574 of file CPnumerics.h.

◆ min4()

template<class T >
T min4 ( x1,
x2,
x3,
x4 
)
inline

Definition at line 582 of file CPnumerics.h.

◆ min_abs_value()

template<class T >
T min_abs_value ( const std::vector< T > &  x)

Definition at line 608 of file CPnumerics.h.

◆ normalize_vector()

template<class T >
void normalize_vector ( std::vector< T > &  x)

Definition at line 424 of file CPnumerics.h.

◆ nth_derivative_of_x_to_m()

template<class T1 , class T2 >
T1 nth_derivative_of_x_to_m ( T1  x,
T2  n,
T2  m 
)

◆ POW2()

template<class T >
T POW2 ( x)

Definition at line 477 of file CPnumerics.h.

◆ POW3()

template<class T >
T POW3 ( x)

Definition at line 481 of file CPnumerics.h.

◆ POW4()

template<class T >
T POW4 ( x)

Definition at line 485 of file CPnumerics.h.

◆ powerset()

std::set<std::set<std::size_t> > powerset ( std::set< std::size_t > const &  set)
inline

Definition at line 379 of file CPnumerics.h.

◆ powerset_dereference()

std::size_t powerset_dereference ( std::set< std::size_t >::const_iterator  v)
inline

Definition at line 374 of file CPnumerics.h.

◆ powInt()

double powInt ( double  x,
int  y 
)

Definition at line 39 of file CPnumerics.cpp.

◆ QuadInterp() [1/2]

template<class T1 , class T2 >
T2 QuadInterp ( const std::vector< T1 > &  x,
const std::vector< T1 > &  y,
std::size_t  i0,
std::size_t  i1,
std::size_t  i2,
T2  val 
)

Definition at line 514 of file CPnumerics.h.

◆ QuadInterp() [2/2]

template<class T >
T QuadInterp ( x0,
x1,
x2,
f0,
f1,
f2,
x 
)

Definition at line 502 of file CPnumerics.h.

◆ root_sum_square()

double root_sum_square ( const std::vector< double > &  x)

Definition at line 5 of file CPnumerics.cpp.

◆ solve_cubic()

void solve_cubic ( double  a,
double  b,
double  c,
double  d,
int &  N,
double &  x0,
double &  x1,
double &  x2 
)

Solve a cubic with coefficients in decreasing order.

0 = ax^3 + b*x^2 + c*x + d

Parameters
aThe x^3 coefficient
bThe x^2 coefficient
cThe x^1 coefficient
dThe x^0 coefficient
NThe number of unique real solutions found
x0The first solution found
x1The second solution found
x2The third solution found

Definition at line 81 of file CPnumerics.cpp.

◆ solve_quartic()

void solve_quartic ( double  a,
double  b,
double  c,
double  d,
double  e,
int &  N,
double &  x0,
double &  x1,
double &  x2,
double &  x3 
)

Definition at line 133 of file CPnumerics.cpp.

◆ sort3()

template<typename T >
void sort3 ( T &  a,
T &  b,
T &  c 
)

Sort three values in place; see http://codereview.stackexchange.com/a/64763.

Definition at line 637 of file CPnumerics.h.

◆ ValidNumber()

bool ValidNumber ( double  x)
inline

Definition at line 24 of file CPnumerics.h.