Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Issue #747 transport exchange options #820

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
Show file tree
Hide file tree
Changes from all 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
4 changes: 0 additions & 4 deletions imod/mf6/gwtgwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ def __init__(

def set_options(
self,
print_input: Optional[bool] = None,
print_flows: Optional[bool] = None,
save_flows: Optional[bool] = None,
adv_scheme: Optional[str] = None,
dsp_xt3d_off: Optional[bool] = None,
dsp_xt3d_rhs: Optional[bool] = None,
):
self.dataset["print_input"] = print_input
self.dataset["print_flows"] = print_flows
self.dataset["save_flows"] = save_flows
self.dataset["adv_scheme"] = adv_scheme
self.dataset["dsp_xt3d_off"] = dsp_xt3d_off
Expand Down
31 changes: 26 additions & 5 deletions imod/mf6/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,8 @@ def split(self, submodel_labels: xr.DataArray) -> Modflow6Simulation:
tpt_model_name, flow_model_name, model.domain.layer
)
new_simulation._add_modelsplit_exchanges(exchanges)
new_simulation._set_exchange_options()
new_simulation._set_flow_exchange_options()
new_simulation._set_transport_exchange_options()
new_simulation._update_ssm_packages()

new_simulation._filter_inactive_cells_from_exchanges()
Expand Down Expand Up @@ -1018,7 +1019,7 @@ def _add_modelsplit_exchanges(self, exchanges_list: list[GWFGWF]) -> None:
self["split_exchanges"] = []
self["split_exchanges"].extend(exchanges_list)

def _set_exchange_options(self):
def _set_flow_exchange_options(self) -> None:
# collect some options that we will auto-set
for exchange in self["split_exchanges"]:
if isinstance(exchange, GWFGWF):
Expand All @@ -1031,9 +1032,29 @@ def _set_exchange_options(self):
xt3d=model_1["npf"].get_xt3d_option(),
newton=model_1.is_use_newton(),
)
elif isinstance(exchange, GWTGWT):
# TODO: issue #747
continue

def _set_transport_exchange_options(self) -> None:
for exchange in self["split_exchanges"]:
if isinstance(exchange, GWTGWT):
model_name_1 = exchange.dataset["model_name_1"].values[()]
model_1 = self[model_name_1]
advection_key = model_1._get_pkgkey("adv")
dispersion_key = model_1._get_pkgkey("dsp")

scheme = None
xt3d_off = None
xt3d_rhs = None
if advection_key is not None:
scheme = model_1[advection_key].dataset["scheme"].values[()]
if dispersion_key is not None:
xt3d_off = model_1[dispersion_key].dataset["xt3d_off"].values[()]
xt3d_rhs = model_1[dispersion_key].dataset["xt3d_rhs"].values[()]
exchange.set_options(
save_flows=model_1["oc"].is_budget_output,
adv_scheme=scheme,
dsp_xt3d_off=xt3d_off,
dsp_xt3d_rhs=xt3d_rhs,
)

def _filter_inactive_cells_from_exchanges(self) -> None:
for ex in self["split_exchanges"]:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import numpy as np
import pytest

from imod.mf6.adv import Advection
from imod.mf6.dsp import Dispersion
from imod.mf6.multimodel.modelsplitter import create_partition_info, slice_model
from imod.mf6.simulation import Modflow6Simulation
from imod.tests.fixtures.mf6_modelrun_fixture import assert_simulation_can_run
from imod.typing.grid import zeros_like

Expand Down Expand Up @@ -81,6 +84,17 @@ def test_split_flow_and_transport_model(tmp_path, flow_transport_simulation):
assert_simulation_can_run(new_simulation, "dis", tmp_path)


def _edit_fixture(simulation: Modflow6Simulation) -> Modflow6Simulation:
# TODO: put the other transport models back when #797 is solved
simulation.pop("tpt_a")
simulation.pop("tpt_c")
simulation.pop("tpt_d")
simulation["transport_solver"].remove_model_from_solution("tpt_a")
simulation["transport_solver"].remove_model_from_solution("tpt_c")
simulation["transport_solver"].remove_model_from_solution("tpt_d")
return simulation


@pytest.mark.usefixtures("flow_transport_simulation")
def test_split_flow_and_transport_model_evaluate_output(
tmp_path, flow_transport_simulation
Expand All @@ -90,13 +104,7 @@ def test_split_flow_and_transport_model_evaluate_output(
flow_model = simulation["flow"]
active = flow_model.domain

# TODO: put the other transport models back when #797 is solved
simulation.pop("tpt_a")
simulation.pop("tpt_c")
simulation.pop("tpt_d")
simulation["transport_solver"].remove_model_from_solution("tpt_a")
simulation["transport_solver"].remove_model_from_solution("tpt_c")
simulation["transport_solver"].remove_model_from_solution("tpt_d")
simulation = _edit_fixture(simulation)

# create label array
submodel_labels = zeros_like(active)
Expand Down Expand Up @@ -130,3 +138,44 @@ def test_split_flow_and_transport_model_evaluate_output(
rtol=1e-4,
atol=0.011,
)


@pytest.mark.usefixtures("flow_transport_simulation")
@pytest.mark.parametrize("advection_scheme", ["TVD", "upstream", "central"])
@pytest.mark.parametrize("dsp_xt3d", [True, False])
def test_split_flow_and_transport_settings(
tmp_path, flow_transport_simulation, advection_scheme, dsp_xt3d
):
simulation = flow_transport_simulation

flow_model = simulation["flow"]
active = flow_model.domain

simulation = _edit_fixture(simulation)
simulation["tpt_b"]["dsp"] = Dispersion(
diffusion_coefficient=1e-2,
longitudinal_horizontal=20.0,
transversal_horizontal1=2.0,
xt3d_off=dsp_xt3d,
xt3d_rhs=dsp_xt3d,
)
simulation["tpt_b"]["adv"] = Advection(scheme=advection_scheme)
# create label array
submodel_labels = zeros_like(active)
submodel_labels = submodel_labels.drop_vars("layer")
submodel_labels.values[:, :, 30:] = 1
submodel_labels = submodel_labels.sel(layer=0, drop=True)

new_simulation = simulation.split(submodel_labels)
assert (
new_simulation["split_exchanges"][1].dataset["adv_scheme"].values[()]
== advection_scheme
)
assert (
new_simulation["split_exchanges"][1].dataset["dsp_xt3d_off"].values[()]
== dsp_xt3d
)
assert (
new_simulation["split_exchanges"][1].dataset["dsp_xt3d_rhs"].values[()]
== dsp_xt3d
)