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
CoolProp.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 "REFPROP.h"
9 
10 #if defined(__ISWINDOWS__)
11 #include <windows.h>
12 #else
13 #ifndef DBL_EPSILON
14  #include <limits>
15  #define DBL_EPSILON std::numeric_limits<double>::epsilon()
16 #endif
17 #endif
18 
19 #include <iostream>
20 #include <stdlib.h>
21 #include <vector>
22 #include <exception>
23 #include <stdio.h>
24 #include "string.h"
25 #include "FluidClass.h"
26 #include "CoolPropTools.h"
27 #include "CPExceptions.h"
28 #include "Brine.h"
29 #include "Solvers.h"
30 #include "CPState.h"
31 #include "IncompLiquid.h"
32 #include "TTSE.h"
33 #include "purefluids/R290.h"
34 #include "purefluids/R134a.h"
35 #include "AllFluids.h"
36 
38 double _CoolProp_Fluid_PropsSI(long iOutput, long iName1, double Value1, long iName2, double Value2, Fluid *pFluid);
39 double _PropsSI(std::string Output,std::string Name1, double Prop1, std::string Name2, double Prop2, std::string Ref);
40 double _Props1SI(std::string FluidName, std::string Output);
41 
42 static std::string err_string;
43 static std::string warning_string;
44 
45 static Fluid * pFluid;
46 
47 // This is very hacky, but pull the git revision from the file
48 #include "gitrevision.h" // Contents are like "long gitrevision = "aa121435436ggregrea4t43t433";"
49 #include "version.h" // Contents are like "char version [] = "2.5";"
50 
51 int global_Phase = -1;
52 bool global_SinglePhase = false;
53 bool global_SaturatedL = false;
54 bool global_SaturatedV = false;
55 
56 // Default to the KSI unit system
58 
59 void set_warning(std::string warning){ warning_string = warning; }
60 
62 void _set_standard_unit_system(int unit_sys){ unit_system = unit_sys; }
63 
64 // This is a map of all possible strings to a unique identifier
65 std::pair<std::string, long> map_data[] = {
66  std::make_pair("E",iPcrit),
67  std::make_pair("M",iMM),
68  std::make_pair("w",iAccentric),
69  std::make_pair("R",iTtriple),
70  std::make_pair("N",iRhocrit),
71  std::make_pair("B",iTcrit),
72 
73  std::make_pair("pcrit",iPcrit),
74  std::make_pair("PCRIT",iPcrit),
75  std::make_pair("molemass",iMM),
76  std::make_pair("MOLEMASS",iMM),
77  std::make_pair("accentric",iAccentric),
78  std::make_pair("ACCENTRIC",iAccentric),
79  std::make_pair("dipole",iDipole),
80  std::make_pair("DIPOLE",iDipole),
81  std::make_pair("Tmin",iTmin),
82  std::make_pair("TMIN",iTmin),
83  std::make_pair("t",iTmin),
84  std::make_pair("Tmax",iTmax),
85  std::make_pair("TMAX",iTmax),
86  std::make_pair("pmax",iPmax),
87  std::make_pair("PMAX",iPmax),
88  std::make_pair("Ttriple",iTtriple),
89  std::make_pair("TTRIPLE",iTtriple),
90  std::make_pair("ptriple",iPtriple),
91  std::make_pair("PTRIPLE",iPtriple),
92  std::make_pair("rhocrit",iRhocrit),
93  std::make_pair("RHOCRIT",iRhocrit),
94  std::make_pair("Tcrit",iTcrit),
95  std::make_pair("TCRIT",iTcrit),
96  std::make_pair("Treduce",iTreduce),
97  std::make_pair("TREDUCE",iTreduce),
98  std::make_pair("rhoreduce",iRhoreduce),
99  std::make_pair("RHOREDUCE",iRhoreduce),
100  std::make_pair("Hcrit",iHcrit),
101  std::make_pair("HCRIT",iHcrit),
102  std::make_pair("Scrit",iScrit),
103  std::make_pair("SCRIT",iScrit),
104 
105  std::make_pair("Q",iQ),
106  std::make_pair("T",iT),
107  std::make_pair("P",iP),
108  std::make_pair("D",iD),
109  std::make_pair("C",iC),
110  std::make_pair("C0",iC0),
111  std::make_pair("O",iO),
112  std::make_pair("U",iU),
113  std::make_pair("H",iH),
114  std::make_pair("S",iS),
115  std::make_pair("A",iA),
116  std::make_pair("G",iG),
117  std::make_pair("V",iV),
118  std::make_pair("L",iL),
119  std::make_pair("Prandtl",iPrandtl),
120  std::make_pair("PRANDTL",iPrandtl),
121  std::make_pair("Tmax",iTmax),
122  std::make_pair("Tfreeze",iTfreeze),
123  std::make_pair("Psat",iPsat),
124  std::make_pair("I",iI),
125  std::make_pair("SurfaceTension",iI),
126  std::make_pair("rhosatLanc",iRhosatLanc),
127  std::make_pair("rhosatVanc",iRhosatVanc),
128  std::make_pair("psatLanc",iPsatLanc),
129  std::make_pair("psatVanc",iPsatVanc),
130  std::make_pair("Phase",iPhase),
131  std::make_pair("PHASE_LIQUID",iPHASE_LIQUID),
132  std::make_pair("PHASE_GAS",iPHASE_GAS),
133  std::make_pair("PHASE_SUPERCRITICAL",iPHASE_SUPERCRITICAL),
134  std::make_pair("PHASE_TWOPHASE",iPHASE_TWOPHASE),
135  std::make_pair("ODP",iODP),
136  std::make_pair("GWP20",iGWP20),
137  std::make_pair("GWP100",iGWP100),
138  std::make_pair("GWP500",iGWP500),
139  std::make_pair("CritSplineT",iCritSplineT),
140  // Derivatives
141  std::make_pair("dhdp|rho",iDERdh_dp__rho),
142  std::make_pair("Z",iDERZ),
143  std::make_pair("dZ_dDelta",iDERdZ_dDelta),
144  std::make_pair("dZ_dTau",iDERdZ_dTau),
145  std::make_pair("VB",iDERB),
146  std::make_pair("dBdT",iDERdB_dT),
147  std::make_pair("VC",iDERC),
148  std::make_pair("dCdT",iDERdC_dT),
149  std::make_pair("phir",iDERphir),
150  std::make_pair("dphir_dTau",iDERdphir_dTau),
151  std::make_pair("dphir_dDelta",iDERdphir_dDelta),
152  std::make_pair("d2phir_dTau2",iDERd2phir_dTau2),
153  std::make_pair("d2phir_dDelta2",iDERd2phir_dDelta2),
154  std::make_pair("d2phir_dDelta_dTau",iDERd2phir_dDelta_dTau),
155  std::make_pair("d3phir_dDelta3",iDERd3phir_dDelta3),
156  std::make_pair("d3phir_dDelta2_dTau",iDERd3phir_dDelta2_dTau),
157  std::make_pair("d3phir_dDelta_dTau2",iDERd3phir_dDelta_dTau2),
158  std::make_pair("d3phir_dTau3",iDERd3phir_dTau3),
159  std::make_pair("phi0",iDERphi0),
160  std::make_pair("dphi0_dTau",iDERdphi0_dTau),
161  std::make_pair("d2phi0_dTau2",iDERd2phi0_dTau2),
162  std::make_pair("dphi0_dDelta",iDERdphi0_dDelta),
163  std::make_pair("d2phi0_dDelta2",iDERd2phi0_dDelta2),
164  std::make_pair("d2phi0_dDelta_dTau",iDERd2phi0_dDelta_dTau),
165  std::make_pair("d3phi0_dTau3",iDERd3phi0_dTau3),
166  std::make_pair("dpdT" ,iDERdp_dT__rho),
167  std::make_pair("dpdT|rho",iDERdp_dT__rho),
168  std::make_pair("dpdrho" ,iDERdp_drho__T),
169  std::make_pair("dpdrho|T",iDERdp_drho__T),
170  std::make_pair("dhdT|rho",iDERdh_dT__rho),
171  std::make_pair("dhdp|T",iDERdh_dp__T),
172  std::make_pair("DHDP|T",iDERdh_dp__T),
173  std::make_pair("dhdrho|T",iDERdh_drho__T),
174  std::make_pair("drhodT|p",iDERdrho_dT__p),
175  std::make_pair("drhodh|p",iDERdrho_dh__p),
176  std::make_pair("drhodp|h",iDERdrho_dp__h),
177  std::make_pair("rho_smoothed",iDERrho_smoothed),
178  std::make_pair("d(rho_smoothed)/dh",iDERdrho_smoothed_dh),
179  std::make_pair("d(rho_smoothed)/dp",iDERdrho_smoothed_dp),
180  std::make_pair("drhodh_constp_smoothed",iDERdrhodh_constp_smoothed),
181  std::make_pair("drhodp_consth_smoothed",iDERdrhodp_consth_smoothed),
182  std::make_pair("IsothermalCompressibility",iDERIsothermalCompressibility)
183 };
184 
185 //Now actually construct the map
186 std::map<std::string, long> param_map(map_data,
187  map_data + sizeof map_data / sizeof map_data[0]);
188 
190 
191 void set_err_string(std::string error_string)
192 {
193  err_string = error_string;
194 }
195 
196 void set_phase(std::string Phase_str){
197  if (!Phase_str.compare("Two-Phase")){
198  global_SinglePhase = false;
199  global_SaturatedL = false;
200  global_SaturatedV = false;
202  }
203  else if (!Phase_str.compare("Liquid")){
204  global_SinglePhase = true;
205  global_SaturatedL = false;
206  global_SaturatedV = false;
208  }
209  else if (!Phase_str.compare("Gas")){
210  global_SinglePhase = true;
211  global_SaturatedL = false;
212  global_SaturatedV = false;
213  global_Phase = iGas;
214  }
215  else if (!Phase_str.compare("Supercritical")){
216  global_SinglePhase = true;
217  global_SaturatedL = false;
218  global_SaturatedV = false;
220  }
221  else if (!Phase_str.compare("SaturatedL")){
222  global_SinglePhase = false;
223  global_SaturatedL = true;
224  global_SaturatedV = false;
226  }
227  else if (!Phase_str.compare("SaturatedV")){
228  global_SinglePhase = false;
229  global_SaturatedL = false;
230  global_SaturatedV = true;
232  }
233 }
234 
235 // Returns a pointer to the fluid class
236 Fluid* get_fluid(long iFluid){
237  return Fluids.get_fluid(iFluid);
238 }
239 long get_Fluid_index(std::string FluidName)
240 {
241  // Try to get the fluid from Fluids by name
242  pFluid = Fluids.get_fluid(FluidName);
243  // If NULL, didn't find it (or its alias)
244  if (pFluid!=NULL)
245  {
246  // Find the fluid index
247  return Fluids.get_fluid_index(pFluid);
248  }
249  else
250  return -1;
251 }
252 
253 bool add_REFPROP_fluid(std::string FluidName)
254 {
255  std::vector<double> x(100);
256  // Starts with REFPROP- keep going
257  if (!(FluidName.find("REFPROP-") == 0)) return false;
258  // Stop here if there is no REFPROP support
259  if (!REFPROPFluidClass::refpropSupported()) return false;
260  // Try to load this fluid, index >= 0 if already added
261  long iFluid = get_Fluid_index(FluidName);
262  // If not added yet, and a valid fluid, then continue
263  if (iFluid < 0 && set_REFPROP_fluid(FluidName, x)) // If you can set the fluid, it's a valid fluid
264  {
265  Fluids.add_REFPROP_fluid(FluidName,std::vector<double>(1,1));
266  if (get_debug_level() > 0)
267  {
268  std::cout << format("%s:%d: Added the fluid %s\n",__FILE__,__LINE__,FluidName.c_str()).c_str();
269  }
270  return true;
271  }
272  return true;
273 }
274 
275 std::string get_ASHRAE34(std::string fluid)
276 {
277  long iFluid = get_Fluid_index(fluid);
278  if (iFluid > -1)
279  {
280  Fluid *pFluid = get_fluid(iFluid);
281  return pFluid->environment.ASHRAE34;
282  }
283  else
284  {
285  return "Fluid name invalid";
286  }
287 }
288 long get_param_index(std::string param)
289 {
290  std::map<std::string,long>::iterator it;
291  // Try to find using the map
292  it = param_map.find(param);
293  // If it is found the iterator will not be equal to end
294  if (it != param_map.end() )
295  {
296  // Return the index of the parameter
297  return (*it).second;
298  }
299  else
300  {
301  return -1;
302  }
303 }
304 
305 static int IsCoolPropFluid(std::string FluidName)
306 {
307  // Try to get the fluid from Fluids by name
308  try
309  {
310  pFluid = Fluids.get_fluid(FluidName);
311  }
312  catch (NotImplementedError &)
313  {
314  return false;
315  }
316  // If NULL, didn't find it (or its alias)
317  if (pFluid!=NULL)
318  {
319  return true;
320  }
321  else
322  return false;
323 }
324 
325 static int IsBrine(const char* Ref)
326 {
327  // First check whether it is one of the Brines that does
328  // not have a pure-fluid equivalent in CoolProp
329  if (
330  strcmp(Ref,"HC-10")==0 ||
331  strncmp(Ref,"PG-",3)==0 ||
332  strncmp(Ref,"EG-",3)==0 ||
333  strncmp(Ref,"EA-",3)==0 ||
334  strncmp(Ref,"MA-",3)==0 ||
335  strncmp(Ref,"Glycerol-",9)==0 ||
336  strncmp(Ref,"K2CO3-",6)==0 ||
337  strncmp(Ref,"CaCl2-",6)==0 ||
338  strncmp(Ref,"MgCl2-",6)==0 ||
339  strncmp(Ref,"NaCl-",5)==0 ||
340  strncmp(Ref,"KAC-",4)==0 ||
341  strncmp(Ref,"KFO-",4)==0 ||
342  strncmp(Ref,"LiCl-",4)==0 ||
343  strncmp(Ref,"NH3/H2O-",8)==0
344  )
345  {
346  return 1;
347  }
348  // Then check for diluants that are also pure fluids in CoolProp
349  else if ( (strncmp(Ref,"Methanol-",9)==0 && Ref[8] == '-') ||
350  (strncmp(Ref,"Ethanol-",8)==0 && Ref[7] == '-') ||
351  (strncmp(Ref,"NH3-",4)==0 && Ref[3] == '-')
352  )
353  {
354  return 1;
355  }
356  else
357  {
358  return 0;
359  }
360 }
361 static int IsREFPROP(std::string Ref)
362 {
363  if (!Ref.compare(0,8,"REFPROP-"))
364  return 1;
365  else
366  return 0;
367 }
368 
369 long getFluidType(std::string FluidName){
370  if (IsREFPROP(FluidName)) { return FLUID_TYPE_REFPROP;}
371  else if(IsIncompressibleLiquid(FluidName)){ return FLUID_TYPE_INCOMPRESSIBLE_LIQUID;}
372  // TODO SOLUTION: Check if working
373  else if(IsIncompressibleSolution(FluidName)){ return FLUID_TYPE_INCOMPRESSIBLE_SOLUTION; }
374  else {
375  // Try to get the index of the fluid
376  long iFluid = get_Fluid_index(FluidName);
377  // If iFluid is greater than -1, it is a CoolProp Fluid, otherwise not
378  if (iFluid > -1) {
379  // Get a pointer to the fluid object
380  pFluid = get_fluid(iFluid);
381  if (pFluid->pure()) { return FLUID_TYPE_PURE;}
382  else { return FLUID_TYPE_PSEUDOPURE; }
383  } else {
384  throw ValueError(format("Bad Fluid name [%s] - not a CoolProp fluid",FluidName.c_str()));
385  }
386  }
387  return -1;
388 }
389 
390 EXPORT_CODE int CONVENTION IsFluidType(const char *Ref, const char *Type)
391 {
392  pFluid = Fluids.get_fluid(Ref);
393 
394  if (IsBrine(Ref)){ // TODO Solution: Remove this part
395  if (!strcmp(Type,"Brine")){
396  return 1;
397  }
398  else{
399  return 0;
400  }
401  }
402  else if (IsIncompressibleSolution(Ref)){
403  if (!strcmp(Type,"Solution")){
404  return 1;
405  }
406  else{
407  return 0;
408  }
409  }
410  else if (IsIncompressibleLiquid(Ref)){
411  if (!strcmp(Type,"Liquid")){
412  return 1;
413  }
414  else{
415  return 0;
416  }
417  }
418  else if (IsREFPROP(Ref)){
419  if (!strcmp(Type,"PureFluid")){
420  return 1;
421  }
422  else{
423  return 0;
424  }
425  }
426  else if (!pFluid->pure()){
427  if (!strcmp(Type,"PseudoPure") || !strcmp(Type,"PseudoPureFluid")){
428  return 1;
429  }
430  else{
431  return 0;
432  }
433  }
434  else if (pFluid->pure()){
435  if (!strcmp(Type,"PureFluid")){
436  return 1;
437  }
438  else{
439  return 0;
440  }
441  }
442  else
443  {
444  return 0;
445  }
446 }
447 
448 double _T_hp_secant(std::string Ref, double h, double p, double T_guess)
449 {
450  double x1=0,x2=0,x3=0,y1=0,y2=0,eps=1e-8,change=999,f=999,T=300;
451  int iter=1;
452 
453  while ((iter<=3 || fabs(f)>eps) && iter<100)
454  {
455  if (iter==1){x1=T_guess; T=x1;}
456  if (iter==2){x2=T_guess+0.1; T=x2;}
457  if (iter>2) {T=x2;}
458  f=PropsSI("H","T",T,"P",p,Ref)-h;
459  if (iter==1){y1=f;}
460  if (iter>1)
461  {
462  y2=f;
463  x3=x2-y2/(y2-y1)*(x2-x1);
464  change=fabs(y2/(y2-y1)*(x2-x1));
465  y1=y2; x1=x2; x2=x3;
466  }
467  iter=iter+1;
468  if (iter>100)
469  {
470  throw SolutionError(format("iter %d: T_hp not converging with inputs(%s,%g,%g,%g) value: %0.12g\n",iter,(char*)Ref.c_str(),h,p,T_guess,f));
471  }
472  }
473  return T;
474 }
475 
476 std::string Phase_Trho(std::string Fluid, double T, double rho)
477 {
478  try{
479  // Try to load the CoolProp Fluid
480  pFluid = Fluids.get_fluid(Fluid);
481  double pL,pV,rhoL,rhoV;
482  return pFluid->phase_Trho(T,rho, pL, pV, rhoL, rhoV);
483  }
484  catch(NotImplementedError &){
485  return std::string("");
486  }
487  return std::string("");
488 }
489 
490 std::string Phase(std::string Fluid, double T, double p)
491 {
492  try{
493  // Try to load the CoolProp Fluid
494  pFluid = Fluids.get_fluid(Fluid);
495  double pL,pV,rhoL,rhoV;
496  return pFluid->phase_Tp(T, p, pL, pV, rhoL, rhoV);
497  }
498  catch(NotImplementedError &){
499  return std::string("");
500  }
501  return std::string("");
502 }
503 
504 std::string Phase_Tp(std::string Fluid, double T, double p)
505 {
506  return Phase(Fluid,T,p);
507 }
508 
509 /*
510  * Start with the internal functions to handle different inputs
511  * First we handle the constants: Props1
512  */
513 // Internal one to do the actual calculations
514 double _Props1SI(std::string FluidName, std::string Output)
515 {
516  double out = _HUGE;
517  // Try to load the CoolProp Fluid
518  pFluid = Fluids.get_fluid(FluidName);
519  if (pFluid != NULL)
520  {
521  // It's a CoolProp fluid
522  // Convert the parameter to integer
523  long iOutput = get_param_index(Output);
524  if (iOutput < 0){
525  throw ValueError(format("Your output key [%s] is not valid. (names are case sensitive)",Output.c_str()));
526  }
527  // Get the output using the conventional function
528  return _CoolProp_Fluid_PropsSI(iOutput,0,0,0,0,pFluid);
529  }
530  else if (IsREFPROP(FluidName))
531  {
532  // REFPROP fluid
533  long iOutput = get_param_index(Output);
534  switch (iOutput)
535  {
536  case iTtriple:
537  case iTcrit:
538  case iPcrit:
539  case iTmin:
540  case iMM:
541  case iRhocrit:
542  case iAccentric:
543  out = Props(Output,'T',0,'P',0,FluidName);
544  break;
545  default:
546  throw ValueError(format("Output parameter \"%s\" is invalid for REFPROP fluid",Output.c_str()));
547  }
549  }
550  else
551  {
552  throw ValueError(format("Fluid \"%s\" is an invalid fluid",FluidName.c_str()));
553  }
554  return -_HUGE;
555 }
556 double _Props1(std::string FluidName, std::string Output)
557 {
558  double val = _Props1SI(FluidName, Output);
559  if (ValidNumber(val))
560  {
561  long iOutput = get_param_index(Output);
563  }
564  else
565  {
566  return _HUGE;
567  }
568 }
569 // Define the functions from the header file
570 double Props1SI(std::string FluidName,std::string Output){
571  // Redirect to the Props() function that takes const char *
572  // In this function the error catching happens;
573  try{
574  return _Props1SI(FluidName, Output);
575  }
576  catch(const std::exception& e){
577  err_string = std::string("CoolProp error: ").append(e.what());
578  return _HUGE;
579  }
580  catch(...){
581  err_string = std::string("CoolProp error: Indeterminate error");
582  return _HUGE;
583  }
584  return _HUGE;
585 }
586 double Props1(std::string FluidName, std::string Output){
587 
588  // Redirect to the Props() function that takes const char *
589  // In this function the error catching happens;
590  try{
591  return _Props1(FluidName, Output);
592  }
593  catch(const std::exception& e){
594  err_string = std::string("CoolProp error: ").append(e.what());
595  return _HUGE;
596  }
597  catch(...){
598  err_string = std::string("CoolProp error: Indeterminate error");
599  return _HUGE;
600  }
601  return _HUGE;
602 }
603 
604 
605 
606 
607 /*
608  * Now we need an internal functions to handle different
609  * inputs for non-constant values: Props
610  */
611 // Internal one to do the actual calculations, make this a wrapped function so
612 // that error bubbling can be done properly
613 double _PropsSI(std::string Output, std::string Name1, double Prop1, std::string Name2, double Prop2, std::string Ref)
614 {
615  if (get_debug_level()>5){
616  std::cout << format("%s:%d: _Props(%s,%s,%g,%s,%g,%s)\n",__FILE__,__LINE__,Output.c_str(),Name1.c_str(),Prop1,Name2.c_str(),Prop2,Ref.c_str()).c_str();
617  }
618 
619  // Convert all the input and output parameters to integers
620  long iOutput = get_param_index(Output);
621  if (iOutput<0)
622  throw ValueError(format("Your output key [%s] is not valid. (names are case sensitive)",Output.c_str()));
623  long iName1 = get_param_index(std::string(Name1));
624  if (iName1<0)
625  throw ValueError(format("Your input key #1 [%s] is not valid. (names are case sensitive)",Name1.c_str()));
626  long iName2 = get_param_index(std::string(Name2));
627  if (iName2<0)
628  throw ValueError(format("Your input key #2 [%s] is not valid. (names are case sensitive)",Name2.c_str()));
629 
630  /*if (iOutput == iName1)
631  throw ValueError(format("Input parameter #1 [%s] cannot be the same as the output",Name1.c_str()));
632  if (iOutput == iName2)
633  throw ValueError(format("Input parameter #2 [%s] cannot be the same as the output",Name2.c_str()));*/
634 
635  /*
636  If the fluid name is not actually a refrigerant name, but a string beginning with "REFPROP-",
637  then REFPROP is used to calculate the desired property.
638  */
639  if (IsREFPROP(Ref)) // First eight characters match "REFPROP-"
640  {
641  if (get_debug_level()>7) std::cout<<__FILE__<<": Identified Refprop fluid - "<<Ref.c_str()<<std::endl;
642  // Stop here if there is no REFPROP support
644  return REFPROPSI(iOutput,iName1,Prop1,iName2,Prop2,Ref);
645  } else {
646  throw AttributeError(format("Your fluid [%s] is from REFPROP, but CoolProp does not support REFPROP on this platform, yet.",Ref.c_str()));
647  return -_HUGE;
648  }
649  }
650  else if (IsCoolPropFluid(Ref))
651  {
652  if (get_debug_level()>7) std::cout << format("%s:%d: Identified CoolProp fluid - %s\n",__FILE__,__LINE__,Ref.c_str()).c_str();
653  pFluid = Fluids.get_fluid(Ref);
654  // Call the internal method that uses the parameters converted to longs
655  return _CoolProp_Fluid_PropsSI(iOutput,iName1,Prop1,iName2,Prop2,pFluid);
656  }
657  // It's a brine, call the brine routine // TODO Solutions: remove this part
658  else if (IsBrine(Ref.c_str()))
659  {
660  if (get_debug_level()>7) std::cout<<__FILE__<<": Identified brine - "<<Ref.c_str()<<std::endl;
661  //Enthalpy and pressure are the inputs
662  if ((iName1 == iH && iName2 == iP) || (iName2 == iH && iName1 == iP))
663  {
664  if (iName2 == iH && iName1 == iP)
665  {
666  std::swap(Prop1,Prop2);
667  std::swap(Name1,Name2);
668  }
669  // Start with a guess of 10 K below max temp of fluid
670  double Tguess = SecFluids("Tmax",Prop1,Prop2,Ref)-10;
671  // Solve for the temperature
672  double T =_T_hp_secant(Ref,Prop1,Prop2,Tguess);
673  // Return whatever property is desired
674  return SecFluidsSI(Output,T,Prop2,Ref);
675  }
676  else if ((iName1 == iT && iName2 == iP) || (iName1 == iP && iName2 == iT))
677  {
678  if (iName1 == iP && iName2 == iT){
679  std::swap(Prop1,Prop2);
680  }
681  return SecFluidsSI(Output,Prop1,Prop2,Ref);
682  }
683  else
684  {
685  throw ValueError("For brine, inputs must be (order does not matter) 'T' and 'P', or 'H' and 'P'");
686  }
687  }
688  // It's an incompressible liquid, call the routine
689  else if (IsIncompressibleLiquid(Ref))
690  {
691  if (get_debug_level()>7) std::cout<<__FILE__<<": Identified incompressible liquid - "<<Ref.c_str()<<std::endl;
692  //Enthalpy and pressure are the inputs
693  if ((iName1 == iH && iName2 == iP) || (iName2 == iH && iName1 == iP))
694  {
695  if (iName2 == iH && iName1 == iP)
696  {
697  std::swap(Prop1,Prop2);
698  std::swap(Name1,Name2);
699  }
700 
701  // Solve for the temperature
702  double Tma = IncompLiquidSI(get_param_index("Tmax"),0.0,0.0,Ref);
703  double T_guess = Tma - 10.0 ;
704  double T =_T_hp_secant(Ref,Prop1,Prop2,T_guess);
705  // Return whatever property is desired
706  return IncompLiquidSI(iOutput,T,Prop2,Ref);
707  }
708  else if ((iName1 == iT && iName2 == iP) || (iName1 == iP && iName2 == iT))
709  {
710  if (iName1 == iP && iName2 == iT){
711  std::swap(Prop1, Prop2);
712  }
713  return IncompLiquidSI(iOutput,Prop1,Prop2,Ref);
714  }
715  else
716  {
717  throw ValueError("For incompressible fluids, inputs must be (order does not matter) 'T' and 'P', or 'H' and 'P'");
718  }
719  }
720  // It's an incompressible solution, call the routine
721  else if (IsIncompressibleSolution(Ref))
722  {
723  if (get_debug_level()>7) std::cout<<__FILE__<<": Identified incompressible solution - "<<Ref.c_str()<<std::endl;
724  //Enthalpy and pressure are the inputs
725  if ((iName1 == iH && iName2 == iP) || (iName2 == iH && iName1 == iP))
726  {
727  if (iName2 == iH && iName1 == iP)
728  {
729  std::swap(Prop1,Prop2);
730  std::swap(Name1,Name2);
731  }
732 
733  // Solve for the temperature
734  double Tma = IncompSolutionSI(get_param_index("Tmax"),0.0,0.0,Ref);
735  double Tmi = IncompSolutionSI(get_param_index("Tmin"),0.0,0.0,Ref);
736  double T_guess = (Tma+Tmi)/2.0 ;
737  double T =_T_hp_secant(Ref,Prop1,Prop2,T_guess);
738  // Return whatever property is desired
739  return IncompSolutionSI(iOutput,T,Prop2,Ref);
740  }
741  else if ((iName1 == iT && iName2 == iP) || (iName1 == iP && iName2 == iT))
742  {
743  if (iName1 == iP && iName2 == iT){
744  std::swap(Prop1,Prop2);
745  }
746  return IncompSolutionSI(iOutput,Prop1,Prop2,Ref);
747  }
748  else
749  {
750  throw ValueError("For incompressible solutions, inputs must be (order does not matter) 'T' and 'P', or 'H' and 'P'");
751  }
752  }
753  else
754  {
755  throw ValueError(format("Your fluid name [%s] is not a CoolProp fluid, a REFPROP fluid, a brine or a liquid",Ref.c_str()));
756  }
757 }
758 EXPORT_CODE double CONVENTION IProps(long iOutput, long iName1, double Prop1, long iName2, double Prop2, long iFluid)
759 {
762  double out = IPropsSI(iOutput,iName1,Prop1,iName2,Prop2,iFluid);
764 }
765 double _CoolProp_Fluid_PropsSI(long iOutput, long iName1, double Prop1, long iName2, double Prop2, Fluid *pFluid)
766 {
767  double val = _HUGE, T = _HUGE;
768  // This private method uses the indices directly for speed
769 
770  if (get_debug_level()>3){
771  std::cout << format("%s:%d: _CoolProp_Fluid_PropsSI(%d,%d,%g,%d,%g,%s)\n",__FILE__,__LINE__,iOutput,iName1, Prop1, iName2, Prop2, pFluid->get_name().c_str()).c_str();
772  }
773  if (iName1 == iT){
774  T = Prop1;}
775  else if (iName2 == iT){
776  T = Prop2;}
777 
778  // Generate a State instance wrapped around the Fluid instance
779  CoolPropStateClassSI CPS(pFluid);
780 
781  // Check if it is an output that doesn't require a state input
782  // Deal with it and return
783  switch (iOutput)
784  {
785  case iI:
786  {
787  if (!ValidNumber(T)){throw ValueError(format("T must be provided as an input to use this output").c_str());}
788  return CPS.pFluid->surface_tension_T(T);
789  }
790  case iRhosatLanc:
791  {
792  if (!ValidNumber(T)){throw ValueError(format("T must be provided as an input to use this output").c_str());}
793  return CPS.pFluid->rhosatL(T);
794  }
795  case iRhosatVanc:
796  {
797  if (!ValidNumber(T)){throw ValueError(format("T must be provided as an input to use this output").c_str());}
798  return CPS.pFluid->rhosatV(T);
799  }
800  case iPsatLanc:
801  {
802  if (!ValidNumber(T)){throw ValueError(format("T must be provided as an input to use this output").c_str());}
803  if (CPS.pFluid->pure()){
804  return CPS.pFluid->psat(T);
805  }
806  else{
807  return CPS.pFluid->psatL(T);
808  }
809  }
810  case iPsatVanc:
811  {
812  if (!ValidNumber(T)){throw ValueError(format("T must be provided as an input to use this output").c_str());}
813  if (CPS.pFluid->pure()){
814  return CPS.pFluid->psat(T);
815  }
816  else{
817  return CPS.pFluid->psatV(T);
818  }
819  }
820  case iMM:
821  case iPcrit:
822  case iTcrit:
823  case iTtriple:
824  case iPtriple:
825  case iPmax:
826  case iTmax:
827  case iRhocrit:
828  case iTmin:
829  case iAccentric:
830  case iPHASE_LIQUID:
831  case iPHASE_GAS:
833  case iPHASE_TWOPHASE:
834  case iGWP20:
835  case iGWP100:
836  case iGWP500:
837  case iODP:
838  case iCritSplineT:
839  case iScrit:
840  case iHcrit:
841  case iTreduce:
842  case iRhoreduce:
843  return CPS.keyed_output(iOutput);
844  }
845 
846  // Update the class
847  CPS.update(iName1,Prop1,iName2,Prop2);
848 
849  // Debug
850  if (get_debug_level()>9){std::cout << format("%s:%d: State update successful\n",__FILE__,__LINE__).c_str();}
851 
852  // Get the output
853  val = CPS.keyed_output(iOutput);
854 
855  // Debug
856  if (get_debug_level()>5){std::cout << format("%s:%d: _CoolProp_Fluid_PropsSI returns: %g\n",__FILE__,__LINE__,val).c_str();}
857 
858  // Return the value
859  return val;
860 }
861 EXPORT_CODE double CONVENTION IPropsSI(long iOutput, long iName1, double Prop1, long iName2, double Prop2, long iFluid)
862 {
863  pFluid = Fluids.get_fluid(iFluid);
864  // Didn't work
865  if (pFluid == NULL){
866  err_string=std::string("CoolProp error: ").append(format("%d is an invalid fluid index to IProps",iFluid));
867  return _HUGE;
868  }
869  else{
870  // In this function the error catching happens;
871  try{
872  // This is already converted to the right units since we take in SI units
873  return _CoolProp_Fluid_PropsSI(iOutput,iName1,Prop1,iName2,Prop2,pFluid);
874  }
875  catch(std::exception &e){
876  err_string=std::string("CoolProp error: ").append(e.what());
877  return _HUGE;
878  }
879  catch(...){
880  err_string=std::string("CoolProp error: Indeterminate error");
881  return _HUGE;
882  }
883  }
884 }
885 
886 double PropsSI(std::string Output, std::string Name1, double Prop1, std::string Name2, double Prop2, std::string Ref)
887 {
888  // In this function the error catching happens;
889  try{
890  return _PropsSI(Output,Name1,Prop1,Name2,Prop2,Ref);
891  }
892  catch(const std::exception& e){
893  set_err_string(std::string("CoolProp error: ").append(e.what()));
894  return _HUGE;
895  }
896  catch(...){
897  set_err_string(std::string("CoolProp error: Indeterminate error"));
898  return _HUGE;
899  }
900  return _HUGE;
901 }
902 double Props(std::string Output, std::string Name1, double Prop1, std::string Name2, double Prop2, std::string Ref)
903 {
904  // Go to the std::string version
905  return PropsS(Output.c_str(),Name1.c_str(),Prop1,Name2.c_str(),Prop2,Ref.c_str());
906 }
907 double Props(std::string Output,char Name1, double Prop1, char Name2, double Prop2, std::string Ref)
908 {
909  return Props(Output, std::string(1,Name1), Prop1, std::string(1,Name2), Prop2, Ref);
910 }
911 
913 double _CoolProp_Deriv_Terms(long iTerm, double T, double rho, Fluid * pFluid)
914 {
915  double val = _HUGE;
916  // This private method uses the indices directly for speed
917 
918  if (get_debug_level()>3){
919  std::cout<<__FILE__<<" _CoolProp_Deriv_Terms return: "<<val<<std::endl;
920  }
921 
922  switch (iTerm) {
923  case iDERdh_dp__rho:
924  case iDERdh_dp__v:
925  case iDERZ:
926  case iDERdZ_dDelta:
927  case iDERdZ_dTau:
928  case iDERB:
929  case iDERdB_dT:
930  case iDERC:
931  case iDERdC_dT:
932  case iDERphir:
933  case iDERdphir_dTau:
934  case iDERdphir_dDelta:
935  case iDERd2phir_dTau2:
936  case iDERd2phir_dDelta2:
938  case iDERd3phir_dDelta3:
941  case iDERd3phir_dTau3:
942  case iDERphi0:
943  case iDERdphi0_dTau:
944  case iDERd2phi0_dTau2:
945  case iDERdphi0_dDelta:
946  case iDERd2phi0_dDelta2:
948  case iDERd3phi0_dTau3:
949  case iDERdp_dT__rho:
950  case iDERdp_drho__T:
951  case iDERdh_dT__rho:
952  case iDERdh_drho__T:
953  case iDERdrho_dT__p:
954  case iDERdrho_dh__p:
955  case iDERdrho_dp__h:
956  {
957  // Generate a State instance wrapped around the Fluid instance
958  CoolPropStateClass CPS(pFluid);
959 
960  // Force the update to consider the inputs as single-phase inputs
961  CPS.flag_SinglePhase = true;
962 
963  // Update the class
964  CPS.update(iT,T,iD,rho);
965 
966  // Get the output value
967  val = CPS.keyed_output(iTerm);
968  break;
969  }
970 
971  case iDERrho_smoothed:
977  {
978  // Generate a State instance wrapped around the Fluid instance
979  CoolPropStateClass CPS(pFluid);
980 
981  // Update the class
982  CPS.update(iT,T,iD,rho);
983 
984  // Get the output value
985  val = CPS.keyed_output(iTerm);
986  break;
987  }
988 
989  default:
990  throw ValueError(format("Sorry DerivTerms is a work in progress, your derivative term [%d] is not available!",iTerm));
991  }
992 
993  if (get_debug_level()>5){
994  std::cout<<__FILE__<<" _CoolProp_Deriv_Terms return: "<<val<<std::endl;
995  }
996  // Return the value
997  return val;
998 }
999 
1000 // Define the functions from the header
1001 double DerivTerms(long iTerm, double T, double rho, Fluid * pFluid){
1002  return _CoolProp_Deriv_Terms(iTerm,T,rho,pFluid);
1003 }
1004 double DerivTerms(std::string Term, double T, double rho, std::string Fluidname){
1005  if (get_debug_level()>5){
1006  std::cout<<__FILE__<<": "<<Term.c_str()<<",T="<<T<<",rho="<<rho<<","<<Fluidname.c_str()<<std::endl;
1007  }
1008  /*
1009  Derivatives are only supported for CoolProp fluids
1010  */
1011  if (IsCoolPropFluid(Fluidname))
1012  {
1013  pFluid = Fluids.get_fluid(Fluidname);
1014  // for compatibility, replace B and C with VB and VC
1015  if ((!Term.compare("B")) || (!Term.compare("C"))) {
1016  Term = std::string("V").append(Term);
1017  }
1018  // Convert all the parameters to integers
1019  long iOutput = get_param_index(Term);
1020  if (iOutput<0)
1021  throw ValueError(format("Your output key [%s] is not valid. (names are case sensitive)",Term.c_str()));
1022 
1023  if (T<=0)
1024  throw ValueError(format("Your input temperature [%f] is not valid.",T));
1025 
1026  if (rho<=0)
1027  throw ValueError(format("Your input density [%f] is not valid.",rho));
1028  // Call the internal method that uses the parameters converted to longs
1029  return _CoolProp_Deriv_Terms(iOutput,T,rho,pFluid);
1030  }
1031  else
1032  {
1033  throw ValueError(format("Your fluid name [%s] is not a CoolProp fluid.",Fluidname.c_str()));
1034  }
1035 }
1036 
1037 int set_reference_stateS(std::string Ref, std::string reference_state)
1038 {
1039  Fluid *pFluid=Fluids.get_fluid(Ref);
1040  if (pFluid!=NULL)
1041  {
1042  return set_reference_stateP(pFluid, reference_state);
1043  }
1044  else{
1045  return -1;
1046  }
1047 }
1048 
1049 int set_reference_stateP(Fluid *pFluid, std::string reference_state)
1050 {
1051  CoolPropStateClassSI CPS(pFluid);
1052  if (!reference_state.compare("IIR"))
1053  {
1054  CoolPropStateClassSI CPS(pFluid);
1055  CPS.update(iT,273.15,iQ,0);
1056  // Get current values for the enthalpy and entropy
1057  double h1 = CPS.h();
1058  double s1 = CPS.s();
1059  double deltah = h1-200000; // offset from 200 kJ/kg enthalpy
1060  double deltas = s1-1000; // offset from 1 kJ/kg/K entropy
1061  double delta_a1 = deltas/((8314.472/pFluid->params.molemass));
1062  double delta_a2 = -deltah/((8314.472/pFluid->params.molemass)*pFluid->reduce.T);
1063  pFluid->phi0list.push_back(new phi0_enthalpy_entropy_offset(delta_a1, delta_a2));
1064  return 0;
1065  }
1066  else if (!reference_state.compare("ASHRAE"))
1067  {
1068  CoolPropStateClassSI CPS(pFluid);
1069  CPS.update(iT,233.15,iQ,0);
1070  // Get current values for the enthalpy and entropy
1071  double h1 = CPS.h();
1072  double s1 = CPS.s();
1073  double deltah = h1-0; // offset from 0 kJ/kg enthalpy
1074  double deltas = s1-0; // offset from 0 kJ/kg/K entropy
1075  double delta_a1 = deltas/((8314.472/pFluid->params.molemass));
1076  double delta_a2 = -deltah/((8314.472/pFluid->params.molemass)*pFluid->reduce.T);
1077  pFluid->phi0list.push_back(new phi0_enthalpy_entropy_offset(delta_a1, delta_a2));
1078  return 0;
1079  }
1080  else if (!reference_state.compare("NBP"))
1081  {
1082  CoolPropStateClassSI CPS(pFluid);
1083  CPS.update(iP,101325.0,iQ,0); // Saturated boiling point at 1 atmosphere
1084  // Get current values for the enthalpy and entropy
1085  double h1 = CPS.h();
1086  double s1 = CPS.s();
1087  double deltah = h1-0; // offset from 0 kJ/kg enthalpy
1088  double deltas = s1-0; // offset from 0 kJ/kg/K entropy
1089  double delta_a1 = deltas/((8314.472/pFluid->params.molemass));
1090  double delta_a2 = -deltah/((8314.472/pFluid->params.molemass)*pFluid->reduce.T);
1091  pFluid->phi0list.push_back(new phi0_enthalpy_entropy_offset(delta_a1, delta_a2));
1092  return 0;
1093  }
1094  else
1095  {
1096  return -1;
1097  }
1098 
1099 }
1100 int set_reference_stateD(std::string Ref, double T, double rho, double h0, double s0)
1101 {
1102  pFluid=Fluids.get_fluid(Ref);
1103  if (pFluid!=NULL)
1104  {
1105  CoolPropStateClassSI CPS(pFluid);
1106  CPS.update(iT,T,iD,rho);
1107  // Get current values for the enthalpy and entropy
1108  double h1 = CPS.h();
1109  double s1 = CPS.s();
1110  double deltah = h1-h0; // offset from given enthalpy in SI units
1111  double deltas = s1-s0; // offset from given enthalpy in SI units
1112  double delta_a1 = deltas/((8314.472/pFluid->params.molemass));
1113  double delta_a2 = -deltah/((8314.472/pFluid->params.molemass)*pFluid->reduce.T);
1114  pFluid->phi0list.push_back(new phi0_enthalpy_entropy_offset(delta_a1, delta_a2));
1115  return 0;
1116  }
1117  else{
1118  return -1;
1119  }
1120 }
1121 
1122 std::string get_BibTeXKey(std::string Ref, std::string item)
1123 {
1124  pFluid=Fluids.get_fluid(Ref);
1125  if (pFluid!=NULL)
1126  {
1127 
1128  if (!item.compare("EOS")){ return pFluid->BibTeXKeys.EOS; }
1129  else if (!item.compare("CP0")){ return pFluid->BibTeXKeys.CP0; }
1130  else if (!item.compare("VISCOSITY")){ return pFluid->BibTeXKeys.VISCOSITY; }
1131  else if (!item.compare("CONDUCTIVITY")){ return pFluid->BibTeXKeys.CONDUCTIVITY; }
1132  else if (!item.compare("ECS_LENNARD_JONES")){ return pFluid->BibTeXKeys.ECS_LENNARD_JONES; }
1133  else if (!item.compare("ECS_FITS")){ return pFluid->BibTeXKeys.ECS_FITS; }
1134  else if (!item.compare("SURFACE_TENSION")){ return pFluid->BibTeXKeys.SURFACE_TENSION; }
1135  else{ return "Bad key";}
1136  }
1137  else{
1138  return std::string("");
1139  }
1140 }
1141 
1142 std::string get_global_param_string(std::string ParamName)
1143 {
1144  if (!ParamName.compare("version"))
1145  {
1146  return std::string(version);
1147  }
1148  else if (!ParamName.compare("errstring"))
1149  {
1150  std::string temp = err_string;
1151  err_string = std::string("");
1152  return temp;
1153  }
1154  else if (!ParamName.compare("warnstring"))
1155  {
1156  std::string temp = warning_string;
1157  warning_string = std::string("");
1158  return temp;
1159  }
1160  else if (!ParamName.compare("gitrevision"))
1161  {
1162  return gitrevision;
1163  }
1164  else if (!ParamName.compare("FluidsList") || !ParamName.compare("fluids_list"))
1165  {
1166  return Fluids.FluidList();
1167  }
1168  else
1169  {
1170  return format("Input value [%s] is invalid",ParamName.c_str()).c_str();
1171  }
1172 };
1173 std::string get_fluid_param_string(std::string FluidName, std::string ParamName)
1174 {
1175  try{
1176  pFluid = Fluids.get_fluid(FluidName);
1177  // Didn't work
1178  if (pFluid == NULL){
1179  err_string=std::string("CoolProp error: ").append(format("%s is an invalid fluid for get_fluid_param_string",FluidName.c_str()));
1180  return format("%s is an invalid fluid for get_fluid_param_string",FluidName.c_str()).c_str();
1181  }
1182  else{
1183  if (!ParamName.compare("aliases"))
1184  {
1185  std::vector<std::string> v = pFluid->get_aliases();
1186  return strjoin(v,", ");
1187  }
1188  else if (!ParamName.compare("CAS") || !ParamName.compare("CAS_number"))
1189  {
1190  return pFluid->params.CAS;
1191  }
1192  else if (!ParamName.compare("ASHRAE34"))
1193  {
1194  return pFluid->environment.ASHRAE34;
1195  }
1196  else if (!ParamName.compare("REFPROPName") || !ParamName.compare("REFPROP_name") || !ParamName.compare("REFPROPname"))
1197  {
1198  return pFluid->get_REFPROPname();
1199  }
1200  else if (!ParamName.compare("TTSE_mode"))
1201  {
1202  int mode = pFluid->TTSESinglePhase.get_mode();
1203  switch (mode)
1204  {
1205  case TTSE_MODE_TTSE:
1206  return "TTSE";
1207  case TTSE_MODE_BICUBIC:
1208  return "BICUBIC";
1209  default:
1210  throw ValueError("TTSE mode is invalid");
1211  }
1212  }
1213  else
1214  {
1215  return format("Input value [%s] is invalid for Fluid [%s]",ParamName.c_str(),FluidName.c_str()).c_str();
1216  }
1217  }
1218  }
1219  catch(std::exception &e)
1220  {
1221  return(std::string("CoolProp error: ").append(e.what()));
1222  }
1223  catch(...){
1224  return(std::string("CoolProp error: Indeterminate error"));
1225  }
1226 }
1227 
1228 
1229 #ifndef DISABLE_CATCH
1230 #include "Catch/catch.hpp"
1231 TEST_CASE("Check ancillaries and surface tension", "[fast]" )
1232 {
1233  SECTION("surface tension")
1234  {
1235  REQUIRE_THROWS(_PropsSI("I","P",101325,"D",1,"Propane"));
1236  REQUIRE_NOTHROW(_PropsSI("I","T",300,"D",1,"Propane"));
1237  }
1238  SECTION("rhosatLanc")
1239  {
1240  REQUIRE_THROWS(_PropsSI("rhosatLanc","P",101325,"D",1,"Propane"));
1241  REQUIRE_NOTHROW(_PropsSI("rhosatLanc","T",300,"D",1,"Propane"));
1242  }
1243  SECTION("rhosatVanc")
1244  {
1245  REQUIRE_THROWS(_PropsSI("rhosatVanc","P",101325,"D",1,"Propane"));
1246  REQUIRE_NOTHROW(_PropsSI("rhosatVanc","T",300,"D",1,"Propane"));
1247  }
1248  SECTION("psatLanc")
1249  {
1250  REQUIRE_THROWS(_PropsSI("psatLanc","P",101325,"D",1,"Propane"));
1251  REQUIRE_NOTHROW(_PropsSI("psatLanc","T",300,"D",1,"Propane"));
1252  }
1253  SECTION("psatVanc")
1254  {
1255  REQUIRE_THROWS(_PropsSI("psatVanc","P",101325,"D",1,"Propane"));
1256  REQUIRE_NOTHROW(_PropsSI("psatVanc","T",300,"D",1,"Propane"));
1257  }
1258 }
1259 #endif
Fluid * get_fluid(long iFluid)
Definition: CoolProp.cpp:236
void set_warning(std::string warning)
Definition: CoolProp.cpp:59
EXPORT_CODE double CONVENTION IProps(long iOutput, long iName1, double Prop1, long iName2, double Prop2, long iFluid)
Definition: CoolProp.cpp:758
std::pair< std::string, long > map_data[]
Definition: CoolProp.cpp:65
int set_reference_stateP(Fluid *pFluid, std::string reference_state)
Definition: CoolProp.cpp:1049
std::map< std::string, long > param_map(map_data, map_data+sizeof map_data/sizeof map_data[0])
double keyed_output(long iInput)
Return an output based on the integer key for the term.
Definition: CPState.cpp:1077
long get_Fluid_index(std::string FluidName)
Definition: CoolProp.cpp:239
std::string EOS
Definition: FluidClass.h:120
double _CoolProp_Deriv_Terms(long iTerm, double T, double rho, Fluid *pFluid)
Calculate some interesting derivatives.
Definition: CoolProp.cpp:913
std::string VISCOSITY
Definition: FluidClass.h:122
std::string get_global_param_string(std::string ParamName)
Definition: CoolProp.cpp:1142
std::vector< std::string > get_aliases()
Definition: FluidClass.h:241
std::string CAS
Definition: FluidClass.h:44
void _set_standard_unit_system(int unit_sys)
Definition: CoolProp.cpp:62
EXPORT_CODE int CONVENTION get_debug_level()
std::string gitrevision
Definition: gitrevision.h:1
int global_Phase
Definition: CoolProp.cpp:51
double Props(std::string Output, std::string Name1, double Prop1, std::string Name2, double Prop2, std::string Ref)
Definition: CoolProp.cpp:902
bool global_SinglePhase
Definition: CoolProp.cpp:52
double _Props1(std::string FluidName, std::string Output)
Definition: CoolProp.cpp:556
std::string strjoin(std::vector< std::string > strings, std::string delim)
int _get_standard_unit_system()
Definition: CoolProp.cpp:61
virtual double psat(double T)
Definition: FluidClass.h:359
std::string CP0
Definition: FluidClass.h:121
double Props1(std::string FluidName, std::string Output)
Definition: CoolProp.cpp:586
bool set_REFPROP_fluid(std::string Ref, std::vector< double > &x)
Definition: REFPROP.cpp:417
double molemass
Definition: FluidClass.h:43
double REFPROPSI(long iOutput, long iName1, double Prop1, long iName2, double Prop2, std::string Ref)
Definition: REFPROP.cpp:685
void update(long iInput1, double Value1, long iInput2, double Value2, double T0=-1, double rho0=-1)
Definition: CPState.cpp:213
EXPORT_CODE int CONVENTION get_standard_unit_system(void)
FluidsContainer Fluids
Definition: CoolProp.cpp:189
struct CriticalStruct reduce
A pointer to the point that is used to reduce the T and rho for EOS.
Definition: FluidClass.h:222
double _T_hp_secant(std::string Ref, double h, double p, double T_guess)
Definition: CoolProp.cpp:448
#define EXPORT_CODE
Definition: CoolPropTools.h:31
std::string get_BibTeXKey(std::string Ref, std::string item)
Definition: CoolProp.cpp:1122
std::string get_REFPROPname()
Definition: FluidClass.h:238
std::string get_name()
Returns a std::string with the name of the fluid.
Definition: FluidClass.h:235
double _PropsSI(std::string Output, std::string Name1, double Prop1, std::string Name2, double Prop2, std::string Ref)
Definition: CoolProp.cpp:613
virtual double surface_tension_T(double T)
virtual double rhosatV(double T)
Definition: FluidClass.h:371
std::string format(const char *fmt,...)
long getFluidType(std::string FluidName)
Definition: CoolProp.cpp:369
Fluid * pFluid
A pointer to a CoolProp fluid.
Definition: CPState.h:195
double IncompLiquidSI(long iOutput, double T, double p_SI, long iFluid)
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
double PropsSI(std::string Output, std::string Name1, double Prop1, std::string Name2, double Prop2, std::string Ref)
Definition: CoolProp.cpp:886
std::string ECS_FITS
Definition: FluidClass.h:125
EnvironmentalFactorsStruct environment
Definition: FluidClass.h:176
int set_reference_stateD(std::string Ref, double T, double rho, double h0, double s0)
Definition: CoolProp.cpp:1100
static bool refpropSupported()
Definition: REFPROP.cpp:1066
int unit_system
Definition: CoolProp.cpp:57
TTSESinglePhaseTableClass TTSESinglePhase
Definition: FluidClass.h:228
std::vector< double > x(ncmax, 0)
std::string ECS_LENNARD_JONES
Definition: FluidClass.h:124
Type
Type of JSON value.
Definition: rapidjson.h:513
void set_phase(std::string Phase_str)
Nearly deprecated function.
Definition: CoolProp.cpp:196
struct OtherParameters params
Definition: FluidClass.h:220
std::string SURFACE_TENSION
Definition: FluidClass.h:126
std::string FluidList()
Returns a std::string of a comma-separated list of the CoolProp names of all the fluids that are load...
Definition: AllFluids.cpp:313
double _CoolProp_Fluid_PropsSI(long iOutput, long iName1, double Value1, long iName2, double Value2, Fluid *pFluid)
The lower-level methods that can throw exceptions.
Definition: CoolProp.cpp:765
TEST_CASE("Check ancillaries and surface tension","[fast]")
Definition: CoolProp.cpp:1231
bool global_SaturatedV
Definition: CoolProp.cpp:54
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
double SecFluids(std::string Output, double T, double p, std::string Ref)
Definition: Brine.cpp:345
virtual double psatV(double T)
Definition: FluidClass.h:365
bool add_REFPROP_fluid(std::string FluidName)
Add a REFPROP fluid to the fluid listing in CoolProp.
Definition: CoolProp.cpp:253
bool IsIncompressibleLiquid(std::string name)
#define REQUIRE_THROWS(expr)
Definition: catch.hpp:8054
std::string Phase_Trho(std::string Fluid, double T, double rho)
Definition: CoolProp.cpp:476
bool IsIncompressibleSolution(std::string name)
double h(void)
Definition: CPState.cpp:1382
BibTeXKeysStruct BibTeXKeys
Definition: FluidClass.h:175
EXPORT_CODE int CONVENTION IsFluidType(const char *Ref, const char *Type)
Definition: CoolProp.cpp:390
double DerivTerms(long iTerm, double T, double rho, Fluid *pFluid)
Definition: CoolProp.cpp:1001
double SecFluidsSI(std::string Output, double T, double p, std::string Ref)
Definition: Brine.cpp:337
std::string phase_Tp(double T, double p, double &pL, double &pV, double &rhoL, double &rhoV)
Return the phase given the temperature and pressure.
std::string Phase(std::string Fluid, double T, double p)
Definition: CoolProp.cpp:490
double s(void)
Definition: CPState.cpp:1420
long get_param_index(std::string param)
Definition: CoolProp.cpp:288
#define REQUIRE_NOTHROW(expr)
Definition: catch.hpp:8056
std::vector< phi_BC * > phi0list
A vector of instances of the phi_BC classes for the residual Helmholtz energy contribution.
Definition: FluidClass.h:179
void update(long iInput1, double Value1, long iInput2, double Value2)
Definition: CPState.cpp:2818
Fluid * get_fluid(std::string name)
Definition: AllFluids.cpp:275
std::string get_ASHRAE34(std::string fluid)
Definition: CoolProp.cpp:275
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
bool pure()
Returns true if the fluid is pure, false if pseudo-pure or a mixture.
Definition: FluidClass.h:243
#define SECTION(name, description)
Definition: catch.hpp:8088
virtual double psatL(double T)
Definition: FluidClass.h:362
long get_fluid_index(Fluid *pFluid)
Definition: AllFluids.cpp:298
virtual double rhosatL(double T)
Definition: FluidClass.h:368
bool add_REFPROP_fluid(std::string FluidName, std::vector< double > xmol)
Definition: AllFluids.cpp:254
bool global_SaturatedL
Definition: CoolProp.cpp:53
int set_reference_stateS(std::string Ref, std::string reference_state)
Definition: CoolProp.cpp:1037
std::string Phase_Tp(std::string Fluid, double T, double p)
Definition: CoolProp.cpp:504
std::string get_fluid_param_string(std::string FluidName, std::string ParamName)
Definition: CoolProp.cpp:1173
double keyed_output(long iInput)
Returns an output based on the key provided where iInput is one of iT,iP,iH,iS,....
Definition: CPState.h:530
double _Props1SI(std::string FluidName, std::string Output)
Definition: CoolProp.cpp:514
EXPORT_CODE double CONVENTION IPropsSI(long iOutput, long iName1, double Prop1, long iName2, double Prop2, long iFluid)
Definition: CoolProp.cpp:861
double Props1SI(std::string FluidName, std::string Output)
Definition: CoolProp.cpp:570
bool ValidNumber(double x)
std::string CONDUCTIVITY
Definition: FluidClass.h:123
std::string phase_Trho(double T, double rho, double &pL, double &pV, double &rhoL, double &rhoV)
Return the phase given the temperature and the density.
#define CONVENTION
Definition: CoolPropTools.h:34
double IncompSolutionSI(long iOutput, double T, double p, double x, long iFluid)