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