Well test bench
A drawdown-buildup test designer: choose a boundary model and the test's inputs, and read a log-log Bourdet diagnostic, a Horner plot and the test's history. It then interprets its own synthetic response as an engineer would read field data, and compares the result with the inputs, on Team76.Engineering's PTA models.
- UC-PTA-001
- UC-PTA-005
- UC-PTA-007
- UC-PTA-009
Open in the workbench Open the live page
Live preview
Engineering use cases UC-PTA-001 (Analyze Drawdown Test), UC-PTA-005 (Detect Boundary Effects), UC-PTA-007 (Generate Diagnostic Plot) and UC-PTA-009 (Interpret Flow Regimes). The scripts pta-drawdown-semilog, pta-boundary-signatures and pta-wellbore-storage work the same readings by hand.
Source well-test-bench.dashboard
@using System.Globalization
@using System.Threading
@using Team76.Engineering.DCA.Diagnostics
@using Team76.Engineering.PTA.Boundaries
@using Team76.Engineering.PTA.Models
<Page MaxWidth="Wide">
<PageHeader Eyebrow="Pressure transient analysis" Title="Drawdown-buildup test designer"
Subtitle="Design a single-rate drawdown and a shut-in, choose a reservoir boundary model, and read the diagnostic plots.">
<Status><CalcStatus Of="Run" /></Status>
</PageHeader>
<Rail Width="310" Sticky="true">
<Inputs>
<Section Title="Boundary model" Icon="inputs">
<ToggleGroup Options="Models" @bind-Value="Boundary" Text="m => m.Name">
<Template Context="m">
<Sketch Path="@m.Solid" DashedPath="@m.Dashed" FilledPath="M18.5 15a3.5 3.5 0 1 0 7 0a3.5 3.5 0 1 0 -7 0" />
</Template>
</ToggleGroup>
</Section>
<Section Title="Test design" Icon="inputs">
<Parameter Label="Flow rate" Symbol="q" Unit="STB/d" @bind-Value="Q" Min="50" Max="5000" Step="10" />
<Parameter Label="Drawdown duration" Symbol="tp" Unit="h" @bind-Value="Tp" Min="2" Max="500" Step="1" />
<Parameter Label="Shut-in duration" Symbol="Δt" Unit="h" @bind-Value="Dt" Min="2" Max="500" Step="1" />
<Parameter Label="Initial pressure" Symbol="pi" Unit="psi" @bind-Value="Pi" Min="500" Max="15000" Step="50" />
</Section>
<Section Title="Reservoir and well" Icon="inputs">
<Parameter Label="Permeability" Symbol="k" Unit="mD" @bind-Value="K" Min="0.5" Max="2000" Step="0.5" />
<Parameter Label="Skin" Symbol="S" @bind-Value="S" Min="-5" Max="30" Step="0.5" />
<Parameter Label="Net pay" Symbol="h" Unit="ft" @bind-Value="H" Min="5" Max="500" Step="1" />
<Parameter Label="Porosity" Symbol="φ" Unit="frac" @bind-Value="Phi" Min="0.03" Max="0.35" Step="0.01" />
<Parameter Label="Wellbore storage" Symbol="C" Unit="bbl/psi" @bind-Value="C" Min="0.001" Max="0.1" Step="0.001" />
<Parameter Label="Wellbore radius" Symbol="rw" Unit="ft" @bind-Value="Rw" Min="0.15" Max="0.6" Step="0.001" />
@if (Boundary.Lines >= 1)
{
<Parameter Label="Distance to boundary 1" Symbol="L1" Unit="ft" @bind-Value="L1" Min="50" Max="5000" Step="10" />
}
@if (Boundary.Lines >= 2)
{
<Parameter Label="Distance to boundary 2" Symbol="L2" Unit="ft" @bind-Value="L2" Min="50" Max="5000" Step="10" />
}
</Section>
<Section Title="Fluid" Icon="inputs">
<Parameter Label="Oil viscosity" Symbol="μ" Unit="cP" @bind-Value="Mu" Min="0.1" Max="50" Step="0.05" />
<Parameter Label="Formation volume factor" Symbol="B" Unit="bbl/STB" @bind-Value="B" Min="1" Max="2.5" Step="0.01" />
<Parameter Label="Total compressibility" Symbol="ct" Unit="1e-6/psi" @bind-Value="Ct" Min="2" Max="50" Step="0.5" />
</Section>
</Inputs>
<Results>
<Calc Of="Run" Input="@Current" Context="r" Title="Well test">
<Section Title="Interpretation" Icon="value">
<KpiRow>
@if (r.Reading is { } read)
{
<Value Label="Interpreted k" Number="@read.K" Unit="mD" Format="@(read.K < 10 ? "F2" : "F1")"
Status="@Grade(read.KError, 5, 15)" StatusText="@Signed(read.KError, "F1", "% vs input")" />
<Value Label="Interpreted skin" Number="@read.S" Format="F2"
Status="@Grade(read.S - r.Inputs.S, 0.5, 1.5)" StatusText="@Signed(read.S - r.Inputs.S, "F2", " vs input")" />
<Value Label="p* (Horner)" Number="@read.PStar" Unit="psi" Format="N0"
Note="@(Inv($"pi {r.Inputs.Pi:N0}, difference {read.PStar - r.Inputs.Pi:N0} psi"))" />
}
else
{
<Value Label="Interpreted k" Number="double.NaN" Note="No radial flow in this buildup: lengthen it, or reduce storage" />
}
<Value Label="End of storage" Number="@r.EndOfStorage" Unit="h" Format="@HoursFormat(r.EndOfStorage)" Note="(200 000 + 12 000 S) C μ / kh" />
<Value Label="Radius investigated" Number="@r.Radius" Unit="ft" Format="N0" Note="at the end of the drawdown" />
</KpiRow>
</Section>
<Section Title="Log-log diagnostic" Icon="chart">
<Actions><Segmented Options="Periods" @bind-Value="Period" /></Actions>
<ChildContent>
@{ var shown = Period == "Buildup" ? r.Buildup : r.Drawdown; var window = Period == "Buildup" ? r.BuildupWindow : r.DrawdownWindow; }
<DiagnosticPlot Rows="shown" Time="T:h" Pressure="Dp:psi" Derivative="Derivative:psi"
Reference="@(r.Inputs.Boundary.Lines > 0 ? "Infinite:psi" : null)" Guides="false" Height="380" ReadoutExtra="Extra">
@if (window is { } w)
{
<Band XFrom="w.From" XTo="w.To" />
<HLine Y="w.Level" Text="@(Inv($"radial, Δp′ = {w.Level:F1} psi"))" />
@if (r.Inputs.Boundary.Level is { } level)
{
<HLine Y="@(w.Level * level)" Text="@(Inv($"{level}× radial"))" />
}
}
<Slope Gradient="1" X="r.StorageAt" Y="@(r.StorageSlope * r.StorageAt)" Text="unit slope, storage" />
@for (var b = 0; b < r.Inputs.Boundary.Lines; b++)
{
<VLine X="@r.BoundaryFelt[b]" Text="@(Inv($"L{b + 1} felt, {r.BoundaryFelt[b]:F1} h"))" />
}
</DiagnosticPlot>
</ChildContent>
</Section>
<Grid MinWidth="420">
<Section Title="Horner plot" Icon="chart">
<HornerPlot Rows="r.Horner" TimeRatio="Ratio" Pressure="Pws:psi" Extrapolated="r.Reading?.PStar">
@if (r.Reading is { } line)
{
<Slope Gradient="@(-line.M)" X="1" Y="line.PStar" Text="@(Inv($"m = {line.M:F1} psi/cycle"))" />
}
</HornerPlot>
</Section>
<Section Title="Test history" Icon="chart">
<RateHistory Rows="r.History" Time="Time:h" Pressure="Pressure:psi" Rate="Rate:STB/d" Height="130">
<VLine X="r.Inputs.Tp" Text="shut-in" />
</RateHistory>
</Section>
</Grid>
<Grid MinWidth="420">
<Section Title="Interpretation check" Icon="table">
<Table Rows="r.Checks" Columns="Quantity, Input, Interpreted, Difference, Method" Filter="false" FileName="interpretation-check"
CellStatus="@((column, value) => column == "Difference" ? Graded(r.Checks, value as string) : null)" />
</Section>
<Section Title="Calculation record" Icon="notes">
<CalcTrace Of="Run" Lines="6" />
</Section>
</Grid>
</Calc>
<Notes Text="@Method" />
</Results>
</Rail>
</Page>
@code {
record Model(string Name, int Lines, int? Level, string Solid, string Dashed);
static readonly Model[] Models =
[
new("Infinite", 0, null, null, null),
new("Sealing fault", 1, 2, "M38 3v28", null),
new("Constant P", 1, null, null, "M38 3v28"),
new("90° faults", 2, 4, "M38 3v24M6 27h32", null),
new("90° const P", 2, null, null, "M38 3v24M6 27h32"),
new("Fault + const P", 2, null, "M38 3v24", "M6 27h32"),
];
static readonly string[] Periods = ["Buildup", "Drawdown"];
string Period = Periods[0];
Model Boundary = Models[1];
double Q = 500, Tp = 48, Dt = 72, Pi = 5000;
double K = 50, S = 3, H = 60, Phi = 0.18, C = 0.01, Rw = 0.354, L1 = 400, L2 = 900;
double Mu = 0.9, B = 1.25, Ct = 12;
Inputs Current => new(Boundary, Q, Tp, Dt, Pi, K, S, H, Phi, C, Rw, L1, L2, Mu, B, Ct);
readonly Calculation<Inputs, Output> Run = new(Compute, TimeSpan.FromMilliseconds(200));
record Inputs(Model Boundary, double Q, double Tp, double Dt, double Pi, double K, double S, double H, double Phi, double C, double Rw, double L1, double L2, double Mu, double B, double Ct)
{
public double CtPerPsi => Ct * 1e-6;
public override string ToString() =>
Inv($"{Boundary.Name}: q {Q:G6}, tp {Tp:G6}, Δt {Dt:G6}, pi {Pi:G6}, k {K:G6}, S {S:G6}, h {H:G6}, φ {Phi:G6}, C {C:G6}, rw {Rw:G6}, L1 {L1:G6}, L2 {L2:G6}, μ {Mu:G6}, B {B:G6}, ct {Ct:G6}");
}
record Point(double T, double Dp, double Derivative, double Infinite, double Pws, double Ri);
record HornerRow(double Ratio, double Pws);
record HistoryRow(double Time, double Pressure, double Rate);
record Window(double Level, double From, double To);
record Reading(double K, double KError, double Kh, double M, double PStar, double S);
record Check(string Quantity, string Input, string Interpreted, string Difference, string Grade, string Method);
record Output(Inputs Inputs, IReadOnlyList<Point> Drawdown, IReadOnlyList<Point> Buildup, IReadOnlyList<HornerRow> Horner,
IReadOnlyList<HistoryRow> History, Window DrawdownWindow, Window BuildupWindow, Reading Reading, IReadOnlyList<Check> Checks,
double EndOfStorage, double Radius, double[] BoundaryFelt, double StorageSlope, double StorageAt);
// What a page writes reads the same on any machine, as the kit's own numbers do.
static string Inv(FormattableString text) => text.ToString(CultureInfo.InvariantCulture);
// By the text in the cell: two rows that read the same are graded the same.
static string Graded(IReadOnlyList<Check> checks, string difference) => checks.FirstOrDefault(c => c.Difference == difference)?.Grade;
static string Grade(double difference, double good, double warn) =>
Math.Abs(difference) < good ? "good" : Math.Abs(difference) < warn ? "warn" : "bad";
// Signed as it reads, as a Value's change is: what rounds to nothing has no sign.
static string Signed(double value, string format, string unit)
{
var text = value.ToString(format, CultureInfo.InvariantCulture);
return (text.Any(c => c is >= '1' and <= '9') ? (value > 0 ? "+" + text : text) : text.TrimStart('-')) + unit;
}
static string HoursFormat(double hours) => hours < 0.1 ? "F3" : hours < 10 ? "F2" : hours < 100 ? "F1" : "F0";
static string Extra(Point p) => Inv($"ri {p.Ri:N0} ft");
static PtaModel Build(Inputs v, Model model)
{
var fluid = new Fluid { Ul = v.Mu, B = v.B };
var well = new Well { Rw = v.Rw, C = v.C, SkinFactor = v.S };
var reservoir = new Reservoir { K = v.K, H = v.H, Porosity = v.Phi, Ct = v.CtPerPsi };
BoundaryBase boundary = model.Name switch
{
"Sealing fault" => new LinearSealingFaultBoundary(v.Rw, v.L1),
"Constant P" => new LinearConstantPressureBoundary(v.Rw, v.L1),
"90° faults" => new PerpendicularSealingFaultsBoundary(v.Rw, v.L1, v.L2),
"90° const P" => new PerpendicularConstantPressuresBoundary(v.Rw, v.L1, v.L2),
"Fault + const P" => new PerpendicularMixedBoundaries(v.Rw, v.L1, v.L2),
_ => null,
};
return boundary is null ? new PtaModel(fluid, well, reservoir) : new PtaModel(fluid, well, reservoir, boundary);
}
static double[] LogSpace(double from, double to, int count) =>
[.. Enumerable.Range(0, count).Select(i => Math.Exp(Math.Log(from) + (Math.Log(to) - Math.Log(from)) * i / (count - 1)))];
static (double[] T, double[] Dp, double[] Derivative) Drawdown(PtaModel model, Inputs v, double[] times, CancellationToken token)
{
var keep = times.Select(t =>
{
token.ThrowIfCancellationRequested();
return (T: t, Dp: model.PressureDrop(t, v.Q));
}).Where(p => p.Dp > 0).ToArray();
double[] t = [.. keep.Select(p => p.T)];
double[] dp = [.. keep.Select(p => p.Dp)];
return (t, dp, keep.Length > 2 ? BourdetDerivative.CalculateAllSemiLog(t, dp, 0.15) : new double[keep.Length]);
}
// A shut-in is the rate and minus the rate from tp on. Its derivative is against Agarwal's equivalent time, plotted against Δt.
static (double[] T, double[] Dp, double[] Pws, double[] Derivative) Shutin(PtaModel model, Inputs v, double[] times, double atTp, CancellationToken token)
{
Tuple<double, double>[] rates = [Tuple.Create(0.0, v.Q), Tuple.Create(v.Tp, 0.0)];
var keep = times.Select(dt =>
{
token.ThrowIfCancellationRequested();
var drop = model.PressureDrop(v.Tp + dt, rates);
return (T: dt, Te: v.Tp * dt / (v.Tp + dt), Dp: atTp - drop, Pws: v.Pi - drop);
}).Where(p => p.Dp > 0).ToArray();
double[] te = [.. keep.Select(p => p.Te)];
double[] dp = [.. keep.Select(p => p.Dp)];
return ([.. keep.Select(p => p.T)], dp, [.. keep.Select(p => p.Pws)], keep.Length > 2 ? BourdetDerivative.CalculateAllSemiLog(te, dp, 0.15) : new double[keep.Length]);
}
// The radial level: the median derivative between storage and the first boundary. Where the test never shows one there is
// none to read: the least derivative after storage could be a constant-pressure boundary's fall towards zero, and a
// permeability read from that is off by orders of magnitude and looks like a result.
static Window Pick(IReadOnlyList<Point> points, double endOfStorage, double boundaryAt, double periodEnd)
{
var (lo, hi) = (endOfStorage * 1.5, Math.Min(boundaryAt, periodEnd * 0.8));
var inside = points.Where(p => p.Derivative > 0 && p.T >= lo && p.T <= hi).ToList();
if (inside.Count < 2)
{
return null;
}
var sorted = inside.Select(p => p.Derivative).Order().ToList();
return new Window(sorted[sorted.Count / 2], inside[0].T, inside[^1].T);
}
static Output Compute(Inputs v, CancellationToken token)
{
const int Count = 36;
var model = Build(v, v.Boundary);
double[] drawdownTimes = LogSpace(1e-3, v.Tp, Count);
double[] shutinTimes = LogSpace(1e-3, v.Dt, Count);
var atTp = model.PressureDrop(v.Tp, v.Q);
var dd = Drawdown(model, v, drawdownTimes, token);
var bu = Shutin(model, v, shutinTimes, atTp, token);
// The reference: the same well with no boundary, whose derivative shows what the boundary changed.
var riFactor = v.K / (v.Phi * v.Mu * v.CtPerPsi);
var (ddReference, buReference) = (dd.T.Select(_ => double.NaN).ToArray(), bu.T.Select(_ => double.NaN).ToArray());
if (v.Boundary.Lines > 0)
{
var infinite = Build(v, Models[0]);
var iDd = Drawdown(infinite, v, drawdownTimes, token);
var iBu = Shutin(infinite, v, shutinTimes, infinite.PressureDrop(v.Tp, v.Q), token);
ddReference = [.. dd.T.Select(t => Nearest(iDd.T, iDd.Derivative, t))];
buReference = [.. bu.T.Select(t => Nearest(iBu.T, iBu.Derivative, t))];
}
Point[] drawdown = [.. dd.T.Select((t, i) => new Point(t, dd.Dp[i], dd.Derivative[i], ddReference[i], v.Pi - dd.Dp[i], 0.029 * Math.Sqrt(riFactor * t)))];
Point[] buildup = [.. bu.T.Select((t, i) => new Point(t, bu.Dp[i], bu.Derivative[i], buReference[i], bu.Pws[i], 0.029 * Math.Sqrt(riFactor * t)))];
var storage = (200000 + 12000 * v.S) * v.C / (v.K * v.H / v.Mu);
double[] felt = [3800 * v.Phi * v.Mu * v.CtPerPsi * v.L1 * v.L1 / v.K, 3800 * v.Phi * v.Mu * v.CtPerPsi * v.L2 * v.L2 / v.K];
var boundaryAt = v.Boundary.Lines switch { 0 => double.PositiveInfinity, 1 => felt[0] * 0.5, _ => Math.Min(felt[0], felt[1]) * 0.5 };
var buildupWindow = Pick(buildup, storage, boundaryAt, v.Dt);
var drawdownWindow = Pick(drawdown, storage, boundaryAt, v.Tp);
var reading = Read(v, buildup, buildupWindow, atTp);
List<HistoryRow> history = [new(0, v.Pi, v.Q)];
history.AddRange(drawdown.Select(p => new HistoryRow(p.T, p.Pws, v.Q)));
history.Add(new(v.Tp, v.Pi - atTp, 0));
history.AddRange(buildup.Select(p => new HistoryRow(v.Tp + p.T, p.Pws, 0)));
return new Output(v, drawdown, buildup, [.. buildup.Select(p => new HornerRow((v.Tp + p.T) / p.T, p.Pws))],
history, drawdownWindow, buildupWindow, reading, Checks(v, reading),
storage, 0.029 * Math.Sqrt(v.K * v.Tp / (v.Phi * v.Mu * v.CtPerPsi)), felt, v.Q * v.B / (24 * v.C), 1e-3);
}
static double Nearest(double[] xs, double[] ys, double x)
{
if (xs.Length == 0)
{
return double.NaN;
}
var best = 0;
for (var i = 1; i < xs.Length; i++)
{
if (Math.Abs(Math.Log(xs[i] / x)) < Math.Abs(Math.Log(xs[best] / x)))
{
best = i;
}
}
return ys[best];
}
// The way an engineer reads field data: k from the buildup's radial derivative level, m and p* from the semilog line through
// a point of that window, S from p at 1 h. All of it from the one window, or a p* drawn from a point in storage looks as good.
static Reading Read(Inputs v, IReadOnlyList<Point> buildup, Window radial, double atTp)
{
if (radial is null)
{
return null;
}
var kh = 70.6 * v.Q * v.B * v.Mu / radial.Level;
var k = kh / v.H;
var m = 2.303 * radial.Level;
var inside = buildup.Where(p => p.T >= radial.From && p.T <= radial.To).ToList();
var anchor = inside[inside.Count / 2];
var pStar = anchor.Pws + m * Math.Log10((v.Tp + anchor.T) / anchor.T);
var pOneHour = pStar - m * Math.Log10(v.Tp + 1);
var pwf = v.Pi - atTp;
var skin = 1.151 * ((pOneHour - pwf) / m - Math.Log10(k / (v.Phi * v.Mu * v.CtPerPsi * v.Rw * v.Rw)) + 3.23);
return new Reading(k, 100 * (k - v.K) / v.K, kh, m, pStar, skin);
}
static IReadOnlyList<Check> Checks(Inputs v, Reading r)
{
if (r is null)
{
return [];
}
var dKh = 100 * (r.Kh - v.K * v.H) / (v.K * v.H);
var theory = 2.303 * 70.6 * v.Q * v.B * v.Mu / (v.K * v.H);
var dM = 100 * (r.M - theory) / theory;
var dS = r.S - v.S;
var dP = r.PStar - v.Pi;
return
[
new("Permeability k, mD", Inv($"{v.K:F1}"), Inv($"{r.K:F2}"), Signed(r.KError, "F1", "%"), Grade(r.KError, 5, 15), "70.6 qBμ / (h Δp′)"),
new("Flow capacity kh, mD ft", Inv($"{v.K * v.H:N0}"), Inv($"{r.Kh:N0}"), Signed(dKh, "F1", "%"), Grade(dKh, 5, 15), "radial derivative level"),
new("Skin S", Inv($"{v.S:F2}"), Inv($"{r.S:F2}"), Signed(dS, "F2", ""), Grade(dS, 0.5, 1.5), "Horner p at 1 h"),
new("Semilog slope m, psi/cycle", Inv($"{theory:F1}"), Inv($"{r.M:F1}"), Signed(dM, "F1", "%"), Grade(dM, 5, 15), "2.303 Δp′"),
new("Extrapolated p*, psi", Inv($"{v.Pi:N0} (pi)"), Inv($"{r.PStar:N0}"), Signed(dP, "F0", " psi"), v.Boundary.Lines == 0 ? Grade(dP, 10, 50) : null, v.Boundary.Lines == 0 ? "Horner at ratio 1" : "boundaries shift p* from pi"),
];
}
const string Method = "Field units. A vertical well in a homogeneous reservoir, with constant wellbore storage and skin and a single-phase, slightly compressible liquid. The buildup derivative is taken against Agarwal's equivalent time tp Δt / (tp + Δt) and plotted against Δt. Boundary-felt times use t ≈ 3 800 φμct L² / k. The radius of investigation is 0.029 √(k t / φμct).";
}