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