Simulate a constant composition expansion on a volatile oil

A 17-component volatile oil on Peng–Robinson: its saturation pressure at 220 °F, found without saying whether it is a bubble or a dew point, then the CCE from 6,000 to 1,000 psia with relative volume, liquid dropout and the Y-function.

Open in the workbench

Engineering use case: Thermodynamics, Layer 2, Constant Composition Expansion (CCE), with the Saturation Point Functions of Layer 3.

A CCE is the first experiment in a PVT report: the cell holds the reservoir fluid at reservoir temperature, the pressure is stepped down, and the total volume is read against the volume at the saturation pressure. Each step is one isothermal flash of the unchanged feed. Saturation.FindPressure decides the kind of saturation point itself; CCE.Calculate reports V/Vsat, the liquid volume fraction and whether each step is two-phase. The fluid is the documented volatile oil: 58 % methane, N₂ to C₆ from the component database and C₇+ as six pseudo-components with their own Tc, Pc, ω and molar mass.

What an engineer learns from it: the saturation point at 220 °F is a bubble point, 3,347 psia, and Σ z·K there is 1, the bubble-point condition. Above it V/Vsat is below 1 and rises smoothly: the compressibility read from the 4,000 and 3,500 psia volumes is about 5.6 × 10⁻⁵ 1/psi, high, as a volatile oil's is. Below it the volume grows fast as gas comes out, to three times Vsat at 1,000 psia, with the liquid down to 18 % of the cell: that steep dropout is what makes a volatile oil volatile. The Y-function, (Psat − P)/(P (V/Vsat − 1)), is what a lab uses to smooth the two-phase volumes; on a black oil it is close to a straight line in pressure.

Units: the library works in K and Pa; the script converts to °F and psia. This is an untuned Peng–Robinson model without volume translation: the saturation pressure and the shape of the CCE are its strengths, the absolute liquid density is not.

Source

using System;
using System.Linq;
using Team76.Engineering.Thermodynamics.Eos.Builders;
using Team76.Engineering.Thermodynamics.Experiments;
using Team76.Engineering.Thermodynamics.Flash;
using Team76.Engineering.Thermodynamics.Models;

public class S : ICalcScript
{
    public ScriptResult Run(ICalcContext ctx)
    {
        const double Psi = 6894.757;   // Pa per psi

        // A volatile oil: N2, CO2, H2S, C1 to C6 from the database, C7+ as six pseudo-components (Tc K, Pc Pa, ω, Mw kg/mol).
        var plus = 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),
        };
        var components = ComponentDatabase.Get(["nitrogen", "CO2", "H2S", "methane", "ethane", "propane", "i-butane", "n-butane", "i-pentane", "n-pentane", "n-hexane"])
            .Concat(plus).ToArray();
        double[] z = [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];
        var eos = CubicEoSBuilder.PengRobinson(components);
        var feed = Mixture.FromFractions(components, z);

        // Reservoir temperature 220 °F. The saturation pressure first, without saying whether it is a bubble or a dew point.
        var tres = (220 - 32) / 1.8 + 273.15;
        var sat = new Saturation(eos, feed).FindPressure(tres);

        // The CCE at reservoir temperature, with the saturation pressure itself among the steps.
        var psia = new[] { 6000.0, 5000, 4500, 4000, 3500, sat.P / Psi, 3000, 2500, 2000, 1500, 1000 };
        var cce = new CCE(eos, feed).Calculate(tres, psia.Select(p => p * Psi).ToArray());

        var psat = sat.P / Psi;
        var rows = Enumerable.Range(0, psia.Length).Select(i =>
        {
            var vrel = cce.RelativeVolumes[i];
            // Standing's Y-function, (Psat − P) / (P (Vrel − 1)), read below the saturation pressure only.
            object y = cce.IsTwoPhase[i] ? Math.Round((psat - psia[i]) / (psia[i] * (vrel - 1)), 3) : "";
            return new object[] { Math.Round(psia[i]), Math.Round(vrel, 4), Math.Round(cce.LiquidVolumeFraction[i] * 100, 1), cce.IsTwoPhase[i] ? "two-phase" : "liquid", y };
        }).ToList();

        // Undersaturated compressibility from the CCE volumes between 4,000 and 3,500 psia: co = −ln(V2/V1) / (p2 − p1).
        var co = -Math.Log(cce.RelativeVolumes[4] / cce.RelativeVolumes[3]) / (psia[4] - psia[3]);

        return ctx.Result()
            .Set("Saturation pressure (psia)", Math.Round(psat))
            .Set("Saturation kind", sat.Kind.ToString())
            .Set("Σ z·K at the saturation pressure", Math.Round(z.Zip(sat.Saturation.K, (zi, k) => zi * k).Sum(), 4))
            .Set("Relative volume at 1,000 psia", Math.Round(cce.RelativeVolumes[^1], 3))
            .Set("Liquid at 1,000 psia (% of volume)", Math.Round(cce.LiquidVolumeFraction[^1] * 100, 1))
            .Set("co, 4,000 to 3,500 psia (1/psi)", Math.Round(co, 8))
            .Set("CCE at 220 °F", new ScriptTable(["P (psia)", "V/Vsat", "Liquid (% vol)", "State", "Y-function"], rows))
            .Set("Relative volume", new ScriptChart(psia, cce.RelativeVolumes, title: "Constant composition expansion at 220 °F", xLabel: "P (psia)", yLabel: "V/Vsat"));
    }
}