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
CoolPropDLL.cpp
Go to the documentation of this file.
1 #if defined(_MSC_VER)
2 #define _CRTDBG_MAP_ALLOC
3 #define _CRT_SECURE_NO_WARNINGS
4 #include <crtdbg.h>
5 #endif
6 
7 #include "CoolProp.h"
8 #include "CPState.h"
9 #include "FluidClass.h"
10 
11 static int debug_level=0;
12 
13 EXPORT_CODE long CONVENTION redirect_stdout(const char* file)
14 {
15  freopen(file, "a+", stdout);
16  return 0;
17 }
18 EXPORT_CODE int CONVENTION set_reference_stateS(const char *Ref, const char *reference_state)
19 {
20  return set_reference_stateS(std::string(Ref), std::string(reference_state));
21 }
22 EXPORT_CODE int CONVENTION set_reference_stateD(const char *Ref, double T, double rho, double h0, double s0)
23 {
24  return set_reference_stateD(std::string(Ref), T, rho, h0, s0);
25 }
26 // All the function interfaces that point to the single-input Props function
27 EXPORT_CODE double CONVENTION Props1(const char *FluidName, const char *Output)
28 {
29  return Props1(std::string(FluidName), std::string(Output));
30 }
31 EXPORT_CODE double CONVENTION Props1SI(const char *FluidName, const char *Output)
32 {
33  return Props1SI(std::string(FluidName),std::string(Output));
34 }
35 EXPORT_CODE double CONVENTION PropsS(const char *Output,const char* Name1, double Prop1, const char* Name2, double Prop2, const char * Ref)
36 {
37  double val = Props(Output,Name1[0],Prop1,Name2[0],Prop2,Ref);
38  return val;
39 }
40 EXPORT_CODE double CONVENTION Props(const char *Output,char Name1, double Prop1, char Name2, double Prop2, const char * Ref)
41 {
42  // Get parameter indices
43  long iOutput = get_param_index(Output);
44  if (iOutput < 0){
45  set_err_string(format("Your output key [%s] is not valid. (names are case sensitive)",Output));
46  return _HUGE;
47  }
48  long iName1 = get_param_index(std::string(1,Name1));
49  if (iName1 < 0){
50  set_err_string(format("Your input key #1 [%c] is not valid. (names are case sensitive)",Name1));
51  return _HUGE;
52  }
53  long iName2 = get_param_index(std::string(1,Name2));
54  if (iName2 < 0){
55  set_err_string(format("Your input key #2 [%c] is not valid. (names are case sensitive)",Name2));
56  return _HUGE;
57  }
58  char n1[] = "\0", n2[] = "\0";
59  n1[0] = Name1;
60  n2[0] = Name2;
61 
62  // Convert inputs to SI
65 
66  // Call the SI function
67  double val = PropsSI(Output,(const char*)n1,Prop1,(const char*)n2,Prop2,Ref);
68 
69  // Convert back to unit system
71 }
72 
73 EXPORT_CODE double CONVENTION PropsSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char * FluidName)
74 {
75  double val = PropsSI(std::string(Output),Name1,Prop1,Name2,Prop2,FluidName);
76  return val;
77 }
78 EXPORT_CODE double CONVENTION K2F(double T)
79 { return T * 9 / 5 - 459.67; }
80 
81 EXPORT_CODE double CONVENTION F2K(double T_F)
82 { return (T_F + 459.67) * 5 / 9;}
83 
84 EXPORT_CODE double CONVENTION DerivTerms(const char *Term, double T, double rho, const char * Ref)
85 {
86  // Go to the std::string, std::string version
87  double val = DerivTerms(std::string(Term),T,rho,std::string(Ref));
88  return val;
89 }
90 
91 EXPORT_CODE double CONVENTION fromSI(const char *input, double value, const char *new_system)
92 {
93  return convert_from_SI_to_unit_system(input, value, new_system);
94 }
95 EXPORT_CODE double CONVENTION toSI(const char *input, double value, const char *old_system)
96 {
97  return convert_from_unit_system_to_SI(input, value, old_system);
98 }
99 
100 EXPORT_CODE int CONVENTION get_debug_level(){return debug_level;}
101 EXPORT_CODE void CONVENTION set_debug_level(int level){debug_level=level;}
102 EXPORT_CODE long CONVENTION get_Fluid_index(const char * param)
103 {
104  return get_Fluid_index(std::string(param));
105 }
106 EXPORT_CODE int CONVENTION set_TTSE_mode(const char* fluid, const char *value)
107 {
108  long iFluid = get_Fluid_index(fluid);
109  if (iFluid > -1)
110  {
111  Fluid *pFluid = get_fluid(iFluid);
112 
113  // Try to build the LUT; Nothing will happen if the tables are already built
114  CoolPropStateClass C(fluid);
115  pFluid->build_TTSE_LUT();
116 
117  if (!strcmp(value,"TTSE"))
118  {
119  pFluid->TTSESinglePhase.set_mode(TTSE_MODE_TTSE); return true;
120  }
121  else if (!strcmp(value,"BICUBIC"))
122  {
123  pFluid->TTSESinglePhase.set_mode(TTSE_MODE_BICUBIC); return true;
124  }
125  else
126  {
127  return false;
128  }
129  }
130  else
131  {
132  return false;
133  }
134 }
135 EXPORT_CODE long CONVENTION get_param_index(const char * param)
136 {
137  return get_param_index(std::string(param));
138 }
139 #ifndef SWIG
140 EXPORT_CODE long CONVENTION get_global_param_string(const char *param, char * Output)
141 {
142  strcpy(Output,get_global_param_string(std::string(param)).c_str());
143  return 0;
144 }
145 EXPORT_CODE long CONVENTION get_fluid_param_string(const char *fluid, const char *param, char * Output)
146 {
147  strcpy(Output, get_fluid_param_string(std::string(fluid), std::string(param)).c_str());
148  return 0;
149 }
150 #endif
151 EXPORT_CODE long CONVENTION Phase(const char *Fluid, double T, double p, char *Phase_str)
152 {
153  strcpy(Phase_str,(char*)Phase(std::string(Fluid),T,p).c_str());
154  return 0;
155 }
156 EXPORT_CODE long CONVENTION Phase_Tp(const char *Fluid, double T, double p, char *Phase_str)
157 {
158  strcpy(Phase_str,(char*)Phase(std::string(Fluid),T,p).c_str());
159  return 0;
160 }
161 EXPORT_CODE long CONVENTION Phase_Trho(const char *Fluid, double T, double rho, char *Phase_str)
162 {
163  strcpy(Phase_str,(char*)Phase_Trho(std::string(Fluid),T,rho).c_str());
164  return 0;
165 }
166 // A function to enforce the state if known
167 EXPORT_CODE void CONVENTION set_phase(const char *Phase_str){
168  set_phase(std::string(Phase_str));
169 }
171 EXPORT_CODE bool CONVENTION enable_TTSE_LUT(const char *FluidName){
172  long iFluid = get_Fluid_index(FluidName); if (iFluid<0){ return false; };
173  Fluid *pFluid = get_fluid(iFluid);
174  pFluid->enable_TTSE_LUT();
175  return true;
176 };
178 EXPORT_CODE bool CONVENTION isenabled_TTSE_LUT(const char *FluidName){
179  long iFluid = get_Fluid_index(FluidName); if (iFluid<0){ return false; };
180  Fluid *pFluid = get_fluid(iFluid);
181  return pFluid->isenabled_TTSE_LUT();
182 }
184 EXPORT_CODE bool CONVENTION disable_TTSE_LUT(const char *FluidName){
185  long iFluid = get_Fluid_index(FluidName); if (iFluid<0){ return false; };
186  Fluid *pFluid = get_fluid(iFluid);
187  pFluid->disable_TTSE_LUT();
188  return true;
189 }
191 EXPORT_CODE bool CONVENTION enable_TTSE_LUT_writing(const char *FluidName){
192  long iFluid = get_Fluid_index(FluidName); if (iFluid<0){ return true;};
193  Fluid *pFluid = get_fluid(iFluid);
194  pFluid->enable_TTSE_LUT_writing();
195  return true;
196 };
199  long iFluid = get_Fluid_index(FluidName); if (iFluid<0){ return false;};
200  Fluid *pFluid = get_fluid(iFluid);
201  return pFluid->isenabled_TTSE_LUT_writing();
202 }
204 EXPORT_CODE bool CONVENTION disable_TTSE_LUT_writing(const char *FluidName){
205  long iFluid = get_Fluid_index(FluidName); if (iFluid<0){ return false;};
206  Fluid *pFluid = get_fluid(iFluid);
207  pFluid->disable_TTSE_LUT_writing();
208  return true;
209 }
211 EXPORT_CODE bool CONVENTION set_TTSESat_LUT_size(const char *FluidName, int Nsat){
212  long iFluid = get_Fluid_index(FluidName); if (iFluid<0){ return false; };
213  Fluid *pFluid = get_fluid(iFluid);
214  pFluid->set_TTSESat_LUT_size(Nsat);
215  return true;
216 }
218 EXPORT_CODE bool CONVENTION set_TTSESinglePhase_LUT_size(const char *FluidName, int Np, int Nh){
219  long iFluid = get_Fluid_index(FluidName); if (iFluid<0){ return false;};
220  Fluid *pFluid = get_fluid(iFluid);
221  pFluid->set_TTSESinglePhase_LUT_size(Np,Nh);
222  return true;
223 }
225 EXPORT_CODE bool CONVENTION set_TTSESinglePhase_LUT_range(const char *FluidName, double hmin, double hmax, double pmin, double pmax){
226  long iFluid = get_Fluid_index(FluidName); if (iFluid<0){ return false;};
227  Fluid *pFluid = get_fluid(iFluid);
228  pFluid->set_TTSESinglePhase_LUT_range(hmin,hmax,pmin,pmax);
229  return true;
230 }
232 EXPORT_CODE bool CONVENTION get_TTSESinglePhase_LUT_range(const char *FluidName, double *hmin, double *hmax, double *pmin, double *pmax){
233  long iFluid = get_Fluid_index(FluidName); if (iFluid<0){ return false;};
234  Fluid *pFluid = get_fluid(iFluid);
235  pFluid->get_TTSESinglePhase_LUT_range(hmin,hmax,pmin,pmax);
236  if (!ValidNumber(*hmin) && !ValidNumber(*hmax) && !ValidNumber(*pmin) && !ValidNumber(*pmax))
237  {
238  return false;
239  }
240  else
241  {
242  return true;
243  }
244 }
245 
249  return _get_standard_unit_system();
250 }
254  return _set_standard_unit_system(val);
255 }
EXPORT_CODE double CONVENTION F2K(double T_F)
Convert from degrees Fahrenheit to Kelvin (useful primarily for testing)
Definition: CoolPropDLL.cpp:81
Fluid * get_fluid(long iFluid)
Definition: CoolProp.cpp:236
EXPORT_CODE long CONVENTION Phase(const char *Fluid, double T, double p, char *Phase_str)
EXPORT_CODE bool CONVENTION enable_TTSE_LUT(const char *FluidName)
Enable the TTSE for this fluid.
EXPORT_CODE void CONVENTION set_standard_unit_system(int val)
bool build_TTSE_LUT(bool force=false)
Build of the TTSE LUT.
void enable_TTSE_LUT_writing(void)
Enable the writing of TTSE tables to file.
EXPORT_CODE int CONVENTION set_reference_stateS(const char *Ref, const char *reference_state)
Definition: CoolPropDLL.cpp:18
EXPORT_CODE int CONVENTION set_TTSE_mode(const char *fluid, const char *value)
Set the TTSE mode (normal or bicubic)
bool isenabled_TTSE_LUT_writing(void)
Check if the writing of TTSE tables to file is enabled.
EXPORT_CODE bool CONVENTION set_TTSESat_LUT_size(const char *FluidName, int Nsat)
Over-ride the default size of both of the saturation LUT.
EXPORT_CODE double CONVENTION Props1SI(const char *FluidName, const char *Output)
Definition: CoolPropDLL.cpp:31
void _set_standard_unit_system(int unit_sys)
Definition: CoolProp.cpp:62
EXPORT_CODE int CONVENTION get_debug_level()
void set_TTSESinglePhase_LUT_range(double hmin, double hmax, double pmin, double pmax)
Over-ride the default range of the single-phase LUT.
EXPORT_CODE void CONVENTION set_phase(const char *Phase_str)
int _get_standard_unit_system()
Definition: CoolProp.cpp:61
EXPORT_CODE void CONVENTION set_debug_level(int level)
EXPORT_CODE int CONVENTION get_standard_unit_system(void)
#define EXPORT_CODE
Definition: CoolPropTools.h:31
void set_TTSESinglePhase_LUT_size(int Np, int Nh)
Over-ride the default size of the single-phase LUT.
std::string format(const char *fmt,...)
EXPORT_CODE long CONVENTION get_Fluid_index(const char *param)
Fluid is the abstract base class that is employed by all the other fluids.
Definition: FluidClass.h:147
double convert_from_SI_to_unit_system(long iInput, double value, int new_system)
Definition: Units.cpp:123
EXPORT_CODE bool CONVENTION isenabled_TTSE_LUT_writing(const char *FluidName)
Check if the writing of TTSE tables to file is enabled.
EXPORT_CODE bool CONVENTION disable_TTSE_LUT_writing(const char *FluidName)
Disable the writing of TTSE tables to file for this fluid.
EXPORT_CODE long CONVENTION get_global_param_string(const char *param, char *Output)
void enable_TTSE_LUT(void)
void set_TTSESat_LUT_size(int Nsat)
Over-ride the default size of both of the saturation LUT.
TTSESinglePhaseTableClass TTSESinglePhase
Definition: FluidClass.h:228
EXPORT_CODE bool CONVENTION enable_TTSE_LUT_writing(const char *FluidName)
Enable the writing of TTSE tables to file for this fluid.
int set_mode(int mode)
Definition: TTSE.cpp:160
EXPORT_CODE long CONVENTION redirect_stdout(const char *file)
Definition: CoolPropDLL.cpp:13
EXPORT_CODE bool CONVENTION set_TTSESinglePhase_LUT_range(const char *FluidName, double hmin, double hmax, double pmin, double pmax)
Over-ride the default range of the single-phase LUT.
EXPORT_CODE double CONVENTION PropsS(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *Ref)
Definition: CoolPropDLL.cpp:35
EXPORT_CODE long CONVENTION get_param_index(const char *param)
void disable_TTSE_LUT_writing(void)
Disable the writing of TTSE tables to file.
EXPORT_CODE double CONVENTION PropsSI(const char *Output, const char *Name1, double Prop1, const char *Name2, double Prop2, const char *FluidName)
Definition: CoolPropDLL.cpp:73
EXPORT_CODE double CONVENTION fromSI(const char *input, double value, const char *new_system)
Definition: CoolPropDLL.cpp:91
void get_TTSESinglePhase_LUT_range(double *hmin, double *hmax, double *pmin, double *pmax)
Get the current range of the single-phase LUT.
EXPORT_CODE double CONVENTION Props(const char *Output, char Name1, double Prop1, char Name2, double Prop2, const char *Ref)
Definition: CoolPropDLL.cpp:40
EXPORT_CODE double CONVENTION DerivTerms(const char *Term, double T, double rho, const char *Ref)
Definition: CoolPropDLL.cpp:84
EXPORT_CODE double CONVENTION Props1(const char *FluidName, const char *Output)
Definition: CoolPropDLL.cpp:27
bool isenabled_TTSE_LUT(void)
Check if TTSE is enabled.
EXPORT_CODE long CONVENTION Phase_Trho(const char *Fluid, double T, double rho, char *Phase_str)
double convert_from_unit_system_to_SI(long iInput, double value, int old_system)
Definition: Units.cpp:5
void set_err_string(std::string error_string)
Definition: CoolProp.cpp:191
EXPORT_CODE long CONVENTION Phase_Tp(const char *Fluid, double T, double p, char *Phase_str)
EXPORT_CODE int CONVENTION set_reference_stateD(const char *Ref, double T, double rho, double h0, double s0)
Definition: CoolPropDLL.cpp:22
EXPORT_CODE bool CONVENTION set_TTSESinglePhase_LUT_size(const char *FluidName, int Np, int Nh)
Over-ride the default size of the single-phase LUT.
EXPORT_CODE bool CONVENTION disable_TTSE_LUT(const char *FluidName)
Disable the TTSE for this fluid.
void disable_TTSE_LUT(void)
Disable the TTSE.
EXPORT_CODE double CONVENTION K2F(double T)
Convert from Kelvin to degrees Fahrenheit (useful primarily for testing)
Definition: CoolPropDLL.cpp:78
EXPORT_CODE double CONVENTION toSI(const char *input, double value, const char *old_system)
Definition: CoolPropDLL.cpp:95
EXPORT_CODE bool CONVENTION isenabled_TTSE_LUT(const char *FluidName)
Check if TTSE is enabled.
bool ValidNumber(double x)
EXPORT_CODE long CONVENTION get_fluid_param_string(const char *fluid, const char *param, char *Output)
EXPORT_CODE bool CONVENTION get_TTSESinglePhase_LUT_range(const char *FluidName, double *hmin, double *hmax, double *pmin, double *pmax)
Get the current range of the single-phase LUT.
#define CONVENTION
Definition: CoolPropTools.h:34