-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Donwhill] migrate to Downhill.jl * [vtflash] add state to vtflash result * [test vtflash] just work test * [vtflash] add directory for vtflash * [vtflash] nvt gradient and hessian with test * [vtflash] nvthessian! and tests Create a function for calculating hessian only. Add tests for it on 4-component mixture. Update documentation of nvt.jl functions. * [vtflash] moved and renamed pressure gradient function to nvt.jl * [vtflash] add helmholtz energy calculation * [vtflash] Draft of general interface For now, PhysicalState variables are implemented and tested against previous code. Both implementations (general for variables and original) work for now and may be compared. Soon, original version will be deprecated and granted name of FractionState or smth like that. * [vtflash] upd vtflashresult interface * Layout change of mixture to StructVector * [vtflash] rm some commented code * [vtflash] mv documentation for variables constructor from concentration and saturation * [vtflash ratiostate] constructors for RatioState * [flash physical] copying of x to state wrapper in constrain step * [vtflash] kwargs for vt_flash to control optimizator * [vtflash] add errors for constrain step * [vtflash physical] throwing custom errors * [vtflash] update for optimizers tolerances and single phase result * [vtflash physical] upd docstring for script * [vtflash ratio] add gradient, hessian and closures. It works! * [vtflash idealidentity] constructors * [vtflash idealidentity] add gradient, hessian and closures * [test vtflash] add comparing of vtflash for 3 possible internal variables * [vtflash newton] mv * [vtflash ratio] typo * [vtflash newton] Add support of new interface to vt_flash_newton Flash by Newton was tested against bfgs for RatioState for four-component mixture. I faced possible drawbacks of copying in closures like state1x .= x for Newton algo the internal x = convert(..., x_), which gives x === x_ for vector of floats. So, in @debug call there was overwriting in gradient (gprev) call. Somehow it produced mistakes. * [vtflash idealidentity] typo-bug * [vtflash nvt] upd comment * [vtflash newton] force copy to float of init x * [test vt_flash] add vt_flash_newton tests * [test vtflash] tests of states for bfgs and newton based flashes * [vtflash] parametric constructor for state variables * [vtflash] occasionally, this seems type-stable * [vtflash] fix abstractype in field of BrusilovskyEoSMixture * #22 Rm unnecessary type alias definition * Convergence condition on chemical potentials and pressure (#24) * #23 Add convcond to newton optimization * #23 Convergence condition for newton version of vt-flash * #23 Update of convergence criteria * #23 Update conv criteria, now tolerances are same by default, chematol is renamed to chemtol * #23 Change signature of convcond to (x, xpre, y, ypre, g) -> Bool * #23 Deprecate unused simplified version of linesearch * #23 Add convcond for quasinewton vt-flash / Can be used currently only from dev of Downhill * #23 Move convergence closure to vt_flash.jl source * #23 Documentation for vt_flash, vt_flash! and vt_flash_newton * Set version to v0.2.0 * Upd Readme Co-authored-by: Vasily <[email protected]>
- Loading branch information
Showing
21 changed files
with
1,705 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
name = "CubicEoS" | ||
uuid = "0772a1fa-d924-41f2-9f07-889679823dc5" | ||
authors = ["Vasily Pisarev <[email protected]>", "Stepan Zakharov <[email protected]>"] | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
|
||
[deps] | ||
CubicEoSDatabase = "8742253c-1987-415f-b31d-1ec9670d9ed7" | ||
DescentMethods = "f4becde8-b16e-4b5a-8f91-16ef0c22c8bc" | ||
Downhill = "a4c28711-7027-4a57-8564-74545b4697a4" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" | ||
|
||
[compat] | ||
julia = "1.4" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,101 @@ | ||
# CubicEoS.jl | ||
The package implements functions to work with substances and mixtures described by cubic equations of state. | ||
|
||
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) | ||
|
||
CubicEoS.jl implements functions to work with substances and mixtures described by cubic equations of state. This includes | ||
|
||
- Basic thermodynamics: pressure, z-factor, chemical potential etc.; | ||
- Check of NVT stability of single-phase state; | ||
- Phase equilibrium calculation for NVT variables. | ||
|
||
So far, the general cubic equation of state [[Brusilovsky, SPE Reservoir Engineering, February 1992](https://doi.org/10.2118/20180-PA)] is implemented. | ||
|
||
Most of implemented functions | ||
|
||
- are designed in a zero-allocating way, such functions has optional `buf` keyword; | ||
- has a desctructive option `func!`. | ||
|
||
## Installation | ||
|
||
The package registry is **[LammpsToolsRegistry](https://github.com/stepanzh-test-org/LammpsToolsRegistry)**. So, you need to add the registry and then install CubicEoS.jl in a usual Julia-way. | ||
|
||
```julia | ||
]pkg> registry add https://github.com/stepanzh-test-org/LammpsToolsRegistry | ||
pkg> add CubicEoS | ||
``` | ||
|
||
## Brusilovsky equation of state | ||
|
||
To construct an set of parameters for a component, use | ||
Components and mixtures may be constructed either explicitly or by loading. | ||
|
||
A **component** can be defined explicitly | ||
```julia | ||
BrusilovskyEoSComponent(;name="No Name", critical_pressure, critical_temperature, acentric_factor, Omegac, Zc, Psi, molar_mass, carbon_number::Integer) | ||
BrusilovskyEoSComponent(; name="No Name", critical_pressure, critical_temperature, acentric_factor, Omegac, Zc, Psi, molar_mass, carbon_number::Integer) | ||
``` | ||
The values of parameters `Omegac`, `Zc` and `Psi` for hydrocarbons may be found in Brusilovsky's paper (https://doi.org/10.2118/20180-PA). | ||
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). | ||
|
||
The parameters can be loaded from a file (using **CubicEoSDatabase.jl**): | ||
Or, the component can be loaded from a file (using **[CubicEoSDatabase.jl](https://github.com/stepanzh/CubicEoSDatabase.jl)**) | ||
```julia | ||
methane = load(BrusilovskyEoSComponent, name = "methane", physics_db = "martinez.csv", eos_db = "brusilovsky.csv") | ||
methane = CubicEoS.load(BrusilovskyEoSComponent; name="methane"[, custom_databases...]) | ||
``` | ||
|
||
Mixtures are constructed via | ||
A **mixture** is constructed via | ||
|
||
```julia | ||
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. | ||
|
||
The parameters can be loaded from a file (using **CubicEoSDatabase.jl**): | ||
Or can be loaded from a file (using **[CubicEoSDatabase.jl](https://github.com/stepanzh/CubicEoSDatabase.jl)**): | ||
```julia | ||
c1c5 = load(BrusilovskyEoSMixture, names = ["methane", "n-pentane", comp_physics_db = "martinez.csv", comp_eos_db = "brusilovsky.csv", mix_eos_db = "brusilovsky_mix.csv") | ||
c1c5 = CubicEoS.load(BrusilovskyEoSMixture; names=("methane", "n-pentane")[, custom_databases...]) | ||
``` | ||
|
||
## Basic thermodynamics | ||
|
||
To get the pressure of a pure component: | ||
Basic thermodynamics includes pressure, Wilson saturation pressure and z-factor (`compressibility`). | ||
|
||
```julia | ||
pressure(component; nmol, volume, temperature) | ||
pressure(component or mixture, nmol, volume, temperature) | ||
``` | ||
|
||
To get the estimate of the saturation pressure at a given temperature: | ||
```julia | ||
wilson_saturation_pressure(component, RT) | ||
``` | ||
|
||
To get compressibility at given pressure and temperature: | ||
```julia | ||
compressibility(mixture, molar_composition, pressure, RT, phase = 'g' | ||
compressibility(mixture, molar_composition, pressure, RT, phase='g') | ||
``` | ||
|
||
## Phase stability | ||
## Chemical potential | ||
|
||
The packages includes functions for calculating activity coefficient and its Jacobian matrix for a mixture defined by Brusilovsky EoS. | ||
|
||
```julia | ||
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. | ||
|
||
## NVT phase equilibrium | ||
|
||
**Phase stability.** To check if a single-phase state is stable, defined in NVT variables, use | ||
|
||
To check if a single-phase state is stable: | ||
```julia | ||
vt_stability(mix::BrusilovskyEoSMixture, nmol::AbstractVector, volume, RT) | ||
isstable, vtstab_results = vt_stability(mix, nmol, volume, RT) | ||
``` | ||
|
||
**Flash.** To calculate NVT phase equilibrium use | ||
|
||
```julia | ||
# quasi-Newton phase split | ||
flash_result = vt_flash(mix, nmol, volume, RT, StateVariables[; tol, maxiter]) | ||
# Newton phase split | ||
flash_result = vt_flash_newton(mix, nmol, volume, RT, StateVariables[; tol, maxiter]) | ||
``` | ||
|
||
where type `StateVariables` defines an internal variables used at phase split stage in optimization solver (e.g. `CubicEoS.PhysicalState`). Quasi-Newton solver is implemented in **[Downhill.jl](https://github.com/vvpisarev/Downhill.jl)**. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.