Skip to content

Repository files navigation

PVTtool

A MATLAB/Octave toolbox for PVT (Pressure-Volume-Temperature) calculations using cubic equations of state. Supports vapor-liquid equilibrium (VLE), liquid-liquid equilibrium (LLE), phase stability testing, and residual enthalpy calculations for multicomponent mixtures.


Getting Started

% 1. Initialise (adds all subdirectories to path)
PVTinitialize()
% 2. Load components from the built-in database
[comp, flag] = addComponents({'CH4', 'C2H6', 'C10H22'});
% 3. Create a mixture at T = 300 K, P = 5 MPa
mix = addMixture(comp, 300, 5e6);
mix.mole_fraction = [0.60.20.2];
% 4. Configure thermodynamic model (defaults: PR EOS, vdW mixing)
thermo = addThermo();
% 5. Run a stability test
[flag, SL, SV, result] = stabilityTest(mix, thermo);
disp(result.message)
% 6. Run a VLE flash
opts = FlashOptions();
[y, x, V] = vleflash(mix, thermo, opts);
fprintf('Vapor fraction: %.4f\n', V)

Class Reference

All classes are defined in Classes/ and are available after PVTinitialize().

ClassPurposeConstructor
ComponentPure-component thermodynamic propertiesComponent(name, formula, ...) or Component.fromDatabase('CH4')
BIPBinary interaction parameter matricesBIP(n) — initialises all matrices to zero for n components
MixtureMulticomponent mixture at T, PMixture(components, T_K, p_Pa)
ThermoModelEOS + mixing rule + activity model selectionThermoModel() — then override fields
FlashOptionsConvergence settings for flash/stabilityFlashOptions() — then override fields

ThermoModel fields

FieldDefaultOptions
EOS@PREOS@PREOS, @SRKEOS, @PR78EOS
activity_model@NRTL@NRTL, @Wilson, @UNIQUAC, @Margules2
mixingrule11=van der Waals, 2=Huron-Vidal, 3=MHV1, 4=MHV2
phase11=liquid Z-root, 2=vapor Z-root
fugacity_switch11=compute fugacity, 0=skip

FlashOptions fields

FieldDefaultDescription
accuracy1e-7Convergence tolerance for VLE/LLE flash
iteration100Maximum successive substitution iterations
trivialSolutionMaxError1e-5Stability test trivial solution threshold
convergenceMaxError1e-10Stability test convergence threshold
maxIteration50Maximum stability test iterations

Setting Binary Interaction Parameters

The Mixture constructor creates a fully-initialised BIP object with all matrices set to zero. Set non-zero parameters by assigning individual fields:

mix = addMixture(comp, T, p);
% EOS kij parameters
mix.bip.EOScons = [0-0.05; -0.050];
% NRTL parameters (A + B*T + C*T² + D/T + E*ln(T))
mix.bip.NRTLcons = [0A12; A210]; % [J/mol]
mix.bip.NRTLtdep = [0B12; B210];
mix.bip.NRTLalfa = [00.3; 0.30]; % non-randomness

All BIP fields: EOScons, EOStdep, NRTLcons, NRTLtdep, NRTLtdep2, NRTLtdepm1, NRTLtdeplog, NRTLalfa, Wilsoncons, Wilsontdep, UNIQUACcons, UNIQUACtdep, UNIQUACR, UNIQUACQ.


API Reference

Flash functions

FunctionDescription
vleflash(mix, thermo, opts)VLE flash, vapor fraction ∈ [0, 1]; GDEM acceleration
vleflashnegative(mix, thermo, opts)VLE flash, extended vapor fraction (negative saturation)
lleflash(mix, thermo, opts)LLE flash (two liquid phases)
bubblePressure(mix, thermo, opts)Bubble-point pressure at fixed T; returns (P_bub, y, flag)
bubbleTemperature(mix, thermo, opts)Bubble-point temperature at fixed P; returns (T_bub, y, flag)
dewPressure(mix, thermo, opts)Dew-point pressure at fixed T; returns (P_dew, x, flag)
dewTemperature(mix, thermo, opts)Dew-point temperature at fixed P; returns (T_dew, x, flag)

Stability tests

FunctionDescription
stabilityTest(mix, thermo)Michelsen VLE stability test; returns (flag, SL, SV, result)
stabilityLLETest(mix, thermo)Michelsen LLE stability test; returns (flag, SL, SV, result)

stability_flag values: 1 = stable (trivial), 2 = unstable (non-trivial), 3 = inconclusive.
result.overall: 'stable' | 'unstable' | 'inconclusive'.

EOS functions

Basic signature: [liquid_z, vapor_z, fugacity, HR] = EOS(mixture, thermo)
Extended signature (5th output): [..., props] = EOS(mixture, thermo) where props contains HR, SR, GR, VR, Cp_R, Cv_R.

FunctionDescription
PREOSPeng-Robinson (1976)
SRKEOSSoave-Redlich-Kwong (1972)
PR78EOSPeng-Robinson with 1978 alpha correction (better for ω > 0.491)

Residual properties (from the optional props struct):

PropertyUnitsDescription
props.HRJ/molResidual enthalpy
props.SRJ/(mol·K)Residual entropy
props.GRJ/molResidual Gibbs energy
props.VRm³/molResidual molar volume = RT(Z-1)/P
props.Cp_RJ/(mol·K)Residual isobaric heat capacity
props.Cv_RJ/(mol·K)Residual isochoric heat capacity

Activity models

All share the signature [gErt, gama] = Model(T, x, component, bip).

FunctionDescription
NRTLNon-Random Two-Liquid
WilsonWilson model
UNIQUACUniversal Quasi-Chemical
Margules2Two-parameter Margules

Mixing rules

NumberNameNotes
1van der WaalsNo activity model needed
2Huron-Vidal (HV)Requires activity model
3Modified HV-1 (MHV1)Requires activity model
4Modified HV-2 (MHV2)Requires activity model

Convenience functions (Tools/)

FunctionDescription
addComponents(names)Load Component array from database
addMixture(comp, T, p)Create Mixture (wraps Mixture())
addThermo()Create ThermoModel with defaults (wraps ThermoModel())
zeroBIP(comp)Create zero BIP (wraps BIP(n))

Examples

All examples are in the Examples/ folder and can be run after PVTinitialize().

FileSystemCalculation
methanol_water_vle.mCH₃OH + H₂O at 322.91 KVLE flash vs experimental data
testcase2.mCH₄ to C₁₅H₃₂ (6 components)Multi-component VLE
testcase3.mDME + H₂O + C₁₀H₂₂LLE flash + stability test
pure_component_density.mH₂OLiquid/vapor molar volume vs steam tables
bubbledewtest.mBinary mixtureBubble/dew point via fzero
blackoilmodel.mBlack-oil systemBlack-oil thermodynamic model

Tests

Run the test suite from the project root:

PVTinitialize()
cdTestsrun_all_tests

Tests cover: class construction, EOS Z-factors and residual properties, VLE flash vs experimental data, stability test stable/unstable cases, and bubble/dew point calculations.


Octave Compatibility

Tested with Octave 7+. All classes use value semantics (no handle). No MATLAB-only toolboxes are required.


License

BSD 2-Clause — see source file headers.
Copyright © 2012–2013 Ali Akbar Eftekhari.

Releases

Packages

Contributors

Languages