MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
modelpackageinputsmodule Module Reference

This module contains the ModelPackageInputsModule. More...

Data Types

type  loadablepackagetype
 derived type for loadable package type More...
 
type  modelpackageinputstype
 derived type for model package inputs type More...
 

Functions/Subroutines

logical(lgp) function multi_pkg_type (mtype_component, ptype_component, pkgtype)
 does model support multiple instances of this package type More...
 
subroutine pkgtype_create (this, modeltype, modelname, pkgtype)
 create a new package type More...
 
subroutine pkgtype_add (this, modelname, mtype_component, filetype, filename, pkgname, iout)
 add a new package instance to this package type More...
 
subroutine pkgtype_destroy (this)
 deallocate object More...
 
subroutine modelpkgs_init (this, modeltype, modelfname, modelname, iout)
 initialize model package inputs object More...
 
subroutine modelpkgs_create (this, ftypes)
 create the package type list More...
 
subroutine modelpkgs_add (this, pkgtype, filename, pkgname)
 add a model package instance to package type list More...
 
subroutine modelpkgs_addpkgs (this)
 build the type list with all model package instances More...
 
integer(i4b) function modelpkgs_pkgcount (this)
 get package instance count and verify base or multi of each More...
 
subroutine modelpkgs_memload (this)
 load package descriptors to managed memory More...
 
subroutine modelpkgs_destroy (this)
 deallocate object More...
 

Detailed Description

This module contains the high-level routines for assembling model package information and loading to the input context

Function/Subroutine Documentation

◆ modelpkgs_add()

subroutine modelpackageinputsmodule::modelpkgs_add ( class(modelpackageinputstype this,
character(len=*), intent(in)  pkgtype,
character(len=*), intent(in)  filename,
character(len=*), intent(in)  pkgname 
)

Definition at line 357 of file ModelPackageInputs.f90.

358  ! -- modules
359  ! -- dummy
360  class(ModelPackageInputsType) :: this
361  character(len=*), intent(in) :: pkgtype
362  character(len=*), intent(in) :: filename
363  character(len=*), intent(in) :: pkgname
364  ! -- local
365  type(LoadablePackageType) :: pkg
366  integer(I4B) :: n
367  !
368  ! -- locate index of pkgtype in pkglist
369  do n = 1, size(this%pkglist)
370  pkg = this%pkglist(n)
371  if (pkg%pkgtype == pkgtype) then
372  call this%pkglist(n)%add(this%modelname, this%component_type, &
373  pkgtype, filename, pkgname, this%iout)
374  exit
375  end if
376  end do
377  !
378  ! -- return
379  return

◆ modelpkgs_addpkgs()

subroutine modelpackageinputsmodule::modelpkgs_addpkgs ( class(modelpackageinputstype this)
private

Definition at line 384 of file ModelPackageInputs.f90.

385  ! -- modules
387  ! -- dummy
388  class(ModelPackageInputsType) :: this
389  ! -- local
390  type(CharacterStringType), dimension(:), contiguous, &
391  pointer :: ftypes !< file types
392  type(CharacterStringType), dimension(:), contiguous, &
393  pointer :: fnames !< file names
394  type(CharacterStringType), dimension(:), contiguous, &
395  pointer :: pnames !< package names
396  character(len=LINELENGTH) :: ftype, fname, pname
397  integer(I4B) :: n
398  !
399  ! -- set pointers to input context model package attribute arrays
400  call mem_setptr(ftypes, 'FTYPE', this%input_mempath)
401  call mem_setptr(fnames, 'FNAME', this%input_mempath)
402  call mem_setptr(pnames, 'PNAME', this%input_mempath)
403  !
404  ! -- create the package list
405  call this%create(ftypes)
406  !
407  ! -- load model packages
408  do n = 1, size(ftypes)
409  !
410  ! -- attributes for this package
411  ftype = ftypes(n)
412  fname = fnames(n)
413  pname = pnames(n)
414  !
415  ! -- add this instance to package list
416  call this%add(ftype, fname, pname)
417  end do
418  !
419  ! --
420  return

◆ modelpkgs_create()

subroutine modelpackageinputsmodule::modelpkgs_create ( class(modelpackageinputstype this,
type(characterstringtype), dimension(:), pointer, contiguous  ftypes 
)

Definition at line 282 of file ModelPackageInputs.f90.

283  ! -- modules
284  use sortmodule, only: qsort
285  ! -- dummy
286  class(ModelPackageInputsType) :: this
287  type(CharacterStringType), dimension(:), contiguous, &
288  pointer :: ftypes
289  ! -- local
290  integer(I4B), dimension(:), allocatable :: cunit_idxs, indx
291  character(len=LENPACKAGETYPE) :: ftype
292  integer(I4B) :: n, m
293  logical(LGP) :: found
294  !
295  ! -- allocate
296  allocate (cunit_idxs(0))
297  !
298  ! -- identify input packages and check that each is supported
299  do n = 1, size(ftypes)
300  !
301  ! -- type from model nam file packages block
302  ftype = ftypes(n)
303  found = .false.
304  !
305  ! -- search supported types for this filetype
306  do m = 1, this%niunit
307  if (this%cunit(m) == ftype) then
308  ! -- set found
309  found = .true.
310  !
311  ! -- add to cunit list if first instance of this type
312  if (any(cunit_idxs == m)) then
313  ! no-op
314  else
315  call expandarray(cunit_idxs)
316  cunit_idxs(size(cunit_idxs)) = m
317  end if
318  !
319  ! -- exit search
320  exit
321  end if
322  end do
323  !
324  ! -- set error if namfile pkg filetype is not supported
325  if (.not. found) then
326  write (errmsg, '(a,a,a,a,a)') 'Model package type not supported &
327  &[model=', trim(this%modelname), ', type=', &
328  trim(ftype), '].'
329  call store_error(errmsg)
330  call store_error_filename(this%modelfname)
331  end if
332  end do
333  !
334  ! -- allocate the pkglist
335  allocate (this%pkglist(size(cunit_idxs)))
336  !
337  ! -- sort cunit indexes
338  allocate (indx(size(cunit_idxs)))
339  call qsort(indx, cunit_idxs)
340  !
341  ! -- create sorted LoadablePackageType object list
342  do n = 1, size(cunit_idxs)
343  call this%pkglist(n)%create(this%modeltype, this%modelname, &
344  this%cunit(cunit_idxs(n)))
345  end do
346  !
347  ! -- cleanup
348  deallocate (cunit_idxs)
349  deallocate (indx)
350  !
351  ! -- return
352  return
Here is the call graph for this function:

◆ modelpkgs_destroy()

subroutine modelpackageinputsmodule::modelpkgs_destroy ( class(modelpackageinputstype this)

Definition at line 514 of file ModelPackageInputs.f90.

515  ! -- modules
516  ! -- dummy
517  class(ModelPackageInputsType) :: this
518  ! -- local
519  integer(I4B) :: n
520  !
521  ! --
522  do n = 1, size(this%pkglist)
523  call this%pkglist(n)%destroy()
524  end do
525  !
526  deallocate (this%pkglist)
527  deallocate (this%cunit)
528  !
529  ! -- return
530  return

◆ modelpkgs_init()

subroutine modelpackageinputsmodule::modelpkgs_init ( class(modelpackageinputstype this,
character(len=*), intent(in)  modeltype,
character(len=*), intent(in)  modelfname,
character(len=*), intent(in)  modelname,
integer(i4b), intent(in)  iout 
)
private

Definition at line 234 of file ModelPackageInputs.f90.

235  ! -- modules
241  ! -- dummy
242  class(ModelPackageInputsType) :: this
243  character(len=*), intent(in) :: modeltype
244  character(len=*), intent(in) :: modelfname
245  character(len=*), intent(in) :: modelname
246  integer(I4B), intent(in) :: iout
247  ! -- local
248  !
249  ! -- initialize object
250  this%modeltype = modeltype
251  this%modelfname = modelfname
252  this%modelname = modelname
253  this%component_type = idm_component_type(modeltype)
254  this%iout = iout
255  !
256  ! -- allocate and set model supported package types
257  call supported_model_packages(modeltype, this%cunit, this%niunit)
258  !
259  ! -- set memory paths
260  this%input_mempath = create_mem_path(this%modelname, 'NAM', idm_context)
261  this%model_mempath = create_mem_path(component=this%modelname, &
262  context=idm_context)
263  !
264  ! -- allocate managed memory
265  call mem_allocate(this%pkgtypes, lenpackagetype, 0, 'PKGTYPES', &
266  this%model_mempath)
267  call mem_allocate(this%pkgnames, lenpackagename, 0, 'PKGNAMES', &
268  this%model_mempath)
269  call mem_allocate(this%mempaths, lenmempath, 0, 'MEMPATHS', &
270  this%model_mempath)
271  call mem_allocate(this%inunits, 0, 'INUNITS', this%model_mempath)
272  !
273  ! build descriptions of packages
274  call this%addpkgs()
275  !
276  ! -- return
277  return
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
This module contains the ModelPackageInputModule.
subroutine, public supported_model_packages(mtype, pkgtypes, numpkgs)
set supported package types for model
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=linelength) idm_context
This module contains the SourceCommonModule.
Definition: SourceCommon.f90:7
character(len=lencomponentname) function, public idm_component_type(component)
component from package or model type
Here is the call graph for this function:

◆ modelpkgs_memload()

subroutine modelpackageinputsmodule::modelpkgs_memload ( class(modelpackageinputstype this)
private

Definition at line 467 of file ModelPackageInputs.f90.

468  ! -- modules
470  ! -- dummy
471  class(ModelPackageInputsType) :: this
472  ! -- local
473  integer(I4B) :: n, m, idx
474  integer(I4B) :: pnum
475  !
476  ! -- initialize load index
477  idx = 0
478  !
479  ! -- set total number of package instances
480  pnum = this%pkgcount()
481  !
482  ! -- reallocate model input package attribute arrays
483  call mem_reallocate(this%pkgtypes, lenpackagetype, pnum, 'PKGTYPES', &
484  this%model_mempath)
485  call mem_reallocate(this%pkgnames, lenpackagename, pnum, 'PKGNAMES', &
486  this%model_mempath)
487  call mem_reallocate(this%mempaths, lenmempath, pnum, 'MEMPATHS', &
488  this%model_mempath)
489  call mem_reallocate(this%inunits, pnum, 'INUNITS', this%model_mempath)
490  !
491  ! -- load pkinfo
492  do n = 1, size(this%pkglist)
493  !
494  do m = 1, this%pkglist(n)%pnum
495  ! -- increment index
496  idx = idx + 1
497  ! -- package type like 'CHD6'
498  this%pkgtypes(idx) = trim(this%pkglist(n)%pkgtype)
499  ! -- package name like 'CHD-2'
500  this%pkgnames(idx) = trim(this%pkglist(n)%pkgnames(m))
501  ! -- memory path like '__INPUT__/MYMODEL/CHD-2'
502  this%mempaths(idx) = trim(this%pkglist(n)%mempaths(m))
503  ! -- input file unit number
504  this%inunits(idx) = this%pkglist(n)%inunits(m)
505  end do
506  end do
507  !
508  ! -- return
509  return

◆ modelpkgs_pkgcount()

integer(i4b) function modelpackageinputsmodule::modelpkgs_pkgcount ( class(modelpackageinputstype this)

Definition at line 425 of file ModelPackageInputs.f90.

426  ! -- modules
427  ! -- dummy
428  class(ModelPackageInputsType) :: this
429  !
430  ! -- return
431  integer(I4B) :: pnum
432  ! -- local
433  integer(I4B) :: n
434  !
435  ! -- initialize
436  pnum = 0
437  !
438  ! -- count model package instances
439  do n = 1, size(this%pkglist)
440  !
441  if (multi_pkg_type(this%component_type, &
442  this%pkglist(n)%subcomponent_type, &
443  this%pkglist(n)%pkgtype)) then
444  ! multiple instances ok
445  else
446  ! -- set error for unexpected extra packages
447  if (this%pkglist(n)%pnum > 1) then
448  write (errmsg, '(a,a,a,a,a)') &
449  'Multiple instances specified for model base package type &
450  &[model=', trim(this%modelname), ', type=', &
451  trim(this%pkglist(n)%pkgtype), '].'
452  call store_error(errmsg)
453  call store_error_filename(this%modelfname)
454  end if
455  end if
456  !
457  ! -- add to package count
458  pnum = pnum + this%pkglist(n)%pnum
459  end do
460  !
461  ! -- return
462  return
Here is the call graph for this function:

◆ multi_pkg_type()

logical(lgp) function modelpackageinputsmodule::multi_pkg_type ( character(len=lencomponentname), intent(in)  mtype_component,
character(len=lencomponentname), intent(in)  ptype_component,
character(len=lenftype), intent(in)  pkgtype 
)
private

Definition at line 92 of file ModelPackageInputs.f90.

94  ! -- modules
97  ! -- dummy
98  character(len=LENCOMPONENTNAME), intent(in) :: mtype_component
99  character(len=LENCOMPONENTNAME), intent(in) :: ptype_component
100  character(len=LENFTYPE), intent(in) :: pkgtype
101  ! -- return
102  logical(LGP) :: multi_pkg
103  ! -- local
104  !
105  multi_pkg = .false.
106  !
107  if (idm_integrated(mtype_component, ptype_component)) then
108  multi_pkg = idm_multi_package(mtype_component, ptype_component)
109  !
110  else
111  multi_pkg = multi_package_type(mtype_component, ptype_component, pkgtype)
112  !
113  end if
114  !
115  ! -- return
116  return
logical function, public idm_integrated(component, subcomponent)
logical function, public idm_multi_package(component, subcomponent)
logical(lgp) function, public multi_package_type(mtype_component, ptype_component, pkgtype)
Is the package multi-instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pkgtype_add()

subroutine modelpackageinputsmodule::pkgtype_add ( class(loadablepackagetype this,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  mtype_component,
character(len=*), intent(in)  filetype,
character(len=*), intent(in)  filename,
character(len=*), intent(in)  pkgname,
integer(i4b), intent(in)  iout 
)

Definition at line 148 of file ModelPackageInputs.f90.

150  ! -- modules
157  ! -- dummy
158  class(LoadablePackageType) :: this
159  character(len=*), intent(in) :: modelname
160  character(len=*), intent(in) :: mtype_component
161  character(len=*), intent(in) :: filetype
162  character(len=*), intent(in) :: filename
163  character(len=*), intent(in) :: pkgname
164  integer(I4B), intent(in) :: iout
165  ! -- local
166  character(len=LENPACKAGENAME) :: sc_name, pname
167  character(len=LENMEMPATH) :: mempath
168  character(len=LINELENGTH), pointer :: cstr
169  !
170  ! -- reallocate
171  call expandarray(this%filenames)
172  call expandarray(this%pkgnames)
173  call expandarray(this%inunits)
174  call expandarray(this%mempaths)
175  !
176  ! -- add new package instance
177  this%pnum = this%pnum + 1
178  this%filenames(this%pnum) = filename
179  this%pkgnames(this%pnum) = pkgname
180  this%inunits(this%pnum) = 0
181  !
182  ! -- set pkgname if empty
183  if (this%pkgnames(this%pnum) == '') then
184  write (pname, '(a,i0)') trim(this%subcomponent_type)//'-', this%pnum
185  this%pkgnames(this%pnum) = pname
186  end if
187  !
188  ! -- set up input context for model
189  if (idm_integrated(mtype_component, this%subcomponent_type)) then
190  !
191  ! -- set subcomponent name
192  sc_name = idm_subcomponent_name(mtype_component, this%subcomponent_type, &
193  this%pkgnames(this%pnum))
194  !
195  ! -- create and store the mempath
196  this%mempaths(this%pnum) = &
197  create_mem_path(modelname, sc_name, idm_context)
198  !
199  ! -- allocate and initialize filename for package
200  mempath = create_mem_path(modelname, sc_name, idm_context)
201  call mem_allocate(cstr, linelength, 'INPUT_FNAME', mempath)
202  cstr = filename
203  !
204  else
205  !
206  ! -- set mempath empty
207  this%mempaths(this%pnum) = ''
208  end if
209  !
210  ! -- return
211  return
character(len=lenpackagename) function, public idm_subcomponent_name(component_type, subcomponent_type, sc_name)
model package subcomponent name
Here is the call graph for this function:

◆ pkgtype_create()

subroutine modelpackageinputsmodule::pkgtype_create ( class(loadablepackagetype this,
character(len=*), intent(in)  modeltype,
character(len=*), intent(in)  modelname,
character(len=*), intent(in)  pkgtype 
)

Definition at line 121 of file ModelPackageInputs.f90.

122  ! -- modules
124  ! -- dummy
125  class(LoadablePackageType) :: this
126  character(len=*), intent(in) :: modeltype
127  character(len=*), intent(in) :: modelname
128  character(len=*), intent(in) :: pkgtype
129  ! -- local
130  !
131  ! -- initialize
132  this%pkgtype = pkgtype
133  this%subcomponent_type = idm_subcomponent_type(modeltype, pkgtype)
134  this%pnum = 0
135  !
136  ! -- allocate arrays
137  allocate (this%filenames(0))
138  allocate (this%pkgnames(0))
139  allocate (this%mempaths(0))
140  allocate (this%inunits(0))
141  !
142  ! -- return
143  return
character(len=lencomponentname) function, public idm_subcomponent_type(component, subcomponent)
component from package or model type
Here is the call graph for this function:

◆ pkgtype_destroy()

subroutine modelpackageinputsmodule::pkgtype_destroy ( class(loadablepackagetype this)

Definition at line 216 of file ModelPackageInputs.f90.

217  ! -- modules
218  ! -- dummy
219  class(LoadablePackageType) :: this
220  ! -- local
221  !
222  ! -- deallocate dynamic arrays
223  deallocate (this%filenames)
224  deallocate (this%pkgnames)
225  deallocate (this%inunits)
226  deallocate (this%mempaths)
227  !
228  ! -- return
229  return