teqp 0.22.0
|
#include <derivs.hpp>
Static Public Member Functions | |
static auto | get_splus (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the residual entropy ( \(s^+ = -s^r/R\)) from derivatives of alphar. | |
static auto | get_pr (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the residual pressure from derivatives of alphar. | |
static auto | get_Ar00 (const Model &model, const Scalar &T, const VectorType &rhovec) |
static auto | get_Ar10 (const Model &model, const Scalar &T, const VectorType &rhovec) |
static auto | get_Ar01 (const Model &model, const Scalar &T, const VectorType &rhovec) |
static auto | get_Psir (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate \(\Psi^r=a^r \rho\). | |
static auto | get_dPsirdT_constrhovec (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate derivative \(\Psi^r=a^r \rho\) w.r.t. T at constant molar concentrations. | |
static auto | build_Psir_Hessian_autodiff (const Model &model, const Scalar &T, const VectorType &rho) |
Calculate the Hessian of \(\Psi^r = a^r \rho\) w.r.t. the molar concentrations. | |
static auto | build_Psir_fgradHessian_autodiff (const Model &model, const Scalar &T, const VectorType &rho) |
Calculate the function value, gradient, and Hessian of \(Psi^r = a^r\rho\) w.r.t. the molar concentrations. | |
static auto | build_Psi_Hessian_autodiff (const Model &model, const Scalar &T, const VectorType &rho) |
Calculate the Hessian of \(\Psi = a \rho\) w.r.t. the molar concentrations. | |
static auto | build_Psir_gradient_autodiff (const Model &model, const Scalar &T, const VectorType &rho) |
Gradient of Psir = ar*rho w.r.t. the molar concentrations. | |
static auto | build_Psir_gradient_complex_step (const Model &model, const Scalar &T, const VectorType &rho) |
Gradient of Psir = ar*rho w.r.t. the molar concentrations. | |
template<ADBackends be = ADBackends::autodiff> | |
static auto | build_Psir_gradient (const Model &model, const Scalar &T, const VectorType &rho) |
static auto | get_chempotVLE_autodiff (const Model &model, const Scalar &T, const VectorType &rho) |
Calculate the chemical potential of each component. | |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_fugacity_coefficients (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the fugacity coefficient of each component. | |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_ln_fugacity_coefficients (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the natural logarithm of fugacity coefficient of each component. | |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_ln_fugacity_coefficients_Trhomolefracs (const Model &model, const Scalar &T, const Scalar &rhotot, const VectorType &molefrac) |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_ln_fugacity_coefficients1 (const Model &model, const Scalar &T, const VectorType &rhovec) |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_ln_fugacity_coefficients2 (const Model &model, const Scalar &T, const VectorType &rhovec) |
static Eigen::ArrayXd | build_d2PsirdTdrhoi_autodiff (const Model &model, const Scalar &T, const VectorType &rho) |
static Eigen::ArrayXd | build_d2alphardrhodxi_constT (const Model &model, const Scalar &T, const Scalar &rhomolar, const VectorType &molefrac) |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_d_ln_fugacity_coefficients_dT_constrhovec (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the derivative of the natural logarithm of fugacity coefficient of each component w.r.t. temperature at constant mole concentrations (implying constant mole fractions and density) | |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_lnZ_Z_dZdrho (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate ln(Z), Z, and dZ/drho at constant temperature and mole fractions. | |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_d_ln_fugacity_coefficients_drho_constTmolefracs (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the derivative of the natural logarithm of fugacity coefficient of each component w.r.t. molar density at constant temperature and mole fractions. | |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_d_ln_fugacity_coefficients_dv_constTmolefracs (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the derivative of the natural logarithm of fugacity coefficient of each component w.r.t. molar volume at constant temperature and mole fractions. | |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_d_ln_fugacity_coefficients_dmolefracs_constTrho (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the derivative of the natural logarithm of fugacity coefficient of each component w.r.t. mole fraction of each component, at constant temperature and molar density. | |
template<ADBackends be = ADBackends::autodiff> | |
static auto | get_d_ln_fugacity_coefficients_dmolefracs_constTrho1 (const Model &model, const Scalar &T, const VectorType &rhovec) |
static auto | get_dchempotdT_autodiff (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the temperature derivative of the chemical potential of each component. | |
static auto | get_dpdT_constrhovec (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the temperature derivative of the pressure at constant molar concentrations. | |
static auto | get_dpdrhovec_constT (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the molar concentration derivatives of the pressure at constant temperature. | |
static auto | get_partial_molar_volumes (const Model &model, const Scalar &T, const VectorType &rhovec) |
Calculate the partial molar volumes of each component. | |
static VectorType | get_Psir_sigma_derivs (const Model &model, const Scalar &T, const VectorType &rhovec, const VectorType &v) |
In the isochoric formalism, the fugacity coefficient array can be obtained by the gradient of the residual Helmholtz energy density (which is a scalar) and the compressibility factor \(Z\) (which is also a scalar) in terms of the temperature \(T\) and the molar concentration vector \(\vec\rho\):
\[ \ln\vec\phi = \frac{1}{RT}\frac{\partial \Psi^r}{d\vec\rho} - \ln(Z) \]
Easy: temperature derivative at constant molar concentrations (implying constant volume and molar composition)
\[ \deriv{ \ln\vec\phi}{T}{\vec\rho} = \frac{1}{RT}\frac{\partial^2 \Psi^r}{\partial \vec\rho\partial T} + \frac{-1}{RT^2}\deriv{\Psi^r}{\vec\rho}{T} - \frac{1}{Z}\deriv{Z}{T}{\vec\rho} \]
Medium: molar density derivative at constant temperature and mole fractions
\[ \deriv{ \ln\vec\phi}{\rho}{T,\vec x} = \frac{1}{RT}\frac{\partial^2 \Psi^r}{\partial \vec\rho\partial \rho} - \frac{1}{Z}\deriv{Z}{\rho}{T,\vec x} \]
\[ Z = 1+\rho\deriv{\alpha^r}{\rho}{T} \]
\[ \deriv{Z}{\rho}{T,\vec x} = \rho\deriv{^2\alpha^r}{\rho^2}{T} + \deriv{\alpha^r}{\rho}{T} \]
Back to basics, for a quantity \(\chi\) that is a function of \(T\) and \(\vec\rho\), and then the derivative taken w.r.t. density at constant temperature and mole fractions:
\[ \deriv{\chi}{\rho}{T, \vec x} = \deriv{\chi}{T}{\vec \rho}\cancelto{0}{\deriv{T}{\rho}{T}} + \sum_i\deriv{\chi}{\rho_i}{T, \rho_{j\neq i}}\deriv{\rho_i}{\rho}{T,\vec x} \]
with \(\rho_i =x_i\rho\)
\[ \deriv{\rho_i}{\rho}{T, \vec x} = x_i \]
thus
\[ \deriv{\chi}{\rho}{T, \vec x} = \sum_i\deriv{\chi}{\rho_i}{T, \rho_{j\neq i}}x_i \]
and following the pattern yields
\[ \frac{\partial^2 \Psi^r}{\partial \vec\rho\partial \rho} = \sum_i\deriv{\frac{\partial \Psi^r}{d\vec\rho} }{\rho_i}{T, \rho_{j\neq i}}x_i \]
where the big thing is the Hessian of the residual Hessian matrix of the residual Helmholtz energy density. This uses terms that are already developed.
Medium+: Volume derivative, based on the density derivative
\[ \deriv{ \ln\vec\phi}{v}{T,\vec x} = \deriv{ \ln\vec\phi}{\rho}{T,\vec x}\deriv{ \rho}{v}{} \]
\[ \deriv{\rho}{v}{} = -1/v^2 = -\rho^2 \]
Hard: mole fraction derivatives (this results in a matrix rather than a vector)
\[ \deriv{ \ln\vec\phi}{\vec x}{T,\rho} = ? \]
The first term is conceptually tricky. Again, considering a generic quantity \(\chi\)
\[ \deriv{\chi}{x_i}{T, \rho, x_{j\neq i}} = \deriv{\chi}{T}{\vec \rho}\cancelto{0}{\deriv{T}{x_i}{T,\rho,x_{j\neq i}}} + \sum_i\deriv{\chi}{\rho_i}{T, \rho_{j\neq i}}\deriv{\rho_i}{x_i}{T,\rho, x_{j\neq i}} \]
yields
\[ \deriv{\chi}{x_i}{T, \rho, x_{j\neq i}} = \rho \sum_i\deriv{\chi}{\rho_i}{T, \rho_{j\neq i}} \]
so the first part becomes
\[ \deriv{\frac{\partial \Psi^r}{d\vec\rho}}{x_i}{T, \rho, x_{j\neq i}} = \rho \sum_i\deriv{\frac{\partial \Psi^r}{d\vec\rho}}{\rho_i}{T, \rho_{j\neq i}} \]
or
\[ \deriv{^2\partial \Psi^r}{\vec\rho \partial \vec x}{T, \rho} = \rho H(\Psi^r) \]
which is somewhat surprising because the order of derivatives with respect to composition and density doesn't matter, as the Hessian is symmetric
The second part, from derivatives of \(\ln Z\), with \(Z\) given by
\[ Z = 1+\rho\deriv{\alpha^r}{\rho}{T, \vec x} \]
yields
\[ \deriv{\ln Z}{x_i}{T,\rho,x_{k \neq j}} = \frac{1}{Z}\deriv{Z}{x_i}{T,\rho,x_{k \neq i}} \]
which results in a vector because you have
\[ \deriv{Z}{x_i}{T,\rho,x_{k \neq i}} = \rho \deriv{^2\alpha^r}{\rho\partial x_i}{T} \]
Definition at line 957 of file derivs.hpp.
|
inlinestatic |
Definition at line 1282 of file derivs.hpp.
|
inlinestatic |
Definition at line 1264 of file derivs.hpp.
|
inlinestatic |
Calculate the Hessian of \(\Psi = a \rho\) w.r.t. the molar concentrations.
Uses autodiff derivatives to calculate second partial derivatives
Definition at line 1076 of file derivs.hpp.
|
inlinestatic |
Calculate the function value, gradient, and Hessian of \(Psi^r = a^r\rho\) w.r.t. the molar concentrations.
Uses autodiff to calculate the derivatives
Definition at line 1051 of file derivs.hpp.
|
inlinestatic |
Definition at line 1173 of file derivs.hpp.
|
inlinestatic |
Gradient of Psir = ar*rho w.r.t. the molar concentrations.
Uses autodiff to calculate derivatives
Definition at line 1115 of file derivs.hpp.
|
inlinestatic |
Gradient of Psir = ar*rho w.r.t. the molar concentrations.
Uses complex step to calculate derivatives
Definition at line 1152 of file derivs.hpp.
|
inlinestatic |
Calculate the Hessian of \(\Psi^r = a^r \rho\) w.r.t. the molar concentrations.
Requires the use of autodiff derivatives to calculate second partial derivatives
Definition at line 1031 of file derivs.hpp.
|
inlinestatic |
Definition at line 980 of file derivs.hpp.
|
inlinestatic |
Definition at line 992 of file derivs.hpp.
|
inlinestatic |
Definition at line 986 of file derivs.hpp.
|
inlinestatic |
Calculate the chemical potential of each component.
Uses autodiff to calculate derivatives See Eq. 5 of https://doi.org/10.1002/aic.16730, but the rho in the denominator should be a rhoref (taken to be 1)
Definition at line 1196 of file derivs.hpp.
|
inlinestatic |
Calculate the derivative of the natural logarithm of fugacity coefficient of each component w.r.t. mole fraction of each component, at constant temperature and molar density.
\[ \deriv{ \ln\vec\phi}{\vec x}{T, \rho} \]
Definition at line 1375 of file derivs.hpp.
|
inlinestatic |
Definition at line 1396 of file derivs.hpp.
|
inlinestatic |
Calculate the derivative of the natural logarithm of fugacity coefficient of each component w.r.t. molar density at constant temperature and mole fractions.
\[ \deriv{ \ln\vec\phi}{\rho}{T,\vec x} = \frac{1}{RT}H(\Psi_r)\vec x - \frac{1}{Z}\deriv{Z}{\rho}{T,\vec x} \]
Definition at line 1344 of file derivs.hpp.
|
inlinestatic |
Calculate the derivative of the natural logarithm of fugacity coefficient of each component w.r.t. temperature at constant mole concentrations (implying constant mole fractions and density)
Uses autodiff to calculate derivatives by default
\[ \deriv{ \ln\vec\phi}{T}{\vec \rho} \]
Definition at line 1307 of file derivs.hpp.
|
inlinestatic |
Calculate the derivative of the natural logarithm of fugacity coefficient of each component w.r.t. molar volume at constant temperature and mole fractions.
\[ \deriv{ \ln\vec\phi}{v}{T,\vec x} = \deriv{ \ln\vec\phi}{\rho}{T,\vec x}\deriv{ \rho}{v}{} \]
Definition at line 1361 of file derivs.hpp.
|
inlinestatic |
Calculate the temperature derivative of the chemical potential of each component.
Definition at line 1411 of file derivs.hpp.
|
inlinestatic |
Calculate the molar concentration derivatives of the pressure at constant temperature.
Definition at line 1431 of file derivs.hpp.
|
inlinestatic |
Calculate the temperature derivative of the pressure at constant molar concentrations.
Definition at line 1421 of file derivs.hpp.
|
inlinestatic |
Calculate derivative \(\Psi^r=a^r \rho\) w.r.t. T at constant molar concentrations.
Definition at line 1018 of file derivs.hpp.
|
inlinestatic |
Calculate the fugacity coefficient of each component.
Uses autodiff to calculate derivatives
Definition at line 1209 of file derivs.hpp.
|
inlinestatic |
Calculate the natural logarithm of fugacity coefficient of each component.
Uses autodiff to calculate derivatives by default
Definition at line 1220 of file derivs.hpp.
|
inlinestatic |
Definition at line 1245 of file derivs.hpp.
|
inlinestatic |
Definition at line 1256 of file derivs.hpp.
|
inlinestatic |
Definition at line 1233 of file derivs.hpp.
|
inlinestatic |
Calculate ln(Z), Z, and dZ/drho at constant temperature and mole fractions.
Uses autodiff to calculate derivatives by default
Definition at line 1325 of file derivs.hpp.
|
inlinestatic |
Calculate the partial molar volumes of each component.
\[ \hat v_i = \left(\frac{\partial V}{\partial n_i}\right)_{T,V,n_{j \neq i}} \]
Eq 7.32 from GERG-2004
\[ \hat v_i = \deriv{V}{n_i}{T,p,n_j} = \displaystyle\frac{-n\deriv{p}{n_i}{T,V,n_j}}{n\deriv{p}{V}{T,\vec{n}}} \]
Total differential of a variable \(Y\) that is a function of \(T\), \(\vec{\rho}\):
\[ \mathrm{d} Y = \deriv{Y}{T}{\vec{\rho}} \mathrm{d} T + \sum_k \deriv{Y}{\rho_k}{T,\rho_{j\neq i}} \mathrm{d} \rho_k \]
so
\[ \deriv{Y}{n_i}{T,V,n_{j\neq i}} = \deriv{Y}{T}{\vec{\rho}} \cancelto{0}{\deriv{T}{n_i}{T,V,n_j}} + \sum_k \deriv{Y}{\rho_k}{T,\rho_{j\neq i}} \deriv{\rho_k}{n_i}{T,V,n_j} \]
\[ \deriv{\rho_k}{n_i}{T,V,n_j} = \frac{\delta_{ik}}{V} \]
because \(\rho_k = n_k/V\).
Thus in the isochoric framework, the partial molar volume is given by
\[ \hat v_i = \displaystyle\frac{-\frac{n}{V}\deriv{p}{\rho_i}{T,\rho_j}}{n\deriv{p}{V}{T,\vec{n}}} \]
The final formulation includes this term in the numerator (see the supporting info from isochoric paper):
\[ \deriv{p}{\rho_i}{T,\rho_j} = RT + \sum_k\rho_k\deriv{^2\Psi^{\rm r}}{\rho_k\partial \rho_i}{T,\rho_{j\neq k}} \]
and the denominator is given by (Eq. 7.62 of GERG-2004)
\[ n\deriv{p}{V}{T,\vec{n}} = -\rho^2 RT\left(1+2\delta\deriv{\alpha^{\rm r}}{\delta}{\tau} + \delta^2\deriv{^2\alpha^{\rm r}}{\delta^2}{\tau} \right) \]
and finally
\[ \hat v_i = \displaystyle\frac{-\rho\deriv{p}{\rho_i}{T,\rho_j}}{n\deriv{p}{V}{T,\vec{n}}} \]
Definition at line 1482 of file derivs.hpp.
|
inlinestatic |
Calculate the residual pressure from derivatives of alphar.
Definition at line 971 of file derivs.hpp.
|
inlinestatic |
Calculate \(\Psi^r=a^r \rho\).
Definition at line 1009 of file derivs.hpp.
|
inlinestatic |
Definition at line 1496 of file derivs.hpp.
|
inlinestatic |
Calculate the residual entropy ( \(s^+ = -s^r/R\)) from derivatives of alphar.
Definition at line 962 of file derivs.hpp.