Coverage for C:\src\imod-python\imod\mf6\ic.py: 90%
39 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-08 13:27 +0200
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-08 13:27 +0200
1import warnings
2from typing import Optional, Tuple
4import numpy as np
6from imod.logging import init_log_decorator
7from imod.mf6.interfaces.iregridpackage import IRegridPackage
8from imod.mf6.package import Package
9from imod.mf6.utilities.regrid import RegridderType
10from imod.mf6.validation import PKG_DIMS_SCHEMA
11from imod.schemata import DTypeSchema, IdentityNoDataSchema, IndexesSchema
14class InitialConditions(Package, IRegridPackage):
15 """
16 Initial Conditions (IC) Package information is read from the file that is
17 specified by "IC6" as the file type. Only one IC Package can be specified
18 for a GWF model.
19 https://water.usgs.gov/water-resources/software/MODFLOW-6/mf6io_6.0.4.pdf#page=46
21 Parameters
22 ----------
23 head: array of floats (xr.DataArray)
24 for backwards compatibility this argument is maintained, but please use
25 the start-argument instead.
26 start: array of floats (xr.DataArray)
27 is the initial (starting) head or concentration—that is, the simulation's
28 initial state.
29 STRT must be specified for all simulations, including steady-state simulations.
30 One value is read for every model cell. For
31 simulations in which the first stress period is steady state, the values
32 used for STRT generally do not affect the simulation (exceptions may
33 occur if cells go dry and (or) rewet). The execution time, however, will
34 be less if STRT includes hydraulic heads that are close to the
35 steadystate solution. A head value lower than the cell bottom can be
36 provided if a cell should start as dry. (strt)
37 validate: {True, False}
38 Flag to indicate whether the package should be validated upon
39 initialization. This raises a ValidationError if package input is
40 provided in the wrong manner. Defaults to True.
41 """
43 _pkg_id = "ic"
44 _grid_data = {"head": np.float64}
45 _keyword_map = {"head": "strt"}
46 _template = Package._initialize_template(_pkg_id)
48 _init_schemata = {
49 "start": [
50 DTypeSchema(np.floating),
51 IndexesSchema(),
52 PKG_DIMS_SCHEMA,
53 ],
54 }
55 _write_schemata = {
56 "start": [
57 IdentityNoDataSchema(other="idomain", is_other_notnull=(">", 0)),
58 ],
59 }
61 _grid_data = {"start": np.float64}
62 _keyword_map = {"start": "strt"}
63 _template = Package._initialize_template(_pkg_id)
65 _regrid_method = {
66 "start": (
67 RegridderType.OVERLAP,
68 "mean",
69 ), # TODO set to barycentric once supported
70 }
72 @init_log_decorator()
73 def __init__(self, start=None, head=None, validate: bool = True):
74 if start is None:
75 start = head
76 warnings.warn(
77 'The keyword argument "head" is deprecated. Please use the start argument.',
78 DeprecationWarning,
79 )
80 if head is None:
81 raise ValueError("start and head arguments cannot both be None")
82 else:
83 if head is not None:
84 raise ValueError("start and head arguments cannot both be defined")
86 dict_dataset = {"start": start}
87 super().__init__(dict_dataset)
88 self._validate_init_schemata(validate)
90 def render(self, directory, pkgname, globaltimes, binary):
91 d = {}
93 icdirectory = directory / pkgname
94 d["layered"], d["strt"] = self._compose_values(
95 self["start"], icdirectory, "strt", binary=binary
96 )
97 return self._template.render(d)
99 def get_regrid_methods(self) -> Optional[dict[str, Tuple[RegridderType, str]]]:
100 return self._regrid_method