MODFLOW 6  version 6.7.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(I4B), 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  class(boundinputcontexttype) :: this
74  type(modflowinputtype), intent(in) :: mf6_input
75  logical(LGP), intent(in) :: readasarrays
76 
77  this%mf6_input = mf6_input
78  this%readasarrays = readasarrays
79 
80  ! create the dynamic package input context
81  call this%allocate_scalars()
82  end subroutine create
83 
84  !> @brief create boundary input context
85  !!
86  !<
87  subroutine allocate_scalars(this)
90  class(boundinputcontexttype) :: this
91  logical(LGP) :: found
92 
93  ! set pointers to defined scalars
94  call mem_setptr(this%naux, 'NAUX', this%mf6_input%mempath)
95 
96  ! allocate memory managed scalars
97  call mem_allocate(this%nbound, 'NBOUND', this%mf6_input%mempath)
98  call mem_allocate(this%ncpl, 'NCPL', this%mf6_input%mempath)
99 
100  ! internally allocate package optional scalars
101  allocate (this%maxbound)
102  allocate (this%inamedbound)
103  allocate (this%iprpak)
104 
105  ! initialize allocated and internal scalars
106  this%nbound = 0
107  this%ncpl = 0
108  this%maxbound = 0
109  this%inamedbound = 0
110  this%iprpak = 0
111 
112  ! update optional scalars
113  call mem_set_value(this%inamedbound, 'BOUNDNAMES', this%mf6_input%mempath, &
114  found)
115  call mem_set_value(this%maxbound, 'MAXBOUND', this%mf6_input%mempath, found)
116  call mem_set_value(this%iprpak, 'IPRPAK', this%mf6_input%mempath, found)
117 
118  ! set pointer to model shape
119  call mem_setptr(this%mshape, 'MODEL_SHAPE', &
120  this%mf6_input%component_mempath)
121 
122  ! update ncpl from model shape
123  if (size(this%mshape) == 2) then
124  this%ncpl = this%mshape(2)
125  else if (size(this%mshape) == 3) then
126  this%ncpl = this%mshape(2) * this%mshape(3)
127  end if
128 
129  ! initialize package params object
130  call this%package_params%init(this%mf6_input, 'PERIOD', this%readasarrays, &
131  this%naux, this%inamedbound)
132  end subroutine allocate_scalars
133 
134  !> @brief allocate_arrays
135  !!
136  !! allocate bound input context arrays
137  !!
138  !<
139  subroutine allocate_arrays(this)
142  class(boundinputcontexttype) :: this
143  integer(I4B), dimension(:, :), pointer, contiguous :: cellid
144 
145  ! set auxname_cst and iauxmultcol
146  if (this%naux > 0) then
147  call mem_setptr(this%auxname_cst, 'AUXILIARY', this%mf6_input%mempath)
148  else
149  call mem_allocate(this%auxname_cst, lenauxname, 0, &
150  'AUXILIARY', this%mf6_input%mempath)
151  end if
152 
153  ! allocate cellid if this is not list input
154  if (this%readasarrays) then
155  call mem_allocate(cellid, 0, 0, 'CELLID', this%mf6_input%mempath)
156  end if
157 
158  ! set pointer to BOUNDNAME
159  call mem_setptr(this%boundname_cst, 'BOUNDNAME', this%mf6_input%mempath)
160 
161  ! set pointer to AUXVAR
162  call mem_setptr(this%auxvar, 'AUXVAR', this%mf6_input%mempath)
163  end subroutine allocate_arrays
164 
165  subroutine list_params_create(this, params, nparam, input_name)
173  class(boundinputcontexttype) :: this
174  character(len=*), dimension(:), allocatable, intent(in) :: params
175  integer(I4B), intent(in) :: nparam
176  character(len=*), intent(in) :: input_name
177  type(inputparamdefinitiontype), pointer :: idt
178  integer(I4B) :: iparam
179 
180  do iparam = 1, nparam
181  idt => get_param_definition_type(this%mf6_input%param_dfns, &
182  this%mf6_input%component_type, &
183  this%mf6_input%subcomponent_type, &
184  'PERIOD', params(iparam), '')
185  ! allocate based on dfn datatype
186  select case (idt%datatype)
187  case ('INTEGER')
188  call allocate_param_int1d(this%maxbound, idt%mf6varname, &
189  this%mf6_input%mempath)
190  case ('DOUBLE')
191  call allocate_param_dbl1d(this%maxbound, idt%mf6varname, &
192  this%mf6_input%mempath)
193  case ('STRING')
194  call allocate_param_charstr(lenboundname, this%maxbound, idt%mf6varname, &
195  this%mf6_input%mempath)
196  case ('INTEGER1D')
197  if (idt%shape == 'NCELLDIM') then
198  call allocate_param_int2d(size(this%mshape), this%maxbound, &
199  idt%mf6varname, this%mf6_input%mempath)
200  else
201  errmsg = 'IDM unimplemented. BoundInputContext::list_params_create &
202  &shape='//trim(idt%shape)
203  call store_error(errmsg)
204  call store_error_filename(input_name)
205  end if
206  case ('DOUBLE1D')
207  if (idt%shape == 'NAUX') then
208  call allocate_param_dbl2d(this%naux, this%maxbound, &
209  idt%mf6varname, this%mf6_input%mempath)
210  else
211  errmsg = 'IDM unimplemented. BoundInputContext::list_params_create &
212  &tagname='//trim(idt%tagname)
213  call store_error(errmsg)
214  call store_error_filename(input_name)
215  end if
216  case default
217  errmsg = 'IDM unimplemented. BoundInputContext::list_params_create &
218  &datatype='//trim(idt%datatype)
219  call store_error(errmsg)
220  call store_error_filename(input_name)
221  end select
222  end do
223  end subroutine list_params_create
224 
225  !> @brief allocate dfn array input period block parameters
226  !!
227  !! Currently supports numeric (i.e. array based) params
228  !!
229  !<
230  subroutine array_params_create(this, params, nparam, input_name)
235  class(boundinputcontexttype) :: this
236  character(len=*), dimension(:), allocatable, intent(in) :: params
237  integer(I4B), intent(in) :: nparam
238  character(len=*), intent(in) :: input_name
239  type(inputparamdefinitiontype), pointer :: idt
240  integer(I4B) :: iparam
241 
242  ! allocate dfn input params
243  do iparam = 1, nparam
244 
245  ! assign param definition pointer
246  idt => get_param_definition_type(this%mf6_input%param_dfns, &
247  this%mf6_input%component_type, &
248  this%mf6_input%subcomponent_type, &
249  'PERIOD', params(iparam), '')
250  if (idt%blockname == 'PERIOD') then
251  select case (idt%datatype)
252  case ('INTEGER1D')
253  call allocate_param_int1d(this%ncpl, idt%mf6varname, &
254  this%mf6_input%mempath)
255  case ('DOUBLE1D')
256  call allocate_param_dbl1d(this%ncpl, idt%mf6varname, &
257  this%mf6_input%mempath)
258  case ('DOUBLE2D')
259  call allocate_param_dbl2d(this%naux, this%ncpl, idt%mf6varname, &
260  this%mf6_input%mempath)
261  case default
262  errmsg = 'IDM unimplemented. BoundInputContext::array_params_create &
263  &datatype='//trim(idt%datatype)
264  call store_error(errmsg)
265  call store_error_filename(input_name)
266  end select
267  end if
268  end do
269  end subroutine array_params_create
270 
271  !> @brief destroy boundary input context
272  !!
273  !<
274  subroutine destroy(this)
275  class(boundinputcontexttype) :: this
276 
277  ! destroy package params object
278  call this%package_params%destroy()
279 
280  ! deallocate
281  deallocate (this%maxbound)
282  deallocate (this%inamedbound)
283  deallocate (this%iprpak)
284 
285  ! nullify
286  nullify (this%naux)
287  nullify (this%nbound)
288  nullify (this%ncpl)
289  nullify (this%maxbound)
290  nullify (this%inamedbound)
291  nullify (this%iprpak)
292  nullify (this%auxname_cst)
293  nullify (this%boundname_cst)
294  nullify (this%auxvar)
295  nullify (this%mshape)
296  end subroutine destroy
297 
298  !> @brief allocate a read state variable
299  !!
300  !! Create and set a read state variable, e.g. 'INRECHARGE',
301  !! which are updated per iper load as follows:
302  !! -1: unset, not in use
303  !! 0: not read in most recent period block
304  !! 1: numeric input read in most recent period block
305  !! 2: time series input read in most recent period block
306  !!
307  !<
308  function rsv_alloc(this, mf6varname) result(varname)
309  use constantsmodule, only: lenvarname
311  class(boundinputcontexttype) :: this
312  character(len=*), intent(in) :: mf6varname
313  character(len=LENVARNAME) :: varname
314  integer(I4B), pointer :: intvar
315 
316  varname = rsv_name(mf6varname)
317  call mem_allocate(intvar, varname, this%mf6_input%mempath)
318  intvar = -1
319  end function rsv_alloc
320 
321  !> @brief allocate and set input array to filtered param set
322  !!
323  !<
324  subroutine bound_params(this, params, nparam, input_name, create)
325  class(boundinputcontexttype) :: this
326  character(len=LINELENGTH), dimension(:), allocatable, &
327  intent(inout) :: params
328  integer(I4B), intent(inout) :: nparam
329  character(len=*), intent(in) :: input_name
330  logical(LGP), optional, intent(in) :: create
331  logical(LGP) :: allocate_params
332  integer(I4B) :: n
333 
334  ! initialize allocate_params
335  allocate_params = .true.
336 
337  ! override default if provided
338  if (present(create)) then
339  allocate_params = create
340  end if
341 
342  if (allocated(params)) deallocate (params)
343  nparam = this%package_params%nparam
344  allocate (params(nparam))
345  do n = 1, nparam
346  params(n) = this%package_params%params(n)
347  end do
348 
349  if (allocate_params) then
350  if (this%readasarrays) then
351  call this%array_params_create(params, nparam, input_name)
352  else
353  call this%list_params_create(params, nparam, input_name)
354  end if
355  end if
356  end subroutine bound_params
357 
358  !> @brief create read state variable name
359  !!
360  !<
361  function rsv_name(mf6varname) result(varname)
362  use constantsmodule, only: lenvarname
363  character(len=*), intent(in) :: mf6varname
364  character(len=LENVARNAME) :: varname
365  integer(I4B) :: ilen
366  character(len=2) :: prefix = 'IN'
367 
368  ilen = len_trim(mf6varname)
369  if (ilen > (lenvarname - len(prefix))) then
370  varname = prefix//mf6varname(1:(lenvarname - len(prefix)))
371  else
372  varname = prefix//trim(mf6varname)
373  end if
374  end function rsv_name
375 
376 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