MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
InputLoadType.f90
Go to the documentation of this file.
1 !> @brief This module contains the InputLoadTypeModule
2 !!
3 !! This module defines types that support generic IDM
4 !! static and dynamic input loading.
5 !!
6 !<
8 
9  use kindmodule, only: dp, i4b, lgp
11  use simvariablesmodule, only: errmsg
14  use listmodule, only: listtype
16 
17  implicit none
18  private
19  public :: staticpkgloadbasetype
20  public :: dynamicpkgloadbasetype
21  public :: modeldynamicpkgstype
24 
25  !> @brief Static loader type
26  !!
27  !! This type is a base concrete type for a static input loader
28  !!
29  !<
31  type(modflowinputtype) :: mf6_input !< description of modflow6 input
32  character(len=LENCOMPONENTNAME) :: component_name !< name of component
33  character(len=LINELENGTH) :: component_input_name !< component input name, e.g. model name file
34  character(len=LINELENGTH) :: input_name !< input name, e.g. package *.chd file
35  integer(I4B) :: iperblock !< index of period block on block definition list
36  contains
37  procedure :: init => static_init
38  procedure :: destroy => static_destroy
39  end type staticpkgloadtype
40 
41  !> @brief Base abstract type for static input loader
42  !!
43  !! IDM sources should extend and implement this type
44  !!
45  !<
46  type, abstract, extends(staticpkgloadtype) :: staticpkgloadbasetype
47  contains
48  procedure(load_if), deferred :: load
49  end type staticpkgloadbasetype
50 
51  !> @brief Dynamic loader type
52  !!
53  !! This type is a base concrete type for a dynamic (period) input loader
54  !!
55  !<
57  type(modflowinputtype) :: mf6_input !< description of modflow6 input
58  character(len=LENCOMPONENTNAME) :: component_name !< name of component
59  character(len=LINELENGTH) :: component_input_name !< component input name, e.g. model name file
60  character(len=LINELENGTH) :: input_name !< input name, e.g. package *.chd file
61  character(len=LINELENGTH), dimension(:), allocatable :: param_names !< dynamic param tagnames
62  logical(LGP) :: readasarrays !< is this array based input
63  integer(I4B) :: iperblock !< index of period block on block definition list
64  integer(I4B) :: iout !< inunit number for logging
65  integer(I4B) :: nparam !< number of in scope params
66  contains
67  procedure :: init => dynamic_init
68  procedure :: df => dynamic_df
69  procedure :: ad => dynamic_ad
70  procedure :: destroy => dynamic_destroy
71  end type dynamicpkgloadtype
72 
73  !> @brief Base abstract type for dynamic input loader
74  !!
75  !! IDM sources should extend and implement this type
76  !!
77  !<
78  type, abstract, extends(dynamicpkgloadtype) :: dynamicpkgloadbasetype
79  contains
80  procedure(period_load_if), deferred :: rp
81  end type dynamicpkgloadbasetype
82 
83  !> @brief load interfaces for source static and dynamic types
84  !<
85  abstract interface
86  function load_if(this, iout) result(dynamic_loader)
88  class(staticpkgloadbasetype), intent(inout) :: this
89  integer(I4B), intent(in) :: iout
90  class(dynamicpkgloadbasetype), pointer :: dynamic_loader
91  end function load_if
92  subroutine period_load_if(this)
93  import dynamicpkgloadbasetype, i4b
94  class(dynamicpkgloadbasetype), intent(inout) :: this
95  end subroutine
96  end interface
97 
98  !> @brief type for storing a dynamic package load list
99  !!
100  !! This type is used to store a list of package
101  !! dynamic load types for a model
102  !!
103  !<
105  character(len=LENMODELNAME) :: modelname !< name of model
106  character(len=LINELENGTH) :: modelfname !< name of model input file
107  type(listtype) :: pkglist !< list of pointers to model dynamic package loaders
108  integer(I4B) :: iout
109  contains
110  procedure :: init => dynamicpkgs_init
111  procedure :: add => dynamicpkgs_add
112  procedure :: get => dynamicpkgs_get
113  procedure :: rp => dynamicpkgs_rp
114  procedure :: df => dynamicpkgs_df
115  procedure :: ad => dynamicpkgs_ad
116  procedure :: size => dynamicpkgs_size
117  procedure :: destroy => dynamicpkgs_destroy
118  end type modeldynamicpkgstype
119 
120 contains
121 
122  !> @brief initialize static package loader
123  !!
124  !<
125  subroutine static_init(this, mf6_input, component_name, component_input_name, &
126  input_name)
127  class(staticpkgloadtype), intent(inout) :: this
128  type(modflowinputtype), intent(in) :: mf6_input
129  character(len=*), intent(in) :: component_name
130  character(len=*), intent(in) :: component_input_name
131  character(len=*), intent(in) :: input_name
132  integer(I4B) :: iblock
133  !
134  this%mf6_input = mf6_input
135  this%component_name = component_name
136  this%component_input_name = component_input_name
137  this%input_name = input_name
138  this%iperblock = 0
139  !
140  ! -- identify period block definition
141  do iblock = 1, size(mf6_input%block_dfns)
142  !
143  if (mf6_input%block_dfns(iblock)%blockname == 'PERIOD') then
144  this%iperblock = iblock
145  exit
146  end if
147  end do
148  !
149  return
150  end subroutine static_init
151 
152  subroutine static_destroy(this)
153  class(staticpkgloadtype), intent(inout) :: this
154  !
155  return
156  end subroutine static_destroy
157 
158  !> @brief initialize dynamic package loader
159  !!
160  !! Any managed memory pointed to from model/package context
161  !! must be allocated when dynamic loader is initialized.
162  !!
163  !<
164  subroutine dynamic_init(this, mf6_input, component_name, component_input_name, &
165  input_name, iperblock, iout)
166  use simvariablesmodule, only: errmsg
168  ! -- dummy
169  class(dynamicpkgloadtype), intent(inout) :: this
170  type(modflowinputtype), intent(in) :: mf6_input
171  character(len=*), intent(in) :: component_name
172  character(len=*), intent(in) :: component_input_name
173  character(len=*), intent(in) :: input_name
174  integer(I4B), intent(in) :: iperblock
175  integer(I4B), intent(in) :: iout
176  type(inputparamdefinitiontype), pointer :: idt
177  !
178  this%mf6_input = mf6_input
179  this%component_name = component_name
180  this%component_input_name = component_input_name
181  this%input_name = input_name
182  this%iperblock = iperblock
183  this%nparam = 0
184  this%iout = iout
185  nullify (idt)
186  !
187  ! -- throw error and exit if not found
188  if (this%iperblock == 0) then
189  write (errmsg, '(a,a)') &
190  'Programming error. (IDM) PERIOD block not found in '&
191  &'dynamic package input block dfns: ', &
192  trim(mf6_input%subcomponent_name)
193  call store_error(errmsg)
194  call store_error_filename(this%input_name)
195  end if
196  !
197  ! -- set readasarrays
198  this%readasarrays = (.not. mf6_input%block_dfns(iperblock)%aggregate)
199  !
200  ! -- return
201  return
202  end subroutine dynamic_init
203 
204  !> @brief dynamic package loader define
205  !!
206  !<
207  subroutine dynamic_df(this)
208  class(dynamicpkgloadtype), intent(inout) :: this
209  !
210  ! override in derived type
211  !
212  return
213  end subroutine dynamic_df
214 
215  !> @brief dynamic package loader advance
216  !!
217  !<
218  subroutine dynamic_ad(this)
219  class(dynamicpkgloadtype), intent(inout) :: this
220  !
221  ! override in derived type
222  !
223  return
224  end subroutine dynamic_ad
225 
226  !> @brief dynamic package loader destroy
227  !!
228  !<
229  subroutine dynamic_destroy(this)
233  class(dynamicpkgloadtype), intent(inout) :: this
234  !
235  ! -- deallocate package static and dynamic input context
236  call memorylist_remove(this%mf6_input%component_name, &
237  this%mf6_input%subcomponent_name, &
238  idm_context)
239  !
240  return
241  end subroutine dynamic_destroy
242 
243  !> @brief model dynamic packages init
244  !!
245  !<
246  subroutine dynamicpkgs_init(this, modelname, modelfname, iout)
247  class(modeldynamicpkgstype), intent(inout) :: this
248  character(len=*), intent(in) :: modelname
249  character(len=*), intent(in) :: modelfname
250  integer(I4B), intent(in) :: iout
251  !
252  this%modelname = modelname
253  this%modelfname = modelfname
254  this%iout = iout
255  !
256  return
257  end subroutine dynamicpkgs_init
258 
259  !> @brief add package to model dynamic packages list
260  !!
261  !<
262  subroutine dynamicpkgs_add(this, dynamic_pkg)
263  class(modeldynamicpkgstype), intent(inout) :: this
264  class(dynamicpkgloadbasetype), pointer, intent(inout) :: dynamic_pkg
265  class(*), pointer :: obj
266  !
267  obj => dynamic_pkg
268  call this%pkglist%add(obj)
269  !
270  return
271  end subroutine dynamicpkgs_add
272 
273  !> @brief retrieve package from model dynamic packages list
274  !!
275  !<
276  function dynamicpkgs_get(this, idx) result(res)
277  class(modeldynamicpkgstype), intent(inout) :: this
278  integer(I4B), intent(in) :: idx
279  class(dynamicpkgloadbasetype), pointer :: res
280  class(*), pointer :: obj
281  !
282  nullify (res)
283  obj => this%pkglist%GetItem(idx)
284  !
285  if (associated(obj)) then
286  select type (obj)
287  class is (dynamicpkgloadbasetype)
288  res => obj
289  end select
290  end if
291  !
292  return
293  end function dynamicpkgs_get
294 
295  !> @brief read and prepare model dynamic packages
296  !!
297  !<
298  subroutine dynamicpkgs_rp(this)
300  class(modeldynamicpkgstype), intent(inout) :: this
301  class(dynamicpkgloadbasetype), pointer :: dynamic_pkg
302  integer(I4B) :: n
303  !
304  call idm_log_period_header(this%modelname, this%iout)
305  !
306  do n = 1, this%pkglist%Count()
307  dynamic_pkg => this%get(n)
308  call dynamic_pkg%rp()
309  end do
310  !
311  call idm_log_period_close(this%iout)
312  !
313  return
314  end subroutine dynamicpkgs_rp
315 
316  !> @brief define model dynamic packages
317  !!
318  !<
319  subroutine dynamicpkgs_df(this)
320  class(modeldynamicpkgstype), intent(inout) :: this
321  class(dynamicpkgloadbasetype), pointer :: dynamic_pkg
322  integer(I4B) :: n
323  !
324  do n = 1, this%pkglist%Count()
325  dynamic_pkg => this%get(n)
326  call dynamic_pkg%df()
327  end do
328  !
329  return
330  end subroutine dynamicpkgs_df
331 
332  !> @brief advance model dynamic packages
333  !!
334  !<
335  subroutine dynamicpkgs_ad(this)
336  class(modeldynamicpkgstype), intent(inout) :: this
337  class(dynamicpkgloadbasetype), pointer :: dynamic_pkg
338  integer(I4B) :: n
339  !
340  do n = 1, this%pkglist%Count()
341  dynamic_pkg => this%get(n)
342  call dynamic_pkg%ad()
343  end do
344  !
345  return
346  end subroutine dynamicpkgs_ad
347 
348  !> @brief get size of model dynamic packages list
349  !!
350  !<
351  function dynamicpkgs_size(this) result(size)
352  class(modeldynamicpkgstype), intent(inout) :: this
353  integer(I4B) :: size
354  !
355  size = this%pkglist%Count()
356  !
357  return
358  end function dynamicpkgs_size
359 
360  !> @brief destroy model dynamic packages object
361  !!
362  !<
363  subroutine dynamicpkgs_destroy(this)
364  class(modeldynamicpkgstype), intent(inout) :: this
365  class(dynamicpkgloadbasetype), pointer :: dynamic_pkg
366  integer(I4B) :: n
367  !
368  do n = 1, this%pkglist%Count()
369  dynamic_pkg => this%get(n)
370  call dynamic_pkg%destroy()
371  deallocate (dynamic_pkg)
372  nullify (dynamic_pkg)
373  end do
374  !
375  call this%pkglist%Clear()
376  !
377  return
378  end subroutine dynamicpkgs_destroy
379 
380  !> @brief add model dynamic packages object to list
381  !!
382  !<
383  subroutine adddynamicmodeltolist(list, model_dynamic)
384  ! -- dummy variables
385  type(listtype), intent(inout) :: list !< package list
386  class(modeldynamicpkgstype), pointer, intent(inout) :: model_dynamic
387  ! -- local variables
388  class(*), pointer :: obj
389  !
390  obj => model_dynamic
391  call list%Add(obj)
392  !
393  ! -- return
394  return
395  end subroutine adddynamicmodeltolist
396 
397  !> @brief get model dynamic packages object from list
398  !!
399  !<
400  function getdynamicmodelfromlist(list, idx) result(res)
401  ! -- dummy variables
402  type(listtype), intent(inout) :: list !< spd list
403  integer(I4B), intent(in) :: idx !< package number
404  class(modeldynamicpkgstype), pointer :: res
405  ! -- local variables
406  class(*), pointer :: obj
407  !
408  ! -- initialize res
409  nullify (res)
410  !
411  ! -- get the object from the list
412  obj => list%GetItem(idx)
413  if (associated(obj)) then
414  select type (obj)
415  class is (modeldynamicpkgstype)
416  res => obj
417  end select
418  end if
419  !
420  ! -- return
421  return
422  end function getdynamicmodelfromlist
423 
424 end module inputloadtypemodule
subroutine init()
Definition: GridSorting.f90:24
load interfaces for source static and dynamic types
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 lencomponentname
maximum length of a component name
Definition: Constants.f90:18
integer(i4b), parameter lenmodelname
maximum length of the model name
Definition: Constants.f90:21
This module contains the Input Data Model Logger Module.
Definition: IdmLogger.f90:7
subroutine, public idm_log_period_header(component, iout)
@ brief log a dynamic header message
Definition: IdmLogger.f90:69
subroutine, public idm_log_period_close(iout)
@ brief log the period closing message
Definition: IdmLogger.f90:82
This module contains the InputDefinitionModule.
This module contains the InputLoadTypeModule.
subroutine dynamic_ad(this)
dynamic package loader advance
subroutine static_init(this, mf6_input, component_name, component_input_name, input_name)
initialize static package loader
class(modeldynamicpkgstype) function, pointer, public getdynamicmodelfromlist(list, idx)
get model dynamic packages object from list
integer(i4b) function dynamicpkgs_size(this)
get size of model dynamic packages list
subroutine dynamic_init(this, mf6_input, component_name, component_input_name, input_name, iperblock, iout)
initialize dynamic package loader
subroutine, public adddynamicmodeltolist(list, model_dynamic)
add model dynamic packages object to list
subroutine dynamicpkgs_add(this, dynamic_pkg)
add package to model dynamic packages list
subroutine dynamicpkgs_rp(this)
read and prepare model dynamic packages
subroutine dynamicpkgs_init(this, modelname, modelfname, iout)
model dynamic packages init
subroutine static_destroy(this)
subroutine dynamicpkgs_destroy(this)
destroy model dynamic packages object
class(dynamicpkgloadbasetype) function, pointer dynamicpkgs_get(this, idx)
retrieve package from model dynamic packages list
subroutine dynamicpkgs_ad(this)
advance model dynamic packages
subroutine dynamic_destroy(this)
dynamic package loader destroy
subroutine dynamic_df(this)
dynamic package loader define
subroutine dynamicpkgs_df(this)
define model dynamic packages
This module defines variable data types.
Definition: kind.f90:8
subroutine, public memorylist_remove(component, subcomponent, context)
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
character(len=linelength) idm_context
Base abstract type for dynamic input loader.
type for storing a dynamic package load list
Base abstract type for static input loader.
A generic heterogeneous doubly-linked list.
Definition: List.f90:10
derived type for storing input definition for a file