Cubic Equations of State Utilities (thermo.eos_mix_methods)¶
This file contains a number of overflow methods for EOSs which for various reasons are better implemented as functions. Documentation is not provided for this file and no methods are intended to be used outside this library.
For reporting bugs, adding feature requests, or submitting pull requests, please use the GitHub issue tracker.
Alpha Function Mixing Rules¶
These are where the bulk of the time is spent in solving the equation of state. For that reason, these functional forms often duplicate functionality but have different performance characteristics.
Implementations which store N^2 matrices for other calculations:
- thermo.eos_mix_methods.a_alpha_aijs_composition_independent(a_alphas, kijs)[source]¶
Calculates the matrix \((a\alpha)_{ij}\) as well as the array \(\sqrt{(a\alpha)_{i}}\) and the matrix \(\frac{1}{\sqrt{(a\alpha)_{i}}\sqrt{(a\alpha)_{j}}}\).
\[(a\alpha)_{ij} = (1-k_{ij})\sqrt{(a\alpha)_{i}(a\alpha)_{j}} \]This routine is efficient in both numba and PyPy, but it is generally better to avoid calculating and storing any N^2 matrices. However, this particular calculation only depends on T so in some circumstances this can be feasible.
- Parameters
- a_alphaslist[float]
EOS attractive terms, [J^2/mol^2/Pa]
- kijslist[list[float]]
Constant kijs, [-]
- Returns
- a_alpha_ijslist[list[float]]
Matrix of \((1-k_{ij})\sqrt{(a\alpha)_{i}(a\alpha)_{j}}\), [J^2/mol^2/Pa]
- a_alpha_rootslist[float]
Array of \(\sqrt{(a\alpha)_{i}}\) values, [J/mol/Pa^0.5]
- a_alpha_ij_roots_invlist[list[float]]
Matrix of \(\frac{1}{\sqrt{(a\alpha)_{i}}\sqrt{(a\alpha)_{j}}}\), [mol^2*Pa/J^2]
Examples
>>> kijs = [[0,.083],[0.083,0]] >>> a_alphas = [0.2491099357671155, 0.6486495863528039] >>> a_alpha_ijs, a_alpha_roots, a_alpha_ij_roots_inv = a_alpha_aijs_composition_independent(a_alphas, kijs) >>> a_alpha_ijs [[0.249109935767, 0.36861239374], [0.36861239374, 0.64864958635]] >>> a_alpha_roots [0.49910914213, 0.80538784840] >>> a_alpha_ij_roots_inv [[4.0142919105, 2.487707997796], [2.487707997796, 1.54166443799]]
- thermo.eos_mix_methods.a_alpha_and_derivatives_full(a_alphas, da_alpha_dTs, d2a_alpha_dT2s, T, zs, kijs, a_alpha_ijs=None, a_alpha_roots=None, a_alpha_ij_roots_inv=None)[source]¶
Calculates the a_alpha term, and its first two temperature derivatives, for an equation of state along with the matrix quantities calculated in the process.
\[a \alpha = \sum_i \sum_j z_i z_j {(a\alpha)}_{ij} \]\[\frac{\partial (a\alpha)}{\partial T} = \sum_i \sum_j z_i z_j \frac{\partial (a\alpha)_{ij}}{\partial T} \]\[\frac{\partial^2 (a\alpha)}{\partial T^2} = \sum_i \sum_j z_i z_j \frac{\partial^2 (a\alpha)_{ij}}{\partial T^2} \]\[(a\alpha)_{ij} = (1-k_{ij})\sqrt{(a\alpha)_{i}(a\alpha)_{j}} \]\[\frac{\partial (a\alpha)_{ij}}{\partial T} = \frac{\sqrt{\operatorname{a\alpha_{i}}{\left(T \right)} \operatorname{a\alpha_{j}} {\left(T \right)}} \left(1 - k_{ij}\right) \left(\frac{\operatorname{a\alpha_{i}} {\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)}}{2} + \frac{\operatorname{a\alpha_{j}}{\left(T \right)} \frac{d}{d T} \operatorname{ a\alpha_{i}}{\left(T \right)}}{2}\right)}{\operatorname{a\alpha_{i}}{\left(T \right)} \operatorname{a\alpha_{j}}{\left(T \right)}} \]\[\frac{\partial^2 (a\alpha)_{ij}}{\partial T^2} = - \frac{\sqrt{\operatorname{a\alpha_{i}}{\left(T \right)} \operatorname{a\alpha_{j}} {\left(T \right)}} \left(k_{ij} - 1\right) \left(\frac{\left(\operatorname{ a\alpha_{i}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)} + \operatorname{a\alpha_{j}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{i}} {\left(T \right)}\right)^{2}}{4 \operatorname{a\alpha_{i}}{\left(T \right)} \operatorname{a\alpha_{j}}{\left(T \right)}} - \frac{\left(\operatorname{a\alpha_{i}} {\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)} + \operatorname{a\alpha_{j}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{i}}{\left(T \right)}\right) \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)}}{2 \operatorname{a\alpha_{j}} {\left(T \right)}} - \frac{\left(\operatorname{a\alpha_{i}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)} + \operatorname{a\alpha_{j}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{i}}{\left(T \right)}\right) \frac{d}{d T} \operatorname{a\alpha_{i}}{\left(T \right)}}{2 \operatorname{a\alpha_{i}} {\left(T \right)}} + \frac{\operatorname{a\alpha_{i}}{\left(T \right)} \frac{d^{2}}{d T^{2}} \operatorname{a\alpha_{j}}{\left(T \right)}}{2} + \frac{\operatorname{a\alpha_{j}}{\left(T \right)} \frac{d^{2}}{d T^{2}} \operatorname{a\alpha_{i}}{\left(T \right)}}{2} + \frac{d}{d T} \operatorname{a\alpha_{i}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)}\right)} {\operatorname{a\alpha_{i}}{\left(T \right)} \operatorname{a\alpha_{j}} {\left(T \right)}} \]- Parameters
- a_alphaslist[float]
EOS attractive terms, [J^2/mol^2/Pa]
- da_alpha_dTslist[float]
Temperature derivative of coefficient calculated by EOS-specific method, [J^2/mol^2/Pa/K]
- d2a_alpha_dT2slist[float]
Second temperature derivative of coefficient calculated by EOS-specific method, [J^2/mol^2/Pa/K**2]
- Tfloat
Temperature, not used, [K]
- zslist[float]
Mole fractions of each species
- kijslist[list[float]]
Constant kijs, [-]
- a_alpha_ijslist[list[float]], optional
Matrix of \((1-k_{ij})\sqrt{(a\alpha)_{i}(a\alpha)_{j}}\), [J^2/mol^2/Pa]
- a_alpha_rootslist[float], optional
Array of \(\sqrt{(a\alpha)_{i}}\) values, [J/mol/Pa^0.5]
- a_alpha_ij_roots_invlist[list[float]], optional
Matrix of \(\frac{1}{\sqrt{(a\alpha)_{i}}\sqrt{(a\alpha)_{j}}}\), [mol^2*Pa/J^2]
- Returns
- a_alphafloat
EOS attractive term, [J^2/mol^2/Pa]
- da_alpha_dTfloat
Temperature derivative of coefficient calculated by EOS-specific method, [J^2/mol^2/Pa/K]
- d2a_alpha_dT2float
Second temperature derivative of coefficient calculated by EOS-specific method, [J^2/mol^2/Pa/K**2]
- a_alpha_ijslist[list[float]], optional
Matrix of \((1-k_{ij})\sqrt{(a\alpha)_{i}(a\alpha)_{j}}\), [J^2/mol^2/Pa]
- da_alpha_dT_ijslist[list[float]], optional
Matrix of \(\frac{\partial (a\alpha)_{ij}}{\partial T}\), [J^2/mol^2/Pa/K]
- d2a_alpha_dT2_ijslist[list[float]], optional
Matrix of \(\frac{\partial^2 (a\alpha)_{ij}}{\partial T^2}\), [J^2/mol^2/Pa/K^2]
Examples
>>> kijs = [[0,.083],[0.083,0]] >>> zs = [0.1164203, 0.8835797] >>> a_alphas = [0.2491099357671155, 0.6486495863528039] >>> da_alpha_dTs = [-0.0005102028006086241, -0.0011131153520304886] >>> d2a_alpha_dT2s = [1.8651128859234162e-06, 3.884331923127011e-06] >>> a_alpha, da_alpha_dT, d2a_alpha_dT2, a_alpha_ijs, da_alpha_dT_ijs, d2a_alpha_dT2_ijs = a_alpha_and_derivatives_full(a_alphas=a_alphas, da_alpha_dTs=da_alpha_dTs, d2a_alpha_dT2s=d2a_alpha_dT2s, T=299.0, zs=zs, kijs=kijs) >>> a_alpha, da_alpha_dT, d2a_alpha_dT2 (0.58562139582, -0.001018667672, 3.56669817856e-06) >>> a_alpha_ijs [[0.2491099357, 0.3686123937], [0.36861239374, 0.64864958635]] >>> da_alpha_dT_ijs [[-0.000510202800, -0.0006937567844], [-0.000693756784, -0.00111311535]] >>> d2a_alpha_dT2_ijs [[1.865112885e-06, 2.4734471244e-06], [2.4734471244e-06, 3.8843319e-06]]
Compute only the alpha term itself:
- thermo.eos_mix_methods.a_alpha_and_derivatives(a_alphas, T, zs, kijs, a_alpha_ijs=None, a_alpha_roots=None, a_alpha_ij_roots_inv=None)[source]¶
Faster implementations which do not store N^2 matrices:
- thermo.eos_mix_methods.a_alpha_quadratic_terms(a_alphas, a_alpha_roots, T, zs, kijs, a_alpha_j_rows=None, vec0=None)[source]¶
Calculates the a_alpha term for an equation of state along with the vector quantities needed to compute the fugacities of the mixture. This routine is efficient in both numba and PyPy.
\[a \alpha = \sum_i \sum_j z_i z_j {(a\alpha)}_{ij} \]\[(a\alpha)_{ij} = (1-k_{ij})\sqrt{(a\alpha)_{i}(a\alpha)_{j}} \]The secondary values are as follows:
\[\sum_i y_i(a\alpha)_{ij} \]- Parameters
- a_alphaslist[float]
EOS attractive terms, [J^2/mol^2/Pa]
- a_alpha_rootslist[float]
Square roots of a_alphas; provided for speed [J/mol/Pa^0.5]
- Tfloat
Temperature, not used, [K]
- zslist[float]
Mole fractions of each species
- kijslist[list[float]]
Constant kijs, [-]
- a_alpha_j_rowslist[float], optional
EOS attractive term row destimation vector (does not need to be zeroed, should be provided to prevent allocations), [J^2/mol^2/Pa]
- vec0list[float], optional
Empty vector, used in internal calculations, provide to avoid the allocations; does not need to be zeroed, [-]
- Returns
- a_alphafloat
EOS attractive term, [J^2/mol^2/Pa]
- a_alpha_j_rowslist[float]
EOS attractive term row sums, [J^2/mol^2/Pa]
Notes
Tried moving the i=j loop out, no difference in speed, maybe got a bit slower in PyPy.
Examples
>>> kijs = [[0,.083],[0.083,0]] >>> zs = [0.1164203, 0.8835797] >>> a_alphas = [0.2491099357671155, 0.6486495863528039] >>> a_alpha_roots = [i**0.5 for i in a_alphas] >>> a_alpha, a_alpha_j_rows = a_alpha_quadratic_terms(a_alphas, a_alpha_roots, 299.0, zs, kijs) >>> a_alpha, a_alpha_j_rows (0.58562139582, [0.35469988173, 0.61604757237])
- thermo.eos_mix_methods.a_alpha_and_derivatives_quadratic_terms(a_alphas, a_alpha_roots, da_alpha_dTs, d2a_alpha_dT2s, T, zs, kijs, a_alpha_j_rows=None, da_alpha_dT_j_rows=None)[source]¶
Calculates the a_alpha term, and its first two temperature derivatives, for an equation of state along with the vector quantities needed to compute the fugacitie and temperature derivatives of fugacities of the mixture. This routine is efficient in both numba and PyPy.
\[a \alpha = \sum_i \sum_j z_i z_j {(a\alpha)}_{ij} \]\[\frac{\partial (a\alpha)}{\partial T} = \sum_i \sum_j z_i z_j \frac{\partial (a\alpha)_{ij}}{\partial T} \]\[\frac{\partial^2 (a\alpha)}{\partial T^2} = \sum_i \sum_j z_i z_j \frac{\partial^2 (a\alpha)_{ij}}{\partial T^2} \]\[(a\alpha)_{ij} = (1-k_{ij})\sqrt{(a\alpha)_{i}(a\alpha)_{j}} \]\[\frac{\partial (a\alpha)_{ij}}{\partial T} = \frac{\sqrt{\operatorname{a\alpha_{i}}{\left(T \right)} \operatorname{a\alpha_{j}} {\left(T \right)}} \left(1 - k_{ij}\right) \left(\frac{\operatorname{a\alpha_{i}} {\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)}}{2} + \frac{\operatorname{a\alpha_{j}}{\left(T \right)} \frac{d}{d T} \operatorname{ a\alpha_{i}}{\left(T \right)}}{2}\right)}{\operatorname{a\alpha_{i}}{\left(T \right)} \operatorname{a\alpha_{j}}{\left(T \right)}} \]\[\frac{\partial^2 (a\alpha)_{ij}}{\partial T^2} = - \frac{\sqrt{\operatorname{a\alpha_{i}}{\left(T \right)} \operatorname{a\alpha_{j}} {\left(T \right)}} \left(k_{ij} - 1\right) \left(\frac{\left(\operatorname{ a\alpha_{i}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)} + \operatorname{a\alpha_{j}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{i}} {\left(T \right)}\right)^{2}}{4 \operatorname{a\alpha_{i}}{\left(T \right)} \operatorname{a\alpha_{j}}{\left(T \right)}} - \frac{\left(\operatorname{a\alpha_{i}} {\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)} + \operatorname{a\alpha_{j}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{i}}{\left(T \right)}\right) \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)}}{2 \operatorname{a\alpha_{j}} {\left(T \right)}} - \frac{\left(\operatorname{a\alpha_{i}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)} + \operatorname{a\alpha_{j}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{i}}{\left(T \right)}\right) \frac{d}{d T} \operatorname{a\alpha_{i}}{\left(T \right)}}{2 \operatorname{a\alpha_{i}} {\left(T \right)}} + \frac{\operatorname{a\alpha_{i}}{\left(T \right)} \frac{d^{2}}{d T^{2}} \operatorname{a\alpha_{j}}{\left(T \right)}}{2} + \frac{\operatorname{a\alpha_{j}}{\left(T \right)} \frac{d^{2}}{d T^{2}} \operatorname{a\alpha_{i}}{\left(T \right)}}{2} + \frac{d}{d T} \operatorname{a\alpha_{i}}{\left(T \right)} \frac{d}{d T} \operatorname{a\alpha_{j}}{\left(T \right)}\right)} {\operatorname{a\alpha_{i}}{\left(T \right)} \operatorname{a\alpha_{j}} {\left(T \right)}} \]The secondary values are as follows:
\[\sum_i y_i(a\alpha)_{ij} \]\[\sum_i y_i \frac{\partial (a\alpha)_{ij}}{\partial T} \]- Parameters
- a_alphaslist[float]
EOS attractive terms, [J^2/mol^2/Pa]
- a_alpha_rootslist[float]
Square roots of a_alphas; provided for speed [J/mol/Pa^0.5]
- da_alpha_dTslist[float]
Temperature derivative of coefficient calculated by EOS-specific method, [J^2/mol^2/Pa/K]
- d2a_alpha_dT2slist[float]
Second temperature derivative of coefficient calculated by EOS-specific method, [J^2/mol^2/Pa/K**2]
- Tfloat
Temperature, not used, [K]
- zslist[float]
Mole fractions of each species
- kijslist[list[float]]
Constant kijs, [-]
- Returns
- a_alphafloat
EOS attractive term, [J^2/mol^2/Pa]
- da_alpha_dTfloat
Temperature derivative of coefficient calculated by EOS-specific method, [J^2/mol^2/Pa/K]
- d2a_alpha_dT2float
Second temperature derivative of coefficient calculated by EOS-specific method, [J^2/mol^2/Pa/K**2]
- a_alpha_j_rowslist[float]
EOS attractive term row sums, [J^2/mol^2/Pa]
- da_alpha_dT_j_rowslist[float]
Temperature derivative of EOS attractive term row sums, [J^2/mol^2/Pa/K]
Examples
>>> kijs = [[0,.083],[0.083,0]] >>> zs = [0.1164203, 0.8835797] >>> a_alphas = [0.2491099357671155, 0.6486495863528039] >>> a_alpha_roots = [i**0.5 for i in a_alphas] >>> da_alpha_dTs = [-0.0005102028006086241, -0.0011131153520304886] >>> d2a_alpha_dT2s = [1.8651128859234162e-06, 3.884331923127011e-06] >>> a_alpha_and_derivatives_quadratic_terms(a_alphas, a_alpha_roots, da_alpha_dTs, d2a_alpha_dT2s, 299.0, zs, kijs) (0.58562139582, -0.001018667672, 3.56669817856e-06, [0.35469988173, 0.61604757237], [-0.000672387374, -0.001064293501])