Activity Coefficients (thermo.activity)¶
This module contains a base class GibbsExcess
for handling activity
coefficient based
models. The design is for a sub-class to provide the minimum possible number of
derivatives of Gibbs energy, and for this base class to provide the rest of the
methods. An ideal-liquid class with no excess Gibbs energy
IdealSolution
is also available.
For reporting bugs, adding feature requests, or submitting pull requests, please use the GitHub issue tracker.
Base Class¶
- class thermo.activity.GibbsExcess[source]¶
Bases:
object
Class for representing an activity coefficient model. While these are typically presented as tools to compute activity coefficients, in truth they are excess Gibbs energy models and activity coefficients are just one derived aspect of them.
This class does not implement any activity coefficient models itself; it must be subclassed by another model. All properties are derived with the CAS SymPy, not relying on any derivations previously published, and checked numerically for consistency.
Different subclasses have different parameter requirements for initialization;
IdealSolution
is available as a simplest model with activity coefficients of 1 to show what needs to be implemented in subclasses. It is also intended subclasses implement the method to_T_xs, which creates a new object at the specified temperature and composition but with the same parameters.These objects are intended to lazy-calculate properties as much as possible, and for the temperature and composition of an object to be immutable.
- Attributes
- N
- T
- scalar
- xs
Methods
CpE
()Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.
HE
()Calculate and return the excess entropy of a liquid phase using an activity coefficient model.
SE
()Calculates the excess entropy of a liquid phase using an activity coefficient model.
as_json
()Method to create a JSON-friendly representation of the Gibbs Excess model which can be stored, and reloaded later.
Calculate and return the mole number derivative of the first temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
Calculate and return the partial mole number derivative of the first temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
Calculate and return the second partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
dGE_dns
()Calculate and return the mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
dHE_dT
()Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.
dHE_dns
()Calculate and return the mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.
dHE_dxs
()Calculate and return the mole fraction derivative of excess enthalpy of a liquid phase using an activity coefficient model.
dSE_dT
()Calculate and return the first temperature derivative of excess entropy of a liquid phase using an activity coefficient model.
dSE_dns
()Calculate and return the mole number derivative of excess entropy of a liquid phase using an activity coefficient model.
dSE_dxs
()Calculate and return the mole fraction derivative of excess entropy of a liquid phase using an activity coefficient model.
Calculate and return the temperature derivatives of activity coefficients of a liquid phase using an activity coefficient model.
Calculate and return the mole number derivative of activity coefficients of a liquid phase using an activity coefficient model.
dnGE_dns
()Calculate and return the partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
dnHE_dns
()Calculate and return the partial mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.
dnSE_dns
()Calculate and return the partial mole number derivative of excess entropy of a liquid phase using an activity coefficient model.
from_json
(json_repr)Method to create a Gibbs Excess model from a JSON-friendly serialization of another Gibbs Excess model.
gammas
()Calculate and return the activity coefficients of a liquid phase using an activity coefficient model.
Calculate and return the infinite dilution activity coefficients of each component.
Basic method to calculate a hash of the non-state parts of the model This is useful for comparing to models to determine if they are the same, i.e. in a VLL flash it is important to know if both liquids have the same model.
Basic method to calculate a hash of the state of the model and its model parameters.
- CpE()¶
Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.
$\frac{\partial h^E}{\partial T} = -T \frac{\partial^2 g^E} {\partial T^2}$- Returns
- dHE_dT
float
First temperature derivative of excess enthalpy of the liquid phase, [J/mol/K]
- dHE_dT
- HE()[source]¶
Calculate and return the excess entropy of a liquid phase using an activity coefficient model.
$h^E = -T \frac{\partial g^E}{\partial T} + g^E$- Returns
- HE
float
Excess enthalpy of the liquid phase, [J/mol]
- HE
- N¶
- SE()[source]¶
Calculates the excess entropy of a liquid phase using an activity coefficient model.
$s^E = \frac{h^E - g^E}{T}$- Returns
- SE
float
Excess entropy of the liquid phase, [J/mol/K]
- SE
Notes
Note also the relationship of the expressions for partial excess entropy:
$S_i^E = -R\left(T \frac{\partial \ln \gamma_i}{\partial T} + \ln \gamma_i\right)$
- T¶
- __hash__()[source]¶
Method to calculate and return a hash representing the exact state of the object. This includes T, xs, the model class, and which values have already been calculated.
- Returns
- hash
int
Hash of the object, [-]
- hash
- __repr__()[source]¶
Method to create a string representation of the state of the model. Included is T, xs, and all constants necessary to create the model. This can be passed into
exec
to re-create the model. Note that parsing strings like this can be slow.- Returns
- repr
str
String representation of the object, [-]
- repr
Examples
>>> IdealSolution(T=300.0, xs=[.1, .2, .3, .4]) IdealSolution(T=300.0, xs=[.1, .2, .3, .4])
- as_json()[source]¶
Method to create a JSON-friendly representation of the Gibbs Excess model which can be stored, and reloaded later.
- Returns
- json_repr
dict
JSON-friendly representation, [-]
- json_repr
Examples
>>> import json >>> model = IdealSolution(T=300.0, xs=[.1, .2, .3, .4]) >>> json_view = model.as_json() >>> json_str = json.dumps(json_view) >>> assert type(json_str) is str >>> model_copy = IdealSolution.from_json(json.loads(json_str)) >>> assert model_copy == model
- d2GE_dTdns()[source]¶
Calculate and return the mole number derivative of the first temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
$\frac{\partial^2 G^E}{\partial n_i \partial T}$
- d2nGE_dTdns()[source]¶
Calculate and return the partial mole number derivative of the first temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
$\frac{\partial^2 n G^E}{\partial n_i \partial T}$
- d2nGE_dninjs()[source]¶
Calculate and return the second partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
$\frac{\partial^2 n G^E}{\partial n_i \partial n_i}$
- dGE_dns()[source]¶
Calculate and return the mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
$\frac{\partial G^E}{\partial n_i}$
- dHE_dT()[source]¶
Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.
$\frac{\partial h^E}{\partial T} = -T \frac{\partial^2 g^E} {\partial T^2}$- Returns
- dHE_dT
float
First temperature derivative of excess enthalpy of the liquid phase, [J/mol/K]
- dHE_dT
- dHE_dns()[source]¶
Calculate and return the mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.
$\frac{\partial h^E}{\partial n_i}$
- dHE_dxs()[source]¶
Calculate and return the mole fraction derivative of excess enthalpy of a liquid phase using an activity coefficient model.
$\frac{\partial h^E}{\partial x_i} = -T \frac{\partial^2 g^E} {\partial T \partial x_i} + \frac{\partial g^E}{\partial x_i}$
- dSE_dT()[source]¶
Calculate and return the first temperature derivative of excess entropy of a liquid phase using an activity coefficient model.
$\frac{\partial s^E}{\partial T} = \frac{1}{T} \left(\frac{-\partial g^E}{\partial T} + \frac{\partial h^E}{\partial T} - \frac{(G + H)}{T}\right)$- Returns
- dSE_dT
float
First temperature derivative of excess entropy of the liquid phase, [J/mol/K]
- dSE_dT
- dSE_dns()[source]¶
Calculate and return the mole number derivative of excess entropy of a liquid phase using an activity coefficient model.
$\frac{\partial S^E}{\partial n_i}$
- dSE_dxs()[source]¶
Calculate and return the mole fraction derivative of excess entropy of a liquid phase using an activity coefficient model.
$\frac{\partial S^E}{\partial x_i} = \frac{1}{T}\left( \frac{\partial h^E} {\partial x_i} - \frac{\partial g^E}{\partial x_i}\right) = -\frac{\partial^2 g^E}{\partial x_i \partial T}$
- dgammas_dT()[source]¶
Calculate and return the temperature derivatives of activity coefficients of a liquid phase using an activity coefficient model.
$\frac{\partial \gamma_i}{\partial T} = \left(\frac{\frac{\partial^2 n G^E}{\partial T \partial n_i}}{RT} - \frac{{\frac{\partial n_i G^E}{\partial n_i }}}{RT^2}\right) \exp\left(\frac{\frac{\partial n_i G^E}{\partial n_i }}{RT}\right)$
- dgammas_dns()[source]¶
Calculate and return the mole number derivative of activity coefficients of a liquid phase using an activity coefficient model.
$\frac{\partial \gamma_i}{\partial n_i} = \gamma_i \left(\frac{\frac{\partial^2 G^E}{\partial x_i \partial x_j}}{RT}\right)$
- dnGE_dns()[source]¶
Calculate and return the partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
$\frac{\partial n G^E}{\partial n_i}$
- dnHE_dns()[source]¶
Calculate and return the partial mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.
$\frac{\partial n h^E}{\partial n_i}$
- dnSE_dns()[source]¶
Calculate and return the partial mole number derivative of excess entropy of a liquid phase using an activity coefficient model.
$\frac{\partial n S^E}{\partial n_i}$
- classmethod from_json(json_repr)[source]¶
Method to create a Gibbs Excess model from a JSON-friendly serialization of another Gibbs Excess model.
- Parameters
- json_repr
dict
JSON-friendly representation, [-]
- json_repr
- Returns
- model
GibbsExcess
Newly created object from the json serialization, [-]
- model
Notes
It is important that the input string be in the same format as that created by
GibbsExcess.as_json
.Examples
>>> model = IdealSolution(T=300.0, xs=[.1, .2, .3, .4]) >>> json_view = model.as_json() >>> new_model = IdealSolution.from_json(json_view) >>> assert model == new_model
- gammas()[source]¶
Calculate and return the activity coefficients of a liquid phase using an activity coefficient model.
$\gamma_i = \exp\left(\frac{\frac{\partial n_i G^E}{\partial n_i }}{RT}\right)$
- gammas_infinite_dilution()[source]¶
Calculate and return the infinite dilution activity coefficients of each component.
Notes
The algorithm is as follows. For each component, set its composition to zero. Normalize the remaining compositions to 1. Create a new object with that composition, and calculate the activity coefficient of the component whose concentration was set to zero.
- model_hash()[source]¶
Basic method to calculate a hash of the non-state parts of the model This is useful for comparing to models to determine if they are the same, i.e. in a VLL flash it is important to know if both liquids have the same model.
Note that the hashes should only be compared on the same system running in the same process!
- Returns
- model_hash
int
Hash of the object’s model parameters, [-]
- model_hash
- scalar¶
- state_hash()[source]¶
Basic method to calculate a hash of the state of the model and its model parameters.
Note that the hashes should only be compared on the same system running in the same process!
- Returns
- state_hash
int
Hash of the object’s model parameters and state, [-]
- state_hash
- xs¶
Ideal Liquid Class¶
- class thermo.activity.IdealSolution(T=None, xs=None)[source]¶
Bases:
thermo.activity.GibbsExcess
Class for representing an ideal liquid, with no excess gibbs energy and thus activity coefficients of 1.
Examples
>>> model = IdealSolution(T=300.0, xs=[.1, .2, .3, .4]) >>> model.GE() 0.0 >>> model.gammas() [1.0, 1.0, 1.0, 1.0] >>> model.dgammas_dT() [0.0, 0.0, 0.0, 0.0]
Methods
GE
()Calculate and return the excess Gibbs energy of a liquid phase using an activity coefficient model.
d2GE_dT2
()Calculate and return the second temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
Calculate and return the temperature derivative of mole fraction derivatives of excess Gibbs energy of an ideal liquid.
Calculate and return the second mole fraction derivatives of excess Gibbs energy of an ideal liquid.
d3GE_dT3
()Calculate and return the third temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
Calculate and return the third mole fraction derivatives of excess Gibbs energy of an ideal liquid.
dGE_dT
()Calculate and return the temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
dGE_dxs
()Calculate and return the mole fraction derivatives of excess Gibbs energy of an ideal liquid.
to_T_xs
(T, xs)Method to construct a new
IdealSolution
instance at temperature T, and mole fractions xs with the same parameters as the existing object.- GE()[source]¶
Calculate and return the excess Gibbs energy of a liquid phase using an activity coefficient model.
$g^E = 0$- Returns
- GE
float
Excess Gibbs energy of an ideal liquid, [J/mol]
- GE
- d2GE_dT2()[source]¶
Calculate and return the second temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
$\frac{\partial^2 g^E}{\partial T^2} = 0$- Returns
- d2GE_dT2
float
Second temperature derivative of excess Gibbs energy of an ideal liquid, [J/(mol*K^2)]
- d2GE_dT2
- d2GE_dTdxs()[source]¶
Calculate and return the temperature derivative of mole fraction derivatives of excess Gibbs energy of an ideal liquid.
$\frac{\partial^2 g^E}{\partial x_i \partial T} = 0$
- d2GE_dxixjs()[source]¶
Calculate and return the second mole fraction derivatives of excess Gibbs energy of an ideal liquid.
$\frac{\partial^2 g^E}{\partial x_i \partial x_j} = 0$
- d3GE_dT3()[source]¶
Calculate and return the third temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
$\frac{\partial^3 g^E}{\partial T^3} = 0$- Returns
- d3GE_dT3
float
Third temperature derivative of excess Gibbs energy of an ideal liquid, [J/(mol*K^3)]
- d3GE_dT3
- d3GE_dxixjxks()[source]¶
Calculate and return the third mole fraction derivatives of excess Gibbs energy of an ideal liquid.
$\frac{\partial^3 g^E}{\partial x_i \partial x_j \partial x_k} = 0$
- dGE_dT()[source]¶
Calculate and return the temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
$\frac{\partial g^E}{\partial T} = 0$- Returns
- dGE_dT
float
First temperature derivative of excess Gibbs energy of an ideal liquid, [J/(mol*K)]
- dGE_dT
- dGE_dxs()[source]¶
Calculate and return the mole fraction derivatives of excess Gibbs energy of an ideal liquid.
$\frac{\partial g^E}{\partial x_i} = 0$
- to_T_xs(T, xs)[source]¶
Method to construct a new
IdealSolution
instance at temperature T, and mole fractions xs with the same parameters as the existing object.- Parameters
- Returns
- obj
IdealSolution
New
IdealSolution
object at the specified conditions [-]
- obj
Examples
>>> p = IdealSolution(T=300.0, xs=[.1, .2, .3, .4]) >>> p.to_T_xs(T=500.0, xs=[.25, .25, .25, .25]) IdealSolution(T=500.0, xs=[0.25, 0.25, 0.25, 0.25])
Notes¶
References¶
- 1
Walas, Stanley M. Phase Equilibria in Chemical Engineering. Butterworth-Heinemann, 1985.
- 2
Gmehling, Jurgen. Chemical Thermodynamics: For Process Simulation. Weinheim, Germany: Wiley-VCH, 2012.