Skip to content

Commit

Permalink
Merge branch 'master' into release_0.15.3
Browse files Browse the repository at this point in the history
  • Loading branch information
JoerivanEngelen committed Feb 23, 2024
2 parents 0013a91 + 6962958 commit 910cfef
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
15 changes: 8 additions & 7 deletions imod/mf6/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@
from imod.typing import GridDataArray


def initialize_template(name: str) -> Template:
loader = jinja2.PackageLoader("imod", "templates/mf6")
env = jinja2.Environment(loader=loader, keep_trailing_newline=True)
return env.get_template(name)


class Modflow6Model(collections.UserDict, abc.ABC):
_mandatory_packages: Tuple[str, ...] = ()
_model_id: Optional[str] = None
_template: Template

@staticmethod
def _initialize_template(name: str) -> Template:
loader = jinja2.PackageLoader("imod", "templates/mf6")
env = jinja2.Environment(loader=loader, keep_trailing_newline=True)
return env.get_template(name)


def __init__(self, **kwargs):
collections.UserDict.__init__(self)
for k, v in kwargs.items():
self[k] = v

self._options = {}
self._template = None

def __setitem__(self, key, value):
if len(key) > 16:
Expand Down
5 changes: 3 additions & 2 deletions imod/mf6/model_gwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

from imod.mf6 import ConstantHead
from imod.mf6.clipped_boundary_condition_creator import create_clipped_boundary
from imod.mf6.model import Modflow6Model, initialize_template
from imod.mf6.model import Modflow6Model
from imod.mf6.regridding_utils import RegridderType
from imod.typing import GridDataArray


class GroundwaterFlowModel(Modflow6Model):
_mandatory_packages = ("npf", "ic", "oc", "sto")
_model_id = "gwf6"
_template = Modflow6Model._initialize_template("gwf-nam.j2")

def __init__(
self,
Expand All @@ -34,7 +35,7 @@ def __init__(
"newton": newton,
"under_relaxation": under_relaxation,
}
self._template = initialize_template("gwf-nam.j2")


def _get_unique_regridder_types(self) -> dict[RegridderType, str]:
"""
Expand Down
4 changes: 2 additions & 2 deletions imod/mf6/model_gwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Optional

from imod.mf6.model import Modflow6Model, initialize_template
from imod.mf6.model import Modflow6Model


class GroundwaterTransportModel(Modflow6Model):
Expand All @@ -13,6 +13,7 @@ class GroundwaterTransportModel(Modflow6Model):

_mandatory_packages = ("mst", "dsp", "oc", "ic")
_model_id = "gwt6"
_template = Modflow6Model._initialize_template("gwt-nam.j2")

def __init__(
self,
Expand All @@ -29,4 +30,3 @@ def __init__(
"save_flows": save_flows,
}

self._template = initialize_template("gwt-nam.j2")
8 changes: 8 additions & 0 deletions imod/tests/test_mf6/test_mf6_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,11 @@ def test_purge_empty_package(
unstructured_flow_model["hfb"] = imod.mf6.HorizontalFlowBarrierResistance(geometry)
unstructured_flow_model.purge_empty_packages()
assert original_nr_packages == len(unstructured_flow_model.items())



def test_deepcopy(
unstructured_flow_model: GroundwaterFlowModel,
):
# test making a deepcopy will not crash
_ = deepcopy(unstructured_flow_model)
7 changes: 7 additions & 0 deletions imod/tests/test_mf6/test_mf6_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import sys
import textwrap
from copy import deepcopy
from datetime import datetime
from pathlib import Path
from unittest import mock
Expand Down Expand Up @@ -475,6 +476,12 @@ def test_prevent_clip_box_after_split(
with pytest.raises(RuntimeError):
_ = split_simulation.clip_box()

def test_deepcopy(
split_transient_twri_model
):
# test making a deepcopy will not crash
_ = deepcopy( split_transient_twri_model)

@pytest.mark.usefixtures("split_transient_twri_model")
def test_prevent_regrid_like_after_split(
self,
Expand Down

0 comments on commit 910cfef

Please sign in to comment.