Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b95eec

Browse files
authored
feat(exg pkg binary file support) (#2205)
* feat(exg pkg binary file support) * feat(binary file) * feat(exchange binary file) * fix(workflows): use latest version of modflow with notebook tests * fix(workflows)
1 parent f26cbd4 commit 3b95eec

8 files changed

Lines changed: 192 additions & 147 deletions

File tree

.docs/Notebooks/lgr_tutorial01.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -462,23 +462,11 @@
462462
# retrieve the exchange data from the lgr object
463463
exchangedata = lgr.get_exchange_data(angldegx=True, cdist=True)
464464
nexg = len(exchangedata)
465-
466-
# When creating the exchange, which couples the child and parent
467-
# models, use the xt3d option, which is an alternative to the
468-
# ghost-node correction. This xt3d option was added as a new
469-
# capability for the gwt-gwt and gwf-gwf exchanges in MODFLOW version 6.3.0.
470-
exg = flopy.mf6.ModflowGwtgwt(
471-
sim,
472-
exgtype="GWT6-GWT6",
473-
gwfmodelname1=gwfp.name,
474-
gwfmodelname2=gwfc.name,
475-
# xt3d=True,
476-
auxiliary=["angldegx", "cdist"],
477-
exgmnamea=pname,
478-
exgmnameb=cname,
479-
nexg=nexg,
480-
exchangedata=exchangedata,
481-
)
465+
exg_data = {
466+
"filename": "exg_data.bin",
467+
"data": exchangedata,
468+
"binary": True,
469+
}
482470

483471
# Set up the parent model and use the lgr.parent object to
484472
# help provide the necessary information.
@@ -522,6 +510,23 @@
522510
)
523511
sim.register_ims_package(ims_tran, [gwtp.name, gwtc.name])
524512

513+
# When creating the exchange, which couples the child and parent
514+
# models, use the xt3d option, which is an alternative to the
515+
# ghost-node correction. This xt3d option was added as a new
516+
# capability for the gwt-gwt and gwf-gwf exchanges in MODFLOW version 6.3.0.
517+
exg = flopy.mf6.ModflowGwtgwt(
518+
sim,
519+
exgtype="GWT6-GWT6",
520+
gwfmodelname1=gwfp.name,
521+
gwfmodelname2=gwfc.name,
522+
# xt3d=True,
523+
auxiliary=["angldegx", "cdist"],
524+
exgmnamea=pname,
525+
exgmnameb=cname,
526+
nexg=nexg,
527+
exchangedata=exg_data,
528+
)
529+
525530
# couple flow and transport models
526531
gwfgwt_p = flopy.mf6.ModflowGwfgwt(
527532
sim,

.github/workflows/rtd.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,14 @@ jobs:
7474
$PSDefaultParameterValues['*:ErrorAction']='Stop'
7575
powershell .github/install_opengl.ps1
7676
77-
- name: Install MODFLOW executables
77+
- name: Install Modflow-related executables
7878
uses: modflowpy/install-modflow-action@v1
7979

80+
- name: Install Modflow dev build executables
81+
uses: modflowpy/install-modflow-action@v1
82+
with:
83+
repo: modflow6-nightly-build
84+
8085
- name: Run tutorial and example notebooks
8186
working-directory: autotest
8287
run: pytest -v -n auto test_notebooks.py

autotest/regression/test_mf6.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2853,14 +2853,19 @@ def test006_create_tests_2models_gnc(function_tmpdir, example_data_path):
28532853
)
28542854
sim.remove_package(exg_package.package_type)
28552855

2856+
exg_data = {
2857+
"filename": "exg_data.txt",
2858+
"data": exgrecarray,
2859+
"binary": True,
2860+
}
28562861
exg_package = ModflowGwfgwf(
28572862
sim,
28582863
print_input=True,
28592864
print_flows=True,
28602865
save_flows=True,
28612866
auxiliary="testaux",
28622867
nexg=36,
2863-
exchangedata=exgrecarray,
2868+
exchangedata=exg_data,
28642869
exgtype="gwf6-gwf6",
28652870
exgmnamea=model_name_1,
28662871
exgmnameb=model_name_2,
@@ -2881,6 +2886,7 @@ def test006_create_tests_2models_gnc(function_tmpdir, example_data_path):
28812886

28822887
# change folder to save simulation
28832888
sim.set_sim_path(function_tmpdir)
2889+
exg_package.exchangedata.set_record(exg_data)
28842890

28852891
# write simulation to new location
28862892
sim.write_simulation()
@@ -4039,6 +4045,11 @@ def test006_2models_different_dis(function_tmpdir, example_data_path):
40394045
exgrecarray = testutils.read_exchangedata(
40404046
os.path.join(pth, "exg.txt"), 3, 2
40414047
)
4048+
exg_data = {
4049+
"filename": "exg_data.bin",
4050+
"data": exgrecarray,
4051+
"binary": True,
4052+
}
40424053

40434054
# build obs dictionary
40444055
gwf_obs = {
@@ -4055,7 +4066,7 @@ def test006_2models_different_dis(function_tmpdir, example_data_path):
40554066
save_flows=True,
40564067
auxiliary="testaux",
40574068
nexg=9,
4058-
exchangedata=exgrecarray,
4069+
exchangedata=exg_data,
40594070
exgtype="gwf6-gwf6",
40604071
exgmnamea=model_name_1,
40614072
exgmnameb=model_name_2,
@@ -4077,6 +4088,7 @@ def test006_2models_different_dis(function_tmpdir, example_data_path):
40774088

40784089
# change folder to save simulation
40794090
sim.set_sim_path(function_tmpdir)
4091+
exg_package.exchangedata.set_record(exg_data)
40804092

40814093
# write simulation to new location
40824094
sim.write_simulation()

autotest/regression/test_mf6_pandas.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ def test_pandas_001(function_tmpdir, example_data_path):
182182
assert well_data_pd.iloc[0, 1] == 0
183183
assert well_data_pd.iloc[0, 2] == 4
184184
assert well_data_pd.iloc[0, 3] == -2000.0
185-
assert well_data_pd["layer"][0] == 0
186-
assert well_data_pd["row"][0] == 0
187-
assert well_data_pd["column"][0] == 4
185+
assert well_data_pd["cellid_layer"][0] == 0
186+
assert well_data_pd["cellid_row"][0] == 0
187+
assert well_data_pd["cellid_column"][0] == 4
188188
assert well_data_pd["q"][0] == -2000.0
189-
assert well_data_pd["layer"][1] == 0
190-
assert well_data_pd["row"][1] == 0
191-
assert well_data_pd["column"][1] == 7
189+
assert well_data_pd["cellid_layer"][1] == 0
190+
assert well_data_pd["cellid_row"][1] == 0
191+
assert well_data_pd["cellid_column"][1] == 7
192192
assert well_data_pd["q"][1] == -2.0
193193

194194
well_data_rec = wel_package.stress_period_data.get_data(0)
@@ -284,27 +284,27 @@ def test_pandas_001(function_tmpdir, example_data_path):
284284
assert well_data_pd_0.iloc[0, 1] == 0
285285
assert well_data_pd_0.iloc[0, 2] == 4
286286
assert well_data_pd_0.iloc[0, 3] == -2000.0
287-
assert well_data_pd_0["layer"][0] == 0
288-
assert well_data_pd_0["row"][0] == 0
289-
assert well_data_pd_0["column"][0] == 4
287+
assert well_data_pd_0["cellid_layer"][0] == 0
288+
assert well_data_pd_0["cellid_row"][0] == 0
289+
assert well_data_pd_0["cellid_column"][0] == 4
290290
assert well_data_pd_0["q"][0] == -2000.0
291-
assert well_data_pd_0["layer"][1] == 0
292-
assert well_data_pd_0["row"][1] == 0
293-
assert well_data_pd_0["column"][1] == 7
291+
assert well_data_pd_0["cellid_layer"][1] == 0
292+
assert well_data_pd_0["cellid_row"][1] == 0
293+
assert well_data_pd_0["cellid_column"][1] == 7
294294
assert well_data_pd_0["q"][1] == -2.0
295295
well_data_pd = test_wel.stress_period_data.get_dataframe(1)
296296
assert isinstance(well_data_pd, pd.DataFrame)
297297
assert well_data_pd.iloc[0, 0] == 0
298298
assert well_data_pd.iloc[0, 1] == 0
299299
assert well_data_pd.iloc[0, 2] == 4
300300
assert well_data_pd.iloc[0, 3] == -1000.0
301-
assert well_data_pd["layer"][0] == 0
302-
assert well_data_pd["row"][0] == 0
303-
assert well_data_pd["column"][0] == 4
301+
assert well_data_pd["cellid_layer"][0] == 0
302+
assert well_data_pd["cellid_row"][0] == 0
303+
assert well_data_pd["cellid_column"][0] == 4
304304
assert well_data_pd["q"][0] == -1000.0
305-
assert well_data_pd["layer"][1] == 0
306-
assert well_data_pd["row"][1] == 0
307-
assert well_data_pd["column"][1] == 7
305+
assert well_data_pd["cellid_layer"][1] == 0
306+
assert well_data_pd["cellid_row"][1] == 0
307+
assert well_data_pd["cellid_column"][1] == 7
308308
assert well_data_pd["q"][1] == -20.0
309309
test_riv = test_mod.get_package("riv")
310310
riv_data_pd = test_riv.stress_period_data.get_dataframe(0)

flopy/mf6/coordinates/modeldimensions.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ def model_subspace_size(self, subspace_string="", data_item_num=None):
102102
subspace_string
103103
)
104104

105+
def get_cellid_size(self, data_item_name):
106+
model_num = DatumUtil.cellid_model_num(
107+
data_item_name,
108+
self.structure.model_data,
109+
self.package_dim.model_dim,
110+
)
111+
model_grid = self.get_model_grid(model_num=model_num)
112+
return model_grid.get_num_spatial_coordinates()
113+
105114
def get_model_dim(self, data_item_num, model_num=None):
106115
if (
107116
self.package_dim.model_dim is None
@@ -111,9 +120,14 @@ def get_model_dim(self, data_item_num, model_num=None):
111120
return self.package_dim.model_dim[0]
112121
else:
113122
if model_num is None:
114-
model_num = self.structure.data_item_structures[data_item_num][
115-
-1
116-
]
123+
# see if the name of the data item indicates which model to use
124+
item_name = self.structure.data_item_structures[
125+
data_item_num
126+
].name
127+
if item_name[-2] == "m" and DatumUtil.is_int(item_name[-1]):
128+
model_num = int(item_name[-1]) - 1
129+
else:
130+
return self.package_dim.model_dim[0]
117131
if not (
118132
len(self.structure.data_item_structures) > data_item_num
119133
):
@@ -133,8 +147,7 @@ def get_model_dim(self, data_item_num, model_num=None):
133147
f"{len(self.package_dim.model_dim)}."
134148
)
135149

136-
if DatumUtil.is_int(model_num):
137-
return self.package_dim.model_dim[int(model_num)]
150+
return self.package_dim.model_dim[model_num]
138151

139152

140153
class PackageDimensions:

0 commit comments

Comments
 (0)