From 98de7504484b6d72e6510489ce277fc68296112d Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Wed, 11 Nov 2026 05:47:04 -0800 Subject: [PATCH] require COLUMNS, WIDTH and DIGITS in a print format Regenerate from MODFLOW-ORG/modflow6@65278c93, which merges #3129. The DFNs now make columns, width and digits required and the format word optional, as MF6 reads them. So HEAD PRINT_FORMAT COLUMNS 10 WIDTH 11 DIGITS 4 loads (mf6/test/test060_gms_ets now passes), and a record that stops early, which MF6 now rejects, fails to parse. Codegen made a required tagged first child the record's trigger keyword, which writes its value after any other tagged fields. Only do that when no other child is tagged, so the format record keeps COLUMNS first. The Format fields are now in DFN order, columns, width, digits, format_, so its tuple form is (10, 12, 6, "GENERAL"). The new DFN commit is on develop, unlike the last one, so MAW also loses CONNECTION_STATUS and BOTTOM, which develop reverted in #3089. Co-Authored-By: Claude Opus 5.5 --- flopy4/mf6/_contract.py | 2 +- flopy4/mf6/chf/oc.py | 8 +- .../reader/grammar/generated/chf-oc.lark | 2 +- .../reader/grammar/generated/gwe-oc.lark | 2 +- .../reader/grammar/generated/gwf-oc.lark | 2 +- .../reader/grammar/generated/gwt-ist.lark | 2 +- .../reader/grammar/generated/gwt-oc.lark | 2 +- .../reader/grammar/generated/olf-oc.lark | 2 +- flopy4/mf6/gwe/oc.py | 8 +- flopy4/mf6/gwf/maw.py | 15 +- flopy4/mf6/gwf/oc.py | 8 +- flopy4/mf6/gwt/ist.py | 8 +- flopy4/mf6/gwt/oc.py | 8 +- flopy4/mf6/olf/oc.py | 8 +- flopy4/mf6/record.py | 2 +- flopy4/mf6/utils/codegen/make.py | 9 +- ...est_roundtrip[mf6testtest060_gms_ets].json | 272 ++++++++++ ...ad_simulation[mf6testtest060_gms_ets].json | 513 ++++++++++++++++++ test/mf6/test_mf6_codec.py | 115 +++- test/mf6/test_mf6_load_all_models.py | 1 + 20 files changed, 926 insertions(+), 63 deletions(-) create mode 100644 test/mf6/__snapshots__/test_mf6_io_roundtrip/test_roundtrip[mf6testtest060_gms_ets].json create mode 100644 test/mf6/__snapshots__/test_mf6_load_all_models/test_load_simulation[mf6testtest060_gms_ets].json diff --git a/flopy4/mf6/_contract.py b/flopy4/mf6/_contract.py index 4e6d02512..5a3295963 100644 --- a/flopy4/mf6/_contract.py +++ b/flopy4/mf6/_contract.py @@ -1,6 +1,6 @@ # autogenerated file, do not modify MF6_VERSION = "6.9.0.dev0" -DFN_COMMIT = "203d72f0e89bc049154f4e391e6e4fd18dab99b6" +DFN_COMMIT = "65278c938a0c6e742b52fa7398b35a9aea6c0752" DFN_SCHEMA_VERSION = "2.0.0.dev3" GENERATED_FILES = ( "chf/__init__.py", diff --git a/flopy4/mf6/chf/oc.py b/flopy4/mf6/chf/oc.py index e03e88a99..ae310b7c9 100644 --- a/flopy4/mf6/chf/oc.py +++ b/flopy4/mf6/chf/oc.py @@ -28,10 +28,10 @@ class Oc(Package): @attrs.define class Format(Record): _keyword: ClassVar[str] = "" - format_: str = string() - columns: Optional[int] = integer(default=None, tagged=True, optional=True) - width: Optional[int] = integer(default=None, tagged=True, optional=True) - digits: Optional[int] = integer(default=None, tagged=True, optional=True) + columns: int = integer(tagged=True) + width: int = integer(tagged=True) + digits: int = integer(tagged=True) + format_: Optional[str] = string(default=None, optional=True) @attrs.define class Qoutflowprint(Record): diff --git a/flopy4/mf6/codec/reader/grammar/generated/chf-oc.lark b/flopy4/mf6/codec/reader/grammar/generated/chf-oc.lark index b03b6684b..14f02f11a 100644 --- a/flopy4/mf6/codec/reader/grammar/generated/chf-oc.lark +++ b/flopy4/mf6/codec/reader/grammar/generated/chf-oc.lark @@ -44,7 +44,7 @@ saverecord__rec__elem: "save"i saverecord__rtype__val ocsetting__union [_remark] saverecord__rtype__val: word printrecord__rec__elem: "print"i printrecord__rtype__val ocsetting__union [_remark] _NL printrecord__rtype__val: word -formatrecord__rec: [formatrecord__columns__val] [formatrecord__width__val] [formatrecord__digits__val] formatrecord__format__val +formatrecord__rec: formatrecord__columns__val formatrecord__width__val formatrecord__digits__val [formatrecord__format__val] formatrecord__columns__val: "columns"i integer formatrecord__width__val: "width"i integer formatrecord__digits__val: "digits"i integer diff --git a/flopy4/mf6/codec/reader/grammar/generated/gwe-oc.lark b/flopy4/mf6/codec/reader/grammar/generated/gwe-oc.lark index 2770ce2b7..1b125434d 100644 --- a/flopy4/mf6/codec/reader/grammar/generated/gwe-oc.lark +++ b/flopy4/mf6/codec/reader/grammar/generated/gwe-oc.lark @@ -42,7 +42,7 @@ saverecord__rec__elem: "save"i saverecord__rtype__val ocsetting__union [_remark] saverecord__rtype__val: word printrecord__rec__elem: "print"i printrecord__rtype__val ocsetting__union [_remark] _NL printrecord__rtype__val: word -formatrecord__rec: [formatrecord__columns__val] [formatrecord__width__val] [formatrecord__digits__val] formatrecord__format__val +formatrecord__rec: formatrecord__columns__val formatrecord__width__val formatrecord__digits__val [formatrecord__format__val] formatrecord__columns__val: "columns"i integer formatrecord__width__val: "width"i integer formatrecord__digits__val: "digits"i integer diff --git a/flopy4/mf6/codec/reader/grammar/generated/gwf-oc.lark b/flopy4/mf6/codec/reader/grammar/generated/gwf-oc.lark index 6fbe522e8..15cdfe7b5 100644 --- a/flopy4/mf6/codec/reader/grammar/generated/gwf-oc.lark +++ b/flopy4/mf6/codec/reader/grammar/generated/gwf-oc.lark @@ -42,7 +42,7 @@ saverecord__rec__elem: "save"i saverecord__rtype__val ocsetting__union [_remark] saverecord__rtype__val: word printrecord__rec__elem: "print"i printrecord__rtype__val ocsetting__union [_remark] _NL printrecord__rtype__val: word -formatrecord__rec: [formatrecord__columns__val] [formatrecord__width__val] [formatrecord__digits__val] formatrecord__format__val +formatrecord__rec: formatrecord__columns__val formatrecord__width__val formatrecord__digits__val [formatrecord__format__val] formatrecord__columns__val: "columns"i integer formatrecord__width__val: "width"i integer formatrecord__digits__val: "digits"i integer diff --git a/flopy4/mf6/codec/reader/grammar/generated/gwt-ist.lark b/flopy4/mf6/codec/reader/grammar/generated/gwt-ist.lark index 5ecf8b20d..9dc0f9eb2 100644 --- a/flopy4/mf6/codec/reader/grammar/generated/gwt-ist.lark +++ b/flopy4/mf6/codec/reader/grammar/generated/gwt-ist.lark @@ -59,7 +59,7 @@ decay_sorbed__val: "decay_sorbed"i [_remark] [_NL] array bulk_density__val: "bulk_density"i [_remark] [_NL] array distcoef__val: "distcoef"i [_remark] [_NL] array sp2__val: "sp2"i [_remark] [_NL] array -formatrecord__rec: [formatrecord__columns__val] [formatrecord__width__val] [formatrecord__digits__val] formatrecord__format__val +formatrecord__rec: formatrecord__columns__val formatrecord__width__val formatrecord__digits__val [formatrecord__format__val] formatrecord__columns__val: "columns"i integer formatrecord__width__val: "width"i integer formatrecord__digits__val: "digits"i integer diff --git a/flopy4/mf6/codec/reader/grammar/generated/gwt-oc.lark b/flopy4/mf6/codec/reader/grammar/generated/gwt-oc.lark index 47d03e51c..9f60d5acb 100644 --- a/flopy4/mf6/codec/reader/grammar/generated/gwt-oc.lark +++ b/flopy4/mf6/codec/reader/grammar/generated/gwt-oc.lark @@ -42,7 +42,7 @@ saverecord__rec__elem: "save"i saverecord__rtype__val ocsetting__union [_remark] saverecord__rtype__val: word printrecord__rec__elem: "print"i printrecord__rtype__val ocsetting__union [_remark] _NL printrecord__rtype__val: word -formatrecord__rec: [formatrecord__columns__val] [formatrecord__width__val] [formatrecord__digits__val] formatrecord__format__val +formatrecord__rec: formatrecord__columns__val formatrecord__width__val formatrecord__digits__val [formatrecord__format__val] formatrecord__columns__val: "columns"i integer formatrecord__width__val: "width"i integer formatrecord__digits__val: "digits"i integer diff --git a/flopy4/mf6/codec/reader/grammar/generated/olf-oc.lark b/flopy4/mf6/codec/reader/grammar/generated/olf-oc.lark index b8dbbb25d..c81607c3f 100644 --- a/flopy4/mf6/codec/reader/grammar/generated/olf-oc.lark +++ b/flopy4/mf6/codec/reader/grammar/generated/olf-oc.lark @@ -44,7 +44,7 @@ saverecord__rec__elem: "save"i saverecord__rtype__val ocsetting__union [_remark] saverecord__rtype__val: word printrecord__rec__elem: "print"i printrecord__rtype__val ocsetting__union [_remark] _NL printrecord__rtype__val: word -formatrecord__rec: [formatrecord__columns__val] [formatrecord__width__val] [formatrecord__digits__val] formatrecord__format__val +formatrecord__rec: formatrecord__columns__val formatrecord__width__val formatrecord__digits__val [formatrecord__format__val] formatrecord__columns__val: "columns"i integer formatrecord__width__val: "width"i integer formatrecord__digits__val: "digits"i integer diff --git a/flopy4/mf6/gwe/oc.py b/flopy4/mf6/gwe/oc.py index 79d54f2d9..24b34e4e9 100644 --- a/flopy4/mf6/gwe/oc.py +++ b/flopy4/mf6/gwe/oc.py @@ -28,10 +28,10 @@ class Oc(Package): @attrs.define class Format(Record): _keyword: ClassVar[str] = "" - format_: str = string() - columns: Optional[int] = integer(default=None, tagged=True, optional=True) - width: Optional[int] = integer(default=None, tagged=True, optional=True) - digits: Optional[int] = integer(default=None, tagged=True, optional=True) + columns: int = integer(tagged=True) + width: int = integer(tagged=True) + digits: int = integer(tagged=True) + format_: Optional[str] = string(default=None, optional=True) @attrs.define class Temperatureprint(Record): diff --git a/flopy4/mf6/gwf/maw.py b/flopy4/mf6/gwf/maw.py index f62731b55..0f80ceba1 100644 --- a/flopy4/mf6/gwf/maw.py +++ b/flopy4/mf6/gwf/maw.py @@ -104,17 +104,6 @@ class Status(Item): _keyword: ClassVar[str] = "status" status: str = string() - @attrs.define - class ConnectionStatus(Item): - _keyword: ClassVar[str] = "connection_status" - icon: int = integer(index=True) - connstatus: str = string() - - @attrs.define - class Bottom(Item): - _keyword: ClassVar[str] = "bottom" - bottom: float = double() - @attrs.define class FlowingWell(Item): _keyword: ClassVar[str] = "flowing_well" @@ -158,7 +147,7 @@ class Auxiliary(Item): @attrs.define class StressPeriodData(Item): ifno: int = integer(index=True, fk="packagedata.ifno") - mawsetting: "Maw.Status | Maw.ConnectionStatus | Maw.Bottom | Maw.FlowingWell | Maw.Rate | Maw.WellHead | Maw.HeadLimit | Maw.Shutoff | Maw.RateScaling | Maw.Auxiliary" = union() # noqa: E501 + mawsetting: "Maw.Status | Maw.FlowingWell | Maw.Rate | Maw.WellHead | Maw.HeadLimit | Maw.Shutoff | Maw.RateScaling | Maw.Auxiliary" = union() # noqa: E501 auxiliary: Optional[NDArray[np.str_]] = array( default=None, @@ -311,8 +300,6 @@ class StressPeriodData(Item): MawConnectiondata = Maw.Connectiondata MawAngledata = Maw.Angledata MawStatus = Maw.Status -MawConnectionStatus = Maw.ConnectionStatus -MawBottom = Maw.Bottom MawFlowingWell = Maw.FlowingWell MawRate = Maw.Rate MawWellHead = Maw.WellHead diff --git a/flopy4/mf6/gwf/oc.py b/flopy4/mf6/gwf/oc.py index 42b816950..a1b48e6be 100644 --- a/flopy4/mf6/gwf/oc.py +++ b/flopy4/mf6/gwf/oc.py @@ -28,10 +28,10 @@ class Oc(Package): @attrs.define class Format(Record): _keyword: ClassVar[str] = "" - format_: str = string() - columns: Optional[int] = integer(default=None, tagged=True, optional=True) - width: Optional[int] = integer(default=None, tagged=True, optional=True) - digits: Optional[int] = integer(default=None, tagged=True, optional=True) + columns: int = integer(tagged=True) + width: int = integer(tagged=True) + digits: int = integer(tagged=True) + format_: Optional[str] = string(default=None, optional=True) @attrs.define class Headprint(Record): diff --git a/flopy4/mf6/gwt/ist.py b/flopy4/mf6/gwt/ist.py index b214d4976..434a2fd26 100644 --- a/flopy4/mf6/gwt/ist.py +++ b/flopy4/mf6/gwt/ist.py @@ -20,10 +20,10 @@ class Ist(Package): @attrs.define class Format(Record): _keyword: ClassVar[str] = "" - format_: str = string() - columns: Optional[int] = integer(default=None, tagged=True, optional=True) - width: Optional[int] = integer(default=None, tagged=True, optional=True) - digits: Optional[int] = integer(default=None, tagged=True, optional=True) + columns: int = integer(tagged=True) + width: int = integer(tagged=True) + digits: int = integer(tagged=True) + format_: Optional[str] = string(default=None, optional=True) @attrs.define class Cimprint(Record): diff --git a/flopy4/mf6/gwt/oc.py b/flopy4/mf6/gwt/oc.py index c1d271884..88815e0da 100644 --- a/flopy4/mf6/gwt/oc.py +++ b/flopy4/mf6/gwt/oc.py @@ -28,10 +28,10 @@ class Oc(Package): @attrs.define class Format(Record): _keyword: ClassVar[str] = "" - format_: str = string() - columns: Optional[int] = integer(default=None, tagged=True, optional=True) - width: Optional[int] = integer(default=None, tagged=True, optional=True) - digits: Optional[int] = integer(default=None, tagged=True, optional=True) + columns: int = integer(tagged=True) + width: int = integer(tagged=True) + digits: int = integer(tagged=True) + format_: Optional[str] = string(default=None, optional=True) @attrs.define class Concentrationprint(Record): diff --git a/flopy4/mf6/olf/oc.py b/flopy4/mf6/olf/oc.py index 75e94a594..30d8da95a 100644 --- a/flopy4/mf6/olf/oc.py +++ b/flopy4/mf6/olf/oc.py @@ -28,10 +28,10 @@ class Oc(Package): @attrs.define class Format(Record): _keyword: ClassVar[str] = "" - format_: str = string() - columns: Optional[int] = integer(default=None, tagged=True, optional=True) - width: Optional[int] = integer(default=None, tagged=True, optional=True) - digits: Optional[int] = integer(default=None, tagged=True, optional=True) + columns: int = integer(tagged=True) + width: int = integer(tagged=True) + digits: int = integer(tagged=True) + format_: Optional[str] = string(default=None, optional=True) @attrs.define class Qoutflowprint(Record): diff --git a/flopy4/mf6/record.py b/flopy4/mf6/record.py index 40c56b0a4..15ba7d370 100644 --- a/flopy4/mf6/record.py +++ b/flopy4/mf6/record.py @@ -287,7 +287,7 @@ def from_tokens(cls, tokens: str | list[str]) -> "Record": fields, in declaration order. E.g. for ``Oc.Headprint``, these are all equivalent: ``"HEAD PRINT_FORMAT COLUMNS 10 WIDTH 12 DIGITS 6 exponential"``, ``"COLUMNS 10 WIDTH 12 DIGITS 6 exponential"``, - ``"exponential"``. + ``"10 12 6 exponential"``. """ if isinstance(tokens, str): tokens = tokens.split() diff --git a/flopy4/mf6/utils/codegen/make.py b/flopy4/mf6/utils/codegen/make.py index 1810f0f0f..7e55d40c5 100644 --- a/flopy4/mf6/utils/codegen/make.py +++ b/flopy4/mf6/utils/codegen/make.py @@ -763,6 +763,9 @@ class can reference an earlier one). is a required tagged scalar (IMS ``INNER_RCLOSE ...``), its tag is the trigger token: it becomes ``_keyword`` and the child an untagged data field, so the record is found by its leading token like any other. + Not if a later child is tagged too (OC's ``COLUMNS WIDTH + DIGITS []``): the trigger's value is written + after the tagged fields, so it would land after ``DIGITS ``. Otherwise there is no trigger token (``_keyword = ""``) and all children become data fields. @@ -791,7 +794,11 @@ class bodies can't see sibling names at class-body-execution time. kw = first.name aliases = first.aliases data_children = children[1:] - elif getattr(first, "tagged", False) and not first.optional: + elif ( + getattr(first, "tagged", False) + and not first.optional + and not any(getattr(c, "tagged", False) for c in children[1:]) + ): kw = first.name aliases = getattr(first, "aliases", None) or [] data_children = children diff --git a/test/mf6/__snapshots__/test_mf6_io_roundtrip/test_roundtrip[mf6testtest060_gms_ets].json b/test/mf6/__snapshots__/test_mf6_io_roundtrip/test_roundtrip[mf6testtest060_gms_ets].json new file mode 100644 index 000000000..4c6d10127 --- /dev/null +++ b/test/mf6/__snapshots__/test_mf6_io_roundtrip/test_roundtrip[mf6testtest060_gms_ets].json @@ -0,0 +1,272 @@ +{ + "ets3_dis.chd": [ + "BEGIN OPTIONS", + " SAVE_FLOWS", + "END OPTIONS", + "", + "BEGIN DIMENSIONS", + " MAXBOUND 30", + "END DIMENSIONS", + "", + "BEGIN PERIOD 1", + "<30 data lines bd4bbce9b8276f4b>", + "END PERIOD 1" + ], + "ets3_dis.dis": [ + "BEGIN OPTIONS", + " LENGTH_UNITS METERS", + " NOGRB", + "END OPTIONS", + "", + "BEGIN DIMENSIONS", + " NLAY 3", + " NROW 15", + " NCOL 15", + "END DIMENSIONS", + "", + "BEGIN GRIDDATA", + " DELR", + " CONSTANT 1524.0", + "", + " DELC", + " CONSTANT 1524.0", + "", + " TOP", + " CONSTANT 60.0", + "", + " BOTM LAYERED", + "", + " CONSTANT -45.0", + " CONSTANT -120.0", + " CONSTANT -215.0", + " IDOMAIN LAYERED", + "", + " CONSTANT 1", + " CONSTANT 1", + " CONSTANT 1", + "END GRIDDATA" + ], + "ets3_dis.drn": [ + "BEGIN OPTIONS", + " AUXILIARY IFACE CONDFACT CELLGRP", + " SAVE_FLOWS", + "END OPTIONS", + "", + "BEGIN DIMENSIONS", + " MAXBOUND 9", + "END DIMENSIONS", + "", + "BEGIN PERIOD 1", + "<9 data lines 819fb6b43045c52b>", + "END PERIOD 1" + ], + "ets3_dis.evt": [ + "BEGIN OPTIONS", + " SAVE_FLOWS", + "END OPTIONS", + "", + "BEGIN DIMENSIONS", + " MAXBOUND 225", + " NSEG 3", + "END DIMENSIONS", + "", + "BEGIN PERIOD 1", + "<225 data lines 0790bd28ac5695b1>", + "END PERIOD 1", + "", + "BEGIN PERIOD 2", + "<225 data lines a42a9711757353b5>", + "END PERIOD 2", + "", + "BEGIN PERIOD 3", + "<225 data lines 90092b8965b86c00>", + "END PERIOD 3" + ], + "ets3_dis.ic": [ + "BEGIN GRIDDATA", + " STRT", + " CONSTANT 0.0", + "", + "END GRIDDATA" + ], + "ets3_dis.ims": [ + "BEGIN OPTIONS", + " PRINT_OPTION summary", + " COMPLEXITY moderate", + "END OPTIONS", + "", + "BEGIN NONLINEAR", + " OUTER_DVCLOSE 1e-06", + "END NONLINEAR", + "", + "BEGIN LINEAR", + " INNER_DVCLOSE 1e-05", + " INNER_RCLOSE 10000.0", + "END LINEAR" + ], + "ets3_dis.nam": [ + "BEGIN OPTIONS", + " LIST ets3_dis.out", + " PRINT_INPUT", + " PRINT_FLOWS", + " SAVE_FLOWS", + "END OPTIONS", + "", + "BEGIN PACKAGES", + " DIS6 ets3_dis.dis dis", + " CHD6 ets3_dis.chd chd-1", + " DRN6 ets3_dis.drn drn-1", + " EVT6 ets3_dis.evt evt-1", + " IC6 ets3_dis.ic ic", + " NPF6 ets3_dis.npf npf", + " OC6 ets3_dis.oc oc", + " RCH6 ets3_dis.rch rch-1", + " STO6 ets3_dis.sto sto", + " WEL6 ets3_dis.wel wel-1", + "END PACKAGES" + ], + "ets3_dis.npf": [ + "BEGIN OPTIONS", + " SAVE_FLOWS", + " VARIABLECV DEWATERED", + " PERCHED", + " REWET WETFCT 1.0 IWETIT 1 IHDWET 0", + "END OPTIONS", + "", + "BEGIN GRIDDATA", + " ICELLTYPE", + " CONSTANT 1", + "", + " K", + " INTERNAL", + "<2926 chars befdf43cbe6a4242>", + " K33", + " INTERNAL", + "<2926 chars ac8913717ec72222>", + " WETDRY", + " CONSTANT 0.01", + "", + "END GRIDDATA" + ], + "ets3_dis.oc": [ + "BEGIN OPTIONS", + " BUDGET FILEOUT ets3_dis.ccf", + " HEAD FILEOUT ets3_dis.hed", + " HEAD PRINT_FORMAT COLUMNS 10 WIDTH 11 DIGITS 4", + "END OPTIONS", + "", + "BEGIN PERIOD 1", + " PRINT BUDGET FIRST", + " SAVE HEAD FIRST", + " SAVE BUDGET FIRST", + "END PERIOD 1", + "", + "BEGIN PERIOD 2", + " PRINT BUDGET FIRST", + " SAVE HEAD FIRST", + " SAVE BUDGET FIRST", + "END PERIOD 2", + "", + "BEGIN PERIOD 3", + " PRINT BUDGET FIRST", + " SAVE HEAD FIRST", + " SAVE BUDGET FIRST", + " PRINT HEAD ALL", + "END PERIOD 3" + ], + "ets3_dis.rch": [ + "BEGIN OPTIONS", + " READASARRAYS", + "END OPTIONS", + "", + "BEGIN PERIOD 1", + " RECHARGE", + " CONSTANT 0.0009", + "", + "END PERIOD 1", + "", + "BEGIN PERIOD 2", + " RECHARGE", + " CONSTANT 0.0009", + "", + "END PERIOD 2" + ], + "ets3_dis.sto": [ + "BEGIN OPTIONS", + " SAVE_FLOWS", + "END OPTIONS", + "", + "BEGIN GRIDDATA", + " ICONVERT", + " CONSTANT 1", + "", + " SS", + " CONSTANT 0.0", + "", + " SY", + " CONSTANT 0.0", + "", + "END GRIDDATA", + "", + "BEGIN PERIOD 1", + " STEADY-STATE", + "END PERIOD 1", + "", + "BEGIN PERIOD 2", + " TRANSIENT", + "END PERIOD 2", + "", + "BEGIN PERIOD 3", + " TRANSIENT", + "END PERIOD 3" + ], + "ets3_dis.tdis": [ + "BEGIN OPTIONS", + " TIME_UNITS days", + "END OPTIONS", + "", + "BEGIN DIMENSIONS", + " NPER 3", + "END DIMENSIONS", + "", + "BEGIN PERIODDATA", + " 1.0 1 1.0", + " 1.0 1 1.0", + " 1.0 1 1.0", + "END PERIODDATA" + ], + "ets3_dis.wel": [ + "BEGIN OPTIONS", + " AUXILIARY IFACE QFACT CELLGRP", + " SAVE_FLOWS", + "END OPTIONS", + "", + "BEGIN DIMENSIONS", + " MAXBOUND 15", + "END DIMENSIONS", + "", + "BEGIN PERIOD 1", + "<15 data lines f5fce17a1bc30b36>", + "END PERIOD 1" + ], + "mfsim.nam": [ + "BEGIN OPTIONS", + "END OPTIONS", + "", + "BEGIN TIMING", + " TDIS6 ets3_dis.tdis", + "END TIMING", + "", + "BEGIN MODELS", + " GWF6 ets3_dis.nam GWF_Model", + "END MODELS", + "", + "BEGIN EXCHANGES", + "END EXCHANGES", + "", + "BEGIN SOLUTIONGROUP 1", + " MXITER 1", + " IMS6 ets3_dis.ims GWF_Model", + "END SOLUTIONGROUP 1" + ] +} diff --git a/test/mf6/__snapshots__/test_mf6_load_all_models/test_load_simulation[mf6testtest060_gms_ets].json b/test/mf6/__snapshots__/test_mf6_load_all_models/test_load_simulation[mf6testtest060_gms_ets].json new file mode 100644 index 000000000..d847aac4c --- /dev/null +++ b/test/mf6/__snapshots__/test_mf6_load_all_models/test_load_simulation[mf6testtest060_gms_ets].json @@ -0,0 +1,513 @@ +{ + "simulation": { + "__type__": "Simulation", + "continue_": false, + "dims": {}, + "exchanges": [], + "filename": "mfsim.nam", + "models": [ + "" + ], + "mxiter": 1, + "nocheck": false, + "print_input": false, + "solutiongroup": [ + "" + ], + "tdis": "", + "workspace": "" + }, + "simulation/GWF_Model": { + "__type__": "Gwf", + "api": [], + "chd": [ + "" + ], + "dims": {}, + "dis": "", + "drn": [ + "" + ], + "evt": [ + "" + ], + "filename": "ets3_dis.nam", + "ghb": [], + "ic": "", + "lak": [], + "list_": "ets3_dis.out", + "maw": [], + "name": "GWF_Model", + "npf": "", + "oc": "", + "print_flows": true, + "print_input": true, + "rch": [ + "" + ], + "riv": [], + "save_flows": true, + "sfr": [], + "sto": "", + "uzf": [], + "wel": [ + "" + ], + "workspace": "" + }, + "simulation/GWF_Model/chd-1": { + "__type__": "Chd", + "_stress_period_data": { + "0": { + "__table__": "StressPeriodData", + "aux": "float64[30, 0] da39a3ee5e6b4b0d", + "boundname": [ + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "cellid": "int64[30, 3] 85024be68c8b8bbb", + "head": "float64[30] de0e7c9e496fdd65", + "n": 30 + } + }, + "boundnames": false, + "dims": { + "ncelldim": 3, + "ncol": 15, + "ncpl": 225, + "nlay": 3, + "nodes": 675, + "nrow": 15 + }, + "filename": "ets3_dis.chd", + "name": "chd-1", + "print_flows": false, + "print_input": false, + "save_flows": true, + "ts": [] + }, + "simulation/GWF_Model/dis": { + "__type__": "Dis", + "botm": "float64[675] 88293fed49993361", + "delc": "float64[15] 08d3965f358bb62c", + "delr": "float64[15] 08d3965f358bb62c", + "dims": {}, + "export_array_ascii": false, + "export_array_netcdf": false, + "filename": "ets3_dis.dis", + "idomain": "int64[675] 51bb844a15459418", + "length_units": "METERS", + "name": "dis", + "ncol": 15, + "nlay": 3, + "nogrb": true, + "nrow": 15, + "top": "float64[225] 302a32eb86e5e362" + }, + "simulation/GWF_Model/drn-1": { + "__type__": "Drn", + "_stress_period_data": { + "0": { + "__table__": "StressPeriodData", + "aux": "float64[9, 3] be3a62cda200e2bf", + "boundname": [ + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "cellid": "int64[9, 3] a739c4e81e7fcc75", + "cond": "float64[9] 813468f3c3db1312", + "elev": "float64[9] 741275df2fd911db", + "n": 9 + } + }, + "auxiliary": [ + "IFACE", + "CONDFACT", + "CELLGRP" + ], + "boundnames": false, + "dims": { + "ncelldim": 3, + "ncol": 15, + "ncpl": 225, + "nlay": 3, + "nodes": 675, + "nrow": 15 + }, + "filename": "ets3_dis.drn", + "mover": false, + "name": "drn-1", + "print_flows": false, + "print_input": false, + "save_flows": true, + "ts": [] + }, + "simulation/GWF_Model/evt-1": { + "__type__": "Evt", + "_stress_period_data": { + "0": { + "__table__": "StressPeriodData", + "aux": "float64[225, 0] da39a3ee5e6b4b0d", + "boundname": "1350 chars e6be834cd4fec514", + "cellid": "int64[225, 3] 69e7be7018829203", + "depth": "float64[225] 29c3fc253524f2b4", + "n": 225, + "petm": "float64[225, 2] 7130d0fe9316b0c2", + "petm0": "1350 chars e6be834cd4fec514", + "pxdp": "float64[225, 2] 3dedb833f4136175", + "rate": "float64[225] 6a44b5eccf16b6aa", + "surface": "float64[225] 9d1cbc096a295737" + }, + "1": { + "__table__": "StressPeriodData", + "aux": "float64[225, 0] da39a3ee5e6b4b0d", + "boundname": "1350 chars e6be834cd4fec514", + "cellid": "int64[225, 3] 0f208be05ba59abb", + "depth": "float64[225] 29c3fc253524f2b4", + "n": 225, + "petm": "float64[225, 2] 7130d0fe9316b0c2", + "petm0": "1350 chars e6be834cd4fec514", + "pxdp": "float64[225, 2] 3dedb833f4136175", + "rate": "float64[225] 6a44b5eccf16b6aa", + "surface": "float64[225] 0e5aee74e26c5146" + }, + "2": { + "__table__": "StressPeriodData", + "aux": "float64[225, 0] da39a3ee5e6b4b0d", + "boundname": "1350 chars e6be834cd4fec514", + "cellid": "int64[225, 3] 0f208be05ba59abb", + "depth": "float64[225] 354b08e86e976fc4", + "n": 225, + "petm": "float64[225, 2] a78eba2ca799330e", + "petm0": "1350 chars e6be834cd4fec514", + "pxdp": "float64[225, 2] b4c9f651488c82bd", + "rate": "float64[225] 8e125d03c1e9710d", + "surface": "float64[225] 0e5aee74e26c5146" + } + }, + "boundnames": false, + "dims": { + "ncelldim": 3, + "ncol": 15, + "ncpl": 225, + "nlay": 3, + "nodes": 675, + "nrow": 15 + }, + "filename": "ets3_dis.evt", + "fixed_cell": false, + "name": "evt-1", + "nseg": 3, + "print_flows": false, + "print_input": false, + "save_flows": true, + "surf_rate_specified": false, + "ts": [] + }, + "simulation/GWF_Model/ic": { + "__type__": "Ic", + "dims": { + "ncelldim": 3, + "ncol": 15, + "ncpl": 225, + "nlay": 3, + "nodes": 675, + "nrow": 15 + }, + "export_array_ascii": false, + "export_array_netcdf": false, + "filename": "ets3_dis.ic", + "name": "ic", + "strt": "float64[675] 4b6a77fd2118c2a0" + }, + "simulation/GWF_Model/npf": { + "__type__": "Npf", + "cvoptions": { + "__type__": "Cvoptions", + "dewatered": true + }, + "dims": { + "ncelldim": 3, + "ncol": 15, + "ncpl": 225, + "nlay": 3, + "nodes": 675, + "nrow": 15 + }, + "export_array_ascii": false, + "export_array_netcdf": false, + "filename": "ets3_dis.npf", + "highest_cell_saturation": false, + "icelltype": "int64[675] 51bb844a15459418", + "k": "float64[675] 4a0a83c295c5796c", + "k22overk": false, + "k33": "float64[675] c926c4ed15e78979", + "k33overk": false, + "name": "npf", + "perched": true, + "print_flows": false, + "rewet": { + "__type__": "Rewet", + "ihdwet": 0, + "iwetit": 1, + "wetfct": "1.0" + }, + "save_flows": true, + "save_saturation": false, + "save_specific_discharge": false, + "thickstrt": false, + "wetdry": "float64[675] 8523721a2130adfe" + }, + "simulation/GWF_Model/oc": { + "__type__": "Oc", + "_stress_period_data": { + "0": [ + { + "__type__": "Print", + "ocsetting": "FIRST", + "rtype": "BUDGET" + }, + { + "__type__": "Save", + "ocsetting": "FIRST", + "rtype": "HEAD" + }, + { + "__type__": "Save", + "ocsetting": "FIRST", + "rtype": "BUDGET" + } + ], + "1": [ + { + "__type__": "Print", + "ocsetting": "FIRST", + "rtype": "BUDGET" + }, + { + "__type__": "Save", + "ocsetting": "FIRST", + "rtype": "HEAD" + }, + { + "__type__": "Save", + "ocsetting": "FIRST", + "rtype": "BUDGET" + } + ], + "2": [ + { + "__type__": "Print", + "ocsetting": "FIRST", + "rtype": "BUDGET" + }, + { + "__type__": "Save", + "ocsetting": "FIRST", + "rtype": "HEAD" + }, + { + "__type__": "Save", + "ocsetting": "FIRST", + "rtype": "BUDGET" + }, + { + "__type__": "Print", + "ocsetting": "ALL", + "rtype": "HEAD" + } + ] + }, + "budget_file": "ets3_dis.ccf", + "dims": { + "ncelldim": 3, + "ncol": 15, + "ncpl": 225, + "nlay": 3, + "nodes": 675, + "nrow": 15 + }, + "filename": "ets3_dis.oc", + "head_file": "ets3_dis.hed", + "headprint": { + "__type__": "Headprint", + "formatrecord": { + "__type__": "Format", + "columns": 10, + "digits": 4, + "format_": null, + "width": 11 + } + }, + "name": "oc" + }, + "simulation/GWF_Model/rch-1": { + "__type__": "Rcha", + "dims": { + "ncelldim": 3, + "ncol": 15, + "ncpl": 225, + "nlay": 3, + "nodes": 675, + "nrow": 15 + }, + "export_array_netcdf": false, + "filename": "ets3_dis.rch", + "fixed_cell": false, + "name": "rch-1", + "print_flows": false, + "print_input": false, + "readasarrays": true, + "recharge": { + "0": "float64[675] b93e59bb6a62703c", + "1": "float64[675] b93e59bb6a62703c" + }, + "save_flows": false, + "tas": [] + }, + "simulation/GWF_Model/sto": { + "__type__": "Sto", + "dims": { + "ncelldim": 3, + "ncol": 15, + "ncpl": 225, + "nlay": 3, + "nodes": 675, + "nrow": 15 + }, + "export_array_ascii": false, + "export_array_netcdf": false, + "filename": "ets3_dis.sto", + "iconvert": "int64[675] 51bb844a15459418", + "name": "sto", + "save_flows": true, + "ss": "float64[675] 4b6a77fd2118c2a0", + "ss_confined_only": false, + "storagecoefficient": false, + "stress_period_data": { + "0": "steady-state", + "1": "transient", + "2": "transient" + }, + "sy": "float64[675] 4b6a77fd2118c2a0" + }, + "simulation/GWF_Model/wel-1": { + "__type__": "Wel", + "_stress_period_data": { + "0": { + "__table__": "StressPeriodData", + "aux": "float64[15, 3] 490166baf7cb3a9a", + "boundname": [ + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "cellid": "int64[15, 3] 6a0f93accc30c380", + "n": 15, + "q": "float64[15] df3c4269264dfabf" + } + }, + "auxiliary": [ + "IFACE", + "QFACT", + "CELLGRP" + ], + "boundnames": false, + "dims": { + "ncelldim": 3, + "ncol": 15, + "ncpl": 225, + "nlay": 3, + "nodes": 675, + "nrow": 15 + }, + "filename": "ets3_dis.wel", + "flow_reduction_length": false, + "mover": false, + "name": "wel-1", + "print_flows": false, + "print_input": false, + "save_flows": true, + "ts": [] + }, + "simulation/ims-1": { + "__type__": "Ims", + "complexity": "moderate", + "dims": {}, + "filename": "ets3_dis.ims", + "inner_dvclose": "1e-05", + "name": "ims-1", + "outer_dvclose": "1e-06", + "print_option": "summary", + "rclose": { + "__type__": "Rclose", + "inner_rclose": "10000.0", + "rclose_option": null + }, + "slnmnames": [ + "GWF_Model" + ] + }, + "simulation/tdis": { + "__type__": "Tdis", + "dims": {}, + "filename": "ets3_dis.tdis", + "name": "tdis", + "nper": 3, + "perioddata": { + "__table__": "Perioddata", + "n": 3, + "nstp": "int64[3] 8aaab8ea3dc5e112", + "perlen": "float64[3] 12a72e95677fc01d", + "tsmult": "float64[3] 12a72e95677fc01d" + }, + "time_units": "days" + } +} diff --git a/test/mf6/test_mf6_codec.py b/test/mf6/test_mf6_codec.py index 21a62a576..369e6a5a8 100644 --- a/test/mf6/test_mf6_codec.py +++ b/test/mf6/test_mf6_codec.py @@ -976,7 +976,7 @@ def test_series_attributes_from_values(): ("gwf.Npf", "xt3doptions", True, ("Xt3doptions", ())), ("gwf.Npf", "xt3doptions", {"rhs": True}, ("Xt3doptions", (True,))), ("gwf.Oc", "headprint", "COLUMNS 10 WIDTH 12 DIGITS 6 GENERAL", ("Headprint", None)), - ("gwt.Oc", "concentrationprint", ("GENERAL", 10, 12, 6), ("Concentrationprint", None)), + ("gwt.Oc", "concentrationprint", (10, 12, 6, "GENERAL"), ("Concentrationprint", None)), ( "gwe.Oc", "temperatureprint", @@ -1001,7 +1001,7 @@ def test_record_fields_from_values(cls_path, name, value, record): cls = getattr(importlib.import_module(f"flopy4.mf6.{module}"), cls_name) rec_name, args = record if args is None: # a print format, one nested Format - args = (cls.Format("GENERAL", columns=10, width=12, digits=6),) + args = (cls.Format(columns=10, width=12, digits=6, format_="GENERAL"),) expected = getattr(cls, rec_name)(*args) component = cls(**{name: value}) assert getattr(component, name) == expected @@ -1401,6 +1401,75 @@ def test_oc_head_file_and_print_format(): assert "STEPS 1 5 10\n" in out +def test_oc_print_format_without_format_word(): + """The format word is optional. Left out, it stays out when written, + rather than being written as None.""" + from flopy4.mf6.converter.egress.unstructure import unstructure_component + from flopy4.mf6.converter.ingress.structure import structure_component + from flopy4.mf6.gwf import Oc + + text = """BEGIN OPTIONS + HEAD PRINT_FORMAT COLUMNS 10 WIDTH 11 DIGITS 4 +END OPTIONS +""" + oc = structure_component(loads(text), Oc) + assert oc.headprint.formatrecord == Oc.Format(columns=10, width=11, digits=4) + assert oc.headprint.formatrecord.format_ is None + assert " HEAD PRINT_FORMAT COLUMNS 10 WIDTH 11 DIGITS 4\n" in dumps(unstructure_component(oc)) + + +_PRINT_FORMATS = [ + ("gwf-oc", "HEAD"), + ("gwt-oc", "CONCENTRATION"), + ("gwe-oc", "TEMPERATURE"), + ("chf-oc", "QOUTFLOW"), + ("olf-oc", "QOUTFLOW"), + ("gwt-ist", "CIM"), +] + + +@pytest.mark.parametrize("dfn_name, word", _PRINT_FORMATS) +@pytest.mark.parametrize("format_", ["", " GENERAL"]) +def test_typed_print_format_word_optional(dfn_name, word, format_): + """Every component with a print format parses it with or without the + format word, and a word that's there is still the format.""" + from flopy4.mf6.codec.reader import loads_typed + + text = ( + f"BEGIN OPTIONS\n {word} PRINT_FORMAT COLUMNS 10 WIDTH 11 DIGITS 4{format_}\nEND OPTIONS\n" + ) + records = loads_typed(text, dfn_name)["options"] + assert len(records) == 1 + expected = {"columns": 10, "width": 11, "digits": 4} + if format_: + expected["format"] = format_.strip() + assert next(iter(records.values())) == {"formatrecord": expected} + + +@pytest.mark.parametrize("dfn_name, word", _PRINT_FORMATS) +@pytest.mark.parametrize( + "record", + [ + "COLUMNS 10", + "COLUMNS 10 WIDTH 11", + "COLUMNS 10 WIDTH 11 FIXED", + "COLUMNS 10 DIGITS 4", + "GENERAL", + ], +) +def test_typed_print_format_partial_rejected(dfn_name, word, record): + """COLUMNS, WIDTH and DIGITS are all required, in that order. MF6 used + to ignore a format that stopped early, and rejects it since + MODFLOW-ORG/modflow6#3129.""" + from lark.exceptions import UnexpectedInput + + from flopy4.mf6.codec.reader import loads_typed + + text = f"BEGIN OPTIONS\n {word} PRINT_FORMAT {record}\nEND OPTIONS\n" + with pytest.raises(UnexpectedInput): + loads_typed(text, dfn_name) + + def test_ims_rclose_and_unknown_block(): from flopy4.mf6.converter.egress.unstructure import unstructure_component from flopy4.mf6.converter.ingress.structure import structure_component @@ -3472,38 +3541,52 @@ def test_headprint_from_tokens_no_prefix(): assert hp.formatrecord.digits == 6 -def test_headprint_from_tokens_format_only(): - """A single untagged token populates the required positional field.""" +def test_headprint_from_tokens_no_format(): + """The format word is optional.""" from flopy4.mf6.gwf.oc import Oc - hp = Oc.Headprint.from_tokens("exponential") - assert hp.formatrecord.format_ == "exponential" - assert hp.formatrecord.columns is None - assert hp.formatrecord.width is None - assert hp.formatrecord.digits is None + hp = Oc.Headprint.from_tokens("COLUMNS 10 WIDTH 12 DIGITS 6") + assert hp.formatrecord == Oc.Format(columns=10, width=12, digits=6) + assert hp.formatrecord.format_ is None + + +@pytest.mark.parametrize( + "tokens", + [ + "exponential", + "COLUMNS 10 exponential", + "COLUMNS 10 WIDTH 12", + "WIDTH 15 DIGITS 4 fixed", + "COLUMNS 10 DIGITS 6", + ], +) +def test_headprint_from_tokens_partial_raises(tokens): + """COLUMNS, WIDTH and DIGITS are all required.""" + from flopy4.mf6.gwf.oc import Oc + + with pytest.raises((TypeError, ValueError)): + Oc.Headprint.from_tokens(tokens) def test_headprint_from_tokens_list(): """Token list form works the same as the string form.""" from flopy4.mf6.gwf.oc import Oc - hp = Oc.Headprint.from_tokens(["COLUMNS", "10", "exponential"]) - assert hp.formatrecord.format_ == "exponential" - assert hp.formatrecord.columns == 10 - assert hp.formatrecord.width is None - assert hp.formatrecord.digits is None + hp = Oc.Headprint.from_tokens(["COLUMNS", "10", "WIDTH", "12", "DIGITS", "6", "exponential"]) + assert hp == Oc.Headprint.from_tokens("COLUMNS 10 WIDTH 12 DIGITS 6 exponential") def test_headprint_from_tokens_tagged_types(): """Tagged integer fields are coerced from string tokens to int.""" from flopy4.mf6.gwf.oc import Oc - hp = Oc.Headprint.from_tokens("WIDTH 15 DIGITS 4 fixed") + hp = Oc.Headprint.from_tokens("COLUMNS 2 WIDTH 15 DIGITS 4 fixed") + assert isinstance(hp.formatrecord.columns, int) + assert hp.formatrecord.columns == 2 assert isinstance(hp.formatrecord.width, int) assert hp.formatrecord.width == 15 assert isinstance(hp.formatrecord.digits, int) assert hp.formatrecord.digits == 4 - assert hp.formatrecord.columns is None def test_rclose_from_tokens_with_keyword(): diff --git a/test/mf6/test_mf6_load_all_models.py b/test/mf6/test_mf6_load_all_models.py index 126c8542b..fb81d11be 100644 --- a/test/mf6/test_mf6_load_all_models.py +++ b/test/mf6/test_mf6_load_all_models.py @@ -339,6 +339,7 @@ "mf6/test/test056_mt3dms_usgs_gwtex_dev", "mf6/test/test057_transientchd", "mf6/test/test059_mvlake_lak_ss", + "mf6/test/test060_gms_ets", "mf6/test/test061_csub_holly", "mf6/test/test061_csub_jacob", "mf6/test/test100_ss_ic",