Additional Equations of State
General Process
Adding another EOS, or family is straightforward in DESPASITO.
The EOS keyword in initiate_eos() is structured as EOS family and variant separated by a period (e.g. eos_family.eos_variant or saft.gamma_mie).
However, those terms also correspond to the next two layers of respective submodules (Figure 1), as the initiating function uses those terms to locate the EOS class.
Within a given despasito.equations_of_state.eos_family.eos_variant module is the class EosType for each EOS option.
Each EosType references our EosTemplate abstract class to ensure consistency with the other modules.
Here abstract methods ensure it’s compatibility with the thermodynamics and parameter_fitting modules.
This structure requires an additional level of organization where each EOS must be categorized in an EOS family.
Once a new EOS is added, we have included thermodynamic consistency tests, verify_eos(), to ensure accuracy.
Figure 1: The Equations of State module includes an abstract class, EosTemplate from which all EosType classes inherit. Added EOS types are easily discovered by initiate_eos in a factory pattern, represented by the green folders. Similarly, the green color of Aideal signifies that it is a source for a factory pattern of calculating the ideal term. This module is equipped to use compiled modules to decrease computational time, although only selected modules are currently employing this option.
Additional Versions of SAFT
Our interest in SAFT has led us to add another level of organization for its specific use.
As described earlier, SAFT relates non-bonded interactions to macroscopic properties through the Helmholtz free energy.
Contributions to the Helmholtz free energy are segmented into terms.
Often these include the ideal, monomer, chain, and association site contributions, although different SAFT variants may or may not include other terms (e.g. electrostatic and solvation terms [1] or polar terms [2]). An added SAFT sub-class must be added to the function saft_type().
The ideal and association site terms are usually consistent throughout the variants of SAFT, while those variants are distinguished by the particulars of the remaining terms.
Thus, a general SAFT class, despasito.equations_of_state.saft.saft.EosType, handles the ideal and association site terms, and separate, variant specific classes, are imported to provide their specific terms, as illustrated in Figure 1.
Because of the fundamental nature of the ideal term and the occasional variation in its method of calculation, the module, Aideal.py allows a factory pattern to exchange methods.
Additionally, this main SAFT class also handles parameters updates in a generalized manner.
Thus, we removed redundancy on multiple fronts, allowing rapid addition of a SAFT variants.
In the directory despasito.equations_of_state.saft we have included a commented example of a SAFT sub-class to aid in the addition of a new SAFT variant.
[1] Shahriari, R.; Dehghani, M. R. Fluid Phase Equilibria 2018, 463, 128–141. https://doi.org/10.1016/j.fluid.2018.02.006.
[2] Dominik, A.; Chapman, W. G.; Kleiner, M.; Sadowski, G. Ind. Eng. Chem. Res. 2005, 44 (17), 6928–6938. https://doi.org/10.1021/ie050071c.
EOS Class Interface
Adding an EOS family is easily implemented by adding a new directory to the equations_of_state directory. A new EOS is added as a module containing a class named EosType derived from our EOS interface:
- class EosTemplate(beads, bead_library, **kwargs)[source]
Interface used in all EOS object options.
By using this template, all EOS objects are then easily exchanged.
- Parameters:
beads (list[str]) – List of unique bead names used among components
bead_library (dict) – A dictionary where bead names are the keys to access EOS self interaction parameters
cross_library (dict, Optional) – Optional library of bead cross interaction parameters. As many or as few of the desired parameters may be defined for whichever group combinations are desired. The remaining are estimated with mixing rules.
kwargs – Additional keywords from EOS object type
- Variables:
beads (list[str]) – List of unique bead names used among components
bead_library (dict) – A dictionary where bead names are the keys to access EOS self interaction parameters
cross_library (dict) – Library of bead cross interaction parameters. As many or as few of the desired parameters may be defined for whichever group combinations are desired.
parameter_types (list[str]) – This list of parameter names must be defined in an EOS object for parameter fitting
parameter_bound_extreme (dict) – With each parameter names as an entry representing a list with the minimum and maximum feasible parameter value.
number_of_components (int) – Number of components in mixture represented by given EOS object.
- check_bounds(parameter, param_name, bounds)[source]
Generate initial guesses for the parameters to be fit.
- Parameters:
parameter (str) – Parameter to be fit. See EOS documentation for supported parameter names.
param_name (str) – Full parameter string to be fit. See EOS documentation for supported parameter names.
bounds (list) – Upper and lower bound for given parameter type
- Returns:
bounds – A screened and possibly corrected low and a high value for the parameter, param_name
- Return type:
list
- abstract density_max(xi, T, maxpack=0.9)[source]
Estimate the maximum density based on the hard sphere packing fraction.
- Parameters:
xi (list[float]) – Mole fraction of each component
T (float) – Temperature of the system [K]
maxpack (float, Optional, default=0.9) – Maximum packing fraction
- Returns:
max_density – Maximum molar density [mol/m^3]
- Return type:
float
- abstract fugacity_coefficient(P, rho, xi, T)[source]
Compute fugacity coefficient
- Parameters:
P (float) – Pressure of the system [Pa]
rho (float) – Molar density of system [mol/m^3]
T (float) – Temperature of the system [K]
xi (list[float]) – Mole fraction of each component
- Returns:
fugacity_coefficient – \(\mu_i\), Array of fugacity coefficient values for each component
- Return type:
numpy.ndarray
- abstract pressure(rho, T, xi)[source]
Compute pressure given system information
- Parameters:
rho (numpy.ndarray) – Number density of system [mol/m^3]
T (float) – Temperature of the system [K]
xi (list[float]) – Mole fraction of each component
- Returns:
P – Array of pressure values [Pa] associated with each density and so equal in length
- Return type:
numpy.ndarray
- update_parameter(param_name, bead_names, param_value)[source]
Update a single parameter value during parameter fitting process.
- Parameters:
param_name (str) – Parameter to be fit. See EOS documentation for supported parameter names. Cross interaction parameter names should be composed of parameter name and the other bead type, separated by an underscore (e.g. epsilon_CO2).
bead_names (list) – Bead names to be changed. For a self interaction parameter, the length will be 1, for a cross interaction parameter, the length will be two.
param_value (float) – Value of parameter