MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
gwe.f90
Go to the documentation of this file.
1 ! Groundwater Energy Transport (GWE) Model
2 
3 module gwemodule
4 
5  use kindmodule, only: dp, i4b
13  use gwecndmodule, only: gwecndtype
14  use gweestmodule, only: gweesttype
15  use budgetmodule, only: budgettype
19 
20  implicit none
21 
22  private
23  public :: gwe_cr
24  public :: gwemodeltype
25  public :: castasgwemodel
26 
27  public :: gwe_nbasepkg, gwe_nmultipkg
28  public :: gwe_basepkg, gwe_multipkg
29  character(len=LENVARNAME), parameter :: dvt = 'TEMPERATURE ' !< dependent variable type, varies based on model type
30  character(len=LENVARNAME), parameter :: dvu = 'ENERGY ' !< dependent variable unit of measure, either "mass" or "energy"
31  character(len=LENVARNAME), parameter :: dvua = 'E ' !< abbreviation of the dependent variable unit of measure, either "M" or "E"
32 
33  type, extends(transportmodeltype) :: gwemodeltype
34 
35  type(gweinputdatatype), pointer :: gwecommon => null() !< container for data shared with multiple packages
36  type(gweesttype), pointer :: est => null() !< mass storage and transfer package
37  type(gwecndtype), pointer :: cnd => null() !< dispersion package
38  integer(I4B), pointer :: inest => null() ! unit number EST
39  integer(I4B), pointer :: incnd => null() ! unit number CND
40 
41  contains
42 
43  procedure :: model_df => gwe_df
44  procedure :: model_ac => gwe_ac
45  procedure :: model_mc => gwe_mc
46  procedure :: model_ar => gwe_ar
47  procedure :: model_rp => gwe_rp
48  procedure :: model_dt => gwe_dt
49  procedure :: model_ad => gwe_ad
50  procedure :: model_cf => gwe_cf
51  procedure :: model_fc => gwe_fc
52  procedure :: model_cc => gwe_cc
53  procedure :: model_cq => gwe_cq
54  procedure :: model_bd => gwe_bd
55  procedure :: tsp_ot_flow => gwe_ot_flow
56  procedure :: model_da => gwe_da
57  procedure :: model_bdentry => gwe_bdentry
58  procedure :: allocate_scalars
59  procedure :: get_iasym => gwe_get_iasym
60  procedure :: create_packages => create_gwe_packages
61  procedure, private :: create_bndpkgs
62  procedure, private :: package_create
63 
64  end type gwemodeltype
65 
66  !> @brief GWE base package array descriptors
67  !!
68  !! GWE6 model base package types. Only listed packages are candidates
69  !! for input and these will be loaded in the order specified.
70  !<
71  integer(I4B), parameter :: gwe_nbasepkg = 50
72  character(len=LENPACKAGETYPE), dimension(GWE_NBASEPKG) :: gwe_basepkg
73  data gwe_basepkg/'DIS6 ', 'DISV6', 'DISU6', ' ', ' ', & ! 5
74  &'IC6 ', 'FMI6 ', 'EST6 ', 'ADV6 ', ' ', & ! 10
75  &'CND6 ', 'SSM6 ', 'MVE6 ', 'OC6 ', ' ', & ! 15
76  &'OBS6 ', ' ', ' ', ' ', ' ', & ! 20
77  &30*' '/ ! 50
78 
79  !> @brief GWE multi package array descriptors
80  !!
81  !! GWE6 model multi-instance package types. Only listed packages are
82  !! candidates for input and these will be loaded in the order specified.
83  !<
84  integer(I4B), parameter :: gwe_nmultipkg = 50
85  character(len=LENPACKAGETYPE), dimension(GWE_NMULTIPKG) :: gwe_multipkg
86  data gwe_multipkg/'CTP6 ', 'ESL6 ', 'LKE6 ', 'SFE6 ', ' ', & ! 5
87  &'MWE6 ', 'UZE6 ', 'API6 ', ' ', ' ', & ! 10
88  &40*' '/ ! 50
89 
90  ! -- Size of supported model package arrays
91  integer(I4B), parameter :: niunit_gwe = gwe_nbasepkg + gwe_nmultipkg
92 
93 contains
94 
95  !> @brief Create a new groundwater energy transport model object
96  !<
97  subroutine gwe_cr(filename, id, modelname)
98  ! -- modules
99  use listsmodule, only: basemodellist
105  use budgetmodule, only: budget_cr
107  ! -- dummy
108  character(len=*), intent(in) :: filename !< input file
109  integer(I4B), intent(in) :: id !< consecutive model number listed in mfsim.nam
110  character(len=*), intent(in) :: modelname !< name of the model
111  ! -- local
112  integer(I4B) :: indis
113  type(gwemodeltype), pointer :: this
114  class(basemodeltype), pointer :: model
115  !
116  ! -- Allocate a new GWE Model (this) and add it to basemodellist
117  allocate (this)
118  !
119  ! -- Set memory path before allocation in memory manager can be done
120  this%memoryPath = create_mem_path(modelname)
121  !
122  ! -- Allocate scalars and add model to basemodellist
123  call this%allocate_scalars(modelname)
124  !
125  ! -- Set labels for transport model - needed by create_packages() below
126  call this%set_tsp_labels(this%macronym, dvt, dvu, dvua)
127  !
128  model => this
129  call addbasemodeltolist(basemodellist, model)
130  !
131  ! -- Instantiate shared data container
132  call gweshared_dat_cr(this%gwecommon)
133  !
134  ! -- Call parent class routine
135  call this%tsp_cr(filename, id, modelname, 'GWE', indis)
136  !
137  ! -- Create model packages
138  call this%create_packages(indis)
139  end subroutine gwe_cr
140 
141  !> @brief Define packages of the GWE model
142  !!
143  !! This subroutine defines a gwe model type. Steps include:
144  !! - call df routines for each package
145  !! - set variables and pointers
146  !<
147  subroutine gwe_df(this)
148  ! -- modules
149  use simmodule, only: store_error
150  ! -- dummy
151  class(gwemodeltype) :: this
152  ! -- local
153  integer(I4B) :: ip
154  class(bndtype), pointer :: packobj
155  !
156  ! -- Define packages and utility objects
157  call this%dis%dis_df()
158  call this%fmi%fmi_df(this%dis, 0)
159  if (this%inmvt > 0) call this%mvt%mvt_df(this%dis)
160  if (this%inadv > 0) call this%adv%adv_df()
161  if (this%incnd > 0) call this%cnd%cnd_df(this%dis)
162  if (this%inssm > 0) call this%ssm%ssm_df()
163  call this%oc%oc_df()
164  call this%budget%budget_df(niunit_gwe, this%depvarunit, &
165  this%depvarunitabbrev)
166  !
167  ! -- Check for SSM package
168  if (this%inssm == 0) then
169  if (this%fmi%nflowpack > 0) then
170  call store_error('Flow model has boundary packages, but there &
171  &is no SSM package. The SSM package must be activated.', &
172  terminate=.true.)
173  end if
174  end if
175  !
176  ! -- Assign or point model members to dis members
177  this%neq = this%dis%nodes
178  this%nja = this%dis%nja
179  this%ia => this%dis%con%ia
180  this%ja => this%dis%con%ja
181  !
182  ! -- Allocate model arrays, now that neq and nja are assigned
183  call this%allocate_arrays()
184  !
185  ! -- Define packages and assign iout for time series managers
186  do ip = 1, this%bndlist%Count()
187  packobj => getbndfromlist(this%bndlist, ip)
188  call packobj%bnd_df(this%neq, this%dis)
189  packobj%TsManager%iout = this%iout
190  packobj%TasManager%iout = this%iout
191  end do
192  !
193  ! -- Store information needed for observations
194  call this%obs%obs_df(this%iout, this%name, 'GWE', this%dis)
195  end subroutine gwe_df
196 
197  !> @brief Add the internal connections of this model to the sparse matrix
198  !<
199  subroutine gwe_ac(this, sparse)
200  ! -- modules
201  use sparsemodule, only: sparsematrix
202  ! -- dummy
203  class(gwemodeltype) :: this
204  type(sparsematrix), intent(inout) :: sparse
205  ! -- local
206  class(bndtype), pointer :: packobj
207  integer(I4B) :: ip
208  !
209  ! -- Add the internal connections of this model to sparse
210  call this%dis%dis_ac(this%moffset, sparse)
211  if (this%incnd > 0) &
212  call this%cnd%cnd_ac(this%moffset, sparse)
213  !
214  ! -- Add any package connections
215  do ip = 1, this%bndlist%Count()
216  packobj => getbndfromlist(this%bndlist, ip)
217  call packobj%bnd_ac(this%moffset, sparse)
218  end do
219  end subroutine gwe_ac
220 
221  !> @brief Map the positions of the GWE model connections in the numerical
222  !! solution coefficient matrix.
223  !<
224  subroutine gwe_mc(this, matrix_sln)
225  ! -- dummy
226  class(gwemodeltype) :: this
227  class(matrixbasetype), pointer :: matrix_sln !< global system matrix
228  ! -- local
229  class(bndtype), pointer :: packobj
230  integer(I4B) :: ip
231  !
232  ! -- Find the position of each connection in the global ia, ja structure
233  ! and store them in idxglo.
234  call this%dis%dis_mc(this%moffset, this%idxglo, matrix_sln)
235  !
236  if (this%incnd > 0) call this%cnd%cnd_mc(this%moffset, matrix_sln)
237  !
238  ! -- Map any package connections
239  do ip = 1, this%bndlist%Count()
240  packobj => getbndfromlist(this%bndlist, ip)
241  call packobj%bnd_mc(this%moffset, matrix_sln)
242  end do
243  end subroutine gwe_mc
244 
245  !> @brief GWE Model Allocate and Read
246  !!
247  !! This subroutine:
248  !! - allocates and reads packages that are part of this model,
249  !! - allocates memory for arrays used by this model object
250  !<
251  subroutine gwe_ar(this)
252  ! -- modules
253  use constantsmodule, only: dhnoflo
254  ! -- dummy
255  class(gwemodeltype) :: this
256  ! -- locals
257  integer(I4B) :: ip
258  class(bndtype), pointer :: packobj
259  !
260  ! -- Allocate and read modules attached to model
261  call this%fmi%fmi_ar(this%ibound)
262  if (this%inmvt > 0) call this%mvt%mvt_ar()
263  if (this%inic > 0) call this%ic%ic_ar(this%x)
264  if (this%inest > 0) call this%est%est_ar(this%dis, this%ibound)
265  if (this%inadv > 0) call this%adv%adv_ar(this%dis, this%ibound)
266  if (this%incnd > 0) call this%cnd%cnd_ar(this%ibound, this%est%porosity)
267  if (this%inssm > 0) call this%ssm%ssm_ar(this%dis, this%ibound, this%x)
268  if (this%inobs > 0) call this%obs%tsp_obs_ar(this%ic, this%x, this%flowja)
269  !
270  ! -- Set governing equation scale factor
271  this%eqnsclfac = this%gwecommon%gwerhow * this%gwecommon%gwecpw
272  !
273  ! -- Call dis_ar to write binary grid file
274  !call this%dis%dis_ar(this%npf%icelltype)
275  !
276  ! -- Set up output control
277  call this%oc%oc_ar(this%x, this%dis, dhnoflo, this%depvartype)
278  call this%budget%set_ibudcsv(this%oc%ibudcsv)
279  !
280  ! -- Package input files now open, so allocate and read
281  do ip = 1, this%bndlist%Count()
282  packobj => getbndfromlist(this%bndlist, ip)
283  call packobj%set_pointers(this%dis%nodes, this%ibound, this%x, &
284  this%xold, this%flowja)
285  ! -- Read and allocate package
286  call packobj%bnd_ar()
287  end do
288  end subroutine gwe_ar
289 
290  !> @brief GWE Model Read and Prepare
291  !!
292  !! This subroutine calls the attached packages' read and prepare routines
293  !<
294  subroutine gwe_rp(this)
295  ! -- modules
296  use tdismodule, only: readnewdata
297  ! -- dummy
298  class(gwemodeltype) :: this
299  ! -- local
300  class(bndtype), pointer :: packobj
301  integer(I4B) :: ip
302  !
303  ! -- In fmi, check for mvt and mvrbudobj consistency
304  call this%fmi%fmi_rp(this%inmvt)
305  if (this%inmvt > 0) call this%mvt%mvt_rp()
306  !
307  ! -- Check with TDIS on whether or not it is time to RP
308  if (.not. readnewdata) return
309  !
310  ! -- Read and prepare
311  if (this%inoc > 0) call this%oc%oc_rp()
312  if (this%inssm > 0) call this%ssm%ssm_rp()
313  do ip = 1, this%bndlist%Count()
314  packobj => getbndfromlist(this%bndlist, ip)
315  call packobj%bnd_rp()
316  call packobj%bnd_rp_obs()
317  end do
318  end subroutine gwe_rp
319 
320  !> @brief GWT Model time step size
321  !!
322  !! Calculate the maximum allowable time step size subject to time-step
323  !! constraints. If adaptive time steps are used, then the time step used
324  !! will be no larger than dtmax calculated here.
325  !<
326  subroutine gwe_dt(this)
327  use tdismodule, only: kstp, kper
329  ! dummy
330  class(gwemodeltype) :: this
331  ! local
332  real(DP) :: dtmax
333  character(len=LINELENGTH) :: msg
334  dtmax = dnodata
335 
336  ! advection package courant stability
337  call this%adv%adv_dt(dtmax, msg, this%est%porosity)
338  if (msg /= '') then
339  call ats_submit_delt(kstp, kper, dtmax, msg)
340  end if
341  end subroutine gwe_dt
342 
343  !> @brief GWE Model Time Step Advance
344  !!
345  !! This subroutine calls the attached packages' advance subroutines
346  !<
347  subroutine gwe_ad(this)
348  ! -- modules
350  ! -- dummy
351  class(gwemodeltype) :: this
352  class(bndtype), pointer :: packobj
353  ! -- local
354  integer(I4B) :: irestore
355  integer(I4B) :: ip, n
356  !
357  ! -- Reset state variable
358  irestore = 0
359  if (ifailedstepretry > 0) irestore = 1
360  if (irestore == 0) then
361  !
362  ! -- Copy x into xold
363  do n = 1, this%dis%nodes
364  if (this%ibound(n) == 0) then
365  this%xold(n) = dzero
366  else
367  this%xold(n) = this%x(n)
368  end if
369  end do
370  else
371  !
372  ! -- Copy xold into x if this time step is a redo
373  do n = 1, this%dis%nodes
374  this%x(n) = this%xold(n)
375  end do
376  end if
377  !
378  ! -- Advance fmi
379  call this%fmi%fmi_ad(this%x)
380  !
381  ! -- Advance
382  if (this%incnd > 0) call this%cnd%cnd_ad()
383  if (this%inssm > 0) call this%ssm%ssm_ad()
384  do ip = 1, this%bndlist%Count()
385  packobj => getbndfromlist(this%bndlist, ip)
386  call packobj%bnd_ad()
387  if (isimcheck > 0) then
388  call packobj%bnd_ck()
389  end if
390  end do
391  !
392  ! -- Push simulated values to preceding time/subtime step
393  call this%obs%obs_ad()
394  end subroutine gwe_ad
395 
396  !> @brief GWE Model calculate coefficients
397  !!
398  !! This subroutine calls the attached packages' calculate coefficients
399  !! subroutines
400  !<
401  subroutine gwe_cf(this, kiter)
402  ! -- dummy
403  class(gwemodeltype) :: this
404  integer(I4B), intent(in) :: kiter
405  ! -- local
406  class(bndtype), pointer :: packobj
407  integer(I4B) :: ip
408  !
409  ! -- Call package cf routines
410  do ip = 1, this%bndlist%Count()
411  packobj => getbndfromlist(this%bndlist, ip)
412  call packobj%bnd_cf()
413  end do
414  end subroutine gwe_cf
415 
416  !> @brief GWE Model fill coefficients
417  !!
418  !! This subroutine calls the attached packages' fill coefficients
419  !! subroutines
420  !<
421  subroutine gwe_fc(this, kiter, matrix_sln, inwtflag)
422  ! -- dummy
423  class(gwemodeltype) :: this
424  integer(I4B), intent(in) :: kiter
425  class(matrixbasetype), pointer :: matrix_sln
426  integer(I4B), intent(in) :: inwtflag
427  ! -- local
428  class(bndtype), pointer :: packobj
429  integer(I4B) :: ip
430  !
431  ! -- Call fc routines
432  call this%fmi%fmi_fc(this%dis%nodes, this%xold, this%nja, matrix_sln, &
433  this%idxglo, this%rhs)
434  if (this%inmvt > 0) then
435  call this%mvt%mvt_fc(this%x, this%x)
436  end if
437  if (this%inest > 0) then
438  call this%est%est_fc(this%dis%nodes, this%xold, this%nja, matrix_sln, &
439  this%idxglo, this%x, this%rhs, kiter)
440  end if
441  if (this%inadv > 0) then
442  call this%adv%adv_fc(this%dis%nodes, matrix_sln, this%idxglo, this%x, &
443  this%rhs)
444  end if
445  if (this%incnd > 0) then
446  call this%cnd%cnd_fc(kiter, this%dis%nodes, this%nja, matrix_sln, &
447  this%idxglo, this%rhs, this%x)
448  end if
449  if (this%inssm > 0) then
450  call this%ssm%ssm_fc(matrix_sln, this%idxglo, this%rhs)
451  end if
452  !
453  ! -- Packages
454  do ip = 1, this%bndlist%Count()
455  packobj => getbndfromlist(this%bndlist, ip)
456  call packobj%bnd_fc(this%rhs, this%ia, this%idxglo, matrix_sln)
457  end do
458  end subroutine gwe_fc
459 
460  !> @brief GWE Model Final Convergence Check
461  !!
462  !! If MVR/MVT is active, this subroutine calls the MVR convergence check
463  !! subroutines.
464  !<
465  subroutine gwe_cc(this, innertot, kiter, iend, icnvgmod, cpak, ipak, dpak)
466  ! -- dummy
467  class(gwemodeltype) :: this
468  integer(I4B), intent(in) :: innertot
469  integer(I4B), intent(in) :: kiter
470  integer(I4B), intent(in) :: iend
471  integer(I4B), intent(in) :: icnvgmod
472  character(len=LENPAKLOC), intent(inout) :: cpak
473  integer(I4B), intent(inout) :: ipak
474  real(DP), intent(inout) :: dpak
475  !
476  ! -- If mover is on, then at least 2 outers required
477  if (this%inmvt > 0) call this%mvt%mvt_cc(kiter, iend, icnvgmod, cpak, dpak)
478  end subroutine gwe_cc
479 
480  !> @brief GWE Model calculate flow
481  !!
482  !! This subroutine calls the attached packages' intercell flows (flow ja)
483  !<
484  subroutine gwe_cq(this, icnvg, isuppress_output)
485  ! -- modules
486  use sparsemodule, only: csr_diagsum
487  ! -- dummy
488  class(gwemodeltype) :: this
489  integer(I4B), intent(in) :: icnvg
490  integer(I4B), intent(in) :: isuppress_output
491  ! -- local
492  integer(I4B) :: i
493  integer(I4B) :: ip
494  class(bndtype), pointer :: packobj
495  !
496  ! -- Construct the flowja array. Flowja is calculated each time, even if
497  ! output is suppressed. (flowja is positive into a cell.) The diagonal
498  ! position of the flowja array will contain the flow residual after
499  ! these routines are called, so each package is responsible for adding
500  ! its flow to this diagonal position.
501  do i = 1, this%nja
502  this%flowja(i) = dzero
503  end do
504  if (this%inadv > 0) call this%adv%adv_cq(this%x, this%flowja)
505  if (this%incnd > 0) call this%cnd%cnd_cq(this%x, this%flowja)
506  if (this%inest > 0) call this%est%est_cq(this%dis%nodes, this%x, this%xold, &
507  this%flowja)
508  if (this%inssm > 0) call this%ssm%ssm_cq(this%flowja)
509  if (this%infmi > 0) call this%fmi%fmi_cq(this%x, this%flowja)
510  !
511  ! -- Go through packages and call cq routines. cf() routines are called
512  ! first to regenerate non-linear terms to be consistent with the final
513  ! conc solution.
514  do ip = 1, this%bndlist%Count()
515  packobj => getbndfromlist(this%bndlist, ip)
516  call packobj%bnd_cf()
517  call packobj%bnd_cq(this%x, this%flowja)
518  end do
519  !
520  ! -- Finalize calculation of flowja by adding face flows to the diagonal.
521  ! This results in the flow residual being stored in the diagonal
522  ! position for each cell.
523  call csr_diagsum(this%dis%con%ia, this%flowja)
524  end subroutine gwe_cq
525 
526  !> @brief GWE Model Budget
527  !!
528  !! This subroutine:
529  !! - calculates intercell flows (flowja)
530  !! - calculates package contributions to the model budget
531  !<
532  subroutine gwe_bd(this, icnvg, isuppress_output)
533  ! -- dummy
534  class(gwemodeltype) :: this
535  integer(I4B), intent(in) :: icnvg
536  integer(I4B), intent(in) :: isuppress_output
537  ! -- local
538  integer(I4B) :: ip
539  class(bndtype), pointer :: packobj
540  !
541  ! -- Save the solution convergence flag
542  this%icnvg = icnvg
543  !
544  ! -- Budget routines (start by resetting). Sole purpose of this section
545  ! is to add in and outs to model budget. All ins and out for a model
546  ! should be added here to this%budget. In a subsequent exchange call,
547  ! exchange flows might also be added.
548  call this%budget%reset()
549  if (this%inest > 0) call this%est%est_bd(isuppress_output, this%budget)
550  if (this%inssm > 0) call this%ssm%ssm_bd(isuppress_output, this%budget)
551  if (this%infmi > 0) call this%fmi%fmi_bd(isuppress_output, this%budget)
552  if (this%inmvt > 0) call this%mvt%mvt_bd(this%x, this%x)
553  do ip = 1, this%bndlist%Count()
554  packobj => getbndfromlist(this%bndlist, ip)
555  call packobj%bnd_bd(this%budget)
556  end do
557  end subroutine gwe_bd
558 
559  !> @brief GWE model output routine
560  !!
561  !! Save and print flows
562  !<
563  subroutine gwe_ot_flow(this, icbcfl, ibudfl, icbcun)
564  ! dummy
565  class(gwemodeltype) :: this
566  integer(I4B), intent(in) :: icbcfl
567  integer(I4B), intent(in) :: ibudfl
568  integer(I4B), intent(in) :: icbcun
569  ! local
570 
571  if (this%inest > 0) call this%est%est_ot_flow(icbcfl, icbcun)
572  call this%TransportModelType%tsp_ot_flow(icbcfl, ibudfl, icbcun)
573 
574  end subroutine gwe_ot_flow
575 
576  !> @brief Deallocate
577  !!
578  !! Deallocate memory at conclusion of model run
579  !<
580  subroutine gwe_da(this)
581  ! -- modules
585  ! -- dummy
586  class(gwemodeltype) :: this
587  ! -- local
588  integer(I4B) :: ip
589  class(bndtype), pointer :: packobj
590  !
591  ! -- Deallocate idm memory
592  call memorystore_remove(this%name, 'NAM', idm_context)
593  call memorystore_remove(component=this%name, context=idm_context)
594  !
595  ! -- Internal flow packages deallocate
596  call this%dis%dis_da()
597  call this%ic%ic_da()
598  call this%fmi%fmi_da()
599  call this%adv%adv_da()
600  call this%cnd%cnd_da()
601  call this%ssm%ssm_da()
602  call this%est%est_da()
603  call this%mvt%mvt_da()
604  call this%budget%budget_da()
605  call this%oc%oc_da()
606  call this%obs%obs_da()
607  call this%gwecommon%gweshared_dat_da()
608  !
609  ! -- Internal package objects
610  deallocate (this%dis)
611  deallocate (this%ic)
612  deallocate (this%fmi)
613  deallocate (this%adv)
614  deallocate (this%cnd)
615  deallocate (this%ssm)
616  deallocate (this%est)
617  deallocate (this%mvt)
618  deallocate (this%budget)
619  deallocate (this%oc)
620  deallocate (this%obs)
621  nullify (this%gwecommon)
622  !
623  ! -- Boundary packages
624  do ip = 1, this%bndlist%Count()
625  packobj => getbndfromlist(this%bndlist, ip)
626  call packobj%bnd_da()
627  deallocate (packobj)
628  end do
629  !
630  ! -- Scalars
631  call mem_deallocate(this%inest)
632  call mem_deallocate(this%incnd)
633  !
634  ! -- Parent class members
635  call this%TransportModelType%tsp_da()
636  !
637  ! -- NumericalModelType
638  call this%NumericalModelType%model_da()
639  end subroutine gwe_da
640 
641  !> @brief GroundWater Energy Transport Model Budget Entry
642  !!
643  !! This subroutine adds a budget entry to the flow budget. It was added as
644  !! a method for the gwe model object so that the exchange object could add its
645  !! contributions.
646  !<
647  subroutine gwe_bdentry(this, budterm, budtxt, rowlabel)
648  ! -- modules
649  use constantsmodule, only: lenbudtxt
650  use tdismodule, only: delt
651  ! -- dummy
652  class(gwemodeltype) :: this
653  real(DP), dimension(:, :), intent(in) :: budterm
654  character(len=LENBUDTXT), dimension(:), intent(in) :: budtxt
655  character(len=*), intent(in) :: rowlabel
656  !
657  call this%budget%addentry(budterm, delt, budtxt, rowlabel=rowlabel)
658  end subroutine gwe_bdentry
659 
660  !> @brief return 1 if any package causes the matrix to be asymmetric.
661  !! Otherwise return 0.
662  !<
663  function gwe_get_iasym(this) result(iasym)
664  class(gwemodeltype) :: this
665  ! -- local
666  integer(I4B) :: iasym
667  integer(I4B) :: ip
668  class(bndtype), pointer :: packobj
669  !
670  ! -- Start by setting iasym to zero
671  iasym = 0
672  !
673  ! -- ADV
674  if (this%inadv > 0) then
675  if (this%adv%iasym /= 0) iasym = 1
676  end if
677  !
678  ! -- CND
679  if (this%incnd > 0) then
680  if (this%cnd%ixt3d /= 0) iasym = 1
681  end if
682  !
683  ! -- Check for any packages that introduce matrix asymmetry
684  do ip = 1, this%bndlist%Count()
685  packobj => getbndfromlist(this%bndlist, ip)
686  if (packobj%iasym /= 0) iasym = 1
687  end do
688  end function gwe_get_iasym
689 
690  !> Allocate memory for non-allocatable members
691  !!
692  !! A subroutine for allocating the scalars specific to the GWE model type.
693  !! Additional scalars used by the parent class are allocated by the parent
694  !! class.
695  !<
696  subroutine allocate_scalars(this, modelname)
697  ! -- modules
699  ! -- dummy
700  class(gwemodeltype) :: this
701  character(len=*), intent(in) :: modelname
702  !
703  ! -- Allocate parent class scalars
704  call this%allocate_tsp_scalars(modelname)
705  !
706  ! -- Allocate members that are part of model class
707  call mem_allocate(this%inest, 'INEST', this%memoryPath)
708  call mem_allocate(this%incnd, 'INCND', this%memoryPath)
709  !
710  this%inest = 0
711  this%incnd = 0
712  end subroutine allocate_scalars
713 
714  !> @brief Create boundary condition packages for this model
715  !!
716  !! This subroutine calls the package create routines for packages activated
717  !! by the user.
718  !<
719  subroutine package_create(this, filtyp, ipakid, ipaknum, pakname, mempath, &
720  inunit, iout)
721  ! -- modules
722  use simmodule, only: store_error
723  use gwectpmodule, only: ctp_create
724  use gweeslmodule, only: esl_create
725  use gwelkemodule, only: lke_create
726  use gwesfemodule, only: sfe_create
727  use gwemwemodule, only: mwe_create
728  use gweuzemodule, only: uze_create
729  use apimodule, only: api_create
730  ! -- dummy
731  class(gwemodeltype) :: this
732  character(len=*), intent(in) :: filtyp
733  character(len=LINELENGTH) :: errmsg
734  integer(I4B), intent(in) :: ipakid
735  integer(I4B), intent(in) :: ipaknum
736  character(len=*), intent(in) :: pakname
737  character(len=*), intent(in) :: mempath
738  integer(I4B), intent(in) :: inunit
739  integer(I4B), intent(in) :: iout
740  ! -- local
741  class(bndtype), pointer :: packobj
742  class(bndtype), pointer :: packobj2
743  integer(I4B) :: ip
744  !
745  ! -- This part creates the package object
746  select case (filtyp)
747  case ('CTP6')
748  call ctp_create(packobj, ipakid, ipaknum, inunit, iout, this%name, &
749  pakname, this%depvartype, mempath)
750  case ('ESL6')
751  call esl_create(packobj, ipakid, ipaknum, inunit, iout, this%name, &
752  pakname, this%gwecommon)
753  case ('LKE6')
754  call lke_create(packobj, ipakid, ipaknum, inunit, iout, this%name, &
755  pakname, this%fmi, this%eqnsclfac, this%gwecommon, &
756  this%depvartype, this%depvarunit, this%depvarunitabbrev)
757  case ('SFE6')
758  call sfe_create(packobj, ipakid, ipaknum, inunit, iout, this%name, &
759  pakname, this%fmi, this%eqnsclfac, this%gwecommon, &
760  this%depvartype, this%depvarunit, this%depvarunitabbrev)
761  case ('MWE6')
762  call mwe_create(packobj, ipakid, ipaknum, inunit, iout, this%name, &
763  pakname, this%fmi, this%eqnsclfac, this%gwecommon, &
764  this%depvartype, this%depvarunit, this%depvarunitabbrev)
765  case ('UZE6')
766  call uze_create(packobj, ipakid, ipaknum, inunit, iout, this%name, &
767  pakname, this%fmi, this%eqnsclfac, this%gwecommon, &
768  this%depvartype, this%depvarunit, this%depvarunitabbrev)
769  !case('API6')
770  ! call api_create(packobj, ipakid, ipaknum, inunit, iout, this%name, &
771  ! pakname)
772  case default
773  write (errmsg, *) 'Invalid package type: ', filtyp
774  call store_error(errmsg, terminate=.true.)
775  end select
776  !
777  ! -- Packages is the bndlist that is associated with the parent model
778  ! -- The following statement puts a pointer to this package in the ipakid
779  ! -- position of packages.
780  do ip = 1, this%bndlist%Count()
781  packobj2 => getbndfromlist(this%bndlist, ip)
782  if (packobj2%packName == pakname) then
783  write (errmsg, '(a,a)') 'Cannot create package. Package name '// &
784  'already exists: ', trim(pakname)
785  call store_error(errmsg, terminate=.true.)
786  end if
787  end do
788  call addbndtolist(this%bndlist, packobj)
789  end subroutine package_create
790 
791  !> @brief Cast to GweModelType
792  !<
793  function castasgwemodel(model) result(gwemodel)
794  ! -- dummy
795  class(*), pointer :: model !< The object to be cast
796  ! -- return
797  class(gwemodeltype), pointer :: gwemodel !< The GWE model
798  !
799  gwemodel => null()
800  if (.not. associated(model)) return
801  select type (model)
802  type is (gwemodeltype)
803  gwemodel => model
804  end select
805  end function castasgwemodel
806 
807  !> @brief Source package info and begin to process
808  !<
809  subroutine create_bndpkgs(this, bndpkgs, pkgtypes, pkgnames, &
810  mempaths, inunits)
811  ! -- modules
814  ! -- dummy
815  class(gwemodeltype) :: this
816  integer(I4B), dimension(:), allocatable, intent(inout) :: bndpkgs
817  type(characterstringtype), dimension(:), contiguous, &
818  pointer, intent(inout) :: pkgtypes
819  type(characterstringtype), dimension(:), contiguous, &
820  pointer, intent(inout) :: pkgnames
821  type(characterstringtype), dimension(:), contiguous, &
822  pointer, intent(inout) :: mempaths
823  integer(I4B), dimension(:), contiguous, &
824  pointer, intent(inout) :: inunits
825  ! -- local
826  integer(I4B) :: ipakid, ipaknum
827  character(len=LENFTYPE) :: pkgtype, bndptype
828  character(len=LENPACKAGENAME) :: pkgname
829  character(len=LENMEMPATH) :: mempath
830  integer(I4B), pointer :: inunit
831  integer(I4B) :: n
832  !
833  if (allocated(bndpkgs)) then
834  !
835  ! -- Create stress packages
836  ipakid = 1
837  bndptype = ''
838  do n = 1, size(bndpkgs)
839  !
840  pkgtype = pkgtypes(bndpkgs(n))
841  pkgname = pkgnames(bndpkgs(n))
842  mempath = mempaths(bndpkgs(n))
843  inunit => inunits(bndpkgs(n))
844  !
845  if (bndptype /= pkgtype) then
846  ipaknum = 1
847  bndptype = pkgtype
848  end if
849  !
850  call this%package_create(pkgtype, ipakid, ipaknum, pkgname, mempath, &
851  inunit, this%iout)
852  ipakid = ipakid + 1
853  ipaknum = ipaknum + 1
854  end do
855  !
856  ! -- Cleanup
857  deallocate (bndpkgs)
858  end if
859  end subroutine create_bndpkgs
860 
861  !> @brief Source package info and begin to process
862  !<
863  subroutine create_gwe_packages(this, indis)
864  ! -- modules
871  use gweestmodule, only: est_cr
872  use gwecndmodule, only: cnd_cr
873  ! -- dummy
874  class(gwemodeltype) :: this
875  integer(I4B), intent(in) :: indis
876  ! -- local
877  type(characterstringtype), dimension(:), contiguous, &
878  pointer :: pkgtypes => null()
879  type(characterstringtype), dimension(:), contiguous, &
880  pointer :: pkgnames => null()
881  type(characterstringtype), dimension(:), contiguous, &
882  pointer :: mempaths => null()
883  integer(I4B), dimension(:), contiguous, &
884  pointer :: inunits => null()
885  character(len=LENMEMPATH) :: model_mempath
886  character(len=LENFTYPE) :: pkgtype
887  character(len=LENPACKAGENAME) :: pkgname
888  character(len=LENMEMPATH) :: mempath
889  integer(I4B), pointer :: inunit
890  integer(I4B), dimension(:), allocatable :: bndpkgs
891  integer(I4B) :: n
892  character(len=LENMEMPATH) :: mempathcnd = ''
893  !
894  ! -- Set input memory paths, input/model and input/model/namfile
895  model_mempath = create_mem_path(component=this%name, context=idm_context)
896  !
897  ! -- Set pointers to model path package info
898  call mem_setptr(pkgtypes, 'PKGTYPES', model_mempath)
899  call mem_setptr(pkgnames, 'PKGNAMES', model_mempath)
900  call mem_setptr(mempaths, 'MEMPATHS', model_mempath)
901  call mem_setptr(inunits, 'INUNITS', model_mempath)
902  !
903  do n = 1, size(pkgtypes)
904  !
905  ! -- Attributes for this input package
906  pkgtype = pkgtypes(n)
907  pkgname = pkgnames(n)
908  mempath = mempaths(n)
909  inunit => inunits(n)
910  !
911  ! -- Create dis package as it is a prerequisite for other packages
912  select case (pkgtype)
913  case ('EST6')
914  this%inest = inunit
915  case ('CND6')
916  this%incnd = 1
917  mempathcnd = mempath
918  case ('CTP6', 'ESL6', 'LKE6', 'SFE6', &
919  'MWE6', 'UZE6', 'API6')
920  call expandarray(bndpkgs)
921  bndpkgs(size(bndpkgs)) = n
922  case default
923  ! TODO
924  end select
925  end do
926  !
927  ! -- Create packages that are tied directly to model
928  call est_cr(this%est, this%name, this%inest, this%iout, this%fmi, &
929  this%eqnsclfac, this%gwecommon)
930  call cnd_cr(this%cnd, this%name, mempathcnd, this%incnd, this%iout, &
931  this%fmi, this%eqnsclfac, this%gwecommon)
932  !
933  ! -- Check to make sure that required ftype's have been specified
934  call this%ftype_check(indis, this%inest)
935  !
936  call this%create_bndpkgs(bndpkgs, pkgtypes, pkgnames, mempaths, inunits)
937  end subroutine create_gwe_packages
938 
939 end module gwemodule
subroutine, public ats_submit_delt(kstp, kper, dt, sloc, idir)
@ brief Allow and external caller to submit preferred time step
Definition: ats.f90:493
This module contains the API package methods.
Definition: gwf-api.f90:12
subroutine, public api_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname)
@ brief Create a new package object
Definition: gwf-api.f90:49
subroutine, public addbasemodeltolist(list, model)
Definition: BaseModel.f90:161
This module contains the base boundary package.
subroutine, public addbndtolist(list, bnd)
Add boundary to package list.
class(bndtype) function, pointer, public getbndfromlist(list, idx)
Get boundary from package list.
This module contains the BudgetModule.
Definition: Budget.f90:20
subroutine, public budget_cr(this, name_model)
@ brief Create a new budget object
Definition: Budget.f90:84
This module contains simulation constants.
Definition: Constants.f90:9
integer(i4b), parameter linelength
maximum length of a standard line
Definition: Constants.f90:45
integer(i4b), parameter lenpackagename
maximum length of the package name
Definition: Constants.f90:23
real(dp), parameter dnodata
real no data constant
Definition: Constants.f90:95
integer(i4b), parameter lenpackagetype
maximum length of a package type (DIS6, SFR6, CSUB6, etc.)
Definition: Constants.f90:38
real(dp), parameter dhnoflo
real no flow constant
Definition: Constants.f90:93
integer(i4b), parameter lenpakloc
maximum length of a package location
Definition: Constants.f90:50
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition: Constants.f90:17
integer(i4b), parameter lenftype
maximum length of a package type (DIS, WEL, OC, etc.)
Definition: Constants.f90:39
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
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition: Constants.f90:27
subroutine, public cnd_cr(cndobj, name_model, input_mempath, inunit, iout, fmi, eqnsclfac, gwecommon)
Create a new CND object.
Definition: gwe-cnd.f90:86
subroutine, public ctp_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, depvartype, mempath)
Create a new constant temperature package.
Definition: gwe-ctp.f90:57
subroutine, public esl_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, gwecommon)
Create an energy source loading package.
Definition: gwe-esl.f90:48
– @ brief Energy Storage and Transfer (EST) Module
Definition: gwe-est.f90:13
subroutine, public est_cr(estobj, name_model, inunit, iout, fmi, eqnsclfac, gwecommon)
@ brief Create a new EST package object
Definition: gwe-est.f90:87
subroutine, public gweshared_dat_cr(gwe_dat)
Allocate the shared data.
subroutine, public lke_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, fmi, eqnsclfac, gwecommon, dvt, dvu, dvua)
Create a new lke package.
Definition: gwe-lke.f90:107
Definition: gwe.f90:3
subroutine create_bndpkgs(this, bndpkgs, pkgtypes, pkgnames, mempaths, inunits)
Source package info and begin to process.
Definition: gwe.f90:811
character(len=lenpackagetype), dimension(gwe_nmultipkg), public gwe_multipkg
Definition: gwe.f90:85
subroutine gwe_cf(this, kiter)
GWE Model calculate coefficients.
Definition: gwe.f90:402
subroutine gwe_ot_flow(this, icbcfl, ibudfl, icbcun)
GWE model output routine.
Definition: gwe.f90:564
subroutine gwe_bd(this, icnvg, isuppress_output)
GWE Model Budget.
Definition: gwe.f90:533
subroutine gwe_bdentry(this, budterm, budtxt, rowlabel)
GroundWater Energy Transport Model Budget Entry.
Definition: gwe.f90:648
integer(i4b), parameter, public gwe_nbasepkg
GWE base package array descriptors.
Definition: gwe.f90:71
subroutine gwe_ad(this)
GWE Model Time Step Advance.
Definition: gwe.f90:348
subroutine gwe_cq(this, icnvg, isuppress_output)
GWE Model calculate flow.
Definition: gwe.f90:485
subroutine gwe_mc(this, matrix_sln)
Map the positions of the GWE model connections in the numerical solution coefficient matrix.
Definition: gwe.f90:225
subroutine gwe_da(this)
Deallocate.
Definition: gwe.f90:581
character(len=lenvarname), parameter dvt
dependent variable type, varies based on model type
Definition: gwe.f90:29
subroutine gwe_df(this)
Define packages of the GWE model.
Definition: gwe.f90:148
subroutine gwe_cc(this, innertot, kiter, iend, icnvgmod, cpak, ipak, dpak)
GWE Model Final Convergence Check.
Definition: gwe.f90:466
subroutine allocate_scalars(this, modelname)
Allocate memory for non-allocatable members.
Definition: gwe.f90:697
subroutine package_create(this, filtyp, ipakid, ipaknum, pakname, mempath, inunit, iout)
Create boundary condition packages for this model.
Definition: gwe.f90:721
subroutine gwe_ac(this, sparse)
Add the internal connections of this model to the sparse matrix.
Definition: gwe.f90:200
subroutine gwe_rp(this)
GWE Model Read and Prepare.
Definition: gwe.f90:295
integer(i4b), parameter niunit_gwe
Definition: gwe.f90:91
subroutine, public gwe_cr(filename, id, modelname)
Create a new groundwater energy transport model object.
Definition: gwe.f90:98
subroutine gwe_fc(this, kiter, matrix_sln, inwtflag)
GWE Model fill coefficients.
Definition: gwe.f90:422
integer(i4b) function gwe_get_iasym(this)
return 1 if any package causes the matrix to be asymmetric. Otherwise return 0.
Definition: gwe.f90:664
character(len=lenvarname), parameter dvu
dependent variable unit of measure, either "mass" or "energy"
Definition: gwe.f90:30
subroutine gwe_ar(this)
GWE Model Allocate and Read.
Definition: gwe.f90:252
character(len=lenpackagetype), dimension(gwe_nbasepkg), public gwe_basepkg
Definition: gwe.f90:72
integer(i4b), parameter, public gwe_nmultipkg
GWE multi package array descriptors.
Definition: gwe.f90:84
subroutine create_gwe_packages(this, indis)
Source package info and begin to process.
Definition: gwe.f90:864
subroutine gwe_dt(this)
GWT Model time step size.
Definition: gwe.f90:327
class(gwemodeltype) function, pointer, public castasgwemodel(model)
Cast to GweModelType.
Definition: gwe.f90:794
character(len=lenvarname), parameter dvua
abbreviation of the dependent variable unit of measure, either "M" or "E"
Definition: gwe.f90:31
subroutine, public mwe_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, fmi, eqnsclfac, gwecommon, dvt, dvu, dvua)
Create new MWE package.
Definition: gwe-mwe.f90:100
subroutine, public sfe_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, fmi, eqnsclfac, gwecommon, dvt, dvu, dvua)
Create a new sfe package.
Definition: gwe-sfe.f90:106
subroutine, public uze_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, fmi, eqnsclfac, gwecommon, dvt, dvu, dvua)
Create a new UZE package.
Definition: gwe-uze.f90:96
subroutine, public parseline(line, nwords, words, inunit, filename)
Parse a line into words.
subroutine, public upcase(word)
Convert to upper case.
This module defines variable data types.
Definition: kind.f90:8
type(listtype), public basemodellist
Definition: mf6lists.f90:16
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
subroutine, public memorystore_remove(component, subcomponent, context)
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=linelength) idm_context
integer(i4b) isimcheck
simulation input check flag (1) to check input, (0) to ignore checks
integer(i4b) ifailedstepretry
current retry for this time step
subroutine csr_diagsum(ia, flowja)
Definition: Sparse.f90:263
logical(lgp), pointer, public readnewdata
flag indicating time to read new data
Definition: tdis.f90:26
integer(i4b), pointer, public kstp
current time step number
Definition: tdis.f90:24
integer(i4b), pointer, public kper
current stress period number
Definition: tdis.f90:23
real(dp), pointer, public delt
length of the current time step
Definition: tdis.f90:29
This module contains the base transport model type.
Definition: tsp.f90:7
subroutine tsp_ot_flow(this, icbcfl, ibudfl, icbcun)
Generalized transport model output routine.
Definition: tsp.f90:356
Highest level model type. All models extend this parent type.
Definition: BaseModel.f90:13
@ brief BndType
Derived type for the Budget object.
Definition: Budget.f90:39
This class is used to store a single deferred-length character string. It was designed to work in an ...
Definition: CharString.f90:23
@ brief Energy storage and transfer
Definition: gwe-est.f90:38
Data for sharing among multiple packages. Originally read in from.