3 #define _CRTDBG_MAP_ALLOC
4 #define _CRT_SECURE_NO_WARNINGS
30 printf(
"Testing %s \n",this->
get_name().c_str());
31 printf(
"Inputs: T = %3.3f degC \t p = %2.4f bar \t x = %1.5f \n",T_K-273.15,p/1e5,x);
33 result = this->
rho(T_K,p,x);
34 printf(
"From object: rho = %4.2f \t kg/m3 \n",result);
35 result = this->
cp(T_K,p,x);
36 printf(
"From object: cp = %1.5f \t kJ/kg-K \n",result/1e3);
37 result = this->
h(T_K,p,x);
38 printf(
"From object: h = %3.3f \t kJ/kg \n",result/1e3);
39 result = this->
s(T_K,p,x);
40 printf(
"From object: s = %1.5f \t kJ/kg-K \n",result/1e3);
41 result = this->
visc(T_K,p,x);
42 printf(
"From object: eta = %1.5f \t 1e-5 Pa-s\n",result*1e5);
43 result = this->
cond(T_K,p,x);
44 printf(
"From object: lambda = %1.5f \t W/m-k \n",result*1e3);
45 result = this->
u(T_K,p,x);
46 printf(
"From object: u = %3.3f \t kJ/kg \n",result/1e3);
47 result = this->
psat(T_K,x);
48 printf(
"From object: psat = %2.4f \t bar \n",result/1e5);
50 printf(
"From object:Tfreeze = %3.3f \t degC \n\n",result-273.15);
68 throw ValueError(
"Please specify the minimum temperature.");
69 }
else if(
Tmax < 0.) {
70 throw ValueError(
"Please specify the maximum temperature.");
71 }
else if ( (
Tmin>T_K) || (T_K>
Tmax) ) {
73 }
else if (T_K <
Tfreeze(p,x)) {
89 double ps =
psat(T_K,x);
91 throw ValueError(
format(
"Equations are valid for solution phase only: %f < %f. ",p,ps));
103 throw ValueError(
"Please specify the minimum concentration.");
104 }
else if(
xmax < 0.) {
105 throw ValueError(
"Please specify the maximum concentration.");
106 }
else if ( (
xmin>x) || (x>
xmax) ) {
124 std::vector<IncompressibleSolution*> tmpVector;
142 tmpVector.push_back(
new ZitrecAC());
146 tmpVector.push_back(
new PK2000());
156 while (!solution_list.empty()) {
157 delete solution_list.back();
158 solution_list.pop_back();
163 return solution_list[index];
167 std::map<std::string,IncompressibleSolution*>::iterator it;
169 it = solution_map.find(name);
171 if (it != solution_map.end() )
182 solution_list = list;
184 for (std::vector<IncompressibleSolution*>::iterator it = solution_list.begin(); it != solution_list.end(); it++)
187 solution_map[(*it)->get_name()] = *it;
196 if (pSolution == NULL){
214 out = pSolution->
rho(T,p_SI,x);
break;
216 out = pSolution->
cp(T,p_SI,x);
break;
218 out = pSolution->
s(T,p_SI,x);
break;
220 out = pSolution->
u(T,p_SI,x);
break;
222 out = pSolution->
h(T,p_SI,x);
break;
224 out = pSolution->
visc(T,p_SI,x);
break;
226 out = pSolution->
cond(T,p_SI,x);
break;
228 out = pSolution->
getTmax();
break;
230 out = pSolution->
getTmin();
break;
232 out = pSolution->
Tfreeze(p_SI,x);
break;
234 out = pSolution->
psat(T,x);
break;
236 throw ValueError(
format(
"Your index [%d] is invalid for the incompressible solution %s",iOutput,pSolution->
getName().c_str()));
257 std::vector<std::string> fluid_concentration =
strsplit(std::string(name),
'-');
259 if (fluid_concentration.size() != 2){
260 throw ValueError(
format(
"Format of incompressible solution string [%s] is invalid, should be like \"EG-20%\" or \"EG-0.2\" ", name.c_str()) );
264 double x = strtod(fluid_concentration[1].c_str(), &pEnd);
266 if (!strcmp(pEnd,
"%")){ x *= 0.01;}
271 std::vector<std::string> fluid_concentration =
strsplit(std::string(name),
'-');
272 return fluid_concentration[0];
276 std::vector<std::string> fluid_concentration =
strsplit(std::string(name),
'-');
278 if (fluid_concentration.size() != 2){
279 throw ValueError(
format(
"Format of incompressible solution string [%s] is invalid, should be like \"EG-20%\" or \"EG-0.2\" ", name.c_str()) );
283 double x = strtod(fluid_concentration[1].c_str(), &pEnd);
285 if (!strcmp(pEnd,
"%")){ x *= 0.01;}
305 +coefficients[15])*T_K
306 +(((coefficients[14])*x
309 +coefficients[11])*T_K
310 +((((coefficients[10])*x
314 +coefficients[6])*T_K
315 +(((((coefficients[5])*x
325 std::vector< std::vector<double> > matrix;
326 std::vector<double> tmpVector;
329 tmpVector.push_back(coefficients[0]);
330 tmpVector.push_back(coefficients[6]);
331 tmpVector.push_back(coefficients[11]);
332 tmpVector.push_back(coefficients[15]);
333 matrix.push_back(tmpVector);
336 tmpVector.push_back(coefficients[1]);
337 tmpVector.push_back(coefficients[7]);
338 tmpVector.push_back(coefficients[12]);
339 tmpVector.push_back(coefficients[16]);
340 matrix.push_back(tmpVector);
343 tmpVector.push_back(coefficients[2]);
344 tmpVector.push_back(coefficients[8]);
345 tmpVector.push_back(coefficients[13]);
346 tmpVector.push_back(coefficients[17]);
347 matrix.push_back(tmpVector);
350 tmpVector.push_back(coefficients[3]);
351 tmpVector.push_back(coefficients[9]);
352 tmpVector.push_back(coefficients[14]);
353 tmpVector.push_back(0.0);
354 matrix.push_back(tmpVector);
357 tmpVector.push_back(coefficients[4]);
358 tmpVector.push_back(coefficients[10]);
359 tmpVector.push_back(0.0);
360 tmpVector.push_back(0.0);
361 matrix.push_back(tmpVector);
364 tmpVector.push_back(coefficients[5]);
365 tmpVector.push_back(0.0);
366 tmpVector.push_back(0.0);
367 tmpVector.push_back(0.0);
368 matrix.push_back(tmpVector);
376 const int lengthA = 18;
377 const int lengthB = 5;
378 if ((A==lengthA) && (B==lengthB) ){
380 double oldCoeffs[lengthA][lengthB];
381 for (
int j = 0; j < lengthB; j++) {
382 oldCoeffs[ 0][j] = oldestCoeffs[( 0 * B) + j ];
383 oldCoeffs[ 1][j] = oldestCoeffs[( 4 * B) + j ];
384 oldCoeffs[ 2][j] = oldestCoeffs[( 8 * B) + j ];
385 oldCoeffs[ 3][j] = oldestCoeffs[(12 * B) + j ];
386 oldCoeffs[ 4][j] = oldestCoeffs[(15 * B) + j ];
387 oldCoeffs[ 5][j] = oldestCoeffs[(17 * B) + j ];
388 oldCoeffs[ 6][j] = oldestCoeffs[( 1 * B) + j ];
389 oldCoeffs[ 7][j] = oldestCoeffs[( 5 * B) + j ];
390 oldCoeffs[ 8][j] = oldestCoeffs[( 9 * B) + j ];
391 oldCoeffs[ 9][j] = oldestCoeffs[(13 * B) + j ];
392 oldCoeffs[10][j] = oldestCoeffs[(16 * B) + j ];
393 oldCoeffs[11][j] = oldestCoeffs[( 2 * B) + j ];
394 oldCoeffs[12][j] = oldestCoeffs[( 6 * B) + j ];
395 oldCoeffs[13][j] = oldestCoeffs[(10 * B) + j ];
396 oldCoeffs[14][j] = oldestCoeffs[(14 * B) + j ];
397 oldCoeffs[15][j] = oldestCoeffs[( 3 * B) + j ];
398 oldCoeffs[16][j] = oldestCoeffs[( 7 * B) + j ];
399 oldCoeffs[17][j] = oldestCoeffs[(11 * B) + j ];
401 std::vector<std::vector<double> > tmpVector;
402 tmpVector.push_back(std::vector<double>());
403 tmpVector.push_back(std::vector<double>());
404 tmpVector.push_back(std::vector<double>());
405 tmpVector.push_back(std::vector<double>());
406 tmpVector.push_back(std::vector<double>());
407 for (
int i = 0; i < lengthA; i++) {
408 for (
int j = 0; j < lengthB; j++) {
409 if (i<1) tmpVector[j].clear();
410 tmpVector[j].push_back(oldCoeffs[i][j]);
415 throw ValueError(
format(
"Your array has the dimensions [%d,%d], but only [%d,%d] arrays are supported.",A,B,lengthA,lengthB));
static double const M_LiBr
virtual double cp(double T_K, double p, double x)
static double const M_H2O
SolutionsContainer Solutions
virtual double s(double T_K, double p, double x)
Entropy as a function of temperature, pressure and composition.
virtual double visc(double T_K, double p, double x)
Viscosity as a function of temperature, pressure and composition.
virtual double cond(double T_K, double p, double x)
Thermal conductivity as a function of temperature, pressure and composition.
bool checkTPX(double T, double p, double x)
Check validity of temperature, pressure and composition input.
virtual double psat(double T_K, double x)
Saturation pressure as a function of temperature and composition.
std::string getName() const
virtual double u(double T_K, double p, double x)
Internal energy as a function of temperature, pressure and composition.
bool checkT(double T_K, double p, double x)
Check validity of temperature input.
std::string get_name() const
Base class for simplified brine/solution models.
std::vector< std::vector< double > > makeMatrix(std::vector< double > const &coefficients)
virtual double h(double T_K, double p, double x)
Enthalpy as a function of temperature, pressure and composition.
Class to access Lithium-Bromide solutions.
std::vector< double > x(ncmax, 0)
void testInputs(double T_K, double p, double x)
Base class for simplified brine/solution models.
static double const pc_H2O
double baseFunction(std::vector< double > const &coefficients, double T_K, double p, double x)
Some more general purpose functions.
IncompressibleSolution * get_solution(long index)
virtual double rho(double T_K, double p, double x)
Density as a function of temperature, pressure and composition.
std::string getSolutionName(std::string name)
bool checkP(double T_K, double p, double x)
Check validity of pressure input.
std::vector< std::vector< double > > convertCoeffs(double *oldestCoeffs, int A, int B)
Convert pre-v4.0-style coefficient array to new format.
static double const Tt_H2O
static double const Tc_H2O
bool IsIncompressibleSolution(std::string name)
double getSolutionConc(std::string name)
static double const sc_H2O
bool checkCoefficients(std::vector< double > const &coefficients, unsigned int n)
Basic checks for coefficient vectors.
static double const cpt_H2O
bool checkX(double x)
Check validity of composition input.
static double const rhoc_H2O
void set_solutions(std::vector< IncompressibleSolution * > list)
static double const hc_H2O
double pIncompSolutionSI(long iOutput, double T, double p_SI, double x, IncompressibleSolution *pSolution)
virtual double Tfreeze(double p, double x)
Freezing temperature as a function of pressure and composition.
double IncompSolutionSI(long iOutput, double T, double p, double x, long iFluid)