CoolProp  4.2.5
An open-source fluid property and humid air property database
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Helmholtz.cpp
Go to the documentation of this file.
1 #if defined(_MSC_VER)
2 #define _CRTDBG_MAP_ALLOC
3 #define _CRT_SECURE_NO_WARNINGS
4 #include <stdlib.h>
5 #include <crtdbg.h>
6 #include "float.h"
7 #else
8 #include <stdlib.h>
9 #include <limits>
10 #define DBL_EPSILON std::numeric_limits<double>::epsilon()
11 #endif
12 
13 #include "time.h"
14 #include <vector>
15 #include <iostream>
16 #include "math.h"
17 #include "Helmholtz.h"
18 #include "CoolPropTools.h"
19 
20 #ifndef DISABLE_CATCH
21 #include "Catch/catch.hpp"
22 #endif
23 
24 void check_derivatives(phi_BC * phi, double tau, double delta, double ddelta, double dtau)
25 {
26  double dphir_dDelta_a = (phi->base(tau,delta+ddelta)-phi->base(tau,delta-ddelta))/(2*ddelta);
27  double dphir_dDelta_e = phi->dDelta(tau,delta);
28 
29  double d2phir_dDelta2_a = (phi->dDelta(tau,delta+ddelta)-phi->dDelta(tau,delta-ddelta))/(2*ddelta);
30  double d2phir_dDelta2_e = phi->dDelta2(tau,delta);
31 
32  double d2phir_dDelta_dTau_a = (phi->dDelta(tau+dtau,delta)-phi->dDelta(tau-dtau,delta))/(2*dtau);
33  double d2phir_dDelta_dTau_e = phi->dDelta_dTau(tau,delta);
34 
35  double d3phir_dDelta2_dTau_a = (phi->dDelta_dTau(tau,delta+ddelta)-phi->dDelta_dTau(tau,delta-ddelta))/(2*ddelta);
36  double d3phir_dDelta2_dTau_e = phi->dDelta2_dTau(tau,delta);
37 
38  double d3phir_dDelta_dTau2_a = (phi->dDelta_dTau(tau+dtau,delta)-phi->dDelta_dTau(tau-dtau,delta))/(2*dtau);
39  double d3phir_dDelta_dTau2_e = phi->dDelta_dTau2(tau,delta);
40 
41  double d3phir_dDelta3_a = (phi->dDelta2(tau,delta+ddelta)-phi->dDelta2(tau,delta-ddelta))/(2*ddelta);
42  double d3phir_dDelta3_e = phi->dDelta3(tau,delta);
43 
44  double dphir_dTau_a = (phi->base(tau+dtau,delta)-phi->base(tau-dtau,delta))/(2*dtau);
45  double dphir_dTau_e = phi->dTau(tau,delta);
46 
47  double d2phir_dTau2_a = (phi->dTau(tau+dtau,delta)-phi->dTau(tau-dtau,delta))/(2*dtau);
48  double d2phir_dTau2_e = phi->dTau2(tau,delta);
49 
50  double d3phir_dTau3_a = (phi->dTau2(tau+dtau,delta)-phi->dTau2(tau-dtau,delta))/(2*dtau);
51  double d3phir_dTau3_e = phi->dTau3(tau,delta);
52 
53  double d2phir_dDelta2 = 0;
54 }
55 
56 // Constructors
57 phir_power::phir_power(std::vector<double> n_in,std::vector<double> d_in,std::vector<double> t_in, std::vector<double> l_in, int iStart_in,int iEnd_in)
58 {
59  n=n_in;
60  d=d_in;
61  t=t_in;
62  l=l_in;
63  iStart=iStart_in;
64  iEnd=iEnd_in;
65  cache();
66 }
67 phir_power::phir_power(std::vector<double> n_in,std::vector<double> d_in,std::vector<double> t_in,int iStart_in,int iEnd_in)
68 {
69  n=n_in;
70  d=d_in;
71  t=t_in;
72  l.assign(d.size(),0.0);
73  iStart=iStart_in;
74  iEnd=iEnd_in;
75  cache();
76 }
77 phir_power::phir_power(const double n_in[], const double d_in[], const double t_in[],int iStart_in,int iEnd_in, int N)
78 {
79  n=std::vector<double>(n_in,n_in+N);
80  d=std::vector<double>(d_in,d_in+N);
81  t=std::vector<double>(t_in,t_in+N);
82  l.assign(d.size(),0.0);
83  iStart=iStart_in;
84  iEnd=iEnd_in;
85  cache();
86 }
87 phir_power::phir_power(double n_in[], double d_in[], double t_in[],int iStart_in,int iEnd_in, int N)
88 {
89  n=std::vector<double>(n_in,n_in+N);
90  d=std::vector<double>(d_in,d_in+N);
91  t=std::vector<double>(t_in,t_in+N);
92  l.assign(d.size(),0.0);
93  iStart=iStart_in;
94  iEnd=iEnd_in;
95  cache();
96 }
97 phir_power::phir_power(double n_in[], double d_in[], double t_in[], double l_in[], int iStart_in,int iEnd_in, int N)
98 {
99  n=std::vector<double>(n_in,n_in+N);
100  d=std::vector<double>(d_in,d_in+N);
101  t=std::vector<double>(t_in,t_in+N);
102  l=std::vector<double>(l_in,l_in+N);
103  iStart=iStart_in;
104  iEnd=iEnd_in;
105  cache();
106 }
107 phir_power::phir_power(const double n_in[], const double d_in[], const double t_in[], const double l_in[], int iStart_in,int iEnd_in, int N)
108 {
109  n=std::vector<double>(n_in,n_in+N);
110  d=std::vector<double>(d_in,d_in+N);
111  t=std::vector<double>(t_in,t_in+N);
112  l=std::vector<double>(l_in,l_in+N);
113  iStart=iStart_in;
114  iEnd=iEnd_in;
115  cache();
116 }
118 {
119  // Check that taking the integer representation of each of the powers of delta (delta^l_i) all yield integer
120  for (unsigned int i=iStart;i<=iEnd;i++)
121  {
122  if ( fabs((double)((int)(l[i])) - l[i]) > DBL_EPSILON)
123  {
124  throw ValueError(format("coefficient %0.16f does not round to integer within DBL_EPSILON",l[i]).c_str());
125  }
126  }
127 }
128 
129 // Term and its derivatives
130 double phir_power::base(double tau, double delta) throw()
131 {
132  double summer=0, log_tau = log(tau), log_delta = log(delta);
133  for (unsigned int i=iStart;i<=iEnd;i++)
134  {
135  summer += n[i]*A(log_tau,log_delta,delta,i);
136  }
137  return summer;
138 }
139 double phir_power::dTau(double tau, double delta) throw()
140 {
141  double summer=0, log_tau = log(tau), log_delta = log(delta);
142  for (unsigned int i=iStart;i<=iEnd;i++)
143  {
144  summer += n[i]*dA_dTau(log_tau,log_delta,delta,i);
145  }
146  return summer;
147 }
148 double phir_power::dTau2(double tau, double delta) throw()
149 {
150  double summer=0, log_tau = log(tau), log_delta = log(delta);
151  for (unsigned int i=iStart;i<=iEnd;i++)
152  {
153  summer += n[i]*d2A_dTau2(log_tau,log_delta,delta,i);
154  }
155  return summer;
156 }
157 double phir_power::dTau3(double tau, double delta) throw()
158 {
159  double summer=0, log_tau = log(tau), log_delta = log(delta);
160  for (unsigned int i=iStart;i<=iEnd;i++)
161  {
162  if (l[i]>0)
163  summer+=n[i]*t[i]*(t[i]-1)*(t[i]-2)*exp((t[i]-3)*log_tau+d[i]*log_delta-pow(delta,(int)l[i]));
164  else
165  summer+=n[i]*t[i]*(t[i]-1)*(t[i]-2)*exp((t[i]-3)*log_tau+d[i]*log_delta);
166  }
167  return summer;
168 }
170 {
171  el.AddMember("type","ResidualHelmholtzPower",doc.GetAllocator());
173  for (unsigned int i=iStart;i<=iEnd;i++)
174  {
175  _n.PushBack(n[i],doc.GetAllocator());
176  _d.PushBack(d[i],doc.GetAllocator());
177  _t.PushBack(t[i],doc.GetAllocator());
178  _l.PushBack(l[i],doc.GetAllocator());
179  }
180  el.AddMember("n",_n,doc.GetAllocator());
181  el.AddMember("d",_d,doc.GetAllocator());
182  el.AddMember("t",_t,doc.GetAllocator());
183  el.AddMember("l",_l,doc.GetAllocator());
184 }
185 double phir_power::dDelta_dTau2(double tau, double delta) throw()
186 {
187  double summer=0, log_tau = log(tau), log_delta = log(delta);
188  for (unsigned int i=iStart;i<=iEnd;i++)
189  {
190  if (l[i]>0){
191  double pow_delta_li = pow(delta,(int)l[i]);
192  summer+=n[i]*t[i]*(t[i]-1)*(d[i]-l[i]*pow_delta_li)*exp((t[i]-2)*log_tau+(d[i]-1)*log_delta-pow_delta_li);
193  }
194  else
195  summer+=n[i]*t[i]*(t[i]-1)*d[i]*exp((t[i]-2)*log_tau+(d[i]-1)*log_delta);
196  }
197  return summer;
198 }
199 double phir_power::dDelta(double tau, double delta) throw()
200 {
201  double summer=0, log_tau = log(tau), log_delta = log(delta);
202  for (unsigned int i=iStart;i<=iEnd;++i)
203  {
204  summer += n[i]*dA_dDelta(log_tau,log_delta,delta,i);
205  }
206  return summer;
207 }
208 double phir_power::dDelta2(double tau, double delta) throw()
209 {
210  double summer=0, log_tau = log(tau), log_delta = log(delta);
211  for (unsigned int i=iStart;i<=iEnd;i++)
212  {
213  summer += n[i]*d2A_dDelta2(log_tau,log_delta,delta,i);
214  }
215  return summer;
216 }
217 double phir_power::dDelta3(double tau, double delta) throw()
218 {
219  double summer=0, log_tau = log(tau), log_delta = log(delta);
220  for (unsigned int i=iStart;i<=iEnd;i++)
221  {
222  if (l[i]>0)
223  {
224  double pow_delta_li = pow(delta,(int)l[i]);
225  double bracket = (d[i]*(d[i]-1)*(d[i]-2)+pow_delta_li*(-2*l[i]+6*d[i]*l[i]-3*d[i]*d[i]*l[i]-3*d[i]*l[i]*l[i]+3*l[i]*l[i]-l[i]*l[i]*l[i])+pow_delta_li*pow_delta_li*(3*d[i]*l[i]*l[i]-3*l[i]*l[i]+3*l[i]*l[i]*l[i])-l[i]*l[i]*l[i]*pow_delta_li*pow_delta_li*pow_delta_li);
226  summer+=n[i]*bracket*exp(t[i]*log_tau+(d[i]-3)*log_delta-pow_delta_li);
227  }
228  else
229  summer+=n[i]*d[i]*(d[i]-1.0)*(d[i]-2)*exp(t[i]*log_tau+(d[i]-3)*log_delta);
230  }
231  return summer;
232 }
233 double phir_power::dDelta2_dTau(double tau, double delta) throw()
234 {
235  double summer=0, log_tau = log(tau), log_delta = log(delta);
236  for (unsigned int i=iStart;i<=iEnd;i++)
237  {
238  if (l[i]>0){
239  double pow_delta_li = pow(delta,(int)l[i]);
240  summer+=n[i]*t[i]*(((d[i]-l[i]*pow_delta_li))*(d[i]-1-l[i]*pow_delta_li)-l[i]*l[i]*pow_delta_li)*exp((t[i]-1)*log_tau+(d[i]-2)*log_delta-pow_delta_li);
241  }
242  else
243  summer+=n[i]*d[i]*t[i]*(d[i]-1)*exp((t[i]-1)*log_tau+(d[i]-2)*log_delta);
244  }
245  return summer;
246 }
247 double phir_power::dDelta_dTau(double tau, double delta) throw()
248 {
249  double summer=0, log_tau = log(tau), log_delta = log(delta);
250  for (unsigned int i=iStart;i<=iEnd;i++)
251  {
252  summer += n[i]*d2A_dDelta_dTau(log_tau, log_delta, delta, i);
253  }
254  return summer;
255 }
256 
257 double phir_power::A(double log_tau, double log_delta, double delta, int i) throw()
258 {
259  if (l[i]>0)
260  return exp(t[i]*log_tau+d[i]*log_delta-pow(delta,(int)l[i]));
261  else
262  return exp(t[i]*log_tau+d[i]*log_delta);
263 }
264 double phir_power::dA_dDelta(double log_tau, double log_delta, double delta, int i) throw()
265 {
266  double pow_delta_li, li, ni, di, ti;
267  ni = n[i]; di = d[i]; ti = t[i]; li = l[i];
268  if (li > 0){
269  pow_delta_li = pow(delta,(int)li);
270  return (di-li*pow_delta_li)*exp(ti*log_tau+(di-1)*log_delta-pow_delta_li);
271  }
272  else
273  {
274  return di*exp(ti*log_tau+(di-1)*log_delta);
275  }
276 }
277 double phir_power::d2A_dDelta2(double log_tau, double log_delta, double delta, int i) throw()
278 {
279  if (l[i]>0){
280  double pow_delta_li = pow(delta,(int)l[i]);
281  return ((d[i]-l[i]*pow_delta_li)*(d[i]-1.0-l[i]*pow_delta_li) - l[i]*l[i]*pow_delta_li)*exp(t[i]*log_tau+(d[i]-2)*log_delta-pow_delta_li);
282  }
283  else
284  return d[i]*(d[i]-1.0)*exp(t[i]*log_tau+(d[i]-2)*log_delta);
285 }
286 double phir_power::d2A_dDelta_dTau(double log_tau, double log_delta, double delta, int i) throw()
287 {
288  if (l[i]>0){
289  double pow_delta_li = pow(delta,(int)l[i]);
290  return t[i]*(d[i]-l[i]*pow_delta_li)*exp((t[i]-1)*log_tau+(d[i]-1)*log_delta-pow_delta_li);
291  }
292  else
293  return d[i]*t[i]*exp((t[i]-1)*log_tau+(d[i]-1)*log_delta);
294 }
295 
296 double phir_power::dA_dTau(double log_tau, double log_delta, double delta, int i) throw()
297 {
298  if (l[i]>0)
299  return t[i]*exp((t[i]-1)*log_tau+d[i]*log_delta-pow(delta,(int)l[i]));
300  else
301  return t[i]*exp((t[i]-1)*log_tau+d[i]*log_delta);
302 }
303 double phir_power::d2A_dTau2(double log_tau, double log_delta, double delta, int i) throw()
304 {
305  if (l[i]>0)
306  return t[i]*(t[i]-1)*exp((t[i]-2)*log_tau+d[i]*log_delta-pow(delta,(int)l[i]));
307  else
308  return t[i]*(t[i]-1)*exp((t[i]-2)*log_tau+d[i]*log_delta);
309 }
310 
311 
312 std::vector<double> phir_power::dDeltaV(std::vector<double> tau, std::vector<double> delta) throw()
313 {
314  std::vector<double> out = tau;
315  for (int i = 0; i < (int)tau.size(); i++)
316  {
317  out[i] = this->dDelta(tau[i],delta[i]);
318  }
319  return out;
320 }
321 std::vector<double> phir_power::dDelta2V(std::vector<double> tau, std::vector<double> delta) throw()
322 {
323  std::vector<double> out = tau;
324  for (int i = 0; i < (int)tau.size(); i++)
325  {
326  out[i] = this->dDelta2(tau[i],delta[i]);
327  }
328  return out;
329 }
330 std::vector<double> phir_power::dTau2V(std::vector<double> tau, std::vector<double> delta) throw()
331 {
332  std::vector<double> out = tau;
333  for (int i = 0; i < (int)tau.size(); i++)
334  {
335  out[i] = this->dTau2(tau[i],delta[i]);
336  }
337  return out;
338 }
339 std::vector<double> phir_power::dDelta_dTauV(std::vector<double> tau, std::vector<double> delta) throw()
340 {
341  std::vector<double> out = tau;
342  for (int i = 0; i < (int)tau.size(); i++)
343  {
344  out[i] = this->dDelta_dTau(tau[i],delta[i]);
345  }
346  return out;
347 }
348 
349 #ifndef DISABLE_CATCH
350 TEST_CASE("Power Helmholtz terms", "[helmholtz],[fast]")
351 {
352  // From R134a
353  double n[]={0.0, 0.5586817e-1, 0.4982230e0, 0.2458698e-1, 0.8570145e-3, 0.4788584e-3, -0.1800808e1, 0.2671641e0, -0.4781652e-1, 0.1423987e-1, 0.3324062e0, -0.7485907e-2, 0.1017263e-3, -0.5184567e+0, -0.8692288e-1, 0.2057144e+0, -0.5000457e-2, 0.4603262e-3, -0.3497836e-2, 0.6995038e-2, -0.1452184e-1, -0.1285458e-3};
354  double d[]={0,2,1,3,6,6,1,1,2,5,2,2,4,1,4,1,2,4,1,5,3,10};
355  double t[]={0.0,-1.0/2.0,0.0,0.0,0.0,3.0/2.0,3.0/2.0,2.0,2.0,1.0,3.0,5.0,1.0,5.0,5.0,6.0,10.0,10.0,10.0,18.0,22.0,50.0};
356  double c[]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,2.0,2.0,2.0,2.0,2.0,2.0,3.0,3.0,3.0,4.0};
357 
358  phir_power phir(n,d,t,c,1,21,22);
359  double eps = 10*sqrt(DBL_EPSILON);
360 
361  SECTION("dDelta")
362  {
363  double ANA = phir.dDelta(0.5, 0.5);
364  double NUM = (phir.base(0.5, 0.5+eps) - phir.base(0.5,0.5-eps))/(2*eps);
365  REQUIRE(abs(NUM-ANA) < 1e-6);
366  }
367  SECTION("dTau")
368  {
369  double ANA = phir.dTau(0.5, 0.5);
370  double NUM = (phir.base(0.5+eps, 0.5) - phir.base(0.5-eps,0.5))/(2*eps);
371  REQUIRE(abs(NUM-ANA) < 1e-6);
372  }
373  SECTION("dDelta2")
374  {
375  double ANA = phir.dDelta2(0.5, 0.5);
376  double NUM = (phir.dDelta(0.5, 0.5+eps) - phir.dDelta(0.5,0.5-eps))/(2*eps);
377  REQUIRE(abs(NUM-ANA) < 1e-6);
378  }
379  SECTION("dTau2")
380  {
381  double ANA = phir.dTau2(0.5, 0.5);
382  double NUM = (phir.dTau(0.5+eps, 0.5) - phir.dTau(0.5-eps,0.5))/(2*eps);
383  REQUIRE(abs(NUM-ANA) < 1e-6);
384  }
385  SECTION("dDeltadTau")
386  {
387  double ANA = phir.dDelta_dTau(0.5, 0.5);
388  double NUM = (phir.dTau(0.5, 0.5+eps) - phir.dTau(0.5,0.5-eps))/(2*eps);
389  REQUIRE(abs(NUM-ANA) < 1e-6);
390  }
391 }
392 #endif
393 
395 {
396  el.AddMember("type","ResidualHelmholtzExponential",doc.GetAllocator());
398  for (unsigned int i=iStart;i<=iEnd;i++)
399  {
400  _n.PushBack(n[i],doc.GetAllocator());
401  _d.PushBack(d[i],doc.GetAllocator());
402  _t.PushBack(t[i],doc.GetAllocator());
403  _l.PushBack(l[i],doc.GetAllocator());
404  _g.PushBack(g[i],doc.GetAllocator());
405  }
406  el.AddMember("n",_n,doc.GetAllocator());
407  el.AddMember("d",_d,doc.GetAllocator());
408  el.AddMember("t",_t,doc.GetAllocator());
409  el.AddMember("l",_l,doc.GetAllocator());
410  el.AddMember("g",_g,doc.GetAllocator());
411 }
412 
413 // Constructors
414 phir_exponential::phir_exponential(std::vector<double> n, std::vector<double> d, std::vector<double> t, std::vector<double> l, std::vector<double> g, int iStart_in,int iEnd_in)
415 {
416  this->n = n;
417  this->d = d;
418  this->t = t;
419  this->l = l;
420  this->g = g;
421  iStart=iStart_in;
422  iEnd=iEnd_in;
423 }
424 phir_exponential::phir_exponential(double n[], double d[], double t[], double l[], double g[], int iStart_in,int iEnd_in, int N)
425 {
426  this->n=std::vector<double>(n, n+N);
427  this->d=std::vector<double>(d, d+N);
428  this->t=std::vector<double>(t, t+N);
429  this->l=std::vector<double>(l, l+N);
430  this->g=std::vector<double>(g, g+N);
431  iStart=iStart_in;
432  iEnd=iEnd_in;
433 }
434 phir_exponential::phir_exponential(const double n[], const double d[], const double t[], const double l[], const double g[], int iStart_in,int iEnd_in, int N)
435 {
436  this->n = std::vector<double>(n, n+N);
437  this->d = std::vector<double>(d, d+N);
438  this->t = std::vector<double>(t, t+N);
439  this->l = std::vector<double>(l, l+N);
440  this->g = std::vector<double>(g, g+N);
441  iStart = iStart_in;
442  iEnd = iEnd_in;
443 }
444 
445 // Term and its derivatives
446 double phir_exponential::base(double tau, double delta) throw()
447 {
448  double summer=0, log_tau = log(tau), log_delta = log(delta);
449  for (unsigned int i=iStart;i<=iEnd;i++)
450  {
451  summer += n[i]*exp(t[i]*log_tau+d[i]*log_delta-g[i]*pow(delta,l[i]));
452  }
453  return summer;
454 }
455 double phir_exponential::dTau(double tau, double delta) throw()
456 {
457  double summer=0, log_tau = log(tau), log_delta = log(delta);
458  for (unsigned int i=iStart;i<=iEnd;i++)
459  {
460  summer += n[i]*t[i]*exp((t[i]-1)*log_tau+d[i]*log_delta-g[i]*pow(delta,l[i]));
461  }
462  return summer;
463 }
464 double phir_exponential::dTau2(double tau, double delta) throw()
465 {
466  double summer=0, log_tau = log(tau), log_delta = log(delta);
467  for (unsigned int i=iStart;i<=iEnd;i++)
468  {
469  summer+=n[i]*t[i]*(t[i]-1)*exp((t[i]-2)*log_tau+d[i]*log_delta-g[i]*pow(delta,l[i]));
470  }
471  return summer;
472 }
473 double phir_exponential::dTau3(double tau, double delta) throw()
474 {
475  double summer=0, log_tau = log(tau), log_delta = log(delta);
476  for (unsigned int i=iStart;i<=iEnd;i++)
477  {
478  summer+=n[i]*t[i]*(t[i]-1)*(t[i]-2)*exp((t[i]-3)*log_tau+d[i]*log_delta-g[i]*pow(delta,l[i]));
479  }
480  return summer;
481 }
482 double phir_exponential::dDelta_dTau2(double tau, double delta) throw()
483 {
484  double summer=0, log_tau = log(tau), log_delta = log(delta);
485  for (unsigned int i=iStart;i<=iEnd;i++)
486  {
487  double pow_delta_li = pow(delta,l[i]);
488  summer+=n[i]*t[i]*(t[i]-1)*(d[i]-g[i]*l[i]*pow_delta_li)*exp((t[i]-2)*log_tau+(d[i]-1)*log_delta-g[i]*pow_delta_li);
489  }
490  return summer;
491 }
492 double phir_exponential::dDelta(double tau, double delta) throw()
493 {
494  double summer=0, log_tau = log(tau), log_delta = log(delta), pow_delta_li;
495  for (unsigned int i=iStart;i<=iEnd;i++)
496  {
497  pow_delta_li = pow(delta,l[i]);
498  summer += n[i]*(d[i]-g[i]*l[i]*pow_delta_li)*exp(t[i]*log_tau+(d[i]-1)*log_delta-g[i]*pow_delta_li);
499  }
500  return summer;
501 }
502 double phir_exponential::dDelta2(double tau, double delta) throw()
503 {
504  double summer=0, log_tau = log(tau), log_delta = log(delta), pow_delta_li;
505  for (unsigned int i=iStart;i<=iEnd;i++)
506  {
507  pow_delta_li = pow(delta,l[i]);
508  // Typo in Span, 2000, re-derived from Sympy
509  double bracket = d[i]*d[i] - 2*d[i]*pow(delta,l[i])*g[i]*l[i] - d[i] + pow(delta,2*l[i])*g[i]*g[i]*l[i]*l[i] - pow(delta,l[i])*g[i]*l[i]*l[i] + pow(delta,l[i])*g[i]*l[i];
510  summer += n[i]*bracket*exp(t[i]*log_tau+(d[i]-2)*log_delta-g[i]*pow_delta_li);
511  }
512  return summer;
513 }
514 double phir_exponential::dDelta3(double tau, double delta) throw()
515 {
516  double summer=0, log_tau = log(tau), log_delta = log(delta);
517  for (unsigned int i=iStart;i<=iEnd;i++)
518  {
519  // >> n_i, tau, t_i, d_i, delta, g_i, l_i = symbols(' n_i tau t_i d_i delta g_i l_i')
520  // >> phir = n_i*tau**t_i*delta**d_i*exp(-g_i*pow(delta,l_i))
521  // >> simplify(diff(diff(diff(phir,delta),delta),delta))
522  double pow_delta_li = pow(delta,l[i]);
523  double pow_delta_2li = pow(delta,2*l[i]);
524  double pow_delta_3li = pow(delta,3*l[i]);
525  double bracket = d[i]*d[i]*d[i] - 3*d[i]*d[i]*pow_delta_li*g[i]*l[i] - 3*d[i]*d[i] + 3*d[i]*pow_delta_2li*g[i]*g[i]*l[i]*l[i] - 3*d[i]*pow_delta_li*g[i]*l[i]*l[i] + 6*d[i]*pow_delta_li*g[i]*l[i] + 2*d[i] - pow_delta_3li*g[i]*g[i]*g[i]*l[i]*l[i]*l[i] + 3*pow_delta_2li*g[i]*g[i]*l[i]*l[i]*l[i] - 3*pow_delta_2li*g[i]*g[i]*l[i]*l[i] - pow_delta_li*g[i]*l[i]*l[i]*l[i] + 3*pow_delta_li*g[i]*l[i]*l[i] - 2*pow_delta_li*g[i]*l[i];
526  summer += n[i]*bracket*exp(t[i]*log_tau+(d[i]-3)*log_delta-g[i]*pow_delta_li);
527  }
528  return summer;
529 }
530 double phir_exponential::dDelta2_dTau(double tau, double delta) throw()
531 {
532  double summer=0, log_tau = log(tau), log_delta = log(delta);
533  for (unsigned int i=iStart;i<=iEnd;i++)
534  {
535  double pow_delta_li = pow(delta,l[i]);
536  // Typo in Span, 2000, re-derived from Sympy
537  double bracket = d[i]*d[i] - 2*d[i]*pow(delta,l[i])*g[i]*l[i] - d[i] + pow(delta,2*l[i])*g[i]*g[i]*l[i]*l[i] - pow(delta,l[i])*g[i]*l[i]*l[i] + pow(delta,l[i])*g[i]*l[i];
538  summer += n[i]*t[i]*bracket*exp((t[i]-1)*log_tau+(d[i]-2)*log_delta-g[i]*pow_delta_li);
539  }
540  return summer;
541 }
542 double phir_exponential::dDelta_dTau(double tau, double delta) throw()
543 {
544  double summer=0, log_tau = log(tau), log_delta = log(delta);
545  for (unsigned int i=iStart;i<=iEnd;i++)
546  {
547  double pow_delta_li = pow(delta,l[i]);
548  summer+=n[i]*t[i]*(d[i]-g[i]*l[i]*pow_delta_li)*exp((t[i]-1)*log_tau+(d[i]-1)*log_delta-g[i]*pow_delta_li);
549  }
550  return summer;
551 }
552 
554 {
555  el.AddMember("type","ResidualHelmholtzLemmon2005",doc.GetAllocator());
557  for (unsigned int i=iStart;i<=iEnd;i++)
558  {
559  _n.PushBack(n[i],doc.GetAllocator());
560  _d.PushBack(d[i],doc.GetAllocator());
561  _t.PushBack(t[i],doc.GetAllocator());
562  _l.PushBack(l[i],doc.GetAllocator());
563  _m.PushBack(m[i],doc.GetAllocator());
564  }
565  el.AddMember("n",_n,doc.GetAllocator());
566  el.AddMember("d",_d,doc.GetAllocator());
567  el.AddMember("t",_t,doc.GetAllocator());
568  el.AddMember("l",_l,doc.GetAllocator());
569  el.AddMember("m",_m,doc.GetAllocator());
570 }
571 
572 // Constructors
573 phir_Lemmon2005::phir_Lemmon2005(std::vector<double> n,std::vector<double> d,std::vector<double> t, std::vector<double> l, std::vector< double> m, int iStart_in,int iEnd_in)
574 {
575  this->n = n;
576  this->d = d;
577  this->t = t;
578  this->l = l;
579  this->m = m;
580  iStart=iStart_in;
581  iEnd=iEnd_in;
582 }
583 phir_Lemmon2005::phir_Lemmon2005(double n[], double d[], double t[], double l[], double m[], int iStart_in,int iEnd_in, int N)
584 {
585  this->n=std::vector<double>(n,n+N);
586  this->d=std::vector<double>(d,d+N);
587  this->t=std::vector<double>(t,t+N);
588  this->l=std::vector<double>(l,l+N);
589  this->m=std::vector<double>(m,m+N);
590  iStart=iStart_in;
591  iEnd=iEnd_in;
592 }
593 phir_Lemmon2005::phir_Lemmon2005(const double n[], const double d[], const double t[], const double l[], const double m[], int iStart_in,int iEnd_in, int N)
594 {
595  this->n=std::vector<double>(n,n+N);
596  this->d=std::vector<double>(d,d+N);
597  this->t=std::vector<double>(t,t+N);
598  this->l=std::vector<double>(l,l+N);
599  this->m=std::vector<double>(m,m+N);
600  iStart=iStart_in;
601  iEnd=iEnd_in;
602 }
603 
604 // Term and its derivatives
605 double phir_Lemmon2005::base(double tau, double delta) throw()
606 {
607  double summer=0, log_tau = log(tau), log_delta = log(delta);
608  for (unsigned int i=iStart;i<=iEnd;i++)
609  {
610  if (l[i] != 0 && m[i] != 0)
611  summer += n[i]*exp(t[i]*log_tau+d[i]*log_delta-pow(delta,l[i])-pow(tau,m[i]));
612  else if (l[i] != 0 && m[i] == 0)
613  summer += n[i]*exp(t[i]*log_tau+d[i]*log_delta-pow(delta,l[i]));
614  else
615  summer += n[i]*exp(t[i]*log_tau+d[i]*log_delta);
616  }
617  return summer;
618 }
619 double phir_Lemmon2005::dTau(double tau, double delta) throw()
620 {
621  double summer=0, log_tau = log(tau), log_delta = log(delta), pow_tau_mi;
622  for (unsigned int i=iStart;i<=iEnd;i++)
623  {
624  if (l[i] != 0 && m[i] != 0){
625  pow_tau_mi = pow(tau,m[i]);
626  summer += n[i]*(t[i]-m[i]*pow_tau_mi)*exp((t[i]-1)*log_tau+d[i]*log_delta-pow(delta,l[i])-pow_tau_mi);
627  }
628  else if (l[i] != 0 && m[i] == 0)
629  summer += n[i]*t[i]*exp((t[i]-1)*log_tau+d[i]*log_delta-pow(delta,l[i]));
630  else
631  summer += n[i]*t[i]*exp((t[i]-1)*log_tau+d[i]*log_delta);
632  }
633  return summer;
634 }
635 double phir_Lemmon2005::dTau2(double tau, double delta) throw()
636 {
637  double summer=0, log_tau = log(tau), log_delta = log(delta), pow_tau_mi;
638  for (unsigned int i=iStart;i<=iEnd;i++)
639  {
640  if (l[i] != 0 && m[i] != 0){
641  pow_tau_mi = pow(tau,m[i]);
642  double bracket = (t[i]-m[i]*pow_tau_mi)*(t[i]-1-m[i]*pow_tau_mi)-m[i]*m[i]*pow_tau_mi;
643  summer+=n[i]*bracket*exp((t[i]-2)*log_tau+d[i]*log_delta-pow(delta,l[i])-pow_tau_mi);
644  }
645  else if (l[i] != 0 && m[i] == 0)
646  summer+=n[i]*t[i]*(t[i]-1)*exp((t[i]-2)*log_tau+d[i]*log_delta-pow(delta,l[i]));
647  else
648  summer+=n[i]*t[i]*(t[i]-1)*exp((t[i]-2)*log_tau+d[i]*log_delta);
649  }
650  return summer;
651 }
652 
681 double phir_Lemmon2005::dTau3(double tau, double delta) throw()
682 {
683  double summer=0, log_tau = log(tau), log_delta = log(delta),pow_delta_li, pow_tau_mi, bracket;
684  for (unsigned int i=iStart;i<=iEnd;i++)
685  {
686  if (l[i] != 0 && m[i] != 0){
687  pow_delta_li = pow(delta,l[i]);
688  pow_tau_mi = pow(tau,m[i]);
689  bracket = -pow(tau,t[i]+m[i]-3)*m[i]*m[i]*(2*t[i]-2*m[i]*pow_tau_mi-1-m[i])+((t[i]-2)*pow(tau,t[i]-3)-pow(tau,t[i]-2)*m[i]*pow(tau,m[i]-1))*((t[i]-m[i]*pow_tau_mi)*(t[i]-1-m[i]*pow_tau_mi)-m[i]*m[i]*pow_tau_mi);
690  summer += n[i]*t[i]*(t[i]-1)*(t[i]-2)*exp((t[i]-3)*log_tau+d[i]*log_delta-pow_delta_li-pow_tau_mi);
691  }
692  else if (l[i] != 0 && m[i] == 0){
693  summer += n[i]*t[i]*(t[i]-1)*(t[i]-2)*exp((t[i]-3)*log_tau+d[i]*log_delta-pow(delta,l[i]));
694  }
695  else
696  summer += n[i]*t[i]*(t[i]-1)*(t[i]-2)*exp((t[i]-3)*log_tau+d[i]*log_delta);
697  }
698  return summer;
699 }
700 double phir_Lemmon2005::dDelta_dTau2(double tau, double delta) throw()
701 {
702  double summer=0, log_tau = log(tau), log_delta = log(delta), pow_delta_li, pow_tau_mi, bracket;
703  for (unsigned int i=iStart;i<=iEnd;i++)
704  {
705  if (l[i] != 0 && m[i] != 0){
706  pow_delta_li = pow(delta,l[i]);
707  pow_tau_mi = pow(tau,m[i]);
708  // delta derivative of second tau derivative
709  bracket = ((t[i]-m[i]*pow_tau_mi)*(t[i]-1-m[i]*pow_tau_mi)-m[i]*m[i]*pow_tau_mi)*(d[i]-l[i]*pow_delta_li);
710  summer+=n[i]*bracket*exp((t[i]-2)*log_tau+(d[i]-1)*log_delta-pow_delta_li-pow_tau_mi);
711  }
712  else if (l[i] != 0 && m[i] == 0){
713  pow_delta_li = pow(delta,l[i]);
714  summer+=n[i]*t[i]*(t[i]-1)*(d[i]-l[i]*pow_delta_li)*exp((t[i]-2)*log_tau+(d[i]-1)*log_delta-pow_delta_li);
715  }
716  else
717  summer+=n[i]*t[i]*(t[i]-1)*d[i]*exp((t[i]-2)*log_tau+(d[i]-1)*log_delta);
718  }
719  return summer;
720 }
721 double phir_Lemmon2005::dDelta(double tau, double delta) throw()
722 {
723  double summer=0, log_tau = log(tau), log_delta = log(delta), pow_delta_li, pow_tau_mi;
724  for (unsigned int i=iStart;i<=iEnd;i++)
725  {
726  if (l[i] != 0 && m[i] != 0){
727  pow_delta_li = pow(delta,l[i]);
728  pow_tau_mi = pow(tau,m[i]);
729  summer += n[i]*(d[i]-l[i]*pow_delta_li)*exp(t[i]*log_tau+(d[i]-1)*log_delta-pow_delta_li-pow_tau_mi);
730  }
731  else if (l[i]>0 && m[i] == 0){
732  pow_delta_li = pow(delta,l[i]);
733  summer += n[i]*(d[i]-l[i]*pow_delta_li)*exp(t[i]*log_tau+(d[i]-1)*log_delta-pow_delta_li);
734  }
735  else
736  summer += n[i]*d[i]*exp(t[i]*log_tau+(d[i]-1)*log_delta);
737  }
738  return summer;
739 }
740 double phir_Lemmon2005::dDelta2(double tau, double delta) throw()
741 {
742  double summer=0, log_tau = log(tau), log_delta = log(delta), pow_delta_li, pow_tau_mi;
743  for (unsigned int i=iStart;i<=iEnd;i++)
744  {
745  if (l[i] != 0 && m[i] != 0){
746  pow_delta_li = pow(delta,l[i]);
747  pow_tau_mi = pow(tau,m[i]);
748  summer+=n[i]*((d[i]-l[i]*pow_delta_li)*(d[i]-1.0-l[i]*pow_delta_li) - l[i]*l[i]*pow_delta_li)*exp(t[i]*log_tau+(d[i]-2)*log_delta-pow_delta_li-pow_tau_mi);
749  }
750 
751  else if (l[i] != 0 && m[i] == 0){
752  pow_delta_li = pow(delta,l[i]);
753  summer+=n[i]*((d[i]-l[i]*pow_delta_li)*(d[i]-1.0-l[i]*pow_delta_li) - l[i]*l[i]*pow_delta_li)*exp(t[i]*log_tau+(d[i]-2)*log_delta-pow_delta_li);
754  }
755  else
756  summer+=n[i]*d[i]*(d[i]-1.0)*exp(t[i]*log_tau+(d[i]-2)*log_delta);
757  }
758  return summer;
759 }
760 double phir_Lemmon2005::dDelta3(double tau, double delta) throw()
761 {
762  double summer=0, log_tau = log(tau), log_delta = log(delta), pow_delta_li, pow_tau_mi, bracket;
763  for (unsigned int i=iStart;i<=iEnd;i++)
764  {
765  if (l[i] != 0 && m[i] != 0){
766  pow_delta_li = pow(delta,l[i]);
767  pow_tau_mi = pow(tau,m[i]);
768  bracket = (d[i]*(d[i]-1)*(d[i]-2)+pow_delta_li*(-2*l[i]+6*d[i]*l[i]-3*d[i]*d[i]*l[i]-3*d[i]*l[i]*l[i]+3*l[i]*l[i]-l[i]*l[i]*l[i])+pow_delta_li*pow_delta_li*(3*d[i]*l[i]*l[i]-3*l[i]*l[i]+3*l[i]*l[i]*l[i])-l[i]*l[i]*l[i]*pow_delta_li*pow_delta_li*pow_delta_li);
769  summer+=n[i]*bracket*exp(t[i]*log_tau+(d[i]-3)*log_delta-pow_delta_li-pow_tau_mi);
770  }
771  else if (l[i] != 0 && m[i] == 0)
772  {
773  pow_delta_li = pow(delta,l[i]);
774  bracket = (d[i]*(d[i]-1)*(d[i]-2)+pow_delta_li*(-2*l[i]+6*d[i]*l[i]-3*d[i]*d[i]*l[i]-3*d[i]*l[i]*l[i]+3*l[i]*l[i]-l[i]*l[i]*l[i])+pow_delta_li*pow_delta_li*(3*d[i]*l[i]*l[i]-3*l[i]*l[i]+3*l[i]*l[i]*l[i])-l[i]*l[i]*l[i]*pow_delta_li*pow_delta_li*pow_delta_li);
775  summer+=n[i]*bracket*exp(t[i]*log_tau+(d[i]-3)*log_delta-pow_delta_li);
776  }
777  else
778  summer+=n[i]*d[i]*(d[i]-1.0)*(d[i]-2)*exp(t[i]*log_tau+(d[i]-3)*log_delta);
779  }
780  return summer;
781 }
782 
783 double phir_Lemmon2005::dDelta2_dTau(double tau, double delta) throw()
784 {
785  double summer=0, log_tau = log(tau), log_delta = log(delta), bracket, pow_tau_mi, pow_delta_li;
786  for (unsigned int i=iStart;i<=iEnd;i++)
787  {
788  if (l[i] != 0 && m[i] != 0){
789  pow_delta_li = pow(delta,l[i]);
790  pow_tau_mi = pow(tau,m[i]);
791  bracket = (t[i]-m[i]*pow_tau_mi)*(((d[i]-l[i]*pow_delta_li))*(d[i]-1-l[i]*pow_delta_li)-l[i]*l[i]*pow_delta_li);
792  summer += n[i]*bracket*exp((t[i]-1)*log_tau+(d[i]-2)*log_delta-pow_delta_li-pow_tau_mi);
793  }
794  else if (l[i] != 0 && m[i] == 0){
795  pow_delta_li = pow(delta,l[i]);
796  bracket = t[i]*(((d[i]-l[i]*pow_delta_li))*(d[i]-1-l[i]*pow_delta_li)-l[i]*l[i]*pow_delta_li);
797  summer += n[i]*bracket*exp((t[i]-1)*log_tau+(d[i]-2)*log_delta-pow_delta_li);
798  }
799  else
800  summer += n[i]*d[i]*t[i]*(d[i]-1)*exp((t[i]-1)*log_tau+(d[i]-2)*log_delta);
801  }
802  return summer;
803 }
804 double phir_Lemmon2005::dDelta_dTau(double tau, double delta) throw()
805 {
806  double summer=0, log_tau = log(tau), log_delta = log(delta), pow_delta_li, pow_tau_mi;
807  for (unsigned int i=iStart;i<=iEnd;i++)
808  {
809  if (l[i] != 0 && m[i] != 0){
810  pow_delta_li = pow(delta,l[i]);
811  pow_tau_mi = pow(tau,m[i]);
812  summer+=n[i]*(d[i]-l[i]*pow_delta_li)*(t[i]-m[i]*pow_tau_mi)*exp((t[i]-1)*log_tau+(d[i]-1)*log_delta-pow_delta_li-pow_tau_mi);
813  }
814  else if (l[i] != 0 && m[i] == 0){
815  double pow_delta_li = pow(delta,l[i]);
816  summer+=n[i]*t[i]*(d[i]-l[i]*pow_delta_li)*exp((t[i]-1)*log_tau+(d[i]-1)*log_delta-pow_delta_li);
817  }
818  else
819  summer+=n[i]*d[i]*t[i]*exp((t[i]-1)*log_tau+(d[i]-1)*log_delta);
820  }
821  return summer;
822 }
823 
824 phir_gaussian::phir_gaussian(std::vector<double> n_in, std::vector<double> d_in, std::vector<double> t_in,
825  std::vector<double> alpha_in, std::vector<double> epsilon_in, std::vector<double> beta_in, std::vector<double> gamma_in,
826  unsigned int iStart_in, unsigned int iEnd_in)
827 {
828  n=n_in;
829  d=d_in;
830  t=t_in;
831  alpha=alpha_in;
832  epsilon=epsilon_in;
833  beta=beta_in;
834  gamma=gamma_in;
835  iStart=iStart_in;
836  iEnd=iEnd_in;
837 }
838 
839 phir_gaussian::phir_gaussian(double n_in[], double d_in[],double t_in[], double alpha_in[],
840  double epsilon_in[], double beta_in[], double gamma_in[],
841  unsigned int iStart_in, unsigned int iEnd_in, unsigned int N)
842 {
843  n=std::vector<double>(n_in,n_in+N);
844  d=std::vector<double>(d_in,d_in+N);
845  t=std::vector<double>(t_in,t_in+N);
846  alpha=std::vector<double>(alpha_in,alpha_in+N);
847  epsilon=std::vector<double>(epsilon_in,epsilon_in+N);
848  beta=std::vector<double>(beta_in,beta_in+N);
849  gamma=std::vector<double>(gamma_in,gamma_in+N);
850  iStart=iStart_in;
851  iEnd=iEnd_in;
852 }
853 phir_gaussian::phir_gaussian(const double n_in[], const double d_in[], const double t_in[], const double alpha_in[],
854  const double epsilon_in[], const double beta_in[], const double gamma_in[],
855  unsigned int iStart_in, unsigned int iEnd_in, unsigned int N)
856 {
857  n=std::vector<double>(n_in,n_in+N);
858  d=std::vector<double>(d_in,d_in+N);
859  t=std::vector<double>(t_in,t_in+N);
860  alpha=std::vector<double>(alpha_in,alpha_in+N);
861  epsilon=std::vector<double>(epsilon_in,epsilon_in+N);
862  beta=std::vector<double>(beta_in,beta_in+N);
863  gamma=std::vector<double>(gamma_in,gamma_in+N);
864  iStart=iStart_in;
865  iEnd=iEnd_in;
866 }
867 
869 {
870  el.AddMember("type","ResidualHelmholtzGaussian",doc.GetAllocator());
873  for (unsigned int i=iStart;i<=iEnd;i++)
874  {
875  _n.PushBack(n[i],doc.GetAllocator());
876  _d.PushBack(d[i],doc.GetAllocator());
877  _t.PushBack(t[i],doc.GetAllocator());
878  _eta.PushBack(alpha[i],doc.GetAllocator());
879  _epsilon.PushBack(epsilon[i],doc.GetAllocator());
880  _beta.PushBack(beta[i],doc.GetAllocator());
881  _gamma.PushBack(gamma[i],doc.GetAllocator());
882  }
883  el.AddMember("n",_n,doc.GetAllocator());
884  el.AddMember("d",_d,doc.GetAllocator());
885  el.AddMember("t",_t,doc.GetAllocator());
886  el.AddMember("eta",_eta,doc.GetAllocator());
887  el.AddMember("epsilon",_epsilon,doc.GetAllocator());
888  el.AddMember("beta",_beta,doc.GetAllocator());
889  el.AddMember("gamma",_gamma,doc.GetAllocator());
890 }
891 
892 // Term and its derivatives
893 double phir_gaussian::base(double tau, double delta) throw()
894 {
895  double summer=0,psi;
896  for (unsigned int i=iStart;i<=iEnd;i++)
897  {
898  psi=exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2));
899  summer+=n[i]*pow(delta,d[i])*pow(tau,t[i])*psi;
900  }
901  return summer;
902 }
903 double phir_gaussian::dTau(double tau, double delta) throw()
904 {
905  double summer=0,psi;
906  for (unsigned int i=iStart;i<=iEnd;i++)
907  {
908  psi=exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2));
909  summer+=n[i]*pow(delta,d[i])*pow(tau,t[i])*psi*(t[i]/tau-2.0*beta[i]*(tau-gamma[i]));
910  }
911  return summer;
912 }
913 double phir_gaussian::dTau2(double tau, double delta) throw()
914 {
915  double summer=0,psi;
916  for (unsigned int i=iStart;i<=iEnd;i++)
917  {
918  psi=exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2));
919  summer+=n[i]*pow(delta,d[i])*pow(tau,t[i])*psi*(pow(t[i]/tau-2.0*beta[i]*(tau-gamma[i]),2)-t[i]/pow(tau,2)-2.0*beta[i]);
920  }
921  return summer;
922 }
923 double phir_gaussian::dTau3(double tau, double delta) throw()
924 {
925  double summer=0,psi;
926  for (unsigned int i=iStart;i<=iEnd;i++)
927  {
928  // triple derivative product rule (a*b*c)' = a'*b*c+a*b'*c+a*b*c'
929  psi=exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2));
930  double dpsi_dTau = exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2))*(-2*beta[i]*(tau-gamma[i]));
931 
932  double bracket = pow(t[i]/tau-2.0*beta[i]*(tau-gamma[i]),2)-t[i]/pow(tau,2)-2.0*beta[i];
933  double dbracket_dTau = 2*(t[i]/tau-2.0*beta[i]*(tau-gamma[i]))*(-t[i]/tau/tau-2*beta[i])+2*t[i]/pow(tau,3);
934  summer+=n[i]*pow(delta,d[i])*(t[i]*pow(tau,t[i]-1)*psi*bracket+pow(tau,t[i])*dpsi_dTau*bracket+pow(tau,t[i])*psi*dbracket_dTau);
935  }
936  return summer;
937 }
938 double phir_gaussian::dDelta(double tau, double delta) throw()
939 {
940  double summer=0,psi;
941  for (unsigned int i=iStart;i<=iEnd;i++)
942  {
943  psi=exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2));
944  summer+=n[i]*pow(delta,d[i])*pow(tau,t[i])*psi*(d[i]/delta-2.0*alpha[i]*(delta-epsilon[i]));
945  }
946  return summer;
947 }
948 double phir_gaussian::dDelta2(double tau, double delta) throw()
949 {
950  double summer=0,psi;
951  for (unsigned int i=iStart;i<=iEnd;i++)
952  {
953  psi=exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2));
954  summer+=n[i]*pow(tau,t[i])*psi*(-2.0*alpha[i]*pow(delta,d[i])+4.0*pow(alpha[i],2)*pow(delta,d[i])*pow(delta-epsilon[i],2)-4.0*d[i]*alpha[i]*pow(delta,d[i]-1)*(delta-epsilon[i])+d[i]*(d[i]-1.0)*pow(delta,d[i]-2));
955  }
956  return summer;
957 }
958 double phir_gaussian::dDelta3(double tau, double delta) throw()
959 {
960  double summer=0,psi;
961  for (unsigned int i=iStart;i<=iEnd;i++)
962  {
963  psi=exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2));
964  double bracket = (pow(d[i]-2*alpha[i]*delta*(delta-epsilon[i]),3)-3*d[i]*d[i]+2*d[i]-6*d[i]*alpha[i]*delta*delta+6*alpha[i]*delta*(delta-epsilon[i])*(d[i]+2*alpha[i]*delta*delta));
965  summer+=n[i]*pow(tau,t[i])*pow(delta,d[i]-3)*psi*bracket;
966  }
967  return summer;
968 }
969 double phir_gaussian::dDelta2_dTau(double tau, double delta) throw()
970 {
971  double summer=0,psi;
972  for (unsigned int i=iStart;i<=iEnd;i++)
973  {
974  psi=exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2));
975  summer+=n[i]*pow(tau,t[i])*psi*(t[i]/tau-2.0*beta[i]*(tau-gamma[i]))*(-2.0*alpha[i]*pow(delta,d[i])+4.0*pow(alpha[i],2)*pow(delta,d[i])*pow(delta-epsilon[i],2)-4.0*d[i]*alpha[i]*pow(delta,d[i]-1)*(delta-epsilon[i])+d[i]*(d[i]-1.0)*pow(delta,d[i]-2));
976  }
977  return summer;
978 }
979 double phir_gaussian::dDelta_dTau(double tau, double delta) throw()
980 {
981  double summer=0,psi;
982  for (unsigned int i=iStart;i<=iEnd;i++)
983  {
984  psi=exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2));
985  summer+=n[i]*pow(delta,d[i])*pow(tau,t[i])*psi*(d[i]/delta-2.0*alpha[i]*(delta-epsilon[i]))*(t[i]/tau-2.0*beta[i]*(tau-gamma[i]));
986  }
987  return summer;
988 }
989 double phir_gaussian::dDelta_dTau2(double tau, double delta) throw()
990 {
991  double summer=0,psi;
992  for (unsigned int i=iStart;i<=iEnd;i++)
993  {
994  psi=exp(-alpha[i]*pow(delta-epsilon[i],2)-beta[i]*pow(tau-gamma[i],2));
995  summer+=n[i]*pow(delta,d[i])*pow(tau,t[i])*psi*(d[i]/delta-2.0*alpha[i]*(delta-epsilon[i]))*(pow(t[i]-2.0*beta[i]*tau*(tau-gamma[i]),2)-t[i]-2*beta[i]*tau*tau)/tau/tau;
996  }
997  return summer;
998 }
999 
1000 phir_GERG2008_gaussian::phir_GERG2008_gaussian(std::vector<double> n_in, std::vector<double> d_in, std::vector<double> t_in,
1001  std::vector<double> eta_in, std::vector<double> epsilon_in, std::vector<double> beta_in, std::vector<double> gamma_in,
1002  unsigned int iStart_in, unsigned int iEnd_in)
1003 {
1004  n=n_in;
1005  d=d_in;
1006  t=t_in;
1007  eta=eta_in;
1008  epsilon=epsilon_in;
1009  beta=beta_in;
1010  gamma=gamma_in;
1011  iStart=iStart_in;
1012  iEnd=iEnd_in;
1013 }
1014 
1016 {
1017  el.AddMember("type","ResidualHelmholtzGERG2008Gaussian",doc.GetAllocator());
1020  for (unsigned int i=iStart;i<=iEnd;i++)
1021  {
1022  _n.PushBack(n[i],doc.GetAllocator());
1023  _d.PushBack(d[i],doc.GetAllocator());
1024  _t.PushBack(t[i],doc.GetAllocator());
1025  _eta.PushBack(eta[i],doc.GetAllocator());
1026  _epsilon.PushBack(epsilon[i],doc.GetAllocator());
1027  _beta.PushBack(beta[i],doc.GetAllocator());
1028  _gamma.PushBack(gamma[i],doc.GetAllocator());
1029  }
1030  el.AddMember("n",_n,doc.GetAllocator());
1031  el.AddMember("d",_d,doc.GetAllocator());
1032  el.AddMember("t",_t,doc.GetAllocator());
1033  el.AddMember("eta",_eta,doc.GetAllocator());
1034  el.AddMember("epsilon",_epsilon,doc.GetAllocator());
1035  el.AddMember("beta",_beta,doc.GetAllocator());
1036  el.AddMember("gamma",_gamma,doc.GetAllocator());
1037 }
1038 
1039 phir_GERG2008_gaussian::phir_GERG2008_gaussian(double n_in[], double d_in[],double t_in[], double eta_in[],
1040  double epsilon_in[], double beta_in[], double gamma_in[],
1041  unsigned int iStart_in, unsigned int iEnd_in, unsigned int N)
1042 {
1043  n=std::vector<double>(n_in, n_in+N);
1044  d=std::vector<double>(d_in, d_in+N);
1045  t=std::vector<double>(t_in, t_in+N);
1046  eta=std::vector<double>(eta_in, eta_in+N);
1047  epsilon=std::vector<double>(epsilon_in, epsilon_in+N);
1048  beta=std::vector<double>(beta_in, beta_in+N);
1049  gamma=std::vector<double>(gamma_in, gamma_in+N);
1050  iStart=iStart_in;
1051  iEnd=iEnd_in;
1052 }
1053 double phir_GERG2008_gaussian::base(double tau, double delta)
1054 {
1055  double summer = 0, psi;
1056  for (unsigned int i=iStart;i<=iEnd;i++)
1057  {
1058  psi = exp(-eta[i]*pow(delta-epsilon[i],2)-beta[i]*(delta-gamma[i]));
1059  summer += n[i]*pow(tau,t[i])*pow(delta,d[i])*psi;
1060  }
1061  return summer;
1062 }
1063 double phir_GERG2008_gaussian::dDelta(double tau, double delta)
1064 {
1065  double summer = 0, psi;
1066  for (unsigned int i=iStart;i<=iEnd;i++)
1067  {
1068  psi = exp(-eta[i]*pow(delta-epsilon[i],2)-beta[i]*(delta-gamma[i]));
1069  summer += n[i]*pow(tau,t[i])*pow(delta,d[i])*psi*(d[i]/delta-2*eta[i]*(delta-epsilon[i])-beta[i]);
1070  }
1071  return summer;
1072 }
1073 double phir_GERG2008_gaussian::dDelta2(double tau, double delta)
1074 {
1075  double summer = 0, psi;
1076  for (unsigned int i=iStart;i<=iEnd;i++)
1077  {
1078  psi = exp(-eta[i]*pow(delta-epsilon[i],2)-beta[i]*(delta-gamma[i]));
1079  summer += n[i]*pow(tau,t[i])*pow(delta,d[i])*psi*(pow(d[i]/delta-2*eta[i]*(delta-epsilon[i])-beta[i],2)-d[i]/delta/delta-2*eta[i]);
1080  }
1081  return summer;
1082 }
1083 double phir_GERG2008_gaussian::dTau(double tau, double delta)
1084 {
1085  double summer = 0, psi;
1086  for (unsigned int i=iStart;i<=iEnd;i++)
1087  {
1088  psi = exp(-eta[i]*pow(delta-epsilon[i],2)-beta[i]*(delta-gamma[i]));
1089  summer += n[i]*t[i]*pow(tau,t[i]-1)*pow(delta,d[i])*psi;
1090  }
1091  return summer;
1092 }
1093 double phir_GERG2008_gaussian::dTau2(double tau, double delta)
1094 {
1095  double summer = 0, psi;
1096  for (unsigned int i=iStart;i<=iEnd;i++)
1097  {
1098  psi = exp(-eta[i]*pow(delta-epsilon[i],2)-beta[i]*(delta-gamma[i]));
1099  summer += n[i]*t[i]*(t[i]-1)*pow(tau,t[i]-2)*pow(delta,d[i])*psi;
1100  }
1101  return summer;
1102 }
1103 double phir_GERG2008_gaussian::dDelta_dTau(double tau, double delta)
1104 {
1105  double summer = 0, psi;
1106  for (unsigned int i=iStart;i<=iEnd;i++)
1107  {
1108  psi = exp(-eta[i]*pow(delta-epsilon[i],2)-beta[i]*(delta-gamma[i]));
1109  summer += n[i]*t[i]*pow(tau,t[i]-1)*pow(delta,d[i])*psi*(d[i]/delta-2*eta[i]*(delta-epsilon[i])-beta[i]);
1110  }
1111  return summer;
1112 }
1113 
1114 
1115 phir_critical::phir_critical(std::vector<double> n_in, std::vector<double> d_in, std::vector<double> t_in,
1116  std::vector<double> a_in, std::vector<double> b_in, std::vector<double> beta_in,
1117  std::vector<double> A_in, std::vector<double> B_in, std::vector<double> C_in,
1118  std::vector<double> D_in, int iStart_in, int iEnd_in)
1119 {
1120  n=n_in;
1121  d=d_in;
1122  t=t_in;
1123  a=a_in;
1124  b=b_in;
1125  beta=beta_in;
1126  A=A_in;
1127  B=B_in;
1128  C=C_in;
1129  D=D_in;
1130  iStart=iStart_in;
1131  iEnd=iEnd_in;
1132 }
1133 
1134 phir_critical::phir_critical(double n[], double d[], double t[],
1135  double a[], double b[], double beta[],
1136  double A[], double B[], double C[],
1137  double D[], int iStart, int iEnd,
1138  int N)
1139 {
1140  this->n=std::vector<double>(n,n+N);
1141  this->d=std::vector<double>(d,d+N);
1142  this->t=std::vector<double>(t,t+N);
1143  this->a=std::vector<double>(a,a+N);
1144  this->b=std::vector<double>(b,b+N);
1145  this->beta=std::vector<double>(beta,beta+N);
1146  this->A=std::vector<double>(A,A+N);
1147  this->B=std::vector<double>(B,B+N);
1148  this->C=std::vector<double>(C,C+N);
1149  this->D=std::vector<double>(D,D+N);
1150  this->iStart=iStart;
1151  this->iEnd=iEnd;
1152 }
1153 
1155 {
1156  el.AddMember("type","ResidualHelmholtzNonAnalytic",doc.GetAllocator());
1157 
1160  for (int i=iStart;i<=iEnd;i++)
1161  {
1162  _n.PushBack(n[i],doc.GetAllocator());
1163  _a.PushBack(a[i],doc.GetAllocator());
1164  _b.PushBack(b[i],doc.GetAllocator());
1165  _beta.PushBack(beta[i],doc.GetAllocator());
1166  _A.PushBack(A[i],doc.GetAllocator());
1167  _B.PushBack(B[i],doc.GetAllocator());
1168  _C.PushBack(C[i],doc.GetAllocator());
1169  _D.PushBack(D[i],doc.GetAllocator());
1170  }
1171  el.AddMember("n",_n,doc.GetAllocator());
1172  el.AddMember("a",_a,doc.GetAllocator());
1173  el.AddMember("b",_b,doc.GetAllocator());
1174  el.AddMember("beta",_beta,doc.GetAllocator());
1175  el.AddMember("A",_A,doc.GetAllocator());
1176  el.AddMember("B",_B,doc.GetAllocator());
1177  el.AddMember("C",_C,doc.GetAllocator());
1178  el.AddMember("D",_D,doc.GetAllocator());
1179 }
1180 
1181 double phir_critical::base(double tau, double delta) throw()
1182 {
1183  double summer=0,theta,DELTA,PSI;
1184  for (int i=iStart;i<=iEnd;i++)
1185  {
1186  theta=(1.0-tau)+A[i]*pow(pow(delta-1.0,2),1/(2*beta[i]));
1187  DELTA=pow(theta,2)+B[i]*pow(pow(delta-1.0,2),a[i]);
1188  PSI=exp(-C[i]*pow(delta-1.0,2)-D[i]*pow(tau-1.0,2));
1189  summer+=n[i]*pow(DELTA,b[i])*delta*PSI;
1190  }
1191  return summer;
1192 }
1193 
1194 double phir_critical::dDelta(double tau, double delta) throw()
1195 {
1196  double summer=0,theta,DELTA,PSI,dPSI_dDelta,dDELTA_dDelta,dDELTAbi_dDelta;
1197  for (int i=iStart;i<=iEnd;i++)
1198  {
1199  theta=(1.0-tau)+A[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i]));
1200  DELTA=pow(theta,2)+B[i]*pow(pow(delta-1.0,2),a[i]);
1201  PSI=exp(-C[i]*pow(delta-1.0,2)-D[i]*pow(tau-1.0,2));
1202  dPSI_dDelta=-2.0*C[i]*(delta-1.0)*PSI;
1203  dDELTA_dDelta=(delta-1.0)*(A[i]*theta*2.0/beta[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0)+2.0*B[i]*a[i]*pow(pow(delta-1.0,2),a[i]-1.0));
1204 
1205  // At critical point, DELTA is 0, and 1/0^n is undefined
1206  if (fabs(DELTA) < 10*DBL_EPSILON)
1207  {
1208  dDELTAbi_dDelta = 0;
1209  }
1210  else{
1211  dDELTAbi_dDelta=b[i]*pow(DELTA,b[i]-1.0)*dDELTA_dDelta;
1212  }
1213  summer+=n[i]*(pow(DELTA,b[i])*(PSI+delta*dPSI_dDelta)+dDELTAbi_dDelta*delta*PSI);
1214  }
1215  return summer;
1216 }
1217 double phir_critical::dDelta_dTau2(double tau, double delta) throw()
1218 {
1219  double summer=0,theta,DELTA,PSI,dPSI_dDelta,dDELTA_dDelta,dDELTAbi_dDelta;
1220  double dDELTAbi_dTau,dPSI_dTau, dtheta_dDelta;
1221  double dPSI2_dDelta2, dDELTA2_dDelta2,dDELTAbi2_dDelta2,dPSI2_dTau2,dDELTAbi2_dTau2;
1222  double dDELTAbi2_dDelta_dTau,dPSI2_dDelta_dTau;
1223  double dDELTAbi3_dDelta_dTau2,dPSI3_dDelta_dTau2;
1224 
1225  for (int i=iStart;i<=iEnd;i++)
1226  {
1227  theta=(1.0-tau)+A[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i]));
1228  DELTA=pow(theta,2)+B[i]*pow(pow(delta-1.0,2),a[i]);
1229  PSI=exp(-C[i]*pow(delta-1.0,2)-D[i]*pow(tau-1.0,2));
1230 
1231  dPSI_dDelta=-2.0*C[i]*(delta-1.0)*PSI;
1232  dDELTA_dDelta=(delta-1.0)*(A[i]*theta*2.0/beta[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0)+2.0*B[i]*a[i]*pow(pow(delta-1.0,2),a[i]-1.0));
1233  dDELTAbi_dDelta=b[i]*pow(DELTA,b[i]-1.0)*dDELTA_dDelta;
1234 
1235  dPSI2_dDelta2=(2.0*C[i]*pow(delta-1.0,2)-1.0)*2.0*C[i]*PSI;
1236  dDELTA2_dDelta2=1.0/(delta-1.0)*dDELTA_dDelta+pow(delta-1.0,2)*(4.0*B[i]*a[i]*(a[i]-1.0)*pow(pow(delta-1.0,2),a[i]-2.0)+2.0*pow(A[i]/beta[i],2)*pow(pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0),2)+A[i]*theta*4.0/beta[i]*(1.0/(2.0*beta[i])-1.0)*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-2.0));
1237  dDELTAbi2_dDelta2=b[i]*(pow(DELTA,b[i]-1.0)*dDELTA2_dDelta2+(b[i]-1.0)*pow(DELTA,b[i]-2.0)*pow(dDELTA_dDelta,2));
1238 
1239  dPSI_dTau=-2.0*D[i]*(tau-1.0)*PSI;
1240  dDELTAbi_dTau=-2.0*theta*b[i]*pow(DELTA,b[i]-1.0);
1241 
1242  dPSI2_dTau2=(2.0*D[i]*pow(tau-1.0,2)-1.0)*2.0*D[i]*PSI;
1243  dDELTAbi2_dTau2=2.0*b[i]*pow(DELTA,b[i]-1.0)+4.0*pow(theta,2)*b[i]*(b[i]-1.0)*pow(DELTA,b[i]-2.0);
1244  dPSI2_dDelta_dTau=4.0*C[i]*D[i]*(delta-1.0)*(tau-1.0)*PSI;
1245  dDELTAbi2_dDelta_dTau=-A[i]*b[i]*2.0/beta[i]*pow(DELTA,b[i]-1.0)*(delta-1.0)*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0)-2.0*theta*b[i]*(b[i]-1.0)*pow(DELTA,b[i]-2.0)*dDELTA_dDelta;
1246 
1247  dPSI3_dDelta_dTau2 = 2*D[i]*(2*D[i]*pow(tau-1,2)-1)*dPSI_dDelta;
1248  dtheta_dDelta = A[i]/(2*beta[i])*pow(pow(delta-1,2),1/(2*beta[i])-1)*2*(delta-1);
1249  dDELTAbi3_dDelta_dTau2 = 2*b[i]*(b[i]-1)*pow(DELTA,b[i]-2)*dDELTA_dDelta+4*pow(theta,2)*b[i]*(b[i]-1)*(b[i]-2)*pow(DELTA,b[i]-3)*dDELTA_dDelta+8*theta*b[i]*(b[i]-1)*pow(DELTA,b[i]-2)*dtheta_dDelta;
1250 
1251  summer += n[i]*delta*(dDELTAbi2_dTau2*dPSI_dDelta+dDELTAbi3_dDelta_dTau2*PSI+2*dDELTAbi_dTau*dPSI2_dDelta_dTau+2.0*dDELTAbi2_dDelta_dTau*dPSI_dTau+pow(DELTA,b[i])*dPSI3_dDelta_dTau2+dDELTAbi_dDelta*dPSI2_dTau2)+n[i]*(dDELTAbi2_dTau2*PSI+2.0*dDELTAbi_dTau*dPSI_dTau+pow(DELTA,b[i])*dPSI2_dTau2);
1252  }
1253  return summer;
1254 }
1255 
1256 double phir_critical::dDelta2(double tau, double delta) throw()
1257 {
1258  double summer=0,theta,DELTA,PSI,dPSI_dDelta,dDELTA_dDelta,dDELTAbi_dDelta;
1259  double dPSI2_dDelta2, dDELTA2_dDelta2,dDELTAbi2_dDelta2;
1260  for (int i=iStart;i<=iEnd;i++)
1261  {
1262  theta=(1.0-tau)+A[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i]));
1263  DELTA=pow(theta,2)+B[i]*pow(pow(delta-1.0,2),a[i]);
1264  PSI=exp(-C[i]*pow(delta-1.0,2)-D[i]*pow(tau-1.0,2));
1265 
1266  dPSI_dDelta=-2.0*C[i]*(delta-1.0)*PSI;
1267  dDELTA_dDelta=(delta-1.0)*(A[i]*theta*2.0/beta[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0)+2.0*B[i]*a[i]*pow(pow(delta-1.0,2),a[i]-1.0));
1268  dDELTAbi_dDelta=b[i]*pow(DELTA,b[i]-1.0)*dDELTA_dDelta;
1269 
1270  dPSI2_dDelta2=(2.0*C[i]*pow(delta-1.0,2)-1.0)*2.0*C[i]*PSI;
1271  dDELTA2_dDelta2=1.0/(delta-1.0)*dDELTA_dDelta+pow(delta-1.0,2)*(4.0*B[i]*a[i]*(a[i]-1.0)*pow(pow(delta-1.0,2),a[i]-2.0)+2.0*pow(A[i]/beta[i],2)*pow(pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0),2)+A[i]*theta*4.0/beta[i]*(1.0/(2.0*beta[i])-1.0)*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-2.0));
1272  dDELTAbi2_dDelta2=b[i]*(pow(DELTA,b[i]-1.0)*dDELTA2_dDelta2+(b[i]-1.0)*pow(DELTA,b[i]-2.0)*pow(dDELTA_dDelta,2));
1273 
1274  summer+=n[i]*(pow(DELTA,b[i])*(2.0*dPSI_dDelta+delta*dPSI2_dDelta2)+2.0*dDELTAbi_dDelta*(PSI+delta*dPSI_dDelta)+dDELTAbi2_dDelta2*delta*PSI);
1275  }
1276  return summer;
1277 }
1278 double phir_critical::dDelta3(double tau, double delta) throw()
1279 {
1280  double summer=0,theta,DELTA,PSI,dPSI_dDelta,dDELTA_dDelta,dDELTAbi_dDelta;
1281  double dPSI2_dDelta2, dDELTA2_dDelta2,dDELTAbi2_dDelta2;
1282  double dPSI3_dDelta3,PI,dPI_dDelta,dDELTA3_dDelta3, dDELTAbi3_dDelta3;
1283  double dtheta_dDelta;
1284  for (int i=iStart;i<=iEnd;i++)
1285  {
1286  theta=(1.0-tau)+A[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i]));
1287  DELTA=pow(theta,2)+B[i]*pow(pow(delta-1.0,2),a[i]);
1288  PSI=exp(-C[i]*pow(delta-1.0,2)-D[i]*pow(tau-1.0,2));
1289 
1290  dPSI_dDelta=-2.0*C[i]*(delta-1.0)*PSI;
1291  dDELTA_dDelta=(delta-1.0)*(A[i]*theta*2.0/beta[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0)+2.0*B[i]*a[i]*pow(pow(delta-1.0,2),a[i]-1.0));
1292  dDELTAbi_dDelta=b[i]*pow(DELTA,b[i]-1.0)*dDELTA_dDelta;
1293 
1294  dPSI2_dDelta2=(2.0*C[i]*pow(delta-1.0,2)-1.0)*2.0*C[i]*PSI;
1295  dDELTA2_dDelta2=1.0/(delta-1.0)*dDELTA_dDelta+pow(delta-1.0,2)*(4.0*B[i]*a[i]*(a[i]-1.0)*pow(pow(delta-1.0,2),a[i]-2.0)+2.0*pow(A[i]/beta[i],2)*pow(pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0),2)+A[i]*theta*4.0/beta[i]*(1.0/(2.0*beta[i])-1.0)*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-2.0));
1296  dDELTAbi2_dDelta2=b[i]*(pow(DELTA,b[i]-1.0)*dDELTA2_dDelta2+(b[i]-1.0)*pow(DELTA,b[i]-2.0)*pow(dDELTA_dDelta,2));
1297 
1298  dPSI3_dDelta3=2.0*C[i]*PSI*(-4*C[i]*C[i]*pow(delta-1.0,3)+6*C[i]*(delta-1));
1299  dtheta_dDelta = A[i]/(2*beta[i])*pow(pow(delta-1,2),1/(2*beta[i])-1)*2*(delta-1);
1300 
1301  PI = 4*B[i]*a[i]*(a[i]-1)*pow(pow(delta-1,2),a[i]-2)+2*pow(A[i]/beta[i],2)*pow(pow(delta-1,2),1/beta[i]-2)+4*A[i]*theta/beta[i]*(1/(2*beta[i])-1)*pow(pow(delta-1,2),1/(2*beta[i])-2);
1302  dPI_dDelta = -8*B[i]*a[i]*(a[i]-1)*(a[i]-2)*pow(pow(delta-1,2),a[i]-5.0/2.0)-8*pow(A[i]/beta[i],2)*(1/(2*beta[i])-1)*pow(pow(delta-1,2),1/beta[i]-5.0/2.0)-(8*A[i]*theta)/beta[i]*(1/(2*beta[i])-1)*(1/(2*beta[i])-2)*pow(pow(delta-1,2),1/(2*beta[i])-5.0/2.0)+4*A[i]/beta[i]*(1/(2*beta[i])-1)*pow(pow(delta-1,2),1/(2*beta[i])-2)*dtheta_dDelta;
1303  dDELTA3_dDelta3 = 1/(delta-1)*dDELTA2_dDelta2-1/pow(delta-1,2)*dDELTA_dDelta+pow(delta-1,2)*dPI_dDelta+2*(delta-1)*PI;
1304  dDELTAbi3_dDelta3 = b[i]*(pow(DELTA,b[i]-1)*dDELTA3_dDelta3+dDELTA2_dDelta2*(b[i]-1)*pow(DELTA,b[i]-2)*dDELTA_dDelta+(b[i]-1)*(pow(DELTA,b[i]-2)*2*dDELTA_dDelta*dDELTA2_dDelta2+pow(dDELTA_dDelta,2)*(b[i]-2)*pow(DELTA,b[i]-3)*dDELTA_dDelta));
1305 
1306  summer += n[i]*(pow(DELTA,b[i])*(3.0*dPSI2_dDelta2+delta*dPSI3_dDelta3)+3.0*dDELTAbi_dDelta*(2*dPSI_dDelta+delta*dPSI2_dDelta2)+3*dDELTAbi2_dDelta2*(PSI+delta*dPSI_dDelta)+dDELTAbi3_dDelta3*PSI*delta);
1307  }
1308  return summer;
1309 }
1310 
1311 double phir_critical::dDelta2_dTau(double tau, double delta) throw()
1312 {
1313  double summer=0;
1314  double theta,DELTA,PSI,dPSI_dDelta,dDELTA_dDelta,dDELTAbi_dDelta,dPSI2_dDelta2,dDELTAbi2_dDelta2,dDELTA2_dDelta2;
1315  double dPSI2_dDelta_dTau, dDELTAbi2_dDelta_dTau, dPSI_dTau, dDELTAbi_dTau;
1316  double Line1,Line2,Line3,dDELTA2_dDelta_dTau,dDELTA3_dDelta2_dTau,dDELTAbim1_dTau,dDELTAbim2_dTau;
1317  double dDELTA_dTau,dDELTAbi3_dDelta2_dTau,dPSI3_dDelta2_dTau;
1318 
1319  for (int i=iStart;i<=iEnd;i++)
1320  {
1321  theta=(1.0-tau)+A[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i]));
1322  DELTA=pow(theta,2)+B[i]*pow(pow(delta-1.0,2),a[i]);
1323  PSI=exp(-C[i]*pow(delta-1.0,2)-D[i]*pow(tau-1.0,2));
1324 
1325  dPSI_dDelta=-2.0*C[i]*(delta-1.0)*PSI;
1326  dDELTA_dDelta=(delta-1.0)*(A[i]*theta*2.0/beta[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0)+2.0*B[i]*a[i]*pow(pow(delta-1.0,2),a[i]-1.0));
1327  dDELTAbi_dDelta=b[i]*pow(DELTA,b[i]-1.0)*dDELTA_dDelta;
1328 
1329  dPSI2_dDelta2=(2.0*C[i]*pow(delta-1.0,2)-1.0)*2.0*C[i]*PSI;
1330  dDELTA2_dDelta2=1.0/(delta-1.0)*dDELTA_dDelta+pow(delta-1.0,2)*(4.0*B[i]*a[i]*(a[i]-1.0)*pow(pow(delta-1.0,2),a[i]-2.0)+2.0*pow(A[i]/beta[i],2)*pow(pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0),2)+A[i]*theta*4.0/beta[i]*(1.0/(2.0*beta[i])-1.0)*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-2.0));
1331  dDELTAbi2_dDelta2=b[i]*(pow(DELTA,b[i]-1.0)*dDELTA2_dDelta2+(b[i]-1.0)*pow(DELTA,b[i]-2.0)*pow(dDELTA_dDelta,2));
1332 
1333  dPSI_dTau=-2.0*D[i]*(tau-1.0)*PSI;
1334  dDELTAbi_dTau=-2.0*theta*b[i]*pow(DELTA,b[i]-1.0);
1335 
1336  dPSI2_dDelta_dTau=4.0*C[i]*D[i]*(delta-1.0)*(tau-1.0)*PSI;
1337  dDELTAbi2_dDelta_dTau=-A[i]*b[i]*2.0/beta[i]*pow(DELTA,b[i]-1.0)*(delta-1.0)*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0)-2.0*theta*b[i]*(b[i]-1.0)*pow(DELTA,b[i]-2.0)*dDELTA_dDelta;
1338 
1339  //Following Terms added for this derivative
1340  dPSI3_dDelta2_dTau = (2.0*C[i]*pow(delta-1.0,2)-1.0)*2.0*C[i]*dPSI_dTau;
1341  dDELTA_dTau = -2*theta;
1342  dDELTA2_dDelta_dTau = 2.0*A[i]/(beta[i])*pow(pow(delta-1,2),1.0/(2.0*beta[i])-0.5);
1343  dDELTA3_dDelta2_dTau = 2.0*A[i]*(beta[i]-1)/(beta[i]*beta[i])*pow(pow(delta-1,2),1/(2*beta[i])-1.0);
1344 
1345  dDELTAbim1_dTau = (b[i]-1)*pow(DELTA,b[i]-2)*dDELTA_dTau;
1346  dDELTAbim2_dTau = (b[i]-2)*pow(DELTA,b[i]-3)*dDELTA_dTau;
1347  Line1 = dDELTAbim1_dTau*dDELTA2_dDelta2 + pow(DELTA,b[i]-1)*dDELTA3_dDelta2_dTau;
1348  Line2 = (b[i]-1)*(dDELTAbim2_dTau*pow(dDELTA_dDelta,2)+pow(DELTA,b[i]-2)*2*dDELTA_dDelta*dDELTA2_dDelta_dTau);
1349  dDELTAbi3_dDelta2_dTau = b[i]*(Line1+Line2);
1350 
1351  Line1 = pow(DELTA,b[i])*(2*dPSI2_dDelta_dTau+delta*dPSI3_dDelta2_dTau)+dDELTAbi_dTau*(2*dPSI_dDelta+delta*dPSI2_dDelta2);
1352  Line2 = 2*dDELTAbi_dDelta*(dPSI_dTau+delta*dPSI2_dDelta_dTau)+2*dDELTAbi2_dDelta_dTau*(PSI+delta*dPSI_dDelta);
1353  Line3 = dDELTAbi2_dDelta2*delta*dPSI_dTau + dDELTAbi3_dDelta2_dTau*delta*PSI;
1354  summer += n[i]*(Line1+Line2+Line3);
1355  }
1356  return summer;
1357 }
1358 
1359 double phir_critical::dDelta_dTau(double tau, double delta) throw()
1360 {
1361  double summer=0,theta,DELTA,PSI,dPSI_dDelta,dDELTAbi_dDelta;
1362  double dPSI_dTau, dDELTAbi_dTau,dDELTA_dDelta, dPSI2_dDelta_dTau;
1363  double dDELTAbi2_dDelta_dTau;
1364  for (int i=iStart;i<=iEnd;i++)
1365  {
1366  theta=(1.0-tau)+A[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i]));
1367  DELTA=pow(theta,2)+B[i]*pow(pow(delta-1.0,2),a[i]);
1368  PSI=exp(-C[i]*pow(delta-1.0,2)-D[i]*pow(tau-1.0,2));
1369 
1370  dPSI_dDelta=-2.0*C[i]*(delta-1.0)*PSI;
1371  dDELTA_dDelta=(delta-1.0)*(A[i]*theta*2.0/beta[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0)+2.0*B[i]*a[i]*pow(pow(delta-1.0,2),a[i]-1.0));
1372  dDELTAbi_dDelta=b[i]*pow(DELTA,b[i]-1.0)*dDELTA_dDelta;
1373  dPSI_dTau=-2.0*D[i]*(tau-1.0)*PSI;
1374  dDELTAbi_dTau=-2.0*theta*b[i]*pow(DELTA,b[i]-1.0);
1375 
1376  dPSI2_dDelta_dTau=4.0*C[i]*D[i]*(delta-1.0)*(tau-1.0)*PSI;
1377  dDELTAbi2_dDelta_dTau=-A[i]*b[i]*2.0/beta[i]*pow(DELTA,b[i]-1.0)*(delta-1.0)*pow(pow(delta-1.0,2),1.0/(2.0*beta[i])-1.0)-2.0*theta*b[i]*(b[i]-1.0)*pow(DELTA,b[i]-2.0)*dDELTA_dDelta;
1378 
1379  summer+=n[i]*(pow(DELTA,b[i])*(dPSI_dTau+delta*dPSI2_dDelta_dTau)+delta*dDELTAbi_dDelta*dPSI_dTau+ dDELTAbi_dTau*(PSI+delta*dPSI_dDelta)+dDELTAbi2_dDelta_dTau*delta*PSI);
1380  }
1381  return summer;
1382 }
1383 
1384 double phir_critical::dTau(double tau, double delta) throw()
1385 {
1386  double summer=0,theta,DELTA,PSI,dPSI_dTau, dDELTAbi_dTau;
1387 
1388  for (int i=iStart;i<=iEnd;i++)
1389  {
1390  theta=(1.0-tau)+A[i]*pow(pow(delta-1.0,2),1.0/(2.0*beta[i]));
1391  DELTA=pow(theta,2)+B[i]*pow(pow(delta-1.0,2),a[i]);
1392  PSI=exp(-C[i]*pow(delta-1.0,2)-D[i]*pow(tau-1.0,2));
1393  dPSI_dTau=-2.0*D[i]*(tau-1.0)*PSI;
1394  if (fabs(DELTA)<10*DBL_EPSILON)
1395  dDELTAbi_dTau = 0;
1396  else
1397  dDELTAbi_dTau = -2.0*theta*b[i]*pow(DELTA,b[i]-1.0);
1398  summer+=n[i]*delta*(dDELTAbi_dTau*PSI+pow(DELTA,b[i])*dPSI_dTau);
1399  }
1400  return summer;
1401 }
1402 
1403 double phir_critical::dTau2(double tau, double delta) throw()
1404 {
1405  double summer=0,theta,DELTA,PSI,dPSI_dTau, dDELTAbi_dTau;
1406  double dPSI2_dTau2, dDELTAbi2_dTau2;
1407  for (int i=iStart;i<=iEnd;i++)
1408  {
1409  theta=(1.0-tau)+A[i]*pow(pow(delta-1.0,2),1/(2*beta[i]));
1410  DELTA=pow(theta,2)+B[i]*pow(pow(delta-1.0,2),a[i]);
1411  PSI=exp(-C[i]*pow(delta-1.0,2)-D[i]*pow(tau-1.0,2));
1412  dPSI_dTau=-2.0*D[i]*(tau-1.0)*PSI;
1413  dDELTAbi_dTau=-2.0*theta*b[i]*pow(DELTA,b[i]-1.0);
1414  dPSI2_dTau2=(2.0*D[i]*pow(tau-1.0,2)-1.0)*2.0*D[i]*PSI;
1415  dDELTAbi2_dTau2=2.0*b[i]*pow(DELTA,b[i]-1.0)+4.0*pow(theta,2)*b[i]*(b[i]-1.0)*pow(DELTA,b[i]-2.0);
1416  summer+=n[i]*delta*(dDELTAbi2_dTau2*PSI+2.0*dDELTAbi_dTau*dPSI_dTau+pow(DELTA,b[i])*dPSI2_dTau2);
1417  }
1418  return summer;
1419 }
1420 double phir_critical::dTau3(double tau, double delta) throw()
1421 {
1422  double summer=0,theta,DELTA,PSI,dPSI_dTau, dDELTAbi_dTau;
1423  double dPSI2_dTau2, dDELTAbi2_dTau2, dPSI3_dTau3, dDELTAbi3_dTau3;
1424  for (int i=iStart;i<=iEnd;i++)
1425  {
1426  theta=(1.0-tau)+A[i]*pow(pow(delta-1.0,2),1/(2*beta[i]));
1427  DELTA=pow(theta,2)+B[i]*pow(pow(delta-1.0,2),a[i]);
1428  PSI=exp(-C[i]*pow(delta-1.0,2)-D[i]*pow(tau-1.0,2));
1429  dPSI_dTau=-2.0*D[i]*(tau-1.0)*PSI;
1430  dDELTAbi_dTau=-2.0*theta*b[i]*pow(DELTA,b[i]-1.0);
1431  dPSI2_dTau2=(2.0*D[i]*pow(tau-1.0,2)-1.0)*2.0*D[i]*PSI;
1432  dDELTAbi2_dTau2=2.0*b[i]*pow(DELTA,b[i]-1.0)+4.0*pow(theta,2)*b[i]*(b[i]-1.0)*pow(DELTA,b[i]-2.0);
1433 
1434  dPSI3_dTau3=2.0*D[i]*PSI*(-4*D[i]*D[i]*pow(tau-1,3)+6*D[i]*(tau-1));
1435  dDELTAbi3_dTau3 = -12.0*theta*b[i]*(b[i]-1.0)*pow(DELTA,b[i]-2)-8*pow(theta,3)*b[i]*(b[i]-1)*(b[i]-2)*pow(DELTA,b[i]-3.0);
1436  summer += n[i]*delta*(dDELTAbi3_dTau3*PSI+(3.0*dDELTAbi2_dTau2)*dPSI_dTau+(3*dDELTAbi_dTau )*dPSI2_dTau2+pow(DELTA,b[i])*dPSI3_dTau3);
1437  }
1438  return summer;
1439 }
1440 #ifndef DISABLE_CATCH
1441 TEST_CASE((char*)"Non-analytic critical point Helmholtz derivative check", (char*)"[helmholtz],[fast]")
1442 {
1443  // From CO2
1444  double n[] = {0,-0.666422765408E+00,0.726086323499E+00,0.550686686128E-01};
1445  double d[] = {0,2,3,3};
1446  double t[] = {0, 1.00, 3.00, 3.00};
1447  double a[] = {0, 3.5, 3.5, 3.0};
1448  double b[] = {0, 0.875, 0.925, 0.875};
1449  double beta[] = {9,0.300, 0.300, 0.300};
1450  double A[] = {0, 0.700, 0.700, 0.700};
1451  double B[] = {0, 0.3, 0.3, 1.0};
1452  double C[] = {0, 10.0, 10.0, 12.5};
1453  double D[] = {0, 275.0, 275.0, 275.0};
1454 
1455  phir_critical phir = phir_critical(n,d,t,a,b,beta,A,B,C,D,1,3,4);
1456  double eps = sqrt(DBL_EPSILON);
1457 
1458  SECTION((char*)"dDelta")
1459  {
1460  double ANA = phir.dDelta(0.5, 0.5);
1461  double NUM = (phir.base(0.5, 0.5+eps) - phir.base(0.5,0.5-eps))/(2*eps);
1462  REQUIRE(abs(NUM-ANA) < 1e-12);
1463  }
1464  SECTION((char*)"dTau")
1465  {
1466  double ANA = phir.dTau(0.5, 0.5);
1467  double NUM = (phir.base(0.5+eps, 0.5) - phir.base(0.5-eps,0.5))/(2*eps);
1468  REQUIRE(abs(NUM-ANA) < 1e-12);
1469  }
1470  SECTION((char*)"dDelta2")
1471  {
1472  double ANA = phir.dDelta2(0.5, 0.5);
1473  double NUM = (phir.dDelta(0.5, 0.5+eps) - phir.dDelta(0.5,0.5-eps))/(2*eps);
1474  REQUIRE(abs(NUM-ANA) < 1e-12);
1475  }
1476  SECTION((char*)"dTau2")
1477  {
1478  double ANA = phir.dTau2(0.5, 0.5);
1479  double NUM = (phir.dTau(0.5+eps, 0.5) - phir.dTau(0.5-eps,0.5))/(2*eps);
1480  REQUIRE(abs(NUM-ANA) < 1e-12);
1481  }
1482  SECTION((char*)"dDeltadTau")
1483  {
1484  double ANA = phir.dDelta_dTau(0.5, 0.5);
1485  double NUM = (phir.dTau(0.5, 0.5+eps) - phir.dTau(0.5,0.5-eps))/(2*eps);
1486  REQUIRE(abs(NUM-ANA) < 1e-12);
1487  }
1488 }
1489 #endif
1490 
1492 {
1493  el.AddMember("type","ResidualHelmholtzAssociating",doc.GetAllocator());
1494  el.AddMember("a",a,doc.GetAllocator());
1495  el.AddMember("m",m,doc.GetAllocator());
1496  el.AddMember("epsilonbar",epsilonbar,doc.GetAllocator());
1497  el.AddMember("vbarn",vbarn,doc.GetAllocator());
1498  el.AddMember("kappabar",kappabar,doc.GetAllocator());
1499 }
1500 double phir_SAFT_associating::Deltabar(double tau, double delta)
1501 {
1502  return this->g(this->eta(delta))*(exp(this->epsilonbar*tau)-1)*this->kappabar;
1503 }
1505 {
1506  return this->dg_deta(this->eta(delta))*(exp(this->epsilonbar*tau)-1)*this->kappabar*this->vbarn;
1507 }
1509 {
1510  return this->d2g_deta2(this->eta(delta))*(exp(this->epsilonbar*tau)-1)*this->kappabar*pow(this->vbarn,(int)2);
1511 }
1513 {
1514  return this->g(this->eta(delta))*this->kappabar*exp(this->epsilonbar*tau)*this->epsilonbar;
1515 }
1517 {
1518  return this->g(this->eta(delta))*this->kappabar*exp(this->epsilonbar*tau)*pow(this->epsilonbar,(int)2);
1519 }
1520 double phir_SAFT_associating::d2Deltabar_ddelta_dtau(double tau, double delta)
1521 {
1522  return this->dg_deta(this->eta(delta))*exp(this->epsilonbar*tau)*this->epsilonbar*this->kappabar*this->vbarn;
1523 }
1525 {
1526  return this->g(this->eta(delta))*this->kappabar*exp(this->epsilonbar*tau)*pow(this->epsilonbar,(int)3);
1527 }
1528 double phir_SAFT_associating::d3Deltabar_ddelta_dtau2(double tau, double delta)
1529 {
1530  return this->dg_deta(this->eta(delta))*this->kappabar*exp(this->epsilonbar*tau)*pow(this->epsilonbar,(int)2)*this->vbarn;
1531 }
1532 double phir_SAFT_associating::d3Deltabar_ddelta2_dtau(double tau, double delta)
1533 {
1534  return this->d2g_deta2(this->eta(delta))*exp(this->epsilonbar*tau)*this->epsilonbar*this->kappabar*pow(this->vbarn,(int)2);
1535 }
1537 {
1538  return this->d3g_deta3(this->eta(delta))*(exp(this->epsilonbar*tau)-1)*this->kappabar*pow(this->vbarn,(int)3);
1539 }
1540 
1541 double phir_SAFT_associating::X(double delta, double Deltabar)
1542 {
1543  return 2/(sqrt(1+4*Deltabar*delta)+1);
1544 }
1545 double phir_SAFT_associating::dX_dDeltabar__constdelta(double delta, double Deltabar)
1546 {
1547  double X = this->X(delta,Deltabar);
1548  return -delta*X*X/(2*Deltabar*delta*X+1);
1549 }
1550 double phir_SAFT_associating::dX_ddelta__constDeltabar(double delta, double Deltabar)
1551 {
1552  double X = this->X(delta,Deltabar);
1553  return -Deltabar*X*X/(2*Deltabar*delta*X+1);
1554 }
1555 double phir_SAFT_associating::dX_dtau(double tau, double delta)
1556 {
1557  double Deltabar = this->Deltabar(tau, delta);
1558  return this->dX_dDeltabar__constdelta(delta, Deltabar)*this->dDeltabar_dtau__constdelta(tau, delta);
1559 }
1560 double phir_SAFT_associating::dX_ddelta(double tau, double delta)
1561 {
1562  double Deltabar = this->Deltabar(tau, delta);
1563  return (this->dX_ddelta__constDeltabar(delta, Deltabar)
1564  + this->dX_dDeltabar__constdelta(delta, Deltabar)*this->dDeltabar_ddelta__consttau(tau, delta));
1565 }
1566 double phir_SAFT_associating::d2X_dtau2(double tau, double delta)
1567 {
1568  double Deltabar = this->Deltabar(tau, delta);
1569  double X = this->X(delta, Deltabar);
1570  double beta = this->dDeltabar_dtau__constdelta(tau, delta);
1571  double d_dXdtau_dbeta = -delta*X*X/(2*Deltabar*delta*X+1);
1572  double d_dXdtau_dDeltabar = 2*delta*delta*X*X*X/pow(2*Deltabar*delta*X+1,2)*beta;
1573  double d_dXdtau_dX = -2*beta*delta*X*(Deltabar*delta*X+1)/pow(2*Deltabar*delta*X+1,2);
1574  double dbeta_dtau = this->d2Deltabar_dtau2__constdelta(tau, delta);
1575  double dX_dDeltabar = this->dX_dDeltabar__constdelta(delta, Deltabar);
1576  return d_dXdtau_dX*dX_dDeltabar*beta+d_dXdtau_dDeltabar*beta+d_dXdtau_dbeta*dbeta_dtau;
1577 }
1578 double phir_SAFT_associating::d2X_ddeltadtau(double tau, double delta)
1579 {
1580  double Deltabar = this->Deltabar(tau, delta);
1581  double X = this->X(delta, Deltabar);
1582  double alpha = this->dDeltabar_ddelta__consttau(tau, delta);
1583  double beta = this->dDeltabar_dtau__constdelta(tau, delta);
1584  double dalpha_dtau = this->d2Deltabar_ddelta_dtau(tau, delta);
1585  double d_dXddelta_dDeltabar = X*X*(2*delta*delta*X*alpha-1)/pow(2*Deltabar*delta*X+1,2);
1586  double d_dXddelta_dalpha = -delta*X*X/(2*Deltabar*delta*X+1);
1587  double d_dXddelta_dX = -(Deltabar+delta*alpha)*2*(Deltabar*delta*X*X+X)/pow(2*Deltabar*delta*X+1,2);
1588  double dX_dDeltabar = this->dX_dDeltabar__constdelta(delta, Deltabar);
1589  return d_dXddelta_dX*dX_dDeltabar*beta+d_dXddelta_dDeltabar*beta+d_dXddelta_dalpha*dalpha_dtau;
1590 }
1591 double phir_SAFT_associating::d2X_ddelta2(double tau, double delta)
1592 {
1593  double Deltabar = this->Deltabar(tau, delta);
1594  double X = this->X(delta, Deltabar);
1595  double alpha = this->dDeltabar_ddelta__consttau(tau, delta);
1596  double dalpha_ddelta = this->d2Deltabar_ddelta2__consttau(tau, delta);
1597 
1598  double dX_ddelta_constall = X*X*(2*Deltabar*Deltabar*X-alpha)/pow(2*Deltabar*delta*X+1,2);
1599  double d_dXddelta_dX = -(Deltabar+delta*alpha)*2*(Deltabar*delta*X*X+X)/pow(2*Deltabar*delta*X+1,2);
1600  double d_dXddelta_dDeltabar = X*X*(2*delta*delta*X*alpha-1)/pow(2*Deltabar*delta*X+1,2);
1601  double d_dXddelta_dalpha = -delta*X*X/(2*Deltabar*delta*X+1);
1602 
1603  double dX_dDeltabar = this->dX_dDeltabar__constdelta(delta, Deltabar);
1604  double dX_ddelta = this->dX_ddelta__constDeltabar(delta, Deltabar);
1605 
1606  double val = (dX_ddelta_constall
1607  + d_dXddelta_dX*dX_ddelta
1608  + d_dXddelta_dX*dX_dDeltabar*alpha
1609  + d_dXddelta_dDeltabar*alpha
1610  + d_dXddelta_dalpha*dalpha_ddelta);
1611  return val;
1612 }
1613 double phir_SAFT_associating::d3X_dtau3(double tau, double delta)
1614 {
1615  double Delta = this->Deltabar(tau, delta);
1616  double X = this->X(delta, Delta);
1617  double dX_dDelta = this->dX_dDeltabar__constdelta(delta, Delta);
1618  double Delta_t = this->dDeltabar_dtau__constdelta(tau, delta);
1619  double Delta_tt = this->d2Deltabar_dtau2__constdelta(tau, delta);
1620  double Delta_ttt = this->d3Deltabar_dtau3__constdelta(tau, delta);
1621  double dXtt_dX = 2*X*delta*(-6*Delta*pow(Delta_t, 2)*pow(X, 2)*pow(delta, 2)*(Delta*X*delta + 1) + 3*pow(Delta_t, 2)*X*delta*(2*Delta*X*delta + 1) - Delta_tt*pow(2*Delta*X*delta + 1, 3) + X*delta*(Delta*Delta_tt + 3*pow(Delta_t, 2))*pow(2*Delta*X*delta + 1, 2))/pow(2*Delta*X*delta + 1, 4);
1622  double dXtt_dDelta = 2*pow(X, 3)*pow(delta, 2)*(-6*pow(Delta_t, 2)*X*delta*(Delta*X*delta + 1) - 3*pow(Delta_t, 2)*X*delta*(2*Delta*X*delta + 1) + Delta_tt*pow(2*Delta*X*delta + 1, 2))/pow(2*Delta*X*delta + 1, 4);
1623  double dXtt_dDelta_t = 4*Delta_t*pow(X, 3)*pow(delta, 2)*(3*Delta*X*delta + 2)/pow(2*Delta*X*delta + 1, 3);
1624  double dXtt_dDelta_tt = -pow(X, 2)*delta/(2*Delta*X*delta + 1);
1625  return dXtt_dX*dX_dDelta*Delta_t+dXtt_dDelta*Delta_t + dXtt_dDelta_t*Delta_tt + dXtt_dDelta_tt*Delta_ttt;
1626 }
1627 double phir_SAFT_associating::d3X_ddeltadtau2(double tau, double delta)
1628 {
1629  double Delta = this->Deltabar(tau, delta);
1630  double X = this->X(delta, Delta);
1631  double dX_ddelta = this->dX_ddelta__constDeltabar(delta, Delta);
1632  double dX_dDelta = this->dX_dDeltabar__constdelta(delta, Delta);
1633  double Delta_t = this->dDeltabar_dtau__constdelta(tau, delta);
1634  double Delta_d = this->dDeltabar_ddelta__consttau(tau, delta);
1635  double Delta_dt = this->d2Deltabar_ddelta_dtau(tau, delta);
1636  double Delta_tt = this->d2Deltabar_dtau2__constdelta(tau, delta);
1637  double Delta_dtt = this->d3Deltabar_ddelta_dtau2(tau, delta);
1638  double dXtt_ddelta = pow(X, 2)*(-12*Delta*pow(Delta_t, 2)*pow(X, 2)*pow(delta, 2)*(Delta*X*delta + 1) + 2*pow(Delta_t, 2)*X*delta*(-Delta*X*delta + 2)*(2*Delta*X*delta + 1) - Delta_tt*pow(2*Delta*X*delta + 1, 3) + 2*X*delta*(Delta*Delta_tt + 2*pow(Delta_t, 2))*pow(2*Delta*X*delta + 1, 2))/pow(2*Delta*X*delta + 1, 4);
1639  double dXtt_dX = 2*X*delta*(-6*Delta*pow(Delta_t, 2)*pow(X, 2)*pow(delta, 2)*(Delta*X*delta + 1) + 3*pow(Delta_t, 2)*X*delta*(2*Delta*X*delta + 1) - Delta_tt*pow(2*Delta*X*delta + 1, 3) + X*delta*(Delta*Delta_tt + 3*pow(Delta_t, 2))*pow(2*Delta*X*delta + 1, 2))/pow(2*Delta*X*delta + 1, 4);
1640  double dXtt_dDelta = 2*pow(X, 3)*pow(delta, 2)*(-6*pow(Delta_t, 2)*X*delta*(Delta*X*delta + 1) - 3*pow(Delta_t, 2)*X*delta*(2*Delta*X*delta + 1) + Delta_tt*pow(2*Delta*X*delta + 1, 2))/pow(2*Delta*X*delta + 1, 4);
1641  double dXtt_dDelta_t = 4*Delta_t*pow(X, 3)*pow(delta, 2)*(3*Delta*X*delta + 2)/pow(2*Delta*X*delta + 1, 3);
1642  double dXtt_dDelta_tt = -pow(X, 2)*delta/(2*Delta*X*delta + 1);
1643  return dXtt_ddelta + dXtt_dX*dX_ddelta + dXtt_dX*dX_dDelta*Delta_d + dXtt_dDelta*Delta_d + dXtt_dDelta_t*Delta_dt + dXtt_dDelta_tt*Delta_dtt;
1644 }
1645 
1646 double phir_SAFT_associating::d3X_ddelta2dtau(double tau, double delta)
1647 {
1648  double Delta = this->Deltabar(tau, delta);
1649  double X = this->X(delta, Delta);
1650  double dX_ddelta = this->dX_ddelta__constDeltabar(delta, Delta);
1651  double dX_dDelta = this->dX_dDeltabar__constdelta(delta, Delta);
1652  double Delta_t = this->dDeltabar_dtau__constdelta(tau, delta);
1653  double Delta_d = this->dDeltabar_ddelta__consttau(tau, delta);
1654  double Delta_dd = this->d2Deltabar_ddelta2__consttau(tau, delta);
1655  double Delta_dt = this->d2Deltabar_ddelta_dtau(tau, delta);
1656  double Delta_tt = this->d2Deltabar_dtau2__constdelta(tau, delta);
1657  double Delta_ddt = this->d3Deltabar_ddelta2_dtau(tau, delta);
1658  double dXdd_dX = 2*X*(-6*Delta*pow(X, 2)*delta*pow(Delta + Delta_d*delta, 2)*(Delta*X*delta + 1) - Delta_dd*delta*pow(2*Delta*X*delta + 1, 3) + 2*X*(2*Delta*X*delta + 1)*(-Delta*Delta_d*delta*(2*Delta_d*X*pow(delta, 2) - 1) - Delta*delta*(2*pow(Delta, 2)*X - Delta_d) + Delta*(Delta + Delta_d*delta)*(Delta*X*delta + 1) + Delta_d*delta*(Delta + Delta_d*delta)*(Delta*X*delta + 1)) + pow(2*Delta*X*delta + 1, 2)*(3*pow(Delta, 2)*X + Delta*Delta_dd*X*pow(delta, 2) + Delta*X*(Delta + Delta_d*delta) + pow(Delta_d, 2)*X*pow(delta, 2) + Delta_d*X*delta*(Delta + Delta_d*delta) + Delta_d*(2*Delta_d*X*pow(delta, 2) - 1) - Delta_d))/pow(2*Delta*X*delta + 1, 4);
1659  double dXdd_ddelta = pow(X, 2)*(-24*pow(Delta, 4)*pow(X, 3)*delta - 8*pow(Delta, 3)*Delta_d*pow(X, 3)*pow(delta, 2) - 18*pow(Delta, 3)*pow(X, 2) + 8*pow(Delta, 2)*Delta_d*pow(X, 2)*delta - 4*pow(Delta, 2)*Delta_dd*pow(X, 2)*pow(delta, 2) + 10*Delta*pow(Delta_d, 2)*pow(X, 2)*pow(delta, 2) + 12*Delta*Delta_d*X - 4*Delta*Delta_dd*X*delta + 8*pow(Delta_d, 2)*X*delta - Delta_dd)/(16*pow(Delta, 4)*pow(X, 4)*pow(delta, 4) + 32*pow(Delta, 3)*pow(X, 3)*pow(delta, 3) + 24*pow(Delta, 2)*pow(X, 2)*pow(delta, 2) + 8*Delta*X*delta + 1);
1660  double dXdd_dDelta = pow(X, 3)*(-8*pow(Delta, 2)*Delta_d*pow(X, 2)*pow(delta, 3) + 8*pow(Delta, 2)*Delta_dd*pow(X, 2)*pow(delta, 4) + 10*pow(Delta, 2)*X*delta - 24*Delta*pow(Delta_d, 2)*pow(X, 2)*pow(delta, 4) + 8*Delta*Delta_d*X*pow(delta, 2) + 8*Delta*Delta_dd*X*pow(delta, 3) + 8*Delta - 18*pow(Delta_d, 2)*X*pow(delta, 3) + 12*Delta_d*delta + 2*Delta_dd*pow(delta, 2))/(16*pow(Delta, 4)*pow(X, 4)*pow(delta, 4) + 32*pow(Delta, 3)*pow(X, 3)*pow(delta, 3) + 24*pow(Delta, 2)*pow(X, 2)*pow(delta, 2) + 8*Delta*X*delta + 1);
1661  double dXdd_dDelta_d = 2*pow(X, 2)*(2*X*delta*(Delta + Delta_d*delta)*(Delta*X*delta + 1) + (2*Delta*X*delta + 1)*(2*Delta_d*X*pow(delta, 2) - 1))/pow(2*Delta*X*delta + 1, 3);
1662  double dXdd_dDelta_dd = -pow(X, 2)*delta/(2*Delta*X*delta + 1);
1663 
1664  return dXdd_dX*dX_dDelta*Delta_t + dXdd_dDelta*Delta_t + dXdd_dDelta_d*Delta_dt + dXdd_dDelta_dd*Delta_ddt;
1665 }
1666 
1667 double Xdd(double X, double delta, double Delta, double Delta_d, double Delta_dd)
1668 {
1669  return Delta*pow(X, 2)*(2*Delta + 2*Delta_d*delta)*(Delta*pow(X, 2)*delta + X)/pow(2*Delta*X*delta + 1, 3) + Delta_d*pow(X, 2)*delta*(2*Delta + 2*Delta_d*delta)*(Delta*pow(X, 2)*delta + X)/pow(2*Delta*X*delta + 1, 3) + Delta_d*pow(X, 2)*(2*Delta_d*X*pow(delta, 2) - 1)/pow(2*Delta*X*delta + 1, 2) - Delta_dd*pow(X, 2)*delta/(2*Delta*X*delta + 1) + pow(X, 2)*(2*pow(Delta, 2)*X - Delta_d)/pow(2*Delta*X*delta + 1, 2);
1670 }
1671 
1672 double phir_SAFT_associating::d3X_ddelta3(double tau, double delta)
1673 {
1674  double Delta = this->Deltabar(tau, delta);
1675  double X = this->X(delta, Delta);
1676  double dX_ddelta = this->dX_ddelta__constDeltabar(delta, Delta);
1677  double dX_dDelta = this->dX_dDeltabar__constdelta(delta, Delta);
1678  double Delta_d = this->dDeltabar_ddelta__consttau(tau, delta);
1679  double Delta_dd = this->d2Deltabar_ddelta2__consttau(tau, delta);
1680  double Delta_ddd = this->d3Deltabar_ddelta3__consttau(tau, delta);
1681 
1682  double dXdd_dX = 2*X*(-6*Delta*pow(X, 2)*delta*pow(Delta + Delta_d*delta, 2)*(Delta*X*delta + 1) - Delta_dd*delta*pow(2*Delta*X*delta + 1, 3) + 2*X*(2*Delta*X*delta + 1)*(-Delta*Delta_d*delta*(2*Delta_d*X*pow(delta, 2) - 1) - Delta*delta*(2*pow(Delta, 2)*X - Delta_d) + Delta*(Delta + Delta_d*delta)*(Delta*X*delta + 1) + Delta_d*delta*(Delta + Delta_d*delta)*(Delta*X*delta + 1)) + pow(2*Delta*X*delta + 1, 2)*(3*pow(Delta, 2)*X + Delta*Delta_dd*X*pow(delta, 2) + Delta*X*(Delta + Delta_d*delta) + pow(Delta_d, 2)*X*pow(delta, 2) + Delta_d*X*delta*(Delta + Delta_d*delta) + Delta_d*(2*Delta_d*X*pow(delta, 2) - 1) - Delta_d))/pow(2*Delta*X*delta + 1, 4);
1683  double dXdd_ddelta = pow(X, 2)*(-24*pow(Delta, 4)*pow(X, 3)*delta - 8*pow(Delta, 3)*Delta_d*pow(X, 3)*pow(delta, 2) - 18*pow(Delta, 3)*pow(X, 2) + 8*pow(Delta, 2)*Delta_d*pow(X, 2)*delta - 4*pow(Delta, 2)*Delta_dd*pow(X, 2)*pow(delta, 2) + 10*Delta*pow(Delta_d, 2)*pow(X, 2)*pow(delta, 2) + 12*Delta*Delta_d*X - 4*Delta*Delta_dd*X*delta + 8*pow(Delta_d, 2)*X*delta - Delta_dd)/(16*pow(Delta, 4)*pow(X, 4)*pow(delta, 4) + 32*pow(Delta, 3)*pow(X, 3)*pow(delta, 3) + 24*pow(Delta, 2)*pow(X, 2)*pow(delta, 2) + 8*Delta*X*delta + 1);
1684  double dXdd_dDelta = pow(X, 3)*(-8*pow(Delta, 2)*Delta_d*pow(X, 2)*pow(delta, 3) + 8*pow(Delta, 2)*Delta_dd*pow(X, 2)*pow(delta, 4) + 10*pow(Delta, 2)*X*delta - 24*Delta*pow(Delta_d, 2)*pow(X, 2)*pow(delta, 4) + 8*Delta*Delta_d*X*pow(delta, 2) + 8*Delta*Delta_dd*X*pow(delta, 3) + 8*Delta - 18*pow(Delta_d, 2)*X*pow(delta, 3) + 12*Delta_d*delta + 2*Delta_dd*pow(delta, 2))/(16*pow(Delta, 4)*pow(X, 4)*pow(delta, 4) + 32*pow(Delta, 3)*pow(X, 3)*pow(delta, 3) + 24*pow(Delta, 2)*pow(X, 2)*pow(delta, 2) + 8*Delta*X*delta + 1);
1685  double dXdd_dDelta_d = 2*pow(X, 2)*(2*X*delta*(Delta + Delta_d*delta)*(Delta*X*delta + 1) + (2*Delta*X*delta + 1)*(2*Delta_d*X*pow(delta, 2) - 1))/pow(2*Delta*X*delta + 1, 3);
1686  double dXdd_dDelta_dd = -pow(X, 2)*delta/(2*Delta*X*delta + 1);
1687 
1688  return dXdd_ddelta + dXdd_dX*(dX_ddelta + dX_dDelta*Delta_d) + dXdd_dDelta*Delta_d + dXdd_dDelta_d*Delta_dd + dXdd_dDelta_dd*Delta_ddd;
1689 }
1690 
1691 
1692 double phir_SAFT_associating::g(double eta)
1693 {
1694  return 0.5*(2-eta)/pow(1-eta,(int)3);
1695 }
1697 {
1698  return 0.5*(5-2*eta)/pow(1-eta,(int)4);
1699 }
1701 {
1702  return 3*(3-eta)/pow(1-eta,(int)5);
1703 }
1705 {
1706  return 6*(7-2*eta)/pow(1-eta,(int)6);
1707 }
1708 double phir_SAFT_associating::eta(double delta){
1709  return this->vbarn*delta;
1710 }
1711 double phir_SAFT_associating::base(double tau, double delta)
1712 {
1713  double X = this->X(delta, this->Deltabar(tau, delta));
1714  return this->m*this->a*((log(X)-X/2.0+0.5));
1715 }
1716 double phir_SAFT_associating::dDelta(double tau, double delta)
1717 {
1718  double X = this->X(delta, this->Deltabar(tau, delta));
1719  return this->m*this->a*(1/X-0.5)*this->dX_ddelta(tau, delta);
1720 }
1721 double phir_SAFT_associating::dTau(double tau, double delta)
1722 {
1723  double X = this->X(delta, this->Deltabar(tau, delta));
1724  return this->m*this->a*(1/X-0.5)*this->dX_dtau(tau, delta);
1725 }
1726 double phir_SAFT_associating::dTau2(double tau, double delta)
1727 {
1728  double X = this->X(delta, this->Deltabar(tau, delta));
1729  double X_tau = this->dX_dtau(tau, delta);
1730  double X_tautau = this->d2X_dtau2(tau, delta);
1731  return this->m*this->a*((1/X-0.5)*X_tautau-pow(X_tau/X, 2));
1732 }
1733 double phir_SAFT_associating::dDelta2(double tau, double delta)
1734 {
1735  double X = this->X(delta, this->Deltabar(tau, delta));
1736  double X_delta = this->dX_ddelta(tau, delta);
1737  double X_deltadelta = this->d2X_ddelta2(tau, delta);
1738  return this->m*this->a*((1/X-0.5)*X_deltadelta-pow(X_delta/X,2));
1739 }
1740 double phir_SAFT_associating::dDelta_dTau(double tau, double delta)
1741 {
1742  double X = this->X(delta, this->Deltabar(tau, delta));
1743  double X_delta = this->dX_ddelta(tau, delta);
1744  double X_deltadelta = this->d2X_ddelta2(tau, delta);
1745  double X_tau = this->dX_dtau(tau, delta);
1746  double X_deltatau = this->d2X_ddeltadtau(tau, delta);
1747  return this->m*this->a*((-X_tau/X/X)*X_delta+X_deltatau*(1/X-0.5));
1748 }
1749 double phir_SAFT_associating::dTau3(double tau, double delta)
1750 {
1751  double X = this->X(delta, this->Deltabar(tau, delta));
1752  double X_t = this->dX_dtau(tau, delta);
1753  double X_tt = this->d2X_dtau2(tau, delta);
1754  double X_ttt = this->d3X_dtau3(tau, delta);
1755  return this->m*this->a*((1/X-1.0/2.0)*X_ttt+(-X_t/pow(X,(int)2))*X_tt-2*(pow(X,(int)2)*(X_t*X_tt)-pow(X_t,(int)2)*(X*X_t))/pow(X,(int)4));
1756 }
1757 double phir_SAFT_associating::dDelta_dTau2(double tau, double delta)
1758 {
1759  double X = this->X(delta, this->Deltabar(tau, delta));
1760  double X_t = this->dX_dtau(tau, delta);
1761  double X_d = this->dX_ddelta(tau, delta);
1762  double X_tt = this->d2X_dtau2(tau, delta);
1763  double X_dt = this->d2X_ddeltadtau(tau, delta);
1764  double X_dtt = this->d3X_ddeltadtau2(tau, delta);
1765  return this->m*this->a*((1/X-1.0/2.0)*X_dtt-X_d/pow(X,(int)2)*X_tt-2*(pow(X,(int)2)*(X_t*X_dt)-pow(X_t,(int)2)*(X*X_d))/pow(X,(int)4));
1766 }
1767 double phir_SAFT_associating::dDelta2_dTau(double tau, double delta)
1768 {
1769  double X = this->X(delta, this->Deltabar(tau, delta));
1770  double X_t = this->dX_dtau(tau, delta);
1771  double X_d = this->dX_ddelta(tau, delta);
1772  double X_dd = this->d2X_ddelta2(tau, delta);
1773  double X_dt = this->d2X_ddeltadtau(tau, delta);
1774  double X_ddt = this->d3X_ddelta2dtau(tau, delta);
1775  return this->m*this->a*((1/X-1.0/2.0)*X_ddt-X_t/pow(X,(int)2)*X_dd-2*(pow(X,(int)2)*(X_d*X_dt)-pow(X_d,(int)2)*(X*X_t))/pow(X,(int)4));
1776 }
1777 double phir_SAFT_associating::dDelta3(double tau, double delta)
1778 {
1779  double X = this->X(delta, this->Deltabar(tau, delta));
1780  double X_d = this->dX_ddelta(tau, delta);
1781  double X_dd = this->d2X_ddelta2(tau, delta);
1782  double X_ddd = this->d3X_ddelta3(tau, delta);
1783  return this->m*this->a*((1/X-1.0/2.0)*X_ddd-X_d/pow(X,(int)2)*X_dd-2*(pow(X,(int)2)*(X_d*X_dd)-pow(X_d,(int)2)*(X*X_d))/pow(X,(int)4));
1784 }
1785 #ifndef DISABLE_CATCH
1786 
1787 TEST_CASE("SAFT Helmholtz derivative check", "[helmholtz],[fast]")
1788 {
1789  double m = 0.977118832;
1790  double epsilon = 5.46341463;
1791  double vbarn = 0.204481952;
1792  double kappa = 0.148852832e-2;
1793  phir_SAFT_associating_2B phir = phir_SAFT_associating_2B(m,epsilon,vbarn,kappa);
1794  double eps = sqrt(DBL_EPSILON);
1795 
1796  SECTION("dDelta")
1797  {
1798  double ANA = phir.dDelta(0.5, 0.5);
1799  double NUM = (phir.base(0.5, 0.5+eps) - phir.base(0.5,0.5-eps))/(2*eps);
1800  REQUIRE(fabs(NUM-ANA) < 1e-6);
1801  }
1802  SECTION("dTau")
1803  {
1804  double ANA = phir.dTau(0.5, 0.5);
1805  double NUM = (phir.base(0.5+eps, 0.5) - phir.base(0.5-eps,0.5))/(2*eps);
1806  REQUIRE(fabs(NUM-ANA) < 1e-6);
1807  }
1808  SECTION("dDelta2")
1809  {
1810  double ANA = phir.dDelta2(0.5, 0.5);
1811  double NUM = (phir.dDelta(0.5, 0.5+eps) - phir.dDelta(0.5,0.5-eps))/(2*eps);
1812  REQUIRE(fabs(NUM-ANA) < 1e-6);
1813  }
1814  SECTION("dTau2")
1815  {
1816  double ANA = phir.dTau2(0.5, 0.5);
1817  double NUM = (phir.dTau(0.5+eps, 0.5) - phir.dTau(0.5-eps,0.5))/(2*eps);
1818  REQUIRE(fabs(NUM-ANA) < 1e-6);
1819  }
1820  SECTION("dDeltadTau")
1821  {
1822  double ANA = phir.dDelta_dTau(0.5, 0.5);
1823  double NUM = (phir.dTau(0.5, 0.5+eps) - phir.dTau(0.5,0.5-eps))/(2*eps);
1824  REQUIRE(fabs(NUM-ANA) < 1e-6);
1825  }
1826  SECTION("dTau3")
1827  {
1828  double ANA = phir.dTau3(0.5, 0.5);
1829  double NUM = (phir.dTau2(0.5+eps, 0.5) - phir.dTau2(0.5-eps,0.5))/(2*eps);
1830  REQUIRE(fabs(NUM-ANA) < 1e-6);
1831  }
1832  SECTION("dDelta3")
1833  {
1834  double ANA = phir.dDelta3(0.5, 0.5);
1835  double NUM = (phir.dDelta2(0.5, 0.5+eps) - phir.dDelta2(0.5,0.5-eps))/(2*eps);
1836  REQUIRE(fabs(NUM-ANA) < 1e-6);
1837  }
1838  SECTION("dDelta2dTau")
1839  {
1840  double ANA = phir.dDelta2_dTau(0.5, 0.5);
1841  double NUM = (phir.dDelta_dTau(0.5, 0.5+eps) - phir.dDelta_dTau(0.5,0.5-eps))/(2*eps);
1842  REQUIRE(fabs(NUM-ANA) < 1e-6);
1843  }
1844  SECTION("dDeltadTau2")
1845  {
1846  double ANA = phir.dDelta_dTau2(0.5, 0.5);
1847  double NUM = (phir.dDelta_dTau(0.5+eps, 0.5) - phir.dDelta_dTau(0.5-eps,0.5))/(2*eps);
1848  REQUIRE(fabs(NUM-ANA) < 1e-6);
1849  }
1850 }
1851 #endif
1852 
1854 {
1855  el.AddMember("type","IdealGasHelmholtzPlanckEinstein",doc.GetAllocator());
1857  for (int i=iStart;i<=iEnd;i++)
1858  {
1859  _n.PushBack(a[i],doc.GetAllocator());
1860  _t.PushBack(theta[i],doc.GetAllocator());
1861  }
1862  el.AddMember("n",_n,doc.GetAllocator());
1863  el.AddMember("t",_t,doc.GetAllocator());
1864 }
1865 
1866 double phi0_Planck_Einstein::base(double tau, double delta)
1867 {
1868  double summer=0;
1869  for (int i=iStart;i<=iEnd;i++)
1870  {
1871  summer+=a[i]*log(1.0-exp(-theta[i]*tau));
1872  }
1873  return summer;
1874 }
1875 double phi0_Planck_Einstein::dTau(double tau, double delta)
1876 {
1877  double summer=0;
1878  for (int i=iStart;i<=iEnd;i++)
1879  {
1880  summer+=a[i]*theta[i]*(1.0/(1.0-exp(-theta[i]*tau))-1.0);
1881  }
1882  return summer;
1883 }
1884 double phi0_Planck_Einstein::dTau2(double tau, double delta)
1885 {
1886  double summer=0;
1887  for (int i=iStart;i<=iEnd;i++)
1888  {
1889  summer -= a[i]*pow(theta[i],2.0)*exp(theta[i]*tau)/pow(1.0-exp(theta[i]*tau),2.0);
1890  }
1891  return summer;
1892 }
1893 double phi0_Planck_Einstein::dTau3(double tau, double delta)
1894 {
1895  double summer=0;
1896  for (int i=iStart;i<=iEnd;i++)
1897  {
1898  summer += a[i]*pow(theta[i],2.0)*theta[i]*exp(theta[i]*tau)*(exp(theta[i]*tau)+1)/pow(exp(theta[i]*tau)-1,3.0);
1899  }
1900  return summer;
1901 }
1902 
1903 
1905 {
1906  el.AddMember("type","IdealGasHelmholtzPlanckEinstein2",doc.GetAllocator());
1908  for (int i=iStart;i<=iEnd;i++)
1909  {
1910  _n.PushBack(a[i],doc.GetAllocator());
1911  _c.PushBack(c[i],doc.GetAllocator());
1912  _t.PushBack(theta[i],doc.GetAllocator());
1913  }
1914  el.AddMember("n",_n,doc.GetAllocator());
1915  el.AddMember("c",_c,doc.GetAllocator());
1916  el.AddMember("t",_t,doc.GetAllocator());
1917 }
1918 
1919 /*
1920 Maxima code for the term:
1921 
1922 term:a*log(c+exp(%theta*%tau));
1923 ratsimp(diff(term,%tau));
1924 ratsimp(diff(%,%tau));
1925 
1926 (%o23) a*log(c+%e^(%tau*%theta))
1927 (%o24) (%theta*%e^(%tau*%theta)*a)/(c+%e^(%tau*%theta))
1928 (%o25) (%theta^2*%e^(%tau*%theta)*a*c)/(c^2+2*%e^(%tau*%theta)*c+%e^(2*%tau*%theta))
1929 */
1930 double phi0_Planck_Einstein2::base(double tau, double delta)
1931 {
1932  double summer=0;
1933  for (int i=iStart;i<=iEnd;i++)
1934  {
1935  //a_0*log(c+exp(-theta_0*tau))
1936  summer+=a[i]*log(c[i]+exp(theta[i]*tau));
1937  }
1938  return summer;
1939 }
1940 double phi0_Planck_Einstein2::dTau(double tau, double delta)
1941 {
1942  double summer=0;
1943  for (int i=iStart;i<=iEnd;i++)
1944  {
1945  summer+=a[i]*theta[i]*exp(tau*theta[i])/(c[i]+exp(theta[i]*tau));
1946  }
1947  return summer;
1948 }
1949 double phi0_Planck_Einstein2::dTau2(double tau, double delta)
1950 {
1951  double summer=0;
1952  for (int i=iStart;i<=iEnd;i++)
1953  {
1954  summer+=a[i]*pow(theta[i],2)*c[i]*exp(tau*theta[i])/pow(c[i]+exp(tau*theta[i]),2);
1955  }
1956  return summer;
1957 }
1958 double phi0_Planck_Einstein2::dTau3(double tau, double delta)
1959 {
1960  double summer=0;
1961  for (int i=iStart;i<=iEnd;i++)
1962  {
1963  summer += a[i]*pow(theta[i],2.0)*c[i]*(-theta[i])*exp(theta[i]*tau)*(exp(theta[i]*tau)-c[i])/pow(exp(theta[i]*tau)+c[i],3.0);
1964  }
1965  return summer;
1966 }
1967 
1969  el.AddMember("type","IdealGasHelmholtzCP0AlyLee",doc.GetAllocator());
1971  for (int i=1;i<=5;i++)
1972  {
1973  if (i==1 || i==2 || i==4){
1974  _n.PushBack(a[i]/R_u,doc.GetAllocator());
1975  }
1976  else
1977  {
1978  _n.PushBack(a[i],doc.GetAllocator());
1979  }
1980  }
1981  el.AddMember("c",_n,doc.GetAllocator());
1982  el.AddMember("Tc",Tc,doc.GetAllocator());
1983  el.AddMember("T0",T0,doc.GetAllocator());
1984 }
1985 /*
1986 Maxima code for the sinh term:
1987 part a)
1988 ((Tc*chi/tau)/sinh(Tc*chi/tau))^2;
1989 -integrate(%,tau);
1990 ratsimp(%);
1991 part b)
1992 ((Tc*chi/tau)/sinh(Tc*chi/tau))^2;
1993 integrate(%/tau,tau);
1994 ratsimp(%);
1995 Swap cosh for sinh and do it again
1996 */
1997 double phi0_cp0_AlyLee::base(double tau, double delta)
1998 {
1999  return -tau/R_u*(anti_deriv_cp0_tau2(tau)-anti_deriv_cp0_tau2(tau0))+1/R_u*(anti_deriv_cp0_tau(tau)-anti_deriv_cp0_tau(tau0));
2000 }
2001 double phi0_cp0_AlyLee::dTau(double tau, double delta)
2002 {
2003  // combining the integral terms for dTau yields
2004  // -1/Rbar*int(cp0/tau^2,dtau,tau0,tau)
2005 
2006  return -1/R_u*(anti_deriv_cp0_tau2(tau) - anti_deriv_cp0_tau2(tau0));
2007 }
2009 {
2010  /*
2011  Maxima code:
2012  a[1]+a[2]*(a[3]*tau/Tc/sinh(a[3]*tau/Tc))^2+a[4]*(a[5]*tau/Tc/cosh(a[5]*tau/Tc))^2;
2013  integrate(%/tau^2,tau);
2014  */
2015  return (4*a[4]*a[5])/(Tc*(2*exp(-(2*a[5]*tau)/Tc)+2))+(4*a[2]*a[3])/(Tc*(2*exp(-(2*a[3]*tau)/Tc)-2))-a[1]/tau;
2016 }
2018 {
2019  double term1;
2020  /*
2021  Maxima code:
2022  a[1]+a[2]*(a[3]*tau/Tc/sinh(a[3]*tau/Tc))^2+a[4]*(a[5]*tau/Tc/cosh(a[5]*tau/Tc))^2;
2023  integrate(%/tau,tau);
2024  */
2025  if (a[4] == 0.0 && a[5] == 0.0)
2026  {
2027  term1 = 0;
2028  }
2029  else
2030  {
2031  term1 = (4*a[4]*a[5]*a[5]*((tau*Tc*exp((2*a[5]*tau)/Tc))/(2*a[5]*exp((2*a[5]*tau)/Tc)+2*a[5])-(Tc*Tc*log(exp((2*a[5]*tau)/Tc)+1))/(4*a[5]*a[5])))/Tc/Tc;
2032  }
2033 
2034  double term2 = (4*a[2]*a[3]*a[3]*((Tc*Tc*log(exp((a[3]*tau)/Tc)+1))/(4*a[3]*a[3])+(Tc*Tc*log(exp((a[3]*tau)/Tc)-1))/(4*a[3]*a[3])-(tau*Tc*exp((2*a[3]*tau)/Tc))/(2*a[3]*exp((2*a[3]*tau)/Tc)-2*a[3])))/Tc/Tc;
2035  double term3 = a[1]*log(tau);
2036  return term1 + term2 + term3;
2037 }
2038 double phi0_cp0_AlyLee::cp0(double tau)
2039 {
2040  return a[1]+a[2]*pow(a[3]*tau/Tc/sinh(a[3]*tau/Tc),2)+a[4]*pow(a[5]*tau/Tc/(cosh(a[5]*tau/Tc)),2);
2041 }
2042 double phi0_cp0_AlyLee::dTau2(double tau, double delta)
2043 {
2044  // The first integral term goes away, leaving just the second partial of the term (1/Rbar)*int(cp0/tau,dtau,tau0,tau)
2045  // which is equal to 1/Rbar*((tau*dcp0_dtau-cp0)/tau^2)
2046  return -cp0(tau)/(tau*tau*R_u);
2047 }
2048 double phi0_cp0_AlyLee::dTau3(double tau, double delta)
2049 {
2050  // -cp0/tau/tau/R_u = -a[1]/tau^2/R_u-a[2]/R_u*(a[3]/Tc/sinh(a[3]*tau/Tc))^2-a[4]/R_u*(a[5]/Tc/cosh(a[5]*tau/Tc))^2;
2051  return 2*a[1]/tau/tau/tau/R_u -a[2]/R_u*(-2)*pow(a[3]/Tc,3)*cosh(a[3]*tau/Tc)/pow(sinh(a[3]*tau/Tc),3) -a[4]/R_u*(-2)*pow(a[5]/Tc,3)*sinh(a[5]*tau/Tc)/pow(cosh(a[5]*tau/Tc),3);
2052 }
2053 
2054 
2056 {
2057  el.AddMember("type","IdealGasHelmholtzCP0PolyT", doc.GetAllocator());
2058 
2060  for (int i=iStart;i<=iEnd;i++)
2061  {
2062  _a.PushBack(a[i],doc.GetAllocator());
2063  _t.PushBack(tv[i],doc.GetAllocator());
2064  }
2065  el.AddMember("c",_a,doc.GetAllocator());
2066  el.AddMember("t",_t,doc.GetAllocator());
2067  el.AddMember("Tc",Tc,doc.GetAllocator());
2068  el.AddMember("T0",T0,doc.GetAllocator());
2069 }
2070 
2071 double phi0_cp0_poly::dTau(double tau, double delta)
2072 {
2073  double sum=0;
2074  for (int i = iStart; i<=iEnd; i++){
2075  double t=tv[i];
2076  if (fabs(t)<10*DBL_EPSILON)
2077  {
2078  sum += a[i]/tau-a[i]/tau0;
2079  }
2080  else if (fabs(t+1) < 10*DBL_EPSILON)
2081  {
2082  sum += a[i]/Tc*log(tau0/tau);
2083  }
2084  else
2085  {
2086  sum+=a[i]*pow(Tc,t)*pow(tau,-t-1)/(t+1)-a[i]*pow(Tc,t)/(pow(tau0,t+1)*(t+1));
2087  }
2088  }
2089  return sum;
2090 }
2091 
2092 double phi0_cp0_poly::dTau2(double tau, double delta)
2093 {
2094  double sum=0;
2095  for (int i = iStart; i<=iEnd; i++){
2096  double t = tv[i];
2097  if (fabs(t)<10*DBL_EPSILON)
2098  {
2099  sum += -a[i]/(tau*tau);
2100  }
2101  else if (fabs(t+1) < 10*DBL_EPSILON)
2102  {
2103  sum += -a[i]/(tau*Tc);
2104  }
2105  else
2106  {
2107  sum += -a[i]*pow(Tc/tau,tv[i])/(tau*tau);
2108  }
2109  }
2110  return sum;
2111 }
2112 
2113 double phi0_cp0_poly::dTau3(double tau, double delta)
2114 {
2115  double sum=0;
2116  for (int i = iStart; i<=iEnd; i++){
2117  double t = tv[i];
2118  if (fabs(t)<10*DBL_EPSILON)
2119  {
2120  sum += 2*a[i]/(tau*tau*tau);
2121  }
2122  else if (fabs(t+1) < 10*DBL_EPSILON)
2123  {
2124  sum += a[i]/(tau*tau*Tc);
2125  }
2126  else
2127  {
2128  sum += a[i]*pow(Tc/tau,tv[i])*(tv[i]+2)/(tau*tau*tau);
2129  }
2130  }
2131  return sum;
2132 }
2133 
2134 
2135 
2136 
2137 #ifndef DISABLE_CATCH
2138 
2139 //class HelmholtzTestsFixture {
2140 // private:
2141 // static int uniqueID;
2142 // protected:
2143 // phi_BC* phi;
2144 // public:
2145 // HelmholtzTestsFixture() : conn(DBConnection::createConnection("myDB")) {
2146 // }
2147 //
2148 // protected:
2149 // int getID() {
2150 // return ++uniqueID;
2151 // }
2152 // };
2153 //
2154 // int HelmholtzTestsFixture::uniqueID = 0;
2155 //
2156 // TEST_CASE_METHOD(UniqueTestsFixture, "phi0_power Helmholtz checks", "[helmholtz]") {
2157 // REQUIRE_THROWS(HelmholtzTestsFixture));
2158 // }
2159 
2160 TEST_CASE("phi0_power Helmholtz derivative check", "[helmholtz],[fast]")
2161 {
2162 
2163  /*phi0list.push_back(new phi0_power());
2164  phi0list.push_back(new phi0_power());*/
2165 
2166  phi0_Planck_Einstein phi = phi0_Planck_Einstein( 6.28891793, 2.09502491);
2167  double eps = sqrt(DBL_EPSILON);
2168 
2169  SECTION("dDelta")
2170  {
2171  double ANA = phi.dDelta(0.5, 0.5);
2172  double NUM = (phi.base(0.5, 0.5+eps) - phi.base(0.5,0.5-eps))/(2*eps);
2173  REQUIRE(fabs(NUM-ANA) < 1e-6);
2174  }
2175  SECTION("dTau")
2176  {
2177  double ANA = phi.dTau(0.5, 0.5);
2178  double NUM = (phi.base(0.5+eps, 0.5) - phi.base(0.5-eps,0.5))/(2*eps);
2179  REQUIRE(fabs(NUM-ANA) < 1e-6);
2180  }
2181  SECTION("dDelta2")
2182  {
2183  double ANA = phi.dDelta2(0.5, 0.5);
2184  double NUM = (phi.dDelta(0.5, 0.5+eps) - phi.dDelta(0.5,0.5-eps))/(2*eps);
2185  REQUIRE(fabs(NUM-ANA) < 1e-6);
2186  }
2187  SECTION("dTau2")
2188  {
2189  double ANA = phi.dTau2(0.5, 0.5);
2190  double NUM = (phi.dTau(0.5+eps, 0.5) - phi.dTau(0.5-eps,0.5))/(2*eps);
2191  REQUIRE(fabs(NUM-ANA) < 1e-6);
2192  }
2193  SECTION("dDeltadTau")
2194  {
2195  double ANA = phi.dDelta_dTau(0.5, 0.5);
2196  double NUM = (phi.dTau(0.5, 0.5+eps) - phi.dTau(0.5,0.5-eps))/(2*eps);
2197  REQUIRE(fabs(NUM-ANA) < 1e-6);
2198  }
2199 }
2200 #endif
double d3Deltabar_dtau3__constdelta(double tau, double delta)
Definition: Helmholtz.cpp:1524
double d3Deltabar_ddelta_dtau2(double tau, double delta)
Definition: Helmholtz.cpp:1528
std::vector< double > dTau2V(std::vector< double > tau, std::vector< double > delta)
Definition: Helmholtz.cpp:330
phir_exponential(std::vector< double >, std::vector< double >, std::vector< double >, std::vector< double >, std::vector< double >, int, int)
Definition: Helmholtz.cpp:414
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:455
double dDelta2_dTau(double tau, double delta)
Definition: Helmholtz.cpp:783
double dDeltabar_dtau__constdelta(double tau, double delta)
Definition: Helmholtz.cpp:1512
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:1384
double dDelta_dTau2(double tau, double delta)
Definition: Helmholtz.cpp:185
double dDelta2_dTau(double tau, double delta)
Definition: Helmholtz.cpp:530
virtual double dTau(double tau, double delta)=0
double A(double log_tau, double log_delta, double delta, int i)
Derivatives for a single term for use in fitter.
Definition: Helmholtz.cpp:257
double base(double tau, double delta)
Definition: Helmholtz.cpp:893
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:903
virtual double dDelta2(double tau, double delta)=0
double dX_dtau(double tau, double delta)
Definition: Helmholtz.cpp:1555
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:1721
double dDelta(double tau, double delta)
Definition: Helmholtz.cpp:1063
virtual double dDelta2_dTau(double tau, double delta)=0
double dDelta_dTau(double tau, double delta)
Definition: Helmholtz.cpp:247
double dTau3(double tau, double delta)
Definition: Helmholtz.cpp:681
double d2A_dDelta_dTau(double log_tau, double log_delta, double delta, int i)
Definition: Helmholtz.cpp:286
double d3Deltabar_ddelta3__consttau(double tau, double delta)
Definition: Helmholtz.cpp:1536
double dDelta_dTau2(double tau, double delta)
Definition: Helmholtz.cpp:482
double dDelta_dTau(double tau, double delta)
Definition: Helmholtz.cpp:1359
double dDelta(double tau, double delta)
Definition: Helmholtz.cpp:199
void cache()
Cache some terms for internal use.
Definition: Helmholtz.cpp:117
double dA_dDelta(double log_tau, double log_delta, double delta, int i)
Definition: Helmholtz.cpp:264
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:139
std::vector< double > dDelta2V(std::vector< double > tau, std::vector< double > delta)
Definition: Helmholtz.cpp:321
double dDelta_dTau(double tau, double delta)
Definition: Helmholtz.cpp:1103
double dDelta2(double tau, double delta)
Definition: Helmholtz.cpp:1073
double d2Deltabar_ddelta_dtau(double tau, double delta)
Definition: Helmholtz.cpp:1520
double d2g_deta2(double eta)
Definition: Helmholtz.cpp:1700
double dTau3(double tau, double delta)
Definition: Helmholtz.cpp:157
double dDelta2_dTau(double tau, double delta)
Definition: Helmholtz.cpp:233
double dDelta3(double tau, double delta)
Definition: Helmholtz.cpp:1278
double X(double delta, double Deltabar)
Definition: Helmholtz.cpp:1541
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:1875
double dDelta2(double tau, double delta)
Definition: Helmholtz.cpp:1733
double dTau3(double tau, double delta)
Definition: Helmholtz.cpp:923
phir_Lemmon2005(std::vector< double >, std::vector< double >, std::vector< double >, std::vector< double >, std::vector< double >, int, int)
Definition: Helmholtz.cpp:573
#define DBL_EPSILON
Definition: Helmholtz.cpp:10
double dX_ddelta(double tau, double delta)
Definition: Helmholtz.cpp:1560
double dX_ddelta__constDeltabar(double delta, double Deltabar)
Definition: Helmholtz.cpp:1550
double dDelta_dTau2(double tau, double delta)
Definition: Helmholtz.cpp:989
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:913
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:635
double dDelta2(double tau, double delta)
Definition: Helmholtz.cpp:502
double dDelta_dTau2(double tau, double delta)
Definition: Helmholtz.cpp:1757
double anti_deriv_cp0_tau(double tau)
Definition: Helmholtz.cpp:2017
std::string format(const char *fmt,...)
double d2Deltabar_ddelta2__consttau(double tau, double delta)
Definition: Helmholtz.cpp:1508
void to_json(rapidjson::Value &el, rapidjson::Document &doc)
Definition: Helmholtz.cpp:553
double d2X_ddeltadtau(double tau, double delta)
Definition: Helmholtz.cpp:1578
double dA_dTau(double log_tau, double log_delta, double delta, int i)
Definition: Helmholtz.cpp:296
double d2X_dtau2(double tau, double delta)
Definition: Helmholtz.cpp:1566
double anti_deriv_cp0_tau2(double tau)
Definition: Helmholtz.cpp:2008
double dDelta2(double tau, double delta)
Definition: Helmholtz.cpp:740
void to_json(rapidjson::Value &el, rapidjson::Document &doc)
Definition: Helmholtz.cpp:1154
virtual double base(double tau, double delta)=0
std::vector< double > d
The power for the delta terms.
Definition: Helmholtz.h:97
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:464
GenericValue & AddMember(GenericValue &name, GenericValue &value, Allocator &allocator)
Add a member (name-value pair) to the object.
Definition: document.h:258
double dDelta(double tau, double delta)
Definition: Helmholtz.cpp:1194
std::string to_json()
double dDelta_dTau2(double tau, double delta)
Definition: Helmholtz.cpp:1217
double base(double tau, double delta)
Definition: Helmholtz.cpp:1711
double d3X_ddeltadtau2(double tau, double delta)
Definition: Helmholtz.cpp:1627
double dDelta3(double tau, double delta)
Definition: Helmholtz.cpp:514
virtual double dDelta_dTau2(double tau, double delta)=0
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:1403
double d3X_ddelta3(double tau, double delta)
Definition: Helmholtz.cpp:1672
unsigned int iEnd
Definition: Helmholtz.h:96
double cp0(double tau)
Definition: Helmholtz.cpp:2038
double dDeltabar_ddelta__consttau(double tau, double delta)
Definition: Helmholtz.cpp:1504
double dDelta(double tau, double delta)
Definition: Helmholtz.h:646
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:2071
double dDelta2(double tau, double delta)
Definition: Helmholtz.h:647
virtual double dDelta(double tau, double delta)=0
double dDelta_dTau2(double tau, double delta)
Definition: Helmholtz.cpp:700
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:148
GenericValue & PushBack(GenericValue &value, Allocator &allocator)
Append a value at the end of the array.
Definition: document.h:396
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:1884
std::vector< double > l
Definition: Helmholtz.h:97
double dTau3(double tau, double delta)
Definition: Helmholtz.cpp:2048
unsigned int iStart
Definition: Helmholtz.h:96
double dX_dDeltabar__constdelta(double delta, double Deltabar)
Definition: Helmholtz.cpp:1545
A document for parsing JSON text as DOM.
Definition: document.h:691
double dDelta2(double tau, double delta)
Definition: Helmholtz.cpp:208
double base(double tau, double delta)
Definition: Helmholtz.cpp:1930
void to_json(rapidjson::Value &el, rapidjson::Document &doc)
Definition: Helmholtz.cpp:394
double base(double tau, double delta)
Definition: Helmholtz.cpp:1997
double d2Deltabar_dtau2__constdelta(double tau, double delta)
Definition: Helmholtz.cpp:1516
virtual double dTau2(double tau, double delta)=0
std::vector< double > dDelta_dTauV(std::vector< double > tau, std::vector< double > delta)
Definition: Helmholtz.cpp:339
double dTau3(double tau, double delta)
Definition: Helmholtz.cpp:2113
double dTau3(double tau, double delta)
Definition: Helmholtz.cpp:1420
double dTau3(double tau, double delta)
Definition: Helmholtz.cpp:1958
double dTau3(double tau, double delta)
Definition: Helmholtz.cpp:1749
virtual double dTau3(double tau, double delta)=0
double dDelta3(double tau, double delta)
Definition: Helmholtz.cpp:1777
double d2X_ddelta2(double tau, double delta)
Definition: Helmholtz.cpp:1591
double d3X_ddelta2dtau(double tau, double delta)
Definition: Helmholtz.cpp:1646
std::vector< double > t
The powers for the tau terms.
Definition: Helmholtz.h:97
double dDelta2_dTau(double tau, double delta)
Definition: Helmholtz.cpp:1767
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:2001
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:2042
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:1940
Allocator & GetAllocator()
Get the allocator of this document.
Definition: document.h:758
double dDelta_dTau(double tau, double delta)
Definition: Helmholtz.cpp:804
double g(double eta)
Definition: Helmholtz.cpp:1692
void to_json(rapidjson::Value &el, rapidjson::Document &doc)
Definition: Helmholtz.cpp:1015
double base(double tau, double delta)
Definition: Helmholtz.cpp:1866
REQUIRE(fabs(CPWater.p()-RPWater.p())< 1e-4)
double dDelta(double tau, double delta)
Definition: Helmholtz.cpp:492
double d3g_deta3(double eta)
Definition: Helmholtz.cpp:1704
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:1093
double d2A_dDelta2(double log_tau, double log_delta, double delta, int i)
Definition: Helmholtz.cpp:277
double base(double tau, double delta)
Definition: Helmholtz.cpp:1181
void to_json(rapidjson::Value &el, rapidjson::Document &doc)
Definition: Helmholtz.cpp:868
double base(double tau, double delta)
Definition: Helmholtz.cpp:446
double dDelta2(double tau, double delta)
Definition: Helmholtz.cpp:948
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:1949
double dDelta3(double tau, double delta)
Definition: Helmholtz.cpp:217
double dDelta(double tau, double delta)
Definition: Helmholtz.cpp:721
double dDelta_dTau(double tau, double delta)
Definition: Helmholtz.cpp:1740
double dDelta2_dTau(double tau, double delta)
Definition: Helmholtz.cpp:1311
double base(double tau, double delta)
Definition: Helmholtz.cpp:130
double eta(double delta)
Definition: Helmholtz.cpp:1708
double dDelta3(double tau, double delta)
Definition: Helmholtz.cpp:760
void to_json(rapidjson::Value &el, rapidjson::Document &doc)
Definition: Helmholtz.cpp:1853
std::vector< double > dDeltaV(std::vector< double > tau, std::vector< double > delta)
Vectorized form so iteration happens at c++ level.
Definition: Helmholtz.cpp:312
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:2092
double d3X_dtau3(double tau, double delta)
Definition: Helmholtz.cpp:1613
virtual double dDelta3(double tau, double delta)=0
double dDelta(double tau, double delta)
Definition: Helmholtz.cpp:938
This is the abstract base class upon which each residual Helmholtz energy class is built...
Definition: Helmholtz.h:24
double dg_deta(double eta)
Definition: Helmholtz.cpp:1696
double Deltabar(double tau, double delta)
Definition: Helmholtz.cpp:1500
void to_json(rapidjson::Value &el, rapidjson::Document &doc)
Definition: Helmholtz.cpp:1968
phir_critical(std::vector< double > n_in, std::vector< double > d_in, std::vector< double > t_in, std::vector< double > a_in, std::vector< double > b_in, std::vector< double > beta_in, std::vector< double > A_in, std::vector< double > B_in, std::vector< double > C_in, std::vector< double > D_in, int iStart_in, int iEnd_in)
Definition: Helmholtz.cpp:1115
double dDelta_dTau(double tau, double delta)
Definition: Helmholtz.h:649
#define SECTION(name, description)
Definition: catch.hpp:8088
double d3Deltabar_ddelta2_dtau(double tau, double delta)
Definition: Helmholtz.cpp:1532
double dTau3(double tau, double delta)
Definition: Helmholtz.cpp:473
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition: document.h:30
double dTau3(double tau, double delta)
Definition: Helmholtz.cpp:1893
void to_json(rapidjson::Value &el, rapidjson::Document &doc)
Definition: Helmholtz.cpp:2055
void to_json(rapidjson::Value &el, rapidjson::Document &doc)
Definition: Helmholtz.cpp:1904
double Xdd(double X, double delta, double Delta, double Delta_d, double Delta_dd)
Definition: Helmholtz.cpp:1667
void to_json(rapidjson::Value &el, rapidjson::Document &doc)
Definition: Helmholtz.cpp:169
double dTau2(double tau, double delta)
Definition: Helmholtz.cpp:1726
double dDelta2_dTau(double tau, double delta)
Definition: Helmholtz.cpp:969
double dDelta_dTau(double tau, double delta)
Definition: Helmholtz.cpp:542
std::vector< double > n
The coefficients multiplying each term.
Definition: Helmholtz.h:97
double d2A_dTau2(double log_tau, double log_delta, double delta, int i)
Definition: Helmholtz.cpp:303
double base(double tau, double delta)
Definition: Helmholtz.cpp:1053
double base(double tau, double delta)
Definition: Helmholtz.cpp:605
double dDelta3(double tau, double delta)
Definition: Helmholtz.cpp:958
double dDelta2(double tau, double delta)
Definition: Helmholtz.cpp:1256
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:619
void check_derivatives(phi_BC *phi, double tau, double delta, double ddelta, double dtau)
Definition: Helmholtz.cpp:24
double dDelta(double tau, double delta)
Definition: Helmholtz.cpp:1716
virtual double dDelta_dTau(double tau, double delta)=0
double dDelta_dTau(double tau, double delta)
Definition: Helmholtz.cpp:979
TEST_CASE("Power Helmholtz terms","[helmholtz],[fast]")
Definition: Helmholtz.cpp:350
double dTau(double tau, double delta)
Definition: Helmholtz.cpp:1083