-
Notifications
You must be signed in to change notification settings - Fork 3
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
Issue #1255 msw refactor mf6 obj at write #1259
Changes from all commits
68cf5e3
c752561
1bd6a23
4d67516
da79834
d862b09
24f1da6
ad0cc83
a253bd9
d06ccdc
0aaeb04
6b291fe
091f859
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ | |
import jinja2 | ||
import numpy as np | ||
|
||
from imod import mf6 | ||
from imod.mf6.dis import StructuredDiscretization | ||
from imod.mf6.mf6_wel_adapter import Mf6Wel | ||
from imod.mf6.utilities.regrid import RegridderWeightsCache | ||
from imod.msw.coupler_mapping import CouplerMapping | ||
from imod.msw.grid_data import GridData | ||
|
@@ -106,7 +107,7 @@ def __init__(self, unsaturated_database): | |
self._render_unsaturated_database_path(unsaturated_database) | ||
) | ||
|
||
def _render_unsaturated_database_path(self, unsaturated_database): | ||
def _render_unsaturated_database_path(self, unsaturated_database: Union[str, Path]): | ||
# Force to Path object | ||
unsaturated_database = Path(unsaturated_database) | ||
|
||
|
@@ -204,7 +205,12 @@ def _get_pkg_key(self, pkg_type: type, optional_package: bool = False): | |
if not optional_package: | ||
raise KeyError(f"Could not find package of type: {pkg_type}") | ||
|
||
def write(self, directory: Union[str, Path]): | ||
def write( | ||
self, | ||
directory: Union[str, Path], | ||
mf6_dis: StructuredDiscretization, | ||
mf6_wel: Mf6Wel, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean there can only be one well in the model? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only one MODFLOW6 well package can be coupled to MetaSWAP. The MODFLOW6 groundwater model itsself can have more well packages. |
||
): | ||
""" | ||
Write packages and simulation settings (para_sim.inp). | ||
|
||
|
@@ -244,11 +250,11 @@ def write(self, directory: Union[str, Path]): | |
|
||
# write package contents | ||
for pkgname in self: | ||
self[pkgname].write(directory, index, svat) | ||
self[pkgname].write(directory, index, svat, mf6_dis, mf6_wel) | ||
|
||
def regrid_like( | ||
self, | ||
mf6_regridded_dis: mf6.StructuredDiscretization, | ||
mf6_regridded_dis: StructuredDiscretization, | ||
regrid_context: Optional[RegridderWeightsCache] = None, | ||
regridder_types: Optional[dict[str, Tuple[RegridderType, str]]] = None, | ||
) -> "MetaSwapModel": | ||
|
@@ -273,6 +279,6 @@ def regrid_like( | |
raise ValueError(f"package {pkgname} cannot be regridded") | ||
regridded_model[pkgname] = regridded_package | ||
if mod2svat_name is not None: | ||
regridded_model[mod2svat_name] = CouplerMapping(mf6_regridded_dis) | ||
regridded_model[mod2svat_name] = CouplerMapping() | ||
|
||
return regridded_model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don;t know if this is better but below an alternative way of writting this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is also a good way of doing things. It has the slight advantage that there is an additional variable being named, which might improve reality a bit, though updating keys in a for loop is such a basic thing in python that most developers will not struggle with this part of the code.
The slight advantage of the present approach is a slightly reduced memory use, as variables are updated one by one, instead of creating a full dictionary
appended_well_data
first and updating the existing dict with it. Though I do not think in most cases memory use here will matter a lot.I think I'll stick to the present approach, it is a bit of a micro-optimalization; I do not have a strong opinion on the best approach, and I don't think it will matter a lot in the end.