CoolProp 8.0.0
An open-source fluid property and humid air property database
ExcessHEFunction.h
Go to the documentation of this file.
1#ifndef EXCESSHE_FUNCTIONS_H
2#define EXCESSHE_FUNCTIONS_H
3
4#include <memory>
5using std::shared_ptr;
6#include <vector>
10
11namespace CoolProp {
12
13using STLMatrix = std::vector<std::vector<CoolPropDbl>>;
14
21{
22 public:
23 DepartureFunction() = default;
25 virtual ~DepartureFunction() = default;
28
30 return new DepartureFunction(phi);
31 }
32
33 virtual void update(double tau, double delta) {
34 derivs.reset(0.0);
35 phi.all(tau, delta, derivs);
36 };
37 double get(std::size_t itau, std::size_t idelta) {
38 return derivs.get(itau, idelta);
39 }
40
41 // Calculate the derivatives without caching internally
42 void calc_nocache(double tau, double delta, HelmholtzDerivatives& _derivs) {
43 phi.all(tau, delta, _derivs);
44 }
45
46 double alphar() {
47 return derivs.alphar;
48 };
49 double dalphar_dDelta() {
50 return derivs.dalphar_ddelta;
51 };
52 double dalphar_dTau() {
53 return derivs.dalphar_dtau;
54 };
55
57 return derivs.d2alphar_ddelta2;
58 };
60 return derivs.d2alphar_ddelta_dtau;
61 };
62 double d2alphar_dTau2() {
63 return derivs.d2alphar_dtau2;
64 };
65
66 double d3alphar_dTau3() {
67 return derivs.d3alphar_dtau3;
68 };
70 return derivs.d3alphar_ddelta_dtau2;
71 };
73 return derivs.d3alphar_ddelta2_dtau;
74 };
76 return derivs.d3alphar_ddelta3;
77 };
78
79 double d4alphar_dTau4() {
80 return derivs.d4alphar_dtau4;
81 };
83 return derivs.d4alphar_ddelta_dtau3;
84 };
86 return derivs.d4alphar_ddelta2_dtau2;
87 };
89 return derivs.d4alphar_ddelta3_dtau;
90 };
92 return derivs.d4alphar_ddelta4;
93 };
94};
95
105{
106 public:
108 GERG2008DepartureFunction(const std::vector<double>& n, const std::vector<double>& d, const std::vector<double>& t,
109 const std::vector<double>& eta, const std::vector<double>& epsilon, const std::vector<double>& beta,
110 const std::vector<double>& gamma, std::size_t Npower) {
112 {
113 std::vector<CoolPropDbl> _n(n.begin(), n.begin() + Npower);
114 std::vector<CoolPropDbl> _d(d.begin(), d.begin() + Npower);
115 std::vector<CoolPropDbl> _t(t.begin(), t.begin() + Npower);
116 std::vector<CoolPropDbl> _l(Npower, 0.0);
117 phi.add_Power(_n, _d, _t, _l);
118 }
119 if (n.size() == Npower) {
120 } else {
121 std::vector<CoolPropDbl> _n(n.begin() + Npower, n.end());
122 std::vector<CoolPropDbl> _d(d.begin() + Npower, d.end());
123 std::vector<CoolPropDbl> _t(t.begin() + Npower, t.end());
124 std::vector<CoolPropDbl> _eta(eta.begin() + Npower, eta.end());
125 std::vector<CoolPropDbl> _epsilon(epsilon.begin() + Npower, epsilon.end());
126 std::vector<CoolPropDbl> _beta(beta.begin() + Npower, beta.end());
127 std::vector<CoolPropDbl> _gamma(gamma.begin() + Npower, gamma.end());
128 phi.add_GERG2008Gaussian(_n, _d, _t, _eta, _epsilon, _beta, _gamma);
129 }
130 phi.finish();
131 };
133};
134
144{
145 public:
147 GaussianExponentialDepartureFunction(const std::vector<double>& n, const std::vector<double>& d, const std::vector<double>& t,
148 const std::vector<double>& l, const std::vector<double>& eta, const std::vector<double>& epsilon,
149 const std::vector<double>& beta, const std::vector<double>& gamma, std::size_t Npower) {
151 {
152 std::vector<CoolPropDbl> _n(n.begin(), n.begin() + Npower);
153 std::vector<CoolPropDbl> _d(d.begin(), d.begin() + Npower);
154 std::vector<CoolPropDbl> _t(t.begin(), t.begin() + Npower);
155 std::vector<CoolPropDbl> _l(l.begin(), l.begin() + Npower);
156 phi.add_Power(_n, _d, _t, _l);
157 }
158 if (n.size() == Npower) {
159 } else {
160 std::vector<CoolPropDbl> _n(n.begin() + Npower, n.end());
161 std::vector<CoolPropDbl> _d(d.begin() + Npower, d.end());
162 std::vector<CoolPropDbl> _t(t.begin() + Npower, t.end());
163 std::vector<CoolPropDbl> _eta(eta.begin() + Npower, eta.end());
164 std::vector<CoolPropDbl> _epsilon(epsilon.begin() + Npower, epsilon.end());
165 std::vector<CoolPropDbl> _beta(beta.begin() + Npower, beta.end());
166 std::vector<CoolPropDbl> _gamma(gamma.begin() + Npower, gamma.end());
167 phi.add_Gaussian(_n, _d, _t, _eta, _epsilon, _beta, _gamma);
168 }
169 phi.finish();
170 };
172};
173
183{
184 public:
186 ExponentialDepartureFunction(const std::vector<double>& n, const std::vector<double>& d, const std::vector<double>& t,
187 const std::vector<double>& l) {
188 std::vector<CoolPropDbl> _n(n.begin(), n.begin() + n.size());
189 std::vector<CoolPropDbl> _d(d.begin(), d.begin() + d.size());
190 std::vector<CoolPropDbl> _t(t.begin(), t.begin() + t.size());
191 std::vector<CoolPropDbl> _l(l.begin(), l.begin() + l.size());
192 phi.add_Power(_n, _d, _t, _l);
193 phi.finish();
194 };
196};
197
198using DepartureFunctionPointer = shared_ptr<DepartureFunction>;
199
201{
202 public:
203 std::size_t N;
204 std::vector<std::vector<DepartureFunctionPointer>> DepartureFunctionMatrix;
206
207 ExcessTerm() : N(0) {};
208
209 // operator= and copy-ctor: rely on the compiler-generated defaults, which
210 // shallow-copy N, F, and DepartureFunctionMatrix (vector of shared_ptr).
211 // The hand-written operator= that lived here did not actually copy any
212 // member of *this and self-assigned other's matrix — see ::copy() below
213 // for an explicit deep-copy variant.
214
216 ExcessTerm _term;
217 _term.resize(N);
218 for (std::size_t i = 0; i < N; ++i) {
219 for (std::size_t j = 0; j < N; ++j) {
220 if (i != j) {
221 _term.DepartureFunctionMatrix[i][j].reset(DepartureFunctionMatrix[i][j].get()->copy_ptr());
222 }
223 }
224 }
225 _term.F = F;
226 return _term;
227 }
228
230 void resize(std::size_t N) {
231 this->N = N;
232 F.resize(N, std::vector<CoolPropDbl>(N, 0));
234 for (std::size_t i = 0; i < N; ++i) {
235 DepartureFunctionMatrix[i].resize(N);
236 }
237 };
239 void update(double tau, double delta) {
240 for (std::size_t i = 0; i < N; i++) {
241 for (std::size_t j = i + 1; j < N; j++) {
242 DepartureFunctionMatrix[i][j]->update(tau, delta);
243 }
244 for (std::size_t j = 0; j < i; j++) {
245 DepartureFunctionMatrix[i][j]->update(tau, delta);
246 }
247 }
248 }
249
251 virtual HelmholtzDerivatives all(const CoolPropDbl tau, const CoolPropDbl delta, const std::vector<CoolPropDbl>& mole_fractions,
252 bool cache_values = false) {
254
255 // If there is no excess contribution, just stop and return
256 if (N == 0) {
257 return derivs;
258 }
259
260 if (cache_values == true) {
261
262 update(tau, delta);
263
264 derivs.alphar = alphar(mole_fractions);
265 derivs.dalphar_ddelta = dalphar_dDelta(mole_fractions);
266 derivs.dalphar_dtau = dalphar_dTau(mole_fractions);
267
268 derivs.d2alphar_ddelta2 = d2alphar_dDelta2(mole_fractions);
269 derivs.d2alphar_ddelta_dtau = d2alphar_dDelta_dTau(mole_fractions);
270 derivs.d2alphar_dtau2 = d2alphar_dTau2(mole_fractions);
271
272 derivs.d3alphar_ddelta3 = d3alphar_dDelta3(mole_fractions);
273 derivs.d3alphar_ddelta2_dtau = d3alphar_dDelta2_dTau(mole_fractions);
274 derivs.d3alphar_ddelta_dtau2 = d3alphar_dDelta_dTau2(mole_fractions);
275 derivs.d3alphar_dtau3 = d3alphar_dTau3(mole_fractions);
276
277 derivs.d4alphar_ddelta4 = d4alphar_dDelta4(mole_fractions);
278 derivs.d4alphar_ddelta3_dtau = d4alphar_dDelta3_dTau(mole_fractions);
279 derivs.d4alphar_ddelta2_dtau2 = d4alphar_dDelta2_dTau2(mole_fractions);
280 derivs.d4alphar_ddelta_dtau3 = d4alphar_dDelta_dTau3(mole_fractions);
281 derivs.d4alphar_dtau4 = d4alphar_dTau4(mole_fractions);
282 return derivs;
283 } else {
284 return get_deriv_nocomp_notcached(mole_fractions, tau, delta);
285 }
286 }
287 HelmholtzDerivatives get_deriv_nocomp_notcached(const std::vector<CoolPropDbl>& x, double tau, double delta) const {
289 // If Excess term is not being used, return zero
290 if (N == 0) {
291 return summer;
292 }
293 for (std::size_t i = 0; i < N - 1; i++) {
294 for (std::size_t j = i + 1; j < N; j++) {
296 DepartureFunctionMatrix[i][j]->calc_nocache(tau, delta, term);
297 summer = summer + term * x[i] * x[j] * F[i][j];
298 }
299 }
300 return summer;
301 }
302 double get_deriv_nocomp_cached(const std::vector<CoolPropDbl>& x, std::size_t itau, std::size_t idelta) {
303 // If Excess term is not being used, return zero
304 if (N == 0) {
305 return 0;
306 }
307 double summer = 0;
308 for (std::size_t i = 0; i < N - 1; i++) {
309 for (std::size_t j = i + 1; j < N; j++) {
310 // Retrieve cached value
311 summer += x[i] * x[j] * F[i][j] * DepartureFunctionMatrix[i][j]->get(itau, idelta);
312 }
313 }
314 return summer;
315 }
316 double alphar(const std::vector<CoolPropDbl>& x) {
317 return get_deriv_nocomp_cached(x, 0, 0);
318 };
319 double dalphar_dDelta(const std::vector<CoolPropDbl>& x) {
320 return get_deriv_nocomp_cached(x, 0, 1);
321 };
322 double d2alphar_dDelta2(const std::vector<CoolPropDbl>& x) {
323 return get_deriv_nocomp_cached(x, 0, 2);
324 };
325 double d2alphar_dDelta_dTau(const std::vector<CoolPropDbl>& x) {
326 return get_deriv_nocomp_cached(x, 1, 1);
327 };
328 double dalphar_dTau(const std::vector<CoolPropDbl>& x) {
329 return get_deriv_nocomp_cached(x, 1, 0);
330 };
331 double d2alphar_dTau2(const std::vector<CoolPropDbl>& x) {
332 return get_deriv_nocomp_cached(x, 2, 0);
333 };
334 double d3alphar_dTau3(const std::vector<CoolPropDbl>& x) {
335 return get_deriv_nocomp_cached(x, 3, 0);
336 };
337 double d3alphar_dDelta_dTau2(const std::vector<CoolPropDbl>& x) {
338 return get_deriv_nocomp_cached(x, 2, 1);
339 };
340 double d3alphar_dDelta2_dTau(const std::vector<CoolPropDbl>& x) {
341 return get_deriv_nocomp_cached(x, 1, 2);
342 };
343 double d3alphar_dDelta3(const std::vector<CoolPropDbl>& x) {
344 return get_deriv_nocomp_cached(x, 0, 3);
345 };
346 double d4alphar_dTau4(const std::vector<CoolPropDbl>& x) {
347 return get_deriv_nocomp_cached(x, 4, 0);
348 };
349 double d4alphar_dDelta_dTau3(const std::vector<CoolPropDbl>& x) {
350 return get_deriv_nocomp_cached(x, 3, 1);
351 };
352 double d4alphar_dDelta2_dTau2(const std::vector<CoolPropDbl>& x) {
353 return get_deriv_nocomp_cached(x, 2, 2);
354 };
355 double d4alphar_dDelta3_dTau(const std::vector<CoolPropDbl>& x) {
356 return get_deriv_nocomp_cached(x, 1, 3);
357 };
358 double d4alphar_dDelta4(const std::vector<CoolPropDbl>& x) {
359 return get_deriv_nocomp_cached(x, 0, 4);
360 };
361
362 double dalphar_dxi(const std::vector<CoolPropDbl>& x, std::size_t i, x_N_dependency_flag xN_flag) {
363 // If Excess term is not being used, return zero
364 if (N == 0) {
365 return 0;
366 }
367 if (xN_flag == XN_INDEPENDENT) {
368 double summer = 0;
369 for (std::size_t k = 0; k < N; k++) {
370 if (i != k) {
371 summer += x[k] * F[i][k] * DepartureFunctionMatrix[i][k]->alphar();
372 }
373 }
374 return summer;
375 } else if (xN_flag == XN_DEPENDENT) {
376 if (i == N - 1) {
377 return 0;
378 }
379 CoolPropDbl dar_dxi = 0.0;
380 double FiNariN = F[i][N - 1] * DepartureFunctionMatrix[i][N - 1]->alphar();
381 dar_dxi += (1 - 2 * x[i]) * FiNariN;
382 for (std::size_t k = 0; k < N - 1; ++k) {
383 if (i == k) continue;
384 double Fikarik = F[i][k] * DepartureFunctionMatrix[i][k]->alphar();
385 double FkNarkN = F[k][N - 1] * DepartureFunctionMatrix[k][N - 1]->alphar();
386 dar_dxi += x[k] * (Fikarik - FiNariN - FkNarkN);
387 }
388 return dar_dxi;
389 } else {
390 throw ValueError(format("xN_flag is invalid"));
391 }
392 };
393 double d2alphardxidxj(const std::vector<CoolPropDbl>& x, std::size_t i, std::size_t j, x_N_dependency_flag xN_flag) {
394 // If Excess term is not being used, return zero
395 if (N == 0) {
396 return 0;
397 }
398 if (xN_flag == XN_INDEPENDENT) {
399 if (i != j) {
400 return F[i][j] * DepartureFunctionMatrix[i][j]->alphar();
401 } else {
402 return 0;
403 }
404 } else if (xN_flag == XN_DEPENDENT) {
405 if (i == N - 1) {
406 return 0.0;
407 }
408 std::size_t N = x.size();
409 if (i == N - 1 || j == N - 1) {
410 return 0;
411 }
412 double FiNariN = F[i][N - 1] * DepartureFunctionMatrix[i][N - 1]->alphar();
413 if (i == j) {
414 return -2 * FiNariN;
415 }
416 double Fijarij = F[i][j] * DepartureFunctionMatrix[i][j]->alphar();
417 double FjNarjN = F[j][N - 1] * DepartureFunctionMatrix[j][N - 1]->alphar();
418 return Fijarij - FiNariN - FjNarjN;
419 } else {
420 throw ValueError(format("xN_flag is invalid"));
421 }
422 };
423 double d3alphar_dxi_dxj_dDelta(const std::vector<CoolPropDbl>& x, std::size_t i, std::size_t j, x_N_dependency_flag xN_flag) {
424 // If Excess term is not being used, return zero
425 if (N == 0) {
426 return 0;
427 }
428 if (xN_flag == XN_INDEPENDENT) {
429 if (i != j) {
430 return F[i][j] * DepartureFunctionMatrix[i][j]->dalphar_dDelta();
431 } else {
432 return 0;
433 }
434 } else if (xN_flag == XN_DEPENDENT) {
435 if (i == N - 1) {
436 return 0.0;
437 }
438 std::size_t N = x.size();
439 if (i == N - 1 || j == N - 1) {
440 return 0;
441 }
442 double FiNariN = F[i][N - 1] * DepartureFunctionMatrix[i][N - 1]->dalphar_dDelta();
443 if (i == j) {
444 return -2 * FiNariN;
445 }
446 double Fijarij = F[i][j] * DepartureFunctionMatrix[i][j]->dalphar_dDelta();
447 double FjNarjN = F[j][N - 1] * DepartureFunctionMatrix[j][N - 1]->dalphar_dDelta();
448 return Fijarij - FiNariN - FjNarjN;
449 } else {
450 throw ValueError(format("xN_flag is invalid"));
451 }
452 };
453 double d3alphar_dxi_dxj_dTau(const std::vector<CoolPropDbl>& x, std::size_t i, std::size_t j, x_N_dependency_flag xN_flag) {
454 // If Excess term is not being used, return zero
455 if (N == 0) {
456 return 0;
457 }
458 if (xN_flag == XN_INDEPENDENT) {
459 if (i != j) {
460 return F[i][j] * DepartureFunctionMatrix[i][j]->dalphar_dTau();
461 } else {
462 return 0;
463 }
464 } else {
465 throw ValueError(format("xN_flag is invalid"));
466 }
467 };
468 double d4alphar_dxi_dxj_dDelta2(const std::vector<CoolPropDbl>& x, std::size_t i, std::size_t j, x_N_dependency_flag xN_flag) {
469 // If Excess term is not being used, return zero
470 if (N == 0) {
471 return 0;
472 }
473 if (xN_flag == XN_INDEPENDENT) {
474 if (i != j) {
475 return F[i][j] * DepartureFunctionMatrix[i][j]->d2alphar_dDelta2();
476 } else {
477 return 0;
478 }
479 } else {
480 throw ValueError(format("xN_flag is invalid"));
481 }
482 };
483 double d4alphar_dxi_dxj_dDelta_dTau(const std::vector<CoolPropDbl>& x, std::size_t i, std::size_t j, x_N_dependency_flag xN_flag) {
484 // If Excess term is not being used, return zero
485 if (N == 0) {
486 return 0;
487 }
488 if (xN_flag == XN_INDEPENDENT) {
489 if (i != j) {
490 return F[i][j] * DepartureFunctionMatrix[i][j]->d2alphar_dDelta_dTau();
491 } else {
492 return 0;
493 }
494 } else if (xN_flag == XN_DEPENDENT) {
495 if (i == N - 1) {
496 return 0.0;
497 }
498 double FiNariN = F[i][N - 1] * DepartureFunctionMatrix[i][N - 1]->d2alphar_dDelta_dTau();
499 CoolPropDbl d3ar_dxi_dDelta_dTau = (1 - 2 * x[i]) * FiNariN;
500 for (std::size_t k = 0; k < N - 1; ++k) {
501 if (i == k) continue;
502 double Fikarik = F[i][k] * DepartureFunctionMatrix[i][k]->d2alphar_dDelta_dTau();
503 double FkNarkN = F[k][N - 1] * DepartureFunctionMatrix[k][N - 1]->d2alphar_dDelta_dTau();
504 d3ar_dxi_dDelta_dTau += x[k] * (Fikarik - FiNariN - FkNarkN);
505 }
506 return d3ar_dxi_dDelta_dTau;
507 } else {
508 throw ValueError(format("xN_flag is invalid"));
509 }
510 };
511 double d4alphar_dxi_dxj_dTau2(const std::vector<CoolPropDbl>& x, std::size_t i, std::size_t j, x_N_dependency_flag xN_flag) {
512 // If Excess term is not being used, return zero
513 if (N == 0) {
514 return 0;
515 }
516 if (xN_flag == XN_INDEPENDENT) {
517 if (i != j) {
518 return F[i][j] * DepartureFunctionMatrix[i][j]->d2alphar_dTau2();
519 } else {
520 return 0;
521 }
522 } else {
523 throw ValueError(format("xN_flag is invalid"));
524 }
525 };
526
527 double d3alphardxidxjdxk(const std::vector<CoolPropDbl>& x, std::size_t i, std::size_t j, std::size_t k, x_N_dependency_flag xN_flag) {
528 return 0;
529 };
530 double d2alphar_dxi_dTau(const std::vector<CoolPropDbl>& x, std::size_t i, x_N_dependency_flag xN_flag) {
531 // If Excess term is not being used, return zero
532 if (N == 0) {
533 return 0;
534 }
535 if (xN_flag == XN_INDEPENDENT) {
536 double summer = 0;
537 for (std::size_t k = 0; k < N; k++) {
538 if (i != k) {
539 summer += x[k] * F[i][k] * DepartureFunctionMatrix[i][k]->dalphar_dTau();
540 }
541 }
542 return summer;
543 } else if (xN_flag == XN_DEPENDENT) {
544 if (i == N - 1) {
545 return 0.0;
546 }
547 double FiNariN = F[i][N - 1] * DepartureFunctionMatrix[i][N - 1]->dalphar_dTau();
548 CoolPropDbl d2ar_dxi_dTau = (1 - 2 * x[i]) * FiNariN;
549 for (std::size_t k = 0; k < N - 1; ++k) {
550 if (i == k) continue;
551 double Fikarik = F[i][k] * DepartureFunctionMatrix[i][k]->dalphar_dTau();
552 double FkNarkN = F[k][N - 1] * DepartureFunctionMatrix[k][N - 1]->dalphar_dTau();
553 d2ar_dxi_dTau += x[k] * (Fikarik - FiNariN - FkNarkN);
554 }
555 return d2ar_dxi_dTau;
556 } else {
557 throw ValueError(format("xN_flag is invalid"));
558 }
559 };
560 double d2alphar_dxi_dDelta(const std::vector<CoolPropDbl>& x, std::size_t i, x_N_dependency_flag xN_flag) {
561 // If Excess term is not being used, return zero
562 if (N == 0) {
563 return 0;
564 }
565 if (xN_flag == XN_INDEPENDENT) {
566 double summer = 0;
567 for (std::size_t k = 0; k < N; k++) {
568 if (i != k) {
569 summer += x[k] * F[i][k] * DepartureFunctionMatrix[i][k]->dalphar_dDelta();
570 }
571 }
572 return summer;
573 } else if (xN_flag == XN_DEPENDENT) {
574 if (i == N - 1) {
575 return 0.0;
576 }
577 CoolPropDbl d2ar_dxi_dDelta = 0;
578 double FiNariN = F[i][N - 1] * DepartureFunctionMatrix[i][N - 1]->dalphar_dDelta();
579 d2ar_dxi_dDelta += (1 - 2 * x[i]) * FiNariN;
580 for (std::size_t k = 0; k < N - 1; ++k) {
581 if (i == k) continue;
582 double Fikarik = F[i][k] * DepartureFunctionMatrix[i][k]->dalphar_dDelta();
583 double FkNarkN = F[k][N - 1] * DepartureFunctionMatrix[k][N - 1]->dalphar_dDelta();
584 d2ar_dxi_dDelta += x[k] * (Fikarik - FiNariN - FkNarkN);
585 }
586 return d2ar_dxi_dDelta;
587 } else {
588 throw ValueError(format("xN_flag is invalid"));
589 }
590 };
591 double d3alphar_dxi_dDelta2(const std::vector<CoolPropDbl>& x, std::size_t i, x_N_dependency_flag xN_flag) {
592 // If Excess term is not being used, return zero
593 if (N == 0) {
594 return 0;
595 }
596 if (xN_flag == XN_INDEPENDENT) {
597 double summer = 0;
598 for (std::size_t k = 0; k < N; k++) {
599 if (i != k) {
600 summer += x[k] * F[i][k] * DepartureFunctionMatrix[i][k]->d2alphar_dDelta2();
601 }
602 }
603 return summer;
604 } else if (xN_flag == XN_DEPENDENT) {
605 if (i == N - 1) {
606 return 0.0;
607 }
608 double FiNariN = F[i][N - 1] * DepartureFunctionMatrix[i][N - 1]->d2alphar_dDelta2();
609 CoolPropDbl d3ar_dxi_dDelta2 = (1 - 2 * x[i]) * FiNariN;
610 for (std::size_t k = 0; k < N - 1; ++k) {
611 if (i == k) continue;
612 double Fikarik = F[i][k] * DepartureFunctionMatrix[i][k]->d2alphar_dDelta2();
613 double FkNarkN = F[k][N - 1] * DepartureFunctionMatrix[k][N - 1]->d2alphar_dDelta2();
614 d3ar_dxi_dDelta2 += x[k] * (Fikarik - FiNariN - FkNarkN);
615 }
616 return d3ar_dxi_dDelta2;
617 } else {
618 throw ValueError(format("xN_flag is invalid"));
619 }
620 };
621 double d4alphar_dxi_dDelta3(const std::vector<CoolPropDbl>& x, std::size_t i, x_N_dependency_flag xN_flag) {
622 // If Excess term is not being used, return zero
623 if (N == 0) {
624 return 0;
625 }
626 if (xN_flag == XN_INDEPENDENT) {
627 double summer = 0;
628 for (std::size_t k = 0; k < N; k++) {
629 if (i != k) {
630 summer += x[k] * F[i][k] * DepartureFunctionMatrix[i][k]->d3alphar_dDelta3();
631 }
632 }
633 return summer;
634 } else {
635 throw ValueError(format("xN_flag is invalid"));
636 }
637 };
638 double d3alphar_dxi_dTau2(const std::vector<CoolPropDbl>& x, std::size_t i, x_N_dependency_flag xN_flag) {
639 // If Excess term is not being used, return zero
640 if (N == 0) {
641 return 0;
642 }
643 if (xN_flag == XN_INDEPENDENT) {
644 double summer = 0;
645 for (std::size_t k = 0; k < N; k++) {
646 if (i != k) {
647 summer += x[k] * F[i][k] * DepartureFunctionMatrix[i][k]->d2alphar_dTau2();
648 }
649 }
650 return summer;
651 } else if (xN_flag == XN_DEPENDENT) {
652 if (i == N - 1) {
653 return 0.0;
654 }
655 double FiNariN = F[i][N - 1] * DepartureFunctionMatrix[i][N - 1]->d2alphar_dTau2();
656 CoolPropDbl d3ar_dxi_dTau2 = (1 - 2 * x[i]) * FiNariN;
657 for (std::size_t k = 0; k < N - 1; ++k) {
658 if (i == k) continue;
659 double Fikarik = F[i][k] * DepartureFunctionMatrix[i][k]->d2alphar_dTau2();
660 double FkNarkN = F[k][N - 1] * DepartureFunctionMatrix[k][N - 1]->d2alphar_dTau2();
661 d3ar_dxi_dTau2 += x[k] * (Fikarik - FiNariN - FkNarkN);
662 }
663 return d3ar_dxi_dTau2;
664 } else {
665 throw ValueError(format("xN_flag is invalid"));
666 }
667 };
668 double d4alphar_dxi_dTau3(const std::vector<CoolPropDbl>& x, std::size_t i, x_N_dependency_flag xN_flag) {
669 // If Excess term is not being used, return zero
670 if (N == 0) {
671 return 0;
672 }
673 if (xN_flag == XN_INDEPENDENT) {
674 double summer = 0;
675 for (std::size_t k = 0; k < N; k++) {
676 if (i != k) {
677 summer += x[k] * F[i][k] * DepartureFunctionMatrix[i][k]->d3alphar_dTau3();
678 }
679 }
680 return summer;
681 } else {
682 throw ValueError(format("xN_flag is invalid"));
683 }
684 };
685 double d3alphar_dxi_dDelta_dTau(const std::vector<CoolPropDbl>& x, std::size_t i, x_N_dependency_flag xN_flag) {
686 // If Excess term is not being used, return zero
687 if (N == 0) {
688 return 0;
689 }
690 if (xN_flag == XN_INDEPENDENT) {
691 double summer = 0;
692 for (std::size_t k = 0; k < N; k++) {
693 if (i != k) {
694 summer += x[k] * F[i][k] * DepartureFunctionMatrix[i][k]->d2alphar_dDelta_dTau();
695 }
696 }
697 return summer;
698 } else {
699 throw ValueError(format("xN_flag is invalid"));
700 }
701 };
702 double d4alphar_dxi_dDelta2_dTau(const std::vector<CoolPropDbl>& x, std::size_t i, x_N_dependency_flag xN_flag) {
703 // If Excess term is not being used, return zero
704 if (N == 0) {
705 return 0;
706 }
707 if (xN_flag == XN_INDEPENDENT) {
708 double summer = 0;
709 for (std::size_t k = 0; k < N; k++) {
710 if (i != k) {
711 summer += x[k] * F[i][k] * DepartureFunctionMatrix[i][k]->d3alphar_dDelta2_dTau();
712 }
713 }
714 return summer;
715 } else {
716 throw ValueError(format("xN_flag is invalid"));
717 }
718 };
719 double d4alphar_dxi_dDelta_dTau2(const std::vector<CoolPropDbl>& x, std::size_t i, x_N_dependency_flag xN_flag) {
720 // If Excess term is not being used, return zero
721 if (N == 0) {
722 return 0;
723 }
724 if (xN_flag == XN_INDEPENDENT) {
725 double summer = 0;
726 for (std::size_t k = 0; k < N; k++) {
727 if (i != k) {
728 summer += x[k] * F[i][k] * DepartureFunctionMatrix[i][k]->d3alphar_dDelta_dTau2();
729 }
730 }
731 return summer;
732 } else {
733 throw ValueError(format("xN_flag is invalid"));
734 }
735 };
736};
737
738} /* namespace CoolProp */
739#endif