CoolProp 8.0.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
14
15#include <numeric>
16#include <string>
17#include <vector>
18#include <map>
19#include <variant>
20#include <optional>
21#include <cassert>
22#include <iterator>
23#include "Eigen/Core"
27
28namespace CoolProp {
29
31{
33};
34
36{
37 double GWP20 = _HUGE, GWP100 = _HUGE, GWP500 = _HUGE, ODP = _HUGE, HH = _HUGE, PH = _HUGE, FH = _HUGE;
38 std::string ASHRAE34;
39};
41{
43 std::vector<double> cL, cV;
44 bool enabled;
45 CriticalRegionSplines() : T_min(_HUGE), T_max(_HUGE), rhomolar_min(_HUGE), rhomolar_max(_HUGE), enabled(false) {};
46
47 const void get_densities(double T, double rho_min, double rho_crit, double rho_max, double& rhoL, double& rhoV) const {
48 int Nsoln = -1, Ngood = 0;
49 double rho1 = 0, rho2 = 0, rho3 = 0;
50
51 // -----------
52 // Liquid part
53 // -----------
54 Ngood = 0;
55 solve_cubic(cL[0], cL[1], cL[2], cL[3] - T, Nsoln, rho1, rho2, rho3);
56 if (Nsoln == 1 && rho1 < rho_max && rho1 > rho_crit) {
57 rhoL = rho1;
58 } else {
59 if (rho1 < rho_max && rho1 > rho_crit) {
60 Ngood++;
61 rhoL = rho1;
62 }
63 if (rho2 < rho_max && rho2 > rho_crit) {
64 Ngood++;
65 rhoL = rho2;
66 }
67 if (Nsoln > 2 && rho3 < rho_max && rho3 > rho_crit) {
68 Ngood++;
69 rhoL = rho3;
70 }
71 if (Ngood > 1) {
72 throw ValueError(format("More than one liquid solution found for critical spline for T=%0.12g", T));
73 };
74 if (Ngood < 1) {
75 throw ValueError(format("No liquid solution found for critical spline for T=%0.12g", T));
76 };
77 }
78
79 // ----------
80 // Vapor part
81 // ----------
82 Ngood = 0;
83 Nsoln = 0;
84 solve_cubic(cV[0], cV[1], cV[2], cV[3] - T, Nsoln, rho1, rho2, rho3);
85 if (Nsoln == 1 && rho1 > rho_min && rho1 < rho_crit) {
86 rhoV = rho1;
87 } else {
88 if (rho1 > rho_min && rho1 < rho_crit) {
89 Ngood++;
90 rhoV = rho1;
91 }
92 if (rho2 > rho_min && rho2 < rho_crit) {
93 Ngood++;
94 rhoV = rho2;
95 }
96 if (Nsoln > 2 && rho3 > rho_min && rho3 < rho_crit) {
97 Ngood++;
98 rhoV = rho3;
99 }
100 if (Ngood > 1) {
101 throw ValueError(format("More than one vapor solution found for critical spline for T=%0.12g", T));
102 };
103 if (Ngood < 1) {
104 throw ValueError(format("No vapor solution found for critical spline for T=%0.12g", T));
105 };
106 }
107 };
108};
109
112{
113 double Tmin, Tmax, rhomax, pmax;
114};
115
117{
118 std::string reference_fluid;
120 std::vector<CoolPropDbl> psi_a, psi_t, f_int_a, f_int_t;
121};
122
124{
125 std::vector<CoolPropDbl> A, t;
126};
127
129{
131 std::vector<CoolPropDbl> A, B, n, m;
132};
134{
136 {
144 };
148};
149
151{
153 std::vector<CoolPropDbl> A, t, d, gamma, l;
154};
155
157{
159 std::vector<CoolPropDbl> B, t, d;
160};
162{
164 {
170 };
174};
175
177{
180 : // Universal constants - can still be adjusted if need be
181 k(1.3806488e-23), //[J/K]
182 R0(1.03), //[-]
183 gamma(1.239), //[-]
184 nu(0.63), //[-]
185 // Suggested default values - can be over-written
186 GAMMA(0.0496), //[-]
187 zeta0(1.94e-10), //[m]
188 qD(2e9), //[m]
189 // Set to invalid number, can be provided in the JSON file
190 // T_ref default is 1.5*Tc
191 T_reducing(_HUGE),
192 p_reducing(_HUGE),
193 T_ref(_HUGE) {}
194};
196{
198 {
205 };
208};
209
212{
214 std::vector<CoolPropDbl> a, t;
215};
217{
220 std::vector<CoolPropDbl> a, t;
221};
223{
224 std::vector<CoolPropDbl> a, t;
225};
227{
228 std::vector<CoolPropDbl> a, t;
230};
232{
234 {
244 };
251};
252
254{
255 std::vector<CoolPropDbl> b, t;
256};
258{
259 std::vector<CoolPropDbl> n, d, t;
261};
262
264{
266 {
270 };
274};
275
277{
278 std::vector<CoolPropDbl> a, d1, d2, t1, t2, f, g, h, p, q, gamma, l;
280};
282{
283 std::vector<CoolPropDbl> Aa, Aaa, Aaaa, Ar, Arr, Adrdr, Arrr, Ai, Aii, AdrAdr;
284 int Na = 0, Naa = 0, Naaa = 0, Nr = 0, Nrr = 0, Nrrr = 0, Nii = 0;
285 CoolPropDbl c1 = _HUGE, c2 = _HUGE, T_reduce = _HUGE, rhomolar_reduce = _HUGE;
286};
288{
290 {
301 };
306};
307
309{
310 std::vector<double> c_liq, c_vap;
311 double C = _HUGE, x_crossover = _HUGE, rhosr_critical = _HUGE;
312};
314{
315 std::string reference_fluid;
317 std::vector<CoolPropDbl> psi_a, psi_t;
318};
320{
322};
323
325{
326 public:
328 {
338 };
340 {
347 };
354
359
360 std::string BibTeX_viscosity,
373 : viscosity_using_ECS(false),
379 sigma_eta(_HUGE),
380 epsilon_over_k(_HUGE),
383};
384
386{
390};
391
393
401{
402 public:
404
405 private:
406 std::string superancillaries_str;
407 std::shared_ptr<SuperAncillary_t> superancillaries;
408
409 public:
417 double R_u,
425 std::string BibTeX_EOS,
429
433 std::shared_ptr<SuperAncillary_t> get_superanc() {
434 if (!superancillaries && !superancillaries_str.empty()) {
435 superancillaries = std::make_shared<SuperAncillary_t>(superancillaries_str);
436 }
437 return superancillaries;
438 }
439
441 void set_superancillaries_str(const std::string& s) {
442 superancillaries_str = s;
443 // Do the construction greedily by default, but allow it to be lazy if you want
444#if !defined(LAZY_LOAD_SUPERANCILLARIES)
445 get_superanc();
446#endif
447 }
448
450 void validate() {
451 assert(R_u < 9 && R_u > 8);
452 assert(molar_mass > 0.001 && molar_mass < 1);
453 };
454 CoolPropDbl baser(const CoolPropDbl& tau, const CoolPropDbl& delta) {
455 return alphar.base(tau, delta);
456 };
457 // First partials
459 return alphar.dDelta(tau, delta);
460 };
462 return alphar.dTau(tau, delta);
463 };
464 // Second partials
466 return alphar.dDelta2(tau, delta);
467 };
469 return alphar.dDelta_dTau(tau, delta);
470 };
472 return alphar.dTau2(tau, delta);
473 };
474 // Third partials
476 return alphar.dDelta3(tau, delta);
477 };
479 return alphar.dDelta2_dTau(tau, delta);
480 };
482 return alphar.dDelta_dTau2(tau, delta);
483 };
485 return alphar.dTau3(tau, delta);
486 };
487
488 CoolPropDbl base0(const CoolPropDbl& tau, const CoolPropDbl& delta) {
489 return alpha0.base(tau, delta);
490 };
491 // First partials
493 return alpha0.dDelta(tau, delta);
494 };
496 return alpha0.dTau(tau, delta);
497 };
498 // Second partials
500 return alpha0.dDelta2(tau, delta);
501 };
503 return alpha0.dDelta_dTau(tau, delta);
504 };
506 return alpha0.dTau2(tau, delta);
507 };
508 // Third partials
510 return alpha0.dDelta3(tau, delta);
511 };
513 return alpha0.dDelta2_dTau(tau, delta);
514 };
516 return alpha0.dDelta_dTau2(tau, delta);
517 };
519 return alpha0.dTau3(tau, delta);
520 };
521};
522
524
528{
529 protected:
530 // Transport property data
531 std::string ECSReferenceFluid;
532 double ECS_qd;
533 public:
535 : ECS_qd(-_HUGE), ChemSpider_id(-1) {
536
537 };
538 ~CoolPropFluid() = default;
539 const EquationOfState& EOS() const {
540 return EOSVector[0];
541 }
543 return EOSVector[0];
544 }
545 std::vector<EquationOfState> EOSVector;
546
547 std::string name;
548 std::string
550 std::string CAS;
551 std::string formula;
552 std::vector<std::string> aliases;
553 std::string InChI;
554 std::string InChIKey;
555 std::string smiles;
557 std::string TwoDPNG_URL;
558
566
567 double gas_constant() {
568 return EOS().R_u;
569 };
570 double molar_mass() {
571 return EOS().molar_mass;
572 };
573};
574
575#if !defined(NO_FMTLIB) && FMT_VERSION >= 90000
576inline int format_as(ViscosityDiluteVariables::ViscosityDiluteType type) {
577 return fmt::underlying(type);
578}
579
580inline int format_as(TransportPropertyData::ViscosityHardcodedEnum viscosity) {
581 return fmt::underlying(viscosity);
582}
583
584inline int format_as(TransportPropertyData::ConductivityHardcodedEnum conductivity) {
585 return fmt::underlying(conductivity);
586}
587#endif
588
589} /* namespace CoolProp */
590#endif /* COOLPROPFLUID_H_ */