CoolProp  4.2.5
An open-source fluid property and humid air property database
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CoolPropTools.h
Go to the documentation of this file.
1 #ifndef COOLPROPTOOLS_H
2 #define COOLPROPTOOLS_H
3 
4 #define _CRT_SECURE_NO_WARNINGS
5 
6 #if defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(__WIN64__)
7 # define __ISWINDOWS__
8 #elif __APPLE__
9 # define __ISAPPLE__
10 #elif __linux
11 # define __ISLINUX__
12 #endif
13 
14 #if defined(COOLPROP_LIB)
15 # ifndef EXPORT_CODE
16 # if defined(__ISWINDOWS__)
17 # define EXPORT_CODE extern "C" __declspec(dllexport)
18 # else
19 # define EXPORT_CODE extern "C"
20 # endif
21 # endif
22 # ifndef CONVENTION
23 # if defined(__ISWINDOWS__)
24 # define CONVENTION __stdcall
25 # else
26 # define CONVENTION
27 # endif
28 # endif
29 #else
30 # ifndef EXPORT_CODE
31 # define EXPORT_CODE
32 # endif
33 # ifndef CONVENTION
34 # define CONVENTION
35 # endif
36 #endif
37 
38 // Hack for PowerPC compilation to only use extern "C"
39 #if defined(__powerpc__) || defined(EXTERNC)
40 # undef EXPORT_CODE
41 # define EXPORT_CODE extern "C"
42 #endif
43 
44 // Fall-back solutions
45 #ifndef CONVENTION
46 # define CONVENTION
47 #endif
48 #ifndef EXPORT_CODE
49 # define EXPORT_CODE
50 #endif
51 
52 #include <string>
53 #include <vector>
54 #include <cmath>
55 #include "float.h"
56 
57 #ifndef M_PI
58 # define M_PI 3.14159265358979323846
59 #endif
60 
61 #ifndef COOLPROP_OK
62 #define COOLPROP_OK 1
63 #endif
64 
65 #ifdef HUGE_VAL
66 # define _HUGE HUGE_VAL
67 #else
68 // GCC Version of huge value macro
69 #ifdef HUGE
70 # define _HUGE HUGE
71 #endif
72 #endif
73 
74  #if defined(_MSC_VER)
75  // Microsoft version of math.h doesn't include acosh or asinh, so we just define them here.
76  // It was included from Visual Studio 2013
77  #if _MSC_VER < 1800
78  static double acosh(double x)
79  {
80  return log(x + sqrt(x*x - 1.0));
81  }
82  static double asinh(double value)
83  {
84  if(value>0){
85  return log(value + sqrt(value * value + 1));
86  }
87  else{
88  return -log(-value + sqrt(value * value + 1));
89  }
90  }
91  #endif
92  #endif
93 
94  #if defined(__powerpc__)
95  // PPC version of math.h doesn't include acosh or asinh, so we just define them here
96  static double acosh(double x)
97  {
98  return log(x + sqrt(x*x - 1.0) );
99  }
100  static double asinh(double value)
101  {
102  if(value>0){
103  return log(value + sqrt(value * value + 1));
104  }
105  else{
106  return -log(-value + sqrt(value * value + 1));
107  }
108  }
109  #endif
110 
111  #if defined(__powerpc__)
112  #undef min
113  #undef max
114  #undef EOS
115  #endif
116 
117  inline bool ValidNumber(double x)
118  {
119  // Idea from http://www.johndcook.com/IEEE_exceptions_in_cpp.html
120  return (x <= DBL_MAX && x >= -DBL_MAX);
121  };
122 
124  #ifdef __GNUC__
125  #define DEPRECATED(func) func __attribute__ ((deprecated))
126  #elif defined(_MSC_VER)
127  #define DEPRECATED(func) __declspec(deprecated) func
128  #else
129  #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
130  #define DEPRECATED(func) func
131  #endif
132 
133  #include <algorithm>
134  #include <functional>
135  #include <cctype>
136  #include <locale>
137  #include <fstream>
138  #include <cerrno>
139 
141  // trim from start
142  inline std::string &strlstrip(std::string &s) {
143  s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
144  return s;
145  }
146  // trim from end
147  inline std::string &strrstrip(std::string &s) {
148  s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
149  return s;
150  }
151  // trim from both ends
152  inline std::string &strstrip(std::string &s) {
153  return strlstrip(strrstrip(s));
154  }
155 
156  // Get all the contents of a file and dump into a STL string
157  // Thanks to http://stackoverflow.com/questions/2602013/read-whole-ascii-file-into-c-stdstring
158  std::string get_file_contents(const char *filename);
159 
160  //missing string printf
161  std::string format(const char* fmt, ...);
162  // Missing string split - like in Python
163  std::vector<std::string> strsplit(std::string s, char del);
164 
165  inline std::string upper(const std::string str_)
166  {
167  std::string str = str_;
168  std::transform(str.begin(), str.end(), str.begin(), ::toupper);
169  return str;
170  }
171 
172  std::string strjoin(std::vector<std::string> strings, std::string delim);
173 
174  void MatInv_2(double A[2][2] , double B[2][2]);
175 
176  double root_sum_square(std::vector<double> x);
177  double interp1d(std::vector<double> *x, std::vector<double> *y, double x0);
178  double powInt(double x, int y);
179  double QuadInterp(double x0, double x1, double x2, double f0, double f1, double f2, double x);
180  double CubicInterp( double x0, double x1, double x2, double x3, double f0, double f1, double f2, double f3, double x);
181 
182  void solve_cubic(double a, double b, double c, double d, double *x0, double *x1, double *x2);
183 
184 
185 
186  inline double min3(double x1, double x2, double x3){return std::min(std::min(x1, x2), x3);};
187  inline double max3(double x1, double x2, double x3){return std::max(std::max(x1, x2), x3);};
188 
189  inline bool double_equal(double a, double b){return fabs(a - b) <= 1 * DBL_EPSILON * std::max(fabs(a), fabs(b));};
190 
191  inline int Kronecker_delta(int i, int j){if (i == j) {return 1;} else {return 0;}};
192 
193 #endif
std::string get_file_contents(const char *filename)
std::string & strstrip(std::string &s)
double powInt(double x, int y)
std::vector< std::string > strsplit(std::string s, char del)
double min3(double x1, double x2, double x3)
double root_sum_square(std::vector< double > x)
double max3(double x1, double x2, double x3)
bool double_equal(double a, double b)
#define DBL_EPSILON
Definition: Helmholtz.cpp:10
std::string & strlstrip(std::string &s)
The following code for the trim functions was taken from http://stackoverflow.com/questions/216823/wh...
std::vector< double > x(ncmax, 0)
double interp1d(std::vector< double > *x, std::vector< double > *y, double x0)
std::string & strrstrip(std::string &s)
double QuadInterp(double x0, double x1, double x2, double f0, double f1, double f2, double x)
void MatInv_2(double A[2][2], double B[2][2])
std::string format(const char *fmt,...)
std::string strjoin(std::vector< std::string > strings, std::string delim)
int Kronecker_delta(int i, int j)
double CubicInterp(double x0, double x1, double x2, double x3, double f0, double f1, double f2, double f3, double x)
std::string upper(const std::string str_)
bool ValidNumber(double x)
void solve_cubic(double a, double b, double c, double d, double *x0, double *x1, double *x2)