Skip to content

feat(swr): implement ModflowSwr1 write and load - #2866

Open
eacuellarq wants to merge 2 commits into
modflowpy:developfrom
eacuellarq:feat-swr1
Open

eacuellarq wants to merge 2 commits into
modflowpy:developfrom
eacuellarq:feat-swr1

Conversation

@eacuellarq

Copy link
Copy Markdown

Refs #2389

flopy.modflow.ModflowSwr1 was a stub: write_file() raised
NotImplementedError, load() did not parse the file, and swr was not
registered in Modflow.load. This PR replaces it with a full implementation
of the SWR1 Process (MODFLOW-NWT 1.3.0 / SWR1 1.05).

What's included

  • write_file and load for every input item (1–15): options, solver
    controls, reaches and connectivity, tabfiles (ASCII and binary, with the
    time series loaded into tabfiles[i]["data"]), observations, boundary
    types, rain/evap/lateral flow (lists or grids), geometry types 1–5
    (including cross sections and tables), structures of every ISTRTYPE
    (including operable structures and SFR coupling), stage, auxiliary
    variables and direct runoff.
  • Where the input instructions and gwf2swr7.f disagree (item 13a field
    order, item 13b, item 4f IOBSLOC2, undocumented options), the code is
    followed; the differences are listed in the module docstring.
  • validate() (run by write_file) reports input MODFLOW would stop on or
    silently misread: reach/grid indices, non-symmetric connectivity,
    structures connected to unconnected reaches, TABDATAn/REACHn
    references, missing geometry fields, lines longer than the 200-character
    Fortran buffer.
  • SwrExternal keeps lists and grids in OPEN/CLOSE files; loading keeps
    OPEN/CLOSE references.
  • "swr" is registered in Modflow.mfnam_packages.
  • The constructor stays compatible with the stub (ModflowSwr1(m)).

Index convention

Reach, layer, row and column numbers default to one-based, as in the
SWR1 manual, because reach numbers also appear in connectivity, structures,
observations and REACHn references. zero_based=True makes
KRCH/IRCH/JRCH zero-based like other FloPy packages. Happy to change the
default if preferred.

Tests (autotest/test_swr.py)

  • Load of the USGS SWR test problem 5 (added as
    examples/data/swr_sample05, ~350 KB of inputs) and text-identical
    load → write → load → write.
  • @pytest.mark.slow: load → write → run of the USGS problem gives
    byte-identical .hds, QAQ, group flow, stage and RIV outputs.
  • A channel model built from scratch runs in mfnwt, the flood wave passes,
    and the binary outputs are read with SwrStage/SwrExchange/SwrBudget.
  • Every structure type and geometry option written, read by mfnwt, and
    round-tripped.
  • Validation errors, option conflicts, zero-based indices, OPEN/CLOSE files,
    binary tabfiles.

Ran locally: ruff check / ruff format --check clean, codespell clean,
pytest autotest/test_swr.py autotest/test_swr_binaryread.py 17 passed.

eacuellarq and others added 2 commits October 12, 2026 13:58
Replace the SWR1 stub, which could not write or load the package, with a
complete implementation of every SWR1 input item (MODFLOW-NWT 1.3.0,
SWR1 1.05), and register it in Modflow.load.

* write_file and load for items 1-15, structures of every type, geometry
  types 1-5, tabfiles (ASCII and binary), observations, direct runoff
* where the input instructions and gwf2swr7.f disagree, follow the code
* validate() reports inconsistencies MODFLOW would stop on or misread
* SwrExternal keeps lists and grids in OPEN/CLOSE files
* optional zero-based KRCH/IRCH/JRCH (zero_based=True)
* add the USGS SWR test problem 5 to examples/data/swr_sample05

Refs modflowpy#2389
@wpbonelli wpbonelli added this to the 3.12 milestone Oct 27, 2026
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.1%. Comparing base (556c088) to head (041a9a9).
⚠️ Report is 247 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2866      +/-   ##
===========================================
+ Coverage     55.5%    74.1%   +18.6%     
===========================================
  Files          644      659      +15     
  Lines       124135   134925   +10790     
===========================================
+ Hits         68947   100051   +31104     
+ Misses       55188    34874   -20314     

see 588 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

Copy link
Copy Markdown
Member

Sorry for converting your feature request to a discussion, I don't know why I did that. Thanks for this contribution.

We'll review before long — trying to get an mf6 release out the door which will necessitate a flopy release so I tentatively put this on the next milestone, I'm probably also not the best person to look at it

@eacuellarq

Copy link
Copy Markdown
Author

Thanks, no worries!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants