CubicEoS.jl is an extensible package for thermodynamic calculations. The package defines an abstract interface needed to implement an equation of state (EoS) and uses it to calculate NVT phase equilibrium.
As an example of EoS, the package implements the general cubic equation of state [Brusilovsky, SPE Reservoir Engineering, February 1992]. To implement an EoS you need, use src/BrusilovskyEoS
submodule as a template.
TODO: add links to other extensions: CPPCSAFT and MBWREoS.
What CubicEoS.jl do provide?
- Interface needed to solve NVT phase equilibrium problem;
- NVT solvers: phase stability and phase split which
- Support automatic differentation;
- Based on optimization: currently uses Cholesky BFGS with control of step from Downhill.jl;
- Provide choice of internal variables for better scaling of a problem;
- Implementation of the general equation of state.
Most of implemented functions
- are designed in a zero-allocating way, such functions has optional
buf
keyword; - has a desctructive option
func!
.
The package registry is LammpsToolsRegistry. So, you need to add the registry and then install CubicEoS.jl in a usual Julia-way.
]pkg> registry add https://github.com/stepanzh-test-org/LammpsToolsRegistry
pkg> add CubicEoS
Currently, only docstrings are provided. You may also take a look at tests with minimal working examples.
Components and mixtures may be constructed either explicitly or by loading.
A component can be defined explicitly
BrusilovskyEoSComponent(; name="No Name", critical_pressure, critical_temperature, acentric_factor, Omegac, Zc, Psi, molar_mass, carbon_number::Integer)
where the values of parameters Omegac
, Zc
and Psi
may be found in Brusilovsky's paper (https://doi.org/10.2118/20180-PA).
The temperatures must be in absolute scale (e.g., in Kelvins).
Or, the component can be loaded from a file (using CubicEoSDatabase.jl)
methane = CubicEoS.load(BrusilovskyEoSComponent; name="methane"[, custom_databases...])
A mixture is constructed via
BrusilovskyEoSMixture(; components::AbstractVector{<:BrusilovskyEoSComponent}, constant, linear, quadratic)
where constant
, linear
and quadratic
are matrices of constant, linear and quadratic in temperature terms for Zudkevitch-Joffe corrections.
Or can be loaded from a file (using CubicEoSDatabase.jl):
c1c5 = CubicEoS.load(BrusilovskyEoSMixture; names=("methane", "n-pentane")[, custom_databases...])
Basic thermodynamics includes pressure, Wilson saturation pressure and z-factor (compressibility
).
pressure(component or mixture, nmol, volume, temperature)
wilson_saturation_pressure(component, RT)
compressibility(mixture, nmol, pressure, RT, phase='g')
The packages includes functions for calculating activity coefficient and its Jacobian matrix for a mixture defined by Brusilovsky EoS.
log_ca = log_c_activity(mixture, nmol, volume, RT)
log_ca, jac = log_c_activity_wj(mixture, nmol, volume, RT)
In case of a component you may use a mixture of one component.
Phase stability. To check if a single-phase state is stable, defined in NVT variables, use
issuccess, isstable, results = vt_stability(mix, nmol, volume, RT, StateVariables)
Phase split. To calculate NVT phase equilibrium use
result = vt_split(mix, nmol, volume, RT, trial_concentration, StateVariables)
where type StateVariables
defines an internal variables used at phase split stage in optimization solver (e.g. CubicEoS.PhysicalState
). For the split trial_concentration
is given from results of the stability.
There are several options to control behavior of the solvers. Check docstrings of vt_stability
and vt_split
for overview.
Currently, to implement an EoS you need, use src/BrusilovskyEoS
submodule as a template (check functions that add methods to the main module, e.g. CubicEoS.pressure
).
Briefly speaking, the interface can be divided into servicing and physical categories. The servicing interface mostly requires getter-like functions. The physical interface requires minimal set of functions to compute pressure, activity coefficients and constraints on phases introducing by an EoS.
Currently, there are several EoS under development:
TODO: add links to other extensions: CPPCSAFT and MBWREoS.