Coverage for C:\src\imod-python\imod\wq\riv.py: 96%
28 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-08 14:15 +0200
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-08 14:15 +0200
1from imod.wq.pkgbase import BoundaryCondition
4class River(BoundaryCondition):
5 """
6 The River package is used to simulate head-dependent flux boundaries. In the
7 River package if the head in the cell falls below a certain threshold, the
8 flux from the river to the model cell is set to a specified lower bound.
10 Parameters
11 ----------
12 stage: float or xr.DataArray of floats
13 is the head in the river (STAGE).
14 bottom_elevation: float or xr.DataArray of floats
15 is the bottom of the riverbed (RBOT).
16 conductance: float or xr.DataArray of floats
17 is the conductance of the river.
18 density: float or xr.DataArray of floats
19 is the density used to convert the point head to the freshwater head
20 (RIVSSMDENS).
21 concentration: "None", float or xr.DataArray of floats, optional
22 is the concentration in the river.
23 Default is None.
24 save_budget: bool, optional
25 is a flag indicating if the budget should be saved (IRIVCB).
26 Default is False.
27 """
29 _pkg_id = "riv"
31 _mapping = (
32 ("stage", "stage"),
33 ("cond", "conductance"),
34 ("rbot", "bottom_elevation"),
35 ("rivssmdens", "density"),
36 )
38 def __init__(
39 self,
40 stage,
41 conductance,
42 bottom_elevation,
43 density,
44 concentration=None,
45 save_budget=False,
46 ):
47 super().__init__()
48 self["stage"] = stage
49 self["conductance"] = conductance
50 self["bottom_elevation"] = bottom_elevation
51 self["density"] = density
52 if concentration is not None:
53 self["concentration"] = concentration
54 self["save_budget"] = save_budget
56 def _pkgcheck(self, ibound=None):
57 to_check = ["conductance", "density"]
58 if "concentration" in self.dataset.data_vars:
59 to_check.append("concentration")
60 self._check_positive(to_check)
62 to_check.append("stage")
63 to_check.append("bottom_elevation")
64 self._check_location_consistent(to_check)
66 if (self.dataset["bottom_elevation"] > self.dataset["stage"]).any():
67 raise ValueError(
68 "Bottom elevation in {self} should not be higher than stage"
69 )
71 def repeat_stress(
72 self,
73 stage=None,
74 conductance=None,
75 bottom_elevation=None,
76 concentration=None,
77 density=None,
78 use_cftime=False,
79 ):
80 varnames = [
81 "stage",
82 "conductance",
83 "bottom_elevation",
84 "density",
85 "concentration",
86 ]
87 values = [stage, conductance, bottom_elevation, density, concentration]
88 for varname, value in zip(varnames, values):
89 self._repeat_stress(varname, value, use_cftime)