MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
BoundInputContext.f90
Go to the documentation of this file.
1 !> @brief This module contains the BoundInputContextModule
2 !!
3 !! This module contains a type that stores and creates context
4 !! relevant to stress package inputs.
5 !!
6 !<
8 
9  use kindmodule, only: dp, i4b, lgp
12  use simvariablesmodule, only: errmsg
18 
19  implicit none
20  private
21  public :: boundinputcontexttype
22  public :: readstatevartype
23  public :: rsv_name
24 
25  !> @brief Pointer type for read state variable
26  !<
28  integer, pointer :: invar
29  end type readstatevartype
30 
31  !> @brief derived type for boundary package input context
32  !!
33  !! This derived type defines input context used by dynamic package loaders.
34  !! Some variables (e.g. iprpak) in the type may have already been created
35  !! by a static loader whereas others (e.g. nboound) are created by this
36  !! type, updated by to dynamic loader, and accessed from the model package.
37  !!
38  !<
40  integer(I4B), pointer :: naux => null() !< number of auxiliary variables
41  integer(I4B), pointer :: maxbound => null() !< max list input records per period
42  integer(I4B), pointer :: inamedbound => null() !< are bound names optioned
43  integer(I4B), pointer :: iprpak => null() ! print input option
44  integer(I4B), pointer :: nbound => null() !< number of bounds in period
45  integer(I4B), pointer :: ncpl => null() !< number of cells per layer
46  type(characterstringtype), dimension(:), pointer, &
47  contiguous :: auxname_cst => null() !< array of auxiliary names
48  type(characterstringtype), dimension(:), pointer, &
49  contiguous :: boundname_cst => null() !< array of bound names
50  real(dp), dimension(:, :), pointer, &
51  contiguous :: auxvar => null() !< auxiliary variable array
52  integer(I4B), dimension(:), pointer, contiguous :: mshape => null() !< model shape
53  logical(LGP) :: readasarrays !< grid or list based input
54  type(dynamicpackageparamstype) :: package_params
55  type(modflowinputtype) :: mf6_input !< description of input
56  contains
57  procedure :: create
58  procedure :: allocate_scalars
59  procedure :: allocate_arrays
60  procedure :: list_params_create
61  procedure :: array_params_create
62  procedure :: destroy
63  procedure :: rsv_alloc
64  procedure :: bound_params
65  end type boundinputcontexttype
66 
67 contains
68 
69  !> @brief create boundary input context
70  !!
71  !<
72  subroutine create(this, mf6_input, readasarrays)
73  ! -- modules
74  ! -- dummy
75  class(boundinputcontexttype) :: this
76  type(modflowinputtype), intent(in) :: mf6_input
77  logical(LGP), intent(in) :: readasarrays
78  !
79  this%mf6_input = mf6_input
80  this%readasarrays = readasarrays
81  !
82  ! -- create the dynamic package input context
83  call this%allocate_scalars()
84  !
85  ! --return
86  return
87  end subroutine create
88 
89  !> @brief create boundary input context
90  !!
91  !<
92  subroutine allocate_scalars(this)
93  ! -- modules
96  ! -- dummy
97  class(boundinputcontexttype) :: this
98  logical(LGP) :: found
99  !
100  ! -- set pointers to defined scalars
101  call mem_setptr(this%naux, 'NAUX', this%mf6_input%mempath)
102  !
103  ! -- allocate memory managed scalars
104  call mem_allocate(this%nbound, 'NBOUND', this%mf6_input%mempath)
105  call mem_allocate(this%ncpl, 'NCPL', this%mf6_input%mempath)
106  !
107  ! -- internally allocate package optional scalars
108  allocate (this%maxbound)
109  allocate (this%inamedbound)
110  allocate (this%iprpak)
111  !
112  ! -- initialize allocated and internal scalars
113  this%nbound = 0
114  this%ncpl = 0
115  this%maxbound = 0
116  this%inamedbound = 0
117  this%iprpak = 0
118  !
119  ! -- update optional scalars
120  call mem_set_value(this%inamedbound, 'BOUNDNAMES', this%mf6_input%mempath, &
121  found)
122  call mem_set_value(this%maxbound, 'MAXBOUND', this%mf6_input%mempath, found)
123  call mem_set_value(this%iprpak, 'IPRPAK', this%mf6_input%mempath, found)
124  !
125  ! -- set pointer to model shape
126  call mem_setptr(this%mshape, 'MODEL_SHAPE', &
127  this%mf6_input%component_mempath)
128  !
129  ! -- update ncpl from model shape
130  if (size(this%mshape) == 2) then
131  this%ncpl = this%mshape(2)
132  else if (size(this%mshape) == 3) then
133  this%ncpl = this%mshape(2) * this%mshape(3)
134  end if
135  !
136  ! -- initialize package params object
137  call this%package_params%init(this%mf6_input, 'PERIOD', this%readasarrays, &
138  this%naux, this%inamedbound)
139  !
140  ! -- return
141  return
142  end subroutine allocate_scalars
143 
144  !> @brief allocate_arrays
145  !!
146  !! allocate bound input context arrays
147  !!
148  !<
149  subroutine allocate_arrays(this)
150  ! -- modules
153  ! -- dummy
154  class(boundinputcontexttype) :: this
155  integer(I4B), dimension(:, :), pointer, contiguous :: cellid
156  ! -- local
157  !
158  ! -- set auxname_cst and iauxmultcol
159  if (this%naux > 0) then
160  call mem_setptr(this%auxname_cst, 'AUXILIARY', this%mf6_input%mempath)
161  else
162  call mem_allocate(this%auxname_cst, lenauxname, 0, &
163  'AUXILIARY', this%mf6_input%mempath)
164  end if
165  !
166  ! -- allocate cellid if this is not list input
167  if (this%readasarrays) then
168  call mem_allocate(cellid, 0, 0, 'CELLID', this%mf6_input%mempath)
169  end if
170  !
171  ! -- set pointer to BOUNDNAME
172  call mem_setptr(this%boundname_cst, 'BOUNDNAME', this%mf6_input%mempath)
173  !
174  ! -- set pointer to AUXVAR
175  call mem_setptr(this%auxvar, 'AUXVAR', this%mf6_input%mempath)
176  !
177  ! -- return
178  return
179  end subroutine allocate_arrays
180 
181  subroutine list_params_create(this, params, nparam, input_name)
182  ! -- modules
190  ! -- dummy
191  class(boundinputcontexttype) :: this
192  character(len=*), dimension(:), allocatable, intent(in) :: params
193  integer(I4B), intent(in) :: nparam
194  character(len=*), intent(in) :: input_name
195  ! -- local
196  type(inputparamdefinitiontype), pointer :: idt
197  integer(I4B) :: iparam
198  !
199  ! --
200  do iparam = 1, nparam
201  idt => get_param_definition_type(this%mf6_input%param_dfns, &
202  this%mf6_input%component_type, &
203  this%mf6_input%subcomponent_type, &
204  'PERIOD', params(iparam), '')
205  !
206  ! allocate based on dfn datatype
207  select case (idt%datatype)
208  case ('INTEGER')
209  call allocate_param_int1d(this%maxbound, idt%mf6varname, &
210  this%mf6_input%mempath)
211  !
212  case ('DOUBLE')
213  call allocate_param_dbl1d(this%maxbound, idt%mf6varname, &
214  this%mf6_input%mempath)
215  !
216  case ('STRING')
217  call allocate_param_charstr(lenboundname, this%maxbound, idt%mf6varname, &
218  this%mf6_input%mempath)
219  !
220  case ('INTEGER1D')
221  if (idt%shape == 'NCELLDIM') then
222  call allocate_param_int2d(size(this%mshape), this%maxbound, &
223  idt%mf6varname, this%mf6_input%mempath)
224  else
225  errmsg = 'IDM unimplemented. BoundInputContext::list_params_create &
226  &shape='//trim(idt%shape)
227  call store_error(errmsg)
228  call store_error_filename(input_name)
229  end if
230  !
231  case ('DOUBLE1D')
232  if (idt%shape == 'NAUX') then
233  call allocate_param_dbl2d(this%naux, this%maxbound, &
234  idt%mf6varname, this%mf6_input%mempath)
235  else
236  errmsg = 'IDM unimplemented. BoundInputContext::list_params_create &
237  &tagname='//trim(idt%tagname)
238  call store_error(errmsg)
239  call store_error_filename(input_name)
240  end if
241  !
242  case default
243  errmsg = 'IDM unimplemented. BoundInputContext::list_params_create &
244  &datatype='//trim(idt%datatype)
245  call store_error(errmsg)
246  call store_error_filename(input_name)
247  end select
248  end do
249  !
250  ! -- return
251  return
252  end subroutine list_params_create
253 
254  !> @brief allocate dfn array input period block parameters
255  !!
256  !! Currently supports numeric (i.e. array based) params
257  !!
258  !<
259  subroutine array_params_create(this, params, nparam, input_name)
260  ! -- modules
265  ! -- dummy
266  class(boundinputcontexttype) :: this
267  character(len=*), dimension(:), allocatable, intent(in) :: params
268  integer(I4B), intent(in) :: nparam
269  character(len=*), intent(in) :: input_name
270  ! -- local
271  type(inputparamdefinitiontype), pointer :: idt
272  integer(I4B) :: iparam
273  !
274  ! -- allocate dfn input params
275  do iparam = 1, nparam
276  !
277  ! -- assign param definition pointer
278  idt => get_param_definition_type(this%mf6_input%param_dfns, &
279  this%mf6_input%component_type, &
280  this%mf6_input%subcomponent_type, &
281  'PERIOD', params(iparam), '')
282  !
283  if (idt%blockname == 'PERIOD') then
284  select case (idt%datatype)
285  case ('INTEGER1D')
286  call allocate_param_int1d(this%ncpl, idt%mf6varname, &
287  this%mf6_input%mempath)
288  !
289  case ('DOUBLE1D')
290  call allocate_param_dbl1d(this%ncpl, idt%mf6varname, &
291  this%mf6_input%mempath)
292  !
293  case ('DOUBLE2D')
294  call allocate_param_dbl2d(this%naux, this%ncpl, idt%mf6varname, &
295  this%mf6_input%mempath)
296  !
297  case default
298  errmsg = 'IDM unimplemented. BoundInputContext::array_params_create &
299  &datatype='//trim(idt%datatype)
300  call store_error(errmsg)
301  call store_error_filename(input_name)
302  end select
303  end if
304  end do
305  !
306  ! -- return
307  return
308  end subroutine array_params_create
309 
310  !> @brief destroy boundary input context
311  !!
312  !<
313  subroutine destroy(this)
314  ! -- modules
315  ! -- dummy
316  class(boundinputcontexttype) :: this
317  !
318  ! -- destroy package params object
319  call this%package_params%destroy()
320  !
321  ! -- deallocate
322  deallocate (this%maxbound)
323  deallocate (this%inamedbound)
324  deallocate (this%iprpak)
325  !
326  ! -- nullify
327  nullify (this%naux)
328  nullify (this%nbound)
329  nullify (this%ncpl)
330  nullify (this%maxbound)
331  nullify (this%inamedbound)
332  nullify (this%iprpak)
333  nullify (this%auxname_cst)
334  nullify (this%boundname_cst)
335  nullify (this%auxvar)
336  nullify (this%mshape)
337  !
338  ! --return
339  return
340  end subroutine destroy
341 
342  !> @brief allocate a read state variable
343  !!
344  !! Create and set a read state variable, e.g. 'INRECHARGE',
345  !! which are updated per iper load as follows:
346  !! -1: unset, not in use
347  !! 0: not read in most recent period block
348  !! 1: numeric input read in most recent period block
349  !! 2: time series input read in most recent period block
350  !!
351  !<
352  function rsv_alloc(this, mf6varname) result(varname)
353  ! -- modules
354  use constantsmodule, only: lenvarname
356  ! -- dummy
357  class(boundinputcontexttype) :: this
358  character(len=*), intent(in) :: mf6varname
359  ! -- local
360  character(len=LENVARNAME) :: varname
361  integer(I4B), pointer :: intvar
362  !
363  varname = rsv_name(mf6varname)
364  !
365  call mem_allocate(intvar, varname, this%mf6_input%mempath)
366  intvar = -1
367  !
368  ! -- return
369  return
370  end function rsv_alloc
371 
372  !> @brief allocate and set input array to filtered param set
373  !!
374  !<
375  subroutine bound_params(this, params, nparam, input_name, create)
376  ! -- modules
377  ! -- dummy
378  class(boundinputcontexttype) :: this
379  character(len=LINELENGTH), dimension(:), allocatable, &
380  intent(inout) :: params
381  integer(I4B), intent(inout) :: nparam
382  character(len=*), intent(in) :: input_name
383  logical(LGP), optional, intent(in) :: create
384  logical(LGP) :: allocate_params
385  integer(I4B) :: n
386  !
387  ! -- initialize allocate_params
388  allocate_params = .true.
389  !
390  ! -- override default if provided
391  if (present(create)) then
392  allocate_params = create
393  end if
394  !
395  if (allocated(params)) deallocate (params)
396  !
397  nparam = this%package_params%nparam
398  !
399  allocate (params(nparam))
400  !
401  do n = 1, nparam
402  params(n) = this%package_params%params(n)
403  end do
404  !
405  if (allocate_params) then
406  if (this%readasarrays) then
407  !
408  call this%array_params_create(params, nparam, input_name)
409  else
410  !
411  call this%list_params_create(params, nparam, input_name)
412  end if
413  end if
414  !
415  ! -- return
416  return
417  end subroutine bound_params
418 
419  !> @brief create read state variable name
420  !!
421  !<
422  function rsv_name(mf6varname) result(varname)
423  ! -- modules
424  use constantsmodule, only: lenvarname
425  ! -- dummy
426  character(len=*), intent(in) :: mf6varname
427  ! -- local
428  character(len=LENVARNAME) :: varname
429  integer(I4B) :: ilen
430  character(len=2) :: prefix = 'IN'
431  !
432  ilen = len_trim(mf6varname)
433  !
434  if (ilen > (lenvarname - len(prefix))) then
435  varname = prefix//mf6varname(1:(lenvarname - len(prefix)))
436  else
437  varname = prefix//trim(mf6varname)
438  end if
439  !
440  ! -- return
441  return
442  end function rsv_name
443 
444 end module boundinputcontextmodule
This module contains the BoundInputContextModule.
subroutine array_params_create(this, params, nparam, input_name)
allocate dfn array input period block parameters
character(len=lenvarname) function, public rsv_name(mf6varname)
create read state variable name
subroutine allocate_arrays(this)
allocate_arrays
subroutine bound_params(this, params, nparam, input_name, create)
allocate and set input array to filtered param set
character(len=lenvarname) function rsv_alloc(this, mf6varname)
allocate a read state variable
subroutine create(this, mf6_input, readasarrays)
create boundary input context
subroutine allocate_scalars(this)
create boundary input context
subroutine destroy(this)
destroy boundary input context
subroutine list_params_create(this, params, nparam, input_name)
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 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 lenboundname
maximum length of a bound name
Definition: Constants.f90:36
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)
Return parameter definition.
This module contains the DynamicPackageParamsModule.
subroutine, public allocate_param_int2d(ncol, nrow, varname, mempath)
allocate int2d
subroutine, public allocate_param_int1d(nrow, varname, mempath)
allocate int1d
subroutine, public allocate_param_dbl1d(nrow, varname, mempath)
allocate dbl1d
subroutine, public allocate_param_charstr(strlen, nrow, varname, mempath)
allocate character string type array
subroutine, public allocate_param_dbl2d(ncol, nrow, varname, mempath)
allocate dbl2d
This module contains the InputDefinitionModule.
This module defines variable data types.
Definition: kind.f90:8
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
derived type for boundary package input context
Pointer type for read state variable.
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23
derived type for storing input definition for a file