A delayed coker#

difflow_refinery.coking models a delayed coker. Its yields come from the Gary-Handwerk correlations in Conradson carbon (CCR), and its product gravities follow from the correlations’ volume yields. The unit balances sulfur, nitrogen and metals, and it pools several residue feeds before the yield model. This notebook:

  1. runs the unit on a blend of vacuum residue and FCC slurry;

  2. differentiates the yields with respect to feed CCR and the operating levers;

  3. builds a planning block;

  4. compares the AD sensitivities with the published delta-base vectors of the Du et al. (2025) Case 2 cokers, when the benchmark data are available.

The yield correlation (Gary et al. Table 5.5), the gas split, the sulfur and nitrogen distributions and the gas oil split come from Gary et al., ch. 5. The olefins and the operating-lever sensitivities are illustrative. The sources disagree on how coke moves with heater outlet temperature; see the docs.

import jax
import jax.numpy as jnp
import numpy as np
from difflow_refinery.coking import PRODUCTS, CokerFeed, DelayedCoker, coker_block

jax.config.update("jax_enable_x64", True)

vr = CokerFeed.from_properties(8.0, sg=1.03, sulfur_wt=3.5, ccr_wt=22.0,
                               nitrogen_wppm=4000.0, nickel_vanadium_wppm=250.0)
slurry = CokerFeed.from_properties(2.0, sg=1.08, sulfur_wt=1.2, ccr_wt=6.0)
unit = DelayedCoker()
out = unit.solve([vr, slurry])
for k in PRODUCTS:
    print(f"{k:8s} {100 * float(out['yield.' + k]):6.2f} wt%")
print("naphtha SG", round(float(out["naphtha.SG"]), 4), " coke S wt%", round(float(out["coke.S_wt"]), 2),
      " coke Ni+V wppm", round(float(out["coke.NiV_wppm"]), 0))
print("balances", {k: float(v) for k, v in out.items() if k.startswith("balance.")})
dry_gas    5.94 wt%
lpg        3.60 wt%
h2s        0.97 wt%
nh3        0.00 wt%
naphtha   17.74 wt%
diesel    27.01 wt%
gas_oil   14.67 wt%
coke      30.08 wt%
naphtha SG 0.7587  coke S wt% 3.03  coke Ni+V wppm 665.0
balances {'balance.mass': 0.0, 'balance.S': 0.0, 'balance.N': 1.3552527156068805e-16, 'balance.NiV': 0.0}

Sensitivities#

The yields are differentiable with respect to the feed and the operating levers. Each column of the Jacobian below is a delta vector of the kind a planner uses.

def y(x):   # (CCR wt%, drum pressure barg, recycle ratio) -> yields
    feed = CokerFeed.from_properties(1.0, sg=1.03, sulfur_wt=3.5, ccr_wt=x[0])
    return unit.yields(feed, drum_P=x[1], recycle=x[2])

J = jax.jacfwd(y)(jnp.array([22.0, 2.76, 0.05]))   # base drum P: 40 psig (Gary Table 5.5)
print(f"{'product':8s} {'d/dCCR':>9s} {'d/dP':>9s} {'d/dR':>9s}")
for k, row in zip(PRODUCTS, np.asarray(J)):
    print(f"{k:8s} " + " ".join(f"{v:9.5f}" for v in row))

block = coker_block(unit, CokerFeed.blend([vr, slurry]), ["feed.ccr", "drum_P", "recycle"])
print(block.y_names)
product     d/dCCR      d/dP      d/dR
dry_gas    0.00090   0.00205   0.02733
lpg        0.00054   0.00124   0.01654
h2s        0.00000   0.00000   0.00000
nh3        0.00000   0.00000   0.00000
naphtha    0.00343   0.00000   0.00000
diesel    -0.01352  -0.01126  -0.16529
gas_oil   -0.00735  -0.00611  -0.08979
coke       0.01600   0.01408   0.21120
['yield.dry_gas', 'yield.lpg', 'yield.h2s', 'yield.naphtha', 'yield.diesel', 'yield.gas_oil', 'yield.coke', 'naphtha.SG', 'gas_oil.SG', 'coke.S_wt']

Against the Du et al. (2025) Case 2 cokers#

Case 2 of the benchmark has two delta-base delayed cokers. Below are our yields and AD sensitivities at their base feeds, next to the published ones. Coke and its CCR slope agree, and so does H2S and its sulfur slope. Naphtha and gas move with CCR in opposite directions. The correlation has no SG term, so all its SG sensitivities are zero. The benchmark data are downloaded, not shipped; without them this cell only says so.

from difflow_refinery.benchmarks import du2025
from difflow_refinery.benchmarks.du2025.calibration import unit_base

case2 = du2025.find_case(2)
if case2 is None:
    print("Case 2 data not available (du2025.fetch(cases=(2,)) downloads them)")
else:
    data = du2025.load_case(case2)
    b = unit_base(data, "Upd0")
    outlets = {"coke": "s272", "naphtha": "s276", "h2s": "s274"}
    x0 = jnp.array([b.props["Q0"], b.props["Q1"], b.props["Q22"]])     # SG, S, CCR
    f = lambda x: unit.yields(CokerFeed.from_properties(1.0, sg=x[0], sulfur_wt=x[1], ccr_wt=x[2]))
    ours, Jc = np.asarray(f(x0)), np.asarray(jax.jacfwd(f)(x0))
    for k, s in outlets.items():
        i, j = PRODUCTS.index(k), b.outlets.index(s)
        pub = [b.delta[q][j] for q in ("Q0", "Q1", "Q22")]
        print(f"{k:8s} yield {ours[i]:.4f} (published {b.yields[j]:.4f});  "
              f"d/d(SG, S, CCR) ours {np.round(Jc[i], 4)}  published {np.round(pub, 4)}")
Case 2 data not available (du2025.fetch(cases=(2,)) downloads them)

The kinetic yield model (#546)#

CokerParams(yield_model="kinetic") takes the coke from Del Bianco et al.’s lumped scheme (Fuel 72 (1993) 75): VR → distillate (k1), VR → intermediate (k2) → coke (k3), with their Table 3 Arrhenius constants. A drum holds its liquid for hours, so the scheme runs to its long-time limit and the coke is the selectivity k2/(k1 + k2). A2 is scaled so that at the base temperature (462.9 C) the coke equals the correlation’s for any CCR. The kinetics change the temperature response: a hotter drum makes less coke (the direction of Sawarkar et al.’s Table 9; Gary et al.’s Table 5.4 says the opposite), and about 2.5 times more strongly than the correlation’s illustrative lever.

Below: the batch scheme at 450 C against Del Bianco’s Table 2, and the coke yield against coil outlet temperature for both models. Outside 410-470 C reaction temperature the kinetics are extrapolated, and the unit warns.

import warnings
from difflow_refinery.coking import CokerParams, del_bianco_batch

measured = [(3, 1.1, 24.2), (8, 3.1, 44.2), (15, 8.4, 57.7), (30, 17.6, 62.9), (60, 29.7, 63.0),
            (120, 39.0, 60.0)]                     # Table 2, 450 C: (min, coke wt%, distillate wt%)
print(" t min   coke model / measured   distillate model / measured")
for tm, c, d in measured:
    o = del_bianco_batch(723.15, tm)
    print(f"{tm:6d}   {100 * float(o['C']):5.1f} / {c:5.1f}            {100 * float(o['D']):5.1f} / {d:5.1f}")

feed = CokerFeed.from_properties(1.0, sg=1.03, sulfur_wt=3.5, ccr_wt=20.8)
kin, corr = DelayedCoker(CokerParams(yield_model="kinetic")), DelayedCoker()
print("\nCOT C   coke kinetic   coke correlation")
with warnings.catch_warnings():
    warnings.simplefilter("ignore")              # above 470 C the kinetics extrapolate
    for cot in (480.0, 490.0, 495.0, 500.0, 505.0):
        T = cot + 273.15
        print(f"{cot:5.0f}   {100 * float(kin.solve(feed, coil_outlet_T=T)['yield.coke']):6.2f}"
              f"         {100 * float(corr.solve(feed, coil_outlet_T=T)['yield.coke']):6.2f}")
 t min   coke model / measured   distillate model / measured
     3     0.5 /   1.1             22.1 /  24.2
     8     3.0 /   3.1             43.5 /  44.2
    15     7.6 /   8.4             56.6 /  57.7
    30    16.8 /  17.6             63.6 /  62.9
    60    27.6 /  29.7             64.5 /  63.0
   120    34.1 /  39.0             64.5 /  60.0

COT C   coke kinetic   coke correlation
  480    35.85          34.28
  490    34.12          33.61
  495    33.28          33.28
  500    32.47          32.95
  505    31.67          32.61