MODFLOW 6  version 6.9.0.dev0
USGS Modular Hydrologic Model
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
20 
21  implicit none
22  private
23  public :: gridarrayloadtype
24 
25  !> @brief Ascii grid based dynamic loader type
26  !<
28  type(readstatevartype), dimension(:), allocatable :: param_reads !< read states for current load
29  type(loadcontexttype) :: ctx
30  integer(I4B), dimension(:), pointer, contiguous :: nodeulist
31  contains
32  procedure :: ainit
33  procedure :: df
34  procedure :: ts_advance
35  procedure :: rp
36  procedure :: destroy
37  procedure :: reset
38  procedure :: params_alloc
39  procedure :: param_load
40  end type gridarrayloadtype
41 
42 contains
43 
44  subroutine ainit(this, mf6_input, component_name, &
45  component_input_name, input_name, &
46  iperblock, parser, iout)
50  class(gridarrayloadtype), intent(inout) :: this
51  type(modflowinputtype), intent(in) :: mf6_input
52  character(len=*), intent(in) :: component_name
53  character(len=*), intent(in) :: component_input_name
54  character(len=*), intent(in) :: input_name
55  integer(I4B), intent(in) :: iperblock
56  type(blockparsertype), pointer, intent(inout) :: parser
57  integer(I4B), intent(in) :: iout
58  type(loadmf6filetype) :: loader
59  integer(I4B) :: isize
60  integer(I4B), pointer :: maxbound
61 
62  ! initialize base type
63  call this%DynamicPkgLoadType%init(mf6_input, component_name, &
64  component_input_name, &
65  input_name, iperblock, iout)
66  ! initialize
67  this%iout = iout
68 
69  ! load static input
70  call loader%load(parser, mf6_input, this%nc_vars, this%input_name, iout)
71 
72  ! maxbound is optional
73  call get_isize('MAXBOUND', mf6_input%mempath, isize)
74  if (isize < 0) then
75  ! set maxbound to grid nodes
76  call mem_allocate(maxbound, 'MAXBOUND', mf6_input%mempath)
77  maxbound = product(loader%mshape)
78  end if
79 
80  ! initialize input context memory
81  call this%ctx%init(mf6_input)
82 
83  ! allocate user nodelist
84  call mem_allocate(this%nodeulist, this%ctx%maxbound, &
85  'NODEULIST', mf6_input%mempath)
86 
87  ! allocate dfn params
88  call this%params_alloc()
89  end subroutine ainit
90 
91  subroutine df(this)
92  class(gridarrayloadtype), intent(inout) :: this
93  end subroutine df
94 
95  subroutine ts_advance(this)
96  class(gridarrayloadtype), intent(inout) :: this
97  end subroutine ts_advance
98 
99  subroutine rp(this, parser)
103  use arrayhandlersmodule, only: ifind
106  class(gridarrayloadtype), intent(inout) :: this
107  type(blockparsertype), pointer, intent(inout) :: parser
108  logical(LGP) :: endOfBlock, netcdf, layered
109  character(len=LINELENGTH) :: keyword, param_tag
110  type(inputparamdefinitiontype), pointer :: idt
111  integer(I4B) :: iaux
112 
113  ! reset for this period
114  call this%reset()
115 
116  ! log lst file header
117  call idm_log_header(this%mf6_input%component_name, &
118  this%mf6_input%subcomponent_name, this%iout)
119 
120  ! read array block
121  do
122  ! initialize
123  iaux = 0
124  netcdf = .false.
125  layered = .false.
126 
127  ! read next line
128  call parser%GetNextLine(endofblock)
129  if (endofblock) exit
130  ! read param_tag
131  call parser%GetStringCaps(param_tag)
132 
133  ! is param tag an auxvar?
134  iaux = ifind_charstr(this%ctx%auxname_cst, param_tag)
135 
136  ! any auxvar corresponds to the definition tag 'AUX'
137  if (iaux > 0) param_tag = 'AUX'
138 
139  ! set input definition
140  idt => get_param_definition_type(this%mf6_input%param_dfns, &
141  this%mf6_input%component_type, &
142  this%mf6_input%subcomponent_type, &
143  'PERIOD', param_tag, this%input_name)
144  ! look for Layered and NetCDF keywords
145  call parser%GetStringCaps(keyword)
146  if (keyword == 'LAYERED' .and. idt%layered) then
147  layered = .true.
148  else if (keyword == 'NETCDF') then
149  netcdf = .true.
150  end if
151 
152  ! read and load the parameter
153  call this%param_load(parser, idt, this%mf6_input%mempath, layered, &
154  netcdf, iaux)
155  end do
156 
157  ! log lst file header
158  call idm_log_close(this%mf6_input%component_name, &
159  this%mf6_input%subcomponent_name, this%iout)
160  end subroutine rp
161 
162  subroutine destroy(this)
164  class(gridarrayloadtype), intent(inout) :: this
165  call mem_deallocate(this%nodeulist)
166  end subroutine destroy
167 
168  subroutine reset(this)
169  class(gridarrayloadtype), intent(inout) :: this
170  integer(I4B) :: n
171 
172  this%ctx%nbound = 0
173 
174  do n = 1, this%nparam
175  ! reset read state
176  this%param_reads(n)%invar = 0
177  end do
178  end subroutine reset
179 
180  subroutine params_alloc(this)
181  class(gridarrayloadtype), intent(inout) :: this
182  character(len=LENVARNAME) :: rs_varname
183  integer(I4B), pointer :: intvar
184  integer(I4B) :: iparam
185 
186  ! set in-scope param names directly from context
187  this%param_names = this%ctx%params
188  this%nparam = size(this%ctx%params)
189  call this%ctx%allocate_params()
190  call this%ctx%check_developmode(this%input_name)
191  call this%ctx%allocate_arrays()
192 
193  ! allocate and set param_reads pointer array
194  allocate (this%param_reads(this%nparam))
195 
196  ! store read state variable pointers
197  do iparam = 1, this%nparam
198  ! allocate and store name of read state variable
199  rs_varname = this%ctx%rsv_alloc(this%param_names(iparam))
200  call mem_setptr(intvar, rs_varname, this%mf6_input%mempath)
201  this%param_reads(iparam)%invar => intvar
202  this%param_reads(iparam)%invar = 0
203  end do
204  end subroutine params_alloc
205 
206  subroutine param_load(this, parser, idt, mempath, layered, netcdf, iaux)
207  use tdismodule, only: kper
208  use constantsmodule, only: dnodata
209  use arrayhandlersmodule, only: ifind
215  use idmloggermodule, only: idm_log_var
216  class(gridarrayloadtype), intent(inout) :: this
217  type(blockparsertype), intent(in) :: parser
218  type(inputparamdefinitiontype), intent(in) :: idt
219  character(len=*), intent(in) :: mempath
220  logical(LGP), intent(in) :: layered
221  logical(LGP), intent(in) :: netcdf
222  integer(I4B), intent(in) :: iaux
223  real(DP), dimension(:), pointer, contiguous :: dbl1d, nodes
224  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
225  integer(I4B), dimension(:), allocatable :: layer_shape
226  integer(I4B) :: iparam, n, nlay, nnode
227 
228  nnode = 0
229 
230  select case (idt%datatype)
231  case ('DOUBLE1D')
232  call mem_setptr(dbl1d, idt%mf6varname, mempath)
233  allocate (nodes(this%ctx%nodes))
234  if (netcdf) then
235  call netcdf_read_array(nodes, this%ctx%mshape, idt, &
236  this%mf6_input, this%nc_vars, this%input_name, &
237  this%iout, kper)
238  else if (layered) then
239  call get_layered_shape(this%ctx%mshape, nlay, layer_shape)
240  call read_dbl1d_layered(parser, nodes, idt%mf6varname, nlay, layer_shape)
241  else
242  call read_dbl1d(parser, nodes, idt%mf6varname)
243  end if
244 
245  call idm_log_var(nodes, idt%tagname, mempath, this%iout)
246 
247  if (this%ctx%nbound > 0) then
248  ! nodeulist already established: extract values at known positions
249  do n = 1, this%ctx%nbound
250  dbl1d(n) = nodes(this%nodeulist(n))
251  end do
252  else
253  ! first array: filter by DNODATA to establish nodeulist and nbound
254  do n = 1, this%ctx%nodes
255  if (nodes(n) /= dnodata) then
256  nnode = nnode + 1
257  if (nnode > this%ctx%maxbound) then
258  write (errmsg, '(a,i0,a)') &
259  'Input error: number of defined (non-DNODATA) cells &
260  &exceeds MAXBOUND=', this%ctx%maxbound, '.'
261  call store_error(errmsg)
262  call store_error_filename(this%input_name)
263  end if
264  dbl1d(nnode) = nodes(n)
265  this%nodeulist(nnode) = n
266  end if
267  end do
268  this%ctx%nbound = nnode
269  end if
270  deallocate (nodes)
271  case ('DOUBLE2D')
272  call mem_setptr(dbl2d, idt%mf6varname, mempath)
273  allocate (nodes(this%ctx%nodes))
274 
275  if (netcdf) then
276  call netcdf_read_array(nodes, this%ctx%mshape, idt, &
277  this%mf6_input, this%nc_vars, this%input_name, &
278  this%iout, kper, iaux)
279  else if (layered) then
280  call get_layered_shape(this%ctx%mshape, nlay, layer_shape)
281  call read_dbl1d_layered(parser, nodes, idt%mf6varname, nlay, layer_shape)
282  else
283  call read_dbl1d(parser, nodes, idt%mf6varname)
284  end if
285 
286  call idm_log_var(nodes, idt%tagname, mempath, this%iout)
287 
288  if (this%ctx%nbound > 0) then
289  ! nodeulist already established: extract values at known positions
290  do n = 1, this%ctx%nbound
291  dbl2d(iaux, n) = nodes(this%nodeulist(n))
292  end do
293  else
294  ! first array: filter by DNODATA to establish nodeulist and nbound
295  do n = 1, this%ctx%nodes
296  if (nodes(n) /= dnodata) then
297  nnode = nnode + 1
298  if (nnode > this%ctx%maxbound) then
299  write (errmsg, '(a,i0,a)') &
300  'Input error: number of defined (non-DNODATA) cells &
301  &exceeds MAXBOUND=', this%ctx%maxbound, '.'
302  call store_error(errmsg)
303  call store_error_filename(this%input_name)
304  end if
305  dbl2d(iaux, nnode) = nodes(n)
306  this%nodeulist(nnode) = n
307  end if
308  end do
309  this%ctx%nbound = nnode
310  end if
311  deallocate (nodes)
312  case default
313  errmsg = 'IDM unimplemented. GridArrayLoad::param_load &
314  &datatype='//trim(idt%datatype)
315  call store_error(errmsg)
316  call store_error_filename(this%input_name)
317  end select
318 
319  ! if param is tracked set read state
320  iparam = ifind(this%param_names, idt%tagname)
321  if (iparam > 0) then
322  this%param_reads(iparam)%invar = 1
323  end if
324  end subroutine param_load
325 
326 end module gridarrayloadmodule
This module contains the AsciiInputLoadTypeModule.
This module contains block parser methods.
Definition: BlockParser.f90:7
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
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition: Constants.f90:17
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 destroy(this)
subroutine df(this)
subroutine param_load(this, parser, idt, mempath, layered, netcdf, iaux)
subroutine reset(this)
subroutine rp(this, parser)
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)
@ brief log the closing message
Definition: IdmLogger.f90:56
subroutine, public idm_log_header(component, subcomponent, iout)
@ brief 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.
Definition: LoadContext.f90:10
This module contains the LoadMf6FileModule.
Definition: LoadMf6File.f90:8
This module contains the LoadNCInputModule.
Definition: LoadNCInput.F90:7
subroutine, public get_isize(name, mem_path, isize)
@ brief Get the number of elements for this variable
This module contains the ModflowInputModule.
Definition: ModflowInput.f90:9
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition: Sim.f90:204
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=maxcharlen) errmsg
error message string
This module contains the SourceCommonModule.
Definition: SourceCommon.f90:7
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....
Definition: LoadContext.f90:75
Pointer type for read state variable.
Definition: LoadContext.f90:41
Static parser based input loader.
Definition: LoadMf6File.f90:54
derived type for storing input definition for a file