MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
gwf-sfr-transient.f90
Go to the documentation of this file.
1submodule(sfrmodule) sfrmoduletransient
2contains
3
4 ! -- documented on the SfrType type-bound procedure in gwf-sfr.f90
5 module procedure sfr_calc_transient
6 use tdismodule, only: delt
7
8 integer(I4B) :: igwfconn
9 integer(I4B) :: number_picard
10 integer(I4B) :: i
11 integer(I4B) :: j
12 real(DP) :: kinematic_residual
13 real(DP) :: kinematic_storage
14 real(DP) :: weight
15 real(DP) :: celerity
16 real(DP) :: courant
17 real(DP) :: dq
18 real(DP) :: qtol
19 real(DP) :: qsrc
20 real(DP) :: qlat
21 real(DP) :: da
22 real(DP) :: db
23 real(DP) :: dc
24 real(DP) :: dd
25 real(DP) :: qa
26 real(DP) :: qb
27 real(DP) :: qc
28 real(DP) :: xsa_a
29 real(DP) :: xsa_b
30 real(DP) :: xsa_c
31 real(DP) :: q
32 real(DP) :: q2
33 real(DP) :: d
34 real(DP) :: d2
35 real(DP) :: a
36 real(DP) :: a2
37 real(DP) :: d1old
38 real(DP) :: qd2
39 real(DP) :: ad
40 real(DP) :: ad2
41 real(DP) :: residual
42 real(DP) :: residual2
43 real(DP) :: residual_final
44 real(DP) :: qderv
45 real(DP) :: delq
46 real(DP) :: delh
47 real(DP) :: dd2
48 real(DP) :: en1
49 real(DP) :: en2
50 real(DP) :: dmid
51 logical :: lbisect
52
53 weight = this%storage_weight
54 dq = this%deps
55 qtol = dq * dtwo
56
57 celerity = dzero
58 qgwf = dzero
59 lbisect = .false.
60
61 qlat = qr + qro - qe
62
63 this%usinflow(n) = qu + qi + qfrommvr
64
65 qa = this%usinflowold(n)
66 qb = this%dsflowold(n)
67 call this%sfr_calc_reach_depth(n, qa, da)
68 call this%sfr_calc_reach_depth(n, qb, db)
69
70 qc = this%usinflow(n)
71 call this%sfr_calc_reach_depth(n, qc, dc)
72
73 xsa_a = this%calc_area_wet(n, da)
74 xsa_b = this%calc_area_wet(n, db)
75 xsa_c = this%calc_area_wet(n, dc)
76
77 ! estimate qd
78 qd = this%dsflow(n)
79 if (qd == dzero) then
80 qd = (qc + qb) * dhalf
81 end if
82 call this%sfr_calc_reach_depth(n, qd, dd)
83 ad = this%calc_area_wet(n, dd)
84
85 ! estimate the depth at the midpoint
86 d1 = (dc + dd) * dhalf
87 d1old = d1
88
89 ! estimate qgwf
90 igwfconn = this%sfr_gwf_conn(n)
91 if (igwfconn == 1) then
92 ! -- a dry gaining reach with no inflow can get stuck at zero depth under
93 ! Picard iteration: with a small time step zero depth is a stable fixed
94 ! point because conductance and saturation vanish there. Only in that
95 ! case (aquifer head above the streambed top and effectively no routed
96 ! inflow) solve the depth by bisection instead, bracketed between the
97 ! wet-streambed depth (DEM5) and the aquifer depth above the streambed
98 ! top, so the reach rewets at any dt. A reach with meaningful inflow
99 ! (dc >= DEM5) is left on the untouched Picard path.
100 en2 = hgwf - this%strtop(n)
101 if (en2 > dtwo * dem5 .and. dc < dem5) then
102 lbisect = .true.
103 en1 = dem5
104 d1 = dhalf * (en1 + en2)
105 end if
106 q = qu + qi + qr - qe + qro + qfrommvr
107 call this%sfr_calc_qgwf(n, d1, hgwf, qgwf)
108 qgwf = -qgwf
109 if (qgwf > q) then
110 qgwf = q
111 end if
112 end if
113
114 ! calculate maximum wave speed and courant number
115 q = qc + qlat - qgwf
116 call this%sfr_calc_reach_depth(n, q, d)
117 a = this%calc_area_wet(n, d)
118 if (d > dzero) then
119 q2 = q + dq
120 call this%sfr_calc_reach_depth(n, q2, d2)
121 a2 = this%calc_area_wet(n, d2)
122 celerity = (q2 - q) / (a2 - a)
123 else
124 celerity = dzero
125 end if
126 courant = celerity * delt / this%length(n)
127 if (courant > dzero) then
128 if (courant < this%crmin(n)) this%crmin(n) = courant
129 if (courant > this%crmax(n)) this%crmax(n) = courant
130 this%crsum(n) = this%crsum(n) + courant
131 this%crcnt(n) = this%crcnt(n) + 1
132 end if
133
134 qlat = qlat / this%length(n)
135
136 number_picard = this%maxsfrpicard
137 if (igwfconn == 1) then
138 number_picard = this%maxsfrpicard
139 else
140 number_picard = 1
141 end if
142
143 kinematicpicard: do i = 1, number_picard
144 if (igwfconn == 1) then
145 q = qu + qi + qr - qe + qro + qfrommvr
146 call this%sfr_calc_qgwf(n, d1, hgwf, qgwf)
147 qgwf = -qgwf
148 if (qgwf > q) then
149 qgwf = q
150 end if
151 end if
152
153 qsrc = qlat - qgwf / this%length(n)
154
155 newton: do j = 1, this%maxsfrit
156 qd2 = qd + dq
157 call this%sfr_calc_reach_depth(n, qd2, dd2)
158 ad2 = this%calc_area_wet(n, dd2)
159
160 residual = kinematic_residual(qa, qb, qc, qd, &
161 xsa_a, xsa_b, xsa_c, ad, &
162 qsrc, this%length(n), weight, delt, &
163 courant)
164
165 residual2 = kinematic_residual(qa, qb, qc, qd2, &
166 xsa_a, xsa_b, xsa_c, ad2, &
167 qsrc, this%length(n), weight, delt, &
168 courant)
169 qderv = (residual2 - residual) / dq
170 if (qderv > dzero) then
171 delq = -residual / qderv
172 else
173 delq = dzero
174 end if
175
176 if (qd + delq < dem30) then
177 delq = -qd
178 end if
179
180 qd = qd + delq
181
182 call this%sfr_calc_reach_depth(n, qd, dd)
183 ad = this%calc_area_wet(n, dd)
184 residual_final = kinematic_residual(qa, qb, qc, qd, &
185 xsa_a, xsa_b, xsa_c, ad, &
186 qsrc, this%length(n), weight, delt, &
187 courant)
188
189 if (abs(delq) < qtol .and. abs(residual_final) < qtol) then
190 exit newton
191 end if
192
193 end do newton
194
195 qd = max(qd, dzero)
196 if (lbisect) then
197 ! -- bisection step. dmid is the depth implied by the routed flow at the
198 ! current depth d1; the root is where the two are equal. Move the
199 ! bracket end that keeps the root inside it.
200 dmid = (dc + dd) * dhalf
201 if (dmid > d1) then
202 en1 = d1
203 else
204 en2 = d1
205 end if
206 d1 = dhalf * (en1 + en2)
207 delh = en2 - en1
208 else
209 d1 = (dc + dd) * dhalf
210 delh = (d1 - d1old)
211 end if
212
213 if (i > 1 .and. abs(delh) < this%dmaxchg) then
214 exit kinematicpicard
215 end if
216
217 end do kinematicpicard
218
219 this%storage(n) = kinematic_storage(xsa_a, xsa_b, xsa_c, ad, &
220 this%length(n), delt, &
221 courant)
222
223 end procedure sfr_calc_transient
224
225end submodule
real(dp) function kinematic_storage(aa, ab, ac, ad, length, delt, courant)
Kinematic routing equation storage term.
real(dp) function kinematic_residual(qa, qb, qc, qd, aa, ab, ac, ad, qsrc, length, weight, delt, courant)
Kinematic routing equation residual.
This module contains the SFR package methods.
Definition gwf-sfr.f90:7
real(dp), pointer, public delt
length of the current time step
Definition tdis.f90:32