Skip to content
Merged
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
6 changes: 3 additions & 3 deletions docs/examples/quickstart.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from flopy4.mf6 import Sim, Tdis
from flopy4.mf6 import Simulation, Tdis
from flopy4.mf6.gwf import Chd, Dis, Gwf, Ic, Npf, Oc

# TODO rewrite bottom up

ws = "./mymodel"
name = "mymodel"
sim = Sim(name=name, path=ws, exe="mf6")
sim = Simulation(name=name)
tdis = Tdis(sim)
gwf = Gwf(sim, name=name, save_flows=True)
dis = Dis(gwf, nrow=10, ncol=10)
ic = Ic(gwf)
npf = Npf(gwf, save_specific_discharge=True)
chd = Chd(
gwf,
stress_period_data=[[(0, 0, 0), 1.0], [(0, 9, 9), 0.0]],
head={(0, 0, 0): 1.0, (0, 9, 9): 0.0},
)

# list input in the mf6 paradigm, just stored in xarray.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/quickstart_expanded.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
changes to support.
"""

from flopy4.mf6 import Sim, Tdis
from flopy4.mf6 import Simulation, Tdis
from flopy4.mf6.gwf import Chd, Dis, Gwf, Ic, Npf, Oc

ws = "./mymodel"
name = "mymodel"
sim = Sim(name=name, path=ws, exe="mf6")
sim = Simulation(name=name, path=ws, exe="mf6")
tdis = Tdis(sim)
gwf = Gwf(sim, name=name, save_flows=True)
dis = Dis(gwf, nrow=10, ncol=10)
Expand Down
34 changes: 33 additions & 1 deletion flopy4/mf6/gwf/chd.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
from pathlib import Path
from typing import Optional

import attrs
import numpy as np
from attrs import define
from numpy.typing import NDArray
from xattree import array, field, xattree
from xattree import _get_xatspec, array, field, xattree

from flopy4.mf6 import Package

dnodata = 1e30


def _get_nn(ncol, nrow, k, i, j):
return k * nrow * ncol + i * ncol + j


def _convert_array(value, self_, field):
if not isinstance(value, dict):
return value

inherited_dims = self_.__dict__.get("dims", {})
spec = _get_xatspec(type(self_))
field = spec.arrays["head"]
shape = field.dims
if not shape:
raise ValueError()
dims = [inherited_dims.get(d, d) for d in shape]
# TODO pull out dtype from annotation
a = np.full(dims, fill_value=dnodata, dtype=np.float64)
for kper, period in value.items():
if kper == "*":
kper = 0
for cellid, v in period.items():
nn = _get_nn(inherited_dims["col"], inherited_dims["row"], *cellid)
a[kper, nn] = v
return a


@xattree(multi="list")
class Chd(Package):
Expand Down Expand Up @@ -46,6 +75,9 @@ class Steps:
),
default=None,
metadata={"block": "period"},
converter=attrs.Converter(
_convert_array, takes_self=True, takes_field=True
),
)
aux: Optional[NDArray[np.floating]] = array(
dims=(
Expand Down
Loading