Find the well's operating point
Hagedorn & Brown outflow against generalized Vogel inflow, intersected by the operating-point solver: the bottom-hole pressure where what the reservoir gives meets what the tubing can lift.
The node is at the bottom of the hole. InflowPerformanceCurve gives a rate for a flowing pressure; MultiPhaseLiftCurve gives the flowing pressure the tubing needs to lift that rate to the wellhead. OperatingPointSolver.Solve sweeps the rate range, finds every rate where the two agree, and refines each one. The plot shows both curves, and the operating point is where they cross. The dip in the outflow curve at low rates is the liquid holding up in the tubing. A crossing on its falling side is unstable: the well loads up there rather than settling. The solver returns such crossings in UnstableCrossings and the stable one as OperatingPoint, and this well has one of each.
Units are field throughout: psia, STB/d for oil, ft and inches for the pipe. The lift curve takes the producing GOR (500 scf/STB here) and an optional water cut, and works out the gas and liquid rates the correlation needs from the oil rate.
Hagedorn & Brown is a near-vertical correlation; for a deviated well use FlowModelBuilder.BeggsAndBrill or another that takes the inclination. OperatingPoint is null when there is no stable crossing, so read it through HasOperatingPoint. The script then says why under Verdict: only unstable crossings (the well loads up), no crossing where the correlation is defined (UndefinedSampleCount above zero: it refused some rates, and no crossing is inferred across them), or none at all (the well does not flow on its own). The plot is drawn either way, over the solver's own range: no flow to the open-flow rate. ChokedOperatingPointSolver does the same with a wellhead choke in front of the tubing.
Source
using System;
using System.Collections.Generic;
using System.Linq;
using Team76.Engineering.Core.Measures;
using Team76.Engineering.Orchestration.Nodal;
using Team76.Engineering.VFP.Builders;
using Team76.Engineering.VFP.Models;
using Team76.Engineering.VFP.Providers;
public class S : ICalcScript
{
public ScriptResult Run(ICalcContext ctx)
{
// Outflow: Hagedorn & Brown up 8,000 ft of 2.992" tubing, from 200 psia at the wellhead, at a GOR of 500 scf/STB.
var tubing = FlowModelBuilder.HagedornAndBrown(
new Pipe(Length.FromFeet(8000), Angle.FromDegrees(90),
Roughness.From(0.0006), Length.FromInches(2.992)),
new TraverseFluidProvider(GasSpecificGravity.From(0.7),
Density.FromLbPerFt3(53), Viscosity.FromCP(1.2),
InterfacialTension.FromDynesPerCm(30), Temperature.FromDegF(180)));
var lift = new MultiPhaseLiftCurve(tubing, Pressure.FromPsi(200), SolutionRelation.FromScfPerStb(500));
// Inflow: generalized Vogel, PI 1.5 STB/(psi.d), 3,000 psia reservoir, 2,200 psia bubble point.
var inflow = InflowPerformanceCurve.GeneralizedVogel(1.5, Pressure.FromPsi(3000), Pressure.FromPsi(2200));
// Where they cross. OperatingPoint is the stable crossing, and null when there is none.
var nodal = OperatingPointSolver.Solve(inflow, lift);
var point = nodal.HasOperatingPoint ? nodal.OperatingPoint : null;
// The two curves the solver intersected, over the ranges it swept: from no flow to the open-flow rate.
var reservoir = inflow.ReservoirPressure.Psi;
var pressures = Enumerable.Range(0, 21).Select(i => reservoir * i / 20).ToArray();
var inflowRates = pressures.Select(p => inflow.RateAt(Pressure.FromPsi(p)).BblPerD).ToArray();
var outflowRates = new List<double>();
var outflowPressures = new List<double>();
// Outflow from near no flow, closest at low rates: the dip where liquid holds up in the tubing, and the unstable
// crossing on its falling side, are within the first few percent of the open-flow rate.
foreach (var rate in Enumerable.Range(1, 30).Select(i => inflow.MaximumRate.BblPerD * i * i / 900))
{
try
{
outflowPressures.Add(lift.RequiredInletPressure(FlowRate.FromBblPerD(rate)).Psi);
outflowRates.Add(rate);
}
catch (ArgumentOutOfRangeException)
{
// A rate the tubing correlation refuses: the solver skips it too.
}
}
var plot = new ScriptChart(
[new ScriptSeries("Inflow (Vogel)", inflowRates, pressures),
new ScriptSeries("Outflow (tubing)", [.. outflowRates], [.. outflowPressures])],
title: "Nodal analysis", xLabel: "Oil rate (STB/d)", yLabel: "Flowing bottom-hole pressure (psia)");
var result = ctx.Result()
.Set("Operating point", plot)
.Set("Unstable crossings", nodal.UnstableCrossings.Count);
if (point is null)
{
return result.Set("Verdict",
nodal.UnstableCrossings.Count > 0 ? "No stable crossing: where the curves meet, the well loads up rather than settling."
: nodal.UndefinedSampleCount > 0 ? $"No crossing where the curves are defined: the correlation refused {nodal.UndefinedSampleCount} of the rates swept."
: "No crossing: the well does not flow on its own at these conditions.");
}
return result
.Set("Flowing pressure (psia)", Math.Round(point.FlowingPressure.Psi, 1))
.Set("Rate (STB/d)", Math.Round(point.Rate.BblPerD, 1));
}
}