Skip to content

Commit

Permalink
feat(sim options block packages): Support for packages declared in si…
Browse files Browse the repository at this point in the history
…mulation name file's options block (#2174)

* feat(sim options block packages):

Support for simulation options block packages added including the hpc package.

* feat

* feat

* fix

* fix(format)

* fix(array reader)

* Revert "fix(array reader)"

This reverts commit 0b753ac.

* fix(array reader): Limit array line size read based on the dimensions of the array (#2053)

* fix(data formatting): test case data format issue

* fix(test updates)

* fix(reformat)

* fix(HPC)

---------

Co-authored-by: scottrp <45947939+scottrp@users.noreply.github.com>
  • Loading branch information
spaulins-usgs and scottrp authored May 2, 2024
1 parent 50bbd01 commit 6237cec
Showing 5 changed files with 136 additions and 4 deletions.
74 changes: 72 additions & 2 deletions autotest/regression/test_mf6.py
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
ModflowGwtssm,
ModflowIms,
ModflowTdis,
ModflowUtlhpc,
ModflowUtltas,
)
from flopy.mf6.data.mfdatastorage import DataStorageType
@@ -3110,7 +3111,7 @@ def test028_create_tests_sfr(function_tmpdir, example_data_path):
delc=5000.0,
top=top,
botm=botm,
# idomain=idomain,
idomain=idomain,
filename=f"{model_name}.dis",
)
strt = testutils.read_std_array(os.path.join(pth, "strt.txt"), "float")
@@ -3310,8 +3311,77 @@ def test028_create_tests_sfr(function_tmpdir, example_data_path):
htol=10.0,
)

# test hpc package
part = [("model1", 1), ("model2", 2)]
hpc = ModflowUtlhpc(
sim, dev_log_mpi=True, partitions=part, filename="test.hpc"
)

assert sim.hpc.dev_log_mpi.get_data()
assert hpc.filename == "test.hpc"
part = hpc.partitions.get_data()
assert part[0][0] == "model1"
assert part[0][1] == 1
assert part[1][0] == "model2"
assert part[1][1] == 2

sim.write_simulation()
sim2 = MFSimulation.load(
sim_name=test_ex_name,
version="mf6",
exe_name="mf6",
sim_ws=function_tmpdir,
)
hpc_a = sim2.get_package("hpc")
assert hpc_a.filename == "test.hpc"
fr = sim2.name_file._hpc_filerecord.get_data()
assert fr[0][0] == "test.hpc"
assert hpc_a.dev_log_mpi.get_data()
part_a = hpc_a.partitions.get_data()
assert part_a[0][0] == "model1"
assert part_a[0][1] == 1
assert part_a[1][0] == "model2"
assert part_a[1][1] == 2

sim2.remove_package(hpc_a)
sim2.set_sim_path(os.path.join(function_tmpdir, "temp"))
sim2.write_simulation()
sim3 = MFSimulation.load(
sim_name=test_ex_name,
version="mf6",
exe_name="mf6",
sim_ws=os.path.join(function_tmpdir, "temp"),
)
hpc_n = sim3.get_package("hpc")
assert hpc_n is None
fr_2 = sim3.name_file._hpc_filerecord.get_data()
assert fr_2 is None
sim3.set_sim_path(function_tmpdir)

hpc_data = {
"filename": "hpc_data_file.hpc",
"dev_log_mpi": True,
"partitions": part,
}
sim4 = MFSimulation(
sim_name=test_ex_name,
version="mf6",
exe_name="mf6",
sim_ws=pth,
hpc_data=hpc_data,
)
fr_4 = sim4.name_file._hpc_filerecord.get_data()
assert fr_4[0][0] == "hpc_data_file.hpc"
assert sim4.hpc.filename == "hpc_data_file.hpc"
assert sim4.hpc.dev_log_mpi.get_data()
part = sim4.hpc.partitions.get_data()
assert part[0][0] == "model1"
assert part[0][1] == 1
assert part[1][0] == "model2"
assert part[1][1] == 2

# clean up
sim.delete_output_files()
sim3.delete_output_files()


@requires_exe("mf6")
5 changes: 4 additions & 1 deletion examples/data/mf6/notebooks/iconvert.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
8 changes: 8 additions & 0 deletions flopy/mf6/data/mffileaccess.py
Original file line number Diff line number Diff line change
@@ -581,6 +581,10 @@ def read_text_data_from_file(
fd=None,
data_item=None,
):
# determine line size
line_size = None
if isinstance(data_dim, list):
line_size = data_dim[-1]
# load variable data from file
current_size = 0
if layer is None:
@@ -601,6 +605,8 @@ def read_text_data_from_file(
if line == "" or arr_line[0].upper() == "END":
break
if not MFComment.is_comment(arr_line, True):
if line_size is not None:
arr_line = arr_line[:line_size]
data_raw += arr_line
else:
PyListUtil.reset_delimiter_used()
@@ -609,6 +615,8 @@ def read_text_data_from_file(
line = fd.readline()
arr_line = PyListUtil.split_data_line(line, True)
if not MFComment.is_comment(arr_line, True):
if line_size is not None:
arr_line = arr_line[:line_size]
data_raw += arr_line
else:
PyListUtil.reset_delimiter_used()
Binary file removed flopy/mf6/modflow.zip
Binary file not shown.
53 changes: 52 additions & 1 deletion flopy/mf6/modflow/mfnam.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DO NOT MODIFY THIS FILE DIRECTLY. THIS FILE MUST BE CREATED BY
# mf6/utils/createpackages.py
# FILE created on February 07, 2024 20:16:08 UTC
# FILE created on April 23, 2024 17:27:32 UTC
from .. import mfpackage
from ..data.mfdatautil import ListTemplateGenerator

@@ -40,6 +40,11 @@ class ModflowNam(mfpackage.MFPackage):
keyword, input summaries will be written for those packages that
support newer input data model routines. Not all packages are
supported yet by the newer input data model routines.
hpc : {varname:data} or hpc_data data
* Contains data for the hpc package. Data can be stored in a dictionary
containing data for the hpc package with variable names as keys and
package data as values. Data just for the hpc variable is also
acceptable. See hpc package documentation for more information.
tdis6 : string
* tdis6 (string) is the name of the Temporal Discretization (TDIS)
Input File.
@@ -79,6 +84,9 @@ class ModflowNam(mfpackage.MFPackage):
"""

hpc_filerecord = ListTemplateGenerator(
("nam", "options", "hpc_filerecord")
)
models = ListTemplateGenerator(("nam", "models", "models"))
exchanges = ListTemplateGenerator(("nam", "exchanges", "exchanges"))
solutiongroup = ListTemplateGenerator(
@@ -128,6 +136,48 @@ class ModflowNam(mfpackage.MFPackage):
"reader urword",
"optional true",
],
[
"block options",
"name hpc_filerecord",
"type record hpc6 filein hpc6_filename",
"shape",
"reader urword",
"tagged true",
"optional true",
"construct_package hpc",
"construct_data hpc_data",
"parameter_name hpc",
],
[
"block options",
"name hpc6",
"type keyword",
"shape",
"in_record true",
"reader urword",
"tagged true",
"optional false",
],
[
"block options",
"name filein",
"type keyword",
"shape",
"in_record true",
"reader urword",
"tagged true",
"optional false",
],
[
"block options",
"name hpc6_filename",
"type string",
"preserve_case true",
"in_record true",
"reader urword",
"optional false",
"tagged false",
],
[
"block timing",
"name tdis6",
@@ -290,6 +340,7 @@ def __init__(
)
self.maxerrors = self.build_mfdata("maxerrors", maxerrors)
self.print_input = self.build_mfdata("print_input", print_input)
self._hpc_filerecord = self.build_mfdata("hpc_filerecord", None)
self.tdis6 = self.build_mfdata("tdis6", tdis6)
self.models = self.build_mfdata("models", models)
self.exchanges = self.build_mfdata("exchanges", exchanges)

0 comments on commit 6237cec

Please sign in to comment.