Skip to content

Commit 229f15e

Browse files
authored
adapt/stub some more examples (#46)
1 parent 95a320a commit 229f15e

File tree

4 files changed

+229
-4
lines changed

4 files changed

+229
-4
lines changed

docs/examples/list_example.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# # List input variables
2+
#
3+
# This example demonstrates how to work with list input variables.
4+
#
5+
# A list variable is a generic collection type, whose elements can
6+
# be scalars, records, or unions of such. A list with a consistent
7+
# (non-union) element type can be provided as a NumPy recarray or a
8+
# Pandas dataframe.
9+
10+
from tempfile import TemporaryDirectory
11+
12+
import flopy
13+
import numpy as np
14+
15+
# set up where simulation workspace will be stored
16+
temp_dir = TemporaryDirectory()
17+
workspace = temp_dir.name
18+
name = "tutorial06_mf6_data"
19+
20+
# create the Flopy simulation and tdis objects
21+
sim = flopy.mf6.MFSimulation(
22+
sim_name=name, exe_name="mf6", version="mf6", sim_ws=workspace
23+
)
24+
tdis = flopy.mf6.modflow.mftdis.ModflowTdis(
25+
sim,
26+
pname="tdis",
27+
time_units="DAYS",
28+
nper=2,
29+
perioddata=[(1.0, 1, 1.0), (1.0, 1, 1.0)],
30+
)
31+
# create the Flopy groundwater flow (gwf) model object
32+
model_nam_file = f"{name}.nam"
33+
gwf = flopy.mf6.ModflowGwf(sim, modelname=name, model_nam_file=model_nam_file)
34+
# create the flopy iterative model solver (ims) package object
35+
ims = flopy.mf6.modflow.mfims.ModflowIms(sim, pname="ims", complexity="SIMPLE")
36+
# create the discretization package
37+
bot = np.linspace(-50.0 / 3.0, -3.0, 3)
38+
delrow = delcol = 4.0
39+
dis = flopy.mf6.modflow.mfgwfdis.ModflowGwfdis(
40+
gwf,
41+
pname="dis",
42+
nogrb=True,
43+
nlay=3,
44+
nrow=10,
45+
ncol=10,
46+
delr=delrow,
47+
delc=delcol,
48+
top=0.0,
49+
botm=bot,
50+
)
51+
52+
# Below we pass the CHD package's `stress_period_data` as a list.
53+
54+
# build chd package
55+
stress_period_data = [((1, 8, 8), 100.0), ((1, 9, 9), 105.0)]
56+
chd = flopy.mf6.modflow.mfgwfchd.ModflowGwfchd(
57+
gwf,
58+
pname="chd",
59+
maxbound=len(stress_period_data),
60+
stress_period_data=stress_period_data,
61+
save_flows=True,
62+
)
63+
64+
# TODO: demo typed records

docs/examples/record_example.py

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,90 @@
1-
# # Record variables
1+
# # Record and union variables
22
#
3-
# This example demonstrates how to work with record input variables.
3+
# This example demonstrates how to work with record and union input
4+
# variables.
45
#
56
# A record variable is a product type. Record fields can be scalars,
67
# other record variables, or unions of such.
78
#
9+
# A union (keystring) variable is a sum type.
10+
#
811
# MODFLOW 6 represents records as (possibly variadic) tuples. FloPy
912
# supports both a low-level tuple interface for records, conforming
1013
# to MODFLOW 6, and a high-level, strongly-typed record interface.
14+
15+
# package import
16+
from tempfile import TemporaryDirectory
17+
18+
import flopy
19+
import numpy as np
20+
21+
# set up where simulation workspace will be stored
22+
temp_dir = TemporaryDirectory()
23+
workspace = temp_dir.name
24+
name = "tutorial06_mf6_data"
25+
26+
# create the Flopy simulation and tdis objects
27+
sim = flopy.mf6.MFSimulation(
28+
sim_name=name, exe_name="mf6", version="mf6", sim_ws=workspace
29+
)
30+
tdis = flopy.mf6.modflow.mftdis.ModflowTdis(
31+
sim,
32+
pname="tdis",
33+
time_units="DAYS",
34+
nper=2,
35+
perioddata=[(1.0, 1, 1.0), (1.0, 1, 1.0)],
36+
)
37+
# create the Flopy groundwater flow (gwf) model object
38+
model_nam_file = f"{name}.nam"
39+
gwf = flopy.mf6.ModflowGwf(sim, modelname=name, model_nam_file=model_nam_file)
40+
# create the flopy iterative model solver (ims) package object
41+
ims = flopy.mf6.modflow.mfims.ModflowIms(sim, pname="ims", complexity="SIMPLE")
42+
# create the discretization package
43+
bot = np.linspace(-50.0 / 3.0, -3.0, 3)
44+
delrow = delcol = 4.0
45+
dis = flopy.mf6.modflow.mfgwfdis.ModflowGwfdis(
46+
gwf,
47+
pname="dis",
48+
nogrb=True,
49+
nlay=3,
50+
nrow=10,
51+
ncol=10,
52+
delr=delrow,
53+
delc=delcol,
54+
top=0.0,
55+
botm=bot,
56+
)
57+
58+
# ## Adding MODFLOW Package Data, Connection Data, and Option Lists
59+
#
60+
# MODFLOW Package data, connection data, and option lists are stored by FloPy
61+
# as numpy recarrays. FloPy does accept numpy recarrays as input, but does
62+
# has other supported formats discussed below.
63+
#
64+
# MODFLOW option lists that only contain a single row or data can be either
65+
# specified by:
66+
#
67+
# 1. Specifying a string containing the entire line as it would be displayed
68+
# in the package file (`rewet_record="REWET WETFCT 1.0 IWETIT 1 IHDWET 0"`)
69+
# 2. Specifying the data in a tuple within a list
70+
# (`rewet_record=[("WETFCT", 1.0, "IWETIT", 1, "IHDWET", 0)]`)
1171
#
12-
# TODO flesh out
72+
# In the example below the npf package is created setting the `rewet_record`
73+
# option to a string of text as would be typed into the package file.
74+
75+
npf = flopy.mf6.modflow.mfgwfnpf.ModflowGwfnpf(
76+
gwf,
77+
rewet_record="REWET WETFCT 1.0 IWETIT 1 IHDWET 0",
78+
pname="npf",
79+
icelltype=1,
80+
k=1.0,
81+
save_flows=True,
82+
xt3doptions="xt3d rhs",
83+
)
84+
85+
# `rewet_record` is then set using the npf package's `rewet_record` property.
86+
# This time 'rewet_record' is defined using a tuple within a list.
87+
88+
npf.rewet_record = [("WETFCT", 1.1, "IWETIT", 0, "IHDWET", 1)]
89+
90+
# TODO: typed API demo

docs/examples/transient_example.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# # Transient input variables
2+
3+
# MODFLOW stress period data is stored by FloPy as a dictionary of numpy
4+
# recarrays, where each dictionary key is a zero-based stress period and each
5+
# dictionary value is a recarray containing the stress period data for that
6+
# stress period. FloPy keeps this stress period data in a `MFTransientList`
7+
# object and this data type is referred to as a transient list.
8+
#
9+
# FloPy accepts stress period data as a dictionary of numpy recarrays, but also
10+
# supports replacing the recarrays with lists of tuples discussed above.
11+
# Stress period data spanning multiple stress periods must be specified as a
12+
# dictionary of lists where the dictionary key is the stress period expressed
13+
# as a zero-based integer.
14+
#
15+
# The example below creates `stress_period_data` for the wel package with the
16+
# first stress period containing a single well and the second stress period
17+
# empty. When empty stress period data is entered FloPy writes an empty
18+
# stress period block to the package file.
19+
20+
from tempfile import TemporaryDirectory
21+
22+
import flopy
23+
import numpy as np
24+
25+
# set up where simulation workspace will be stored
26+
temp_dir = TemporaryDirectory()
27+
workspace = temp_dir.name
28+
name = "tutorial06_mf6_data"
29+
30+
# create the Flopy simulation and tdis objects
31+
sim = flopy.mf6.MFSimulation(
32+
sim_name=name, exe_name="mf6", version="mf6", sim_ws=workspace
33+
)
34+
tdis = flopy.mf6.modflow.mftdis.ModflowTdis(
35+
sim,
36+
pname="tdis",
37+
time_units="DAYS",
38+
nper=2,
39+
perioddata=[(1.0, 1, 1.0), (1.0, 1, 1.0)],
40+
)
41+
# create the Flopy groundwater flow (gwf) model object
42+
model_nam_file = f"{name}.nam"
43+
gwf = flopy.mf6.ModflowGwf(sim, modelname=name, model_nam_file=model_nam_file)
44+
# create the flopy iterative model solver (ims) package object
45+
ims = flopy.mf6.modflow.mfims.ModflowIms(sim, pname="ims", complexity="SIMPLE")
46+
# create the discretization package
47+
bot = np.linspace(-50.0 / 3.0, -3.0, 3)
48+
delrow = delcol = 4.0
49+
dis = flopy.mf6.modflow.mfgwfdis.ModflowGwfdis(
50+
gwf,
51+
pname="dis",
52+
nogrb=True,
53+
nlay=3,
54+
nrow=10,
55+
ncol=10,
56+
delr=delrow,
57+
delc=delcol,
58+
top=0.0,
59+
botm=bot,
60+
)
61+
62+
# First we create wel package with stress_period_data dictionary
63+
# keys as zero-based integers so key "0" is stress period 1
64+
65+
stress_period_data = {
66+
0: [((2, 3, 1), -25.0)], # stress period 1 well data
67+
1: [],
68+
} # stress period 2 well data is empty
69+
70+
# Then, using the dictionary created above, we build the wel package.
71+
72+
wel = flopy.mf6.ModflowGwfwel(
73+
gwf,
74+
print_input=True,
75+
print_flows=True,
76+
stress_period_data=stress_period_data,
77+
save_flows=False,
78+
pname="WEL-1",
79+
)
80+
81+
# TODO typed API demo

docs/examples/input_data_model_example.py renamed to docs/examples/variables_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# # Input data model
1+
# Input variables
22
#
33
# TODO: flesh this out, describe prospective plan for type hints,
44
# determine whether we want to work directly with numpy or with
@@ -81,3 +81,5 @@
8181
# - While MODFLOW 6 typically formulates file path inputs as records with
8282
# 3 fields (identifying keyword, `filein`/`fileout`, and filename), FloPy
8383
# simply accepts `PathLike`.
84+
85+
# TODO: demonstrate setting/accessing scalars in an options block

0 commit comments

Comments
 (0)