Skip to content

Commit 0c52f8c

Browse files
committed
wip
1 parent 8f94b9b commit 0c52f8c

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

flopy4/mf6/gwf/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
__all__ = ["Gwf", "Chd", "Dis", "Ic", "Npf", "Oc"]
2020

2121

22+
def convert_grid(value):
23+
if isinstance(value, Grid):
24+
return Dis.from_grid(value)
25+
if isinstance(value, Dis):
26+
return value
27+
raise TypeError(
28+
f"Expected Grid or Dis, got {type(value)}"
29+
)
30+
31+
2232
@xattree
2333
class Gwf(Model):
2434
@define
@@ -40,7 +50,7 @@ def budget(self):
4050
merge_to_dataset=True,
4151
)
4252

43-
dis: Dis = field(converter=lambda grid: Dis.from_grid(grid))
53+
dis: Dis = field(converter=convert_grid)
4454
ic: Ic = field()
4555
oc: Oc = field()
4656
npf: Npf = field()

flopy4/mf6/simulation.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@
1212
from flopy.discretization.modeltime import ModelTime
1313

1414

15+
def convert_time(value):
16+
if isinstance(value, ModelTime):
17+
return Tdis.from_time(value)
18+
if isinstance(value, Tdis):
19+
return value
20+
raise TypeError(
21+
f"Expected ModelTime or Tdis, got {type(value)}"
22+
)
23+
1524
@xattree
1625
class Simulation(Component):
1726
models: dict[str, Model] = field()
1827
exchanges: dict[str, Exchange] = field()
1928
solutions: dict[str, Solution] = field()
2029
sim_ws: Path = field(default=None)
21-
tdis: Tdis = field(converter=lambda time: Tdis.from_time(time))
30+
tdis: Tdis = field(converter=convert_time)

test/test_component.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ def test_init_gwf_explicit_dims():
4949
)
5050

5151
assert isinstance(gwf.data, DataTree)
52-
assert gwf.dis is not dis # dimension order switched.. is this ok?
52+
assert gwf.dis is dis # dimension order switched.. is this ok?
5353
assert gwf.ic is ic
5454
assert gwf.oc is oc
5555
assert gwf.npf is npf
5656
assert gwf.chd[0] is chd
57-
assert gwf.data.dis is not dis.data
57+
assert gwf.data.dis is dis.data
5858
assert gwf.data.ic is ic.data
5959
assert gwf.data.oc is oc.data
6060
assert gwf.data.npf is npf.data
@@ -106,7 +106,7 @@ def test_init_gwf_dis_first():
106106
chd = Chd(parent=gwf, strict=False)
107107

108108
assert isinstance(gwf.data, DataTree)
109-
assert gwf.dis is not dis
109+
assert gwf.dis is dis
110110
assert gwf.ic is ic
111111
assert gwf.oc is oc
112112
assert gwf.npf is npf
@@ -185,7 +185,7 @@ def test_init_sim_explicit_dims():
185185
assert isinstance(sim.data, DataTree)
186186
assert sim.data.tdis is tdis.data
187187
assert sim.data.gwf is gwf.data
188-
assert gwf.dis is not dis # gwf.dis has inherited dim nper
188+
assert gwf.dis is dis # gwf.dis has inherited dim nper
189189
assert gwf.ic is ic
190190
assert gwf.oc is oc
191191
assert gwf.npf is npf

0 commit comments

Comments
 (0)