-
Notifications
You must be signed in to change notification settings - Fork 3
Issue #748 Fix failing transport model examples i.c.w. the MODFLOW6 nightly build #771
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aab4522
Fix failing transport model examples i.c.w. the MODFLOW6 nightly build
Manangka 96a53ce
Fix mypy errors. Clean up code
Manangka c3372aa
Add unit tests
Manangka 2bde064
Update changelog
Manangka a9227be
Fix failing unit test
Manangka 39d7be5
Apply review comments
Manangka 8fb7a67
Fix failing unit test
Manangka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import Dict, Tuple | ||
|
||
from imod.mf6.package import Package | ||
|
||
_pkg_id_to_type = {"gwfgwf": "GWF6-GWF6", "gwfgwt": "GWF6-GWT6"} | ||
|
||
|
||
class ExchangeBase(Package): | ||
""" | ||
Base class for all the exchanges. | ||
This class enables writing the exchanges to file in a uniform way. | ||
""" | ||
|
||
_keyword_map: Dict[str, str] = {} | ||
|
||
@property | ||
def model_name1(self) -> str: | ||
if "model_name_1" not in self.dataset: | ||
raise ValueError("model_name_1 not present in dataset") | ||
return self.dataset["model_name_1"].values[()].take(0) | ||
|
||
@property | ||
def model_name2(self) -> str: | ||
if "model_name_2" not in self.dataset: | ||
raise ValueError("model_name_2 not present in dataset") | ||
return self.dataset["model_name_2"].values[()].take(0) | ||
|
||
def package_name(self) -> str: | ||
return f"{self.model_name1}_{self.model_name2}" | ||
|
||
def get_specification(self) -> Tuple[str, str, str, str]: | ||
""" | ||
Returns a tuple containing the exchange type, the exchange file name, and the model names. This can be used | ||
to write the exchange information in the simulation .nam input file | ||
""" | ||
filename = f"{self.package_name()}.{self._pkg_id}" | ||
return ( | ||
_pkg_id_to_type[self._pkg_id], | ||
filename, | ||
self.model_name1, | ||
self.model_name2, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from copy import deepcopy | ||
from typing import Optional | ||
|
||
import cftime | ||
import numpy as np | ||
|
||
from imod.mf6.exchangebase import ExchangeBase | ||
from imod.mf6.package import Package | ||
from imod.typing import GridDataArray | ||
|
||
|
||
class GWFGWT(ExchangeBase): | ||
_pkg_id = "gwfgwt" | ||
_template = Package._initialize_template(_pkg_id) | ||
|
||
def __init__(self, model_id1: str, model_id2: str): | ||
super().__init__(locals()) | ||
self.dataset["model_name_1"] = model_id1 | ||
self.dataset["model_name_2"] = model_id2 | ||
|
||
def clip_box( | ||
self, | ||
time_min: Optional[cftime.datetime | np.datetime64 | str] = None, | ||
time_max: Optional[cftime.datetime | np.datetime64 | str] = None, | ||
layer_min: Optional[int] = None, | ||
layer_max: Optional[int] = None, | ||
x_min: Optional[float] = None, | ||
x_max: Optional[float] = None, | ||
y_min: Optional[float] = None, | ||
y_max: Optional[float] = None, | ||
top: Optional[GridDataArray] = None, | ||
bottom: Optional[GridDataArray] = None, | ||
state_for_boundary: Optional[GridDataArray] = None, | ||
) -> Package: | ||
""" | ||
The GWF-GWT exchange does not have any spatial coordinates that can be clipped. | ||
""" | ||
return deepcopy(self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from contextlib import nullcontext as does_not_raise | ||
|
||
import pytest | ||
|
||
from imod.mf6.exchangebase import ExchangeBase, _pkg_id_to_type | ||
|
||
|
||
class DummyExchange(ExchangeBase): | ||
_pkg_id = "gwfgwt" | ||
|
||
def __init__(self, model_id1: str = None, model_id2: str = None): | ||
super().__init__() | ||
if model_id1: | ||
self.dataset["model_name_1"] = model_id1 | ||
if model_id2: | ||
self.dataset["model_name_2"] = model_id2 | ||
|
||
|
||
def test_package_name_construct_name(): | ||
# Arrange. | ||
model_name1 = "testmodel1" | ||
model_name2 = "testmodel2" | ||
exchange = DummyExchange(model_name1, model_name2) | ||
|
||
# Act. | ||
package_name = exchange.package_name() | ||
|
||
# Assert. | ||
assert model_name1 in package_name | ||
assert model_name2 in package_name | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("model_name1", "model_name2", "expectation"), | ||
( | ||
[None, None, pytest.raises(ValueError)], | ||
["testmodel1", None, pytest.raises(ValueError)], | ||
[None, "testmodel2", pytest.raises(ValueError)], | ||
["testmodel1", "testmodel2", does_not_raise()], | ||
), | ||
) | ||
def test_package_name_missing_name(model_name1, model_name2, expectation): | ||
# Arrange | ||
exchange = DummyExchange(model_name1, model_name2) | ||
|
||
# Act/Assert | ||
with expectation: | ||
exchange.package_name() | ||
|
||
|
||
def test_get_specification(): | ||
# Arrange. | ||
model_name1 = "testmodel1" | ||
model_name2 = "testmodel2" | ||
exchange = DummyExchange(model_name1, model_name2) | ||
|
||
# Act. | ||
( | ||
spec_exchange_type, | ||
spec_filename, | ||
spec_model_name1, | ||
spec_model_name2, | ||
) = exchange.get_specification() | ||
|
||
# Assert | ||
assert spec_exchange_type is _pkg_id_to_type[DummyExchange._pkg_id] | ||
assert model_name1 in spec_filename | ||
assert model_name2 in spec_filename | ||
assert DummyExchange._pkg_id in spec_filename | ||
assert spec_model_name1 == model_name1 | ||
assert spec_model_name2 == model_name2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.