CoolProp 6.8.0
An open-source fluid property and humid air property database
CoolPropFluid.h
Go to the documentation of this file.
1/*
2 * CoolPropFluid.h
3 *
4 * Created on: 20 Dec 2013
5 * Author: jowr
6 */
7
8#ifndef COOLPROPFLUID_H_
9#define COOLPROPFLUID_H_
10
11#include "DataStructures.h"
12#include "Helmholtz.h"
13#include "Solvers.h"
14
15#include <numeric>
16#include <string>
17#include <vector>
18#include <map>
19#include <cassert>
20#include <iterator>
21#include "Eigen/Core"
22#include "PolyMath.h"
23#include "Ancillaries.h"
24
25namespace CoolProp {
26
28{
30};
31
33{
34 double GWP20, GWP100, GWP500, ODP, HH, PH, FH;
35 std::string ASHRAE34;
36};
38{
40 std::vector<double> cL, cV;
41 bool enabled;
42 CriticalRegionSplines() : T_min(_HUGE), T_max(_HUGE), rhomolar_min(_HUGE), rhomolar_max(_HUGE), enabled(false){};
43
44 const void get_densities(double T, double rho_min, double rho_crit, double rho_max, double& rhoL, double& rhoV) const {
45 int Nsoln = -1, Ngood = 0;
46 double rho1 = 0, rho2 = 0, rho3 = 0;
47
48 // -----------
49 // Liquid part
50 // -----------
51 Ngood = 0;
52 solve_cubic(cL[0], cL[1], cL[2], cL[3] - T, Nsoln, rho1, rho2, rho3);
53 if (Nsoln == 1 && rho1 < rho_max && rho1 > rho_crit) {
54 rhoL = rho1;
55 } else {
56 if (rho1 < rho_max && rho1 > rho_crit) {
57 Ngood++;
58 rhoL = rho1;
59 }
60 if (rho2 < rho_max && rho2 > rho_crit) {
61 Ngood++;
62 rhoL = rho2;
63 }
64 if (Nsoln > 2 && rho3 < rho_max && rho3 > rho_crit) {
65 Ngood++;
66 rhoL = rho3;
67 }
68 if (Ngood > 1) {
69 throw ValueError(format("More than one liquid solution found for critical spline for T=%0.12g", T));
70 };
71 if (Ngood < 1) {
72 throw ValueError(format("No liquid solution found for critical spline for T=%0.12g", T));
73 };
74 }
75
76 // ----------
77 // Vapor part
78 // ----------
79 Ngood = 0;
80 Nsoln = 0;
81 solve_cubic(cV[0], cV[1], cV[2], cV[3] - T, Nsoln, rho1, rho2, rho3);
82 if (Nsoln == 1 && rho1 > rho_min && rho1 < rho_crit) {
83 rhoV = rho1;
84 } else {
85 if (rho1 > rho_min && rho1 < rho_crit) {
86 Ngood++;
87 rhoV = rho1;
88 }
89 if (rho2 > rho_min && rho2 < rho_crit) {
90 Ngood++;
91 rhoV = rho2;
92 }
93 if (Nsoln > 2 && rho3 > rho_min && rho3 < rho_crit) {
94 Ngood++;
95 rhoV = rho3;
96 }
97 if (Ngood > 1) {
98 throw ValueError(format("More than one vapor solution found for critical spline for T=%0.12g", T));
99 };
100 if (Ngood < 1) {
101 throw ValueError(format("No vapor solution found for critical spline for T=%0.12g", T));
102 };
103 }
104 };
105};
106
109{
110 double Tmin, Tmax, rhomax, pmax;
111};
112
114{
115 std::string reference_fluid;
117 std::vector<CoolPropDbl> psi_a, psi_t, f_int_a, f_int_t;
118};
119
121{
122 std::vector<CoolPropDbl> A, t;
123};
124
126{
128 std::vector<CoolPropDbl> A, B, n, m;
129};
131{
133 {
141 };
142 int type;
145
148 }
149};
150
152{
154 std::vector<CoolPropDbl> A, t, d, gamma, l;
155};
156
158{
160 std::vector<CoolPropDbl> B, t, d;
161};
163{
165 {
171 };
172 int type;
175
178 }
179};
180
182{
185 : // Universal constants - can still be adjusted if need be
186 k(1.3806488e-23), //[J/K]
187 R0(1.03), //[-]
188 gamma(1.239), //[-]
189 nu(0.63), //[-]
190 // Suggested default values - can be over-written
191 GAMMA(0.0496), //[-]
192 zeta0(1.94e-10), //[m]
193 qD(2e9), //[m]
194 // Set to invalid number, can be provided in the JSON file
195 // T_ref default is 1.5*Tc
196 T_reducing(_HUGE),
197 p_reducing(_HUGE),
198 T_ref(_HUGE) {}
199};
201{
203 {
210 };
211 int type;
213
216 }
217};
218
221{
223 std::vector<CoolPropDbl> a, t;
224};
226{
229 std::vector<CoolPropDbl> a, t;
230};
232{
233 std::vector<CoolPropDbl> a, t;
234};
236{
237 std::vector<CoolPropDbl> a, t;
239};
241{
243 {
253 };
262 }
263};
264
266{
267 std::vector<CoolPropDbl> b, t;
268};
270{
271 std::vector<CoolPropDbl> n, d, t;
273};
274
276{
278 {
282 };
288 }
289};
290
292{
293 std::vector<CoolPropDbl> a, d1, d2, t1, t2, f, g, h, p, q, gamma, l;
295};
297{
298 std::vector<CoolPropDbl> Aa, Aaa, Aaaa, Ar, Arr, Adrdr, Arrr, Ai, Aii, AdrAdr;
299 int Na, Naa, Naaa, Nr, Nrr, Nrrr, Nii;
301};
303{
305 {
316 };
323 };
324};
325
327{
328 std::vector<double> c_liq, c_vap;
330};
332{
333 std::string reference_fluid;
335 std::vector<CoolPropDbl> psi_a, psi_t;
336};
338{
340};
341
343{
344 public:
346 {
356 };
358 {
365 };
372
377
378 std::string BibTeX_viscosity,
391 : viscosity_using_ECS(false),
397 sigma_eta(_HUGE),
398 epsilon_over_k(_HUGE),
401};
402
404{
408};
409
411
419{
420 public:
430 double R_u,
438 std::string BibTeX_EOS,
442
444 void validate() {
445 assert(R_u < 9 && R_u > 8);
446 assert(molar_mass > 0.001 && molar_mass < 1);
447 };
448 CoolPropDbl baser(const CoolPropDbl& tau, const CoolPropDbl& delta) {
449 return alphar.base(tau, delta);
450 };
451 // First partials
453 return alphar.dDelta(tau, delta);
454 };
456 return alphar.dTau(tau, delta);
457 };
458 // Second partials
460 return alphar.dDelta2(tau, delta);
461 };
463 return alphar.dDelta_dTau(tau, delta);
464 };
466 return alphar.dTau2(tau, delta);
467 };
468 // Third partials
470 return alphar.dDelta3(tau, delta);
471 };
473 return alphar.dDelta2_dTau(tau, delta);
474 };
476 return alphar.dDelta_dTau2(tau, delta);
477 };
479 return alphar.dTau3(tau, delta);
480 };
481
482 CoolPropDbl base0(const CoolPropDbl& tau, const CoolPropDbl& delta) {
483 return alpha0.base(tau, delta);
484 };
485 // First partials
487 return alpha0.dDelta(tau, delta);
488 };
490 return alpha0.dTau(tau, delta);
491 };
492 // Second partials
494 return alpha0.dDelta2(tau, delta);
495 };
497 return alpha0.dDelta_dTau(tau, delta);
498 };
500 return alpha0.dTau2(tau, delta);
501 };
502 // Third partials
504 return alpha0.dDelta3(tau, delta);
505 };
507 return alpha0.dDelta2_dTau(tau, delta);
508 };
510 return alpha0.dDelta_dTau2(tau, delta);
511 };
513 return alpha0.dTau3(tau, delta);
514 };
515};
516
518
522{
523 protected:
524 // Transport property data
525 std::string ECSReferenceFluid;
526 double ECS_qd;
527 public:
528 CoolPropFluid() : ECS_qd(-_HUGE) {
529 this->ChemSpider_id = -1;
530 };
532 const EquationOfState& EOS() const {
533 return EOSVector[0];
534 }
536 return EOSVector[0];
537 }
538 std::vector<EquationOfState> EOSVector;
539
540 std::string name;
541 std::string
543 std::string CAS;
544 std::string formula;
545 std::vector<std::string> aliases;
546 std::string InChI;
547 std::string InChIKey;
548 std::string smiles;
550 std::string TwoDPNG_URL;
551
559
560 double gas_constant() {
561 return EOS().R_u;
562 };
563 double molar_mass() {
564 return EOS().molar_mass;
565 };
566};
567
568#if !defined(NO_FMTLIB) && FMT_VERSION >= 90000
569inline int format_as(ViscosityDiluteVariables::ViscosityDiluteType type) {
570 return fmt::underlying(type);
571}
572
573inline int format_as(TransportPropertyData::ViscosityHardcodedEnum viscosity) {
574 return fmt::underlying(viscosity);
575}
576
577inline int format_as(TransportPropertyData::ConductivityHardcodedEnum conductivity) {
578 return fmt::underlying(conductivity);
579}
580#endif
581
582} /* namespace CoolProp */
583#endif /* COOLPROPFLUID_H_ */