MODFLOW 6  version 6.8.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
187  call this%ctx%tags(this%param_names, this%nparam, this%input_name, &
188  create=.true.)
189  call this%ctx%allocate_arrays()
190 
191  ! allocate and set param_reads pointer array
192  allocate (this%param_reads(this%nparam))
193 
194  ! store read state variable pointers
195  do iparam = 1, this%nparam
196  ! allocate and store name of read state variable
197  rs_varname = this%ctx%rsv_alloc(this%param_names(iparam))
198  call mem_setptr(intvar, rs_varname, this%mf6_input%mempath)
199  this%param_reads(iparam)%invar => intvar
200  this%param_reads(iparam)%invar = 0
201  end do
202  end subroutine params_alloc
203 
204  subroutine param_load(this, parser, idt, mempath, layered, netcdf, iaux)
205  use tdismodule, only: kper
206  use constantsmodule, only: dnodata
207  use arrayhandlersmodule, only: ifind
213  use idmloggermodule, only: idm_log_var
214  class(gridarrayloadtype), intent(inout) :: this
215  type(blockparsertype), intent(in) :: parser
216  type(inputparamdefinitiontype), intent(in) :: idt
217  character(len=*), intent(in) :: mempath
218  logical(LGP), intent(in) :: layered
219  logical(LGP), intent(in) :: netcdf
220  integer(I4B), intent(in) :: iaux
221  real(DP), dimension(:), pointer, contiguous :: dbl1d, nodes
222  real(DP), dimension(:, :), pointer, contiguous :: dbl2d
223  integer(I4B), dimension(:), allocatable :: layer_shape
224  integer(I4B) :: iparam, n, nlay, nnode
225 
226  nnode = 0
227 
228  select case (idt%datatype)
229  case ('DOUBLE1D')
230  call mem_setptr(dbl1d, idt%mf6varname, mempath)
231  allocate (nodes(this%ctx%nodes))
232  if (netcdf) then
233  call netcdf_read_array(nodes, this%ctx%mshape, idt, &
234  this%mf6_input, this%nc_vars, this%input_name, &
235  this%iout, kper)
236  else if (layered) then
237  call get_layered_shape(this%ctx%mshape, nlay, layer_shape)
238  call read_dbl1d_layered(parser, nodes, idt%mf6varname, nlay, layer_shape)
239  else
240  call read_dbl1d(parser, nodes, idt%mf6varname)
241  end if
242 
243  call idm_log_var(nodes, idt%tagname, mempath, this%iout)
244 
245  if (this%ctx%nbound > 0) then
246  ! nodeulist already established: extract values at known positions
247  do n = 1, this%ctx%nbound
248  dbl1d(n) = nodes(this%nodeulist(n))
249  end do
250  else
251  ! first array: filter by DNODATA to establish nodeulist and nbound
252  do n = 1, this%ctx%nodes
253  if (nodes(n) /= dnodata) then
254  nnode = nnode + 1
255  dbl1d(nnode) = nodes(n)
256  this%nodeulist(nnode) = n
257  end if
258  end do
259  this%ctx%nbound = nnode
260  end if
261  deallocate (nodes)
262  case ('DOUBLE2D')
263  call mem_setptr(dbl2d, idt%mf6varname, mempath)
264  allocate (nodes(this%ctx%nodes))
265 
266  if (netcdf) then
267  call netcdf_read_array(nodes, this%ctx%mshape, idt, &
268  this%mf6_input, this%nc_vars, this%input_name, &
269  this%iout, kper, iaux)
270  else if (layered) then
271  call get_layered_shape(this%ctx%mshape, nlay, layer_shape)
272  call read_dbl1d_layered(parser, nodes, idt%mf6varname, nlay, layer_shape)
273  else
274  call read_dbl1d(parser, nodes, idt%mf6varname)
275  end if
276 
277  call idm_log_var(nodes, idt%tagname, mempath, this%iout)
278 
279  if (this%ctx%nbound > 0) then
280  ! nodeulist already established: extract values at known positions
281  do n = 1, this%ctx%nbound
282  dbl2d(iaux, n) = nodes(this%nodeulist(n))
283  end do
284  else
285  ! first array: filter by DNODATA to establish nodeulist and nbound
286  do n = 1, this%ctx%nodes
287  if (nodes(n) /= dnodata) then
288  nnode = nnode + 1
289  dbl2d(iaux, nnode) = nodes(n)
290  this%nodeulist(nnode) = n
291  end if
292  end do
293  this%ctx%nbound = nnode
294  end if
295  deallocate (nodes)
296  case default
297  errmsg = 'IDM unimplemented. GridArrayLoad::param_load &
298  &datatype='//trim(idt%datatype)
299  call store_error(errmsg)
300  call store_error_filename(this%input_name)
301  end select
302 
303  ! if param is tracked set read state
304  iparam = ifind(this%param_names, idt%tagname)
305  if (iparam > 0) then
306  this%param_reads(iparam)%invar = 1
307  end if
308  end subroutine param_load
309 
310 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)
This module contains the LoadContextModule.
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:203
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.
derived type for boundary package input context
Definition: LoadContext.f90:65
Pointer type for read state variable.
Definition: LoadContext.f90:50
Static parser based input loader.
Definition: LoadMf6File.f90:54
derived type for storing input definition for a file