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

Add support for discharge scaling in drainage package #1012

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
3 changes: 0 additions & 3 deletions docs/api/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ Changed
:class:`imod.mf6.utilities.regrid.RegridderWeightsCache`, as they were not
used.

[0.16.0] - 2024-03-29
---------------------

Added
~~~~~
- The :func:`imod.mf6.model.mask_all_packages` now also masks the idomain array
Expand Down
2 changes: 1 addition & 1 deletion imod/mf6/boundary_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def get_period_varnames(self):
if hasattr(self, "_auxiliary_data"):
result.extend(get_variable_names(self))

return result
return [var for var in result if var in self.dataset.data_vars]


class AdvancedBoundaryCondition(BoundaryCondition, abc.ABC):
Expand Down
42 changes: 41 additions & 1 deletion imod/mf6/drn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np

from imod.logging import init_log_decorator
from imod.mf6.auxiliary_variables import get_variable_names
from imod.mf6.boundary_condition import BoundaryCondition
from imod.mf6.interfaces.iregridpackage import IRegridPackage
from imod.mf6.utilities.regrid import RegridderType
Expand Down Expand Up @@ -37,6 +38,15 @@ class Drainage(BoundaryCondition, IRegridPackage):
concentration_boundary_type: ({"AUX", "AUXMIXED"}, optional)
if this flow package is used in simulations also involving transport, then this keyword specifies
how outflow over this boundary is computed.
scaling_depth: array of floats (xr.DataArray)
if provided, enables the drainage package discharge scaling.
Effectively, the conductance is reduced. Its value may be both positive
or negative.
If positive: drainage starts at head equals elevation. At (elevation +
depth) the scaling factor becomes 1.0.
If negative: drainage starts at
elevation + depth (elevation - |depth|). At elevation the scaling
factor becomes 1.0.
print_input: ({True, False}, optional)
keyword to indicate that the list of drain information will be written
to the listing file immediately after it is read. Default is False.
Expand Down Expand Up @@ -93,6 +103,12 @@ class Drainage(BoundaryCondition, IRegridPackage):
),
CONC_DIMS_SCHEMA,
],
"scaling_depth": [
DTypeSchema(np.floating),
IndexesSchema(),
CoordsSchema(("layer",)),
BOUNDARY_DIMS_SCHEMA,
],
"print_flows": [DTypeSchema(np.bool_), DimsSchema()],
"save_flows": [DTypeSchema(np.bool_), DimsSchema()],
}
Expand All @@ -104,9 +120,10 @@ class Drainage(BoundaryCondition, IRegridPackage):
],
"conductance": [IdentityNoDataSchema("elevation"), AllValueSchema(">", 0.0)],
"concentration": [IdentityNoDataSchema("elevation"), AllValueSchema(">=", 0.0)],
"scaling_depth": [IdentityNoDataSchema("elevation")],
}

_period_data = ("elevation", "conductance")
_period_data = ("elevation", "conductance", "scaling_depth")
_keyword_map = {}
_template = BoundaryCondition._initialize_template(_pkg_id)
_auxiliary_data = {"concentration": "species"}
Expand All @@ -123,6 +140,7 @@ def __init__(
elevation,
conductance,
concentration=None,
scaling_depth=None,
concentration_boundary_type="aux",
print_input=False,
print_flows=False,
Expand All @@ -135,6 +153,7 @@ def __init__(
"elevation": elevation,
"conductance": conductance,
"concentration": concentration,
"scaling_depth": scaling_depth,
"concentration_boundary_type": concentration_boundary_type,
"print_input": print_input,
"print_flows": print_flows,
Expand All @@ -153,5 +172,26 @@ def _validate(self, schemata, **kwargs):

return errors

def render(self, directory, pkgname, globaltimes, binary):
"""Render fills in the template only, doesn't write binary data"""
d = {"binary": binary}
bin_ds = self._get_bin_ds()
d["periods"] = self._period_paths(
directory, pkgname, globaltimes, bin_ds, binary
)
# construct the rest (dict for render)
d = self._get_options(d)
d["maxbound"] = self._max_active_n()

if (hasattr(self, "_auxiliary_data")) and (names := get_variable_names(self)):
d["auxiliary"] = names
if self.dataset["scaling_depth"] is not None:
d["auxdepthname"] = "scaling_depth"
if "auxiliary" in d:
d["auxiliary"] += ["scaling_depth"]
else:
d["auxiliary"] = ["scaling_depth"]
return self._template.render(d)

def get_regrid_methods(self) -> Optional[dict[str, Tuple[RegridderType, str]]]:
return self._regrid_method
2 changes: 2 additions & 0 deletions imod/templates/mf6/gwf-drn.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ begin options
{% endif %}
{%- if auxmultname is defined %} auxmultname {{auxmultname}}
{% endif %}
{%- if auxdepthname is defined %} auxdepthname {{auxdepthname}}
{% endif %}
{%- if boundnames is defined %} boundnames
{% endif %}
{%- if print_input is defined %} print_input
Expand Down