MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
Mf6FileLayerArray.f90
Go to the documentation of this file.
1!> @brief This module contains the LayerArrayLoadModule
2!!
3!! This module contains the routines for reading period block
4!! array based input that is associated with a layer and an
5!! layer index array, such as with the EVTA and RCHA packages.
6!!
7!<
9
10 use kindmodule, only: i4b, dp, lgp
13 use simvariablesmodule, only: errmsg
25
26 implicit none
27 private
28 public :: layerarrayloadtype
29
30 !> @brief Ascii array layer dynamic loader type
31 !<
33 integer(I4B) :: tas_active !< Are TAS6 inputs defined
34 type(characterstringtype), dimension(:), contiguous, &
35 pointer :: aux_tasnames !< array of AUXVAR TAS names
36 type(characterstringtype), dimension(:), contiguous, &
37 pointer :: param_tasnames !< array of dynamic param TAS names
38 type(readstatevartype), dimension(:), allocatable :: param_reads !< read states for current load
39 integer(I4B), dimension(:), pointer, contiguous :: aux_reads => null() !< read state of each auxiliary variable
40 type(timearrayseriesmanagertype), pointer :: tasmanager !< TAS manager
41 type(loadcontexttype) :: ctx
42 contains
43 procedure :: ainit
44 procedure :: df
45 procedure :: ts_advance
46 procedure :: rp
47 procedure :: destroy
48 procedure :: reset
49 procedure :: init_charstr1d
50 procedure :: params_alloc
51 procedure :: param_load
52 procedure :: tas_arrays_alloc
53 procedure :: tas_links_create
54 end type layerarrayloadtype
55
56contains
57
58 subroutine ainit(this, mf6_input, component_name, &
59 component_input_name, input_name, &
60 iperblock, parser, iout)
65 class(layerarrayloadtype), intent(inout) :: this
66 type(modflowinputtype), intent(in) :: mf6_input
67 character(len=*), intent(in) :: component_name
68 character(len=*), intent(in) :: component_input_name
69 character(len=*), intent(in) :: input_name
70 integer(I4B), intent(in) :: iperblock
71 type(blockparsertype), pointer, intent(inout) :: parser
72 integer(I4B), intent(in) :: iout
73 type(loadmf6filetype) :: loader
74 type(characterstringtype), dimension(:), pointer, &
75 contiguous :: tas_fnames
76 type(inputparamdefinitiontype), pointer :: idt
77 integer(I4B), dimension(:), pointer, contiguous :: int1d
78 character(len=LINELENGTH) :: fname
79 integer(I4B) :: tas6_size, n
80
81 ! initialize base type
82 call this%DynamicPkgLoadType%init(mf6_input, component_name, &
83 component_input_name, &
84 input_name, iperblock, iout)
85 ! initialize
86 nullify (this%aux_tasnames)
87 nullify (this%param_tasnames)
88 this%tas_active = 0
89 this%iout = iout
90
91 ! load static input
92 call loader%load(parser, mf6_input, this%nc_vars, this%input_name, iout)
93
94 ! create tasmanager
95 allocate (this%tasmanager)
96 call tasmanager_cr(this%tasmanager, modelname=this%mf6_input%component_name, &
97 iout=this%iout)
98
99 ! determine if TAS6 files were provided in OPTIONS block
100 call get_isize('TAS6_FILENAME', this%mf6_input%mempath, tas6_size)
101 if (tas6_size > 0) then
102 this%tas_active = 1
103 call mem_setptr(tas_fnames, 'TAS6_FILENAME', this%mf6_input%mempath)
104 ! add files to tasmanager
105 do n = 1, size(tas_fnames)
106 fname = tas_fnames(n)
107 call this%tasmanager%add_tasfile(fname)
108 end do
109 end if
110
111 ! initialize input context memory
112 call this%ctx%init(mf6_input)
113
114 ! allocate dfn params
115 call this%params_alloc()
116
117 ! allocate memory for storing TAS strings
118 call this%tas_arrays_alloc()
119
120 ! layer index variable (e.g. IRCH, IEVT) is 1 until it is specified
121 if (this%param_names(1) == &
122 'I'//trim(this%mf6_input%subcomponent_type(1:3))) then
123 idt => get_param_definition_type(this%mf6_input%param_dfns, &
124 this%mf6_input%component_type, &
125 this%mf6_input%subcomponent_type, &
126 'PERIOD', this%param_names(1), &
127 this%input_name)
128 call mem_setptr(int1d, idt%mf6varname, this%mf6_input%mempath)
129 int1d = 1
130 end if
131 end subroutine ainit
132
133 subroutine df(this)
134 class(layerarrayloadtype), intent(inout) :: this
135 call this%tasmanager%tasmanager_df()
136 end subroutine df
137
138 subroutine ts_advance(this)
139 class(layerarrayloadtype), intent(inout) :: this
140 call this%tasmanager%ad()
141 end subroutine ts_advance
142
143 subroutine rp(this, parser)
148 use arrayhandlersmodule, only: ifind
151 class(layerarrayloadtype), intent(inout) :: this
152 type(blockparsertype), pointer, intent(inout) :: parser
153 logical(LGP) :: endOfBlock, netcdf
154 character(len=LINELENGTH) :: keyword, param_tag
155 type(inputparamdefinitiontype), pointer :: idt
156 integer(I4B) :: iaux, iparam
157 character(len=LENTIMESERIESNAME) :: tas_name
158
159 ! reset for this period
160 call this%reset()
161
162 ! log lst file header
163 call idm_log_header(this%mf6_input%component_name, &
164 this%mf6_input%subcomponent_name, this%iout)
165
166 ! read array block
167 do
168 ! initialize
169 iaux = 0
170 netcdf = .false.
171
172 ! read next line
173 call parser%GetNextLine(endofblock)
174 if (endofblock) exit
175 ! read param_tag
176 call parser%GetStringCaps(param_tag)
177
178 ! is param tag an auxvar?
179 iaux = ifind_charstr(this%ctx%auxname_cst, param_tag)
180 ! any auvxar corresponds to the definition tag 'AUX'
181 if (iaux > 0) param_tag = 'AUX'
182
183 ! set input definition
184 idt => get_param_definition_type(this%mf6_input%param_dfns, &
185 this%mf6_input%component_type, &
186 this%mf6_input%subcomponent_type, &
187 'PERIOD', param_tag, this%input_name)
188 ! look for TAS and NetCDF keywords
189 call parser%GetStringCaps(keyword)
190 if (keyword == 'TIMEARRAYSERIES') then
191 if (this%tas_active /= 0) then
192 call parser%GetStringCaps(tas_name)
193 if (param_tag == 'AUX') then
194 this%aux_tasnames(iaux) = tas_name
195 this%aux_reads(iaux) = rs_series
196 else
197 iparam = ifind(this%param_names, param_tag)
198 this%param_tasnames(iparam) = tas_name
199 this%param_reads(iparam)%invar = rs_series
200 end if
201 ! log variable
202 call idm_log_var(param_tag, this%mf6_input%mempath, this%iout, .true., &
203 trim(tas_name))
204 ! cycle to next input param
205 cycle
206 else
207 ! TODO: throw error
208 end if
209 else if (keyword == 'NETCDF') then
210 netcdf = .true.
211 end if
212
213 ! read and load the parameter
214 call this%param_load(parser, idt, this%mf6_input%mempath, netcdf, iaux)
215 end do
216
217 if (this%tas_active /= 0) then
218 call this%tas_links_create(parser%iuactive)
219 end if
220
221 ! log lst file header
222 call idm_log_close(this%mf6_input%component_name, &
223 this%mf6_input%subcomponent_name, this%iout)
224 end subroutine rp
225
226 subroutine destroy(this)
227 class(layerarrayloadtype), intent(inout) :: this
228 !
229 ! nullify ctx pointers (including mshape) before deallocate
230 call this%ctx%destroy()
231 !
232 ! deallocate tasmanager
233 call this%tasmanager%da()
234 deallocate (this%tasmanager)
235 nullify (this%tasmanager)
236 end subroutine destroy
237
238 subroutine reset(this)
239 class(layerarrayloadtype), intent(inout) :: this
240 integer(I4B) :: n
241
242 if (this%tas_active /= 0) then
243 ! reset tasmanager
244 call this%tasmanager%reset(this%mf6_input%subcomponent_name)
245 ! reinitialize tas name arrays
246 call this%init_charstr1d('AUXTASNAME', this%input_name)
247 call this%init_charstr1d('PARAMTASNAME', this%input_name)
248 end if
249
250 do n = 1, this%nparam
251 ! reset read state
252 this%param_reads(n)%invar = rs_none
253 end do
254 this%aux_reads = rs_none
255
256 end subroutine reset
257
258 subroutine init_charstr1d(this, varname, input_name)
260 class(layerarrayloadtype) :: this
261 character(len=*), intent(in) :: varname
262 character(len=*), intent(in) :: input_name
263 type(characterstringtype), dimension(:), pointer, &
264 contiguous :: charstr1d
265 integer(I4B) :: n
266 call mem_setptr(charstr1d, varname, this%mf6_input%mempath)
267 do n = 1, size(charstr1d)
268 charstr1d(n) = ''
269 end do
270 end subroutine init_charstr1d
271
272 subroutine params_alloc(this)
273 class(layerarrayloadtype), intent(inout) :: this
274 character(len=LENVARNAME) :: rs_varname
275 integer(I4B), pointer :: intvar
276 integer(I4B) :: iparam
277
278 ! set in-scope param names directly from context
279 this%param_names = this%ctx%params
280 this%nparam = size(this%ctx%params)
281 call this%ctx%allocate_params()
282 call this%ctx%check_developmode(this%input_name)
283 call this%ctx%allocate_arrays()
284
285 ! allocate and set param_reads pointer array
286 allocate (this%param_reads(this%nparam))
287
288 ! store read state variable pointers
289 do iparam = 1, this%nparam
290 ! allocate and store name of read state variable
291 rs_varname = this%ctx%rsv_alloc(this%param_names(iparam))
292 call mem_setptr(intvar, rs_varname, this%mf6_input%mempath)
293 this%param_reads(iparam)%invar => intvar
294 this%param_reads(iparam)%invar = rs_none
295 end do
296
297 ! read state of each auxiliary variable
298 call mem_allocate(this%aux_reads, this%ctx%naux, 'INAUXVARS', &
299 this%mf6_input%mempath)
300 this%aux_reads = rs_none
301 end subroutine params_alloc
302
303 subroutine param_load(this, parser, idt, mempath, netcdf, iaux)
304 use tdismodule, only: kper
306 use arrayhandlersmodule, only: ifind
314 class(layerarrayloadtype), intent(inout) :: this
315 type(blockparsertype), intent(in) :: parser
316 type(inputparamdefinitiontype), intent(in) :: idt
317 character(len=*), intent(in) :: mempath
318 logical(LGP), intent(in) :: netcdf
319 integer(I4B), intent(in) :: iaux
320 integer(I4B), dimension(:), pointer, contiguous :: int1d
321 real(DP), dimension(:), pointer, contiguous :: dbl1d
322 real(DP), dimension(:, :), pointer, contiguous :: dbl2d
323 integer(I4B) :: iparam, n
324
325 select case (idt%datatype)
326 case ('INTEGER1D')
327 call mem_setptr(int1d, idt%mf6varname, mempath)
328 if (netcdf) then
329 call netcdf_read_array(int1d, this%ctx%mshape, idt, &
330 this%mf6_input, this%nc_vars, this%input_name, &
331 this%iout, kper)
332 else
333 call read_int1d(parser, int1d, idt%mf6varname)
334 end if
335 call idm_log_var(int1d, idt%tagname, mempath, this%iout)
336 case ('DOUBLE1D')
337 call mem_setptr(dbl1d, idt%mf6varname, mempath)
338 if (netcdf) then
339 call netcdf_read_array(dbl1d, this%ctx%mshape, idt, &
340 this%mf6_input, this%nc_vars, this%input_name, &
341 this%iout, kper)
342 else
343 call read_dbl1d(parser, dbl1d, idt%mf6varname)
344 end if
345 call idm_log_var(dbl1d, idt%tagname, mempath, this%iout)
346 case ('DOUBLE2D')
347 call mem_setptr(dbl2d, idt%mf6varname, mempath)
348 allocate (dbl1d(this%ctx%ncpl))
349 if (netcdf) then
350 call netcdf_read_array(dbl1d, this%ctx%mshape, idt, &
351 this%mf6_input, this%nc_vars, this%input_name, &
352 this%iout, kper, iaux)
353 else
354 call read_dbl1d(parser, dbl1d, idt%mf6varname)
355 end if
356 do n = 1, this%ctx%ncpl
357 dbl2d(iaux, n) = dbl1d(n)
358 end do
359 call idm_log_var(dbl1d, idt%tagname, mempath, this%iout)
360 deallocate (dbl1d)
361 this%aux_reads(iaux) = merge(rs_netcdf, rs_values, netcdf)
362 case default
363 errmsg = 'IDM unimplemented. LayerArrayLoad::param_load &
364 &datatype='//trim(idt%datatype)
365 call store_error(errmsg)
366 call store_error_filename(this%input_name)
367 end select
368
369 ! if param is tracked set read state
370 iparam = ifind(this%param_names, idt%tagname)
371 if (iparam > 0) then
372 this%param_reads(iparam)%invar = merge(rs_netcdf, rs_values, netcdf)
373 end if
374 end subroutine param_load
375
376 subroutine tas_arrays_alloc(this)
378 class(layerarrayloadtype), intent(inout) :: this
379
380 ! count params other than AUX
381 if (this%tas_active /= 0) then
382 call mem_allocate(this%aux_tasnames, lentimeseriesname, &
383 this%ctx%naux, 'AUXTASNAME', &
384 this%mf6_input%mempath)
385 call mem_allocate(this%param_tasnames, lentimeseriesname, this%nparam, &
386 'PARAMTASNAME', this%mf6_input%mempath)
387 call this%init_charstr1d('AUXTASNAME', this%input_name)
388 call this%init_charstr1d('PARAMTASNAME', this%input_name)
389 else
390 call mem_allocate(this%aux_tasnames, lentimeseriesname, 0, &
391 'AUXTASNAME', this%mf6_input%mempath)
392 call mem_allocate(this%param_tasnames, lentimeseriesname, 0, &
393 'PARAMTASNAME', this%mf6_input%mempath)
394 end if
395 end subroutine tas_arrays_alloc
396
397 ! FLUX and SFAC are handled in model context
398 subroutine tas_links_create(this, inunit)
401 class(layerarrayloadtype), intent(inout) :: this
402 integer(I4B), intent(in) :: inunit
403 type(inputparamdefinitiontype), pointer :: idt
404 ! non-contiguous because a slice of bound is passed
405 real(DP), dimension(:), pointer :: auxArrayPtr, bndArrayPtr
406 real(DP), dimension(:), pointer, contiguous :: bound
407 integer(I4B), dimension(:), pointer, contiguous :: nodelist
408 character(len=LENTIMESERIESNAME) :: tas_name
409 character(len=LENAUXNAME) :: aux_name
410 logical :: convertFlux
411 integer(I4B) :: n
412
413 ! initialize
414 nullify (auxarrayptr)
415 nullify (bndarrayptr)
416 nullify (nodelist)
417 convertflux = .false.
418
419 ! Create AUX Time Array Series links
420 do n = 1, this%ctx%naux
421 tas_name = this%aux_tasnames(n)
422 if (tas_name /= '') then
423 ! set auxvar pointer
424 auxarrayptr => this%ctx%auxvar(n, :)
425 aux_name = this%ctx%auxname_cst(n)
426 call this%tasmanager%MakeTasLink(this%mf6_input%subcomponent_name, &
427 auxarrayptr, this%ctx%iprpak, &
428 tas_name, aux_name, convertflux, &
429 nodelist, inunit)
430 end if
431 end do
432
433 ! Create BND Time Array Series links
434 do n = 1, this%nparam
435 ! assign param definition pointer
436 idt => get_param_definition_type(this%mf6_input%param_dfns, &
437 this%mf6_input%component_type, &
438 this%mf6_input%subcomponent_type, &
439 'PERIOD', this%param_names(n), &
440 this%input_name)
441 if (idt%timeseries) then
442 if (this%param_reads(n)%invar == rs_series) then
443 tas_name = this%param_tasnames(n)
444 call mem_setptr(bound, idt%mf6varname, this%mf6_input%mempath)
445 ! set bound pointer
446 bndarrayptr => bound(:)
447 call this%tasmanager%MakeTasLink(this%mf6_input%subcomponent_name, &
448 bndarrayptr, &
449 this%ctx%iprpak, &
450 tas_name, idt%mf6varname, &
451 convertflux, nodelist, inunit)
452 end if
453 end if
454 end do
455 end subroutine tas_links_create
456
457end module layerarrayloadmodule
This module contains the AsciiInputLoadTypeModule.
This module contains block parser methods.
subroutine destroy(this)
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition Constants.f90:45
integer(i4b), parameter lentimeseriesname
maximum length of a time series name
Definition Constants.f90:42
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition Constants.f90:17
integer(i4b), parameter lenauxname
maximum length of a aux variable
Definition Constants.f90:35
integer(i4b), parameter izero
integer constant zero
Definition Constants.f90:51
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65
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)
subroutine, public read_dbl2d(parser, dbl2d, aname)
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.
subroutine, public read_int1d(parser, int1d, aname)
This module defines variable data types.
Definition kind.f90:8
This module contains the LayerArrayLoadModule.
subroutine param_load(this, parser, idt, mempath, netcdf, iaux)
subroutine ts_advance(this)
subroutine tas_arrays_alloc(this)
subroutine tas_links_create(this, inunit)
subroutine ainit(this, mf6_input, component_name, component_input_name, input_name, iperblock, parser, iout)
subroutine rp(this, parser)
subroutine init_charstr1d(this, varname, input_name)
subroutine params_alloc(this)
Load context for IDM generic dynamic loaders.
@ rs_series
time-array series given in the most recent period block
@ 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
This module contains the LoadMf6FileModule.
This module contains the LoadNCInputModule.
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
This module contains the SourceCommonModule.
integer(i4b) function, public ifind_charstr(array, str)
integer(i4b), pointer, public kper
current stress period number
Definition tdis.f90:26
subroutine, public tasmanager_cr(this, dis, modelname, iout)
Create the time-array series manager.
base abstract type for ascii source dynamic load
This class is used to store a single deferred-length character string. It was designed to work in an ...
Input parameter definition. Describes an input parameter.
Ascii array layer dynamic loader type.
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