Soil Water Balance (SWB2)
Loading...
Searching...
No Matches
direct_net_infiltration__gridded_data.F90
Go to the documentation of this file.
1!> @file
2!! Contains the module \ref direct_net_infiltration__gridded_data.
3
4!>
5!! Module \ref direct_net_infiltration__gridded_data
6!! provides support for adding miscellaneous source and sink terms.
7
9
10 use iso_c_binding
12 use data_catalog
14 use datetime
15 use dictionary
16 use exceptions
19 use parameters, only : params
21 use fstring
22 use fstring_list
23
24 implicit none
25
26 private
27
29
35
36 real (c_float), allocatable :: fcesspool(:)
37 real (c_float), allocatable :: fdisposal_well(:)
38 real (c_float), allocatable :: fwater_body_recharge(:)
39 real (c_float), allocatable :: fwater_main(:)
40 real (c_float), allocatable :: fannual_recharge_rate(:)
41
42 ! ****_TABLE variables: will have same number of values as there are landuses
43 real (c_float), allocatable :: fcesspool_table(:)
44 real (c_float), allocatable :: fdisposal_well_table(:)
45 real (c_float), allocatable :: fwater_body_recharge_table(:)
46 real (c_float), allocatable :: fwater_main_table(:)
47 real (c_float), allocatable :: fannual_recharge_rate_table(:)
48
50
51contains
52
53 !> Initialize the routine to enable input/output of arbitrary sources/sink terms.
54 !!
55 !! Open gridded data file.
56 !! Open a NetCDF output file to hold variable output.
57 !!
58 !! @param[in] is_cell_active 2D array of active cells within the model domain.
59 !! @param[in] iLanduseIndex 1D vector of indices corresponding to rows of the
60 !! landuse lookup table(s).
61 !! @param[in] dX 1D vector of X coordinates associated with the model domain.
62 !! @param[in] dY 1D vector of Y coordinates.
63 !! @param[in] dX_lon 2D array of longitude values.
64 !! @param[in] dY_lat 2D array of latitude values.
65
66 subroutine direct_net_infiltration_initialize( is_cell_active, landuse_index )
67
68 logical (c_bool), intent(in) :: is_cell_active(:,:)
69 integer (c_int), intent(in) :: landuse_index(:)
70
71 ! [ LOCALS ]
72 integer (c_int) :: status
73 type (fstring_list_t) :: parameter_list
74 integer (c_int) :: indx
75 integer (c_int), allocatable :: landuse_codes(:)
76 integer (c_int) :: number_of_landuses
77 logical (c_bool) :: are_lengths_equal
78
79
80 !> Determine how many landuse codes are present
81 call parameter_list%append( "LU_Code" )
82 call parameter_list%append( "Landuse_Code" )
83 call parameter_list%append( "Landuse_Lookup_Code" )
84
85 call params%get_parameters( slkeys=parameter_list, ivalues=landuse_codes )
86 number_of_landuses = count( landuse_codes > 0 )
87
88 call parameter_list%clear()
89 call parameter_list%append( "Annual_direct_net_infiltration_rate" )
90 call parameter_list%append( "Annual_direct_recharge_rate" )
91 call parameter_list%append( "Annual_direct_recharge" )
92 call parameter_list%append( "Annual_direct_net_infiltration" )
93
94 call params%get_parameters( slkeys=parameter_list , fvalues=fannual_recharge_rate_table )
95
96 ! attempt to find a source of GRIDDED ANNUAL DIRECT RECHARGE data
97 pannual_recharge_rate => dat%find( "ANNUAL_DIRECT_NET_INFILTRATION_RATE" )
98
99
100 call parameter_list%clear()
101 call parameter_list%append( "Cesspool_direct_net_infiltration" )
102 call parameter_list%append( "Cesspool_recharge" )
103 call parameter_list%append( "Cesspool_discharge" )
104 call parameter_list%append( "Cesspool_leakage" )
105
106 call params%get_parameters( slkeys=parameter_list , fvalues=fcesspool_table )
107
108 ! attempt to find a source of GRIDDED CESSPOOL data
109 pcesspool => dat%find( "CESSPOOL_LEAKAGE" )
110
111
112 ! call parameter_list%clear()
113 ! call parameter_list%append( "Storm_drain_discharge" )
114 ! call parameter_list%append( "Storm_drain_recharge" )
115 ! call parameter_list%append( "Storm_drain_leakage" )
116 !
117 ! call PARAMS%get_parameters( slKeys=parameter_list , fValues=fSTORM_DRAIN_TABLE )
118 !
119 ! pSTORM_DRAIN => DAT%find( "STORM_DRAIN" )
120 !
121
122 call parameter_list%clear()
123 call parameter_list%append( "Water_body_recharge" )
124 call parameter_list%append( "Water_body_discharge" )
125 call parameter_list%append( "Water_body_leakage" )
126
127 call params%get_parameters( slkeys=parameter_list , fvalues=fwater_body_recharge_table )
128
129 pwater_body_recharge => dat%find( "WATER_BODY_RECHARGE" )
130
131
132 call parameter_list%clear()
133 call parameter_list%append( "Water_main_recharge" )
134 call parameter_list%append( "Water_main_discharge" )
135 call parameter_list%append( "Water_main_leakage" )
136
137 call params%get_parameters( slkeys=parameter_list , fvalues=fwater_main_table )
138
139 pwater_main => dat%find( "WATER_MAIN_LEAKAGE" )
140
141
142 call parameter_list%clear()
143 call parameter_list%append( "Disposal_well_recharge" )
144 call parameter_list%append( "Disposal_well_discharge" )
145
146 call params%get_parameters( slkeys=parameter_list , fvalues=fdisposal_well_table )
147
148 pdisposal_well => dat%find( "DISPOSAL_WELL_DISCHARGE" )
149
150 if ( associated( pannual_recharge_rate ) ) then
151
152 allocate( fannual_recharge_rate( count( is_cell_active ) ), stat=status )
153 call assert( status==0, "Problem allocating memory", __file__, __line__ )
154
155 elseif ( fannual_recharge_rate_table(1) > ftinyval ) then
156
157 are_lengths_equal = ( ( ubound(fannual_recharge_rate_table,1) == ubound(landuse_codes,1) ) )
158
159 if ( .not. are_lengths_equal ) &
160 call warn( smessage="The number of landuses does not match the number of annual direct" &
161 //" recharge rate values.", smodule=__file__, iline=__line__, lfatal=.true._c_bool )
162
163 allocate( fannual_recharge_rate( count( is_cell_active ) ), stat=status )
164 call assert( status==0, "Problem allocating memory", __file__, __line__ )
165
166 do indx=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
167 fannual_recharge_rate( indx ) = fannual_recharge_rate_table( landuse_index( indx ) )
168 enddo
169
170 endif
171
172
173 if ( associated( pcesspool ) ) then
174
175 allocate( fcesspool( count( is_cell_active ) ), stat=status )
176 call assert( status==0, "Problem allocating memory", __file__, __line__ )
177
178 elseif ( fcesspool_table(1) > ftinyval ) then
179
180 are_lengths_equal = ( ( ubound(fcesspool_table,1) == ubound(landuse_codes,1) ) )
181
182 if ( .not. are_lengths_equal ) &
183 call warn( smessage="The number of landuses does not match the number of cesspool discharge/leakage values.", &
184 smodule=__file__, iline=__line__, lfatal=.true._c_bool )
185
186 allocate( fcesspool( count( is_cell_active ) ), stat=status )
187 call assert( status==0, "Problem allocating memory", __file__, __line__ )
188
189 do indx=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
190 fcesspool( indx ) = fcesspool_table( landuse_index( indx ) )
191 enddo
192
193 endif
194
195 ! if ( associated( pSTORM_DRAIN ) ) then
196 !
197 ! allocate( fSTORM_DRAIN( count( is_cell_active ) ), stat=status )
198 ! call assert( status==0, "Problem allocating memory", __FILE__, __LINE__ )
199 !
200 ! elseif ( fSTORM_DRAIN_TABLE(1) > fTINYVAL ) then
201 !
202 ! are_lengths_equal = ( ( ubound(fSTORM_DRAIN_TABLE,1) == ubound(landuse_codes,1) ) )
203 !
204 ! if ( .not. are_lengths_equal ) &
205 ! call warn( sMessage="The number of landuses does not match the number of storm drain discharge/leakage values.", &
206 ! sModule=__FILE__, iLine=__LINE__, lFatal=.true._c_bool )
207 !
208 ! allocate( fSTORM_DRAIN( count( is_cell_active ) ), stat=status )
209 ! call assert( status==0, "Problem allocating memory", __FILE__, __LINE__ )
210 !
211 ! do indx=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
212 ! fSTORM_DRAIN( indx ) = fSTORM_DRAIN_TABLE( landuse_index( indx ) )
213 ! enddo
214 !
215 ! endif
216
217 if ( associated( pwater_body_recharge ) ) then
218
219 allocate( fwater_body_recharge( count( is_cell_active ) ), stat=status )
220 call assert( status==0, "Problem allocating memory", __file__, __line__ )
221
222 elseif ( fwater_body_recharge_table(1) > ftinyval ) then
223
224 are_lengths_equal = ( ( ubound(fwater_body_recharge_table,1) == ubound(landuse_codes,1) ) )
225
226 if ( .not. are_lengths_equal ) &
227 call warn( smessage="The number of landuses does not match the number of water body recharge/leakage values.", &
228 smodule=__file__, iline=__line__, lfatal=.true._c_bool )
229
230 allocate( fwater_body_recharge( count( is_cell_active ) ), stat=status )
231 call assert( status==0, "Problem allocating memory", __file__, __line__ )
232
233 do indx=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
234 fwater_body_recharge( indx ) = fwater_body_recharge_table( landuse_index( indx ) )
235 enddo
236
237 endif
238
239
240 if ( associated( pwater_main ) ) then
241
242 allocate( fwater_main( count( is_cell_active ) ), stat=status )
243 call assert( status==0, "Problem allocating memory", __file__, __line__ )
244
245 elseif ( fwater_main_table(1) > ftinyval ) then
246
247 are_lengths_equal = ( ( ubound(fwater_main_table,1) == ubound(landuse_codes,1) ) )
248
249 if ( .not. are_lengths_equal ) &
250 call warn( smessage="The number of landuses does not match the number of water main leakage values.", &
251 smodule=__file__, iline=__line__, lfatal=.true._c_bool )
252
253 allocate( fwater_main( count( is_cell_active ) ), stat=status )
254 call assert( status==0, "Problem allocating memory", __file__, __line__ )
255
256 do indx=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
257 fwater_main( indx ) = fwater_main_table( landuse_index( indx ) )
258 enddo
259
260 endif
261
262
263 if ( associated( pdisposal_well ) ) then
264
265 allocate( fdisposal_well( count( is_cell_active ) ), stat=status )
266 call assert( status==0, "Problem allocating memory", __file__, __line__ )
267
268 elseif ( fdisposal_well_table(1) > ftinyval ) then
269
270 are_lengths_equal = ( ( ubound(fdisposal_well_table,1) == ubound(landuse_codes,1) ) )
271
272 if ( .not. are_lengths_equal ) &
273 call warn( smessage="The number of landuses does not match the number of discharge well values.", &
274 smodule=__file__, iline=__line__, lfatal=.true._c_bool )
275
276 allocate( fdisposal_well( count( is_cell_active ) ), stat=status )
277 call assert( status==0, "Problem allocating memory", __file__, __line__ )
278
279 do indx=lbound( landuse_index, 1 ), ubound( landuse_index, 1 )
280 fdisposal_well( indx ) = fdisposal_well_table( landuse_index( indx ) )
281 enddo
282
283 endif
284
285 ! initialize last retrieval date to something implausibly low to trigger initial read
286 ! in the calculate procedure
287 call date_of_last_retrieval%parseDate("01/01/1000", __file__, __line__)
288
290
291!--------------------------------------------------------------------------------------------------
292
293 subroutine direct_net_infiltration_calculate( direct_net_infiltration, indx, is_cell_active, nodata_fill_value )
294
295 real (c_float), intent(inout) :: direct_net_infiltration
296 integer (c_int), intent(in) :: indx
297 logical (c_bool), intent(in) :: is_cell_active(:,:)
298 real (c_float), intent(in) :: nodata_fill_value(:,:)
299
300 ! [ LOCALS ]
301
302 if ( .not. date_of_last_retrieval == sim_dt%curr ) then
303
304 associate( dt => sim_dt%curr )
305
306 if ( associated( pcesspool ) ) then
307 call pcesspool%getvalues( dt )
308 if ( pcesspool%lGridHasChanged ) fcesspool = pack( pcesspool%pGrdBase%rData, is_cell_active )
309 endif
310
311 if ( associated( pdisposal_well ) ) then
312 call pdisposal_well%getvalues( dt )
313 if ( pdisposal_well%lGridHasChanged ) fdisposal_well = &
314 pack( pdisposal_well%pGrdBase%rData, is_cell_active )
315 endif
316
317 ! if ( associated( pSTORM_DRAIN ) ) then
318 ! call pSTORM_DRAIN%getvalues( iMonth, iDay, iYear, iJulianDay )
319 ! if ( pSTORM_DRAIN%lGridHasChanged ) fSTORM_DRAIN = pack( pSTORM_DRAIN%pGrdBase%rData, is_cell_active )
320 ! endif
321
322 if ( associated( pwater_body_recharge ) ) then
323 call pwater_body_recharge%getvalues( dt )
324 if ( pwater_body_recharge%lGridHasChanged ) fwater_body_recharge = &
325 pack( pwater_body_recharge%pGrdBase%rData, is_cell_active )
326 endif
327
328 if ( associated( pwater_main ) ) then
329 call pwater_main%getvalues( dt )
330 if ( pwater_main%lGridHasChanged ) fwater_main = pack( pwater_main%pGrdBase%rData, is_cell_active )
331 endif
332
333 if ( associated( pannual_recharge_rate ) ) then
334 call pannual_recharge_rate%getvalues( dt )
335 if ( pannual_recharge_rate%lGridHasChanged ) fannual_recharge_rate = &
336 pack( pannual_recharge_rate%pGrdBase%rData, is_cell_active )
337 endif
338
340
341 end associate
342
343 endif
344
345 direct_net_infiltration = 0.0_c_float
346
347 if ( allocated( fcesspool ) ) &
348 direct_net_infiltration = direct_net_infiltration + fcesspool( indx )
349
350 if ( allocated( fdisposal_well ) ) &
351 direct_net_infiltration = direct_net_infiltration + fdisposal_well( indx )
352
353 if ( allocated( fwater_main ) ) &
354 direct_net_infiltration = direct_net_infiltration + fwater_main( indx )
355
356 if ( allocated( fwater_body_recharge ) ) &
357 direct_net_infiltration = direct_net_infiltration + fwater_body_recharge( indx )
358
359! if ( allocated( fSTORM_DRAIN ) ) direct_net_infiltration = direct_net_infiltration + fSTORM_DRAIN( indx )
360
361 if ( allocated( fannual_recharge_rate) ) &
362 direct_net_infiltration = direct_net_infiltration + fannual_recharge_rate( indx ) / 365.25_c_float
363
365
This module contains physical constants and convenience functions aimed at performing unit conversion...
logical(c_bool), parameter, public true
Defines the DATA_CATALOG_T data type, which contains type-bound procedures to add,...
type(data_catalog_t), public dat
DAT is a global to hold data catalog entries.
This module contains the DATETIME_T class and associated time and date-related routines,...
Definition datetime.F90:9
Module direct_net_infiltration__gridded_data provides support for adding miscellaneous source and sin...
real(c_float), dimension(:), allocatable fwater_body_recharge
real(c_float), dimension(:), allocatable fdisposal_well_table
real(c_float), dimension(:), allocatable fdisposal_well
real(c_float), dimension(:), allocatable fwater_main_table
real(c_float), dimension(:), allocatable fwater_body_recharge_table
subroutine, public direct_net_infiltration_calculate(direct_net_infiltration, indx, is_cell_active, nodata_fill_value)
real(c_float), dimension(:), allocatable fannual_recharge_rate_table
real(c_float), dimension(:), allocatable fwater_main
real(c_float), dimension(:), allocatable fcesspool_table
real(c_float), dimension(:), allocatable fannual_recharge_rate
subroutine, public direct_net_infiltration_initialize(is_cell_active, landuse_index)
Initialize the routine to enable input/output of arbitrary sources/sink terms.
subroutine, public warn(smessage, smodule, iline, shints, lfatal, iloglevel, lecho)
Provide support for use of netCDF files as input for time-varying, gridded meteorlogic data,...
type(parameters_t), public params
type(date_range_t), public sim_dt