Skip to content

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

Open
eacuellarq wants to merge 1 commit into
modflowpy:developfrom
eacuellarq:feat-swr1
Open

eacuellarq wants to merge 1 commit 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.

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant