MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
swf-flw.f90
Go to the documentation of this file.
1!> @brief This module contains the FLW package methods
2!!
3!! This module can be used to represent inflow to streams. It is
4!! designed similarly to the GWF WEL package.
5!!
6!<
8 ! -- modules
9 use kindmodule, only: dp, i4b
11 use simvariablesmodule, only: errmsg
13 use bndmodule, only: bndtype
14 use bndextmodule, only: bndexttype
16 use observemodule, only: observetype
20 !
21 implicit none
22 !
23 private
24 public :: flw_create
25 !
26 character(len=LENFTYPE) :: ftype = 'FLW' !< package ftype
27 character(len=16) :: text = ' FLW' !< package flow text string
28 !
29 type, extends(bndexttype) :: swfflwtype
30 real(dp), dimension(:), pointer, contiguous :: q => null() !< volumetric rate
31 contains
35 procedure :: log_flw_options
36 procedure :: bnd_cf => flw_cf
37 procedure :: bnd_fc => flw_fc
38 procedure :: bnd_da => flw_da
39 procedure :: define_listlabel
41 procedure :: q_mult
42 ! -- methods for observations
43 procedure, public :: bnd_obs_supported => flw_obs_supported
44 procedure, public :: bnd_df_obs => flw_df_obs
45 procedure, public :: bnd_bd_obs => flw_bd_obs
46 ! -- methods for time series
47 procedure, public :: bnd_rp_ts => flw_rp_ts
48 end type swfflwtype
49
50contains
51
52 !> @brief Create a new package object
53 !!
54 !! Create a new FLW Package object
55 !!
56 !<
57 subroutine flw_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, &
58 mempath)
59 ! -- dummy variables
60 class(bndtype), pointer :: packobj !< pointer to default package type
61 integer(I4B), intent(in) :: id !< package id
62 integer(I4B), intent(in) :: ibcnum !< boundary condition number
63 integer(I4B), intent(in) :: inunit !< unit number of FLW package input file
64 integer(I4B), intent(in) :: iout !< unit number of model listing file
65 character(len=*), intent(in) :: namemodel !< model name
66 character(len=*), intent(in) :: pakname !< package name
67 character(len=*), intent(in) :: mempath !< input mempath
68 ! -- local variables
69 type(swfflwtype), pointer :: flwobj
70 !
71 ! -- allocate the object and assign values to object variables
72 allocate (flwobj)
73 packobj => flwobj
74 !
75 ! -- create name and memory path
76 call packobj%set_names(ibcnum, namemodel, pakname, ftype, mempath)
77 packobj%text = text
78 !
79 ! -- allocate scalars
80 call flwobj%allocate_scalars()
81 !
82 ! -- initialize package
83 call packobj%pack_initialize()
84
85 packobj%inunit = inunit
86 packobj%iout = iout
87 packobj%id = id
88 packobj%ibcnum = ibcnum
89 packobj%ncolbnd = 1
90 packobj%iscloc = 1
91 packobj%ictMemPath = ''
92 end subroutine flw_create
93
94 !> @brief Allocate scalars
95 !!
96 !! Allocate and initialize scalars for the FLW package. The base model
97 !! allocate scalars method is also called.
98 !!
99 !<
100 subroutine flw_allocate_scalars(this)
101 ! -- modules
103 ! -- dummy variables
104 class(swfflwtype) :: this !< SwfFlwType object
105 !
106 ! -- call base type allocate scalars
107 call this%BndExtType%allocate_scalars()
108 !
109 ! -- allocate the object and assign values to object variables
110 ! none for this package
111 !
112 ! -- Set values
113 ! none for this package
114 end subroutine flw_allocate_scalars
115
116 !> @brief Allocate arrays
117 !!
118 !! Allocate and initialize arrays for the SWF package
119 !!
120 !<
121 subroutine flw_allocate_arrays(this, nodelist, auxvar)
122 ! -- modules
124 ! -- dummy
125 class(swfflwtype) :: this
126 integer(I4B), dimension(:), pointer, contiguous, optional :: nodelist
127 real(DP), dimension(:, :), pointer, contiguous, optional :: auxvar
128 ! -- local
129 !
130 ! -- call BndExtType allocate scalars
131 call this%BndExtType%allocate_arrays(nodelist, auxvar)
132 !
133 ! -- set q array input context pointer
134 call mem_setptr(this%q, 'Q', this%input_mempath)
135 !
136 ! -- checkin q array input context pointer
137 call mem_checkin(this%q, 'Q', this%memoryPath, &
138 'Q', this%input_mempath)
139 end subroutine flw_allocate_arrays
140
141 !> @brief Deallocate package memory
142 !!
143 !! Deallocate SWF package scalars and arrays.
144 !!
145 !<
146 subroutine flw_da(this)
147 ! -- modules
149 ! -- dummy variables
150 class(swfflwtype) :: this !< SwfFlwType object
151 !
152 ! -- Deallocate parent package
153 call this%BndExtType%bnd_da()
154 !
155 ! -- scalars
156 call mem_deallocate(this%q, 'Q', this%memoryPath)
157 end subroutine flw_da
158
159 !> @brief Source additional options for package
160 !!
161 !! Source additional options for SWF package.
162 !!
163 !<
164 subroutine flw_options(this)
165 ! -- modules
166 use inputoutputmodule, only: urword
168 ! -- dummy variables
169 class(swfflwtype), intent(inout) :: this !< SwfFlwType object
170 ! -- formats
171 !
172 ! -- source base BndExtType options
173 call this%BndExtType%source_options()
174 !
175 ! -- source options from input context
176 ! none
177 !
178 ! -- log SWF specific options
179 call this%log_flw_options()
180 end subroutine flw_options
181
182 !> @brief Log SWF specific package options
183 !<
184 subroutine log_flw_options(this)
185 ! -- dummy variables
186 class(swfflwtype), intent(inout) :: this
187 ! -- local variables
188 ! -- format
189 !
190 ! -- log found options
191 write (this%iout, '(/1x,a)') 'PROCESSING '//trim(adjustl(this%text)) &
192 //' OPTIONS'
193 !
194 ! -- close logging block
195 write (this%iout, '(1x,a)') &
196 'END OF '//trim(adjustl(this%text))//' OPTIONS'
197 end subroutine log_flw_options
198
199 !> @brief Formulate the package hcof and rhs terms.
200 !!
201 !! Formulate the hcof and rhs terms for the FLW package that will be
202 !! added to the coefficient matrix and right-hand side vector.
203 !!
204 !<
205 subroutine flw_cf(this)
206 ! -- dummy variables
207 class(swfflwtype) :: this !< SwfFlwType object
208 ! -- local variables
209 integer(I4B) :: i, node
210 real(DP) :: q
211 !
212 ! -- Return if no inflows
213 if (this%nbound == 0) return
214 !
215 ! -- Calculate hcof and rhs for each flw entry
216 do i = 1, this%nbound
217 node = this%nodelist(i)
218 this%hcof(i) = dzero
219 if (this%ibound(node) <= 0) then
220 this%rhs(i) = dzero
221 cycle
222 end if
223 q = this%q_mult(i)
224 this%rhs(i) = -q
225 end do
226 end subroutine flw_cf
227
228 !> @brief Copy hcof and rhs terms into solution.
229 !!
230 !! Add the hcof and rhs terms for the FLW package to the
231 !! coefficient matrix and right-hand side vector.
232 !!
233 !<
234 subroutine flw_fc(this, rhs, ia, idxglo, matrix_sln)
235 ! -- dummy variables
236 class(swfflwtype) :: this !< SwfFlwType object
237 real(DP), dimension(:), intent(inout) :: rhs !< right-hand side vector for model
238 integer(I4B), dimension(:), intent(in) :: ia !< solution CRS row pointers
239 integer(I4B), dimension(:), intent(in) :: idxglo !< mapping vector for model (local) to solution (global)
240 class(matrixbasetype), pointer :: matrix_sln !< solution coefficient matrix
241 ! -- local variables
242 integer(I4B) :: i
243 integer(I4B) :: n
244 integer(I4B) :: ipos
245 !
246 ! -- pakmvrobj fc
247 if (this%imover == 1) then
248 call this%pakmvrobj%fc()
249 end if
250 !
251 ! -- Copy package rhs and hcof into solution rhs and amat
252 do i = 1, this%nbound
253 n = this%nodelist(i)
254 rhs(n) = rhs(n) + this%rhs(i)
255 ipos = ia(n)
256 call matrix_sln%add_value_pos(idxglo(ipos), this%hcof(i))
257 !
258 ! -- If mover is active and this flw item is discharging,
259 ! store available water (as positive value).
260 if (this%imover == 1 .and. this%rhs(i) > dzero) then
261 call this%pakmvrobj%accumulate_qformvr(i, this%rhs(i))
262 end if
263 end do
264 end subroutine flw_fc
265
266 !> @brief Define the list label for the package
267 !!
268 !! Method defined the list label for the FLW package. The list label is
269 !! the heading that is written to iout when PRINT_INPUT option is used.
270 !!
271 !<
272 subroutine define_listlabel(this)
273 ! -- dummy variables
274 class(swfflwtype), intent(inout) :: this !< SwfFlwType object
275 !
276 ! -- create the header list label
277 this%listlabel = trim(this%filtyp)//' NO.'
278 if (this%dis%ndim == 3) then
279 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'LAYER'
280 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'ROW'
281 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'COL'
282 elseif (this%dis%ndim == 2) then
283 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'LAYER'
284 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'CELL2D'
285 else
286 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'NODE'
287 end if
288 write (this%listlabel, '(a, a16)') trim(this%listlabel), 'FLOW RATE'
289 if (this%inamedbound == 1) then
290 write (this%listlabel, '(a, a16)') trim(this%listlabel), 'BOUNDARY NAME'
291 end if
292 end subroutine define_listlabel
293
294 ! -- Procedures related to observations
295
296 !> @brief Determine if observations are supported.
297 !!
298 !! Function to determine if observations are supported by the FLW package.
299 !! Observations are supported by the FLW package.
300 !!
301 !! @return flw_obs_supported boolean indicating if observations are supported
302 !!
303 !<
304 logical function flw_obs_supported(this)
305 ! -- dummy variables
306 class(swfflwtype) :: this !< SwfFlwType object
307 !
308 ! -- set boolean
309 flw_obs_supported = .true.
310 end function flw_obs_supported
311
312 !> @brief Define the observation types available in the package
313 !!
314 !! Method to define the observation types available in the FLW package.
315 !!
316 !<
317 subroutine flw_df_obs(this)
318 ! -- dummy variables
319 class(swfflwtype) :: this !< SwfFlwType object
320 ! -- local variables
321 integer(I4B) :: indx
322 !
323 ! -- initialize observations
324 call this%obs%StoreObsType('flw', .true., indx)
325 this%obs%obsData(indx)%ProcessIdPtr => defaultobsidprocessor
326 !
327 ! -- Store obs type and assign procedure pointer
328 ! for to-mvr observation type.
329 call this%obs%StoreObsType('to-mvr', .true., indx)
330 this%obs%obsData(indx)%ProcessIdPtr => defaultobsidprocessor
331 end subroutine flw_df_obs
332
333 !> @brief Save observations for the package
334 !!
335 !! Method to save simulated values for the FLW package.
336 !!
337 !<
338 subroutine flw_bd_obs(this)
339 ! -- dummy variables
340 class(swfflwtype) :: this !< SwfFlwType object
341 ! -- local variables
342 integer(I4B) :: i
343 integer(I4B) :: n
344 integer(I4B) :: jj
345 real(DP) :: v
346 type(observetype), pointer :: obsrv => null()
347 !
348 ! -- clear the observations
349 call this%obs%obs_bd_clear()
350 !
351 ! -- Save simulated values for all of package's observations.
352 do i = 1, this%obs%npakobs
353 obsrv => this%obs%pakobs(i)%obsrv
354 if (obsrv%BndFound) then
355 do n = 1, obsrv%indxbnds_count
356 v = dnodata
357 jj = obsrv%indxbnds(n)
358 select case (obsrv%ObsTypeId)
359 case ('TO-MVR')
360 if (this%imover == 1) then
361 v = this%pakmvrobj%get_qtomvr(jj)
362 if (v > dzero) then
363 v = -v
364 end if
365 end if
366 case ('FLW')
367 v = this%simvals(jj)
368 case default
369 errmsg = 'Unrecognized observation type: '//trim(obsrv%ObsTypeId)
370 call store_error(errmsg)
371 end select
372 call this%obs%SaveOneSimval(obsrv, v)
373 end do
374 else
375 call this%obs%SaveOneSimval(obsrv, dnodata)
376 end if
377 end do
378 end subroutine flw_bd_obs
379
380 ! -- Procedure related to time series
381
382 !> @brief Assign time series links for the package
383 !!
384 !! Assign the time series links for the FLW package. Only
385 !! the Q variable can be defined with time series.
386 !!
387 !<
388 subroutine flw_rp_ts(this)
389 ! -- dummy variables
390 class(swfflwtype), intent(inout) :: this !< SwfFlwType object
391 ! -- local variables
392 integer(I4B) :: i, nlinks
393 type(timeserieslinktype), pointer :: tslink => null()
394 !
395 ! -- set up the time series links
396 nlinks = this%TsManager%boundtslinks%Count()
397 do i = 1, nlinks
398 tslink => gettimeserieslinkfromlist(this%TsManager%boundtslinks, i)
399 if (associated(tslink)) then
400 if (tslink%JCol == 1) then
401 tslink%Text = 'Q'
402 end if
403 end if
404 end do
405 end subroutine flw_rp_ts
406
407 function q_mult(this, row) result(q)
408 ! -- modules
409 use constantsmodule, only: dzero
410 ! -- dummy variables
411 class(swfflwtype), intent(inout) :: this
412 integer(I4B), intent(in) :: row
413 ! -- result
414 real(dp) :: q
415 !
416 if (this%iauxmultcol > 0) then
417 q = this%q(row) * this%auxvar(this%iauxmultcol, row)
418 else
419 q = this%q(row)
420 end if
421 end function q_mult
422
423 !> @brief Return a bound value
424 !!
425 !! Return a bound value associated with an ncolbnd index
426 !! and row.
427 !!
428 !<
429 function flw_bound_value(this, col, row) result(bndval)
430 ! -- modules
431 use constantsmodule, only: dzero
432 ! -- dummy variables
433 class(swfflwtype), intent(inout) :: this
434 integer(I4B), intent(in) :: col
435 integer(I4B), intent(in) :: row
436 ! -- result
437 real(dp) :: bndval
438 !
439 select case (col)
440 case (1)
441 bndval = this%q_mult(row)
442 case default
443 errmsg = 'Programming error. FLW bound value requested column '&
444 &'outside range of ncolbnd (1).'
445 call store_error(errmsg)
446 call store_error_filename(this%input_fname)
447 end select
448 end function flw_bound_value
449
450end module swfflwmodule
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 allocate_scalars(this)
Allocate package scalars.
subroutine bnd_rp_ts(this)
Assign time series links for the package.
subroutine bnd_bd_obs(this)
Save observations for the 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_df_obs(this)
Define the observation types available in the package.
subroutine bnd_cf(this)
Formulate the package hcof and rhs terms.
subroutine define_listlabel(this)
Define the list label for the package.
This module contains simulation constants.
Definition Constants.f90:9
real(dp), parameter dnodata
real no data constant
Definition Constants.f90:95
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, public urword(line, icol, istart, istop, ncode, n, r, iout, in)
Extract a word from a string.
This module defines variable data types.
Definition kind.f90:8
This module contains the derived types ObserveType and ObsDataType.
Definition Observe.f90:15
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
subroutine, public store_error_filename(filename, terminate)
Store the erroring file name.
Definition Sim.f90:208
This module contains simulation variables.
character(len=maxcharlen) errmsg
error message string
integer(i4b) iout
file unit number for simulation output
This module contains the FLW package methods.
Definition swf-flw.f90:7
subroutine flw_df_obs(this)
Define the observation types available in the package.
Definition swf-flw.f90:318
character(len=lenftype) ftype
package ftype
Definition swf-flw.f90:26
subroutine log_flw_options(this)
Log SWF specific package options.
Definition swf-flw.f90:185
subroutine flw_cf(this)
Formulate the package hcof and rhs terms.
Definition swf-flw.f90:206
subroutine, public flw_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, mempath)
Create a new package object.
Definition swf-flw.f90:59
subroutine flw_da(this)
Deallocate package memory.
Definition swf-flw.f90:147
real(dp) function flw_bound_value(this, col, row)
Return a bound value.
Definition swf-flw.f90:430
logical function flw_obs_supported(this)
Determine if observations are supported.
Definition swf-flw.f90:305
subroutine flw_allocate_scalars(this)
Allocate scalars.
Definition swf-flw.f90:101
character(len=16) text
package flow text string
Definition swf-flw.f90:27
subroutine flw_bd_obs(this)
Save observations for the package.
Definition swf-flw.f90:339
subroutine flw_options(this)
Source additional options for package.
Definition swf-flw.f90:165
real(dp) function q_mult(this, row)
Definition swf-flw.f90:408
subroutine flw_allocate_arrays(this, nodelist, auxvar)
Allocate arrays.
Definition swf-flw.f90:122
subroutine flw_fc(this, rhs, ia, idxglo, matrix_sln)
Copy hcof and rhs terms into solution.
Definition swf-flw.f90:235
subroutine flw_rp_ts(this)
Assign time series links for the package.
Definition swf-flw.f90:389
type(timeserieslinktype) function, pointer, public gettimeserieslinkfromlist(list, indx)
Get time series link from a list.