Skip to content

fix(compositional): stop a rate well's BHP at its limit and on its flowing side (#163, #175) - #178

Merged
sergeyfarin merged 10 commits into
masterfrom
fix/163-175-rate-well-bhp-update
Dec 3, 2026
Merged

sergeyfarin merged 10 commits into
masterfrom
fix/163-175-rate-well-bhp-update

Conversation

@sergeyfarin

Copy link
Copy Markdown
Owner

Summary

Closes #163
Closes #175

How each acceptance item is met:

SPE3 regression in reach, by owner decision. The new path meets #164 earlier: the replay now fails at 2937.21875 d (year 9) instead of 4109.0625 d. Stepping that frozen state on 7518d043 (master) fails identically: ten attempts, each at its first assembly before any Newton step, with the same residual (1.93e-28) and K norm. So it is #164, met sooner by a different path, not a new failure. As decided in the session, the state is frozen as stall_2937.json with its own seed test, and the replay floor moved to 2937.21875 d with that justification in the commit. #164 is now the wall at year 9.

Validation

  • bash scripts/validate-compositional.sh all: compositional gate 'all': OK (comp_newton_ 27, comp_well_ 36; fixture, reference and records reproduce; wasm compiles)
  • bash scripts/validate-cross-solver.sh: cross-solver check: OK, inventory check OK
  • bash scripts/benchmarks.sh check: benchmark check: OK, pages in sync
  • pnpm run validate:product: 92 files / 1,145 tests passed, IMPES bucket OK
  • comp_spe5_case1_stops_at_the_published_shut_in (release, 0b7b8b87): 6285.34375 d, report 1239, water cut; 1,239 steps, 0 failed, 6,226 Newton, 909 s
  • SPE5 WASM worker path (SPE5_WASM_REPLAY=1, 2b7e6c67): same stop, water cut 0.8344891317395606, bit for bit with native, 1,207 s
  • comp_spe3_full_horizon_replay (release, 2b7e6c67; first run on 0b7b8b87 identical): reaches 2937.21875 d; balance ≤ 3.53e-11; 1,546 s
  • comp_spe3_seed_ (both seeds) and comp_spe5_from_scratch_218_seed_reproduces_signature_b: pass
  • comp_newton_rate_producer_sweep (new, ignored diagnostic): 1,944 one-cell solves; converged 1,659 → 1,927, singular rate rows 163 → 0, collapsed bounds 122 → 0; all 17 remaining failures also failed before
  • Docs: COMPOSITIONAL_WELL_DESIGN.md, SPE3_VALIDATION.md, SPE5_VALIDATION.md

Not run, and why: validate-solver-coverage.sh, because no black-oil or shared engine code is touched (compositional/ only). The other ignored #116 SPE5 diagnostics were not run (no gate selects them); one of them, signature B, was spot-checked and passes.

Numbers

Yes: solver behaviour and two replay records.

  • SPE5 shut-in replay: stop unchanged (6285.34375 d, report 1239, water cut); water cut 0.8344920492842325 → 0.8344891317395606; failed attempts 4 → 0. Recorded in SPE5_VALIDATION.md; the earlier table is kept as recorded.
  • SPE3 replay: reach 4109.0625 → 2937.21875 d (both SPE3 fails at 4109 d: separator stability trial converged to roundoff but its trial sum never stops moving by 1e-14 #164); failed attempts years 1–8 54 → 5; pressures within 0.1 psia year by year. The RECORDED_REACH_DAYS floor moved in 2b7e6c67, with justification.
  • No tolerance, band, benchmark record or scorecard changed; benchmarks.sh check and the compositional records match.

Also fixed

  • 41403657 starting_well_bhp used a matches! that re-spells WellControl::is_rate().

Follow-up issues

Decisions made on the owner's behalf

🤖 Generated with Claude Code

sergeyfarin and others added 4 commits December 2, 2026 21:11
…owing side (#163, #175)

A rate-controlled well's BHP update had one fraction-to-boundary bound,
0.99 of the gap to its limit, applied to the whole Newton step, and no
bound relative to its completions.

#175: a well the linearization kept pushing past its limit crept onto it,
each step 1% of the remaining gap, until the gap rounded to zero and the
step bound collapsed. The step now stops where the BHP reaches the limit
and lands on it exactly; a well already on its limit whose update points
past it is held there on BHP control and the direction is solved again.

#163: nothing kept a producer's BHP below its completions' connection
pressures (an injector's above). Past that edge a completion carries no
flow, the rate row's d(rate)/d(bhp) is zero and cannot be eliminated, and
a multi-completion well crossflows. The stepped BHP alone is now put 99%
of the way from where it was to that edge; the cells keep their step.

One-cell rate-producer sweep (comp_newton_rate_producer_sweep, 1944
solves): converged 1659 -> 1927; singular rate rows 163 -> 0; collapsed
step bounds 122 -> 0; every remaining failure also failed before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rate in the BHP start

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eplay floor to it (#163, #164)

The rate-well fix (#163/#175) takes the SPE3 replay down a path with 5
failed attempts in years 1-8 instead of 54, but the path reaches a state
at 2937.21875 d (year 9 of cycling) where every attempt fails on the #164
separator stability trial, before the 4109.0625 d where the previous path
met it.

Justification for lowering RECORDED_REACH_DAYS from 4109.0625 to
2937.21875 d: the new end is the same defect, not a new one. From the
frozen 2937.21875 d state, the engine before #163/#175 (7518d04) and
after it fail identically: ten attempts, each at its first assembly
before any Newton step, all on the producer's separator flash with the
same residual (1.93e-28) and K norm (278.76). How far the run gets before
#164 is path luck, so the floor follows the path the merged engine takes,
and #164 stays the hard wall for both.

Both seeds stay: stall_4109.json still reproduces its failure, and
stall_2937.json gets its own test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…5 replays (#163, #175)

COMPOSITIONAL_WELL_DESIGN.md gains "The BHP update": the limit stops the
step exactly and holds a well that stays on it; the connection pressures
only clip the stepped BHP. It records the one-cell sweep and the
two-completion infeasibility trade-off.

SPE3_VALIDATION.md keeps the c41a6b3 record (the only one reaching the
2500 psia crossing #96 needs) and adds the replay on 2b7e6c6: fails at
2937.21875 d on #164, from a state the previous engine fails identically;
failed attempts in years 1-8 fall from 54 to 5.

SPE5_VALIDATION.md: same shut-in stop and report; its four failed
attempts were the #175 creep and are gone; water cut 0.8344891317395606,
native and WASM alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sergeyfarin and others added 4 commits December 3, 2026 00:02
…e evaluates (#163, #175)

The flowing-side clip judged a BHP by `p_cell - head`, but the source term
evaluates `p_cell - (bhp + head)`. One ulp short of the edge the clipped
`from + 0.99 (edge - from)` rounded back onto it: a 100 bar cell with an 8 bar
head, stepped from 92⁻ to 93, landed on exactly 92, where the potential is
zero and so is d(rate)/d(bhp). The clip now tests every completion with the
source's own expression and steps back one ulp at a time to the first BHP that
still flows. Any BHP that flowed before is returned unchanged; the 1,944-case
rate-producer sweep is identical (1,927 converged, 17 not).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…109 d (#163, #164)

The 2937.21875 d floor is justified only by the separator stability failure
the rate-well fix exposed earlier. A default replay that stops before the
previous 4109.0625 d reach must now stop on that failure (`well PROD: surface
flash failed: ... LiquidLike trial did not converge`); any other early stop
fails the test. The seed tests share the same message constant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e bounds (#163, #175)

"Moves less than 99% of the way to its limit" read as a property of the
direction; what decides bit-identity is whether the old 99% well bound or the
new completion clip activated on an iteration. Once either did, the step is
1/0.99 longer, held and re-solved, or clipped, and the rest of the solve takes
a different Newton path. State that in the module docs and the design doc, and
record the SPE5 shut-in water cut (0.8344920492842325 -> 0.8344891317395606)
as the deliberate exception to #163's bit-identity acceptance. The design doc
also notes that the clip judges flow by the source term's own potential.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sing (#163, #164)

The roadmap still gave 4109 d as where SPE3 fails and used the later datum
crossing to scope #96. Since #163/#175 the replay stops at 2937.21875 d on
#164; the crossing at 3743.8125-3774.25 d comes from the c41a6b3 replay and
is labelled as such until #164 lets the current engine get past it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sergeyfarin

Copy link
Copy Markdown
Owner Author

Review round (Codex findings), all on this branch at acda250c. All four findings are taken as raised; none is disputed.

P2 — the BHP clip can still zero the rate row (newton.rs admissible_rate_bhp) — fixed in 76d116dc. The clip now judges every completion with the source term's own expression, p_cell - (bhp + head). When the 99% point rounds onto the edge, it steps back one ulp at a time to the first BHP that still flows (injector mirrored with next_up). A BHP that flowed before is returned unchanged.

  • New test comp_newton_admissible_rate_bhp_flows_at_the_source_potential, built from your example: 100 bar cell, 8 bar head, from = 92⁻, stepped to 93. It failed on the previous head (the clipped BHP 92 must draw at the source's potential) and now passes. It also asserts a nonzero bhp_derivative from rate_constraint_at_bhp and covers the injector mirror.
  • The comp_newton_ gate minimum is raised to 28.
  • The rate-producer sweep is unchanged: 1,927 of 1,944 converged.

P2 — require the known failure when SPE3 stops early (spe3_full_horizon_tests.rs) — fixed in 1be069e9. The default replay keeps the approved 2937.21875 d floor. If it stops before 4109.0625 d (PREVIOUS_REACH_DAYS), the failure message must now contain well PROD: surface flash failed: stability test failed: LiquidLike trial did not converge. Both seed tests share that constant.

  • Full replay on acda250c: reached 2937.21875 d on exactly that message, 102 steps / 16 failed / 790 Newton, balance 3.53e-11, 1,333 s. The test passes.

P2 — resolve the bit-identity acceptance (newton.rs module docs) — fixed in aac80fbd, as docs; no behaviour change. Your 200 bar / 170 bar case is the old 99% limit bound activating: 0.71750221 / 0.71032719 = 1.0101010, which is 1/0.99. The module docs and COMPOSITIONAL_WELL_DESIGN.md ("The BHP update") now define "unchanged" by which bounds activate. An iteration is unchanged bit for bit when neither the old 99% well bound nor the new completion clip activates on it. Once either activates, the step lands on the limit, is held and re-solved, or is clipped, and the rest of the solve takes a different Newton path. A converged answer then moves within the Newton tolerance.

P3 — ROADMAP line 141 — fixed in acda250c. The roadmap now shows the year-nine stop at 2937.21875 d on #164, and gives the earlier 4109.0625 d stop as the pre-fix result. The 2500 psia crossing (3743.8125–3774.25 d) is labelled as evidence from the c41a6b33 replay, which the current run does not reach until #164 is fixed.

Gates on acda250c

  • bash scripts/validate-compositional.sh all: compositional gate 'all': OK.
  • bash scripts/validate-cross-solver.sh: cross-solver check: OK.
  • bash scripts/benchmarks.sh check: benchmark check: OK, pages in sync.
  • comp_spe3_full_horizon_replay and comp_spe5_case1_stops_at_the_published_shut_in: both pass, results above.
  • Not rerun this round: the WASM SPE5 worker replay. The ulp clip left the native SPE5 record unchanged; the worker replay last matched bit for bit on 2b7e6c67.

sergeyfarin and others added 2 commits December 3, 2026 06:46
…e, with a bounded search (#163, #175)

Two holes in the flowing-side clip, both found in review:

- It compared a BHP with the rounded edge `p_cell - head` before asking the
  source. At 80.01 bar and a -18.9 bar head the edge rounds to 98.91 bar,
  where the source still draws 1.4e-14 bar, so a flowing stepped BHP was
  rejected and pulled down. Now `p_cell - (bhp + head)` alone decides whether
  the stepped BHP is kept and whether the starting BHP can anchor the clip.
- It walked one ulp at a time back from the 99% point, and the anchor it fell
  back to need not flow. With a 2^40 bar cell and a 2^40 - 1 bar head no BHP in
  an injector's [1, 1 + 2^-14] bar interval injects, and the walk took 2.7e11
  steps to return the limit. Now the interval's flowing end is checked first
  (the limit is returned at once if it does not flow) and the search bisects
  between the anchor and the 99% point. The potential never increases with
  the BHP, so the bisection finds the same BHP the walk did.

Both have a named test; the 1,944-case rate-producer sweep is unchanged
(1,927 converged, 17 not).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…unds it covers (#163, #175)

The old well bound also damped the step 99% of the way to both ends of the
absolute BHP search interval, not only to the control limit: a producer
moving from 1999 to 2001 bar was scaled to 0.495 and now takes the cells' full
step with only the BHP clamped. List that case with the others that change the
Newton path, and stop saying the converged answer moves "within the Newton
tolerance": the tolerance bounds each path's scaled residual, and any bound
on how far pressure, water cut or other outputs move needs its own evidence.
The design doc also describes the clip's bisection and its no-flow return.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sergeyfarin

Copy link
Copy Markdown
Owner Author

Review round 2 (Codex findings), on this branch at f71068b3. All three findings are taken as raised; none is disputed.

P2: bound the search for a flowing BHP (newton.rs, admissible_rate_bhp). Fixed in 33fe14c6.

  • The clip now checks the interval's flowing end first: the limit for a producer, the top for an injector. If that end does not flow, no BHP in the interval does, and the limit is returned at once for the assembly to report.
  • Otherwise the clip bisects between the anchor (which flows) and the 99% point (which does not). The source potential never increases with the BHP, so the flowing BHPs form one interval. The bisection therefore finds the same BHP the ulp walk did, within a few dozen passes.
  • New test comp_newton_admissible_rate_bhp_search_is_bounded_when_nothing_flows uses your case: a 2^40 bar cell, a 2^40 − 1 bar head, and an injector limit of 1 + 2^-14 bar. It returns the limit at once. On the previous head it ran until a 60 s timeout killed it.

P2: preserve an already-flowing BHP. Fixed in the same commit, because both changes rewrite the same function. The source potential p_cell - (bhp + head) alone now decides two things: whether the stepped BHP is kept, and whether the starting BHP anchors the clip. The rounded edge p_cell - head is used only to aim the 99% point. That aim is clamped between the anchor and the stepped BHP.

  • New test comp_newton_admissible_rate_bhp_keeps_a_bhp_the_source_sees_flowing uses your case: 80.01 bar cell, −18.9 bar head, 40 bar limit. A stepped 98.91 bar is kept, and a starting 98.91 bar is kept against a step to 99. On the previous head the first assertion returned 98.9009.

P3: state the limits of the bit-identity claim. Fixed in f71068b3. The module docs and COMPOSITIONAL_WELL_DESIGN.md ("The BHP update") now say the old well bound damped the step toward three BHPs: the control limit and both search ends, 1 and 2000 bar. They give your 1999 → 2001 bar producer (0.99 × 1 / 2 = 0.495 before; now no scale, with only the BHP clamped) as one of the iteration kinds that change the Newton path. They no longer say a converged answer moves "within the Newton tolerance". The tolerance bounds each path's scaled residual, and any bound on pressure, water cut or other outputs needs its own evidence. SPE5's is in docs/SPE5_VALIDATION.md.

Gates on f71068b3

  • bash scripts/validate-compositional.sh all: compositional gate 'all': OK, with comp_newton_ at 30 tests (the minimum is raised to 30).
  • comp_newton_rate_producer_sweep: unchanged, 1,927 converged and 17 not, out of 1,944.
  • comp_spe3_full_horizon_replay: 2937.21875 d on the SPE3 fails at 4109 d: separator stability trial converged to roundoff but its trial sum never stops moving by 1e-14 #164 separator failure. 102 steps, 16 failed attempts, 790 Newton iterations, balance 3.53e-11. Identical to acda250c.
  • comp_spe5_case1_stops_at_the_published_shut_in: 6285.34375 d, water cut 0.8344891317395606. 1,239 steps, 0 failed attempts, 6,226 Newton iterations. Identical to acda250c.
  • bash scripts/validate-cross-solver.sh: cross-solver check: OK.
  • bash scripts/benchmarks.sh check: benchmark check: OK, and the pages are in sync.
  • Not rerun: the WASM SPE5 worker replay. The native SPE5 record is unchanged.

@sergeyfarin
sergeyfarin merged commit 9d8fdb1 into master Dec 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant