Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(solvers): support for multiple solver types (#1706) #1709

Merged
merged 4 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions autotest/regression/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ def test005_create_tests_advgw_tidal(function_tmpdir, example_data_path):
assert filename == f"all_files_same_name.{package.package_type}"
package_type_dict[package.package_type] = 1
assert sim._tdis_file.filename == "all_files_same_name.tdis"
for ims_file in sim._ims_files.values():
for ims_file in sim._solution_files.values():
assert ims_file.filename == "all_files_same_name.ims"
sim.write_simulation()
name_file = str(function_tmpdir / "all_files_same_name.nam")
Expand Down Expand Up @@ -3929,12 +3929,12 @@ def test006_2models_mvr(function_tmpdir, example_data_path):
for name in names:
assert name in model_names
model = sim.get_model(name)
assert model.model_type == "gwf"
assert model.model_type == "gwf6"
models = sim.gwf
assert len(models) == 2
for model in models:
assert model.name in model_names
assert model.model_type == "gwf"
assert model.model_type == "gwf6"

# change some settings
parent_model = sim.get_model(model_names[0])
Expand Down Expand Up @@ -4021,7 +4021,7 @@ def test006_2models_mvr(function_tmpdir, example_data_path):
assert (len(sim._exchange_files) > 0) == (
"gwf6-gwf6" in load_only or "gwf-gwf" in load_only
)
assert (len(sim._ims_files) > 0) == (
assert (len(sim._solution_files) > 0) == (
"ims6" in load_only or "ims" in load_only
)

Expand Down
45 changes: 30 additions & 15 deletions flopy/mbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1695,23 +1695,38 @@ def run_model(
normal_msg[idx] = s.lower()

# Check to make sure that program and namefile exist
exe = which(exe_name)
if exe is None:
if exe_name.lower().endswith(".exe"):
# try removing .exe suffix
exe = which(exe_name[:-4])
if exe is None:
# try abspath
exe = which(os.path.abspath(exe_name))
if exe is None:
raise Exception(
f"The program {exe_name} does not exist or is not executable."
)
if os.path.dirname(exe_name) == "":
exe = which(exe_name)
if exe is None:
if exe_name.lower().endswith(".exe"):
# try removing .exe suffix
exe = which(exe_name[:-4])
if exe is not None:
exe_name = exe_name[:-4]
if exe is None:
raise Exception(
f"The program {exe_name} does not exist or is not executable."
)
else:
if not silent:
print(
f"FloPy is using the following executable to run the "
f"model: {exe}"
)
else:
if not silent:
print(
f"FloPy is using the following executable to run the model: {exe}"
exe_name = os.path.abspath(exe_name)
if not os.path.exists(exe_name) and not os.path.exists(
f"{exe_name}.exe"
):
raise Exception(
f"The program {exe_name} does not exist or is not executable."
)
else:
if not silent:
print(
f"FloPy is using the following executable to run the "
f"model: {exe_name}"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great to have this change, but I think we want this one as a separate PR. I understand that that it's easy to sneak it in here, but I think a separate PR is warranted in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@langevin-usgs, rolled back exe path feature for another PR


if namefile is not None:
if not os.path.isfile(os.path.join(model_ws, namefile)):
Expand Down
1 change: 1 addition & 0 deletions flopy/mf6/data/dfn/sln-ims.dfn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# --------------------- sln ims options ---------------------
# flopy solution_package ims *

block options
name print_option
Expand Down
29 changes: 28 additions & 1 deletion flopy/mf6/data/mfstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ast
import keyword
import os
import warnings
from enum import Enum
from textwrap import TextWrapper

Expand Down Expand Up @@ -2458,6 +2459,9 @@ def __load_structure(self):
# set up structure classes
self.sim_struct = MFSimulationStructure()

# initialize flopy dict keys
MFStructure().flopy_dict["solution_packages"] = {}

if self.load_from_dfn_files:
mf_dfn = Dfn()
dfn_files = mf_dfn.get_file_list()
Expand Down Expand Up @@ -2488,14 +2492,37 @@ def __load_structure(self):
"parameter_name": line_lst[6],
}
MFStructure().flopy_dict[line_lst[3]] = sp_dict

elif line_lst[2] == "solution_package":
MFStructure().flopy_dict["solution_packages"][
line_lst[3]
] = line_lst[4:]
if len(MFStructure().flopy_dict["solution_packages"]) == 0:
MFStructure().flopy_dict["solution_packages"]["ims"] = ["*"]
warnings.warn(
"Package definition files (dfn) do not define a solution "
"package. This can happen if your dfn files are out of "
"sync. Auto-loaded default IMS solution package metadata."
" In the future auto-loading default metadata will be "
"deprecated.",
DeprecationWarning,
)
# process each file
for file in dfn_files:
self.sim_struct.process_dfn(DfnFile(file))
self.sim_struct.tag_read_as_arrays()
else:
package_list = PackageContainer.package_list()
for package in package_list:
# process header
for entry in package.dfn[0][1:]:
if (
isinstance(entry, list)
and entry[0] == "solution_package"
):
MFStructure().flopy_dict["solution_packages"][
package.package_abbr
] = entry[1:]
# process each package
self.sim_struct.process_dfn(DfnPackage(package))
self.sim_struct.tag_read_as_arrays()

Expand Down
4 changes: 2 additions & 2 deletions flopy/mf6/modflow/mfgwf.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 December 15, 2022 12:49:36 UTC
# FILE created on January 27, 2023 18:36:16 UTC
from .. import mfmodel
from ..data.mfdatautil import ArrayTemplateGenerator, ListTemplateGenerator

Expand Down Expand Up @@ -129,7 +129,7 @@ def load(
structure,
modelname,
model_nam_file,
"gwf",
"gwf6",
version,
exe_name,
strict,
Expand Down
4 changes: 2 additions & 2 deletions flopy/mf6/modflow/mfgwt.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 December 15, 2022 12:49:36 UTC
# FILE created on January 27, 2023 18:36:16 UTC
from .. import mfmodel
from ..data.mfdatautil import ArrayTemplateGenerator, ListTemplateGenerator

Expand Down Expand Up @@ -122,7 +122,7 @@ def load(
structure,
modelname,
model_nam_file,
"gwt",
"gwt6",
version,
exe_name,
strict,
Expand Down
3 changes: 2 additions & 1 deletion flopy/mf6/modflow/mfims.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 December 15, 2022 12:49:36 UTC
# FILE created on January 27, 2023 18:36:16 UTC
from .. import mfpackage
from ..data.mfdatautil import ListTemplateGenerator

Expand Down Expand Up @@ -381,6 +381,7 @@ class ModflowIms(mfpackage.MFPackage):
dfn = [
[
"header",
["solution_package", "*"],
],
[
"block options",
Expand Down
Loading