Skip to content

fix(utils): fix zone off-by-one, add test for #2612 - #2818

Merged
wpbonelli merged 5 commits into
modflowpy:developfrom
wpbonelli:test-2612
Aug 20, 2026
Merged

fix(utils): fix zone off-by-one, add test for #2612#2818
wpbonelli merged 5 commits into
modflowpy:developfrom
wpbonelli:test-2612

Conversation

@wpbonelli

@wpbonelli wpbonelli commented Aug 20, 2026

Copy link
Copy Markdown
Member

Two separate things. Fix an off-by-one bug in EndpointFile: zone numbers read back from a MODPATH 7 endpoint file were silently decremented by 1. And add a test reproducing #2613. Bisect confirms the issue was fixed some time ago by #1415.

wpbonelli and others added 4 commits August 20, 2026 10:44
…add PRT

The original modflowpy#2612 repro built no PRT model despite its docstring
claiming to compare PRT to MP7, and only checked that Modpath7Sim
didn't raise on 2D/3D zones arrays -- with no boundary conditions the
lone default particle terminated immediately without ever crossing
between zones, so the test never exercised zone semantics at all.

Rework it against a small DISV grid with real CHD-driven flow, where
a particle released upstream of a stopzone cell must pass through it
before reaching a sink cell. This lets the test assert the particle
is actually intercepted by the zone (not just that construction
doesn't crash), and that the 2D (nlay, ncpl) and 3D (nlay, 1, ncpl)
zones arrays are interpreted identically by Util3d, which is the
actual substance of the issue. Also add the promised PRT model: PRT's
izone (MIP package) takes a native 2D griddata array for DISV grids,
so it serves as a second reference implementation to check MP7's zone
behavior against.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LzbPuZ3nFWeCKM5Rpmpvmo
EndpointFile.kijnames lumped "zone0"/"zone" in with the k/i/j/node
fields that get -1 applied to convert MODPATH 7's 1-based Fortran
indices to 0-based. But zone numbers are user-assigned labels, not
positional indices -- MP7 writes them unshifted (verified against a
raw .mpend record: a cell tagged zone 2 is written as "2", not "3"),
so every zone value read back through EndpointFile was silently off
by one.

Found while building a zones-focused regression test for modflowpy#2612 that
actually checks a stopzone value against the endpoint file rather
than just the input zones array. Nothing else in flopy reads zone/
zone0 from parsed endpoint data (searched plot/export code and
autotest/), so this only affects direct EndpointFile consumers who
were compensating for the off-by-one themselves.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LzbPuZ3nFWeCKM5Rpmpvmo
@wpbonelli wpbonelli added this to the 3.11 milestone Aug 20, 2026
@wpbonelli wpbonelli added the bug label Aug 20, 2026
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.3%. Comparing base (556c088) to head (34cce8f).
⚠️ Report is 209 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2818      +/-   ##
===========================================
+ Coverage     55.5%    73.3%   +17.8%     
===========================================
  Files          644      659      +15     
  Lines       124135   132188    +8053     
===========================================
+ Hits         68947    97013   +28066     
+ Misses       55188    35175   -20013     
Files with missing lines Coverage Δ
flopy/utils/modpathfile.py 82.9% <ø> (-5.6%) ⬇️

... and 584 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wpbonelli
wpbonelli marked this pull request as ready for review August 20, 2026 17:50
@wpbonelli
wpbonelli merged commit 6c8b29b into modflowpy:develop Aug 20, 2026
23 checks passed
@wpbonelli
wpbonelli deleted the test-2612 branch August 20, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant