MODFLOW 6  version 6.7.0.dev2
USGS Modular Hydrologic Model
gwf-ghb.f90
Go to the documentation of this file.
1 module ghbmodule
2  use kindmodule, only: dp, i4b, lgp
4  use simvariablesmodule, only: errmsg
7  use bndmodule, only: bndtype
8  use bndextmodule, only: bndexttype
11  !
12  implicit none
13  !
14  private
15  public :: ghb_create
16  public :: ghbtype
17  !
18  character(len=LENFTYPE) :: ftype = 'GHB'
19  character(len=LENPACKAGENAME) :: text = ' GHB'
20  !
21  type, extends(bndexttype) :: ghbtype
22  real(dp), dimension(:), pointer, contiguous :: bhead => null() !< GHB boundary head
23  real(dp), dimension(:), pointer, contiguous :: cond => null() !< GHB hydraulic conductance
24  contains
25  procedure :: allocate_arrays => ghb_allocate_arrays
26  procedure :: source_options => ghb_options
27  procedure :: log_ghb_options
28  procedure :: bnd_rp => ghb_rp
29  procedure :: bnd_ck => ghb_ck
30  procedure :: bnd_cf => ghb_cf
31  procedure :: bnd_fc => ghb_fc
32  procedure :: bnd_da => ghb_da
33  procedure :: define_listlabel
34  procedure :: bound_value => ghb_bound_value
35  procedure :: cond_mult
36  ! -- methods for observations
37  procedure, public :: bnd_obs_supported => ghb_obs_supported
38  procedure, public :: bnd_df_obs => ghb_df_obs
39  procedure, public :: ghb_store_user_cond
40  end type ghbtype
41 
42 contains
43 
44  !> @brief Create a New Ghb Package and point bndobj to the new package
45  !<
46  subroutine ghb_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, &
47  mempath)
48  ! -- dummy
49  class(bndtype), pointer :: packobj
50  integer(I4B), intent(in) :: id
51  integer(I4B), intent(in) :: ibcnum
52  integer(I4B), intent(in) :: inunit
53  integer(I4B), intent(in) :: iout
54  character(len=*), intent(in) :: namemodel
55  character(len=*), intent(in) :: pakname
56  character(len=*), intent(in) :: mempath
57  ! -- local
58  type(ghbtype), pointer :: ghbobj
59  !
60  ! -- allocate the object and assign values to object variables
61  allocate (ghbobj)
62  packobj => ghbobj
63  !
64  ! -- create name and memory path
65  call packobj%set_names(ibcnum, namemodel, pakname, ftype, mempath)
66  packobj%text = text
67  !
68  ! -- allocate scalars
69  call packobj%allocate_scalars()
70  !
71  ! -- initialize package
72  call packobj%pack_initialize()
73  !
74  packobj%inunit = inunit
75  packobj%iout = iout
76  packobj%id = id
77  packobj%ibcnum = ibcnum
78  packobj%ictMemPath = create_mem_path(namemodel, 'NPF')
79  end subroutine ghb_create
80 
81  !> @brief Deallocate memory
82  !<
83  subroutine ghb_da(this)
84  ! -- modules
86  ! -- dummy
87  class(ghbtype) :: this
88  !
89  ! -- Deallocate parent package
90  call this%BndExtType%bnd_da()
91  !
92  ! -- arrays
93  call mem_deallocate(this%bhead, 'BHEAD', this%memoryPath)
94  call mem_deallocate(this%cond, 'COND', this%memoryPath)
95  end subroutine ghb_da
96 
97  !> @brief Set options specific to GhbType
98  !<
99  subroutine ghb_options(this)
100  ! -- modules
103  ! -- dummy
104  class(ghbtype), intent(inout) :: this
105  ! -- local
106  logical(LGP) :: found_mover
107  !
108  ! -- source base class options
109  call this%BndExtType%source_options()
110  !
111  ! -- source options from input context
112  call mem_set_value(this%imover, 'MOVER', this%input_mempath, found_mover)
113  !
114  ! -- log ghb specific options
115  call this%log_ghb_options(found_mover)
116  end subroutine ghb_options
117 
118  !> @brief Log options specific to GhbType
119  !<
120  subroutine log_ghb_options(this, found_mover)
121  ! -- modules
122  ! -- dummy
123  class(ghbtype), intent(inout) :: this !< BndExtType object
124  logical(LGP), intent(in) :: found_mover
125  !
126  ! -- log found options
127  write (this%iout, '(/1x,a)') 'PROCESSING '//trim(adjustl(this%text)) &
128  //' OPTIONS'
129  !
130  if (found_mover) then
131  write (this%iout, '(4x,A)') 'MOVER OPTION ENABLED'
132  end if
133  !
134  ! -- close logging block
135  write (this%iout, '(1x,a)') &
136  'END OF '//trim(adjustl(this%text))//' OPTIONS'
137  end subroutine log_ghb_options
138 
139  !> @brief Allocate arrays
140  !<
141  subroutine ghb_allocate_arrays(this, nodelist, auxvar)
142  ! -- modules
144  ! -- dummy
145  class(ghbtype) :: this
146  integer(I4B), dimension(:), pointer, contiguous, optional :: nodelist
147  real(DP), dimension(:, :), pointer, contiguous, optional :: auxvar
148  !
149  ! -- call base type allocate arrays
150  call this%BndExtType%allocate_arrays(nodelist, auxvar)
151  !
152  ! -- set ghb input context pointers
153  call mem_setptr(this%bhead, 'BHEAD', this%input_mempath)
154  call mem_setptr(this%cond, 'COND', this%input_mempath)
155  !
156  ! --checkin ghb input context pointers
157  call mem_checkin(this%bhead, 'BHEAD', this%memoryPath, &
158  'BHEAD', this%input_mempath)
159  call mem_checkin(this%cond, 'COND', this%memoryPath, &
160  'COND', this%input_mempath)
161  end subroutine ghb_allocate_arrays
162 
163  !> @brief Read and prepare
164  !<
165  subroutine ghb_rp(this)
166  ! -- modules
167  use tdismodule, only: kper
168  ! -- dummy
169  class(ghbtype), intent(inout) :: this
170  !
171  if (this%iper /= kper) return
172  !
173  ! -- Call the parent class read and prepare
174  call this%BndExtType%bnd_rp()
175  !
176  ! -- store user cond
177  if (this%ivsc == 1) then
178  call this%ghb_store_user_cond()
179  end if
180  !
181  ! -- Write the list to iout if requested
182  if (this%iprpak /= 0) then
183  call this%write_list()
184  end if
185  end subroutine ghb_rp
186 
187  !> @brief Check ghb boundary condition data
188  !<
189  subroutine ghb_ck(this)
190  ! -- modules
191  use constantsmodule, only: linelength
193  ! -- dummy
194  class(ghbtype), intent(inout) :: this
195  ! -- local
196  character(len=LINELENGTH) :: errmsg
197  integer(I4B) :: i
198  integer(I4B) :: node
199  real(DP) :: bt
200  ! -- formats
201  character(len=*), parameter :: fmtghberr = &
202  "('GHB BOUNDARY (',i0,') HEAD (',f10.3,') IS LESS THAN CELL &
203  &BOTTOM (',f10.3,')')"
204  character(len=*), parameter :: fmtcondmulterr = &
205  "('GHB BOUNDARY (',i0,') CONDUCTANCE MULTIPLIER (',g10.3,') IS &
206  &LESS THAN ZERO')"
207  character(len=*), parameter :: fmtconderr = &
208  "('GHB BOUNDARY (',i0,') CONDUCTANCE (',g10.3,') IS LESS THAN &
209  &ZERO')"
210  !
211  ! -- check stress period data
212  do i = 1, this%nbound
213  node = this%nodelist(i)
214  if (node == 0) cycle
215  bt = this%dis%bot(node)
216  ! -- accumulate errors
217  if (this%bhead(i) < bt .and. this%icelltype(node) /= 0) then
218  write (errmsg, fmt=fmtghberr) i, this%bhead(i), bt
219  call store_error(errmsg)
220  end if
221  if (this%iauxmultcol > 0) then
222  if (this%auxvar(this%iauxmultcol, i) < dzero) then
223  write (errmsg, fmt=fmtcondmulterr) &
224  i, this%auxvar(this%iauxmultcol, i)
225  call store_error(errmsg)
226  end if
227  end if
228  if (this%cond(i) < dzero) then
229  write (errmsg, fmt=fmtconderr) i, this%cond(i)
230  call store_error(errmsg)
231  end if
232  end do
233  !
234  !write summary of ghb package error messages
235  if (count_errors() > 0) then
236  call store_error_unit(this%inunit)
237  end if
238  end subroutine ghb_ck
239 
240  !> @brief Formulate the HCOF and RHS terms
241  !!
242  !! Skip if no GHBs
243  !<
244  subroutine ghb_cf(this)
245  ! -- dummy
246  class(ghbtype) :: this
247  ! -- local
248  integer(I4B) :: i, node
249  !
250  ! -- Return if no ghbs
251  if (this%nbound .eq. 0) return
252  !
253  ! -- Calculate hcof and rhs for each ghb entry
254  do i = 1, this%nbound
255  node = this%nodelist(i)
256  if (node == 0) cycle
257  if (this%ibound(node) .le. 0) then
258  this%hcof(i) = dzero
259  this%rhs(i) = dzero
260  cycle
261  end if
262  this%hcof(i) = -this%cond_mult(i)
263  this%rhs(i) = -this%cond_mult(i) * this%bhead(i)
264  end do
265  end subroutine ghb_cf
266 
267  !> @brief Copy rhs and hcof into solution rhs and amat
268  !<
269  subroutine ghb_fc(this, rhs, ia, idxglo, matrix_sln)
270  ! -- dummy
271  class(ghbtype) :: this
272  real(DP), dimension(:), intent(inout) :: rhs
273  integer(I4B), dimension(:), intent(in) :: ia
274  integer(I4B), dimension(:), intent(in) :: idxglo
275  class(matrixbasetype), pointer :: matrix_sln
276  ! -- local
277  integer(I4B) :: i, n, ipos
278  real(DP) :: cond, bhead, qghb
279  !
280  ! -- pakmvrobj fc
281  if (this%imover == 1) then
282  call this%pakmvrobj%fc()
283  end if
284  !
285  ! -- Copy package rhs and hcof into solution rhs and amat
286  do i = 1, this%nbound
287  n = this%nodelist(i)
288  if (n == 0) cycle
289  rhs(n) = rhs(n) + this%rhs(i)
290  ipos = ia(n)
291  call matrix_sln%add_value_pos(idxglo(ipos), this%hcof(i))
292  !
293  ! -- If mover is active and this boundary is discharging,
294  ! store available water (as positive value).
295  bhead = this%bhead(i)
296  if (this%imover == 1 .and. this%xnew(n) > bhead) then
297  cond = this%cond_mult(i)
298  qghb = cond * (this%xnew(n) - bhead)
299  call this%pakmvrobj%accumulate_qformvr(i, qghb)
300  end if
301  end do
302  end subroutine ghb_fc
303 
304  !> @brief Define the list heading that is written to iout when PRINT_INPUT
305  !! option is used
306  !<
307  subroutine define_listlabel(this)
308  ! -- dummy
309  class(ghbtype), intent(inout) :: this
310  !
311  ! -- create the header list label
312  this%listlabel = trim(this%filtyp)//' NO.'
313  if (this%dis%ndim == 3) then
314  write (this%listlabel, '(a, a7)') trim(this%listlabel), 'LAYER'
315  write (this%listlabel, '(a, a7)') trim(this%listlabel), 'ROW'
316  write (this%listlabel, '(a, a7)') trim(this%listlabel), 'COL'
317  elseif (this%dis%ndim == 2) then
318  write (this%listlabel, '(a, a7)') trim(this%listlabel), 'LAYER'
319  write (this%listlabel, '(a, a7)') trim(this%listlabel), 'CELL2D'
320  else
321  write (this%listlabel, '(a, a7)') trim(this%listlabel), 'NODE'
322  end if
323  write (this%listlabel, '(a, a16)') trim(this%listlabel), 'STAGE'
324  write (this%listlabel, '(a, a16)') trim(this%listlabel), 'CONDUCTANCE'
325  if (this%inamedbound == 1) then
326  write (this%listlabel, '(a, a16)') trim(this%listlabel), 'BOUNDARY NAME'
327  end if
328  end subroutine define_listlabel
329 
330  ! -- Procedures related to observations
331 
332  !> @brief Return true because GHB package supports observations
333  !!
334  !! Overrides BndType%bnd_obs_supported()
335  !<
336  logical function ghb_obs_supported(this)
337  implicit none
338  ! -- dummy
339  class(ghbtype) :: this
340  !
341  ghb_obs_supported = .true.
342  end function ghb_obs_supported
343 
344  !> @brief Store observation type supported by GHB package
345  !!
346  !! Overrides BndType%bnd_df_obs
347  !<
348  subroutine ghb_df_obs(this)
349  implicit none
350  ! -- dummy
351  class(ghbtype) :: this
352  ! -- local
353  integer(I4B) :: indx
354  !
355  call this%obs%StoreObsType('ghb', .true., indx)
356  this%obs%obsData(indx)%ProcessIdPtr => defaultobsidprocessor
357  !
358  ! -- Store obs type and assign procedure pointer
359  ! for to-mvr observation type.
360  call this%obs%StoreObsType('to-mvr', .true., indx)
361  this%obs%obsData(indx)%ProcessIdPtr => defaultobsidprocessor
362  end subroutine ghb_df_obs
363 
364  !> @brief Store user-specified conductance for GHB boundary type
365  !<
366  subroutine ghb_store_user_cond(this)
367  ! -- dummy
368  class(ghbtype), intent(inout) :: this !< BndExtType object
369  ! -- local
370  integer(I4B) :: n
371  !
372  ! -- store backup copy of conductance values
373  do n = 1, this%nbound
374  this%condinput(n) = this%cond_mult(n)
375  end do
376  end subroutine ghb_store_user_cond
377 
378  !> @brief Apply multiplier to GHB conductance if option AUXMULTCOL is used
379  !<
380  function cond_mult(this, row) result(cond)
381  ! -- modules
382  use constantsmodule, only: dzero
383  ! -- dummy variables
384  class(ghbtype), intent(inout) :: this !< BndExtType object
385  integer(I4B), intent(in) :: row
386  ! -- result
387  real(dp) :: cond
388  !
389  if (this%iauxmultcol > 0) then
390  cond = this%cond(row) * this%auxvar(this%iauxmultcol, row)
391  else
392  cond = this%cond(row)
393  end if
394  end function cond_mult
395 
396  !> @brief Return requested boundary value
397  !<
398  function ghb_bound_value(this, col, row) result(bndval)
399  ! -- modules
400  use constantsmodule, only: dzero
401  ! -- dummy
402  class(ghbtype), intent(inout) :: this !< BndExtType object
403  integer(I4B), intent(in) :: col
404  integer(I4B), intent(in) :: row
405  ! -- result
406  real(dp) :: bndval
407  !
408  select case (col)
409  case (1)
410  bndval = this%bhead(row)
411  case (2)
412  bndval = this%cond_mult(row)
413  case default
414  errmsg = 'Programming error. GHB bound value requested column '&
415  &'outside range of ncolbnd (2).'
416  call store_error(errmsg)
417  call store_error_filename(this%input_fname)
418  end select
419  end function ghb_bound_value
420 
421 end module ghbmodule
This module contains the extended boundary package.
This module contains the base boundary package.
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
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
subroutine ghb_cf(this)
Formulate the HCOF and RHS terms.
Definition: gwf-ghb.f90:245
subroutine ghb_allocate_arrays(this, nodelist, auxvar)
Allocate arrays.
Definition: gwf-ghb.f90:142
subroutine ghb_ck(this)
Check ghb boundary condition data.
Definition: gwf-ghb.f90:190
subroutine ghb_da(this)
Deallocate memory.
Definition: gwf-ghb.f90:84
subroutine ghb_fc(this, rhs, ia, idxglo, matrix_sln)
Copy rhs and hcof into solution rhs and amat.
Definition: gwf-ghb.f90:270
subroutine ghb_df_obs(this)
Store observation type supported by GHB package.
Definition: gwf-ghb.f90:349
character(len=lenpackagename) text
Definition: gwf-ghb.f90:19
real(dp) function ghb_bound_value(this, col, row)
Return requested boundary value.
Definition: gwf-ghb.f90:399
real(dp) function cond_mult(this, row)
Apply multiplier to GHB conductance if option AUXMULTCOL is used.
Definition: gwf-ghb.f90:381
character(len=lenftype) ftype
Definition: gwf-ghb.f90:18
subroutine ghb_store_user_cond(this)
Store user-specified conductance for GHB boundary type.
Definition: gwf-ghb.f90:367
logical function ghb_obs_supported(this)
Return true because GHB package supports observations.
Definition: gwf-ghb.f90:337
subroutine ghb_rp(this)
Read and prepare.
Definition: gwf-ghb.f90:166
subroutine, public ghb_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, mempath)
Create a New Ghb Package and point bndobj to the new package.
Definition: gwf-ghb.f90:48
subroutine log_ghb_options(this, found_mover)
Log options specific to GhbType.
Definition: gwf-ghb.f90:121
subroutine ghb_options(this)
Set options specific to GhbType.
Definition: gwf-ghb.f90:100
subroutine define_listlabel(this)
Define the list heading that is written to iout when PRINT_INPUT option is used.
Definition: gwf-ghb.f90:308
This module defines variable data types.
Definition: kind.f90:8
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
This module contains the derived type ObsType.
Definition: Obs.f90:127
subroutine, public defaultobsidprocessor(obsrv, dis, inunitobs, iout)
@ brief Process IDstring provided for each observation
Definition: Obs.f90:246
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public store_error(msg, terminate)
Store an error message.
Definition: Sim.f90:92
integer(i4b) function, public count_errors()
Return number of errors.
Definition: Sim.f90:59
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition: Sim.f90:203
subroutine, public store_error_unit(iunit, terminate)
Store the file unit number.
Definition: Sim.f90:168
This module contains simulation variables.
Definition: SimVariables.f90:9
character(len=maxcharlen) errmsg
error message string
integer(i4b), pointer, public kper
current stress period number
Definition: tdis.f90:23
@ 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