Contents

Index

Flash methods

Quick summary of available flash methods

In the following table:

  • P,T represent pressure and temperature.
  • X,Y represent any arbitrary specification (enthalpy, volume, internal energy, etc).
  • Q represents the (molar) vapour fraction. Q = 1 is the specification of the dew point, Q = 0 corresponds to the bubble point.
Method NameFlash Typemaximum phasesDerivative OrderActivity ModelsElectrolyte ModelsNotes
RRTPFlashP-T2 (VLE,LLE)First orderNo (cubic EoS)YesRachford-Rice (RR) Flash
MichelsenTPFlashP-T2 (VLE,LLE)Second order¹YesNoRR + Gibbs optimization
MultiPhaseTPFlashP-Tany (automatic phase detection, incl. solids³)Second orderYesNoRR + Gibbs optimization + phase search
DETPFlashP-Tany (via numphases)Zeroth OrderYesNoGlobal Gibbs optimization over fixed phases
CEMFlashP-Tany (automatic phase detection, incl. solids³)Zeroth Order (polished: same as polish)YesNoConvex envelope of the discretized Gibbs energy (+ local refinement)
GeneralizedXYFlashX-Y2² (VLE/LLE)Second OrderNoNoEquilibria conditions as constrained non-linear system
RRQXFlashQ-T,Q-P2First OrderYesNoRR update + Root-finding of Q(p)/Q(T)
RRXYFlashP-Y,T-Y2 (VLE/LLE)First OrderYesNoRR iterations + Root-finding on Y(T)/Y(p)
MCFlashJLP-T2 (VLE)Second orderNoNoMultiComponentFlash.jl extension

Notes:

  1. MichelsenTPFlash can switch how it can solve the gibbs optimization problem via the second_order::Bool keyword, from L-BFGS (first order method) to Newton (second order Newton) By default, MichelsenTPFlash uses a first order gibbs optimization solver.

  2. GeneralizedXYFlash is a wrapper to the xy_flash method. While xy_flash can solve an arbitrary, multiphase, X-Y flash problem, `Clapeyron.jl is only capable at the moment of generating 2-phase initial points for some combinations of specifications.

  3. MichelsenTPFlash and RRTPFlash will always return a result with two phases, the phase with zero phase fraction carry information about the converged K value.

  4. Solid phases are considered for a CompositeModel with a solid model. They are stored after the fluid phases, result.data.solid_idx is the index of the first solid phase and Clapeyron.is_solid(result,i) checks a phase. MultiPhaseTPFlash requires at least one fluid phase in equilibrium. See Phase Diagrams with the Convex Envelope Method.

The default flash methods are the following:

  • Helmholtz models: MichelsenTPFlash (P-T), GeneralizedXYFlash (X-Y)
  • Activity Models/Composite models: MichelsenTPFlash (P-T), RRQXFlash (Q-T,Q-P), RRXYFlash (P-Y,T-Y)
  • Electrolyte Models: RRTPFlash (P-T)

Flash API

Clapeyron.supports_reduction — Function
supports_reduction(method::FlashMethod)::Bool

Checks if a Flash method supports index reduction (the ability to prune model components with compositions lower than a threshold). All current Clapeyron.jl methods support index reduction, but some methods that alllow passing a cache could have problems.

source
Clapeyron.FlashResult — Type
FlashResult(compositions,fractions,volumes,data::FlashData)
FlashResult(model,p,T,z,compositions,fractions,volumes,g = nothing;sort = true)
FlashResult(model,p,T,compositions,fractions,volumes,g = nothing;sort = true)
FlashResult(model,p,T,z;phase = :unknown)
FlashResult(p,T,z,compositions,fractions,volumes,g = nothing;sort = true)
FlashResult(p,T,compositions,fractions,volumes,g = nothing;sort = true)
FlashResult(flash::FlashResult,g = nothing;sort = true)

Structure used to contain the result of a flash. Contains a list of molar compositions, a list of molar amounts per phase, a list of molar volumes and an auxiliary struct, FlashData, containing the pressure, temperature and reduced Gibbs energy. When an EoSModel is used as an input for a FlashResult, the reduced molar Gibbs energy (g = g/NRT) is calculated, if not provided. By default, the phases are sorted by volume, this can be changed by passing the keyword argument sort = false FlashResult(model,p,T,z;phase) constructs a single phase FlashResult. If the bulk composition z is provided, it will be used to scale the fractions, forcing sum(fractions) == sum(z)

source
Clapeyron.FlashData — Type
FlashData

Auxiliary struct that contains information about the current FlashResult object. It stores the pressure, temperature and reduced Gibbs energy (g = G/nRT), the index of the vapour phase (vapour_idx, 0 if not identified, -1 if there is no vapour phase) and the index of the first solid phase (solid_idx, 0 if not identified, -1 if there is no solid phase). Solid phases are stored after the fluid phases.

source
Clapeyron.FlashSpecifications — Type
FlashSpecifications(;v,T,p,h,s,u,q)

Struct that holds two specifications for a general flash. The keyword arguments have the following meaning:

  • T: temperature [K]
  • v: total volume [m³]
  • p: pressure [Pa]
  • h: enthalpy [J]
  • s: entropy [J·K⁻¹]
  • u: internal energy [J]
  • q: vapour fraction

Examples:

specs = FlashSpecifications(p = 101325,T = 298.15) #PT flash
specs = FlashSpecifications(Clapeyron.pressure,101325,Clapeyron.temperature,298.15) #equivalent
source
Clapeyron.numphases — Function
numphases(method::FlashMethod)

Return the number of phases supported by a flash method. By default it is set to 2. If the method allows it, you can set the number of phases by doing method(;numphases = n).

source
Clapeyron.is_active_phase — Function
is_active_phase(result::FlashResult,i)::Bool

Returns a boolean indicating if the phase stored in Result is "active". An active phase is defined as:

  • A non-negative volume (some Activity models use zero liquid volume),
  • A valid composition (at least one positive phase)
  • A positive fraction.
  • Nonnegative and finite temperatures and pressures.

A single-phase sucessful flash will have one active phase and zero or more inactive phases. The function Clapeyron.eachactivephase_index returns an iterator of all active phase indices. Inactive phases can still carry relevant information; for example, in a QP flash where Q is 0 (bubble point), the inactive phase stores the gas composition and volume.

source

Flash functions

Note

For legacy reasons, the return type of tp_flash does not return a FlashResult. If you want to get a consistent return type for P-T flash, call Clapeyron.tp_flash2 instead.

Clapeyron.tp_flash — Function
tp_flash(model, p, T, n, method::TPFlashMethod = DETPFlash())

Routine to solve non-reactive multicomponent flash problem. The default method tries to find all phases. See MultiPhaseTPFlash

Inputs:

  • T, Temperature [K]
  • p, Pressure [Pa]
  • n, vector of number of moles of each species [mol]

Outputs - Tuple containing:

  • xᵢⱼ, Array of mole fractions of species j in phase i
  • nᵢⱼ, Array of mole numbers of species j in phase i, [mol]
  • G, Gibbs energy of Equilibrium Mixture [J]
source
Clapeyron.tp_flash2 — Function
result = tp_flash2(model, p, s, n, method::FlashMethod = GeneralizedXYFlash())
result = tp_flash2(model, p, s, n; kwargs...)

Routine to solve non-reactive two-phase multicomponent flash problem. With P-T specifications. The default method tries to find all phases. See MultiPhaseTPFlash

Inputs:

  • p, pressure [Pa]
  • T, temperature [K]
  • n, vector of number of moles of each species [mol]

Outputs:

  • result, a FlashResult struct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
source
Clapeyron.ph_flash — Function
result = ph_flash(model, p, h, n, method::FlashMethod = GeneralizedXYFlash())
result = ph_flash(model, p, h, n; kwargs...)

Routine to solve non-reactive two-phase multicomponent flash problem. With P-H specifications. Wrapper around Clapeyron.xy_flash, with automatic initial point calculations.

Inputs:

  • p, pressure [Pa]
  • h, enthalpy [J]
  • n, vector of number of moles of each species [mol]

All keyword arguments are forwarded to GeneralizedXYFlash.

Outputs:

  • result, a FlashResult struct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
source
Clapeyron.ps_flash — Function
result = ps_flash(model, p, s, n, method::FlashMethod = GeneralizedXYFlash())
result = ps_flash(model, p, s, n; kwargs...)

Routine to solve non-reactive two-phase multicomponent flash problem. With P-S specifications. Wrapper around Clapeyron.xy_flash, with automatic initial point calculations.

Inputs:

  • p, pressure [Pa]
  • s, entropy [J·K⁻¹]
  • n, vector of number of moles of each species [mol]

All keyword arguments are forwarded to GeneralizedXYFlash.

Outputs:

  • result, a FlashResult struct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
source
Clapeyron.uv_flash — Function
result = uv_flash(model, u, v, n, method::FlashMethod = GeneralizedXYFlash())
result = uv_flash(model, u, v, n; kwargs...)

Routine to solve non-reactive two-phase multicomponent flash problem. With U-V specifications. Wrapper around Clapeyron.xy_flash, with automatic initial point calculations. Inputs:

  • u, internal energy [J]
  • v, total volume [m³]
  • z, vector of number of moles of each species [mol]

All keyword arguments are forwarded to GeneralizedXYFlash.

Outputs:

  • result, a FlashResult struct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
source
Clapeyron.qt_flash — Function
result = qt_flash(model, q, T, n, method::FlashMethod = GeneralizedXYFlash())
result = qt_flash(model, q, T, n; kwargs...)

Routine to solve non-reactive two-phase multicomponent flash problem. With vapour fraction - T specifications. Wrapper around Clapeyron.xy_flash, with automatic initial point calculations.

Inputs:

  • q, vapour fraction
  • T, temperature [K]
  • n, vector of number of moles of each species [mol]

All keyword arguments are forwarded to GeneralizedXYFlash.

Outputs:

  • result, a FlashResult struct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
Note

Using qt_flash with q = 0 or q = 1 is equivalent to calculating bubble or dew pressures. Passing GeneralizedXYFlash as a method to bubble_pressure of dew_pressure will use qt_flash to calculate the bubble/dew point.

source
Clapeyron.qp_flash — Function
result = qp_flash(model, q, p, n, method::FlashMethod = GeneralizedXYFlash())
result = qp_flash(model, q, p, n; kwargs...)

Routine to solve non-reactive two-phase multicomponent flash problem. With vapour fraction - P specifications. Wrapper around Clapeyron.xy_flash, with automatic initial point calculations.

Inputs:

  • q, vapour fraction
  • p, pressure [Pa]
  • n, vector of number of moles of each species [mol]

All keyword arguments are forwarded to GeneralizedXYFlash.

Outputs:

  • result, a FlashResult struct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
Note

Using qp_flash with q = 0 or q = 1 is equivalent to calculating bubble or dew temperatures. Passing GeneralizedXYFlash as a method to bubble_temperature of dew_temperature will use qp_flash to calculate the bubble/dew point.

source
Clapeyron.ts_flash — Function
result = ts_flash(model, T, s, n, method::FlashMethod = GeneralizedXYFlash())
result = ts_flash(model, T, s, n; kwargs...)

Routine to solve non-reactive two-phase multicomponent flash problem. With T-S specifications. Wrapper around Clapeyron.xy_flash, with automatic initial point calculations.

Inputs:

  • T, temperature [K]
  • s, entropy [J·K⁻¹]
  • n, vector of number of moles of each species [mol]

All keyword arguments are forwarded to GeneralizedXYFlash.

Outputs:

  • result, a FlashResult struct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
source
Clapeyron.vt_flash — Function
result = vt_flash(model, v, T, n, method::FlashMethod = GeneralizedXYFlash())
result = vt_flash(model, v, T, n; kwargs...)

Routine to solve non-reactive two-phase multicomponent flash problem. With V-T specifications. Wrapper around Clapeyron.xy_flash, with automatic initial point calculations.

Inputs:

  • v, volume [m³]
  • T, temperature [K]
  • n, vector of number of moles of each species [mol]

All keyword arguments are forwarded to GeneralizedXYFlash.

Outputs:

  • result, a FlashResult struct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
source
Clapeyron.xy_flash — Function
xy_flash(model,spec::FlashSpecifications,z,w0::FlashResult,method::GeneralizedXYFlash)
xy_flash(model,spec::FlashSpecifications,z,w0::FlashResult;rtol = 1e-12,atol = 1e-10,max_iters = 50)

Routine to solve a non-reactive multiphase, multicomponent flash problem with arbitrary specifications. Based on the unified formulation proposed by Ben Gharbia (2021). The two necessary specifications are taken from specs, the initial point is obtained from w0. Returns a FlashResult struct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.

Examples

spec = FlashSpecifications(p = 101325.0, T = 200.15) #p-T flash
model = cPR(["ethane","propane"],idealmodel=ReidIdeal)
z = [0.5,0.5] #bulk composition
x1 = [0.25,0.75] #liquid composition
x2 = [0.75,0.25] #gas composition
compositions = [x1,x2]
volumes = [6.44e-5,0.016]
fractions = [0.5,0.5]
p0,T0 = NaN,NaN #in p-T flash, pressure and temperature are already specifications
data = FlashData(p0,T0)
result0 = FlashResult(compositions,fractions,volumes,data) #a FlashResult containing all necessary information
result = xy_flash(model,spec,z,result0) #perform the flash
source

General methods

Clapeyron.DETPFlash — Type
DETPFlash(; numphases = 2,
max_steps = 3000(numphases-1),
population_size = 50,
time_limit = Inf,
seed = 1,
stagnation_evals = 0,
stagnation_tol = 0.0,
backend = :sass,
verbose = false,
logspace = false,
equilibrium = :auto)

Method to solve a non-reactive multicomponent TP-flash problem by global optimization of the Gibbs free energy.

This implementation uses an ask–tell metaheuristic backend. The current default backend is :sass (Self-adaptive spherical search, SASS). The optimizer stops when it reaches max_steps function evaluations, exceeds time_limit seconds, or triggers stagnation-based early stopping controlled by stagnation_evals and stagnation_tol.

Note: the file name is historical; the original implementation used differential evolution.

User must assume a number of phases, numphases. If true number of phases is smaller than numphases, model should predict either (a) identical composition in two or more phases, or (b) one phase with negligible total number of moles. If true number of phases is larger than numphases, a thermodynamically unstable solution will be predicted.

The equilibrium keyword allows to restrict the search of phases to just liquid-liquid equilibria (equilibrium = :lle). The default searches for liquid and gas phases.

source
Clapeyron.RRTPFlash — Type
RRTPFlash{T}(;kwargs...)

Method to solve non-reactive multicomponent flash problem by Rachford-Rice equation.

Only two phases are supported. If K0 is nothing, it will be calculated via the Wilson correlation.

Keyword Arguments:

  • equilibrium: :vle for liquid vapor equilibria, :lle for liquid liquid equilibria, :unknown if not specified.
  • K0: initial guess for the K-values.
  • x0: initial guess for the composition of phase x.
  • y0: initial guess for the composition of phase y.
  • vol0: initial guesses for phase x and phase y volumes.
  • K_tol: tolerance to stop the calculation.
  • ss_iters: number of Successive Substitution iterations to perform.
  • nacc: accelerate successive substitution method every nacc steps. Should be an integer bigger than 3. Set to 0 for no acceleration.
  • second_order: wheter to solve the Gibbs energy minimization using the analytical hessian or not.
  • noncondensables: arrays with names (strings) of components non allowed on the liquid phase. In the case of LLE equilibria, corresponds to the x phase.
  • nonvolatiles: arrays with names (strings) of components non allowed on the vapour phase. In the case of LLE equilibria, corresponds to the y phase.
  • flash_result::FlashResult: can be provided instead of x0,y0 and vol0 for initial guesses.

Result values

This flash method will always return two phases, independently of the amount of actual phases in equilibria. The phase in the first index is considered the x phase (always liquid), whereas the phase on the second index is considered the y phase (vapour phase in VLE, liquid phase in LLE). In this way, one can recover the converged K value by dividing the compositions in the following way:

x,y = result.compositions
K = y ./ x

On two-phase equilibria, there are two different phases, with non-zero phase fractions and compositions, whereas on one-phase equilibria, one phase will have a zero phase fraction and one phase will have a phase fraction equal to sum(z_bulk). We will name the phase with non-zero phase fraction "active phase"; the phase with null phase fraction will be named "incipient" phase. A two-phase equilibria result will have two active phases and zero incipient phases, a one-phase equilibria result will have one active phase and one incipient phase. We can get the amount of active phases using Clapeyron.numphases(result,true), and check whatever phase is active via Clapeyron.is_active_phase.

K-values on results with incipient phases

On a one-phase equilibria result, the K value calculated via K = y ./ x is not a valid equilibrium K with respect to the bulk composition. This value is still useful, but some care is needed while handling this result. we can identify three cases:

  1. "hard" liquid and "hard" vapour: In those cases, the converged K value has all Kᵢ > 1 (vapour result), or all Kᵢ < 1 (liquid result). Because compositions in a FlashResult are normalized, the K obtained via y ./ x will have at least one value equal to 1.
  2. "soft" liquid and "soft" vapour: In those cases, while K converged, no vapour fraction β in the range (0,1) can satisfy β = Clapeyron.rachfordrice(K,z). In this case, minimum(K) < 1 and maximum(K) > 1.
  3. "trivial" result: No separation could be done, and the flash procedure converged to the trivial result K .= 1. The phase is still identified (so the active phase can still be identified as liquid or vapour), no incipient phase could be found. In this case, all(isone,K) == true.
source
Clapeyron.MichelsenTPFlash — Type
MichelsenTPFlash{T}(;kwargs...)

Method to solve non-reactive multicomponent flash problem by Michelsen's method.

Only two phases are supported. If K0 is nothing, it will be calculated via the Wilson correlation.

Keyword Arguments:

  • equilibrium: :vle for liquid vapor equilibria, :lle for liquid liquid equilibria, :unknown if not specified.
  • K0: initial guess for the K-values.
  • x0: initial guess for the composition of phase x.
  • y0: initial guess for the composition of phase y.
  • vol0: initial guesses for phase x and phase y volumes.
  • K_tol: tolerance to stop the calculation.
  • ss_iters: number of Successive Substitution iterations to perform.
  • nacc: accelerate successive substitution method every nacc steps. Should be an integer bigger than 3. Set to 0 for no acceleration.
  • second_order: whether to solve the Gibbs energy minimization using the analytical hessian or not.
  • noncondensables: arrays with names (strings) of components non allowed on the liquid phase. In the case of LLE equilibria, corresponds to the x phase.
  • nonvolatiles: arrays with names (strings) of components non allowed on the vapour phase. In the case of LLE equilibria, corresponds to the y phase.
  • flash_result::FlashResult: can be provided instead of x0,y0 and vol0 for initial guesses.
  • verbose : if set to true, the method will display additional information in the REPL.

Result values

This flash method will always return two phases, independently of the amount of actual phases in equilibria. The phase in the first index is considered the x phase (always liquid), whereas the phase on the second index is considered the y phase (vapour phase in VLE, liquid phase in LLE). In this way, one can recover the converged K value by dividing the compositions in the following way:

x,y = result.compositions
K = y ./ x

On two-phase equilibria, there are two different phases, with non-zero phase fractions and compositions, whereas on one-phase equilibria, one phase will have a zero phase fraction and one phase will have a phase fraction equal to sum(z_bulk). We will name the phase with non-zero phase fraction "active phase"; the phase with null phase fraction will be named "incipient" phase. A two-phase equilibria result will have two active phases and zero incipient phases, a one-phase equilibria result will have one active phase and one incipient phase. We can get the amount of active phases using Clapeyron.numphases(result,true), and check whatever phase is active via Clapeyron.is_active_phase.

K-values on results with incipient phases

On a one-phase equilibria result, the K value calculated via K = y ./ x is not a valid equilibrium K with respect to the bulk composition. This value is still useful, but some care is needed while handling this result. we can identify three cases:

  1. "hard" liquid and "hard" vapour: In those cases, the converged K value has all Kᵢ > 1 (vapour result), or all Kᵢ < 1 (liquid result). Because compositions in a FlashResult are normalized, the K obtained via y ./ x will have at least one value equal to 1.
  2. "soft" liquid and "soft" vapour: In those cases, while K converged, no vapour fraction β in the range (0,1) can satisfy β = Clapeyron.rachfordrice(K,z). In this case, minimum(K) < 1 and maximum(K) > 1.
  3. "trivial" result: No separation could be done, and the flash procedure converged to the trivial result K .= 1. The phase is still identified (so the active phase can still be identified as liquid or vapour), no incipient phase could be found. In this case, all(isone,K) == true.
source
Clapeyron.MultiPhaseTPFlash — Type
MultiPhaseTPFlash(;kwargs...)

Method to solve non-reactive multiphase (np phases), multicomponent (nc components) flash problem.

The flash algorithm uses successive stability tests to find new phases [1], and then tries to solve the system via Rachford-Rice and succesive substitution for nc * np * ss_iters iterations.

If the Rachford-Rice SS fails to converge, it proceeds to solve the system via Gibbs minimization in VT-space using lnK-β-ρ as variables [3].

The algorithm finishes when SS or the Gibbs minimization converges and all resulting phases are stable.

If the result of the phase equilibria is not stable, then it proceeds to add/remove phases again, for a maximum of phase_iters iterations.

For a CompositeModel with a solid model, the solids (stoichiometric compounds of the fluid components given by the mapping) are added and removed in an outer loop until all of them are stable, the fluid phases are solved on the remaining feed. At least one fluid phase has to be present, use CEMFlash otherwise.

Keyword Arguments:

  • K0 (optional), initial guess for the constants K.
  • x0 (optional), initial guess for the composition of phase x.
  • y0 (optional), initial guess for the composition of phase y.
  • n0 (optional), initial guess for all compositions. It can be a matrix or a vector of vectors.
  • K_tol = sqrt(eps(Float64)), tolerance to stop the calculation (norm(lnK,1) < K_tol).
  • ss_iters = 6, number of Successive Substitution iterations to perform.
  • nacc = 5, accelerate successive substitution method every nacc steps. Should be an integer bigger than 3. Set to 0 for no acceleration.
  • second_order = true, whether to solve the Gibbs energy minimization using the analytical hessian or not. If set to false, the Gibbs minimization will be done using L-BFGS.
  • full_tpd = false, whether to start with a simple K-split or using an intensive TPD search first.
  • max_phases = typemax(Int), the algorithm stops if there are more than min(max_phases,nc) phases.
  • phase_iters = 20, the maximum number of solve-add/remove-phase iterations.

References

  1. Thermopack - Thermodynamic equilibrium algorithms reimplemented in a new framework. (2020, September 08). https://github.com/thermotools/thermopack. Retrieved May 4, 2024, from https://github.com/thermotools/thermopack/blob/main/docs/memo/flash/flash.pdf
  2. Okuno, R., Johns, R. T. T., & Sepehrnoori, K. (2010). A new algorithm for Rachford-Rice for multiphase compositional simulation. SPE Journal, 15(02), 313–325. doi:10.2118/117752-pa
  3. Adhithya, T. B., & Venkatarathnam, G. (2021). New pressure and density based methods for isothermal-isobaric flash calculations. Fluid Phase Equilibria, 537(112980), 112980. doi:10.1016/j.fluid.2021.112980
source
Clapeyron.CEMFlash — Type
CEMFlash(;δ = nothing, equilibrium = :auto, polish = MichelsenTPFlash(second_order = true), threaded = true, diagram = nothing, λ_tol = 1e-12, vol_rtol = 0.1, lnf_tol = 1e-6)

Method to solve the non-reactive multicomponent, multiphase flash problem with the convex envelope method (CEM) [1].

The Gibbs energy of every aggregate state is evaluated on a lattice of the composition simplex (step 1/δ). The phase split is the facet of the lower convex envelope above the feed composition, found with a linear program (see CEMPhaseDiagram). The number of phases does not need to be known, and the method does not depend on initial guesses. The CEM result has a discretization error of order 1/δ. By default, it is refined with a local flash method (polish).

If a CEMDiagram obtained with phase_diagram is passed via diagram, the stored envelope is used and no Gibbs energy evaluation on the grid is necessary (the conditions and components must match).

Keyword arguments

  • δ: number of divisions of the composition axes. By default, 256, 128 and 64 for binary, ternary and quaternary mixtures (as in [1]), and 32 for more components (smaller for more than six components, at most ~5⋅10⁵ grid points). Ignored if diagram is given.
  • equilibrium: :auto considers liquid and vapour phases, :lle only liquid phases. Ignored if diagram is given.
  • polish: TPFlashMethod used to refine the CEM phases (initialized with the CEM result), or nothing to return the CEM result. The refined result is only accepted if its phases are in equilibrium and it has a lower Gibbs energy than the CEM result. If MichelsenTPFlash is given and the CEM finds more than two phases, a MultiPhaseTPFlash with the same tolerances is used. Results with solid phases are refined with a MultiPhaseTPFlash that includes the solid phases (with the tolerances of polish if it is a MichelsenTPFlash or MultiPhaseTPFlash), starting from the CEM solids.
  • threaded: evaluate the grid in parallel.
  • diagram: a precomputed CEMDiagram.
  • λ_tol: vertices of a facet with a smaller weight are not part of the phase split. Ignored if diagram is given.
  • vol_rtol: liquid and vapour grid points whose volumes differ by less than this relative tolerance can belong to the same phase (near critical region). Ignored if diagram is given.
  • lnf_tol: tolerance of the log fugacities for a polished result to be accepted.

Solid phases are considered for CompositeModels with a solid model. Each solid is a stoichiometric compound of the fluid components given by the mapping of the CompositeModel, its volume is calculated with the solid model.

References

  1. Göttl, Q., Rosen, N., & Burger, J. (2025). Convex envelope method for T, p flash calculations for mixtures with an arbitrary number of components and arbitrary aggregate states. Computers & Chemical Engineering, 203, 109326. doi:10.1016/j.compchemeng.2025.109326
source
Clapeyron.MCFlashJL — Type

MCFlashJL(; method = MultiComponentFlash.SSIFlash(), storage = nothing, V = NaN, K = nothing, kwargs.... )

Uses MultiComponentFlash.jl two-phase flash solver. Allows passing storage to minimize allocations. That storage can be created by calling MultiComponentFlash.flash_storage(model,p,T,z,method::MCFlashJL)

Note

This method requires MultiComponentFlash to be loaded in the current session (using MultiComponentFlash) and julia >= v1.9

source
Clapeyron.GeneralizedXYFlash — Type
GeneralizedXYFlash{T}(;kwargs...)

Method to solve non-reactive multicomponent, two-phase flash problem, using a generalized formulation.

Only two phases are supported. If K0 is nothing, it will be calculated via fugacity coefficients at p,T conditions.

Keyword Arguments:

  • equilibrium (optional) = equilibrium type ":vle" for liquid vapor equilibria, ":lle" for liquid liquid equilibria, :unknown if not specified.
  • p0 (optional), initial guess pressure, ignored if pressure is one of the flash specifications.
  • T0 (optional), initial guess temperature, ignored if temperature is one of the flash specifications.
  • K0 (optional), initial guess for the K-values.
  • x0 (optional), initial guess for the composition of phase x.
  • y0 = optional, initial guess for the composition of phase y.
  • vol0 = optional, initial guesses for phase x and phase y volumes.
  • atol = absolute tolerance to stop the calculation.
  • rtol = relative tolerance to stop the calculation.
  • max_iters = maximum number of iterations.
  • flash_result::FlashResult: can be provided instead of x0,y0 and vol0 for initial guesses.
source
Clapeyron.RRQXFlash — Type
RRQXFlash{T}(;kwargs...)

Method to solve non-reactive multicomponent, two-phase flash problem, using a generalized formulation.

Only two phases are supported. If K0 is nothing, it will be calculated via fugacity coefficients at p,T conditions.

Keyword Arguments:

  • equilibrium (optional) = equilibrium type ":vle" for liquid vapor equilibria, ":lle" for liquid liquid equilibria, :unknown if not specified
  • p0 (optional), initial guess pressure, ignored if pressure is one of the flash specifications.
  • T0 (optional), initial guess temperature, ignored if temperature is one of the flash specifications.
  • K0 (optional), initial guess for the K-values.
  • x0 (optional), initial guess for the composition of phase x.
  • y0 = optional, initial guess for the composition of phase y.
  • vol0 = optional, initial guesses for phase x and phase y volumes.
  • atol = absolute tolerance to stop the calculation.
  • rtol = relative tolerance to stop the calculation.
  • max_iters = maximum number of iterations
  • flash_result::FlashResult: can be provided instead of x0,y0 and vol0 for initial guesses.
source
Clapeyron.RRXYFlash — Type
RRXYFlash{T}(;kwargs...)

Method to solve non-reactive multicomponent, two-phase flash problem, using a generalized succesive substitution formulation.

Only two phases are supported. If K0 is nothing, it will be calculated via fugacity coefficients at p,T conditions.

Keyword Arguments:

  • equilibrium (optional) = equilibrium type ":vle" for liquid vapor equilibria, ":lle" for liquid liquid equilibria, :unknown if not specified.
  • p0 (optional), initial guess pressure, ignored if pressure is one of the flash specifications.
  • T0 (optional), initial guess temperature, ignored if temperature is one of the flash specifications.
  • K0 (optional), initial guess for the K-values.
  • x0 (optional), initial guess for the composition of phase x.
  • y0 = optional, initial guess for the composition of phase y.
  • vol0 = optional, initial guesses for phase x and phase y volumes.
  • tol_xy = absolute composition tolerance
  • tol_pT = relative temperature or pressure tolerance.
  • tol_of = absolute objective property tolerance.
  • max_iters = maximum number of iterations.
  • ss_iters = maximum number of inner sucessive substitution iterations.
  • flash_result::FlashResult: can be provided instead of x0,y0 and vol0 for initial guesses.
source

Rachford-Rice

The two-phase rachford-rice solver in Clapeyron.jl is also available as a standalone package, RachfordRice.jl.

Clapeyron.RachfordRice.rachfordrice — Function
rachfordrice(K, z, β0 = nothing; negative_flash = false, K_tol = 4*eps(eltype(K)),
             non_inx = nothing, non_iny = nothing, verbose = nothing)
rachfordrice(RR::RachfordRiceResidual, β0 = nothing; negative_flash = false,
             K_tol = 4*eps(eltype(RR)), verbose = nothing)

Solve the Rachford-Rice mass balance for the molar vapour fraction β:

Σᵢ zᵢ (Kᵢ - 1) / (1 + β (Kᵢ - 1)) = 0

and return a RachfordRiceResult.

The solver first detects trivial, failed and single-phase cases, then computes the Whitson-Michelsen bounds on β. Small problems (up to 3 non-trivial components) are solved in closed form; otherwise a bracketed Halley iteration is used. When negative_flash = false and the root lies within K_tol^(1/3) of 0 or 1, a boundary check may project the result onto the bubble point (β = 0) or the dew point (β = 1).

  • K: vector of K-values Kᵢ = yᵢ/xᵢ. They must be non-negative; Inf and 0 are allowed.
  • z: vector of overall molar composition. It does not need to be normalised.
  • β0: optional initial guess for the vapour fraction. It is ignored if it falls outside the valid bounds.

K, z, non_inx, non_iny are arguments used to instantiate a RachfordRiceResidual.

Keyword arguments

  • negative_flash: if true, β may be outside [0, 1] (negative flash). If false (default), single-phase cases return β = 0 (liquid) or β = 1 (vapour) and the result is clamped to [0, 1].
  • K_tol: tolerance for the trivial-solution check (norm(K,Inf) <= K_tol) and for the boundary tests.
  • verbose: nothing (default) or a Bool. If true, diagnostic information is logged with @info.

Returns

A RachfordRiceResult.

Example

K = [2.0, 1.5, 0.5, 0.1]
z = [0.25, 0.25, 0.25, 0.25]
res = rachfordrice(K, z)
β = res.V
y = vapour_compositions(K, z, β)
x = liquid_compositions(K, z, β)
source
Clapeyron.RachfordRice.RachfordRiceResidual — Type
RachfordRiceResidual(K, z; non_inx = nothing, non_iny = nothing)

Container describing a Rachford-Rice problem: the K-values K, the overall molar composition z and the (optional) sets of components that are absent from one of the phases. The vapour fraction β is the root of

Σᵢ zᵢ (Kᵢ - 1) / (1 + β (Kᵢ - 1)) = 0

(the sum is normalised by Σᵢ zᵢ, so z does not need to add up to one).

Arguments

  • K: vector of K-values Kᵢ = yᵢ/xᵢ.
  • z: vector of overall molar composition, with length(z) >= length(K).

Keyword arguments

  • non_inx: nothing, or a Bool vector marking the components that are not present in the liquid phase. These components are treated as having Kᵢ = Inf.
  • non_iny: nothing, or a Bool vector marking the components that are not present in the vapour phase. These components are treated as having Kᵢ = 0.

A RachfordRiceResidual behaves as a read-only iterable container of effective K-values.

Example

K = [2.0, 1.5, 0.5, 0.1]
z = [0.25, 0.25, 0.25, 0.25]
RR = RachfordRiceResidual(K, z)
res = rachfordrice(RR)
RR[1] #2.0
source
Clapeyron.RachfordRice.RachfordRiceStatus — Type
RachfordRiceStatus

Enumeration describing the phase state found by rachfordrice.

valuemeaning
RRLiquidsingle-phase liquid: the residual at β = 0 is negative, so no vapour is formed.
RRVapoursingle-phase vapour: the residual at β = 1 is positive, so no liquid is formed.
RREqtwo-phase (vapour-liquid equilibrium) solution; a root of the Rachford-Rice equation exists.
RRTrivialtrivial solution: all K-values are equal to one within K_tol (maximum(abs.(log.(K))) <= K_tol), so the phases are indistinguishable.
RRFailurethe problem is ill-posed (NaN or negative K-values, NaN residual) or the iteration did not converge.
source
Clapeyron.RachfordRice.RachfordRiceResult — Type
RachfordRiceResult{T}

Result returned by rachfordrice.

Fields

  • V::T: molar vapour fraction β
  • L::T: molar liquid fraction 1 - β
  • status::RachfordRiceStatus: phase state found, one of RRLiquid, RRVapour, RREq, RRTrivial, RRFailure (see RachfordRiceStatus).
  • negative_flash::Bool: whether the problem was solved allowing β outside [0, 1].
  • solved::Bool: true if a root of the Rachford-Rice equation was found by the solver (or recovered by the boundary projection). It is false for single-phase shortcuts, trivial solutions and failures.
  • feasible::Bool: true if the K-values straddle one (minimum(K) <= 1 <= maximum(K)) and have a valid domain, i.e. a two-phase root can exist.
  • iters::Int: number of iterations used by the iterative solver (0 when the closed-form solution, a shortcut was used or no solution is possible).

When no valid result is available, V and L are NaN. For a single-phase result with negative_flash = false, (V, L) is (0, 1) for RRLiquid or (1, 0) for RRVapour, with solved = false.

source
Clapeyron.RachfordRice.vapour_compositions — Function
vapour_compositions(K,z,β)
vapour_compositions!(y,K,z,β)
vapour_compositions(RR::RachfordRiceResidual,β)
vapour_compositions!(y,RR::RachfordRiceResidual,β)

Returns the gas phase composition, given K-values K, the initial molar composition z and the molar vapor fraction ´β´.

Each gas phase composition is calculated acording to:

xvᵢ = kᵢzᵢ/(1+ β(kᵢ - 1))

vapour_compositions! does the same, but it overwrites the input y.

source
Clapeyron.RachfordRice.liquid_compositions — Function
liquid_compositions(K,z,β)
liquid_compositions!(x,K,z,β)
liquid_compositions(RR::RachfordRiceResidual,β::Union{Number,RachfordRiceResult})
liquid_compositions!(x,RR::RachfordRiceResidual,β::Union{Number,RachfordRiceResult})

Returns the liquid phase composition, given k-values K, the initial molar composition z and the molar vapor fraction ´β´.

Each gas phase composition is calculated acording to:

xlᵢ = zᵢ/(1+ β(kᵢ-1))

liquid_compositions! does the same, but it overwrites the input x.

source
Clapeyron.RachfordRice.rr_limits — Function
βmin,βmax = rr_limits(RR::RachfordRiceResidual, negative_flash::Bool = false)

Whitston-michelsen bounds for the rachford-rice problem.

returns NaN,NaN if the provided K and z values cannot be separated into two phases.

source
Clapeyron.RachfordRice.rr_feasible — Function
rr_feasible(RR::RachfordRiceResidual)::Bool

Returns a Bool indicating if the system could have a solution. systems without solution are:

  • Systems where all K-values are over 1 (one phase, vapour state)
  • Systems where all K-values are below 1 (one phase, liquid state)
  • Systems where one or more values of K or z are negative
  • Systems where one or more values of K or z are non-finite. K can be Inf, but it cannot be NaN
source
Clapeyron.RachfordRice.residual — Function
residual(RR::RachfordRiceResidual, βv, βl = 1 - βv)

Evaluate the Rachford-Rice residual function

F(β) = Σᵢ zᵢ (Kᵢ - 1) / (1 + β (Kᵢ - 1)) / Σᵢ zᵢ

at β = βv. The molar vapour fraction of the solution is the root of F.

Here RR is a RachfordRiceResidual, βv is the molar vapour fraction β and βl is the molar liquid fraction, which defaults to 1 - βv.

Returns the residual F(β).

source
Clapeyron.RachfordRice.residual_first_derivative — Function
residual_first_derivative(RR::RachfordRiceResidual, βv, βl = 1 - βv) -> (F, ∂F)

Evaluate the Rachford-Rice residual and its first derivative with respect to β:

F(β) = Σᵢ zᵢ (Kᵢ - 1) / (1 + β (Kᵢ - 1)) / Σᵢ zᵢ
∂F(β) = -Σᵢ zᵢ (Kᵢ - 1)² / (1 + β (Kᵢ - 1))² / Σᵢ zᵢ

at β = βv. The molar vapour fraction of the solution is the root of F.

Here RR is a RachfordRiceResidual, βv is the molar vapour fraction β and βl is the molar liquid fraction, which defaults to 1 - βv.

Returns the tuple (F, ∂F).

source
Clapeyron.RachfordRice.residual_first_second_derivative — Function
residual_first_second_derivative(RR::RachfordRiceResidual, βv, βl = 1 - βv) -> (F, ∂F, ∂²F)

Evaluate the Rachford-Rice residual and its first and second derivatives with respect to β:

F(β) = Σᵢ zᵢ (Kᵢ - 1) / (1 + β (Kᵢ - 1)) / Σᵢ zᵢ
∂F(β) = -Σᵢ zᵢ (Kᵢ - 1)² / (1 + β (Kᵢ - 1))² / Σᵢ zᵢ
∂²F(β) = 2 Σᵢ zᵢ (Kᵢ - 1)³ / (1 + β (Kᵢ - 1))³ / Σᵢ zᵢ

at β = βv. The molar vapour fraction of the solution is the root of F.

Here RR is a RachfordRiceResidual, βv is the molar vapour fraction β and βl is the molar liquid fraction, which defaults to 1 - βv.

Returns the tuple (F, ∂F, ∂²F)

source
Clapeyron.RachfordRice.residual_first_second_derivative_error — Function
residual_first_second_derivative_error(RR::RachfordRiceResidual, βv, βl = 1 - βv) -> (F, ∂F, ∂²F, S)

Same as residual_first_second_derivative, but additionally returns:

S(β) = Σᵢ zᵢ |Kᵢ - 1| / |1 + β (Kᵢ - 1)| / Σᵢ zᵢ

the sum of the absolute values of the terms that make up F. Since F is a sum of terms of both signs, S is the natural scale of its floating-point rounding error: a residual with |F| <= C * eps * S cannot be distinguished from zero. The solver uses this as its convergence criterion.

Here RR is a RachfordRiceResidual, βv is the molar vapour fraction β and βl is the molar liquid fraction, which defaults to 1 - βv.

Returns the tuple (F, ∂F, ∂²F, S).

source