MODFLOW 6  version 6.9.0.dev0
USGS Modular Hydrologic Model
gwt-lkt.f90
Go to the documentation of this file.
1 ! -- Lake Transport Module
2 ! -- todo: what to do about reactions in lake? Decay?
3 ! -- todo: save the lkt concentration into the lak aux variable?
4 ! -- todo: calculate the lak DENSE aux variable using concentration?
5 !
6 ! LAK flows (lakbudptr) index var LKT term Transport Type
7 !---------------------------------------------------------------------------------
8 
9 ! -- terms from LAK that will be handled by parent APT Package
10 ! FLOW-JA-FACE idxbudfjf FLOW-JA-FACE cv2cv
11 ! GWF (aux FLOW-AREA) idxbudgwf GWF cv2gwf
12 ! STORAGE (aux VOLUME) idxbudsto none used for cv volumes
13 ! FROM-MVR idxbudfmvr FROM-MVR q * cext = this%qfrommvr(:)
14 ! TO-MVR idxbudtmvr TO-MVR q * cfeat
15 
16 ! -- LAK terms
17 ! RAINFALL idxbudrain RAINFALL q * crain
18 ! EVAPORATION idxbudevap EVAPORATION cfeat<cevap: q*cfeat, else: q*cevap
19 ! RUNOFF idxbudroff RUNOFF q * croff
20 ! EXT-INFLOW idxbudiflw EXT-INFLOW q * ciflw
21 ! WITHDRAWAL idxbudwdrl WITHDRAWAL q * cfeat
22 ! EXT-OUTFLOW idxbudoutf EXT-OUTFLOW q * cfeat
23 
24 ! -- terms from a flow file that should be skipped
25 ! CONSTANT none none none
26 ! AUXILIARY none none none
27 
28 ! -- terms that are written to the transport budget file
29 ! none none STORAGE (aux MASS) dM/dt
30 ! none none AUXILIARY none
31 ! none none CONSTANT accumulate
32 !
33 !
35 
36  use kindmodule, only: dp, i4b
40  use bndmodule, only: bndtype, getbndfromlist
42  use tspfmimodule, only: tspfmitype
43  use lakmodule, only: laktype
44  use observemodule, only: observetype
48 
49  implicit none
50 
51  public lkt_create
52 
53  character(len=*), parameter :: ftype = 'LKT'
54  character(len=*), parameter :: flowtype = 'LAK'
55  character(len=16) :: text = ' LKT'
56 
57  type, extends(tspapttype) :: gwtlkttype
58 
59  integer(I4B), pointer :: idxbudrain => null() ! index of rainfall terms in flowbudptr
60  integer(I4B), pointer :: idxbudevap => null() ! index of evaporation terms in flowbudptr
61  integer(I4B), pointer :: idxbudroff => null() ! index of runoff terms in flowbudptr
62  integer(I4B), pointer :: idxbudiflw => null() ! index of inflow terms in flowbudptr
63  integer(I4B), pointer :: idxbudwdrl => null() ! index of withdrawal terms in flowbudptr
64  integer(I4B), pointer :: idxbudoutf => null() ! index of outflow terms in flowbudptr
65 
66  real(dp), dimension(:), pointer, contiguous :: concrain => null() ! rainfall concentration
67  real(dp), dimension(:), pointer, contiguous :: concevap => null() ! evaporation concentration
68  real(dp), dimension(:), pointer, contiguous :: concroff => null() ! runoff concentration
69  real(dp), dimension(:), pointer, contiguous :: conciflw => null() ! inflow concentration
70 
71  contains
72 
73  procedure :: bnd_da => lkt_da
74  procedure :: allocate_scalars
75  procedure :: apt_allocate_arrays => lkt_allocate_arrays
76  procedure :: apt_checkin_deprecated_names => lkt_checkin_deprecated_names
77  procedure :: find_apt_package => find_lkt_package
78  procedure :: apt_setting_value => lkt_setting_value
79  procedure :: pak_fc_expanded => lkt_fc_expanded
80  procedure :: pak_solve => lkt_solve
81  procedure :: pak_get_nbudterms => lkt_get_nbudterms
82  procedure :: pak_setup_budobj => lkt_setup_budobj
83  procedure :: pak_fill_budobj => lkt_fill_budobj
84  procedure :: lkt_rain_term
85  procedure :: lkt_evap_term
86  procedure :: lkt_roff_term
87  procedure :: lkt_iflw_term
88  procedure :: lkt_wdrl_term
89  procedure :: lkt_outf_term
90  procedure :: pak_df_obs => lkt_df_obs
91  procedure :: pak_rp_obs => lkt_rp_obs
92  procedure :: pak_bd_obs => lkt_bd_obs
93 
94  end type gwtlkttype
95 
96 contains
97 
98  !> @brief Create a new lkt package
99  !<
100  subroutine lkt_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, &
101  mempath, fmi, eqnsclfac, dvt, dvu, dvua)
102  ! -- dummy
103  class(bndtype), pointer :: packobj
104  integer(I4B), intent(in) :: id
105  integer(I4B), intent(in) :: ibcnum
106  integer(I4B), intent(in) :: inunit
107  integer(I4B), intent(in) :: iout
108  character(len=*), intent(in) :: namemodel
109  character(len=*), intent(in) :: pakname
110  character(len=*), intent(in) :: mempath !< input memory path
111  type(tspfmitype), pointer :: fmi
112  real(dp), intent(in), pointer :: eqnsclfac !< governing equation scale factor
113  character(len=*), intent(in) :: dvt !< For GWT, set to "CONCENTRATION" in TspAptType
114  character(len=*), intent(in) :: dvu !< For GWT, set to "mass" in TspAptType
115  character(len=*), intent(in) :: dvua !< For GWT, set to "M" in TspAptType
116  ! -- local
117  type(gwtlkttype), pointer :: lktobj
118  !
119  ! -- allocate the object and assign values to object variables
120  allocate (lktobj)
121  packobj => lktobj
122  !
123  ! -- create name and memory path
124  call packobj%set_names(ibcnum, namemodel, pakname, ftype, mempath)
125  packobj%text = text
126  !
127  ! -- allocate scalars
128  call lktobj%allocate_scalars()
129  !
130  ! -- initialize package
131  call packobj%pack_initialize()
132 
133  packobj%inunit = inunit
134  packobj%iout = iout
135  packobj%id = id
136  packobj%ibcnum = ibcnum
137  packobj%ncolbnd = 1
138  packobj%iscloc = 1
139  packobj%isadvpak = 1
140 
141  ! -- Store pointer to flow model interface. When the GwfGwt exchange is
142  ! created, it sets fmi%bndlist so that the GWT model has access to all
143  ! the flow packages
144  lktobj%fmi => fmi
145  !
146  ! -- Store pointer to governing equation scale factor
147  lktobj%eqnsclfac => eqnsclfac
148  !
149  ! -- Set labels that will be used in generalized APT class
150  lktobj%depvartype = dvt
151  lktobj%depvarunit = dvu
152  lktobj%depvarunitabbrev = dvua
153  end subroutine lkt_create
154 
155  !> @brief Find corresponding lkt package
156  !<
157  subroutine find_lkt_package(this)
158  ! -- modules
160  ! -- dummy
161  class(gwtlkttype) :: this
162  ! -- local
163  character(len=LINELENGTH) :: errmsg
164  class(bndtype), pointer :: packobj
165  integer(I4B) :: ip, icount
166  integer(I4B) :: nbudterm
167  logical :: found
168  !
169  ! -- Initialize found to false, and error later if flow package cannot
170  ! be found
171  found = .false.
172  !
173  ! -- If user is specifying flows in a binary budget file, then set up
174  ! the budget file reader, otherwise set a pointer to the flow package
175  ! budobj
176  if (this%fmi%flows_from_file) then
177  call this%fmi%set_aptbudobj_pointer(this%flowpackagename, this%flowbudptr)
178  if (associated(this%flowbudptr)) found = .true.
179  !
180  else
181  if (associated(this%fmi%gwfbndlist)) then
182  ! -- Look through gwfbndlist for a flow package with the same name as
183  ! this transport package name
184  do ip = 1, this%fmi%gwfbndlist%Count()
185  packobj => getbndfromlist(this%fmi%gwfbndlist, ip)
186  if (packobj%packName == this%flowpackagename) then
187  found = .true.
188  !
189  ! -- store BndType pointer to packobj, and then
190  ! use the select type to point to the budobj in flow package
191  this%flowpackagebnd => packobj
192  select type (packobj)
193  type is (laktype)
194  this%flowbudptr => packobj%budobj
195  end select
196  end if
197  if (found) exit
198  end do
199  end if
200  end if
201  !
202  ! -- error if flow package not found
203  if (.not. found) then
204  write (errmsg, '(a)') 'Could not find flow package with name '&
205  &//trim(adjustl(this%flowpackagename))//'.'
206  call store_error(errmsg)
207  call store_error_filename(this%input_fname)
208  end if
209  !
210  ! -- allocate space for idxbudssm, which indicates whether this is a
211  ! special budget term or one that is a general source and sink
212  nbudterm = this%flowbudptr%nbudterm
213  call mem_allocate(this%idxbudssm, nbudterm, 'IDXBUDSSM', this%memoryPath)
214  !
215  ! -- Process budget terms and identify special budget terms
216  write (this%iout, '(/, a, a)') &
217  'PROCESSING '//ftype//' INFORMATION FOR ', this%packName
218  write (this%iout, '(a)') ' IDENTIFYING FLOW TERMS IN '//flowtype//' PACKAGE'
219  write (this%iout, '(a, i0)') &
220  ' NUMBER OF '//flowtype//' = ', this%flowbudptr%ncv
221  icount = 1
222  do ip = 1, this%flowbudptr%nbudterm
223  select case (trim(adjustl(this%flowbudptr%budterm(ip)%flowtype)))
224  case ('FLOW-JA-FACE')
225  this%idxbudfjf = ip
226  this%idxbudssm(ip) = 0
227  case ('GWF')
228  this%idxbudgwf = ip
229  this%idxbudssm(ip) = 0
230  case ('STORAGE')
231  this%idxbudsto = ip
232  this%idxbudssm(ip) = 0
233  case ('RAINFALL')
234  this%idxbudrain = ip
235  this%idxbudssm(ip) = 0
236  case ('EVAPORATION')
237  this%idxbudevap = ip
238  this%idxbudssm(ip) = 0
239  case ('RUNOFF')
240  this%idxbudroff = ip
241  this%idxbudssm(ip) = 0
242  case ('EXT-INFLOW')
243  this%idxbudiflw = ip
244  this%idxbudssm(ip) = 0
245  case ('WITHDRAWAL')
246  this%idxbudwdrl = ip
247  this%idxbudssm(ip) = 0
248  case ('EXT-OUTFLOW')
249  this%idxbudoutf = ip
250  this%idxbudssm(ip) = 0
251  case ('TO-MVR')
252  this%idxbudtmvr = ip
253  this%idxbudssm(ip) = 0
254  case ('FROM-MVR')
255  this%idxbudfmvr = ip
256  this%idxbudssm(ip) = 0
257  case ('AUXILIARY')
258  this%idxbudaux = ip
259  this%idxbudssm(ip) = 0
260  case default
261  !
262  ! -- set idxbudssm equal to a column index for where the concentrations
263  ! are stored in the concbud(nbudssm, ncv) array
264  this%idxbudssm(ip) = icount
265  icount = icount + 1
266  end select
267  write (this%iout, '(a, i0, " = ", a,/, a, i0)') &
268  ' TERM ', ip, trim(adjustl(this%flowbudptr%budterm(ip)%flowtype)), &
269  ' MAX NO. OF ENTRIES = ', this%flowbudptr%budterm(ip)%maxlist
270  end do
271  write (this%iout, '(a, //)') 'DONE PROCESSING '//ftype//' INFORMATION'
272  end subroutine find_lkt_package
273 
274  !> @brief Value for a package-specific PERIOD setting
275  !!
276  !! Already resolved by the input context; this only supplies it for
277  !! the shared apt_rp table echo.
278  !<
279  function lkt_setting_value(this, itemno, key) result(val)
280  ! -- dummy
281  class(gwtlkttype), intent(inout) :: this
282  integer(I4B), intent(in) :: itemno
283  character(len=*), intent(in) :: key
284  real(dp) :: val
285  !
286  val = dzero
287  select case (trim(key))
288  case ('RAINFALL')
289  val = this%concrain(itemno)
290  case ('EVAPORATION')
291  val = this%concevap(itemno)
292  case ('RUNOFF')
293  val = this%concroff(itemno)
294  case ('EXT-INFLOW')
295  val = this%conciflw(itemno)
296  end select
297  end function lkt_setting_value
298 
299  !> @brief Add matrix terms related to LKT
300  !!
301  !! This will be called from TspAptType%apt_fc_expanded()
302  !! in order to add matrix terms specifically for LKT
303  !<
304  subroutine lkt_fc_expanded(this, rhs, ia, idxglo, matrix_sln)
305  ! -- modules
306  ! -- dummy
307  class(gwtlkttype) :: this
308  real(DP), dimension(:), intent(inout) :: rhs
309  integer(I4B), dimension(:), intent(in) :: ia
310  integer(I4B), dimension(:), intent(in) :: idxglo
311  class(matrixbasetype), pointer :: matrix_sln
312  ! -- local
313  integer(I4B) :: j, n1, n2
314  integer(I4B) :: iloc
315  integer(I4B) :: iposd
316  real(DP) :: rrate
317  real(DP) :: rhsval
318  real(DP) :: hcofval
319  !
320  ! -- add rainfall contribution
321  if (this%idxbudrain /= 0) then
322  do j = 1, this%flowbudptr%budterm(this%idxbudrain)%nlist
323  call this%lkt_rain_term(j, n1, n2, rrate, rhsval, hcofval)
324  iloc = this%idxlocnode(n1)
325  iposd = this%idxpakdiag(n1)
326  call matrix_sln%add_value_pos(iposd, hcofval)
327  rhs(iloc) = rhs(iloc) + rhsval
328  end do
329  end if
330  !
331  ! -- add evaporation contribution
332  if (this%idxbudevap /= 0) then
333  do j = 1, this%flowbudptr%budterm(this%idxbudevap)%nlist
334  call this%lkt_evap_term(j, n1, n2, rrate, rhsval, hcofval)
335  iloc = this%idxlocnode(n1)
336  iposd = this%idxpakdiag(n1)
337  call matrix_sln%add_value_pos(iposd, hcofval)
338  rhs(iloc) = rhs(iloc) + rhsval
339  end do
340  end if
341  !
342  ! -- add runoff contribution
343  if (this%idxbudroff /= 0) then
344  do j = 1, this%flowbudptr%budterm(this%idxbudroff)%nlist
345  call this%lkt_roff_term(j, n1, n2, rrate, rhsval, hcofval)
346  iloc = this%idxlocnode(n1)
347  iposd = this%idxpakdiag(n1)
348  call matrix_sln%add_value_pos(iposd, hcofval)
349  rhs(iloc) = rhs(iloc) + rhsval
350  end do
351  end if
352  !
353  ! -- add inflow contribution
354  if (this%idxbudiflw /= 0) then
355  do j = 1, this%flowbudptr%budterm(this%idxbudiflw)%nlist
356  call this%lkt_iflw_term(j, n1, n2, rrate, rhsval, hcofval)
357  iloc = this%idxlocnode(n1)
358  iposd = this%idxpakdiag(n1)
359  call matrix_sln%add_value_pos(iposd, hcofval)
360  rhs(iloc) = rhs(iloc) + rhsval
361  end do
362  end if
363  !
364  ! -- add withdrawal contribution
365  if (this%idxbudwdrl /= 0) then
366  do j = 1, this%flowbudptr%budterm(this%idxbudwdrl)%nlist
367  call this%lkt_wdrl_term(j, n1, n2, rrate, rhsval, hcofval)
368  iloc = this%idxlocnode(n1)
369  iposd = this%idxpakdiag(n1)
370  call matrix_sln%add_value_pos(iposd, hcofval)
371  rhs(iloc) = rhs(iloc) + rhsval
372  end do
373  end if
374  !
375  ! -- add outflow contribution
376  if (this%idxbudoutf /= 0) then
377  do j = 1, this%flowbudptr%budterm(this%idxbudoutf)%nlist
378  call this%lkt_outf_term(j, n1, n2, rrate, rhsval, hcofval)
379  iloc = this%idxlocnode(n1)
380  iposd = this%idxpakdiag(n1)
381  call matrix_sln%add_value_pos(iposd, hcofval)
382  rhs(iloc) = rhs(iloc) + rhsval
383  end do
384  end if
385  end subroutine lkt_fc_expanded
386 
387  !> @brief Add terms specific to lakes to the explicit lake solve
388  !<
389  subroutine lkt_solve(this)
390  ! -- dummy
391  class(gwtlkttype) :: this
392  ! -- local
393  integer(I4B) :: j
394  integer(I4B) :: n1, n2
395  real(DP) :: rrate
396  !
397  ! -- add rainfall contribution
398  if (this%idxbudrain /= 0) then
399  do j = 1, this%flowbudptr%budterm(this%idxbudrain)%nlist
400  call this%lkt_rain_term(j, n1, n2, rrate)
401  this%dbuff(n1) = this%dbuff(n1) + rrate
402  end do
403  end if
404  !
405  ! -- add evaporation contribution
406  if (this%idxbudevap /= 0) then
407  do j = 1, this%flowbudptr%budterm(this%idxbudevap)%nlist
408  call this%lkt_evap_term(j, n1, n2, rrate)
409  this%dbuff(n1) = this%dbuff(n1) + rrate
410  end do
411  end if
412  !
413  ! -- add runoff contribution
414  if (this%idxbudroff /= 0) then
415  do j = 1, this%flowbudptr%budterm(this%idxbudroff)%nlist
416  call this%lkt_roff_term(j, n1, n2, rrate)
417  this%dbuff(n1) = this%dbuff(n1) + rrate
418  end do
419  end if
420  !
421  ! -- add inflow contribution
422  if (this%idxbudiflw /= 0) then
423  do j = 1, this%flowbudptr%budterm(this%idxbudiflw)%nlist
424  call this%lkt_iflw_term(j, n1, n2, rrate)
425  this%dbuff(n1) = this%dbuff(n1) + rrate
426  end do
427  end if
428  !
429  ! -- add withdrawal contribution
430  if (this%idxbudwdrl /= 0) then
431  do j = 1, this%flowbudptr%budterm(this%idxbudwdrl)%nlist
432  call this%lkt_wdrl_term(j, n1, n2, rrate)
433  this%dbuff(n1) = this%dbuff(n1) + rrate
434  end do
435  end if
436  !
437  ! -- add outflow contribution
438  if (this%idxbudoutf /= 0) then
439  do j = 1, this%flowbudptr%budterm(this%idxbudoutf)%nlist
440  call this%lkt_outf_term(j, n1, n2, rrate)
441  this%dbuff(n1) = this%dbuff(n1) + rrate
442  end do
443  end if
444  end subroutine lkt_solve
445 
446  !> @brief Function to return the number of budget terms just for this package.
447  !!
448  !! This overrides a function in the parent class.
449  !<
450  function lkt_get_nbudterms(this) result(nbudterms)
451  ! -- modules
452  ! -- dummy
453  class(gwtlkttype) :: this
454  ! -- return
455  integer(I4B) :: nbudterms
456  ! -- local
457  !
458  ! -- Number of budget terms is 6
459  nbudterms = 6
460  end function lkt_get_nbudterms
461 
462  !> @brief Set up the budget object that stores all the lake flows
463  !<
464  subroutine lkt_setup_budobj(this, idx)
465  ! -- modules
466  use constantsmodule, only: lenbudtxt
467  ! -- dummy
468  class(gwtlkttype) :: this
469  integer(I4B), intent(inout) :: idx
470  ! -- local
471  integer(I4B) :: maxlist, naux
472  character(len=LENBUDTXT) :: text
473  !
474  ! -- Addition of mass associated with rainfall directly on lake surface
475  text = ' RAINFALL'
476  idx = idx + 1
477  maxlist = this%flowbudptr%budterm(this%idxbudrain)%maxlist
478  naux = 0
479  call this%budobj%budterm(idx)%initialize(text, &
480  this%name_model, &
481  this%packName, &
482  this%name_model, &
483  this%packName, &
484  maxlist, .false., .false., &
485  naux)
486  !
487  ! -- Loss of dissolved mass associated with evaporation when a non-zero
488  ! evaporative concentration is specified
489  text = ' EVAPORATION'
490  idx = idx + 1
491  maxlist = this%flowbudptr%budterm(this%idxbudevap)%maxlist
492  naux = 0
493  call this%budobj%budterm(idx)%initialize(text, &
494  this%name_model, &
495  this%packName, &
496  this%name_model, &
497  this%packName, &
498  maxlist, .false., .false., &
499  naux)
500  !
501  ! -- Addition of mass associated with runoff that flows to the lake
502  text = ' RUNOFF'
503  idx = idx + 1
504  maxlist = this%flowbudptr%budterm(this%idxbudroff)%maxlist
505  naux = 0
506  call this%budobj%budterm(idx)%initialize(text, &
507  this%name_model, &
508  this%packName, &
509  this%name_model, &
510  this%packName, &
511  maxlist, .false., .false., &
512  naux)
513  !
514  ! -- Addition of mass associated with user-specified inflow to the lake
515  text = ' EXT-INFLOW'
516  idx = idx + 1
517  maxlist = this%flowbudptr%budterm(this%idxbudiflw)%maxlist
518  naux = 0
519  call this%budobj%budterm(idx)%initialize(text, &
520  this%name_model, &
521  this%packName, &
522  this%name_model, &
523  this%packName, &
524  maxlist, .false., .false., &
525  naux)
526  !
527  ! -- Removal of mass associated with user-specified withdrawal from lake
528  text = ' WITHDRAWAL'
529  idx = idx + 1
530  maxlist = this%flowbudptr%budterm(this%idxbudwdrl)%maxlist
531  naux = 0
532  call this%budobj%budterm(idx)%initialize(text, &
533  this%name_model, &
534  this%packName, &
535  this%name_model, &
536  this%packName, &
537  maxlist, .false., .false., &
538  naux)
539  !
540  ! -- Removal of heat associated with outflow from lake that leaves
541  ! model domain
542  text = ' EXT-OUTFLOW'
543  idx = idx + 1
544  maxlist = this%flowbudptr%budterm(this%idxbudoutf)%maxlist
545  naux = 0
546  call this%budobj%budterm(idx)%initialize(text, &
547  this%name_model, &
548  this%packName, &
549  this%name_model, &
550  this%packName, &
551  maxlist, .false., .false., &
552  naux)
553  end subroutine lkt_setup_budobj
554 
555  !> @brief Copy flow terms into this%budobj
556  !<
557  subroutine lkt_fill_budobj(this, idx, x, flowja, ccratin, ccratout)
558  ! -- modules
559  ! -- dummy
560  class(gwtlkttype) :: this
561  integer(I4B), intent(inout) :: idx
562  real(DP), dimension(:), intent(in) :: x
563  real(DP), dimension(:), contiguous, intent(inout) :: flowja
564  real(DP), intent(inout) :: ccratin
565  real(DP), intent(inout) :: ccratout
566  ! -- local
567  integer(I4B) :: j, n1, n2
568  integer(I4B) :: nlist
569  real(DP) :: q
570  ! -- formats
571  !
572  ! -- RAIN
573  idx = idx + 1
574  nlist = this%flowbudptr%budterm(this%idxbudrain)%nlist
575  call this%budobj%budterm(idx)%reset(nlist)
576  do j = 1, nlist
577  call this%lkt_rain_term(j, n1, n2, q)
578  call this%budobj%budterm(idx)%update_term(n1, n2, q)
579  call this%apt_accumulate_ccterm(n1, q, ccratin, ccratout)
580  end do
581  !
582  ! -- EVAPORATION
583  idx = idx + 1
584  nlist = this%flowbudptr%budterm(this%idxbudevap)%nlist
585  call this%budobj%budterm(idx)%reset(nlist)
586  do j = 1, nlist
587  call this%lkt_evap_term(j, n1, n2, q)
588  call this%budobj%budterm(idx)%update_term(n1, n2, q)
589  call this%apt_accumulate_ccterm(n1, q, ccratin, ccratout)
590  end do
591  !
592  ! -- RUNOFF
593  idx = idx + 1
594  nlist = this%flowbudptr%budterm(this%idxbudroff)%nlist
595  call this%budobj%budterm(idx)%reset(nlist)
596  do j = 1, nlist
597  call this%lkt_roff_term(j, n1, n2, q)
598  call this%budobj%budterm(idx)%update_term(n1, n2, q)
599  call this%apt_accumulate_ccterm(n1, q, ccratin, ccratout)
600  end do
601  !
602  ! -- EXT-INFLOW
603  idx = idx + 1
604  nlist = this%flowbudptr%budterm(this%idxbudiflw)%nlist
605  call this%budobj%budterm(idx)%reset(nlist)
606  do j = 1, nlist
607  call this%lkt_iflw_term(j, n1, n2, q)
608  call this%budobj%budterm(idx)%update_term(n1, n2, q)
609  call this%apt_accumulate_ccterm(n1, q, ccratin, ccratout)
610  end do
611  !
612  ! -- WITHDRAWAL
613  idx = idx + 1
614  nlist = this%flowbudptr%budterm(this%idxbudwdrl)%nlist
615  call this%budobj%budterm(idx)%reset(nlist)
616  do j = 1, nlist
617  call this%lkt_wdrl_term(j, n1, n2, q)
618  call this%budobj%budterm(idx)%update_term(n1, n2, q)
619  call this%apt_accumulate_ccterm(n1, q, ccratin, ccratout)
620  end do
621  !
622  ! -- EXT-OUTFLOW
623  idx = idx + 1
624  nlist = this%flowbudptr%budterm(this%idxbudoutf)%nlist
625  call this%budobj%budterm(idx)%reset(nlist)
626  do j = 1, nlist
627  call this%lkt_outf_term(j, n1, n2, q)
628  call this%budobj%budterm(idx)%update_term(n1, n2, q)
629  call this%apt_accumulate_ccterm(n1, q, ccratin, ccratout)
630  end do
631  end subroutine lkt_fill_budobj
632 
633  !> @brief Allocate scalars specific to the lake mass transport (LKT)
634  !! package.
635  !<
636  subroutine allocate_scalars(this)
637  ! -- modules
639  ! -- dummy
640  class(gwtlkttype) :: this
641  ! -- local
642  !
643  ! -- allocate scalars in TspAptType
644  call this%TspAptType%allocate_scalars()
645  !
646  ! -- Allocate
647  call mem_allocate(this%idxbudrain, 'IDXBUDRAIN', this%memoryPath)
648  call mem_allocate(this%idxbudevap, 'IDXBUDEVAP', this%memoryPath)
649  call mem_allocate(this%idxbudroff, 'IDXBUDROFF', this%memoryPath)
650  call mem_allocate(this%idxbudiflw, 'IDXBUDIFLW', this%memoryPath)
651  call mem_allocate(this%idxbudwdrl, 'IDXBUDWDRL', this%memoryPath)
652  call mem_allocate(this%idxbudoutf, 'IDXBUDOUTF', this%memoryPath)
653  !
654  ! -- Initialize
655  this%idxbudrain = 0
656  this%idxbudevap = 0
657  this%idxbudroff = 0
658  this%idxbudiflw = 0
659  this%idxbudwdrl = 0
660  this%idxbudoutf = 0
661  end subroutine allocate_scalars
662 
663  !> @brief Allocate arrays specific to the lake mass transport (LKT)
664  !! package.
665  !<
666  subroutine lkt_allocate_arrays(this)
667  ! -- modules
669  ! -- dummy
670  class(gwtlkttype), intent(inout) :: this
671  !
672  ! -- alias into the input context's permanent, feature-indexed arrays
673  ! (allocated and DZERO-initialized by the input context)
674  call mem_setptr(this%concrain, 'RAINFALL', this%input_mempath)
675  call mem_setptr(this%concevap, 'EVAPORATION', this%input_mempath)
676  call mem_setptr(this%concroff, 'RUNOFF', this%input_mempath)
677  call mem_setptr(this%conciflw, 'EXT_INFLOW', this%input_mempath)
678  !
679  ! -- call standard TspAptType allocate arrays
680  call this%TspAptType%apt_allocate_arrays()
681  !
682  end subroutine lkt_allocate_arrays
683 
684  !> @brief Alias deprecated LKT variable names to their current storage
685  !<
687  ! -- modules
689  ! -- dummy
690  class(gwtlkttype), intent(inout) :: this
691  ! -- code
692  !
693  ! -- names common to all advanced transport packages
694  call this%TspAptType%apt_checkin_deprecated_names()
695  !
696  call mem_alias_deprecated(this%concrain, 'CONCRAIN', this%memoryPath, &
697  'RAINFALL', this%input_mempath, '6.8.2')
698  call mem_alias_deprecated(this%concevap, 'CONCEVAP', this%memoryPath, &
699  'EVAPORATION', this%input_mempath, '6.8.2')
700  call mem_alias_deprecated(this%concroff, 'CONCROFF', this%memoryPath, &
701  'RUNOFF', this%input_mempath, '6.8.2')
702  call mem_alias_deprecated(this%conciflw, 'CONCIFLW', this%memoryPath, &
703  'EXT_INFLOW', this%input_mempath, '6.8.2')
704  end subroutine lkt_checkin_deprecated_names
705 
706  !> @brief Deallocate memory
707  !<
708  subroutine lkt_da(this)
709  ! -- modules
711  ! -- dummy
712  class(gwtlkttype) :: this
713  ! -- local
714  !
715  ! -- deallocate scalars
716  call mem_deallocate(this%idxbudrain)
717  call mem_deallocate(this%idxbudevap)
718  call mem_deallocate(this%idxbudroff)
719  call mem_deallocate(this%idxbudiflw)
720  call mem_deallocate(this%idxbudwdrl)
721  call mem_deallocate(this%idxbudoutf)
722  !
723  ! -- input-context-owned aliases, not package-allocated
724  nullify (this%concrain)
725  nullify (this%concevap)
726  nullify (this%concroff)
727  nullify (this%conciflw)
728  !
729  ! -- deallocate scalars in TspAptType
730  call this%TspAptType%bnd_da()
731  end subroutine lkt_da
732 
733  !> @brief Rain term
734  !<
735  subroutine lkt_rain_term(this, ientry, n1, n2, rrate, &
736  rhsval, hcofval)
737  ! -- dummy
738  class(gwtlkttype) :: this
739  integer(I4B), intent(in) :: ientry
740  integer(I4B), intent(inout) :: n1
741  integer(I4B), intent(inout) :: n2
742  real(DP), intent(inout), optional :: rrate
743  real(DP), intent(inout), optional :: rhsval
744  real(DP), intent(inout), optional :: hcofval
745  ! -- local
746  real(DP) :: qbnd
747  real(DP) :: ctmp
748  !
749  n1 = this%flowbudptr%budterm(this%idxbudrain)%id1(ientry)
750  n2 = this%flowbudptr%budterm(this%idxbudrain)%id2(ientry)
751  qbnd = this%flowbudptr%budterm(this%idxbudrain)%flow(ientry)
752  ctmp = this%concrain(n1)
753  if (present(rrate)) rrate = ctmp * qbnd
754  if (present(rhsval)) rhsval = -rrate
755  if (present(hcofval)) hcofval = dzero
756  end subroutine lkt_rain_term
757 
758  !> @brief Evaporative term
759  !<
760  subroutine lkt_evap_term(this, ientry, n1, n2, rrate, &
761  rhsval, hcofval)
762  ! -- dummy
763  class(gwtlkttype) :: this
764  integer(I4B), intent(in) :: ientry
765  integer(I4B), intent(inout) :: n1
766  integer(I4B), intent(inout) :: n2
767  real(DP), intent(inout), optional :: rrate
768  real(DP), intent(inout), optional :: rhsval
769  real(DP), intent(inout), optional :: hcofval
770  ! -- local
771  real(DP) :: qbnd
772  real(DP) :: ctmp
773  real(DP) :: omega
774  !
775  n1 = this%flowbudptr%budterm(this%idxbudevap)%id1(ientry)
776  n2 = this%flowbudptr%budterm(this%idxbudevap)%id2(ientry)
777  ! -- note that qbnd is negative for evap
778  qbnd = this%flowbudptr%budterm(this%idxbudevap)%flow(ientry)
779  ctmp = this%concevap(n1)
780  if (this%xnewpak(n1) < ctmp) then
781  omega = done
782  else
783  omega = dzero
784  end if
785  if (present(rrate)) &
786  rrate = omega * qbnd * this%xnewpak(n1) + &
787  (done - omega) * qbnd * ctmp
788  if (present(rhsval)) rhsval = -(done - omega) * qbnd * ctmp
789  if (present(hcofval)) hcofval = omega * qbnd
790  end subroutine lkt_evap_term
791 
792  !> @brief Runoff term
793  !<
794  subroutine lkt_roff_term(this, ientry, n1, n2, rrate, &
795  rhsval, hcofval)
796  ! -- dummy
797  class(gwtlkttype) :: this
798  integer(I4B), intent(in) :: ientry
799  integer(I4B), intent(inout) :: n1
800  integer(I4B), intent(inout) :: n2
801  real(DP), intent(inout), optional :: rrate
802  real(DP), intent(inout), optional :: rhsval
803  real(DP), intent(inout), optional :: hcofval
804  ! -- local
805  real(DP) :: qbnd
806  real(DP) :: ctmp
807  !
808  n1 = this%flowbudptr%budterm(this%idxbudroff)%id1(ientry)
809  n2 = this%flowbudptr%budterm(this%idxbudroff)%id2(ientry)
810  qbnd = this%flowbudptr%budterm(this%idxbudroff)%flow(ientry)
811  ctmp = this%concroff(n1)
812  if (present(rrate)) rrate = ctmp * qbnd
813  if (present(rhsval)) rhsval = -rrate
814  if (present(hcofval)) hcofval = dzero
815  end subroutine lkt_roff_term
816 
817  !> @brief Inflow Term
818  !!
819  !! Accounts for mass flowing into a lake from a connected stream, for
820  !! example.
821  !<
822  subroutine lkt_iflw_term(this, ientry, n1, n2, rrate, &
823  rhsval, hcofval)
824  ! -- dummy
825  class(gwtlkttype) :: this
826  integer(I4B), intent(in) :: ientry
827  integer(I4B), intent(inout) :: n1
828  integer(I4B), intent(inout) :: n2
829  real(DP), intent(inout), optional :: rrate
830  real(DP), intent(inout), optional :: rhsval
831  real(DP), intent(inout), optional :: hcofval
832  ! -- local
833  real(DP) :: qbnd
834  real(DP) :: ctmp
835  !
836  n1 = this%flowbudptr%budterm(this%idxbudiflw)%id1(ientry)
837  n2 = this%flowbudptr%budterm(this%idxbudiflw)%id2(ientry)
838  qbnd = this%flowbudptr%budterm(this%idxbudiflw)%flow(ientry)
839  ctmp = this%conciflw(n1)
840  if (present(rrate)) rrate = ctmp * qbnd
841  if (present(rhsval)) rhsval = -rrate
842  if (present(hcofval)) hcofval = dzero
843  end subroutine lkt_iflw_term
844 
845  !> @brief Specified withdrawal term
846  !!
847  !! Accounts for mass associated with a withdrawal of water from a lake
848  !! or group of lakes.
849  !<
850  subroutine lkt_wdrl_term(this, ientry, n1, n2, rrate, &
851  rhsval, hcofval)
852  ! -- dummy
853  class(gwtlkttype) :: this
854  integer(I4B), intent(in) :: ientry
855  integer(I4B), intent(inout) :: n1
856  integer(I4B), intent(inout) :: n2
857  real(DP), intent(inout), optional :: rrate
858  real(DP), intent(inout), optional :: rhsval
859  real(DP), intent(inout), optional :: hcofval
860  ! -- local
861  real(DP) :: qbnd
862  real(DP) :: ctmp
863  !
864  n1 = this%flowbudptr%budterm(this%idxbudwdrl)%id1(ientry)
865  n2 = this%flowbudptr%budterm(this%idxbudwdrl)%id2(ientry)
866  qbnd = this%flowbudptr%budterm(this%idxbudwdrl)%flow(ientry)
867  ctmp = this%xnewpak(n1)
868  if (present(rrate)) rrate = ctmp * qbnd
869  if (present(rhsval)) rhsval = dzero
870  if (present(hcofval)) hcofval = qbnd
871  end subroutine lkt_wdrl_term
872 
873  !> @brief Outflow term
874  !!
875  !! Accounts for the mass leaving a lake, for example, mass exiting a
876  !! lake via a flow into a draining stream channel.
877  !<
878  subroutine lkt_outf_term(this, ientry, n1, n2, rrate, &
879  rhsval, hcofval)
880  ! -- dummy
881  class(gwtlkttype) :: this
882  integer(I4B), intent(in) :: ientry
883  integer(I4B), intent(inout) :: n1
884  integer(I4B), intent(inout) :: n2
885  real(DP), intent(inout), optional :: rrate
886  real(DP), intent(inout), optional :: rhsval
887  real(DP), intent(inout), optional :: hcofval
888  ! -- local
889  real(DP) :: qbnd
890  real(DP) :: ctmp
891  !
892  n1 = this%flowbudptr%budterm(this%idxbudoutf)%id1(ientry)
893  n2 = this%flowbudptr%budterm(this%idxbudoutf)%id2(ientry)
894  qbnd = this%flowbudptr%budterm(this%idxbudoutf)%flow(ientry)
895  ctmp = this%xnewpak(n1)
896  if (present(rrate)) rrate = ctmp * qbnd
897  if (present(rhsval)) rhsval = dzero
898  if (present(hcofval)) hcofval = qbnd
899  end subroutine lkt_outf_term
900 
901  !> @brief Defined observation types
902  !!
903  !! Store the observation type supported by the APT package and override
904  !! BndType%bnd_df_obs
905  !<
906  subroutine lkt_df_obs(this)
907  ! -- modules
908  ! -- dummy
909  class(gwtlkttype) :: this
910  ! -- local
911  integer(I4B) :: indx
912  !
913  ! -- Store obs type and assign procedure pointer
914  ! for concentration observation type.
915  call this%obs%StoreObsType('concentration', .false., indx)
916  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
917  !
918  ! -- Store obs type and assign procedure pointer
919  ! for flow between features, such as lake to lake.
920  call this%obs%StoreObsType('flow-ja-face', .true., indx)
921  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid12
922  !
923  ! -- Store obs type and assign procedure pointer
924  ! for from-mvr observation type.
925  call this%obs%StoreObsType('from-mvr', .true., indx)
926  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
927  !
928  ! -- Store obs type and assign procedure pointer
929  ! for to-mvr observation type.
930  call this%obs%StoreObsType('to-mvr', .true., indx)
931  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
932  !
933  ! -- Store obs type and assign procedure pointer
934  ! for storage observation type.
935  call this%obs%StoreObsType('storage', .true., indx)
936  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
937  !
938  ! -- Store obs type and assign procedure pointer
939  ! for constant observation type.
940  call this%obs%StoreObsType('constant', .true., indx)
941  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
942  !
943  ! -- Store obs type and assign procedure pointer
944  ! for observation type: lkt
945  call this%obs%StoreObsType('lkt', .true., indx)
946  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid12
947  !
948  ! -- Store obs type and assign procedure pointer
949  ! for rainfall observation type.
950  call this%obs%StoreObsType('rainfall', .true., indx)
951  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
952  !
953  ! -- Store obs type and assign procedure pointer
954  ! for evaporation observation type.
955  call this%obs%StoreObsType('evaporation', .true., indx)
956  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
957  !
958  ! -- Store obs type and assign procedure pointer
959  ! for runoff observation type.
960  call this%obs%StoreObsType('runoff', .true., indx)
961  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
962  !
963  ! -- Store obs type and assign procedure pointer
964  ! for inflow observation type.
965  call this%obs%StoreObsType('ext-inflow', .true., indx)
966  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
967  !
968  ! -- Store obs type and assign procedure pointer
969  ! for withdrawal observation type.
970  call this%obs%StoreObsType('withdrawal', .true., indx)
971  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
972  !
973  ! -- Store obs type and assign procedure pointer
974  ! for ext-outflow observation type.
975  call this%obs%StoreObsType('ext-outflow', .true., indx)
976  this%obs%obsData(indx)%ProcessIdPtr => apt_process_obsid
977  end subroutine lkt_df_obs
978 
979  !> @brief Process package specific obs
980  !!
981  !! Method to process specific observations for this package.
982  !<
983  subroutine lkt_rp_obs(this, obsrv, found)
984  ! -- dummy
985  class(gwtlkttype), intent(inout) :: this !< package class
986  type(observetype), intent(inout) :: obsrv !< observation object
987  logical, intent(inout) :: found !< indicate whether observation was found
988  ! -- local
989  !
990  found = .true.
991  select case (obsrv%ObsTypeId)
992  case ('RAINFALL')
993  call this%rp_obs_byfeature(obsrv)
994  case ('EVAPORATION')
995  call this%rp_obs_byfeature(obsrv)
996  case ('RUNOFF')
997  call this%rp_obs_byfeature(obsrv)
998  case ('EXT-INFLOW')
999  call this%rp_obs_byfeature(obsrv)
1000  case ('WITHDRAWAL')
1001  call this%rp_obs_byfeature(obsrv)
1002  case ('EXT-OUTFLOW')
1003  call this%rp_obs_byfeature(obsrv)
1004  case ('TO-MVR')
1005  call this%rp_obs_budterm(obsrv, &
1006  this%flowbudptr%budterm(this%idxbudtmvr))
1007  case default
1008  found = .false.
1009  end select
1010  end subroutine lkt_rp_obs
1011 
1012  !> @brief Calculate observation value and pass it back to APT
1013  !<
1014  subroutine lkt_bd_obs(this, obstypeid, jj, v, found)
1015  ! -- dummy
1016  class(gwtlkttype), intent(inout) :: this
1017  character(len=*), intent(in) :: obstypeid
1018  real(DP), intent(inout) :: v
1019  integer(I4B), intent(in) :: jj
1020  logical, intent(inout) :: found
1021  ! -- local
1022  integer(I4B) :: n1, n2
1023  !
1024  found = .true.
1025  select case (obstypeid)
1026  case ('RAINFALL')
1027  if (this%iboundpak(jj) /= 0) then
1028  call this%lkt_rain_term(jj, n1, n2, v)
1029  end if
1030  case ('EVAPORATION')
1031  if (this%iboundpak(jj) /= 0) then
1032  call this%lkt_evap_term(jj, n1, n2, v)
1033  end if
1034  case ('RUNOFF')
1035  if (this%iboundpak(jj) /= 0) then
1036  call this%lkt_roff_term(jj, n1, n2, v)
1037  end if
1038  case ('EXT-INFLOW')
1039  if (this%iboundpak(jj) /= 0) then
1040  call this%lkt_iflw_term(jj, n1, n2, v)
1041  end if
1042  case ('WITHDRAWAL')
1043  if (this%iboundpak(jj) /= 0) then
1044  call this%lkt_wdrl_term(jj, n1, n2, v)
1045  end if
1046  case ('EXT-OUTFLOW')
1047  if (this%iboundpak(jj) /= 0) then
1048  call this%lkt_outf_term(jj, n1, n2, v)
1049  end if
1050  case default
1051  found = .false.
1052  end select
1053  end subroutine lkt_bd_obs
1054 
1055 end module gwtlktmodule
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 linelength
maximum length of a standard line
Definition: Constants.f90:45
real(dp), parameter dnodata
real no data constant
Definition: Constants.f90:95
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition: Constants.f90:17
real(dp), parameter dzero
real constant zero
Definition: Constants.f90:65
integer(i4b), parameter lenbudtxt
maximum length of a budget component names
Definition: Constants.f90:37
real(dp), parameter done
real constant 1
Definition: Constants.f90:76
character(len= *), parameter flowtype
Definition: gwt-lkt.f90:54
subroutine lkt_allocate_arrays(this)
Allocate arrays specific to the lake mass transport (LKT) package.
Definition: gwt-lkt.f90:667
subroutine lkt_da(this)
Deallocate memory.
Definition: gwt-lkt.f90:709
subroutine lkt_roff_term(this, ientry, n1, n2, rrate, rhsval, hcofval)
Runoff term.
Definition: gwt-lkt.f90:796
subroutine, public lkt_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, mempath, fmi, eqnsclfac, dvt, dvu, dvua)
Create a new lkt package.
Definition: gwt-lkt.f90:102
subroutine lkt_bd_obs(this, obstypeid, jj, v, found)
Calculate observation value and pass it back to APT.
Definition: gwt-lkt.f90:1015
subroutine lkt_outf_term(this, ientry, n1, n2, rrate, rhsval, hcofval)
Outflow term.
Definition: gwt-lkt.f90:880
subroutine lkt_rp_obs(this, obsrv, found)
Process package specific obs.
Definition: gwt-lkt.f90:984
subroutine find_lkt_package(this)
Find corresponding lkt package.
Definition: gwt-lkt.f90:158
character(len= *), parameter ftype
Definition: gwt-lkt.f90:53
subroutine lkt_iflw_term(this, ientry, n1, n2, rrate, rhsval, hcofval)
Inflow Term.
Definition: gwt-lkt.f90:824
subroutine lkt_solve(this)
Add terms specific to lakes to the explicit lake solve.
Definition: gwt-lkt.f90:390
subroutine lkt_evap_term(this, ientry, n1, n2, rrate, rhsval, hcofval)
Evaporative term.
Definition: gwt-lkt.f90:762
subroutine allocate_scalars(this)
Allocate scalars specific to the lake mass transport (LKT) package.
Definition: gwt-lkt.f90:637
subroutine lkt_rain_term(this, ientry, n1, n2, rrate, rhsval, hcofval)
Rain term.
Definition: gwt-lkt.f90:737
integer(i4b) function lkt_get_nbudterms(this)
Function to return the number of budget terms just for this package.
Definition: gwt-lkt.f90:451
subroutine lkt_checkin_deprecated_names(this)
Alias deprecated LKT variable names to their current storage.
Definition: gwt-lkt.f90:687
subroutine lkt_setup_budobj(this, idx)
Set up the budget object that stores all the lake flows.
Definition: gwt-lkt.f90:465
subroutine lkt_fill_budobj(this, idx, x, flowja, ccratin, ccratout)
Copy flow terms into thisbudobj.
Definition: gwt-lkt.f90:558
subroutine lkt_fc_expanded(this, rhs, ia, idxglo, matrix_sln)
Add matrix terms related to LKT.
Definition: gwt-lkt.f90:305
real(dp) function lkt_setting_value(this, itemno, key)
Value for a package-specific PERIOD setting.
Definition: gwt-lkt.f90:280
character(len=16) text
Definition: gwt-lkt.f90:55
subroutine lkt_wdrl_term(this, ientry, n1, n2, rrate, rhsval, hcofval)
Specified withdrawal term.
Definition: gwt-lkt.f90:852
subroutine lkt_df_obs(this)
Defined observation types.
Definition: gwt-lkt.f90:907
This module defines variable data types.
Definition: kind.f90:8
Previous variable names checked in as deprecated aliases.
Definition: MemoryAlias.f90:7
This module contains the derived types ObserveType and ObsDataType.
Definition: Observe.f90:15
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:204
subroutine, public apt_process_obsid(obsrv, dis, inunitobs, iout)
Process observation IDs for an advanced package.
Definition: tsp-apt.f90:2729
subroutine, public apt_process_obsid12(obsrv, dis, inunitobs, iout)
Process observation IDs for a package.
Definition: tsp-apt.f90:2772
@ brief BndType
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23