MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
gwf-sfr-steady.f90
Go to the documentation of this file.
1submodule(sfrmodule) sfrmodulesteady
2contains
3
4 ! -- documented on the SfrType type-bound procedure in gwf-sfr.f90
5 module procedure sfr_calc_steady
6 integer(I4B) :: i
7 integer(I4B) :: isolve
8 integer(I4B) :: iic
9 integer(I4B) :: iic2
10 integer(I4B) :: iic3
11 integer(I4B) :: iic4
12 integer(I4B) :: ibflg
13 real(DP) :: qmp
14 real(DP) :: qsrc
15 real(DP) :: qsrcmp
16 real(DP) :: tp
17 real(DP) :: bt
18 real(DP) :: hsfr
19 real(DP) :: qc
20 real(DP) :: en1
21 real(DP) :: en2
22 real(DP) :: qen1
23 real(DP) :: f1
24 real(DP) :: f2
25 real(DP) :: qgwf1
26 real(DP) :: qgwf2
27 real(DP) :: qgwfp
28 real(DP) :: qgwfold
29 real(DP) :: fhstr1
30 real(DP) :: fhstr2
31 real(DP) :: d2
32 real(DP) :: dpp
33 real(DP) :: dx
34 real(DP) :: q1
35 real(DP) :: q2
36 real(DP) :: derv
37 real(DP) :: dlh
38 real(DP) :: dlhold
39 real(DP) :: fp
40 real(DP) :: err
41 real(DP) :: errold
42
43 d2 = dzero
44 q1 = dzero
45 q2 = dzero
46 qsrc = dzero
47 qgwf = dzero
48 qgwfold = dzero
49
50 ! calculate the flow at end of the reach
51 ! excluding groundwater leakage
52 qc = qu + qi + qr - qe + qro + qfrommvr
53
54 ! calculate flow at the middle of the reach
55 ! excluding groundwater leakage
56 qsrcmp = qu + qi + qfrommvr + dhalf * (qr - qe + qro)
57 qmp = qsrcmp ! initial estimate flow at the midpoint
58
59 ! calculate stream depth at the midpoint
60 call this%sfr_calc_reach_depth(n, qmp, d1)
61
62 ! calculate sources/sinks for reach
63 ! excluding groundwater leakage
64 call this%sfr_calc_qsource(n, d1, qsrc)
65
66 ! calculate initial reach stage, downstream flow,
67 ! and groundwater leakage
68 tp = this%strtop(n)
69 bt = tp - this%bthick(n)
70 hsfr = d1 + tp
71 qd = max(qsrc, dzero)
72 qgwf = dzero
73 ! set flag to skip iterations
74 isolve = 1
75 if (hsfr <= tp .and. hgwf <= tp) isolve = 0
76 if (hgwf <= tp .and. qc < dem30) isolve = 0
77 if (this%sfr_gwf_conn(n) == 0) isolve = 0
78
79 ! iterate to achieve solution
80 calc_solution: if (isolve /= 0) then
81
82 ! estimate initial end points
83 en1 = dzero
84 if (d1 > dem30) then
85 if ((tp - hgwf) > dem30) then
86 en2 = dp9 * d1
87 else
88 en2 = d1p1 * d1 - (tp - hgwf)
89 end if
90 else if ((tp - hgwf) > dem30) then
91 en2 = done
92 else
93 en2 = dp99 * (hgwf - tp)
94 end if
95
96 ! estimate flow at end points
97 ! end point 1
98 if (hgwf > tp) then
99 call this%sfr_calc_qgwf(n, dzero, hgwf, qgwf1)
100 qgwf1 = -qgwf1
101 qen1 = qmp - dhalf * qgwf1
102 else
103 qgwf1 = dzero
104 qen1 = qsrcmp
105 end if
106 if (hgwf > bt) then
107 call this%sfr_calc_qgwf(n, en2, hgwf, qgwf2)
108 qgwf2 = -qgwf2
109 else
110 call this%sfr_calc_qgwf(n, en2, bt, qgwf2)
111 qgwf2 = -qgwf2
112 end if
113 if (qgwf2 > qsrc) qgwf2 = qsrc
114
115 ! calculate two depths
116 call this%sfr_calc_reach_depth(n, (qsrcmp - dhalf * qgwf1), d1)
117 call this%sfr_calc_reach_depth(n, (qsrcmp - dhalf * qgwf2), d2)
118
119 ! determine roots
120 if (d1 > dem30) then
121 f1 = en1 - d1
122 else
123 en1 = dzero
124 f1 = en1 - dzero
125 end if
126 if (d2 > dem30) then
127 f2 = en2 - d2
128 if (f2 < dem30) en2 = d2
129 else
130 d2 = dzero
131 f2 = en2 - dzero
132 end if
133
134 ! iterate to find a solution
135 dpp = dhalf * (en1 + en2)
136 dx = dpp
137 iic = 0
138 iic2 = 0
139 iic3 = 0
140 fhstr1 = dzero
141 fhstr2 = dzero
142 qgwfp = dzero
143 dlhold = dzero
144 do i = 1, this%maxsfrit
145 ibflg = 0
146 d1 = dpp
147 d2 = d1 + dtwo * this%deps
148 ! calculate q at midpoint at both end points
149 call this%sfr_calc_qman(n, d1, q1)
150 call this%sfr_calc_qman(n, d2, q2)
151 ! calculate groundwater leakage at both end points
152 call this%sfr_calc_qgwf(n, d1, hgwf, qgwf1)
153 qgwf1 = -qgwf1
154 call this%sfr_calc_qgwf(n, d2, hgwf, qgwf2)
155 qgwf2 = -qgwf2
156 !
157 if (qgwf1 >= qsrc) then
158 en2 = dpp
159 dpp = dhalf * (en1 + en2)
160 call this%sfr_calc_qgwf(n, dpp, hgwf, qgwfp)
161 qgwfp = -qgwfp
162 if (qgwfp > qsrc) qgwfp = qsrc
163 call this%sfr_calc_reach_depth(n, (qsrcmp - dhalf * qgwfp), dx)
164 ibflg = 1
165 else
166 fhstr1 = (qsrcmp - dhalf * qgwf1) - q1
167 fhstr2 = (qsrcmp - dhalf * qgwf2) - q2
168 end if
169 !
170 if (ibflg == 0) then
171 derv = dzero
172 if (abs(d1 - d2) > dzero) then
173 derv = (fhstr1 - fhstr2) / (d1 - d2)
174 end if
175 if (abs(derv) > dem30) then
176 dlh = -fhstr1 / derv
177 else
178 dlh = dzero
179 end if
180 dpp = d1 + dlh
181
182 ! updated depth outside of endpoints - use bisection instead
183 if ((dpp >= en2) .or. (dpp <= en1)) then
184 if (abs(dlh) > abs(dlhold) .or. dpp < dem30) then
185 ibflg = 1
186 dpp = dhalf * (en1 + en2)
187 end if
188 end if
189
190 ! check for slow convergence
191 ! set flags to determine if the Newton-Raphson method oscillates
192 ! or if convergence is slow
193 if (qgwf1 * qgwfold < dem30) then
194 iic2 = iic2 + 1
195 else
196 iic2 = 0
197 end if
198 if (qgwf1 < dem30) then
199 iic3 = iic3 + 1
200 else
201 iic3 = 0
202 end if
203 if (dlh * dlhold < dem30 .or. abs(dlh) > abs(dlhold)) then
204 iic = iic + 1
205 end if
206 iic4 = 0
207 if (iic3 > 7 .and. iic > 12) then
208 iic4 = 1
209 end if
210
211 ! switch to bisection when the Newton-Raphson method oscillates
212 ! or when convergence is slow
213 if (iic2 > 7 .or. iic > 12 .or. iic4 == 1) then
214 ibflg = 1
215 dpp = dhalf * (en1 + en2)
216 end if
217 !
218 ! Calculate perturbed gwf flow
219 call this%sfr_calc_qgwf(n, dpp, hgwf, qgwfp)
220 qgwfp = -qgwfp
221 if (qgwfp > qsrc) then
222 qgwfp = qsrc
223 if (abs(en1 - en2) < this%dmaxchg * dem6) then
224 call this%sfr_calc_reach_depth(n, (qsrcmp - dhalf * qgwfp), dpp)
225 end if
226 end if
227 call this%sfr_calc_reach_depth(n, (qsrcmp - dhalf * qgwfp), dx)
228 end if
229
230 ! bisection to update end points
231 fp = dpp - dx
232 if (ibflg == 1) then
233 dlh = fp
234 ! change end points
235 ! root is between f1 and fp
236 if (f1 * fp < dzero) then
237 en2 = dpp
238 f2 = fp
239 ! root is between fp and f2
240 else
241 en1 = dpp
242 f1 = fp
243 end if
244 err = min(abs(fp), abs(en2 - en1))
245 else
246 err = abs(dlh)
247 end if
248
249 ! check for convergence and exit if converged
250 if (err < this%dmaxchg) then
251 d1 = dpp
252 qgwf = qgwfp
253 qd = qsrc - qgwf
254 exit
255 end if
256
257 ! save iterates
258 errold = err
259 dlhold = dlh
260 if (ibflg == 1) then
261 qgwfold = qgwfp
262 else
263 qgwfold = qgwf1
264 end if
265
266 end do
267 ! depth = 0 and hgwf < bt
268 else
269 call this%sfr_calc_qgwf(n, d1, hgwf, qgwf)
270 qgwf = -qgwf
271
272 ! leakage exceeds inflow
273 if (qgwf > qsrc) then
274 d1 = dzero
275 call this%sfr_calc_qsource(n, d1, qsrc)
276 qgwf = qsrc
277 end if
278 qd = qsrc - qgwf
279 end if calc_solution
280
281 end procedure sfr_calc_steady
282end submodule
This module contains the SFR package methods.
Definition gwf-sfr.f90:7