Contents
Index
Clapeyron.CEMFlashClapeyron.DETPFlashClapeyron.FlashDataClapeyron.FlashResultClapeyron.FlashSpecificationsClapeyron.GeneralizedXYFlashClapeyron.MCFlashJLClapeyron.MichelsenTPFlashClapeyron.MultiPhaseTPFlashClapeyron.RRQXFlashClapeyron.RRTPFlashClapeyron.RRXYFlashClapeyron.RachfordRice.RachfordRiceResidualClapeyron.RachfordRice.RachfordRiceResultClapeyron.RachfordRice.RachfordRiceStatusClapeyron.RachfordRice.liquid_compositionsClapeyron.RachfordRice.rachfordriceClapeyron.RachfordRice.residualClapeyron.RachfordRice.residual_first_derivativeClapeyron.RachfordRice.residual_first_second_derivativeClapeyron.RachfordRice.residual_first_second_derivative_errorClapeyron.RachfordRice.rr_feasibleClapeyron.RachfordRice.rr_limitsClapeyron.RachfordRice.rr_statusClapeyron.RachfordRice.vapour_compositionsClapeyron.each_active_phase_indexClapeyron.is_active_phaseClapeyron.numphasesClapeyron.ph_flashClapeyron.ps_flashClapeyron.qp_flashClapeyron.qt_flashClapeyron.supports_reductionClapeyron.tp_flashClapeyron.tp_flash2Clapeyron.ts_flashClapeyron.uv_flashClapeyron.vt_flashClapeyron.xy_flash
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 Name | Flash Type | maximum phases | Derivative Order | Activity Models | Electrolyte Models | Notes |
|---|---|---|---|---|---|---|
RRTPFlash | P-T | 2 (VLE,LLE) | First order | No (cubic EoS) | Yes | Rachford-Rice (RR) Flash |
MichelsenTPFlash | P-T | 2 (VLE,LLE) | Second order¹ | Yes | No | RR + Gibbs optimization |
MultiPhaseTPFlash | P-T | any (automatic phase detection, incl. solids³) | Second order | Yes | No | RR + Gibbs optimization + phase search |
DETPFlash | P-T | any (via numphases) | Zeroth Order | Yes | No | Global Gibbs optimization over fixed phases |
CEMFlash | P-T | any (automatic phase detection, incl. solids³) | Zeroth Order (polished: same as polish) | Yes | No | Convex envelope of the discretized Gibbs energy (+ local refinement) |
GeneralizedXYFlash | X-Y | 2² (VLE/LLE) | Second Order | No | No | Equilibria conditions as constrained non-linear system |
RRQXFlash | Q-T,Q-P | 2 | First Order | Yes | No | RR update + Root-finding of Q(p)/Q(T) |
RRXYFlash | P-Y,T-Y | 2 (VLE/LLE) | First Order | Yes | No | RR iterations + Root-finding on Y(T)/Y(p) |
MCFlashJL | P-T | 2 (VLE) | Second order | No | No | MultiComponentFlash.jl extension |
Notes:
MichelsenTPFlashcan switch how it can solve the gibbs optimization problem via thesecond_order::Boolkeyword, from L-BFGS (first order method) to Newton (second order Newton) By default,MichelsenTPFlashuses a first order gibbs optimization solver.GeneralizedXYFlashis a wrapper to thexy_flashmethod. Whilexy_flashcan 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.MichelsenTPFlashandRRTPFlashwill always return a result with two phases, the phase with zero phase fraction carry information about the converged K value.Solid phases are considered for a
CompositeModelwith a solid model. They are stored after the fluid phases,result.data.solid_idxis the index of the first solid phase andClapeyron.is_solid(result,i)checks a phase.MultiPhaseTPFlashrequires 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)::BoolChecks 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.
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)
Clapeyron.FlashData — Type
FlashDataAuxiliary 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.
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) #equivalentClapeyron.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).
Clapeyron.is_active_phase — Function
is_active_phase(result::FlashResult,i)::BoolReturns 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.
Clapeyron.each_active_phase_index — Function
each_active_phase_index(result::FlashResult)Lazy iterator returning the indices of each active phase.
Flash functions
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]
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, aFlashResultstruct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
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, aFlashResultstruct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
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, aFlashResultstruct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
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, aFlashResultstruct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
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 fractionT, temperature[K]n, vector of number of moles of each species[mol]
All keyword arguments are forwarded to GeneralizedXYFlash.
Outputs:
result, aFlashResultstruct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
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.
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 fractionp, pressure[Pa]n, vector of number of moles of each species[mol]
All keyword arguments are forwarded to GeneralizedXYFlash.
Outputs:
result, aFlashResultstruct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
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.
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, aFlashResultstruct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
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, aFlashResultstruct containing molar fractions, vapour fractions, molar volumes and the equilibrium temperature and pressure.
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 flashGeneral 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.
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::vlefor liquid vapor equilibria,:llefor liquid liquid equilibria,:unknownif 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 thexphase.nonvolatiles: arrays with names (strings) of components non allowed on the vapour phase. In the case of LLE equilibria, corresponds to theyphase.flash_result::FlashResult: can be provided instead ofx0,y0andvol0for 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 ./ xOn 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:
- "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
FlashResultare normalized, the K obtained viay ./ xwill have at least one value equal to1. - "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) < 1andmaximum(K) > 1. - "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.
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::vlefor liquid vapor equilibria,:llefor liquid liquid equilibria,:unknownif 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 thexphase.nonvolatiles: arrays with names (strings) of components non allowed on the vapour phase. In the case of LLE equilibria, corresponds to theyphase.flash_result::FlashResult: can be provided instead ofx0,y0andvol0for initial guesses.verbose: if set totrue, 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 ./ xOn 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:
- "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
FlashResultare normalized, the K obtained viay ./ xwill have at least one value equal to1. - "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) < 1andmaximum(K) > 1. - "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.
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 tofalse, 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 thanmin(max_phases,nc)phases.phase_iters = 20, the maximum number of solve-add/remove-phase iterations.
References
- 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
- 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
- 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
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,128and64for binary, ternary and quaternary mixtures (as in [1]), and32for more components (smaller for more than six components, at most ~5⋅10⁵ grid points). Ignored ifdiagramis given.equilibrium::autoconsiders liquid and vapour phases,:lleonly liquid phases. Ignored ifdiagramis given.polish:TPFlashMethodused to refine the CEM phases (initialized with the CEM result), ornothingto 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. IfMichelsenTPFlashis given and the CEM finds more than two phases, aMultiPhaseTPFlashwith the same tolerances is used. Results with solid phases are refined with aMultiPhaseTPFlashthat includes the solid phases (with the tolerances ofpolishif it is aMichelsenTPFlashorMultiPhaseTPFlash), starting from the CEM solids.threaded: evaluate the grid in parallel.diagram: a precomputedCEMDiagram.λ_tol: vertices of a facet with a smaller weight are not part of the phase split. Ignored ifdiagramis 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 ifdiagramis 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
- 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
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)
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,:unknownif 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 ofx0,y0andvol0for initial guesses.
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,:unknownif not specifiedp0(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 iterationsflash_result::FlashResult: can be provided instead ofx0,y0andvol0for initial guesses.
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,:unknownif 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 tolerancetol_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 ofx0,y0andvol0for initial guesses.
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)) = 0and 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-valuesKᵢ = yᵢ/xᵢ. They must be non-negative;Infand0are 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: iftrue,βmay be outside[0, 1](negative flash). Iffalse(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 aBool. Iftrue, diagnostic information is logged with@info.
Returns
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, β)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-valuesKᵢ = yᵢ/xᵢ.z: vector of overall molar composition, withlength(z) >= length(K).
Keyword arguments
non_inx:nothing, or aBoolvector marking the components that are not present in the liquid phase. These components are treated as havingKᵢ = Inf.non_iny:nothing, or aBoolvector marking the components that are not present in the vapour phase. These components are treated as havingKᵢ = 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.0Clapeyron.RachfordRice.RachfordRiceStatus — Type
RachfordRiceStatusEnumeration describing the phase state found by rachfordrice.
| value | meaning |
|---|---|
RRLiquid | single-phase liquid: the residual at β = 0 is negative, so no vapour is formed. |
RRVapour | single-phase vapour: the residual at β = 1 is positive, so no liquid is formed. |
RREq | two-phase (vapour-liquid equilibrium) solution; a root of the Rachford-Rice equation exists. |
RRTrivial | trivial solution: all K-values are equal to one within K_tol (maximum(abs.(log.(K))) <= K_tol), so the phases are indistinguishable. |
RRFailure | the problem is ill-posed (NaN or negative K-values, NaN residual) or the iteration did not converge. |
Clapeyron.RachfordRice.RachfordRiceResult — Type
RachfordRiceResult{T}Result returned by rachfordrice.
Fields
V::T: molar vapour fractionβL::T: molar liquid fraction1 - βstatus::RachfordRiceStatus: phase state found, one ofRRLiquid,RRVapour,RREq,RRTrivial,RRFailure(seeRachfordRiceStatus).negative_flash::Bool: whether the problem was solved allowingβoutside[0, 1].solved::Bool:trueif a root of the Rachford-Rice equation was found by the solver (or recovered by the boundary projection). It isfalsefor single-phase shortcuts, trivial solutions and failures.feasible::Bool:trueif 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 (0when 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.
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.
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.
Clapeyron.RachfordRice.rr_status — Function
rr_status(RR::RachfordRiceResidual;K_tol = 4*eps(eltype(RR)))given an RachfordRiceResidual return a RachfordRiceStatus enum describing the state of the system. K_tol is used as a measure to see how far apart are the K-values from the trivial solution.
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.
Clapeyron.RachfordRice.rr_feasible — Function
rr_feasible(RR::RachfordRiceResidual)::BoolReturns 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 beNaN
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(β).
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).
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)
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).