CoolProp
Helmholtz.h
1 
2 #ifndef HELMHOLTZ_H
3 #define HELMHOLTZ_H
4 
5 #include <vector>
6 #include "rapidjson_include.h"
7 //#include "Eigen/Core"
8 #include "time.h"
9 #include "CachedElement.h"
10 #include "Backends/Cubics/GeneralizedCubic.h"
11 #include "crossplatform_shared_ptr.h"
12 
13 namespace CoolProp{
14 
15 // #############################################################################
16 // #############################################################################
17 // #############################################################################
18 // RESIDUAL TERMS
19 // #############################################################################
20 // #############################################################################
21 // #############################################################################
22 
23 #define LIST_OF_DERIVATIVE_VARIABLES \
24  X(alphar) \
25  X(dalphar_ddelta) \
26  X(dalphar_dtau) \
27  X(d2alphar_ddelta2) \
28  X(d2alphar_dtau2) \
29  X(d2alphar_ddelta_dtau) \
30  X(d3alphar_ddelta3) \
31  X(d3alphar_ddelta_dtau2) \
32  X(d3alphar_ddelta2_dtau) \
33  X(d3alphar_dtau3) \
34  X(d4alphar_ddelta4) \
35  X(d4alphar_ddelta3_dtau) \
36  X(d4alphar_ddelta2_dtau2) \
37  X(d4alphar_ddelta_dtau3) \
38  X(d4alphar_dtau4) \
39  X(delta_x_dalphar_ddelta) \
40  X(tau_x_dalphar_dtau) \
41  X(delta2_x_d2alphar_ddelta2) \
42  X(deltatau_x_d2alphar_ddelta_dtau) \
43  X(tau2_x_d2alphar_dtau2) \
44 
45 
47 {
48  #define X(name) CoolPropDbl name;
49  LIST_OF_DERIVATIVE_VARIABLES
50  #undef X
51 
52  void reset(CoolPropDbl v){
53  #define X(name) name = v;
54  LIST_OF_DERIVATIVE_VARIABLES
55  #undef X
56  }
57  HelmholtzDerivatives operator+(const HelmholtzDerivatives &other) const
58  {
60  #define X(name) _new.name = name + other.name;
61  LIST_OF_DERIVATIVE_VARIABLES
62  #undef X
63  return _new;
64  }
65  HelmholtzDerivatives operator*(const CoolPropDbl &other) const
66  {
68  #define X(name) _new.name = name*other;
69  LIST_OF_DERIVATIVE_VARIABLES
70  #undef X
71  return _new;
72  }
73  HelmholtzDerivatives(){reset(0.0);};
75  double get(std::size_t itau, std::size_t idelta){
76  if (itau == 0){
77  if (idelta == 0){ return alphar; }
78  else if (idelta == 1){ return dalphar_ddelta; }
79  else if (idelta == 2){ return d2alphar_ddelta2; }
80  else if (idelta == 3){ return d3alphar_ddelta3; }
81  else if (idelta == 4){ return d4alphar_ddelta4; }
82  else { throw ValueError(); }
83  }
84  else if (itau == 1){
85  if (idelta == 0){ return dalphar_dtau; }
86  else if (idelta == 1){ return d2alphar_ddelta_dtau; }
87  else if (idelta == 2){ return d3alphar_ddelta2_dtau; }
88  else if (idelta == 3){ return d4alphar_ddelta3_dtau; }
89  else { throw ValueError(); }
90  }
91  else if (itau == 2){
92  if (idelta == 0){ return d2alphar_dtau2; }
93  else if (idelta == 1){ return d3alphar_ddelta_dtau2; }
94  else if (idelta == 2){ return d4alphar_ddelta2_dtau2; }
95  else { throw ValueError(); }
96  }
97  else if (itau == 3){
98  if (idelta == 0){ return d3alphar_dtau3; }
99  else if (idelta == 1){ return d4alphar_ddelta_dtau3; }
100  else { throw ValueError(); }
101  }
102  else if (itau == 4){
103  if (idelta == 0){ return d4alphar_dtau4; }
104  else { throw ValueError(); }
105  }
106  else { throw ValueError(); }
107  }
108 };
109 #undef LIST_OF_DERIVATIVE_VARIABLES
110 
112 
138 public:
139  BaseHelmholtzTerm(){};
140  virtual ~BaseHelmholtzTerm(){};
141 
143 
146  virtual CoolPropDbl base(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.alphar;};
148 
151  virtual CoolPropDbl dTau(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.dalphar_dtau;};
153 
156  virtual CoolPropDbl dTau2(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d2alphar_dtau2;};
158 
161  virtual CoolPropDbl dDelta_dTau(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d2alphar_ddelta_dtau;};
163 
166  virtual CoolPropDbl dDelta(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.dalphar_ddelta;};
168 
171  virtual CoolPropDbl dDelta2(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d2alphar_ddelta2;};
173 
176  virtual CoolPropDbl dDelta2_dTau(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d3alphar_ddelta2_dtau;};
178 
181  virtual CoolPropDbl dDelta_dTau2(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d3alphar_ddelta_dtau2;};
183 
186  virtual CoolPropDbl dTau3(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d3alphar_dtau3;};
188 
191  virtual CoolPropDbl dDelta3(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d3alphar_ddelta3;};
193 
196  virtual CoolPropDbl dTau4(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d4alphar_dtau4;};
197  virtual CoolPropDbl dDelta_dTau3(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d4alphar_ddelta_dtau3;};
198  virtual CoolPropDbl dDelta2_dTau2(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d4alphar_ddelta2_dtau2;};
199  virtual CoolPropDbl dDelta3_dTau(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d4alphar_ddelta3_dtau;};
200  virtual CoolPropDbl dDelta4(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){HelmholtzDerivatives deriv; all(tau,delta,deriv); return deriv.d4alphar_ddelta4;};
201 
202  virtual void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw() = 0;
203 };
204 
206 {
208  CoolPropDbl n,d,t;
211  CoolPropDbl c, l_double, omega, m_double, eta1, epsilon1, eta2, epsilon2, beta1, gamma1, beta2, gamma2;
213  int l_int, m_int;
215  bool l_is_int, m_is_int;
216 
218  {
219  n = 0; d = 0; t = 0; c = 0;
220  l_double = 0; omega = 0; m_double = 0;
221  eta1 = 0; epsilon1 = 0; eta2 = 0; epsilon2 = 0;
222  beta1 = 0; gamma1 = 0; beta2 = 0; gamma2 = 0;
223  l_int = 0; m_int = 0; l_is_int = false; m_is_int = true;
224  };
225 };
235 
236 public:
237  bool delta_li_in_u, tau_mi_in_u, eta1_in_u, eta2_in_u, beta1_in_u, beta2_in_u, finished;
238  std::vector<CoolPropDbl> s;
239  std::size_t N;
240 
241  // These variables are for the exp(u) part
242  // u is given by -c*delta^l_i-omega*tau^m_i-eta1*(delta-epsilon1)-eta2*(delta-epsilon2)^2-beta1*(tau-gamma1)-beta2*(tau-gamma2)^2
243  std::vector<double> n,d,t,c, l_double, omega, m_double, eta1, epsilon1, eta2, epsilon2, beta1, gamma1, beta2, gamma2;
244  // If l_i or m_i are integers, we will store them as integers in order to call pow(double, int) rather than pow(double, double)
245  std::vector<int> l_int, m_int;
246 
247  //Eigen::ArrayXd uE, du_ddeltaE, du_dtauE, d2u_ddelta2E, d2u_dtau2E, d3u_ddelta3E, d3u_dtau3E;
248 
249  std::vector<ResidualHelmholtzGeneralizedExponentialElement> elements;
250  // Default Constructor
252  : delta_li_in_u(false),tau_mi_in_u(false),eta1_in_u(false),
253  eta2_in_u(false),beta1_in_u(false),beta2_in_u(false),finished(false), N(0) {};
259  void add_Power(const std::vector<CoolPropDbl> &n, const std::vector<CoolPropDbl> &d,
260  const std::vector<CoolPropDbl> &t, const std::vector<CoolPropDbl> &l)
261  {
262  for (std::size_t i = 0; i < n.size(); ++i)
263  {
265  el.n = n[i];
266  el.d = d[i];
267  el.t = t[i];
268  el.l_double = l[i];
269  el.l_int = (int)el.l_double;
270  if (el.l_double > 0)
271  el.c = 1.0;
272  else
273  el.c = 0.0;
274  elements.push_back(el);
275  }
276  delta_li_in_u = true;
277  };
283  void add_Exponential(const std::vector<CoolPropDbl> &n, const std::vector<CoolPropDbl> &d,
284  const std::vector<CoolPropDbl> &t, const std::vector<CoolPropDbl> &g,
285  const std::vector<CoolPropDbl> &l)
286  {
287  for (std::size_t i = 0; i < n.size(); ++i)
288  {
290  el.n = n[i];
291  el.d = d[i];
292  el.t = t[i];
293  el.c = g[i];
294  el.l_double = l[i];
295  el.l_int = (int)el.l_double;
296  elements.push_back(el);
297  }
298  delta_li_in_u = true;
299  }
305  void add_Gaussian(const std::vector<CoolPropDbl> &n,
306  const std::vector<CoolPropDbl> &d,
307  const std::vector<CoolPropDbl> &t,
308  const std::vector<CoolPropDbl> &eta,
309  const std::vector<CoolPropDbl> &epsilon,
310  const std::vector<CoolPropDbl> &beta,
311  const std::vector<CoolPropDbl> &gamma
312  )
313  {
314  for (std::size_t i = 0; i < n.size(); ++i)
315  {
317  el.n = n[i];
318  el.d = d[i];
319  el.t = t[i];
320  el.eta2 = eta[i];
321  el.epsilon2 = epsilon[i];
322  el.beta2 = beta[i];
323  el.gamma2 = gamma[i];
324  elements.push_back(el);
325  }
326  eta2_in_u = true;
327  beta2_in_u = true;
328  };
334  void add_GERG2008Gaussian(const std::vector<CoolPropDbl> &n,
335  const std::vector<CoolPropDbl> &d,
336  const std::vector<CoolPropDbl> &t,
337  const std::vector<CoolPropDbl> &eta,
338  const std::vector<CoolPropDbl> &epsilon,
339  const std::vector<CoolPropDbl> &beta,
340  const std::vector<CoolPropDbl> &gamma)
341  {
342  for (std::size_t i = 0; i < n.size(); ++i)
343  {
345  el.n = n[i];
346  el.d = d[i];
347  el.t = t[i];
348  el.eta2 = eta[i];
349  el.epsilon2 = epsilon[i];
350  el.eta1 = beta[i];
351  el.epsilon1 = gamma[i];
352  elements.push_back(el);
353  }
354  eta2_in_u = true;
355  eta1_in_u = true;
356  };
362  void add_Lemmon2005(const std::vector<CoolPropDbl> &n,
363  const std::vector<CoolPropDbl> &d,
364  const std::vector<CoolPropDbl> &t,
365  const std::vector<CoolPropDbl> &l,
366  const std::vector<CoolPropDbl> &m)
367  {
368  for (std::size_t i = 0; i < n.size(); ++i)
369  {
371  el.n = n[i];
372  el.d = d[i];
373  el.t = t[i];
374  el.c = 1.0;
375  el.omega = 1.0;
376  el.l_double = l[i];
377  el.m_double = m[i];
378  el.l_int = (int)el.l_double;
379  el.m_int = (int)el.m_double;
380  elements.push_back(el);
381  }
382  delta_li_in_u = true;
383  tau_mi_in_u = true;
384  };
385 
386  void finish(){
387  n.resize(elements.size()); d.resize(elements.size());
388  t.resize(elements.size()); c.resize(elements.size());
389  omega.resize(elements.size());
390  l_double.resize(elements.size()); l_int.resize(elements.size());
391  m_double.resize(elements.size()); m_int.resize(elements.size());
392  epsilon2.resize(elements.size()); eta2.resize(elements.size());
393  gamma2.resize(elements.size()); beta2.resize(elements.size());
394 
395  for (std::size_t i = 0; i < elements.size(); ++i){
396  n[i] = elements[i].n;
397  d[i] = elements[i].d;
398  t[i] = elements[i].t;
399  c[i] = elements[i].c;
400  omega[i] = elements[i].omega;
401  l_double[i] = elements[i].l_double;
402  l_int[i] = elements[i].l_int;
403  m_double[i] = elements[i].m_double;
404  m_int[i] = elements[i].m_int;
405  epsilon2[i] = elements[i].epsilon2;
406  eta2[i] = elements[i].eta2;
407  gamma2[i] = elements[i].gamma2;
408  beta2[i] = elements[i].beta2;
409 
410  // See if l is an integer, and store a flag if it is
411  elements[i].l_is_int = ( std::abs(static_cast<long>(elements[i].l_double) - elements[i].l_double) < 1e-14 );
412  }
413 // uE.resize(elements.size());
414 // du_ddeltaE.resize(elements.size());
415 // du_dtauE.resize(elements.size());
416 // d2u_ddelta2E.resize(elements.size());
417 // d2u_dtau2E.resize(elements.size());
418 // d3u_ddelta3E.resize(elements.size());
419 // d3u_dtau3E.resize(elements.size());
420 
421  finished = true;
422  };
423 
424  void to_json(rapidjson::Value &el, rapidjson::Document &doc);
425 
426  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
427  //void allEigen(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
428 };
429 
431 {
432  CoolPropDbl n, a, b, beta, A, B, C, D;
433 };
435 
436 public:
437  std::size_t N;
438  std::vector<CoolPropDbl> s;
439  std::vector<ResidualHelmholtzNonAnalyticElement> elements;
445  ResidualHelmholtzNonAnalytic(const std::vector<CoolPropDbl> &n,
446  const std::vector<CoolPropDbl> &a,
447  const std::vector<CoolPropDbl> &b,
448  const std::vector<CoolPropDbl> &beta,
449  const std::vector<CoolPropDbl> &A,
450  const std::vector<CoolPropDbl> &B,
451  const std::vector<CoolPropDbl> &C,
452  const std::vector<CoolPropDbl> &D
453  )
454  {
455  N = n.size();
456  s.resize(N);
457  for (std::size_t i = 0; i < n.size(); ++i)
458  {
460  el.n = n[i];
461  el.a = a[i];
462  el.b = b[i];
463  el.beta = beta[i];
464  el.A = A[i];
465  el.B = B[i];
466  el.C = C[i];
467  el.D = D[i];
468  elements.push_back(el);
469  }
470  };
471  void to_json(rapidjson::Value &el, rapidjson::Document &doc);
472  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
473 };
474 
476 protected:
477  shared_ptr<AbstractCubic> m_abstractcubic;
478  std::vector<double> z;
479 public:
480  bool enabled;
481 
483  ResidualHelmholtzGeneralizedCubic() { enabled = false; };
485  ResidualHelmholtzGeneralizedCubic(shared_ptr<AbstractCubic> & ac) : m_abstractcubic(ac){
486  enabled = true;
487  z = std::vector<double>(1,1); // Init the vector to [1.0]
488  };
489 
490  void to_json(rapidjson::Value &el, rapidjson::Document &doc);
491  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
492 };
493 
494 
496 protected:
497  std::vector<double> n,t,d,eta,beta,gamma,epsilon,b;
498 public:
499  bool enabled;
500 
502  ResidualHelmholtzGaoB() { enabled = false; };
503 
506  const std::vector<CoolPropDbl> &n,
507  const std::vector<CoolPropDbl> &t,
508  const std::vector<CoolPropDbl> &d,
509  const std::vector<CoolPropDbl> &eta,
510  const std::vector<CoolPropDbl> &beta,
511  const std::vector<CoolPropDbl> &gamma,
512  const std::vector<CoolPropDbl> &epsilon,
513  const std::vector<CoolPropDbl> &b)
514  :n(n),t(t),d(d),eta(eta),beta(beta),gamma(gamma),epsilon(epsilon),b(b) {
515  enabled = true;
516  };
517 
518  void to_json(rapidjson::Value &el, rapidjson::Document &doc);
519  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
520 };
521 
524 
525 public:
526  bool enabled;
528  CoolPropDbl Tc, pc, rhomolarc, acentric, R, theta;
530  ResidualHelmholtzXiangDeiters() : Tc(_HUGE), pc(_HUGE), rhomolarc(_HUGE), acentric(_HUGE), R(_HUGE), theta(_HUGE)
531  {
532  enabled = false;
533  };
536  const CoolPropDbl Tc,
537  const CoolPropDbl pc,
538  const CoolPropDbl rhomolarc,
539  const CoolPropDbl acentric,
540  const CoolPropDbl R
541  );
542  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
543 };
544 
546 
547 protected:
548  double a, m,epsilonbar, vbarn, kappabar;
549 
550  CoolPropDbl Deltabar(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
551  CoolPropDbl dDeltabar_ddelta__consttau(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
552  CoolPropDbl d2Deltabar_ddelta2__consttau(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
553  CoolPropDbl dDeltabar_dtau__constdelta(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
554  CoolPropDbl d2Deltabar_dtau2__constdelta(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
555  CoolPropDbl d2Deltabar_ddelta_dtau(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
556  CoolPropDbl d3Deltabar_dtau3__constdelta(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
557  CoolPropDbl d3Deltabar_ddelta_dtau2(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
558  CoolPropDbl d3Deltabar_ddelta3__consttau(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
559  CoolPropDbl d3Deltabar_ddelta2_dtau(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
560 
561  CoolPropDbl X(const CoolPropDbl &delta, const CoolPropDbl &Deltabar) const;
562  CoolPropDbl dX_dDeltabar__constdelta(const CoolPropDbl &delta, const CoolPropDbl &Deltabar) const;
563  CoolPropDbl dX_ddelta__constDeltabar(const CoolPropDbl &delta, const CoolPropDbl &Deltabar) const;
564  CoolPropDbl dX_dtau(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
565  CoolPropDbl dX_ddelta(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
566  CoolPropDbl d2X_dtau2(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
567  CoolPropDbl d2X_ddeltadtau(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
568  CoolPropDbl d2X_ddelta2(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
569 
570  CoolPropDbl d3X_dtau3(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
571  CoolPropDbl d3X_ddelta3(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
572  CoolPropDbl d3X_ddeltadtau2(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
573  CoolPropDbl d3X_ddelta2dtau(const CoolPropDbl &tau, const CoolPropDbl &delta) const;
574 
575  CoolPropDbl g(const CoolPropDbl &eta) const;
576  CoolPropDbl dg_deta(const CoolPropDbl &eta) const;
577  CoolPropDbl d2g_deta2(const CoolPropDbl &eta) const;
578  CoolPropDbl d3g_deta3(const CoolPropDbl &eta) const;
579  CoolPropDbl eta(const CoolPropDbl &delta) const;
580 
581 public:
583  ResidualHelmholtzSAFTAssociating() : a(_HUGE), m(_HUGE), epsilonbar(_HUGE), vbarn(_HUGE), kappabar(_HUGE)
584  { disabled = true; };
585 
586  // Constructor
587  ResidualHelmholtzSAFTAssociating(double a, double m, double epsilonbar, double vbarn, double kappabar)
588  : a(a), m(m), epsilonbar(epsilonbar), vbarn(vbarn), kappabar(kappabar)
589  {
590  disabled = false;
591  };
592 
593  bool disabled;
594 
595  //Destructor. No Implementation
597 
598  void to_json(rapidjson::Value &el, rapidjson::Document &doc);
599 
600  CoolPropDbl dTau4(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 1e99;};
601  CoolPropDbl dDelta_dTau3(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 1e99;};
602  CoolPropDbl dDelta2_dTau2(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 1e99;};
603  CoolPropDbl dDelta3_dTau(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 1e99;};
604  CoolPropDbl dDelta4(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 1e99;};
605 
606  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &deriv) throw();
607 };
608 
610 protected:
611  CachedElement _base, _dDelta, _dTau, _dDelta2, _dTau2, _dDelta_dTau, _dDelta3, _dDelta2_dTau, _dDelta_dTau2, _dTau3;
612  CachedElement _dDelta4, _dDelta3_dTau, _dDelta2_dTau2, _dDelta_dTau3, _dTau4;
613 public:
614  void clear(){
615  _base.clear();
616  _dDelta.clear(); _dTau.clear();
617  _dDelta2.clear(); _dTau2.clear(); _dDelta_dTau.clear();
618  _dDelta3.clear(); _dTau3.clear(); _dDelta2_dTau.clear(); _dDelta_dTau2.clear();
619  _dDelta4.clear(); _dDelta3_dTau.clear(); _dDelta2_dTau2.clear(); _dDelta_dTau3.clear(); _dTau4.clear();
620  };
621 
622  virtual void empty_the_EOS() = 0;
623  virtual HelmholtzDerivatives all(const CoolPropDbl tau, const CoolPropDbl delta, bool cache_values) = 0;
624 
625  CoolPropDbl base(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) {
626  if (!_base || dont_use_cache)
627  return all(tau, delta, false).alphar;
628  else
629  return _base;
630  };
631  CoolPropDbl dDelta(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) {
632  if (!_dDelta || dont_use_cache)
633  return all(tau, delta, false).dalphar_ddelta;
634  else
635  return _dDelta;
636  };
637  CoolPropDbl dTau(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) {
638  if (!_dTau || dont_use_cache)
639  return all(tau, delta, false).dalphar_dtau;
640  else
641  return _dTau;
642  };
643  CoolPropDbl dDelta2(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) {
644  if (!_dDelta2 || dont_use_cache)
645  return all(tau, delta, false).d2alphar_ddelta2;
646  else
647  return _dDelta2;
648  };
649  CoolPropDbl dDelta_dTau(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) {
650  if (!_dDelta_dTau || dont_use_cache)
651  return all(tau, delta, false).d2alphar_ddelta_dtau;
652  else
653  return _dDelta_dTau;
654  };
655  CoolPropDbl dTau2(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) {
656  if (!_dTau2 || dont_use_cache)
657  return all(tau, delta, false).d2alphar_dtau2;
658  else
659  return _dTau2;
660  };
661  CoolPropDbl dDelta3(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) {
662  if (!_dDelta3 || dont_use_cache)
663  return all(tau, delta, false).d3alphar_ddelta3;
664  else
665  return _dDelta3;
666  };
667  CoolPropDbl dDelta2_dTau(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) {
668  if (!_dDelta2_dTau || dont_use_cache)
669  return all(tau, delta, false).d3alphar_ddelta2_dtau;
670  else
671  return _dDelta2_dTau;
672  };
673  CoolPropDbl dDelta_dTau2(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) {
674  if (!_dDelta_dTau2 || dont_use_cache)
675  return all(tau, delta, false).d3alphar_ddelta_dtau2;
676  else
677  return _dDelta_dTau2;
678  };
679  CoolPropDbl dTau3(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) {
680  if (!_dTau3 || dont_use_cache)
681  return all(tau, delta, false).d3alphar_dtau3;
682  else
683  return _dTau3;
684  };
685  CoolPropDbl dDelta4(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) { return all(tau, delta, false).d4alphar_ddelta4; };
686  CoolPropDbl dDelta3_dTau(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) { return all(tau, delta, false).d4alphar_ddelta3_dtau; };
687  CoolPropDbl dDelta2_dTau2(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) { return all(tau, delta, false).d4alphar_ddelta2_dtau2; };
688  CoolPropDbl dDelta_dTau3(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) { return all(tau, delta, false).d4alphar_ddelta_dtau3; };
689  CoolPropDbl dTau4(CoolPropDbl tau, CoolPropDbl delta, const bool dont_use_cache = false) { return all(tau, delta, false).d4alphar_dtau4; };
690 };
691 
693 {
694 public:
695  ResidualHelmholtzNonAnalytic NonAnalytic;
699  ResidualHelmholtzXiangDeiters XiangDeiters;
701 
702  void empty_the_EOS(){
703  NonAnalytic = ResidualHelmholtzNonAnalytic();
707  XiangDeiters = ResidualHelmholtzXiangDeiters();
708  GaoB = ResidualHelmholtzGaoB();
709  };
710 
711  HelmholtzDerivatives all(const CoolPropDbl tau, const CoolPropDbl delta, bool cache_values = false)
712  {
713  HelmholtzDerivatives derivs; // zeros out the elements
714  GenExp.all(tau, delta, derivs);
715  NonAnalytic.all(tau, delta, derivs);
716  SAFT.all(tau, delta, derivs);
717  cubic.all(tau, delta, derivs);
718  XiangDeiters.all(tau, delta, derivs);
719  GaoB.all(tau, delta, derivs);
720  if (cache_values){
721  _base = derivs.alphar;
722  _dDelta = derivs.dalphar_ddelta;
723  _dTau = derivs.dalphar_dtau;
724  _dDelta2 = derivs.d2alphar_ddelta2;
725  _dTau2 = derivs.d2alphar_dtau2;
726  _dDelta_dTau = derivs.d2alphar_ddelta_dtau;
727  _dDelta3 = derivs.d3alphar_ddelta3;
728  _dTau3 = derivs.d3alphar_dtau3;
729  _dDelta2_dTau = derivs.d3alphar_ddelta2_dtau;
730  _dDelta_dTau2 = derivs.d3alphar_ddelta_dtau2;
731  }
732  return derivs;
733  };
734 };
735 
736 // #############################################################################
737 // #############################################################################
738 // #############################################################################
739 // IDEAL GAS TERMS
740 // #############################################################################
741 // #############################################################################
742 // #############################################################################
743 
745 
751 
752 private:
753  CoolPropDbl a1, a2;
754  bool enabled;
755 public:
756  // Default constructor
757  IdealHelmholtzLead() :a1(_HUGE), a2(_HUGE), enabled(false) {}
758 
759  // Constructor
760  IdealHelmholtzLead(CoolPropDbl a1, CoolPropDbl a2)
761  :a1(a1), a2(a2), enabled(true) {}
762 
763  bool is_enabled() const {return enabled;}
764 
765  void to_json(rapidjson::Value &el, rapidjson::Document &doc){
766  el.AddMember("type","IdealHelmholtzLead",doc.GetAllocator());
767  el.AddMember("a1", static_cast<double>(a1), doc.GetAllocator());
768  el.AddMember("a2", static_cast<double>(a2), doc.GetAllocator());
769  };
770 
771  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
772 
773 };
774 
776 
782 private:
783  CoolPropDbl a1,a2; // Use these variables internally
784  std::string reference;
785  bool enabled;
786 public:
787  IdealHelmholtzEnthalpyEntropyOffset():a1(_HUGE),a2(_HUGE),enabled(false){}
788 
789  // Constructor
790  IdealHelmholtzEnthalpyEntropyOffset(CoolPropDbl a1, CoolPropDbl a2, const std::string &ref):a1(a1),a2(a2),reference(ref),enabled(true) {}
791 
792  // Set the values in the class
793  void set(CoolPropDbl a1, CoolPropDbl a2, const std::string &ref){
794  // If it doesn't already exist, just set the values
795  if (enabled == false){
796  this->a1 = a1; this->a2 = a2;
797  enabled = true;
798  }
799  else if(ref == "DEF"){
800  this->a1 = 0.0; this->a2 = 0.0; enabled = false;
801  }
802  else{
803  // Otherwise, increment the values
804  this->a1 += a1; this->a2 += a2;
805  enabled = true;
806  }
807  this->reference = ref;
808  }
809 
810  bool is_enabled() const {return enabled;};
811 
812  void to_json(rapidjson::Value &el, rapidjson::Document &doc){
813  el.AddMember("type","IdealHelmholtzEnthalpyEntropyOffset",doc.GetAllocator());
814  el.AddMember("a1", static_cast<double>(a1), doc.GetAllocator());
815  el.AddMember("a2", static_cast<double>(a2), doc.GetAllocator());
816  };
817  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
818 };
819 
820 
827 {
828 private:
829  CoolPropDbl a1;
830  bool enabled;
831 public:
832 
834  IdealHelmholtzLogTau():a1(_HUGE),enabled(false){}
835 
836  // Constructor
837  IdealHelmholtzLogTau(CoolPropDbl a1):a1(a1),enabled(true){}
838 
839  bool is_enabled() const {return enabled;};
840 
841  void to_json(rapidjson::Value &el, rapidjson::Document &doc){
842  el.AddMember("type", "IdealHelmholtzLogTau", doc.GetAllocator());
843  el.AddMember("a1", static_cast<double>(a1), doc.GetAllocator());
844  };
845  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
846 };
847 
854 
855 private:
856  std::vector<CoolPropDbl> n, t; // Use these variables internally
857  std::size_t N;
858  bool enabled;
859 public:
860  IdealHelmholtzPower():N(0),enabled(false){};
861  // Constructor
862  IdealHelmholtzPower(const std::vector<CoolPropDbl> &n, const std::vector<CoolPropDbl> &t)
863  :n(n), t(t), N(n.size()), enabled(true) {};
864 
865  bool is_enabled() const {return enabled;};
866 
867  void to_json(rapidjson::Value &el, rapidjson::Document &doc)
868  {
869  el.AddMember("type","IdealHelmholtzPower",doc.GetAllocator());
870  cpjson::set_long_double_array("n",n,el,doc);
871  cpjson::set_long_double_array("t",t,el,doc);
872  };
873  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
874 };
875 
923 
924 private:
925  std::vector<CoolPropDbl> n,theta,c,d; // Use these variables internally
926  std::size_t N;
927  bool enabled;
928 public:
929  IdealHelmholtzPlanckEinsteinGeneralized():N(0),enabled(false){}
930  // Constructor with std::vector instances
931  IdealHelmholtzPlanckEinsteinGeneralized(const std::vector<CoolPropDbl> &n, const std::vector<CoolPropDbl> &theta, const std::vector<CoolPropDbl> &c, const std::vector<CoolPropDbl> &d)
932  :n(n), theta(theta), c(c), d(d), N(n.size()), enabled(true) {}
933 
934  // Extend the vectors to allow for multiple instances feeding values to this function
935  void extend(const std::vector<CoolPropDbl> &n, const std::vector<CoolPropDbl> &theta, const std::vector<CoolPropDbl> &c, const std::vector<CoolPropDbl> &d)
936  {
937  this->n.insert(this->n.end(), n.begin(), n.end());
938  this->theta.insert(this->theta.end(), theta.begin(), theta.end());
939  this->c.insert(this->c.end(), c.begin(), c.end());
940  this->d.insert(this->d.end(), d.begin(), d.end());
941  N += n.size();
942  }
943 
944  bool is_enabled() const {return enabled;};
945 
946  void to_json(rapidjson::Value &el, rapidjson::Document &doc)
947  {
948  el.AddMember("type","IdealHelmholtzPlanckEinsteinGeneralized",doc.GetAllocator());
949  cpjson::set_long_double_array("n",n,el,doc);
950  cpjson::set_long_double_array("theta",theta,el,doc);
951  };
952  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
953 };
954 
956 
957 private:
958  double cp_over_R,Tc,T0,tau0; // Use these variables internally
959  bool enabled;
960 public:
962  IdealHelmholtzCP0Constant() : cp_over_R(_HUGE), Tc(_HUGE), T0(_HUGE), tau0(_HUGE)
963  {enabled = false;};
964 
966  IdealHelmholtzCP0Constant(CoolPropDbl cp_over_R, CoolPropDbl Tc, CoolPropDbl T0)
967  : cp_over_R(cp_over_R), Tc(Tc), T0(T0)
968  {
969  enabled = true; tau0 = Tc/T0;
970  };
971 
974 
975  bool is_enabled() const {return enabled;};
976 
977  void to_json(rapidjson::Value &el, rapidjson::Document &doc)
978  {
979  el.AddMember("type","IdealGasHelmholtzCP0Constant", doc.GetAllocator());
980  el.AddMember("cp_over_R", cp_over_R, doc.GetAllocator());
981  el.AddMember("Tc", Tc, doc.GetAllocator());
982  el.AddMember("T0", T0, doc.GetAllocator());
983  };
984 
985  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
986 };
987 
989 private:
990  std::vector<CoolPropDbl> c, t;
991  CoolPropDbl Tc, T0, tau0; // Use these variables internally
992  std::size_t N;
993  bool enabled;
994 public:
996  : Tc(_HUGE), T0(_HUGE), tau0(_HUGE), N(0), enabled(false) {}
997 
999  IdealHelmholtzCP0PolyT(const std::vector<CoolPropDbl> &c, const std::vector<CoolPropDbl> &t, double Tc, double T0)
1000  : c(c), t(t), Tc(Tc), T0(T0), tau0(Tc/T0), N(c.size()), enabled(true)
1001  { assert(c.size() == t.size()); }
1002 
1003  void extend(const std::vector<CoolPropDbl> &c, const std::vector<CoolPropDbl> &t)
1004  {
1005  this->c.insert(this->c.end(), c.begin(), c.end());
1006  this->t.insert(this->t.end(), t.begin(), t.end());
1007  N += c.size();
1008  }
1009 
1010  bool is_enabled() const {return enabled;};
1011 
1012  void to_json(rapidjson::Value &el, rapidjson::Document &doc);
1013  void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs) throw();
1014 };
1015 
1018 //\f[
1019 //\frac{c_p^0}{R_u} = A + B\left(\frac{C/T}{\sinh(C/T)}\right)^2 + D\left(\frac{E/T}{\cosh(E/T)}\right)^2
1020 //\f]
1021 //Second partial of ideal-gas Helmholtz energy given directly by specific heat (\f$\displaystyle\alpha_{\tau\tau}^0=-\frac{1}{\tau^2}\frac{c_p^0}{R_u} \f$) - this is obtained by real gas \f$c_p\f$ relationship, and killing off residual Helmholtz terms
1022 //\f[
1023 //\alpha^0_{\tau\tau} = -\frac{A}{\tau^2} - \frac{B}{\tau^2}\left(\frac{C/T}{\sinh(C/T)}\right)^2 - \frac{D}{\tau^2}\left(\frac{E/T}{\cosh(E/T)}\right)^2
1024 //\f]
1025 //or in terms of \f$ \tau \f$:
1026 //\f[
1027 //\alpha^0_{\tau\tau} = -\frac{A}{\tau^2} - \frac{BC^2}{T_c^2}\left(\frac{1}{\sinh(C\tau/T_c)}\right)^2 - \frac{DE^2}{T_c^2}\left(\frac{1}{\cosh(E\tau/T_c)}\right)^2
1028 //\f]
1029 //Third partial:
1030 //\f[
1031 //\alpha^0_{\tau\tau\tau} = 2\frac{A}{\tau^3} + 2\frac{BC^3}{T_c^3}\frac{\cosh(C\tau/T_c)}{\sinh^3(C\tau/T_c)} +2 \frac{DE^3}{T_c^3}\frac{\sinh(E\tau/T_c)}{\cosh^3(E\tau/T_c)}
1032 //\f]
1033 //Now coming back to the ideal gas Helmholtz energy definition:
1034 //\f[
1035 //\alpha^0 = -\tau\displaystyle\int_{\tau_0}^{\tau} \frac{1}{\tau^2}\frac{c_p^0}{R_u}d\tau+\displaystyle\int_{\tau_0}^{\tau} \frac{1}{\tau}\frac{c_p^0}{R_u}d\tau
1036 //\f]
1037 //Applying derivative
1038 //\f[
1039 //\alpha^0_{\tau} = -\displaystyle\int_{\tau_0}^{\tau} \frac{1}{\tau^2}\frac{c_p^0}{R_u}d\tau-\tau\frac{\partial}{\partial \tau}\left[\displaystyle\int_{\tau_0}^{\tau} \frac{1}{\tau^2}\frac{c_p^0}{R_u}d\tau \right]+\frac{\partial}{\partial \tau}\left[\displaystyle\int_{\tau_0}^{\tau} \frac{1}{\tau}\frac{c_p^0}{R_u}d\tau \right]
1040 //\f]
1041 //Fundamental theorem of calculus
1042 //\f[
1043 //\alpha^0_{\tau} = -\int_{\tau_0}^{\tau} \frac{1}{\tau^2}\frac{c_p^0}{R_u}d\tau-\tau \frac{1}{\tau^2}\frac{c_p^0}{R_u}d\tau+\frac{1}{\tau}\frac{c_p^0}{R_u}
1044 //\f]
1045 //Last two terms cancel, leaving
1046 //\f[
1047 //\alpha^0_{\tau} = -\int_{\tau_0}^{\tau} \frac{1}{\tau^2}\frac{c_p^0}{R_u}d\tau
1048 //\f]
1049 //Another derivative yields (from fundamental theorem of calculus)
1050 //\f[
1051 //\alpha^0_{\tau\tau} = - \frac{1}{\tau^2}\frac{c_p^0}{R_u}
1052 //\f]
1053 //
1054 //see also Jaeschke and Schley, 1995, (http://link.springer.com/article/10.1007%2FBF02083547#page-1)
1055 //*/
1057 //class IdealHelmholtzCP0AlyLee : public BaseHelmholtzTerm{
1058 //private:
1059 // std::vector<CoolPropDbl> c;
1060 // CoolPropDbl Tc, tau0, T0; // Use these variables internally
1061 // bool enabled;
1062 //public:
1063 // IdealHelmholtzCP0AlyLee(){enabled = false;};
1064 //
1065 // /// Constructor with std::vectors
1066 // IdealHelmholtzCP0AlyLee(const std::vector<CoolPropDbl> &c, double Tc, double T0)
1067 // :c(c), Tc(Tc), T0(T0)
1068 // {
1069 // tau0=Tc/T0;
1070 // enabled = true;
1071 // };
1072 //
1073 // /// Destructor
1074 // ~IdealHelmholtzCP0AlyLee(){};
1075 //
1076 // bool is_enabled() const {return enabled;};
1077 //
1078 // void to_json(rapidjson::Value &el, rapidjson::Document &doc);
1079 //
1080 //
1081 // /// The antiderivative given by \f$ \displaystyle\int \frac{1}{\tau^2}\frac{c_p^0}{R_u}d\tau \f$
1082 // /**
1083 // sympy code for this derivative:
1084 //
1085 // from sympy import *
1086 // a1,a2,a3,a4,a5,Tc,tau = symbols('a1,a2,a3,a4,a5,Tc,tau', real = True)
1087 // integrand = a1 + a2*(a3/Tc/sinh(a3*tau/Tc))**2 + a4*(a5/Tc/cosh(a5*tau/Tc))**2
1088 // integrand = integrand.rewrite(exp)
1089 // antideriv = trigsimp(integrate(integrand,tau))
1090 // display(antideriv)
1091 // print latex(antideriv)
1092 // print ccode(antideriv)
1093 //
1094 // \f[
1095 // \displaystyle\int \frac{1}{\tau^2}\frac{c_p^0}{R_u}d\tau = -\frac{a_0}{\tau}+\frac{2a_1a_2}{T_c\left[\exp\left(-\frac{2a_2\tau}{T_c}\right)-1\right]}+\frac{2a_3a_4}{T_c\left[\exp\left(-\frac{2a_4\tau}{T_c}\right)+1\right]}
1096 // \f]
1097 // */
1098 // CoolPropDbl anti_deriv_cp0_tau2(const CoolPropDbl &tau);
1099 //
1100 // /// The antiderivative given by \f$ \displaystyle\int \frac{1}{\tau}\frac{c_p^0}{R_u}d\tau \f$
1101 // /**
1102 // sympy code for this derivative:
1103 //
1104 // a_0,a_1,a_2,a_3,a_4,Tc,tau = symbols('a_0,a_1,a_2,a_3,a_4,Tc,tau', real = True)
1105 // integrand = a_0/tau + a_1/tau*(a_2*tau/Tc/sinh(a_2*tau/Tc))**2 + a_3/tau*(a_4*tau/Tc/cosh(a_4*tau/Tc))**2
1106 //
1107 // term2 = a_1/tau*(a_2*tau/Tc/sinh(a_2*tau/Tc))**2
1108 // term2 = term2.rewrite(exp) # Unpack the sinh to exp functions
1109 // antideriv2 = trigsimp(integrate(term2,tau))
1110 // display(antideriv2)
1111 // print latex(antideriv2)
1112 // print ccode(antideriv2)
1113 //
1114 // term3 = a_3/tau*(a_4*tau/Tc/cosh(a_4*tau/Tc))**2
1115 // term3 = term3.rewrite(exp) # Unpack the cosh to exp functions
1116 // antideriv3 = factor(trigsimp(integrate(term3,tau).rewrite(exp)))
1117 // display(antideriv3)
1118 // print latex(antideriv3)
1119 // print ccode(antideriv3)
1120 //
1121 // Can be broken into three parts (trick is to express \f$sinh\f$ and \f$cosh\f$ in terms of \f$exp\f$ function)
1122 //
1123 // Term 2:
1124 // \f[
1125 // \displaystyle\int \frac{a_1a_2^2}{T_c^2}\frac{\tau}{\sinh\left(\displaystyle\frac{a_2\tau}{T_c}\right)^2} d\tau = \frac{2 a_{1} a_{2} \tau}{- Tc + Tc e^{- \frac{2 a_{2}}{Tc} \tau}} + a_{1} \log{\left (-1 + e^{- \frac{2 a_{2}}{Tc} \tau} \right )} + \frac{2 a_{1}}{Tc} a_{2} \tau
1126 // \f]
1127 //
1128 // Term 3:
1129 // \f[
1130 // \displaystyle\int \frac{a_1a_2^2}{T_c^2}\frac{\tau}{\cosh\left(\displaystyle\frac{a_2\tau}{T_c}\right)^2} d\tau = - \frac{a_{3}}{Tc \left(e^{\frac{2 a_{4}}{Tc} \tau} + 1\right)} \left(Tc e^{\frac{2 a_{4}}{Tc} \tau} \log{\left (e^{\frac{2 a_{4}}{Tc} \tau} + 1 \right )} + Tc \log{\left (e^{\frac{2 a_{4}}{Tc} \tau} + 1 \right )} - 2 a_{4} \tau e^{\frac{2 a_{4}}{Tc} \tau}\right)
1131 // \f]
1132 // */
1133 // CoolPropDbl anti_deriv_cp0_tau(const CoolPropDbl &tau);
1134 //
1135 // CoolPropDbl base(const CoolPropDbl &tau, const CoolPropDbl &delta) throw();
1136 // CoolPropDbl dDelta(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 0.0;};
1137 // CoolPropDbl dTau(const CoolPropDbl &tau, const CoolPropDbl &delta) throw();
1138 // CoolPropDbl dDelta2(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 0.0;};
1139 // CoolPropDbl dDelta_dTau(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 0.0;};
1140 // CoolPropDbl dTau2(const CoolPropDbl &tau, const CoolPropDbl &delta) throw();
1141 // CoolPropDbl dDelta3(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 0.0;};
1142 // CoolPropDbl dDelta2_dTau(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 0.0;};
1143 // CoolPropDbl dDelta_dTau2(const CoolPropDbl &tau, const CoolPropDbl &delta) throw(){return 0.0;};
1144 // CoolPropDbl dTau3(const CoolPropDbl &tau, const CoolPropDbl &delta) throw();
1145 // CoolPropDbl dTau4(const CoolPropDbl &tau, const CoolPropDbl &delta) throw();
1146 //
1147 //};
1148 
1150  {
1151  public:
1152  IdealHelmholtzLead Lead;
1153  IdealHelmholtzEnthalpyEntropyOffset EnthalpyEntropyOffsetCore, EnthalpyEntropyOffset;
1154  IdealHelmholtzLogTau LogTau;
1155  IdealHelmholtzPower Power;
1157 
1158  IdealHelmholtzCP0Constant CP0Constant;
1159  IdealHelmholtzCP0PolyT CP0PolyT;
1160 
1161  void empty_the_EOS(){
1162  Lead = IdealHelmholtzLead();
1163  EnthalpyEntropyOffsetCore = IdealHelmholtzEnthalpyEntropyOffset();
1164  EnthalpyEntropyOffset = IdealHelmholtzEnthalpyEntropyOffset();
1165  LogTau = IdealHelmholtzLogTau();
1166  Power = IdealHelmholtzPower();
1167  PlanckEinstein = IdealHelmholtzPlanckEinsteinGeneralized();
1168  CP0Constant = IdealHelmholtzCP0Constant();
1169  CP0PolyT = IdealHelmholtzCP0PolyT();
1170  };
1171 
1172  HelmholtzDerivatives all(const CoolPropDbl tau, const CoolPropDbl delta, bool cache_values = false)
1173  {
1174  HelmholtzDerivatives derivs; // zeros out the elements
1175  Lead.all(tau, delta, derivs);
1176  EnthalpyEntropyOffsetCore.all(tau, delta, derivs);
1177  EnthalpyEntropyOffset.all(tau, delta, derivs);
1178  LogTau.all(tau, delta, derivs);
1179  Power.all(tau, delta, derivs);
1180  PlanckEinstein.all(tau, delta, derivs);
1181  CP0Constant.all(tau, delta, derivs);
1182  CP0PolyT.all(tau, delta, derivs);
1183 
1184  if (cache_values){
1185  _base = derivs.alphar;
1186  _dDelta = derivs.dalphar_ddelta;
1187  _dTau = derivs.dalphar_dtau;
1188  _dDelta2 = derivs.d2alphar_ddelta2;
1189  _dTau2 = derivs.d2alphar_dtau2;
1190  _dDelta_dTau = derivs.d2alphar_ddelta_dtau;
1191  _dDelta3 = derivs.d3alphar_ddelta3;
1192  _dTau3 = derivs.d3alphar_dtau3;
1193  _dDelta2_dTau = derivs.d3alphar_ddelta2_dtau;
1194  _dDelta_dTau2 = derivs.d3alphar_ddelta_dtau2;
1195  }
1196  return derivs;
1197  };
1198  };
1199 }; /* namespace CoolProp */
1200 
1201 #endif
A generalized residual helmholtz energy container that can deal with a wide range of terms which can ...
Definition: Helmholtz.h:234
Definition: Helmholtz.h:609
ResidualHelmholtzGaoB(const std::vector< CoolPropDbl > &n, const std::vector< CoolPropDbl > &t, const std::vector< CoolPropDbl > &d, const std::vector< CoolPropDbl > &eta, const std::vector< CoolPropDbl > &beta, const std::vector< CoolPropDbl > &gamma, const std::vector< CoolPropDbl > &epsilon, const std::vector< CoolPropDbl > &b)
Constructor given coefficients.
Definition: Helmholtz.h:505
void add_Gaussian(const std::vector< CoolPropDbl > &n, const std::vector< CoolPropDbl > &d, const std::vector< CoolPropDbl > &t, const std::vector< CoolPropDbl > &eta, const std::vector< CoolPropDbl > &epsilon, const std::vector< CoolPropDbl > &beta, const std::vector< CoolPropDbl > &gamma)
Add and convert an old-style Gaussian term to generalized form.
Definition: Helmholtz.h:305
ResidualHelmholtzGeneralizedCubic()
Default Constructor.
Definition: Helmholtz.h:483
The base class class for the Helmholtz energy terms.
Definition: Helmholtz.h:137
ResidualHelmholtzNonAnalytic(const std::vector< CoolPropDbl > &n, const std::vector< CoolPropDbl > &a, const std::vector< CoolPropDbl > &b, const std::vector< CoolPropDbl > &beta, const std::vector< CoolPropDbl > &A, const std::vector< CoolPropDbl > &B, const std::vector< CoolPropDbl > &C, const std::vector< CoolPropDbl > &D)
Constructor.
Definition: Helmholtz.h:445
bool enabled
Vector of mole fractions, will be initialized to [1.0] since this is a pure fluid.
Definition: Helmholtz.h:480
virtual CoolPropDbl dTau3(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the third partial derivative of Helmholtz energy term with respect to tau [-]...
Definition: Helmholtz.h:186
void add_Power(const std::vector< CoolPropDbl > &n, const std::vector< CoolPropDbl > &d, const std::vector< CoolPropDbl > &t, const std::vector< CoolPropDbl > &l)
Add and convert an old-style power (polynomial) term to generalized form.
Definition: Helmholtz.h:259
ResidualHelmholtzGaoB()
Default Constructor.
Definition: Helmholtz.h:502
Term in the ideal-gas specific heat equation that is based on Aly-Lee formulation ** Specific heat is...
Definition: Helmholtz.h:1149
Definition: Helmholtz.h:988
Definition: Helmholtz.h:826
Definition: Helmholtz.h:495
Definition: Helmholtz.h:434
The leading term in the EOS used to set the desired reference state.
Definition: Helmholtz.h:750
Definition: Exceptions.h:26
IdealHelmholtzCP0Constant()
Default constructor.
Definition: Helmholtz.h:962
Definition: Helmholtz.h:853
ResidualHelmholtzSAFTAssociating()
Default constructor.
Definition: Helmholtz.h:583
void all(const CoolPropDbl &tau, const CoolPropDbl &delta, HelmholtzDerivatives &derivs)
Sympy code:
Definition: Helmholtz.cpp:542
virtual CoolPropDbl dDelta2_dTau(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the third mixed partial derivative (delta2,dtau1) of Helmholtz energy term with respect to de...
Definition: Helmholtz.h:176
void add_Lemmon2005(const std::vector< CoolPropDbl > &n, const std::vector< CoolPropDbl > &d, const std::vector< CoolPropDbl > &t, const std::vector< CoolPropDbl > &l, const std::vector< CoolPropDbl > &m)
Add and convert a term from Lemmon and Jacobsen (2005) used for R125.
Definition: Helmholtz.h:362
CoolPropDbl n
These variables are for the n*delta^d_i*tau^t_i part.
Definition: Helmholtz.h:208
void add_GERG2008Gaussian(const std::vector< CoolPropDbl > &n, const std::vector< CoolPropDbl > &d, const std::vector< CoolPropDbl > &t, const std::vector< CoolPropDbl > &eta, const std::vector< CoolPropDbl > &epsilon, const std::vector< CoolPropDbl > &beta, const std::vector< CoolPropDbl > &gamma)
Add and convert an old-style Gaussian term from GERG 2008 natural gas model to generalized form...
Definition: Helmholtz.h:334
CoolPropDbl c
These variables are for the exp(u) part u is given by -c*delta^l_i-omega*tau^m_i-eta1*(delta-epsilon1...
Definition: Helmholtz.h:211
virtual CoolPropDbl dDelta(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the first partial derivative of Helmholtz energy term with respect to delta [-]...
Definition: Helmholtz.h:166
void clear()
Clear the flag and the value.
Definition: CachedElement.h:74
virtual CoolPropDbl dDelta_dTau(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the second mixed partial derivative (delta1,dtau1) of Helmholtz energy term with respect to d...
Definition: Helmholtz.h:161
Definition: Helmholtz.h:46
Definition: Helmholtz.h:692
virtual CoolPropDbl dDelta_dTau2(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the third mixed partial derivative (delta1,dtau2) of Helmholtz energy term with respect to de...
Definition: Helmholtz.h:181
ResidualHelmholtzXiangDeiters()
Default Constructor.
Definition: Helmholtz.h:530
~IdealHelmholtzCP0Constant()
Destructor.
Definition: Helmholtz.h:973
virtual CoolPropDbl base(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the base, non-dimensional, Helmholtz energy term (no derivatives) [-].
Definition: Helmholtz.h:146
int l_int
If l_i or m_i are integers, we will store them as integers in order to call pow(double, int) rather than pow(double, double)
Definition: Helmholtz.h:213
The term in the EOS used to shift the reference state of the fluid.
Definition: Helmholtz.h:781
The generalized Lee-Kesler formulation of Xiang & Deiters: doi:10.1016/j.ces.2007.11.029.
Definition: Helmholtz.h:523
~ResidualHelmholtzNonAnalytic()
Destructor. No implementation.
Definition: Helmholtz.h:443
virtual CoolPropDbl dTau4(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the fourth partial derivative of Helmholtz energy term with respect to tau [-]...
Definition: Helmholtz.h:196
bool l_is_int
If l is an integer, store a boolean flag so we can evaluate the correct pow() function.
Definition: Helmholtz.h:215
virtual CoolPropDbl dDelta3(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the third partial derivative of Helmholtz energy term with respect to delta [-]...
Definition: Helmholtz.h:191
virtual CoolPropDbl dDelta2(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the second partial derivative of Helmholtz energy term with respect to delta [-]...
Definition: Helmholtz.h:171
ResidualHelmholtzNonAnalytic()
Default Constructor.
Definition: Helmholtz.h:441
virtual CoolPropDbl dTau(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the first partial derivative of Helmholtz energy term with respect to tau [-]...
Definition: Helmholtz.h:151
CoolPropDbl dTau4(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the fourth partial derivative of Helmholtz energy term with respect to tau [-]...
Definition: Helmholtz.h:600
This file contains flash routines in which the state is unknown, and a solver of some kind must be us...
Definition: AbstractState.h:19
IdealHelmholtzCP0PolyT(const std::vector< CoolPropDbl > &c, const std::vector< CoolPropDbl > &t, double Tc, double T0)
Constructor with std::vectors.
Definition: Helmholtz.h:999
IdealHelmholtzLogTau()
Default constructor.
Definition: Helmholtz.h:834
Definition: CachedElement.h:32
ResidualHelmholtzGeneralizedCubic(shared_ptr< AbstractCubic > &ac)
Constructor given an abstract cubic instance.
Definition: Helmholtz.h:485
Definition: Helmholtz.h:955
virtual CoolPropDbl dTau2(const CoolPropDbl &tau, const CoolPropDbl &delta)
Returns the second partial derivative of Helmholtz energy term with respect to tau [-]...
Definition: Helmholtz.h:156
void add_Exponential(const std::vector< CoolPropDbl > &n, const std::vector< CoolPropDbl > &d, const std::vector< CoolPropDbl > &t, const std::vector< CoolPropDbl > &g, const std::vector< CoolPropDbl > &l)
Add and convert an old-style exponential term to generalized form.
Definition: Helmholtz.h:283
IdealHelmholtzCP0Constant(CoolPropDbl cp_over_R, CoolPropDbl Tc, CoolPropDbl T0)
Constructor with just a single double value.
Definition: Helmholtz.h:966