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 fixed_cell: ({True, False}, optional)

72 indicates that recharge will not be reassigned to a cell underlying the

73 cell specified in the list if the specified cell is inactive.

74 """

75

76 _pkg_id = "rch"

77 _period_data = ("rate",)

78 _keyword_map = {}

79

80 _init_schemata = {

81 "rate": [

82 DTypeSchema(np.floating),

83 IndexesSchema(),

84 CoordsSchema(("layer",)),

85 BOUNDARY_DIMS_SCHEMA,

86 ],

87 "concentration": [

88 DTypeSchema(np.floating),

89 IndexesSchema(),

90 CoordsSchema(

91 (

92 "species",

93 "layer",

94 )

95 ),

96 CONC_DIMS_SCHEMA,

97 ],

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

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

100 }

101 _write_schemata = {

102 "rate": [

103 OtherCoordsSchema("idomain"),

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

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

106 ],

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

108 }

109

110 _template = BoundaryCondition._initialize_template(_pkg_id)

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

112

113 _regrid_method = {

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

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

116 }

117

118 @init_log_decorator()

119 def __init__(

120 self,

121 rate,

122 concentration=None,

123 concentration_boundary_type="auxmixed",

124 print_input=False,

125 print_flows=False,

126 save_flows=False,

127 observations=None,

128 validate: bool = True,

129 repeat_stress=None,

130 fixed_cell: bool = False,

131 ):

132 dict_dataset = {

133 "rate": rate,

134 "concentration": concentration,

135 "concentration_boundary_type": concentration_boundary_type,

136 "print_input": print_input,

137 "print_flows": print_flows,

138 "save_flows": save_flows,

139 "observations": observations,

140 "repeat_stress": repeat_stress,

141 "fixed_cell": fixed_cell,

142 }

143 super().__init__(dict_dataset)

144 self._validate_init_schemata(validate)

145

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

147 # Insert additional kwargs

148 kwargs["rate"] = self["rate"]

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

150

151 return errors

152

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

154 return self._regrid_method