-
Notifications
You must be signed in to change notification settings - Fork 0
/
bmp_sand_filter.f
353 lines (297 loc) · 13.7 KB
/
bmp_sand_filter.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
subroutine sand_filter(kk,flw,sed)
!! ~ ~ ~ PURPOSE ~ ~ ~
!! this subroutine routes water and sediment through sand filters in the subbasin
!! ~ ~ ~ INCOMING VARIABLES ~ ~ ~
!! name |units |definition
!! ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
!! hru_sub(:) |none |subbasin in which HRU/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qq,
& qfiltr,sloss,spndconc,sedpnd,qpndi,qpnde,sedrmeff,sed_removed,
& sedconc,qevap,hrd
real*8, dimension(:) :: qpnd(0:nstep),qsw(0:nstep),qin(0:nstep),
& qout(0:nstep),fc(0:nstep),f(0:nstep)
real, dimension(3,0:nstep), intent(inout) :: flw, sed
sb = inum1
sub_ha = da_ha * sub_fr(sb)
dt = real(idt) / 60. !time interval in hours
qin = 0.; qout = 0.;qevap=0
flw(2,:) = 0.; sed(2,:) = 0.;f=0
qpnd = 0.; qsw = 0.; qpndi = 0.; qpnde = 0.; fc = 0.;qfiltr = 0.
kb = 1.38e-16 !Boltzmann constant, g-cm^2/s^2-K
!! Initialize parameters, coefficients, etc
tsa = ft_sa(sb,kk) !total surface area of filter (m^2)
if (tsa>sub_ha*10000.*0.5) tsa = sub_ha*10000.*0.5 !sandfilter should be smaller than 0.5 times the subbasin area
ffsa = ft_fsa(sb,kk) !fraction of infiltration bed in the filtration basin (m2/m2)
mxvol = ft_h(sb,kk) / 1000. * tsa !max. capacity of the basin (m^3)
pdia = ft_pd(sb,kk) !outflow orifice pipe diameter (mm)
splw = ft_bpw(sb,kk) !spillway overflow weir width (m)
ksat = ft_k(sb,kk) !saturated hydraulic conductivity (mm/hr)
por = ft_por(sb,kk) !filter porosity
dp = ft_dp(sb,kk) / 10. !median diameter of TSS particle (cm)
dc = ft_dc(sb,kk) / 10. !median diameter of filter media (cm)
pden = tss_den(sb,kk) !density of tss particle (g/cm3)
alp = ft_alp(sb,kk) !filter attachment efficiency (0-1)
vfiltr = ft_dep(sb,kk) / 1000. * tsa * ffsa * por !actual volume of filter column (m^3)
!! wetting front suction head (mm)
wetfsh = 10. * Exp(6.5309 - 7.32561 * por + 3.809479 * por ** 2 -
& 0.049837 * por * 100. + 0.001608 * por ** 2 * 100. ** 2 -
& 0.000799 * 100. ** 2 * por)
!! Get initial values from previous day
qpnd(0) = ft_qpnd(sb,kk)
qsw(0) = ft_qsw(sb,kk)
qin(0) = ft_qin(sb,kk)
qout(0) = ft_qout(sb,kk)
sedpnd = ft_sedpnd(sb,kk)
fc(0) = ft_fc(sb,kk)
do ii=1,nstep
qloss = 0.
qin(ii) = flw(1,ii) * 10. * (sub_ha - tsa / 10000.) +
& precipdt(ii) * tsa / 1000. !m^3
qout(ii) = qout(ii-1)
If (qin(ii)<0.001.and.qpnd(ii-1)<0.001)then
if (qsw(ii-1)<0.001) then
!No flow
qout(ii) = 0.
qloss = 0.
else
qout(ii) = ksat * dt * qsw(ii-1) / vfiltr / 1000.* tsa
& * ffsa !m^3
! outflow control
if (sf_ptp(sb,kk)==1) then
phead = (qsw(ii-1)/(tsa*ffsa)/por) * 1000. !mm
! If (phead>pdia/2.) then
qpipe = pipeflow(pdia,phead) * dt *3600. !m^3
! else
! qpipe = qout(ii) * 2. !pipe flow does not affect outflow
! endif
!recalculate water balance if orifice pipe limits outflow
if(qout(ii) > qpipe) qout(ii) = qpipe
end if
qsw(ii) = max(0.,qsw(ii - 1) - qout(ii)) ! m^3
endif
Else
qpnd(ii) = qpnd(ii-1) + qin(ii) !m^3
hpnd = qpnd(ii) / tsa * 1000. !ponding depth on the filter surface, mm
!spillway overflow
If (hpnd > ft_h(sb,kk)) Then
qloss = max(0.,qpnd(ii) - mxvol) !weir outflow
hpnd = ft_h(sb,kk)
qpnd(ii) = max(0.,qpnd(ii) - qloss)
End If
qpndi = qpnd(ii) + qsw(ii-1)
! estimate unsaturated filter flow
if(qsw(ii-1)<0.99*vfiltr) then
if (qpnd(ii)>0) then
whd = (wetfsh + hpnd)
tst = ksat
Do !green and ampt infiltration
fc(ii) = fc(ii - 1) + ksat * dt + whd * Log((tst + whd)
& / (fc(ii - 1) + whd))
If (Abs(fc(ii) - tst) < 0.001) Then
Exit
Else
tst = fc(ii)
End If
End do
!infiltration rate
f(ii) = ksat * (1 + whd / fc(ii)) !mm/hr
!water infiltrated, m^3
qfiltr = f(ii) * dt / 1000. * tsa * ffsa
!infiltration limited by the total available water
If (qfiltr > qpnd(ii)) then
qfiltr = qpnd(ii)
qpnd(ii) = 0.
else
qpnd(ii) = qpnd(ii) - qfiltr
endif
hpnd = qpnd(ii) / tsa * 1000. !mm
!update soil water
qsw(ii) = qsw(ii-1) + qfiltr
else
f(ii) = 0.
qfiltr = 0.
end if
!soil water no more than saturation
if (qsw(ii) > vfiltr) then
hrd = qsw(ii) / vfiltr
qout(ii) = ksat * hrd * dt / 1000. * tsa * ffsa !m3
qsw(ii) = qsw(ii) - qout(ii)
qpnd(ii) = qpndi - qsw(ii) - qout(ii)
else
if (qpnd(ii)>=qpnd(ii-1).and.qout(ii-1)<0.001) then
!rising hydrograph, no outflow
qout(ii) = 0.
else
!receding or continuing hydrograph
qout(ii) = ksat * qsw(ii) / vfiltr * dt / 1000.
& * tsa * ffsa !m3
if (qout(ii)>qout(ii-1)) qout(ii) = qout(ii-1)
qsw(ii) = qsw(ii) - qout(ii)
endif
endif
else
!darcy flow when saturated
qfiltr = ksat * (hpnd + ft_dep(sb,kk)) /
& ft_dep(sb,kk) * dt / 1000. * tsa * ffsa
qout(ii) = qfiltr
qpnd(ii) = qpnd(ii) - qfiltr
if(qpnd(ii)<0) then
qpnd(ii) = 0.
qsw(ii) = qsw(ii-1)+qin(ii)+qpnd(ii-1)-qfiltr
qfiltr = qin(ii) + qpnd(ii-1)
else
qsw(ii) = vfiltr
qfiltr = qout(ii)
endif
end if
!Evapotranspiration loss
qevap = tsa * sub_etday(sb) / 1000. / 1440. * idt !m^3
if(qevap<1e-6) qevap = 0.
qpnd(ii) = qpnd(ii) - qevap
If (qpnd(ii)<0) then
qpnd(ii) = 0.
qevap = 0.
endif
!check if orifice pipe limits outflow in case outflow control exists
if (sf_ptp(sb,kk)==1) then
phead = (qsw(ii)/(tsa*ffsa)/por + qpnd(ii)/tsa) * 1000. !mm
qpipe = pipeflow(pdia,phead) * dt *3600. !m^3
!recalculate water balance if orifice pipe limits outflow
if(qout(ii) > qpipe) then
qout(ii) = qpipe ! m^3
if (qout(ii)<qin(ii)+qpnd(ii-1)+qsw(ii-1)) then
if (qout(ii)<qin(ii)+qpnd(ii-1)) then
qfiltr = qout(ii)
else
qfiltr = qin(ii) + qpnd(ii-1)
endif
qsw(ii) = qsw(ii-1) + qfiltr - qout(ii)
qpnd(ii) = qin(ii) + qpnd(ii-1) - qfiltr
else
qout(ii) = qin(ii) + qpnd(ii-1) + qsw(ii-1)
qfiltr = qin(ii) + qpnd(ii-1)
qsw(ii) = 0.
qpnd(ii) = 0.
endif
qloss = max(0.,qpnd(ii) - mxvol)
qpnd(ii) = max(0.,qpnd(ii) - qloss)
endif
end if
qpnde = qpnd(ii) + qsw(ii)
Endif
! no outlet control: all the infiltration water is added to shallow aquifer recharge for next day\
if (sf_ptp(sb,kk)==0) then
bmp_recharge(sb) = bmp_recharge(sb)
& + qout(ii) / (sub_ha*10000.- tsa) *1000.
qout(ii) = 0. !effluent from the filter unit (through-flow+overflow), normalized to subbasin area
end if
! store the flow output
flw(1,ii) = qin(ii) / (sub_ha *10000. - tsa) * 1000. !mm
flw(2,ii) = qout(ii) / (sub_ha*10000.- tsa) *1000. !mm
flw(3,ii) = qloss / (sub_ha *10000. - tsa) * 1000. !mm
! write(*,'(2i3,20f7.3)') iida, ii, qin(ii),qout(ii),qpnd(ii),
! & qsw(ii),qloss
!--------------------------------------------------------------------------------------
! TSS removal
sloss = 0.; sedrmeff = 0.
! sediment bypass in spillway overflow
if (qloss>0) then
if(qin(ii)>0) then
sedconc = sed(1,ii) / qin(ii) !tons/m3
else
sedconc = sedpnd / qpnd(ii) !tons/m3
endif
sloss = sedconc * qloss !tons
sedpnd = sedpnd + sed(1,ii) - sloss !tons
end if
if (qpndi>0.001) then
spndconc = sedpnd / qpndi ! tons/m^3
else
spndconc = 0.
end if
If (qout(ii)<0.001)then
! no outflow through filter media
if (qloss>0.001) then
sed(2,ii) = sloss
else
sed(2,ii) = 0.
end if
Else
! water temperature, C
tmpw = sub_hhwtmp(sb,ii)
! water viscosity (g/cm-s) using 3rd order polynomial interpolation
mu = -3.e-6 * tmpw ** 3 + 0.0006 * tmpw ** 2 -
& 0.0469 * tmpw + 1.7517
mu = mu * 1.e-2
!filter flow, cm/s
qcms = qout(ii) / (tsa * ffsa) * 100. / dt / 3600.
If (qcms > 0.001) Then
!sedimentation efficiency
effg = (pden - 1) * 981 * dp ** 2 / (18 * mu * qcms)
if (effg<0.001) effg = 0.001
!brownian motion efficiency
effbr = 0.905 * (kb * (tmpw+273.) / (mu * dp * dc *
& qcms)) ** 0.6667
Else
effg = 0.999
effbr = 0.999
End If
!interception efficiency
effl = 1.5 * (dp / dc) ** 2
If (effl > 0.999) effl = 0.99
If (effg > 0.999) effg = 0.99
If (effbr > 0.999) effbr = 0.99
!contact efficiency
effct = effl + effg + effbr
If (effct > 0.999) effct = 0.99
! sediment removal efficiency
sedrmeff = 1. - Exp(-1.5 * (1. - por) * alp * effct *
& ft_dep(sb,kk) / ft_dc(sb,kk))
! sediment removed during the time step
sed_removed = spndconc * qout(ii) * sedrmeff
! sediment through filter, tons
sed(2,ii) = spndconc * qout(ii) * (1. - sedrmeff)
sedpnd = sedpnd - spndconc * qout(ii) !tons
sed(3,ii) = sloss
if (sedpnd<0) sedpnd = 0.
! write cumulative amount of sediment removed
ft_sed_cumul(sb,kk) = ft_sed_cumul(sb,kk) + sed_removed !tons
End if
! write(*,'(3i6,20f10.3)') iyr,iida,ii,qin(ii),
! & qout(ii),qsw(ii),qpnd(ii),qloss,qevap
! write(*,'(3i5,20f10.3)') iyr,iida,ii,precipdt(ii),qin(ii),
! & qout(ii),qloss,qpndi,qpnde,qpnd(ii),qsw(ii),f(ii),sed(1,ii)*1000,
! & sed(2,ii)*1000,sloss*1000
end do
! store end-of-day values for next day
ft_qpnd(sb,kk) = qpnd(nstep)
ft_qsw(sb,kk) = qsw(nstep)
ft_qin(sb,kk) = qin(nstep)
ft_qout(sb,kk) = qout(nstep)
ft_sedpnd(sb,kk) = sedpnd
ft_fc(sb,kk) = fc(nstep)
return
end subroutine