CoolProp 6.8.1dev
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 <variant>
20#include <optional>
21#include <cassert>
22#include <iterator>
23#include "Eigen/Core"
24#include "PolyMath.h"
25#include "Ancillaries.h"
27
28namespace CoolProp {
29
31{
33};
34
36{
37 double GWP20, GWP100, GWP500, ODP, HH, PH, FH;
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, Naa, Naaa, Nr, Nrr, Nrrr, Nii;
286};
288{
290 {
301 };
306};
307
309{
310 std::vector<double> c_liq, c_vap;
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{
402public:
404
405private:
406 std::string superancillaries_str;
407 std::optional<SuperAncillary_t> superancillaries = std::nullopt;
408
409 public:
417 double R_u,
425 std::string BibTeX_EOS,
429
431 std::optional<SuperAncillary_t> & get_superanc_optional(){
432
433 if (!superancillaries){
434 if (!superancillaries_str.empty()){
435 auto start = std::chrono::high_resolution_clock::now(); // Start time
436 // Now do the parsing pass and replace with the actual superancillary
437 superancillaries.emplace(SuperAncillary_t(superancillaries_str));
438 auto end = std::chrono::high_resolution_clock::now(); // End time
439 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
440 //std::cout << "Execution time: " << duration.count() << " microseconds for " << BibTeX_EOS << std::endl;
441 }
442 }
443 return superancillaries;
444 }
445
447 void set_superancillaries_str(const std::string &s){
448 superancillaries_str = s;
449 // Do the construction greedily by default, but allow it to be lazy if you want
450#if !defined(LAZY_LOAD_SUPERANCILLARIES)
452#endif
453 }
454
455
456
458 void validate() {
459 assert(R_u < 9 && R_u > 8);
460 assert(molar_mass > 0.001 && molar_mass < 1);
461 };
462 CoolPropDbl baser(const CoolPropDbl& tau, const CoolPropDbl& delta) {
463 return alphar.base(tau, delta);
464 };
465 // First partials
467 return alphar.dDelta(tau, delta);
468 };
470 return alphar.dTau(tau, delta);
471 };
472 // Second partials
474 return alphar.dDelta2(tau, delta);
475 };
477 return alphar.dDelta_dTau(tau, delta);
478 };
480 return alphar.dTau2(tau, delta);
481 };
482 // Third partials
484 return alphar.dDelta3(tau, delta);
485 };
487 return alphar.dDelta2_dTau(tau, delta);
488 };
490 return alphar.dDelta_dTau2(tau, delta);
491 };
493 return alphar.dTau3(tau, delta);
494 };
495
496 CoolPropDbl base0(const CoolPropDbl& tau, const CoolPropDbl& delta) {
497 return alpha0.base(tau, delta);
498 };
499 // First partials
501 return alpha0.dDelta(tau, delta);
502 };
504 return alpha0.dTau(tau, delta);
505 };
506 // Second partials
508 return alpha0.dDelta2(tau, delta);
509 };
511 return alpha0.dDelta_dTau(tau, delta);
512 };
514 return alpha0.dTau2(tau, delta);
515 };
516 // Third partials
518 return alpha0.dDelta3(tau, delta);
519 };
521 return alpha0.dDelta2_dTau(tau, delta);
522 };
524 return alpha0.dDelta_dTau2(tau, delta);
525 };
527 return alpha0.dTau3(tau, delta);
528 };
529};
530
532
536{
537 protected:
538 // Transport property data
539 std::string ECSReferenceFluid;
540 double ECS_qd;
541 public:
542 CoolPropFluid() : ECS_qd(-_HUGE) {
543 this->ChemSpider_id = -1;
544 };
546 const EquationOfState& EOS() const {
547 return EOSVector[0];
548 }
550 return EOSVector[0];
551 }
552 std::vector<EquationOfState> EOSVector;
553
554 std::string name;
555 std::string
557 std::string CAS;
558 std::string formula;
559 std::vector<std::string> aliases;
560 std::string InChI;
561 std::string InChIKey;
562 std::string smiles;
564 std::string TwoDPNG_URL;
565
573
574 double gas_constant() {
575 return EOS().R_u;
576 };
577 double molar_mass() {
578 return EOS().molar_mass;
579 };
580};
581
582#if !defined(NO_FMTLIB) && FMT_VERSION >= 90000
583inline int format_as(ViscosityDiluteVariables::ViscosityDiluteType type) {
584 return fmt::underlying(type);
585}
586
587inline int format_as(TransportPropertyData::ViscosityHardcodedEnum viscosity) {
588 return fmt::underlying(viscosity);
589}
590
591inline int format_as(TransportPropertyData::ConductivityHardcodedEnum conductivity) {
592 return fmt::underlying(conductivity);
593}
594#endif
595
596} /* namespace CoolProp */
597#endif /* COOLPROPFLUID_H_ */