Skip to content

MSW: derive the shut-valve trivial-equation Jacobian entry from the rate - #7314

Draft
hnil wants to merge 1 commit into
OPM:masterfrom
hnil:pr/msw-trivial-eq-derivative
Draft

MSW: derive the shut-valve trivial-equation Jacobian entry from the rate#7314
hnil wants to merge 1 commit into
OPM:masterfrom
hnil:pr/msw-trivial-eq-derivative

Conversation

@hnil

@hnil hnil commented Aug 12, 2026

Copy link
Copy Markdown
Member

A SHUT valve segment gets the trivial equation q = 0 in place of its pressure-drop relation, written into the segment pressure row. assembleTrivialEq set the residual from the rate but hard-coded the Jacobian entry as 1., i.e. dq/dq. That is only right while the rate primary variable is unscaled; with --well-rate-scaling=s the primary variable is q/s and the entry must be s. Take it from the rate Evaluation instead, so it is correct by construction. This was the only hard-coded derivative in either well assembler.

Effect: the linear solve returns an increment a factor s too small, updateNewton multiplies by s, and the shut segment rate is multiplied by (1-s) every iteration instead of being zeroed.

Reproducing needs a shut valve, which no deck in opm-tests currently has. Take wsegvalv/BASE_MSW_WSEGVALV.DATA and set the status of one valve:

PROD1  14  0.70000  5.589e-5  1* 1* 1* 1* SHUT /

then

flow BASE_MSW_WSEGVALV.DATA --linear-solver=cprw --well-rate-scaling=4

The shut segment rate reads -3.86e-4, 1.16e-3, -3.48e-3, ... growing by (1-s) = -3 per iteration and reaching 9.96e+131 over the run; with this change it converges to zero in one iteration (max 3.9e-4 over the run). Summary output differs between the two.

Two related observations, not addressed here:

  • The convergence check does not escalate this. The SPres branch of MultisegmentWellEval::getWellConvergence tests only isnan/isinf, with no max_residual_allowed comparison of the kind the mass-balance and energy branches have, so a finite 1e131 is reported Severity::Normal rather than TooLarge - no timestep cut, no warning.
  • That residual is a rate but is compared against tolerance_pressure_ms_wells (0.01 bar), so the trivial equation is never enforced tightly.

🤖 Generated with Claude Code

assembleTrivialEq, the zero-rate equation for a SHUT valve, wrote a physical
rate as the residual but hard-coded its Jacobian entry as 1. The linear
system solves for the scaled primary variable, so the entry has to be
d(q)/d(q/s) = s; with a hard-coded 1 the Newton step for that segment comes
back a factor s too small and is then multiplied by s on update.

Pass the rate as an Evaluation and take the derivative from it, so the entry
is correct by construction rather than by remembering to multiply. This was
the only hard-coded derivative in either well assembler; every other entry
already comes from an EvalWell and scales automatically.

Latent until now because --well-rate-scaling defaults to 1 and every
measurement so far used the default.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@GitPaean GitPaean added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants