Skip to content

Run inactive-patch validation over all patch slots - #1727

Closed
Mohit-Ak wants to merge 1 commit into
MFlowCode:masterfrom
Mohit-Ak:fix/inactive-patch-validation
Closed

Run inactive-patch validation over all patch slots#1727
Mohit-Ak wants to merge 1 commit into
MFlowCode:masterfrom
Mohit-Ak:fix/inactive-patch-validation

Conversation

@Mohit-Ak

Copy link
Copy Markdown

Three of the four per-patch validation loops in s_check_patches were bounded at
num_patches instead of num_patches_max, so their else branches — the ones
that validate the inactive patch slots — could never be reached.

The first loop (alteration of deprecated geometry numbers, L43) is already
correct: it runs do i = 1, num_patches_max and uses if (i <= num_patches) to
split active from inactive slots. The other three copy that same
if (i <= num_patches) ... else ... shape but only ever iterate to
num_patches, which makes the predicate unconditionally true. That left three
validators as dead code:

loop validator that was unreachable
L98 — alteration rights s_check_inactive_patch_alteration_rights (L405)
L107 — smoothing s_check_unsupported_patch_smoothing (L442)
L119 — primitive variables s_check_inactive_patch_primitive_variables (L512)

The fix widens those three bounds to num_patches_max. That's the whole change,
+3/-3 in one file.

The smoothing loop is worth a second look because it's structurally different —
its predicate is a geometry whitelist (i > 1 .and. geometry == 2/3/4/...)
rather than i <= num_patches. An inactive slot has geometry == dflt_int, so
once the bound is widened it falls through to the else/unsupported branch,
which is the intended behaviour. I verified that empirically rather than by
reading (see the smooth row below).

Why this can't change results for any valid case

m_global_parameters.fpp:230-268 initialises all num_patches_max (= 10, from
m_constants.fpp:26) slots to defaults in its own do i = 1, num_patches_max
loop — alter_patch = .false. with alter_patch(0) = .true., smoothen = .false., smooth_patch_id = i, and dflt_real for every primitive variable.
Those defaults are exactly what the inactive-patch validators assert. So for a
well-formed case the newly-reachable checks are no-ops; the change only tightens
validation on misconfigured input and cannot move a golden file.

How it was tested

I built a 1D Sod-like case with num_patches: 2 and then set one forbidden
parameter on the inactive slot 3, one variant per broken loop, plus a clean
control. Run through ./mfc.sh run <case.json> -t pre_process -n 1:

variant what it sets on patch 3 before after
control nothing (valid case) exit 0 exit 0
alter alter_patch(1) = T exit 0 — wrongly accepted aborts: Inactive patch 3: cannot have any alter_patch(i) enabled
smooth smoothen = T, smooth_coeff = 0.5 exit 0 — wrongly accepted aborts: Inactive patch 3: cannot have smoothen enabled
prim pres, vel(1), rho exit 0 — wrongly accepted aborts: Inactive patch 3: rho must not be set

Each bad variant produces a different message, which is what proves the three
loops independently rather than just showing that some check fires. The control
still passes in both directions, so nothing valid became newly rejected.

Both CI gates pass locally on the committed tree:

  • ./mfc.sh lint372 passed, 4 subtests passed in 9.74s
  • ./mfc.sh precheck -j 4 → all 7 checks OK (formatting, spelling, toolchain
    lint, source lint, doc refs, parameter docs, example cases)

Note on prior work

PR #1599 took the same approach and was closed for author inactivity, not
because anything was wrong with it. This is a clean re-do with the reachability
matrix above as evidence.

Fixes #1482

Three of the four validation loops in s_check_patches were bounded at
num_patches rather than num_patches_max, so their else branches -- the
inactive-slot validators -- were unreachable. Widen those bounds to match
the first loop, which already gets this right.
@Mohit-Ak

Copy link
Copy Markdown
Author

Closing: the Fortran fix is correct but causes widespread pre_process failures across the existing test suite — many test cases inherit a 3-patch BASE_CFG and only override num_patches to 1 or 2, leaving inactive slots with non-default values that the now-reachable validators reject. The fix needs a coordinated update to the test-case generator alongside the Fortran change. Will revisit with a complete fix.

@Mohit-Ak Mohit-Ak closed this Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Inactive-patch validation never runs: s_check_patches loops bound at num_patches instead of num_patches_max

1 participant