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
31 changes: 16 additions & 15 deletions docs/examples/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

import matplotlib.pyplot as plt
import numpy as np
from flopy.discretization.modeltime import ModelTime
from flopy.discretization.structuredgrid import StructuredGrid

from flopy4.mf6.gwf import Chd, Dis, Gwf, Ic, Npf, Oc
from flopy4.mf6.gwf import Chd, Gwf, Npf, Oc
from flopy4.mf6.ims import Ims
from flopy4.mf6.simulation import Simulation
from flopy4.mf6.tdis import Tdis

ws = Path(__file__).parent / "quickstart_data"
name = "mymodel"
tdis = Tdis()
ims = Ims()
sim = Simulation(name=name, tdis=tdis, solutions={"ims": ims}, sim_ws=ws)
dis = Dis(nrow=10, ncol=10)
gwf = Gwf(parent=sim, name=name, save_flows=True, dis=dis)
ic = Ic(parent=gwf)

name = "quickstart"
workspace = Path(__file__).parent / name
time = ModelTime(perlen=[1.0], nstp=[1])
grid = StructuredGrid(nlay=1, nrow=10, ncol=10)
sim = Simulation(name=name, path=workspace, tdis=time)
ims = Ims(parent=sim)
gwf_name = "mymodel"
gwf = Gwf(parent=sim, name=gwf_name, save_flows=True, dis=grid)
npf = Npf(parent=gwf, save_specific_discharge=True)
chd = Chd(
parent=gwf,
head={"*": {(0, 0, 0): 1.0, (0, 9, 9): 0.0}},
)
oc = Oc(
parent=gwf,
budget_file=f"{name}.bud",
head_file=f"{name}.hds",
budget_file=f"{gwf.name}.bud",
head_file=f"{gwf.name}.hds",
save_head={"*": "all"},
save_budget={"*": "all"},
)
Expand All @@ -35,7 +36,7 @@
assert np.allclose(chd.data.head[:, 1:99], np.full(98, 1e30))

# check DIS
assert dis.data.botm.sel(lay=0, col=0, row=0) == 0.0
assert gwf.dis.data.botm.sel(lay=0, col=0, row=0) == 0.0

# check OC
assert oc.data["save_head"][0] == "all"
Expand All @@ -56,4 +57,4 @@
head.plot.imshow(ax=ax)
head.plot.contour(ax=ax, levels=[0.2, 0.4, 0.6, 0.8], linewidths=3.0)
budget.plot.quiver(x="x", y="y", u="npf-qx", v="npf-qy", ax=ax, color="white")
fig.savefig(ws / "quickstart.png")
fig.savefig(workspace / f"{name}.png")
Binary file added docs/examples/quickstart/quickstart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions flopy4/mf6/gwf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ class Output:

@property
def head(self) -> xr.DataArray:
# TODO support other extensions than .hds (e.g. .hed)
return open_hds(
self.parent.parent.sim_ws / f"{self.parent.name}.hds", # type: ignore
self.parent.parent.sim_ws / f"{self.parent.name}.dis.grb", # type: ignore
self.parent.parent.path / f"{self.parent.name}.hds", # type: ignore
self.parent.parent.path / f"{self.parent.name}.dis.grb", # type: ignore
)

@property
def budget(self):
# TODO support other extensions than .bud (e.g. .cbc)
return imod.mf6.open_cbc(
self.parent.parent.sim_ws / "mymodel.bud",
self.parent.parent.sim_ws / "mymodel.dis.grb",
self.parent.parent.path / f"{self.parent.name}.bud",
self.parent.parent.path / f"{self.parent.name}.dis.grb",
merge_to_dataset=True,
)

Expand Down
4 changes: 3 additions & 1 deletion flopy4/mf6/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class Simulation(Component):
exchanges: dict[str, Exchange] = field()
solutions: dict[str, Solution] = field()
tdis: Tdis = field(converter=convert_time)
sim_ws: Path = field(default=None)
# TODO: decorator for components bound
# to some directory or file path?
path: Path = field(default=None)

@property
def time(self) -> ModelTime:
Expand Down
64 changes: 32 additions & 32 deletions pixi.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading