MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
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
logical(lgp) function, public supported_model (ctype)
 is this a supported MODFLOW 6 model type
subroutine pkgtype_create (this, modeltype, modelname, pkgtype)
 create a new package type
subroutine pkgtype_add (this, modelname, mtype_component, filetype, filename, pkgname, iout)
 add a new package instance to this package type
subroutine pkgtype_destroy (this)
 deallocate object
subroutine modelpkgs_init (this, modeltype, modelfname, modelname, iout)
 initialize model package inputs object
subroutine modelpkgs_create (this, ftypes)
 create the package type list
subroutine modelpkgs_add (this, pkgtype, filename, pkgname)
 add a model package instance to package type list
subroutine modelpkgs_addpkgs (this)
 build the type list with all model package instances
integer(i4b) function modelpkgs_pkgcount (this)
 get package instance count and verify base or multi of each
subroutine modelpkgs_memload (this)
 load package descriptors to managed memory
subroutine modelpkgs_destroy (this)
 deallocate object

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 )
private

Definition at line 353 of file ModelPackageInputs.f90.

354 class(ModelPackageInputsType) :: this
355 character(len=*), intent(in) :: pkgtype
356 character(len=*), intent(in) :: filename
357 character(len=*), intent(in) :: pkgname
358 type(LoadablePackageType) :: pkg
359 integer(I4B) :: n
360 ! locate index of pkgtype in pkglist
361 do n = 1, size(this%pkglist)
362 pkg = this%pkglist(n)
363 if (pkg%pkgtype == pkgtype) then
364 call this%pkglist(n)%add(this%modelname, this%component_type, &
365 pkgtype, filename, pkgname, this%iout)
366 exit
367 end if
368 end do

◆ modelpkgs_addpkgs()

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

Definition at line 373 of file ModelPackageInputs.f90.

376 class(ModelPackageInputsType) :: this
377 type(CharacterStringType), dimension(:), contiguous, &
378 pointer :: ftypes !< file types
379 type(CharacterStringType), dimension(:), contiguous, &
380 pointer :: fnames !< file names
381 type(CharacterStringType), dimension(:), contiguous, &
382 pointer :: pnames !< package names
383 character(len=LINELENGTH) :: ftype, fname, pname
384 integer(I4B) :: n
385
386 ! set pointers to input context model package attribute arrays
387 call mem_setptr(ftypes, 'FTYPE', this%input_mempath)
388 call mem_setptr(fnames, 'FNAME', this%input_mempath)
389 call mem_setptr(pnames, 'PNAME', this%input_mempath)
390
391 ! create the package list
392 call this%create(ftypes)
393
394 ! load model packages
395 do n = 1, size(ftypes)
396 ! attributes for this package
397 ftype = ftypes(n)
398 fname = fnames(n)
399 call inlen_check(pnames(n), pname, lenpackagename, 'PACKAGENAME')
400
401 ! add this instance to package list
402 call this%add(ftype, fname, pname)
403 end do
404
405 ! terminate if errors were detected
406 if (count_errors() > 0) then
407 call store_error_filename(this%modelfname)
408 end if
This module contains the SourceCommonModule.
subroutine, public inlen_check(input_name, mf6_name, maxlen, name_type)
store an error for input exceeding internal name length
Here is the call graph for this function:

◆ modelpkgs_create()

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

Definition at line 272 of file ModelPackageInputs.f90.

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

◆ modelpkgs_destroy()

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

Definition at line 486 of file ModelPackageInputs.f90.

487 class(ModelPackageInputsType) :: this
488 integer(I4B) :: n
489 do n = 1, size(this%pkglist)
490 call this%pkglist(n)%destroy()
491 end do
492 deallocate (this%pkglist)
493 deallocate (this%cunit)

◆ 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 222 of file ModelPackageInputs.f90.

228 class(ModelPackageInputsType) :: this
229 character(len=*), intent(in) :: modeltype
230 character(len=*), intent(in) :: modelfname
231 character(len=*), intent(in) :: modelname
232 integer(I4B), intent(in) :: iout
233
234 ! initialize object
235 this%modeltype = modeltype
236 this%modelfname = modelfname
237 this%modelname = modelname
238 this%component_type = idm_component_type(modeltype)
239 this%iout = iout
240
241 ! verify user specified model type
242 if (.not. supported_model(modeltype)) then
243 ! -- error and exit for unsupported model type
244 write (errmsg, '(3a)') 'Models block model type "', trim(modeltype), &
245 '" is not valid.'
246 call store_error(errmsg)
247 call store_error_filename(simfile)
248 end if
249
250 ! allocate and set model supported package types
251 call supported_model_packages(modeltype, this%cunit, this%niunit)
252
253 ! set memory paths
254 this%input_mempath = create_mem_path(this%modelname, 'NAM', idm_context)
255 this%model_mempath = create_mem_path(component=this%modelname, &
256 context=idm_context)
257 ! allocate managed memory
258 call mem_allocate(this%pkgtypes, lenpackagetype, 0, 'PKGTYPES', &
259 this%model_mempath)
260 call mem_allocate(this%pkgnames, lenpackagename, 0, 'PKGNAMES', &
261 this%model_mempath)
262 call mem_allocate(this%mempaths, lenmempath, 0, 'MEMPATHS', &
263 this%model_mempath)
264 call mem_allocate(this%inunits, 0, 'INUNITS', this%model_mempath)
265
266 ! build descriptions of packages
267 call this%addpkgs()
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.
character(len=maxcharlen) errmsg
error message string
character(len=linelength) idm_context
integer(i4b) iout
file unit number for simulation output
character(len=linelength) simfile
simulation name file
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 446 of file ModelPackageInputs.f90.

448 class(ModelPackageInputsType) :: this
449 integer(I4B) :: n, m, idx
450 integer(I4B) :: pnum
451
452 ! initialize load index
453 idx = 0
454
455 ! set total number of package instances
456 pnum = this%pkgcount()
457
458 ! reallocate model input package attribute arrays
459 call mem_reallocate(this%pkgtypes, lenpackagetype, pnum, 'PKGTYPES', &
460 this%model_mempath)
461 call mem_reallocate(this%pkgnames, lenpackagename, pnum, 'PKGNAMES', &
462 this%model_mempath)
463 call mem_reallocate(this%mempaths, lenmempath, pnum, 'MEMPATHS', &
464 this%model_mempath)
465 call mem_reallocate(this%inunits, pnum, 'INUNITS', this%model_mempath)
466
467 ! load pkinfo
468 do n = 1, size(this%pkglist)
469 do m = 1, this%pkglist(n)%pnum
470 ! increment index
471 idx = idx + 1
472 ! package type like 'CHD6'
473 this%pkgtypes(idx) = trim(this%pkglist(n)%pkgtype)
474 ! package name like 'CHD-2'
475 this%pkgnames(idx) = trim(this%pkglist(n)%pkgnames(m))
476 ! memory path like '__INPUT__/MYMODEL/CHD-2'
477 this%mempaths(idx) = trim(this%pkglist(n)%mempaths(m))
478 ! input file unit number
479 this%inunits(idx) = this%pkglist(n)%inunits(m)
480 end do
481 end do

◆ modelpkgs_pkgcount()

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

Definition at line 413 of file ModelPackageInputs.f90.

414 class(ModelPackageInputsType) :: this
415 integer(I4B) :: pnum
416 integer(I4B) :: n
417
418 ! initialize
419 pnum = 0
420
421 ! count model package instances
422 do n = 1, size(this%pkglist)
423 if (multi_pkg_type(this%component_type, &
424 this%pkglist(n)%subcomponent_type, &
425 this%pkglist(n)%pkgtype)) then
426 ! multiple instances ok
427 else
428 ! set error for unexpected extra packages
429 if (this%pkglist(n)%pnum > 1) then
430 write (errmsg, '(a,a,a,a,a)') &
431 'Multiple instances specified for model base package type &
432 &[model=', trim(this%modelname), ', type=', &
433 trim(this%pkglist(n)%pkgtype), '].'
434 call store_error(errmsg)
435 call store_error_filename(this%modelfname)
436 end if
437 end if
438
439 ! add to package count
440 pnum = pnum + this%pkglist(n)%pnum
441 end do
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 )

Definition at line 93 of file ModelPackageInputs.f90.

97 character(len=LENCOMPONENTNAME), intent(in) :: mtype_component
98 character(len=LENCOMPONENTNAME), intent(in) :: ptype_component
99 character(len=LENFTYPE), intent(in) :: pkgtype
100 logical(LGP) :: multi_pkg
101 multi_pkg = .false.
102 if (idm_integrated(mtype_component, ptype_component)) then
103 multi_pkg = idm_multi_package(mtype_component, ptype_component)
104 else
105 multi_pkg = multi_package_type(mtype_component, ptype_component, pkgtype)
106 end if
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 )
private

Definition at line 148 of file ModelPackageInputs.f90.

155 class(LoadablePackageType) :: this
156 character(len=*), intent(in) :: modelname
157 character(len=*), intent(in) :: mtype_component
158 character(len=*), intent(in) :: filetype
159 character(len=*), intent(in) :: filename
160 character(len=*), intent(in) :: pkgname
161 integer(I4B), intent(in) :: iout
162 character(len=LENPACKAGENAME) :: sc_name, pname
163 character(len=LENMEMPATH) :: mempath
164 character(len=LINELENGTH), pointer :: cstr
165
166 ! reallocate
167 call expandarray(this%filenames)
168 call expandarray(this%pkgnames)
169 call expandarray(this%inunits)
170 call expandarray(this%mempaths)
171
172 ! add new package instance
173 this%pnum = this%pnum + 1
174 this%filenames(this%pnum) = filename
175 this%pkgnames(this%pnum) = pkgname
176 this%inunits(this%pnum) = 0
177
178 ! set pkgname if empty
179 if (this%pkgnames(this%pnum) == '') then
180 if (multi_pkg_type(mtype_component, &
181 this%subcomponent_type, &
182 filetype)) then
183 pname = idm_pkg_instance_name(this%subcomponent_type, &
184 this%pnum)
185 else
186 write (pname, '(a)') trim(this%subcomponent_type)
187 end if
188 this%pkgnames(this%pnum) = pname
189 end if
190
191 ! set up input context for model
192 if (idm_integrated(mtype_component, this%subcomponent_type)) then
193 ! set subcomponent name
194 sc_name = idm_subcomponent_name(mtype_component, this%subcomponent_type, &
195 this%pkgnames(this%pnum))
196 ! create and store the mempath
197 this%mempaths(this%pnum) = &
198 create_mem_path(modelname, sc_name, idm_context)
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 else
204 ! set mempath empty
205 this%mempaths(this%pnum) = ''
206 end if
character(len=lenpackagename) function, public idm_pkg_instance_name(pkg_type, inst)
default name for a multi-package instance
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 )
private

Definition at line 127 of file ModelPackageInputs.f90.

129 class(LoadablePackageType) :: this
130 character(len=*), intent(in) :: modeltype
131 character(len=*), intent(in) :: modelname
132 character(len=*), intent(in) :: pkgtype
133
134 ! initialize
135 this%pkgtype = pkgtype
136 this%subcomponent_type = idm_subcomponent_type(modeltype, pkgtype)
137 this%pnum = 0
138
139 ! allocate arrays
140 allocate (this%filenames(0))
141 allocate (this%pkgnames(0))
142 allocate (this%mempaths(0))
143 allocate (this%inunits(0))
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)
private

Definition at line 211 of file ModelPackageInputs.f90.

212 class(LoadablePackageType) :: this
213 ! deallocate dynamic arrays
214 deallocate (this%filenames)
215 deallocate (this%pkgnames)
216 deallocate (this%inunits)
217 deallocate (this%mempaths)

◆ supported_model()

logical(lgp) function, public modelpackageinputsmodule::supported_model ( character(len=*), intent(in) ctype)

Definition at line 111 of file ModelPackageInputs.f90.

113 character(len=*), intent(in) :: ctype
114 logical(LGP) :: supported_model
115 integer(I4B) :: n
116 supported_model = .false.
117 do n = 1, nmodel
118 if (ctype == modflow6models(n)) then
119 supported_model = .true.
120 exit
121 end if
122 end do
integer(i4b), parameter, public nmodel
Valid simulation model types.
character(len=lenpackagetype), dimension(nmodel), public modflow6models
Here is the call graph for this function:
Here is the caller graph for this function: