16 for (std::size_t i = 1; i < x.size(); ++i) {
25 return std::abs(i) > std::abs(j);
138 CoolPropDbl log_tau = log(tau), log_delta = log(delta), ndteu, one_over_delta = 1 / delta,
139 one_over_tau = 1 / tau;
143 const std::size_t N = elements.size();
144 for (std::size_t i = 0; i < N; ++i) {
163 const CoolPropDbl du_ddelta_increment = l_double * u_increment * one_over_delta;
164 const CoolPropDbl d2u_ddelta2_increment = (l_double - 1) * du_ddelta_increment * one_over_delta;
165 const CoolPropDbl d3u_ddelta3_increment = (l_double - 2) * d2u_ddelta2_increment * one_over_delta;
166 const CoolPropDbl d4u_ddelta4_increment = (l_double - 3) * d3u_ddelta3_increment * one_over_delta;
168 du_ddelta += du_ddelta_increment;
169 d2u_ddelta2 += d2u_ddelta2_increment;
170 d3u_ddelta3 += d3u_ddelta3_increment;
171 d4u_ddelta4 += d4u_ddelta4_increment;
176 if (std::abs(m_double) > 0) {
177 const CoolPropDbl u_increment = -omegai * pow(tau, m_double);
178 const CoolPropDbl du_dtau_increment = m_double * u_increment * one_over_tau;
179 const CoolPropDbl d2u_dtau2_increment = (m_double - 1) * du_dtau_increment * one_over_tau;
180 const CoolPropDbl d3u_dtau3_increment = (m_double - 2) * d2u_dtau2_increment * one_over_tau;
181 const CoolPropDbl d4u_dtau4_increment = (m_double - 3) * d3u_dtau3_increment * one_over_tau;
183 du_dtau += du_dtau_increment;
184 d2u_dtau2 += d2u_dtau2_increment;
185 d3u_dtau3 += d3u_dtau3_increment;
186 d4u_dtau4 += d4u_dtau4_increment;
192 u += -eta1 * (delta - epsilon1);
199 u += -eta2 *
POW2(delta - epsilon2);
200 du_ddelta += -2 * eta2 * (delta - epsilon2);
201 d2u_ddelta2 += -2 * eta2;
207 u += -beta1 * (tau - gamma1);
214 u += -beta2 *
POW2(tau - gamma2);
215 du_dtau += -2 * beta2 * (tau - gamma2);
216 d2u_dtau2 += -2 * beta2;
220 ndteu = ni * exp(ti * log_tau + di * log_delta + u);
222 const CoolPropDbl dB_delta_ddelta = delta * d2u_ddelta2 + du_ddelta;
223 const CoolPropDbl d2B_delta_ddelta2 = delta * d3u_ddelta3 + 2 * d2u_ddelta2;
224 const CoolPropDbl d3B_delta_ddelta3 = delta * d4u_ddelta4 + 3 * d3u_ddelta3;
226 const CoolPropDbl B_delta = (delta * du_ddelta + di);
227 const CoolPropDbl B_delta2 = delta * dB_delta_ddelta + (B_delta - 1) * B_delta;
228 const CoolPropDbl dB_delta2_ddelta = delta * d2B_delta_ddelta2 + 2 * B_delta * dB_delta_ddelta;
229 const CoolPropDbl B_delta3 = delta * dB_delta2_ddelta + (B_delta - 2) * B_delta2;
230 const CoolPropDbl dB_delta3_ddelta = delta * delta * d3B_delta_ddelta3 + 3 * delta * B_delta * d2B_delta_ddelta2
231 + 3 * delta *
POW2(dB_delta_ddelta) + 3 * B_delta * (B_delta - 1) * dB_delta_ddelta;
232 const CoolPropDbl B_delta4 = delta * dB_delta3_ddelta + (B_delta - 3) * B_delta3;
234 const CoolPropDbl dB_tau_dtau = tau * d2u_dtau2 + du_dtau;
235 const CoolPropDbl d2B_tau_dtau2 = tau * d3u_dtau3 + 2 * d2u_dtau2;
236 const CoolPropDbl d3B_tau_dtau3 = tau * d4u_dtau4 + 3 * d3u_dtau3;
239 const CoolPropDbl B_tau2 = tau * dB_tau_dtau + (B_tau - 1) * B_tau;
240 const CoolPropDbl dB_tau2_dtau = tau * d2B_tau_dtau2 + 2 * B_tau * dB_tau_dtau;
241 const CoolPropDbl B_tau3 = tau * dB_tau2_dtau + (B_tau - 2) * B_tau2;
243 tau * tau * d3B_tau_dtau3 + 3 * tau * B_tau * d2B_tau_dtau2 + 3 * tau *
POW2(dB_tau_dtau) + 3 * B_tau * (B_tau - 1) * dB_tau_dtau;
244 const CoolPropDbl B_tau4 = tau * dB_tau3_dtau + (B_tau - 3) * B_tau3;
246 derivs.alphar += ndteu;
248 derivs.dalphar_ddelta += ndteu * B_delta;
249 derivs.dalphar_dtau += ndteu * B_tau;
251 derivs.d2alphar_ddelta2 += ndteu * B_delta2;
252 derivs.d2alphar_ddelta_dtau += ndteu * B_delta * B_tau;
253 derivs.d2alphar_dtau2 += ndteu * B_tau2;
255 derivs.d3alphar_ddelta3 += ndteu * B_delta3;
256 derivs.d3alphar_ddelta2_dtau += ndteu * B_delta2 * B_tau;
257 derivs.d3alphar_ddelta_dtau2 += ndteu * B_delta * B_tau2;
258 derivs.d3alphar_dtau3 += ndteu * B_tau3;
260 derivs.d4alphar_ddelta4 += ndteu * B_delta4;
261 derivs.d4alphar_ddelta3_dtau += ndteu * B_delta3 * B_tau;
262 derivs.d4alphar_ddelta2_dtau2 += ndteu * B_delta2 * B_tau2;
263 derivs.d4alphar_ddelta_dtau3 += ndteu * B_delta * B_tau3;
264 derivs.d4alphar_dtau4 += ndteu * B_tau4;
266 derivs.dalphar_ddelta *= one_over_delta;
267 derivs.dalphar_dtau *= one_over_tau;
268 derivs.d2alphar_ddelta2 *=
POW2(one_over_delta);
269 derivs.d2alphar_dtau2 *=
POW2(one_over_tau);
270 derivs.d2alphar_ddelta_dtau *= one_over_delta * one_over_tau;
272 derivs.d3alphar_ddelta3 *=
POW3(one_over_delta);
273 derivs.d3alphar_dtau3 *=
POW3(one_over_tau);
274 derivs.d3alphar_ddelta2_dtau *=
POW2(one_over_delta) * one_over_tau;
275 derivs.d3alphar_ddelta_dtau2 *= one_over_delta *
POW2(one_over_tau);
277 derivs.d4alphar_ddelta4 *=
POW4(one_over_delta);
278 derivs.d4alphar_dtau4 *=
POW4(one_over_tau);
279 derivs.d4alphar_ddelta3_dtau *=
POW3(one_over_delta) * one_over_tau;
280 derivs.d4alphar_ddelta2_dtau2 *=
POW2(one_over_delta) *
POW2(one_over_tau);
281 derivs.d4alphar_ddelta_dtau3 *= one_over_delta *
POW3(one_over_tau);
287 el.AddMember(
"type",
"GeneralizedExponential", doc.GetAllocator());
304 el.AddMember(
"type",
"ResidualHelmholtzNonAnalytic", doc.GetAllocator());
306 rapidjson::Value _n(rapidjson::kArrayType), _a(rapidjson::kArrayType), _b(rapidjson::kArrayType), _beta(rapidjson::kArrayType),
307 _A(rapidjson::kArrayType), _B(rapidjson::kArrayType), _C(rapidjson::kArrayType), _D(rapidjson::kArrayType);
308 for (
unsigned int i = 0; i <=
N; ++i) {
310 _n.PushBack((
double)elem.
n, doc.GetAllocator());
311 _a.PushBack((
double)elem.
a, doc.GetAllocator());
312 _b.PushBack((
double)elem.
b, doc.GetAllocator());
313 _beta.PushBack((
double)elem.
beta, doc.GetAllocator());
314 _A.PushBack((
double)elem.
A, doc.GetAllocator());
315 _B.PushBack((
double)elem.
B, doc.GetAllocator());
316 _C.PushBack((
double)elem.
C, doc.GetAllocator());
317 _D.PushBack((
double)elem.
D, doc.GetAllocator());
319 el.AddMember(
"n", _n, doc.GetAllocator());
320 el.AddMember(
"a", _a, doc.GetAllocator());
321 el.AddMember(
"b", _b, doc.GetAllocator());
322 el.AddMember(
"beta", _beta, doc.GetAllocator());
323 el.AddMember(
"A", _A, doc.GetAllocator());
324 el.AddMember(
"B", _B, doc.GetAllocator());
325 el.AddMember(
"C", _C, doc.GetAllocator());
326 el.AddMember(
"D", _D, doc.GetAllocator());
344 for (
unsigned int i = 0; i < N; ++i) {
351 const CoolPropDbl theta = (1.0 - tau) + Ai * pow(
POW2(delta - 1.0), 1.0 / (2.0 * betai));
353 const CoolPropDbl dtheta_dDelta = Ai / (betai)*pow(
POW2(delta - 1), 1 / (2 * betai) - 1) * (delta - 1);
355 const CoolPropDbl d2theta_dDelta2 = Ai / betai * (1 / betai - 1) * pow(
POW2(delta - 1), 1 / (2 * betai) - 1);
356 const CoolPropDbl d3theta_dDelta3 = Ai / betai * (2 - 3 / betai + 1 /
POW2(betai)) * pow(
POW2(delta - 1), 1 / (2 * betai)) /
POW3(delta - 1);
358 Ai / betai * (-6 + 11 / betai - 6 /
POW2(betai) + 1 /
POW3(betai)) * pow(
POW2(delta - 1), 1 / (2 * betai) - 2);
362 const CoolPropDbl dPSI_dDelta_over_PSI = -2.0 * Ci * (delta - 1.0);
363 const CoolPropDbl dPSI_dDelta = dPSI_dDelta_over_PSI * PSI;
364 const CoolPropDbl dPSI_dTau_over_PSI = -2.0 * Di * (tau - 1.0);
365 const CoolPropDbl dPSI_dTau = dPSI_dTau_over_PSI * PSI;
366 const CoolPropDbl d2PSI_dDelta2_over_PSI = (2.0 * Ci *
POW2(delta - 1.0) - 1.0) * 2.0 * Ci;
367 const CoolPropDbl d2PSI_dDelta2 = d2PSI_dDelta2_over_PSI * PSI;
368 const CoolPropDbl d3PSI_dDelta3 = 2 * Ci * PSI * (-4 * Ci * Ci *
POW3(delta - 1) + 6 * Ci * (delta - 1));
369 const CoolPropDbl d4PSI_dDelta4 = 4 * Ci * Ci * PSI * (4 * Ci * Ci *
POW4(delta - 1) - 12 * Ci *
POW2(delta - 1) + 3);
370 const CoolPropDbl d2PSI_dTau2 = (2.0 * Di *
POW2(tau - 1.0) - 1.0) * 2.0 * Di * PSI;
371 const CoolPropDbl d3PSI_dTau3 = 2.0 * Di * PSI * (-4 * Di * Di *
POW3(tau - 1) + 6 * Di * (tau - 1));
372 const CoolPropDbl d4PSI_dTau4 = 4 * Di * Di * PSI * (4 * Di * Di *
POW4(tau - 1) - 12 * Di *
POW2(tau - 1) + 3);
373 const CoolPropDbl d2PSI_dDelta_dTau = dPSI_dDelta * dPSI_dTau_over_PSI;
374 const CoolPropDbl d3PSI_dDelta2_dTau = d2PSI_dDelta2 * dPSI_dTau_over_PSI;
375 const CoolPropDbl d3PSI_dDelta_dTau2 = d2PSI_dTau2 * dPSI_dDelta_over_PSI;
376 const CoolPropDbl d4PSI_dDelta_dTau3 = d3PSI_dTau3 * dPSI_dDelta_over_PSI;
377 const CoolPropDbl d4PSI_dDelta2_dTau2 = d2PSI_dTau2 * d2PSI_dDelta2_over_PSI;
378 const CoolPropDbl d4PSI_dDelta3_dTau = d3PSI_dDelta3 * dPSI_dTau_over_PSI;
382 const CoolPropDbl dDELTA_dTau = 2 * theta * dtheta_dTau;
383 const CoolPropDbl dDELTA_dDelta = 2 * theta * dtheta_dDelta + 2 * Bi * ai * pow(
POW2(delta - 1.0), ai - 1.0) * (delta - 1);
385 const CoolPropDbl d2DELTA_dDelta_dTau = 2 * dtheta_dTau * dtheta_dDelta;
387 2 * (theta * d2theta_dDelta2 +
POW2(dtheta_dDelta) + Bi * (2 * ai * ai - ai) * pow(
POW2(delta - 1.0), ai - 1.0));
390 const CoolPropDbl d3DELTA_dDelta2_dTau = 2 * dtheta_dTau * d2theta_dDelta2;
392 * (theta * d3theta_dDelta3 + 3 * dtheta_dDelta * d2theta_dDelta2
393 + 2 * Bi * ai * (2 * ai * ai - 3 * ai + 1) * pow(
POW2(delta - 1.0), ai - 1.0) / (delta - 1));
398 const CoolPropDbl d4DELTA_dDelta3_dTau = 2 * dtheta_dTau * d3theta_dDelta3;
400 * (theta * d4theta_dDelta4 + 4 * dtheta_dDelta * d3theta_dDelta3 + 3 *
POW2(d2theta_dDelta2)
401 + 2 * Bi * ai * (4 * ai * ai * ai - 12 * ai * ai + 11 * ai - 3) * pow(
POW2(delta - 1.0), ai - 2.0));
403 const CoolPropDbl dDELTAbi_dDelta = bi * pow(DELTA, bi - 1.0) * dDELTA_dDelta;
404 const CoolPropDbl dDELTAbi_dTau = -2.0 * theta * bi * pow(DELTA, bi - 1.0);
405 const CoolPropDbl d2DELTAbi_dDelta2 = bi * (pow(DELTA, bi - 1) * d2DELTA_dDelta2 + (bi - 1.0) * pow(DELTA, bi - 2.0) * pow(dDELTA_dDelta, 2));
408 * (pow(DELTA, bi - 1) * d3DELTA_dDelta3 + d2DELTA_dDelta2 * (bi - 1) * pow(DELTA, bi - 2) * dDELTA_dDelta
410 * (pow(DELTA, bi - 2) * 2 * dDELTA_dDelta * d2DELTA_dDelta2
411 + pow(dDELTA_dDelta, 2) * (bi - 2) * pow(DELTA, bi - 3) * dDELTA_dDelta));
413 -Ai * bi * 2.0 / betai * pow(DELTA, bi - 1.0) * (delta - 1.0) * pow(pow(delta - 1.0, 2), 1.0 / (2.0 * betai) - 1.0)
414 - 2.0 * theta * bi * (bi - 1.0) * pow(DELTA, bi - 2.0) * dDELTA_dDelta;
415 const CoolPropDbl d2DELTAbi_dTau2 = 2.0 * bi * pow(DELTA, bi - 1.0) + 4.0 * pow(theta, 2) * bi * (bi - 1.0) * pow(DELTA, bi - 2.0);
417 -12.0 * theta * bi * (bi - 1.0) * pow(DELTA, bi - 2) - 8 * pow(theta, 3) * bi * (bi - 1) * (bi - 2) * pow(DELTA, bi - 3);
418 const CoolPropDbl d3DELTAbi_dDelta_dTau2 = 2 * bi * (bi - 1) * pow(DELTA, bi - 2) * dDELTA_dDelta
419 + 4 * pow(theta, 2) * bi * (bi - 1) * (bi - 2) * pow(DELTA, bi - 3) * dDELTA_dDelta
420 + 8 * theta * bi * (bi - 1) * pow(DELTA, bi - 2) * dtheta_dDelta;
423 * ((bi - 1) * pow(DELTA, bi - 2) * dDELTA_dTau * d2DELTA_dDelta2 + pow(DELTA, bi - 1) * d3DELTA_dDelta2_dTau
425 * ((bi - 2) * pow(DELTA, bi - 3) * dDELTA_dTau * pow(dDELTA_dDelta, 2)
426 + pow(DELTA, bi - 2) * 2 * dDELTA_dDelta * d2DELTA_dDelta_dTau));
431 bi * DELTA_bi / DELTA
432 * ((
POW3(bi) - 6 *
POW2(bi) + 11 * bi - 6) *
POW4(dDELTA_dTau) /
POW3(DELTA)
433 + 6 * (bi * bi - 3 * bi + 2) *
POW2(dDELTA_dTau / DELTA) * d2DELTA_dTau2 + 4 * (bi - 1) * dDELTA_dTau / DELTA * d3DELTA_dTau3
434 + 3 * (bi - 1) *
POW2(d2DELTA_dTau2) / DELTA + d4DELTA_dTau4);
436 bi * DELTA_bi / DELTA
437 * ((
POW3(bi) - 6 *
POW2(bi) + 11 * bi - 6) *
POW4(dDELTA_dDelta) /
POW3(DELTA)
438 + 6 * (bi * bi - 3 * bi + 2) *
POW2(dDELTA_dDelta / DELTA) * d2DELTA_dDelta2 + 4 * (bi - 1) * dDELTA_dDelta / DELTA * d3DELTA_dDelta3
439 + 3 * (bi - 1) *
POW2(d2DELTA_dDelta2) / DELTA + d4DELTA_dDelta4);
441 bi * (bi - 1) * DELTA_bi /
POW2(DELTA) * dDELTA_dDelta
442 * ((bi - 1) * (bi - 2) *
POW3(dDELTA_dTau) /
POW2(DELTA) + 3 * (bi - 1) * dDELTA_dTau / DELTA * d2DELTA_dTau2 + d3DELTA_dTau3)
443 + bi * DELTA_bi / DELTA
444 * ((bi - 1) * (bi - 2)
445 * (3 *
POW2(dDELTA_dTau) /
POW2(DELTA) * d2DELTA_dDelta_dTau - 2 *
POW3(dDELTA_dTau) /
POW3(DELTA) * dDELTA_dDelta)
447 * (dDELTA_dTau / DELTA * d3DELTA_dDelta_dTau2 + d2DELTA_dTau2 / DELTA * d2DELTA_dDelta_dTau
448 - dDELTA_dDelta /
POW2(DELTA) * dDELTA_dTau * d2DELTA_dTau2)
449 + d4DELTA_dDelta_dTau3);
451 bi * (bi - 1) * DELTA_bi /
POW2(DELTA) * dDELTA_dTau
452 * ((bi - 1) * (bi - 2) *
POW3(dDELTA_dDelta) /
POW2(DELTA) + 3 * (bi - 1) * dDELTA_dDelta / DELTA * d2DELTA_dDelta2 + d3DELTA_dDelta3)
453 + bi * DELTA_bi / DELTA
454 * ((bi - 1) * (bi - 2)
455 * (3 *
POW2(dDELTA_dDelta) /
POW2(DELTA) * d2DELTA_dDelta_dTau - 2 *
POW3(dDELTA_dDelta) /
POW3(DELTA) * dDELTA_dTau)
457 * (dDELTA_dDelta / DELTA * d3DELTA_dDelta2_dTau + d2DELTA_dDelta2 / DELTA * d2DELTA_dDelta_dTau
458 - dDELTA_dTau /
POW2(DELTA) * dDELTA_dDelta * d2DELTA_dDelta2)
459 + d4DELTA_dDelta3_dTau);
460 const CoolPropDbl d4DELTAbi_dDelta2_dTau2 = bi * DELTA_bi /
POW4(DELTA)
461 * ((
POW3(bi) - 6 * bi * bi + 11 * bi - 6) *
POW2(dDELTA_dDelta) *
POW2(dDELTA_dTau)
462 + (bi - 1) * (bi - 2) * DELTA *
POW2(dDELTA_dDelta) * d2DELTA_dTau2
463 + (bi - 1) * (bi - 2) * DELTA *
POW2(dDELTA_dTau) * d2DELTA_dDelta2
464 + 4 * (bi - 1) * (bi - 2) * DELTA * dDELTA_dDelta * dDELTA_dTau * d2DELTA_dDelta_dTau
465 + 2 * (bi - 1) *
POW2(DELTA * d2DELTA_dDelta_dTau)
466 + 2 * (bi - 1) *
POW2(DELTA) * dDELTA_dTau * d3DELTA_dDelta2_dTau
467 + 2 * (bi - 1) *
POW2(DELTA) * dDELTA_dDelta * d3DELTA_dDelta_dTau2
468 + (bi - 1) *
POW2(DELTA) * d2DELTA_dDelta2 * d2DELTA_dTau2
469 +
POW3(DELTA) * d4DELTA_dDelta2_dTau2);
471 derivs.alphar += delta * ni * DELTA_bi * PSI;
474 derivs.dalphar_dtau += ni * delta * (DELTA_bi * dPSI_dTau + dDELTAbi_dTau * PSI);
475 derivs.dalphar_ddelta += ni * (DELTA_bi * (PSI + delta * dPSI_dDelta) + dDELTAbi_dDelta * delta * PSI);
478 derivs.d2alphar_dtau2 += ni * delta * (d2DELTAbi_dTau2 * PSI + 2 * dDELTAbi_dTau * dPSI_dTau + DELTA_bi * d2PSI_dTau2);
479 derivs.d2alphar_ddelta_dtau += ni
480 * (DELTA_bi * (dPSI_dTau + delta * d2PSI_dDelta_dTau) + delta * dDELTAbi_dDelta * dPSI_dTau
481 + dDELTAbi_dTau * (PSI + delta * dPSI_dDelta) + d2DELTAbi_dDelta_dTau * delta * PSI);
482 derivs.d2alphar_ddelta2 += ni
483 * (DELTA_bi * (2.0 * dPSI_dDelta + delta * d2PSI_dDelta2) + 2.0 * dDELTAbi_dDelta * (PSI + delta * dPSI_dDelta)
484 + d2DELTAbi_dDelta2 * delta * PSI);
487 derivs.d3alphar_dtau3 +=
488 ni * delta * (d3DELTAbi_dTau3 * PSI + 3 * d2DELTAbi_dTau2 * dPSI_dTau + 3 * dDELTAbi_dTau * d2PSI_dTau2 + DELTA_bi * d3PSI_dTau3);
489 derivs.d3alphar_ddelta_dtau2 +=
491 * (d2DELTAbi_dTau2 * dPSI_dDelta + d3DELTAbi_dDelta_dTau2 * PSI + 2 * dDELTAbi_dTau * d2PSI_dDelta_dTau
492 + 2.0 * d2DELTAbi_dDelta_dTau * dPSI_dTau + DELTA_bi * d3PSI_dDelta_dTau2 + dDELTAbi_dDelta * d2PSI_dTau2)
493 + ni * (d2DELTAbi_dTau2 * PSI + 2.0 * dDELTAbi_dTau * dPSI_dTau + DELTA_bi * d2PSI_dTau2);
494 derivs.d3alphar_ddelta3 +=
496 * (DELTA_bi * (3 * d2PSI_dDelta2 + delta * d3PSI_dDelta3) + 3 * dDELTAbi_dDelta * (2 * dPSI_dDelta + delta * d2PSI_dDelta2)
497 + 3 * d2DELTAbi_dDelta2 * (PSI + delta * dPSI_dDelta) + d3DELTAbi_dDelta3 * PSI * delta);
499 DELTA_bi * (2 * d2PSI_dDelta_dTau + delta * d3PSI_dDelta2_dTau) + dDELTAbi_dTau * (2 * dPSI_dDelta + delta * d2PSI_dDelta2);
500 CoolPropDbl Line2 = 2 * dDELTAbi_dDelta * (dPSI_dTau + delta * d2PSI_dDelta_dTau) + 2 * d2DELTAbi_dDelta_dTau * (PSI + delta * dPSI_dDelta);
501 CoolPropDbl Line3 = d2DELTAbi_dDelta2 * delta * dPSI_dTau + d3DELTAbi_dDelta2_dTau * delta * PSI;
502 derivs.d3alphar_ddelta2_dtau += ni * (Line1 + Line2 + Line3);
505 derivs.d4alphar_dtau4 += ni * delta
506 * (DELTA_bi * d4PSI_dTau4 + 4 * dDELTAbi_dTau * d3PSI_dTau3 + 6 * d2DELTAbi_dTau2 * d2PSI_dTau2
507 + 4 * d3DELTAbi_dTau3 * dPSI_dTau + PSI * d4DELTAbi_dTau4);
508 derivs.d4alphar_ddelta4 +=
510 * (delta * DELTA_bi * d4PSI_dDelta4 + delta * PSI * d4DELTAbi_dDelta4 + 4 * delta * dDELTAbi_dDelta * d3PSI_dDelta3
511 + 4 * delta * dPSI_dDelta * d3DELTAbi_dDelta3 + 6 * delta * d2DELTAbi_dDelta2 * d2PSI_dDelta2 + 4 * DELTA_bi * d3PSI_dDelta3
512 + 4 * PSI * d3DELTAbi_dDelta3 + 12 * dDELTAbi_dDelta * d2PSI_dDelta2 + 12 * dPSI_dDelta * d2DELTAbi_dDelta2);
514 derivs.d4alphar_ddelta_dtau3 +=
516 * (delta * DELTA_bi * d4PSI_dDelta_dTau3 + delta * PSI * d4DELTAbi_dDelta_dTau3 + delta * dDELTAbi_dDelta * d3PSI_dTau3
517 + 3 * delta * dDELTAbi_dTau * d3PSI_dDelta_dTau2 + delta * dPSI_dDelta * d3DELTAbi_dTau3 + 3 * delta * dPSI_dTau * d3DELTAbi_dDelta_dTau2
518 + 3 * delta * d2DELTAbi_dDelta_dTau * d2PSI_dTau2 + 3 * delta * d2DELTAbi_dTau2 * d2PSI_dDelta_dTau + DELTA_bi * d3PSI_dTau3
519 + PSI * d3DELTAbi_dTau3 + 3 * dDELTAbi_dTau * d2PSI_dTau2 + 3 * dPSI_dTau * d2DELTAbi_dTau2);
520 derivs.d4alphar_ddelta3_dtau +=
522 * (delta * DELTA_bi * d4PSI_dDelta3_dTau + delta * PSI * d4DELTAbi_dDelta3_dTau + 3 * delta * dDELTAbi_dDelta * d3PSI_dDelta2_dTau
523 + delta * dDELTAbi_dTau * d3PSI_dDelta3 + 3 * delta * dPSI_dDelta * d3DELTAbi_dDelta2_dTau + delta * dPSI_dTau * d3DELTAbi_dDelta3
524 + 3 * delta * d2DELTAbi_dDelta2 * d2PSI_dDelta_dTau + 3 * delta * d2DELTAbi_dDelta_dTau * d2PSI_dDelta2
525 + 3 * DELTA_bi * d3PSI_dDelta2_dTau + 3 * PSI * d3DELTAbi_dDelta2_dTau + 6 * dDELTAbi_dDelta * d2PSI_dDelta_dTau
526 + 3 * dDELTAbi_dTau * d2PSI_dDelta2 + 6 * dPSI_dDelta * d2DELTAbi_dDelta_dTau + 3 * dPSI_dTau * d2DELTAbi_dDelta2);
527 derivs.d4alphar_ddelta2_dtau2 +=
529 * (delta * DELTA_bi * d4PSI_dDelta2_dTau2 + delta * PSI * d4DELTAbi_dDelta2_dTau2 + 2 * delta * dDELTAbi_dDelta * d3PSI_dDelta_dTau2
530 + 2 * delta * dDELTAbi_dTau * d3PSI_dDelta2_dTau + 2 * delta * dPSI_dDelta * d3DELTAbi_dDelta_dTau2
531 + 2 * delta * dPSI_dTau * d3DELTAbi_dDelta2_dTau + delta * d2DELTAbi_dDelta2 * d2PSI_dTau2
532 + 4 * delta * d2DELTAbi_dDelta_dTau * d2PSI_dDelta_dTau + delta * d2DELTAbi_dTau2 * d2PSI_dDelta2 + 2 * DELTA_bi * d3PSI_dDelta_dTau2
533 + 2 * PSI * d3DELTAbi_dDelta_dTau2 + 2 * dDELTAbi_dDelta * d2PSI_dTau2 + 4 * dDELTAbi_dTau * d2PSI_dDelta_dTau
534 + 2 * dPSI_dDelta * d2DELTAbi_dTau2 + 4 * dPSI_dTau * d2DELTAbi_dDelta_dTau);
543 derivs.alphar += m_abstractcubic->alphar(tau, delta, z, 0, 0);
545 derivs.dalphar_ddelta += m_abstractcubic->alphar(tau, delta, z, 0, 1);
546 derivs.dalphar_dtau += m_abstractcubic->alphar(tau, delta, z, 1, 0);
548 derivs.d2alphar_ddelta2 += m_abstractcubic->alphar(tau, delta, z, 0, 2);
549 derivs.d2alphar_ddelta_dtau += m_abstractcubic->alphar(tau, delta, z, 1, 1);
550 derivs.d2alphar_dtau2 += m_abstractcubic->alphar(tau, delta, z, 2, 0);
552 derivs.d3alphar_ddelta3 += m_abstractcubic->alphar(tau, delta, z, 0, 3);
553 derivs.d3alphar_ddelta2_dtau += m_abstractcubic->alphar(tau, delta, z, 1, 2);
554 derivs.d3alphar_ddelta_dtau2 += m_abstractcubic->alphar(tau, delta, z, 2, 1);
555 derivs.d3alphar_dtau3 += m_abstractcubic->alphar(tau, delta, z, 3, 0);
557 derivs.d4alphar_ddelta4 += m_abstractcubic->alphar(tau, delta, z, 0, 4);
558 derivs.d4alphar_ddelta3_dtau += m_abstractcubic->alphar(tau, delta, z, 1, 3);
559 derivs.d4alphar_ddelta2_dtau2 += m_abstractcubic->alphar(tau, delta, z, 2, 2);
560 derivs.d4alphar_ddelta_dtau3 += m_abstractcubic->alphar(tau, delta, z, 3, 1);
561 derivs.d4alphar_dtau4 += m_abstractcubic->alphar(tau, delta, z, 4, 0);
593 CoolPropDbl Ftau = 0, Fdelta = 0, taudFtaudtau = 0, tau2d2Ftaudtau2 = 0, tau3d3Ftaudtau3 = 0, tau4d4Ftaudtau4 = 0, deltadFdeltaddelta = 0,
594 delta2d2Fdeltaddelta2 = 0, delta3d3Fdeltaddelta3 = 0, delta4d4Fdeltaddelta4 = 0;
596 for (
int i = 0; i < static_cast<int>(n.size()); ++i) {
598 const CoolPropDbl n = this->n[i], t = this->t[i], d = this->d[i], eta = this->eta[i], beta = this->beta[i], gamma = this->gamma[i],
599 epsilon = this->epsilon[i], b = this->b[i];
601 Ftau = pow(tau, t) * exp(1.0 / (b + beta * pow(-gamma + tau, 2)));
602 Fdelta = pow(delta, d) * exp(eta * pow(delta - epsilon, 2));
603 taudFtaudtau = (2 * beta * pow(tau, t + 1) * (gamma - tau) + t * pow(tau, t) * pow(b + beta * pow(gamma - tau, 2), 2))
604 * exp(1.0 / (b + beta * pow(gamma - tau, 2))) / pow(b + beta * pow(gamma - tau, 2), 2);
605 tau2d2Ftaudtau2 = pow(tau, t)
606 * (4 * beta * t * tau * pow(b + beta * pow(gamma - tau, 2), 2) * (gamma - tau)
607 + 2 * beta * pow(tau, 2)
608 * (4 * beta * (b + beta * pow(gamma - tau, 2)) * pow(gamma - tau, 2) + 2 * beta * pow(gamma - tau, 2)
609 - pow(b + beta * pow(gamma - tau, 2), 2))
610 + t * pow(b + beta * pow(gamma - tau, 2), 4) * (t - 1))
611 * exp(1.0 / (b + beta * pow(gamma - tau, 2))) / pow(b + beta * pow(gamma - tau, 2), 4);
614 * (4 * pow(beta, 2) * pow(tau, 3) * (gamma - tau)
615 * (12 * beta * (b + beta * pow(gamma - tau, 2)) * pow(gamma - tau, 2) + 2 * beta * pow(gamma - tau, 2)
616 - 6 * pow(b + beta * pow(gamma - tau, 2), 3) + pow(b + beta * pow(gamma - tau, 2), 2) * (12 * beta * pow(gamma - tau, 2) - 3))
617 + 6 * beta * t * pow(tau, 2) * pow(b + beta * pow(gamma - tau, 2), 2)
618 * (4 * beta * (b + beta * pow(gamma - tau, 2)) * pow(gamma - tau, 2) + 2 * beta * pow(gamma - tau, 2)
619 - pow(b + beta * pow(gamma - tau, 2), 2))
620 + 6 * beta * t * tau * pow(b + beta * pow(gamma - tau, 2), 4) * (gamma - tau) * (t - 1)
621 + t * pow(b + beta * pow(gamma - tau, 2), 6) * (pow(t, 2) - 3 * t + 2))
622 * exp(1.0 / (b + beta * pow(gamma - tau, 2))) / pow(b + beta * pow(gamma - tau, 2), 6);
625 * (16 * pow(beta, 2) * t * pow(tau, 3) * pow(b + beta * pow(gamma - tau, 2), 2) * (gamma - tau)
626 * (12 * beta * (b + beta * pow(gamma - tau, 2)) * pow(gamma - tau, 2) + 2 * beta * pow(gamma - tau, 2)
627 - 6 * pow(b + beta * pow(gamma - tau, 2), 3) + pow(b + beta * pow(gamma - tau, 2), 2) * (12 * beta * pow(gamma - tau, 2) - 3))
628 + pow(beta, 2) * pow(tau, 4)
629 * (pow(beta, 2) * (192 * b + 192 * beta * pow(gamma - tau, 2)) * pow(gamma - tau, 4) + 16 * pow(beta, 2) * pow(gamma - tau, 4)
630 + 96 * beta * pow(b + beta * pow(gamma - tau, 2), 3) * pow(gamma - tau, 2) * (4 * beta * pow(gamma - tau, 2) - 3)
631 + 48 * beta * pow(b + beta * pow(gamma - tau, 2), 2) * pow(gamma - tau, 2) * (12 * beta * pow(gamma - tau, 2) - 1)
632 + 24 * pow(b + beta * pow(gamma - tau, 2), 5) + pow(b + beta * pow(gamma - tau, 2), 4) * (-288 * beta * pow(gamma - tau, 2) + 12))
633 + 12 * beta * t * pow(tau, 2) * pow(b + beta * pow(gamma - tau, 2), 4) * (t - 1)
634 * (4 * beta * (b + beta * pow(gamma - tau, 2)) * pow(gamma - tau, 2) + 2 * beta * pow(gamma - tau, 2)
635 - pow(b + beta * pow(gamma - tau, 2), 2))
636 + 8 * beta * t * tau * pow(b + beta * pow(gamma - tau, 2), 6) * (gamma - tau) * (pow(t, 2) - 3 * t + 2)
637 + t * pow(b + beta * pow(gamma - tau, 2), 8) * (pow(t, 3) - 6 * pow(t, 2) + 11 * t - 6))
638 * exp(1.0 / (b + beta * pow(gamma - tau, 2))) / pow(b + beta * pow(gamma - tau, 2), 8);
639 deltadFdeltaddelta = (d * pow(delta, d) + 2 * pow(delta, d + 1) * eta * (delta - epsilon)) * exp(eta * pow(delta - epsilon, 2));
640 delta2d2Fdeltaddelta2 =
641 pow(delta, d) * (4 * d * delta * eta * (delta - epsilon) + d * (d - 1) + 2 * pow(delta, 2) * eta * (2 * eta * pow(delta - epsilon, 2) + 1))
642 * exp(eta * pow(delta - epsilon, 2));
643 delta3d3Fdeltaddelta3 =
645 * (6 * d * pow(delta, 2) * eta * (2 * eta * pow(delta - epsilon, 2) + 1) + 6 * d * delta * eta * (d - 1) * (delta - epsilon)
646 + d * (pow(d, 2) - 3 * d + 2) + 4 * pow(delta, 3) * pow(eta, 2) * (delta - epsilon) * (2 * eta * pow(delta - epsilon, 2) + 3))
647 * exp(eta * pow(delta - epsilon, 2));
648 delta4d4Fdeltaddelta4 =
650 * (16 * d * pow(delta, 3) * pow(eta, 2) * (delta - epsilon) * (2 * eta * pow(delta - epsilon, 2) + 3)
651 + 12 * d * pow(delta, 2) * eta * (d - 1) * (2 * eta * pow(delta - epsilon, 2) + 1)
652 + 8 * d * delta * eta * (delta - epsilon) * (pow(d, 2) - 3 * d + 2) + d * (pow(d, 3) - 6 * pow(d, 2) + 11 * d - 6)
653 + pow(delta, 4) * pow(eta, 2) * (16 * pow(eta, 2) * pow(delta - epsilon, 4) + 48 * eta * pow(delta - epsilon, 2) + 12))
654 * exp(eta * pow(delta - epsilon, 2));
656 derivs.alphar += n * Ftau * Fdelta;
658 derivs.dalphar_ddelta += n * Ftau * deltadFdeltaddelta / delta;
659 derivs.dalphar_dtau += n * Fdelta * taudFtaudtau / tau;
661 derivs.d2alphar_ddelta2 += n * Ftau * delta2d2Fdeltaddelta2 /
POW2(delta);
662 derivs.d2alphar_ddelta_dtau += n * taudFtaudtau * deltadFdeltaddelta / tau / delta;
663 derivs.d2alphar_dtau2 += n * Fdelta * tau2d2Ftaudtau2 /
POW2(tau);
665 derivs.d3alphar_ddelta3 += n * Ftau * delta3d3Fdeltaddelta3 /
POW3(delta);
666 derivs.d3alphar_ddelta2_dtau += n * taudFtaudtau * delta2d2Fdeltaddelta2 /
POW2(delta) / tau;
667 derivs.d3alphar_ddelta_dtau2 += n * tau2d2Ftaudtau2 * deltadFdeltaddelta /
POW2(tau) / delta;
668 derivs.d3alphar_dtau3 += n * Fdelta * tau3d3Ftaudtau3 /
POW3(tau);
670 derivs.d4alphar_ddelta4 += n * Ftau * delta4d4Fdeltaddelta4 /
POW4(delta);
671 derivs.d4alphar_ddelta3_dtau += n * taudFtaudtau * delta3d3Fdeltaddelta3 /
POW3(delta) / tau;
672 derivs.d4alphar_ddelta2_dtau2 += n * tau2d2Ftaudtau2 * delta2d2Fdeltaddelta2 /
POW2(delta) /
POW2(tau);
673 derivs.d4alphar_ddelta_dtau3 += n * tau3d3Ftaudtau3 * deltadFdeltaddelta /
POW3(tau) / delta;
674 derivs.d4alphar_dtau4 += n * Fdelta * tau4d4Ftaudtau4 /
POW4(tau);
680 : Tc(Tc), pc(pc), rhomolarc(rhomolarc), acentric(acentric), R(R) {
685 double _d[] = {1, 1, 1, 2, 3, 7, 1, 1, 2, 5, 1, 1, 4, 2};
686 std::vector<CoolPropDbl> d(_d, _d +
sizeof(_d) /
sizeof(
double));
687 double _t[] = {0.25, 1.25, 1.5, 1.375, 0.25, 0.875, 0, 2.375, 2, 2.125, 3.5, 6.5, 4.75, 12.5};
688 std::vector<CoolPropDbl> t(_t, _t +
sizeof(_t) /
sizeof(
double));
689 double _l[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3};
690 std::vector<CoolPropDbl> l(_l, _l +
sizeof(_l) /
sizeof(
double));
691 double _g[] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1};
692 std::vector<CoolPropDbl> g(_g, _g +
sizeof(_g) /
sizeof(
double));
693 double _a0[] = {8.5740489E-01, -3.2863233E+00, 1.6480939E+00, -5.4524817E-02, 6.1623592E-02, 2.7389266E-04, -6.0655087E-02,
694 -3.1811852E-02, -1.1550422E-01, -1.8610466E-02, -1.8348671E-01, 5.5071325E-03, -1.2268039E-02, -5.0433436E-03};
695 std::vector<CoolPropDbl> a0(_a0, _a0 +
sizeof(_a0) /
sizeof(
double));
696 double _a1[] = {5.6200117E-01, 3.2439544E+00, -4.9628768E+00, -2.2132851E-01, 9.3388356E-02, 2.4940171E-05, -1.7519204E-01,
697 8.9325660E-01, 2.9886613E+00, 1.0881387E-01, -6.7166746E-01, 1.4477326E-01, -2.8716809E-01, -1.1478402E-01};
698 std::vector<CoolPropDbl> a1(_a1, _a1 +
sizeof(_a1) /
sizeof(
double));
699 double _a2[] = {-8.1680511E+01, 4.6384732E+02, -2.7970850E+02, 2.9317364E+01, -2.2324825E+01, -5.0932691E-02, -7.2836590E+00,
700 -2.2063100E+02, -3.0435126E+02, 5.8514719E+00, 1.7995451E+02, -1.0178400E+02, 4.0848053E+01, 1.2411984E+01};
701 std::vector<CoolPropDbl> a2(_a2, _a2 +
sizeof(_a2) /
sizeof(
double));
718 phi0.all(tau, delta, derivs0);
719 phi1.all(tau, delta, derivs1);
720 phi2.all(tau, delta, derivs2);
723 derivs = derivs + derivs0 + derivs1 * acentric + derivs2 * theta;
727 el.AddMember(
"type",
"ResidualHelmholtzSAFTAssociating", doc.GetAllocator());
728 el.AddMember(
"a",
a, doc.GetAllocator());
729 el.AddMember(
"m",
m, doc.GetAllocator());
730 el.AddMember(
"epsilonbar",
epsilonbar, doc.GetAllocator());
731 el.AddMember(
"vbarn",
vbarn, doc.GetAllocator());
732 el.AddMember(
"kappabar",
kappabar, doc.GetAllocator());
766 return 2 / (sqrt(1 + 4 *
Deltabar * delta) + 1);
770 return -delta *
X *
X / (2 *
Deltabar * delta *
X + 1);
794 return d_dXdtau_dX * dX_dDeltabar * beta + d_dXdtau_dDeltabar * beta + d_dXdtau_dbeta * dbeta_dtau;
802 CoolPropDbl d_dXddelta_dDeltabar =
X *
X * (2 * delta * delta *
X * alpha - 1) / pow(2 *
Deltabar * delta *
X + 1, 2);
806 return d_dXddelta_dX * dX_dDeltabar * beta + d_dXddelta_dDeltabar * beta + d_dXddelta_dalpha * dalpha_dtau;
816 CoolPropDbl d_dXddelta_dDeltabar =
X *
X * (2 * delta * delta *
X * alpha - 1) / pow(2 *
Deltabar * delta *
X + 1, 2);
822 CoolPropDbl val = (dX_ddelta_constall + d_dXddelta_dX *
dX_ddelta + d_dXddelta_dX * dX_dDeltabar * alpha + d_dXddelta_dDeltabar * alpha
823 + d_dXddelta_dalpha * dalpha_ddelta);
834 * (-6 * Delta * pow(Delta_t, 2) * pow(
X, 2) * pow(delta, 2) * (Delta *
X * delta + 1)
835 + 3 * pow(Delta_t, 2) *
X * delta * (2 * Delta *
X * delta + 1) - Delta_tt * pow(2 * Delta *
X * delta + 1, 3)
836 +
X * delta * (Delta * Delta_tt + 3 * pow(Delta_t, 2)) * pow(2 * Delta *
X * delta + 1, 2))
837 / pow(2 * Delta *
X * delta + 1, 4);
839 * (-6 * pow(Delta_t, 2) *
X * delta * (Delta *
X * delta + 1)
840 - 3 * pow(Delta_t, 2) *
X * delta * (2 * Delta *
X * delta + 1) + Delta_tt * pow(2 * Delta *
X * delta + 1, 2))
841 / pow(2 * Delta *
X * delta + 1, 4);
842 CoolPropDbl dXtt_dDelta_t = 4 * Delta_t * pow(
X, 3) * pow(delta, 2) * (3 * Delta *
X * delta + 2) / pow(2 * Delta *
X * delta + 1, 3);
843 CoolPropDbl dXtt_dDelta_tt = -pow(
X, 2) * delta / (2 * Delta *
X * delta + 1);
844 return dXtt_dX * dX_dDelta * Delta_t + dXtt_dDelta * Delta_t + dXtt_dDelta_t * Delta_tt + dXtt_dDelta_tt * Delta_ttt;
858 * (-12 * Delta * pow(Delta_t, 2) * pow(
X, 2) * pow(delta, 2) * (Delta *
X * delta + 1)
859 + 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)
860 + 2 *
X * delta * (Delta * Delta_tt + 2 * pow(Delta_t, 2)) * pow(2 * Delta *
X * delta + 1, 2))
861 / pow(2 * Delta *
X * delta + 1, 4);
863 * (-6 * Delta * pow(Delta_t, 2) * pow(
X, 2) * pow(delta, 2) * (Delta *
X * delta + 1)
864 + 3 * pow(Delta_t, 2) *
X * delta * (2 * Delta *
X * delta + 1) - Delta_tt * pow(2 * Delta *
X * delta + 1, 3)
865 +
X * delta * (Delta * Delta_tt + 3 * pow(Delta_t, 2)) * pow(2 * Delta *
X * delta + 1, 2))
866 / pow(2 * Delta *
X * delta + 1, 4);
868 * (-6 * pow(Delta_t, 2) *
X * delta * (Delta *
X * delta + 1)
869 - 3 * pow(Delta_t, 2) *
X * delta * (2 * Delta *
X * delta + 1) + Delta_tt * pow(2 * Delta *
X * delta + 1, 2))
870 / pow(2 * Delta *
X * delta + 1, 4);
871 CoolPropDbl dXtt_dDelta_t = 4 * Delta_t * pow(
X, 3) * pow(delta, 2) * (3 * Delta *
X * delta + 2) / pow(2 * Delta *
X * delta + 1, 3);
872 CoolPropDbl dXtt_dDelta_tt = -pow(
X, 2) * delta / (2 * Delta *
X * delta + 1);
873 return dXtt_ddelta + dXtt_dX *
dX_ddelta + dXtt_dX * dX_dDelta * Delta_d + dXtt_dDelta * Delta_d + dXtt_dDelta_t * Delta_dt
874 + dXtt_dDelta_tt * Delta_dtt;
888 * (-6 * Delta * pow(
X, 2) * delta * pow(Delta + Delta_d * delta, 2) * (Delta *
X * delta + 1)
889 - Delta_dd * delta * pow(2 * Delta *
X * delta + 1, 3)
890 + 2 *
X * (2 * Delta *
X * delta + 1)
891 * (-Delta * Delta_d * delta * (2 * Delta_d *
X * pow(delta, 2) - 1) - Delta * delta * (2 * pow(Delta, 2) *
X - Delta_d)
892 + Delta * (Delta + Delta_d * delta) * (Delta *
X * delta + 1) + Delta_d * delta * (Delta + Delta_d * delta) * (Delta *
X * delta + 1))
893 + pow(2 * Delta *
X * delta + 1, 2)
894 * (3 * pow(Delta, 2) *
X + Delta * Delta_dd *
X * pow(delta, 2) + Delta *
X * (Delta + Delta_d * delta)
895 + pow(Delta_d, 2) *
X * pow(delta, 2) + Delta_d *
X * delta * (Delta + Delta_d * delta)
896 + Delta_d * (2 * Delta_d *
X * pow(delta, 2) - 1) - Delta_d))
897 / pow(2 * Delta *
X * delta + 1, 4);
899 * (-8 * pow(Delta, 2) * Delta_d * pow(
X, 2) * pow(delta, 3) + 8 * pow(Delta, 2) * Delta_dd * pow(
X, 2) * pow(delta, 4)
900 + 10 * pow(Delta, 2) *
X * delta - 24 * Delta * pow(Delta_d, 2) * pow(
X, 2) * pow(delta, 4)
901 + 8 * Delta * Delta_d *
X * pow(delta, 2) + 8 * Delta * Delta_dd *
X * pow(delta, 3) + 8 * Delta
902 - 18 * pow(Delta_d, 2) *
X * pow(delta, 3) + 12 * Delta_d * delta + 2 * Delta_dd * pow(delta, 2))
903 / (16 * pow(Delta, 4) * pow(
X, 4) * pow(delta, 4) + 32 * pow(Delta, 3) * pow(
X, 3) * pow(delta, 3)
904 + 24 * pow(Delta, 2) * pow(
X, 2) * pow(delta, 2) + 8 * Delta *
X * delta + 1);
907 * (2 *
X * delta * (Delta + Delta_d * delta) * (Delta *
X * delta + 1) + (2 * Delta *
X * delta + 1) * (2 * Delta_d *
X * pow(delta, 2) - 1))
908 / pow(2 * Delta *
X * delta + 1, 3);
909 CoolPropDbl dXdd_dDelta_dd = -pow(
X, 2) * delta / (2 * Delta *
X * delta + 1);
911 return dXdd_dX * dX_dDelta * Delta_t + dXdd_dDelta * Delta_t + dXdd_dDelta_d * Delta_dt + dXdd_dDelta_dd * Delta_ddt;
914 double Xdd(
double X,
double delta,
double Delta,
double Delta_d,
double Delta_dd) {
915 return Delta * pow(
X, 2) * (2 * Delta + 2 * Delta_d * delta) * (Delta * pow(
X, 2) * delta +
X) / pow(2 * Delta *
X * delta + 1, 3)
916 + 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)
917 + Delta_d * pow(
X, 2) * (2 * Delta_d *
X * pow(delta, 2) - 1) / pow(2 * Delta *
X * delta + 1, 2)
918 - Delta_dd * pow(
X, 2) * delta / (2 * Delta *
X * delta + 1)
919 + pow(
X, 2) * (2 * pow(Delta, 2) *
X - Delta_d) / pow(2 * Delta *
X * delta + 1, 2);
933 * (-6 * Delta * pow(
X, 2) * delta * pow(Delta + Delta_d * delta, 2) * (Delta *
X * delta + 1)
934 - Delta_dd * delta * pow(2 * Delta *
X * delta + 1, 3)
935 + 2 *
X * (2 * Delta *
X * delta + 1)
936 * (-Delta * Delta_d * delta * (2 * Delta_d *
X * pow(delta, 2) - 1) - Delta * delta * (2 * pow(Delta, 2) *
X - Delta_d)
937 + Delta * (Delta + Delta_d * delta) * (Delta *
X * delta + 1) + Delta_d * delta * (Delta + Delta_d * delta) * (Delta *
X * delta + 1))
938 + pow(2 * Delta *
X * delta + 1, 2)
939 * (3 * pow(Delta, 2) *
X + Delta * Delta_dd *
X * pow(delta, 2) + Delta *
X * (Delta + Delta_d * delta)
940 + pow(Delta_d, 2) *
X * pow(delta, 2) + Delta_d *
X * delta * (Delta + Delta_d * delta)
941 + Delta_d * (2 * Delta_d *
X * pow(delta, 2) - 1) - Delta_d))
942 / pow(2 * Delta *
X * delta + 1, 4);
944 * (-24 * pow(Delta, 4) * pow(
X, 3) * delta - 8 * pow(Delta, 3) * Delta_d * pow(
X, 3) * pow(delta, 2)
945 - 18 * pow(Delta, 3) * pow(
X, 2) + 8 * pow(Delta, 2) * Delta_d * pow(
X, 2) * delta
946 - 4 * pow(Delta, 2) * Delta_dd * pow(
X, 2) * pow(delta, 2) + 10 * Delta * pow(Delta_d, 2) * pow(
X, 2) * pow(delta, 2)
947 + 12 * Delta * Delta_d *
X - 4 * Delta * Delta_dd *
X * delta + 8 * pow(Delta_d, 2) *
X * delta - Delta_dd)
948 / (16 * pow(Delta, 4) * pow(
X, 4) * pow(delta, 4) + 32 * pow(Delta, 3) * pow(
X, 3) * pow(delta, 3)
949 + 24 * pow(Delta, 2) * pow(
X, 2) * pow(delta, 2) + 8 * Delta *
X * delta + 1);
951 * (-8 * pow(Delta, 2) * Delta_d * pow(
X, 2) * pow(delta, 3) + 8 * pow(Delta, 2) * Delta_dd * pow(
X, 2) * pow(delta, 4)
952 + 10 * pow(Delta, 2) *
X * delta - 24 * Delta * pow(Delta_d, 2) * pow(
X, 2) * pow(delta, 4)
953 + 8 * Delta * Delta_d *
X * pow(delta, 2) + 8 * Delta * Delta_dd *
X * pow(delta, 3) + 8 * Delta
954 - 18 * pow(Delta_d, 2) *
X * pow(delta, 3) + 12 * Delta_d * delta + 2 * Delta_dd * pow(delta, 2))
955 / (16 * pow(Delta, 4) * pow(
X, 4) * pow(delta, 4) + 32 * pow(Delta, 3) * pow(
X, 3) * pow(delta, 3)
956 + 24 * pow(Delta, 2) * pow(
X, 2) * pow(delta, 2) + 8 * Delta *
X * delta + 1);
959 * (2 *
X * delta * (Delta + Delta_d * delta) * (Delta *
X * delta + 1) + (2 * Delta *
X * delta + 1) * (2 * Delta_d *
X * pow(delta, 2) - 1))
960 / pow(2 * Delta *
X * delta + 1, 3);
961 CoolPropDbl dXdd_dDelta_dd = -pow(
X, 2) * delta / (2 * Delta *
X * delta + 1);
963 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;
966 return 0.5 * (2 -
eta) / pow(1 -
eta, (
int)3);
969 return 0.5 * (5 - 2 *
eta) / pow(1 -
eta, (
int)4);
972 return 3 * (3 -
eta) / pow(1 -
eta, (
int)5);
975 return 6 * (7 - 2 *
eta) / pow(1 -
eta, (
int)6);
978 return this->
vbarn * delta;
990 CoolPropDbl X_dt = this->d2X_ddeltadtau(tau, delta);
992 CoolPropDbl X_dtt = this->d3X_ddeltadtau2(tau, delta);
993 CoolPropDbl X_ddt = this->d3X_ddelta2dtau(tau, delta);
996 deriv.alphar += this->m * this->a * ((log(
X) -
X / 2.0 + 0.5));
997 deriv.dalphar_ddelta += this->m * this->a * (1 /
X - 0.5) * this->dX_ddelta(tau, delta);
998 deriv.dalphar_dtau += this->m * this->a * (1 /
X - 0.5) * this->dX_dtau(tau, delta);
999 deriv.d2alphar_dtau2 += this->m * this->a * ((1 /
X - 0.5) * X_tt - pow(X_t /
X, 2));
1000 deriv.d2alphar_ddelta2 += this->m * this->a * ((1 /
X - 0.5) * X_dd - pow(X_d /
X, 2));
1001 deriv.d2alphar_ddelta_dtau += this->m * this->a * ((-X_t /
X /
X) * X_d + X_dt * (1 /
X - 0.5));
1002 deriv.d3alphar_dtau3 += this->m * this->a
1003 * ((1 /
X - 1.0 / 2.0) * X_ttt + (-X_t / pow(
X, (
int)2)) * X_tt
1004 - 2 * (pow(
X, (
int)2) * (X_t * X_tt) - pow(X_t, (
int)2) * (
X * X_t)) / pow(
X, (
int)4));
1005 deriv.d3alphar_ddelta_dtau2 += this->m * this->a
1006 * ((1 /
X - 1.0 / 2.0) * X_dtt - X_d / pow(
X, (
int)2) * X_tt
1007 - 2 * (pow(
X, (
int)2) * (X_t * X_dt) - pow(X_t, (
int)2) * (
X * X_d)) / pow(
X, (
int)4));
1008 deriv.d3alphar_ddelta2_dtau += this->m * this->a
1009 * ((1 /
X - 1.0 / 2.0) * X_ddt - X_t / pow(
X, (
int)2) * X_dd
1010 - 2 * (pow(
X, (
int)2) * (X_d * X_dt) - pow(X_d, (
int)2) * (
X * X_t)) / pow(
X, (
int)4));
1011 deriv.d3alphar_ddelta3 += this->m * this->a
1012 * ((1 /
X - 1.0 / 2.0) * X_ddd - X_d / pow(
X, (
int)2) * X_dd
1013 - 2 * (pow(
X, (
int)2) * (X_d * X_dd) - pow(X_d, (
int)2) * (
X * X_d)) / pow(
X, (
int)4));
1017 el.AddMember(
"type",
"IdealGasCP0Poly", doc.GetAllocator());
1019 rapidjson::Value _c(rapidjson::kArrayType), _t(rapidjson::kArrayType);
1020 for (std::size_t i = 0; i < N; ++i) {
1021 _c.PushBack(
static_cast<double>(c[i]), doc.GetAllocator());
1022 _t.PushBack(
static_cast<double>(t[i]), doc.GetAllocator());
1024 el.AddMember(
"c", _c, doc.GetAllocator());
1025 el.AddMember(
"t", _t, doc.GetAllocator());
1026 el.AddMember(
"Tc",
static_cast<double>(Tc), doc.GetAllocator());
1027 el.AddMember(
"T0",
static_cast<double>(T0), doc.GetAllocator());
1034 derivs.alphar += log(delta) + a1 + a2 * tau;
1035 derivs.dalphar_ddelta += 1.0 / delta;
1036 derivs.dalphar_dtau += a2;
1037 derivs.d2alphar_ddelta2 += -1.0 / delta / delta;
1038 derivs.d3alphar_ddelta3 += 2 / delta / delta / delta;
1039 derivs.d4alphar_ddelta4 += -6 /
POW4(delta);
1045 derivs.alphar += a1 + a2 * tau;
1046 derivs.dalphar_dtau += a2;
1053 derivs.alphar += a1 * log(tau);
1054 derivs.dalphar_dtau += a1 / tau;
1055 derivs.d2alphar_dtau2 += -a1 / tau / tau;
1056 derivs.d3alphar_dtau3 += 2 * a1 / tau / tau / tau;
1057 derivs.d4alphar_dtau4 += -6 * a1 /
POW4(tau);
1065 for (std::size_t i = 0; i < N; ++i) {
1066 s += n[i] * pow(tau, t[i]);
1072 for (std::size_t i = 0; i < N; ++i) {
1073 s += n[i] * t[i] * pow(tau, t[i] - 1);
1075 derivs.dalphar_dtau += s;
1079 for (std::size_t i = 0; i < N; ++i) {
1080 s += n[i] * t[i] * (t[i] - 1) * pow(tau, t[i] - 2);
1082 derivs.d2alphar_dtau2 += s;
1086 for (std::size_t i = 0; i < N; ++i) {
1087 s += n[i] * t[i] * (t[i] - 1) * (t[i] - 2) * pow(tau, t[i] - 3);
1089 derivs.d3alphar_dtau3 += s;
1093 for (std::size_t i = 0; i < N; ++i) {
1094 s += n[i] * t[i] * (t[i] - 1) * (t[i] - 2) * (t[i] - 3) * pow(tau, t[i] - 4);
1096 derivs.d4alphar_dtau4 += s;
1101 std::vector<double> expthetatau(N);
1102 for (std::size_t i = 0; i < N; ++i) {
1103 expthetatau[i] = exp(theta[i] * tau);
1111 for (std::size_t i = 0; i < N; ++i) {
1112 s += n[i] * log(c[i] + d[i] * expthetatau[i]);
1118 for (std::size_t i = 0; i < N; ++i) {
1119 s += n[i] * theta[i] * d[i] * expthetatau[i] / (c[i] + d[i] * expthetatau[i]);
1121 derivs.dalphar_dtau += s;
1125 for (std::size_t i = 0; i < N; ++i) {
1126 s += n[i] *
POW2(theta[i]) * c[i] * d[i] * expthetatau[i] / pow(c[i] + d[i] * expthetatau[i], 2);
1128 derivs.d2alphar_dtau2 += s;
1132 for (std::size_t i = 0; i < N; ++i) {
1133 s += n[i] *
POW3(theta[i]) * c[i] * d[i] * (c[i] - d[i] * expthetatau[i]) * expthetatau[i] / pow(c[i] + d[i] * expthetatau[i], 3);
1135 derivs.d3alphar_dtau3 += s;
1139 for (std::size_t i = 0; i < N; ++i) {
1140 const CoolPropDbl para = c[i] + d[i] * expthetatau[i];
1141 const CoolPropDbl bracket = 6 *
POW3(d[i]) *
POW3(expthetatau[i]) - 12 * d[i] * d[i] * para *
POW2(expthetatau[i])
1142 + 7 * d[i] *
POW2(para) * expthetatau[i] -
POW3(para);
1143 s += -n[i] * d[i] * pow(theta[i], 4) * bracket * expthetatau[i] / pow(c[i] + d[i] * expthetatau[i], 4);
1145 derivs.d4alphar_dtau4 += s;
1152 derivs.alphar += cp_over_R - cp_over_R * tau / tau0 + cp_over_R * log(tau / tau0);
1153 derivs.dalphar_dtau += cp_over_R / tau - cp_over_R / tau0;
1154 derivs.d2alphar_dtau2 += -cp_over_R / (tau * tau);
1155 derivs.d3alphar_dtau3 += 2 * cp_over_R / (tau * tau * tau);
1156 derivs.d4alphar_dtau4 += -6 * cp_over_R /
POW4(tau);
1164 for (std::size_t i = 0; i < N; ++i) {
1166 sum += c[i] - c[i] * tau / tau0 + c[i] * log(tau / tau0);
1167 }
else if (std::abs(t[i] + 1) < 10 *
DBL_EPSILON) {
1168 sum += c[i] * tau / Tc * log(tau0 / tau) + c[i] / Tc * (tau - tau0);
1170 sum += -c[i] * pow(Tc, t[i]) * pow(tau, -t[i]) / (t[i] * (t[i] + 1)) - c[i] * pow(T0, t[i] + 1) * tau / (Tc * (t[i] + 1))
1171 + c[i] * pow(T0, t[i]) / t[i];
1174 derivs.alphar += sum;
1178 for (std::size_t i = 0; i < N; ++i) {
1180 sum += c[i] / tau - c[i] / tau0;
1181 }
else if (std::abs(t[i] + 1) < 10 *
DBL_EPSILON) {
1182 sum += c[i] / Tc * log(tau0 / tau);
1184 sum += c[i] * pow(Tc, t[i]) * pow(tau, -t[i] - 1) / (t[i] + 1) - c[i] * pow(Tc, t[i]) / (pow(tau0, t[i] + 1) * (t[i] + 1));
1187 derivs.dalphar_dtau += sum;
1191 for (std::size_t i = 0; i < N; ++i) {
1193 sum += -c[i] / (tau * tau);
1194 }
else if (std::abs(t[i] + 1) < 10 *
DBL_EPSILON) {
1195 sum += -c[i] / (tau * Tc);
1197 sum += -c[i] * pow(Tc / tau, t[i]) / (tau * tau);
1200 derivs.d2alphar_dtau2 += sum;
1204 for (std::size_t i = 0; i < N; ++i) {
1206 sum += 2 * c[i] / (tau * tau * tau);
1207 }
else if (std::abs(t[i] + 1) < 10 *
DBL_EPSILON) {
1208 sum += c[i] / (tau * tau * Tc);
1210 sum += c[i] * pow(Tc / tau, t[i]) * (t[i] + 2) / (tau * tau * tau);
1213 derivs.d3alphar_dtau3 += sum;
1217 for (std::size_t i = 0; i < N; ++i) {
1219 sum += -6 * c[i] /
POW4(tau);
1220 }
else if (std::abs(t[i] + 1) < 10 *
DBL_EPSILON) {
1221 sum += -3 * c[i] / (
POW3(tau) * Tc);
1223 sum += -c[i] * (t[i] + 2) * (t[i] + 3) * pow(Tc / tau, t[i]) / (tau * tau * tau * tau);
1226 derivs.d4alphar_dtau4 += sum;
1239 T_red = derivs.T_red;
1241 throw ValueError(
"T_red needs to be stored somewhere for GERG2004Sinh");
1245 double sum00 = 0, sum10 = 0, sum20 = 0, sum30 = 0, sum40 = 0;
1246 for (std::size_t i = 0; i < N; ++i) {
1248 sum00 += n[i] * log(std::abs(sinh(t * tau)));
1249 sum10 += n[i] * t / tanh(t * tau);
1250 sum20 += -n[i] *
POW2(t) /
POW2(sinh(t * tau));
1251 sum30 += -2 * n[i] *
POW3(t) * (1 / tanh(t * tau) - 1 /
POW3(tanh(t * tau)));
1252 sum40 += -2 * n[i] *
POW4(t) * (1 - 4 /
POW2(tanh(t * tau)) + 3 /
POW4(tanh(t * tau)));
1254 derivs.alphar += sum00;
1255 derivs.dalphar_dtau += sum10;
1256 derivs.d2alphar_dtau2 += sum20;
1257 derivs.d3alphar_dtau3 += sum30;
1258 derivs.d4alphar_dtau4 += sum40;
1270 T_red = derivs.T_red;
1272 throw ValueError(
"T_red needs to be stored somewhere for GERG2004Cosh");
1276 double sum00 = 0, sum10 = 0, sum20 = 0, sum30 = 0, sum40 = 0;
1277 for (std::size_t i = 0; i < N; ++i) {
1279 sum00 += -n[i] * log(std::abs(cosh(t * tau)));
1280 sum10 += -n[i] * t * tanh(t * tau);
1281 sum20 += -n[i] *
POW2(t) /
POW2(cosh(t * tau));
1282 sum30 += -2 * n[i] *
POW3(t) * (
POW3(tanh(t * tau)) - tanh(t * tau));
1283 sum40 += 2 * n[i] *
POW4(t) * (3 *
POW4(tanh(t * tau)) - 4 *
POW2(tanh(t * tau)) + 1);
1285 derivs.alphar += sum00;
1286 derivs.dalphar_dtau += sum10;
1287 derivs.d2alphar_dtau2 += sum20;
1288 derivs.d3alphar_dtau3 += sum30;
1289 derivs.d4alphar_dtau4 += sum40;
1343 # include <catch2/catch_all.hpp>
1346 class HelmholtzConsistencyFixture
1351 shared_ptr<CoolProp::BaseHelmholtzTerm> PlanckEinstein, Lead, LogTau, IGPower, CP0Constant, CP0PolyT, SAFT, NonAnalytic, Soave, PR, XiangDeiters,
1352 GaoB, GERG2004Cosh, GERG2004Sinh;
1353 shared_ptr<CoolProp::ResidualHelmholtzGeneralizedExponential> Gaussian, Lemmon2005, Exponential, GERG2008, Power;
1355 HelmholtzConsistencyFixture() {
1356 shared_ptr<AbstractCubic> _SRK(
new SRK(300, 4e6, 0.3, 8.314461));
1358 _SRK->set_rhor(4000);
1361 shared_ptr<AbstractCubic> _PR(
new PengRobinson(300, 4e6, 0.3, 8.314461));
1363 _PR->set_rhor(4000);
1367 CoolPropDbl beta[] = {0.3696, 0.2962}, epsilon[] = {0.4478, 0.44689}, eta[] = {-2.8452, -2.8342}, gamma[] = {1.108, 1.313},
1368 n[] = {-1.6909858, 0.93739074}, t[] = {4.3315, 4.015}, d[] = {1, 1}, b[] = {1.244, 0.6826};
1370 std::vector<CoolPropDbl>(n, n +
sizeof(n) /
sizeof(n[0])), std::vector<CoolPropDbl>(t, t +
sizeof(t) /
sizeof(t[0])),
1371 std::vector<CoolPropDbl>(d, d +
sizeof(d) /
sizeof(d[0])), std::vector<CoolPropDbl>(eta, eta +
sizeof(eta) /
sizeof(eta[0])),
1372 std::vector<CoolPropDbl>(beta, beta +
sizeof(beta) /
sizeof(beta[0])),
1373 std::vector<CoolPropDbl>(gamma, gamma +
sizeof(gamma) /
sizeof(gamma[0])),
1374 std::vector<CoolPropDbl>(epsilon, epsilon +
sizeof(epsilon) /
sizeof(epsilon[0])),
1375 std::vector<CoolPropDbl>(b, b +
sizeof(b) /
sizeof(b[0]))));
1383 std::vector<CoolPropDbl> n(4, 0), t(4, 1);
1392 std::vector<CoolPropDbl> n(4, 0), t(4, 1), c(4, 1), d(4, -1);
1402 std::vector<CoolPropDbl> c(3, 1), t(3, 0);
1413 std::vector<CoolPropDbl> n(2, 0.0);
1416 std::vector<CoolPropDbl> theta(2, 0.0);
1417 theta[0] = 5.251822620;
1418 theta[1] = 13.788988208;
1419 CoolPropDbl rhomolar_crit = 11183.900000, T_crit = 126.192000000;
1425 std::vector<CoolPropDbl> n(1, 0.0);
1426 n[0] = -0.146600000;
1427 std::vector<CoolPropDbl> theta(1, 0.0);
1428 theta[0] = -5.393067706;
1429 CoolPropDbl rhomolar_crit = 11183.900000, T_crit = 126.192000000;
1435 CoolPropDbl beta[] = {1.24, 0.821, 15.45, 2.21, 437, 0.743}, d[] = {1, 1, 2, 2, 3, 3},
1436 epsilon[] = {0.6734, 0.9239, 0.8636, 1.0507, 0.8482, 0.7522}, eta[] = {0.9667, 1.5154, 1.0591, 1.6642, 12.4856, 0.9662},
1437 gamma[] = {1.2827, 0.4317, 1.1217, 1.1871, 1.1243, 0.4203},
1438 n[] = {1.2198, -0.4883, -0.0033293, -0.0035387, -0.51172, -0.16882}, t[] = {1, 2.124, 0.4, 3.5, 0.5, 2.7};
1440 Gaussian->add_Gaussian(
1441 std::vector<CoolPropDbl>(n, n +
sizeof(n) /
sizeof(n[0])), std::vector<CoolPropDbl>(d, d +
sizeof(d) /
sizeof(d[0])),
1442 std::vector<CoolPropDbl>(t, t +
sizeof(t) /
sizeof(t[0])), std::vector<CoolPropDbl>(eta, eta +
sizeof(eta) /
sizeof(eta[0])),
1443 std::vector<CoolPropDbl>(epsilon, epsilon +
sizeof(epsilon) /
sizeof(epsilon[0])),
1444 std::vector<CoolPropDbl>(beta, beta +
sizeof(beta) /
sizeof(beta[0])),
1445 std::vector<CoolPropDbl>(gamma, gamma +
sizeof(gamma) /
sizeof(gamma[0])));
1448 CoolPropDbl d[] = {1, 1, 1, 2, 4, 1, 1, 2, 2, 3, 4, 5, 1, 5, 1, 2, 3, 5}, l[] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 2, 3, 3},
1449 m[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.7, 7, 6},
1450 n[] = {5.28076, -8.67658, 0.7501127, 0.7590023, 0.01451899, 4.777189, -3.330988, 3.775673, -2.290919,
1451 0.8888268, -0.6234864, -0.04127263, -0.08455389, -0.1308752, 0.008344962, -1.532005, -0.05883649, 0.02296658},
1452 t[] = {0.669, 1.05, 2.75, 0.956, 1, 2, 2.75, 2.38, 3.37, 3.47, 2.63, 3.45, 0.72, 4.23, 0.2, 4.5, 29, 24};
1454 Lemmon2005->add_Lemmon2005(
1455 std::vector<CoolPropDbl>(n, n +
sizeof(n) /
sizeof(n[0])), std::vector<CoolPropDbl>(d, d +
sizeof(d) /
sizeof(d[0])),
1456 std::vector<CoolPropDbl>(t, t +
sizeof(t) /
sizeof(t[0])), std::vector<CoolPropDbl>(l, l +
sizeof(l) /
sizeof(l[0])),
1457 std::vector<CoolPropDbl>(m, m +
sizeof(m) /
sizeof(m[0])));
1460 CoolPropDbl d[] = {1, 1, 1, 3, 7, 1, 2, 5, 1, 1, 4, 2}, l[] = {0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3},
1461 n[] = {1.0038, -2.7662, 0.42921, 0.081363, 0.00024174, 0.48246, 0.75542, -0.00743, -0.4146, -0.016558, -0.10644, -0.021704},
1462 t[] = {0.25, 1.25, 1.5, 0.25, 0.875, 2.375, 2, 2.125, 3.5, 6.5, 4.75, 12.5};
1464 Power->add_Power(std::vector<CoolPropDbl>(n, n +
sizeof(n) /
sizeof(n[0])), std::vector<CoolPropDbl>(d, d +
sizeof(d) /
sizeof(d[0])),
1465 std::vector<CoolPropDbl>(t, t +
sizeof(t) /
sizeof(t[0])), std::vector<CoolPropDbl>(l, l +
sizeof(l) /
sizeof(l[0])));
1469 CoolPropDbl a = 1, epsilonbar = 12.2735737, kappabar = 1.09117041e-05, m = 1.01871348, vbarn = 0.0444215309;
1473 CoolPropDbl n[] = {-0.666422765408, 0.726086323499, 0.0550686686128}, A[] = {0.7, 0.7, 0.7}, B[] = {0.3, 0.3, 1}, C[] = {10, 10, 12.5},
1474 D[] = {275, 275, 275}, a[] = {3.5, 3.5, 3}, b[] = {0.875, 0.925, 0.875}, beta[] = {0.3, 0.3, 0.3};
1476 std::vector<CoolPropDbl>(n, n +
sizeof(n) /
sizeof(n[0])), std::vector<CoolPropDbl>(a, a +
sizeof(a) /
sizeof(a[0])),
1477 std::vector<CoolPropDbl>(b, b +
sizeof(b) /
sizeof(b[0])), std::vector<CoolPropDbl>(beta, beta +
sizeof(beta) /
sizeof(beta[0])),
1478 std::vector<CoolPropDbl>(A, A +
sizeof(A) /
sizeof(A[0])), std::vector<CoolPropDbl>(B, B +
sizeof(B) /
sizeof(B[0])),
1479 std::vector<CoolPropDbl>(C, C +
sizeof(C) /
sizeof(C[0])), std::vector<CoolPropDbl>(D, D +
sizeof(D) /
sizeof(D[0]))));
1482 CoolPropDbl d[] = {2, 2, 2, 0, 0, 0}, g[] = {1.65533788, 1.65533788, 1.65533788, 1.65533788, 1.65533788, 1.65533788},
1483 l[] = {2, 2, 2, 2, 2, 2},
1484 n[] = {-3.821884669859, 8.30345065618981, -4.4832307260286, -1.02590136933231, 2.20786016506394, -1.07889905203761},
1485 t[] = {3, 4, 5, 3, 4, 5};
1487 Exponential->add_Exponential(
1488 std::vector<CoolPropDbl>(n, n +
sizeof(n) /
sizeof(n[0])), std::vector<CoolPropDbl>(d, d +
sizeof(d) /
sizeof(n[0])),
1489 std::vector<CoolPropDbl>(t, t +
sizeof(t) /
sizeof(d[0])), std::vector<CoolPropDbl>(g, g +
sizeof(g) /
sizeof(t[0])),
1490 std::vector<CoolPropDbl>(l, l +
sizeof(l) /
sizeof(l[0])));
1493 CoolPropDbl d[] = {1, 4, 1, 2, 2, 2, 2, 2, 3}, t[] = {0.0, 1.85, 7.85, 5.4, 0.0, 0.75, 2.8, 4.45, 4.25},
1494 n[] = {-0.0098038985517335, 0.00042487270143005, -0.034800214576142, -0.13333813013896, -0.011993694974627,
1495 0.069243379775168, -0.31022508148249, 0.24495491753226, 0.22369816716981},
1496 eta[] = {0.0, 0.0, 1.0, 1.0, 0.25, 0.0, 0.0, 0.0, 0.0}, epsilon[] = {0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5},
1497 beta[] = {0.0, 0.0, 1.0, 1.0, 2.5, 3.0, 3.0, 3.0, 3.0}, gamma[] = {0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5};
1499 GERG2008->add_GERG2008Gaussian(
1500 std::vector<CoolPropDbl>(n, n +
sizeof(n) /
sizeof(n[0])), std::vector<CoolPropDbl>(d, d +
sizeof(d) /
sizeof(n[0])),
1501 std::vector<CoolPropDbl>(t, t +
sizeof(t) /
sizeof(d[0])), std::vector<CoolPropDbl>(eta, eta +
sizeof(eta) /
sizeof(eta[0])),
1502 std::vector<CoolPropDbl>(epsilon, epsilon +
sizeof(epsilon) /
sizeof(epsilon[0])),
1503 std::vector<CoolPropDbl>(beta, beta +
sizeof(beta) /
sizeof(beta[0])),
1504 std::vector<CoolPropDbl>(gamma, gamma +
sizeof(gamma) /
sizeof(gamma[0])));
1508 if (!d.compare(
"dTau")) {
1509 return dTau(term, tau, delta, ddelta);
1510 }
else if (!d.compare(
"dTau2")) {
1511 return dTau2(term, tau, delta, ddelta);
1512 }
else if (!d.compare(
"dTau3")) {
1513 return dTau3(term, tau, delta, ddelta);
1514 }
else if (!d.compare(
"dTau4")) {
1515 return dTau4(term, tau, delta, ddelta);
1516 }
else if (!d.compare(
"dDelta")) {
1517 return dDelta(term, tau, delta, ddelta);
1518 }
else if (!d.compare(
"dDelta2")) {
1519 return dDelta2(term, tau, delta, ddelta);
1520 }
else if (!d.compare(
"dDelta3")) {
1521 return dDelta3(term, tau, delta, ddelta);
1522 }
else if (!d.compare(
"dDelta4")) {
1523 return dDelta4(term, tau, delta, ddelta);
1524 }
else if (!d.compare(
"dDelta_dTau")) {
1525 return dDelta_dTau(term, tau, delta, ddelta);
1526 }
else if (!d.compare(
"dDelta_dTau2")) {
1527 return dDelta_dTau2(term, tau, delta, ddelta);
1528 }
else if (!d.compare(
"dDelta2_dTau")) {
1529 return dDelta2_dTau(term, tau, delta, ddelta);
1530 }
else if (!d.compare(
"dDelta3_dTau")) {
1531 return dDelta3_dTau(term, tau, delta, ddelta);
1532 }
else if (!d.compare(
"dDelta2_dTau2")) {
1533 return dDelta2_dTau2(term, tau, delta, ddelta);
1534 }
else if (!d.compare(
"dDelta_dTau3")) {
1535 return dDelta_dTau3(term, tau, delta, ddelta);
1540 shared_ptr<CoolProp::BaseHelmholtzTerm> get(std::string t) {
1541 if (!t.compare(
"Lead")) {
1543 }
else if (!t.compare(
"LogTau")) {
1545 }
else if (!t.compare(
"IGPower")) {
1547 }
else if (!t.compare(
"PlanckEinstein")) {
1548 return PlanckEinstein;
1549 }
else if (!t.compare(
"CP0Constant")) {
1551 }
else if (!t.compare(
"CP0PolyT")) {
1553 }
else if (!t.compare(
"GERG2004Cosh")) {
1554 return GERG2004Cosh;
1555 }
else if (!t.compare(
"GERG2004Sinh")) {
1556 return GERG2004Sinh;
1557 }
else if (!t.compare(
"SRK")) {
1559 }
else if (!t.compare(
"PengRobinson")) {
1561 }
else if (!t.compare(
"XiangDeiters")) {
1562 return XiangDeiters;
1563 }
else if (!t.compare(
"GaoB")) {
1567 else if (!t.compare(
"Gaussian")) {
1569 }
else if (!t.compare(
"Lemmon2005")) {
1571 }
else if (!t.compare(
"Power")) {
1573 }
else if (!t.compare(
"SAFT")) {
1575 }
else if (!t.compare(
"NonAnalytic")) {
1577 }
else if (!t.compare(
"Exponential")) {
1579 }
else if (!t.compare(
"GERG2008")) {
1586 CoolPropDbl term_plus = term->base(tau + dtau, delta);
1587 CoolPropDbl term_minus = term->base(tau - dtau, delta);
1588 numerical = (term_plus - term_minus) / (2 * dtau);
1589 analytic = term->dTau(tau, delta);
1592 CoolPropDbl term_plus = term->dTau(tau + dtau, delta);
1593 CoolPropDbl term_minus = term->dTau(tau - dtau, delta);
1594 numerical = (term_plus - term_minus) / (2 * dtau);
1595 analytic = term->dTau2(tau, delta);
1598 CoolPropDbl term_plus = term->dTau2(tau + dtau, delta);
1599 CoolPropDbl term_minus = term->dTau2(tau - dtau, delta);
1600 numerical = (term_plus - term_minus) / (2 * dtau);
1601 analytic = term->dTau3(tau, delta);
1604 CoolPropDbl term_plus = term->dTau3(tau + dtau, delta);
1605 CoolPropDbl term_minus = term->dTau3(tau - dtau, delta);
1606 numerical = (term_plus - term_minus) / (2 * dtau);
1607 analytic = term->dTau4(tau, delta);
1610 CoolPropDbl term_plus = term->base(tau, delta + ddelta);
1611 CoolPropDbl term_minus = term->base(tau, delta - ddelta);
1612 numerical = (term_plus - term_minus) / (2 * ddelta);
1613 analytic = term->dDelta(tau, delta);
1616 CoolPropDbl term_plus = term->dDelta(tau, delta + ddelta);
1617 CoolPropDbl term_minus = term->dDelta(tau, delta - ddelta);
1618 numerical = (term_plus - term_minus) / (2 * ddelta);
1619 analytic = term->dDelta2(tau, delta);
1622 CoolPropDbl term_plus = term->dDelta2(tau, delta + ddelta);
1623 CoolPropDbl term_minus = term->dDelta2(tau, delta - ddelta);
1624 numerical = (term_plus - term_minus) / (2 * ddelta);
1625 analytic = term->dDelta3(tau, delta);
1628 CoolPropDbl term_plus = term->dDelta3(tau, delta + ddelta);
1629 CoolPropDbl term_minus = term->dDelta3(tau, delta - ddelta);
1630 numerical = (term_plus - term_minus) / (2 * ddelta);
1631 analytic = term->dDelta4(tau, delta);
1634 CoolPropDbl term_plus = term->dTau(tau, delta + ddelta);
1635 CoolPropDbl term_minus = term->dTau(tau, delta - ddelta);
1636 numerical = (term_plus - term_minus) / (2 * ddelta);
1637 analytic = term->dDelta_dTau(tau, delta);
1640 CoolPropDbl term_plus = term->dTau2(tau, delta + ddelta);
1641 CoolPropDbl term_minus = term->dTau2(tau, delta - ddelta);
1642 numerical = (term_plus - term_minus) / (2 * ddelta);
1643 analytic = term->dDelta_dTau2(tau, delta);
1646 CoolPropDbl term_plus = term->dDelta_dTau(tau, delta + ddelta);
1647 CoolPropDbl term_minus = term->dDelta_dTau(tau, delta - ddelta);
1648 numerical = (term_plus - term_minus) / (2 * ddelta);
1649 analytic = term->dDelta2_dTau(tau, delta);
1652 CoolPropDbl term_plus = term->dDelta2_dTau(tau, delta + ddelta);
1653 CoolPropDbl term_minus = term->dDelta2_dTau(tau, delta - ddelta);
1654 numerical = (term_plus - term_minus) / (2 * ddelta);
1655 analytic = term->dDelta3_dTau(tau, delta);
1658 CoolPropDbl term_plus = term->dDelta_dTau2(tau, delta + ddelta);
1659 CoolPropDbl term_minus = term->dDelta_dTau2(tau, delta - ddelta);
1660 numerical = (term_plus - term_minus) / (2 * ddelta);
1661 analytic = term->dDelta2_dTau2(tau, delta);
1664 CoolPropDbl term_plus = term->dTau3(tau, delta + ddelta);
1665 CoolPropDbl term_minus = term->dTau3(tau, delta - ddelta);
1666 numerical = (term_plus - term_minus) / (2 * ddelta);
1667 analytic = term->dDelta_dTau3(tau, delta);
1669 double err(
double v1,
double v2) {
1670 if (std::abs(v2) > 1e-15) {
1671 return std::abs((v1 - v2) / v2);
1673 return std::abs(v1 - v2);
1678 std::string terms[] = {
"Lead",
"LogTau",
"IGPower",
"PlanckEinstein",
"CP0Constant",
"CP0PolyT",
"Gaussian",
1679 "Lemmon2005",
"Power",
"SAFT",
"NonAnalytic",
"Exponential",
"GERG2008",
"SRK",
1680 "PengRobinson",
"XiangDeiters",
"GaoB",
"GERG2004Cosh",
"GERG2004Sinh"};
1681 std::string derivs[] = {
"dTau",
"dTau2",
"dTau3",
"dDelta",
"dDelta2",
"dDelta3",
"dDelta_dTau",
1682 "dDelta_dTau2",
"dDelta2_dTau",
"dTau4",
"dDelta_dTau3",
"dDelta2_dTau2",
"dDelta3_dTau",
"dDelta4"};
1684 TEST_CASE_METHOD(HelmholtzConsistencyFixture,
"Helmholtz energy derivatives",
"[helmholtz]") {
1685 shared_ptr<CoolProp::BaseHelmholtzTerm> term;
1686 std::size_t n =
sizeof(terms) /
sizeof(terms[0]);
1687 for (std::size_t i = 0; i < n; ++i) {
1688 term = get(terms[i]);
1689 for (std::size_t j = 0; j <
sizeof(derivs) /
sizeof(derivs[0]); ++j) {
1690 if (terms[i] ==
"SAFT"
1691 && (derivs[j] ==
"dTau4" || derivs[j] ==
"dDelta_dTau3" || derivs[j] ==
"dDelta2_dTau2" || derivs[j] ==
"dDelta3_dTau"
1692 || derivs[j] ==
"dDelta4")) {
1695 call(derivs[j], term, 1.3, 0.9, 1e-6);
1700 CHECK(err(analytic, numerical) < 1e-8);