Flash a wellstream and read its phases
A light-oil wellstream, 1,000 kmol/h of nitrogen through n-eicosane, flashed at the HP separator's 30 bar and 66.5 °C: each phase's mole fraction, molar mass, density, viscosity and flows, and the PH flash that gives the vapour's temperature back from its enthalpy.
- UC-PROCESS-001
- UC-PROCESS-002
Engineering use cases UC-PROCESS-001 (Flash a feed and read the stream) and UC-PROCESS-002 (Recover temperature from a known enthalpy).
A process model starts from a stream: one fluid package (FluidBuilder, Peng–Robinson with estimated kij and the Jhaveri–Youngren volume shift) and one TP flash (MaterialStream.FromTP) of the component molar flows. The stream is what every later unit reads: temperature in K, pressure in Pa, molar enthalpy, and a MaterialPhase per phase with its fraction, molar mass, density, viscosity, and mass and actual volumetric flow. A heater or compressor specifies enthalpy, not temperature; MaterialStream.FromPH is the inverse flash that returns it.
What an engineer learns from it: at 30 bar and 66.5 °C the 25.1 kg/s stream (90.5 kg/kmol) splits 41 % vapour and 59 % liquid by moles, but 2.4 against 22.7 kg/s by mass. The vapour, 21.1 kg/kmol at 23.9 kg/m³ and 0.0125 cP, fills 364 m³/h; the liquid, 139 kg/kmol at 676 kg/m³ and 0.33 cP, fills 121 m³/h. Those are the numbers a separator is sized on: the density difference sets the vapour's allowable velocity, and the liquid volume sets the residence time. The light ends alone (nitrogen to n-butane) are a single vapour at these conditions, and flashing it again at its own enthalpy, 1,096 J/mol, gives back 339.65 K, the 66.5 °C it started at: the PH flash is the TP flash's inverse.
Units: SI from the stream (K, Pa, J/mol, kg/s, Pa·s), shown as °C, bar, cP and m³/h. The heavy end is three n-paraffins; the database has no parachor for n-hexadecane, so this fluid cannot report an interfacial tension.
Source
using System;
using System.Linq;
using Team76.Engineering.Process;
using Team76.Engineering.Process.Fluids;
public class S : ICalcScript
{
public ScriptResult Run(ICalcContext ctx)
{
// The choke-separation entry's light-oil wellstream, 1,000 kmol/h, Peng-Robinson with the Jhaveri-Youngren shift.
string[] names = ["nitrogen", "carbon dioxide", "methane", "ethane", "propane", "i-butane", "n-butane", "i-pentane", "n-pentane", "n-hexane", "n-heptane", "n-decane", "n-hexadecane", "n-eicosane"];
double[] molePercent = [0.5, 1.5, 38, 7, 5, 1, 2.5, 1, 1.5, 3, 6, 14, 12, 7];
var fluid = FluidBuilder.PengRobinson().Components(names)
.WithKij(KijSource.Estimated()).WithVolumeShift(VolumeShift.JhaveriYoungren).Build();
var flows = molePercent.Select(x => Quantity.KilomolePerHour(10 * x)).ToArray();
// One TP flash at the HP separator's conditions: the stream carries its phases and their properties.
var stream = MaterialStream.FromTP(fluid, Quantity.Celsius(66.5), Quantity.Bar(30), flows);
// The inverse: read the vapour's enthalpy, flash again at (P, H), and get the temperature back.
var dryVapour = MaterialStream.FromTP(fluid, Quantity.Celsius(66.5), Quantity.Bar(30),
[.. flows.Take(7), .. Enumerable.Repeat(Quantity.KilomolePerHour(0), 7)]);
var recovered = MaterialStream.FromPH(fluid, Quantity.Bar(30), Quantity.JoulePerMole(dryVapour.Enthalpy), dryVapour.MolarFlows.Select(Quantity.MolePerSecond).ToArray());
var phases = stream.Phases
.Select(p => new object[]
{
p.Kind.ToString(),
Math.Round(p.Fraction, 4),
Math.Round(1000 * p.MolecularWeight, 2),
Math.Round(p.Density, 1),
Math.Round(1000 * p.Viscosity, 4),
Math.Round(p.MassFlow, 3),
Math.Round(p.VolumetricFlow * 3600, 1),
})
.ToList();
double feedMolarMass = stream.MassFlow / stream.TotalMolarFlow;
return ctx.Result()
.Set("Phases", new ScriptTable(["Phase", "Mole fraction", "Molar mass (kg/kmol)", "Density (kg/m3)", "Viscosity (cP)", "Mass flow (kg/s)", "Actual flow (m3/h)"], phases))
.Set("Temperature (K)", Math.Round(stream.Temperature, 3))
.Set("Pressure (bar)", Math.Round(stream.Pressure / 1e5, 3))
.Set("Total molar flow (mol/s)", Math.Round(stream.TotalMolarFlow, 4))
.Set("Mass flow (kg/s)", Math.Round(stream.MassFlow, 4))
.Set("Feed molar mass (kg/kmol)", Math.Round(1000 * feedMolarMass, 3))
.Set("Vapour mole fraction", Math.Round(stream.Phases.Where(p => p.Kind.ToString() == "Vapor").Sum(p => p.Fraction), 4))
.Set("Light-ends vapour enthalpy (J/mol)", Math.Round(dryVapour.Enthalpy, 1))
.Set("Light-ends vapour, temperature in (K)", Math.Round(dryVapour.Temperature, 6))
.Set("Light-ends vapour, temperature from the PH flash (K)", Math.Round(recovered.Temperature, 6));
}
}