Coverage for C:\src\imod-python\imod\mf6\ghb.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 GeneralHeadBoundary(BoundaryCondition, IRegridPackage):

24 """

25 The General-Head Boundary package is used to simulate head-dependent flux

26 boundaries.

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

28

29 Parameters

30 ----------

31 head: array of floats (xr.DataArray)

32 is the boundary head. (bhead)

33 conductance: array of floats (xr.DataArray)

34 is the hydraulic conductance of the interface between the aquifer cell and

35 the boundary.(cond)

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 general head boundary information

44 will be 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 general head boundary flow rates will be

48 printed to the listing file for every stress period time step in which

49 "BUDGET PRINT" is specified in Output Control. If there is no Output

50 Control option and PRINT FLOWS is specified, then flow rates are printed

51 for the last time step of each stress period.

52 Default is False.

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

54 Indicates that general head boundary flow terms will be written to the

55 file specified 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 = "ghb"

74 _period_data = ("head", "conductance")

75

76 _init_schemata = {

77 "head": [

78 DTypeSchema(np.floating),

79 IndexesSchema(),

80 CoordsSchema(("layer",)),

81 BOUNDARY_DIMS_SCHEMA,

82 ],

83 "conductance": [

84 DTypeSchema(np.floating),

85 IndexesSchema(),

86 CoordsSchema(("layer",)),

87 BOUNDARY_DIMS_SCHEMA,

88 ],

89 "concentration": [

90 DTypeSchema(np.floating),

91 IndexesSchema(),

92 CoordsSchema(

93 (

94 "species",

95 "layer",

96 )

97 ),

98 CONC_DIMS_SCHEMA,

99 ],

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

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

102 }

103 _write_schemata = {

104 "head": [

105 OtherCoordsSchema("idomain"),

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

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

108 ],

109 "conductance": [IdentityNoDataSchema("head"), AllValueSchema(">", 0.0)],

110 "concentration": [IdentityNoDataSchema("head"), AllValueSchema(">=", 0.0)],

111 }

112

113 _keyword_map = {}

114 _template = BoundaryCondition._initialize_template(_pkg_id)

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

116

117 _regrid_method = {

118 "head": (

119 RegridderType.OVERLAP,

120 "mean",

121 ), # TODO set to barycentric once supported

122 "conductance": (RegridderType.RELATIVEOVERLAP, "conductance"),

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

124 }

125

126 @init_log_decorator()

127 def __init__(

128 self,

129 head,

130 conductance,

131 concentration=None,

132 concentration_boundary_type="aux",

133 print_input=False,

134 print_flows=False,

135 save_flows=False,

136 observations=None,

137 validate: bool = True,

138 repeat_stress=None,

139 ):

140 dict_dataset = {

141 "head": head,

142 "conductance": conductance,

143 "concentration": concentration,

144 "concentration_boundary_type": concentration_boundary_type,

145 "print_input": print_input,

146 "print_flows": print_flows,

147 "save_flows": save_flows,

148 "observations": observations,

149 "repeat_stress": repeat_stress,

150 }

151 super().__init__(dict_dataset)

152 self._validate_init_schemata(validate)

153

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

155 # Insert additional kwargs

156 kwargs["head"] = self["head"]

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

158

159 return errors

160

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

162 return self._regrid_method