Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flopy4/mf6/chf/oc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
format_: Optional[str] = string(default=None, optional=True)

@attrs.define
class Qoutflowprint(Record):
Expand Down
3 changes: 2 additions & 1 deletion flopy4/mf6/codec/reader/grammar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from flopy4.mf6.codec.reader.grammar import filters
from flopy4.mf6.codec.reader.grammar.names import rule_name, to_rule_name
from flopy4.mf6.utils.codegen.dfn_fixes import fix_component


def _get_env():
Expand Down Expand Up @@ -128,7 +129,7 @@ def make_grammar(component: Component, outdir: PathLike):
env = _get_env()
template = env.get_template("component.lark.jinja")
target_path = outdir / f"{component.name}.lark"
blocks, fields = _to_context(component.blocks or {})
blocks, fields = _to_context(fix_component(component).blocks or {})
text = template.render(name=component.name, blocks=blocks, fields=fields)
# one trailing newline, however the template's last rule ends
target_path.write_text(text.rstrip("\n") + "\n")
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/codec/reader/grammar/generated/chf-oc.lark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/codec/reader/grammar/generated/gwe-oc.lark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/codec/reader/grammar/generated/gwf-oc.lark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/codec/reader/grammar/generated/gwt-ist.lark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/codec/reader/grammar/generated/gwt-oc.lark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/codec/reader/grammar/generated/olf-oc.lark
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/gwe/oc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
format_: Optional[str] = string(default=None, optional=True)

@attrs.define
class Temperatureprint(Record):
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/gwf/oc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
format_: Optional[str] = string(default=None, optional=True)

@attrs.define
class Headprint(Record):
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/gwt/ist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
format_: Optional[str] = string(default=None, optional=True)

@attrs.define
class Cimprint(Record):
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/gwt/oc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
format_: Optional[str] = string(default=None, optional=True)

@attrs.define
class Concentrationprint(Record):
Expand Down
2 changes: 1 addition & 1 deletion flopy4/mf6/olf/oc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
format_: Optional[str] = string(default=None, optional=True)

@attrs.define
class Qoutflowprint(Record):
Expand Down
39 changes: 39 additions & 0 deletions flopy4/mf6/utils/codegen/dfn_fixes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Corrections for where MF6 accepts input its DFNs say it doesn't.

Classes and grammars are generated from whichever release's DFNs ``flopy4 mf6
sync`` reads, so a correction has to be made during generation to survive a
sync. One should be removed when no supported release's DFNs need it.
"""

from typing import Any

from modflow_devtools.dfns.schema import Component, Record

# Record parts MF6 doesn't require but the DFNs mark `optional false`.
#
# formatrecord's format: MF6's `print_format` (src/Utilities/InputOutput.f90)
# reads whatever words follow DIGITS, and without any keeps the caller's edit
# descriptor. mf6/test/test060_gms_ets relies on this.
_OPTIONAL_PARTS: dict[str, frozenset[str]] = {"formatrecord": frozenset({"format"})}


def _fix_field(field: Any) -> Any:
if not isinstance(field, Record):
return field
optional = _OPTIONAL_PARTS.get(field.name, frozenset())
fixed = {}
for name, part in field.fields.items():
part = _fix_field(part)
fixed[name] = part.model_copy(update={"optional": True}) if name in optional else part
return field.model_copy(update={"fields": fixed})


def fix_component(component: Component) -> Component:
"""A copy of the component, with the DFN corrections applied."""
blocks = {
name: block.model_copy(
update={"fields": {k: _fix_field(f) for k, f in block.fields.items()}}
)
for name, block in (component.blocks or {}).items()
}
return component.model_copy(update={"blocks": blocks or component.blocks})
5 changes: 4 additions & 1 deletion flopy4/mf6/utils/codegen/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
)

from . import filters
from .dfn_fixes import fix_component
from .filters import ColumnSpec, FieldV3, ItemColumn, _dq, item_class, pascal_name, python_repr

# Pre-computed context dataclasses
Expand Down Expand Up @@ -2253,7 +2254,9 @@ def make_modules(
for name, component in dfns.items():
if name in skip:
continue
spec = build_component_spec(component, root=outdir, developmode=developmode, dfns=dfns)
spec = build_component_spec(
fix_component(component), root=outdir, developmode=developmode, dfns=dfns
)
if existing_only:
if not spec.outpath.exists():
if verbose:
Expand Down
Loading
Loading