Coverage for C:\src\imod-python\imod\mf6\rch.py: 100%

1 from typing import Optional, Tuple

2

3 import numpy as np

4

5 from imod.logging import init_log_decorator

6 from imod.mf6.boundary_condition import BoundaryCondition

7 from imod.mf6.interfaces.iregridpackage import IRegridPackage

8 from imod.mf6.utilities.regrid import RegridderType

9 from imod.mf6.validation import BOUNDARY_DIMS_SCHEMA, CONC_DIMS_SCHEMA

10 from imod.schemata import (

11 AllInsideNoDataSchema,

12 AllNoDataSchema,

13 AllValueSchema,

14 CoordsSchema,

15 DimsSchema,

16 DTypeSchema,

17 IdentityNoDataSchema,

18 IndexesSchema,

19 OtherCoordsSchema,

20)

21

22

23 class Recharge(BoundaryCondition, IRegridPackage):

24 """

25 Recharge Package.

26 Any number of RCH Packages can be specified for a single groundwater flow

27 model.

28 https://water.usgs.gov/water-resources/software/MODFLOW-6/mf6io_6.0.4.pdf#page=79

29

30 Parameters

31 ----------

32 rate: array of floats (xr.DataArray)

33 is the recharge flux rate (LT −1). This rate is multiplied inside the

34 program by the surface area of the cell to calculate the volumetric

35 recharge rate. A time-series name may be specified.

36 concentration: array of floats (xr.DataArray, optional)

37 if this flow package is used in simulations also involving transport, then this array is used

38 as the concentration for inflow over this boundary.

39 concentration_boundary_type: ({"AUX", "AUXMIXED"}, optional)

40 if this flow package is used in simulations also involving transport, then this keyword specifies

41 how outflow over this boundary is computed.

42 print_input: ({True, False}, optional)

43 keyword to indicate that the list of recharge information will be

44 written to the listing file immediately after it is read.

45 Default is False.

46 print_flows: ({True, False}, optional)

47 Indicates that the list of recharge flow rates will be printed to the

48 listing file for every stress period time step in which "BUDGET PRINT"is

49 specified in Output Control. If there is no Output Control option and

50 PRINT FLOWS is specified, then flow rates are printed for the last time

51 step of each stress period.

52 Default is False.

53 save_flows: ({True, False}, optional)

54 Indicates that recharge flow terms will be written to the file specified

55 with "BUDGET FILEOUT" in Output Control.

56 Default is False.

57 observations: [Not yet supported.]

58 Default is None.

59 validate: {True, False}

60 Flag to indicate whether the package should be validated upon

61 initialization. This raises a ValidationError if package input is

62 provided in the wrong manner. Defaults to True.

63 repeat_stress: Optional[xr.DataArray] of datetimes

64 Used to repeat data for e.g. repeating stress periods such as

65 seasonality without duplicating the values. The DataArray should have

66 dimensions ``("repeat", "repeat_items")``. The ``repeat_items``

67 dimension should have size 2: the first value is the "key", the second

68 value is the "value". For the "key" datetime, the data of the "value"

69 datetime will be used. Can also be set with a dictionary using the

70 ``set_repeat_stress`` method.

71 """

72

73 _pkg_id = "rch"

74 _period_data = ("rate",)

75 _keyword_map = {}

76

77 _init_schemata = {

78 "rate": [

79 DTypeSchema(np.floating),

80 IndexesSchema(),

81 CoordsSchema(("layer",)),

82 BOUNDARY_DIMS_SCHEMA,

83 ],

84 "concentration": [

85 DTypeSchema(np.floating),

86 IndexesSchema(),

87 CoordsSchema(

88 (

89 "species",

90 "layer",

91 )

92 ),

93 CONC_DIMS_SCHEMA,

94 ],

95 "print_flows": [DTypeSchema(np.bool_), DimsSchema()],

96 "save_flows": [DTypeSchema(np.bool_), DimsSchema()],

97 }

98 _write_schemata = {

99 "rate": [

100 OtherCoordsSchema("idomain"),

101 AllNoDataSchema(), # Check for all nan, can occur while clipping

102 AllInsideNoDataSchema(other="idomain", is_other_notnull=(">", 0)),

103 ],

104 "concentration": [IdentityNoDataSchema("rate"), AllValueSchema(">=", 0.0)],

105 }

106

107 _template = BoundaryCondition._initialize_template(_pkg_id)

108 _auxiliary_data = {"concentration": "species"}

109

110 _regrid_method = {

111 "rate": (RegridderType.OVERLAP, "mean"),

112 "concentration": (RegridderType.OVERLAP, "mean"),

113 }

114

115 @init_log_decorator()

116 def __init__(

117 self,

118 rate,

119 concentration=None,

120 concentration_boundary_type="auxmixed",

121 print_input=False,

122 print_flows=False,

123 save_flows=False,

124 observations=None,

125 validate: bool = True,

126 repeat_stress=None,

127 ):

128 dict_dataset = {

129 "rate": rate,

130 "concentration": concentration,

131 "concentration_boundary_type": concentration_boundary_type,

132 "print_input": print_input,

133 "print_flows": print_flows,

134 "save_flows": save_flows,

135 "observations": observations,

136 "repeat_stress": repeat_stress,

137 }

138 super().__init__(dict_dataset)

139 self._validate_init_schemata(validate)

140

141 def _validate(self, schemata, **kwargs):

142 # Insert additional kwargs

143 kwargs["rate"] = self["rate"]

144 errors = super()._validate(schemata, **kwargs)

145

146 return errors

147

148 def get_regrid_methods(self) -> Optional[dict[str, Tuple[RegridderType, str]]]:

149 return self._regrid_method