Skip to content
Draft
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
4 changes: 3 additions & 1 deletion flopy4/mf6/gwf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from xattree import xattree

from flopy4.mf6.gwf.chd import Chd
from flopy4.mf6.gwf.chdg import Chdg
from flopy4.mf6.gwf.dis import Dis
from flopy4.mf6.gwf.drn import Drn
from flopy4.mf6.gwf.ic import Ic
Expand All @@ -19,7 +20,7 @@
from flopy4.mf6.utils import open_cbc, open_hds
from flopy4.utils import to_path

__all__ = ["Gwf", "Chd", "Dis", "Drn", "Ic", "Npf", "Oc", "Wel"]
__all__ = ["Gwf", "Chd", "Chdg", "Dis", "Drn", "Ic", "Npf", "Oc", "Wel"]


def convert_grid(value):
Expand Down Expand Up @@ -76,6 +77,7 @@ def budget(self):
oc: Oc = field(block="packages")
npf: Npf = field(block="packages")
chd: list[Chd] = field(block="packages")
chdg: list[Chdg] = field(block="packages")
wel: list[Wel] = field(block="packages")
drn: list[Drn] = field(block="packages")
output: Output = attrs.field(
Expand Down
48 changes: 48 additions & 0 deletions flopy4/mf6/gwf/chdg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from pathlib import Path
from typing import ClassVar, Optional

import numpy as np
from attrs import Converter
from numpy.typing import NDArray
from xattree import xattree

from flopy4.mf6.converter import structure_array
from flopy4.mf6.package import Package
from flopy4.mf6.spec import array, field, path
from flopy4.utils import to_path


@xattree
class Chdg(Package):
multi_package: ClassVar[bool] = True
auxiliary: Optional[list[str]] = array(block="options", default=None)
auxmultname: Optional[str] = field(block="options", default=None)
print_input: bool = field(block="options", default=False)
print_flows: bool = field(block="options", default=False)
save_flows: bool = field(block="options", default=False)
ts_filerecord: Optional[Path] = path(
block="options", default=None, converter=to_path, inout="filein"
)
obs_filerecord: Optional[Path] = path(
block="options", default=None, converter=to_path, inout="fileout"
)
dev_no_newton: bool = field(default=False, block="options")
maxbound: Optional[int] = field(block="dimensions", default=None, init=False)
head: Optional[NDArray[np.float64]] = array(
block="period",
dims=(
"nper",
"nodes",
),
default=None,
converter=Converter(structure_array, takes_self=True, takes_field=True),
)
aux: Optional[NDArray[np.float64]] = array(
block="period",
dims=(
"nper",
"nodes",
),
default=None,
converter=Converter(structure_array, takes_self=True, takes_field=True),
)
44 changes: 43 additions & 1 deletion test/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

from flopy4.mf6.component import COMPONENTS
from flopy4.mf6.constants import FILL_DNODATA, LENBOUNDNAME
from flopy4.mf6.gwf import Chd, Dis, Gwf, Ic, Npf, Oc
from flopy4.mf6.gwf import Chd, Chdg, Dis, Gwf, Ic, Npf, Oc
from flopy4.mf6.ims import Ims
from flopy4.mf6.simulation import Simulation
from flopy4.mf6.tdis import Tdis

DNODATA = 3.0e30


def test_registry():
assert COMPONENTS["simulation"] is Simulation
Expand Down Expand Up @@ -394,6 +396,46 @@ def test_quickstart(function_tmpdir):
sim.run()


def test_quickstart_array(function_tmpdir):
sim_name = "quickstart"
gwf_name = "mymodel"
nlay = 1
nrow = 10
ncol = 10
time = ModelTime(perlen=[1.0], nstp=[1], tsmult=[1.0])
ims = Ims(filename="mymodel.ims", models=[gwf_name])
dis = Dis(
nlay=nlay,
nrow=nrow,
ncol=ncol,
top=1.0,
botm=0.0,
)
sim = Simulation(
tdis=time,
workspace=function_tmpdir,
name=sim_name,
solutions={"ims": ims},
)
gwf = Gwf(parent=sim, dis=dis, name=gwf_name)
ic = Ic(parent=gwf)
oc = Oc(
parent=gwf,
budget_file=f"{gwf_name}.bud",
head_file=f"{gwf_name}.hds",
save_head=["all"],
save_budget=["all"],
)
npf = Npf(parent=gwf, icelltype=0, k=1.0)
head = {0: np.full((nlay, nrow, ncol), DNODATA, dtype=float)}
head[0][0, 0, 0] = 1.0
head[0][0, 9, 9] = 0.0
chd = Chdg(parent=gwf, head=head)

sim.write()
sim.run()


def test_write_ascii(function_tmpdir):
sim_name = "sim"
gwf_name = "gwf"
Expand Down
Loading