CoolProp 8.0.0
An open-source fluid property and humid air property database
IdealCurves.h
Go to the documentation of this file.
4#include <string>
5
6namespace CoolProp {
7
9{
10 public:
12 double p0, T0, lnT, lnp, rho_guess;
13 std::vector<double> T, p;
15 {
19 };
21 CurveTracer(AbstractState* AS, double p0, double T0) : AS(AS), p0(p0), T0(T0), lnT(_HUGE), lnp(_HUGE), rho_guess(_HUGE), obj(OBJECTIVE_INVALID) {
22 this->p.push_back(p0);
23 };
24 void init() {
25 // Solve for Temperature for first point
26 this->obj = OBJECTIVE_T;
27 this->rho_guess = -1;
28 this->T.push_back(Secant(this, T0, 0.001 * T0, 1e-10, 100));
29 }
30
31 virtual double objective() = 0;
32
33 virtual double starting_direction() {
34 return M_PI / 2.0;
35 }
36
37 double call(double t) override {
38 if (this->obj == OBJECTIVE_CIRCLE) {
39 double T2, P2;
40 this->TPcoords(t, lnT, lnp, T2, P2);
41 this->AS->update(PT_INPUTS, P2, T2);
42 } else {
43 if (this->rho_guess < 0)
44 this->AS->update(PT_INPUTS, this->p[this->p.size() - 1], t);
45 else {
46 GuessesStructure guesses;
47 guesses.rhomolar = this->rho_guess;
48 this->AS->update_with_guesses(PT_INPUTS, this->p[this->p.size() - 1], t, guesses);
49 }
50 }
51 double r = this->objective();
52 return r;
53 }
54
55 void TPcoords(double t, double lnT, double lnp, double& T, double& p) {
56 double rlnT = 0.1, rlnp = 0.1;
57 T = exp(lnT + rlnT * cos(t));
58 p = exp(lnp + rlnp * sin(t));
59 }
60
61 void trace(std::vector<double>& T, std::vector<double>& p) {
62 double t = this->starting_direction();
63 for (int i = 0; i < 1000; ++i) {
64 try {
65 this->lnT = log(this->T[this->T.size() - 1]);
66 this->lnp = log(this->p[this->p.size() - 1]);
67 this->obj = OBJECTIVE_CIRCLE;
68 t = Brent(this, t - M_PI / 2.0, t + M_PI / 2.0, DBL_EPSILON, 1e-10, 100);
69 double T2, P2;
70 this->TPcoords(t, this->lnT, this->lnp, T2, P2);
71 this->T.push_back(T2);
72 this->p.push_back(P2);
73 if (this->T[this->T.size() - 1] < this->AS->keyed_output(iT_triple)
74 || this->p[this->p.size() - 1] > 1000 * this->AS->keyed_output(iP_critical)) {
75 break;
76 }
77 } catch (std::exception&) {
78 break;
79 }
80 }
81 T = this->T;
82 p = this->p;
83 }
84};
85
87{
88 public:
90 init();
91 };
93 double objective() override {
94 return this->AS->keyed_output(iZ) - 1;
95 };
96};
97
99{
100 public:
102 init();
103 };
105 double objective() override {
106 double r =
107 (this->AS->p() - this->AS->rhomolar() * this->AS->first_partial_deriv(iP, iDmolar, iT)) / (this->AS->gas_constant() * this->AS->T());
108 return r;
109 };
110};
112{
113 public:
115 init();
116 };
118 double objective() override {
119 double r = (this->AS->gas_constant() * this->AS->T() * 1 / this->AS->rhomolar() * this->AS->first_partial_deriv(iP, iT, iDmolar)
120 - this->AS->p() * this->AS->gas_constant() / this->AS->rhomolar())
121 / POW2(this->AS->gas_constant() * this->AS->T());
122 return r;
123 };
124};
126{
127 public:
129 init();
130 };
132 double objective() override {
133 double dvdT__constp = -this->AS->first_partial_deriv(iDmolar, iT, iP) / POW2(this->AS->rhomolar());
134 double r = this->AS->p() / (this->AS->gas_constant() * POW2(this->AS->T())) * (this->AS->T() * dvdT__constp - 1 / this->AS->rhomolar());
135 return r;
136 };
137};
138
139} /* namespace CoolProp */