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
- vectorized
- 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
([cache, option])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.
Calculate and return the temperature derivatives of the natural logarithm 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.
Method to calculate and return a hash representing the exact state of the object.
from_json
(json_repr[, cache])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.
lngammas
()Calculate and return the natural logarithm of the activity coefficients of a liquid phase using an activity coefficient model.
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.
d3GE_dT2dxs_numerical
d3GE_dTdxixjs_numerical
d4GE_dT2dxixjs_numerical
d4GE_dT3dxs_numerical
d4GE_dT4_numerical
d5GE_dT3dxixjs_numerical
gammas_dGE_dxs
gammas_numerical
- CpE()¶
Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.
- 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.
- 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.
- 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:
- T¶
- T_DEFAULT = 298.15¶
- __hash__()¶
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
- __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(cache=None, option=0)[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.
- 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.
- 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.
- d3GE_dT2dxs_numerical(derive_attr='d2GE_dT2')¶
- d3GE_dTdxixjs_numerical(derive_attr='dGE_dT')¶
- d4GE_dT2dxixjs_numerical(derive_attr='d2GE_dT2')¶
- d4GE_dT3dxs_numerical(derive_attr='d3GE_dT3')¶
- d4GE_dT4_numerical(derive_attr='GE', n=4)¶
- d5GE_dT3dxixjs_numerical(derive_attr='d3GE_dT3')¶
- dGE_dns()[source]¶
Calculate and return the mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
- dHE_dT()[source]¶
Calculate and return the first temperature derivative of excess enthalpy of a liquid phase using an activity coefficient model.
- 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.
- dHE_dxs()[source]¶
Calculate and return the mole fraction derivative of excess enthalpy of a liquid phase using an activity coefficient model.
- dSE_dT()[source]¶
Calculate and return the first temperature derivative of excess entropy of a liquid phase using an activity coefficient model.
- 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.
- dSE_dxs()[source]¶
Calculate and return the mole fraction derivative of excess entropy of a liquid phase using an activity coefficient model.
- dgammas_dT()[source]¶
Calculate and return the temperature derivatives of activity coefficients of a liquid phase using an activity coefficient model.
- dgammas_dns()[source]¶
Calculate and return the mole number derivative of activity coefficients of a liquid phase using an activity coefficient model.
- dlngammas_dT()[source]¶
Calculate and return the temperature derivatives of the natural logarithm of activity coefficients of a liquid phase using an activity coefficient model.
- Returns
Notes
This method uses the chain rule to calculate the temperature derivative of log activity coefficients.
- dnGE_dns()[source]¶
Calculate and return the partial mole number derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
- dnHE_dns()[source]¶
Calculate and return the partial mole number derivative of excess enthalpy of a liquid phase using an activity coefficient model.
- dnSE_dns()[source]¶
Calculate and return the partial mole number derivative of excess entropy of a liquid phase using an activity coefficient model.
- exact_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
- classmethod from_json(json_repr, cache=None)[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.
- 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.
- json_version = 1¶
- lngammas()[source]¶
Calculate and return the natural logarithm of the activity coefficients of a liquid phase using an activity coefficient model.
- 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
- non_json_attributes = ['_model_hash']¶
- obj_references = []¶
- recalculable_attributes = ('_GE', '_dGE_dT', '_SE', '_d2GE_dT2', '_d2GE_dTdxs', '_dGE_dxs', '_gammas', '_dgammas_dns', '_dgammas_dT', '_d2GE_dxixjs', '_dHE_dxs', '_dSE_dxs')¶
- 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
- vectorized¶
- xs¶
Ideal Liquid Class¶
- class thermo.activity.IdealSolution(*, xs, T=298.15)[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.
- 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.
- 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.
- d2GE_dxixjs()[source]¶
Calculate and return the second mole fraction derivatives of excess Gibbs energy of an ideal liquid.
- d3GE_dT3()[source]¶
Calculate and return the third temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
- 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.
- dGE_dT()[source]¶
Calculate and return the temperature derivative of excess Gibbs energy of a liquid phase using an activity coefficient model.
- 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.
- 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.