MODFLOW 6  version 6.5.0.dev2
MODFLOW 6 Code Documentation
SourceLoad.F90
Go to the documentation of this file.
1 !> @brief This module contains the SourceLoadModule
2 !!
3 !! This module contains the routines needed to generate
4 !! a loader object for an input source and routines
5 !! that distribute processing to a particular source.
6 !!
7 !<
9 
10  use kindmodule, only: dp, i4b, lgp
11  use simvariablesmodule, only: errmsg
16 
17  implicit none
18  private
19  public :: create_input_loader
20  public :: open_source_file
22  public :: remote_model_ndim
23 
24 contains
25 
26  !> @brief factory function to create and setup model package static loader
27  !<
28  function create_input_loader(component_type, subcomponent_type, &
29  component_name, subcomponent_name, input_type, &
30  input_fname, component_fname) result(loader)
33  character(len=*), intent(in) :: component_type
34  character(len=*), intent(in) :: subcomponent_type
35  character(len=*), intent(in) :: component_name
36  character(len=*), intent(in) :: subcomponent_name
37  character(len=*), intent(in) :: input_type
38  character(len=*), intent(in) :: input_fname
39  character(len=*), intent(in) :: component_fname
40  class(staticpkgloadbasetype), pointer :: loader
41  type(modflowinputtype) :: mf6_input
42  character(len=LENPACKAGENAME) :: source_type
43  character(len=LENPACKAGENAME) :: sc_name
44  !
45  ! -- set subcomponent name
46  sc_name = idm_subcomponent_name(component_type, subcomponent_type, &
47  subcomponent_name)
48  !
49  ! -- create description of input
50  mf6_input = getmodflowinput(input_type, component_type, subcomponent_type, &
51  component_name, sc_name, input_fname)
52  !
53  ! -- set package source
54  source_type = package_source_type(input_fname)
55  !
56  ! -- set source loader for model package
57  loader => package_loader(source_type)
58  !
59  ! -- initialize loader
60  call loader%init(mf6_input, component_name, component_fname, input_fname)
61  !
62  ! -- return
63  return
64  end function create_input_loader
65 
66  !> @brief allocate source model package static loader
67  !<
68  function package_loader(source_type) result(loader)
71  character(len=*), intent(inout) :: source_type
72  class(mf6filestaticpkgloadtype), pointer :: mf6file_loader
73  class(staticpkgloadbasetype), pointer :: loader
74  !
75  ! -- initialize
76  nullify (loader)
77  !
78  ! -- allocate derived object
79  select case (source_type)
80  case ('MF6FILE')
81  allocate (mf6file_loader)
82  loader => mf6file_loader
83  case default
84  write (errmsg, '(a)') &
85  'Simulation package input source type "'//trim(source_type)// &
86  '" not currently supported.'
87  call store_error(errmsg, .true.)
88  end select
89  !
90  ! -- return
91  return
92  end function package_loader
93 
94  function open_source_file(pkgtype, filename, modelfname, iout) result(fd)
97  character(len=*), intent(in) :: pkgtype
98  character(len=*), intent(in) :: filename
99  character(len=*), intent(in) :: modelfname
100  integer(I4B), intent(in) :: iout
101  integer(I4B) :: fd
102  character(len=LENPACKAGENAME) :: source_type
103  !
104  ! -- initialize
105  fd = 0
106  !
107  ! -- set source type
108  source_type = package_source_type(filename)
109  !
110  select case (source_type)
111  case ('MF6FILE')
112  fd = open_mf6file(pkgtype, filename, modelfname, iout)
113  case default
114  end select
115  !
116  ! -- return
117  return
118  end function open_source_file
119 
120  subroutine load_modelnam(mtype, mfname, mname, iout)
121  use simvariablesmodule, only: simfile
123  use idmmf6filemodule, only: input_load
124  character(len=*), intent(in) :: mtype
125  character(len=*), intent(in) :: mfname
126  character(len=*), intent(in) :: mname
127  integer(I4B), intent(in) :: iout
128  type(modflowinputtype) :: mf6_input
129  character(len=LENPACKAGENAME) :: source_type
130  !
131  ! -- set source type
132  source_type = package_source_type(mfname)
133  !
134  ! -- create description of input
135  mf6_input = getmodflowinput(mtype, idm_component_type(mtype), 'NAM', &
136  mname, 'NAM', mfname)
137  !
138  select case (source_type)
139  case ('MF6FILE')
140  call input_load(mfname, mf6_input, simfile, iout)
141  case default
142  end select
143  !
144  ! -- return
145  return
146  end subroutine load_modelnam
147 
148  subroutine load_simnam()
149  use simvariablesmodule, only: simfile, iout
150  use messagemodule, only: write_message
151  use idmmf6filemodule, only: input_load
152  type(modflowinputtype) :: mf6_input
153  character(len=LINELENGTH) :: line
154  logical :: lexist
155  !
156  ! -- load mfsim.nam if it exists
157  inquire (file=trim(adjustl(simfile)), exist=lexist)
158  !
159  if (lexist) then
160  !
161  ! -- write name of namfile to stdout
162  write (line, '(2(1x,a))') 'Using Simulation name file:', &
163  trim(adjustl(simfile))
164  call write_message(line, skipafter=1)
165  !
166  ! -- create description of input
167  mf6_input = getmodflowinput('NAM6', 'SIM', 'NAM', 'SIM', 'NAM', simfile)
168  !
169  ! -- open namfile and load to input context
170  call input_load(simfile, mf6_input, simfile, iout)
171  end if
172  !
173  ! -- return
174  return
175  end subroutine load_simnam
176 
177  subroutine load_simtdis()
178  ! -- modules
179  use simvariablesmodule, only: simfile, iout
184  use idmmf6filemodule, only: input_load
185  ! -- dummy
186  ! -- locals
187  character(len=LENMEMPATH) :: input_mempath
188  type(modflowinputtype) :: mf6_input
189  character(len=LENPACKAGENAME) :: source_type
190  character(len=:), pointer :: tdis6
191  logical :: lexist
192  !
193  ! -- set input memory path
194  input_mempath = create_mem_path('SIM', 'NAM', idm_context)
195  !
196  ! -- set pointers to input context timing params
197  call mem_setptr(tdis6, 'TDIS6', input_mempath)
198  !
199  ! -- create timing
200  if (tdis6 /= '') then
201  !
202  ! -- set source type
203  source_type = package_source_type(tdis6)
204  !
205  select case (source_type)
206  case ('MF6FILE')
207  !
208  inquire (file=trim(adjustl(tdis6)), exist=lexist)
209  !
210  if (lexist) then
211  !
212  ! -- create description of input
213  mf6_input = getmodflowinput('TDIS6', 'SIM', 'TDIS', &
214  'SIM', 'TDIS', simfile)
215  !
216  ! -- open namfile and load to input context
217  call input_load(tdis6, mf6_input, simfile, iout)
218  !
219  else
220  write (errmsg, '(a)') &
221  'Simulation TIMING input file "'//trim(tdis6)// &
222  '" does not exist.'
223  call store_error(errmsg)
224  call store_error_filename(simfile)
225  end if
226  case default
227  end select
228  end if
229  !
230  ! -- return
231  return
232  end subroutine load_simtdis
233 
234  function remote_model_ndim(mtype, mfname) result(ncelldim)
236  use constantsmodule, only: linelength
239  character(len=*), intent(in) :: mtype
240  character(len=*), intent(in) :: mfname
241  integer(I4B) :: ncelldim
242  character(len=LENPACKAGENAME) :: source_type
243  type(blockparsertype) :: parser
244  integer(I4B) :: ierr, inunit
245  logical(LGP) :: isfound, endofblock
246  character(len=LINELENGTH) :: ptype
247  !
248  ! -- initialize
249  ncelldim = 0
250  !
251  ! -- set source type
252  source_type = package_source_type(mfname)
253  !
254  select case (source_type)
255  case ('MF6FILE')
256  !
257  ! -- open name file
258  inunit = getunit()
259  call openfile(inunit, 0, trim(adjustl(mfname)), mtype, &
260  'FORMATTED', 'SEQUENTIAL', 'OLD')
261  !
262  ! -- initialize parser
263  call parser%Initialize(inunit, 0)
264  !
265  ! -- get options block
266  call parser%GetBlock('OPTIONS', isfound, ierr, &
267  supportopenclose=.true., blockrequired=.false.)
268  ! -- iterate through options
269  if (isfound) then
270  do
271  call parser%GetNextLine(endofblock)
272  if (endofblock) exit
273  end do
274  end if
275  !
276  ! -- get packages block
277  call parser%GetBlock('PACKAGES', isfound, ierr, &
278  supportopenclose=.true., blockrequired=.true.)
279  if (isfound) then
280  ! -- read through packages
281  do
282  call parser%GetNextLine(endofblock)
283  if (endofblock) exit
284  !
285  call parser%GetStringCaps(ptype)
286  !
287  select case (ptype)
288  case ('DIS6')
289  ncelldim = 3
290  exit
291  case ('DIS2D6')
292  ncelldim = 2
293  exit
294  case ('DISV6')
295  ncelldim = 2
296  exit
297  case ('DISU6')
298  ncelldim = 1
299  exit
300  case default
301  write (errmsg, '(a)') &
302  'Unknown discretization type "'//trim(ptype)// &
303  '" not currently supported.'
304  call store_error(errmsg, .true.)
305  end select
306  end do
307  end if
308  !
309  call parser%clear()
310  !
311  case default
312  end select
313  !
314  ! -- return
315  return
316  end function remote_model_ndim
317 
318 end module sourceloadmodule
This module contains block parser methods.
Definition: BlockParser.f90:7
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 lenmodelname
maximum length of the model name
Definition: Constants.f90:21
integer(i4b), parameter lenpackagename
maximum length of the package name
Definition: Constants.f90:22
integer(i4b), parameter lenpackagetype
maximum length of a package type (DIS6, SFR6, CSUB6, etc.)
Definition: Constants.f90:37
integer(i4b), parameter lenftype
maximum length of a package type (DIS, WEL, OC, etc.)
Definition: Constants.f90:38
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition: Constants.f90:26
This module contains the IdmMf6FileModule.
Definition: IdmMf6File.f90:10
subroutine, public input_load(filename, mf6_input, component_filename, iout)
input load for traditional mf6 simulation static input file
Definition: IdmMf6File.f90:58
integer(i4b) function, public open_mf6file(filetype, filename, component_fname, iout)
open a model package files
Definition: IdmMf6File.f90:360
This module contains the InputLoadTypeModule.
integer(i4b) function, public getunit()
Get a free unit number.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
Definition: InputOutput.f90:30
This module defines variable data types.
Definition: kind.f90:8
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
Store and issue logging messages to output units.
Definition: Message.f90:2
subroutine, public write_message(text, iunit, fmt, skipbefore, skipafter, advance)
Write a message to an output unit.
Definition: Message.f90:210
This module contains the ModflowInputModule.
Definition: ModflowInput.f90:9
type(modflowinputtype) function, public getmodflowinput(pkgtype, component_type, subcomponent_type, component_name, subcomponent_name, filename)
function to return ModflowInputType
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
integer(i4b) iout
file unit number for simulation output
character(len=linelength) simfile
simulation name file
This module contains the SourceCommonModule.
Definition: SourceCommon.f90:7
character(len=lenpackagename) function, public package_source_type(sourcename)
source identifier from model namfile FNAME array
character(len=lencomponentname) function, public idm_component_type(component)
component from package or model type
character(len=lenpackagename) function, public idm_subcomponent_name(component_type, subcomponent_type, sc_name)
model package subcomponent name
This module contains the SourceLoadModule.
Definition: SourceLoad.F90:8
subroutine, public load_simnam()
Definition: SourceLoad.F90:149
class(staticpkgloadbasetype) function, pointer, public create_input_loader(component_type, subcomponent_type, component_name, subcomponent_name, input_type, input_fname, component_fname)
factory function to create and setup model package static loader
Definition: SourceLoad.F90:31
integer(i4b) function, public open_source_file(pkgtype, filename, modelfname, iout)
Definition: SourceLoad.F90:95
subroutine, public load_simtdis()
Definition: SourceLoad.F90:178
class(staticpkgloadbasetype) function, pointer package_loader(source_type)
allocate source model package static loader
Definition: SourceLoad.F90:69
integer(i4b) function, public remote_model_ndim(mtype, mfname)
Definition: SourceLoad.F90:235
subroutine, public load_modelnam(mtype, mfname, mname, iout)
Definition: SourceLoad.F90:121
Base abstract type for static input loader.
derived type for storing input definition for a file