MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
sfrmodule Module Reference

This module contains the SFR package methods. More...

Data Types

type  sfrinputtype
 Input context array pointers for SFR. More...
type  sfrtype

Functions/Subroutines

subroutine, public sfr_create (packobj, id, ibcnum, inunit, iout, namemodel, pakname, mempath)
 Create a new package object.
subroutine sfr_allocate_scalars (this)
 Allocate scalars.
subroutine sfr_allocate_arrays (this)
 Allocate arrays.
subroutine sfr_checkin_deprecated_names (this)
 Alias deprecated SFR variable names to their current storage.
subroutine sfr_source_options (this)
 Source OPTIONS from input context.
subroutine sfr_source_dimensions (this)
 Source DIMENSIONS block from input context and load static data.
subroutine sfr_source_packagedata (this)
 Source PACKAGEDATA block from input context.
subroutine sfr_source_crosssections (this)
 Source CROSSSECTIONS block from input context.
subroutine sfr_source_connectiondata (this)
 Source CONNECTIONDATA block from input context.
subroutine sfr_source_diversions (this)
 Source DIVERSIONS block from input context.
subroutine sfr_source_initialstages (this)
 Source INITIALSTAGES block from input context.
subroutine sfr_ar (this)
 Allocate and read method for package.
subroutine sfr_rp (this)
 Read and prepare period data for package.
subroutine sfr_ad (this)
 Advance the package.
subroutine sfr_cf (this)
 Formulate the package hcof and rhs terms.
subroutine sfr_fc (this, rhs, ia, idxglo, matrix_sln)
 Copy hcof and rhs terms into solution.
subroutine sfr_fn (this, rhs, ia, idxglo, matrix_sln)
 Add Newton-Raphson terms for package into solution.
subroutine sfr_cc (this, innertot, kiter, iend, icnvgmod, cpak, ipak, dpak)
 Convergence check for package.
subroutine sfr_cq (this, x, flowja, iadv)
 Calculate package flows.
subroutine sfr_ot_package_flows (this, icbcfl, ibudfl)
 Output package flow terms.
subroutine sfr_ot_dv (this, idvsave, idvprint)
 Output package dependent-variable terms.
subroutine sfr_ot_bdsummary (this, kstp, kper, iout, ibudfl)
 Output advanced package budget summary.
subroutine sfr_fp (this)
 Write the Courant-number summary table to the listing file.
subroutine sfr_dt (this)
 Submit the ATS time step for the most Courant-constraining reach.
subroutine sfr_calc_celerity (this, n, q, celerity)
 Kinematic-wave celerity from a flow perturbation (0 if dry).
subroutine sfr_da (this)
 Deallocate package memory.
subroutine sfr_precompute_tvd (this)
 Pre-compute the single upstream reach index for the TVD limiter.
subroutine define_listlabel (this)
 Define the list label for the package.
logical function sfr_obs_supported (this)
 Determine if observations are supported.
subroutine sfr_df_obs (this)
 Define the observation types available in the package.
subroutine sfr_bd_obs (this)
 Save observations for the package.
subroutine sfr_rp_obs (this)
 Read and prepare observations for a package.
subroutine sfr_process_obsid (obsrv, dis, inunitobs, iout)
 Process observation IDs for a package.
subroutine sfr_solve (this, n, h, hcof, rhs, update)
 Solve reach continuity equation.
subroutine sfr_update_flows (this, n, qd, qgwf)
 Update flow terms.
subroutine sfr_adjust_ro_ev (this, qc, qu, qi, qr, qro, qe, qfrommvr)
 Adjust runoff and evaporation.
subroutine sfr_calc_qd (this, n, depth, hgwf, qgwf, qd)
 Calculate downstream flow term.
subroutine sfr_calc_qsource (this, n, depth, qsrc)
 Calculate sum of sources.
subroutine sfr_calc_qman (this, n, depth, qman)
 Calculate streamflow.
subroutine sfr_calc_qgwf (this, n, depth, hgwf, qgwf, gwfhcof, gwfrhs)
 Calculate reach-aquifer exchange.
integer(i4b) function sfr_gwf_conn (this, n)
 Determine if a reach is connected to a gwf cell.
subroutine sfr_calc_cond (this, n, depth, cond, hsfr, h_temp)
 Calculate reach-aquifer conductance.
subroutine sfr_calc_div (this, n, i, qd, qdiv)
 Calculate diversion flow.
subroutine sfr_calc_reach_depth (this, n, q1, d1)
 Calculate the depth at the midpoint.
subroutine sfr_calc_xs_depth (this, n, qrch, d)
 Calculate the depth at the midpoint of a irregular cross-section.
subroutine sfr_check_conversion (this)
 Check unit conversion data.
subroutine sfr_check_storage_weight (this)
 Check storage weight.
subroutine sfr_check_reaches (this)
 Check reach data.
subroutine sfr_check_connections (this)
 Check connection data.
subroutine sfr_check_diversions (this)
 Check diversions data.
subroutine sfr_check_initialstages (this)
 Check initial stage data.
subroutine sfr_check_ustrf (this)
 Check upstream fraction data.
subroutine sfr_set_period_value (this, i, n, setting)
 Apply a PERIOD setting value to reach n.
subroutine sfr_setup_budobj (this)
 Setup budget object for package.
subroutine sfr_fill_budobj (this)
 Copy flow terms into budget object for package.
subroutine sfr_setup_tableobj (this)
 Setup stage table object for package.
real(dp) function calc_area_wet (this, n, depth)
 Calculate wetted area.
real(dp) function calc_perimeter_wet (this, n, depth)
 Calculate wetted perimeter.
real(dp) function calc_surface_area (this, n)
 Calculate maximum surface area.
real(dp) function calc_surface_area_wet (this, n, depth)
 Calculate wetted surface area.
real(dp) function calc_top_width_wet (this, n, depth)
 Calculate wetted top width.
subroutine sfr_activate_density (this)
 Activate density terms.
subroutine sfr_activate_viscosity (this)
 Activate viscosity terms.
subroutine sfr_calculate_density_exchange (this, n, stage, head, cond, tops, flow, gwfhcof, gwfrhs)
 Calculate density terms.
subroutine sfr_input_init (this, mempath, naux)
 Bind SfrInputType PERIOD pointers to input context arrays.
subroutine sfr_input_destroy (this)
 Nullify all SfrInputType pointers.

Variables

character(len=lenftype) ftype = 'SFR'
 package ftype string
character(len=lenpackagename) text = ' SFR'
 package budget string

Detailed Description

This module contains the overridden methods for the streamflow routing (SFR) package. Most of the methods in the base Boundary Package are overridden.

Function/Subroutine Documentation

◆ calc_area_wet()

real(dp) function sfrmodule::calc_area_wet ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) depth )
private

Function to calculate the wetted area for a SFR package reach.

Returns
wetted area
Parameters
thisSfrType object
[in]nreach number
[in]depthreach depth

Definition at line 5579 of file gwf-sfr.f90.

5580 ! -- return variable
5581 real(DP) :: calc_area_wet !< wetted area
5582 ! -- dummy
5583 class(SfrType) :: this !< SfrType object
5584 integer(I4B), intent(in) :: n !< reach number
5585 real(DP), intent(in) :: depth !< reach depth
5586 ! -- local
5587 integer(I4B) :: npts
5588 integer(I4B) :: i0
5589 integer(I4B) :: i1
5590 !
5591 ! -- Calculate wetted area
5592 npts = this%ncrosspts(n)
5593 i0 = this%iacross(n)
5594 i1 = this%iacross(n + 1) - 1
5595 if (npts > 1) then
5596 calc_area_wet = get_cross_section_area(npts, this%station(i0:i1), &
5597 this%xsheight(i0:i1), depth)
5598 else
5599 calc_area_wet = this%station(i0) * depth
5600 end if
Here is the call graph for this function:

◆ calc_perimeter_wet()

real(dp) function sfrmodule::calc_perimeter_wet ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) depth )
private

Function to calculate the wetted perimeter for a SFR package reach.

Returns
wetted perimeter
Parameters
thisSfrType object
[in]nreach number
[in]depthreach depth

Definition at line 5607 of file gwf-sfr.f90.

5608 ! -- return variable
5609 real(DP) :: calc_perimeter_wet !< wetted perimeter
5610 ! -- dummy
5611 class(SfrType) :: this !< SfrType object
5612 integer(I4B), intent(in) :: n !< reach number
5613 real(DP), intent(in) :: depth !< reach depth
5614 ! -- local
5615 integer(I4B) :: npts
5616 integer(I4B) :: i0
5617 integer(I4B) :: i1
5618 !
5619 ! -- Calculate wetted perimeter
5620 npts = this%ncrosspts(n)
5621 i0 = this%iacross(n)
5622 i1 = this%iacross(n + 1) - 1
5623 if (npts > 1) then
5624 calc_perimeter_wet = get_wetted_perimeter(npts, this%station(i0:i1), &
5625 this%xsheight(i0:i1), depth)
5626 else
5627 calc_perimeter_wet = this%station(i0) ! no depth dependence in original implementation
5628 end if
Here is the call graph for this function:

◆ calc_surface_area()

real(dp) function sfrmodule::calc_surface_area ( class(sfrtype) this,
integer(i4b), intent(in) n )
private

Function to calculate the maximum surface area for a SFR package reach.

Returns
surface area
Parameters
thisSfrType object
[in]nreach number

Definition at line 5635 of file gwf-sfr.f90.

5636 ! -- return variable
5637 real(DP) :: calc_surface_area !< surface area
5638 ! -- dummy
5639 class(SfrType) :: this !< SfrType object
5640 integer(I4B), intent(in) :: n !< reach number
5641 ! -- local
5642 integer(I4B) :: npts
5643 integer(I4B) :: i0
5644 integer(I4B) :: i1
5645 real(DP) :: top_width
5646 !
5647 ! -- Calculate surface area
5648 npts = this%ncrosspts(n)
5649 i0 = this%iacross(n)
5650 i1 = this%iacross(n + 1) - 1
5651 if (npts > 1) then
5652 top_width = get_saturated_topwidth(npts, this%station(i0:i1))
5653 else
5654 top_width = this%station(i0)
5655 end if
5656 calc_surface_area = top_width * this%length(n)
Here is the call graph for this function:

◆ calc_surface_area_wet()

real(dp) function sfrmodule::calc_surface_area_wet ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) depth )
private

Function to calculate the wetted surface area for a SFR package reach.

Returns
wetted surface area
Parameters
thisSfrType object
[in]nreach number
[in]depthreach depth

Definition at line 5663 of file gwf-sfr.f90.

5664 ! -- return variable
5665 real(DP) :: calc_surface_area_wet !< wetted surface area
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 real(DP) :: top_width
5672 !
5673 ! -- Calculate wetted surface area
5674 top_width = this%calc_top_width_wet(n, depth)
5675 calc_surface_area_wet = top_width * this%length(n)

◆ calc_top_width_wet()

real(dp) function sfrmodule::calc_top_width_wet ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) depth )
private

Function to calculate the wetted top width for a SFR package reach.

Returns
wetted top width
Parameters
thisSfrType object
[in]nreach number
[in]depthreach depth

Definition at line 5682 of file gwf-sfr.f90.

5683 ! -- return variable
5684 real(DP) :: calc_top_width_wet !< wetted top width
5685 ! -- dummy
5686 class(SfrType) :: this !< SfrType object
5687 integer(I4B), intent(in) :: n !< reach number
5688 real(DP), intent(in) :: depth !< reach depth
5689 ! -- local
5690 integer(I4B) :: npts
5691 integer(I4B) :: i0
5692 integer(I4B) :: i1
5693 real(DP) :: sat
5694 !
5695 ! -- Calculate wetted top width
5696 npts = this%ncrosspts(n)
5697 i0 = this%iacross(n)
5698 i1 = this%iacross(n + 1) - 1
5699 sat = scubicsaturation(dem5, dzero, depth, dem5)
5700 if (npts > 1) then
5701 calc_top_width_wet = sat * get_wetted_topwidth(npts, &
5702 this%station(i0:i1), &
5703 this%xsheight(i0:i1), &
5704 depth)
5705 else
5706 calc_top_width_wet = sat * this%station(i0)
5707 end if
Here is the call graph for this function:

◆ define_listlabel()

subroutine sfrmodule::define_listlabel ( class(sfrtype), intent(inout) this)
private

Method defined the list label for the SFR package. The list label is the heading that is written to iout when PRINT_INPUT option is used.

Parameters
[in,out]thisSfrType object

Definition at line 3080 of file gwf-sfr.f90.

3081 ! -- dummy
3082 class(SfrType), intent(inout) :: this !< SfrType object
3083 !
3084 ! -- create the header list label
3085 this%listlabel = trim(this%filtyp)//' NO.'
3086 if (this%dis%ndim == 3) then
3087 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'LAYER'
3088 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'ROW'
3089 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'COL'
3090 elseif (this%dis%ndim == 2) then
3091 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'LAYER'
3092 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'CELL2D'
3093 else
3094 write (this%listlabel, '(a, a7)') trim(this%listlabel), 'NODE'
3095 end if
3096 write (this%listlabel, '(a, a16)') trim(this%listlabel), 'STRESS RATE'
3097 if (this%inamedbound == 1) then
3098 write (this%listlabel, '(a, a16)') trim(this%listlabel), 'BOUNDARY NAME'
3099 end if

◆ sfr_activate_density()

subroutine sfrmodule::sfr_activate_density ( class(sfrtype), intent(inout) this)
private

Method to activate addition of density terms for a SFR package reach.

Parameters
[in,out]thisSfrType object

Definition at line 5714 of file gwf-sfr.f90.

5715 ! -- modules
5717 ! -- dummy
5718 class(SfrType), intent(inout) :: this !< SfrType object
5719 ! -- local
5720 integer(I4B) :: i
5721 integer(I4B) :: j
5722 !
5723 ! -- Set idense and reallocate denseterms to be of size MAXBOUND
5724 this%idense = 1
5725 call mem_reallocate(this%denseterms, 3, this%MAXBOUND, 'DENSETERMS', &
5726 this%memoryPath)
5727 do i = 1, this%maxbound
5728 do j = 1, 3
5729 this%denseterms(j, i) = dzero
5730 end do
5731 end do
5732 write (this%iout, '(/1x,a)') 'DENSITY TERMS HAVE BEEN ACTIVATED FOR SFR &
5733 &PACKAGE: '//trim(adjustl(this%packName))

◆ sfr_activate_viscosity()

subroutine sfrmodule::sfr_activate_viscosity ( class(sfrtype), intent(inout) this)
private

Method to activate addition of viscosity terms for exchange with groundwater along a SFR package reach.

Parameters
[in,out]thisSfrType object

Definition at line 5741 of file gwf-sfr.f90.

5742 ! -- modules
5744 ! -- dummy
5745 class(SfrType), intent(inout) :: this !< SfrType object
5746 ! -- local
5747 integer(I4B) :: i
5748 integer(I4B) :: j
5749 !
5750 ! -- Set ivsc and reallocate viscratios to be of size MAXBOUND
5751 this%ivsc = 1
5752 call mem_reallocate(this%viscratios, 2, this%MAXBOUND, 'VISCRATIOS', &
5753 this%memoryPath)
5754 do i = 1, this%maxbound
5755 do j = 1, 2
5756 this%viscratios(j, i) = done
5757 end do
5758 end do
5759 write (this%iout, '(/1x,a)') 'VISCOSITY HAS BEEN ACTIVATED FOR SFR &
5760 &PACKAGE: '//trim(adjustl(this%packName))

◆ sfr_ad()

subroutine sfrmodule::sfr_ad ( class(sfrtype) this)
private

Advance data in the SFR package. The method sets advances time series, time array series, and observation data.

Parameters
thisSfrType object

Definition at line 2054 of file gwf-sfr.f90.

2055 ! -- modules
2056 use constantsmodule, only: lenvarname
2057 ! -- dummy
2058 class(SfrType) :: this !< SfrType object
2059 ! -- local
2060 integer(I4B) :: n
2061 integer(I4B) :: i
2062 integer(I4B) :: ii
2063 integer(I4B) :: idiv
2064 integer(I4B) :: iaux
2065 character(len=LENVARNAME) :: setting
2066
2067 ! -- sync PACKAGEDATA AUX TS and advance observations;
2068 ! -- step auxvar period block overrides
2069 call this%BndExtType%bnd_ad()
2070 !
2071 ! -- update previous values
2072 if (this%istorage == 1) then
2073 do n = 1, this%maxbound
2074 this%stageold(n) = this%stage(n)
2075 this%usinflowold(n) = this%usinflow(n)
2076 this%dsflowold(n) = this%dsflow(n)
2077 end do
2078 end if
2079 !
2080 ! -- sync PACKAGEDATA and PERIOD TS fields from input context each
2081 ! timestep; skipped when no TS6 files are configured. PACKAGEDATA
2082 ! values are synced only for rows linked to a time series
2083 if (this%ts_active) then
2084 do i = 1, this%maxbound
2085 n = this%pkg_ifno(i)
2086 if (.not. this%bedk_set(n) .and. &
2087 this%input%rhk_tslink(i) /= 0) &
2088 this%hk(n) = this%input%rhk(i)
2089 if (.not. this%manning_set(n) .and. &
2090 this%input%man_tslink(i) /= 0) &
2091 this%rough(n) = this%input%man(i)
2092 if (.not. this%ustrf_set(n) .and. &
2093 this%input%ustrf_tslink(i) /= 0) &
2094 this%ustrf(n) = this%input%ustrf(i)
2095 end do
2096 !
2097 if (this%input%nbound > 0) then
2098 do i = 1, this%input%nbound
2099 n = this%input%ifno(i)
2100 if (n < 1 .or. n > this%maxbound) cycle
2101 ! -- BEDK, MANNING, UPSTREAM_FRAC, STAGE, INFLOW, RAINFALL, EVAPORATION, RUNOFF
2102 setting = this%input%setting(i)
2103 call this%sfr_set_period_value(i, n, setting)
2104 ! -- DIVFLOW
2105 if (trim(setting) == 'DIVERSION') then
2106 if (this%ndiv(n) >= 1) then
2107 idiv = this%input%idv(i)
2108 if (idiv >= 1 .and. idiv <= this%ndiv(n)) then
2109 ii = this%iadiv(n) + idiv - 1
2110 end if
2111 end if
2112 end if
2113 end do
2114 end if
2115 end if
2116 !
2117 ! -- check upstream fractions (only needed when USTRF may be TS-updated;
2118 ! sfr_rp already validates ustrf once per period via ichkustrm)
2119 if (this%ts_active) call this%sfr_check_ustrf()
2120 !
2121 ! -- update auxiliary variables by copying from the derived-type time
2122 ! series variable into the bndpackage auxvar variable so that this
2123 ! information is properly written to the GWF budget file
2124 if (this%naux > 0) then
2125 do n = 1, this%maxbound
2126 do iaux = 1, this%naux
2127 if (this%noupdateauxvar(iaux) /= 0) cycle
2128 this%auxvar(iaux, n) = this%featureauxvar(iaux, n)
2129 end do
2130 end do
2131 end if
2132 !
2133 ! -- reset upstream flow to zero and set specified stage
2134 do n = 1, this%maxbound
2135 this%usflow(n) = dzero
2136 if (this%iboundpak(n) < 0) then
2137 this%stage(n) = this%sstage(n)
2138 end if
2139 end do
2140 !
2141 ! -- pakmvrobj ad
2142 if (this%imover == 1) then
2143 call this%pakmvrobj%ad()
2144 end if
This module contains simulation constants.
Definition Constants.f90:9
integer(i4b), parameter lenvarname
maximum length of a variable name
Definition Constants.f90:17
real(dp), parameter dzero
real constant zero
Definition Constants.f90:65

◆ sfr_adjust_ro_ev()

subroutine sfrmodule::sfr_adjust_ro_ev ( class(sfrtype) this,
real(dp), intent(inout) qc,
real(dp), intent(in) qu,
real(dp), intent(in) qi,
real(dp), intent(in) qr,
real(dp), intent(inout) qro,
real(dp), intent(inout) qe,
real(dp), intent(in) qfrommvr )
private

Method to adjust runoff and evaporation for a SFR package reach based on the total reach flow.

Parameters
thisSfrType object
[in,out]qctotal reach volumetric flow
[in]quupstream reach volumetric flow
[in]qireach volumetric inflow
[in]qrreach volumetric rainfall
[in,out]qroreach volumetric runoff
[in,out]qereach volumetric evaporation
[in]qfrommvrreach volumetric flow from mover

Definition at line 3714 of file gwf-sfr.f90.

3715 ! -- dummy
3716 class(SfrType) :: this !< SfrType object
3717 real(DP), intent(inout) :: qc !< total reach volumetric flow
3718 real(DP), intent(in) :: qu !< upstream reach volumetric flow
3719 real(DP), intent(in) :: qi !< reach volumetric inflow
3720 real(DP), intent(in) :: qr !< reach volumetric rainfall
3721 real(DP), intent(inout) :: qro !< reach volumetric runoff
3722 real(DP), intent(inout) :: qe !< reach volumetric evaporation
3723 real(DP), intent(in) :: qfrommvr !< reach volumetric flow from mover
3724 ! -- local
3725 real(DP) :: qt
3726 !
3727 ! -- adjust runoff or evaporation if sum of sources is negative
3728 if (qc < dzero) then
3729 !
3730 ! -- calculate sources without evaporation
3731 qt = qu + qi + qr + qro + qfrommvr
3732 !
3733 ! -- runoff exceeds sources of water for reach
3734 if (qt < dzero) then
3735 if (qro < dzero) then
3736 qro = -(qu + qi + qr + qfrommvr)
3737 qe = dzero
3738 end if
3739 !
3740 ! -- evaporation exceeds sources of water for reach
3741 else
3742 if (qe > dzero) then
3743 qe = qu + qi + qr + qro + qfrommvr
3744 end if
3745 end if
3746 qc = qu + qi + qr - qe + qro + qfrommvr
3747 end if

◆ sfr_allocate_arrays()

subroutine sfrmodule::sfr_allocate_arrays ( class(sfrtype), intent(inout) this)
private

Allocate and initialize array for the SFR package.

Parameters
[in,out]thisSfrType object

Definition at line 504 of file gwf-sfr.f90.

505 ! -- modules
507 ! -- dummy
508 class(SfrType), intent(inout) :: this !< SfrType object
509 ! -- local
510 integer(I4B) :: i
511 !
512 ! -- allocate character array for budget text
513 allocate (this%csfrbudget(this%bditems))
514 call mem_allocate(this%sfrname, lenboundname, this%maxbound, &
515 'SFRNAME', this%memoryPath)
516 !
517 ! -- variables originally in SfrDataType
518 call mem_allocate(this%iboundpak, this%maxbound, 'IBOUNDPAK', &
519 this%memoryPath)
520 call mem_allocate(this%igwfnode, this%maxbound, 'IGWFNODE', this%memoryPath)
521 call mem_allocate(this%igwftopnode, this%maxbound, 'IGWFTOPNODE', &
522 this%memoryPath)
523 call mem_allocate(this%length, this%maxbound, 'LENGTH', this%memoryPath)
524 call mem_allocate(this%width, this%maxbound, 'WIDTH', this%memoryPath)
525 call mem_allocate(this%strtop, this%maxbound, 'STRTOP', this%memoryPath)
526 call mem_allocate(this%bthick, this%maxbound, 'BTHICK', this%memoryPath)
527 call mem_allocate(this%slope, this%maxbound, 'SLOPE', this%memoryPath)
528 call mem_allocate(this%nconnreach, this%maxbound, 'NCONNREACH', &
529 this%memoryPath)
530 call mem_allocate(this%bedk_set, this%maxbound, 'BEDK_SET', this%memoryPath)
531 call mem_allocate(this%manning_set, this%maxbound, 'MANNING_SET', &
532 this%memoryPath)
533 call mem_allocate(this%ustrf_set, this%maxbound, 'USTRF_SET', &
534 this%memoryPath)
535 this%bedk_set = .false.
536 this%manning_set = .false.
537 this%ustrf_set = .false.
538 call mem_allocate(this%ftotnd, this%maxbound, 'FTOTND', this%memoryPath)
539 call mem_allocate(this%ndiv, this%maxbound, 'NDIV', this%memoryPath)
540 call mem_allocate(this%usflow, this%maxbound, 'USFLOW', this%memoryPath)
541 call mem_allocate(this%dsflow, this%maxbound, 'DSFLOW', this%memoryPath)
542 call mem_allocate(this%depth, this%maxbound, 'DEPTH', this%memoryPath)
543 call mem_allocate(this%stage, this%maxbound, 'STAGE', this%memoryPath)
544 call mem_allocate(this%gwflow, this%maxbound, 'GWFLOW', this%memoryPath)
545 call mem_allocate(this%simevap, this%maxbound, 'SIMEVAP', this%memoryPath)
546 call mem_allocate(this%simrunoff, this%maxbound, 'SIMRUNOFF', &
547 this%memoryPath)
548 call mem_allocate(this%stage0, this%maxbound, 'STAGE0', this%memoryPath)
549 call mem_allocate(this%usflow0, this%maxbound, 'USFLOW0', this%memoryPath)
550 !
551 ! -- stage, usflow, inflow, and dsflow for previous timestep
552 if (this%istorage == 1) then
553 call mem_allocate(this%stageold, this%maxbound, 'STAGEOLD', &
554 this%memoryPath)
555 call mem_allocate(this%usinflow, this%maxbound, 'USINFLOW', &
556 this%memoryPath)
557 call mem_allocate(this%usinflowold, this%maxbound, 'USINFLOWOLD', &
558 this%memoryPath)
559 call mem_allocate(this%dsflowold, this%maxbound, 'DSFLOWOLD', &
560 this%memoryPath)
561 call mem_allocate(this%storage, this%maxbound, 'STORAGE', &
562 this%memoryPath)
563 call mem_allocate(this%crmin, this%maxbound, 'CRMIN', this%memoryPath)
564 call mem_allocate(this%crmax, this%maxbound, 'CRMAX', this%memoryPath)
565 call mem_allocate(this%crsum, this%maxbound, 'CRSUM', this%memoryPath)
566 call mem_allocate(this%crcnt, this%maxbound, 'CRCNT', this%memoryPath)
567 if (this%ats_courant /= dnodata) then
568 call mem_allocate(this%itvd_upstream, this%maxbound, &
569 'ITVD_UPSTREAM', this%memoryPath)
570 else
571 call mem_allocate(this%itvd_upstream, 0, 'ITVD_UPSTREAM', this%memoryPath)
572 end if
573 end if
574 !
575 ! -- reach order and connection data
576 call mem_allocate(this%isfrorder, this%maxbound, 'ISFRORDER', &
577 this%memoryPath)
578 call mem_allocate(this%ia, this%maxbound + 1, 'IA', this%memoryPath)
579 call mem_allocate(this%ja, 0, 'JA', this%memoryPath)
580 call mem_allocate(this%idir, 0, 'IDIR', this%memoryPath)
581 call mem_allocate(this%idiv, 0, 'IDIV', this%memoryPath)
582 call mem_allocate(this%qconn, 0, 'QCONN', this%memoryPath)
583 !
584 ! -- alias into the input context's permanent, feature-indexed arrays
585 ! (allocated and DZERO-initialized by the loader)
586 call mem_setptr(this%rain, 'RAINFALL', this%input_mempath)
587 call mem_setptr(this%evap, 'EVAPORATION', this%input_mempath)
588 call mem_setptr(this%inflow, 'INFLOW', this%input_mempath)
589 call mem_setptr(this%runoff, 'RUNOFF', this%input_mempath)
590 call mem_setptr(this%sstage, 'STAGE', this%input_mempath)
591 call mem_setptr(this%hk, 'BEDK', this%input_mempath)
592 call mem_setptr(this%rough, 'MANNING', this%input_mempath)
593 call mem_setptr(this%ustrf, 'UPSTREAM_FRAC', this%input_mempath)
594 !
595 !
596 ! -- diversion variables
597 call mem_allocate(this%iadiv, this%maxbound + 1, 'IADIV', this%memoryPath)
598 call mem_allocate(this%divreach, 0, 'DIVREACH', this%memoryPath)
599 call mem_allocate(this%divq, 0, 'DIVQ', this%memoryPath)
600 !
601 ! -- cross-section data
602 call mem_allocate(this%ncrosspts, this%maxbound, 'NCROSSPTS', &
603 this%memoryPath)
604 call mem_allocate(this%iacross, this%maxbound + 1, 'IACROSS', &
605 this%memoryPath)
606 call mem_allocate(this%station, this%ncrossptstot, 'STATION', &
607 this%memoryPath)
608 call mem_allocate(this%xsheight, this%ncrossptstot, 'XSHEIGHT', &
609 this%memoryPath)
610 call mem_allocate(this%xsrough, this%ncrossptstot, 'XSROUGH', &
611 this%memoryPath)
612 !
613 ! -- initialize variables
614 this%iacross(1) = 0
615 do i = 1, this%maxbound
616 this%iboundpak(i) = 1
617 this%igwfnode(i) = 0
618 this%igwftopnode(i) = 0
619 this%length(i) = dzero
620 this%width(i) = dzero
621 this%strtop(i) = dzero
622 this%bthick(i) = dzero
623 this%hk(i) = dzero
624 this%slope(i) = dzero
625 this%nconnreach(i) = 0
626 this%ustrf(i) = dzero
627 this%ftotnd(i) = dzero
628 this%ndiv(i) = 0
629 this%usflow(i) = dzero
630 this%dsflow(i) = dzero
631 this%depth(i) = dzero
632 this%stage(i) = dzero
633 this%gwflow(i) = dzero
634 this%simevap(i) = dzero
635 this%simrunoff(i) = dzero
636 this%stage0(i) = dzero
637 this%usflow0(i) = dzero
638 !
639 ! -- stage
640 if (this%istorage == 1) then
641 this%stageold(i) = dzero
642 this%usinflow(i) = dzero
643 this%usinflowold(i) = dzero
644 this%dsflowold(i) = dzero
645 this%storage(i) = dzero
646 this%crmin(i) = dep20
647 this%crmax(i) = -dep20
648 this%crsum(i) = dzero
649 this%crcnt(i) = 0
650 if (this%ats_courant /= dnodata) then
651 this%itvd_upstream(i) = 0
652 end if
653 end if
654 !
655 ! -- boundary data
656 this%rough(i) = dzero
657 !
658 !
659 ! -- cross-section data
660 this%ncrosspts(i) = 0
661 this%iacross(i + 1) = 0
662 end do
663 !
664 ! -- initialize additional cross-section data
665 do i = 1, this%ncrossptstot
666 this%station(i) = dzero
667 this%xsheight(i) = dzero
668 this%xsrough(i) = dzero
669 end do
670 !
671 !-- fill csfrbudget
672 this%csfrbudget(1) = ' RAINFALL'
673 this%csfrbudget(2) = ' EVAPORATION'
674 this%csfrbudget(3) = ' RUNOFF'
675 this%csfrbudget(4) = ' EXT-INFLOW'
676 this%csfrbudget(5) = ' GWF'
677 this%csfrbudget(6) = ' EXT-OUTFLOW'
678 this%csfrbudget(7) = ' FROM-MVR'
679 this%csfrbudget(8) = ' TO-MVR'
680 !
681 ! -- allocate and initialize budget output data
682 call mem_allocate(this%qoutflow, this%maxbound, 'QOUTFLOW', this%memoryPath)
683 call mem_allocate(this%qextoutflow, this%maxbound, 'QEXTOUTFLOW', &
684 this%memoryPath)
685 do i = 1, this%maxbound
686 this%qoutflow(i) = dzero
687 this%qextoutflow(i) = dzero
688 end do
689 !
690 ! -- allocate and initialize dbuff
691 if (this%istageout > 0) then
692 call mem_allocate(this%dbuff, this%maxbound, 'DBUFF', this%memoryPath)
693 do i = 1, this%maxbound
694 this%dbuff(i) = dzero
695 end do
696 else
697 call mem_allocate(this%dbuff, 0, 'DBUFF', this%memoryPath)
698 end if
699 !
700 ! -- allocate character array for budget text
701 allocate (this%cauxcbc(this%cbcauxitems))
702 !
703 ! -- allocate and initialize qauxcbc
704 call mem_allocate(this%qauxcbc, this%cbcauxitems, 'QAUXCBC', &
705 this%memoryPath)
706 do i = 1, this%cbcauxitems
707 this%qauxcbc(i) = dzero
708 end do
709 !
710 ! -- fill cauxcbc
711 this%cauxcbc(1) = 'FLOW-AREA '
712 !
713 ! -- allocate denseterms to size 0
714 call mem_allocate(this%denseterms, 3, 0, 'DENSETERMS', this%memoryPath)
715 !
716 ! -- allocate viscratios to size 0
717 call mem_allocate(this%viscratios, 2, 0, 'VISCRATIOS', this%memoryPath)

◆ sfr_allocate_scalars()

subroutine sfrmodule::sfr_allocate_scalars ( class(sfrtype), intent(inout) this)
private

Allocate and initialize scalars for the SFR package. The base model allocate scalars method is also called.

Parameters
[in,out]thisSfrType object

Definition at line 433 of file gwf-sfr.f90.

434 ! -- modules
437 ! -- dummy
438 class(SfrType), intent(inout) :: this !< SfrType object
439 !
440 ! -- call standard BndExtType allocate scalars
441 call this%BndExtType%allocate_scalars()
442 !
443 ! -- allocate the object and assign values to object variables
444 call mem_allocate(this%istorage, 'ISTORAGE', this%memoryPath)
445 call mem_allocate(this%iprhed, 'IPRHED', this%memoryPath)
446 call mem_allocate(this%istageout, 'ISTAGEOUT', this%memoryPath)
447 call mem_allocate(this%ibudgetout, 'IBUDGETOUT', this%memoryPath)
448 call mem_allocate(this%ibudcsv, 'IBUDCSV', this%memoryPath)
449 call mem_allocate(this%ipakcsv, 'IPAKCSV', this%memoryPath)
450 call mem_allocate(this%idiversions, 'IDIVERSIONS', this%memoryPath)
451 call mem_allocate(this%maxsfrpicard, 'MAXSFRPICARD', this%memoryPath)
452 call mem_allocate(this%maxsfrit, 'MAXSFRIT', this%memoryPath)
453 call mem_allocate(this%bditems, 'BDITEMS', this%memoryPath)
454 call mem_allocate(this%cbcauxitems, 'CBCAUXITEMS', this%memoryPath)
455 call mem_allocate(this%unitconv, 'UNITCONV', this%memoryPath)
456 call mem_allocate(this%lengthconv, 'LENGTHCONV', this%memoryPath)
457 call mem_allocate(this%timeconv, 'TIMECONV', this%memoryPath)
458 call mem_allocate(this%dmaxchg, 'DMAXCHG', this%memoryPath)
459 call mem_allocate(this%deps, 'DEPS', this%memoryPath)
460 call mem_allocate(this%storage_weight, 'STORAGE_WEIGHT', this%memoryPath)
461 call mem_allocate(this%ats_courant, 'ATS_COURANT', this%memoryPath)
462 call mem_allocate(this%nconn, 'NCONN', this%memoryPath)
463 call mem_allocate(this%icheck, 'ICHECK', this%memoryPath)
464 call mem_allocate(this%iconvchk, 'ICONVCHK', this%memoryPath)
465 call mem_allocate(this%idense, 'IDENSE', this%memoryPath)
466 call mem_allocate(this%ianynone, 'IANYNONE', this%memoryPath)
467 call mem_allocate(this%ncrossptstot, 'NCROSSPTSTOT', this%memoryPath)
468 !
469 ! -- set pointer to gwf iss
470 call mem_setptr(this%gwfiss, 'ISS', create_mem_path(this%name_model))
471 !
472 ! -- Set values
473 this%istorage = 0
474 this%iprhed = 0
475 this%istageout = 0
476 this%ibudgetout = 0
477 this%ibudcsv = 0
478 this%ipakcsv = 0
479 this%idiversions = 0
480 this%maxsfrpicard = 100
481 this%maxsfrit = maxadpit
482 this%bditems = 8
483 this%cbcauxitems = 1
484 this%unitconv = done
485 this%lengthconv = dnodata
486 this%timeconv = dnodata
487 this%dmaxchg = dem5
488 this%deps = dp999 * this%dmaxchg
489 this%storage_weight = dnodata
490 this%ats_courant = dnodata
491 this%nconn = 0
492 this%icheck = 1
493 this%iconvchk = 1
494 this%idense = 0
495 this%ivsc = 0
496 this%ianynone = 0
497 this%ncrossptstot = 0
character(len=lenmempath) function create_mem_path(component, subcomponent, context)
returns the path to the memory object
Here is the call graph for this function:

◆ sfr_ar()

subroutine sfrmodule::sfr_ar ( class(sfrtype), intent(inout) this)
private

Method to read and prepare period data for the SFR package.

Parameters
[in,out]thisSfrType object

Definition at line 1703 of file gwf-sfr.f90.

1704 ! -- modules
1705 use tdismodule, only: inats
1706 ! -- dummy
1707 class(SfrType), intent(inout) :: this !< SfrType object
1708 ! -- local
1709 integer(I4B) :: n
1710 integer(I4B) :: ierr
1711 !
1712 ! -- allocate and read observations
1713 call this%obs%obs_ar()
1714 !
1715 ! -- allocate BndType connection-level arrays (nodelist, bound, auxvar, etc.)
1716 call this%BndExtType%allocate_arrays()
1717 !
1718 ! -- allocate featureauxvar and set pkg_ifno/pkg_auxvar input context
1719 ! pointers
1720 call this%BndExtType%allocate_featureauxvar()
1721 !
1722 ! -- set persistent PERIOD pointers into input context (valid for
1723 ! simulation lifetime)
1724 call this%input%init(this%input_mempath, this%naux)
1725 !
1726 ! -- set boundname for each connection
1727 if (this%inamedbound /= 0) then
1728 do n = 1, this%maxbound
1729 this%boundname(n) = this%sfrname(n)
1730 end do
1731 end if
1732 !
1733 ! -- copy boundname into boundname_cst
1734 call this%copy_boundname()
1735 !
1736 ! -- copy igwfnode into nodelist
1737 do n = 1, this%maxbound
1738 this%nodelist(n) = this%igwfnode(n)
1739 end do
1740 !
1741 ! -- check the sfr unit conversion data
1742 call this%sfr_check_conversion()
1743 !
1744 ! -- check the storage_weight
1745 call this%sfr_check_storage_weight()
1746 !
1747 ! -- check that ATS_COURANT is only used with STORAGE
1748 if (this%ats_courant /= dnodata .and. this%istorage /= 1) then
1749 write (errmsg, '(a)') &
1750 'ATS_COURANT OPTION REQUIRES STORAGE OPTION TO BE ACTIVE'
1751 call store_error(errmsg)
1752 end if
1753 !
1754 ! -- warn when ATS_COURANT is specified but ATS is not active in TDIS
1755 if (this%ats_courant /= dnodata .and. inats == 0) then
1756 write (warnmsg, '(a)') &
1757 'ATS_COURANT IS SPECIFIED IN THE SFR OPTIONS BLOCK BUT THE '// &
1758 'ATS PACKAGE IS NOT ACTIVE IN TDIS, SO THE TIME STEP IS NOT '// &
1759 'ADAPTED TO THE COURANT NUMBER. IF THE COURANT NUMBER EXCEEDS 1 '// &
1760 'THE EXPLICIT KINEMATIC-WAVE ROUTING MAY OSCILLATE WHILE STILL '// &
1761 'CLOSING THE BUDGET. ACTIVATE THE ATS PACKAGE OR USE A SMALLER '// &
1762 'TIME STEP.'
1763 call store_warning(warnmsg)
1764 end if
1765 !
1766 ! -- pre-compute TVD upstream connectivity when ATS_COURANT is active
1767 if (this%ats_courant /= dnodata .and. this%istorage == 1) then
1768 call this%sfr_precompute_tvd()
1769 end if
1770 !
1771 ! -- check the sfr reach data
1772 call this%sfr_check_reaches()
1773
1774 ! -- check the connection data
1775 call this%sfr_check_connections()
1776
1777 ! -- check the diversion data
1778 if (this%idiversions /= 0) then
1779 call this%sfr_check_diversions()
1780 end if
1781
1782 ! -- check the diversion data
1783 if (this%istorage == 1) then
1784 call this%sfr_check_initialstages()
1785 end if
1786 !
1787 ! -- terminate if errors were detected in any of the static sfr data
1788 ierr = count_errors()
1789 if (ierr > 0) then
1790 call store_error_filename(this%input_fname)
1791 end if
1792 !
1793 ! -- setup pakmvrobj
1794 if (this%imover /= 0) then
1795 allocate (this%pakmvrobj)
1796 call this%pakmvrobj%ar(this%maxbound, this%maxbound, this%memoryPath)
1797 end if
integer(i4b), pointer, public inats
flag indicating ats active for simulation
Definition tdis.f90:28
Here is the call graph for this function:

◆ sfr_bd_obs()

subroutine sfrmodule::sfr_bd_obs ( class(sfrtype) this)
private

Method to save simulated values for the SFR package.

Parameters
thisSfrType object

Definition at line 3220 of file gwf-sfr.f90.

3221 ! -- dummy
3222 class(SfrType) :: this !< SfrType object
3223 ! -- local
3224 integer(I4B) :: i
3225 integer(I4B) :: j
3226 integer(I4B) :: n
3227 real(DP) :: v
3228 character(len=100) :: msg
3229 type(ObserveType), pointer :: obsrv => null()
3230 !
3231 ! Write simulated values for all sfr observations
3232 if (this%obs%npakobs > 0) then
3233 call this%obs%obs_bd_clear()
3234 do i = 1, this%obs%npakobs
3235 obsrv => this%obs%pakobs(i)%obsrv
3236 do j = 1, obsrv%indxbnds_count
3237 n = obsrv%indxbnds(j)
3238 v = dzero
3239 select case (obsrv%ObsTypeId)
3240 case ('STAGE')
3241 v = this%stage(n)
3242 case ('TO-MVR')
3243 v = dnodata
3244 if (this%imover == 1) then
3245 v = this%pakmvrobj%get_qtomvr(n)
3246 if (v > dzero) then
3247 v = -v
3248 end if
3249 end if
3250 case ('FROM-MVR')
3251 v = dnodata
3252 if (this%imover == 1) then
3253 v = this%pakmvrobj%get_qfrommvr(n)
3254 end if
3255 case ('EXT-INFLOW')
3256 v = this%inflow(n)
3257 case ('INFLOW')
3258 v = this%usflow(n)
3259 case ('OUTFLOW')
3260 v = this%qoutflow(n)
3261 case ('EXT-OUTFLOW')
3262 v = this%qextoutflow(n)
3263 case ('RAINFALL')
3264 if (this%iboundpak(n) /= 0) then
3265 v = this%rain(n)
3266 else
3267 v = dzero
3268 end if
3269 case ('RUNOFF')
3270 v = this%simrunoff(n)
3271 case ('EVAPORATION')
3272 v = this%simevap(n)
3273 case ('SFR')
3274 v = this%gwflow(n)
3275 case ('UPSTREAM-FLOW')
3276 v = this%usflow(n)
3277 if (this%imover == 1) then
3278 v = v + this%pakmvrobj%get_qfrommvr(n)
3279 end if
3280 case ('DOWNSTREAM-FLOW')
3281 v = this%dsflow(n)
3282 if (v > dzero) then
3283 v = -v
3284 end if
3285 case ('DEPTH')
3286 v = this%depth(n)
3287 case ('WET-PERIMETER')
3288 v = this%calc_perimeter_wet(n, this%depth(n))
3289 case ('WET-AREA')
3290 v = this%calc_area_wet(n, this%depth(n))
3291 case ('WET-WIDTH')
3292 v = this%calc_top_width_wet(n, this%depth(n))
3293 case default
3294 msg = 'Unrecognized observation type: '//trim(obsrv%ObsTypeId)
3295 call store_error(msg)
3296 end select
3297 call this%obs%SaveOneSimval(obsrv, v)
3298 end do
3299 end do
3300 !
3301 ! -- write summary of package error messages
3302 if (count_errors() > 0) then
3303 call store_error_filename(this%input_fname)
3304 end if
3305 end if
Here is the call graph for this function:

◆ sfr_calc_celerity()

subroutine sfrmodule::sfr_calc_celerity ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) q,
real(dp), intent(out) celerity )
private
Parameters
thisSfrType object
[in]nreach number
[in]qreach flow
[out]celeritykinematic-wave celerity

Definition at line 2861 of file gwf-sfr.f90.

2862 ! -- dummy
2863 class(SfrType) :: this !< SfrType object
2864 integer(I4B), intent(in) :: n !< reach number
2865 real(DP), intent(in) :: q !< reach flow
2866 real(DP), intent(out) :: celerity !< kinematic-wave celerity
2867 ! -- local
2868 real(DP) :: d
2869 real(DP) :: a
2870 real(DP) :: a2
2871 !
2872 celerity = dzero
2873 call this%sfr_calc_reach_depth(n, q, d)
2874 if (d > dzero) then
2875 a = this%calc_area_wet(n, d)
2876 call this%sfr_calc_reach_depth(n, q + this%deps, d)
2877 a2 = this%calc_area_wet(n, d)
2878 if (a2 > a) then
2879 celerity = this%deps / (a2 - a)
2880 end if
2881 end if

◆ sfr_calc_cond()

subroutine sfrmodule::sfr_calc_cond ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) depth,
real(dp), intent(inout) cond,
real(dp), intent(in), optional hsfr,
real(dp), intent(in), optional h_temp )
private

Method to calculate the reach-aquifer conductance for a SFR package reach.

Parameters
thisSfrType object
[in]nreach number
[in]depthreach depth
[in,out]condreach-aquifer conductance
[in]hsfrstream stage
[in]h_temphead in gw cell

Definition at line 3992 of file gwf-sfr.f90.

3993 ! -- dummy
3994 class(SfrType) :: this !< SfrType object
3995 integer(I4B), intent(in) :: n !< reach number
3996 real(DP), intent(in) :: depth !< reach depth
3997 real(DP), intent(inout) :: cond !< reach-aquifer conductance
3998 real(DP), intent(in), optional :: hsfr !< stream stage
3999 real(DP), intent(in), optional :: h_temp !< head in gw cell
4000 ! -- local
4001 integer(I4B) :: node
4002 real(DP) :: wp
4003 real(DP) :: vscratio
4004 !
4005 ! -- initialize conductance
4006 cond = dzero
4007 !
4008 ! -- initial viscosity ratio to 1
4009 vscratio = done
4010 !
4011 ! -- calculate conductance if GWF cell is active
4012 ! rch-gwf flow will not occur if reach connected to an constant head cell
4013 node = this%igwfnode(n)
4014 if (node > 0) then
4015 if (this%ibound(node) > 0) then
4016 !
4017 ! -- direction of gradient across streambed determines which vsc ratio
4018 if (this%ivsc == 1) then
4019 if (hsfr > h_temp) then
4020 ! strm stg > gw head
4021 vscratio = this%viscratios(1, n)
4022 else
4023 vscratio = this%viscratios(2, n)
4024 end if
4025 end if
4026 wp = this%calc_perimeter_wet(n, depth)
4027 cond = this%hk(n) * vscratio * this%length(n) * wp / this%bthick(n)
4028 end if
4029 end if

◆ sfr_calc_div()

subroutine sfrmodule::sfr_calc_div ( class(sfrtype) this,
integer(i4b), intent(in) n,
integer(i4b), intent(in) i,
real(dp), intent(inout) qd,
real(dp), intent(inout) qdiv )
private

Method to calculate the diversion flow for a diversion connected to a SFR package reach. The downstream flow for a reach is passed in and adjusted by the diversion flow amount calculated in this method.

Parameters
thisSfrType object
[in]nreach number
[in]idiversion number in reach
[in,out]qdremaining downstream flow for reach
[in,out]qdivdiversion flow for diversion i

Definition at line 4039 of file gwf-sfr.f90.

4040 ! -- dummy
4041 class(SfrType) :: this !< SfrType object
4042 integer(I4B), intent(in) :: n !< reach number
4043 integer(I4B), intent(in) :: i !< diversion number in reach
4044 real(DP), intent(inout) :: qd !< remaining downstream flow for reach
4045 real(DP), intent(inout) :: qdiv !< diversion flow for diversion i
4046 ! -- local
4047 character(len=10) :: cp
4048 integer(I4B) :: jpos
4049 integer(I4B) :: n2
4050 real(DP) :: v
4051 !
4052 ! -- set local variables
4053 jpos = this%iadiv(n) + i - 1
4054 n2 = this%divreach(jpos)
4055 cp = this%divcprior(jpos)
4056 v = this%divflow(jpos)
4057 !
4058 ! -- calculate diversion
4059 select case (cp)
4060 ! -- flood diversion
4061 case ('EXCESS')
4062 if (qd < v) then
4063 v = dzero
4064 else
4065 v = qd - v
4066 end if
4067 ! -- diversion percentage
4068 case ('FRACTION')
4069 v = qd * v
4070 ! -- STR priority algorithm
4071 case ('THRESHOLD')
4072 if (qd < v) then
4073 v = dzero
4074 end if
4075 ! -- specified diversion
4076 case ('UPTO')
4077 if (v > qd) then
4078 v = qd
4079 end if
4080 case default
4081 v = dzero
4082 end select
4083 !
4084 ! -- update upstream from for downstream reaches
4085 qd = qd - v
4086 qdiv = v

◆ sfr_calc_qd()

subroutine sfrmodule::sfr_calc_qd ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) depth,
real(dp), intent(in) hgwf,
real(dp), intent(inout) qgwf,
real(dp), intent(inout) qd )
private

Method to calculate downstream flow for a SFR package reach.

Parameters
thisSfrType object
[in]nreach number
[in]depthreach depth
[in]hgwfgroundwater head in connected GWF cell
[in,out]qgwfgroundwater leakage for reach
[in,out]qdresidual

Definition at line 3754 of file gwf-sfr.f90.

3755 ! -- dummy
3756 class(SfrType) :: this !< SfrType object
3757 integer(I4B), intent(in) :: n !< reach number
3758 real(DP), intent(in) :: depth !< reach depth
3759 real(DP), intent(in) :: hgwf !< groundwater head in connected GWF cell
3760 real(DP), intent(inout) :: qgwf !< groundwater leakage for reach
3761 real(DP), intent(inout) :: qd !< residual
3762 ! -- local
3763 real(DP) :: qsrc
3764 !
3765 ! -- initialize residual
3766 qd = dzero
3767 !
3768 ! -- calculate total water sources excluding groundwater leakage
3769 call this%sfr_calc_qsource(n, depth, qsrc)
3770 !
3771 ! -- estimate groundwater leakage
3772 call this%sfr_calc_qgwf(n, depth, hgwf, qgwf)
3773 if (-qgwf > qsrc) qgwf = -qsrc
3774 !
3775 ! -- calculate down stream flow
3776 qd = qsrc + qgwf
3777 !
3778 ! -- limit downstream flow to a positive value
3779 if (qd < dem30) qd = dzero

◆ sfr_calc_qgwf()

subroutine sfrmodule::sfr_calc_qgwf ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) depth,
real(dp), intent(in) hgwf,
real(dp), intent(inout) qgwf,
real(dp), intent(inout), optional gwfhcof,
real(dp), intent(inout), optional gwfrhs )
private

Method to calculate the reach-aquifer exchange for a SFR package reach. The reach-aquifer exchange is relative to the reach. Calculated flow is positive if flow is from the aquifer to the reach.

Parameters
thisSfrType object
[in]nreach number
[in]depthreach depth
[in]hgwfhead in GWF cell connected to reach
[in,out]qgwfreach-aquifer exchange
[in,out]gwfhcofdiagonal coefficient term for reach
[in,out]gwfrhsright-hand side term for reach

Definition at line 3905 of file gwf-sfr.f90.

3906 ! -- dummy
3907 class(SfrType) :: this !< SfrType object
3908 integer(I4B), intent(in) :: n !< reach number
3909 real(DP), intent(in) :: depth !< reach depth
3910 real(DP), intent(in) :: hgwf !< head in GWF cell connected to reach
3911 real(DP), intent(inout) :: qgwf !< reach-aquifer exchange
3912 real(DP), intent(inout), optional :: gwfhcof !< diagonal coefficient term for reach
3913 real(DP), intent(inout), optional :: gwfrhs !< right-hand side term for reach
3914 ! -- local
3915 integer(I4B) :: node
3916 real(DP) :: tp
3917 real(DP) :: bt
3918 real(DP) :: hsfr
3919 real(DP) :: h_temp
3920 real(DP) :: cond
3921 real(DP) :: sat
3922 real(DP) :: derv
3923 real(DP) :: gwfhcof0
3924 real(DP) :: gwfrhs0
3925 !
3926 ! -- initialize qgwf
3927 qgwf = dzero
3928 !
3929 ! -- skip sfr-aquifer exchange in external cells
3930 node = this%igwfnode(n)
3931 if (node < 1) return
3932 !
3933 ! -- skip sfr-aquifer exchange in inactive cells
3934 if (this%ibound(node) == 0) return
3935 !
3936 ! -- calculate saturation
3937 call schsmooth(depth, sat, derv)
3938 !
3939 ! -- terms for calculating direction of gradient across streambed
3940 tp = this%strtop(n)
3941 bt = tp - this%bthick(n)
3942 hsfr = tp + depth
3943 h_temp = hgwf
3944 if (h_temp < bt) then
3945 h_temp = bt
3946 end if
3947 !
3948 ! -- calculate conductance
3949 call this%sfr_calc_cond(n, depth, cond, hsfr, h_temp)
3950 !
3951 ! -- calculate groundwater leakage
3952 qgwf = sat * cond * (h_temp - hsfr)
3953 gwfrhs0 = -sat * cond * hsfr
3954 gwfhcof0 = -sat * cond
3955 !
3956 ! Add density contributions, if active
3957 if (this%idense /= 0) then
3958 call this%sfr_calculate_density_exchange(n, hsfr, hgwf, cond, tp, &
3959 qgwf, gwfhcof0, gwfrhs0)
3960 end if
3961 !
3962 ! -- Set gwfhcof and gwfrhs if present
3963 if (present(gwfhcof)) gwfhcof = gwfhcof0
3964 if (present(gwfrhs)) gwfrhs = gwfrhs0
Here is the call graph for this function:

◆ sfr_calc_qman()

subroutine sfrmodule::sfr_calc_qman ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) depth,
real(dp), intent(inout) qman )
private

Method to calculate the streamflow using Manning's equation for a SFR package reach.

Parameters
thisSfrType object
[in]nreach number
[in]depthreach depth
[in,out]qmanstreamflow

Definition at line 3835 of file gwf-sfr.f90.

3836 ! -- dummy
3837 class(SfrType) :: this !< SfrType object
3838 integer(I4B), intent(in) :: n !< reach number
3839 real(DP), intent(in) :: depth !< reach depth
3840 real(DP), intent(inout) :: qman !< streamflow
3841 ! -- local
3842 integer(I4B) :: npts
3843 integer(I4B) :: i0
3844 integer(I4B) :: i1
3845 real(DP) :: sat
3846 real(DP) :: derv
3847 real(DP) :: s
3848 real(DP) :: r
3849 real(DP) :: aw
3850 real(DP) :: wp
3851 real(DP) :: rh
3852 !
3853 ! -- initialize variables
3854 qman = dzero
3855 !
3856 ! -- calculate Manning's discharge for non-zero depths
3857 if (depth > dzero) then
3858 npts = this%ncrosspts(n)
3859 !
3860 ! -- set constant terms for Manning's equation
3861 call schsmooth(depth, sat, derv)
3862 s = this%slope(n)
3863 !
3864 ! -- calculate the mannings coefficient that is a
3865 ! function of depth
3866 if (npts > 1) then
3867 !
3868 ! -- get the location of the cross-section data for the reach
3869 i0 = this%iacross(n)
3870 i1 = this%iacross(n + 1) - 1
3871 !
3872 ! -- get the Manning's sum of the Manning's discharge
3873 ! for each section
3874 qman = get_mannings_section(npts, &
3875 this%station(i0:i1), &
3876 this%xsheight(i0:i1), &
3877 this%xsrough(i0:i1), &
3878 this%rough(n), &
3879 this%unitconv, &
3880 s, &
3881 depth)
3882 else
3883 r = this%rough(n)
3884 aw = this%calc_area_wet(n, depth)
3885 wp = this%calc_perimeter_wet(n, depth)
3886 if (wp > dzero) then
3887 rh = aw / wp
3888 else
3889 rh = dzero
3890 end if
3891 qman = this%unitconv * aw * (rh**dtwothirds) * sqrt(s) / r
3892 end if
3893 !
3894 ! -- calculate stream flow
3895 qman = sat * qman
3896 end if
Here is the call graph for this function:

◆ sfr_calc_qsource()

subroutine sfrmodule::sfr_calc_qsource ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) depth,
real(dp), intent(inout) qsrc )
private

Method to calculate the sum of sources for reach, excluding reach leakage, for a SFR package reach.

Parameters
thisSfrType object
[in]nreach number
[in]depthreach depth
[in,out]qsrcsum of sources for reach

Definition at line 3787 of file gwf-sfr.f90.

3788 ! -- dummy
3789 class(SfrType) :: this !< SfrType object
3790 integer(I4B), intent(in) :: n !< reach number
3791 real(DP), intent(in) :: depth !< reach depth
3792 real(DP), intent(inout) :: qsrc !< sum of sources for reach
3793 ! -- local
3794 real(DP) :: qu
3795 real(DP) :: qi
3796 real(DP) :: qr
3797 real(DP) :: qe
3798 real(DP) :: qro
3799 real(DP) :: qfrommvr
3800 real(DP) :: a
3801 real(DP) :: ae
3802 !
3803 ! -- initialize residual
3804 qsrc = dzero
3805 !
3806 ! -- calculate flow terms
3807 qu = this%usflow(n)
3808 qi = this%inflow(n)
3809 qro = this%runoff(n)
3810 !
3811 ! -- calculate rainfall and evap
3812 a = this%calc_surface_area(n)
3813 ae = this%calc_surface_area_wet(n, depth)
3814 qr = this%rain(n) * a
3815 qe = this%evap(n) * ae
3816 !
3817 ! -- calculate mover term
3818 qfrommvr = dzero
3819 if (this%imover == 1) then
3820 qfrommvr = this%pakmvrobj%get_qfrommvr(n)
3821 end if
3822 !
3823 ! -- calculate down stream flow
3824 qsrc = qu + qi + qr - qe + qro + qfrommvr
3825 !
3826 ! -- adjust runoff or evaporation if sum of sources is negative
3827 call this%sfr_adjust_ro_ev(qsrc, qu, qi, qr, qro, qe, qfrommvr)

◆ sfr_calc_reach_depth()

subroutine sfrmodule::sfr_calc_reach_depth ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) q1,
real(dp), intent(inout) d1 )
private

Method to calculate the depth at the midpoint of a reach.

Parameters
thisSfrType object
[in]nreach number
[in]q1streamflow
[in,out]d1stream depth at midpoint of reach

Definition at line 4093 of file gwf-sfr.f90.

4094 ! -- dummy
4095 class(SfrType) :: this !< SfrType object
4096 integer(I4B), intent(in) :: n !< reach number
4097 real(DP), intent(in) :: q1 !< streamflow
4098 real(DP), intent(inout) :: d1 !< stream depth at midpoint of reach
4099 ! -- local
4100 real(DP) :: w
4101 real(DP) :: s
4102 real(DP) :: r
4103 real(DP) :: qconst
4104 !
4105 ! -- initialize slope and roughness
4106 s = this%slope(n)
4107 r = this%rough(n)
4108 !
4109 ! -- calculate stream depth at the midpoint
4110 if (q1 > dzero) then
4111 if (this%ncrosspts(n) > 1) then
4112 call this%sfr_calc_xs_depth(n, q1, d1)
4113 else
4114 w = this%station(this%iacross(n))
4115 qconst = this%unitconv * w * sqrt(s) / r
4116 d1 = (q1 / qconst)**dp6
4117 end if
4118 else
4119 d1 = dzero
4120 end if

◆ sfr_calc_xs_depth()

subroutine sfrmodule::sfr_calc_xs_depth ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) qrch,
real(dp), intent(inout) d )
private

Method to calculate the depth at the midpoint of a reach with a irregular cross-section using Newton-Raphson.

Parameters
thisSfrType object
[in]nreach number
[in]qrchstreamflow
[in,out]dstream depth at midpoint of reach

Definition at line 4128 of file gwf-sfr.f90.

4129 ! -- dummy
4130 class(SfrType) :: this !< SfrType object
4131 integer(I4B), intent(in) :: n !< reach number
4132 real(DP), intent(in) :: qrch !< streamflow
4133 real(DP), intent(inout) :: d !< stream depth at midpoint of reach
4134 ! -- local
4135 integer(I4B) :: iter
4136 real(DP) :: perturbation
4137 real(DP) :: q0
4138 real(DP) :: q1
4139 real(DP) :: dq
4140 real(DP) :: derv
4141 real(DP) :: dd
4142 real(DP) :: residual
4143 !
4144 ! -- initialize variables
4145 perturbation = this%deps * dtwo
4146 d = dzero
4147 q0 = dzero
4148 residual = q0 - qrch
4149 !
4150 ! -- Newton-Raphson iteration
4151 nriter: do iter = 1, this%maxsfrit
4152 call this%sfr_calc_qman(n, d + perturbation, q1)
4153 dq = (q1 - q0)
4154 if (dq /= dzero) then
4155 derv = perturbation / (q1 - q0)
4156 else
4157 derv = dzero
4158 end if
4159 dd = derv * residual
4160 d = d - dd
4161 call this%sfr_calc_qman(n, d, q0)
4162 residual = q0 - qrch
4163 !
4164 ! -- check for convergence
4165 if (abs(dd) < this%dmaxchg) then
4166 exit nriter
4167 end if
4168 end do nriter

◆ sfr_calculate_density_exchange()

subroutine sfrmodule::sfr_calculate_density_exchange ( class(sfrtype), intent(inout) this,
integer(i4b), intent(in) n,
real(dp), intent(in) stage,
real(dp), intent(in) head,
real(dp), intent(in) cond,
real(dp), intent(in) tops,
real(dp), intent(inout) flow,
real(dp), intent(inout) gwfhcof,
real(dp), intent(inout) gwfrhs )
private

Method to calculate groundwater-reach density exchange terms for a SFR package reach.

Member variable used here denseterms : shape (3, MAXBOUND), filled by buoyancy package col 1 is relative density of sfr (densesfr / denseref) col 2 is relative density of gwf cell (densegwf / denseref) col 3 is elevation of gwf cell

Parameters
[in,out]thisSfrType object
[in]nreach number
[in]stagereach stage
[in]headhead in connected GWF cell
[in]condreach conductance
[in]topstop elevation of streambed
[in,out]flowcalculated flow, updated here with density terms
[in,out]gwfhcofGWF diagonal coefficient, updated here with density terms
[in,out]gwfrhsGWF right-hand-side value, updated here with density terms

Definition at line 5774 of file gwf-sfr.f90.

5776 ! -- dummy
5777 class(SfrType), intent(inout) :: this !< SfrType object
5778 integer(I4B), intent(in) :: n !< reach number
5779 real(DP), intent(in) :: stage !< reach stage
5780 real(DP), intent(in) :: head !< head in connected GWF cell
5781 real(DP), intent(in) :: cond !< reach conductance
5782 real(DP), intent(in) :: tops !< top elevation of streambed
5783 real(DP), intent(inout) :: flow !< calculated flow, updated here with density terms
5784 real(DP), intent(inout) :: gwfhcof !< GWF diagonal coefficient, updated here with density terms
5785 real(DP), intent(inout) :: gwfrhs !< GWF right-hand-side value, updated here with density terms
5786 ! -- local
5787 real(DP) :: ss
5788 real(DP) :: hh
5789 real(DP) :: havg
5790 real(DP) :: rdensesfr
5791 real(DP) :: rdensegwf
5792 real(DP) :: rdenseavg
5793 real(DP) :: elevsfr
5794 real(DP) :: elevgwf
5795 real(DP) :: elevavg
5796 real(DP) :: d1
5797 real(DP) :: d2
5798 logical(LGP) :: stage_below_bot
5799 logical(LGP) :: head_below_bot
5800 !
5801 ! -- Set sfr density to sfr density or gwf density
5802 if (stage >= tops) then
5803 ss = stage
5804 stage_below_bot = .false.
5805 rdensesfr = this%denseterms(1, n) ! sfr rel density
5806 else
5807 ss = tops
5808 stage_below_bot = .true.
5809 rdensesfr = this%denseterms(2, n) ! gwf rel density
5810 end if
5811 !
5812 ! -- set hh to head or tops (top elev of streambed)
5813 if (head >= tops) then
5814 hh = head
5815 head_below_bot = .false.
5816 rdensegwf = this%denseterms(2, n) ! gwf rel density
5817 else
5818 hh = tops
5819 head_below_bot = .true.
5820 rdensegwf = this%denseterms(1, n) ! sfr rel density
5821 end if
5822 !
5823 ! -- todo: hack because denseterms not updated in a cf calculation
5824 if (rdensegwf == dzero) return
5825 !
5826 ! -- Update flow
5827 if (stage_below_bot .and. head_below_bot) then
5828 !
5829 ! -- flow is zero, so no terms are updated
5830 !
5831 else
5832 !
5833 ! -- calculate average relative density
5834 rdenseavg = dhalf * (rdensesfr + rdensegwf)
5835 !
5836 ! -- Add contribution of first density term:
5837 ! cond * (denseavg/denseref - 1) * (hgwf - hsfr)
5838 d1 = cond * (rdenseavg - done)
5839 gwfhcof = gwfhcof - d1
5840 gwfrhs = gwfrhs - d1 * ss
5841 d1 = d1 * (hh - ss)
5842 flow = flow + d1
5843 !
5844 ! -- Add second density term if stage and head not below bottom
5845 if (.not. stage_below_bot .and. .not. head_below_bot) then
5846 !
5847 ! -- Add contribution of second density term:
5848 ! cond * (havg - elevavg) * (densegwf - densesfr) / denseref
5849 elevgwf = this%denseterms(3, n)
5850 elevsfr = tops
5851 elevavg = dhalf * (elevsfr + elevgwf)
5852 havg = dhalf * (hh + ss)
5853 d2 = cond * (havg - elevavg) * (rdensegwf - rdensesfr)
5854 gwfrhs = gwfrhs + d2
5855 flow = flow + d2
5856 end if
5857 end if

◆ sfr_cc()

subroutine sfrmodule::sfr_cc ( class(sfrtype), intent(inout) this,
integer(i4b), intent(in) innertot,
integer(i4b), intent(in) kiter,
integer(i4b), intent(in) iend,
integer(i4b), intent(in) icnvgmod,
character(len=lenpakloc), intent(inout) cpak,
integer(i4b), intent(inout) ipak,
real(dp), intent(inout) dpak )
private

Perform additional convergence checks on the flow between the SFR package and the model it is attached to.

Parameters
[in,out]thisSfrType object
[in]innertottotal number of inner iterations
[in]kiterPicard iteration number
[in]iendflag indicating if this is the last Picard iteration
[in]icnvgmodflag inficating if the model has met specific convergence criteria
[in,out]cpakstring for user node
[in,out]ipaklocation of the maximum dependent variable change
[in,out]dpakmaximum dependent variable change

Definition at line 2330 of file gwf-sfr.f90.

2331 ! -- modules
2332 use tdismodule, only: totim, kstp, kper, delt
2333 ! -- dummy
2334 class(SfrType), intent(inout) :: this !< SfrType object
2335 integer(I4B), intent(in) :: innertot !< total number of inner iterations
2336 integer(I4B), intent(in) :: kiter !< Picard iteration number
2337 integer(I4B), intent(in) :: iend !< flag indicating if this is the last Picard iteration
2338 integer(I4B), intent(in) :: icnvgmod !< flag inficating if the model has met specific convergence criteria
2339 character(len=LENPAKLOC), intent(inout) :: cpak !< string for user node
2340 integer(I4B), intent(inout) :: ipak !< location of the maximum dependent variable change
2341 real(DP), intent(inout) :: dpak !< maximum dependent variable change
2342 ! -- local
2343 character(len=LENPAKLOC) :: cloc
2344 character(len=LINELENGTH) :: tag
2345 integer(I4B) :: icheck
2346 integer(I4B) :: ipakfail
2347 integer(I4B) :: locdhmax
2348 integer(I4B) :: locrmax
2349 integer(I4B) :: locdqfrommvrmax
2350 integer(I4B) :: ntabrows
2351 integer(I4B) :: ntabcols
2352 integer(I4B) :: n
2353 real(DP) :: q
2354 real(DP) :: q0
2355 real(DP) :: qtolfact
2356 real(DP) :: dh
2357 real(DP) :: r
2358 real(DP) :: dhmax
2359 real(DP) :: rmax
2360 real(DP) :: dqfrommvr
2361 real(DP) :: dqfrommvrmax
2362 !
2363 ! -- initialize local variables
2364 icheck = this%iconvchk
2365 ipakfail = 0
2366 locdhmax = 0
2367 locrmax = 0
2368 r = dzero
2369 dhmax = dzero
2370 rmax = dzero
2371 locdqfrommvrmax = 0
2372 dqfrommvrmax = dzero
2373 !
2374 ! -- if not saving package convergence data on check convergence if
2375 ! the model is considered converged
2376 if (this%ipakcsv == 0) then
2377 if (icnvgmod == 0) then
2378 icheck = 0
2379 end if
2380 !
2381 ! -- saving package convergence data
2382 else
2383 !
2384 ! -- header for package csv
2385 if (.not. associated(this%pakcsvtab)) then
2386 !
2387 ! -- determine the number of columns and rows
2388 ntabrows = 1
2389 ntabcols = 9
2390 if (this%imover == 1) then
2391 ntabcols = ntabcols + 2
2392 end if
2393 !
2394 ! -- setup table
2395 call table_cr(this%pakcsvtab, this%packName, '')
2396 call this%pakcsvtab%table_df(ntabrows, ntabcols, this%ipakcsv, &
2397 lineseparator=.false., separator=',', &
2398 finalize=.false.)
2399 !
2400 ! -- add columns to package csv
2401 tag = 'total_inner_iterations'
2402 call this%pakcsvtab%initialize_column(tag, 10, alignment=tableft)
2403 tag = 'totim'
2404 call this%pakcsvtab%initialize_column(tag, 10, alignment=tableft)
2405 tag = 'kper'
2406 call this%pakcsvtab%initialize_column(tag, 10, alignment=tableft)
2407 tag = 'kstp'
2408 call this%pakcsvtab%initialize_column(tag, 10, alignment=tableft)
2409 tag = 'nouter'
2410 call this%pakcsvtab%initialize_column(tag, 10, alignment=tableft)
2411 tag = 'dvmax'
2412 call this%pakcsvtab%initialize_column(tag, 15, alignment=tableft)
2413 tag = 'dvmax_loc'
2414 call this%pakcsvtab%initialize_column(tag, 15, alignment=tableft)
2415 tag = 'dinflowmax'
2416 call this%pakcsvtab%initialize_column(tag, 15, alignment=tableft)
2417 tag = 'dinflowmax_loc'
2418 call this%pakcsvtab%initialize_column(tag, 15, alignment=tableft)
2419 if (this%imover == 1) then
2420 tag = 'dqfrommvrmax'
2421 call this%pakcsvtab%initialize_column(tag, 15, alignment=tableft)
2422 tag = 'dqfrommvrmax_loc'
2423 call this%pakcsvtab%initialize_column(tag, 16, alignment=tableft)
2424 end if
2425 end if
2426 end if
2427 !
2428 ! -- perform package convergence check
2429 if (icheck /= 0) then
2430 final_check: do n = 1, this%maxbound
2431 if (this%iboundpak(n) == 0) cycle
2432 !
2433 ! -- set the Q to length factor
2434 qtolfact = delt / this%calc_surface_area(n)
2435 !
2436 ! -- calculate stage change
2437 dh = this%stage0(n) - this%stage(n)
2438 !
2439 ! -- evaluate flow difference if the time step is transient
2440 if (this%gwfiss == 0) then
2441 r = this%usflow0(n) - this%usflow(n)
2442 !
2443 ! -- normalize flow difference and convert to a depth
2444 r = r * qtolfact
2445 end if
2446 !
2447 ! -- q from mvr
2448 dqfrommvr = dzero
2449 if (this%imover == 1) then
2450 q = this%pakmvrobj%get_qfrommvr(n)
2451 q0 = this%pakmvrobj%get_qfrommvr0(n)
2452 dqfrommvr = qtolfact * (q0 - q)
2453 end if
2454 !
2455 ! -- evaluate magnitude of differences
2456 if (n == 1) then
2457 locdhmax = n
2458 dhmax = dh
2459 locrmax = n
2460 rmax = r
2461 dqfrommvrmax = dqfrommvr
2462 locdqfrommvrmax = n
2463 else
2464 if (abs(dh) > abs(dhmax)) then
2465 locdhmax = n
2466 dhmax = dh
2467 end if
2468 if (abs(r) > abs(rmax)) then
2469 locrmax = n
2470 rmax = r
2471 end if
2472 if (abs(dqfrommvr) > abs(dqfrommvrmax)) then
2473 dqfrommvrmax = dqfrommvr
2474 locdqfrommvrmax = n
2475 end if
2476 end if
2477 end do final_check
2478 !
2479 ! -- set dpak and cpak
2480 if (abs(dhmax) > abs(dpak)) then
2481 ipak = locdhmax
2482 dpak = dhmax
2483 write (cloc, "(a,'-',a)") trim(this%packName), 'stage'
2484 cpak = trim(cloc)
2485 end if
2486 if (abs(rmax) > abs(dpak)) then
2487 ipak = locrmax
2488 dpak = rmax
2489 write (cloc, "(a,'-',a)") trim(this%packName), 'inflow'
2490 cpak = trim(cloc)
2491 end if
2492 if (this%imover == 1) then
2493 if (abs(dqfrommvrmax) > abs(dpak)) then
2494 ipak = locdqfrommvrmax
2495 dpak = dqfrommvrmax
2496 write (cloc, "(a,'-',a)") trim(this%packName), 'qfrommvr'
2497 cpak = trim(cloc)
2498 end if
2499 end if
2500 !
2501 ! -- write convergence data to package csv
2502 if (this%ipakcsv /= 0) then
2503 !
2504 ! -- write the data
2505 call this%pakcsvtab%add_term(innertot)
2506 call this%pakcsvtab%add_term(totim)
2507 call this%pakcsvtab%add_term(kper)
2508 call this%pakcsvtab%add_term(kstp)
2509 call this%pakcsvtab%add_term(kiter)
2510 call this%pakcsvtab%add_term(dhmax)
2511 call this%pakcsvtab%add_term(locdhmax)
2512 call this%pakcsvtab%add_term(rmax)
2513 call this%pakcsvtab%add_term(locrmax)
2514 if (this%imover == 1) then
2515 call this%pakcsvtab%add_term(dqfrommvrmax)
2516 call this%pakcsvtab%add_term(locdqfrommvrmax)
2517 end if
2518 !
2519 ! -- finalize the package csv
2520 if (iend == 1) then
2521 call this%pakcsvtab%finalize_table()
2522 end if
2523 end if
2524 end if
real(dp), pointer, public totim
time relative to start of simulation
Definition tdis.f90:35
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
Here is the call graph for this function:

◆ sfr_cf()

subroutine sfrmodule::sfr_cf ( class(sfrtype) this)
private

Formulate the hcof and rhs terms for the WEL package that will be added to the coefficient matrix and right-hand side vector.

Parameters
thisSfrType object

Definition at line 2152 of file gwf-sfr.f90.

2153 ! -- dummy
2154 class(SfrType) :: this !< SfrType object
2155 ! -- local
2156 integer(I4B) :: n
2157 integer(I4B) :: igwfnode
2158 !
2159 ! -- return if no sfr reaches
2160 if (this%nbound == 0) return
2161 !
2162 ! -- find highest active cell
2163 do n = 1, this%nbound
2164 igwfnode = this%igwftopnode(n)
2165 if (igwfnode > 0) then
2166 if (this%ibound(igwfnode) == 0) then
2167 call this%dis%highest_active(igwfnode, this%ibound)
2168 end if
2169 end if
2170 this%igwfnode(n) = igwfnode
2171 this%nodelist(n) = igwfnode
2172 end do

◆ sfr_check_connections()

subroutine sfrmodule::sfr_check_connections ( class(sfrtype) this)
private

Method to check connection data for a SFR package. This method also creates the tables used to print input data, if this option in enabled in the SFR package.

Parameters
thisSfrType object

Definition at line 4355 of file gwf-sfr.f90.

4356 ! -- dummy
4357 class(SfrType) :: this !< SfrType object
4358 ! -- local
4359 logical(LGP) :: lreorder
4360 character(len=5) :: crch
4361 character(len=5) :: crch2
4362 character(len=LINELENGTH) :: text
4363 character(len=LINELENGTH) :: title
4364 integer(I4B) :: n
4365 integer(I4B) :: nn
4366 integer(I4B) :: nc
4367 integer(I4B) :: i
4368 integer(I4B) :: ii
4369 integer(I4B) :: j
4370 integer(I4B) :: ifound
4371 integer(I4B) :: ierr
4372 integer(I4B) :: maxconn
4373 integer(I4B) :: ntabcol
4374 !
4375 ! -- determine if the reaches have been reordered
4376 lreorder = .false.
4377 do j = 1, this%MAXBOUND
4378 n = this%isfrorder(j)
4379 if (n /= j) then
4380 lreorder = .true.
4381 exit
4382 end if
4383 end do
4384 !
4385 ! -- write message that the solution order h
4386 if (lreorder) then
4387 write (this%iout, '(/,1x,a)') &
4388 trim(adjustl(this%text))//' PACKAGE ('// &
4389 trim(adjustl(this%packName))//') REACH SOLUTION HAS BEEN '// &
4390 'REORDERED USING A DAG'
4391 !
4392 ! -- print table
4393 if (this%iprpak /= 0) then
4394 !
4395 ! -- reset the input table object
4396 ntabcol = 2
4397 title = trim(adjustl(this%text))//' PACKAGE ('// &
4398 trim(adjustl(this%packName))//') REACH SOLUTION ORDER'
4399 call table_cr(this%inputtab, this%packName, title)
4400 call this%inputtab%table_df(this%maxbound, ntabcol, this%iout)
4401 text = 'ORDER'
4402 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4403 text = 'REACH'
4404 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4405 !
4406 ! -- upstream connection data
4407 do j = 1, this%maxbound
4408 n = this%isfrorder(j)
4409 call this%inputtab%add_term(j)
4410 call this%inputtab%add_term(n)
4411 end do
4412 end if
4413 end if
4414 !
4415 ! -- create input table for reach connections data
4416 if (this%iprpak /= 0) then
4417 !
4418 ! -- calculate the maximum number of connections
4419 maxconn = 0
4420 do n = 1, this%maxbound
4421 maxconn = max(maxconn, this%nconnreach(n))
4422 end do
4423 ntabcol = 1 + maxconn
4424 !
4425 ! -- reset the input table object
4426 title = trim(adjustl(this%text))//' PACKAGE ('// &
4427 trim(adjustl(this%packName))//') STATIC REACH CONNECTION DATA'
4428 call table_cr(this%inputtab, this%packName, title)
4429 call this%inputtab%table_df(this%maxbound, ntabcol, this%iout)
4430 text = 'REACH'
4431 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4432 do n = 1, maxconn
4433 write (text, '(a,1x,i6)') 'CONN', n
4434 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4435 end do
4436 end if
4437 !
4438 ! -- verify every listed connection is reciprocated: if reach n lists
4439 ! -- reach nn, reach nn must list reach n back
4440 do n = 1, this%MAXBOUND
4441 write (crch, '(i5)') n
4442 eachconn: do i = this%ia(n) + 1, this%ia(n + 1) - 1
4443 nn = this%ja(i)
4444 write (crch2, '(i5)') nn
4445 ifound = 0
4446 connreach: do ii = this%ia(nn) + 1, this%ia(nn + 1) - 1
4447 nc = this%ja(ii)
4448 if (nc == n) then
4449 ifound = 1
4450 exit connreach
4451 end if
4452 end do connreach
4453 if (ifound /= 1) then
4454 errmsg = 'Reach '//crch//' is connected to '// &
4455 'reach '//crch2//' but reach '//crch2// &
4456 ' is not connected to reach '//crch//'.'
4457 call store_error(errmsg)
4458 end if
4459 end do eachconn
4460 !
4461 ! -- write connection data to the table
4462 if (this%iprpak /= 0) then
4463 call this%inputtab%add_term(n)
4464 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4465 call this%inputtab%add_term(this%ja(i))
4466 end do
4467 nn = maxconn - this%nconnreach(n)
4468 do i = 1, nn
4469 call this%inputtab%add_term(' ')
4470 end do
4471 end if
4472 end do
4473 !
4474 ! -- verify upstream connections don't form a mutual pair: two reaches
4475 ! -- cannot each list the other as upstream
4476 ierr = 0
4477 do n = 1, this%maxbound
4478 write (crch, '(i5)') n
4479 eachconnv: do i = this%ia(n) + 1, this%ia(n + 1) - 1
4480 !
4481 ! -- skip downstream connections
4482 if (this%idir(i) < 0) cycle eachconnv
4483 nn = this%ja(i)
4484 write (crch2, '(i5)') nn
4485 connreachv: do ii = this%ia(nn) + 1, this%ia(nn + 1) - 1
4486 ! -- skip downstream connections
4487 if (this%idir(ii) < 0) cycle connreachv
4488 nc = this%ja(ii)
4489 !
4490 ! -- if nc == n then that means reach n is an upstream connection for
4491 ! reach nn and reach nn is an upstream connection for reach n
4492 if (nc == n) then
4493 ierr = ierr + 1
4494 errmsg = 'Reach '//crch//' is connected to '// &
4495 'reach '//crch2//' but streamflow from reach '// &
4496 crch//' to reach '//crch2//' is not permitted.'
4497 call store_error(errmsg)
4498 exit connreachv
4499 end if
4500 end do connreachv
4501 end do eachconnv
4502 end do
4503 !
4504 ! -- terminate if connectivity errors
4505 if (count_errors() > 0) then
4506 call store_error_filename(this%input_fname)
4507 end if
4508 !
4509 ! -- check that downstream reaches for a reach are
4510 ! the upstream reaches for the reach
4511 do n = 1, this%maxbound
4512 write (crch, '(i5)') n
4513 eachconnds: do i = this%ia(n) + 1, this%ia(n + 1) - 1
4514 nn = this%ja(i)
4515 if (this%idir(i) > 0) cycle eachconnds
4516 write (crch2, '(i5)') nn
4517 ifound = 0
4518 connreachds: do ii = this%ia(nn) + 1, this%ia(nn + 1) - 1
4519 nc = this%ja(ii)
4520 if (nc == n) then
4521 if (this%idir(i) /= this%idir(ii)) then
4522 ifound = 1
4523 end if
4524 exit connreachds
4525 end if
4526 end do connreachds
4527 if (ifound /= 1) then
4528 errmsg = 'Reach '//crch//' downstream connected reach '// &
4529 'is reach '//crch2//' but reach '//crch//' is not'// &
4530 ' the upstream connected reach for reach '//crch2//'.'
4531 call store_error(errmsg)
4532 end if
4533 end do eachconnds
4534 end do
4535 !
4536 ! -- create input table for upstream and downstream connections
4537 if (this%iprpak /= 0) then
4538 !
4539 ! -- calculate the maximum number of upstream connections
4540 maxconn = 0
4541 do n = 1, this%maxbound
4542 ii = 0
4543 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4544 if (this%idir(i) > 0) then
4545 ii = ii + 1
4546 end if
4547 end do
4548 maxconn = max(maxconn, ii)
4549 end do
4550 ntabcol = 1 + maxconn
4551 !
4552 ! -- reset the input table object
4553 title = trim(adjustl(this%text))//' PACKAGE ('// &
4554 trim(adjustl(this%packName))//') STATIC UPSTREAM REACH '// &
4555 'CONNECTION DATA'
4556 call table_cr(this%inputtab, this%packName, title)
4557 call this%inputtab%table_df(this%maxbound, ntabcol, this%iout)
4558 text = 'REACH'
4559 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4560 do n = 1, maxconn
4561 write (text, '(a,1x,i6)') 'UPSTREAM CONN', n
4562 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4563 end do
4564 !
4565 ! -- upstream connection data
4566 do n = 1, this%maxbound
4567 call this%inputtab%add_term(n)
4568 ii = 0
4569 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4570 if (this%idir(i) > 0) then
4571 call this%inputtab%add_term(this%ja(i))
4572 ii = ii + 1
4573 end if
4574 end do
4575 nn = maxconn - ii
4576 do i = 1, nn
4577 call this%inputtab%add_term(' ')
4578 end do
4579 end do
4580 !
4581 ! -- calculate the maximum number of downstream connections
4582 maxconn = 0
4583 do n = 1, this%maxbound
4584 ii = 0
4585 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4586 if (this%idir(i) < 0) then
4587 ii = ii + 1
4588 end if
4589 end do
4590 maxconn = max(maxconn, ii)
4591 end do
4592 ntabcol = 1 + maxconn
4593 !
4594 ! -- reset the input table object
4595 title = trim(adjustl(this%text))//' PACKAGE ('// &
4596 trim(adjustl(this%packName))//') STATIC DOWNSTREAM '// &
4597 'REACH CONNECTION DATA'
4598 call table_cr(this%inputtab, this%packName, title)
4599 call this%inputtab%table_df(this%maxbound, ntabcol, this%iout)
4600 text = 'REACH'
4601 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4602 do n = 1, maxconn
4603 write (text, '(a,1x,i6)') 'DOWNSTREAM CONN', n
4604 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4605 end do
4606 !
4607 ! -- downstream connection data
4608 do n = 1, this%maxbound
4609 call this%inputtab%add_term(n)
4610 ii = 0
4611 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4612 if (this%idir(i) < 0) then
4613 call this%inputtab%add_term(this%ja(i))
4614 ii = ii + 1
4615 end if
4616 end do
4617 nn = maxconn - ii
4618 do i = 1, nn
4619 call this%inputtab%add_term(' ')
4620 end do
4621 end do
4622 end if
Here is the call graph for this function:

◆ sfr_check_conversion()

subroutine sfrmodule::sfr_check_conversion ( class(sfrtype) this)
private

Method to check unit conversion data for a SFR package. This method also calculates unitconv that is used in the Manning's equation.

Parameters
thisSfrType object

Definition at line 4176 of file gwf-sfr.f90.

4177 ! -- dummy
4178 class(SfrType) :: this !< SfrType object
4179 ! -- local
4180 ! -- formats
4181 character(len=*), parameter :: fmtunitconv_error = &
4182 &"('SFR (',a,') UNIT_CONVERSION SPECIFIED VALUE (',g0,') AND', &
4183 &1x,'LENGTH_CONVERSION OR TIME_CONVERSION SPECIFIED.')"
4184 character(len=*), parameter :: fmtunitconv = &
4185 &"(1x,'SFR PACKAGE (',a,') CONVERSION DATA',&
4186 &/4x,'UNIT CONVERSION VALUE (',g0,').',/)"
4187 !
4188 ! -- check the reach data for simple errors
4189 if (this%lengthconv /= dnodata .or. this%timeconv /= dnodata) then
4190 if (this%unitconv /= done) then
4191 write (errmsg, fmtunitconv_error) &
4192 trim(adjustl(this%packName)), this%unitconv
4193 call store_error(errmsg)
4194 else
4195 if (this%lengthconv /= dnodata) then
4196 this%unitconv = this%unitconv * this%lengthconv**donethird
4197 end if
4198 if (this%timeconv /= dnodata) then
4199 this%unitconv = this%unitconv * this%timeconv
4200 end if
4201 write (this%iout, fmtunitconv) &
4202 trim(adjustl(this%packName)), this%unitconv
4203 end if
4204 end if
Here is the call graph for this function:

◆ sfr_check_diversions()

subroutine sfrmodule::sfr_check_diversions ( class(sfrtype) this)
private

Method to check diversion data for a SFR package. This method also creates the tables used to print input data, if this option in enabled in the SFR package.

Parameters
thisSfrType object

Definition at line 4631 of file gwf-sfr.f90.

4632 ! -- dummy
4633 class(SfrType) :: this !< SfrType object
4634 ! -- local
4635 character(len=LINELENGTH) :: title
4636 character(len=LINELENGTH) :: text
4637 character(len=5) :: crch
4638 character(len=5) :: cdiv
4639 character(len=5) :: crch2
4640 character(len=10) :: cprior
4641 integer(I4B) :: maxdiv
4642 integer(I4B) :: n
4643 integer(I4B) :: nn
4644 integer(I4B) :: nc
4645 integer(I4B) :: ii
4646 integer(I4B) :: idiv
4647 integer(I4B) :: ifound
4648 integer(I4B) :: jpos
4649 ! -- format
465010 format('Diversion ', i0, ' of reach ', i0, &
4651 ' is invalid or has not been defined.')
4652 !
4653 ! -- write header
4654 if (this%iprpak /= 0) then
4655 !
4656 ! -- determine the maximum number of diversions
4657 maxdiv = 0
4658 do n = 1, this%maxbound
4659 maxdiv = maxdiv + this%ndiv(n)
4660 end do
4661 !
4662 ! -- reset the input table object
4663 title = trim(adjustl(this%text))//' PACKAGE ('// &
4664 trim(adjustl(this%packName))//') REACH DIVERSION DATA'
4665 call table_cr(this%inputtab, this%packName, title)
4666 call this%inputtab%table_df(maxdiv, 4, this%iout)
4667 text = 'REACH'
4668 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4669 text = 'DIVERSION'
4670 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4671 text = 'REACH 2'
4672 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4673 text = 'CPRIOR'
4674 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4675 end if
4676 !
4677 ! -- check that diversion data are correct
4678 do n = 1, this%maxbound
4679 if (this%ndiv(n) < 1) cycle
4680 write (crch, '(i5)') n
4681
4682 do idiv = 1, this%ndiv(n)
4683 !
4684 ! -- determine diversion index
4685 jpos = this%iadiv(n) + idiv - 1
4686 !
4687 ! -- write idiv to cdiv
4688 write (cdiv, '(i5)') idiv
4689 !
4690 !
4691 nn = this%divreach(jpos)
4692 write (crch2, '(i5)') nn
4693 !
4694 ! -- make sure diversion reach is connected to current reach
4695 ifound = 0
4696 if (nn < 1 .or. nn > this%maxbound) then
4697 write (errmsg, 10) idiv, n
4698 call store_error(errmsg)
4699 cycle
4700 end if
4701 connreach: do ii = this%ia(nn) + 1, this%ia(nn + 1) - 1
4702 nc = this%ja(ii)
4703 if (nc == n) then
4704 if (this%idir(ii) > 0) then
4705 ifound = 1
4706 end if
4707 exit connreach
4708 end if
4709 end do connreach
4710 if (ifound /= 1) then
4711 errmsg = 'Reach '//crch//' is not a upstream reach for '// &
4712 'reach '//crch2//' as a result diversion '//cdiv// &
4713 ' from reach '//crch//' to reach '//crch2// &
4714 ' is not possible. Check reach connectivity.'
4715 call store_error(errmsg)
4716 end if
4717 ! -- iprior
4718 cprior = this%divcprior(jpos)
4719 !
4720 ! -- add terms to the table
4721 if (this%iprpak /= 0) then
4722 call this%inputtab%add_term(n)
4723 call this%inputtab%add_term(idiv)
4724 call this%inputtab%add_term(nn)
4725 call this%inputtab%add_term(cprior)
4726 end if
4727 end do
4728 end do
Here is the call graph for this function:

◆ sfr_check_initialstages()

subroutine sfrmodule::sfr_check_initialstages ( class(sfrtype) this)
private

Method to check initial data for a SFR package and calculates the initial upstream and downstream flows for the reach based on the initial staalso creates the tables used to print input data, if this option in enabled in the SFR package.

Parameters
thisSfrType object

Definition at line 4738 of file gwf-sfr.f90.

4739 class(SfrType) :: this !< SfrType object
4740
4741 character(len=LINELENGTH) :: title
4742 character(len=LINELENGTH) :: text
4743 character(len=5) :: crch
4744 integer(I4B) :: n
4745 real(DP) :: qman
4746
4747 ! skip check if storage is not activated
4748 if (this%istorage == 0) return
4749
4750 ! write header
4751 if (this%iprpak /= 0) then
4752 !
4753 ! -- reset the input table object
4754 title = trim(adjustl(this%text))//' PACKAGE ('// &
4755 trim(adjustl(this%packName))//') REACH INITIAL STAGE DATA'
4756 call table_cr(this%inputtab, this%packName, title)
4757 call this%inputtab%table_df(this%maxbound, 4, this%iout)
4758 text = 'REACH'
4759 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4760 text = 'INITIAL STAGE'
4761 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4762 text = 'INITIAL DEPTH'
4763 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4764 text = 'INITIAL FLOW'
4765 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4766 end if
4767 !
4768 ! -- check that data are correct
4769 do n = 1, this%maxbound
4770 write (crch, '(i5)') n
4771
4772 ! calculate the initial flows
4773 call this%sfr_calc_qman(n, this%depth(n), qman)
4774 this%usinflow(n) = qman
4775 this%dsflow(n) = qman
4776
4777 ! add terms to the table
4778 if (this%iprpak /= 0) then
4779 call this%inputtab%add_term(n)
4780 call this%inputtab%add_term(this%stage(n))
4781 call this%inputtab%add_term(this%depth(n))
4782 call this%inputtab%add_term(qman)
4783 end if
4784 end do
Here is the call graph for this function:

◆ sfr_check_reaches()

subroutine sfrmodule::sfr_check_reaches ( class(sfrtype) this)
private

Method to check specified data for a SFR package. This method also creates the tables used to print input data, if this option in enabled in the SFR package.

Parameters
thisSfrType object

Definition at line 4237 of file gwf-sfr.f90.

4238 ! -- dummy
4239 class(SfrType) :: this !< SfrType object
4240 ! -- local
4241 character(len=5) :: crch
4242 character(len=10) :: cval
4243 character(len=30) :: nodestr
4244 character(len=LINELENGTH) :: title
4245 character(len=LINELENGTH) :: text
4246 integer(I4B) :: n
4247 integer(I4B) :: nn
4248 real(DP) :: btgwf
4249 real(DP) :: bt
4250 !
4251 ! -- setup inputtab tableobj
4252 if (this%iprpak /= 0) then
4253 title = trim(adjustl(this%text))//' PACKAGE ('// &
4254 trim(adjustl(this%packName))//') STATIC REACH DATA'
4255 call table_cr(this%inputtab, this%packName, title)
4256 call this%inputtab%table_df(this%maxbound, 10, this%iout)
4257 text = 'NUMBER'
4258 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4259 text = 'CELLID'
4260 call this%inputtab%initialize_column(text, 20, alignment=tableft)
4261 text = 'LENGTH'
4262 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4263 text = 'WIDTH'
4264 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4265 text = 'SLOPE'
4266 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4267 text = 'TOP'
4268 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4269 text = 'THICKNESS'
4270 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4271 text = 'HK'
4272 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4273 text = 'ROUGHNESS'
4274 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4275 text = 'UPSTREAM FRACTION'
4276 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4277 end if
4278 !
4279 ! -- check the reach data for simple errors
4280 do n = 1, this%maxbound
4281 write (crch, '(i5)') n
4282 nn = this%igwfnode(n)
4283 if (nn > 0) then
4284 btgwf = this%dis%bot(nn)
4285 call this%dis%noder_to_string(nn, nodestr)
4286 else
4287 nodestr = 'none'
4288 end if
4289 ! -- check reach length
4290 if (this%length(n) <= dzero) then
4291 errmsg = 'Reach '//crch//' length must be greater than 0.0.'
4292 call store_error(errmsg)
4293 end if
4294 ! -- check reach width
4295 if (this%width(n) <= dzero) then
4296 errmsg = 'Reach '//crch//' width must be greater than 0.0.'
4297 call store_error(errmsg)
4298 end if
4299 ! -- check reach slope
4300 if (this%slope(n) <= dzero) then
4301 errmsg = 'Reach '//crch//' slope must be greater than 0.0.'
4302 call store_error(errmsg)
4303 end if
4304 ! -- check bed thickness and bed hk for reaches connected to GWF
4305 if (nn > 0) then
4306 bt = this%strtop(n) - this%bthick(n)
4307 if (bt <= btgwf .and. this%icheck /= 0) then
4308 write (cval, '(f10.4)') bt
4309 errmsg = 'Reach '//crch//' bed bottom (rtp-rbth ='// &
4310 cval//') must be greater than the bottom of cell ('// &
4311 nodestr
4312 write (cval, '(f10.4)') btgwf
4313 errmsg = trim(adjustl(errmsg))//'='//cval//').'
4314 call store_error(errmsg)
4315 end if
4316 if (this%hk(n) < dzero) then
4317 errmsg = 'Reach '//crch//' hk must be greater than or equal to 0.0.'
4318 call store_error(errmsg)
4319 end if
4320 end if
4321 ! -- check reach roughness
4322 if (this%rough(n) <= dzero) then
4323 errmsg = 'Reach '//crch//" Manning's roughness "// &
4324 'coefficient must be greater than 0.0.'
4325 call store_error(errmsg)
4326 end if
4327 ! -- check reach upstream fraction
4328 if (this%ustrf(n) < dzero) then
4329 errmsg = 'Reach '//crch//' upstream fraction must be greater '// &
4330 'than or equal to 0.0.'
4331 call store_error(errmsg)
4332 end if
4333 ! -- write summary of reach information
4334 if (this%iprpak /= 0) then
4335 call this%inputtab%add_term(n)
4336 call this%inputtab%add_term(nodestr)
4337 call this%inputtab%add_term(this%length(n))
4338 call this%inputtab%add_term(this%width(n))
4339 call this%inputtab%add_term(this%slope(n))
4340 call this%inputtab%add_term(this%strtop(n))
4341 call this%inputtab%add_term(this%bthick(n))
4342 call this%inputtab%add_term(this%hk(n))
4343 call this%inputtab%add_term(this%rough(n))
4344 call this%inputtab%add_term(this%ustrf(n))
4345 end if
4346 end do
Here is the call graph for this function:

◆ sfr_check_storage_weight()

subroutine sfrmodule::sfr_check_storage_weight ( class(sfrtype) this)
private

Method to check the kinematic storage weight for a SFR package. If the kinematic storage weight has not been set it is set to the default value.

Parameters
thisSfrType object

Definition at line 4213 of file gwf-sfr.f90.

4214 ! -- dummy
4215 class(SfrType) :: this !< SfrType object
4216 ! -- formats
4217 character(len=*), parameter :: fmtweight = &
4218 &"(1x,'SFR PACKAGE (',a,') SETTING DEFAULT',&
4219 &/4x,'STORAGE_WEIGHT VALUE (',g0,').',/)"
4220 !
4221 ! -- set storage weight if it has not been defined yet
4222 if (this%istorage == 1) then
4223 if (this%storage_weight == dnodata) then
4224 this%storage_weight = done
4225 write (this%iout, fmtweight) &
4226 trim(adjustl(this%packName)), this%storage_weight
4227 end if
4228 end if

◆ sfr_check_ustrf()

subroutine sfrmodule::sfr_check_ustrf ( class(sfrtype) this)
private

Method to check upstream fraction data for a SFR package. This method also creates the tables used to print input data, if this option in enabled in the SFR package.

Parameters
thisSfrType object

Definition at line 4793 of file gwf-sfr.f90.

4794 ! -- dummy
4795 class(SfrType) :: this !< SfrType object
4796 ! -- local
4797 character(len=LINELENGTH) :: title
4798 character(len=LINELENGTH) :: text
4799 logical(LGP) :: lcycle
4800 logical(LGP) :: ladd
4801 character(len=5) :: crch
4802 character(len=5) :: crch2
4803 character(len=10) :: cval
4804 integer(I4B) :: maxcols
4805 integer(I4B) :: npairs
4806 integer(I4B) :: ipair
4807 integer(I4B) :: i
4808 integer(I4B) :: n
4809 integer(I4B) :: n2
4810 integer(I4B) :: idiv
4811 integer(I4B) :: i0
4812 integer(I4B) :: i1
4813 integer(I4B) :: jpos
4814 integer(I4B) :: ids
4815 real(DP) :: f
4816 real(DP) :: rval
4817 !
4818 ! -- write table header
4819 if (this%iprpak /= 0) then
4820 !
4821 ! -- determine the maximum number of columns
4822 npairs = 0
4823 do n = 1, this%maxbound
4824 ipair = 0
4825 ec: do i = this%ia(n) + 1, this%ia(n + 1) - 1
4826 !
4827 ! -- skip upstream connections
4828 if (this%idir(i) > 0) cycle ec
4829 n2 = this%ja(i)
4830 !
4831 ! -- skip inactive downstream reaches
4832 if (this%iboundpak(n2) == 0) cycle ec
4833 !
4834 ! -- increment ipair and see if it exceeds npairs
4835 ipair = ipair + 1
4836 npairs = max(npairs, ipair)
4837 end do ec
4838 end do
4839 maxcols = 1 + npairs * 2
4840 !
4841 ! -- reset the input table object
4842 title = trim(adjustl(this%text))//' PACKAGE ('// &
4843 trim(adjustl(this%packName))//') CONNECTED REACH UPSTREAM '// &
4844 'FRACTION DATA'
4845 call table_cr(this%inputtab, this%packName, title)
4846 call this%inputtab%table_df(this%maxbound, maxcols, this%iout)
4847 text = 'REACH'
4848 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4849 do i = 1, npairs
4850 write (cval, '(i10)') i
4851 text = 'DOWNSTREAM REACH '//trim(adjustl(cval))
4852 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
4853 text = 'FRACTION '//trim(adjustl(cval))
4854 call this%inputtab%initialize_column(text, 12, alignment=tabcenter)
4855 end do
4856 end if
4857 !
4858 ! -- fill diversion number for each connection
4859 do n = 1, this%maxbound
4860 do idiv = 1, this%ndiv(n)
4861 i0 = this%iadiv(n)
4862 i1 = this%iadiv(n + 1) - 1
4863 do jpos = i0, i1
4864 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4865 n2 = this%ja(i)
4866 if (this%divreach(jpos) == n2) then
4867 this%idiv(i) = jpos - i0 + 1
4868 exit
4869 end if
4870 end do
4871 end do
4872 end do
4873 end do
4874 !
4875 ! -- check that the upstream fraction for reach connected by
4876 ! a diversion is zero
4877 do n = 1, this%maxbound
4878 !
4879 ! -- determine the number of downstream reaches
4880 ids = 0
4881 do i = this%ia(n) + 1, this%ia(n + 1) - 1
4882 if (this%idir(i) < 0) then
4883 ids = ids + 1
4884 end if
4885 end do
4886 !
4887 ! -- evaluate the diversions
4888 do idiv = 1, this%ndiv(n)
4889 jpos = this%iadiv(n) + idiv - 1
4890 n2 = this%divreach(jpos)
4891 f = this%ustrf(n2)
4892 if (f /= dzero) then
4893 write (errmsg, '(a,2(1x,i0,1x,a),1x,a,g0,a,2(1x,a))') &
4894 'Reach', n, 'is connected to reach', n2, 'by a diversion', &
4895 'but the upstream fraction is not equal to zero (', f, '). Check', &
4896 trim(this%packName), 'package diversion and package data.'
4897 if (ids > 1) then
4898 call store_error(errmsg)
4899 else
4900 write (warnmsg, '(a,3(1x,a))') &
4901 trim(warnmsg), &
4902 'A warning instead of an error is issued because', &
4903 'the reach is only connected to the diversion reach in the ', &
4904 'downstream direction.'
4905 call store_warning(warnmsg)
4906 end if
4907 end if
4908 end do
4909 end do
4910 !
4911 ! -- calculate the total fraction of connected reaches that are
4912 ! not diversions and check that the sum of upstream fractions
4913 ! is equal to 1 for each reach
4914 do n = 1, this%maxbound
4915 ids = 0
4916 rval = dzero
4917 f = dzero
4918 write (crch, '(i5)') n
4919 if (this%iprpak /= 0) then
4920 call this%inputtab%add_term(n)
4921 end if
4922 ipair = 0
4923 eachconn: do i = this%ia(n) + 1, this%ia(n + 1) - 1
4924 lcycle = .false.
4925 !
4926 ! -- initialize downstream connection q
4927 this%qconn(i) = dzero
4928 !
4929 ! -- skip upstream connections
4930 if (this%idir(i) > 0) then
4931 lcycle = .true.
4932 end if
4933 n2 = this%ja(i)
4934 !
4935 ! -- skip inactive downstream reaches
4936 if (this%iboundpak(n2) == 0) then
4937 lcycle = .true.
4938 end if
4939 if (lcycle) then
4940 cycle eachconn
4941 end if
4942 ipair = ipair + 1
4943 write (crch2, '(i5)') n2
4944 ids = ids + 1
4945 ladd = .true.
4946 f = f + this%ustrf(n2)
4947 write (cval, '(f10.4)') this%ustrf(n2)
4948 !
4949 ! -- write upstream fractions
4950 if (this%iprpak /= 0) then
4951 call this%inputtab%add_term(n2)
4952 call this%inputtab%add_term(this%ustrf(n2))
4953 end if
4954 eachdiv: do idiv = 1, this%ndiv(n)
4955 jpos = this%iadiv(n) + idiv - 1
4956 if (this%divreach(jpos) == n2) then
4957 ladd = .false.
4958 exit eachdiv
4959 end if
4960 end do eachdiv
4961 if (ladd) then
4962 rval = rval + this%ustrf(n2)
4963 end if
4964 end do eachconn
4965 this%ftotnd(n) = rval
4966 !
4967 ! -- write remaining table columns
4968 if (this%iprpak /= 0) then
4969 ipair = ipair + 1
4970 do i = ipair, npairs
4971 call this%inputtab%add_term(' ')
4972 call this%inputtab%add_term(' ')
4973 end do
4974 end if
4975 !
4976 ! -- evaluate if an error condition has occurred
4977 ! the sum of fractions is not equal to 1
4978 if (ids /= 0) then
4979 if (abs(f - done) > dem6) then
4980 write (errmsg, '(a,1x,i0,1x,a,g0,a,3(1x,a))') &
4981 'Upstream fractions for reach ', n, 'is not equal to one (', f, &
4982 '). Check', trim(this%packName), 'package reach connectivity and', &
4983 'package data.'
4984 call store_error(errmsg)
4985 end if
4986 end if
4987 end do
Here is the call graph for this function:

◆ sfr_checkin_deprecated_names()

subroutine sfrmodule::sfr_checkin_deprecated_names ( class(sfrtype), intent(inout) this)
private

IDM integration moved several reach variables into the input context, renaming some. These aliases share memory with the relocated variables so that programs addressing them through the API by their old package-path names continue to resolve; each use is reported as deprecated. DIVFLOW is only set from the input context when diversions are present; otherwise an empty DIVFLOW is allocated at the package path, as before IDM integration.

Definition at line 729 of file gwf-sfr.f90.

730 ! -- modules
733 ! -- dummy
734 class(SfrType), intent(inout) :: this
735 ! -- local
736 real(DP), dimension(:, :), pointer, contiguous :: aux => null()
737 integer(I4B) :: isize
738 ! -- code
739 !
740 ! -- reach auxiliary values, present (possibly empty) in the input context
741 call get_isize('AUX', this%input_mempath, isize)
742 if (isize >= 0) then
743 call mem_setptr(aux, 'AUX', this%input_mempath)
744 call mem_alias_deprecated(aux, 'RAUXVAR', this%memoryPath, &
745 'AUX', this%input_mempath, '6.8.2')
746 end if
747 !
748 ! -- diversion flows
749 if (associated(this%divflow)) then
750 call mem_alias_deprecated(this%divflow, 'DIVFLOW', this%memoryPath, &
751 'DIVFLOW', this%input_mempath, '6.8.2')
752 else
753 call mem_allocate(this%divflow, 0, 'DIVFLOW', this%memoryPath)
754 end if
755 !
756 call mem_alias_deprecated(this%rain, 'RAIN', this%memoryPath, &
757 'RAINFALL', this%input_mempath, '6.8.2')
758 call mem_alias_deprecated(this%evap, 'EVAP', this%memoryPath, &
759 'EVAPORATION', this%input_mempath, '6.8.2')
760 call mem_alias_deprecated(this%inflow, 'INFLOW', this%memoryPath, &
761 'INFLOW', this%input_mempath, '6.8.2')
762 call mem_alias_deprecated(this%runoff, 'RUNOFF', this%memoryPath, &
763 'RUNOFF', this%input_mempath, '6.8.2')
764 call mem_alias_deprecated(this%sstage, 'SSTAGE', this%memoryPath, &
765 'STAGE', this%input_mempath, '6.8.2')
766 call mem_alias_deprecated(this%hk, 'HK', this%memoryPath, &
767 'BEDK', this%input_mempath, '6.8.2')
768 call mem_alias_deprecated(this%rough, 'ROUGH', this%memoryPath, &
769 'MANNING', this%input_mempath, '6.8.2')
770 call mem_alias_deprecated(this%ustrf, 'USTRF', this%memoryPath, &
771 'UPSTREAM_FRAC', this%input_mempath, '6.8.2')
Previous variable names checked in as deprecated aliases.
subroutine, public get_isize(name, mem_path, isize)
Get the number of elements for this variable.
Here is the call graph for this function:

◆ sfr_cq()

subroutine sfrmodule::sfr_cq ( class(sfrtype), intent(inout) this,
real(dp), dimension(:), intent(in) x,
real(dp), dimension(:), intent(inout), contiguous flowja,
integer(i4b), intent(in), optional iadv )
private

Calculate the flow between connected SFR package control volumes.

Parameters
[in,out]thisSfrType object
[in]xcurrent dependent-variable value
[in,out]flowjaflow between two connected control volumes
[in]iadvflag that indicates if this is an advance package

Definition at line 2531 of file gwf-sfr.f90.

2532 ! -- modules
2533 use budgetmodule, only: budgettype
2534 ! -- dummy
2535 class(SfrType), intent(inout) :: this !< SfrType object
2536 real(DP), dimension(:), intent(in) :: x !< current dependent-variable value
2537 real(DP), dimension(:), contiguous, intent(inout) :: flowja !< flow between two connected control volumes
2538 integer(I4B), optional, intent(in) :: iadv !< flag that indicates if this is an advance package
2539 ! -- local
2540 integer(I4B) :: i
2541 real(DP) :: qext
2542 ! -- for budget
2543 integer(I4B) :: n
2544 integer(I4B) :: n2
2545 real(DP) :: qoutflow
2546 real(DP) :: qfrommvr
2547 real(DP) :: qtomvr
2548 !
2549 ! -- call base functionality in bnd_cq. This will calculate sfr-gwf flows
2550 ! and put them into this%simvals
2551 call this%BndType%bnd_cq(x, flowja, iadv=1)
2552 !
2553 ! -- Calculate qextoutflow and qoutflow for subsequent budgets
2554 do n = 1, this%maxbound
2555 !
2556 ! -- mover
2557 qfrommvr = dzero
2558 qtomvr = dzero
2559 if (this%imover == 1) then
2560 qfrommvr = this%pakmvrobj%get_qfrommvr(n)
2561 qtomvr = this%pakmvrobj%get_qtomvr(n)
2562 if (qtomvr > dzero) then
2563 qtomvr = -qtomvr
2564 end if
2565 end if
2566 !
2567 ! -- external downstream stream flow
2568 qext = this%dsflow(n)
2569 qoutflow = dzero
2570 if (qext > dzero) then
2571 qext = -qext
2572 end if
2573 do i = this%ia(n) + 1, this%ia(n + 1) - 1
2574 if (this%idir(i) > 0) cycle
2575 n2 = this%ja(i)
2576 if (this%iboundpak(n2) == 0) cycle
2577 qext = dzero
2578 exit
2579 end do
2580 !
2581 ! -- adjust external downstream stream flow using qtomvr
2582 if (qext < dzero) then
2583 if (qtomvr < dzero) then
2584 qext = qext - qtomvr
2585 end if
2586 else
2587 qoutflow = this%dsflow(n)
2588 if (qoutflow > dzero) then
2589 qoutflow = -qoutflow
2590 end if
2591 end if
2592 !
2593 ! -- set qextoutflow and qoutflow for cell by cell budget
2594 ! output and observations
2595 this%qextoutflow(n) = qext
2596 this%qoutflow(n) = qoutflow
2597 !
2598 end do
2599 !
2600 ! -- fill the budget object
2601 call this%sfr_fill_budobj()
This module contains the BudgetModule.
Definition Budget.f90:20
Derived type for the Budget object.
Definition Budget.f90:40

◆ sfr_create()

subroutine, public sfrmodule::sfr_create ( class(bndtype), pointer packobj,
integer(i4b), intent(in) id,
integer(i4b), intent(in) ibcnum,
integer(i4b), intent(in) inunit,
integer(i4b), intent(in) iout,
character(len=*), intent(in) namemodel,
character(len=*), intent(in) pakname,
character(len=*), intent(in) mempath )

Create a new SFR Package object

Parameters
packobjpointer to default package type
[in]idpackage id
[in]ibcnumboundary condition number
[in]inunitunit number of SFR package input file
[in]ioutunit number of model listing file
[in]namemodelmodel name
[in]paknamepackage name
[in]mempathinput mempath

Definition at line 388 of file gwf-sfr.f90.

390 ! -- modules
392 ! -- dummy
393 class(BndType), pointer :: packobj !< pointer to default package type
394 integer(I4B), intent(in) :: id !< package id
395 integer(I4B), intent(in) :: ibcnum !< boundary condition number
396 integer(I4B), intent(in) :: inunit !< unit number of SFR package input file
397 integer(I4B), intent(in) :: iout !< unit number of model listing file
398 character(len=*), intent(in) :: namemodel !< model name
399 character(len=*), intent(in) :: pakname !< package name
400 character(len=*), intent(in) :: mempath !< input mempath
401 ! -- local
402 type(SfrType), pointer :: sfrobj
403 !
404 ! -- allocate the object and assign values to object variables
405 allocate (sfrobj)
406 packobj => sfrobj
407 !
408 ! -- create name and memory path
409 call packobj%set_names(ibcnum, namemodel, pakname, ftype, mempath)
410 packobj%text = text
411 !
412 ! -- allocate scalars
413 call sfrobj%sfr_allocate_scalars()
414 !
415 ! -- initialize package
416 call packobj%pack_initialize()
417
418 packobj%inunit = inunit
419 packobj%iout = iout
420 packobj%id = id
421 packobj%ibcnum = ibcnum
422 packobj%ncolbnd = 4
423 packobj%iscloc = 0 ! not supported
424 packobj%isadvpak = 1
425 packobj%ictMemPath = create_mem_path(namemodel, 'NPF')
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sfr_da()

subroutine sfrmodule::sfr_da ( class(sfrtype) this)
private

Deallocate SFR package scalars and arrays.

Parameters
thisSfrType object

Definition at line 2888 of file gwf-sfr.f90.

2889 ! -- modules
2891 ! -- dummy
2892 class(SfrType) :: this !< SfrType object
2893 !
2894 ! -- deallocate arrays
2895 call mem_deallocate(this%qoutflow)
2896 call mem_deallocate(this%qextoutflow)
2897 deallocate (this%csfrbudget)
2898 call mem_deallocate(this%sfrname, 'SFRNAME', this%memoryPath)
2899 call mem_deallocate(this%dbuff)
2900 deallocate (this%cauxcbc)
2901 call mem_deallocate(this%qauxcbc)
2902 call mem_deallocate(this%iboundpak)
2903 call mem_deallocate(this%igwfnode)
2904 call mem_deallocate(this%igwftopnode)
2905 call mem_deallocate(this%length)
2906 call mem_deallocate(this%width)
2907 call mem_deallocate(this%strtop)
2908 call mem_deallocate(this%bthick)
2909 call mem_deallocate(this%slope)
2910 call mem_deallocate(this%nconnreach)
2911 call mem_deallocate(this%bedk_set)
2912 call mem_deallocate(this%manning_set)
2913 call mem_deallocate(this%ustrf_set)
2914 call mem_deallocate(this%ftotnd)
2915 call mem_deallocate(this%usflow)
2916 call mem_deallocate(this%dsflow)
2917 call mem_deallocate(this%depth)
2918 call mem_deallocate(this%stage)
2919 call mem_deallocate(this%gwflow)
2920 call mem_deallocate(this%simevap)
2921 call mem_deallocate(this%simrunoff)
2922 call mem_deallocate(this%stage0)
2923 call mem_deallocate(this%usflow0)
2924 call mem_deallocate(this%denseterms)
2925 call mem_deallocate(this%viscratios)
2926 !
2927 ! -- stage, usflow, and dsflow for previous timestep
2928 if (this%istorage == 1) then
2929 call mem_deallocate(this%stageold)
2930 call mem_deallocate(this%dsflowold)
2931 call mem_deallocate(this%storage)
2932 call mem_deallocate(this%usinflow)
2933 call mem_deallocate(this%usinflowold)
2934 call mem_deallocate(this%crmin)
2935 call mem_deallocate(this%crmax)
2936 call mem_deallocate(this%crsum)
2937 call mem_deallocate(this%crcnt)
2938 call mem_deallocate(this%itvd_upstream)
2939 end if
2940 !
2941 ! -- deallocate reach order and connection data
2942 call mem_deallocate(this%isfrorder)
2943 call mem_deallocate(this%ia)
2944 call mem_deallocate(this%ja)
2945 call mem_deallocate(this%idir)
2946 call mem_deallocate(this%idiv)
2947 call mem_deallocate(this%qconn)
2948 !
2949 nullify (this%rain)
2950 nullify (this%evap)
2951 nullify (this%inflow)
2952 nullify (this%runoff)
2953 nullify (this%sstage)
2954 nullify (this%hk)
2955 nullify (this%rough)
2956 nullify (this%ustrf)
2957 !
2958 ! -- deallocate diversion variables
2959 call mem_deallocate(this%iadiv)
2960 call mem_deallocate(this%divreach)
2961 if (associated(this%divcprior)) then
2962 deallocate (this%divcprior)
2963 end if
2964 ! -- divflow is package-owned only when empty (no diversions); it is not
2965 ! associated if the simulation stopped before it was set
2966 if (associated(this%divflow)) then
2967 if (size(this%divflow) == 0) then
2968 call mem_deallocate(this%divflow)
2969 else
2970 nullify (this%divflow)
2971 end if
2972 end if
2973 call mem_deallocate(this%divq)
2974 call mem_deallocate(this%ndiv)
2975 !
2976 ! -- deallocate cross-section data
2977 call mem_deallocate(this%ncrosspts)
2978 call mem_deallocate(this%iacross)
2979 call mem_deallocate(this%station)
2980 call mem_deallocate(this%xsheight)
2981 call mem_deallocate(this%xsrough)
2982 !
2983 ! -- deallocate budobj
2984 call this%budobj%budgetobject_da()
2985 deallocate (this%budobj)
2986 nullify (this%budobj)
2987 !
2988 ! -- deallocate stage table
2989 if (this%iprhed > 0) then
2990 call this%stagetab%table_da()
2991 deallocate (this%stagetab)
2992 nullify (this%stagetab)
2993 end if
2994 !
2995 ! -- deallocate Courant number table
2996 if (associated(this%couranttab)) then
2997 call this%couranttab%table_da()
2998 deallocate (this%couranttab)
2999 nullify (this%couranttab)
3000 end if
3001 !
3002 ! -- deallocate package csv table
3003 if (this%ipakcsv > 0) then
3004 if (associated(this%pakcsvtab)) then
3005 call this%pakcsvtab%table_da()
3006 deallocate (this%pakcsvtab)
3007 nullify (this%pakcsvtab)
3008 end if
3009 end if
3010 !
3011 ! -- deallocate scalars
3012 call mem_deallocate(this%ats_courant)
3013 call mem_deallocate(this%istorage)
3014 call mem_deallocate(this%storage_weight)
3015 call mem_deallocate(this%iprhed)
3016 call mem_deallocate(this%istageout)
3017 call mem_deallocate(this%ibudgetout)
3018 call mem_deallocate(this%ibudcsv)
3019 call mem_deallocate(this%ipakcsv)
3020 call mem_deallocate(this%idiversions)
3021 call mem_deallocate(this%maxsfrpicard)
3022 call mem_deallocate(this%maxsfrit)
3023 call mem_deallocate(this%bditems)
3024 call mem_deallocate(this%cbcauxitems)
3025 call mem_deallocate(this%unitconv)
3026 call mem_deallocate(this%lengthconv)
3027 call mem_deallocate(this%timeconv)
3028 call mem_deallocate(this%dmaxchg)
3029 call mem_deallocate(this%deps)
3030 call mem_deallocate(this%nconn)
3031 call mem_deallocate(this%icheck)
3032 call mem_deallocate(this%iconvchk)
3033 call mem_deallocate(this%idense)
3034 call mem_deallocate(this%ianynone)
3035 call mem_deallocate(this%ncrossptstot)
3036 nullify (this%gwfiss)
3037 !
3038 ! -- nullify SFR input context pointers (input context owns the memory)
3039 call this%input%destroy()
3040 !
3041 ! -- call base BndExtType deallocate
3042 call this%BndExtType%bnd_da()

◆ sfr_df_obs()

subroutine sfrmodule::sfr_df_obs ( class(sfrtype) this)
private

Method to define the observation types available in the SFR package.

Parameters
thisSfrType object

Definition at line 3124 of file gwf-sfr.f90.

3125 ! -- dummy
3126 class(SfrType) :: this !< SfrType object
3127 ! -- local
3128 integer(I4B) :: indx
3129 !
3130 ! -- Store obs type and assign procedure pointer
3131 ! for stage observation type.
3132 call this%obs%StoreObsType('stage', .false., indx)
3133 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3134 !
3135 ! -- Store obs type and assign procedure pointer
3136 ! for inflow observation type.
3137 call this%obs%StoreObsType('inflow', .true., indx)
3138 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3139 !
3140 ! -- Store obs type and assign procedure pointer
3141 ! for inflow observation type.
3142 call this%obs%StoreObsType('ext-inflow', .true., indx)
3143 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3144 !
3145 ! -- Store obs type and assign procedure pointer
3146 ! for rainfall observation type.
3147 call this%obs%StoreObsType('rainfall', .true., indx)
3148 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3149 !
3150 ! -- Store obs type and assign procedure pointer
3151 ! for runoff observation type.
3152 call this%obs%StoreObsType('runoff', .true., indx)
3153 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3154 !
3155 ! -- Store obs type and assign procedure pointer
3156 ! for evaporation observation type.
3157 call this%obs%StoreObsType('evaporation', .true., indx)
3158 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3159 !
3160 ! -- Store obs type and assign procedure pointer
3161 ! for outflow observation type.
3162 call this%obs%StoreObsType('outflow', .true., indx)
3163 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3164 !
3165 ! -- Store obs type and assign procedure pointer
3166 ! for ext-outflow observation type.
3167 call this%obs%StoreObsType('ext-outflow', .true., indx)
3168 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3169 !
3170 ! -- Store obs type and assign procedure pointer
3171 ! for to-mvr observation type.
3172 call this%obs%StoreObsType('to-mvr', .true., indx)
3173 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3174 !
3175 ! -- Store obs type and assign procedure pointer
3176 ! for sfr-frommvr observation type.
3177 call this%obs%StoreObsType('from-mvr', .true., indx)
3178 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3179 !
3180 ! -- Store obs type and assign procedure pointer
3181 ! for sfr observation type.
3182 call this%obs%StoreObsType('sfr', .true., indx)
3183 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3184 !
3185 ! -- Store obs type and assign procedure pointer
3186 ! for upstream flow observation type.
3187 call this%obs%StoreObsType('upstream-flow', .true., indx)
3188 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3189 !
3190 ! -- Store obs type and assign procedure pointer
3191 ! for downstream flow observation type.
3192 call this%obs%StoreObsType('downstream-flow', .true., indx)
3193 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3194 !
3195 ! -- Store obs type and assign procedure pointer
3196 ! for depth observation type.
3197 call this%obs%StoreObsType('depth', .false., indx)
3198 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3199 !
3200 ! -- Store obs type and assign procedure pointer
3201 ! for wetted-perimeter observation type.
3202 call this%obs%StoreObsType('wet-perimeter', .false., indx)
3203 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3204 !
3205 ! -- Store obs type and assign procedure pointer
3206 ! for wetted-area observation type.
3207 call this%obs%StoreObsType('wet-area', .false., indx)
3208 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid
3209 !
3210 ! -- Store obs type and assign procedure pointer
3211 ! for wetted-width observation type.
3212 call this%obs%StoreObsType('wet-width', .false., indx)
3213 this%obs%obsData(indx)%ProcessIdPtr => sfr_process_obsid

◆ sfr_dt()

subroutine sfrmodule::sfr_dt ( class(sfrtype) this)
private
Parameters
thisSfrType object

Definition at line 2823 of file gwf-sfr.f90.

2824 ! -- modules
2825 use tdismodule, only: kstp, kper, ats
2826 ! -- dummy
2827 class(SfrType) :: this !< SfrType object
2828 ! -- local
2829 integer(I4B) :: n
2830 integer(I4B) :: nrmin
2831 real(DP) :: celerity
2832 real(DP) :: dt_n
2833 real(DP) :: dtmin
2834 character(len=LINELENGTH) :: msg
2835 !
2836 if (this%ats_courant == dnodata) return
2837 if (this%istorage /= 1) return
2838 !
2839 dtmin = dnodata
2840 nrmin = 0
2841 !
2842 do n = 1, this%maxbound
2843 call this%sfr_calc_celerity(n, this%dsflow(n), celerity)
2844 if (celerity > dzero) then
2845 dt_n = this%ats_courant * this%length(n) / celerity
2846 if (dt_n < dtmin) then
2847 dtmin = dt_n
2848 nrmin = n
2849 end if
2850 end if
2851 end do
2852 !
2853 if (nrmin > 0) then
2854 write (msg, '(a,i0)') trim(this%packName)//'-REACH-', nrmin
2855 call ats%ats_submit_delt(kstp, kper, dtmin, trim(msg))
2856 end if
class(atstype), pointer, public ats
Definition tdis.f90:48

◆ sfr_fc()

subroutine sfrmodule::sfr_fc ( class(sfrtype) this,
real(dp), dimension(:), intent(inout) rhs,
integer(i4b), dimension(:), intent(in) ia,
integer(i4b), dimension(:), intent(in) idxglo,
class(matrixbasetype), pointer matrix_sln )
private

Add the hcof and rhs terms for the SFR package to the coefficient matrix and right-hand side vector.

Parameters
thisSfrType object
[in,out]rhsright-hand side vector for model
[in]iasolution CRS row pointers
[in]idxglomapping vector for model (local) to solution (global)
matrix_slnsolution coefficient matrix

Definition at line 2180 of file gwf-sfr.f90.

2181 ! -- dummy
2182 class(SfrType) :: this !< SfrType object
2183 real(DP), dimension(:), intent(inout) :: rhs !< right-hand side vector for model
2184 integer(I4B), dimension(:), intent(in) :: ia !< solution CRS row pointers
2185 integer(I4B), dimension(:), intent(in) :: idxglo !< mapping vector for model (local) to solution (global)
2186 class(MatrixBaseType), pointer :: matrix_sln !< solution coefficient matrix
2187 ! -- local
2188 integer(I4B) :: i
2189 integer(I4B) :: j
2190 integer(I4B) :: n
2191 integer(I4B) :: ipos
2192 integer(I4B) :: node
2193 real(DP) :: s0
2194 real(DP) :: ds
2195 real(DP) :: dsmax
2196 real(DP) :: hgwf
2197 real(DP) :: v
2198 real(DP) :: hhcof
2199 real(DP) :: rrhs
2200 !
2201 ! -- picard iterations for sfr to achieve good solution regardless
2202 ! of reach order
2203 sfrpicard: do i = 1, this%maxsfrpicard
2204 !
2205 ! -- initialize maximum stage change for iteration to zero
2206 dsmax = dzero
2207 !
2208 ! -- pakmvrobj fc - reset qformvr to zero
2209 if (this%imover == 1) then
2210 call this%pakmvrobj%fc()
2211 end if
2212 !
2213 ! -- solve for each sfr reach
2214 reachsolve: do j = 1, this%nbound
2215 n = this%isfrorder(j)
2216 node = this%igwfnode(n)
2217 if (node > 0) then
2218 hgwf = this%xnew(node)
2219 else
2220 hgwf = dep20
2221 end if
2222 !
2223 ! -- save previous stage and upstream flow
2224 if (i == 1) then
2225 this%stage0(n) = this%stage(n)
2226 this%usflow0(n) = this%usflow(n)
2227 end if
2228 !
2229 ! -- set initial stage to calculate stage change
2230 s0 = this%stage(n)
2231 !
2232 ! -- solve for flow in swr
2233 if (this%iboundpak(n) /= 0) then
2234 call this%sfr_solve(n, hgwf, hhcof, rrhs)
2235 else
2236 this%depth(n) = dzero
2237 this%stage(n) = this%strtop(n)
2238 v = dzero
2239 call this%sfr_update_flows(n, v, v)
2240 hhcof = dzero
2241 rrhs = dzero
2242 end if
2243 !
2244 ! -- set package hcof and rhs
2245 this%hcof(n) = hhcof
2246 this%rhs(n) = rrhs
2247 !
2248 ! -- calculate stage change
2249 ds = s0 - this%stage(n)
2250 !
2251 ! -- evaluate if stage change exceeds dsmax
2252 if (abs(ds) > abs(dsmax)) then
2253 dsmax = ds
2254 end if
2255
2256 end do reachsolve
2257 !
2258 ! -- evaluate if the sfr picard iterations should be terminated
2259 if (abs(dsmax) <= this%dmaxchg) then
2260 exit sfrpicard
2261 end if
2262
2263 end do sfrpicard
2264 !
2265 ! -- Copy package rhs and hcof into solution rhs and amat
2266 do n = 1, this%nbound
2267 node = this%nodelist(n)
2268 if (node < 1) cycle
2269 rhs(node) = rhs(node) + this%rhs(n)
2270 ipos = ia(node)
2271 call matrix_sln%add_value_pos(idxglo(ipos), this%hcof(n))
2272 end do

◆ sfr_fill_budobj()

subroutine sfrmodule::sfr_fill_budobj ( class(sfrtype) this)
private

Method to copy flows into the budget object that stores all the sfr flows The terms listed here must correspond in number and order to the ones added in the sfr_setup_budobj method.

Parameters
thisSfrType object

Definition at line 5233 of file gwf-sfr.f90.

5234 ! -- dummy
5235 class(SfrType) :: this !< SfrType object
5236 ! -- local
5237 integer(I4B) :: naux
5238 integer(I4B) :: i
5239 integer(I4B) :: n
5240 integer(I4B) :: n1
5241 integer(I4B) :: n2
5242 integer(I4B) :: ii
5243 integer(I4B) :: idx
5244 integer(I4B) :: idiv
5245 integer(I4B) :: jpos
5246 real(DP) :: q
5247 real(DP) :: qt
5248 real(DP) :: d
5249 real(DP) :: ca
5250 real(DP) :: a
5251 real(DP) :: wp
5252 real(DP) :: l
5253 !
5254 ! -- initialize counter
5255 idx = 0
5256 !
5257 ! -- FLOW JA FACE
5258 idx = idx + 1
5259 call this%budobj%budterm(idx)%reset(this%nconn)
5260 do n = 1, this%maxbound
5261 n1 = n
5262 q = dzero
5263 ca = dzero
5264 do i = this%ia(n) + 1, this%ia(n + 1) - 1
5265 n2 = this%ja(i)
5266 if (this%iboundpak(n) /= 0) then
5267 ! flow to downstream reaches
5268 if (this%idir(i) < 0) then
5269 qt = this%dsflow(n)
5270 q = -this%qconn(i)
5271 ! flow from upstream reaches
5272 else
5273 qt = this%usflow(n)
5274 do ii = this%ia(n2) + 1, this%ia(n2 + 1) - 1
5275 if (this%idir(ii) > 0) cycle
5276 if (this%ja(ii) /= n) cycle
5277 q = this%qconn(ii)
5278 exit
5279 end do
5280 end if
5281 ! calculate flow area
5282 call this%sfr_calc_reach_depth(n, qt, d)
5283 ca = this%calc_area_wet(n, d)
5284 else
5285 q = dzero
5286 ca = dzero
5287 end if
5288 this%qauxcbc(1) = ca
5289 call this%budobj%budterm(idx)%update_term(n1, n2, q, this%qauxcbc)
5290 end do
5291 end do
5292 !
5293 ! -- GWF (LEAKAGE)
5294 idx = idx + 1
5295 call this%budobj%budterm(idx)%reset(this%maxbound - this%ianynone)
5296 do n = 1, this%maxbound
5297 n2 = this%igwfnode(n)
5298 if (n2 > 0) then
5299 if (this%iboundpak(n) /= 0) then
5300 ! -- calc_perimeter_wet() does not enforce depth dependence
5301 if (this%depth(n) > dzero) then
5302 wp = this%calc_perimeter_wet(n, this%depth(n))
5303 else
5304 wp = dzero
5305 end if
5306 l = this%length(n)
5307 a = wp * l
5308 this%qauxcbc(1) = a
5309 q = -this%gwflow(n)
5310 else
5311 this%qauxcbc(1) = dzero
5312 q = dzero
5313 end if
5314 call this%budobj%budterm(idx)%update_term(n, n2, q, this%qauxcbc)
5315 end if
5316 end do
5317 !
5318 ! -- RAIN
5319 idx = idx + 1
5320 call this%budobj%budterm(idx)%reset(this%maxbound)
5321 do n = 1, this%maxbound
5322 if (this%iboundpak(n) /= 0) then
5323 a = this%calc_surface_area(n)
5324 q = this%rain(n) * a
5325 else
5326 q = dzero
5327 end if
5328 call this%budobj%budterm(idx)%update_term(n, n, q)
5329 end do
5330 !
5331 ! -- EVAPORATION
5332 idx = idx + 1
5333 call this%budobj%budterm(idx)%reset(this%maxbound)
5334 do n = 1, this%maxbound
5335 if (this%iboundpak(n) /= 0) then
5336 q = -this%simevap(n)
5337 else
5338 q = dzero
5339 end if
5340 call this%budobj%budterm(idx)%update_term(n, n, q)
5341 end do
5342 !
5343 ! -- RUNOFF
5344 idx = idx + 1
5345 call this%budobj%budterm(idx)%reset(this%maxbound)
5346 do n = 1, this%maxbound
5347 if (this%iboundpak(n) /= 0) then
5348 q = this%simrunoff(n)
5349 else
5350 q = dzero
5351 end if
5352 call this%budobj%budterm(idx)%update_term(n, n, q)
5353 end do
5354 !
5355 ! -- INFLOW
5356 idx = idx + 1
5357 call this%budobj%budterm(idx)%reset(this%maxbound)
5358 do n = 1, this%maxbound
5359 if (this%iboundpak(n) /= 0) then
5360 q = this%inflow(n)
5361 else
5362 q = dzero
5363 end if
5364 call this%budobj%budterm(idx)%update_term(n, n, q)
5365 end do
5366 !
5367 ! -- EXTERNAL OUTFLOW
5368 idx = idx + 1
5369 call this%budobj%budterm(idx)%reset(this%maxbound)
5370 do n = 1, this%maxbound
5371 q = dzero
5372 if (this%iboundpak(n) /= 0) then
5373 do i = this%ia(n) + 1, this%ia(n + 1) - 1
5374 if (this%idir(i) > 0) cycle
5375 idiv = this%idiv(i)
5376 if (idiv > 0) then
5377 jpos = this%iadiv(n) + idiv - 1
5378 q = q + this%divq(jpos)
5379 else
5380 q = q + this%qconn(i)
5381 end if
5382 end do
5383 q = q - this%dsflow(n)
5384 if (this%imover == 1) then
5385 q = q + this%pakmvrobj%get_qtomvr(n)
5386 end if
5387 else
5388 if (this%imover == 1) then
5389 q = this%pakmvrobj%get_qfrommvr(n)
5390 end if
5391 end if
5392 call this%budobj%budterm(idx)%update_term(n, n, q)
5393 end do
5394 !
5395 ! -- STORAGE
5396 idx = idx + 1
5397 call this%budobj%budterm(idx)%reset(this%maxbound)
5398 do n = 1, this%maxbound
5399 q = dzero
5400 if (this%iboundpak(n) /= 0) then
5401 d = this%depth(n)
5402 a = this%calc_surface_area_wet(n, d)
5403 this%qauxcbc(1) = a * d
5404 if (this%gwfiss == 0 .and. this%istorage == 1) then
5405 q = this%storage(n)
5406 end if
5407 else
5408 q = dzero
5409 this%qauxcbc(1) = dzero
5410 end if
5411 call this%budobj%budterm(idx)%update_term(n, n, q, this%qauxcbc)
5412 end do
5413 !
5414 ! -- MOVER
5415 if (this%imover == 1) then
5416 !
5417 ! -- FROM MOVER
5418 idx = idx + 1
5419 call this%budobj%budterm(idx)%reset(this%maxbound)
5420 do n = 1, this%maxbound
5421 q = dzero
5422 if (this%iboundpak(n) /= 0) then
5423 q = this%pakmvrobj%get_qfrommvr(n)
5424 end if
5425 call this%budobj%budterm(idx)%update_term(n, n, q)
5426 end do
5427 !
5428 ! -- TO MOVER
5429 idx = idx + 1
5430 call this%budobj%budterm(idx)%reset(this%maxbound)
5431 do n = 1, this%maxbound
5432 if (this%iboundpak(n) /= 0) then
5433 q = this%pakmvrobj%get_qtomvr(n)
5434 if (q > dzero) then
5435 q = -q
5436 end if
5437 else
5438 q = dzero
5439 end if
5440 call this%budobj%budterm(idx)%update_term(n, n, q)
5441 end do
5442 end if
5443 !
5444 ! -- AUXILIARY VARIABLES
5445 naux = this%naux
5446 if (naux > 0) then
5447 idx = idx + 1
5448 call this%budobj%budterm(idx)%reset(this%maxbound)
5449 do n = 1, this%maxbound
5450 q = dzero
5451 call this%budobj%budterm(idx)%update_term(n, n, q, this%auxvar(:, n))
5452 end do
5453 end if
5454 !
5455 ! --Terms are filled, now accumulate them for this time step
5456 call this%budobj%accumulate_terms()

◆ sfr_fn()

subroutine sfrmodule::sfr_fn ( class(sfrtype) this,
real(dp), dimension(:), intent(inout) rhs,
integer(i4b), dimension(:), intent(in) ia,
integer(i4b), dimension(:), intent(in) idxglo,
class(matrixbasetype), pointer matrix_sln )
private

Calculate and add the Newton-Raphson terms for the SFR package to the coefficient matrix and right-hand side vector.

Parameters
thisSfrType object
[in,out]rhsright-hand side vector for model
[in]iasolution CRS row pointers
[in]idxglomapping vector for model (local) to solution (global)
matrix_slnsolution coefficient matrix

Definition at line 2280 of file gwf-sfr.f90.

2281 ! -- dummy
2282 class(SfrType) :: this !< SfrType object
2283 real(DP), dimension(:), intent(inout) :: rhs !< right-hand side vector for model
2284 integer(I4B), dimension(:), intent(in) :: ia !< solution CRS row pointers
2285 integer(I4B), dimension(:), intent(in) :: idxglo !< mapping vector for model (local) to solution (global)
2286 class(MatrixBaseType), pointer :: matrix_sln !< solution coefficient matrix
2287 ! -- local
2288 integer(I4B) :: i
2289 integer(I4B) :: j
2290 integer(I4B) :: n
2291 integer(I4B) :: ipos
2292 real(DP) :: rterm
2293 real(DP) :: drterm
2294 real(DP) :: rhs1
2295 real(DP) :: hcof1
2296 real(DP) :: q1
2297 real(DP) :: q2
2298 real(DP) :: hgwf
2299 !
2300 ! -- Copy package rhs and hcof into solution rhs and amat
2301 do j = 1, this%nbound
2302 i = this%isfrorder(j)
2303 ! -- skip inactive reaches
2304 if (this%iboundpak(i) < 1) cycle
2305 ! -- skip if reach is not connected to gwf
2306 n = this%nodelist(i)
2307 if (n < 1) cycle
2308 ipos = ia(n)
2309 rterm = this%hcof(i) * this%xnew(n)
2310 ! -- calculate perturbed head
2311 hgwf = this%xnew(n) + dem4
2312 call this%sfr_solve(i, hgwf, hcof1, rhs1, update=.false.)
2313 q1 = rhs1 - hcof1 * hgwf
2314 ! -- calculate unperturbed head
2315 q2 = this%rhs(i) - this%hcof(i) * this%xnew(n)
2316 ! -- calculate derivative
2317 drterm = (q2 - q1) / dem4
2318 ! -- add terms to convert conductance formulation into
2319 ! newton-raphson formulation
2320 call matrix_sln%add_value_pos(idxglo(ipos), drterm - this%hcof(i))
2321 rhs(n) = rhs(n) - rterm + drterm * this%xnew(n)
2322 end do

◆ sfr_fp()

subroutine sfrmodule::sfr_fp ( class(sfrtype) this)
private
Parameters
thisSfrType object

Definition at line 2788 of file gwf-sfr.f90.

2789 ! -- dummy
2790 class(SfrType) :: this !< SfrType object
2791 ! -- local
2792 integer(I4B) :: n
2793 real(DP) :: crmean
2794 !
2795 if (this%istorage == 1) then
2796 do n = 1, this%maxbound
2797 if (this%inamedbound == 1) then
2798 call this%couranttab%add_term(this%boundname(n))
2799 end if
2800 call this%couranttab%add_term(n)
2801 if (this%crmin(n) == dep20) then
2802 call this%couranttab%add_term('--')
2803 else
2804 call this%couranttab%add_term(this%crmin(n))
2805 end if
2806 if (this%crmax(n) < dzero) then
2807 call this%couranttab%add_term('--')
2808 else
2809 call this%couranttab%add_term(this%crmax(n))
2810 end if
2811 if (this%crcnt(n) > 0) then
2812 crmean = this%crsum(n) / real(this%crcnt(n), dp)
2813 call this%couranttab%add_term(crmean)
2814 else
2815 call this%couranttab%add_term('--')
2816 end if
2817 end do
2818 end if

◆ sfr_gwf_conn()

integer(i4b) function sfrmodule::sfr_gwf_conn ( class(sfrtype) this,
integer(i4b), intent(in) n )
private

Function to determine if a reach is connected to a gwf cell. If connected, the return value is 1. Otherwise, the return value is 0.

Returns
flag indicating if reach is connected to a gwf cell
Parameters
thisSfrType object
[in]nreach number

Definition at line 3972 of file gwf-sfr.f90.

3973 ! -- return variable
3974 integer(I4B) :: sfr_gwf_conn !< flag indicating if reach is connected to a gwf cell
3975 ! -- dummy
3976 class(SfrType) :: this !< SfrType object
3977 integer(I4B), intent(in) :: n !< reach number
3978 ! -- local
3979 integer(I4B) :: node
3980
3981 sfr_gwf_conn = 0
3982 node = this%igwfnode(n)
3983 if (node > 0 .and. this%hk(n) > dzero) then
3984 sfr_gwf_conn = 1
3985 end if

◆ sfr_input_destroy()

subroutine sfrmodule::sfr_input_destroy ( class(sfrinputtype), intent(inout) this)
private

Definition at line 5884 of file gwf-sfr.f90.

5885 class(SfrInputType), intent(inout) :: this
5886 nullify (this%rhk)
5887 nullify (this%man)
5888 nullify (this%ustrf)
5889 nullify (this%rhk_tslink)
5890 nullify (this%man_tslink)
5891 nullify (this%ustrf_tslink)
5892 nullify (this%nbound)
5893 nullify (this%ifno)
5894 nullify (this%status)
5895 nullify (this%setting)
5896 nullify (this%idv)
5897 nullify (this%tab6_filename)
5898 nullify (this%auxname)
5899 nullify (this%auxval)

◆ sfr_input_init()

subroutine sfrmodule::sfr_input_init ( class(sfrinputtype), intent(inout) this,
character(len=*), intent(in) mempath,
integer(i4b), intent(in) naux )
private

Called once from sfr_ar; PACKAGEDATA pointers are set separately in sfr_source_packagedata.

Definition at line 5865 of file gwf-sfr.f90.

5867 class(SfrInputType), intent(inout) :: this
5868 character(len=*), intent(in) :: mempath
5869 integer(I4B), intent(in) :: naux
5870 call mem_setptr(this%nbound, 'NBOUND', mempath)
5871 call mem_setptr(this%ifno, 'IFNO', mempath)
5872 call mem_setptr(this%setting, 'SETTING', mempath)
5873 call mem_setptr(this%status, 'STATUS', mempath)
5874 call mem_setptr(this%idv, 'IDV', mempath)
5875 call mem_setptr(this%tab6_filename, 'TAB6_FILENAME', mempath)
5876 if (naux > 0) then
5877 call mem_setptr(this%auxname, 'AUXNAME', mempath)
5878 call mem_setptr(this%auxval, 'AUXVAL', mempath)
5879 end if

◆ sfr_obs_supported()

logical function sfrmodule::sfr_obs_supported ( class(sfrtype) this)
private

Function to determine if observations are supported by the SFR package. Observations are supported by the SFR package.

Returns
sfr_obs_supported boolean indicating if observations are supported
Parameters
thisSfrType object

Definition at line 3112 of file gwf-sfr.f90.

3113 ! -- dummy
3114 class(SfrType) :: this !< SfrType object
3115 !
3116 ! -- set boolean
3117 sfr_obs_supported = .true.

◆ sfr_ot_bdsummary()

subroutine sfrmodule::sfr_ot_bdsummary ( class(sfrtype) this,
integer(i4b), intent(in) kstp,
integer(i4b), intent(in) kper,
integer(i4b), intent(in) iout,
integer(i4b), intent(in) ibudfl )
private

Output SFR package budget summary.

Parameters
thisSfrType object
[in]kstptime step number
[in]kperperiod number
[in]ioutflag and unit number for the model listing file
[in]ibudflflag indicating budget should be written

Definition at line 2773 of file gwf-sfr.f90.

2774 ! -- module
2775 use tdismodule, only: totim, delt
2776 ! -- dummy
2777 class(SfrType) :: this !< SfrType object
2778 integer(I4B), intent(in) :: kstp !< time step number
2779 integer(I4B), intent(in) :: kper !< period number
2780 integer(I4B), intent(in) :: iout !< flag and unit number for the model listing file
2781 integer(I4B), intent(in) :: ibudfl !< flag indicating budget should be written
2782 !
2783 call this%budobj%write_budtable(kstp, kper, iout, ibudfl, totim, delt)

◆ sfr_ot_dv()

subroutine sfrmodule::sfr_ot_dv ( class(sfrtype) this,
integer(i4b), intent(in) idvsave,
integer(i4b), intent(in) idvprint )
private

Output SFR boundary package dependent-variable terms.

Parameters
thisSfrType object
[in]idvsaveflag and unit number for dependent-variable output
[in]idvprintflag indicating if dependent-variable should be written to the model listing file

Definition at line 2661 of file gwf-sfr.f90.

2662 ! -- modules
2663 use tdismodule, only: kstp, kper, pertim, totim
2664 use inputoutputmodule, only: ulasav
2665 ! -- dummy
2666 class(SfrType) :: this !< SfrType object
2667 integer(I4B), intent(in) :: idvsave !< flag and unit number for dependent-variable output
2668 integer(I4B), intent(in) :: idvprint !< flag indicating if dependent-variable should be written to the model listing file
2669 ! -- local
2670 character(len=20) :: cellid
2671 integer(I4B) :: ibinun
2672 integer(I4B) :: n
2673 integer(I4B) :: node
2674 real(DP) :: d
2675 real(DP) :: v
2676 real(DP) :: hgwf
2677 real(DP) :: sbot
2678 real(DP) :: depth
2679 real(DP) :: stage
2680 real(DP) :: w
2681 real(DP) :: cond
2682 real(DP) :: grad
2683 !
2684 ! -- set unit number for binary dependent variable output
2685 ibinun = 0
2686 if (this%istageout /= 0) then
2687 ibinun = this%istageout
2688 end if
2689 if (idvsave == 0) ibinun = 0
2690 !
2691 ! -- write sfr binary output
2692 if (ibinun > 0) then
2693 do n = 1, this%maxbound
2694 d = this%depth(n)
2695 v = this%stage(n)
2696 if (this%iboundpak(n) == 0) then
2697 v = dhnoflo
2698 else if (d == dzero) then
2699 v = dhdry
2700 end if
2701 this%dbuff(n) = v
2702 end do
2703 call ulasav(this%dbuff, ' STAGE', kstp, kper, pertim, totim, &
2704 this%maxbound, 1, 1, ibinun)
2705 end if
2706 !
2707 ! -- print sfr stage and depth table
2708 if (idvprint /= 0 .and. this%iprhed /= 0) then
2709 !
2710 ! -- set table kstp and kper
2711 call this%stagetab%set_kstpkper(kstp, kper)
2712 !
2713 ! -- fill stage data
2714 do n = 1, this%maxbound
2715 node = this%igwfnode(n)
2716 if (node > 0) then
2717 call this%dis%noder_to_string(node, cellid)
2718 hgwf = this%xnew(node)
2719 else
2720 cellid = 'NONE'
2721 end if
2722 if (this%inamedbound == 1) then
2723 call this%stagetab%add_term(this%boundname(n))
2724 end if
2725 call this%stagetab%add_term(n)
2726 call this%stagetab%add_term(cellid)
2727 if (this%iboundpak(n) /= 0) then
2728 depth = this%depth(n)
2729 stage = this%stage(n)
2730 w = this%calc_top_width_wet(n, depth)
2731 call this%sfr_calc_cond(n, depth, cond, stage, hgwf)
2732 else
2733 depth = dhnoflo
2734 stage = dhnoflo
2735 w = dhnoflo
2736 cond = dhnoflo
2737 end if
2738 if (depth == dzero) then
2739 call this%stagetab%add_term(dhdry)
2740 else
2741 call this%stagetab%add_term(stage)
2742 end if
2743 call this%stagetab%add_term(depth)
2744 call this%stagetab%add_term(w)
2745 if (node > 0) then
2746 if (this%iboundpak(n) /= 0) then
2747 sbot = this%strtop(n) - this%bthick(n)
2748 if (hgwf < sbot) then
2749 grad = stage - sbot
2750 else
2751 grad = stage - hgwf
2752 end if
2753 grad = grad / this%bthick(n)
2754 else
2755 grad = dhnoflo
2756 end if
2757 call this%stagetab%add_term(hgwf)
2758 call this%stagetab%add_term(cond)
2759 call this%stagetab%add_term(grad)
2760 else
2761 call this%stagetab%add_term('--')
2762 call this%stagetab%add_term('--')
2763 call this%stagetab%add_term('--')
2764 end if
2765 end do
2766 end if
subroutine, public ulasav(buf, text, kstp, kper, pertim, totim, ncol, nrow, ilay, ichn)
Save 1 layer array on disk.
real(dp), pointer, public pertim
time relative to start of stress period
Definition tdis.f90:33
Here is the call graph for this function:

◆ sfr_ot_package_flows()

subroutine sfrmodule::sfr_ot_package_flows ( class(sfrtype) this,
integer(i4b), intent(in) icbcfl,
integer(i4b), intent(in) ibudfl )
private

Output SFR package flow terms.

Parameters
thisSfrType object
[in]icbcflflag and unit number for cell-by-cell output
[in]ibudflflag indication if cell-by-cell data should be saved

Definition at line 2608 of file gwf-sfr.f90.

2609 ! -- modules
2610 use tdismodule, only: kstp, kper, delt, pertim, totim
2611 ! -- dummy
2612 class(SfrType) :: this !< SfrType object
2613 integer(I4B), intent(in) :: icbcfl !< flag and unit number for cell-by-cell output
2614 integer(I4B), intent(in) :: ibudfl !< flag indication if cell-by-cell data should be saved
2615 ! -- local
2616 integer(I4B) :: ibinun
2617 character(len=20), dimension(:), allocatable :: cellidstr
2618 integer(I4B) :: n
2619 integer(I4B) :: node
2620 !
2621 ! -- write the flows from the budobj
2622 ibinun = 0
2623 if (this%ibudgetout /= 0) then
2624 ibinun = this%ibudgetout
2625 end if
2626 if (icbcfl == 0) ibinun = 0
2627 if (ibinun > 0) then
2628 call this%budobj%save_flows(this%dis, ibinun, kstp, kper, delt, &
2629 pertim, totim, this%iout)
2630 end if
2631 !
2632 ! -- Print sfr flows table
2633 if (ibudfl /= 0 .and. this%iprflow /= 0) then
2634 !
2635 ! -- If there are any 'none' gwf connections then need to calculate
2636 ! a vector of cellids and pass that in to the budget flow table because
2637 ! the table assumes that there are maxbound gwf entries, which is not
2638 ! the case if any 'none's are specified.
2639 if (this%ianynone > 0) then
2640 allocate (cellidstr(this%maxbound))
2641 do n = 1, this%maxbound
2642 node = this%igwfnode(n)
2643 if (node > 0) then
2644 call this%dis%noder_to_string(node, cellidstr(n))
2645 else
2646 cellidstr(n) = 'NONE'
2647 end if
2648 end do
2649 call this%budobj%write_flowtable(this%dis, kstp, kper, cellidstr)
2650 deallocate (cellidstr)
2651 else
2652 call this%budobj%write_flowtable(this%dis, kstp, kper)
2653 end if
2654 end if

◆ sfr_precompute_tvd()

subroutine sfrmodule::sfr_precompute_tvd ( class(sfrtype), intent(inout) this)
private

Index 0 for reaches with zero or multiple upstream connections.

Parameters
[in,out]thisSfrType object

Definition at line 3049 of file gwf-sfr.f90.

3050 ! -- dummy
3051 class(SfrType), intent(inout) :: this !< SfrType object
3052 ! -- local
3053 integer(I4B) :: n
3054 integer(I4B) :: j
3055 integer(I4B) :: iup_count
3056 integer(I4B) :: m
3057 !
3058 do n = 1, this%maxbound
3059 iup_count = 0
3060 m = 0
3061 do j = this%ia(n) + 1, this%ia(n + 1) - 1
3062 if (this%idir(j) > 0) then
3063 iup_count = iup_count + 1
3064 m = this%ja(j)
3065 end if
3066 end do
3067 if (iup_count == 1) then
3068 this%itvd_upstream(n) = m
3069 else
3070 this%itvd_upstream(n) = 0
3071 end if
3072 end do

◆ sfr_process_obsid()

subroutine sfrmodule::sfr_process_obsid ( type(observetype), intent(inout) obsrv,
class(disbasetype), intent(in) dis,
integer(i4b), intent(in) inunitobs,
integer(i4b), intent(in) iout )
private

Method to process observation ID strings for a SFR package.

Parameters
[in,out]obsrvObservation object
[in]disDiscretization object
[in]inunitobsfile unit number for the package observation file
[in]ioutmodel listing file unit number

Definition at line 3424 of file gwf-sfr.f90.

3425 ! -- dummy
3426 type(ObserveType), intent(inout) :: obsrv !< Observation object
3427 class(DisBaseType), intent(in) :: dis !< Discretization object
3428 integer(I4B), intent(in) :: inunitobs !< file unit number for the package observation file
3429 integer(I4B), intent(in) :: iout !< model listing file unit number
3430 ! -- local
3431 integer(I4B) :: nn1
3432 integer(I4B) :: icol
3433 integer(I4B) :: istart
3434 integer(I4B) :: istop
3435 character(len=LINELENGTH) :: string
3436 character(len=LENBOUNDNAME) :: bndname
3437 !
3438 ! -- initialize local variables
3439 string = obsrv%IDstring
3440 !
3441 ! -- Extract reach number from string and store it.
3442 ! If 1st item is not an integer(I4B), it should be a
3443 ! boundary name--deal with it.
3444 icol = 1
3445 !
3446 ! -- get reach number or boundary name
3447 call extract_idnum_or_bndname(string, icol, istart, istop, nn1, bndname)
3448 if (nn1 == namedboundflag) then
3449 obsrv%FeatureName = bndname
3450 end if
3451 !
3452 ! -- store reach number (NodeNumber)
3453 obsrv%NodeNumber = nn1

◆ sfr_rp()

subroutine sfrmodule::sfr_rp ( class(sfrtype), intent(inout) this)
private

Method to read and prepare period data for the SFR package.

Parameters
[in,out]thisSfrType object

Definition at line 1804 of file gwf-sfr.f90.

1805 ! -- modules
1806 use constantsmodule, only: lenvarname
1807 use tdismodule, only: kper
1810 ! -- dummy
1811 class(SfrType), intent(inout) :: this !< SfrType object
1812 ! -- local
1813 character(len=LINELENGTH) :: crossfile
1814 character(len=LINELENGTH) :: str
1815 real(DP) :: auxvaldbl
1816 character(len=LINELENGTH) :: title
1817 character(len=LINELENGTH) :: text
1818 character(len=LENVARNAME) :: setting
1819 character(len=10) :: cnum
1820 character(len=10) :: cp
1821 integer(I4B) :: n
1822 integer(I4B) :: i
1823 integer(I4B) :: ii
1824 integer(I4B) :: jj
1825 integer(I4B) :: idiv
1826 integer(I4B) :: ichkustrm
1827 integer(I4B) :: ncrossptstot
1828 type(SfrCrossSection), pointer :: cross_data => null()
1829 ! -- formats
1830 character(len=*), parameter :: fmtlsp = &
1831 &"(1X,/1X,'REUSING ',A,'S FROM LAST STRESS PERIOD')"
1832 !
1833 ! -- initialize flags
1834 ichkustrm = 0
1835 if (kper == 1) then
1836 ichkustrm = 1
1837 end if
1838 !
1839 ! -- set nbound to maxbound
1840 this%nbound = this%maxbound
1841 !
1842 ! -- check if input context has been updated for this stress period
1843 if (this%iper == kper) then
1844 !
1845 ! -- create and initialize cross-section data
1846 call cross_section_cr(cross_data, this%iout, this%iprpak, this%maxbound)
1847 call cross_data%initialize(this%ncrossptstot, this%ncrosspts, &
1848 this%iacross, &
1849 this%station, this%xsheight, &
1850 this%xsrough)
1851 !
1852 ! -- setup table to echo period data
1853 if (this%iprpak /= 0) then
1854 title = trim(adjustl(this%text))//' PACKAGE ('// &
1855 trim(adjustl(this%packName))//') DATA FOR PERIOD'
1856 write (title, '(a,1x,i6)') trim(adjustl(title)), kper
1857 call table_cr(this%inputtab, this%packName, title)
1858 call this%inputtab%table_df(1, 4, this%iout, finalize=.false.)
1859 text = 'NUMBER'
1860 call this%inputtab%initialize_column(text, 10, alignment=tabcenter)
1861 text = 'KEYWORD'
1862 call this%inputtab%initialize_column(text, 20, alignment=tableft)
1863 do jj = 1, 2
1864 write (text, '(a,1x,i6)') 'VALUE', jj
1865 call this%inputtab%initialize_column(text, 15, alignment=tabcenter)
1866 end do
1867 end if
1868 !
1869 ! -- process each period data entry
1870 do i = 1, this%input%nbound
1871 n = this%input%ifno(i)
1872 if (n < 1 .or. n > this%maxbound) then
1873 write (errmsg, '(a,1x,a,1x,i0,a)') &
1874 'Reach number (RNO) must be greater than 0 and', &
1875 'less than or equal to', this%maxbound, '.'
1876 call store_error(errmsg)
1877 cycle
1878 end if
1879 !
1880 ! -- dispatch key for this row
1881 setting = this%input%setting(i)
1882 !
1883 ! -- STATUS
1884 if (trim(setting) == 'STATUS') then
1885 str = this%input%status(i)
1886 ichkustrm = 1
1887 if (str == 'INACTIVE') then
1888 this%iboundpak(n) = 0
1889 else if (str == 'ACTIVE') then
1890 this%iboundpak(n) = 1
1891 else if (str == 'SIMPLE') then
1892 this%iboundpak(n) = -1
1893 else
1894 write (errmsg, '(2a)') &
1895 'Unknown '//trim(this%text)//' sfr status keyword: ', trim(str)
1896 call store_error(errmsg)
1897 end if
1898 end if
1899 !
1900 ! -- BEDK, MANNING, STAGE, INFLOW, RAINFALL, EVAPORATION, RUNOFF,
1901 ! UPSTREAM_FRAC; sfr_ad re-syncs these each timestep if TS-linked
1902 call this%sfr_set_period_value(i, n, setting)
1903 if (trim(setting) == 'UPSTREAM_FRAC') ichkustrm = 1
1904 !
1905 ! -- DIVERSION (compound group)
1906 if (trim(setting) == 'DIVERSION') then
1907 if (this%ndiv(n) < 1) then
1908 write (cnum, '(i0)') n
1909 errmsg = 'diversions cannot be specified for reach '//trim(cnum)
1910 call store_error(errmsg)
1911 else
1912 idiv = this%input%idv(i)
1913 if (idiv < 1 .or. idiv > this%ndiv(n)) then
1914 write (cnum, '(i0)') n
1915 errmsg = 'Reach '//trim(cnum)
1916 write (cnum, '(i0)') this%ndiv(n)
1917 errmsg = trim(errmsg)//' diversion number should be between 1 '// &
1918 'and '//trim(cnum)//'.'
1919 call store_error(errmsg)
1920 else
1921 ii = this%iadiv(n) + idiv - 1
1922 ! -- if cprior is 'FRACTION', check 0.0 <= divflow <= 1.0
1923 cp = this%divcprior(ii)
1924 if (cp == 'FRACTION' .and. &
1925 (this%divflow(ii) < dzero .or. this%divflow(ii) > done)) then
1926 write (errmsg, '(a,1x,i0,a)') &
1927 'cprior is type FRACTION for diversion no.', ii, &
1928 ', but divflow not within the range 0.0 to 1.0'
1929 call store_error(errmsg)
1930 end if
1931 end if
1932 end if
1933 end if
1934 !
1935 ! -- CROSS_SECTION (compound group)
1936 if (trim(setting) == 'CROSS_SECTION') then
1937 crossfile = this%input%tab6_filename(i)
1938 call cross_data%read_table(n, this%width(n), trim(adjustl(crossfile)))
1939 end if
1940 !
1941 ! -- AUXILIARY (compound group): featureauxvar already holds the
1942 ! -- current value; only extract auxname for echoing this row
1943 if (this%naux > 0) then
1944 if (trim(setting) == 'PERIOD_AUXILIARY') then
1945 str = this%input%auxname(i)
1946 auxvaldbl = this%input%auxval(i)
1947 end if
1948 end if
1949 !
1950 ! -- echo row to period data table
1951 if (this%iprpak /= 0) then
1952 call this%inputtab%add_term(n)
1953 if (trim(setting) == 'PERIOD_AUXILIARY') then
1954 call this%inputtab%add_term('AUXILIARY')
1955 else
1956 call this%inputtab%add_term(trim(setting))
1957 end if
1958 select case (trim(setting))
1959 case ('STATUS')
1960 call this%inputtab%add_term(trim(str))
1961 call this%inputtab%add_term(' ')
1962 case ('BEDK')
1963 call this%inputtab%add_term(this%hk(n))
1964 call this%inputtab%add_term(' ')
1965 case ('MANNING')
1966 call this%inputtab%add_term(this%rough(n))
1967 call this%inputtab%add_term(' ')
1968 case ('STAGE')
1969 call this%inputtab%add_term(this%sstage(n))
1970 call this%inputtab%add_term(' ')
1971 case ('INFLOW')
1972 call this%inputtab%add_term(this%inflow(n))
1973 call this%inputtab%add_term(' ')
1974 case ('RAINFALL')
1975 call this%inputtab%add_term(this%rain(n))
1976 call this%inputtab%add_term(' ')
1977 case ('EVAPORATION')
1978 call this%inputtab%add_term(this%evap(n))
1979 call this%inputtab%add_term(' ')
1980 case ('RUNOFF')
1981 call this%inputtab%add_term(this%runoff(n))
1982 call this%inputtab%add_term(' ')
1983 case ('UPSTREAM_FRAC')
1984 call this%inputtab%add_term(this%ustrf(n))
1985 call this%inputtab%add_term(' ')
1986 case ('DIVERSION')
1987 call this%inputtab%add_term(idiv)
1988 call this%inputtab%add_term(this%divflow(ii))
1989 case ('CROSS_SECTION')
1990 call this%inputtab%add_term(trim(crossfile))
1991 call this%inputtab%add_term(' ')
1992 case ('PERIOD_AUXILIARY')
1993 call this%inputtab%add_term(trim(str))
1994 call this%inputtab%add_term(auxvaldbl)
1995 case default
1996 call this%inputtab%add_term(' ')
1997 call this%inputtab%add_term(' ')
1998 end select
1999 end if
2000 end do
2001 if (this%iprpak /= 0) then
2002 call this%inputtab%finalize_table()
2003 end if
2004 !
2005 ! -- determine the current size of cross-section data
2006 ncrossptstot = cross_data%get_ncrossptstot()
2007 !
2008 ! -- reallocate sfr package cross-section data if size changed
2009 if (ncrossptstot /= this%ncrossptstot) then
2010 this%ncrossptstot = ncrossptstot
2011 call mem_reallocate(this%station, this%ncrossptstot, 'STATION', &
2012 this%memoryPath)
2013 call mem_reallocate(this%xsheight, this%ncrossptstot, 'XSHEIGHT', &
2014 this%memoryPath)
2015 call mem_reallocate(this%xsrough, this%ncrossptstot, 'XSROUGH', &
2016 this%memoryPath)
2017 end if
2018 !
2019 ! -- write cross-section data to the model listing file
2020 call cross_data%output(this%width, this%rough, kstp=1, kper=kper)
2021 !
2022 ! -- pack cross-section data
2023 call cross_data%pack(this%ncrossptstot, this%ncrosspts, &
2024 this%iacross, &
2025 this%station, &
2026 this%xsheight, &
2027 this%xsrough)
2028 !
2029 ! -- deallocate temporary local storage for reach cross-sections
2030 call cross_data%destroy()
2031 deallocate (cross_data)
2032 nullify (cross_data)
2033 else
2034 write (this%iout, fmtlsp) trim(this%filtyp)
2035 end if
2036 !
2037 ! -- check upstream fraction values every period; ftotnd must be
2038 ! initialized for sfr_update_flows even when there is no period data
2039 if (ichkustrm /= 0) then
2040 call this%sfr_check_ustrf()
2041 end if
2042 !
2043 ! -- write summary of package block error messages
2044 if (count_errors() > 0) then
2045 call store_error_filename(this%input_fname)
2046 end if
@ tabcenter
centered table column
@ tableft
left justified table column
real(dp), parameter done
real constant 1
Definition Constants.f90:76
subroutine, public cross_section_cr(this, iout, iprpak, nreaches)
Create a cross-section object.
Here is the call graph for this function:

◆ sfr_rp_obs()

subroutine sfrmodule::sfr_rp_obs ( class(sfrtype), intent(inout) this)
private

Method to read and prepare observations for a SFR package.

Parameters
[in,out]thisSfrType object

Definition at line 3312 of file gwf-sfr.f90.

3313 ! -- modules
3314 use tdismodule, only: kper
3315 ! -- dummy
3316 class(SfrType), intent(inout) :: this !< SfrType object
3317 ! -- local
3318 integer(I4B) :: i
3319 integer(I4B) :: j
3320 integer(I4B) :: nn1
3321 character(len=LENBOUNDNAME) :: bname
3322 logical(LGP) :: jfound
3323 class(ObserveType), pointer :: obsrv => null()
3324 ! -- formats
332510 format('Boundary "', a, '" for observation "', a, &
3326 '" is invalid in package "', a, '"')
332730 format('Boundary name not provided for observation "', a, &
3328 '" in package "', a, '"')
3329 !
3330 ! -- process each package observation
3331 ! only done the first stress period since boundaries are fixed
3332 ! for the simulation
3333 if (kper == 1) then
3334 do i = 1, this%obs%npakobs
3335 obsrv => this%obs%pakobs(i)%obsrv
3336 !
3337 ! -- get node number 1
3338 nn1 = obsrv%NodeNumber
3339 if (nn1 == namedboundflag) then
3340 bname = obsrv%FeatureName
3341 if (bname /= '') then
3342 ! -- Observation location(s) is(are) based on a boundary name.
3343 ! Iterate through all boundaries to identify and store
3344 ! corresponding index(indices) in bound array.
3345 jfound = .false.
3346 if (this%inamedbound /= 0) then
3347 do j = 1, this%maxbound
3348 if (this%boundname(j) == bname) then
3349 jfound = .true.
3350 call obsrv%AddObsIndex(j)
3351 end if
3352 end do
3353 end if
3354 if (.not. jfound) then
3355 write (errmsg, 10) &
3356 trim(bname), trim(obsrv%name), trim(this%packName)
3357 call store_error(errmsg)
3358 end if
3359 else
3360 write (errmsg, 30) trim(obsrv%name), trim(this%packName)
3361 call store_error(errmsg)
3362 end if
3363 else if (nn1 < 1 .or. nn1 > this%maxbound) then
3364 write (errmsg, '(a,1x,a,1x,i0,1x,a,1x,i0,a)') &
3365 trim(adjustl(obsrv%ObsTypeId)), &
3366 'reach must be greater than 0 and less than or equal to', &
3367 this%maxbound, '(specified value is ', nn1, ')'
3368 call store_error(errmsg)
3369 else
3370 if (obsrv%indxbnds_count == 0) then
3371 call obsrv%AddObsIndex(nn1)
3372 else
3373 errmsg = 'Programming error in sfr_rp_obs'
3374 call store_error(errmsg)
3375 end if
3376 end if
3377 !
3378 ! -- catch non-cumulative observation assigned to observation defined
3379 ! by a boundname that is assigned to more than one element
3380 if (obsrv%ObsTypeId == 'STAGE' .or. &
3381 obsrv%ObsTypeId == 'DEPTH' .or. &
3382 obsrv%ObsTypeId == 'WET-PERIMETER' .or. &
3383 obsrv%ObsTypeId == 'WET-AREA' .or. &
3384 obsrv%ObsTypeId == 'WET-WIDTH') then
3385 nn1 = obsrv%NodeNumber
3386 if (nn1 == namedboundflag) then
3387 if (obsrv%indxbnds_count > 1) then
3388 write (errmsg, '(a,3(1x,a))') &
3389 trim(adjustl(obsrv%ObsTypeId)), &
3390 'for observation', trim(adjustl(obsrv%Name)), &
3391 ' must be assigned to a reach with a unique boundname.'
3392 call store_error(errmsg)
3393 end if
3394 end if
3395 end if
3396 !
3397 ! -- check that node number 1 is valid; call store_error if not
3398 do j = 1, obsrv%indxbnds_count
3399 nn1 = obsrv%indxbnds(j)
3400 if (nn1 < 1 .or. nn1 > this%maxbound) then
3401 write (errmsg, '(a,1x,a,1x,i0,1x,a,1x,i0,a)') &
3402 trim(adjustl(obsrv%ObsTypeId)), &
3403 'reach must be greater than 0 and less than or equal to', &
3404 this%maxbound, '(specified value is ', nn1, ')'
3405 call store_error(errmsg)
3406 end if
3407 end do
3408 end do
3409 !
3410 ! -- evaluate if there are any observation errors
3411 if (count_errors() > 0) then
3412 call store_error_filename(this%input_fname)
3413 end if
3414 end if
Here is the call graph for this function:

◆ sfr_set_period_value()

subroutine sfrmodule::sfr_set_period_value ( class(sfrtype), intent(inout) this,
integer(i4b), intent(in) i,
integer(i4b), intent(in) n,
character(len=*), intent(in) setting )
private

Shared by sfr_rp and sfr_ad; DIVERSION is handled separately by both callers because its target index requires its own validation.

Parameters
[in]irow index into input context arrays
[in]nreach number
[in]settinguppercase mf6varname dispatch key

Definition at line 4995 of file gwf-sfr.f90.

4996 ! -- dummy
4997 class(SfrType), intent(inout) :: this
4998 integer(I4B), intent(in) :: i !< row index into input context arrays
4999 integer(I4B), intent(in) :: n !< reach number
5000 character(len=*), intent(in) :: setting !< uppercase mf6varname dispatch key
5001 !
5002 select case (trim(setting))
5003 case ('BEDK')
5004 this%bedk_set(n) = .true.
5005 case ('MANNING')
5006 this%manning_set(n) = .true.
5007 case ('UPSTREAM_FRAC')
5008 this%ustrf_set(n) = .true.
5009 end select

◆ sfr_setup_budobj()

subroutine sfrmodule::sfr_setup_budobj ( class(sfrtype) this)
private

Method to set up the budget object that stores all the sfr flows The terms listed here must correspond in number and order to the ones listed in the sfr_fill_budobj method.

Parameters
thisSfrType object

Definition at line 5018 of file gwf-sfr.f90.

5019 ! -- dummy
5020 class(SfrType) :: this !< SfrType object
5021 ! -- local
5022 integer(I4B) :: nbudterm
5023 integer(I4B) :: i
5024 integer(I4B) :: n
5025 integer(I4B) :: n1
5026 integer(I4B) :: n2
5027 integer(I4B) :: maxlist
5028 integer(I4B) :: naux
5029 integer(I4B) :: idx
5030 real(DP) :: q
5031 character(len=LENBUDTXT) :: text
5032 character(len=LENBUDTXT), dimension(1) :: auxtxt
5033 !
5034 ! -- Determine the number of sfr budget terms. These are fixed for
5035 ! the simulation and cannot change. This includes FLOW-JA-FACE
5036 ! so they can be written to the binary budget files, but these internal
5037 ! flows are not included as part of the budget table.
5038 nbudterm = 8
5039 if (this%imover == 1) nbudterm = nbudterm + 2
5040 if (this%naux > 0) nbudterm = nbudterm + 1
5041 !
5042 ! -- set up budobj
5043 call budgetobject_cr(this%budobj, this%packName)
5044 call this%budobj%budgetobject_df(this%maxbound, nbudterm, 0, 0, &
5045 ibudcsv=this%ibudcsv)
5046 idx = 0
5047 !
5048 ! -- Go through and set up each budget term
5049 text = ' FLOW-JA-FACE'
5050 idx = idx + 1
5051 maxlist = this%nconn
5052 naux = 1
5053 auxtxt(1) = ' FLOW-AREA'
5054 call this%budobj%budterm(idx)%initialize(text, &
5055 this%name_model, &
5056 this%packName, &
5057 this%name_model, &
5058 this%packName, &
5059 maxlist, .false., .false., &
5060 naux, auxtxt)
5061 !
5062 ! -- store connectivity
5063 call this%budobj%budterm(idx)%reset(this%nconn)
5064 q = dzero
5065 do n = 1, this%maxbound
5066 n1 = n
5067 do i = this%ia(n) + 1, this%ia(n + 1) - 1
5068 n2 = this%ja(i)
5069 call this%budobj%budterm(idx)%update_term(n1, n2, q)
5070 end do
5071 end do
5072 !
5073 ! --
5074 text = ' GWF'
5075 idx = idx + 1
5076 maxlist = this%maxbound - this%ianynone
5077 naux = 1
5078 auxtxt(1) = ' FLOW-AREA'
5079 call this%budobj%budterm(idx)%initialize(text, &
5080 this%name_model, &
5081 this%packName, &
5082 this%name_model, &
5083 this%name_model, &
5084 maxlist, .false., .true., &
5085 naux, auxtxt)
5086 call this%budobj%budterm(idx)%reset(maxlist)
5087 q = dzero
5088 do n = 1, this%maxbound
5089 n2 = this%igwfnode(n)
5090 if (n2 > 0) then
5091 call this%budobj%budterm(idx)%update_term(n, n2, q)
5092 end if
5093 end do
5094 !
5095 ! --
5096 text = ' RAINFALL'
5097 idx = idx + 1
5098 maxlist = this%maxbound
5099 naux = 0
5100 call this%budobj%budterm(idx)%initialize(text, &
5101 this%name_model, &
5102 this%packName, &
5103 this%name_model, &
5104 this%packName, &
5105 maxlist, .false., .false., &
5106 naux)
5107 !
5108 ! --
5109 text = ' EVAPORATION'
5110 idx = idx + 1
5111 maxlist = this%maxbound
5112 naux = 0
5113 call this%budobj%budterm(idx)%initialize(text, &
5114 this%name_model, &
5115 this%packName, &
5116 this%name_model, &
5117 this%packName, &
5118 maxlist, .false., .false., &
5119 naux)
5120 !
5121 ! --
5122 text = ' RUNOFF'
5123 idx = idx + 1
5124 maxlist = this%maxbound
5125 naux = 0
5126 call this%budobj%budterm(idx)%initialize(text, &
5127 this%name_model, &
5128 this%packName, &
5129 this%name_model, &
5130 this%packName, &
5131 maxlist, .false., .false., &
5132 naux)
5133 !
5134 ! --
5135 text = ' EXT-INFLOW'
5136 idx = idx + 1
5137 maxlist = this%maxbound
5138 naux = 0
5139 call this%budobj%budterm(idx)%initialize(text, &
5140 this%name_model, &
5141 this%packName, &
5142 this%name_model, &
5143 this%packName, &
5144 maxlist, .false., .false., &
5145 naux)
5146 !
5147 ! --
5148 text = ' EXT-OUTFLOW'
5149 idx = idx + 1
5150 maxlist = this%maxbound
5151 naux = 0
5152 call this%budobj%budterm(idx)%initialize(text, &
5153 this%name_model, &
5154 this%packName, &
5155 this%name_model, &
5156 this%packName, &
5157 maxlist, .false., .false., &
5158 naux)
5159 !
5160 ! --
5161 text = ' STORAGE'
5162 idx = idx + 1
5163 maxlist = this%maxbound
5164 naux = 1
5165 auxtxt(1) = ' VOLUME'
5166 call this%budobj%budterm(idx)%initialize(text, &
5167 this%name_model, &
5168 this%packName, &
5169 this%name_model, &
5170 this%packName, &
5171 maxlist, .false., .false., &
5172 naux, auxtxt)
5173 !
5174 ! --
5175 if (this%imover == 1) then
5176 !
5177 ! --
5178 text = ' FROM-MVR'
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 = ' TO-MVR'
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 end if
5203 !
5204 ! --
5205 naux = this%naux
5206 if (naux > 0) then
5207 !
5208 ! --
5209 text = ' AUXILIARY'
5210 idx = idx + 1
5211 maxlist = this%maxbound
5212 call this%budobj%budterm(idx)%initialize(text, &
5213 this%name_model, &
5214 this%packName, &
5215 this%name_model, &
5216 this%packName, &
5217 maxlist, .false., .false., &
5218 naux, this%auxname)
5219 end if
5220 !
5221 ! -- if sfr flow for each reach are written to the listing file
5222 if (this%iprflow /= 0) then
5223 call this%budobj%flowtable_df(this%iout, cellids='GWF')
5224 end if
Here is the call graph for this function:

◆ sfr_setup_tableobj()

subroutine sfrmodule::sfr_setup_tableobj ( class(sfrtype) this)
private

Method to set up the table object that is used to write the sfr stage data. The terms listed here must correspond in number and order to the ones written to the stage table in the sfr_ot method.

Parameters
thisSfrType object

Definition at line 5465 of file gwf-sfr.f90.

5466 ! -- dummy
5467 class(SfrType) :: this !< SfrType object
5468 ! -- local
5469 integer(I4B) :: nterms
5470 character(len=LINELENGTH) :: title
5471 character(len=LINELENGTH) :: text
5472 !
5473 ! -- setup stage table
5474 if (this%iprhed > 0) then
5475 !
5476 ! -- Determine the number of sfr budget terms. These are fixed for
5477 ! the simulation and cannot change. This includes FLOW-JA-FACE
5478 ! so they can be written to the binary budget files, but these internal
5479 ! flows are not included as part of the budget table.
5480 nterms = 8
5481 if (this%inamedbound == 1) then
5482 nterms = nterms + 1
5483 end if
5484 !
5485 ! -- set up table title
5486 title = trim(adjustl(this%text))//' PACKAGE ('// &
5487 trim(adjustl(this%packName))//') STAGES FOR EACH CONTROL VOLUME'
5488 !
5489 ! -- set up stage tableobj
5490 call table_cr(this%stagetab, this%packName, title)
5491 call this%stagetab%table_df(this%maxbound, nterms, this%iout, &
5492 transient=.true.)
5493 !
5494 ! -- Go through and set up table budget term
5495 if (this%inamedbound == 1) then
5496 text = 'NAME'
5497 call this%stagetab%initialize_column(text, lenboundname, &
5498 alignment=tableft)
5499 end if
5500 !
5501 ! -- reach number
5502 text = 'NUMBER'
5503 call this%stagetab%initialize_column(text, 10, alignment=tabcenter)
5504 !
5505 ! -- cellids
5506 text = 'CELLID'
5507 call this%stagetab%initialize_column(text, 20, alignment=tableft)
5508 !
5509 ! -- reach stage
5510 text = 'STAGE'
5511 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5512 !
5513 ! -- reach depth
5514 text = 'DEPTH'
5515 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5516 !
5517 ! -- reach width
5518 text = 'WIDTH'
5519 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5520 !
5521 ! -- gwf head
5522 text = 'GWF HEAD'
5523 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5524 !
5525 ! -- streambed conductance
5526 text = 'STREAMBED CONDUCTANCE'
5527 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5528 !
5529 ! -- streambed gradient
5530 text = 'STREAMBED GRADIENT'
5531 call this%stagetab%initialize_column(text, 12, alignment=tabcenter)
5532 end if
5533 !
5534 ! -- setup Courant number table
5535 if (this%istorage == 1) then
5536 nterms = 4
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))//') COURANT NUMBER FOR EACH REACH'
5544 !
5545 ! -- set up Courant tableobj
5546 call table_cr(this%couranttab, this%packName, title)
5547 call this%couranttab%table_df(this%maxbound, nterms, this%iout)
5548 !
5549 if (this%inamedbound == 1) then
5550 text = 'NAME'
5551 call this%couranttab%initialize_column(text, lenboundname, &
5552 alignment=tableft)
5553 end if
5554 !
5555 ! -- reach number
5556 text = 'NUMBER'
5557 call this%couranttab%initialize_column(text, 10, alignment=tabcenter)
5558 !
5559 ! -- minimum Courant number
5560 text = 'MINIMUM'
5561 call this%couranttab%initialize_column(text, 16, alignment=tabcenter)
5562 !
5563 ! -- maximum Courant number
5564 text = 'MAXIMUM'
5565 call this%couranttab%initialize_column(text, 16, alignment=tabcenter)
5566 !
5567 ! -- mean Courant number
5568 text = 'MEAN'
5569 call this%couranttab%initialize_column(text, 16, alignment=tabcenter)
5570 end if
Here is the call graph for this function:

◆ sfr_solve()

subroutine sfrmodule::sfr_solve ( class(sfrtype) this,
integer(i4b), intent(in) n,
real(dp), intent(in) h,
real(dp), intent(inout) hcof,
real(dp), intent(inout) rhs,
logical(lgp), intent(in), optional update )
private

Method to solve the continuity equation for a SFR package reach.

Parameters
thisSfrType object
[in]nreach number
[in]hgroundwater head in cell connected to reach
[in,out]hcofcoefficient term added to the diagonal
[in,out]rhsright-hand side term
[in]updateboolean indicating if the reach depth and stage variables should be updated to current iterate

Definition at line 3460 of file gwf-sfr.f90.

3461 ! -- dummy
3462 class(SfrType) :: this !< SfrType object
3463 integer(I4B), intent(in) :: n !< reach number
3464 real(DP), intent(in) :: h !< groundwater head in cell connected to reach
3465 real(DP), intent(inout) :: hcof !< coefficient term added to the diagonal
3466 real(DP), intent(inout) :: rhs !< right-hand side term
3467 logical(LGP), intent(in), optional :: update !< boolean indicating if the reach depth and stage variables should be updated to current iterate
3468 ! -- local
3469 logical(LGP) :: lupdate
3470 integer(I4B) :: i
3471 integer(I4B) :: ii
3472 integer(I4B) :: n2
3473 real(DP) :: hgwf
3474 real(DP) :: sa
3475 real(DP) :: sa_wet
3476 real(DP) :: qu
3477 real(DP) :: qi
3478 real(DP) :: qr
3479 real(DP) :: qe
3480 real(DP) :: qro
3481 real(DP) :: qsrc
3482 real(DP) :: qfrommvr
3483 real(DP) :: qgwf
3484 real(DP) :: tp
3485 real(DP) :: bt
3486 real(DP) :: hsfr
3487 real(DP) :: qd
3488 real(DP) :: d1
3489 real(DP) :: sumleak
3490 real(DP) :: sumrch
3491 real(DP) :: gwfhcof
3492 real(DP) :: gwfrhs
3493 !
3494 ! -- Process optional dummy variables
3495 if (present(update)) then
3496 lupdate = update
3497 else
3498 lupdate = .true.
3499 end if
3500
3501 ! -- initialize variables
3502 hcof = dzero
3503 rhs = dzero
3504 !
3505 if (this%iboundpak(n) == 0) then
3506 this%depth(n) = dzero
3507 this%stage(n) = dhnoflo
3508 this%usflow(n) = dzero
3509 this%simevap(n) = dzero
3510 this%simrunoff(n) = dzero
3511 this%dsflow(n) = dzero
3512 this%gwflow(n) = dzero
3513 else
3514 hgwf = h
3515 d1 = dzero
3516 qsrc = dzero
3517 qgwf = dzero
3518 qd = this%dsflow(n)
3519
3520 ! -- calculate initial depth assuming a wide cross-section and
3521 ! ignore groundwater leakage
3522 ! -- calculate upstream flow
3523 qu = dzero
3524 do i = this%ia(n) + 1, this%ia(n + 1) - 1
3525 if (this%idir(i) < 0) cycle
3526 n2 = this%ja(i)
3527 do ii = this%ia(n2) + 1, this%ia(n2 + 1) - 1
3528 if (this%idir(ii) > 0) cycle
3529 if (this%ja(ii) /= n) cycle
3530 qu = qu + this%qconn(ii)
3531 end do
3532 end do
3533 this%usflow(n) = qu
3534
3535 ! -- calculate remaining terms
3536 sa = this%calc_surface_area(n)
3537 sa_wet = this%calc_surface_area_wet(n, this%depth(n))
3538 qi = this%inflow(n)
3539 qr = this%rain(n) * sa
3540 qe = this%evap(n) * sa_wet
3541 qro = this%runoff(n)
3542
3543 ! -- Water mover term; assume that it goes in at the upstream end of the reach
3544 qfrommvr = dzero
3545 if (this%imover == 1) then
3546 qfrommvr = this%pakmvrobj%get_qfrommvr(n)
3547 end if
3548
3549 ! -- calculate downstream flow ignoring groundwater leakage
3550 qsrc = qu + qi + qr - qe + qro + qfrommvr
3551
3552 ! -- adjust runoff or evaporation if sum of sources is negative
3553 call this%sfr_adjust_ro_ev(qsrc, qu, qi, qr, qro, qe, qfrommvr)
3554
3555 ! -- set simulated evaporation and runoff
3556 this%simevap(n) = qe
3557 this%simrunoff(n) = qro
3558
3559 ! -- calculate reach flow using appropriate method
3560 if (this%iboundpak(n) < 0) then
3561 call this%sfr_calc_constant(n, d1, hgwf, qgwf, qd)
3562 else
3563 if (this%gwfiss == 0 .and. this%istorage == 1) then
3564 if (this%ats_courant /= dnodata) then
3565 call this%sfr_calc_tvd(n, d1, hgwf, qu, qi, &
3566 qfrommvr, qr, qe, qro, &
3567 qgwf, qd)
3568 else
3569 call this%sfr_calc_transient(n, d1, hgwf, qu, qi, &
3570 qfrommvr, qr, qe, qro, &
3571 qgwf, qd)
3572 end if
3573 else
3574 call this%sfr_calc_steady(n, d1, hgwf, qu, qi, &
3575 qfrommvr, qr, qe, qro, &
3576 qgwf, qd)
3577 end if
3578 end if
3579
3580 ! -- update sfr stage
3581 tp = this%strtop(n)
3582 bt = tp - this%bthick(n)
3583 hsfr = tp + d1
3584
3585 ! -- update stored values
3586 if (lupdate) then
3587 ! -- save depth and calculate stage
3588 this%depth(n) = d1
3589 this%stage(n) = hsfr
3590 ! -- update flows
3591 call this%sfr_update_flows(n, qd, qgwf)
3592 end if
3593
3594 ! -- calculate sumleak and sumrch
3595 sumleak = dzero
3596 sumrch = dzero
3597 if (this%gwfiss == 0) then
3598 sumleak = qgwf
3599 else
3600 sumleak = qgwf
3601 end if
3602 if (hgwf < bt) then
3603 sumrch = qgwf
3604 end if
3605
3606 ! -- make final qgwf calculation and obtain
3607 ! gwfhcof and gwfrhs values
3608 call this%sfr_calc_qgwf(n, d1, hgwf, qgwf, gwfhcof, gwfrhs)
3609
3610 ! -- update hcof and rhs terms
3611 if (abs(sumleak) > dzero) then
3612 ! -- stream leakage is not head dependent
3613 if (hgwf < bt) then
3614 rhs = rhs - sumrch
3615 ! -- stream leakage is head dependent
3616 else if ((sumleak - qsrc) < -dem30) then
3617 if (this%gwfiss == 0) then
3618 rhs = rhs + gwfrhs - sumrch
3619 else
3620 rhs = rhs + gwfrhs
3621 end if
3622 hcof = gwfhcof
3623 ! -- place holder for UZF
3624 else
3625 if (this%gwfiss == 0) then
3626 rhs = rhs - sumleak - sumrch
3627 else
3628 rhs = rhs - sumleak
3629 end if
3630 end if
3631
3632 ! -- add groundwater leakage
3633 else if (hgwf < bt) then
3634 rhs = rhs - sumrch
3635 end if
3636 end if

◆ sfr_source_connectiondata()

subroutine sfrmodule::sfr_source_connectiondata ( class(sfrtype), intent(inout) this)
private
Parameters
[in,out]thisSfrType object

Definition at line 1296 of file gwf-sfr.f90.

1297 ! -- modules
1299 use sparsemodule, only: sparsematrix
1300 ! -- dummy
1301 class(SfrType), intent(inout) :: this !< SfrType object
1302 ! -- local
1303 integer(I4B), dimension(:), pointer, contiguous :: cd_ifno => null()
1304 integer(I4B), dimension(:), pointer, contiguous :: ic_flat => null()
1305 integer(I4B), dimension(:), pointer, contiguous :: cd_ia => null()
1306 type(sparsematrix), pointer :: sparse => null()
1307 integer(I4B), dimension(:), pointer, contiguous :: rowmaxnnz => null()
1308 integer(I4B), allocatable :: nboundchk(:)
1309 integer(I4B), allocatable :: iconndata(:, :)
1310 integer(I4B), allocatable :: iup(:)
1311 integer(I4B), allocatable :: order(:)
1312 type(dag) :: sfr_dag
1313 integer(I4B) :: i, n, j, jj, jcol, jcol2, nja, nconnmax
1314 integer(I4B) :: ival, idir, nup, ipos, istat, ierr, jlocal, nread
1315 !
1316 write (this%iout, '(/1x,a)') &
1317 'PROCESSING '//trim(adjustl(this%text))//' CONNECTIONDATA'
1318 !
1319 ! -- get input context CONNECTIONDATA arrays
1320 call mem_setptr(cd_ifno, 'CONNDATA_IFNO', this%input_mempath)
1321 call mem_setptr(ic_flat, 'IC', this%input_mempath)
1322 call mem_setptr(cd_ia, 'IC_IA', this%input_mempath)
1323 !
1324 ! -- allocate and initialize check array
1325 allocate (nboundchk(this%maxbound))
1326 nboundchk = 0
1327 !
1328 ! -- build rowmaxnnz from nconnreach
1329 nja = 0
1330 nconnmax = 0
1331 allocate (rowmaxnnz(this%maxbound))
1332 do n = 1, this%maxbound
1333 ival = this%nconnreach(n)
1334 if (ival < 0) ival = 0
1335 rowmaxnnz(n) = ival + 1
1336 nja = nja + ival + 1
1337 if (ival > nconnmax) nconnmax = ival
1338 end do
1339 !
1340 ! -- reallocate connection arrays
1341 call mem_reallocate(this%ja, nja, 'JA', this%memoryPath)
1342 call mem_reallocate(this%idir, nja, 'IDIR', this%memoryPath)
1343 call mem_reallocate(this%idiv, nja, 'IDIV', this%memoryPath)
1344 call mem_reallocate(this%qconn, nja, 'QCONN', this%memoryPath)
1345 this%idir = 0
1346 this%idiv = 0
1347 this%qconn = dzero
1348 !
1349 ! -- allocate iconndata
1350 allocate (iconndata(nconnmax, this%maxbound))
1351 iconndata = 0
1352 !
1353 allocate (sparse)
1354 call sparse%init(this%maxbound, this%maxbound, rowmaxnnz)
1355 !
1356 ! -- process connection data rows
1357 do i = 1, this%maxbound
1358 n = this%validate_ifno(cd_ifno(i), this%maxbound, nboundchk, &
1359 'reach', 'CONNECTIONDATA')
1360 if (n == 0) cycle
1361 nread = cd_ia(i + 1) - cd_ia(i)
1362 if (nread /= this%nconnreach(n)) then
1363 write (errmsg, '(a,1x,i0,1x,a,1x,i0,1x,a,1x,i0,a)') &
1364 'Reach', n, 'connectiondata specifies', nread, &
1365 'connections but NCON for this reach in packagedata is', &
1366 this%nconnreach(n), '.'
1367 call store_error(errmsg)
1368 cycle
1369 end if
1370 call sparse%addconnection(n, n, 1)
1371 jlocal = 0
1372 do j = cd_ia(i), cd_ia(i + 1) - 1
1373 jlocal = jlocal + 1
1374 ival = ic_flat(j)
1375 iconndata(jlocal, n) = ival
1376 if (ival < 0) then
1377 idir = -1
1378 ival = abs(ival)
1379 else if (ival == 0) then
1380 call store_error('Missing or zero connection reach in connectiondata.')
1381 cycle
1382 else
1383 idir = 1
1384 end if
1385 if (ival > this%maxbound) then
1386 call store_error('Reach number exceeds NREACHES in connectiondata.')
1387 cycle
1388 end if
1389 call sparse%addconnection(n, ival, 1)
1390 end do
1391 end do
1392 !
1393 write (this%iout, '(1x,a)') &
1394 'END OF '//trim(adjustl(this%text))//' CONNECTIONDATA'
1395 !
1396 call this%report_ifno_coverage(nboundchk, this%maxbound, 'reach', &
1397 'CONNECTIONDATA')
1398 !
1399 if (count_errors() > 0) then
1400 call store_error_filename(this%input_fname)
1401 end if
1402 !
1403 ! -- fill ia and ja from sparse
1404 call sparse%filliaja(this%ia, this%ja, ierr, sort=.true.)
1405 if (ierr /= 0) then
1406 write (errmsg, '(a,3(1x,a))') &
1407 'Could not fill', trim(this%packName), &
1408 'package IA and JA connection data.', &
1409 'Check connectivity data in connectiondata block.'
1410 call store_error(errmsg)
1411 end if
1412 !
1413 ! -- fill flat connection storage with direction
1414 do n = 1, this%maxbound
1415 do j = this%ia(n) + 1, this%ia(n + 1) - 1
1416 jcol = this%ja(j)
1417 do jj = 1, this%nconnreach(n)
1418 jcol2 = iconndata(jj, n)
1419 if (abs(jcol2) == jcol) then
1420 idir = 1
1421 if (jcol2 < 0) idir = -1
1422 this%idir(j) = idir
1423 exit
1424 end if
1425 end do
1426 end do
1427 end do
1428 !
1429 ! -- deallocate temporaries
1430 deallocate (rowmaxnnz)
1431 deallocate (nboundchk)
1432 deallocate (iconndata)
1433 call sparse%destroy()
1434 deallocate (sparse)
1435 !
1436 ! -- compute reach order using DAG
1437 call sfr_dag%set_vertices(this%maxbound)
1438 fill_dag: do n = 1, this%maxbound
1439 nup = 0
1440 do j = this%ia(n) + 1, this%ia(n + 1) - 1
1441 if (this%idir(j) > 0) nup = nup + 1
1442 end do
1443 if (nup == 0) cycle fill_dag
1444 allocate (iup(nup))
1445 ipos = 1
1446 do j = this%ia(n) + 1, this%ia(n + 1) - 1
1447 if (this%idir(j) > 0) then
1448 iup(ipos) = this%ja(j)
1449 ipos = ipos + 1
1450 end if
1451 end do
1452 call sfr_dag%set_edges(n, iup)
1453 deallocate (iup)
1454 end do fill_dag
1455 call sfr_dag%toposort(order, istat)
1456 if (istat == -1) then
1457 write (warnmsg, '(a)') &
1458 trim(adjustl(this%text))//' PACKAGE ('// &
1459 trim(adjustl(this%packName))//') cannot calculate a '// &
1460 'Directed Asyclic Graph for reach connectivity because '// &
1461 'of circular dependency. Using the reach number for '// &
1462 'solution ordering.'
1463 call store_warning(warnmsg)
1464 end if
1465 do n = 1, this%maxbound
1466 if (istat == 0) then
1467 this%isfrorder(n) = order(n)
1468 else
1469 this%isfrorder(n) = n
1470 end if
1471 end do
1472 call sfr_dag%destroy()
1473 if (istat == 0) deallocate (order)
1474 !
1475 ! -- release input context connectiondata memory
1476 call memorystore_release('CONNDATA_IFNO', this%input_mempath)
1477 call memorystore_release('IC', this%input_mempath)
1478 call memorystore_release('IC_IA', this%input_mempath)
subroutine sort(this, with_csr)
Definition Sparse.f90:218
Here is the call graph for this function:

◆ sfr_source_crosssections()

subroutine sfrmodule::sfr_source_crosssections ( class(sfrtype), intent(inout) this)
private
Parameters
[in,out]thisSfrType object

Definition at line 1206 of file gwf-sfr.f90.

1207 ! -- modules
1208 use constantsmodule, only: lenmempath
1212 ! -- dummy
1213 class(SfrType), intent(inout) :: this !< SfrType object
1214 ! -- local
1215 integer(I4B), dimension(:), pointer, contiguous :: ifno => null()
1216 type(CharacterStringType), dimension(:), pointer, contiguous :: &
1217 tab6_filename => null()
1218 type(CharacterStringType), dimension(:), pointer, contiguous :: &
1219 sfrtab6_mempaths => null()
1220 type(SfrCrossSection), pointer :: cross_data => null()
1221 integer(I4B) :: i, n, ncrossptstot
1222 integer(I4B), allocatable :: nboundchk(:)
1223 integer(I4B) :: isize
1224 character(len=LINELENGTH) :: tabfname
1225 character(len=LENMEMPATH) :: mempath
1226 !
1227 ! -- check if CROSSSECTIONS block was loaded (optional block)
1228 call get_isize('CROSSSECT_IFNO', this%input_mempath, isize)
1229 if (isize < 1) return
1230 !
1231 write (this%iout, '(/1x,a)') &
1232 'PROCESSING '//trim(adjustl(this%text))//' CROSSSECTIONS'
1233 !
1234 ! -- get input context arrays
1235 call mem_setptr(ifno, 'CROSSSECT_IFNO', this%input_mempath)
1236 call mem_setptr(tab6_filename, 'SFRTAB6_FILENAME', this%input_mempath)
1237 call mem_setptr(sfrtab6_mempaths, 'SFRTAB6_MEMPATH', this%input_mempath)
1238 !
1239 ! -- create cross-section object
1240 call cross_section_cr(cross_data, this%iout, this%iprpak, this%maxbound)
1241 call cross_data%initialize(this%ncrossptstot, this%ncrosspts, &
1242 this%iacross, this%station, this%xsheight, &
1243 this%xsrough)
1244 !
1245 allocate (nboundchk(this%maxbound))
1246 nboundchk = 0
1247 !
1248 do i = 1, isize
1249 n = this%validate_ifno(ifno(i), this%maxbound, nboundchk, &
1250 'reach', 'CROSSSECTIONS')
1251 if (n == 0) cycle
1252 tabfname = tab6_filename(i)
1253 mempath = sfrtab6_mempaths(i)
1254 call cross_data%source_table(n, this%width(n), mempath, &
1255 trim(adjustl(tabfname)))
1256 end do
1257 !
1258 write (this%iout, '(1x,a)') &
1259 'END OF '//trim(adjustl(this%text))//' CROSSSECTIONS'
1260 !
1261 ! -- CROSSSECTIONS is optional; only duplicates are reported
1262 call this%report_ifno_coverage(nboundchk, this%maxbound, 'reach', &
1263 'CROSSSECTIONS', check_missing=.false.)
1264 deallocate (nboundchk)
1265 !
1266 if (count_errors() > 0) then
1267 call store_error_filename(this%input_fname)
1268 end if
1269 !
1270 ! -- reallocate cross-section arrays if needed
1271 ncrossptstot = cross_data%get_ncrossptstot()
1272 if (ncrossptstot /= this%ncrossptstot) then
1273 this%ncrossptstot = ncrossptstot
1274 call mem_reallocate(this%station, this%ncrossptstot, 'STATION', &
1275 this%memoryPath)
1276 call mem_reallocate(this%xsheight, this%ncrossptstot, 'XSHEIGHT', &
1277 this%memoryPath)
1278 call mem_reallocate(this%xsrough, this%ncrossptstot, 'XSROUGH', &
1279 this%memoryPath)
1280 end if
1281 !
1282 call cross_data%output(this%width, this%rough)
1283 call cross_data%pack(this%ncrossptstot, this%ncrosspts, this%iacross, &
1284 this%station, this%xsheight, this%xsrough)
1285 call cross_data%destroy()
1286 deallocate (cross_data)
1287 nullify (cross_data)
1288 !
1289 ! -- release input context crosssections memory
1290 call memorystore_release('CROSSSECT_IFNO', this%input_mempath)
1291 call memorystore_release('SFRTAB6_FILENAME', this%input_mempath)
integer(i4b), parameter lenmempath
maximum length of the memory path
Definition Constants.f90:27
This class is used to store a single deferred-length character string. It was designed to work in an ...
Here is the call graph for this function:

◆ sfr_source_dimensions()

subroutine sfrmodule::sfr_source_dimensions ( class(sfrtype), intent(inout) this)
private
Parameters
[in,out]thisSfrType object

Definition at line 960 of file gwf-sfr.f90.

961 ! -- modules
963 ! -- dummy
964 class(SfrType), intent(inout) :: this !< SfrType object
965 ! -- local
966 logical(LGP) :: found
967 !
968 ! -- initialize dimensions to 0
969 this%maxbound = 0
970 !
971 write (this%iout, '(/1x,a)') &
972 'PROCESSING '//trim(adjustl(this%text))//' DIMENSIONS'
973 !
974 ! -- source NREACHES
975 call mem_set_value(this%maxbound, 'MAXBOUND', this%input_mempath, found, &
976 release=.false.)
977 if (found) then
978 write (this%iout, '(4x,a,i0)') 'NREACHES = ', this%maxbound
979 end if
980 !
981 write (this%iout, '(1x,a)') &
982 'END OF '//trim(adjustl(this%text))//' DIMENSIONS'
983 !
984 if (this%maxbound < 1) then
985 write (errmsg, '(a)') &
986 'NREACHES was not specified or was specified incorrectly.'
987 call store_error(errmsg)
988 call store_error_filename(this%input_fname)
989 end if
990 !
991 ! -- set npakeq (SFR adds no extra equations)
992 this%npakeq = 0
993 !
994 ! -- define the default label
995 call this%define_listlabel()
996 !
997 ! -- define default cross-section data size
998 this%ncrossptstot = this%maxbound
999 !
1000 ! -- allocate arrays
1001 call this%sfr_allocate_arrays()
1002 !
1003 ! -- source packagedata
1004 call this%sfr_source_packagedata()
1005 !
1006 ! -- source crosssections
1007 call this%sfr_source_crosssections()
1008 !
1009 ! -- source connectiondata
1010 call this%sfr_source_connectiondata()
1011 !
1012 ! -- source diversions
1013 call this%sfr_source_diversions()
1014 !
1015 ! -- alias deprecated variable names
1016 call this%sfr_checkin_deprecated_names()
1017 !
1018 ! -- source initialstages
1019 call this%sfr_source_initialstages()
1020 !
1021 ! -- setup the budget object
1022 call this%sfr_setup_budobj()
1023 !
1024 ! -- setup the stage table object
1025 call this%sfr_setup_tableobj()
Here is the call graph for this function:

◆ sfr_source_diversions()

subroutine sfrmodule::sfr_source_diversions ( class(sfrtype), intent(inout) this)
private
Parameters
[in,out]thisSfrType object

Definition at line 1483 of file gwf-sfr.f90.

1484 ! -- modules
1487 ! -- dummy
1488 class(SfrType), intent(inout) :: this !< SfrType object
1489 ! -- local
1490 integer(I4B), dimension(:), pointer, contiguous :: d_ifno => null()
1491 integer(I4B), dimension(:), pointer, contiguous :: d_idv => null()
1492 integer(I4B), dimension(:), pointer, contiguous :: d_iconr => null()
1493 type(CharacterStringType), dimension(:), pointer, contiguous :: &
1494 d_cprior => null()
1495 integer(I4B) :: i, n, idiv, ndiversions, i0, ipos, jpos
1496 integer(I4B) :: isize
1497 integer(I4B), allocatable :: iachk(:), nboundchk(:)
1498 character(len=16) :: cval
1499 !
1500 ! -- build iadiv and count total diversions
1501 ndiversions = 0
1502 i0 = 1
1503 this%iadiv(1) = i0
1504 do n = 1, this%maxbound
1505 ndiversions = ndiversions + this%ndiv(n)
1506 i0 = i0 + this%ndiv(n)
1507 this%iadiv(n + 1) = i0
1508 end do
1509 !
1510 ! -- reallocate diversion arrays
1511 if (ndiversions > 0) then
1512 call mem_reallocate(this%divreach, ndiversions, 'DIVREACH', &
1513 this%memoryPath)
1514 allocate (this%divcprior(ndiversions))
1515 call mem_setptr(this%divflow, 'DIVFLOW', this%input_mempath)
1516 call mem_reallocate(this%divq, ndiversions, 'DIVQ', this%memoryPath)
1517 this%divq = dzero
1518 end if
1519 !
1520 ! -- check if DIVERSIONS block was loaded (optional block)
1521 call get_isize('DIVERSIONS_IFNO', this%input_mempath, isize)
1522 if (isize < 1) then
1523 if (this%idiversions /= 0) then
1524 call store_error('REQUIRED DIVERSIONS BLOCK NOT FOUND.')
1525 call store_error_filename(this%input_fname)
1526 end if
1527 return
1528 end if
1529 !
1530 if (this%idiversions == 0) then
1531 write (errmsg, '(a,1x,a)') &
1532 'A diversions block should not be', &
1533 'specified if diversions are not specified.'
1534 call store_error(errmsg)
1535 call store_error_filename(this%input_fname)
1536 return
1537 end if
1538 !
1539 write (this%iout, '(/1x,a)') &
1540 'PROCESSING '//trim(adjustl(this%text))//' DIVERSIONS'
1541 !
1542 ! -- get input context arrays
1543 call mem_setptr(d_ifno, 'DIVERSIONS_IFNO', this%input_mempath)
1544 call mem_setptr(d_idv, 'DIVERSIONS_IDV', this%input_mempath)
1545 call mem_setptr(d_iconr, 'ICONR', this%input_mempath)
1546 call mem_setptr(d_cprior, 'CPRIOR', this%input_mempath)
1547 !
1548 ! -- build check arrays
1549 allocate (iachk(this%maxbound + 1))
1550 allocate (nboundchk(ndiversions))
1551 nboundchk = 0
1552 iachk(1) = 1
1553 do n = 1, this%maxbound
1554 iachk(n + 1) = iachk(n) + this%ndiv(n)
1555 end do
1556 !
1557 do i = 1, isize
1558 n = d_ifno(i)
1559 if (n < 1 .or. n > this%maxbound) then
1560 write (errmsg, '(a,i0,a)') 'Reach number should be between 1 and ', &
1561 this%maxbound, '.'
1562 call store_error(errmsg)
1563 cycle
1564 end if
1565 if (this%ndiv(n) < 1) then
1566 write (errmsg, '(a,i0)') &
1567 'Diversions cannot be specified for reach ', n
1568 call store_error(errmsg)
1569 cycle
1570 end if
1571 idiv = d_idv(i)
1572 if (idiv < 1 .or. idiv > this%ndiv(n)) then
1573 write (errmsg, '(a,i0,a,i0,a)') &
1574 'Reach ', n, ' diversion number should be between 1 and ', &
1575 this%ndiv(n), '.'
1576 call store_error(errmsg)
1577 cycle
1578 end if
1579 ipos = iachk(n) + idiv - 1
1580 nboundchk(ipos) = nboundchk(ipos) + 1
1581 jpos = this%iadiv(n) + idiv - 1
1582 if (d_iconr(i) < 1 .or. d_iconr(i) > this%maxbound) then
1583 write (errmsg, '(a,i0,a)') &
1584 'Diversion target reach number should be between 1 and ', &
1585 this%maxbound, '.'
1586 call store_error(errmsg)
1587 cycle
1588 end if
1589 this%divreach(jpos) = d_iconr(i)
1590 cval = d_cprior(i)
1591 select case (trim(cval))
1592 case ('UPTO', 'THRESHOLD', 'FRACTION', 'EXCESS')
1593 case default
1594 errmsg = 'Invalid cprior type '//trim(cval)//'.'
1595 call store_error(errmsg)
1596 end select
1597 this%divcprior(jpos) = trim(cval)
1598 end do
1599 !
1600 write (this%iout, '(1x,a)') &
1601 'END OF '//trim(adjustl(this%text))//' DIVERSIONS'
1602 !
1603 do n = 1, this%maxbound
1604 do idiv = 1, this%ndiv(n)
1605 ipos = iachk(n) + idiv - 1
1606 if (nboundchk(ipos) == 0) then
1607 write (errmsg, '(a,1x,i0,1x,a,1x,i0)') &
1608 'No data specified for reach', n, 'diversion', idiv
1609 call store_error(errmsg)
1610 else if (nboundchk(ipos) > 1) then
1611 write (errmsg, '(a,1x,i0,1x,a,1x,i0,1x,a,1x,i0,1x,a)') &
1612 'Data for reach', n, 'diversion', idiv, &
1613 'specified', nboundchk(ipos), 'times'
1614 call store_error(errmsg)
1615 end if
1616 end do
1617 end do
1618 deallocate (iachk)
1619 deallocate (nboundchk)
1620 !
1621 if (count_errors() > 0) then
1622 call store_error_filename(this%input_fname)
1623 end if
1624 !
1625 ! -- release input context diversions memory; DIVFLOW excluded
1626 call memorystore_release('DIVERSIONS_IFNO', this%input_mempath)
1627 call memorystore_release('DIVERSIONS_IDV', this%input_mempath)
1628 call memorystore_release('ICONR', this%input_mempath)
1629 call memorystore_release('CPRIOR', this%input_mempath)
Here is the call graph for this function:

◆ sfr_source_initialstages()

subroutine sfrmodule::sfr_source_initialstages ( class(sfrtype), intent(inout) this)
private
Parameters
[in,out]thisSfrType object

Definition at line 1634 of file gwf-sfr.f90.

1635 ! -- modules
1637 ! -- dummy
1638 class(SfrType), intent(inout) :: this !< SfrType object
1639 ! -- local
1640 integer(I4B), dimension(:), pointer, contiguous :: is_ifno => null()
1641 real(DP), dimension(:), pointer, contiguous :: is_stage => null()
1642 integer(I4B) :: i, n
1643 integer(I4B) :: isize
1644 integer(I4B), allocatable :: nboundchk(:)
1645 real(DP) :: rval
1646 !
1647 ! -- check if INITIALSTAGES block was loaded (optional block)
1648 call get_isize('INITSTAGE_IFNO', this%input_mempath, isize)
1649 if (isize < 1) then
1650 ! -- set default initial stage to reach top if STORAGE active
1651 if (this%istorage == 1) then
1652 do n = 1, this%maxbound
1653 this%stage(n) = this%strtop(n)
1654 end do
1655 end if
1656 return
1657 end if
1658 !
1659 write (this%iout, '(/1x,a)') &
1660 'PROCESSING '//trim(adjustl(this%text))//' INITIALSTAGES'
1661 !
1662 call mem_setptr(is_ifno, 'INITSTAGE_IFNO', this%input_mempath)
1663 call mem_setptr(is_stage, 'INITIALSTAGE', this%input_mempath)
1664 !
1665 allocate (nboundchk(this%maxbound))
1666 nboundchk = 0
1667 !
1668 do i = 1, isize
1669 n = this%validate_ifno(is_ifno(i), this%maxbound, nboundchk, &
1670 'reach', 'INITIALSTAGES')
1671 if (n == 0) cycle
1672 rval = is_stage(i)
1673 this%stage(n) = rval
1674 this%depth(n) = rval - this%strtop(n)
1675 if (rval < this%strtop(n)) then
1676 write (errmsg, '(a,g0,a,1x,i0,1x,a,g0,a)') &
1677 'Initial stage (', rval, ') for reach', n, &
1678 'is less than the reach top (', this%strtop(n), ').'
1679 call store_error(errmsg)
1680 end if
1681 end do
1682 !
1683 write (this%iout, '(1x,a)') &
1684 'END OF '//trim(adjustl(this%text))//' INITIALSTAGES'
1685 !
1686 call this%report_ifno_coverage(nboundchk, this%maxbound, 'reach', &
1687 'INITIALSTAGES')
1688 deallocate (nboundchk)
1689 !
1690 if (count_errors() > 0) then
1691 call store_error_filename(this%input_fname)
1692 end if
1693 !
1694 ! -- release input context initialstages memory
1695 call memorystore_release('INITSTAGE_IFNO', this%input_mempath)
1696 call memorystore_release('INITIALSTAGE', this%input_mempath)
Here is the call graph for this function:

◆ sfr_source_options()

subroutine sfrmodule::sfr_source_options ( class(sfrtype), intent(inout) this)
private
Parameters
[in,out]thisSfrType object

Definition at line 776 of file gwf-sfr.f90.

777 ! -- modules
781 use openspecmodule, only: access, form
782 ! -- dummy
783 class(SfrType), intent(inout) :: this !< SfrType object
784 ! -- local
785 character(len=LINELENGTH) :: fname
786 logical(LGP) :: found
787 ! -- formats
788 character(len=*), parameter :: fmtpicard = &
789 &"(4x, 'MAXIMUM SFR PICARD ITERATION VALUE (',i0,') SPECIFIED.')"
790 character(len=*), parameter :: fmtiter = &
791 &"(4x, 'MAXIMUM SFR ITERATION VALUE (',i0,') SPECIFIED.')"
792 character(len=*), parameter :: fmtdmaxchg = &
793 &"(4x, 'MAXIMUM DEPTH CHANGE VALUE (',g0,') SPECIFIED.')"
794 character(len=*), parameter :: fmtlengthconv = &
795 &"(4x, 'LENGTH CONVERSION VALUE (',g0,') SPECIFIED.')"
796 character(len=*), parameter :: fmttimeconv = &
797 &"(4x, 'TIME CONVERSION VALUE (',g0,') SPECIFIED.')"
798 character(len=*), parameter :: fmtstoweight = &
799 &"(4x, 'KINEMATIC STORAGE WEIGHT (',g0,') SPECIFIED.')"
800 character(len=*), parameter :: fmtsfrbin = &
801 "(4x, 'SFR ', 1x, a, 1x, ' WILL BE SAVED TO FILE: ', a, /4x, &
802 &'OPENED ON UNIT: ', I0)"
803 integer(I4B) :: isize
804 !
805 ! -- source base BndExtType options (NAUX, BOUNDNAMES, PRINT_INPUT, etc.)
806 call this%BndExtType%source_options()
807 !
808 write (this%iout, '(/1x,a)') &
809 'PROCESSING '//trim(adjustl(this%text))//' OPTIONS'
810 !
811 ! -- STORAGE
812 call mem_set_value(this%istorage, 'STORAGE', this%input_mempath, found)
813 if (found) then
814 write (this%iout, '(4x,a)') trim(adjustl(this%text))// &
815 ' REACH STORAGE IS ACTIVE.'
816 end if
817 !
818 ! -- ATS_COURANT
819 call mem_set_value(this%ats_courant, 'ATS_COURANT', &
820 this%input_mempath, found)
821 if (found) then
822 if (this%ats_courant <= dzero) then
823 write (errmsg, '(a,g0,a)') &
824 "ATS_COURANT SPECIFIED TO BE '", this%ats_courant, &
825 "' BUT MUST BE GREATER THAN ZERO"
826 call store_error(errmsg)
827 call store_error_filename(this%input_fname)
828 else
829 write (this%iout, '(4x,a,1pg15.6)') &
830 'TARGET COURANT NUMBER FOR ADAPTIVE TIME STEPS: ', &
831 this%ats_courant
832 end if
833 end if
834 !
835 ! -- PRINT_STAGE
836 call mem_set_value(this%iprhed, 'PRINT_STAGE', this%input_mempath, found)
837 if (found) then
838 write (this%iout, '(4x,a)') trim(adjustl(this%text))// &
839 ' STAGES WILL BE PRINTED TO LISTING FILE.'
840 end if
841 !
842 ! -- STAGEFILE
843 call mem_set_value(fname, 'STAGEFILE', this%input_mempath, found)
844 if (found) then
845 this%istageout = getunit()
846 call openfile(this%istageout, this%iout, fname, 'DATA(BINARY)', &
847 form, access, 'REPLACE', mnormal)
848 write (this%iout, fmtsfrbin) 'STAGE', trim(fname), this%istageout
849 end if
850 !
851 ! -- BUDGETFILE
852 call mem_set_value(fname, 'BUDGETFILE', this%input_mempath, found)
853 if (found) then
854 call assign_iounit(this%ibudgetout, this%inunit, 'BUDGET fileout')
855 call openfile(this%ibudgetout, this%iout, fname, 'DATA(BINARY)', &
856 form, access, 'REPLACE', mnormal)
857 write (this%iout, fmtsfrbin) 'BUDGET', trim(fname), this%ibudgetout
858 end if
859 !
860 ! -- BUDGETCSVFILE
861 call mem_set_value(fname, 'BUDGETCSVFILE', this%input_mempath, found)
862 if (found) then
863 call assign_iounit(this%ibudcsv, this%inunit, 'BUDGETCSV fileout')
864 call openfile(this%ibudcsv, this%iout, fname, 'CSV', &
865 filstat_opt='REPLACE')
866 write (this%iout, fmtsfrbin) 'BUDGET CSV', trim(fname), this%ibudcsv
867 end if
868 !
869 ! -- PACKAGE_CONVERGENCE_FILENAME (mf6internal: pkgconvfname)
870 call mem_set_value(fname, 'PKGCONVFNAME', this%input_mempath, found)
871 if (found) then
872 this%ipakcsv = getunit()
873 call openfile(this%ipakcsv, this%iout, fname, 'CSV', &
874 filstat_opt='REPLACE', mode_opt=mnormal)
875 write (this%iout, fmtsfrbin) 'PACKAGE_CONVERGENCE', trim(fname), &
876 this%ipakcsv
877 end if
878 !
879 ! -- MOVER
880 call mem_set_value(this%imover, 'MOVER', this%input_mempath, found)
881 if (found) then
882 write (this%iout, '(4x,A)') 'MOVER OPTION ENABLED'
883 end if
884 !
885 ! -- MAXIMUM_PICARD_ITERATIONS (mf6internal: maxsfrpicard)
886 call mem_set_value(this%maxsfrpicard, 'MAXSFRPICARD', &
887 this%input_mempath, found)
888 if (found) write (this%iout, fmtpicard) this%maxsfrpicard
889 !
890 ! -- MAXIMUM_ITERATIONS (mf6internal: maxsfrit)
891 call mem_set_value(this%maxsfrit, 'MAXSFRIT', &
892 this%input_mempath, found)
893 if (found) write (this%iout, fmtiter) this%maxsfrit
894 !
895 ! -- MAXIMUM_DEPTH_CHANGE (mf6internal: dmaxchg)
896 call mem_set_value(this%dmaxchg, 'DMAXCHG', &
897 this%input_mempath, found)
898 if (found) then
899 this%deps = dp999 * this%dmaxchg
900 write (this%iout, fmtdmaxchg) this%dmaxchg
901 end if
902 !
903 ! -- LENGTH_CONVERSION (mf6internal: lengthconv)
904 call mem_set_value(this%lengthconv, 'LENGTHCONV', &
905 this%input_mempath, found)
906 if (found) write (this%iout, fmtlengthconv) this%lengthconv
907 !
908 ! -- TIME_CONVERSION
909 call mem_set_value(this%timeconv, 'TIME_CONVERSION', &
910 this%input_mempath, found)
911 if (found) write (this%iout, fmttimeconv) this%timeconv
912 !
913 ! -- UNIT_CONVERSION (deprecated)
914 call mem_set_value(this%unitconv, 'UNIT_CONVERSION', &
915 this%input_mempath, found)
916 if (found) then
917 write (warnmsg, '(a)') 'SETTING UNIT_CONVERSION DIRECTLY'
918 call deprecation_warning('OPTIONS', 'UNIT_CONVERSION', '6.4.2', &
919 warnmsg, this%inunit)
920 end if
921 !
922 ! -- DEV_STORAGE_WEIGHT (mf6internal: storage_weight)
923 call mem_set_value(this%storage_weight, 'STORAGE_WEIGHT', &
924 this%input_mempath, found)
925 if (found) then
926 if (this%storage_weight < dhalf .or. this%storage_weight > done) then
927 write (errmsg, '(a,g0,a)') &
928 "STORAGE_WEIGHT SPECIFIED TO BE '", this%storage_weight, &
929 "' BUT CANNOT BE LESS THAN 0.5 OR GREATER THAN 1.0"
930 call store_error(errmsg)
931 call store_error_filename(this%input_fname)
932 else
933 write (this%iout, fmtstoweight) this%storage_weight
934 end if
935 end if
936 !
937 ! -- DEV_NO_CHECK (mf6internal: icheck)
938 call get_isize('ICHECK', this%input_mempath, isize)
939 if (isize > 0) then
940 this%icheck = 0
941 write (this%iout, '(4x,a)') &
942 'REACH GEOMETRY AND PARAMETER CHECKS WILL NOT BE MADE'
943 end if
944 !
945 ! -- DEV_NO_FINAL_CHECK (mf6internal: iconvchk)
946 call get_isize('ICONVCHK', this%input_mempath, isize)
947 if (isize > 0) then
948 this%iconvchk = 0
949 write (this%iout, '(4x,a)') &
950 'A FINAL CONVERGENCE CHECK OF THE CHANGE IN STREAM FLOW ROUTING '// &
951 'STAGES AND FLOWS WILL NOT BE MADE'
952 end if
953 !
954 write (this%iout, '(1x,a)') &
955 'END OF '//trim(adjustl(this%text))//' OPTIONS'
subroutine, public assign_iounit(iounit, errunit, description)
assign io unit number
integer(i4b) function, public getunit()
Get a free unit number.
subroutine, public openfile(iu, iout, fname, ftype, fmtarg_opt, accarg_opt, filstat_opt, mode_opt)
Open a file.
character(len=20) access
Definition OpenSpec.f90:7
character(len=20) form
Definition OpenSpec.f90:7
Here is the call graph for this function:

◆ sfr_source_packagedata()

subroutine sfrmodule::sfr_source_packagedata ( class(sfrtype), intent(inout) this)
private
Parameters
[in,out]thisSfrType object

Definition at line 1030 of file gwf-sfr.f90.

1031 ! -- modules
1034 ! -- dummy
1035 class(SfrType), intent(inout) :: this !< SfrType object
1036 ! -- local
1037 integer(I4B) :: i, n, nconzero
1038 integer(I4B) :: ipos
1039 character(len=10) :: cnum
1040 character(len=LENBOUNDNAME) :: bndName
1041 character(len=LINELENGTH) :: cellid_str
1042 integer(I4B), allocatable :: nboundchk(:)
1043 integer(I4B), dimension(:), pointer, contiguous :: ifno => null()
1044 integer(I4B), dimension(:, :), pointer, contiguous :: cellid => null()
1045 real(DP), dimension(:), pointer, contiguous :: rlen => null()
1046 real(DP), dimension(:), pointer, contiguous :: rwid => null()
1047 real(DP), dimension(:), pointer, contiguous :: rgrd => null()
1048 real(DP), dimension(:), pointer, contiguous :: rtp => null()
1049 real(DP), dimension(:), pointer, contiguous :: rbth => null()
1050 integer(I4B), dimension(:), pointer, contiguous :: ncon => null()
1051 integer(I4B), dimension(:), pointer, contiguous :: ndv => null()
1052 type(CharacterStringType), dimension(:), pointer, contiguous :: &
1053 boundname => null()
1054 integer(I4B), dimension(:, :), pointer, contiguous :: tslink => null()
1055 type(CharacterStringType), dimension(:), pointer, contiguous :: &
1056 tslinkvars => null()
1057 !
1058 write (this%iout, '(/1x,a)') &
1059 'PROCESSING '//trim(adjustl(this%text))//' PACKAGEDATA'
1060 !
1061 ! -- get input context PACKAGEDATA column arrays
1062 call mem_setptr(ifno, 'PACKAGEDATA_IFNO', this%input_mempath)
1063 call mem_setptr(cellid, 'CELLID', this%input_mempath)
1064 call mem_setptr(rlen, 'RLEN', this%input_mempath)
1065 call mem_setptr(rwid, 'RWID', this%input_mempath)
1066 call mem_setptr(rgrd, 'RGRD', this%input_mempath)
1067 call mem_setptr(rtp, 'RTP', this%input_mempath)
1068 call mem_setptr(rbth, 'RBTH', this%input_mempath)
1069 call mem_setptr(this%input%rhk, 'RHK', this%input_mempath)
1070 call mem_setptr(this%input%man, 'MAN', this%input_mempath)
1071 call mem_setptr(ncon, 'NCON', this%input_mempath)
1072 call mem_setptr(this%input%ustrf, 'USTRF', this%input_mempath)
1073 call mem_setptr(tslink, 'TSLINK_PD', this%input_mempath)
1074 call mem_setptr(tslinkvars, 'TSLINKVARS_PD', this%input_mempath)
1075 do n = 1, size(tslinkvars)
1076 if (tslinkvars(n) == 'RHK') this%input%rhk_tslink => tslink(n, :)
1077 if (tslinkvars(n) == 'MAN') this%input%man_tslink => tslink(n, :)
1078 if (tslinkvars(n) == 'USTRF') this%input%ustrf_tslink => tslink(n, :)
1079 end do
1080 if (.not. (associated(this%input%rhk_tslink) .and. &
1081 associated(this%input%man_tslink) .and. &
1082 associated(this%input%ustrf_tslink))) then
1083 call store_error('Time series links for RHK, MAN and USTRF not found &
1084 &in input.')
1085 call store_error_filename(this%input_fname)
1086 end if
1087 call mem_setptr(ndv, 'NDV', this%input_mempath)
1088 if (this%inamedbound /= 0) then
1089 call mem_setptr(boundname, 'BOUNDNAME', this%input_mempath)
1090 end if
1091 !
1092 ! -- allocate check array
1093 allocate (nboundchk(this%maxbound))
1094 nboundchk = 0
1095 nconzero = 0
1096 !
1097 ! -- populate reach data from input context arrays
1098 do i = 1, this%maxbound
1099 n = ifno(i)
1100 !
1101 n = this%validate_ifno(n, this%maxbound, nboundchk, &
1102 'rno', 'PACKAGEDATA')
1103 if (n == 0) cycle
1104 !
1105 ! -- cellid → igwfnode: convert integer cellid array to string
1106 ! -- all-zero or negative cellid means unconnected reach (NONE keyword or 0 0 0)
1107 if (all(cellid(1:this%dis%ndim, i) <= 0)) then
1108 this%igwfnode(n) = 0
1109 else
1110 write (cellid_str, '(10(i0,1x))') cellid(1:this%dis%ndim, i)
1111 this%igwfnode(n) = this%dis%noder_from_cellid(cellid_str, &
1112 this%inunit, this%iout, &
1113 flag_string=.false., &
1114 allow_zero=.true.)
1115 end if
1116 this%igwftopnode(n) = this%igwfnode(n)
1117 if (this%igwfnode(n) < 1) this%ianynone = this%ianynone + 1
1118 !
1119 ! -- scalar reach properties
1120 this%length(n) = rlen(i)
1121 this%width(n) = rwid(i)
1122 this%slope(n) = rgrd(i)
1123 this%strtop(n) = rtp(i)
1124 this%bthick(n) = rbth(i)
1125 !
1126 ! -- ncon and nconn
1127 this%nconnreach(n) = ncon(i)
1128 this%nconn = this%nconn + ncon(i)
1129 if (ncon(i) < 0) then
1130 write (errmsg, '(a,1x,i0,1x,a,i0,a)') &
1131 'NCON for reach', n, &
1132 'must be greater than or equal to 0 (', ncon(i), ').'
1133 call store_error(errmsg)
1134 else if (ncon(i) == 0) then
1135 nconzero = nconzero + 1
1136 end if
1137 !
1138 ! -- ndv (diversions)
1139 this%ndiv(n) = ndv(i)
1140 if (ndv(i) > 0) this%idiversions = 1
1141 !
1142 ! -- bound name
1143 write (cnum, '(i10.10)') n
1144 bndname = 'Reach'//cnum
1145 if (this%inamedbound /= 0) then
1146 bndname = boundname(i)
1147 end if
1148 this%sfrname(n) = bndname
1149 !
1150 ! -- hk, roughness (Manning), upstream fraction: copied from
1151 ! input context; sfr_ad re-syncs TS-linked values each timestep
1152 this%hk(n) = this%input%rhk(i)
1153 this%rough(n) = this%input%man(i)
1154 this%ustrf(n) = this%input%ustrf(i)
1155 !
1156 ! -- initialize sstage to reach top
1157 this%sstage(n) = this%strtop(n)
1158 end do
1159 !
1160 write (this%iout, '(1x,a)') &
1161 'END OF '//trim(adjustl(this%text))//' PACKAGEDATA'
1162 !
1163 ! -- check every reach is specified exactly once
1164 call this%report_ifno_coverage(nboundchk, this%maxbound, 'reach', &
1165 'PACKAGEDATA')
1166 deallocate (nboundchk)
1167 !
1168 if (nconzero > 0) then
1169 write (warnmsg, '(a,1x,a,1x,a,1x,i0,1x,a)') &
1170 'SFR Package', trim(this%packName), &
1171 'has', nconzero, 'reach(es) with zero connections.'
1172 call store_warning(warnmsg)
1173 end if
1174 !
1175 if (count_errors() > 0) then
1176 call store_error_filename(this%input_fname)
1177 end if
1178 !
1179 ! -- initialize default cross-section data
1180 ipos = 1
1181 this%iacross(1) = ipos
1182 do i = 1, this%maxbound
1183 this%ncrosspts(i) = 1
1184 this%station(ipos) = this%width(i)
1185 this%xsheight(ipos) = dzero
1186 this%xsrough(ipos) = done
1187 ipos = ipos + 1
1188 this%iacross(i + 1) = ipos
1189 end do
1190 !
1191 ! -- release input context packagedata memory; PACKAGEDATA_IFNO excluded
1192 ! (allocate_featureauxvar); RHK/MAN/USTRF excluded
1193 call memorystore_release('CELLID', this%input_mempath)
1194 call memorystore_release('RLEN', this%input_mempath)
1195 call memorystore_release('RWID', this%input_mempath)
1196 call memorystore_release('RGRD', this%input_mempath)
1197 call memorystore_release('RTP', this%input_mempath)
1198 call memorystore_release('RBTH', this%input_mempath)
1199 call memorystore_release('NCON', this%input_mempath)
1200 call memorystore_release('NDV', this%input_mempath)
1201 call memorystore_release('BOUNDNAME', this%input_mempath)
Here is the call graph for this function:

◆ sfr_update_flows()

subroutine sfrmodule::sfr_update_flows ( class(sfrtype), intent(inout) this,
integer(i4b), intent(in) n,
real(dp), intent(inout) qd,
real(dp), intent(in) qgwf )
private

Method to update downstream flow and groundwater leakage terms for a SFR package reach.

Parameters
[in,out]thisSfrType object
[in]nreach number
[in,out]qddownstream reach flow
[in]qgwfgroundwater leakage for reach

Definition at line 3644 of file gwf-sfr.f90.

3645 ! -- dummy
3646 class(SfrType), intent(inout) :: this !< SfrType object
3647 integer(I4B), intent(in) :: n !< reach number
3648 real(DP), intent(inout) :: qd !< downstream reach flow
3649 real(DP), intent(in) :: qgwf !< groundwater leakage for reach
3650 ! -- local
3651 integer(I4B) :: i
3652 integer(I4B) :: n2
3653 integer(I4B) :: idiv
3654 integer(I4B) :: jpos
3655 real(DP) :: qdiv
3656 real(DP) :: f
3657 !
3658 ! -- update reach terms
3659 !
3660 ! -- save final downstream stream flow
3661 this%dsflow(n) = qd
3662 !
3663 ! -- save groundwater leakage
3664 this%gwflow(n) = qgwf
3665 !
3666 ! -- route downstream flow
3667 if (qd > dzero) then
3668 !
3669 ! -- route water to diversions
3670 do i = this%ia(n) + 1, this%ia(n + 1) - 1
3671 if (this%idir(i) > 0) cycle
3672 idiv = this%idiv(i)
3673 if (idiv == 0) cycle
3674 jpos = this%iadiv(n) + idiv - 1
3675 call this%sfr_calc_div(n, idiv, qd, qdiv)
3676 this%qconn(i) = qdiv
3677 this%divq(jpos) = qdiv
3678 end do
3679 !
3680 ! -- Mover terms: store outflow after diversion loss
3681 ! as qformvr and reduce outflow (qd)
3682 ! by how much was actually sent to the mover
3683 if (this%imover == 1) then
3684 call this%pakmvrobj%accumulate_qformvr(n, qd)
3685 qd = max(qd - this%pakmvrobj%get_qtomvr(n), dzero)
3686 end if
3687 !
3688 ! -- route remaining water to downstream reaches
3689 do i = this%ia(n) + 1, this%ia(n + 1) - 1
3690 if (this%idir(i) > 0) cycle
3691 if (this%idiv(i) > 0) cycle
3692 n2 = this%ja(i)
3693 if (this%iboundpak(n2) == 0) cycle
3694 f = this%ustrf(n2) / this%ftotnd(n)
3695 this%qconn(i) = qd * f
3696 end do
3697 else
3698 do i = this%ia(n) + 1, this%ia(n + 1) - 1
3699 if (this%idir(i) > 0) cycle
3700 this%qconn(i) = dzero
3701 idiv = this%idiv(i)
3702 if (idiv == 0) cycle
3703 jpos = this%iadiv(n) + idiv - 1
3704 this%divq(jpos) = dzero
3705 end do
3706 end if

Variable Documentation

◆ ftype

character(len=lenftype) sfrmodule::ftype = 'SFR'

Definition at line 50 of file gwf-sfr.f90.

◆ text

character(len=lenpackagename) sfrmodule::text = ' SFR'

Definition at line 51 of file gwf-sfr.f90.