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
IncompLiquid.cpp
Go to the documentation of this file.
1 
2 #if defined(_MSC_VER)
3 #define _CRTDBG_MAP_ALLOC
4 #define _CRT_SECURE_NO_WARNINGS
5 #include <stdlib.h>
6 #include <crtdbg.h>
7 #else
8 #include <stdlib.h>
9 #endif
10 
11 #include "Units.h"
12 #include "math.h"
13 #include "stdio.h"
14 #include <string.h>
15 #include "Brine.h"
16 #include "CoolPropTools.h"
17 #include "CoolProp.h"
18 #include "IncompBase.h"
19 #include "IncompLiquid.h"
20 
21 
23 
26 void IncompressibleLiquid::testInputs(double T_K, double p){
27  double result = 0.;
28 
29  printf(" %s \n"," ");
30  printf("Testing %s \n",this->get_name().c_str());
31  printf("Inputs: T = %3.3f degC \t p = %2.4f bar \n",T_K-273.15,p/1e5);
32 
33  result = this->rho(T_K,p);
34  printf("From object: rho = %4.2f \t kg/m3 \n",result);
35  result = this->cp(T_K,p);
36  printf("From object: cp = %1.5f \t kJ/kg-K \n",result/1e3);
37  result = this->h(T_K,p);
38  printf("From object: h = %3.3f \t kJ/kg \n",result/1e3);
39  result = this->s(T_K,p);
40  printf("From object: s = %1.5f \t kJ/kg-K \n",result/1e3);
41  result = this->visc(T_K,p);
42  printf("From object: eta = %1.5f \t 1e-5 Pa-s\n",result*1e5);
43  result = this->cond(T_K,p);
44  printf("From object: lambda = %1.5f \t W/m-k \n",result*1e3);
45  result = this->u(T_K,p);
46  printf("From object: u = %3.3f \t kJ/kg \n",result/1e3);
47  result = this->psat(T_K);
48  printf("From object: psat = %2.4f \t bar \n",result/1e5);
49 }
50 
51 
52 /*
53  * Some more functions to provide a single implementation
54  * of important routines.
55  * We start with the check functions that can validate input
56  * in terms of pressure p and temperature T.
57  */
58 
60 
64  if( Tmin < 0. ) {
65  throw ValueError("Please specify the minimum temperature.");
66  } else if( Tmax < 0.) {
67  throw ValueError("Please specify the maximum temperature.");
68  } else if ( (Tmin>T_K) || (T_K>Tmax) ) {
69  throw ValueError(format("Your temperature %f is not between %f and %f.",T_K,Tmin,Tmax));
70  } else {
71  return true;
72  }
73  return false;
74 }
75 
77 
83 bool IncompressibleLiquid::checkP(double T_K, double p) {
84  double ps = psat(T_K);
85  if (p<ps) {
86  throw ValueError(format("Equations are valid for liquid phase only: %f < %f. ",p,ps));
87  } else {
88  return true;
89  }
90 }
91 
93 bool IncompressibleLiquid::checkTP(double T, double p) {
94  //return (checkT(T) && checkP(T,p));
95  return 1;
96 }
97 
98 
99 
103  std::vector<IncompressibleLiquid*> tmpVector;
104 
105  tmpVector.push_back(new DEBLiquidClass());
106  tmpVector.push_back(new HCMLiquidClass());
107  tmpVector.push_back(new HFELiquidClass());
108  tmpVector.push_back(new PMS1LiquidClass());
109  tmpVector.push_back(new PMS2LiquidClass());
110  tmpVector.push_back(new SABLiquidClass());
111  tmpVector.push_back(new HCBLiquidClass());
112  tmpVector.push_back(new TCOLiquidClass());
113  // Add new fluids based on data sheets
114  tmpVector.push_back(new TherminolD12Class());
115  tmpVector.push_back(new TherminolVP1Class());
116  tmpVector.push_back(new Therminol72Class());
117  tmpVector.push_back(new Therminol66Class());
118 
119  tmpVector.push_back(new DowthermJClass());
120  tmpVector.push_back(new DowthermQClass());
121 
122  tmpVector.push_back(new Texatherm22Class());
123 
124  tmpVector.push_back(new NitrateSaltClass());
125 
126  tmpVector.push_back(new SylthermXLTClass());
127 
128  tmpVector.push_back(new HC10Class());
129  tmpVector.push_back(new HC20Class());
130  tmpVector.push_back(new HC30Class());
131  tmpVector.push_back(new HC40Class());
132  tmpVector.push_back(new HC50Class());
133 
134  // Add new fluids based SecCool software
135  tmpVector.push_back(new AS10Class());
136  tmpVector.push_back(new AS20Class());
137  tmpVector.push_back(new AS30Class());
138  tmpVector.push_back(new AS40Class());
139  tmpVector.push_back(new AS55Class());
140  tmpVector.push_back(new ZS10Class());
141  tmpVector.push_back(new ZS25Class());
142  tmpVector.push_back(new ZS40Class());
143  tmpVector.push_back(new ZS45Class());
144  tmpVector.push_back(new ZS55Class());
145 
146 
147  // Now we store the vector in the variable
148  // and overwrite the map.
149  set_liquids(tmpVector);
150 }
151 
153  while (!liquid_list.empty()) {
154  delete liquid_list.back();
155  liquid_list.pop_back();
156  }
157 }
158 
160  return liquid_list[index];
161 }
162 
164  std::map<std::string,IncompressibleLiquid*>::iterator it;
165  // Try to find using the map if Fluid name is provided
166  it = liquid_map.find(name);
167  // If it is found the iterator will not be equal to end
168  if (it != liquid_map.end() )
169  {
170  // Return a pointer to the class
171  return (*it).second;
172  }
173  else{
174  return NULL;
175  }
176 }
177 
178 void LiquidsContainer::set_liquids(std::vector<IncompressibleLiquid*> list){
179  liquid_list = list;
180  // Build the map of fluid names mapping to pointers to the liquid class instances
181  for (std::vector<IncompressibleLiquid*>::iterator it = liquid_list.begin(); it != liquid_list.end(); it++)
182  {
183  // Load up entry in map
184  liquid_map[(*it)->get_name()] = *it;
185  }
186 }
187 
189 
190 bool IsIncompressibleLiquid(std::string name)
191 {
192  IncompressibleLiquid *pLiquid = Liquids.get_liquid(name);
193  if (pLiquid == NULL){ //Not found since NULL pointer returned
194  return false;
195  }
196  else{
197  return true;
198  }
199 }
200 
201 
202 double pIncompLiquidSI(long iOutput, double T, double p_SI, IncompressibleLiquid *pLiquid)
203 {
204  double out;
205  switch (iOutput)
206  {
207  case iT:
208  out = T; break;
209  case iP:
210  out = p_SI; break;
211  case iD:
212  out = pLiquid->rho(T,p_SI); break;
213  case iC:
214  out = pLiquid->cp(T,p_SI); break;
215  case iS:
216  out = pLiquid->s(T,p_SI); break;
217  case iU:
218  out = pLiquid->u(T,p_SI); break;
219  case iH:
220  out = pLiquid->h(T,p_SI); break;
221  case iV:
222  out = pLiquid->visc(T,p_SI); break;
223  case iL:
224  out = pLiquid->cond(T,p_SI); break;
225  case iTmin:
226  out = pLiquid->getTmin(); break;
227  case iTmax:
228  out = pLiquid->getTmax(); break;
229  case iPsat:
230  out = pLiquid->psat(T); break;
231  default:
232  throw ValueError(format("Your index [%d] is invalid for the incompressible liquid %s",iOutput,pLiquid->getName().c_str()));
233  out=0; break;
234  }
235  return out;
236 }
237 
238 double pIncompLiquid(long iOutput, double T, double p, IncompressibleLiquid *pLiquid)
239 {
240  // Convert to SI pressure
242 
243  // Call the function
244  double out = pIncompLiquidSI(iOutput,T,p_SI,pLiquid);
245 
246  // Convert back to current unit system
248 }
249 
250 double IncompLiquidSI(long iOutput, double T, double p_SI, long iFluid)
251 {
252  return pIncompLiquidSI(iOutput,T,p_SI,Liquids.get_liquid(iFluid));
253 }
254 
255 double IncompLiquidSI(long iOutput, double T, double p_SI, std::string name)
256 {
257  return pIncompLiquidSI(iOutput,T,p_SI,Liquids.get_liquid(name));
258 }
259 
260 
void testInputs(double T_K, double p)
Base class for simplified brine/solution models.
New fluids added with more coefficients.
Definition: IncompLiquid.h:469
double pIncompLiquidSI(long iOutput, double T, double p_SI, IncompressibleLiquid *pLiquid)
virtual double cp(double T_K, double p)
Definition: IncompLiquid.h:35
double pIncompLiquid(long iOutput, double T, double p, IncompressibleLiquid *pLiquid)
std::string getName() const
Definition: IncompBase.h:31
Base class for simplified brine/solution models.
Definition: IncompLiquid.h:25
virtual double u(double T_K, double p)
Internal energy as a function of temperature and pressure.
Definition: IncompLiquid.h:40
EXPORT_CODE int CONVENTION get_standard_unit_system(void)
LiquidsContainer Liquids
std::string get_name() const
Definition: IncompBase.h:33
double getTmin() const
Definition: IncompBase.h:36
std::string format(const char *fmt,...)
double IncompLiquidSI(long iOutput, double T, double p_SI, long iFluid)
double convert_from_SI_to_unit_system(long iInput, double value, int new_system)
Definition: Units.cpp:123
virtual double rho(double T_K, double p)
Density as a function of temperature and pressure.
Definition: IncompLiquid.h:32
bool checkT(double T_K)
Check validity of temperature input.
bool IsIncompressibleLiquid(std::string name)
virtual double s(double T_K, double p)
Entropy as a function of temperature and pressure.
Definition: IncompLiquid.h:38
virtual double h(double T_K, double p)
Enthalpy as a function of temperature and pressure.
Definition: IncompLiquid.h:42
virtual double psat(double T_K)
Saturation pressure as a function of temperature.
Definition: IncompLiquid.h:48
IncompressibleLiquid * get_liquid(long index)
void set_liquids(std::vector< IncompressibleLiquid * > list)
double convert_from_unit_system_to_SI(long iInput, double value, int old_system)
Definition: Units.cpp:5
bool checkP(double T_K, double p)
Check validity of pressure input.
virtual double cond(double T_K, double p)
Thermal conductivity as a function of temperature and pressure.
Definition: IncompLiquid.h:46
double getTmax() const
Definition: IncompBase.h:35
bool checkTP(double T, double p)
Check validity of temperature and pressure input.
virtual double visc(double T_K, double p)
Viscosity as a function of temperature and pressure.
Definition: IncompLiquid.h:44