MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
DynamicPackageParams.f90
Go to the documentation of this file.
1 !> @brief This module contains the DynamicPackageParamsModule
2 !!
3 !!
4 !<
6 
7  use kindmodule, only: dp, i4b, lgp
9  use simvariablesmodule, only: errmsg
19 
20  implicit none
21  private
22  public :: dynamicpackageparamstype
23  public :: allocate_param_charstr
26 
27  !> @brief dynamic parameter filter type
28  !!
29  !!
30  !<
32  character(len=LINELENGTH), dimension(:), allocatable :: params !< in scope param tags
33  character(len=LINELENGTH) :: blockname !< name of block
34  integer(I4B) :: iauxiliary !< package auxiliary active, 0=inactive, active for values > 0
35  integer(I4B) :: inamedbound !< package inamedbound setting
36  integer(I4B) :: nparam !< number of in scope params
37  type(modflowinputtype) :: mf6_input !< description of input
38  contains
39  procedure :: init
40  procedure :: destroy
41  procedure :: set_filtered_list
42  procedure :: set_filtered_grid
43  procedure :: package_params
45 
46 contains
47 
48  !> @brief initialize dynamic param filter
49  !!
50  !<
51  subroutine init(this, mf6_input, blockname, readasarrays, iauxiliary, &
52  inamedbound)
53  ! -- modules
54  ! -- dummy
55  class(dynamicpackageparamstype) :: this
56  type(modflowinputtype), intent(in) :: mf6_input
57  character(len=*) :: blockname
58  logical(LGP), intent(in) :: readasarrays
59  integer(I4B), intent(in) :: iauxiliary
60  integer(I4B), intent(in) :: inamedbound
61  !integer(I4B) :: iparam
62  ! -- local
63  !
64  this%mf6_input = mf6_input
65  this%blockname = blockname
66  this%nparam = 0
67  this%iauxiliary = iauxiliary
68  this%inamedbound = inamedbound
69  !
70  ! -- determine in scope input params
71  if (readasarrays) then
72  call this%set_filtered_grid()
73  else
74  call this%set_filtered_list()
75  end if
76  !
77  ! --return
78  return
79  end subroutine init
80 
81  !> @brief destroy
82  !!
83  !<
84  subroutine destroy(this)
85  ! -- modules
86  ! -- dummy
87  class(dynamicpackageparamstype) :: this
88  !
89  ! -- deallocate
90  if (allocated(this%params)) deallocate (this%params)
91  !
92  ! --return
93  return
94  end subroutine destroy
95 
96  !> @brief array based input dynamic param filter
97  !!
98  !<
99  subroutine set_filtered_grid(this)
100  ! -- modules
101  ! -- dummy
102  class(dynamicpackageparamstype) :: this
103  ! -- local
104  type(inputparamdefinitiontype), pointer :: idt
105  integer(I4B), dimension(:), allocatable :: idt_idxs
106  type(characterstringtype), dimension(:), pointer, contiguous :: boundname
107  real(DP), dimension(:, :), pointer, contiguous :: auxvar
108  integer(I4B) :: keepcnt, iparam
109  logical(LGP) :: keep
110  !
111  ! -- initialize
112  keepcnt = 0
113  !
114  ! -- allocate dfn input params
115  do iparam = 1, size(this%mf6_input%param_dfns)
116  !
117  keep = .true.
118  !
119  ! -- assign param definition pointer
120  idt => this%mf6_input%param_dfns(iparam)
121  !
122  if (idt%blockname /= this%blockname) then
123  keep = .false.
124  end if
125  !
126  if (idt%tagname == 'AUX') then
127  if (this%iauxiliary == 0) then
128  keep = .false.
129  call mem_allocate(auxvar, 0, 0, 'AUXVAR', this%mf6_input%mempath)
130  end if
131  if (this%inamedbound == 0) then
132  call mem_allocate(boundname, lenboundname, 0, 'BOUNDNAME', &
133  this%mf6_input%mempath)
134  end if
135  end if
136  !
137  if (keep) then
138  keepcnt = keepcnt + 1
139  call expandarray(idt_idxs)
140  idt_idxs(keepcnt) = iparam
141  end if
142  end do
143  !
144  ! -- update nparam
145  this%nparam = keepcnt
146  !
147  ! -- allocate filtcols
148  allocate (this%params(this%nparam))
149  !
150  ! -- set filtcols
151  do iparam = 1, this%nparam
152  idt => this%mf6_input%param_dfns(idt_idxs(iparam))
153  this%params(iparam) = trim(idt%tagname)
154  end do
155  !
156  ! -- cleanup
157  deallocate (idt_idxs)
158  !
159  ! -- return
160  return
161  end subroutine set_filtered_grid
162 
163  !> @brief create array of in scope list input columns
164  !!
165  !! Filter the recarray description of list input parameters
166  !! to determine which columns are to be read in this run.
167  !<
168  subroutine set_filtered_list(this)
169  ! -- modules
170  ! -- dummy
171  class(dynamicpackageparamstype) :: this
172  ! -- local
173  type(inputparamdefinitiontype), pointer :: ra_idt, idt
174  character(len=LINELENGTH), dimension(:), allocatable :: ra_cols
175  type(characterstringtype), dimension(:), pointer, contiguous :: boundname
176  real(DP), dimension(:, :), pointer, contiguous :: auxvar
177  integer(I4B) :: ra_ncol, icol, keepcnt
178  logical(LGP) :: keep
179  !
180  ! -- initialize
181  keepcnt = 0
182  !
183  ! -- get aggregate param definition for period block
184  ra_idt => &
185  get_aggregate_definition_type(this%mf6_input%aggregate_dfns, &
186  this%mf6_input%component_type, &
187  this%mf6_input%subcomponent_type, &
188  this%blockname)
189  !
190  ! -- split recarray definition
191  call idt_parse_rectype(ra_idt, ra_cols, ra_ncol)
192  !
193  ! -- determine which columns are in scope
194  do icol = 1, ra_ncol
195  !
196  keep = .false.
197  !
198  ! -- set dfn pointer to recarray parameter
199  idt => get_param_definition_type(this%mf6_input%param_dfns, &
200  this%mf6_input%component_type, &
201  this%mf6_input%subcomponent_type, &
202  this%blockname, ra_cols(icol), '')
203  !
204  if (ra_cols(icol) == 'RECARRAY') then
205  ! no-op
206  else if (ra_cols(icol) == 'AUX') then
207  if (this%iauxiliary > 0) then
208  keep = .true.
209  else
210  call mem_allocate(auxvar, 0, 0, 'AUXVAR', this%mf6_input%mempath)
211  end if
212  else if (ra_cols(icol) == 'BOUNDNAME') then
213  if (this%inamedbound /= 0) then
214  keep = .true.
215  else
216  call mem_allocate(boundname, lenboundname, 0, 'BOUNDNAME', &
217  this%mf6_input%mempath)
218  end if
219  else
220  ! -- determine if the param is scope
221  keep = pkg_param_in_scope(this%mf6_input, this%blockname, ra_cols(icol))
222  end if
223  !
224  if (keep) then
225  keepcnt = keepcnt + 1
226  call expandarray(this%params)
227  this%params(keepcnt) = trim(ra_cols(icol))
228  end if
229  end do
230  !
231  ! -- update nparam
232  this%nparam = keepcnt
233  !
234  ! -- cleanup
235  deallocate (ra_cols)
236  !
237  ! -- return
238  return
239  end subroutine set_filtered_list
240 
241  !> @brief allocate and set input array to filtered param set
242  !!
243  !<
244  subroutine package_params(this, params, nparam)
245  ! -- modules
246  ! -- dummy
247  class(dynamicpackageparamstype) :: this
248  character(len=LINELENGTH), dimension(:), allocatable, &
249  intent(inout) :: params
250  integer(I4B), intent(inout) :: nparam
251  integer(I4B) :: n
252  !
253  if (allocated(params)) deallocate (params)
254  !
255  nparam = this%nparam
256  !
257  allocate (params(nparam))
258  !
259  do n = 1, nparam
260  params(n) = this%params(n)
261  end do
262  !
263  ! -- return
264  return
265  end subroutine package_params
266 
267  !> @brief allocate character string type array
268  !<
269  subroutine allocate_param_charstr(strlen, nrow, varname, mempath)
270  integer(I4B), intent(in) :: strlen !< string number of characters
271  integer(I4B), intent(in) :: nrow !< integer array number of rows
272  character(len=*), intent(in) :: varname !< variable name
273  character(len=*), intent(in) :: mempath !< variable mempath
274  type(characterstringtype), dimension(:), pointer, &
275  contiguous :: charstr1d
276  integer(I4B) :: n
277  !
278  call mem_allocate(charstr1d, strlen, nrow, varname, mempath)
279  do n = 1, nrow
280  charstr1d(n) = ''
281  end do
282  end subroutine allocate_param_charstr
283 
284  !> @brief allocate int1d
285  !<
286  subroutine allocate_param_int1d(nrow, varname, mempath)
287  integer(I4B), intent(in) :: nrow !< integer array number of rows
288  character(len=*), intent(in) :: varname !< variable name
289  character(len=*), intent(in) :: mempath !< variable mempath
290  integer(I4B), dimension(:), pointer, contiguous :: int1d
291  integer(I4B) :: n
292  !
293  call mem_allocate(int1d, nrow, varname, mempath)
294  do n = 1, nrow
295  int1d(n) = izero
296  end do
297  end subroutine allocate_param_int1d
298 
299  !> @brief allocate int2d
300  !<
301  subroutine allocate_param_int2d(ncol, nrow, varname, mempath)
302  integer(I4B), intent(in) :: ncol !< integer array number of cols
303  integer(I4B), intent(in) :: nrow !< integer array number of rows
304  character(len=*), intent(in) :: varname !< variable name
305  character(len=*), intent(in) :: mempath !< variable mempath
306  integer(I4B), dimension(:, :), pointer, contiguous :: int2d
307  integer(I4B) :: n, m
308  !
309  call mem_allocate(int2d, ncol, nrow, varname, mempath)
310  do m = 1, nrow
311  do n = 1, ncol
312  int2d(n, m) = izero
313  end do
314  end do
315  end subroutine allocate_param_int2d
316 
317  !> @brief allocate dbl1d
318  !<
319  subroutine allocate_param_dbl1d(nrow, varname, mempath)
320  integer(I4B), intent(in) :: nrow !< integer array number of rows
321  character(len=*), intent(in) :: varname !< variable name
322  character(len=*), intent(in) :: mempath !< variable mempath
323  real(dp), dimension(:), pointer, contiguous :: dbl1d
324  integer(I4B) :: n
325  !
326  call mem_allocate(dbl1d, nrow, varname, mempath)
327  do n = 1, nrow
328  dbl1d(n) = dzero
329  end do
330  end subroutine allocate_param_dbl1d
331 
332  !> @brief allocate dbl2d
333  !<
334  subroutine allocate_param_dbl2d(ncol, nrow, varname, mempath)
335  integer(I4B), intent(in) :: ncol !< integer array number of cols
336  integer(I4B), intent(in) :: nrow !< integer array number of rows
337  character(len=*), intent(in) :: varname !< variable name
338  character(len=*), intent(in) :: mempath !< variable mempath
339  real(dp), dimension(:, :), pointer, contiguous :: dbl2d
340  integer(I4B) :: n, m
341  !
342  call mem_allocate(dbl2d, ncol, nrow, varname, mempath)
343  do m = 1, nrow
344  do n = 1, ncol
345  dbl2d(n, m) = dzero
346  end do
347  end do
348  end subroutine allocate_param_dbl2d
349 
350  !> @brief determine if input param is in scope for a package
351  !!
352  !<
353  function pkg_param_in_scope(mf6_input, blockname, tagname) result(in_scope)
354  ! -- modules
356  ! -- dummy
357  type(modflowinputtype), intent(in) :: mf6_input
358  character(len=*), intent(in) :: blockname
359  character(len=*), intent(in) :: tagname
360  ! -- return
361  logical(LGP) :: in_scope
362  ! -- local
363  type(inputparamdefinitiontype), pointer :: idt
364  integer(I4B) :: pdim_isize, popt_isize
365  integer(I4B), pointer :: pdim
366  !
367  ! -- initialize
368  in_scope = .false.
369  !
370  idt => get_param_definition_type(mf6_input%param_dfns, &
371  mf6_input%component_type, &
372  mf6_input%subcomponent_type, &
373  blockname, tagname, '')
374  !
375  if (idt%required) then
376  ! -- required params always included
377  in_scope = .true.
378  else
379  !
380  ! -- package specific logic to determine if input params to be read
381  select case (mf6_input%subcomponent_type)
382  case ('EVT')
383  !
384  if (tagname == 'PXDP' .or. tagname == 'PETM') then
385  call get_isize('NSEG', mf6_input%mempath, pdim_isize)
386  if (pdim_isize > 0) then
387  call mem_setptr(pdim, 'NSEG', mf6_input%mempath)
388  if (pdim > 1) then
389  in_scope = .true.
390  end if
391  end if
392  else if (tagname == 'PETM0') then
393  call get_isize('SURFRATESPEC', mf6_input%mempath, popt_isize)
394  if (popt_isize > 0) then
395  in_scope = .true.
396  end if
397  end if
398  !
399  case ('NAM')
400  in_scope = .true.
401  case default
402  errmsg = 'IDM unimplemented. DynamicPackageParamsType::pkg_param_in_scope &
403  &add case tagname='//trim(idt%tagname)
404  call store_error(errmsg, .true.)
405  !call store_error_filename(sourcename)
406  end select
407  end if
408  !
409  ! -- return
410  return
411  end function pkg_param_in_scope
412 
subroutine init()
Definition: GridSorting.f90:24
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 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.
type(inputparamdefinitiontype) function, pointer, public get_aggregate_definition_type(input_definition_types, component_type, subcomponent_type, blockname)
Return aggregate definition.
subroutine, public idt_parse_rectype(idt, cols, ncol)
allocate and set RECARRAY, KEYSTRING or RECORD param list
This module contains the DynamicPackageParamsModule.
subroutine set_filtered_list(this)
create array of in scope list input columns
subroutine, public allocate_param_int2d(ncol, nrow, varname, mempath)
allocate int2d
subroutine, public allocate_param_int1d(nrow, varname, mempath)
allocate int1d
subroutine set_filtered_grid(this)
array based input dynamic param filter
subroutine destroy(this)
destroy
subroutine package_params(this, params, nparam)
allocate and set input array to filtered param set
logical(lgp) function pkg_param_in_scope(mf6_input, blockname, tagname)
determine if input param is in scope for a package
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
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