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