Phase envelope explorer

Move a volatile oil's methane content and the reservoir temperature, and watch its Peng–Robinson phase envelope, critical point, cricondenbar and cricondentherm move, and the saturation point at the reservoir turn from a bubble point into a dew point.

Open in the workbench Open the live page

Live preview

Engineering use case UC-MULTI-010 (Compositional PVT Analysis), with the Thermodynamics Phase Envelope Function and Saturation Point Functions. The script eos-compositional-workflow reads the same envelope at 58 % methane and checks the correlations against it.

What an engineer learns by moving the sliders: the page opens on the documented volatile oil, 58 % methane at 220 °F. Its critical point is at 442 °F and 2,940 psia, right of the reservoir, so the fluid is an oil and its saturation point a bubble point at 3,347 psia. Add methane and the critical point moves left and up: at 70 % it is at 343 °F and 3,871 psia, still an oil, with a bubble point of 4,091 psia. Past about 77 % the critical point crosses the reservoir temperature, and at 80 % it sits at 198 °F: the same family of fluid is now a gas condensate with a dew point of 4,609 psia, and pressure depletion would drop liquid in the reservoir. Take methane out instead and the envelope widens and drops, 2,278 psia at 40 %. Whether a reservoir fluid is an oil or a condensate is decided by where the critical point falls against the reservoir temperature, not by its GOR alone.

The model is untuned Peng–Robinson without volume translation; tune it to a lab saturation pressure before using the numbers for design.

Source phase-envelope.dashboard

@using Team76.Engineering.Thermodynamics.Envelopes
@using Team76.Engineering.Thermodynamics.Envelopes.CriticalPoint
@using Team76.Engineering.Thermodynamics.Eos.Builders
@using Team76.Engineering.Thermodynamics.Flash
@using Team76.Engineering.Thermodynamics.Models

@{ var r = Compute(); }

<Page MaxWidth="Narrow">
    <Section Title="Fluid">
        <Slider Label="Methane" @bind-Value="Methane" Min="0.40" Max="0.80" Step="0.01" Unit="mol fraction" />
        <Slider Label="Reservoir temperature" @bind-Value="Temperature" Min="100" Max="400" Step="5" Unit="°F" />
    </Section>

    <Section Title="What the fluid is at reservoir temperature">
        <KpiRow>
            <Value Label="Saturation pressure" Number="@r.SaturationPressure" Unit="psia" Format="N0" Note="@r.Kind" />
            <Value Label="Critical point" Number="@r.CriticalT" Unit="°F" Format="N0" Note="@($"at {r.CriticalP:N0} psia")"
                   Status="@(r.CriticalT > Temperature ? "good" : "warn")"
                   StatusText="@(r.CriticalT > Temperature ? "right of the reservoir: an oil" : "left of the reservoir: a gas condensate")" />
            <Value Label="Cricondenbar" Number="@r.Cricondenbar" Unit="psia" Format="N0" Note="no two phases above it" />
            <Value Label="Cricondentherm" Number="@r.Cricondentherm" Unit="°F" Format="N0" Note="no two phases right of it" />
        </KpiRow>
    </Section>

    <Section Title="Phase envelope, Peng-Robinson">
        <Chart Rows="r.Rows" X="Temperature:°F" Series="Bubble:psia + Dew:psia" Height="320" YMin="0" LogYBox="false" />
    </Section>

    <Notes Text="@Method" />
</Page>

@code {
    // The documented volatile oil (58 % methane); the slider trades methane against the rest, which keep their proportions.
    double Methane = 0.58;
    double Temperature = 220;

    static readonly Component[] Components = ComponentDatabase.Get(["nitrogen", "CO2", "H2S", "methane", "ethane", "propane", "i-butane", "n-butane", "i-pentane", "n-pentane", "n-hexane"])
        .Concat(new Component[]
        {
            new("C7", 547.6, 3.124e6, 0.280, 0.0960), new("C8", 575.6, 2.889e6, 0.312, 0.1070), new("C9", 604.2, 2.641e6, 0.348, 0.1210),
            new("C10", 626.7, 2.419e6, 0.385, 0.1340), new("C12", 668.3, 2.082e6, 0.492, 0.1610), new("C16", 741.7, 1.627e6, 0.638, 0.2220),
        })
        .ToArray();

    static readonly double[] Base = [0.0021, 0.0187, 0.0004, 0.5800, 0.0750, 0.0430, 0.0090, 0.0210, 0.0090, 0.0130, 0.0150, 0.0400, 0.0400, 0.0300, 0.0250, 0.0480, 0.0308];

    const double Psi = 6894.757;

    static double DegF(double kelvin) => kelvin * 1.8 - 459.67;

    record Row(double Temperature, double Bubble, double Dew);

    record Result(IReadOnlyList<Row> Rows, double SaturationPressure, string Kind, double CriticalT, double CriticalP, double Cricondenbar, double Cricondentherm);

    Result Compute()
    {
        var z = Base.Select((v, i) => i == 3 ? Methane : v * (1 - Methane) / (1 - Base[3])).ToArray();
        var eos = CubicEoSBuilder.PengRobinson(Components);
        var feed = Mixture.FromFractions(Components, z);
        var envelope = new PhaseEnvelope(eos, feed, new HeidemannKhalilCriticalPointSolver()) { Pmax = 60e6 }.Calculate();

        // Both branches run from low pressure up to the critical point: the bubble curve in that order, the dew curve back down.
        var rows = new List<Row>();
        for (var i = 0; i < envelope.BubbleT.Length; i++)
        {
            if (DegF(envelope.BubbleT[i]) >= 0) rows.Add(new Row(Math.Round(DegF(envelope.BubbleT[i]), 1), Math.Round(envelope.BubbleP[i] / Psi), double.NaN));
        }

        for (var i = envelope.DewT.Length - 1; i >= 0; i--)
        {
            rows.Add(new Row(Math.Round(DegF(envelope.DewT[i]), 1), double.NaN, Math.Round(envelope.DewP[i] / Psi)));
        }

        double psat = double.NaN;
        var kind = "single phase at every pressure";
        try
        {
            var sat = new Saturation(eos, feed).FindPressure((Temperature - 32) / 1.8 + 273.15);
            psat = sat.P / Psi;
            kind = sat.Kind.ToString() == "Bubble" ? "a bubble point" : "a dew point";
        }
        catch (Exception)
        {
        }

        return new Result(rows, psat, kind, DegF(envelope.CriticalT), envelope.CriticalP / Psi, envelope.CricondenbarP / Psi, DegF(envelope.CricondenthermT));
    }

    const string Method = "Peng-Robinson (1976) with the component database for N2 to C6 and six C7+ pseudo-components, no binary interaction coefficients and no volume translation. The envelope is traced by the library's Michelsen calculator and the critical point found by Heidemann-Khalil; the saturation pressure at the reservoir temperature comes from Saturation.FindPressure, which decides for itself whether it is a bubble or a dew point.";
}