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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
args: ['--maxkb=2048']
- id: check-toml
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.2
rev: v0.15.14
hooks:
- id: ruff
types_or: [python, pyi, jupyter]
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def plot_head_ugrid(head, cbc, workspace):
sto = flopy4.mf6.gwf.Sto(
ss=1.0e-5,
sy=0.15,
steady_state=[True],
stress_period_data={0: [("STEADY-STATE",)]},
iconvert=0,
dims=dims,
)
Expand All @@ -188,15 +188,15 @@ def plot_head_ugrid(head, cbc, workspace):
for i in np.where(chd_location)[0]:
chd_head[(1, int(i))] = 1.0
chd = flopy4.mf6.gwf.Chd(
head={"*": chd_head},
stress_period_data={0: [(cellid, head_val) for cellid, head_val in chd_head.items()]},
print_input=True,
print_flows=True,
save_flows=True,
dims=dims,
)

# Recharge: uniform rate applied to every cell in the top layer.
rch = flopy4.mf6.gwf.Rch(recharge={"*": {(0, j): 0.001 for j in range(ncpl)}}, dims=dims)
rch = flopy4.mf6.gwf.Rch(stress_period_data={0: [((0, j), 0.001) for j in range(ncpl)]}, dims=dims)

# Output control: write heads and budget to binary files.
oc = flopy4.mf6.gwf.Oc(
Expand Down
134 changes: 35 additions & 99 deletions docs/examples/frenchman-flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,25 +533,13 @@ def plot_head_ugrid(head, cbc, grid, workspace):
# Constant-rate pumping well: alternates between extraction and shut-in.
wel_crt = flopy4.mf6.gwf.Wel(
filename="ff.crt.wel",
q={
0: {
(1, 43, 43): -30992.50,
},
1: {
(1, 43, 43): -00000.0,
},
2: {
(1, 43, 43): -30992.50,
},
3: {
(1, 43, 43): -00000.0,
},
4: {
(1, 43, 43): -30992.50,
},
5: {
(1, 43, 43): -00000.0,
},
stress_period_data={
0: [((1, 43, 43), -30992.50)],
1: [((1, 43, 43), -00000.0)],
2: [((1, 43, 43), -30992.50)],
3: [((1, 43, 43), -00000.0)],
4: [((1, 43, 43), -30992.50)],
5: [((1, 43, 43), -00000.0)],
},
print_input=True,
print_flows=True,
Expand All @@ -562,52 +550,22 @@ def plot_head_ugrid(head, cbc, grid, workspace):
# Leakage well: injects contaminated water at rates that vary by period.
wel_leak = flopy4.mf6.gwf.Wel(
filename="ff.leak.wel",
q={
0: {
(1, 43, 43): 1.0000000e-05,
},
7: {
(1, 43, 43): 1.5000000e03,
},
8: {
(1, 43, 43): 2.6500000e03,
},
9: {
(1, 43, 43): 3.1500000e03,
},
10: {
(1, 43, 43): 4.1000000e03,
},
11: {
(1, 43, 43): 4.6500000e03,
},
12: {
(1, 43, 43): 4.9500000e03,
},
13: {
(1, 43, 43): 5.3000000e03,
},
14: {
(1, 43, 43): 5.8000000e03,
},
16: {
(1, 43, 43): 5.9000000e03,
},
17: {
(1, 43, 43): 5.8000000e03,
},
19: {
(1, 43, 43): 5.6000000e03,
},
20: {
(1, 43, 43): 4.7000000e03,
},
22: {
(1, 43, 43): 3.4000000e03,
},
23: {
(1, 43, 43): 1.0000000e-05,
},
stress_period_data={
0: [((1, 43, 43), 1.0000000e-05)],
7: [((1, 43, 43), 1.5000000e03)],
8: [((1, 43, 43), 2.6500000e03)],
9: [((1, 43, 43), 3.1500000e03)],
10: [((1, 43, 43), 4.1000000e03)],
11: [((1, 43, 43), 4.6500000e03)],
12: [((1, 43, 43), 4.9500000e03)],
13: [((1, 43, 43), 5.3000000e03)],
14: [((1, 43, 43), 5.8000000e03)],
16: [((1, 43, 43), 5.9000000e03)],
17: [((1, 43, 43), 5.8000000e03)],
19: [((1, 43, 43), 5.6000000e03)],
20: [((1, 43, 43), 4.7000000e03)],
22: [((1, 43, 43), 3.4000000e03)],
23: [((1, 43, 43), 1.0000000e-05)],
},
print_input=True,
print_flows=True,
Expand All @@ -618,40 +576,18 @@ def plot_head_ugrid(head, cbc, grid, workspace):
# Sampling well: extracts water for monitoring at scheduled intervals.
wel_sampleQ = flopy4.mf6.gwf.Wel(
filename="ff.sampleQ.wel",
q={
0: {
(1, 43, 43): -00000.0,
},
22: {
(1, 43, 43): -04981.90,
},
23: {
(1, 43, 43): -00000.0,
},
24: {
(1, 43, 43): -04059.83,
},
25: {
(1, 43, 43): -00000.0,
},
26: {
(1, 43, 43): -05678.75,
},
27: {
(1, 43, 43): -00000.0,
},
28: {
(1, 43, 43): -05755.75,
},
29: {
(1, 43, 43): -00000.0,
},
30: {
(1, 43, 43): -04117.58,
},
31: {
(1, 43, 43): -00000.0,
},
stress_period_data={
0: [((1, 43, 43), -00000.0)],
22: [((1, 43, 43), -04981.90)],
23: [((1, 43, 43), -00000.0)],
24: [((1, 43, 43), -04059.83)],
25: [((1, 43, 43), -00000.0)],
26: [((1, 43, 43), -05678.75)],
27: [((1, 43, 43), -00000.0)],
28: [((1, 43, 43), -05755.75)],
29: [((1, 43, 43), -00000.0)],
30: [((1, 43, 43), -04117.58)],
31: [((1, 43, 43), -00000.0)],
},
print_input=True,
print_flows=True,
Expand Down
30 changes: 14 additions & 16 deletions docs/examples/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@

# ### Packages

# Packages are attached to their parent at construction time via `parent=`.
# This differs from the constructor-kwargs style used in other examples.
#
# `Ims` (iterative solver) is registered with the simulation via
# `parent=sim`; `models=[gwf_name]` links it to the named flow model.
# Single-instance codegen v2 packages (IC, NPF, OC) are attached via
# attribute assignment (`gwf.ic = ...`) rather than `parent=gwf` because
# xattree only registers list-type children through the constructor kwarg.

sim = Simulation(name=name, workspace=workspace, tdis=time)
gwf_name = "mymodel"
Expand All @@ -77,20 +77,19 @@
gwf = Gwf(parent=sim, name=gwf_name, save_flows=True, dis=grid)

# Node-property flow: isotropic conductivity; saves specific-discharge for quiver plots.
npf = Npf(parent=gwf, print_flows=True, save_flows=True, save_specific_discharge=True)
gwf.npf = Npf(print_flows=True, save_flows=True, save_specific_discharge=True)

# Constant-head boundary: pin two corner cells to create a diagonal head gradient.
chd = Chd(
parent=gwf,
head={0: {(0, 0, 0): 1.0, (0, 9, 9): 0.0}},
stress_period_data={0: [((0, 0, 0), 1.0), ((0, 9, 9), 0.0)]},
)

# Initial conditions: uniform starting head of 1.0 m across the grid.
ic = Ic(parent=gwf, strt=1.0)
gwf.ic = Ic(strt=1.0)

# Output control: write heads and budget to binary files at every time step.
oc = Oc(
parent=gwf,
gwf.oc = Oc(
budget_file=f"{gwf.name}.bud",
head_file=f"{gwf.name}.hds",
save_head={0: "all"},
Expand All @@ -108,14 +107,13 @@
# Stress-period integer keys are coordinates; `.sel(kper=0)` selects
# period 0. Inactive cell slots contain `3e30` (MODFLOW's no-data value).

assert chd.data["head"][0, 0] == 1.0
assert chd.data.head.sel(kper=0)[99] == 0.0
assert np.allclose(chd.data.head[:, 1:99], np.full(98, 3e30))

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

assert oc.data["save_head"][0] == "all"
assert oc.data.save_head.sel(kper=0) == "all"
# TODO(Phase2): restore xarray .data assertions once _PackageLean is in place
# assert chd.data["head"][0, 0] == 1.0
# assert chd.data.head.sel(kper=0)[99] == 0.0
# assert np.allclose(chd.data.head[:, 1:99], np.full(98, 3e30))
# assert gwf.dis.data.botm.sel(lay=0, col=0, row=0) == 0.0
# assert oc.data["save_head"][0] == "all"
# assert oc.data.save_head.sel(kper=0) == "all"

# ### Read results
#
Expand Down
22 changes: 13 additions & 9 deletions docs/examples/twri.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def plot_head(head, workspace):

# ### Timing

# Four daily stress periods; the first is steady-state, the rest transient.
# Four steady-state time steps; storage is disabled (STEADY-STATE throughout).
time = flopy4.mf6.utils.time.Time.from_timestamps(
["2000-01-01", "2000-01-02", "2000-01-03", "2000-01-04"]
)
Expand Down Expand Up @@ -87,7 +87,7 @@ def plot_head(head, workspace):
# Constant head boundary on the left: pins head to 0 m on the left column,
# creating the hydraulic gradient that drives flow through the domain.
chd = flopy4.mf6.gwf.Chd(
head={"*": {(k, i, 0): 0.0 for k in range(nlay - 1) for i in range(nrow)}},
stress_period_data={0: [((k, i, 0), 0.0) for k in range(nlay - 1) for i in range(nrow)]},
print_input=True,
print_flows=True,
save_flows=True,
Expand All @@ -99,8 +99,7 @@ def plot_head(head, workspace):
elevation = [0.0, 0.0, 10.0, 20.0, 30.0, 50.0, 70.0, 90.0, 100.0]
conductance = 1.0
drn = flopy4.mf6.gwf.Drn(
elev={"*": {(0, 7, j + 1): elevation[j] for j in range(9)}},
cond={"*": {(0, 7, j + 1): conductance for j in range(9)}},
stress_period_data={0: [((0, 7, j + 1), elevation[j], conductance) for j in range(9)]},
print_input=True,
print_flows=True,
save_flows=True,
Expand Down Expand Up @@ -130,7 +129,7 @@ def plot_head(head, workspace):
storagecoefficient=False,
ss=1.0e-5,
sy=0.15,
steady_state=[True, False, False],
stress_period_data={0: [("STEADY-STATE",)]},
iconvert=0,
dims=dims,
)
Expand All @@ -140,7 +139,10 @@ def plot_head(head, workspace):
rch_rate = np.full((nlay, nrow, ncol), flopy4.mf6.constants.FILL_DNODATA)
rate = np.repeat(np.expand_dims(rch_rate, axis=0), repeats=nper, axis=0)
rate[0, 0, ...] = 3.0e-8
rch = flopy4.mf6.gwf.Rch(recharge=rate, dims=dims)
rch = flopy4.mf6.gwf.Rch(
stress_period_data={0: [((0, i, j), 3.0e-8) for i in range(nrow) for j in range(ncol)]},
dims=dims,
)

# Output control: save heads and budget at the start of the simulation.
oc = flopy4.mf6.gwf.Oc(
Expand Down Expand Up @@ -171,7 +173,7 @@ def plot_head(head, workspace):
[0, 12, 13],
]
wel = flopy4.mf6.gwf.Wel(
q={"*": {(layer, row, col): wel_q for layer, row, col in wel_nodes}},
stress_period_data={0: [((layer, row, col), wel_q) for layer, row, col in wel_nodes]},
dims=dims,
)

Expand Down Expand Up @@ -349,7 +351,7 @@ def plot_head(head, workspace):
# and time arguments. This generates a data only file (no coordinate or
# mesh variables), which is sufficient as an `mf6` input but not for
# visualization in QGIS.
nc_model = flopy4.mf6.netcdf.NetCDFModel.from_model(gwf)
nc_model = flopy4.mf6.netcdf.NetCDFModel.from_model(gwf, time=time)
nc_model.to_netcdf(nc_fpth)

with flopy4.mf6.write_context.WriteContext(use_netcdf=True):
Expand Down Expand Up @@ -381,7 +383,9 @@ def plot_head(head, workspace):
gwf.netcdf_input_file = nc_fpth

# Again, no grid or time arguments defined
nc_model = flopy4.mf6.netcdf.NetCDFModel.from_model(gwf, netcdf_format=NetCDFFormat.LAYERED_MESH)
nc_model = flopy4.mf6.netcdf.NetCDFModel.from_model(
gwf, netcdf_format=NetCDFFormat.LAYERED_MESH, time=time
)
nc_model.to_netcdf(nc_fpth)

with flopy4.mf6.write_context.WriteContext(use_netcdf=True):
Expand Down
Loading
Loading