MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
gwf-sfr.f90
Go to the documentation of this file.
1!> @brief This module contains the SFR package methods
2!!
3!! This module contains the overridden methods for the streamflow routing (SFR)
4!! package. Most of the methods in the base Boundary Package are overridden.
5!!
6!<
8 !
9 use kindmodule, only: dp, i4b, lgp
11 maxadpit, &
14 dp9, dp99, dp999, &
16 dhundred, dep20, &
19 lenbudtxt, &
28 use bndmodule, only: bndtype
29 use bndextmodule, only: bndexttype
31
34 use observemodule, only: observetype
36 use basedismodule, only: disbasetype
45 use dag_module, only: dag
47 !
48 implicit none
49 !
50 character(len=LENFTYPE) :: ftype = 'SFR' !< package ftype string
51 character(len=LENPACKAGENAME) :: text = ' SFR' !< package budget string
52 !
53 private
54 public :: sfr_create
55 public :: sfrtype
56
57 !> @brief Input context array pointers for SFR.
58 !!
59 !! PACKAGEDATA pointers are set in sfr_source_packagedata; PERIOD
60 !! pointers are set once in sfr_ar.
61 !<
63 ! -- packagedata (TS-linked; set in sfr_source_packagedata)
64 real(dp), dimension(:), pointer, contiguous :: rhk => null()
65 real(dp), dimension(:), pointer, contiguous :: man => null()
66 real(dp), dimension(:), pointer, contiguous :: ustrf => null()
67 integer(I4B), dimension(:), pointer :: rhk_tslink => null() !< nonzero for RHK rows linked to a time series
68 integer(I4B), dimension(:), pointer :: man_tslink => null() !< nonzero for MAN rows linked to a time series
69 integer(I4B), dimension(:), pointer :: ustrf_tslink => null() !< nonzero for USTRF rows linked to a time series
70 ! -- period
71 integer(I4B), pointer :: nbound => null()
72 integer(I4B), dimension(:), pointer, contiguous :: ifno => null()
73 type(characterstringtype), dimension(:), pointer, &
74 contiguous :: status => null()
75 type(characterstringtype), dimension(:), pointer, &
76 contiguous :: setting => null()
77 integer(I4B), dimension(:), pointer, contiguous :: idv => null()
78 type(characterstringtype), dimension(:), pointer, &
79 contiguous :: tab6_filename => null()
80 type(characterstringtype), dimension(:), pointer, &
81 contiguous :: auxname => null()
82 real(dp), dimension(:), pointer, contiguous :: auxval => null()
83 contains
84 procedure :: init => sfr_input_init
85 procedure :: destroy => sfr_input_destroy
86 end type sfrinputtype
87
88 type, extends(bndexttype) :: sfrtype
89 ! -- scalars
90 ! -- for budgets
91 ! -- characters
92 character(len=16), dimension(:), pointer, contiguous :: csfrbudget => null() !< advanced package budget names
93 character(len=16), dimension(:), pointer, contiguous :: cauxcbc => null() !< aux names
94 character(len=LENBOUNDNAME), dimension(:), pointer, &
95 contiguous :: sfrname => null() !< internal SFR reach name
96 ! -- integers
97 integer(I4B), pointer :: istorage => null() !< flag for using kinematic wave approximation
98 integer(I4B), pointer :: iprhed => null() !< flag for printing stages to listing file
99 integer(I4B), pointer :: istageout => null() !< flag and unit number for binary stage output
100 integer(I4B), pointer :: ibudgetout => null() !< flag and unit number for binary sfr budget output
101 integer(I4B), pointer :: ibudcsv => null() !< unit number for csv budget output file
102 integer(I4B), pointer :: ipakcsv => null() !< flag and unit number for package convergence information
103 integer(I4B), pointer :: idiversions => null() !< flag indicating if there are any diversions
104 integer(I4B), pointer :: nconn => null() !< number of reach connections
105 integer(I4B), pointer :: maxsfrpicard => null() !< maximum number of Picard iteration calls to SFR solve
106 integer(I4B), pointer :: maxsfrit => null() !< maximum number of iterations in SFR solve
107 integer(I4B), pointer :: bditems => null() !< number of SFR budget items
108 integer(I4B), pointer :: cbcauxitems => null() !< number of aux items in cell-by-cell budget file
109 integer(I4B), pointer :: icheck => null() !< flag indicating if input should be checked (default is yes)
110 integer(I4B), pointer :: iconvchk => null() !< flag indicating of final convergence run is executed
111 integer(I4B), pointer :: gwfiss => null() !< groundwater model steady-state flag
112 integer(I4B), pointer :: ianynone => null() !< number of reaches with 'none' connection
113 ! -- double precision
114 real(dp), pointer :: unitconv => null() !< unit conversion factor (SI to model units)
115 real(dp), pointer :: lengthconv => null() !< length conversion factor (SI to model units)
116 real(dp), pointer :: timeconv => null() !< time conversion factor (SI to model units)
117 real(dp), pointer :: dmaxchg => null() !< maximum depth change allowed
118 real(dp), pointer :: deps => null() !< perturbation value
119 real(dp), pointer :: storage_weight => null() !< time weighting factor for kinematic wave approximation
120 ! -- integer vectors
121 integer(I4B), dimension(:), pointer, contiguous :: isfrorder => null() !< sfr reach order determined from DAG of upstream reaches
122 integer(I4B), dimension(:), pointer, contiguous :: ia => null() !< CRS row pointer for SFR reaches
123 integer(I4B), dimension(:), pointer, contiguous :: ja => null() !< CRS column pointers for SFR reach connections
124 ! -- double precision output vectors
125 real(dp), dimension(:), pointer, contiguous :: qoutflow => null() !< reach downstream flow
126 real(dp), dimension(:), pointer, contiguous :: qextoutflow => null() !< reach discharge to external boundary
127 real(dp), dimension(:), pointer, contiguous :: qauxcbc => null() !< aux value
128 real(dp), dimension(:), pointer, contiguous :: dbuff => null() !< temporary vector
129 !
130 ! -- sfr budget object
131 type(budgetobjecttype), pointer :: budobj => null() !< SFR budget object
132 !
133 ! -- sfr table objects
134 type(tabletype), pointer :: stagetab => null() !< reach stage table written to the listing file
135 type(tabletype), pointer :: couranttab => null() !< Courant number table written to the listing file
136 type(tabletype), pointer :: pakcsvtab => null() !< SFR package convergence table
137 !
138 ! -- sfr reach data
139 integer(I4B), dimension(:), pointer, contiguous :: iboundpak => null() !< ibound array for SFR reaches that defines active, inactive, and constant reaches
140 integer(I4B), dimension(:), pointer, contiguous :: igwfnode => null() !< groundwater node connected to SFR reaches
141 integer(I4B), dimension(:), pointer, contiguous :: igwftopnode => null() !< highest active groundwater node under SFR reaches
142 real(dp), dimension(:), pointer, contiguous :: length => null() !< reach length
143 real(dp), dimension(:), pointer, contiguous :: width => null() !< reach width
144 real(dp), dimension(:), pointer, contiguous :: strtop => null() !< reach bed top elevation
145 real(dp), dimension(:), pointer, contiguous :: bthick => null() !< reach bed thickness
146 real(dp), dimension(:), pointer, contiguous :: hk => null() !< vertical hydraulic conductivity of reach bed sediments
147 real(dp), dimension(:), pointer, contiguous :: slope => null() !< reach slope
148 integer(I4B), dimension(:), pointer, contiguous :: nconnreach => null() !< number of connections for each reach
149 real(dp), dimension(:), pointer, contiguous :: ustrf => null() !< upstream flow fraction for upstream connections
150 logical(LGP), dimension(:), pointer, contiguous :: bedk_set => null() !< reach has an active PERIOD BEDK override
151 logical(LGP), dimension(:), pointer, contiguous :: manning_set => null() !< reach has an active PERIOD MANNING override
152 logical(LGP), dimension(:), pointer, contiguous :: ustrf_set => null() !< reach has an active PERIOD UPSTREAM_FRACTION override
153 real(dp), dimension(:), pointer, contiguous :: ftotnd => null() !< total fraction of connected reaches that are not diversions
154 integer(I4B), dimension(:), pointer, contiguous :: ndiv => null() !< number of diversions for each reach
155 real(dp), dimension(:), pointer, contiguous :: usflow => null() !< upstream reach flow
156 real(dp), dimension(:), pointer, contiguous :: dsflow => null() !< downstream reach flow
157 real(dp), dimension(:), pointer, contiguous :: dsflowold => null() !< downstream reach flow for previous time step
158 real(dp), dimension(:), pointer, contiguous :: usinflow => null() !< upstream reach flow for previous time step
159 real(dp), dimension(:), pointer, contiguous :: usinflowold => null() !< upstream reach flow for previous time step
160 real(dp), dimension(:), pointer, contiguous :: xsaus => null() !< wetted area at the upstream inflow at the end of the last solve
161 real(dp), dimension(:), pointer, contiguous :: xsads => null() !< wetted area at the downstream flow at the end of the last solve
162 real(dp), dimension(:), pointer, contiguous :: xsausold => null() !< wetted area at the upstream inflow for previous time step
163 real(dp), dimension(:), pointer, contiguous :: xsadsold => null() !< wetted area at the downstream flow for previous time step
164 real(dp), pointer :: ats_courant => null() !< target Courant number for ATS time step submission
165 integer(I4B), dimension(:), pointer, contiguous :: itvd_upstream => null() !< upstream reach index for TVD limiter (0 = headwater or confluence)
166 real(dp), dimension(:), pointer, contiguous :: crmin => null() !< simulation-wide minimum Courant number per reach
167 real(dp), dimension(:), pointer, contiguous :: crmax => null() !< simulation-wide maximum Courant number per reach
168 real(dp), dimension(:), pointer, contiguous :: crsum => null() !< simulation-wide sum of Courant numbers per reach
169 integer(I4B), dimension(:), pointer, contiguous :: crcnt => null() !< simulation-wide count of non-zero Courant evaluations per reach
170 real(dp), dimension(:), pointer, contiguous :: depth => null() !< reach depth
171 real(dp), dimension(:), pointer, contiguous :: stage => null() !< reach stage
172 real(dp), dimension(:), pointer, contiguous :: stageold => null() !< reach stage for last timestep
173 real(dp), dimension(:), pointer, contiguous :: gwflow => null() !< flow from groundwater to reach
174 real(dp), dimension(:), pointer, contiguous :: simevap => null() !< simulated reach evaporation
175 real(dp), dimension(:), pointer, contiguous :: simrunoff => null() !< simulated reach runoff
176 real(dp), dimension(:), pointer, contiguous :: stage0 => null() !< previous reach stage iterate
177 real(dp), dimension(:), pointer, contiguous :: usflow0 => null() !< previous upstream reach flow iterate
178 real(dp), dimension(:), pointer, contiguous :: storage => null() !< previous upstream reach flow iterate
179 ! -- cross-section data
180 integer(I4B), pointer :: ncrossptstot => null() !< total number of cross-section points
181 integer(I4B), dimension(:), pointer, contiguous :: ncrosspts => null() !< number of cross-section points for each reach
182 integer(I4B), dimension(:), pointer, contiguous :: iacross => null() !< pointers to cross-section data for each reach
183 real(dp), dimension(:), pointer, contiguous :: station => null() !< cross-section station (x-position) data
184 real(dp), dimension(:), pointer, contiguous :: xsheight => null() !< cross-section height data
185 real(dp), dimension(:), pointer, contiguous :: xsrough => null() !< cross-section roughness data
186 ! -- connection data
187 integer(I4B), dimension(:), pointer, contiguous :: idir => null() !< reach connection direction
188 integer(I4B), dimension(:), pointer, contiguous :: idiv => null() !< reach connection diversion number
189 real(dp), dimension(:), pointer, contiguous :: qconn => null() !< reach connection flow
190 ! -- boundary data
191 real(dp), dimension(:), pointer, contiguous :: rough => null() !< reach Manning's roughness coefficient (SI units)
192 real(dp), dimension(:), pointer, contiguous :: rain => null() !< reach rainfall
193 real(dp), dimension(:), pointer, contiguous :: evap => null() !< reach potential evaporation
194 real(dp), dimension(:), pointer, contiguous :: inflow => null() !< reach upstream inflow
195 real(dp), dimension(:), pointer, contiguous :: runoff => null() !< reach maximum runoff
196 real(dp), dimension(:), pointer, contiguous :: sstage => null() !< reach specified stage
197 ! -- diversion data
198 integer(I4B), dimension(:), pointer, contiguous :: iadiv => null() !< row pointer for reach diversions
199 integer(I4B), dimension(:), pointer, contiguous :: divreach => null() !< diversion reach
200 character(len=10), dimension(:), pointer, contiguous :: divcprior => null() !< diversion rule
201 real(dp), dimension(:), pointer, contiguous :: divflow => null() !< specified diversion flow value
202 real(dp), dimension(:), pointer, contiguous :: divq => null() !< simulated diversion flow
203 !
204 ! -- density variables
205 integer(I4B), pointer :: idense !< flag indicating if density corrections are active
206 real(dp), dimension(:, :), pointer, contiguous :: denseterms => null() !< density terms
207 !
208 ! -- viscosity variables
209 real(dp), dimension(:, :), pointer, contiguous :: viscratios => null() !< viscosity ratios (1: sfr vsc ratio; 2: gwf vsc ratio)
210 !
211 ! -- input context data pointers (PACKAGEDATA + PERIOD arrays)
212 type(sfrinputtype) :: input
213 !
214 ! -- type bound procedures
215 contains
221
222 ! procedure :: set_pointers => sfr_set_pointers
223 procedure :: bnd_ar => sfr_ar
224 procedure :: bnd_rp => sfr_rp
225 procedure :: bnd_ad => sfr_ad
226 procedure :: bnd_cf => sfr_cf
227 procedure :: bnd_fc => sfr_fc
228 procedure :: bnd_fn => sfr_fn
229 procedure :: bnd_cc => sfr_cc
230 procedure :: bnd_cq => sfr_cq
232 procedure :: bnd_ot_dv => sfr_ot_dv
234 procedure :: bnd_dt => sfr_dt
235 procedure :: bnd_fp => sfr_fp
236 procedure :: bnd_da => sfr_da
237 procedure :: define_listlabel
238 ! -- methods for observations
239 procedure, public :: bnd_obs_supported => sfr_obs_supported
240 procedure, public :: bnd_df_obs => sfr_df_obs
241 procedure, public :: bnd_rp_obs => sfr_rp_obs
242 procedure, public :: bnd_bd_obs => sfr_bd_obs
243 ! -- private procedures
244
245 procedure, private :: sfr_solve
246 !> @brief Method for solving for simple reaches
247 !!
248 !! Method to solve the continuity equation for a SFR package
249 !! reach using the simple approach.
250 !<
251 procedure, private :: sfr_calc_constant
252 !> @brief Method for solving for transient reaches
253 !!
254 !! Method to solve the continuity equation for a SFR package
255 !! reach using the kinematic wave approximation.
256 !<
257 procedure, private :: sfr_calc_transient
258 !> @brief Kinematic-wave routing with TVD flux limiter
259 !!
260 !! Explicit van Leer TVD update of the continuity equation with exact
261 !! volume balance; reverts to first-order upwind for Cr > 1 and at
262 !! confluences.
263 !<
264 procedure, private :: sfr_calc_tvd
265 procedure, private :: sfr_calc_celerity
266 !> @brief Method for solving for standard reaches
267 !!
268 !! Method to solve the continuity equation for a SFR package
269 !! reach using the standard approach.
270 !<
271 procedure, private :: sfr_calc_steady
272 procedure, private :: sfr_precompute_tvd
273 procedure, private :: sfr_update_flows
274 procedure, private :: sfr_adjust_ro_ev
275 procedure, private :: sfr_calc_qgwf
276 procedure, private :: sfr_gwf_conn
277 procedure, private :: sfr_calc_cond
278 procedure, private :: sfr_calc_qman
279 procedure, private :: sfr_calc_qd
280 procedure, private :: sfr_calc_qsource
281 procedure, private :: sfr_calc_div
282 ! -- geometry
283 procedure, private :: calc_area_wet
284 procedure, private :: calc_perimeter_wet
285 procedure, private :: calc_surface_area
286 procedure, private :: calc_surface_area_wet
287 procedure, private :: calc_top_width_wet
288 ! -- input context sourcing
289 procedure, private :: sfr_source_packagedata
290 procedure, private :: sfr_source_crosssections
291 procedure, private :: sfr_source_connectiondata
292 procedure, private :: sfr_source_diversions
293 procedure, private :: sfr_source_initialstages
294 ! -- calculations
295 procedure, private :: sfr_calc_reach_depth
296 procedure, private :: sfr_calc_xs_depth
297 ! -- error checking
298 procedure, private :: sfr_check_conversion
299 procedure, private :: sfr_check_storage_weight
300 procedure, private :: sfr_check_reaches
301 procedure, private :: sfr_check_connections
302 procedure, private :: sfr_check_diversions
303 procedure, private :: sfr_check_initialstages
304 procedure, private :: sfr_check_ustrf
305 procedure, private :: sfr_set_period_value
306 ! -- budget
307 procedure, private :: sfr_setup_budobj
308 procedure, private :: sfr_fill_budobj
309 ! -- table
310 procedure, private :: sfr_setup_tableobj
311 ! -- density
313 procedure, private :: sfr_calculate_density_exchange
314 ! -- viscosity
316 end type sfrtype
317
318 interface
319 module subroutine sfr_calc_steady(this, n, d1, hgwf, &
320 qu, qi, qfrommvr, qr, qe, qro, &
321 qgwf, qd)
322 class(sfrtype) :: this !< SfrType object
323 integer(I4B), intent(in) :: n !< reach number
324 real(dp), intent(inout) :: d1 !< current reach depth estimate
325 real(dp), intent(in) :: hgwf !< head in gw cell
326 real(dp), intent(in) :: qu !< reach upstream flow
327 real(dp), intent(in) :: qi !< reach specified inflow
328 real(dp), intent(in) :: qfrommvr !< reach flow from mover
329 real(dp), intent(in) :: qr !< reach rainfall
330 real(dp), intent(in) :: qe !< reach evaporation
331 real(dp), intent(in) :: qro !< reach runoff flow
332 real(dp), intent(inout) :: qgwf !< reach-aquifer exchange
333 real(dp), intent(inout) :: qd !< reach outflow
334 end subroutine
335 end interface
336
337 interface
338 module subroutine sfr_calc_transient(this, n, d1, hgwf, &
339 qu, qi, qfrommvr, qr, qe, qro, &
340 qgwf, qd)
341 class(sfrtype) :: this !< SfrType object
342 integer(I4B), intent(in) :: n !< reach number
343 real(dp), intent(inout) :: d1 !< current reach depth estimate
344 real(dp), intent(in) :: hgwf !< head in gw cell
345 real(dp), intent(in) :: qu !< reach upstream flow
346 real(dp), intent(in) :: qi !< reach specified inflow
347 real(dp), intent(in) :: qfrommvr !< reach flow from mover
348 real(dp), intent(in) :: qr !< reach rainfall
349 real(dp), intent(in) :: qe !< reach evaporation
350 real(dp), intent(in) :: qro !< reach runoff flow
351 real(dp), intent(inout) :: qgwf !< reach-aquifer exchange
352 real(dp), intent(inout) :: qd !< reach outflow
353 end subroutine
354 end interface
355
356 interface
357 module subroutine sfr_calc_tvd(this, n, d1, hgwf, &
358 qu, qi, qfrommvr, qr, qe, qro, &
359 qgwf, qd)
360 class(sfrtype) :: this !< SfrType object
361 integer(I4B), intent(in) :: n !< reach number
362 real(dp), intent(inout) :: d1 !< current reach depth estimate
363 real(dp), intent(in) :: hgwf !< head in gw cell
364 real(dp), intent(in) :: qu !< reach upstream flow
365 real(dp), intent(in) :: qi !< reach specified inflow
366 real(dp), intent(in) :: qfrommvr !< reach flow from mover
367 real(dp), intent(in) :: qr !< reach rainfall
368 real(dp), intent(in) :: qe !< reach evaporation
369 real(dp), intent(in) :: qro !< reach runoff flow
370 real(dp), intent(inout) :: qgwf !< reach-aquifer exchange
371 real(dp), intent(inout) :: qd !< reach outflow
372 end subroutine
373 end interface
374
375 interface
376 module subroutine sfr_calc_constant(this, n, d1, hgwf, qgwf, qd)
377 class(sfrtype) :: this !< SfrType object
378 integer(I4B), intent(in) :: n !< reach number
379 real(dp), intent(inout) :: d1 !< current reach depth estimate
380 real(dp), intent(in) :: hgwf !< head in gw cell
381 real(dp), intent(inout) :: qgwf !< reach-aquifer exchange
382 real(dp), intent(inout) :: qd !< reach outflow
383 end subroutine
384 end interface
385
386contains
387
388 !> @brief Create a new package object
389 !!
390 !! Create a new SFR Package object
391 !<
392 subroutine sfr_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, &
393 mempath)
394 ! -- modules
396 ! -- dummy
397 class(bndtype), pointer :: packobj !< pointer to default package type
398 integer(I4B), intent(in) :: id !< package id
399 integer(I4B), intent(in) :: ibcnum !< boundary condition number
400 integer(I4B), intent(in) :: inunit !< unit number of SFR package input file
401 integer(I4B), intent(in) :: iout !< unit number of model listing file
402 character(len=*), intent(in) :: namemodel !< model name
403 character(len=*), intent(in) :: pakname !< package name
404 character(len=*), intent(in) :: mempath !< input mempath
405 ! -- local
406 type(sfrtype), pointer :: sfrobj
407 !
408 ! -- allocate the object and assign values to object variables
409 allocate (sfrobj)
410 packobj => sfrobj
411 !
412 ! -- create name and memory path
413 call packobj%set_names(ibcnum, namemodel, pakname, ftype, mempath)
414 packobj%text = text
415 !
416 ! -- allocate scalars
417 call sfrobj%sfr_allocate_scalars()
418 !
419 ! -- initialize package
420 call packobj%pack_initialize()
421
422 packobj%inunit = inunit
423 packobj%iout = iout
424 packobj%id = id
425 packobj%ibcnum = ibcnum
426 packobj%ncolbnd = 4
427 packobj%iscloc = 0 ! not supported
428 packobj%isadvpak = 1
429 packobj%ictMemPath = create_mem_path(namemodel, 'NPF')
430 end subroutine sfr_create
431
432 !> @brief Allocate scalars
433 !!
434 !! Allocate and initialize scalars for the SFR package. The base model
435 !! allocate scalars method is also called.
436 !<
437 subroutine sfr_allocate_scalars(this)
438 ! -- modules
441 ! -- dummy
442 class(sfrtype), intent(inout) :: this !< SfrType object
443 !
444 ! -- call standard BndExtType allocate scalars
445 call this%BndExtType%allocate_scalars()
446 !
447 ! -- allocate the object and assign values to object variables
448 call mem_allocate(this%istorage, 'ISTORAGE', this%memoryPath)
449 call mem_allocate(this%iprhed, 'IPRHED', this%memoryPath)
450 call mem_allocate(this%istageout, 'ISTAGEOUT', this%memoryPath)
451 call mem_allocate(this%ibudgetout, 'IBUDGETOUT', this%memoryPath)
452 call mem_allocate(this%ibudcsv, 'IBUDCSV', this%memoryPath)
453 call mem_allocate(this%ipakcsv, 'IPAKCSV', this%memoryPath)
454 call mem_allocate(this%idiversions, 'IDIVERSIONS', this%memoryPath)
455 call mem_allocate(this%maxsfrpicard, 'MAXSFRPICARD', this%memoryPath)
456 call mem_allocate(this%maxsfrit, 'MAXSFRIT', this%memoryPath)
457 call mem_allocate(this%bditems, 'BDITEMS', this%memoryPath)
458 call mem_allocate(this%cbcauxitems, 'CBCAUXITEMS', this%memoryPath)
459 call mem_allocate(this%unitconv, 'UNITCONV', this%memoryPath)
460 call mem_allocate(this%lengthconv, 'LENGTHCONV', this%memoryPath)
461 call mem_allocate(this%timeconv, 'TIMECONV', this%memoryPath)
462 call mem_allocate(this%dmaxchg, 'DMAXCHG', this%memoryPath)
463 call mem_allocate(this%deps, 'DEPS', this%memoryPath)
464 call mem_allocate(this%storage_weight, 'STORAGE_WEIGHT', this%memoryPath)
465 call mem_allocate(this%ats_courant, 'ATS_COURANT', this%memoryPath)
466 call mem_allocate(this%nconn, 'NCONN', this%memoryPath)
467 call mem_allocate(this%icheck, 'ICHECK', this%memoryPath)
468 call mem_allocate(this%iconvchk, 'ICONVCHK', this%memoryPath)
469 call mem_allocate(this%idense, 'IDENSE', this%memoryPath)
470 call mem_allocate(this%ianynone, 'IANYNONE', this%memoryPath)
471 call mem_allocate(this%ncrossptstot, 'NCROSSPTSTOT', this%memoryPath)
472 !
473 ! -- set pointer to gwf iss
474 call mem_setptr(this%gwfiss, 'ISS', create_mem_path(this%name_model))
475 !
476 ! -- Set values
477 this%istorage = 0
478 this%iprhed = 0
479 this%istageout = 0
480 this%ibudgetout = 0
481 this%ibudcsv = 0
482 this%ipakcsv = 0
483 this%idiversions = 0
484 this%maxsfrpicard = 100
485 this%maxsfrit = maxadpit
486 this%bditems = 8
487 this%cbcauxitems = 1
488 this%unitconv = done
489 this%lengthconv = dnodata
490 this%timeconv = dnodata
491 this%dmaxchg = dem5
492 this%deps = dp999 * this%dmaxchg
493 this%storage_weight = dnodata
494 this%ats_courant = dnodata
495 this%nconn = 0
496 this%icheck = 1
497 this%iconvchk = 1
498 this%idense = 0
499 this%ivsc = 0
500 this%ianynone = 0
501 this%ncrossptstot = 0
502 end subroutine sfr_allocate_scalars
503
504 !> @brief Allocate arrays
505 !!
506 !! Allocate and initialize array for the SFR package.
507 !<
508 subroutine sfr_allocate_arrays(this)
509 ! -- modules
511 ! -- dummy
512 class(sfrtype), intent(inout) :: this !< SfrType object
513 ! -- local
514 integer(I4B) :: i
515 !
516 ! -- allocate character array for budget text
517 allocate (this%csfrbudget(this%bditems))
518 call mem_allocate(this%sfrname, lenboundname, this%maxbound, &
519 'SFRNAME', this%memoryPath)
520 !
521 ! -- variables originally in SfrDataType
522 call mem_allocate(this%iboundpak, this%maxbound, 'IBOUNDPAK', &
523 this%memoryPath)
524 call mem_allocate(this%igwfnode, this%maxbound, 'IGWFNODE', this%memoryPath)
525 call mem_allocate(this%igwftopnode, this%maxbound, 'IGWFTOPNODE', &
526 this%memoryPath)
527 call mem_allocate(this%length, this%maxbound, 'LENGTH', this%memoryPath)
528 call mem_allocate(this%width, this%maxbound, 'WIDTH', this%memoryPath)
529 call mem_allocate(this%strtop, this%maxbound, 'STRTOP', this%memoryPath)
530 call mem_allocate(this%bthick, this%maxbound, 'BTHICK', this%memoryPath)
531 call mem_allocate(this%slope, this%maxbound, 'SLOPE', this%memoryPath)
532 call mem_allocate(this%nconnreach, this%maxbound, 'NCONNREACH', &
533 this%memoryPath)
534 call mem_allocate(this%bedk_set, this%maxbound, 'BEDK_SET', this%memoryPath)
535 call mem_allocate(this%manning_set, this%maxbound, 'MANNING_SET', &
536 this%memoryPath)
537 call mem_allocate(this%ustrf_set, this%maxbound, 'USTRF_SET', &
538 this%memoryPath)
539 this%bedk_set = .false.
540 this%manning_set = .false.
541 this%ustrf_set = .false.
542 call mem_allocate(this%ftotnd, this%maxbound, 'FTOTND', this%memoryPath)
543 call mem_allocate(this%ndiv, this%maxbound, 'NDIV', this%memoryPath)
544 call mem_allocate(this%usflow, this%maxbound, 'USFLOW', this%memoryPath)
545 call mem_allocate(this%dsflow, this%maxbound, 'DSFLOW', this%memoryPath)
546 call mem_allocate(this%depth, this%maxbound, 'DEPTH', this%memoryPath)
547 call mem_allocate(this%stage, this%maxbound, 'STAGE', this%memoryPath)
548 call mem_allocate(this%gwflow, this%maxbound, 'GWFLOW', this%memoryPath)
549 call mem_allocate(this%simevap, this%maxbound, 'SIMEVAP', this%memoryPath)
550 call mem_allocate(this%simrunoff, this%maxbound, 'SIMRUNOFF', &
551 this%memoryPath)
552 call mem_allocate(this%stage0, this%maxbound, 'STAGE0', this%memoryPath)
553 call mem_allocate(this%usflow0, this%maxbound, 'USFLOW0', this%memoryPath)
554 !
555 ! -- stage, usflow, inflow, and dsflow for previous timestep
556 if (this%istorage == 1) then
557 call mem_allocate(this%stageold, this%maxbound, 'STAGEOLD', &
558 this%memoryPath)
559 call mem_allocate(this%usinflow, this%maxbound, 'USINFLOW', &
560 this%memoryPath)
561 call mem_allocate(this%usinflowold, this%maxbound, 'USINFLOWOLD', &
562 this%memoryPath)
563 call mem_allocate(this%dsflowold, this%maxbound, 'DSFLOWOLD', &
564 this%memoryPath)
565 call mem_allocate(this%xsaus, this%maxbound, 'XSAUS', this%memoryPath)
566 call mem_allocate(this%xsads, this%maxbound, 'XSADS', this%memoryPath)
567 call mem_allocate(this%xsausold, this%maxbound, 'XSAUSOLD', &
568 this%memoryPath)
569 call mem_allocate(this%xsadsold, this%maxbound, 'XSADSOLD', &
570 this%memoryPath)
571 call mem_allocate(this%storage, this%maxbound, 'STORAGE', &
572 this%memoryPath)
573 call mem_allocate(this%crmin, this%maxbound, 'CRMIN', this%memoryPath)
574 call mem_allocate(this%crmax, this%maxbound, 'CRMAX', this%memoryPath)
575 call mem_allocate(this%crsum, this%maxbound, 'CRSUM', this%memoryPath)
576 call mem_allocate(this%crcnt, this%maxbound, 'CRCNT', this%memoryPath)
577 if (this%ats_courant /= dnodata) then
578 call mem_allocate(this%itvd_upstream, this%maxbound, &
579 'ITVD_UPSTREAM', this%memoryPath)
580 else
581 call mem_allocate(this%itvd_upstream, 0, 'ITVD_UPSTREAM', this%memoryPath)
582 end if
583 end if
584 !
585 ! -- reach order and connection data
586 call mem_allocate(this%isfrorder, this%maxbound, 'ISFRORDER', &
587 this%memoryPath)
588 call mem_allocate(this%ia, this%maxbound + 1, 'IA', this%memoryPath)
589 call mem_allocate(this%ja, 0, 'JA', this%memoryPath)
590 call mem_allocate(this%idir, 0, 'IDIR', this%memoryPath)
591 call mem_allocate(this%idiv, 0, 'IDIV', this%memoryPath)
592 call mem_allocate(this%qconn, 0, 'QCONN', this%memoryPath)
593 !
594 ! -- alias into the input context's permanent, feature-indexed arrays
595 ! (allocated and DZERO-initialized by the loader)
596 call mem_setptr(this%rain, 'RAINFALL', this%input_mempath)
597 call mem_setptr(this%evap, 'EVAPORATION', this%input_mempath)
598 call mem_setptr(this%inflow, 'INFLOW', this%input_mempath)
599 call mem_setptr(this%runoff, 'RUNOFF', this%input_mempath)
600 call mem_setptr(this%sstage, 'STAGE', this%input_mempath)
601 call mem_setptr(this%hk, 'BEDK', this%input_mempath)
602 call mem_setptr(this%rough, 'MANNING', this%input_mempath)
603 call mem_setptr(this%ustrf, 'UPSTREAM_FRAC', this%input_mempath)
604 !
605 !
606 ! -- diversion variables
607 call mem_allocate(this%iadiv, this%maxbound + 1, 'IADIV', this%memoryPath)
608 call mem_allocate(this%divreach, 0, 'DIVREACH', this%memoryPath)
609 call mem_allocate(this%divq, 0, 'DIVQ', this%memoryPath)
610 !
611 ! -- cross-section data
612 call mem_allocate(this%ncrosspts, this%maxbound, 'NCROSSPTS', &
613 this%memoryPath)
614 call mem_allocate(this%iacross, this%maxbound + 1, 'IACROSS', &
615 this%memoryPath)
616 call mem_allocate(this%station, this%ncrossptstot, 'STATION', &
617 this%memoryPath)
618 call mem_allocate(this%xsheight, this%ncrossptstot, 'XSHEIGHT', &
619 this%memoryPath)
620 call mem_allocate(this%xsrough, this%ncrossptstot, 'XSROUGH', &
621 this%memoryPath)
622 !
623 ! -- initialize variables
624 this%iacross(1) = 0
625 do i = 1, this%maxbound
626 this%iboundpak(i) = 1
627 this%igwfnode(i) = 0
628 this%igwftopnode(i) = 0
629 this%length(i) = dzero
630 this%width(i) = dzero
631 this%strtop(i) = dzero
632 this%bthick(i) = dzero
633 this%hk(i) = dzero
634 this%slope(i) = dzero
635 this%nconnreach(i) = 0
636 this%ustrf(i) = dzero
637 this%ftotnd(i) = dzero
638 this%ndiv(i) = 0
639 this%usflow(i) = dzero
640 this%dsflow(i) = dzero
641 this%depth(i) = dzero
642 this%stage(i) = dzero
643 this%gwflow(i) = dzero
644 this%simevap(i) = dzero
645 this%simrunoff(i) = dzero
646 this%stage0(i) = dzero
647 this%usflow0(i) = dzero
648 !
649 ! -- stage
650 if (this%istorage == 1) then
651 this%stageold(i) = dzero
652 this%usinflow(i) = dzero
653 this%usinflowold(i) = dzero
654 this%dsflowold(i) = dzero
655 this%xsaus(i) = dzero
656 this%xsads(i) = dzero
657 this%xsausold(i) = dzero
658 this%xsadsold(i) = dzero
659 this%storage(i) = dzero
660 this%crmin(i) = dep20
661 this%crmax(i) = -dep20
662 this%crsum(i) = dzero
663 this%crcnt(i) = 0
664 if (this%ats_courant /= dnodata) then
665 this%itvd_upstream(i) = 0
666 end if
667 end if
668 !
669 ! -- boundary data
670 this%rough(i) = dzero
671 !
672 !
673 ! -- cross-section data
674 this%ncrosspts(i) = 0
675 this%iacross(i + 1) = 0
676 end do
677 !
678 ! -- initialize additional cross-section data
679 do i = 1, this%ncrossptstot
680 this%station(i) = dzero
681 this%xsheight(i) = dzero
682 this%xsrough(i) = dzero
683 end do
684 !
685 !-- fill csfrbudget
686 this%csfrbudget(1) = ' RAINFALL'
687 this%csfrbudget(2) = ' EVAPORATION'
688 this%csfrbudget(3) = ' RUNOFF'
689 this%csfrbudget(4) = ' EXT-INFLOW'
690 this%csfrbudget(5) = ' GWF'
691 this%csfrbudget(6) = ' EXT-OUTFLOW'
692 this%csfrbudget(7) = ' FROM-MVR'
693 this%csfrbudget(8) = ' TO-MVR'
694 !
695 ! -- allocate and initialize budget output data
696 call mem_allocate(this%qoutflow, this%maxbound, 'QOUTFLOW', this%memoryPath)
697 call mem_allocate(this%qextoutflow, this%maxbound, 'QEXTOUTFLOW', &
698 this%memoryPath)
699 do i = 1, this%maxbound
700 this%qoutflow(i) = dzero
701 this%qextoutflow(i) = dzero
702 end do
703 !
704 ! -- allocate and initialize dbuff
705 if (this%istageout > 0) then
706 call mem_allocate(this%dbuff, this%maxbound, 'DBUFF', this%memoryPath)
707 do i = 1, this%maxbound
708 this%dbuff(i) = dzero
709 end do
710 else
711 call mem_allocate(this%dbuff, 0, 'DBUFF', this%memoryPath)
712 end if
713 !
714 ! -- allocate character array for budget text
715 allocate (this%cauxcbc(this%cbcauxitems))
716 !
717 ! -- allocate and initialize qauxcbc
718 call mem_allocate(this%qauxcbc, this%cbcauxitems, 'QAUXCBC', &
719 this%memoryPath)
720 do i = 1, this%cbcauxitems
721 this%qauxcbc(i) = dzero
722 end do
723 !
724 ! -- fill cauxcbc
725 this%cauxcbc(1) = 'FLOW-AREA '
726 !
727 ! -- allocate denseterms to size 0
728 call mem_allocate(this%denseterms, 3, 0, 'DENSETERMS', this%memoryPath)
729 !
730 ! -- allocate viscratios to size 0
731 call mem_allocate(this%viscratios, 2, 0, 'VISCRATIOS', this%memoryPath)
732 end subroutine sfr_allocate_arrays
733
734 !> @brief Alias deprecated SFR variable names to their current storage
735 !!
736 !! IDM integration moved several reach variables into the input context,
737 !! renaming some. These aliases share memory with the relocated variables so
738 !! that programs addressing them through the API by their old package-path
739 !! names continue to resolve; each use is reported as deprecated. DIVFLOW is
740 !! only set from the input context when diversions are present; otherwise an
741 !! empty DIVFLOW is allocated at the package path, as before IDM integration.
742 !<
743 subroutine sfr_checkin_deprecated_names(this)
744 ! -- modules
747 ! -- dummy
748 class(sfrtype), intent(inout) :: this
749 ! -- local
750 real(DP), dimension(:, :), pointer, contiguous :: aux => null()
751 integer(I4B) :: isize
752 ! -- code
753 !
754 ! -- reach auxiliary values, present (possibly empty) in the input context
755 call get_isize('AUX', this%input_mempath, isize)
756 if (isize >= 0) then
757 call mem_setptr(aux, 'AUX', this%input_mempath)
758 call mem_alias_deprecated(aux, 'RAUXVAR', this%memoryPath, &
759 'AUX', this%input_mempath, '6.8.2')
760 end if
761 !
762 ! -- diversion flows
763 if (associated(this%divflow)) then
764 call mem_alias_deprecated(this%divflow, 'DIVFLOW', this%memoryPath, &
765 'DIVFLOW', this%input_mempath, '6.8.2')
766 else
767 call mem_allocate(this%divflow, 0, 'DIVFLOW', this%memoryPath)
768 end if
769 !
770 call mem_alias_deprecated(this%rain, 'RAIN', this%memoryPath, &
771 'RAINFALL', this%input_mempath, '6.8.2')
772 call mem_alias_deprecated(this%evap, 'EVAP', this%memoryPath, &
773 'EVAPORATION', this%input_mempath, '6.8.2')
774 call mem_alias_deprecated(this%inflow, 'INFLOW', this%memoryPath, &
775 'INFLOW', this%input_mempath, '6.8.2')
776 call mem_alias_deprecated(this%runoff, 'RUNOFF', this%memoryPath, &
777 'RUNOFF', this%input_mempath, '6.8.2')
778 call mem_alias_deprecated(this%sstage, 'SSTAGE', this%memoryPath, &
779 'STAGE', this%input_mempath, '6.8.2')
780 call mem_alias_deprecated(this%hk, 'HK', this%memoryPath, &
781 'BEDK', this%input_mempath, '6.8.2')
782 call mem_alias_deprecated(this%rough, 'ROUGH', this%memoryPath, &
783 'MANNING', this%input_mempath, '6.8.2')
784 call mem_alias_deprecated(this%ustrf, 'USTRF', this%memoryPath, &
785 'UPSTREAM_FRAC', this%input_mempath, '6.8.2')
786 end subroutine sfr_checkin_deprecated_names
787
788 !> @brief Source OPTIONS from input context
789 !<
790 subroutine sfr_source_options(this)
791 ! -- modules
795 use openspecmodule, only: access, form
796 ! -- dummy
797 class(sfrtype), intent(inout) :: this !< SfrType object
798 ! -- local
799 character(len=LINELENGTH) :: fname
800 logical(LGP) :: found
801 ! -- formats
802 character(len=*), parameter :: fmtpicard = &
803 &"(4x, 'MAXIMUM SFR PICARD ITERATION VALUE (',i0,') SPECIFIED.')"
804 character(len=*), parameter :: fmtiter = &
805 &"(4x, 'MAXIMUM SFR ITERATION VALUE (',i0,') SPECIFIED.')"
806 character(len=*), parameter :: fmtdmaxchg = &
807 &"(4x, 'MAXIMUM DEPTH CHANGE VALUE (',g0,') SPECIFIED.')"
808 character(len=*), parameter :: fmtlengthconv = &
809 &"(4x, 'LENGTH CONVERSION VALUE (',g0,') SPECIFIED.')"
810 character(len=*), parameter :: fmttimeconv = &
811 &"(4x, 'TIME CONVERSION VALUE (',g0,') SPECIFIED.')"
812 character(len=*), parameter :: fmtstoweight = &
813 &"(4x, 'KINEMATIC STORAGE WEIGHT (',g0,') SPECIFIED.')"
814 character(len=*), parameter :: fmtsfrbin = &
815 "(4x, 'SFR ', 1x, a, 1x, ' WILL BE SAVED TO FILE: ', a, /4x, &
816 &'OPENED ON UNIT: ', I0)"
817 integer(I4B) :: isize
818 !
819 ! -- source base BndExtType options (NAUX, BOUNDNAMES, PRINT_INPUT, etc.)
820 call this%BndExtType%source_options()
821 !
822 write (this%iout, '(/1x,a)') &
823 'PROCESSING '//trim(adjustl(this%text))//' OPTIONS'
824 !
825 ! -- STORAGE
826 call mem_set_value(this%istorage, 'STORAGE', this%input_mempath, found)
827 if (found) then
828 write (this%iout, '(4x,a)') trim(adjustl(this%text))// &
829 ' REACH STORAGE IS ACTIVE.'
830 end if
831 !
832 ! -- ATS_COURANT
833 call mem_set_value(this%ats_courant, 'ATS_COURANT', &
834 this%input_mempath, found)
835 if (found) then
836 if (this%ats_courant <= dzero) then
837 write (errmsg, '(a,g0,a)') &
838 "ATS_COURANT SPECIFIED TO BE '", this%ats_courant, &
839 "' BUT MUST BE GREATER THAN ZERO"
840 call store_error(errmsg)
841 call store_error_filename(this%input_fname)
842 else
843 write (this%iout, '(4x,a,1pg15.6)') &
844 'TARGET COURANT NUMBER FOR ADAPTIVE TIME STEPS: ', &
845 this%ats_courant
846 end if
847 end if
848 !
849 ! -- PRINT_STAGE
850 call mem_set_value(this%iprhed, 'PRINT_STAGE', this%input_mempath, found)
851 if (found) then
852 write (this%iout, '(4x,a)') trim(adjustl(this%text))// &
853 ' STAGES WILL BE PRINTED TO LISTING FILE.'
854 end if
855 !
856 ! -- STAGEFILE
857 call mem_set_value(fname, 'STAGEFILE', this%input_mempath, found)
858 if (found) then
859 this%istageout = getunit()
860 call openfile(this%istageout, this%iout, fname, 'DATA(BINARY)', &
861 form, access, 'REPLACE', mnormal)
862 write (this%iout, fmtsfrbin) 'STAGE', trim(fname), this%istageout
863 end if
864 !
865 ! -- BUDGETFILE
866 call mem_set_value(fname, 'BUDGETFILE', this%input_mempath, found)
867 if (found) then
868 call assign_iounit(this%ibudgetout, this%inunit, 'BUDGET fileout')
869 call openfile(this%ibudgetout, this%iout, fname, 'DATA(BINARY)', &
870 form, access, 'REPLACE', mnormal)
871 write (this%iout, fmtsfrbin) 'BUDGET', trim(fname), this%ibudgetout
872 end if
873 !
874 ! -- BUDGETCSVFILE
875 call mem_set_value(fname, 'BUDGETCSVFILE', this%input_mempath, found)
876 if (found) then
877 call assign_iounit(this%ibudcsv, this%inunit, 'BUDGETCSV fileout')
878 call openfile(this%ibudcsv, this%iout, fname, 'CSV', &
879 filstat_opt='REPLACE')
880 write (this%iout, fmtsfrbin) 'BUDGET CSV', trim(fname), this%ibudcsv
881 end if
882 !
883 ! -- PACKAGE_CONVERGENCE_FILENAME (mf6internal: pkgconvfname)
884 call mem_set_value(fname, 'PKGCONVFNAME', this%input_mempath, found)
885 if (found) then
886 this%ipakcsv = getunit()
887 call openfile(this%ipakcsv, this%iout, fname, 'CSV', &
888 filstat_opt='REPLACE', mode_opt=mnormal)
889 write (this%iout, fmtsfrbin) 'PACKAGE_CONVERGENCE', trim(fname), &
890 this%ipakcsv
891 end if
892 !
893 ! -- MOVER
894 call mem_set_value(this%imover, 'MOVER', this%input_mempath, found)
895 if (found) then
896 write (this%iout, '(4x,A)') 'MOVER OPTION ENABLED'
897 end if
898 !
899 ! -- MAXIMUM_PICARD_ITERATIONS (mf6internal: maxsfrpicard)
900 call mem_set_value(this%maxsfrpicard, 'MAXSFRPICARD', &
901 this%input_mempath, found)
902 if (found) write (this%iout, fmtpicard) this%maxsfrpicard
903 !
904 ! -- MAXIMUM_ITERATIONS (mf6internal: maxsfrit)
905 call mem_set_value(this%maxsfrit, 'MAXSFRIT', &
906 this%input_mempath, found)
907 if (found) write (this%iout, fmtiter) this%maxsfrit
908 !
909 ! -- MAXIMUM_DEPTH_CHANGE (mf6internal: dmaxchg)
910 call mem_set_value(this%dmaxchg, 'DMAXCHG', &
911 this%input_mempath, found)
912 if (found) then
913 this%deps = dp999 * this%dmaxchg
914 write (this%iout, fmtdmaxchg) this%dmaxchg
915 end if
916 !
917 ! -- LENGTH_CONVERSION (mf6internal: lengthconv)
918 call mem_set_value(this%lengthconv, 'LENGTHCONV', &
919 this%input_mempath, found)
920 if (found) write (this%iout, fmtlengthconv) this%lengthconv
921 !
922 ! -- TIME_CONVERSION
923 call mem_set_value(this%timeconv, 'TIME_CONVERSION', &
924 this%input_mempath, found)
925 if (found) write (this%iout, fmttimeconv) this%timeconv
926 !
927 ! -- UNIT_CONVERSION (deprecated)
928 call mem_set_value(this%unitconv, 'UNIT_CONVERSION', &
929 this%input_mempath, found)
930 if (found) then
931 write (warnmsg, '(a)') 'SETTING UNIT_CONVERSION DIRECTLY'
932 call deprecation_warning('OPTIONS', 'UNIT_CONVERSION', '6.4.2', &
933 warnmsg, this%inunit)
934 end if
935 !
936 ! -- DEV_STORAGE_WEIGHT (mf6internal: storage_weight)
937 call mem_set_value(this%storage_weight, 'STORAGE_WEIGHT', &
938 this%input_mempath, found)
939 if (found) then
940 if (this%storage_weight < dhalf .or. this%storage_weight > done) then
941 write (errmsg, '(a,g0,a)') &
942 "STORAGE_WEIGHT SPECIFIED TO BE '", this%storage_weight, &
943 "' BUT CANNOT BE LESS THAN 0.5 OR GREATER THAN 1.0"
944 call store_error(errmsg)
945 call store_error_filename(this%input_fname)
946 else
947 write (this%iout, fmtstoweight) this%storage_weight
948 end if
949 end if
950 !
951 ! -- DEV_NO_CHECK (mf6internal: icheck)
952 call get_isize('ICHECK', this%input_mempath, isize)
953 if (isize > 0) then
954 this%icheck = 0
955 write (this%iout, '(4x,a)') &
956 'REACH GEOMETRY AND PARAMETER CHECKS WILL NOT BE MADE'
957 end if
958 !
959 ! -- DEV_NO_FINAL_CHECK (mf6internal: iconvchk)
960 call get_isize('ICONVCHK', this%input_mempath, isize)
961 if (isize > 0) then
962 this%iconvchk = 0
963 write (this%iout, '(4x,a)') &
964 'A FINAL CONVERGENCE CHECK OF THE CHANGE IN STREAM FLOW ROUTING '// &
965 'STAGES AND FLOWS WILL NOT BE MADE'
966 end if
967 !
968 write (this%iout, '(1x,a)') &
969 'END OF '//trim(adjustl(this%text))//' OPTIONS'
970 end subroutine sfr_source_options
971
972 !> @brief Source DIMENSIONS block from input context and load static data
973 !<
974 subroutine sfr_source_dimensions(this)
975 ! -- modules
977 ! -- dummy
978 class(sfrtype), intent(inout) :: this !< SfrType object
979 ! -- local
980 logical(LGP) :: found
981 !
982 ! -- initialize dimensions to 0
983 this%maxbound = 0
984 !
985 write (this%iout, '(/1x,a)') &
986 'PROCESSING '//trim(adjustl(this%text))//' DIMENSIONS'
987 !
988 ! -- source NREACHES
989 call mem_set_value(this%maxbound, 'MAXBOUND', this%input_mempath, found, &
990 release=.false.)
991 if (found) then
992 write (this%iout, '(4x,a,i0)') 'NREACHES = ', this%maxbound
993 end if
994 !
995 write (this%iout, '(1x,a)') &
996 'END OF '//trim(adjustl(this%text))//' DIMENSIONS'
997 !
998 if (this%maxbound < 1) then
999 write (errmsg, '(a)') &
1000 'NREACHES was not specified or was specified incorrectly.'
1001 call store_error(errmsg)
1002 call store_error_filename(this%input_fname)
1003 end if
1004 !
1005 ! -- set npakeq (SFR adds no extra equations)
1006 this%npakeq = 0
1007 !
1008 ! -- define the default label
1009 call this%define_listlabel()
1010 !
1011 ! -- define default cross-section data size
1012 this%ncrossptstot = this%maxbound
1013 !
1014 ! -- allocate arrays
1015 call this%sfr_allocate_arrays()
1016 !
1017 ! -- source packagedata
1018 call this%sfr_source_packagedata()
1019 !
1020 ! -- source crosssections
1021 call this%sfr_source_crosssections()
1022 !
1023 ! -- source connectiondata
1024 call this%sfr_source_connectiondata()
1025 !
1026 ! -- source diversions
1027 call this%sfr_source_diversions()
1028 !
1029 ! -- alias deprecated variable names
1030 call this%sfr_checkin_deprecated_names()
1031 !
1032 ! -- source initialstages
1033 call this%sfr_source_initialstages()
1034 !
1035 ! -- setup the budget object
1036 call this%sfr_setup_budobj()
1037 !
1038 ! -- setup the stage table object
1039 call this%sfr_setup_tableobj()
1040 end subroutine sfr_source_dimensions
1041
1042 !> @brief Source PACKAGEDATA block from input context
1043 !<
1044 subroutine sfr_source_packagedata(this)
1045 ! -- modules
1048 ! -- dummy
1049 class(sfrtype), intent(inout) :: this !< SfrType object
1050 ! -- local
1051 integer(I4B) :: i, n, nconzero
1052 integer(I4B) :: ipos
1053 character(len=10) :: cnum
1054 character(len=LENBOUNDNAME) :: bndName
1055 character(len=LINELENGTH) :: cellid_str
1056 integer(I4B), allocatable :: nboundchk(:)
1057 integer(I4B), dimension(:), pointer, contiguous :: ifno => null()
1058 integer(I4B), dimension(:, :), pointer, contiguous :: cellid => null()
1059 real(DP), dimension(:), pointer, contiguous :: rlen => null()
1060 real(DP), dimension(:), pointer, contiguous :: rwid => null()
1061 real(DP), dimension(:), pointer, contiguous :: rgrd => null()
1062 real(DP), dimension(:), pointer, contiguous :: rtp => null()
1063 real(DP), dimension(:), pointer, contiguous :: rbth => null()
1064 integer(I4B), dimension(:), pointer, contiguous :: ncon => null()
1065 integer(I4B), dimension(:), pointer, contiguous :: ndv => null()
1066 type(characterstringtype), dimension(:), pointer, contiguous :: &
1067 boundname => null()
1068 integer(I4B), dimension(:, :), pointer, contiguous :: tslink => null()
1069 type(characterstringtype), dimension(:), pointer, contiguous :: &
1070 tslinkvars => null()
1071 !
1072 write (this%iout, '(/1x,a)') &
1073 'PROCESSING '//trim(adjustl(this%text))//' PACKAGEDATA'
1074 !
1075 ! -- get input context PACKAGEDATA column arrays
1076 call mem_setptr(ifno, 'PACKAGEDATA_IFNO', this%input_mempath)
1077 call mem_setptr(cellid, 'CELLID', this%input_mempath)
1078 call mem_setptr(rlen, 'RLEN', this%input_mempath)
1079 call mem_setptr(rwid, 'RWID', this%input_mempath)
1080 call mem_setptr(rgrd, 'RGRD', this%input_mempath)
1081 call mem_setptr(rtp, 'RTP', this%input_mempath)
1082 call mem_setptr(rbth, 'RBTH', this%input_mempath)
1083 call mem_setptr(this%input%rhk, 'RHK', this%input_mempath)
1084 call mem_setptr(this%input%man, 'MAN', this%input_mempath)
1085 call mem_setptr(ncon, 'NCON', this%input_mempath)
1086 call mem_setptr(this%input%ustrf, 'USTRF', this%input_mempath)
1087 call mem_setptr(tslink, 'TSLINK_PD', this%input_mempath)
1088 call mem_setptr(tslinkvars, 'TSLINKVARS_PD', this%input_mempath)
1089 do n = 1, size(tslinkvars)
1090 if (tslinkvars(n) == 'RHK') this%input%rhk_tslink => tslink(n, :)
1091 if (tslinkvars(n) == 'MAN') this%input%man_tslink => tslink(n, :)
1092 if (tslinkvars(n) == 'USTRF') this%input%ustrf_tslink => tslink(n, :)
1093 end do
1094 if (.not. (associated(this%input%rhk_tslink) .and. &
1095 associated(this%input%man_tslink) .and. &
1096 associated(this%input%ustrf_tslink))) then
1097 call store_error('Time series links for RHK, MAN and USTRF not found &
1098 &in input.')
1099 call store_error_filename(this%input_fname)
1100 end if
1101 call mem_setptr(ndv, 'NDV', this%input_mempath)
1102 if (this%inamedbound /= 0) then
1103 call mem_setptr(boundname, 'BOUNDNAME', this%input_mempath)
1104 end if
1105 !
1106 ! -- allocate check array
1107 allocate (nboundchk(this%maxbound))
1108 nboundchk = 0
1109 nconzero = 0
1110 !
1111 ! -- populate reach data from input context arrays
1112 do i = 1, this%maxbound
1113 n = ifno(i)
1114 !
1115 n = this%validate_ifno(n, this%maxbound, nboundchk, &
1116 'rno', 'PACKAGEDATA')
1117 if (n == 0) cycle
1118 !
1119 ! -- cellid → igwfnode: convert integer cellid array to string
1120 ! -- all-zero or negative cellid means unconnected reach (NONE keyword or 0 0 0)
1121 if (all(cellid(1:this%dis%ndim, i) <= 0)) then
1122 this%igwfnode(n) = 0
1123 else
1124 write (cellid_str, '(10(i0,1x))') cellid(1:this%dis%ndim, i)
1125 this%igwfnode(n) = this%dis%noder_from_cellid(cellid_str, &
1126 this%inunit, this%iout, &
1127 flag_string=.false., &
1128 allow_zero=.true.)
1129 end if
1130 this%igwftopnode(n) = this%igwfnode(n)
1131 if (this%igwfnode(n) < 1) this%ianynone = this%ianynone + 1
1132 !
1133 ! -- scalar reach properties
1134 this%length(n) = rlen(i)
1135 this%width(n) = rwid(i)
1136 this%slope(n) = rgrd(i)
1137 this%strtop(n) = rtp(i)
1138 this%bthick(n) = rbth(i)
1139 !
1140 ! -- ncon and nconn
1141 this%nconnreach(n) = ncon(i)
1142 this%nconn = this%nconn + ncon(i)
1143 if (ncon(i) < 0) then
1144 write (errmsg, '(a,1x,i0,1x,a,i0,a)') &
1145 'NCON for reach', n, &
1146 'must be greater than or equal to 0 (', ncon(i), ').'
1147 call store_error(errmsg)
1148 else if (ncon(i) == 0) then
1149 nconzero = nconzero + 1
1150 end if
1151 !
1152 ! -- ndv (diversions)
1153 this%ndiv(n) = ndv(i)
1154 if (ndv(i) > 0) this%idiversions = 1
1155 !
1156 ! -- bound name
1157 write (cnum, '(i10.10)') n
1158 bndname = 'Reach'//cnum
1159 if (this%inamedbound /= 0) then
1160 bndname = boundname(i)
1161 end if
1162 this%sfrname(n) = bndname
1163 !
1164 ! -- hk, roughness (Manning), upstream fraction: copied from
1165 ! input context; sfr_ad re-syncs TS-linked values each timestep
1166 this%hk(n) = this%input%rhk(i)
1167 this%rough(n) = this%input%man(i)
1168 this%ustrf(n) = this%input%ustrf(i)
1169 !
1170 ! -- initialize sstage to reach top
1171 this%sstage(n) = this%strtop(n)
1172 end do
1173 !
1174 write (this%iout, '(1x,a)') &
1175 'END OF '//trim(adjustl(this%text))//' PACKAGEDATA'
1176 !
1177 ! -- check every reach is specified exactly once
1178 call this%report_ifno_coverage(nboundchk, this%maxbound, 'reach', &
1179 'PACKAGEDATA')
1180 deallocate (nboundchk)
1181 !
1182 if (nconzero > 0) then
1183 write (warnmsg, '(a,1x,a,1x,a,1x,i0,1x,a)') &
1184 'SFR Package', trim(this%packName), &
1185 'has', nconzero, 'reach(es) with zero connections.'
1187 end if
1188 !
1189 if (count_errors() > 0) then
1190 call store_error_filename(this%input_fname)
1191 end if
1192 !
1193 ! -- initialize default cross-section data
1194 ipos = 1
1195 this%iacross(1) = ipos
1196 do i = 1, this%maxbound
1197 this%ncrosspts(i) = 1
1198 this%station(ipos) = this%width(i)
1199 this%xsheight(ipos) = dzero
1200 this%xsrough(ipos) = done
1201 ipos = ipos + 1
1202 this%iacross(i + 1) = ipos
1203 end do
1204 !
1205 ! -- release input context packagedata memory; PACKAGEDATA_IFNO excluded
1206 ! (allocate_featureauxvar); RHK/MAN/USTRF excluded
1207 call memorystore_release('CELLID', this%input_mempath)
1208 call memorystore_release('RLEN', this%input_mempath)
1209 call memorystore_release('RWID', this%input_mempath)
1210 call memorystore_release('RGRD', this%input_mempath)
1211 call memorystore_release('RTP', this%input_mempath)
1212 call memorystore_release('RBTH', this%input_mempath)
1213 call memorystore_release('NCON', this%input_mempath)
1214 call memorystore_release('NDV', this%input_mempath)
1215 call memorystore_release('BOUNDNAME', this%input_mempath)
1216 end subroutine sfr_source_packagedata
1217
1218 !> @brief Source CROSSSECTIONS block from input context
1219 !<
1220 subroutine sfr_source_crosssections(this)
1221 ! -- modules
1222 use constantsmodule, only: lenmempath
1226 ! -- dummy
1227 class(sfrtype), intent(inout) :: this !< SfrType object
1228 ! -- local
1229 integer(I4B), dimension(:), pointer, contiguous :: ifno => null()
1230 type(characterstringtype), dimension(:), pointer, contiguous :: &
1231 tab6_filename => null()
1232 type(characterstringtype), dimension(:), pointer, contiguous :: &
1233 sfrtab6_mempaths => null()
1234 type(sfrcrosssection), pointer :: cross_data => null()
1235 integer(I4B) :: i, n, ncrossptstot
1236 integer(I4B), allocatable :: nboundchk(:)
1237 integer(I4B) :: isize
1238 character(len=LINELENGTH) :: tabfname
1239 character(len=LENMEMPATH) :: mempath
1240 !
1241 ! -- check if CROSSSECTIONS block was loaded (optional block)
1242 call get_isize('CROSSSECT_IFNO', this%input_mempath, isize)
1243 if (isize < 1) return
1244 !
1245 write (this%iout, '(/1x,a)') &
1246 'PROCESSING '//trim(adjustl(this%text))//' CROSSSECTIONS'
1247 !
1248 ! -- get input context arrays
1249 call mem_setptr(ifno, 'CROSSSECT_IFNO', this%input_mempath)
1250 call mem_setptr(tab6_filename, 'SFRTAB6_FILENAME', this%input_mempath)
1251 call mem_setptr(sfrtab6_mempaths, 'SFRTAB6_MEMPATH', this%input_mempath)
1252 !
1253 ! -- create cross-section object
1254 call cross_section_cr(cross_data, this%iout, this%iprpak, this%maxbound)
1255 call cross_data%initialize(this%ncrossptstot, this%ncrosspts, &
1256 this%iacross, this%station, this%xsheight, &
1257 this%xsrough)
1258 !
1259 allocate (nboundchk(this%maxbound))
1260 nboundchk = 0
1261 !
1262 do i = 1, isize
1263 n = this%validate_ifno(ifno(i), this%maxbound, nboundchk, &
1264 'reach', 'CROSSSECTIONS')
1265 if (n == 0) cycle
1266 tabfname = tab6_filename(i)
1267 mempath = sfrtab6_mempaths(i)
1268 call cross_data%source_table(n, this%width(n), mempath, &
1269 trim(adjustl(tabfname)))
1270 end do
1271 !
1272 write (this%iout, '(1x,a)') &
1273 'END OF '//trim(adjustl(this%text))//' CROSSSECTIONS'
1274 !
1275 ! -- CROSSSECTIONS is optional; only duplicates are reported
1276 call this%report_ifno_coverage(nboundchk, this%maxbound, 'reach', &
1277 'CROSSSECTIONS', check_missing=.false.)
1278 deallocate (nboundchk)
1279 !
1280 if (count_errors() > 0) then
1281 call store_error_filename(this%input_fname)
1282 end if
1283 !
1284 ! -- reallocate cross-section arrays if needed
1285 ncrossptstot = cross_data%get_ncrossptstot()
1286 if (ncrossptstot /= this%ncrossptstot) then
1287 this%ncrossptstot = ncrossptstot
1288 call mem_reallocate(this%station, this%ncrossptstot, 'STATION', &
1289 this%memoryPath)
1290 call mem_reallocate(this%xsheight, this%ncrossptstot, 'XSHEIGHT', &
1291 this%memoryPath)
1292 call mem_reallocate(this%xsrough, this%ncrossptstot, 'XSROUGH', &
1293 this%memoryPath)
1294 end if
1295 !
1296 call cross_data%output(this%width, this%rough)
1297 call cross_data%pack(this%ncrossptstot, this%ncrosspts, this%iacross, &
1298 this%station, this%xsheight, this%xsrough)
1299 call cross_data%destroy()
1300 deallocate (cross_data)
1301 nullify (cross_data)
1302 !
1303 ! -- release input context crosssections memory
1304 call memorystore_release('CROSSSECT_IFNO', this%input_mempath)
1305 call memorystore_release('SFRTAB6_FILENAME', this%input_mempath)
1306 end subroutine sfr_source_crosssections
1307
1308 !> @brief Source CONNECTIONDATA block from input context
1309 !<
1310 subroutine sfr_source_connectiondata(this)
1311 ! -- modules
1313 use sparsemodule, only: sparsematrix
1314 ! -- dummy
1315 class(sfrtype), intent(inout) :: this !< SfrType object
1316 ! -- local
1317 integer(I4B), dimension(:), pointer, contiguous :: cd_ifno => null()
1318 integer(I4B), dimension(:), pointer, contiguous :: ic_flat => null()
1319 integer(I4B), dimension(:), pointer, contiguous :: cd_ia => null()
1320 type(sparsematrix), pointer :: sparse => null()
1321 integer(I4B), dimension(:), pointer, contiguous :: rowmaxnnz => null()
1322 integer(I4B), allocatable :: nboundchk(:)
1323 integer(I4B), allocatable :: iconndata(:, :)
1324 integer(I4B), allocatable :: iup(:)
1325 integer(I4B), allocatable :: order(:)
1326 type(dag) :: sfr_dag
1327 integer(I4B) :: i, n, j, jj, jcol, jcol2, nja, nconnmax
1328 integer(I4B) :: ival, idir, nup, ipos, istat, ierr, jlocal, nread
1329 !
1330 write (this%iout, '(/1x,a)') &
1331 'PROCESSING '//trim(adjustl(this%text))//' CONNECTIONDATA'
1332 !
1333 ! -- get input context CONNECTIONDATA arrays
1334 call mem_setptr(cd_ifno, 'CONNDATA_IFNO', this%input_mempath)
1335 call mem_setptr(ic_flat, 'IC', this%input_mempath)
1336 call mem_setptr(cd_ia, 'IC_IA', this%input_mempath)
1337 !
1338 ! -- allocate and initialize check array
1339 allocate (nboundchk(this%maxbound))
1340 nboundchk = 0
1341 !
1342 ! -- build rowmaxnnz from nconnreach
1343 nja = 0
1344 nconnmax = 0
1345 allocate (rowmaxnnz(this%maxbound))
1346 do n = 1, this%maxbound
1347 ival = this%nconnreach(n)
1348 if (ival < 0) ival = 0
1349 rowmaxnnz(n) = ival + 1
1350 nja = nja + ival + 1
1351 if (ival > nconnmax) nconnmax = ival
1352 end do
1353 !
1354 ! -- reallocate connection arrays
1355 call mem_reallocate(this%ja, nja, 'JA', this%memoryPath)
1356 call mem_reallocate(this%idir, nja, 'IDIR', this%memoryPath)
1357 call mem_reallocate(this%idiv, nja, 'IDIV', this%memoryPath)
1358 call mem_reallocate(this%qconn, nja, 'QCONN', this%memoryPath)
1359 this%idir = 0
1360 this%idiv = 0
1361 this%qconn = dzero
1362 !
1363 ! -- allocate iconndata
1364 allocate (iconndata(nconnmax, this%maxbound))
1365 iconndata = 0
1366 !
1367 allocate (sparse)
1368 call sparse%init(this%maxbound, this%maxbound, rowmaxnnz)
1369 !
1370 ! -- process connection data rows
1371 do i = 1, this%maxbound
1372 n = this%validate_ifno(cd_ifno(i), this%maxbound, nboundchk, &
1373 'reach', 'CONNECTIONDATA')
1374 if (n == 0) cycle
1375 nread = cd_ia(i + 1) - cd_ia(i)
1376 if (nread /= this%nconnreach(n)) then
1377 write (errmsg, '(a,1x,i0,1x,a,1x,i0,1x,a,1x,i0,a)') &
1378 'Reach', n, 'connectiondata specifies', nread, &
1379 'connections but NCON for this reach in packagedata is', &
1380 this%nconnreach(n), '.'
1381 call store_error(errmsg)
1382 cycle
1383 end if
1384 call sparse%addconnection(n, n, 1)
1385 jlocal = 0
1386 do j = cd_ia(i), cd_ia(i + 1) - 1
1387 jlocal = jlocal + 1
1388 ival = ic_flat(j)
1389 iconndata(jlocal, n) = ival
1390 if (ival < 0) then
1391 idir = -1
1392 ival = abs(ival)
1393 else if (ival == 0) then
1394 call store_error('Missing or zero connection reach in connectiondata.')
1395 cycle
1396 else
1397 idir = 1
1398 end if
1399 if (ival > this%maxbound) then
1400 call store_error('Reach number exceeds NREACHES in connectiondata.')
1401 cycle
1402 end if
1403 call sparse%addconnection(n, ival, 1)
1404 end do
1405 end do
1406 !
1407 write (this%iout, '(1x,a)') &
1408 'END OF '//trim(adjustl(this%text))//' CONNECTIONDATA'
1409 !
1410 call this%report_ifno_coverage(nboundchk, this%maxbound, 'reach', &
1411 'CONNECTIONDATA')
1412 !
1413 if (count_errors() > 0) then
1414 call store_error_filename(this%input_fname)
1415 end if
1416 !
1417 ! -- fill ia and ja from sparse
1418 call sparse%filliaja(this%ia, this%ja, ierr, sort=.true.)
1419 if (ierr /= 0) then
1420 write (errmsg, '(a,3(1x,a))') &
1421 'Could not fill', trim(this%packName), &
1422 'package IA and JA connection data.', &
1423 'Check connectivity data in connectiondata block.'
1424 call store_error(errmsg)
1425 end if
1426 !
1427 ! -- fill flat connection storage with direction
1428 do n = 1, this%maxbound
1429 do j = this%ia(n) + 1, this%ia(n + 1) - 1
1430 jcol = this%ja(j)
1431 do jj = 1, this%nconnreach(n)
1432 jcol2 = iconndata(jj, n)
1433 if (abs(jcol2) == jcol) then
1434 idir = 1
1435 if (jcol2 < 0) idir = -1
1436 this%idir(j) = idir
1437 exit
1438 end if
1439 end do
1440 end do
1441 end do
1442 !
1443 ! -- deallocate temporaries
1444 deallocate (rowmaxnnz)
1445 deallocate (nboundchk)
1446 deallocate (iconndata)
1447 call sparse%destroy()
1448 deallocate (sparse)
1449 !
1450 ! -- compute reach order using DAG
1451 call sfr_dag%set_vertices(this%maxbound)
1452 fill_dag: do n = 1, this%maxbound
1453 nup = 0
1454 do j = this%ia(n) + 1, this%ia(n + 1) - 1
1455 if (this%idir(j) > 0) nup = nup + 1
1456 end do
1457 if (nup == 0) cycle fill_dag
1458 allocate (iup(nup))
1459 ipos = 1
1460 do j = this%ia(n) + 1, this%ia(n + 1) - 1
1461 if (this%idir(j) > 0) then
1462 iup(ipos) = this%ja(j)
1463 ipos = ipos + 1
1464 end if
1465 end do
1466 call sfr_dag%set_edges(n, iup)
1467 deallocate (iup)
1468 end do fill_dag
1469 call sfr_dag%toposort(order, istat)
1470 if (istat == -1) then
1471 write (warnmsg, '(a)') &
1472 trim(adjustl(this%text))//' PACKAGE ('// &
1473 trim(adjustl(this%packName))//') cannot calculate a '// &
1474 'Directed Asyclic Graph for reach connectivity because '// &
1475 'of circular dependency. Using the reach number for '// &
1476 'solution ordering.'
1478 end if
1479 do n = 1, this%maxbound
1480 if (istat == 0) then
1481 this%isfrorder(n) = order(n)
1482 else
1483 this%isfrorder(n) = n
1484 end if
1485 end do
1486 call sfr_dag%destroy()
1487 if (istat == 0) deallocate (order)
1488 !
1489 ! -- release input context connectiondata memory
1490 call memorystore_release('CONNDATA_IFNO', this%input_mempath)
1491 call memorystore_release('IC', this%input_mempath)
1492 call memorystore_release('IC_IA', this%input_mempath)
1493 end subroutine sfr_source_connectiondata
1494
1495 !> @brief Source DIVERSIONS block from input context
1496 !<
1497 subroutine sfr_source_diversions(this)
1498 ! -- modules
1501 ! -- dummy
1502 class(sfrtype), intent(inout) :: this !< SfrType object
1503 ! -- local
1504 integer(I4B), dimension(:), pointer, contiguous :: d_ifno => null()
1505 integer(I4B), dimension(:), pointer, contiguous :: d_idv => null()
1506 integer(I4B), dimension(:), pointer, contiguous :: d_iconr => null()
1507 type(characterstringtype), dimension(:), pointer, contiguous :: &
1508 d_cprior => null()
1509 integer(I4B) :: i, n, idiv, ndiversions, i0, ipos, jpos
1510 integer(I4B) :: isize
1511 integer(I4B), allocatable :: iachk(:), nboundchk(:)
1512 character(len=16) :: cval
1513 !
1514 ! -- build iadiv and count total diversions
1515 ndiversions = 0
1516 i0 = 1
1517 this%iadiv(1) = i0
1518 do n = 1, this%maxbound
1519 ndiversions = ndiversions + this%ndiv(n)
1520 i0 = i0 + this%ndiv(n)
1521 this%iadiv(n + 1) = i0
1522 end do
1523 !
1524 ! -- reallocate diversion arrays
1525 if (ndiversions > 0) then
1526 call mem_reallocate(this%divreach, ndiversions, 'DIVREACH', &
1527 this%memoryPath)
1528 allocate (this%divcprior(ndiversions))
1529 call mem_setptr(this%divflow, 'DIVFLOW', this%input_mempath)
1530 call mem_reallocate(this%divq, ndiversions, 'DIVQ', this%memoryPath)
1531 this%divq = dzero
1532 end if
1533 !
1534 ! -- check if DIVERSIONS block was loaded (optional block)
1535 call get_isize('DIVERSIONS_IFNO', this%input_mempath, isize)
1536 if (isize < 1) then
1537 if (this%idiversions /= 0) then
1538 call store_error('REQUIRED DIVERSIONS BLOCK NOT FOUND.')
1539 call store_error_filename(this%input_fname)
1540 end if
1541 return
1542 end if
1543 !
1544 if (this%idiversions == 0) then
1545 write (errmsg, '(a,1x,a)') &
1546 'A diversions block should not be', &
1547 'specified if diversions are not specified.'
1548 call store_error(errmsg)
1549 call store_error_filename(this%input_fname)
1550 return
1551 end if
1552 !
1553 write (this%iout, '(/1x,a)') &
1554 'PROCESSING '//trim(adjustl(this%text))//' DIVERSIONS'
1555 !
1556 ! -- get input context arrays
1557 call mem_setptr(d_ifno, 'DIVERSIONS_IFNO', this%input_mempath)
1558 call mem_setptr(d_idv, 'DIVERSIONS_IDV', this%input_mempath)
1559 call mem_setptr(d_iconr, 'ICONR', this%input_mempath)
1560 call mem_setptr(d_cprior, 'CPRIOR', this%input_mempath)
1561 !
1562 ! -- build check arrays
1563 allocate (iachk(this%maxbound + 1))
1564 allocate (nboundchk(ndiversions))
1565 nboundchk = 0
1566 iachk(1) = 1
1567 do n = 1, this%maxbound
1568 iachk(n + 1) = iachk(n) + this%ndiv(n)
1569 end do
1570 !
1571 do i = 1, isize
1572 n = d_ifno(i)
1573 if (n < 1 .or. n > this%maxbound) then
1574 write (errmsg, '(a,i0,a)') 'Reach number should be between 1 and ', &
1575 this%maxbound, '.'
1576 call store_error(errmsg)
1577 cycle
1578 end if
1579 if (this%ndiv(n) < 1) then
1580 write (errmsg, '(a,i0)') &
1581 'Diversions cannot be specified for reach ', n
1582 call store_error(errmsg)
1583 cycle
1584 end if
1585 idiv = d_idv(i)
1586 if (idiv < 1 .or. idiv > this%ndiv(n)) then
1587 write (errmsg, '(a,i0,a,i0,a)') &
1588 'Reach ', n, ' diversion number should be between 1 and ', &
1589 this%ndiv(n), '.'
1590 call store_error(errmsg)
1591 cycle
1592 end if
1593 ipos = iachk(n) + idiv - 1
1594 nboundchk(ipos) = nboundchk(ipos) + 1
1595 jpos = this%iadiv(n) + idiv - 1
1596 if (d_iconr(i) < 1 .or. d_iconr(i) > this%maxbound) then
1597 write (errmsg, '(a,i0,a)') &
1598 'Diversion target reach number should be between 1 and ', &
1599 this%maxbound, '.'
1600 call store_error(errmsg)
1601 cycle
1602 end if
1603 this%divreach(jpos) = d_iconr(i)
1604 cval = d_cprior(i)
1605 select case (trim(cval))
1606 case ('UPTO', 'THRESHOLD', 'FRACTION', 'EXCESS')
1607 case default
1608 errmsg = 'Invalid cprior type '//trim(cval)//'.'
1609 call store_error(errmsg)
1610 end select
1611 this%divcprior(jpos) = trim(cval)
1612 end do
1613 !
1614 write (this%iout, '(1x,a)') &
1615 'END OF '//trim(adjustl(this%text))//' DIVERSIONS'
1616 !
1617 do n = 1, this%maxbound
1618 do idiv = 1, this%ndiv(n)
1619 ipos = iachk(n) + idiv - 1
1620 if (nboundchk(ipos) == 0) then
1621 write (errmsg, '(a,1x,i0,1x,a,1x,i0)') &
1622 'No data specified for reach', n, 'diversion', idiv
1623 call store_error(errmsg)
1624 else if (nboundchk(ipos) > 1) then
1625 write (errmsg, '(a,1x,i0,1x,a,1x,i0,1x,a,1x,i0,1x,a)') &
1626 'Data for reach', n, 'diversion', idiv, &
1627 'specified', nboundchk(ipos), 'times'
1628 call store_error(errmsg)
1629 end if
1630 end do
1631 end do
1632 deallocate (iachk)
1633 deallocate (nboundchk)
1634 !
1635 if (count_errors() > 0) then
1636 call store_error_filename(this%input_fname)
1637 end if
1638 !
1639 ! -- release input context diversions memory; DIVFLOW excluded
1640 call memorystore_release('DIVERSIONS_IFNO', this%input_mempath)
1641 call memorystore_release('DIVERSIONS_IDV', this%input_mempath)
1642 call memorystore_release('ICONR', this%input_mempath)
1643 call memorystore_release('CPRIOR', this%input_mempath)
1644 end subroutine sfr_source_diversions
1645
1646 !> @brief Source INITIALSTAGES block from input context
1647 !<
1648 subroutine sfr_source_initialstages(this)
1649 ! -- modules
1651 ! -- dummy
1652 class(sfrtype), intent(inout) :: this !< SfrType object
1653 ! -- local
1654 integer(I4B), dimension(:), pointer, contiguous :: is_ifno => null()
1655 real(DP), dimension(:), pointer, contiguous :: is_stage => null()
1656 integer(I4B) :: i, n
1657 integer(I4B) :: isize
1658 integer(I4B), allocatable :: nboundchk(:)
1659 real(DP) :: rval
1660 !
1661 ! -- check if INITIALSTAGES block was loaded (optional block)
1662 call get_isize('INITSTAGE_IFNO', this%input_mempath, isize)
1663 if (isize < 1) then
1664 ! -- set default initial stage to reach top if STORAGE active
1665 if (this%istorage == 1) then
1666 do n = 1, this%maxbound
1667 this%stage(n) = this%strtop(n)
1668 end do
1669 end if
1670 return
1671 end if
1672 !
1673 write (this%iout, '(/1x,a)') &
1674 'PROCESSING '//trim(adjustl(this%text))//' INITIALSTAGES'
1675 !
1676 call mem_setptr(is_ifno, 'INITSTAGE_IFNO', this%input_mempath)
1677 call mem_setptr(is_stage, 'INITIALSTAGE', this%input_mempath)
1678 !
1679 allocate (nboundchk(this%maxbound))
1680 nboundchk = 0
1681 !
1682 do i = 1, isize
1683 n = this%validate_ifno(is_ifno(i), this%maxbound, nboundchk, &
1684 'reach', 'INITIALSTAGES')
1685 if (n == 0) cycle
1686 rval = is_stage(i)
1687 this%stage(n) = rval
1688 this%depth(n) = rval - this%strtop(n)
1689 if (rval < this%strtop(n)) then
1690 write (errmsg, '(a,g0,a,1x,i0,1x,a,g0,a)') &
1691 'Initial stage (', rval, ') for reach', n, &
1692 'is less than the reach top (', this%strtop(n), ').'
1693 call store_error(errmsg)
1694 end if
1695 end do
1696 !
1697 write (this%iout, '(1x,a)') &
1698 'END OF '//trim(adjustl(this%text))//' INITIALSTAGES'
1699 !
1700 call this%report_ifno_coverage(nboundchk, this%maxbound, 'reach', &
1701 'INITIALSTAGES')
1702 deallocate (nboundchk)
1703 !
1704 if (count_errors() > 0) then
1705 call store_error_filename(this%input_fname)
1706 end if
1707 !
1708 ! -- release input context initialstages memory
1709 call memorystore_release('INITSTAGE_IFNO', this%input_mempath)
1710 call memorystore_release('INITIALSTAGE', this%input_mempath)
1711 end subroutine sfr_source_initialstages
1712
1713 !> @brief Allocate and read method for package
1714 !!
1715 !! Method to read and prepare period data for the SFR package.
1716 !<
1717 subroutine sfr_ar(this)
1718 ! -- modules
1719 use tdismodule, only: inats
1720 ! -- dummy
1721 class(sfrtype), intent(inout) :: this !< SfrType object
1722 ! -- local
1723 integer(I4B) :: n
1724 integer(I4B) :: ierr
1725 !
1726 ! -- allocate and read observations
1727 call this%obs%obs_ar()
1728 !
1729 ! -- allocate BndType connection-level arrays (nodelist, bound, auxvar, etc.)
1730 call this%BndExtType%allocate_arrays()
1731 !
1732 ! -- allocate featureauxvar and set pkg_ifno/pkg_auxvar input context
1733 ! pointers
1734 call this%BndExtType%allocate_featureauxvar()
1735 !
1736 ! -- set persistent PERIOD pointers into input context (valid for
1737 ! simulation lifetime)
1738 call this%input%init(this%input_mempath, this%naux)
1739 !
1740 ! -- set boundname for each connection
1741 if (this%inamedbound /= 0) then
1742 do n = 1, this%maxbound
1743 this%boundname(n) = this%sfrname(n)
1744 end do
1745 end if
1746 !
1747 ! -- copy boundname into boundname_cst
1748 call this%copy_boundname()
1749 !
1750 ! -- copy igwfnode into nodelist
1751 do n = 1, this%maxbound
1752 this%nodelist(n) = this%igwfnode(n)
1753 end do
1754 !
1755 ! -- check the sfr unit conversion data
1756 call this%sfr_check_conversion()
1757 !
1758 ! -- check the storage_weight
1759 call this%sfr_check_storage_weight()
1760 !
1761 ! -- check that ATS_COURANT is only used with STORAGE
1762 if (this%ats_courant /= dnodata .and. this%istorage /= 1) then
1763 write (errmsg, '(a)') &
1764 'ATS_COURANT OPTION REQUIRES STORAGE OPTION TO BE ACTIVE'
1765 call store_error(errmsg)
1766 end if
1767 !
1768 ! -- warn when ATS_COURANT is specified but ATS is not active in TDIS
1769 if (this%ats_courant /= dnodata .and. inats == 0) then
1770 write (warnmsg, '(a)') &
1771 'ATS_COURANT IS SPECIFIED IN THE SFR OPTIONS BLOCK BUT THE '// &
1772 'ATS PACKAGE IS NOT ACTIVE IN TDIS, SO THE TIME STEP IS NOT '// &
1773 'ADAPTED TO THE COURANT NUMBER. IF THE COURANT NUMBER EXCEEDS 1 '// &
1774 'THE EXPLICIT KINEMATIC-WAVE ROUTING MAY OSCILLATE WHILE STILL '// &
1775 'CLOSING THE BUDGET. ACTIVATE THE ATS PACKAGE OR USE A SMALLER '// &
1776 'TIME STEP.'
1778 end if
1779 !
1780 ! -- pre-compute TVD upstream connectivity when ATS_COURANT is active
1781 if (this%ats_courant /= dnodata .and. this%istorage == 1) then
1782 call this%sfr_precompute_tvd()
1783 end if
1784 !
1785 ! -- check the sfr reach data
1786 call this%sfr_check_reaches()
1787
1788 ! -- check the connection data
1789 call this%sfr_check_connections()
1790
1791 ! -- check the diversion data
1792 if (this%idiversions /= 0) then
1793 call this%sfr_check_diversions()
1794 end if
1795
1796 ! -- check the diversion data
1797 if (this%istorage == 1) then
1798 call this%sfr_check_initialstages()
1799 end if
1800 !
1801 ! -- terminate if errors were detected in any of the static sfr data
1802 ierr = count_errors()
1803 if (ierr > 0) then
1804 call store_error_filename(this%input_fname)
1805 end if
1806 !
1807 ! -- setup pakmvrobj
1808 if (this%imover /= 0) then
1809 allocate (this%pakmvrobj)
1810 call this%pakmvrobj%ar(this%maxbound, this%maxbound, this%memoryPath)
1811 end if
1812 end subroutine sfr_ar
1813
1814 !> @brief Read and prepare period data for package
1815 !!
1816 !! Method to read and prepare period data for the SFR package.
1817 !<
1818 subroutine sfr_rp(this)
1819 ! -- modules
1820 use constantsmodule, only: lenvarname
1821 use tdismodule, only: kper
1824 ! -- dummy
1825 class(sfrtype), intent(inout) :: this !< SfrType object
1826 ! -- local
1827 character(len=LINELENGTH) :: crossfile
1828 character(len=LINELENGTH) :: str
1829 real(DP) :: auxvaldbl
1830 character(len=LINELENGTH) :: title
1831 character(len=LINELENGTH) :: text
1832 character(len=LENVARNAME) :: setting
1833 character(len=10) :: cnum
1834 character(len=10) :: cp
1835 integer(I4B) :: n
1836 integer(I4B) :: i
1837 integer(I4B) :: ii
1838 integer(I4B) :: jj
1839 integer(I4B) :: idiv
1840 integer(I4B) :: ichkustrm
1841 integer(I4B) :: ncrossptstot
1842 type(sfrcrosssection), pointer :: cross_data => null()
1843 ! -- formats
1844 character(len=*), parameter :: fmtlsp = &
1845 &"(1X,/1X,'REUSING ',A,'S FROM LAST STRESS PERIOD')"
1846 !
1847 ! -- initialize flags
1848 ichkustrm = 0
1849 if (kper == 1) then
1850 ichkustrm = 1
1851 end if
1852 !
1853 ! -- set nbound to maxbound
1854 this%nbound = this%maxbound
1855 !
1856 ! -- check if input context has been updated for this stress period
1857 if (this%iper == kper) then
1858 !
1859 ! -- create and initialize cross-section data
1860 call cross_section_cr(cross_data, this%iout, this%iprpak, this%maxbound)
1861 call cross_data%initialize(this%ncrossptstot, this%ncrosspts, &
1862 this%iacross, &
1863 this%station, this%xsheight, &
1864 this%xsrough)
1865 !
1866 ! -- setup table to echo period data
1867 if (this%iprpak /= 0) then
1868 title = trim(adjustl(this%text))//' PACKAGE ('// &
1869 trim(adjustl(this%packName))//') DATA FOR PERIOD'
1870 write (title, '(a,1x,i6)') trim(adjustl(title)), kper
1871 call table_cr(this%inputtab, this%packName, title)
1872 call this%inputtab%table_df(1, 4, this%iout, finalize=.false.)
1873 text = 'NUMBER'
1874 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
1875 text = 'KEYWORD'
1876 call this%inputtab%initialize_column(text, 20, alignment=tableft)
1877 do jj = 1, 2
1878 write (text, '(a,1x,i6)') 'VALUE', jj
1879 call this%inputtab%initialize_column(text, 15, alignment=tabcenter)
1880 end do
1881 end if
1882 !
1883 ! -- process each period data entry
1884 do i = 1, this%input%nbound
1885 n = this%input%ifno(i)
1886 if (n < 1 .or. n > this%maxbound) then
1887 write (errmsg, '(a,1x,a,1x,i0,a)') &
1888 'Reach number (RNO) must be greater than 0 and', &
1889 'less than or equal to', this%maxbound, '.'
1890 call store_error(errmsg)
1891 cycle
1892 end if
1893 !
1894 ! -- dispatch key for this row
1895 setting = this%input%setting(i)
1896 !
1897 ! -- STATUS
1898 if (trim(setting) == 'STATUS') then
1899 str = this%input%status(i)
1900 ichkustrm = 1
1901 if (str == 'INACTIVE') then
1902 this%iboundpak(n) = 0
1903 else if (str == 'ACTIVE') then
1904 this%iboundpak(n) = 1
1905 else if (str == 'SIMPLE') then
1906 this%iboundpak(n) = -1
1907 else
1908 write (errmsg, '(2a)') &
1909 'Unknown '//trim(this%text)//' sfr status keyword: ', trim(str)
1910 call store_error(errmsg)
1911 end if
1912 end if
1913 !
1914 ! -- BEDK, MANNING, STAGE, INFLOW, RAINFALL, EVAPORATION, RUNOFF,
1915 ! UPSTREAM_FRAC; sfr_ad re-syncs these each timestep if TS-linked
1916 call this%sfr_set_period_value(i, n, setting)
1917 if (trim(setting) == 'UPSTREAM_FRAC') ichkustrm = 1
1918 !
1919 ! -- DIVERSION (compound group)
1920 if (trim(setting) == 'DIVERSION') then
1921 if (this%ndiv(n) < 1) then
1922 write (cnum, '(i0)') n
1923 errmsg = 'diversions cannot be specified for reach '//trim(cnum)
1924 call store_error(errmsg)
1925 else
1926 idiv = this%input%idv(i)
1927 if (idiv < 1 .or. idiv > this%ndiv(n)) then
1928 write (cnum, '(i0)') n
1929 errmsg = 'Reach '//trim(cnum)
1930 write (cnum, '(i0)') this%ndiv(n)
1931 errmsg = trim(errmsg)//' diversion number should be between 1 '// &
1932 'and '//trim(cnum)//'.'
1933 call store_error(errmsg)
1934 else
1935 ii = this%iadiv(n) + idiv - 1
1936 ! -- if cprior is 'FRACTION', check 0.0 <= divflow <= 1.0
1937 cp = this%divcprior(ii)
1938 if (cp == 'FRACTION' .and. &
1939 (this%divflow(ii) < dzero .or. this%divflow(ii) > done)) then
1940 write (errmsg, '(a,1x,i0,a)') &
1941 'cprior is type FRACTION for diversion no.', ii, &
1942 ', but divflow not within the range 0.0 to 1.0'
1943 call store_error(errmsg)
1944 end if
1945 end if
1946 end if
1947 end if
1948 !
1949 ! -- CROSS_SECTION (compound group)
1950 if (trim(setting) == 'CROSS_SECTION') then
1951 crossfile = this%input%tab6_filename(i)
1952 call cross_data%read_table(n, this%width(n), trim(adjustl(crossfile)))
1953 end if
1954 !
1955 ! -- AUXILIARY (compound group): featureauxvar already holds the
1956 ! -- current value; only extract auxname for echoing this row
1957 if (this%naux > 0) then
1958 if (trim(setting) == 'PERIOD_AUXILIARY') then
1959 str = this%input%auxname(i)
1960 auxvaldbl = this%input%auxval(i)
1961 end if
1962 end if
1963 !
1964 ! -- echo row to period data table
1965 if (this%iprpak /= 0) then
1966 call this%inputtab%add_term(n)
1967 if (trim(setting) == 'PERIOD_AUXILIARY') then
1968 call this%inputtab%add_term('AUXILIARY')
1969 else
1970 call this%inputtab%add_term(trim(setting))
1971 end if
1972 select case (trim(setting))
1973 case ('STATUS')
1974 call this%inputtab%add_term(trim(str))
1975 call this%inputtab%add_term(' ')
1976 case ('BEDK')
1977 call this%inputtab%add_term(this%hk(n))
1978 call this%inputtab%add_term(' ')
1979 case ('MANNING')
1980 call this%inputtab%add_term(this%rough(n))
1981 call this%inputtab%add_term(' ')
1982 case ('STAGE')
1983 call this%inputtab%add_term(this%sstage(n))
1984 call this%inputtab%add_term(' ')
1985 case ('INFLOW')
1986 call this%inputtab%add_term(this%inflow(n))
1987 call this%inputtab%add_term(' ')
1988 case ('RAINFALL')
1989 call this%inputtab%add_term(this%rain(n))
1990 call this%inputtab%add_term(' ')
1991 case ('EVAPORATION')
1992 call this%inputtab%add_term(this%evap(n))
1993 call this%inputtab%add_term(' ')
1994 case ('RUNOFF')
1995 call this%inputtab%add_term(this%runoff(n))
1996 call this%inputtab%add_term(' ')
1997 case ('UPSTREAM_FRAC')
1998 call this%inputtab%add_term(this%ustrf(n))
1999 call this%inputtab%add_term(' ')
2000 case ('DIVERSION')
2001 call this%inputtab%add_term(idiv)
2002 call this%inputtab%add_term(this%divflow(ii))
2003 case ('CROSS_SECTION')
2004 call this%inputtab%add_term(trim(crossfile))
2005 call this%inputtab%add_term(' ')
2006 case ('PERIOD_AUXILIARY')
2007 call this%inputtab%add_term(trim(str))
2008 call this%inputtab%add_term(auxvaldbl)
2009 case default
2010 call this%inputtab%add_term(' ')
2011 call this%inputtab%add_term(' ')
2012 end select
2013 end if
2014 end do
2015 if (this%iprpak /= 0) then
2016 call this%inputtab%finalize_table()
2017 end if
2018 !
2019 ! -- determine the current size of cross-section data
2020 ncrossptstot = cross_data%get_ncrossptstot()
2021 !
2022 ! -- reallocate sfr package cross-section data if size changed
2023 if (ncrossptstot /= this%ncrossptstot) then
2024 this%ncrossptstot = ncrossptstot
2025 call mem_reallocate(this%station, this%ncrossptstot, 'STATION', &
2026 this%memoryPath)
2027 call mem_reallocate(this%xsheight, this%ncrossptstot, 'XSHEIGHT', &
2028 this%memoryPath)
2029 call mem_reallocate(this%xsrough, this%ncrossptstot, 'XSROUGH', &
2030 this%memoryPath)
2031 end if
2032 !
2033 ! -- write cross-section data to the model listing file
2034 call cross_data%output(this%width, this%rough, kstp=1, kper=kper)
2035 !
2036 ! -- pack cross-section data
2037 call cross_data%pack(this%ncrossptstot, this%ncrosspts, &
2038 this%iacross, &
2039 this%station, &
2040 this%xsheight, &
2041 this%xsrough)
2042 !
2043 ! -- deallocate temporary local storage for reach cross-sections
2044 call cross_data%destroy()
2045 deallocate (cross_data)
2046 nullify (cross_data)
2047 else
2048 write (this%iout, fmtlsp) trim(this%filtyp)
2049 end if
2050 !
2051 ! -- check upstream fraction values every period; ftotnd must be
2052 ! initialized for sfr_update_flows even when there is no period data
2053 if (ichkustrm /= 0) then
2054 call this%sfr_check_ustrf()
2055 end if
2056 !
2057 ! -- write summary of package block error messages
2058 if (count_errors() > 0) then
2059 call store_error_filename(this%input_fname)
2060 end if
2061 end subroutine sfr_rp
2062
2063 !> @brief Advance the package
2064 !!
2065 !! Advance data in the SFR package. The method sets advances
2066 !! time series, time array series, and observation data.
2067 !<
2068 subroutine sfr_ad(this)
2069 ! -- modules
2070 use constantsmodule, only: lenvarname
2072 ! -- dummy
2073 class(sfrtype) :: this !< SfrType object
2074 ! -- local
2075 integer(I4B) :: n
2076 integer(I4B) :: i
2077 integer(I4B) :: ii
2078 integer(I4B) :: idiv
2079 integer(I4B) :: iaux
2080 character(len=LENVARNAME) :: setting
2081
2082 ! -- sync PACKAGEDATA AUX TS and advance observations;
2083 ! -- step auxvar period block overrides
2084 call this%BndExtType%bnd_ad()
2085 !
2086 ! -- update previous values, unless this time step is repeated, when the
2087 ! values are those the failed attempt ended with
2088 if (this%istorage == 1 .and. ifailedstepretry == 0) then
2089 do n = 1, this%maxbound
2090 this%stageold(n) = this%stage(n)
2091 this%usinflowold(n) = this%usinflow(n)
2092 this%dsflowold(n) = this%dsflow(n)
2093 this%xsausold(n) = this%xsaus(n)
2094 this%xsadsold(n) = this%xsads(n)
2095 end do
2096 end if
2097 !
2098 ! -- sync PACKAGEDATA and PERIOD TS fields from input context each
2099 ! timestep; skipped when no TS6 files are configured. PACKAGEDATA
2100 ! values are synced only for rows linked to a time series
2101 if (this%ts_active) then
2102 do i = 1, this%maxbound
2103 n = this%pkg_ifno(i)
2104 if (.not. this%bedk_set(n) .and. &
2105 this%input%rhk_tslink(i) /= 0) &
2106 this%hk(n) = this%input%rhk(i)
2107 if (.not. this%manning_set(n) .and. &
2108 this%input%man_tslink(i) /= 0) &
2109 this%rough(n) = this%input%man(i)
2110 if (.not. this%ustrf_set(n) .and. &
2111 this%input%ustrf_tslink(i) /= 0) &
2112 this%ustrf(n) = this%input%ustrf(i)
2113 end do
2114 !
2115 if (this%input%nbound > 0) then
2116 do i = 1, this%input%nbound
2117 n = this%input%ifno(i)
2118 if (n < 1 .or. n > this%maxbound) cycle
2119 ! -- BEDK, MANNING, UPSTREAM_FRAC, STAGE, INFLOW, RAINFALL, EVAPORATION, RUNOFF
2120 setting = this%input%setting(i)
2121 call this%sfr_set_period_value(i, n, setting)
2122 ! -- DIVFLOW
2123 if (trim(setting) == 'DIVERSION') then
2124 if (this%ndiv(n) >= 1) then
2125 idiv = this%input%idv(i)
2126 if (idiv >= 1 .and. idiv <= this%ndiv(n)) then
2127 ii = this%iadiv(n) + idiv - 1
2128 end if
2129 end if
2130 end if
2131 end do
2132 end if
2133 end if
2134 !
2135 ! -- check upstream fractions (only needed when USTRF may be TS-updated;
2136 ! sfr_rp already validates ustrf once per period via ichkustrm)
2137 if (this%ts_active) call this%sfr_check_ustrf()
2138 !
2139 ! -- update auxiliary variables by copying from the derived-type time
2140 ! series variable into the bndpackage auxvar variable so that this
2141 ! information is properly written to the GWF budget file
2142 if (this%naux > 0) then
2143 do n = 1, this%maxbound
2144 do iaux = 1, this%naux
2145 if (this%noupdateauxvar(iaux) /= 0) cycle
2146 this%auxvar(iaux, n) = this%featureauxvar(iaux, n)
2147 end do
2148 end do
2149 end if
2150 !
2151 ! -- reset upstream flow to zero and set specified stage
2152 do n = 1, this%maxbound
2153 this%usflow(n) = dzero
2154 if (this%iboundpak(n) < 0) then
2155 this%stage(n) = this%sstage(n)
2156 end if
2157 end do
2158 !
2159 ! -- pakmvrobj ad
2160 if (this%imover == 1) then
2161 call this%pakmvrobj%ad()
2162 end if
2163 end subroutine sfr_ad
2164
2165 !> @brief Formulate the package hcof and rhs terms.
2166 !!
2167 !! Formulate the hcof and rhs terms for the WEL package that will be
2168 !! added to the coefficient matrix and right-hand side vector.
2169 !<
2170 subroutine sfr_cf(this)
2171 ! -- dummy
2172 class(sfrtype) :: this !< SfrType object
2173 ! -- local
2174 integer(I4B) :: n
2175 integer(I4B) :: igwfnode
2176 !
2177 ! -- return if no sfr reaches
2178 if (this%nbound == 0) return
2179 !
2180 ! -- find highest active cell
2181 do n = 1, this%nbound
2182 igwfnode = this%igwftopnode(n)
2183 if (igwfnode > 0) then
2184 if (this%ibound(igwfnode) == 0) then
2185 call this%dis%highest_active(igwfnode, this%ibound)
2186 end if
2187 end if
2188 this%igwfnode(n) = igwfnode
2189 this%nodelist(n) = igwfnode
2190 end do
2191 end subroutine sfr_cf
2192
2193 !> @brief Copy hcof and rhs terms into solution.
2194 !!
2195 !! Add the hcof and rhs terms for the SFR package to the
2196 !! coefficient matrix and right-hand side vector.
2197 !<
2198 subroutine sfr_fc(this, rhs, ia, idxglo, matrix_sln)
2199 ! -- dummy
2200 class(sfrtype) :: this !< SfrType object
2201 real(DP), dimension(:), intent(inout) :: rhs !< right-hand side vector for model
2202 integer(I4B), dimension(:), intent(in) :: ia !< solution CRS row pointers
2203 integer(I4B), dimension(:), intent(in) :: idxglo !< mapping vector for model (local) to solution (global)
2204 class(matrixbasetype), pointer :: matrix_sln !< solution coefficient matrix
2205 ! -- local
2206 integer(I4B) :: i
2207 integer(I4B) :: j
2208 integer(I4B) :: n
2209 integer(I4B) :: ipos
2210 integer(I4B) :: node
2211 real(DP) :: s0
2212 real(DP) :: ds
2213 real(DP) :: dsmax
2214 real(DP) :: hgwf
2215 real(DP) :: v
2216 real(DP) :: hhcof
2217 real(DP) :: rrhs
2218 !
2219 ! -- picard iterations for sfr to achieve good solution regardless
2220 ! of reach order
2221 sfrpicard: do i = 1, this%maxsfrpicard
2222 !
2223 ! -- initialize maximum stage change for iteration to zero
2224 dsmax = dzero
2225 !
2226 ! -- pakmvrobj fc - reset qformvr to zero
2227 if (this%imover == 1) then
2228 call this%pakmvrobj%fc()
2229 end if
2230 !
2231 ! -- solve for each sfr reach
2232 reachsolve: do j = 1, this%nbound
2233 n = this%isfrorder(j)
2234 node = this%igwfnode(n)
2235 if (node > 0) then
2236 hgwf = this%xnew(node)
2237 else
2238 hgwf = dep20
2239 end if
2240 !
2241 ! -- save previous stage and upstream flow
2242 if (i == 1) then
2243 this%stage0(n) = this%stage(n)
2244 this%usflow0(n) = this%usflow(n)
2245 end if
2246 !
2247 ! -- set initial stage to calculate stage change
2248 s0 = this%stage(n)
2249 !
2250 ! -- solve for flow in swr
2251 if (this%iboundpak(n) /= 0) then
2252 call this%sfr_solve(n, hgwf, hhcof, rrhs)
2253 else
2254 this%depth(n) = dzero
2255 this%stage(n) = this%strtop(n)
2256 v = dzero
2257 call this%sfr_update_flows(n, v, v)
2258 if (this%istorage == 1) then
2259 this%usinflow(n) = dzero
2260 this%storage(n) = dzero
2261 end if
2262 hhcof = dzero
2263 rrhs = dzero
2264 end if
2265 !
2266 ! -- set package hcof and rhs
2267 this%hcof(n) = hhcof
2268 this%rhs(n) = rrhs
2269 !
2270 ! -- calculate stage change
2271 ds = s0 - this%stage(n)
2272 !
2273 ! -- evaluate if stage change exceeds dsmax
2274 if (abs(ds) > abs(dsmax)) then
2275 dsmax = ds
2276 end if
2277
2278 end do reachsolve
2279 !
2280 ! -- evaluate if the sfr picard iterations should be terminated
2281 if (abs(dsmax) <= this%dmaxchg) then
2282 exit sfrpicard
2283 end if
2284
2285 end do sfrpicard
2286 !
2287 ! -- Copy package rhs and hcof into solution rhs and amat
2288 do n = 1, this%nbound
2289 node = this%nodelist(n)
2290 if (node < 1) cycle
2291 rhs(node) = rhs(node) + this%rhs(n)
2292 ipos = ia(node)
2293 call matrix_sln%add_value_pos(idxglo(ipos), this%hcof(n))
2294 end do
2295 end subroutine sfr_fc
2296
2297 !> @brief Add Newton-Raphson terms for package into solution.
2298 !!
2299 !! Calculate and add the Newton-Raphson terms for the SFR package to the
2300 !! coefficient matrix and right-hand side vector.
2301 !<
2302 subroutine sfr_fn(this, rhs, ia, idxglo, matrix_sln)
2303 ! -- dummy
2304 class(sfrtype) :: this !< SfrType object
2305 real(DP), dimension(:), intent(inout) :: rhs !< right-hand side vector for model
2306 integer(I4B), dimension(:), intent(in) :: ia !< solution CRS row pointers
2307 integer(I4B), dimension(:), intent(in) :: idxglo !< mapping vector for model (local) to solution (global)
2308 class(matrixbasetype), pointer :: matrix_sln !< solution coefficient matrix
2309 ! -- local
2310 integer(I4B) :: i
2311 integer(I4B) :: j
2312 integer(I4B) :: n
2313 integer(I4B) :: ipos
2314 real(DP) :: rterm
2315 real(DP) :: drterm
2316 real(DP) :: rhs1
2317 real(DP) :: hcof1
2318 real(DP) :: q1
2319 real(DP) :: q2
2320 real(DP) :: hgwf
2321 real(DP) :: storage
2322 !
2323 storage = dzero
2324 !
2325 ! -- Copy package rhs and hcof into solution rhs and amat
2326 do j = 1, this%nbound
2327 i = this%isfrorder(j)
2328 ! -- skip inactive reaches
2329 if (this%iboundpak(i) < 1) cycle
2330 ! -- skip if reach is not connected to gwf
2331 n = this%nodelist(i)
2332 if (n < 1) cycle
2333 ipos = ia(n)
2334 rterm = this%hcof(i) * this%xnew(n)
2335 ! -- calculate perturbed head
2336 hgwf = this%xnew(n) + dem4
2337 ! -- keep the storage term of the unperturbed head for the budget
2338 if (this%istorage == 1) storage = this%storage(i)
2339 call this%sfr_solve(i, hgwf, hcof1, rhs1, update=.false.)
2340 if (this%istorage == 1) this%storage(i) = storage
2341 q1 = rhs1 - hcof1 * hgwf
2342 ! -- calculate unperturbed head
2343 q2 = this%rhs(i) - this%hcof(i) * this%xnew(n)
2344 ! -- calculate derivative
2345 drterm = (q2 - q1) / dem4
2346 ! -- add terms to convert conductance formulation into
2347 ! newton-raphson formulation
2348 call matrix_sln%add_value_pos(idxglo(ipos), drterm - this%hcof(i))
2349 rhs(n) = rhs(n) - rterm + drterm * this%xnew(n)
2350 end do
2351 end subroutine sfr_fn
2352
2353 !> @brief Convergence check for package.
2354 !!
2355 !! Perform additional convergence checks on the flow between the SFR package
2356 !! and the model it is attached to.
2357 !<
2358 subroutine sfr_cc(this, innertot, kiter, iend, icnvgmod, cpak, ipak, dpak)
2359 ! -- modules
2360 use tdismodule, only: totim, kstp, kper, delt
2361 ! -- dummy
2362 class(sfrtype), intent(inout) :: this !< SfrType object
2363 integer(I4B), intent(in) :: innertot !< total number of inner iterations
2364 integer(I4B), intent(in) :: kiter !< Picard iteration number
2365 integer(I4B), intent(in) :: iend !< flag indicating if this is the last Picard iteration
2366 integer(I4B), intent(in) :: icnvgmod !< flag inficating if the model has met specific convergence criteria
2367 character(len=LENPAKLOC), intent(inout) :: cpak !< string for user node
2368 integer(I4B), intent(inout) :: ipak !< location of the maximum dependent variable change
2369 real(DP), intent(inout) :: dpak !< maximum dependent variable change
2370 ! -- local
2371 character(len=LENPAKLOC) :: cloc
2372 character(len=LINELENGTH) :: tag
2373 integer(I4B) :: icheck
2374 integer(I4B) :: ipakfail
2375 integer(I4B) :: locdhmax
2376 integer(I4B) :: locrmax
2377 integer(I4B) :: locdqfrommvrmax
2378 integer(I4B) :: ntabrows
2379 integer(I4B) :: ntabcols
2380 integer(I4B) :: n
2381 real(DP) :: q
2382 real(DP) :: q0
2383 real(DP) :: qtolfact
2384 real(DP) :: dh
2385 real(DP) :: r
2386 real(DP) :: dhmax
2387 real(DP) :: rmax
2388 real(DP) :: dqfrommvr
2389 real(DP) :: dqfrommvrmax
2390 !
2391 ! -- initialize local variables
2392 icheck = this%iconvchk
2393 ipakfail = 0
2394 locdhmax = 0
2395 locrmax = 0
2396 r = dzero
2397 dhmax = dzero
2398 rmax = dzero
2399 locdqfrommvrmax = 0
2400 dqfrommvrmax = dzero
2401 !
2402 ! -- if not saving package convergence data on check convergence if
2403 ! the model is considered converged
2404 if (this%ipakcsv == 0) then
2405 if (icnvgmod == 0) then
2406 icheck = 0
2407 end if
2408 !
2409 ! -- saving package convergence data
2410 else
2411 !
2412 ! -- header for package csv
2413 if (.not. associated(this%pakcsvtab)) then
2414 !
2415 ! -- determine the number of columns and rows
2416 ntabrows = 1
2417 ntabcols = 9
2418 if (this%imover == 1) then
2419 ntabcols = ntabcols + 2
2420 end if
2421 !
2422 ! -- setup table
2423 call table_cr(this%pakcsvtab, this%packName, '')
2424 call this%pakcsvtab%table_df(ntabrows, ntabcols, this%ipakcsv, &
2425 lineseparator=.false., separator=',', &
2426 finalize=.false.)
2427 !
2428 ! -- add columns to package csv
2429 tag = 'total_inner_iterations'
2430 call this%pakcsvtab%initialize_column(tag, 10, alignment=tableft)
2431 tag = 'totim'
2432 call this%pakcsvtab%initialize_column(tag, 10, alignment=tableft)
2433 tag = 'kper'
2434 call this%pakcsvtab%initialize_column(tag, 10, alignment=tableft)
2435 tag = 'kstp'
2436 call this%pakcsvtab%initialize_column(tag, 10, alignment=tableft)
2437 tag = 'nouter'
2438 call this%pakcsvtab%initialize_column(tag, 10, alignment=tableft)
2439 tag = 'dvmax'
2440 call this%pakcsvtab%initialize_column(tag, 15, alignment=tableft)
2441 tag = 'dvmax_loc'
2442 call this%pakcsvtab%initialize_column(tag, 15, alignment=tableft)
2443 tag = 'dinflowmax'
2444 call this%pakcsvtab%initialize_column(tag, 15, alignment=tableft)
2445 tag = 'dinflowmax_loc'
2446 call this%pakcsvtab%initialize_column(tag, 15, alignment=tableft)
2447 if (this%imover == 1) then
2448 tag = 'dqfrommvrmax'
2449 call this%pakcsvtab%initialize_column(tag, 15, alignment=tableft)
2450 tag = 'dqfrommvrmax_loc'
2451 call this%pakcsvtab%initialize_column(tag, 16, alignment=tableft)
2452 end if
2453 end if
2454 end if
2455 !
2456 ! -- perform package convergence check
2457 if (icheck /= 0) then
2458 final_check: do n = 1, this%maxbound
2459 if (this%iboundpak(n) == 0) cycle
2460 !
2461 ! -- set the Q to length factor
2462 qtolfact = delt / this%calc_surface_area(n)
2463 !
2464 ! -- calculate stage change
2465 dh = this%stage0(n) - this%stage(n)
2466 !
2467 ! -- evaluate flow difference if the time step is transient
2468 if (this%gwfiss == 0) then
2469 r = this%usflow0(n) - this%usflow(n)
2470 !
2471 ! -- normalize flow difference and convert to a depth
2472 r = r * qtolfact
2473 end if
2474 !
2475 ! -- q from mvr
2476 dqfrommvr = dzero
2477 if (this%imover == 1) then
2478 q = this%pakmvrobj%get_qfrommvr(n)
2479 q0 = this%pakmvrobj%get_qfrommvr0(n)
2480 dqfrommvr = qtolfact * (q0 - q)
2481 end if
2482 !
2483 ! -- evaluate magnitude of differences
2484 if (n == 1) then
2485 locdhmax = n
2486 dhmax = dh
2487 locrmax = n
2488 rmax = r
2489 dqfrommvrmax = dqfrommvr
2490 locdqfrommvrmax = n
2491 else
2492 if (abs(dh) > abs(dhmax)) then
2493 locdhmax = n
2494 dhmax = dh
2495 end if
2496 if (abs(r) > abs(rmax)) then
2497 locrmax = n
2498 rmax = r
2499 end if
2500 if (abs(dqfrommvr) > abs(dqfrommvrmax)) then
2501 dqfrommvrmax = dqfrommvr
2502 locdqfrommvrmax = n
2503 end if
2504 end if
2505 end do final_check
2506 !
2507 ! -- set dpak and cpak
2508 if (abs(dhmax) > abs(dpak)) then
2509 ipak = locdhmax
2510 dpak = dhmax
2511 write (cloc, "(a,'-',a)") trim(this%packName), 'stage'
2512 cpak = trim(cloc)
2513 end if
2514 if (abs(rmax) > abs(dpak)) then
2515 ipak = locrmax
2516 dpak = rmax
2517 write (cloc, "(a,'-',a)") trim(this%packName), 'inflow'
2518 cpak = trim(cloc)
2519 end if
2520 if (this%imover == 1) then
2521 if (abs(dqfrommvrmax) > abs(dpak)) then
2522 ipak = locdqfrommvrmax
2523 dpak = dqfrommvrmax
2524 write (cloc, "(a,'-',a)") trim(this%packName), 'qfrommvr'
2525 cpak = trim(cloc)
2526 end if
2527 end if
2528 !
2529 ! -- write convergence data to package csv
2530 if (this%ipakcsv /= 0) then
2531 !
2532 ! -- write the data
2533 call this%pakcsvtab%add_term(innertot)
2534 call this%pakcsvtab%add_term(totim)
2535 call this%pakcsvtab%add_term(kper)
2536 call this%pakcsvtab%add_term(kstp)
2537 call this%pakcsvtab%add_term(kiter)
2538 call this%pakcsvtab%add_term(dhmax)
2539 call this%pakcsvtab%add_term(locdhmax)
2540 call this%pakcsvtab%add_term(rmax)
2541 call this%pakcsvtab%add_term(locrmax)
2542 if (this%imover == 1) then
2543 call this%pakcsvtab%add_term(dqfrommvrmax)
2544 call this%pakcsvtab%add_term(locdqfrommvrmax)
2545 end if
2546 !
2547 ! -- finalize the package csv
2548 if (iend == 1) then
2549 call this%pakcsvtab%finalize_table()
2550 end if
2551 end if
2552 end if
2553 end subroutine sfr_cc
2554
2555 !> @brief Calculate package flows.
2556 !!
2557 !! Calculate the flow between connected SFR package control volumes.
2558 !<
2559 subroutine sfr_cq(this, x, flowja, iadv)
2560 ! -- modules
2561 use budgetmodule, only: budgettype
2562 ! -- dummy
2563 class(sfrtype), intent(inout) :: this !< SfrType object
2564 real(DP), dimension(:), intent(in) :: x !< current dependent-variable value
2565 real(DP), dimension(:), contiguous, intent(inout) :: flowja !< flow between two connected control volumes
2566 integer(I4B), optional, intent(in) :: iadv !< flag that indicates if this is an advance package
2567 ! -- local
2568 integer(I4B) :: i
2569 real(DP) :: qext
2570 ! -- for budget
2571 integer(I4B) :: n
2572 integer(I4B) :: n2
2573 real(DP) :: qoutflow
2574 real(DP) :: qfrommvr
2575 real(DP) :: qtomvr
2576 real(DP) :: d
2577 !
2578 ! -- call base functionality in bnd_cq. This will calculate sfr-gwf flows
2579 ! and put them into this%simvals
2580 call this%BndType%bnd_cq(x, flowja, iadv=1)
2581 !
2582 ! -- save the wetted areas at the end of the solve with the geometry of
2583 ! this time step, so a change in geometry before the next time step
2584 ! does not change the water stored in the reach
2585 if (this%istorage == 1) then
2586 do n = 1, this%maxbound
2587 call this%sfr_calc_reach_depth(n, this%usinflow(n), d)
2588 this%xsaus(n) = this%calc_area_wet(n, d)
2589 call this%sfr_calc_reach_depth(n, this%dsflow(n), d)
2590 this%xsads(n) = this%calc_area_wet(n, d)
2591 end do
2592 end if
2593 !
2594 ! -- Calculate qextoutflow and qoutflow for subsequent budgets
2595 do n = 1, this%maxbound
2596 !
2597 ! -- mover
2598 qfrommvr = dzero
2599 qtomvr = dzero
2600 if (this%imover == 1) then
2601 qfrommvr = this%pakmvrobj%get_qfrommvr(n)
2602 qtomvr = this%pakmvrobj%get_qtomvr(n)
2603 if (qtomvr > dzero) then
2604 qtomvr = -qtomvr
2605 end if
2606 end if
2607 !
2608 ! -- external downstream stream flow
2609 qext = this%dsflow(n)
2610 qoutflow = dzero
2611 if (qext > dzero) then
2612 qext = -qext
2613 end if
2614 do i = this%ia(n) + 1, this%ia(n + 1) - 1
2615 if (this%idir(i) > 0) cycle
2616 n2 = this%ja(i)
2617 if (this%iboundpak(n2) == 0) cycle
2618 qext = dzero
2619 exit
2620 end do
2621 !
2622 ! -- adjust external downstream stream flow using qtomvr
2623 if (qext < dzero) then
2624 if (qtomvr < dzero) then
2625 qext = qext - qtomvr
2626 end if
2627 else
2628 qoutflow = this%dsflow(n)
2629 if (qoutflow > dzero) then
2630 qoutflow = -qoutflow
2631 end if
2632 end if
2633 !
2634 ! -- set qextoutflow and qoutflow for cell by cell budget
2635 ! output and observations
2636 this%qextoutflow(n) = qext
2637 this%qoutflow(n) = qoutflow
2638 !
2639 end do
2640 !
2641 ! -- fill the budget object
2642 call this%sfr_fill_budobj()
2643 end subroutine sfr_cq
2644
2645 !> @brief Output package flow terms.
2646 !!
2647 !! Output SFR package flow terms.
2648 !<
2649 subroutine sfr_ot_package_flows(this, icbcfl, ibudfl)
2650 ! -- modules
2651 use tdismodule, only: kstp, kper, delt, pertim, totim
2652 ! -- dummy
2653 class(sfrtype) :: this !< SfrType object
2654 integer(I4B), intent(in) :: icbcfl !< flag and unit number for cell-by-cell output
2655 integer(I4B), intent(in) :: ibudfl !< flag indication if cell-by-cell data should be saved
2656 ! -- local
2657 integer(I4B) :: ibinun
2658 character(len=20), dimension(:), allocatable :: cellidstr
2659 integer(I4B) :: n
2660 integer(I4B) :: node
2661 !
2662 ! -- write the flows from the budobj
2663 ibinun = 0
2664 if (this%ibudgetout /= 0) then
2665 ibinun = this%ibudgetout
2666 end if
2667 if (icbcfl == 0) ibinun = 0
2668 if (ibinun > 0) then
2669 call this%budobj%save_flows(this%dis, ibinun, kstp, kper, delt, &
2670 pertim, totim, this%iout)
2671 end if
2672 !
2673 ! -- Print sfr flows table
2674 if (ibudfl /= 0 .and. this%iprflow /= 0) then
2675 !
2676 ! -- If there are any 'none' gwf connections then need to calculate
2677 ! a vector of cellids and pass that in to the budget flow table because
2678 ! the table assumes that there are maxbound gwf entries, which is not
2679 ! the case if any 'none's are specified.
2680 if (this%ianynone > 0) then
2681 allocate (cellidstr(this%maxbound))
2682 do n = 1, this%maxbound
2683 node = this%igwfnode(n)
2684 if (node > 0) then
2685 call this%dis%noder_to_string(node, cellidstr(n))
2686 else
2687 cellidstr(n) = 'NONE'
2688 end if
2689 end do
2690 call this%budobj%write_flowtable(this%dis, kstp, kper, cellidstr)
2691 deallocate (cellidstr)
2692 else
2693 call this%budobj%write_flowtable(this%dis, kstp, kper)
2694 end if
2695 end if
2696 end subroutine sfr_ot_package_flows
2697
2698 !> @brief Output package dependent-variable terms.
2699 !!
2700 !! Output SFR boundary package dependent-variable terms.
2701 !<
2702 subroutine sfr_ot_dv(this, idvsave, idvprint)
2703 ! -- modules
2704 use tdismodule, only: kstp, kper, pertim, totim
2705 use inputoutputmodule, only: ulasav
2706 ! -- dummy
2707 class(sfrtype) :: this !< SfrType object
2708 integer(I4B), intent(in) :: idvsave !< flag and unit number for dependent-variable output
2709 integer(I4B), intent(in) :: idvprint !< flag indicating if dependent-variable should be written to the model listing file
2710 ! -- local
2711 character(len=20) :: cellid
2712 integer(I4B) :: ibinun
2713 integer(I4B) :: n
2714 integer(I4B) :: node
2715 real(DP) :: d
2716 real(DP) :: v
2717 real(DP) :: hgwf
2718 real(DP) :: sbot
2719 real(DP) :: depth
2720 real(DP) :: stage
2721 real(DP) :: w
2722 real(DP) :: cond
2723 real(DP) :: grad
2724 !
2725 ! -- set unit number for binary dependent variable output
2726 ibinun = 0
2727 if (this%istageout /= 0) then
2728 ibinun = this%istageout
2729 end if
2730 if (idvsave == 0) ibinun = 0
2731 !
2732 ! -- write sfr binary output
2733 if (ibinun > 0) then
2734 do n = 1, this%maxbound
2735 d = this%depth(n)
2736 v = this%stage(n)
2737 if (this%iboundpak(n) == 0) then
2738 v = dhnoflo
2739 else if (d == dzero) then
2740 v = dhdry
2741 end if
2742 this%dbuff(n) = v
2743 end do
2744 call ulasav(this%dbuff, ' STAGE', kstp, kper, pertim, totim, &
2745 this%maxbound, 1, 1, ibinun)
2746 end if
2747 !
2748 ! -- print sfr stage and depth table
2749 if (idvprint /= 0 .and. this%iprhed /= 0) then
2750 !
2751 ! -- set table kstp and kper
2752 call this%stagetab%set_kstpkper(kstp, kper)
2753 !
2754 ! -- fill stage data
2755 do n = 1, this%maxbound
2756 node = this%igwfnode(n)
2757 if (node > 0) then
2758 call this%dis%noder_to_string(node, cellid)
2759 hgwf = this%xnew(node)
2760 else
2761 cellid = 'NONE'
2762 end if
2763 if (this%inamedbound == 1) then
2764 call this%stagetab%add_term(this%boundname(n))
2765 end if
2766 call this%stagetab%add_term(n)
2767 call this%stagetab%add_term(cellid)
2768 if (this%iboundpak(n) /= 0) then
2769 depth = this%depth(n)
2770 stage = this%stage(n)
2771 w = this%calc_top_width_wet(n, depth)
2772 call this%sfr_calc_cond(n, depth, cond, stage, hgwf)
2773 else
2774 depth = dhnoflo
2775 stage = dhnoflo
2776 w = dhnoflo
2777 cond = dhnoflo
2778 end if
2779 if (depth == dzero) then
2780 call this%stagetab%add_term(dhdry)
2781 else
2782 call this%stagetab%add_term(stage)
2783 end if
2784 call this%stagetab%add_term(depth)
2785 call this%stagetab%add_term(w)
2786 if (node > 0) then
2787 if (this%iboundpak(n) /= 0) then
2788 sbot = this%strtop(n) - this%bthick(n)
2789 if (hgwf < sbot) then
2790 grad = stage - sbot
2791 else
2792 grad = stage - hgwf
2793 end if
2794 grad = grad / this%bthick(n)
2795 else
2796 grad = dhnoflo
2797 end if
2798 call this%stagetab%add_term(hgwf)
2799 call this%stagetab%add_term(cond)
2800 call this%stagetab%add_term(grad)
2801 else
2802 call this%stagetab%add_term('--')
2803 call this%stagetab%add_term('--')
2804 call this%stagetab%add_term('--')
2805 end if
2806 end do
2807 end if
2808 end subroutine sfr_ot_dv
2809
2810 !> @brief Output advanced package budget summary.
2811 !!
2812 !! Output SFR package budget summary.
2813 !<
2814 subroutine sfr_ot_bdsummary(this, kstp, kper, iout, ibudfl)
2815 ! -- module
2816 use tdismodule, only: totim, delt
2817 ! -- dummy
2818 class(sfrtype) :: this !< SfrType object
2819 integer(I4B), intent(in) :: kstp !< time step number
2820 integer(I4B), intent(in) :: kper !< period number
2821 integer(I4B), intent(in) :: iout !< flag and unit number for the model listing file
2822 integer(I4B), intent(in) :: ibudfl !< flag indicating budget should be written
2823 !
2824 call this%budobj%write_budtable(kstp, kper, iout, ibudfl, totim, delt)
2825 end subroutine sfr_ot_bdsummary
2826
2827 !> @brief Write the Courant-number summary table to the listing file
2828 !<
2829 subroutine sfr_fp(this)
2830 ! -- dummy
2831 class(sfrtype) :: this !< SfrType object
2832 ! -- local
2833 integer(I4B) :: n
2834 real(DP) :: crmean
2835 !
2836 if (this%istorage == 1) then
2837 do n = 1, this%maxbound
2838 if (this%inamedbound == 1) then
2839 call this%couranttab%add_term(this%boundname(n))
2840 end if
2841 call this%couranttab%add_term(n)
2842 if (this%crmin(n) == dep20) then
2843 call this%couranttab%add_term('--')
2844 else
2845 call this%couranttab%add_term(this%crmin(n))
2846 end if
2847 if (this%crmax(n) < dzero) then
2848 call this%couranttab%add_term('--')
2849 else
2850 call this%couranttab%add_term(this%crmax(n))
2851 end if
2852 if (this%crcnt(n) > 0) then
2853 crmean = this%crsum(n) / real(this%crcnt(n), dp)
2854 call this%couranttab%add_term(crmean)
2855 else
2856 call this%couranttab%add_term('--')
2857 end if
2858 end do
2859 end if
2860 end subroutine sfr_fp
2861
2862 !> @brief Submit the ATS time step for the most Courant-constraining reach
2863 !<
2864 subroutine sfr_dt(this)
2865 ! -- modules
2866 use tdismodule, only: kstp, kper, ats
2867 ! -- dummy
2868 class(sfrtype) :: this !< SfrType object
2869 ! -- local
2870 integer(I4B) :: n
2871 integer(I4B) :: nrmin
2872 real(DP) :: celerity
2873 real(DP) :: dt_n
2874 real(DP) :: dtmin
2875 character(len=LINELENGTH) :: msg
2876 !
2877 if (this%ats_courant == dnodata) return
2878 if (this%istorage /= 1) return
2879 !
2880 dtmin = dnodata
2881 nrmin = 0
2882 !
2883 do n = 1, this%maxbound
2884 call this%sfr_calc_celerity(n, this%dsflow(n), celerity)
2885 if (celerity > dzero) then
2886 dt_n = this%ats_courant * this%length(n) / celerity
2887 if (dt_n < dtmin) then
2888 dtmin = dt_n
2889 nrmin = n
2890 end if
2891 end if
2892 end do
2893 !
2894 if (nrmin > 0) then
2895 write (msg, '(a,i0)') trim(this%packName)//'-REACH-', nrmin
2896 call ats%ats_submit_delt(kstp, kper, dtmin, trim(msg))
2897 end if
2898 end subroutine sfr_dt
2899
2900 !> @brief Kinematic-wave celerity from a flow perturbation (0 if dry)
2901 !<
2902 subroutine sfr_calc_celerity(this, n, q, celerity)
2903 ! -- dummy
2904 class(sfrtype) :: this !< SfrType object
2905 integer(I4B), intent(in) :: n !< reach number
2906 real(DP), intent(in) :: q !< reach flow
2907 real(DP), intent(out) :: celerity !< kinematic-wave celerity
2908 ! -- local
2909 real(DP) :: d
2910 real(DP) :: a
2911 real(DP) :: a2
2912 !
2913 celerity = dzero
2914 call this%sfr_calc_reach_depth(n, q, d)
2915 if (d > dzero) then
2916 a = this%calc_area_wet(n, d)
2917 call this%sfr_calc_reach_depth(n, q + this%deps, d)
2918 a2 = this%calc_area_wet(n, d)
2919 if (a2 > a) then
2920 celerity = this%deps / (a2 - a)
2921 end if
2922 end if
2923 end subroutine sfr_calc_celerity
2924
2925 !> @brief Deallocate package memory
2926 !!
2927 !! Deallocate SFR package scalars and arrays.
2928 !<
2929 subroutine sfr_da(this)
2930 ! -- modules
2932 ! -- dummy
2933 class(sfrtype) :: this !< SfrType object
2934 !
2935 ! -- deallocate arrays
2936 call mem_deallocate(this%qoutflow)
2937 call mem_deallocate(this%qextoutflow)
2938 deallocate (this%csfrbudget)
2939 call mem_deallocate(this%sfrname, 'SFRNAME', this%memoryPath)
2940 call mem_deallocate(this%dbuff)
2941 deallocate (this%cauxcbc)
2942 call mem_deallocate(this%qauxcbc)
2943 call mem_deallocate(this%iboundpak)
2944 call mem_deallocate(this%igwfnode)
2945 call mem_deallocate(this%igwftopnode)
2946 call mem_deallocate(this%length)
2947 call mem_deallocate(this%width)
2948 call mem_deallocate(this%strtop)
2949 call mem_deallocate(this%bthick)
2950 call mem_deallocate(this%slope)
2951 call mem_deallocate(this%nconnreach)
2952 call mem_deallocate(this%bedk_set)
2953 call mem_deallocate(this%manning_set)
2954 call mem_deallocate(this%ustrf_set)
2955 call mem_deallocate(this%ftotnd)
2956 call mem_deallocate(this%usflow)
2957 call mem_deallocate(this%dsflow)
2958 call mem_deallocate(this%depth)
2959 call mem_deallocate(this%stage)
2960 call mem_deallocate(this%gwflow)
2961 call mem_deallocate(this%simevap)
2962 call mem_deallocate(this%simrunoff)
2963 call mem_deallocate(this%stage0)
2964 call mem_deallocate(this%usflow0)
2965 call mem_deallocate(this%denseterms)
2966 call mem_deallocate(this%viscratios)
2967 !
2968 ! -- stage, usflow, and dsflow for previous timestep
2969 if (this%istorage == 1) then
2970 call mem_deallocate(this%stageold)
2971 call mem_deallocate(this%dsflowold)
2972 call mem_deallocate(this%storage)
2973 call mem_deallocate(this%usinflow)
2974 call mem_deallocate(this%usinflowold)
2975 call mem_deallocate(this%xsaus)
2976 call mem_deallocate(this%xsads)
2977 call mem_deallocate(this%xsausold)
2978 call mem_deallocate(this%xsadsold)
2979 call mem_deallocate(this%crmin)
2980 call mem_deallocate(this%crmax)
2981 call mem_deallocate(this%crsum)
2982 call mem_deallocate(this%crcnt)
2983 call mem_deallocate(this%itvd_upstream)
2984 end if
2985 !
2986 ! -- deallocate reach order and connection data
2987 call mem_deallocate(this%isfrorder)
2988 call mem_deallocate(this%ia)
2989 call mem_deallocate(this%ja)
2990 call mem_deallocate(this%idir)
2991 call mem_deallocate(this%idiv)
2992 call mem_deallocate(this%qconn)
2993 !
2994 nullify (this%rain)
2995 nullify (this%evap)
2996 nullify (this%inflow)
2997 nullify (this%runoff)
2998 nullify (this%sstage)
2999 nullify (this%hk)
3000 nullify (this%rough)
3001 nullify (this%ustrf)
3002 !
3003 ! -- deallocate diversion variables
3004 call mem_deallocate(this%iadiv)
3005 call mem_deallocate(this%divreach)
3006 if (associated(this%divcprior)) then
3007 deallocate (this%divcprior)
3008 end if
3009 ! -- divflow is package-owned only when empty (no diversions); it is not
3010 ! associated if the simulation stopped before it was set
3011 if (associated(this%divflow)) then
3012 if (size(this%divflow) == 0) then
3013 call mem_deallocate(this%divflow)
3014 else
3015 nullify (this%divflow)
3016 end if
3017 end if
3018 call mem_deallocate(this%divq)
3019 call mem_deallocate(this%ndiv)
3020 !
3021 ! -- deallocate cross-section data
3022 call mem_deallocate(this%ncrosspts)
3023 call mem_deallocate(this%iacross)
3024 call mem_deallocate(this%station)
3025 call mem_deallocate(this%xsheight)
3026 call mem_deallocate(this%xsrough)
3027 !
3028 ! -- deallocate budobj
3029 call this%budobj%budgetobject_da()
3030 deallocate (this%budobj)
3031 nullify (this%budobj)
3032 !
3033 ! -- deallocate stage table
3034 if (this%iprhed > 0) then
3035 call this%stagetab%table_da()
3036 deallocate (this%stagetab)
3037 nullify (this%stagetab)
3038 end if
3039 !
3040 ! -- deallocate Courant number table
3041 if (associated(this%couranttab)) then
3042 call this%couranttab%table_da()
3043 deallocate (this%couranttab)
3044 nullify (this%couranttab)
3045 end if
3046 !
3047 ! -- deallocate package csv table
3048 if (this%ipakcsv > 0) then
3049 if (associated(this%pakcsvtab)) then
3050 call this%pakcsvtab%table_da()
3051 deallocate (this%pakcsvtab)
3052 nullify (this%pakcsvtab)
3053 end if
3054 end if
3055 !
3056 ! -- deallocate scalars
3057 call mem_deallocate(this%ats_courant)
3058 call mem_deallocate(this%istorage)
3059 call mem_deallocate(this%storage_weight)
3060 call mem_deallocate(this%iprhed)
3061 call mem_deallocate(this%istageout)
3062 call mem_deallocate(this%ibudgetout)
3063 call mem_deallocate(this%ibudcsv)
3064 call mem_deallocate(this%ipakcsv)
3065 call mem_deallocate(this%idiversions)
3066 call mem_deallocate(this%maxsfrpicard)
3067 call mem_deallocate(this%maxsfrit)
3068 call mem_deallocate(this%bditems)
3069 call mem_deallocate(this%cbcauxitems)
3070 call mem_deallocate(this%unitconv)
3071 call mem_deallocate(this%lengthconv)
3072 call mem_deallocate(this%timeconv)
3073 call mem_deallocate(this%dmaxchg)
3074 call mem_deallocate(this%deps)
3075 call mem_deallocate(this%nconn)
3076 call mem_deallocate(this%icheck)
3077 call mem_deallocate(this%iconvchk)
3078 call mem_deallocate(this%idense)
3079 call mem_deallocate(this%ianynone)
3080 call mem_deallocate(this%ncrossptstot)
3081 nullify (this%gwfiss)
3082 !
3083 ! -- nullify SFR input context pointers (input context owns the memory)
3084 call this%input%destroy()
3085 !
3086 ! -- call base BndExtType deallocate
3087 call this%BndExtType%bnd_da()
3088 end subroutine sfr_da
3089
3090 !> @brief Pre-compute the single upstream reach index for the TVD limiter
3091 !!
3092 !! Index 0 for reaches with zero or multiple upstream connections.
3093 !<
3094 subroutine sfr_precompute_tvd(this)
3095 ! -- dummy
3096 class(sfrtype), intent(inout) :: this !< SfrType object
3097 ! -- local
3098 integer(I4B) :: n
3099 integer(I4B) :: j
3100 integer(I4B) :: iup_count
3101 integer(I4B) :: m
3102 !
3103 do n = 1, this%maxbound
3104 iup_count = 0
3105 m = 0
3106 do j = this%ia(n) + 1, this%ia(n + 1) - 1
3107 if (this%idir(j) > 0) then
3108 iup_count = iup_count + 1
3109 m = this%ja(j)
3110 end if
3111 end do
3112 if (iup_count == 1) then
3113 this%itvd_upstream(n) = m
3114 else
3115 this%itvd_upstream(n) = 0
3116 end if
3117 end do
3118 end subroutine sfr_precompute_tvd
3119
3120 !> @brief Define the list label for the package
3121 !!
3122 !! Method defined the list label for the SFR package. The list label is
3123 !! the heading that is written to iout when PRINT_INPUT option is used.
3124 !<
3125 subroutine define_listlabel(this)
3126 ! -- dummy
3127 class(sfrtype), intent(inout) :: this !< SfrType object
3128 !
3129 ! -- create the header list label
3130 this%listlabel = trim(this%filtyp)//' NO.'
3131 if (this%dis%ndim == 3) then
3132 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'LAYER'
3133 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'ROW'
3134 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'COL'
3135 elseif (this%dis%ndim == 2) then
3136 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'LAYER'
3137 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'CELL2D'
3138 else
3139 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'NODE'
3140 end if
3141 write (this%listlabel, '(a, a16)') trim(this%listlabel), 'STRESS RATE'
3142 if (this%inamedbound == 1) then
3143 write (this%listlabel, '(a, a16)') trim(this%listlabel), 'BOUNDARY NAME'
3144 end if
3145 end subroutine define_listlabel
3146
3147 !
3148 ! -- Procedures related to observations (type-bound)
3149
3150 !> @brief Determine if observations are supported.
3151 !!
3152 !! Function to determine if observations are supported by the SFR package.
3153 !! Observations are supported by the SFR package.
3154 !!
3155 !! @return sfr_obs_supported boolean indicating if observations are supported
3156 !<
3157 logical function sfr_obs_supported(this)
3158 ! -- dummy
3159 class(sfrtype) :: this !< SfrType object
3160 !
3161 ! -- set boolean
3162 sfr_obs_supported = .true.
3163 end function sfr_obs_supported
3164
3165 !> @brief Define the observation types available in the package
3166 !!
3167 !! Method to define the observation types available in the SFR package.
3168 !<
3169 subroutine sfr_df_obs(this)
3170 ! -- dummy
3171 class(sfrtype) :: this !< SfrType object
3172 ! -- local
3173 integer(I4B) :: indx
3174 !
3175 ! -- Store obs type and assign procedure pointer
3176 ! for stage observation type.
3177 call this%obs%StoreObsType('stage', .false., indx)
3178 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3179 !
3180 ! -- Store obs type and assign procedure pointer
3181 ! for inflow observation type.
3182 call this%obs%StoreObsType('inflow', .true., indx)
3183 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3184 !
3185 ! -- Store obs type and assign procedure pointer
3186 ! for inflow observation type.
3187 call this%obs%StoreObsType('ext-inflow', .true., indx)
3188 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3189 !
3190 ! -- Store obs type and assign procedure pointer
3191 ! for rainfall observation type.
3192 call this%obs%StoreObsType('rainfall', .true., indx)
3193 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3194 !
3195 ! -- Store obs type and assign procedure pointer
3196 ! for runoff observation type.
3197 call this%obs%StoreObsType('runoff', .true., indx)
3198 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3199 !
3200 ! -- Store obs type and assign procedure pointer
3201 ! for evaporation observation type.
3202 call this%obs%StoreObsType('evaporation', .true., indx)
3203 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3204 !
3205 ! -- Store obs type and assign procedure pointer
3206 ! for outflow observation type.
3207 call this%obs%StoreObsType('outflow', .true., indx)
3208 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3209 !
3210 ! -- Store obs type and assign procedure pointer
3211 ! for ext-outflow observation type.
3212 call this%obs%StoreObsType('ext-outflow', .true., indx)
3213 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3214 !
3215 ! -- Store obs type and assign procedure pointer
3216 ! for to-mvr observation type.
3217 call this%obs%StoreObsType('to-mvr', .true., indx)
3218 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3219 !
3220 ! -- Store obs type and assign procedure pointer
3221 ! for sfr-frommvr observation type.
3222 call this%obs%StoreObsType('from-mvr', .true., indx)
3223 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3224 !
3225 ! -- Store obs type and assign procedure pointer
3226 ! for sfr observation type.
3227 call this%obs%StoreObsType('sfr', .true., indx)
3228 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3229 !
3230 ! -- Store obs type and assign procedure pointer
3231 ! for upstream flow observation type.
3232 call this%obs%StoreObsType('upstream-flow', .true., indx)
3233 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3234 !
3235 ! -- Store obs type and assign procedure pointer
3236 ! for downstream flow observation type.
3237 call this%obs%StoreObsType('downstream-flow', .true., indx)
3238 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3239 !
3240 ! -- Store obs type and assign procedure pointer
3241 ! for depth observation type.
3242 call this%obs%StoreObsType('depth', .false., indx)
3243 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3244 !
3245 ! -- Store obs type and assign procedure pointer
3246 ! for wetted-perimeter observation type.
3247 call this%obs%StoreObsType('wet-perimeter', .false., indx)
3248 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3249 !
3250 ! -- Store obs type and assign procedure pointer
3251 ! for wetted-area observation type.
3252 call this%obs%StoreObsType('wet-area', .false., indx)
3253 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3254 !
3255 ! -- Store obs type and assign procedure pointer
3256 ! for wetted-width observation type.
3257 call this%obs%StoreObsType('wet-width', .false., indx)
3258 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3259 end subroutine sfr_df_obs
3260
3261 !> @brief Save observations for the package
3262 !!
3263 !! Method to save simulated values for the SFR package.
3264 !<
3265 subroutine sfr_bd_obs(this)
3266 ! -- dummy
3267 class(sfrtype) :: this !< SfrType object
3268 ! -- local
3269 integer(I4B) :: i
3270 integer(I4B) :: j
3271 integer(I4B) :: n
3272 real(DP) :: v
3273 character(len=100) :: msg
3274 type(observetype), pointer :: obsrv => null()
3275 !
3276 ! Write simulated values for all sfr observations
3277 if (this%obs%npakobs > 0) then
3278 call this%obs%obs_bd_clear()
3279 do i = 1, this%obs%npakobs
3280 obsrv => this%obs%pakobs(i)%obsrv
3281 do j = 1, obsrv%indxbnds_count
3282 n = obsrv%indxbnds(j)
3283 v = dzero
3284 select case (obsrv%ObsTypeId)
3285 case ('STAGE')
3286 v = this%stage(n)
3287 case ('TO-MVR')
3288 v = dnodata
3289 if (this%imover == 1) then
3290 v = this%pakmvrobj%get_qtomvr(n)
3291 if (v > dzero) then
3292 v = -v
3293 end if
3294 end if
3295 case ('FROM-MVR')
3296 v = dnodata
3297 if (this%imover == 1) then
3298 v = this%pakmvrobj%get_qfrommvr(n)
3299 end if
3300 case ('EXT-INFLOW')
3301 v = this%inflow(n)
3302 case ('INFLOW')
3303 v = this%usflow(n)
3304 case ('OUTFLOW')
3305 v = this%qoutflow(n)
3306 case ('EXT-OUTFLOW')
3307 v = this%qextoutflow(n)
3308 case ('RAINFALL')
3309 if (this%iboundpak(n) /= 0) then
3310 v = this%rain(n)
3311 else
3312 v = dzero
3313 end if
3314 case ('RUNOFF')
3315 v = this%simrunoff(n)
3316 case ('EVAPORATION')
3317 v = this%simevap(n)
3318 case ('SFR')
3319 v = this%gwflow(n)
3320 case ('UPSTREAM-FLOW')
3321 v = this%usflow(n)
3322 if (this%imover == 1) then
3323 v = v + this%pakmvrobj%get_qfrommvr(n)
3324 end if
3325 case ('DOWNSTREAM-FLOW')
3326 v = this%dsflow(n)
3327 if (v > dzero) then
3328 v = -v
3329 end if
3330 case ('DEPTH')
3331 v = this%depth(n)
3332 case ('WET-PERIMETER')
3333 v = this%calc_perimeter_wet(n, this%depth(n))
3334 case ('WET-AREA')
3335 v = this%calc_area_wet(n, this%depth(n))
3336 case ('WET-WIDTH')
3337 v = this%calc_top_width_wet(n, this%depth(n))
3338 case default
3339 msg = 'Unrecognized observation type: '//trim(obsrv%ObsTypeId)
3340 call store_error(msg)
3341 end select
3342 call this%obs%SaveOneSimval(obsrv, v)
3343 end do
3344 end do
3345 !
3346 ! -- write summary of package error messages
3347 if (count_errors() > 0) then
3348 call store_error_filename(this%input_fname)
3349 end if
3350 end if
3351 end subroutine sfr_bd_obs
3352
3353 !> @brief Read and prepare observations for a package
3354 !!
3355 !! Method to read and prepare observations for a SFR package.
3356 !<
3357 subroutine sfr_rp_obs(this)
3358 ! -- modules
3359 use tdismodule, only: kper
3360 ! -- dummy
3361 class(sfrtype), intent(inout) :: this !< SfrType object
3362 ! -- local
3363 integer(I4B) :: i
3364 integer(I4B) :: j
3365 integer(I4B) :: nn1
3366 character(len=LENBOUNDNAME) :: bname
3367 logical(LGP) :: jfound
3368 class(observetype), pointer :: obsrv => null()
3369 ! -- formats
337010 format('Boundary "', a, '" for observation "', a, &
3371 '" is invalid in package "', a, '"')
337230 format('Boundary name not provided for observation "', a, &
3373 '" in package "', a, '"')
3374 !
3375 ! -- process each package observation
3376 ! only done the first stress period since boundaries are fixed
3377 ! for the simulation
3378 if (kper == 1) then
3379 do i = 1, this%obs%npakobs
3380 obsrv => this%obs%pakobs(i)%obsrv
3381 !
3382 ! -- get node number 1
3383 nn1 = obsrv%NodeNumber
3384 if (nn1 == namedboundflag) then
3385 bname = obsrv%FeatureName
3386 if (bname /= '') then
3387 ! -- Observation location(s) is(are) based on a boundary name.
3388 ! Iterate through all boundaries to identify and store
3389 ! corresponding index(indices) in bound array.
3390 jfound = .false.
3391 if (this%inamedbound /= 0) then
3392 do j = 1, this%maxbound
3393 if (this%boundname(j) == bname) then
3394 jfound = .true.
3395 call obsrv%AddObsIndex(j)
3396 end if
3397 end do
3398 end if
3399 if (.not. jfound) then
3400 write (errmsg, 10) &
3401 trim(bname), trim(obsrv%name), trim(this%packName)
3402 call store_error(errmsg)
3403 end if
3404 else
3405 write (errmsg, 30) trim(obsrv%name), trim(this%packName)
3406 call store_error(errmsg)
3407 end if
3408 else if (nn1 < 1 .or. nn1 > this%maxbound) then
3409 write (errmsg, '(a,1x,a,1x,i0,1x,a,1x,i0,a)') &
3410 trim(adjustl(obsrv%ObsTypeId)), &
3411 'reach must be greater than 0 and less than or equal to', &
3412 this%maxbound, '(specified value is ', nn1, ')'
3413 call store_error(errmsg)
3414 else
3415 if (obsrv%indxbnds_count == 0) then
3416 call obsrv%AddObsIndex(nn1)
3417 else
3418 errmsg = 'Programming error in sfr_rp_obs'
3419 call store_error(errmsg)
3420 end if
3421 end if
3422 !
3423 ! -- catch non-cumulative observation assigned to observation defined
3424 ! by a boundname that is assigned to more than one element
3425 if (obsrv%ObsTypeId == 'STAGE' .or. &
3426 obsrv%ObsTypeId == 'DEPTH' .or. &
3427 obsrv%ObsTypeId == 'WET-PERIMETER' .or. &
3428 obsrv%ObsTypeId == 'WET-AREA' .or. &
3429 obsrv%ObsTypeId == 'WET-WIDTH') then
3430 nn1 = obsrv%NodeNumber
3431 if (nn1 == namedboundflag) then
3432 if (obsrv%indxbnds_count > 1) then
3433 write (errmsg, '(a,3(1x,a))') &
3434 trim(adjustl(obsrv%ObsTypeId)), &
3435 'for observation', trim(adjustl(obsrv%Name)), &
3436 ' must be assigned to a reach with a unique boundname.'
3437 call store_error(errmsg)
3438 end if
3439 end if
3440 end if
3441 !
3442 ! -- check that node number 1 is valid; call store_error if not
3443 do j = 1, obsrv%indxbnds_count
3444 nn1 = obsrv%indxbnds(j)
3445 if (nn1 < 1 .or. nn1 > this%maxbound) then
3446 write (errmsg, '(a,1x,a,1x,i0,1x,a,1x,i0,a)') &
3447 trim(adjustl(obsrv%ObsTypeId)), &
3448 'reach must be greater than 0 and less than or equal to', &
3449 this%maxbound, '(specified value is ', nn1, ')'
3450 call store_error(errmsg)
3451 end if
3452 end do
3453 end do
3454 !
3455 ! -- evaluate if there are any observation errors
3456 if (count_errors() > 0) then
3457 call store_error_filename(this%input_fname)
3458 end if
3459 end if
3460 end subroutine sfr_rp_obs
3461
3462 !
3463 ! -- Procedures related to observations (NOT type-bound)
3464
3465 !> @brief Process observation IDs for a package
3466 !!
3467 !! Method to process observation ID strings for a SFR package.
3468 !<
3469 subroutine sfr_process_obsid(obsrv, dis, inunitobs, iout)
3470 ! -- dummy
3471 type(observetype), intent(inout) :: obsrv !< Observation object
3472 class(disbasetype), intent(in) :: dis !< Discretization object
3473 integer(I4B), intent(in) :: inunitobs !< file unit number for the package observation file
3474 integer(I4B), intent(in) :: iout !< model listing file unit number
3475 ! -- local
3476 integer(I4B) :: nn1
3477 integer(I4B) :: icol
3478 integer(I4B) :: istart
3479 integer(I4B) :: istop
3480 character(len=LINELENGTH) :: string
3481 character(len=LENBOUNDNAME) :: bndname
3482 !
3483 ! -- initialize local variables
3484 string = obsrv%IDstring
3485 !
3486 ! -- Extract reach number from string and store it.
3487 ! If 1st item is not an integer(I4B), it should be a
3488 ! boundary name--deal with it.
3489 icol = 1
3490 !
3491 ! -- get reach number or boundary name
3492 call extract_idnum_or_bndname(string, icol, istart, istop, nn1, bndname)
3493 if (nn1 == namedboundflag) then
3494 obsrv%FeatureName = bndname
3495 end if
3496 !
3497 ! -- store reach number (NodeNumber)
3498 obsrv%NodeNumber = nn1
3499 end subroutine sfr_process_obsid
3500
3501 !> @brief Solve reach continuity equation
3502 !!
3503 !! Method to solve the continuity equation for a SFR package reach.
3504 !<
3505 subroutine sfr_solve(this, n, h, hcof, rhs, update)
3506 ! -- dummy
3507 class(sfrtype) :: this !< SfrType object
3508 integer(I4B), intent(in) :: n !< reach number
3509 real(DP), intent(in) :: h !< groundwater head in cell connected to reach
3510 real(DP), intent(inout) :: hcof !< coefficient term added to the diagonal
3511 real(DP), intent(inout) :: rhs !< right-hand side term
3512 logical(LGP), intent(in), optional :: update !< boolean indicating if the reach depth and stage variables should be updated to current iterate
3513 ! -- local
3514 logical(LGP) :: lupdate
3515 integer(I4B) :: i
3516 integer(I4B) :: ii
3517 integer(I4B) :: n2
3518 real(DP) :: hgwf
3519 real(DP) :: sa
3520 real(DP) :: sa_wet
3521 real(DP) :: qu
3522 real(DP) :: qi
3523 real(DP) :: qr
3524 real(DP) :: qe
3525 real(DP) :: qro
3526 real(DP) :: qsrc
3527 real(DP) :: qfrommvr
3528 real(DP) :: qgwf
3529 real(DP) :: tp
3530 real(DP) :: bt
3531 real(DP) :: hsfr
3532 real(DP) :: qd
3533 real(DP) :: d1
3534 real(DP) :: sumleak
3535 real(DP) :: sumrch
3536 real(DP) :: gwfhcof
3537 real(DP) :: gwfrhs
3538 !
3539 ! -- Process optional dummy variables
3540 if (present(update)) then
3541 lupdate = update
3542 else
3543 lupdate = .true.
3544 end if
3545
3546 ! -- initialize variables
3547 hcof = dzero
3548 rhs = dzero
3549 !
3550 if (this%iboundpak(n) == 0) then
3551 this%depth(n) = dzero
3552 this%stage(n) = dhnoflo
3553 this%usflow(n) = dzero
3554 this%simevap(n) = dzero
3555 this%simrunoff(n) = dzero
3556 this%dsflow(n) = dzero
3557 this%gwflow(n) = dzero
3558 else
3559 hgwf = h
3560 d1 = dzero
3561 qsrc = dzero
3562 qgwf = dzero
3563 qd = this%dsflow(n)
3564
3565 ! -- calculate initial depth assuming a wide cross-section and
3566 ! ignore groundwater leakage
3567 ! -- calculate upstream flow
3568 qu = dzero
3569 do i = this%ia(n) + 1, this%ia(n + 1) - 1
3570 if (this%idir(i) < 0) cycle
3571 n2 = this%ja(i)
3572 do ii = this%ia(n2) + 1, this%ia(n2 + 1) - 1
3573 if (this%idir(ii) > 0) cycle
3574 if (this%ja(ii) /= n) cycle
3575 qu = qu + this%qconn(ii)
3576 end do
3577 end do
3578 this%usflow(n) = qu
3579
3580 ! -- calculate remaining terms
3581 sa = this%calc_surface_area(n)
3582 sa_wet = this%calc_surface_area_wet(n, this%depth(n))
3583 qi = this%inflow(n)
3584 qr = this%rain(n) * sa
3585 qe = this%evap(n) * sa_wet
3586 qro = this%runoff(n)
3587
3588 ! -- Water mover term; assume that it goes in at the upstream end of the reach
3589 qfrommvr = dzero
3590 if (this%imover == 1) then
3591 qfrommvr = this%pakmvrobj%get_qfrommvr(n)
3592 end if
3593
3594 ! -- calculate downstream flow ignoring groundwater leakage
3595 qsrc = qu + qi + qr - qe + qro + qfrommvr
3596
3597 ! -- adjust runoff or evaporation if sum of sources is negative
3598 call this%sfr_adjust_ro_ev(qsrc, qu, qi, qr, qro, qe, qfrommvr)
3599
3600 ! -- set simulated evaporation and runoff
3601 this%simevap(n) = qe
3602 this%simrunoff(n) = qro
3603
3604 ! -- inflow at the upstream end of the reach for the routing of the
3605 ! next time step; storage is set only by the transient methods
3606 if (this%istorage == 1) then
3607 this%usinflow(n) = qu + qi + qfrommvr
3608 this%storage(n) = dzero
3609 end if
3610
3611 ! -- calculate reach flow using appropriate method
3612 if (this%iboundpak(n) < 0) then
3613 call this%sfr_calc_constant(n, d1, hgwf, qgwf, qd)
3614 else
3615 if (this%gwfiss == 0 .and. this%istorage == 1) then
3616 if (this%ats_courant /= dnodata) then
3617 call this%sfr_calc_tvd(n, d1, hgwf, qu, qi, &
3618 qfrommvr, qr, qe, qro, &
3619 qgwf, qd)
3620 else
3621 call this%sfr_calc_transient(n, d1, hgwf, qu, qi, &
3622 qfrommvr, qr, qe, qro, &
3623 qgwf, qd)
3624 end if
3625 else
3626 call this%sfr_calc_steady(n, d1, hgwf, qu, qi, &
3627 qfrommvr, qr, qe, qro, &
3628 qgwf, qd)
3629 end if
3630 end if
3631
3632 ! -- update sfr stage
3633 tp = this%strtop(n)
3634 bt = tp - this%bthick(n)
3635 hsfr = tp + d1
3636
3637 ! -- update stored values
3638 if (lupdate) then
3639 ! -- save depth and calculate stage
3640 this%depth(n) = d1
3641 this%stage(n) = hsfr
3642 ! -- update flows
3643 call this%sfr_update_flows(n, qd, qgwf)
3644 end if
3645
3646 ! -- calculate sumleak and sumrch
3647 sumleak = dzero
3648 sumrch = dzero
3649 if (this%gwfiss == 0) then
3650 sumleak = qgwf
3651 else
3652 sumleak = qgwf
3653 end if
3654 if (hgwf < bt) then
3655 sumrch = qgwf
3656 end if
3657
3658 ! -- make final qgwf calculation and obtain
3659 ! gwfhcof and gwfrhs values
3660 call this%sfr_calc_qgwf(n, d1, hgwf, qgwf, gwfhcof, gwfrhs)
3661
3662 ! -- update hcof and rhs terms
3663 if (abs(sumleak) > dzero) then
3664 ! -- stream leakage is not head dependent
3665 if (hgwf < bt) then
3666 rhs = rhs - sumrch
3667 ! -- stream leakage is head dependent
3668 else if ((sumleak - qsrc) < -dem30) then
3669 if (this%gwfiss == 0) then
3670 rhs = rhs + gwfrhs - sumrch
3671 else
3672 rhs = rhs + gwfrhs
3673 end if
3674 hcof = gwfhcof
3675 ! -- place holder for UZF
3676 else
3677 if (this%gwfiss == 0) then
3678 rhs = rhs - sumleak - sumrch
3679 else
3680 rhs = rhs - sumleak
3681 end if
3682 end if
3683
3684 ! -- add groundwater leakage
3685 else if (hgwf < bt) then
3686 rhs = rhs - sumrch
3687 end if
3688 end if
3689 end subroutine sfr_solve
3690
3691 !> @brief Update flow terms
3692 !!
3693 !! Method to update downstream flow and groundwater leakage terms for
3694 !! a SFR package reach.
3695 !<
3696 subroutine sfr_update_flows(this, n, qd, qgwf)
3697 ! -- dummy
3698 class(sfrtype), intent(inout) :: this !< SfrType object
3699 integer(I4B), intent(in) :: n !< reach number
3700 real(DP), intent(inout) :: qd !< downstream reach flow
3701 real(DP), intent(in) :: qgwf !< groundwater leakage for reach
3702 ! -- local
3703 integer(I4B) :: i
3704 integer(I4B) :: n2
3705 integer(I4B) :: idiv
3706 integer(I4B) :: jpos
3707 real(DP) :: qdiv
3708 real(DP) :: f
3709 !
3710 ! -- update reach terms
3711 !
3712 ! -- save final downstream stream flow
3713 this%dsflow(n) = qd
3714 !
3715 ! -- save groundwater leakage
3716 this%gwflow(n) = qgwf
3717 !
3718 ! -- route downstream flow
3719 if (qd > dzero) then
3720 !
3721 ! -- route water to diversions
3722 do i = this%ia(n) + 1, this%ia(n + 1) - 1
3723 if (this%idir(i) > 0) cycle
3724 idiv = this%idiv(i)
3725 if (idiv == 0) cycle
3726 jpos = this%iadiv(n) + idiv - 1
3727 call this%sfr_calc_div(n, idiv, qd, qdiv)
3728 this%qconn(i) = qdiv
3729 this%divq(jpos) = qdiv
3730 end do
3731 !
3732 ! -- Mover terms: store outflow after diversion loss
3733 ! as qformvr and reduce outflow (qd)
3734 ! by how much was actually sent to the mover
3735 if (this%imover == 1) then
3736 call this%pakmvrobj%accumulate_qformvr(n, qd)
3737 qd = max(qd - this%pakmvrobj%get_qtomvr(n), dzero)
3738 end if
3739 !
3740 ! -- route remaining water to downstream reaches
3741 do i = this%ia(n) + 1, this%ia(n + 1) - 1
3742 if (this%idir(i) > 0) cycle
3743 if (this%idiv(i) > 0) cycle
3744 n2 = this%ja(i)
3745 if (this%iboundpak(n2) == 0) cycle
3746 f = this%ustrf(n2) / this%ftotnd(n)
3747 this%qconn(i) = qd * f
3748 end do
3749 else
3750 do i = this%ia(n) + 1, this%ia(n + 1) - 1
3751 if (this%idir(i) > 0) cycle
3752 this%qconn(i) = dzero
3753 idiv = this%idiv(i)
3754 if (idiv == 0) cycle
3755 jpos = this%iadiv(n) + idiv - 1
3756 this%divq(jpos) = dzero
3757 end do
3758 end if
3759 end subroutine sfr_update_flows
3760
3761 !> @brief Adjust runoff and evaporation
3762 !!
3763 !! Method to adjust runoff and evaporation for a SFR package reach
3764 !! based on the total reach flow.
3765 !<
3766 subroutine sfr_adjust_ro_ev(this, qc, qu, qi, qr, qro, qe, qfrommvr)
3767 ! -- dummy
3768 class(sfrtype) :: this !< SfrType object
3769 real(DP), intent(inout) :: qc !< total reach volumetric flow
3770 real(DP), intent(in) :: qu !< upstream reach volumetric flow
3771 real(DP), intent(in) :: qi !< reach volumetric inflow
3772 real(DP), intent(in) :: qr !< reach volumetric rainfall
3773 real(DP), intent(inout) :: qro !< reach volumetric runoff
3774 real(DP), intent(inout) :: qe !< reach volumetric evaporation
3775 real(DP), intent(in) :: qfrommvr !< reach volumetric flow from mover
3776 ! -- local
3777 real(DP) :: qt
3778 !
3779 ! -- adjust runoff or evaporation if sum of sources is negative
3780 if (qc < dzero) then
3781 !
3782 ! -- calculate sources without evaporation
3783 qt = qu + qi + qr + qro + qfrommvr
3784 !
3785 ! -- runoff exceeds sources of water for reach
3786 if (qt < dzero) then
3787 if (qro < dzero) then
3788 qro = -(qu + qi + qr + qfrommvr)
3789 qe = dzero
3790 end if
3791 !
3792 ! -- evaporation exceeds sources of water for reach
3793 else
3794 if (qe > dzero) then
3795 qe = qu + qi + qr + qro + qfrommvr
3796 end if
3797 end if
3798 qc = qu + qi + qr - qe + qro + qfrommvr
3799 end if
3800 end subroutine sfr_adjust_ro_ev
3801
3802 !> @brief Calculate downstream flow term
3803 !!
3804 !! Method to calculate downstream flow for a SFR package reach.
3805 !<
3806 subroutine sfr_calc_qd(this, n, depth, hgwf, qgwf, qd)
3807 ! -- dummy
3808 class(sfrtype) :: this !< SfrType object
3809 integer(I4B), intent(in) :: n !< reach number
3810 real(DP), intent(in) :: depth !< reach depth
3811 real(DP), intent(in) :: hgwf !< groundwater head in connected GWF cell
3812 real(DP), intent(inout) :: qgwf !< groundwater leakage for reach
3813 real(DP), intent(inout) :: qd !< residual
3814 ! -- local
3815 real(DP) :: qsrc
3816 !
3817 ! -- initialize residual
3818 qd = dzero
3819 !
3820 ! -- calculate total water sources excluding groundwater leakage
3821 call this%sfr_calc_qsource(n, depth, qsrc)
3822 !
3823 ! -- estimate groundwater leakage
3824 call this%sfr_calc_qgwf(n, depth, hgwf, qgwf)
3825 if (-qgwf > qsrc) qgwf = -qsrc
3826 !
3827 ! -- calculate down stream flow
3828 qd = qsrc + qgwf
3829 !
3830 ! -- limit downstream flow to a positive value
3831 if (qd < dem30) qd = dzero
3832 end subroutine sfr_calc_qd
3833
3834 !> @brief Calculate sum of sources
3835 !!
3836 !! Method to calculate the sum of sources for reach, excluding
3837 !! reach leakage, for a SFR package reach.
3838 !<
3839 subroutine sfr_calc_qsource(this, n, depth, qsrc)
3840 ! -- dummy
3841 class(sfrtype) :: this !< SfrType object
3842 integer(I4B), intent(in) :: n !< reach number
3843 real(DP), intent(in) :: depth !< reach depth
3844 real(DP), intent(inout) :: qsrc !< sum of sources for reach
3845 ! -- local
3846 real(DP) :: qu
3847 real(DP) :: qi
3848 real(DP) :: qr
3849 real(DP) :: qe
3850 real(DP) :: qro
3851 real(DP) :: qfrommvr
3852 real(DP) :: a
3853 real(DP) :: ae
3854 !
3855 ! -- initialize residual
3856 qsrc = dzero
3857 !
3858 ! -- calculate flow terms
3859 qu = this%usflow(n)
3860 qi = this%inflow(n)
3861 qro = this%runoff(n)
3862 !
3863 ! -- calculate rainfall and evap
3864 a = this%calc_surface_area(n)
3865 ae = this%calc_surface_area_wet(n, depth)
3866 qr = this%rain(n) * a
3867 qe = this%evap(n) * ae
3868 !
3869 ! -- calculate mover term
3870 qfrommvr = dzero
3871 if (this%imover == 1) then
3872 qfrommvr = this%pakmvrobj%get_qfrommvr(n)
3873 end if
3874 !
3875 ! -- calculate down stream flow
3876 qsrc = qu + qi + qr - qe + qro + qfrommvr
3877 !
3878 ! -- adjust runoff or evaporation if sum of sources is negative
3879 call this%sfr_adjust_ro_ev(qsrc, qu, qi, qr, qro, qe, qfrommvr)
3880 end subroutine sfr_calc_qsource
3881
3882 !> @brief Calculate streamflow
3883 !!
3884 !! Method to calculate the streamflow using Manning's equation for a
3885 !! SFR package reach.
3886 !<
3887 subroutine sfr_calc_qman(this, n, depth, qman)
3888 ! -- dummy
3889 class(sfrtype) :: this !< SfrType object
3890 integer(I4B), intent(in) :: n !< reach number
3891 real(DP), intent(in) :: depth !< reach depth
3892 real(DP), intent(inout) :: qman !< streamflow
3893 ! -- local
3894 integer(I4B) :: npts
3895 integer(I4B) :: i0
3896 integer(I4B) :: i1
3897 real(DP) :: sat
3898 real(DP) :: derv
3899 real(DP) :: s
3900 real(DP) :: r
3901 real(DP) :: aw
3902 real(DP) :: wp
3903 real(DP) :: rh
3904 !
3905 ! -- initialize variables
3906 qman = dzero
3907 !
3908 ! -- calculate Manning's discharge for non-zero depths
3909 if (depth > dzero) then
3910 npts = this%ncrosspts(n)
3911 !
3912 ! -- set constant terms for Manning's equation
3913 call schsmooth(depth, sat, derv)
3914 s = this%slope(n)
3915 !
3916 ! -- calculate the mannings coefficient that is a
3917 ! function of depth
3918 if (npts > 1) then
3919 !
3920 ! -- get the location of the cross-section data for the reach
3921 i0 = this%iacross(n)
3922 i1 = this%iacross(n + 1) - 1
3923 !
3924 ! -- get the Manning's sum of the Manning's discharge
3925 ! for each section
3926 qman = get_mannings_section(npts, &
3927 this%station(i0:i1), &
3928 this%xsheight(i0:i1), &
3929 this%xsrough(i0:i1), &
3930 this%rough(n), &
3931 this%unitconv, &
3932 s, &
3933 depth)
3934 else
3935 r = this%rough(n)
3936 aw = this%calc_area_wet(n, depth)
3937 wp = this%calc_perimeter_wet(n, depth)
3938 if (wp > dzero) then
3939 rh = aw / wp
3940 else
3941 rh = dzero
3942 end if
3943 qman = this%unitconv * aw * (rh**dtwothirds) * sqrt(s) / r
3944 end if
3945 !
3946 ! -- calculate stream flow
3947 qman = sat * qman
3948 end if
3949 end subroutine sfr_calc_qman
3950
3951 !> @brief Calculate reach-aquifer exchange
3952 !!
3953 !! Method to calculate the reach-aquifer exchange for a SFR package reach.
3954 !! The reach-aquifer exchange is relative to the reach. Calculated flow
3955 !! is positive if flow is from the aquifer to the reach.
3956 !<
3957 subroutine sfr_calc_qgwf(this, n, depth, hgwf, qgwf, gwfhcof, gwfrhs)
3958 ! -- dummy
3959 class(sfrtype) :: this !< SfrType object
3960 integer(I4B), intent(in) :: n !< reach number
3961 real(DP), intent(in) :: depth !< reach depth
3962 real(DP), intent(in) :: hgwf !< head in GWF cell connected to reach
3963 real(DP), intent(inout) :: qgwf !< reach-aquifer exchange
3964 real(DP), intent(inout), optional :: gwfhcof !< diagonal coefficient term for reach
3965 real(DP), intent(inout), optional :: gwfrhs !< right-hand side term for reach
3966 ! -- local
3967 integer(I4B) :: node
3968 real(DP) :: tp
3969 real(DP) :: bt
3970 real(DP) :: hsfr
3971 real(DP) :: h_temp
3972 real(DP) :: cond
3973 real(DP) :: sat
3974 real(DP) :: derv
3975 real(DP) :: gwfhcof0
3976 real(DP) :: gwfrhs0
3977 !
3978 ! -- initialize qgwf
3979 qgwf = dzero
3980 !
3981 ! -- skip sfr-aquifer exchange in external cells
3982 node = this%igwfnode(n)
3983 if (node < 1) return
3984 !
3985 ! -- skip sfr-aquifer exchange in inactive cells
3986 if (this%ibound(node) == 0) return
3987 !
3988 ! -- calculate saturation
3989 call schsmooth(depth, sat, derv)
3990 !
3991 ! -- terms for calculating direction of gradient across streambed
3992 tp = this%strtop(n)
3993 bt = tp - this%bthick(n)
3994 hsfr = tp + depth
3995 h_temp = hgwf
3996 if (h_temp < bt) then
3997 h_temp = bt
3998 end if
3999 !
4000 ! -- calculate conductance
4001 call this%sfr_calc_cond(n, depth, cond, hsfr, h_temp)
4002 !
4003 ! -- calculate groundwater leakage
4004 qgwf = sat * cond * (h_temp - hsfr)
4005 gwfrhs0 = -sat * cond * hsfr
4006 gwfhcof0 = -sat * cond
4007 !
4008 ! Add density contributions, if active
4009 if (this%idense /= 0) then
4010 call this%sfr_calculate_density_exchange(n, hsfr, hgwf, cond, tp, &
4011 qgwf, gwfhcof0, gwfrhs0)
4012 end if
4013 !
4014 ! -- Set gwfhcof and gwfrhs if present
4015 if (present(gwfhcof)) gwfhcof = gwfhcof0
4016 if (present(gwfrhs)) gwfrhs = gwfrhs0
4017 end subroutine sfr_calc_qgwf
4018
4019 !> @brief Determine if a reach is connected to a gwf cell
4020 !!
4021 !! Function to determine if a reach is connected to a gwf cell. If connected,
4022 !! the return value is 1. Otherwise, the return value is 0.
4023 !<
4024 function sfr_gwf_conn(this, n)
4025 ! -- return variable
4026 integer(I4B) :: sfr_gwf_conn !< flag indicating if reach is connected to a gwf cell
4027 ! -- dummy
4028 class(sfrtype) :: this !< SfrType object
4029 integer(I4B), intent(in) :: n !< reach number
4030 ! -- local
4031 integer(I4B) :: node
4032
4033 sfr_gwf_conn = 0
4034 node = this%igwfnode(n)
4035 if (node > 0 .and. this%hk(n) > dzero) then
4036 sfr_gwf_conn = 1
4037 end if
4038 end function sfr_gwf_conn
4039
4040 !> @brief Calculate reach-aquifer conductance
4041 !!
4042 !! Method to calculate the reach-aquifer conductance for a SFR package reach.
4043 !<
4044 subroutine sfr_calc_cond(this, n, depth, cond, hsfr, h_temp)
4045 ! -- dummy
4046 class(sfrtype) :: this !< SfrType object
4047 integer(I4B), intent(in) :: n !< reach number
4048 real(DP), intent(in) :: depth !< reach depth
4049 real(DP), intent(inout) :: cond !< reach-aquifer conductance
4050 real(DP), intent(in), optional :: hsfr !< stream stage
4051 real(DP), intent(in), optional :: h_temp !< head in gw cell
4052 ! -- local
4053 integer(I4B) :: node
4054 real(DP) :: wp
4055 real(DP) :: vscratio
4056 !
4057 ! -- initialize conductance
4058 cond = dzero
4059 !
4060 ! -- initial viscosity ratio to 1
4061 vscratio = done
4062 !
4063 ! -- calculate conductance if GWF cell is active
4064 ! rch-gwf flow will not occur if reach connected to an constant head cell
4065 node = this%igwfnode(n)
4066 if (node > 0) then
4067 if (this%ibound(node) > 0) then
4068 !
4069 ! -- direction of gradient across streambed determines which vsc ratio
4070 if (this%ivsc == 1) then
4071 if (hsfr > h_temp) then
4072 ! strm stg > gw head
4073 vscratio = this%viscratios(1, n)
4074 else
4075 vscratio = this%viscratios(2, n)
4076 end if
4077 end if
4078 wp = this%calc_perimeter_wet(n, depth)
4079 cond = this%hk(n) * vscratio * this%length(n) * wp / this%bthick(n)
4080 end if
4081 end if
4082 end subroutine sfr_calc_cond
4083
4084 !> @brief Calculate diversion flow
4085 !!
4086 !! Method to calculate the diversion flow for a diversion connected
4087 !! to a SFR package reach. The downstream flow for a reach is passed
4088 !! in and adjusted by the diversion flow amount calculated in this
4089 !! method.
4090 !<
4091 subroutine sfr_calc_div(this, n, i, qd, qdiv)
4092 ! -- dummy
4093 class(sfrtype) :: this !< SfrType object
4094 integer(I4B), intent(in) :: n !< reach number
4095 integer(I4B), intent(in) :: i !< diversion number in reach
4096 real(DP), intent(inout) :: qd !< remaining downstream flow for reach
4097 real(DP), intent(inout) :: qdiv !< diversion flow for diversion i
4098 ! -- local
4099 character(len=10) :: cp
4100 integer(I4B) :: jpos
4101 integer(I4B) :: n2
4102 real(DP) :: v
4103 !
4104 ! -- set local variables
4105 jpos = this%iadiv(n) + i - 1
4106 n2 = this%divreach(jpos)
4107 cp = this%divcprior(jpos)
4108 v = this%divflow(jpos)
4109 !
4110 ! -- calculate diversion
4111 select case (cp)
4112 ! -- flood diversion
4113 case ('EXCESS')
4114 if (qd < v) then
4115 v = dzero
4116 else
4117 v = qd - v
4118 end if
4119 ! -- diversion percentage
4120 case ('FRACTION')
4121 v = qd * v
4122 ! -- STR priority algorithm
4123 case ('THRESHOLD')
4124 if (qd < v) then
4125 v = dzero
4126 end if
4127 ! -- specified diversion
4128 case ('UPTO')
4129 if (v > qd) then
4130 v = qd
4131 end if
4132 case default
4133 v = dzero
4134 end select
4135 !
4136 ! -- update upstream from for downstream reaches
4137 qd = qd - v
4138 qdiv = v
4139 end subroutine sfr_calc_div
4140
4141 !> @brief Calculate the depth at the midpoint
4142 !!
4143 !! Method to calculate the depth at the midpoint of a reach.
4144 !<
4145 subroutine sfr_calc_reach_depth(this, n, q1, d1)
4146 ! -- dummy
4147 class(sfrtype) :: this !< SfrType object
4148 integer(I4B), intent(in) :: n !< reach number
4149 real(DP), intent(in) :: q1 !< streamflow
4150 real(DP), intent(inout) :: d1 !< stream depth at midpoint of reach
4151 ! -- local
4152 real(DP) :: w
4153 real(DP) :: s
4154 real(DP) :: r
4155 real(DP) :: qconst
4156 !
4157 ! -- initialize slope and roughness
4158 s = this%slope(n)
4159 r = this%rough(n)
4160 !
4161 ! -- calculate stream depth at the midpoint
4162 if (q1 > dzero) then
4163 if (this%ncrosspts(n) > 1) then
4164 call this%sfr_calc_xs_depth(n, q1, d1)
4165 else
4166 w = this%station(this%iacross(n))
4167 qconst = this%unitconv * w * sqrt(s) / r
4168 d1 = (q1 / qconst)**dp6
4169 end if
4170 else
4171 d1 = dzero
4172 end if
4173 end subroutine sfr_calc_reach_depth
4174
4175 !> @brief Calculate the depth at the midpoint of a irregular cross-section
4176 !!
4177 !! Method to calculate the depth at the midpoint of a reach with a
4178 !! irregular cross-section using Newton-Raphson.
4179 !<
4180 subroutine sfr_calc_xs_depth(this, n, qrch, d)
4181 ! -- dummy
4182 class(sfrtype) :: this !< SfrType object
4183 integer(I4B), intent(in) :: n !< reach number
4184 real(DP), intent(in) :: qrch !< streamflow
4185 real(DP), intent(inout) :: d !< stream depth at midpoint of reach
4186 ! -- local
4187 integer(I4B) :: iter
4188 real(DP) :: perturbation
4189 real(DP) :: q0
4190 real(DP) :: q1
4191 real(DP) :: dq
4192 real(DP) :: derv
4193 real(DP) :: dd
4194 real(DP) :: residual
4195 !
4196 ! -- initialize variables
4197 perturbation = this%deps * dtwo
4198 d = dzero
4199 q0 = dzero
4200 residual = q0 - qrch
4201 !
4202 ! -- Newton-Raphson iteration
4203 nriter: do iter = 1, this%maxsfrit
4204 call this%sfr_calc_qman(n, d + perturbation, q1)
4205 dq = (q1 - q0)
4206 if (dq /= dzero) then
4207 derv = perturbation / (q1 - q0)
4208 else
4209 derv = dzero
4210 end if
4211 dd = derv * residual
4212 d = d - dd
4213 call this%sfr_calc_qman(n, d, q0)
4214 residual = q0 - qrch
4215 !
4216 ! -- check for convergence
4217 if (abs(dd) < this%dmaxchg) then
4218 exit nriter
4219 end if
4220 end do nriter
4221 end subroutine sfr_calc_xs_depth
4222
4223 !> @brief Check unit conversion data
4224 !!
4225 !! Method to check unit conversion data for a SFR package. This method
4226 !! also calculates unitconv that is used in the Manning's equation.
4227 !<
4228 subroutine sfr_check_conversion(this)
4229 ! -- dummy
4230 class(sfrtype) :: this !< SfrType object
4231 ! -- local
4232 ! -- formats
4233 character(len=*), parameter :: fmtunitconv_error = &
4234 &"('SFR (',a,') UNIT_CONVERSION SPECIFIED VALUE (',g0,') AND', &
4235 &1x,'LENGTH_CONVERSION OR TIME_CONVERSION SPECIFIED.')"
4236 character(len=*), parameter :: fmtunitconv = &
4237 &"(1x,'SFR PACKAGE (',a,') CONVERSION DATA',&
4238 &/4x,'UNIT CONVERSION VALUE (',g0,').',/)"
4239 !
4240 ! -- check the reach data for simple errors
4241 if (this%lengthconv /= dnodata .or. this%timeconv /= dnodata) then
4242 if (this%unitconv /= done) then
4243 write (errmsg, fmtunitconv_error) &
4244 trim(adjustl(this%packName)), this%unitconv
4245 call store_error(errmsg)
4246 else
4247 if (this%lengthconv /= dnodata) then
4248 this%unitconv = this%unitconv * this%lengthconv**donethird
4249 end if
4250 if (this%timeconv /= dnodata) then
4251 this%unitconv = this%unitconv * this%timeconv
4252 end if
4253 write (this%iout, fmtunitconv) &
4254 trim(adjustl(this%packName)), this%unitconv
4255 end if
4256 end if
4257 end subroutine sfr_check_conversion
4258
4259 !> @brief Check storage weight
4260 !!
4261 !! Method to check the kinematic storage weight for a SFR package.
4262 !! If the kinematic storage weight has not been set it is set to
4263 !! the default value.
4264 !<
4265 subroutine sfr_check_storage_weight(this)
4266 ! -- dummy
4267 class(sfrtype) :: this !< SfrType object
4268 ! -- formats
4269 character(len=*), parameter :: fmtweight = &
4270 &"(1x,'SFR PACKAGE (',a,') SETTING DEFAULT',&
4271 &/4x,'STORAGE_WEIGHT VALUE (',g0,').',/)"
4272 !
4273 ! -- set storage weight if it has not been defined yet
4274 if (this%istorage == 1) then
4275 if (this%storage_weight == dnodata) then
4276 this%storage_weight = done
4277 write (this%iout, fmtweight) &
4278 trim(adjustl(this%packName)), this%storage_weight
4279 end if
4280 end if
4281 end subroutine sfr_check_storage_weight
4282
4283 !> @brief Check reach data
4284 !!
4285 !! Method to check specified data for a SFR package. This method
4286 !! also creates the tables used to print input data, if this
4287 !! option in enabled in the SFR package.
4288 !<
4289 subroutine sfr_check_reaches(this)
4290 ! -- dummy
4291 class(sfrtype) :: this !< SfrType object
4292 ! -- local
4293 character(len=5) :: crch
4294 character(len=10) :: cval
4295 character(len=30) :: nodestr
4296 character(len=LINELENGTH) :: title
4297 character(len=LINELENGTH) :: text
4298 integer(I4B) :: n
4299 integer(I4B) :: nn
4300 real(DP) :: btgwf
4301 real(DP) :: bt
4302 !
4303 ! -- setup inputtab tableobj
4304 if (this%iprpak /= 0) then
4305 title = trim(adjustl(this%text))//' PACKAGE ('// &
4306 trim(adjustl(this%packName))//') STATIC REACH DATA'
4307 call table_cr(this%inputtab, this%packName, title)
4308 call this%inputtab%table_df(this%maxbound, 10, this%iout)
4309 text = 'NUMBER'
4310 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4311 text = 'CELLID'
4312 call this%inputtab%initialize_column(text, 20, alignment=tableft)
4313 text = 'LENGTH'
4314 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4315 text = 'WIDTH'
4316 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4317 text = 'SLOPE'
4318 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4319 text = 'TOP'
4320 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4321 text = 'THICKNESS'
4322 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4323 text = 'HK'
4324 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4325 text = 'ROUGHNESS'
4326 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4327 text = 'UPSTREAM FRACTION'
4328 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4329 end if
4330 !
4331 ! -- check the reach data for simple errors
4332 do n = 1, this%maxbound
4333 write (crch, '(i5)') n
4334 nn = this%igwfnode(n)
4335 if (nn > 0) then
4336 btgwf = this%dis%bot(nn)
4337 call this%dis%noder_to_string(nn, nodestr)
4338 else
4339 nodestr = 'none'
4340 end if
4341 ! -- check reach length
4342 if (this%length(n) <= dzero) then
4343 errmsg = 'Reach '//crch//' length must be greater than 0.0.'
4344 call store_error(errmsg)
4345 end if
4346 ! -- check reach width
4347 if (this%width(n) <= dzero) then
4348 errmsg = 'Reach '//crch//' width must be greater than 0.0.'
4349 call store_error(errmsg)
4350 end if
4351 ! -- check reach slope
4352 if (this%slope(n) <= dzero) then
4353 errmsg = 'Reach '//crch//' slope must be greater than 0.0.'
4354 call store_error(errmsg)
4355 end if
4356 ! -- check bed thickness and bed hk for reaches connected to GWF
4357 if (nn > 0) then
4358 bt = this%strtop(n) - this%bthick(n)
4359 if (bt <= btgwf .and. this%icheck /= 0) then
4360 write (cval, '(f10.4)') bt
4361 errmsg = 'Reach '//crch//' bed bottom (rtp-rbth ='// &
4362 cval//') must be greater than the bottom of cell ('// &
4363 nodestr
4364 write (cval, '(f10.4)') btgwf
4365 errmsg = trim(adjustl(errmsg))//'='//cval//').'
4366 call store_error(errmsg)
4367 end if
4368 if (this%hk(n) < dzero) then
4369 errmsg = 'Reach '//crch//' hk must be greater than or equal to 0.0.'
4370 call store_error(errmsg)
4371 end if
4372 end if
4373 ! -- check reach roughness
4374 if (this%rough(n) <= dzero) then
4375 errmsg = 'Reach '//crch//" Manning's roughness "// &
4376 'coefficient must be greater than 0.0.'
4377 call store_error(errmsg)
4378 end if
4379 ! -- check reach upstream fraction
4380 if (this%ustrf(n) < dzero) then
4381 errmsg = 'Reach '//crch//' upstream fraction must be greater '// &
4382 'than or equal to 0.0.'
4383 call store_error(errmsg)
4384 end if
4385 ! -- write summary of reach information
4386 if (this%iprpak /= 0) then
4387 call this%inputtab%add_term(n)
4388 call this%inputtab%add_term(nodestr)
4389 call this%inputtab%add_term(this%length(n))
4390 call this%inputtab%add_term(this%width(n))
4391 call this%inputtab%add_term(this%slope(n))
4392 call this%inputtab%add_term(this%strtop(n))
4393 call this%inputtab%add_term(this%bthick(n))
4394 call this%inputtab%add_term(this%hk(n))
4395 call this%inputtab%add_term(this%rough(n))
4396 call this%inputtab%add_term(this%ustrf(n))
4397 end if
4398 end do
4399 end subroutine sfr_check_reaches
4400
4401 !> @brief Check connection data
4402 !!
4403 !! Method to check connection data for a SFR package. This method
4404 !! also creates the tables used to print input data, if this
4405 !! option in enabled in the SFR package.
4406 !<
4407 subroutine sfr_check_connections(this)
4408 ! -- dummy
4409 class(sfrtype) :: this !< SfrType object
4410 ! -- local
4411 logical(LGP) :: lreorder
4412 character(len=5) :: crch
4413 character(len=5) :: crch2
4414 character(len=LINELENGTH) :: text
4415 character(len=LINELENGTH) :: title
4416 integer(I4B) :: n
4417 integer(I4B) :: nn
4418 integer(I4B) :: nc
4419 integer(I4B) :: i
4420 integer(I4B) :: ii
4421 integer(I4B) :: j
4422 integer(I4B) :: ifound
4423 integer(I4B) :: ierr
4424 integer(I4B) :: maxconn
4425 integer(I4B) :: ntabcol
4426 !
4427 ! -- determine if the reaches have been reordered
4428 lreorder = .false.
4429 do j = 1, this%MAXBOUND
4430 n = this%isfrorder(j)
4431 if (n /= j) then
4432 lreorder = .true.
4433 exit
4434 end if
4435 end do
4436 !
4437 ! -- write message that the solution order h
4438 if (lreorder) then
4439 write (this%iout, '(/,1x,a)') &
4440 trim(adjustl(this%text))//' PACKAGE ('// &
4441 trim(adjustl(this%packName))//') REACH SOLUTION HAS BEEN '// &
4442 'REORDERED USING A DAG'
4443 !
4444 ! -- print table
4445 if (this%iprpak /= 0) then
4446 !
4447 ! -- reset the input table object
4448 ntabcol = 2
4449 title = trim(adjustl(this%text))//' PACKAGE ('// &
4450 trim(adjustl(this%packName))//') REACH SOLUTION ORDER'
4451 call table_cr(this%inputtab, this%packName, title)
4452 call this%inputtab%table_df(this%maxbound, ntabcol, this%iout)
4453 text = 'ORDER'
4454 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4455 text = 'REACH'
4456 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4457 !
4458 ! -- upstream connection data
4459 do j = 1, this%maxbound
4460 n = this%isfrorder(j)
4461 call this%inputtab%add_term(j)
4462 call this%inputtab%add_term(n)
4463 end do
4464 end if
4465 end if
4466 !
4467 ! -- create input table for reach connections data
4468 if (this%iprpak /= 0) then
4469 !
4470 ! -- calculate the maximum number of connections
4471 maxconn = 0
4472 do n = 1, this%maxbound
4473 maxconn = max(maxconn, this%nconnreach(n))
4474 end do
4475 ntabcol = 1 + maxconn
4476 !
4477 ! -- reset the input table object
4478 title = trim(adjustl(this%text))//' PACKAGE ('// &
4479 trim(adjustl(this%packName))//') STATIC REACH CONNECTION DATA'
4480 call table_cr(this%inputtab, this%packName, title)
4481 call this%inputtab%table_df(this%maxbound, ntabcol, this%iout)
4482 text = 'REACH'
4483 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4484 do n = 1, maxconn
4485 write (text, '(a,1x,i6)') 'CONN', n
4486 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4487 end do
4488 end if
4489 !
4490 ! -- verify every listed connection is reciprocated: if reach n lists
4491 ! -- reach nn, reach nn must list reach n back
4492 do n = 1, this%MAXBOUND
4493 write (crch, '(i5)') n
4494 eachconn: do i = this%ia(n) + 1, this%ia(n + 1) - 1
4495 nn = this%ja(i)
4496 write (crch2, '(i5)') nn
4497 ifound = 0
4498 connreach: do ii = this%ia(nn) + 1, this%ia(nn + 1) - 1
4499 nc = this%ja(ii)
4500 if (nc == n) then
4501 ifound = 1
4502 exit connreach
4503 end if
4504 end do connreach
4505 if (ifound /= 1) then
4506 errmsg = 'Reach '//crch//' is connected to '// &
4507 'reach '//crch2//' but reach '//crch2// &
4508 ' is not connected to reach '//crch//'.'
4509 call store_error(errmsg)
4510 end if
4511 end do eachconn
4512 !
4513 ! -- write connection data to the table
4514 if (this%iprpak /= 0) then
4515 call this%inputtab%add_term(n)
4516 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4517 call this%inputtab%add_term(this%ja(i))
4518 end do
4519 nn = maxconn - this%nconnreach(n)
4520 do i = 1, nn
4521 call this%inputtab%add_term(' ')
4522 end do
4523 end if
4524 end do
4525 !
4526 ! -- verify upstream connections don't form a mutual pair: two reaches
4527 ! -- cannot each list the other as upstream
4528 ierr = 0
4529 do n = 1, this%maxbound
4530 write (crch, '(i5)') n
4531 eachconnv: do i = this%ia(n) + 1, this%ia(n + 1) - 1
4532 !
4533 ! -- skip downstream connections
4534 if (this%idir(i) < 0) cycle eachconnv
4535 nn = this%ja(i)
4536 write (crch2, '(i5)') nn
4537 connreachv: do ii = this%ia(nn) + 1, this%ia(nn + 1) - 1
4538 ! -- skip downstream connections
4539 if (this%idir(ii) < 0) cycle connreachv
4540 nc = this%ja(ii)
4541 !
4542 ! -- if nc == n then that means reach n is an upstream connection for
4543 ! reach nn and reach nn is an upstream connection for reach n
4544 if (nc == n) then
4545 ierr = ierr + 1
4546 errmsg = 'Reach '//crch//' is connected to '// &
4547 'reach '//crch2//' but streamflow from reach '// &
4548 crch//' to reach '//crch2//' is not permitted.'
4549 call store_error(errmsg)
4550 exit connreachv
4551 end if
4552 end do connreachv
4553 end do eachconnv
4554 end do
4555 !
4556 ! -- terminate if connectivity errors
4557 if (count_errors() > 0) then
4558 call store_error_filename(this%input_fname)
4559 end if
4560 !
4561 ! -- check that downstream reaches for a reach are
4562 ! the upstream reaches for the reach
4563 do n = 1, this%maxbound
4564 write (crch, '(i5)') n
4565 eachconnds: do i = this%ia(n) + 1, this%ia(n + 1) - 1
4566 nn = this%ja(i)
4567 if (this%idir(i) > 0) cycle eachconnds
4568 write (crch2, '(i5)') nn
4569 ifound = 0
4570 connreachds: do ii = this%ia(nn) + 1, this%ia(nn + 1) - 1
4571 nc = this%ja(ii)
4572 if (nc == n) then
4573 if (this%idir(i) /= this%idir(ii)) then
4574 ifound = 1
4575 end if
4576 exit connreachds
4577 end if
4578 end do connreachds
4579 if (ifound /= 1) then
4580 errmsg = 'Reach '//crch//' downstream connected reach '// &
4581 'is reach '//crch2//' but reach '//crch//' is not'// &
4582 ' the upstream connected reach for reach '//crch2//'.'
4583 call store_error(errmsg)
4584 end if
4585 end do eachconnds
4586 end do
4587 !
4588 ! -- create input table for upstream and downstream connections
4589 if (this%iprpak /= 0) then
4590 !
4591 ! -- calculate the maximum number of upstream connections
4592 maxconn = 0
4593 do n = 1, this%maxbound
4594 ii = 0
4595 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4596 if (this%idir(i) > 0) then
4597 ii = ii + 1
4598 end if
4599 end do
4600 maxconn = max(maxconn, ii)
4601 end do
4602 ntabcol = 1 + maxconn
4603 !
4604 ! -- reset the input table object
4605 title = trim(adjustl(this%text))//' PACKAGE ('// &
4606 trim(adjustl(this%packName))//') STATIC UPSTREAM REACH '// &
4607 'CONNECTION DATA'
4608 call table_cr(this%inputtab, this%packName, title)
4609 call this%inputtab%table_df(this%maxbound, ntabcol, this%iout)
4610 text = 'REACH'
4611 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4612 do n = 1, maxconn
4613 write (text, '(a,1x,i6)') 'UPSTREAM CONN', n
4614 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4615 end do
4616 !
4617 ! -- upstream connection data
4618 do n = 1, this%maxbound
4619 call this%inputtab%add_term(n)
4620 ii = 0
4621 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4622 if (this%idir(i) > 0) then
4623 call this%inputtab%add_term(this%ja(i))
4624 ii = ii + 1
4625 end if
4626 end do
4627 nn = maxconn - ii
4628 do i = 1, nn
4629 call this%inputtab%add_term(' ')
4630 end do
4631 end do
4632 !
4633 ! -- calculate the maximum number of downstream connections
4634 maxconn = 0
4635 do n = 1, this%maxbound
4636 ii = 0
4637 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4638 if (this%idir(i) < 0) then
4639 ii = ii + 1
4640 end if
4641 end do
4642 maxconn = max(maxconn, ii)
4643 end do
4644 ntabcol = 1 + maxconn
4645 !
4646 ! -- reset the input table object
4647 title = trim(adjustl(this%text))//' PACKAGE ('// &
4648 trim(adjustl(this%packName))//') STATIC DOWNSTREAM '// &
4649 'REACH CONNECTION DATA'
4650 call table_cr(this%inputtab, this%packName, title)
4651 call this%inputtab%table_df(this%maxbound, ntabcol, this%iout)
4652 text = 'REACH'
4653 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4654 do n = 1, maxconn
4655 write (text, '(a,1x,i6)') 'DOWNSTREAM CONN', n
4656 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4657 end do
4658 !
4659 ! -- downstream connection data
4660 do n = 1, this%maxbound
4661 call this%inputtab%add_term(n)
4662 ii = 0
4663 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4664 if (this%idir(i) < 0) then
4665 call this%inputtab%add_term(this%ja(i))
4666 ii = ii + 1
4667 end if
4668 end do
4669 nn = maxconn - ii
4670 do i = 1, nn
4671 call this%inputtab%add_term(' ')
4672 end do
4673 end do
4674 end if
4675 end subroutine sfr_check_connections
4676
4677 !> @brief Check diversions data
4678 !!
4679 !! Method to check diversion data for a SFR package. This method
4680 !! also creates the tables used to print input data, if this
4681 !! option in enabled in the SFR package.
4682 !<
4683 subroutine sfr_check_diversions(this)
4684 ! -- dummy
4685 class(sfrtype) :: this !< SfrType object
4686 ! -- local
4687 character(len=LINELENGTH) :: title
4688 character(len=LINELENGTH) :: text
4689 character(len=5) :: crch
4690 character(len=5) :: cdiv
4691 character(len=5) :: crch2
4692 character(len=10) :: cprior
4693 integer(I4B) :: maxdiv
4694 integer(I4B) :: n
4695 integer(I4B) :: nn
4696 integer(I4B) :: nc
4697 integer(I4B) :: ii
4698 integer(I4B) :: idiv
4699 integer(I4B) :: ifound
4700 integer(I4B) :: jpos
4701 ! -- format
470210 format('Diversion ', i0, ' of reach ', i0, &
4703 ' is invalid or has not been defined.')
4704 !
4705 ! -- write header
4706 if (this%iprpak /= 0) then
4707 !
4708 ! -- determine the maximum number of diversions
4709 maxdiv = 0
4710 do n = 1, this%maxbound
4711 maxdiv = maxdiv + this%ndiv(n)
4712 end do
4713 !
4714 ! -- reset the input table object
4715 title = trim(adjustl(this%text))//' PACKAGE ('// &
4716 trim(adjustl(this%packName))//') REACH DIVERSION DATA'
4717 call table_cr(this%inputtab, this%packName, title)
4718 call this%inputtab%table_df(maxdiv, 4, this%iout)
4719 text = 'REACH'
4720 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4721 text = 'DIVERSION'
4722 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4723 text = 'REACH 2'
4724 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4725 text = 'CPRIOR'
4726 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4727 end if
4728 !
4729 ! -- check that diversion data are correct
4730 do n = 1, this%maxbound
4731 if (this%ndiv(n) < 1) cycle
4732 write (crch, '(i5)') n
4733
4734 do idiv = 1, this%ndiv(n)
4735 !
4736 ! -- determine diversion index
4737 jpos = this%iadiv(n) + idiv - 1
4738 !
4739 ! -- write idiv to cdiv
4740 write (cdiv, '(i5)') idiv
4741 !
4742 !
4743 nn = this%divreach(jpos)
4744 write (crch2, '(i5)') nn
4745 !
4746 ! -- make sure diversion reach is connected to current reach
4747 ifound = 0
4748 if (nn < 1 .or. nn > this%maxbound) then
4749 write (errmsg, 10) idiv, n
4750 call store_error(errmsg)
4751 cycle
4752 end if
4753 connreach: do ii = this%ia(nn) + 1, this%ia(nn + 1) - 1
4754 nc = this%ja(ii)
4755 if (nc == n) then
4756 if (this%idir(ii) > 0) then
4757 ifound = 1
4758 end if
4759 exit connreach
4760 end if
4761 end do connreach
4762 if (ifound /= 1) then
4763 errmsg = 'Reach '//crch//' is not a upstream reach for '// &
4764 'reach '//crch2//' as a result diversion '//cdiv// &
4765 ' from reach '//crch//' to reach '//crch2// &
4766 ' is not possible. Check reach connectivity.'
4767 call store_error(errmsg)
4768 end if
4769 ! -- iprior
4770 cprior = this%divcprior(jpos)
4771 !
4772 ! -- add terms to the table
4773 if (this%iprpak /= 0) then
4774 call this%inputtab%add_term(n)
4775 call this%inputtab%add_term(idiv)
4776 call this%inputtab%add_term(nn)
4777 call this%inputtab%add_term(cprior)
4778 end if
4779 end do
4780 end do
4781 end subroutine sfr_check_diversions
4782
4783 !> @brief Check initial stage data
4784 !!
4785 !! Method to check initial data for a SFR package and calculates
4786 !! the initial upstream and downstream flows for the reach based
4787 !! on the initial staalso creates the tables used to print input
4788 !! data, if this option in enabled in the SFR package.
4789 !<
4790 subroutine sfr_check_initialstages(this)
4791 class(sfrtype) :: this !< SfrType object
4792
4793 character(len=LINELENGTH) :: title
4794 character(len=LINELENGTH) :: text
4795 character(len=5) :: crch
4796 integer(I4B) :: n
4797 real(DP) :: qman
4798 real(DP) :: d
4799
4800 ! skip check if storage is not activated
4801 if (this%istorage == 0) return
4802
4803 ! write header
4804 if (this%iprpak /= 0) then
4805 !
4806 ! -- reset the input table object
4807 title = trim(adjustl(this%text))//' PACKAGE ('// &
4808 trim(adjustl(this%packName))//') REACH INITIAL STAGE DATA'
4809 call table_cr(this%inputtab, this%packName, title)
4810 call this%inputtab%table_df(this%maxbound, 4, this%iout)
4811 text = 'REACH'
4812 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4813 text = 'INITIAL STAGE'
4814 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4815 text = 'INITIAL DEPTH'
4816 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4817 text = 'INITIAL FLOW'
4818 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4819 end if
4820 !
4821 ! -- check that data are correct
4822 do n = 1, this%maxbound
4823 write (crch, '(i5)') n
4824
4825 ! calculate the initial flows
4826 call this%sfr_calc_qman(n, this%depth(n), qman)
4827 this%usinflow(n) = qman
4828 this%dsflow(n) = qman
4829 call this%sfr_calc_reach_depth(n, qman, d)
4830 this%xsaus(n) = this%calc_area_wet(n, d)
4831 this%xsads(n) = this%xsaus(n)
4832
4833 ! add terms to the table
4834 if (this%iprpak /= 0) then
4835 call this%inputtab%add_term(n)
4836 call this%inputtab%add_term(this%stage(n))
4837 call this%inputtab%add_term(this%depth(n))
4838 call this%inputtab%add_term(qman)
4839 end if
4840 end do
4841 end subroutine sfr_check_initialstages
4842
4843 !> @brief Check upstream fraction data
4844 !!
4845 !! Method to check upstream fraction data for a SFR package.
4846 !! This method also creates the tables used to print input data,
4847 !! if this option in enabled in the SFR package.
4848 !<
4849 subroutine sfr_check_ustrf(this)
4850 ! -- dummy
4851 class(sfrtype) :: this !< SfrType object
4852 ! -- local
4853 character(len=LINELENGTH) :: title
4854 character(len=LINELENGTH) :: text
4855 logical(LGP) :: lcycle
4856 logical(LGP) :: ladd
4857 character(len=5) :: crch
4858 character(len=5) :: crch2
4859 character(len=10) :: cval
4860 integer(I4B) :: maxcols
4861 integer(I4B) :: npairs
4862 integer(I4B) :: ipair
4863 integer(I4B) :: i
4864 integer(I4B) :: n
4865 integer(I4B) :: n2
4866 integer(I4B) :: idiv
4867 integer(I4B) :: i0
4868 integer(I4B) :: i1
4869 integer(I4B) :: jpos
4870 integer(I4B) :: ids
4871 real(DP) :: f
4872 real(DP) :: rval
4873 !
4874 ! -- write table header
4875 if (this%iprpak /= 0) then
4876 !
4877 ! -- determine the maximum number of columns
4878 npairs = 0
4879 do n = 1, this%maxbound
4880 ipair = 0
4881 ec: do i = this%ia(n) + 1, this%ia(n + 1) - 1
4882 !
4883 ! -- skip upstream connections
4884 if (this%idir(i) > 0) cycle ec
4885 n2 = this%ja(i)
4886 !
4887 ! -- skip inactive downstream reaches
4888 if (this%iboundpak(n2) == 0) cycle ec
4889 !
4890 ! -- increment ipair and see if it exceeds npairs
4891 ipair = ipair + 1
4892 npairs = max(npairs, ipair)
4893 end do ec
4894 end do
4895 maxcols = 1 + npairs * 2
4896 !
4897 ! -- reset the input table object
4898 title = trim(adjustl(this%text))//' PACKAGE ('// &
4899 trim(adjustl(this%packName))//') CONNECTED REACH UPSTREAM '// &
4900 'FRACTION DATA'
4901 call table_cr(this%inputtab, this%packName, title)
4902 call this%inputtab%table_df(this%maxbound, maxcols, this%iout)
4903 text = 'REACH'
4904 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4905 do i = 1, npairs
4906 write (cval, '(i10)') i
4907 text = 'DOWNSTREAM REACH '//trim(adjustl(cval))
4908 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4909 text = 'FRACTION '//trim(adjustl(cval))
4910 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4911 end do
4912 end if
4913 !
4914 ! -- fill diversion number for each connection
4915 do n = 1, this%maxbound
4916 do idiv = 1, this%ndiv(n)
4917 i0 = this%iadiv(n)
4918 i1 = this%iadiv(n + 1) - 1
4919 do jpos = i0, i1
4920 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4921 n2 = this%ja(i)
4922 if (this%divreach(jpos) == n2) then
4923 this%idiv(i) = jpos - i0 + 1
4924 exit
4925 end if
4926 end do
4927 end do
4928 end do
4929 end do
4930 !
4931 ! -- check that the upstream fraction for reach connected by
4932 ! a diversion is zero
4933 do n = 1, this%maxbound
4934 !
4935 ! -- determine the number of downstream reaches
4936 ids = 0
4937 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4938 if (this%idir(i) < 0) then
4939 ids = ids + 1
4940 end if
4941 end do
4942 !
4943 ! -- evaluate the diversions
4944 do idiv = 1, this%ndiv(n)
4945 jpos = this%iadiv(n) + idiv - 1
4946 n2 = this%divreach(jpos)
4947 f = this%ustrf(n2)
4948 if (f /= dzero) then
4949 write (errmsg, '(a,2(1x,i0,1x,a),1x,a,g0,a,2(1x,a))') &
4950 'Reach', n, 'is connected to reach', n2, 'by a diversion', &
4951 'but the upstream fraction is not equal to zero (', f, '). Check', &
4952 trim(this%packName), 'package diversion and package data.'
4953 if (ids > 1) then
4954 call store_error(errmsg)
4955 else
4956 write (warnmsg, '(a,3(1x,a))') &
4957 trim(warnmsg), &
4958 'A warning instead of an error is issued because', &
4959 'the reach is only connected to the diversion reach in the ', &
4960 'downstream direction.'
4961 call store_warning(warnmsg)
4962 end if
4963 end if
4964 end do
4965 end do
4966 !
4967 ! -- calculate the total fraction of connected reaches that are
4968 ! not diversions and check that the sum of upstream fractions
4969 ! is equal to 1 for each reach
4970 do n = 1, this%maxbound
4971 ids = 0
4972 rval = dzero
4973 f = dzero
4974 write (crch, '(i5)') n
4975 if (this%iprpak /= 0) then
4976 call this%inputtab%add_term(n)
4977 end if
4978 ipair = 0
4979 eachconn: do i = this%ia(n) + 1, this%ia(n + 1) - 1
4980 lcycle = .false.
4981 !
4982 ! -- initialize downstream connection q
4983 this%qconn(i) = dzero
4984 !
4985 ! -- skip upstream connections
4986 if (this%idir(i) > 0) then
4987 lcycle = .true.
4988 end if
4989 n2 = this%ja(i)
4990 !
4991 ! -- skip inactive downstream reaches
4992 if (this%iboundpak(n2) == 0) then
4993 lcycle = .true.
4994 end if
4995 if (lcycle) then
4996 cycle eachconn
4997 end if
4998 ipair = ipair + 1
4999 write (crch2, '(i5)') n2
5000 ids = ids + 1
5001 ladd = .true.
5002 f = f + this%ustrf(n2)
5003 write (cval, '(f10.4)') this%ustrf(n2)
5004 !
5005 ! -- write upstream fractions
5006 if (this%iprpak /= 0) then
5007 call this%inputtab%add_term(n2)
5008 call this%inputtab%add_term(this%ustrf(n2))
5009 end if
5010 eachdiv: do idiv = 1, this%ndiv(n)
5011 jpos = this%iadiv(n) + idiv - 1
5012 if (this%divreach(jpos) == n2) then
5013 ladd = .false.
5014 exit eachdiv
5015 end if
5016 end do eachdiv
5017 if (ladd) then
5018 rval = rval + this%ustrf(n2)
5019 end if
5020 end do eachconn
5021 this%ftotnd(n) = rval
5022 !
5023 ! -- write remaining table columns
5024 if (this%iprpak /= 0) then
5025 ipair = ipair + 1
5026 do i = ipair, npairs
5027 call this%inputtab%add_term(' ')
5028 call this%inputtab%add_term(' ')
5029 end do
5030 end if
5031 !
5032 ! -- evaluate if an error condition has occurred
5033 ! the sum of fractions is not equal to 1
5034 if (ids /= 0) then
5035 if (abs(f - done) > dem6) then
5036 write (errmsg, '(a,1x,i0,1x,a,g0,a,3(1x,a))') &
5037 'Upstream fractions for reach ', n, 'is not equal to one (', f, &
5038 '). Check', trim(this%packName), 'package reach connectivity and', &
5039 'package data.'
5040 call store_error(errmsg)
5041 end if
5042 end if
5043 end do
5044 end subroutine sfr_check_ustrf
5045
5046 !> @brief Apply a PERIOD setting value to reach n.
5047 !!
5048 !! Shared by sfr_rp and sfr_ad; DIVERSION is handled separately by
5049 !! both callers because its target index requires its own validation.
5050 !<
5051 subroutine sfr_set_period_value(this, i, n, setting)
5052 ! -- dummy
5053 class(sfrtype), intent(inout) :: this
5054 integer(I4B), intent(in) :: i !< row index into input context arrays
5055 integer(I4B), intent(in) :: n !< reach number
5056 character(len=*), intent(in) :: setting !< uppercase mf6varname dispatch key
5057 !
5058 select case (trim(setting))
5059 case ('BEDK')
5060 this%bedk_set(n) = .true.
5061 case ('MANNING')
5062 this%manning_set(n) = .true.
5063 case ('UPSTREAM_FRAC')
5064 this%ustrf_set(n) = .true.
5065 end select
5066 end subroutine sfr_set_period_value
5067
5068 !> @brief Setup budget object for package
5069 !!
5070 !! Method to set up the budget object that stores all the sfr flows
5071 !! The terms listed here must correspond in number and order to the ones
5072 !! listed in the sfr_fill_budobj method.
5073 !<
5074 subroutine sfr_setup_budobj(this)
5075 ! -- dummy
5076 class(sfrtype) :: this !< SfrType object
5077 ! -- local
5078 integer(I4B) :: nbudterm
5079 integer(I4B) :: i
5080 integer(I4B) :: n
5081 integer(I4B) :: n1
5082 integer(I4B) :: n2
5083 integer(I4B) :: maxlist
5084 integer(I4B) :: naux
5085 integer(I4B) :: idx
5086 real(DP) :: q
5087 character(len=LENBUDTXT) :: text
5088 character(len=LENBUDTXT), dimension(1) :: auxtxt
5089 !
5090 ! -- Determine the number of sfr budget terms. These are fixed for
5091 ! the simulation and cannot change. This includes FLOW-JA-FACE
5092 ! so they can be written to the binary budget files, but these internal
5093 ! flows are not included as part of the budget table.
5094 nbudterm = 8
5095 if (this%imover == 1) nbudterm = nbudterm + 2
5096 if (this%naux > 0) nbudterm = nbudterm + 1
5097 !
5098 ! -- set up budobj
5099 call budgetobject_cr(this%budobj, this%packName)
5100 call this%budobj%budgetobject_df(this%maxbound, nbudterm, 0, 0, &
5101 ibudcsv=this%ibudcsv)
5102 idx = 0
5103 !
5104 ! -- Go through and set up each budget term
5105 text = ' FLOW-JA-FACE'
5106 idx = idx + 1
5107 maxlist = this%nconn
5108 naux = 1
5109 auxtxt(1) = ' FLOW-AREA'
5110 call this%budobj%budterm(idx)%initialize(text, &
5111 this%name_model, &
5112 this%packName, &
5113 this%name_model, &
5114 this%packName, &
5115 maxlist, .false., .false., &
5116 naux, auxtxt)
5117 !
5118 ! -- store connectivity
5119 call this%budobj%budterm(idx)%reset(this%nconn)
5120 q = dzero
5121 do n = 1, this%maxbound
5122 n1 = n
5123 do i = this%ia(n) + 1, this%ia(n + 1) - 1
5124 n2 = this%ja(i)
5125 call this%budobj%budterm(idx)%update_term(n1, n2, q)
5126 end do
5127 end do
5128 !
5129 ! --
5130 text = ' GWF'
5131 idx = idx + 1
5132 maxlist = this%maxbound - this%ianynone
5133 naux = 1
5134 auxtxt(1) = ' FLOW-AREA'
5135 call this%budobj%budterm(idx)%initialize(text, &
5136 this%name_model, &
5137 this%packName, &
5138 this%name_model, &
5139 this%name_model, &
5140 maxlist, .false., .true., &
5141 naux, auxtxt)
5142 call this%budobj%budterm(idx)%reset(maxlist)
5143 q = dzero
5144 do n = 1, this%maxbound
5145 n2 = this%igwfnode(n)
5146 if (n2 > 0) then
5147 call this%budobj%budterm(idx)%update_term(n, n2, q)
5148 end if
5149 end do
5150 !
5151 ! --
5152 text = ' RAINFALL'
5153 idx = idx + 1
5154 maxlist = this%maxbound
5155 naux = 0
5156 call this%budobj%budterm(idx)%initialize(text, &
5157 this%name_model, &
5158 this%packName, &
5159 this%name_model, &
5160 this%packName, &
5161 maxlist, .false., .false., &
5162 naux)
5163 !
5164 ! --
5165 text = ' EVAPORATION'
5166 idx = idx + 1
5167 maxlist = this%maxbound
5168 naux = 0
5169 call this%budobj%budterm(idx)%initialize(text, &
5170 this%name_model, &
5171 this%packName, &
5172 this%name_model, &
5173 this%packName, &
5174 maxlist, .false., .false., &
5175 naux)
5176 !
5177 ! --
5178 text = ' RUNOFF'
5179 idx = idx + 1
5180 maxlist = this%maxbound
5181 naux = 0
5182 call this%budobj%budterm(idx)%initialize(text, &
5183 this%name_model, &
5184 this%packName, &
5185 this%name_model, &
5186 this%packName, &
5187 maxlist, .false., .false., &
5188 naux)
5189 !
5190 ! --
5191 text = ' EXT-INFLOW'
5192 idx = idx + 1
5193 maxlist = this%maxbound
5194 naux = 0
5195 call this%budobj%budterm(idx)%initialize(text, &
5196 this%name_model, &
5197 this%packName, &
5198 this%name_model, &
5199 this%packName, &
5200 maxlist, .false., .false., &
5201 naux)
5202 !
5203 ! --
5204 text = ' EXT-OUTFLOW'
5205 idx = idx + 1
5206 maxlist = this%maxbound
5207 naux = 0
5208 call this%budobj%budterm(idx)%initialize(text, &
5209 this%name_model, &
5210 this%packName, &
5211 this%name_model, &
5212 this%packName, &
5213 maxlist, .false., .false., &
5214 naux)
5215 !
5216 ! --
5217 text = ' STORAGE'
5218 idx = idx + 1
5219 maxlist = this%maxbound
5220 naux = 1
5221 auxtxt(1) = ' VOLUME'
5222 call this%budobj%budterm(idx)%initialize(text, &
5223 this%name_model, &
5224 this%packName, &
5225 this%name_model, &
5226 this%packName, &
5227 maxlist, .false., .false., &
5228 naux, auxtxt)
5229 !
5230 ! --
5231 if (this%imover == 1) then
5232 !
5233 ! --
5234 text = ' FROM-MVR'
5235 idx = idx + 1
5236 maxlist = this%maxbound
5237 naux = 0
5238 call this%budobj%budterm(idx)%initialize(text, &
5239 this%name_model, &
5240 this%packName, &
5241 this%name_model, &
5242 this%packName, &
5243 maxlist, .false., .false., &
5244 naux)
5245 !
5246 ! --
5247 text = ' TO-MVR'
5248 idx = idx + 1
5249 maxlist = this%maxbound
5250 naux = 0
5251 call this%budobj%budterm(idx)%initialize(text, &
5252 this%name_model, &
5253 this%packName, &
5254 this%name_model, &
5255 this%packName, &
5256 maxlist, .false., .false., &
5257 naux)
5258 end if
5259 !
5260 ! --
5261 naux = this%naux
5262 if (naux > 0) then
5263 !
5264 ! --
5265 text = ' AUXILIARY'
5266 idx = idx + 1
5267 maxlist = this%maxbound
5268 call this%budobj%budterm(idx)%initialize(text, &
5269 this%name_model, &
5270 this%packName, &
5271 this%name_model, &
5272 this%packName, &
5273 maxlist, .false., .false., &
5274 naux, this%auxname)
5275 end if
5276 !
5277 ! -- if sfr flow for each reach are written to the listing file
5278 if (this%iprflow /= 0) then
5279 call this%budobj%flowtable_df(this%iout, cellids='GWF')
5280 end if
5281 end subroutine sfr_setup_budobj
5282
5283 !> @brief Copy flow terms into budget object for package
5284 !!
5285 !! Method to copy flows into the budget object that stores all the sfr flows
5286 !! The terms listed here must correspond in number and order to the ones
5287 !! added in the sfr_setup_budobj method.
5288 !<
5289 subroutine sfr_fill_budobj(this)
5290 ! -- dummy
5291 class(sfrtype) :: this !< SfrType object
5292 ! -- local
5293 integer(I4B) :: naux
5294 integer(I4B) :: i
5295 integer(I4B) :: n
5296 integer(I4B) :: n1
5297 integer(I4B) :: n2
5298 integer(I4B) :: ii
5299 integer(I4B) :: idx
5300 integer(I4B) :: idiv
5301 integer(I4B) :: jpos
5302 real(DP) :: q
5303 real(DP) :: qt
5304 real(DP) :: d
5305 real(DP) :: ca
5306 real(DP) :: a
5307 real(DP) :: wp
5308 real(DP) :: l
5309 !
5310 ! -- initialize counter
5311 idx = 0
5312 !
5313 ! -- FLOW JA FACE
5314 idx = idx + 1
5315 call this%budobj%budterm(idx)%reset(this%nconn)
5316 do n = 1, this%maxbound
5317 n1 = n
5318 q = dzero
5319 ca = dzero
5320 do i = this%ia(n) + 1, this%ia(n + 1) - 1
5321 n2 = this%ja(i)
5322 if (this%iboundpak(n) /= 0) then
5323 ! flow to downstream reaches
5324 if (this%idir(i) < 0) then
5325 qt = this%dsflow(n)
5326 q = -this%qconn(i)
5327 ! flow from upstream reaches
5328 else
5329 qt = this%usflow(n)
5330 do ii = this%ia(n2) + 1, this%ia(n2 + 1) - 1
5331 if (this%idir(ii) > 0) cycle
5332 if (this%ja(ii) /= n) cycle
5333 q = this%qconn(ii)
5334 exit
5335 end do
5336 end if
5337 ! calculate flow area
5338 call this%sfr_calc_reach_depth(n, qt, d)
5339 ca = this%calc_area_wet(n, d)
5340 else
5341 q = dzero
5342 ca = dzero
5343 end if
5344 this%qauxcbc(1) = ca
5345 call this%budobj%budterm(idx)%update_term(n1, n2, q, this%qauxcbc)
5346 end do
5347 end do
5348 !
5349 ! -- GWF (LEAKAGE)
5350 idx = idx + 1
5351 call this%budobj%budterm(idx)%reset(this%maxbound - this%ianynone)
5352 do n = 1, this%maxbound
5353 n2 = this%igwfnode(n)
5354 if (n2 > 0) then
5355 if (this%iboundpak(n) /= 0) then
5356 ! -- calc_perimeter_wet() does not enforce depth dependence
5357 if (this%depth(n) > dzero) then
5358 wp = this%calc_perimeter_wet(n, this%depth(n))
5359 else
5360 wp = dzero
5361 end if
5362 l = this%length(n)
5363 a = wp * l
5364 this%qauxcbc(1) = a
5365 q = -this%gwflow(n)
5366 else
5367 this%qauxcbc(1) = dzero
5368 q = dzero
5369 end if
5370 call this%budobj%budterm(idx)%update_term(n, n2, q, this%qauxcbc)
5371 end if
5372 end do
5373 !
5374 ! -- RAIN
5375 idx = idx + 1
5376 call this%budobj%budterm(idx)%reset(this%maxbound)
5377 do n = 1, this%maxbound
5378 if (this%iboundpak(n) /= 0) then
5379 a = this%calc_surface_area(n)
5380 q = this%rain(n) * a
5381 else
5382 q = dzero
5383 end if
5384 call this%budobj%budterm(idx)%update_term(n, n, q)
5385 end do
5386 !
5387 ! -- EVAPORATION
5388 idx = idx + 1
5389 call this%budobj%budterm(idx)%reset(this%maxbound)
5390 do n = 1, this%maxbound
5391 if (this%iboundpak(n) /= 0) then
5392 q = -this%simevap(n)
5393 else
5394 q = dzero
5395 end if
5396 call this%budobj%budterm(idx)%update_term(n, n, q)
5397 end do
5398 !
5399 ! -- RUNOFF
5400 idx = idx + 1
5401 call this%budobj%budterm(idx)%reset(this%maxbound)
5402 do n = 1, this%maxbound
5403 if (this%iboundpak(n) /= 0) then
5404 q = this%simrunoff(n)
5405 else
5406 q = dzero
5407 end if
5408 call this%budobj%budterm(idx)%update_term(n, n, q)
5409 end do
5410 !
5411 ! -- INFLOW
5412 idx = idx + 1
5413 call this%budobj%budterm(idx)%reset(this%maxbound)
5414 do n = 1, this%maxbound
5415 if (this%iboundpak(n) /= 0) then
5416 q = this%inflow(n)
5417 else
5418 q = dzero
5419 end if
5420 call this%budobj%budterm(idx)%update_term(n, n, q)
5421 end do
5422 !
5423 ! -- EXTERNAL OUTFLOW
5424 idx = idx + 1
5425 call this%budobj%budterm(idx)%reset(this%maxbound)
5426 do n = 1, this%maxbound
5427 q = dzero
5428 if (this%iboundpak(n) /= 0) then
5429 do i = this%ia(n) + 1, this%ia(n + 1) - 1
5430 if (this%idir(i) > 0) cycle
5431 idiv = this%idiv(i)
5432 if (idiv > 0) then
5433 jpos = this%iadiv(n) + idiv - 1
5434 q = q + this%divq(jpos)
5435 else
5436 q = q + this%qconn(i)
5437 end if
5438 end do
5439 q = q - this%dsflow(n)
5440 if (this%imover == 1) then
5441 q = q + this%pakmvrobj%get_qtomvr(n)
5442 end if
5443 else
5444 if (this%imover == 1) then
5445 q = this%pakmvrobj%get_qfrommvr(n)
5446 end if
5447 end if
5448 call this%budobj%budterm(idx)%update_term(n, n, q)
5449 end do
5450 !
5451 ! -- STORAGE
5452 idx = idx + 1
5453 call this%budobj%budterm(idx)%reset(this%maxbound)
5454 do n = 1, this%maxbound
5455 q = dzero
5456 if (this%iboundpak(n) /= 0) then
5457 d = this%depth(n)
5458 a = this%calc_surface_area_wet(n, d)
5459 this%qauxcbc(1) = a * d
5460 if (this%gwfiss == 0 .and. this%istorage == 1) then
5461 q = this%storage(n)
5462 end if
5463 else
5464 q = dzero
5465 this%qauxcbc(1) = dzero
5466 end if
5467 call this%budobj%budterm(idx)%update_term(n, n, q, this%qauxcbc)
5468 end do
5469 !
5470 ! -- MOVER
5471 if (this%imover == 1) then
5472 !
5473 ! -- FROM MOVER
5474 idx = idx + 1
5475 call this%budobj%budterm(idx)%reset(this%maxbound)
5476 do n = 1, this%maxbound
5477 q = dzero
5478 if (this%iboundpak(n) /= 0) then
5479 q = this%pakmvrobj%get_qfrommvr(n)
5480 end if
5481 call this%budobj%budterm(idx)%update_term(n, n, q)
5482 end do
5483 !
5484 ! -- TO MOVER
5485 idx = idx + 1
5486 call this%budobj%budterm(idx)%reset(this%maxbound)
5487 do n = 1, this%maxbound
5488 if (this%iboundpak(n) /= 0) then
5489 q = this%pakmvrobj%get_qtomvr(n)
5490 if (q > dzero) then
5491 q = -q
5492 end if
5493 else
5494 q = dzero
5495 end if
5496 call this%budobj%budterm(idx)%update_term(n, n, q)
5497 end do
5498 end if
5499 !
5500 ! -- AUXILIARY VARIABLES
5501 naux = this%naux
5502 if (naux > 0) then
5503 idx = idx + 1
5504 call this%budobj%budterm(idx)%reset(this%maxbound)
5505 do n = 1, this%maxbound
5506 q = dzero
5507 call this%budobj%budterm(idx)%update_term(n, n, q, this%auxvar(:, n))
5508 end do
5509 end if
5510 !
5511 ! --Terms are filled, now accumulate them for this time step
5512 call this%budobj%accumulate_terms()
5513 end subroutine sfr_fill_budobj
5514
5515 !> @brief Setup stage table object for package
5516 !!
5517 !! Method to set up the table object that is used to write the sfr
5518 !! stage data. The terms listed here must correspond in number and
5519 !! order to the ones written to the stage table in the sfr_ot method.
5520 !<
5521 subroutine sfr_setup_tableobj(this)
5522 ! -- dummy
5523 class(sfrtype) :: this !< SfrType object
5524 ! -- local
5525 integer(I4B) :: nterms
5526 character(len=LINELENGTH) :: title
5527 character(len=LINELENGTH) :: text
5528 !
5529 ! -- setup stage table
5530 if (this%iprhed > 0) then
5531 !
5532 ! -- Determine the number of sfr budget terms. These are fixed for
5533 ! the simulation and cannot change. This includes FLOW-JA-FACE
5534 ! so they can be written to the binary budget files, but these internal
5535 ! flows are not included as part of the budget table.
5536 nterms = 8
5537 if (this%inamedbound == 1) then
5538 nterms = nterms + 1
5539 end if
5540 !
5541 ! -- set up table title
5542 title = trim(adjustl(this%text))//' PACKAGE ('// &
5543 trim(adjustl(this%packName))//') STAGES FOR EACH CONTROL VOLUME'
5544 !
5545 ! -- set up stage tableobj
5546 call table_cr(this%stagetab, this%packName, title)
5547 call this%stagetab%table_df(this%maxbound, nterms, this%iout, &
5548 transient=.true.)
5549 !
5550 ! -- Go through and set up table budget term
5551 if (this%inamedbound == 1) then
5552 text = 'NAME'
5553 call this%stagetab%initialize_column(text, lenboundname, &
5554 alignment=tableft)
5555 end if
5556 !
5557 ! -- reach number
5558 text = 'NUMBER'
5559 call this%stagetab%initialize_column(text, 10, alignment=tabcenter)
5560 !
5561 ! -- cellids
5562 text = 'CELLID'
5563 call this%stagetab%initialize_column(text, 20, alignment=tableft)
5564 !
5565 ! -- reach stage
5566 text = 'STAGE'
5567 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5568 !
5569 ! -- reach depth
5570 text = 'DEPTH'
5571 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5572 !
5573 ! -- reach width
5574 text = 'WIDTH'
5575 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5576 !
5577 ! -- gwf head
5578 text = 'GWF HEAD'
5579 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5580 !
5581 ! -- streambed conductance
5582 text = 'STREAMBED CONDUCTANCE'
5583 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5584 !
5585 ! -- streambed gradient
5586 text = 'STREAMBED GRADIENT'
5587 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5588 end if
5589 !
5590 ! -- setup Courant number table
5591 if (this%istorage == 1) then
5592 nterms = 4
5593 if (this%inamedbound == 1) then
5594 nterms = nterms + 1
5595 end if
5596 !
5597 ! -- set up table title
5598 title = trim(adjustl(this%text))//' PACKAGE ('// &
5599 trim(adjustl(this%packName))//') COURANT NUMBER FOR EACH REACH'
5600 !
5601 ! -- set up Courant tableobj
5602 call table_cr(this%couranttab, this%packName, title)
5603 call this%couranttab%table_df(this%maxbound, nterms, this%iout)
5604 !
5605 if (this%inamedbound == 1) then
5606 text = 'NAME'
5607 call this%couranttab%initialize_column(text, lenboundname, &
5608 alignment=tableft)
5609 end if
5610 !
5611 ! -- reach number
5612 text = 'NUMBER'
5613 call this%couranttab%initialize_column(text, 10, alignment=tabcenter)
5614 !
5615 ! -- minimum Courant number
5616 text = 'MINIMUM'
5617 call this%couranttab%initialize_column(text, 16, alignment=tabcenter)
5618 !
5619 ! -- maximum Courant number
5620 text = 'MAXIMUM'
5621 call this%couranttab%initialize_column(text, 16, alignment=tabcenter)
5622 !
5623 ! -- mean Courant number
5624 text = 'MEAN'
5625 call this%couranttab%initialize_column(text, 16, alignment=tabcenter)
5626 end if
5627 end subroutine sfr_setup_tableobj
5628
5629 ! -- reach geometry functions
5630
5631 !> @brief Calculate wetted area
5632 !!
5633 !! Function to calculate the wetted area for a SFR package reach.
5634 !<
5635 function calc_area_wet(this, n, depth)
5636 ! -- return variable
5637 real(dp) :: calc_area_wet !< wetted area
5638 ! -- dummy
5639 class(sfrtype) :: this !< SfrType object
5640 integer(I4B), intent(in) :: n !< reach number
5641 real(dp), intent(in) :: depth !< reach depth
5642 ! -- local
5643 integer(I4B) :: npts
5644 integer(I4B) :: i0
5645 integer(I4B) :: i1
5646 !
5647 ! -- Calculate wetted area
5648 npts = this%ncrosspts(n)
5649 i0 = this%iacross(n)
5650 i1 = this%iacross(n + 1) - 1
5651 if (npts > 1) then
5652 calc_area_wet = get_cross_section_area(npts, this%station(i0:i1), &
5653 this%xsheight(i0:i1), depth)
5654 else
5655 calc_area_wet = this%station(i0) * depth
5656 end if
5657 end function calc_area_wet
5658
5659 !> @brief Calculate wetted perimeter
5660 !!
5661 !! Function to calculate the wetted perimeter for a SFR package reach.
5662 !<
5663 function calc_perimeter_wet(this, n, depth)
5664 ! -- return variable
5665 real(dp) :: calc_perimeter_wet !< wetted perimeter
5666 ! -- dummy
5667 class(sfrtype) :: this !< SfrType object
5668 integer(I4B), intent(in) :: n !< reach number
5669 real(dp), intent(in) :: depth !< reach depth
5670 ! -- local
5671 integer(I4B) :: npts
5672 integer(I4B) :: i0
5673 integer(I4B) :: i1
5674 !
5675 ! -- Calculate wetted perimeter
5676 npts = this%ncrosspts(n)
5677 i0 = this%iacross(n)
5678 i1 = this%iacross(n + 1) - 1
5679 if (npts > 1) then
5680 calc_perimeter_wet = get_wetted_perimeter(npts, this%station(i0:i1), &
5681 this%xsheight(i0:i1), depth)
5682 else
5683 calc_perimeter_wet = this%station(i0) ! no depth dependence in original implementation
5684 end if
5685 end function calc_perimeter_wet
5686
5687 !> @brief Calculate maximum surface area
5688 !!
5689 !! Function to calculate the maximum surface area for a SFR package reach.
5690 !<
5691 function calc_surface_area(this, n)
5692 ! -- return variable
5693 real(dp) :: calc_surface_area !< surface area
5694 ! -- dummy
5695 class(sfrtype) :: this !< SfrType object
5696 integer(I4B), intent(in) :: n !< reach number
5697 ! -- local
5698 integer(I4B) :: npts
5699 integer(I4B) :: i0
5700 integer(I4B) :: i1
5701 real(dp) :: top_width
5702 !
5703 ! -- Calculate surface area
5704 npts = this%ncrosspts(n)
5705 i0 = this%iacross(n)
5706 i1 = this%iacross(n + 1) - 1
5707 if (npts > 1) then
5708 top_width = get_saturated_topwidth(npts, this%station(i0:i1))
5709 else
5710 top_width = this%station(i0)
5711 end if
5712 calc_surface_area = top_width * this%length(n)
5713 end function calc_surface_area
5714
5715 !> @brief Calculate wetted surface area
5716 !!
5717 !! Function to calculate the wetted surface area for a SFR package reach.
5718 !<
5719 function calc_surface_area_wet(this, n, depth)
5720 ! -- return variable
5721 real(dp) :: calc_surface_area_wet !< wetted surface area
5722 ! -- dummy
5723 class(sfrtype) :: this !< SfrType object
5724 integer(I4B), intent(in) :: n !< reach number
5725 real(dp), intent(in) :: depth !< reach depth
5726 ! -- local
5727 real(dp) :: top_width
5728 !
5729 ! -- Calculate wetted surface area
5730 top_width = this%calc_top_width_wet(n, depth)
5731 calc_surface_area_wet = top_width * this%length(n)
5732 end function calc_surface_area_wet
5733
5734 !> @brief Calculate wetted top width
5735 !!
5736 !! Function to calculate the wetted top width for a SFR package reach.
5737 !<
5738 function calc_top_width_wet(this, n, depth)
5739 ! -- return variable
5740 real(dp) :: calc_top_width_wet !< wetted top width
5741 ! -- dummy
5742 class(sfrtype) :: this !< SfrType object
5743 integer(I4B), intent(in) :: n !< reach number
5744 real(dp), intent(in) :: depth !< reach depth
5745 ! -- local
5746 integer(I4B) :: npts
5747 integer(I4B) :: i0
5748 integer(I4B) :: i1
5749 real(dp) :: sat
5750 !
5751 ! -- Calculate wetted top width
5752 npts = this%ncrosspts(n)
5753 i0 = this%iacross(n)
5754 i1 = this%iacross(n + 1) - 1
5755 sat = scubicsaturation(dem5, dzero, depth, dem5)
5756 if (npts > 1) then
5757 calc_top_width_wet = sat * get_wetted_topwidth(npts, &
5758 this%station(i0:i1), &
5759 this%xsheight(i0:i1), &
5760 depth)
5761 else
5762 calc_top_width_wet = sat * this%station(i0)
5763 end if
5764 end function calc_top_width_wet
5765
5766 !> @brief Activate density terms
5767 !!
5768 !! Method to activate addition of density terms for a SFR package reach.
5769 !<
5770 subroutine sfr_activate_density(this)
5771 ! -- modules
5773 ! -- dummy
5774 class(sfrtype), intent(inout) :: this !< SfrType object
5775 ! -- local
5776 integer(I4B) :: i
5777 integer(I4B) :: j
5778 !
5779 ! -- Set idense and reallocate denseterms to be of size MAXBOUND
5780 this%idense = 1
5781 call mem_reallocate(this%denseterms, 3, this%MAXBOUND, 'DENSETERMS', &
5782 this%memoryPath)
5783 do i = 1, this%maxbound
5784 do j = 1, 3
5785 this%denseterms(j, i) = dzero
5786 end do
5787 end do
5788 write (this%iout, '(/1x,a)') 'DENSITY TERMS HAVE BEEN ACTIVATED FOR SFR &
5789 &PACKAGE: '//trim(adjustl(this%packName))
5790 end subroutine sfr_activate_density
5791
5792 !> @brief Activate viscosity terms
5793 !!
5794 !! Method to activate addition of viscosity terms for exchange
5795 !! with groundwater along a SFR package reach.
5796 !<
5797 subroutine sfr_activate_viscosity(this)
5798 ! -- modules
5800 ! -- dummy
5801 class(sfrtype), intent(inout) :: this !< SfrType object
5802 ! -- local
5803 integer(I4B) :: i
5804 integer(I4B) :: j
5805 !
5806 ! -- Set ivsc and reallocate viscratios to be of size MAXBOUND
5807 this%ivsc = 1
5808 call mem_reallocate(this%viscratios, 2, this%MAXBOUND, 'VISCRATIOS', &
5809 this%memoryPath)
5810 do i = 1, this%maxbound
5811 do j = 1, 2
5812 this%viscratios(j, i) = done
5813 end do
5814 end do
5815 write (this%iout, '(/1x,a)') 'VISCOSITY HAS BEEN ACTIVATED FOR SFR &
5816 &PACKAGE: '//trim(adjustl(this%packName))
5817 end subroutine sfr_activate_viscosity
5818
5819 !> @brief Calculate density terms
5820 !!
5821 !! Method to calculate groundwater-reach density exchange terms for a
5822 !! SFR package reach.
5823 !!
5824 !! Member variable used here
5825 !! denseterms : shape (3, MAXBOUND), filled by buoyancy package
5826 !! col 1 is relative density of sfr (densesfr / denseref)
5827 !! col 2 is relative density of gwf cell (densegwf / denseref)
5828 !! col 3 is elevation of gwf cell
5829 !<
5830 subroutine sfr_calculate_density_exchange(this, n, stage, head, cond, &
5831 tops, flow, gwfhcof, gwfrhs)
5832 ! -- dummy
5833 class(sfrtype), intent(inout) :: this !< SfrType object
5834 integer(I4B), intent(in) :: n !< reach number
5835 real(DP), intent(in) :: stage !< reach stage
5836 real(DP), intent(in) :: head !< head in connected GWF cell
5837 real(DP), intent(in) :: cond !< reach conductance
5838 real(DP), intent(in) :: tops !< top elevation of streambed
5839 real(DP), intent(inout) :: flow !< calculated flow, updated here with density terms
5840 real(DP), intent(inout) :: gwfhcof !< GWF diagonal coefficient, updated here with density terms
5841 real(DP), intent(inout) :: gwfrhs !< GWF right-hand-side value, updated here with density terms
5842 ! -- local
5843 real(DP) :: ss
5844 real(DP) :: hh
5845 real(DP) :: havg
5846 real(DP) :: rdensesfr
5847 real(DP) :: rdensegwf
5848 real(DP) :: rdenseavg
5849 real(DP) :: elevsfr
5850 real(DP) :: elevgwf
5851 real(DP) :: elevavg
5852 real(DP) :: d1
5853 real(DP) :: d2
5854 logical(LGP) :: stage_below_bot
5855 logical(LGP) :: head_below_bot
5856 !
5857 ! -- Set sfr density to sfr density or gwf density
5858 if (stage >= tops) then
5859 ss = stage
5860 stage_below_bot = .false.
5861 rdensesfr = this%denseterms(1, n) ! sfr rel density
5862 else
5863 ss = tops
5864 stage_below_bot = .true.
5865 rdensesfr = this%denseterms(2, n) ! gwf rel density
5866 end if
5867 !
5868 ! -- set hh to head or tops (top elev of streambed)
5869 if (head >= tops) then
5870 hh = head
5871 head_below_bot = .false.
5872 rdensegwf = this%denseterms(2, n) ! gwf rel density
5873 else
5874 hh = tops
5875 head_below_bot = .true.
5876 rdensegwf = this%denseterms(1, n) ! sfr rel density
5877 end if
5878 !
5879 ! -- todo: hack because denseterms not updated in a cf calculation
5880 if (rdensegwf == dzero) return
5881 !
5882 ! -- Update flow
5883 if (stage_below_bot .and. head_below_bot) then
5884 !
5885 ! -- flow is zero, so no terms are updated
5886 !
5887 else
5888 !
5889 ! -- calculate average relative density
5890 rdenseavg = dhalf * (rdensesfr + rdensegwf)
5891 !
5892 ! -- Add contribution of first density term:
5893 ! cond * (denseavg/denseref - 1) * (hgwf - hsfr)
5894 d1 = cond * (rdenseavg - done)
5895 gwfhcof = gwfhcof - d1
5896 gwfrhs = gwfrhs - d1 * ss
5897 d1 = d1 * (hh - ss)
5898 flow = flow + d1
5899 !
5900 ! -- Add second density term if stage and head not below bottom
5901 if (.not. stage_below_bot .and. .not. head_below_bot) then
5902 !
5903 ! -- Add contribution of second density term:
5904 ! cond * (havg - elevavg) * (densegwf - densesfr) / denseref
5905 elevgwf = this%denseterms(3, n)
5906 elevsfr = tops
5907 elevavg = dhalf * (elevsfr + elevgwf)
5908 havg = dhalf * (hh + ss)
5909 d2 = cond * (havg - elevavg) * (rdensegwf - rdensesfr)
5910 gwfrhs = gwfrhs + d2
5911 flow = flow + d2
5912 end if
5913 end if
5914 end subroutine sfr_calculate_density_exchange
5915
5916 !> @brief Bind SfrInputType PERIOD pointers to input context arrays.
5917 !!
5918 !! Called once from sfr_ar; PACKAGEDATA pointers are set separately
5919 !! in sfr_source_packagedata.
5920 !<
5921 subroutine sfr_input_init(this, mempath, naux)
5923 class(sfrinputtype), intent(inout) :: this
5924 character(len=*), intent(in) :: mempath
5925 integer(I4B), intent(in) :: naux
5926 call mem_setptr(this%nbound, 'NBOUND', mempath)
5927 call mem_setptr(this%ifno, 'IFNO', mempath)
5928 call mem_setptr(this%setting, 'SETTING', mempath)
5929 call mem_setptr(this%status, 'STATUS', mempath)
5930 call mem_setptr(this%idv, 'IDV', mempath)
5931 call mem_setptr(this%tab6_filename, 'TAB6_FILENAME', mempath)
5932 if (naux > 0) then
5933 call mem_setptr(this%auxname, 'AUXNAME', mempath)
5934 call mem_setptr(this%auxval, 'AUXVAL', mempath)
5935 end if
5936 end subroutine sfr_input_init
5937
5938 !> @brief Nullify all SfrInputType pointers.
5939 !<
5940 subroutine sfr_input_destroy(this)
5941 class(sfrinputtype), intent(inout) :: this
5942 nullify (this%rhk)
5943 nullify (this%man)
5944 nullify (this%ustrf)
5945 nullify (this%rhk_tslink)
5946 nullify (this%man_tslink)
5947 nullify (this%ustrf_tslink)
5948 nullify (this%nbound)
5949 nullify (this%ifno)
5950 nullify (this%status)
5951 nullify (this%setting)
5952 nullify (this%idv)
5953 nullify (this%tab6_filename)
5954 nullify (this%auxname)
5955 nullify (this%auxval)
5956 end subroutine sfr_input_destroy
5957
5958end module sfrmodule
subroutine init()
This module contains the extended boundary package.
subroutine source_dimensions(this)
Source package dimensions from input context.
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_ar(this)
Allocate and read method for boundary package.
subroutine bnd_rp(this)
Allocate and read method for package.
subroutine bnd_ot_dv(this, idvsave, idvprint)
Output advanced package dependent-variable terms.
subroutine bnd_ot_package_flows(this, icbcfl, ibudfl)
Output advanced package flow terms.
subroutine bnd_cc(this, innertot, kiter, iend, icnvgmod, cpak, ipak, dpak)
Convergence check for 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 bnd_ot_bdsummary(this, kstp, kper, iout, ibudfl)
Output advanced package budget summary.
subroutine bnd_fp(this)
Final processing at end of simulation (no-op by default).
subroutine bnd_df_obs(this)
Define the observation types available in the package.
subroutine bnd_rp_obs(this)
Read and prepare observations for a package.
subroutine bnd_cf(this)
Formulate the package hcof and rhs terms.
subroutine bnd_fn(this, rhs, ia, idxglo, matrix_sln)
Add Newton-Raphson terms for package into solution.
subroutine bnd_ad(this)
Advance the boundary package.
subroutine bnd_dt(this)
Submit an ATS time step request (no-op by default).
subroutine bnd_cq(this, x, flowja, iadv)
Calculate advanced package flows.
subroutine define_listlabel(this)
Define the list label for the package.
This module contains the BudgetModule.
Definition Budget.f90:20
subroutine, public budgetobject_cr(this, name)
Create a new budget object.
subroutine destroy(this)
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 dhdry
real dry cell constant
Definition Constants.f90:94
@ tabcenter
centered table column
@ tabright
right justified table column
@ tableft
left justified table column
@ mnormal
normal output mode
real(dp), parameter dtwothirds
real constant 2/3
Definition Constants.f90:70
integer(i4b), parameter lenpackagename
maximum length of the package name
Definition Constants.f90:23
real(dp), parameter dp9
real constant 9/10
Definition Constants.f90:72
real(dp), parameter deight
real constant 8
Definition Constants.f90:83
real(dp), parameter dfivethirds
real constant 5/3
Definition Constants.f90:78
real(dp), parameter dp999
real constant 999/1000
Definition Constants.f90:74
integer(i4b), parameter namedboundflag
named bound flag
Definition Constants.f90:49
real(dp), parameter donethird
real constant 1/3
Definition Constants.f90:67
real(dp), parameter dnodata
real no data constant
Definition Constants.f90:95
real(dp), parameter d1p1
real constant 1.1
Definition Constants.f90:77
real(dp), parameter dhnoflo
real no flow constant
Definition Constants.f90:93
real(dp), parameter dhundred
real constant 100
Definition Constants.f90:86
integer(i4b), parameter lenpakloc
maximum length of a package location
Definition Constants.f90:50
real(dp), parameter dep20
real constant 1e20
Definition Constants.f90:91
real(dp), parameter dp6
real constant 3/5
Definition Constants.f90:69
integer(i4b), parameter maxadpit
maximum advanced package Newton-Raphson iterations
Definition Constants.f90:53
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition Constants.f90:17
real(dp), parameter dhalf
real constant 1/2
Definition Constants.f90:68
integer(i4b), parameter lenftype
maximum length of a package type (DIS, WEL, OC, etc.)
Definition Constants.f90:39
real(dp), parameter dpi
real constant
real(dp), parameter dp99
real constant 99/100
Definition Constants.f90:73
integer(i4b), parameter lenboundname
maximum length of a bound name
Definition Constants.f90:36
real(dp), parameter dem4
real constant 1e-4
real(dp), parameter dem30
real constant 1e-30
real(dp), parameter dem6
real constant 1e-6
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65
real(dp), parameter dem5
real constant 1e-5
real(dp), parameter dprec
real constant machine precision
integer(i4b), parameter maxcharlen
maximum length of char string
Definition Constants.f90:47
real(dp), parameter dp7
real constant 7/10
Definition Constants.f90:71
real(dp), parameter dem2
real constant 1e-2
real(dp), parameter dtwo
real constant 2
Definition Constants.f90:79
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
real(dp), parameter done
real constant 1
Definition Constants.f90:76
This module contains stateless sfr subroutines and functions.
real(dp) function, public get_wetted_topwidth(npts, stations, heights, d)
Calculate the wetted top width for a reach.
real(dp) function, public get_wetted_perimeter(npts, stations, heights, d)
Calculate the wetted perimeter for a reach.
real(dp) function, public get_cross_section_area(npts, stations, heights, d)
Calculate the cross-sectional area for a reach.
real(dp) function, public get_saturated_topwidth(npts, stations)
Calculate the saturated top width for a reach.
real(dp) function, public get_mannings_section(npts, stations, heights, roughfracs, roughness, conv_fact, slope, d)
Calculate the manning's discharge for a reach.
subroutine, public assign_iounit(iounit, errunit, description)
assign io unit number
subroutine, public extract_idnum_or_bndname(line, icol, istart, istop, idnum, bndname)
Starting at position icol, define string as line(istart:istop).
integer(i4b) function, public getunit()
Get a free unit number.
subroutine, public upcase(word)
Convert to upper case.
subroutine, public ulasav(buf, text, kstp, kper, pertim, totim, ncol, nrow, ilay, ichn)
Save 1 layer array on disk.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
This module defines variable data types.
Definition kind.f90:8
Previous variable names checked in as deprecated aliases.
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
subroutine, public memorystore_release(varname, memory_path)
Release a single variable from the memory store.
subroutine, public get_isize(name, mem_path, isize)
Get the number of elements for this variable.
This module contains the derived types ObserveType and ObsDataType.
Definition Observe.f90:15
character(len=20) access
Definition OpenSpec.f90:7
character(len=20) form
Definition OpenSpec.f90:7
subroutine, public cross_section_cr(this, iout, iprpak, nreaches)
Create a cross-section object.
This module contains the SFR package methods.
Definition gwf-sfr.f90:7
subroutine sfr_source_connectiondata(this)
Source CONNECTIONDATA block from input context.
Definition gwf-sfr.f90:1311
subroutine sfr_source_initialstages(this)
Source INITIALSTAGES block from input context.
Definition gwf-sfr.f90:1649
subroutine sfr_calc_celerity(this, n, q, celerity)
Kinematic-wave celerity from a flow perturbation (0 if dry).
Definition gwf-sfr.f90:2903
real(dp) function calc_top_width_wet(this, n, depth)
Calculate wetted top width.
Definition gwf-sfr.f90:5739
subroutine sfr_precompute_tvd(this)
Pre-compute the single upstream reach index for the TVD limiter.
Definition gwf-sfr.f90:3095
subroutine sfr_setup_tableobj(this)
Setup stage table object for package.
Definition gwf-sfr.f90:5522
subroutine sfr_cc(this, innertot, kiter, iend, icnvgmod, cpak, ipak, dpak)
Convergence check for package.
Definition gwf-sfr.f90:2359
subroutine sfr_cq(this, x, flowja, iadv)
Calculate package flows.
Definition gwf-sfr.f90:2560
subroutine sfr_ot_package_flows(this, icbcfl, ibudfl)
Output package flow terms.
Definition gwf-sfr.f90:2650
subroutine sfr_activate_viscosity(this)
Activate viscosity terms.
Definition gwf-sfr.f90:5798
subroutine sfr_da(this)
Deallocate package memory.
Definition gwf-sfr.f90:2930
subroutine sfr_calc_reach_depth(this, n, q1, d1)
Calculate the depth at the midpoint.
Definition gwf-sfr.f90:4146
real(dp) function calc_surface_area(this, n)
Calculate maximum surface area.
Definition gwf-sfr.f90:5692
subroutine sfr_check_ustrf(this)
Check upstream fraction data.
Definition gwf-sfr.f90:4850
subroutine sfr_source_packagedata(this)
Source PACKAGEDATA block from input context.
Definition gwf-sfr.f90:1045
subroutine sfr_calc_xs_depth(this, n, qrch, d)
Calculate the depth at the midpoint of a irregular cross-section.
Definition gwf-sfr.f90:4181
subroutine sfr_check_diversions(this)
Check diversions data.
Definition gwf-sfr.f90:4684
subroutine sfr_ot_dv(this, idvsave, idvprint)
Output package dependent-variable terms.
Definition gwf-sfr.f90:2703
subroutine, public sfr_create(packobj, id, ibcnum, inunit, iout, namemodel, pakname, mempath)
Create a new package object.
Definition gwf-sfr.f90:394
subroutine sfr_dt(this)
Submit the ATS time step for the most Courant-constraining reach.
Definition gwf-sfr.f90:2865
subroutine sfr_fc(this, rhs, ia, idxglo, matrix_sln)
Copy hcof and rhs terms into solution.
Definition gwf-sfr.f90:2199
subroutine sfr_fn(this, rhs, ia, idxglo, matrix_sln)
Add Newton-Raphson terms for package into solution.
Definition gwf-sfr.f90:2303
subroutine define_listlabel(this)
Define the list label for the package.
Definition gwf-sfr.f90:3126
subroutine sfr_df_obs(this)
Define the observation types available in the package.
Definition gwf-sfr.f90:3170
subroutine sfr_calc_cond(this, n, depth, cond, hsfr, h_temp)
Calculate reach-aquifer conductance.
Definition gwf-sfr.f90:4045
subroutine sfr_check_connections(this)
Check connection data.
Definition gwf-sfr.f90:4408
subroutine sfr_source_options(this)
Source OPTIONS from input context.
Definition gwf-sfr.f90:791
subroutine sfr_input_destroy(this)
Nullify all SfrInputType pointers.
Definition gwf-sfr.f90:5941
subroutine sfr_allocate_arrays(this)
Allocate arrays.
Definition gwf-sfr.f90:509
subroutine sfr_bd_obs(this)
Save observations for the package.
Definition gwf-sfr.f90:3266
subroutine sfr_source_crosssections(this)
Source CROSSSECTIONS block from input context.
Definition gwf-sfr.f90:1221
subroutine sfr_setup_budobj(this)
Setup budget object for package.
Definition gwf-sfr.f90:5075
subroutine sfr_check_initialstages(this)
Check initial stage data.
Definition gwf-sfr.f90:4791
subroutine sfr_rp(this)
Read and prepare period data for package.
Definition gwf-sfr.f90:1819
subroutine sfr_input_init(this, mempath, naux)
Bind SfrInputType PERIOD pointers to input context arrays.
Definition gwf-sfr.f90:5922
subroutine sfr_ar(this)
Allocate and read method for package.
Definition gwf-sfr.f90:1718
subroutine sfr_calc_qman(this, n, depth, qman)
Calculate streamflow.
Definition gwf-sfr.f90:3888
subroutine sfr_fp(this)
Write the Courant-number summary table to the listing file.
Definition gwf-sfr.f90:2830
subroutine sfr_check_reaches(this)
Check reach data.
Definition gwf-sfr.f90:4290
real(dp) function calc_perimeter_wet(this, n, depth)
Calculate wetted perimeter.
Definition gwf-sfr.f90:5664
subroutine sfr_update_flows(this, n, qd, qgwf)
Update flow terms.
Definition gwf-sfr.f90:3697
subroutine sfr_calc_qd(this, n, depth, hgwf, qgwf, qd)
Calculate downstream flow term.
Definition gwf-sfr.f90:3807
subroutine sfr_fill_budobj(this)
Copy flow terms into budget object for package.
Definition gwf-sfr.f90:5290
subroutine sfr_cf(this)
Formulate the package hcof and rhs terms.
Definition gwf-sfr.f90:2171
subroutine sfr_ot_bdsummary(this, kstp, kper, iout, ibudfl)
Output advanced package budget summary.
Definition gwf-sfr.f90:2815
subroutine sfr_calc_div(this, n, i, qd, qdiv)
Calculate diversion flow.
Definition gwf-sfr.f90:4092
subroutine sfr_calc_qgwf(this, n, depth, hgwf, qgwf, gwfhcof, gwfrhs)
Calculate reach-aquifer exchange.
Definition gwf-sfr.f90:3958
character(len=lenftype) ftype
package ftype string
Definition gwf-sfr.f90:50
subroutine sfr_calculate_density_exchange(this, n, stage, head, cond, tops, flow, gwfhcof, gwfrhs)
Calculate density terms.
Definition gwf-sfr.f90:5832
subroutine sfr_source_dimensions(this)
Source DIMENSIONS block from input context and load static data.
Definition gwf-sfr.f90:975
character(len=lenpackagename) text
package budget string
Definition gwf-sfr.f90:51
subroutine sfr_set_period_value(this, i, n, setting)
Apply a PERIOD setting value to reach n.
Definition gwf-sfr.f90:5052
subroutine sfr_calc_qsource(this, n, depth, qsrc)
Calculate sum of sources.
Definition gwf-sfr.f90:3840
subroutine sfr_checkin_deprecated_names(this)
Alias deprecated SFR variable names to their current storage.
Definition gwf-sfr.f90:744
subroutine sfr_allocate_scalars(this)
Allocate scalars.
Definition gwf-sfr.f90:438
logical function sfr_obs_supported(this)
Determine if observations are supported.
Definition gwf-sfr.f90:3158
subroutine sfr_source_diversions(this)
Source DIVERSIONS block from input context.
Definition gwf-sfr.f90:1498
subroutine sfr_check_storage_weight(this)
Check storage weight.
Definition gwf-sfr.f90:4266
subroutine sfr_solve(this, n, h, hcof, rhs, update)
Solve reach continuity equation.
Definition gwf-sfr.f90:3506
real(dp) function calc_area_wet(this, n, depth)
Calculate wetted area.
Definition gwf-sfr.f90:5636
subroutine sfr_rp_obs(this)
Read and prepare observations for a package.
Definition gwf-sfr.f90:3358
subroutine sfr_activate_density(this)
Activate density terms.
Definition gwf-sfr.f90:5771
subroutine sfr_adjust_ro_ev(this, qc, qu, qi, qr, qro, qe, qfrommvr)
Adjust runoff and evaporation.
Definition gwf-sfr.f90:3767
subroutine sfr_check_conversion(this)
Check unit conversion data.
Definition gwf-sfr.f90:4229
real(dp) function calc_surface_area_wet(this, n, depth)
Calculate wetted surface area.
Definition gwf-sfr.f90:5720
integer(i4b) function sfr_gwf_conn(this, n)
Determine if a reach is connected to a gwf cell.
Definition gwf-sfr.f90:4025
subroutine sfr_ad(this)
Advance the package.
Definition gwf-sfr.f90:2069
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public store_warning(msg, substring)
Store warning message.
Definition Sim.f90:241
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 deprecation_warning(cblock, cvar, cver, endmsg, iunit)
Store deprecation warning message.
Definition Sim.f90:261
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) ifailedstepretry
current retry for this time step
character(len=maxcharlen) warnmsg
warning message string
integer(i4b) iout
file unit number for simulation output
real(dp) function squadraticsaturation(top, bot, x, eps)
sQuadraticSaturation
real(dp) function scubicsaturation(top, bot, x, eps)
sCubicSaturation
real(dp) function squadraticsaturationderivative(top, bot, x, eps)
Derivative of the quadratic saturation function.
real(dp) function sqsaturationderivative(top, bot, x, c1, c2)
sQSaturationDerivative
subroutine schsmooth(d, smooth, dwdh)
sChSmooth
real(dp) function sqsaturation(top, bot, x, c1, c2)
sQSaturation
subroutine sort(this, with_csr)
Definition Sparse.f90:218
subroutine finalize(this)
Definition Table.f90:407
subroutine, public table_cr(this, name, title)
Definition Table.f90:87
real(dp), pointer, public pertim
time relative to start of stress period
Definition tdis.f90:33
real(dp), pointer, public totim
time relative to start of simulation
Definition tdis.f90:35
class(atstype), pointer, public ats
Definition tdis.f90:48
integer(i4b), pointer, public inats
flag indicating ats active for simulation
Definition tdis.f90:28
integer(i4b), pointer, public kstp
current time step number
Definition tdis.f90:27
integer(i4b), pointer, public kper
current stress period number
Definition tdis.f90:26
real(dp), pointer, public delt
length of the current time step
Definition tdis.f90:32
Derived type for the Budget object.
Definition Budget.f90:40
This class is used to store a single deferred-length character string. It was designed to work in an ...
Input context array pointers for SFR.
Definition gwf-sfr.f90:62