MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
exg-gwfprt.f90
Go to the documentation of this file.
2 
3  use kindmodule, only: dp, i4b
6  use simmodule, only: store_error
7  use simvariablesmodule, only: errmsg
10  use gwfmodule, only: gwfmodeltype
11  use prtmodule, only: prtmodeltype
12  use bndmodule, only: bndtype, getbndfromlist
13 
14  implicit none
15  public :: gwfprtexchangetype
16  public :: gwfprt_cr
17 
19 
20  integer(I4B), pointer :: m1id => null()
21  integer(I4B), pointer :: m2id => null()
22 
23  contains
24 
25  procedure :: exg_df
26  procedure :: exg_ar
27  procedure :: exg_da
28  procedure, private :: set_model_pointers
29  procedure, private :: allocate_scalars
30  procedure, private :: gwfbnd2prtfmi
31  ! procedure, private :: gwfconn2prtconn
32  ! procedure, private :: link_connections
33 
34  end type gwfprtexchangetype
35 
36 contains
37 
38  !> @brief Create a new GWF to PRT exchange object
39  subroutine gwfprt_cr(filename, id, m1id, m2id)
40  ! -- modules
42  ! -- dummy
43  character(len=*), intent(in) :: filename
44  integer(I4B), intent(in) :: id
45  integer(I4B), intent(in) :: m1id
46  integer(I4B), intent(in) :: m2id
47  ! -- local
48  class(baseexchangetype), pointer :: baseexchange => null()
49  type(gwfprtexchangetype), pointer :: exchange => null()
50  character(len=20) :: cint
51  !
52  ! -- Create a new exchange and add it to the baseexchangelist container
53  allocate (exchange)
54  baseexchange => exchange
55  call addbaseexchangetolist(baseexchangelist, baseexchange)
56  !
57  ! -- Assign id and name
58  exchange%id = id
59  write (cint, '(i0)') id
60  exchange%name = 'GWF-PRT_'//trim(adjustl(cint))
61  exchange%memoryPath = exchange%name
62  !
63  ! -- allocate scalars
64  call exchange%allocate_scalars()
65  !
66  ! -- NB: convert from id to local model index in base model list
67  exchange%m1id = model_loc_idx(m1id)
68  exchange%m2id = model_loc_idx(m2id)
69  !
70  ! -- set model pointers
71  call exchange%set_model_pointers()
72  end subroutine gwfprt_cr
73 
74  subroutine set_model_pointers(this)
75  ! -- modules
76  ! -- dummy
77  class(gwfprtexchangetype) :: this
78  ! -- local
79  class(basemodeltype), pointer :: mb => null()
80  type(gwfmodeltype), pointer :: gwfmodel => null()
81  type(prtmodeltype), pointer :: prtmodel => null()
82  !
83  ! -- set gwfmodel
84  mb => getbasemodelfromlist(basemodellist, this%m1id)
85  select type (mb)
86  type is (gwfmodeltype)
87  gwfmodel => mb
88  end select
89  !
90  ! -- set prtmodel
91  mb => getbasemodelfromlist(basemodellist, this%m2id)
92  select type (mb)
93  type is (prtmodeltype)
94  prtmodel => mb
95  end select
96  !
97  ! -- Verify that GWF model is of the correct type
98  if (.not. associated(gwfmodel)) then
99  write (errmsg, '(3a)') 'Problem with GWF-PRT exchange ', trim(this%name), &
100  '. Specified GWF Model does not appear to be of the correct type.'
101  call store_error(errmsg, terminate=.true.)
102  end if
103  !
104  ! -- Verify that PRT model is of the correct type
105  if (.not. associated(prtmodel)) then
106  write (errmsg, '(3a)') 'Problem with GWF-PRT exchange ', trim(this%name), &
107  '. Specified PRT Model does not appear to be of the correct type.'
108  call store_error(errmsg, terminate=.true.)
109  end if
110  !
111  ! -- Tell particle tracking model fmi flows are not read from file
112  prtmodel%fmi%flows_from_file = .false.
113  !
114  ! -- Set a pointer to the GWF bndlist. This will allow the transport model
115  ! to look through the flow packages and establish a link to GWF flows
116  prtmodel%fmi%gwfbndlist => gwfmodel%bndlist
117  end subroutine set_model_pointers
118 
119  subroutine exg_df(this)
120  ! -- modules
122  ! -- dummy
123  class(gwfprtexchangetype) :: this
124  ! -- local
125  class(basemodeltype), pointer :: mb => null()
126  type(gwfmodeltype), pointer :: gwfmodel => null()
127  type(prtmodeltype), pointer :: prtmodel => null()
128  integer(I4B) :: ngwfpack, ip
129  class(bndtype), pointer :: packobj => null()
130  !
131  !
132  ! -- set gwfmodel
133  mb => getbasemodelfromlist(basemodellist, this%m1id)
134  select type (mb)
135  type is (gwfmodeltype)
136  gwfmodel => mb
137  end select
138  !
139  ! -- set prtmodel
140  mb => getbasemodelfromlist(basemodellist, this%m2id)
141  select type (mb)
142  type is (prtmodeltype)
143  prtmodel => mb
144  end select
145  !
146  ! -- Check to make sure that flow is solved before particle tracking and in a
147  ! different solution
148  if (gwfmodel%idsoln >= prtmodel%idsoln) then
149  write (errmsg, '(3a)') 'Problem with GWF-PRT exchange ', trim(this%name), &
150  '. The GWF model must be solved by a different solution than the PRT model. &
151  &The IMS specified for GWF must be listed in mfsim.nam &
152  &before the EMS for PRT.'
153  call store_error(errmsg, terminate=.true.)
154  end if
155  !
156  ! -- Set pointer to flowja
157  prtmodel%fmi%gwfflowja => gwfmodel%flowja
158  call mem_checkin(prtmodel%fmi%gwfflowja, &
159  'GWFFLOWJA', prtmodel%fmi%memoryPath, &
160  'FLOWJA', gwfmodel%memoryPath)
161  !
162  ! -- Set the npf flag so that specific discharge is available for
163  ! transport calculations if dispersion is active
164  if (prtmodel%indsp > 0) then
165  gwfmodel%npf%icalcspdis = 1
166  end if
167  !
168  ! -- Set the auxiliary names for gwf flow packages in prt%fmi
169  ngwfpack = gwfmodel%bndlist%Count()
170  do ip = 1, ngwfpack
171  packobj => getbndfromlist(gwfmodel%bndlist, ip)
172  call prtmodel%fmi%gwfpackages(ip)%set_auxname(packobj%naux, &
173  packobj%auxname)
174  end do
175  end subroutine exg_df
176 
177  subroutine exg_ar(this)
178  ! -- modules
180  ! -- dummy
181  class(gwfprtexchangetype) :: this
182  ! -- local
183  class(basemodeltype), pointer :: mb => null()
184  type(gwfmodeltype), pointer :: gwfmodel => null()
185  type(prtmodeltype), pointer :: prtmodel => null()
186  ! -- formats
187  character(len=*), parameter :: fmtdiserr = &
188  "('GWF and PRT Models do not have the same discretization for exchange&
189  & ',a,'.&
190  & GWF Model has ', i0, ' user nodes and ', i0, ' reduced nodes.&
191  & PRT Model has ', i0, ' user nodes and ', i0, ' reduced nodes.&
192  & Ensure discretization packages, including IDOMAIN, are identical.')"
193  !
194  ! -- set gwfmodel
195  mb => getbasemodelfromlist(basemodellist, this%m1id)
196  select type (mb)
197  type is (gwfmodeltype)
198  gwfmodel => mb
199  end select
200  !
201  ! -- set prtmodel
202  mb => getbasemodelfromlist(basemodellist, this%m2id)
203  select type (mb)
204  type is (prtmodeltype)
205  prtmodel => mb
206  end select
207  !
208  ! -- Check to make sure sizes are identical
209  if (prtmodel%dis%nodes /= gwfmodel%dis%nodes .or. &
210  prtmodel%dis%nodesuser /= gwfmodel%dis%nodesuser) then
211  write (errmsg, fmtdiserr) trim(this%name), &
212  gwfmodel%dis%nodesuser, &
213  gwfmodel%dis%nodes, &
214  prtmodel%dis%nodesuser, &
215  prtmodel%dis%nodes
216  call store_error(errmsg, terminate=.true.)
217  end if
218  !
219  ! -- setup pointers to gwf variables allocated in gwf_ar
220  prtmodel%fmi%gwfhead => gwfmodel%x
221  call mem_checkin(prtmodel%fmi%gwfhead, &
222  'GWFHEAD', prtmodel%fmi%memoryPath, &
223  'X', gwfmodel%memoryPath)
224  prtmodel%fmi%gwfsat => gwfmodel%npf%sat
225  call mem_checkin(prtmodel%fmi%gwfsat, &
226  'GWFSAT', prtmodel%fmi%memoryPath, &
227  'SAT', gwfmodel%npf%memoryPath)
228  prtmodel%fmi%gwfspdis => gwfmodel%npf%spdis
229  call mem_checkin(prtmodel%fmi%gwfspdis, &
230  'GWFSPDIS', prtmodel%fmi%memoryPath, &
231  'SPDIS', gwfmodel%npf%memoryPath)
232  !
233  ! -- setup pointers to the flow storage rates. GWF strg arrays are
234  ! available after the gwf_ar routine is called.
235  if (prtmodel%inmst > 0) then
236  if (gwfmodel%insto > 0) then
237  prtmodel%fmi%gwfstrgss => gwfmodel%sto%strgss
238  prtmodel%fmi%igwfstrgss = 1
239  if (gwfmodel%sto%iusesy == 1) then
240  prtmodel%fmi%gwfstrgsy => gwfmodel%sto%strgsy
241  prtmodel%fmi%igwfstrgsy = 1
242  end if
243  end if
244  end if
245 
246  ! -- transfer the boundary package information from gwf to prt
247  call this%gwfbnd2prtfmi()
248 
249  ! -- if mover package is active, then set a pointer to it's budget object
250  if (gwfmodel%inmvr /= 0) &
251  prtmodel%fmi%mvrbudobj => gwfmodel%mvr%budobj
252 
253  ! -- todo connections
254  end subroutine exg_ar
255 
256  ! todo subroutines: gwfconn2prtconn and link_connections
257 
258  subroutine exg_da(this)
259  ! -- modules
261  ! -- dummy
262  class(gwfprtexchangetype) :: this
263  ! -- local
264  !
265  call mem_deallocate(this%m1id)
266  call mem_deallocate(this%m2id)
267  end subroutine exg_da
268 
269  subroutine allocate_scalars(this)
270  ! -- modules
272  ! -- dummy
273  class(gwfprtexchangetype) :: this
274  ! -- local
275  !
276  call mem_allocate(this%m1id, 'M1ID', this%memoryPath)
277  call mem_allocate(this%m2id, 'M2ID', this%memoryPath)
278  this%m1id = 0
279  this%m2id = 0
280  end subroutine allocate_scalars
281 
282  subroutine gwfbnd2prtfmi(this)
283  ! -- modules
284  ! -- dummy
285  class(gwfprtexchangetype) :: this
286  ! -- local
287  integer(I4B) :: ngwfpack, ip, iterm, imover
288  class(basemodeltype), pointer :: mb => null()
289  type(gwfmodeltype), pointer :: gwfmodel => null()
290  type(prtmodeltype), pointer :: prtmodel => null()
291  class(bndtype), pointer :: packobj => null()
292  !
293  ! -- set gwfmodel
294  mb => getbasemodelfromlist(basemodellist, this%m1id)
295  select type (mb)
296  type is (gwfmodeltype)
297  gwfmodel => mb
298  end select
299  !
300  ! -- set prtmodel
301  mb => getbasemodelfromlist(basemodellist, this%m2id)
302  select type (mb)
303  type is (prtmodeltype)
304  prtmodel => mb
305  end select
306  !
307  ! -- Call routines in FMI that will set pointers to the necessary flow
308  ! data (SIMVALS and SIMTOMVR) stored within each GWF flow package
309  ngwfpack = gwfmodel%bndlist%Count()
310  iterm = 1
311  do ip = 1, ngwfpack
312  packobj => getbndfromlist(gwfmodel%bndlist, ip)
313  call prtmodel%fmi%gwfpackages(iterm)%set_pointers( &
314  'SIMVALS', &
315  packobj%memoryPath, &
316  packobj%input_mempath)
317  iterm = iterm + 1
318  !
319  ! -- If a mover is active for this package, then establish a separate
320  ! pointer link for the mover flows stored in SIMTOMVR
321  imover = packobj%imover
322  if (packobj%isadvpak /= 0) imover = 0
323  if (imover /= 0) then
324  call prtmodel%fmi%gwfpackages(iterm)%set_pointers( &
325  'SIMTOMVR', &
326  packobj%memoryPath, &
327  packobj%input_mempath)
328  iterm = iterm + 1
329  end if
330  end do
331  end subroutine gwfbnd2prtfmi
332 
333 end module gwfprtexchangemodule
subroutine, public addbaseexchangetolist(list, exchange)
Add the exchange object (BaseExchangeType) to a list.
class(basemodeltype) function, pointer, public getbasemodelfromlist(list, idx)
Definition: BaseModel.f90:172
This module contains the base boundary package.
class(bndtype) function, pointer, public getbndfromlist(list, idx)
Get boundary from package list.
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter lenpackagename
maximum length of the package name
Definition: Constants.f90:23
Definition: gwf.f90:1
subroutine, public gwfprt_cr(filename, id, m1id, m2id)
Create a new GWF to PRT exchange object.
Definition: exg-gwfprt.f90:40
subroutine exg_da(this)
Definition: exg-gwfprt.f90:259
subroutine gwfbnd2prtfmi(this)
Definition: exg-gwfprt.f90:283
subroutine allocate_scalars(this)
Definition: exg-gwfprt.f90:270
subroutine set_model_pointers(this)
Definition: exg-gwfprt.f90:75
This module defines variable data types.
Definition: kind.f90:8
type(listtype), public basemodellist
Definition: mf6lists.f90:16
type(listtype), public baseexchangelist
Definition: mf6lists.f90:25
Definition: prt.f90:1
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=maxcharlen) errmsg
error message string
integer(i4b), dimension(:), allocatable model_loc_idx
equals the local index into the basemodel list (-1 when not available)
Highest level model type. All models extend this parent type.
Definition: BaseModel.f90:13
@ brief BndType
Particle tracking (PRT) model.
Definition: prt.f90:41