13 double B = 1 + m * (1 -
sqrt_Tr_Tci * sqrt(1 / tau));
38 double dDi_dtau = (itau >= 1) ? (1.0 / 2.0) *
sqrt_Tr_Tci / (pow(tau, 1.5)) : 0;
39 double d2Di_dtau2 = (itau >= 2) ? -(3.0 / 4.0) *
sqrt_Tr_Tci / (pow(tau, 2.5)) : 0;
40 double d3Di_dtau3 = (itau >= 3) ? (15.0 / 8.0) *
sqrt_Tr_Tci / (pow(tau, 3.5)) : 0;
41 double d4Di_dtau4 = (itau >= 4) ? -(105.0 / 16.0) *
sqrt_Tr_Tci / (pow(tau, 4.5)) : 0;
43 double Bi = 1, dBi_dtau = 0, d2Bi_dtau2 = 0, d3Bi_dtau3 = 0, d4Bi_dtau4 = 0;
44 for (
int n = 1; n <= 3; ++n) {
45 Bi +=
c[n - 1] * pow(Di, n);
46 dBi_dtau += (itau < 1) ? 0 : (n *
c[n - 1] * pow(Di, n - 1) * dDi_dtau);
47 d2Bi_dtau2 += (itau < 2) ? 0 : n *
c[n - 1] * ((n - 1) * pow(dDi_dtau, 2) + Di * d2Di_dtau2) * pow(Di, n - 2);
48 d3Bi_dtau3 += (itau < 3)
50 : n *
c[n - 1] * (3 * (n - 1) * Di * dDi_dtau * d2Di_dtau2 + (n * n - 3 * n + 2) * pow(dDi_dtau, 3) + pow(Di, 2) * d3Di_dtau3)
56 * (6 * (n * n - 3 * n + 2) * Di * pow(dDi_dtau, 2) * d2Di_dtau2 + (n * n * n - 6 * n * n + 11 * n - 6) * pow(dDi_dtau, 4)
57 + (4 * n * dDi_dtau * d3Di_dtau3 + 3 * n * pow(d2Di_dtau2, 2) - 4 * dDi_dtau * d3Di_dtau3 - 3 * pow(d2Di_dtau2, 2)) * pow(Di, 2)
58 + pow(Di, 3) * d4Di_dtau4)
65 return 2 *
a0 * Bi * dBi_dtau;
67 return 2 *
a0 * (Bi * d2Bi_dtau2 + dBi_dtau * dBi_dtau);
69 return 2 *
a0 * (Bi * d3Bi_dtau3 + 3 * dBi_dtau * d2Bi_dtau2);
71 return 2 *
a0 * (Bi * d4Bi_dtau4 + 4 * dBi_dtau * d3Bi_dtau3 + 3 * pow(d2Bi_dtau2, 2));
84 const double L =
c[0], M =
c[1], N =
c[2];
86 double B1 = (itau < 1) ? 0 : N / tau * (L * M * A - M + 1);
87 double dB1_dtau = (itau < 2) ? 0 : N /
powInt(tau, 2) * (-L * M * M * N * A - L * M * A + M - 1);
88 double d2B1_dtau2 = (itau < 3) ? 0 : N /
powInt(tau, 3) * (L * M * M * M * N * N * A + 3 * L * M * M * N * A + 2 * L * M * A - 2 * M + 2);
92 * (L *
powInt(M, 4) *
powInt(N, 3) * A + 6 * L * M * M * M * N * N * A + 11 * L * M * M * N * A + 6 * L * M * A - 6 * M + 6);
94 double dam_dtau, d2am_dtau2, d3am_dtau3, d4am_dtau4;
95 double am =
a0 * pow(
Tr_over_Tci / tau, N * (M - 1)) * exp(L * (1 - A));
102 d2am_dtau2 = (itau < 2) ? 0 : B1 * dam_dtau + am * dB1_dtau;
103 d3am_dtau3 = (itau < 3) ? 0 : B1 * d2am_dtau2 + am * d2B1_dtau2 + 2 * dB1_dtau * dam_dtau;
104 d4am_dtau4 = (itau < 4) ? 0 : B1 * d3am_dtau3 + am * d3B1_dtau3 + 3 * dB1_dtau * d2am_dtau2 + 3 * d2B1_dtau2 * dam_dtau;
121 std::vector<double> C1, std::vector<double> C2, std::vector<double> C3)
122 : Tc(Tc), pc(pc), acentric(acentric), R_u(R_u), Delta_1(Delta_1), Delta_2(Delta_2) {
123 N =
static_cast<int>(
Tc.size());
124 k.resize(
N, std::vector<double>(
N, 0));
135 if (C1.empty() && C2.empty() && C3.empty()) {
136 for (std::size_t i = 0; i <
Tc.size(); ++i) {
141 for (std::size_t i = 0; i <
Tc.size(); ++i) {
149 for (
int i =
N - 1; i >= 0; --i) {
150 for (
int j =
N - 1; j >= 0; --j) {
151 summer += x[i] * x[j] *
aij_term(tau, i, j, itau);
157 if (xN_independent) {
159 for (
int j =
N - 1; j >= 0; --j) {
160 summer += x[j] *
aij_term(tau, i, j, itau);
165 for (
int k =
N - 2;
k >= 0; --
k) {
168 return 2 * (summer + x[
N - 1] * (
aij_term(tau,
N - 1, i, itau) -
aij_term(tau,
N - 1,
N - 1, itau)));
172 bool xN_independent) {
173 if (xN_independent) {
174 return 2 *
aij_term(tau, i, j, itau);
176 return 2 * (
aij_term(tau, i, j, itau) -
aij_term(tau, j,
N - 1, itau) -
aij_term(tau,
N - 1, i, itau) +
aij_term(tau,
N - 1,
N - 1, itau));
181 bool xN_independent) {
187 for (
int i =
N - 1; i >= 0; --i) {
188 summer += x[i] *
b0_ii(i);
193 if (xN_independent) {
211 return alpha[i]->term(tau, itau);
223 return (aii *
aii_term(tau, j, 3) + 3 *
aii_term(tau, i, 1) *
aii_term(tau, j, 2) + 3 *
aii_term(tau, i, 2) *
aii_term(tau, j, 1)
226 return (aii *
aii_term(tau, j, 4) + 4 *
aii_term(tau, i, 1) *
aii_term(tau, j, 3) + 6 *
aii_term(tau, i, 2) *
aii_term(tau, j, 2)
233 double u =
u_term(tau, i, j, 0);
237 return (1 -
k[i][j]) * sqrt(u);
239 return (1 -
k[i][j]) / (2.0 * sqrt(u)) *
u_term(tau, i, j, 1);
241 return (1 -
k[i][j]) / (4.0 * pow(u, 3.0 / 2.0)) * (2 * u *
u_term(tau, i, j, 2) - pow(
u_term(tau, i, j, 1), 2));
243 return (1 -
k[i][j]) / (8.0 * pow(u, 5.0 / 2.0))
244 * (4 * pow(u, 2) *
u_term(tau, i, j, 3) - 6 * u *
u_term(tau, i, j, 1) *
u_term(tau, i, j, 2) + 3 * pow(
u_term(tau, i, j, 1), 3));
246 return (1 -
k[i][j]) / (16.0 * pow(u, 7.0 / 2.0))
247 * (-4 * pow(u, 2) * (4 *
u_term(tau, i, j, 1) *
u_term(tau, i, j, 3) + 3 * pow(
u_term(tau, i, j, 2), 2))
248 + 8 * pow(u, 3) *
u_term(tau, i, j, 4) + 36 * u * pow(
u_term(tau, i, j, 1), 2) *
u_term(tau, i, j, 2)
249 - 15 * pow(
u_term(tau, i, j, 1), 4));
255 if (itau > 0)
return 0.0;
257 double bracket = 1 - bmc * delta *
rho_r;
261 return -log(bracket);
263 return bmc *
rho_r / bracket;
265 return pow(bmc *
rho_r / bracket, 2);
267 return 2 * pow(bmc *
rho_r / bracket, 3);
269 return 6 * pow(bmc *
rho_r / bracket, 4);
275 bool xN_independent) {
276 if (itau > 0)
return 0.0;
279 double bracket = 1 - bmc * delta *
rho_r;
283 return delta *
rho_r * db_dxi / bracket;
285 return rho_r * db_dxi / pow(bracket, 2);
287 return 2 * pow(
rho_r, 2) * bmc * db_dxi / pow(bracket, 3);
289 return 6 * pow(
rho_r, 3) * pow(bmc, 2) * db_dxi / pow(bracket, 4);
291 return 24 * pow(
rho_r, 4) * pow(bmc, 3) * db_dxi / pow(bracket, 5);
297 std::size_t j,
bool xN_independent) {
298 if (itau > 0)
return 0.0;
302 double bracket = 1 - bmc * delta *
rho_r;
306 return pow(delta *
rho_r, 2) * db_dxi * db_dxj / pow(bracket, 2) + delta *
rho_r * d2b_dxidxj / bracket;
308 return 2 * delta * pow(
rho_r, 2) * db_dxi * db_dxj / pow(bracket, 3) +
rho_r * d2b_dxidxj / pow(bracket, 2);
310 return 2 * pow(
rho_r, 2) * db_dxi * db_dxj / pow(bracket, 4) * (2 * delta *
rho_r * bmc + 1)
311 + 2 * pow(
rho_r, 2) * bmc * d2b_dxidxj / pow(bracket, 3);
313 return 12 * pow(
rho_r, 3) * bmc * db_dxi * db_dxj / pow(bracket, 5) * (delta *
rho_r * bmc + 1)
314 + 6 * pow(
rho_r, 3) * pow(bmc, 2) * d2b_dxidxj / pow(bracket, 4);
316 return 24 * pow(
rho_r, 4) * pow(bmc, 2) * db_dxi * db_dxj / pow(bracket, 6) * (2 * delta *
rho_r * bmc + 3)
317 + 24 * pow(
rho_r, 4) * pow(bmc, 3) * d2b_dxidxj / pow(bracket, 5);
323 std::size_t j, std::size_t k,
bool xN_independent) {
324 if (itau > 0)
return 0.0;
329 double bracket = 1 - bmc * delta *
rho_r;
333 return delta *
rho_r * d3b_dxidxjdxk / bracket + 2 * pow(delta *
rho_r, 3) * db_dxi * db_dxj * db_dxk / pow(bracket, 3)
334 + pow(delta *
rho_r, 2) / pow(bracket, 2) * (db_dxi * d2b_dxjdxk + db_dxj * d2b_dxidxk + db_dxk * d2b_dxidxj);
336 return rho_r * d3b_dxidxjdxk / pow(bracket, 2) + 6 * pow(delta, 2) * pow(
rho_r, 3) * db_dxi * db_dxj * db_dxk / pow(bracket, 4)
337 + 2 * delta * pow(
rho_r, 2) / pow(bracket, 3) * (db_dxi * d2b_dxjdxk + db_dxj * d2b_dxidxk + db_dxk * d2b_dxidxj);
380 bool xN_independent) {
395 return 2 * pow(
rho_r, 2)
406 bool xN_independent) {
416 + 2 *
Delta_1 *
Delta_2 * delta *
rho_r * (db_dxi * d2b_dxjdxk + db_dxj * d2b_dxidxk + db_dxk * d2b_dxidxj));
420 + 4 *
Delta_1 *
Delta_2 * delta *
rho_r * (db_dxi * d2b_dxjdxk + db_dxj * d2b_dxidxk + db_dxk * d2b_dxidxj));
434 return rho_r * (-
PI_12(delta, x, 0) *
PI_12(delta, x, 2) + 2 * pow(
PI_12(delta, x, 1), 2)) / pow(
PI_12(delta, x, 0), 3);
438 / pow(
PI_12(delta, x, 0), 4);
452 bracket =
d_PI_12_dxi(delta, x, 0, i, xN_independent);
455 bracket = (
d_PI_12_dxi(delta, x, 1, i, xN_independent)
461 + 2 /
rho_r * (pow(
PI_12(delta, x, 1), 2) +
PI_12(delta, x, 0) *
PI_12(delta, x, 2)) *
d_psi_plus_dxi(delta, x, 1, i, xN_independent)
469 + 6 /
rho_r * (pow(
PI_12(delta, x, 1), 2) +
PI_12(delta, x, 0) *
PI_12(delta, x, 2)) *
d_psi_plus_dxi(delta, x, 2, i, xN_independent)
475 return -
rho_r / pow(
PI_12(delta, x, 0), 2) * bracket;
478 bool xN_independent) {
480 double PI12 =
PI_12(delta, x, 0);
496 + 2 * (PI12 *
d_PI_12_dxi(delta, x, 1, j, xN_independent) +
PI_12(delta, x, 1) *
d_PI_12_dxi(delta, x, 0, j, xN_independent))
504 + 2 * (PI12 *
PI_12(delta, x, 2) + pow(
PI_12(delta, x, 1), 2)) *
d2_psi_plus_dxidxj(delta, x, 1, i, j, xN_independent)
505 + 4 * (PI12 *
d_PI_12_dxi(delta, x, 1, j, xN_independent) +
PI_12(delta, x, 1) *
d_PI_12_dxi(delta, x, 0, j, xN_independent))
508 * (PI12 *
d_PI_12_dxi(delta, x, 2, j, xN_independent) + 2 *
PI_12(delta, x, 1) *
d_PI_12_dxi(delta, x, 1, j, xN_independent)
521 (+6 * (PI12 *
PI_12(delta, x, 2) + pow(
PI_12(delta, x, 1), 2)) *
d2_psi_plus_dxidxj(delta, x, 2, i, j, xN_independent)
523 + 6 * (PI12 *
d_PI_12_dxi(delta, x, 1, j, xN_independent) +
PI_12(delta, x, 1) *
d_PI_12_dxi(delta, x, 0, j, xN_independent))
526 * (PI12 *
d_PI_12_dxi(delta, x, 2, j, xN_independent) + 2 *
PI_12(delta, x, 1) *
d_PI_12_dxi(delta, x, 1, j, xN_independent)
539 return -1 / pow(PI12, 2) * bracket;
542 std::size_t k,
bool xN_independent) {
543 double PI12 =
PI_12(delta, x, 0);
556 return -1 / pow(PI12, 2)
571 return tau *
am_term(tau, x, 0);
573 return tau *
am_term(tau, x, itau) + itau *
am_term(tau, x, itau - 1);
584 bool xN_independent) {
588 return tau *
d2_am_term_dxidxj(tau, x, itau, i, j, xN_independent) + itau *
d2_am_term_dxidxj(tau, x, itau - 1, i, j, xN_independent);
592 std::size_t k,
bool xN_independent) {
600 double AbstractCubic::alphar(
double tau,
double delta,
const std::vector<double>& x, std::size_t itau, std::size_t idelta) {
604 bool xN_independent) {
611 std::size_t j,
bool xN_independent) {
620 std::size_t j, std::size_t k,
bool xN_independent) {
643 double b = 0.08664 *
R_u *
Tc[i] /
pc[i];
649 double m = 0.480 + 1.574 * omega - 0.176 * omega * omega;
658 double b = 0.07780 *
R_u *
Tc[i] /
pc[i];
663 double m = 0.37464 + 1.54226 * omega - 0.26992 * omega * omega;