MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
Mf6FileGridArray.f90
Go to the documentation of this file.
1!> @brief This module contains the GridArrayLoadModule
2!!
3!! This module contains the routines for reading period block
4!! grid array-based input for stress packages that use the
5!! READARRAYGRID option (CHD, WEL, DRN, RIV, GHB).
6!!
7!<
9
10 use kindmodule, only: i4b, dp, lgp
12 use simvariablesmodule, only: errmsg
21
22 implicit none
23 private
24 public :: gridarrayloadtype
25
26 !> @brief Ascii grid based dynamic loader type
27 !<
29 type(readstatevartype), dimension(:), allocatable :: param_reads !< read states for current load
30 type(loadcontexttype) :: ctx
31 integer(I4B), dimension(:), pointer, contiguous :: nodeulist
32 logical(LGP), dimension(:), allocatable :: active !< user node IDOMAIN > 0
33 logical(LGP) :: nodeulist_set = .false. !< nodeulist set in this block
34 integer(I4B), dimension(:), pointer, contiguous :: aux_reads => null() !< read state of each auxiliary variable
35 contains
36 procedure :: ainit
37 procedure :: df
38 procedure :: ts_advance
39 procedure :: rp
40 procedure :: destroy
41 procedure :: reset
42 procedure :: params_alloc
43 procedure :: param_load
44 procedure :: set_active
45 end type gridarrayloadtype
46
47contains
48
49 subroutine ainit(this, mf6_input, component_name, &
50 component_input_name, input_name, &
51 iperblock, parser, iout)
55 class(gridarrayloadtype), intent(inout) :: this
56 type(modflowinputtype), intent(in) :: mf6_input
57 character(len=*), intent(in) :: component_name
58 character(len=*), intent(in) :: component_input_name
59 character(len=*), intent(in) :: input_name
60 integer(I4B), intent(in) :: iperblock
61 type(blockparsertype), pointer, intent(inout) :: parser
62 integer(I4B), intent(in) :: iout
63 type(loadmf6filetype) :: loader
64 integer(I4B) :: isize
65 integer(I4B), pointer :: maxbound
66
67 ! initialize base type
68 call this%DynamicPkgLoadType%init(mf6_input, component_name, &
69 component_input_name, &
70 input_name, iperblock, iout)
71 ! initialize
72 this%iout = iout
73
74 ! load static input
75 call loader%load(parser, mf6_input, this%nc_vars, this%input_name, iout)
76
77 ! maxbound is optional
78 call get_isize('MAXBOUND', mf6_input%mempath, isize)
79 if (isize < 0) then
80 ! set maxbound to grid nodes
81 call mem_allocate(maxbound, 'MAXBOUND', mf6_input%mempath)
82 maxbound = product(loader%mshape)
83 end if
84
85 ! initialize input context memory
86 call this%ctx%init(mf6_input)
87
88 ! set active user nodes
89 call this%set_active()
90
91 ! allocate user nodelist
92 call mem_allocate(this%nodeulist, this%ctx%maxbound, &
93 'NODEULIST', mf6_input%mempath)
94
95 ! allocate dfn params
96 call this%params_alloc()
97 end subroutine ainit
98
99 subroutine df(this)
100 class(gridarrayloadtype), intent(inout) :: this
101 end subroutine df
102
103 subroutine ts_advance(this)
104 class(gridarrayloadtype), intent(inout) :: this
105 end subroutine ts_advance
106
107 subroutine rp(this, parser)
111 use arrayhandlersmodule, only: ifind
114 class(gridarrayloadtype), intent(inout) :: this
115 type(blockparsertype), pointer, intent(inout) :: parser
116 logical(LGP) :: endOfBlock, netcdf, layered
117 character(len=LINELENGTH) :: keyword, param_tag
118 type(inputparamdefinitiontype), pointer :: idt
119 integer(I4B) :: iaux
120
121 ! reset for this period
122 call this%reset()
123
124 ! log lst file header
125 call idm_log_header(this%mf6_input%component_name, &
126 this%mf6_input%subcomponent_name, this%iout)
127
128 ! read array block
129 do
130 ! initialize
131 iaux = 0
132 netcdf = .false.
133 layered = .false.
134
135 ! read next line
136 call parser%GetNextLine(endofblock)
137 if (endofblock) exit
138 ! read param_tag
139 call parser%GetStringCaps(param_tag)
140
141 ! is param tag an auxvar?
142 iaux = ifind_charstr(this%ctx%auxname_cst, param_tag)
143
144 ! any auxvar corresponds to the definition tag 'AUX'
145 if (iaux > 0) param_tag = 'AUX'
146
147 ! set input definition
148 idt => get_param_definition_type(this%mf6_input%param_dfns, &
149 this%mf6_input%component_type, &
150 this%mf6_input%subcomponent_type, &
151 'PERIOD', param_tag, this%input_name)
152 ! look for Layered and NetCDF keywords
153 call parser%GetStringCaps(keyword)
154 if (keyword == 'LAYERED' .and. idt%layered) then
155 layered = .true.
156 else if (keyword == 'NETCDF') then
157 netcdf = .true.
158 end if
159
160 ! read and load the parameter
161 call this%param_load(parser, idt, this%mf6_input%mempath, layered, &
162 netcdf, iaux)
163 end do
164
165 ! log lst file header
166 call idm_log_close(this%mf6_input%component_name, &
167 this%mf6_input%subcomponent_name, this%iout)
168 end subroutine rp
169
170 subroutine destroy(this)
172 class(gridarrayloadtype), intent(inout) :: this
173 call mem_deallocate(this%nodeulist)
174 if (allocated(this%active)) deallocate (this%active)
175 end subroutine destroy
176
177 !> @brief Set active user nodes from discretization IDOMAIN input
178 !!
179 !! Cells with IDOMAIN less than one are not boundaries. All cells are
180 !! active if IDOMAIN is not given.
181 !<
182 subroutine set_active(this)
187 class(gridarrayloadtype), intent(inout) :: this
188 character(len=LENMEMPATH) :: model_mempath, dis_mempath
189 integer(I4B), pointer :: disenum
190 integer(I4B), dimension(:), pointer, contiguous :: int1d
191 integer(I4B), dimension(:, :), pointer, contiguous :: int2d
192 integer(I4B), dimension(:, :, :), pointer, contiguous :: int3d
193 integer(I4B) :: isize
194
195 allocate (this%active(this%ctx%nodes))
196 this%active = .true.
197
198 ! set discretization input mempath
199 model_mempath = create_mem_path(component=this%mf6_input%component_name, &
200 context=idm_context)
201 call mem_setptr(disenum, 'DISENUM', model_mempath)
202 select case (disenum)
203 case (dis)
204 dis_mempath = create_mem_path(this%mf6_input%component_name, 'DIS', &
206 case (disv)
207 dis_mempath = create_mem_path(this%mf6_input%component_name, 'DISV', &
209 case (disu)
210 dis_mempath = create_mem_path(this%mf6_input%component_name, 'DISU', &
212 case default
213 return
214 end select
215
216 ! IDOMAIN is optional; read before the discretization package
217 ! releases its input
218 call get_isize('IDOMAIN', dis_mempath, isize)
219 if (isize /= this%ctx%nodes) return
220
221 select case (disenum)
222 case (dis)
223 call mem_setptr(int3d, 'IDOMAIN', dis_mempath)
224 this%active = reshape(int3d, [this%ctx%nodes]) > 0
225 case (disv)
226 call mem_setptr(int2d, 'IDOMAIN', dis_mempath)
227 this%active = reshape(int2d, [this%ctx%nodes]) > 0
228 case (disu)
229 call mem_setptr(int1d, 'IDOMAIN', dis_mempath)
230 this%active = int1d > 0
231 end select
232 end subroutine set_active
233
234 subroutine reset(this)
235 class(gridarrayloadtype), intent(inout) :: this
236 integer(I4B) :: n
237
238 this%ctx%nbound = 0
239 this%nodeulist_set = .false.
240
241 do n = 1, this%nparam
242 ! reset read state
243 this%param_reads(n)%invar = rs_none
244 end do
245 this%aux_reads = rs_none
246 end subroutine reset
247
248 subroutine params_alloc(this)
249 class(gridarrayloadtype), intent(inout) :: this
250 character(len=LENVARNAME) :: rs_varname
251 integer(I4B), pointer :: intvar
252 integer(I4B) :: iparam
253
254 ! set in-scope param names directly from context
255 this%param_names = this%ctx%params
256 this%nparam = size(this%ctx%params)
257 call this%ctx%allocate_params()
258 call this%ctx%check_developmode(this%input_name)
259 call this%ctx%allocate_arrays()
260
261 ! allocate and set param_reads pointer array
262 allocate (this%param_reads(this%nparam))
263
264 ! store read state variable pointers
265 do iparam = 1, this%nparam
266 ! allocate and store name of read state variable
267 rs_varname = this%ctx%rsv_alloc(this%param_names(iparam))
268 call mem_setptr(intvar, rs_varname, this%mf6_input%mempath)
269 this%param_reads(iparam)%invar => intvar
270 this%param_reads(iparam)%invar = rs_none
271 end do
272
273 ! read state of each auxiliary variable
274 call mem_allocate(this%aux_reads, this%ctx%naux, 'INAUXVARS', &
275 this%mf6_input%mempath)
276 this%aux_reads = rs_none
277 end subroutine params_alloc
278
279 subroutine param_load(this, parser, idt, mempath, layered, netcdf, iaux)
280 use tdismodule, only: kper
281 use constantsmodule, only: dnodata
282 use arrayhandlersmodule, only: ifind
289 class(gridarrayloadtype), intent(inout) :: this
290 type(blockparsertype), intent(in) :: parser
291 type(inputparamdefinitiontype), intent(in) :: idt
292 character(len=*), intent(in) :: mempath
293 logical(LGP), intent(in) :: layered
294 logical(LGP), intent(in) :: netcdf
295 integer(I4B), intent(in) :: iaux
296 real(DP), dimension(:), pointer, contiguous :: dbl1d, nodes
297 real(DP), dimension(:, :), pointer, contiguous :: dbl2d
298 integer(I4B), dimension(:), allocatable :: layer_shape
299 integer(I4B) :: iparam, n, nlay, nnode
300
301 nnode = 0
302
303 select case (idt%datatype)
304 case ('DOUBLE1D')
305 call mem_setptr(dbl1d, idt%mf6varname, mempath)
306 allocate (nodes(this%ctx%nodes))
307 if (netcdf) then
308 call netcdf_read_array(nodes, this%ctx%mshape, idt, &
309 this%mf6_input, this%nc_vars, this%input_name, &
310 this%iout, kper)
311 else if (layered) then
312 call get_layered_shape(this%ctx%mshape, nlay, layer_shape)
313 call read_dbl1d_layered(parser, nodes, idt%mf6varname, nlay, layer_shape)
314 else
315 call read_dbl1d(parser, nodes, idt%mf6varname)
316 end if
317
318 call idm_log_var(nodes, idt%tagname, mempath, this%iout)
319
320 if (this%nodeulist_set) then
321 ! nodeulist already established: extract values at known positions
322 do n = 1, this%ctx%nbound
323 dbl1d(n) = nodes(this%nodeulist(n))
324 end do
325 else
326 ! first array sets nodeulist and nbound (defined, active cells)
327 do n = 1, this%ctx%nodes
328 if (nodes(n) /= dnodata .and. this%active(n)) then
329 nnode = nnode + 1
330 if (nnode > this%ctx%maxbound) then
331 write (errmsg, '(a,i0,a)') &
332 'Input error: number of defined (non-DNODATA) active cells &
333 &exceeds MAXBOUND=', this%ctx%maxbound, '.'
334 call store_error(errmsg)
335 call store_error_filename(this%input_name)
336 end if
337 dbl1d(nnode) = nodes(n)
338 this%nodeulist(nnode) = n
339 end if
340 end do
341 this%ctx%nbound = nnode
342 this%nodeulist_set = .true.
343 end if
344 deallocate (nodes)
345 case ('DOUBLE2D')
346 call mem_setptr(dbl2d, idt%mf6varname, mempath)
347 allocate (nodes(this%ctx%nodes))
348
349 if (netcdf) then
350 call netcdf_read_array(nodes, this%ctx%mshape, idt, &
351 this%mf6_input, this%nc_vars, this%input_name, &
352 this%iout, kper, iaux)
353 else if (layered) then
354 call get_layered_shape(this%ctx%mshape, nlay, layer_shape)
355 call read_dbl1d_layered(parser, nodes, idt%mf6varname, nlay, layer_shape)
356 else
357 call read_dbl1d(parser, nodes, idt%mf6varname)
358 end if
359
360 call idm_log_var(nodes, idt%tagname, mempath, this%iout)
361
362 if (this%nodeulist_set) then
363 ! nodeulist already established: extract values at known positions
364 do n = 1, this%ctx%nbound
365 dbl2d(iaux, n) = nodes(this%nodeulist(n))
366 end do
367 else
368 ! first array sets nodeulist and nbound (defined, active cells)
369 do n = 1, this%ctx%nodes
370 if (nodes(n) /= dnodata .and. this%active(n)) then
371 nnode = nnode + 1
372 if (nnode > this%ctx%maxbound) then
373 write (errmsg, '(a,i0,a)') &
374 'Input error: number of defined (non-DNODATA) active cells &
375 &exceeds MAXBOUND=', this%ctx%maxbound, '.'
376 call store_error(errmsg)
377 call store_error_filename(this%input_name)
378 end if
379 dbl2d(iaux, nnode) = nodes(n)
380 this%nodeulist(nnode) = n
381 end if
382 end do
383 this%ctx%nbound = nnode
384 this%nodeulist_set = .true.
385 end if
386 deallocate (nodes)
387 this%aux_reads(iaux) = merge(rs_netcdf, rs_values, netcdf)
388 case default
389 errmsg = 'IDM unimplemented. GridArrayLoad::param_load &
390 &datatype='//trim(idt%datatype)
391 call store_error(errmsg)
392 call store_error_filename(this%input_name)
393 end select
394
395 ! if param is tracked set read state
396 iparam = ifind(this%param_names, idt%tagname)
397 if (iparam > 0) then
398 this%param_reads(iparam)%invar = merge(rs_netcdf, rs_values, netcdf)
399 end if
400 end subroutine param_load
401
402end module gridarrayloadmodule
This module contains the AsciiInputLoadTypeModule.
This module contains block parser methods.
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
real(dp), parameter dnodata
real no data constant
Definition Constants.f90:95
@ disu
DISV6 discretization.
@ dis
DIS6 discretization.
@ disv
DISU6 discretization.
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition Constants.f90:17
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition Constants.f90:27
This module contains the DefinitionSelectModule.
type(inputparamdefinitiontype) function, pointer, public get_param_definition_type(input_definition_types, component_type, subcomponent_type, blockname, tagname, filename, found)
Return parameter definition.
subroutine, public read_dbl1d(parser, dbl1d, aname)
This module contains the GridArrayLoadModule.
subroutine param_load(this, parser, idt, mempath, layered, netcdf, iaux)
subroutine rp(this, parser)
subroutine set_active(this)
Set active user nodes from discretization IDOMAIN input.
subroutine ts_advance(this)
subroutine ainit(this, mf6_input, component_name, component_input_name, input_name, iperblock, parser, iout)
subroutine params_alloc(this)
This module contains the Input Data Model Logger Module.
Definition IdmLogger.f90:7
subroutine, public idm_log_close(component, subcomponent, iout)
log the closing message
Definition IdmLogger.f90:56
subroutine, public idm_log_header(component, subcomponent, iout)
log a header message
Definition IdmLogger.f90:44
Input definition module.
This module defines variable data types.
Definition kind.f90:8
subroutine, public read_dbl1d_layered(parser, dbl1d, aname, nlay, layer_shape)
Load context for IDM generic dynamic loaders.
@ rs_netcdf
values read from NetCDF in the most recent period block
@ rs_values
values given in the most recent period block
@ rs_none
not given in the most recent period block
subroutine destroy(this)
destroy input context object
This module contains the LoadMf6FileModule.
This module contains the LoadNCInputModule.
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
subroutine, public get_isize(name, mem_path, isize)
Get the number of elements for this variable.
This module contains the ModflowInputModule.
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition Sim.f90:94
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition Sim.f90:208
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
character(len=linelength) idm_context
This module contains the SourceCommonModule.
subroutine, public get_layered_shape(mshape, nlay, layer_shape)
integer(i4b) function, public ifind_charstr(array, str)
integer(i4b), pointer, public kper
current stress period number
Definition tdis.f90:26
base abstract type for ascii source dynamic load
Ascii grid based dynamic loader type.
Input parameter definition. Describes an input parameter.
Input load context for generic dynamic loaders and StructArray based static loads....
Pointer type for read state variable.
Static parser based input loader.
derived type for storing input definition for a file