Skip to content

Commit e3a33b7

Browse files
deltamarnixwpbonelli
authored andcommitted
Add output budget and head to Gwf model
Still use the imod functions.
1 parent 9f385dc commit e3a33b7

File tree

5 files changed

+367
-325
lines changed

5 files changed

+367
-325
lines changed

docs/examples/quickstart.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from pathlib import Path
22

3-
import imod.mf6
43
import matplotlib.pyplot as plt
54
import numpy as np
65

@@ -9,11 +8,11 @@
98
from flopy4.mf6.simulation import Simulation
109
from flopy4.mf6.tdis import Tdis
1110

12-
ws = "./mymodel"
11+
ws = "./quickstart_data"
1312
name = "mymodel"
1413
tdis = Tdis()
1514
ims = Ims()
16-
sim = Simulation(name=name, tdis=tdis, solutions={"ims": ims})
15+
sim = Simulation(name=name, tdis=tdis, solutions={"ims": ims}, sim_ws=ws)
1716
dis = Dis(nrow=10, ncol=10)
1817
gwf = Gwf(parent=sim, name=name, save_flows=True, dis=dis)
1918
ic = Ic(parent=gwf)
@@ -43,17 +42,12 @@
4342
assert oc.data.save_head.sel(per=0) == "all"
4443

4544
# PLOT
46-
# create budget reader
47-
bpth = Path("./quickstart_data/mymodel.bud")
48-
grbpth = Path("./quickstart_data/mymodel.dis.grb")
4945

5046
# set specific discharge
51-
spdis = imod.mf6.open_cbc(bpth, grbpth, merge_to_dataset=True)
52-
53-
# create head reader
54-
hpth = Path("./quickstart_data/mymodel.hds")
55-
heads = imod.mf6.open_hds(hpth, grbpth)
47+
spdis = gwf.output.budget
48+
heads = gwf.output.head
5649
sq = heads.squeeze()
50+
5751
fig, ax = plt.subplots()
5852
ax.tick_params()
5953
ax.set_xticks(np.arange(0, 11, 2), minor=False)

flopy4/mf6/gwf/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from pathlib import Path
22
from typing import Optional
33

4+
import attrs
5+
import imod
6+
import xarray as xr
47
from attrs import define
58
from xattree import field, xattree
69

@@ -16,11 +19,33 @@
1619

1720
@xattree
1821
class Gwf(Model):
22+
@define
23+
class Output:
24+
parent: "Gwf" = field(repr=False)
25+
26+
@property
27+
def head(self) -> xr.DataArray:
28+
return imod.mf6.open_hds(
29+
Path("quickstart_data", f"{self.parent.name}.hds"),
30+
Path("quickstart_data", f"{self.parent.name}.dis.grb"),
31+
)
32+
33+
@property
34+
def budget(self):
35+
return imod.mf6.open_cbc(
36+
Path("./quickstart_data/mymodel.bud"),
37+
Path("./quickstart_data/mymodel.dis.grb"),
38+
merge_to_dataset=True,
39+
)
40+
1941
dis: Dis = field()
2042
ic: Ic = field()
2143
oc: Oc = field()
2244
npf: Npf = field()
2345
chd: list[Chd] = field()
46+
output: Output = attrs.field(
47+
default=attrs.Factory(lambda self: Gwf.Output(self), takes_self=True)
48+
)
2449

2550
@define
2651
class NewtonOptions:

flopy4/mf6/simulation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
from xattree import field, xattree
24

35
from flopy4.mf6.component import Component
@@ -9,6 +11,7 @@
911

1012
@xattree
1113
class Simulation(Component):
14+
sim_ws: Path = field()
1215
models: dict[str, Model] = field()
1316
exchanges: dict[str, Exchange] = field()
1417
solutions: dict[str, Solution] = field()

0 commit comments

Comments
 (0)