-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtank.py
388 lines (346 loc) · 13.7 KB
/
tank.py
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#!python3
"""
TankEvap
---------
An engineering calculation that estimates the evaporative water losses from
storage tanks at a facility. This model uses a modified method established
within Chapter 7 of EPA AP-42.
The method estimates evaporation from both standing and working losses.
Evaporative Losses From Fixed Roof Tank:
Lt = Ls + Lw
where:
Lt = total losses (lb/yr)
Ls = standing storage losses (lb/yr)
Lw = working losses (lb/yr)
"""
import math
from pint import UnitRegistry
from thermo.chemical import Chemical
ureg = UnitRegistry()
IDEAL_GAS_CONSTANT = 10.731
class TankEvap:
"""
The original Ch. 7 calculation.
Parameters
----------
(reference name) pythonic_name : dtype (eng. units)
..........
(D) tank_diameter : Float (ft)
(Hs) tank_shell_height : Float (ft)
(Hl) average_liquid_height : Float (ft)
(Hx) maximum_liquid_height : Float (ft)
(Hro) roof_outage : Float (ft)
(Mv) vapor_molecular_weight : Float (lb/lb mol)
(Tla) daily_avg_liquid_surface_temp : Float (F)
(a) tank_paint_solar_absorptance : Float (--)
(I) daily_solar_insolation_factor : Float (btu/ft^2-d)
(Tax) daily_max_ambient_temperature : Float (F)
(Tan) daily_min_ambient_temperature : Float (F)
(Pb) breather_vent_pressure_setting : Float (psia)
(Q) net_throughput : Float (gpm)
Examples
--------
Calculating Evaporation Rates
>>> cst = tank.TankEvap(
tank_diameter=48,
tank_shell_height=40,
average_liquid_height=25.3,
maximum_liquid_height=36.9,
roof_outage=0,
vapor_molecular_weight=18.0152,
daily_avg_liquid_surface_temp=108,
tank_paint_solar_absorptance=0.1,
daily_solar_insolation_factor=1208,
daily_max_ambient_temperature=63.5,
daily_min_ambient_temperature=44.5,
breather_vent_pressure_setting=0,
net_throughput=520,
)
>>> cst.calculate_total_losses()
>>> cst.total_losses
32178.064468484252
"""
def __init__(
self,
tank_diameter=None,
tank_shell_height=None,
average_liquid_height=None,
maximum_liquid_height=None,
roof_outage=None,
vapor_molecular_weight=None,
daily_avg_liquid_surface_temp=None,
tank_paint_solar_absorptance=None,
daily_solar_insolation_factor=None,
daily_max_ambient_temperature=None,
daily_min_ambient_temperature=None,
breather_vent_pressure_setting=None,
net_throughput=None,
atmospheric_pressure=14.7,
):
def degF_to_degR(value):
Q_ = ureg.Quantity
return Q_(value, ureg.degF).to("degR").magnitude
self.tank_diameter = tank_diameter
self.tank_shell_height = tank_shell_height
self.average_liquid_height = average_liquid_height
self.maximum_liquid_height = maximum_liquid_height
self.roof_outage = roof_outage
self.vapor_molecular_weight = vapor_molecular_weight
self.daily_avg_liquid_surface_temp = daily_avg_liquid_surface_temp
self.tank_paint_solar_absorptance = tank_paint_solar_absorptance
self.daily_solar_insolation_factor = daily_solar_insolation_factor
self.daily_max_ambient_temperature = daily_max_ambient_temperature
self.daily_min_ambient_temperature = daily_min_ambient_temperature
self.breather_vent_pressure_setting = breather_vent_pressure_setting
self.net_throughput = net_throughput
self.daily_avg_liquid_surface_temp_R = degF_to_degR(
daily_avg_liquid_surface_temp
)
self.atmospheric_pressure = atmospheric_pressure
def calculate_vapor_space_outage(self):
"Hvo = Hs - Hi + Hro"
self.vapor_space_outage = (
self.tank_shell_height - self.average_liquid_height + self.roof_outage
)
def calculate_vapor_space_volume(self):
"Vv = (ⲡ/4)*D^2*Hvo"
self.calculate_vapor_space_outage()
self.vapor_space_volume = (
(math.pi / 4) * self.tank_diameter ** 2 * self.vapor_space_outage
)
def calculate_vented_vapor_saturation_factor(self):
"Ks = 1/(1 + 0.053 * Pva * Hvo)"
self.calculate_vapor_space_outage()
self.calculate_vapor_pressures()
self.vented_vapor_saturation_factor = 1 / (
1 + 0.053 * self.vapor_pressure_at_tla * self.vapor_space_outage
)
def calculate_vapor_density(self):
"Wv = (Mv * Pva)/(R * Tla)"
self.calculate_vapor_pressures()
self.vapor_density = (
self.vapor_molecular_weight * self.vapor_pressure_at_tla
) / (IDEAL_GAS_CONSTANT * self.daily_avg_liquid_surface_temp_R)
def calculate_daily_vapor_temperature_range(self):
"dTv = 0.72 * (Tax-Tan) + 0.028 * a * I"
self.daily_vapor_temperature_range = (
0.72
* (self.daily_max_ambient_temperature - self.daily_min_ambient_temperature)
+ 0.028
* self.tank_paint_solar_absorptance
* self.daily_solar_insolation_factor
)
def calculate_daily_liquid_surface_temp_extremes(self):
"""
Tlx = Tla + 0.25 * dTv (All Temps in degR)
Tln = Tla - 0.25 * dTv (All Temps in degR)
"""
self.calculate_daily_vapor_temperature_range()
def degR_to_degF(value):
Q_ = ureg.Quantity
return Q_(value, ureg.degR).to("degF").magnitude
tlx = (
self.daily_avg_liquid_surface_temp_R
+ 0.25 * self.daily_vapor_temperature_range
)
self.daily_max_liquid_surface_temp = degR_to_degF(tlx)
tln = (
self.daily_avg_liquid_surface_temp_R
- 0.25 * self.daily_vapor_temperature_range
)
self.daily_min_liquid_surface_temp = degR_to_degF(tln)
def calculate_vapor_pressures(self):
"""
at Tla: Pva = exp [A - (B/Tla + C)]
at Tlx: Pvx = exp [A - (B/Tlx + C)]
at Tln: Pvn = exp [A - (B/Tln + C)]
Dependency library, thermo, uses degK for vapor press calcs.
"""
self.calculate_daily_liquid_surface_temp_extremes()
def degF_to_degK(value):
Q_ = ureg.Quantity
return Q_(value, ureg.degF).to("degK").magnitude
tla = degF_to_degK(self.daily_avg_liquid_surface_temp)
tlx = degF_to_degK(self.daily_max_liquid_surface_temp)
tln = degF_to_degK(self.daily_min_liquid_surface_temp)
self.calculate_daily_vapor_temperature_range()
def water_vapor_press_at(temp):
wat = Chemical("water")
wvp = wat.VaporPressure(temp) * ureg.Pa
return wvp.to("psi").magnitude
# Pva
try:
self.vapor_pressure_at_tla
except AttributeError:
self.vapor_pressure_at_tla = water_vapor_press_at(tla)
# Pvx
try:
self.vapor_pressure_at_tlx
except AttributeError:
self.vapor_pressure_at_tlx = water_vapor_press_at(tlx)
# Pvn
try:
self.vapor_pressure_at_tln
except AttributeError:
self.vapor_pressure_at_tln = water_vapor_press_at(tln)
def calculate_vapor_space_expansion_factor(self):
"Ke = dTv / Tla + (Pvx - Pvn -Pb)/(Pa - Pva)"
self.calculate_vapor_pressures()
self.vapor_space_expansion_factor = (
self.daily_vapor_temperature_range / self.daily_avg_liquid_surface_temp_R
) + (
(
self.vapor_pressure_at_tlx
- self.vapor_pressure_at_tln
- self.breather_vent_pressure_setting
)
/ (self.atmospheric_pressure - self.vapor_pressure_at_tla)
)
def calculate_standing_losses(self):
"Ls = 365 * Vv * Wv * Ke * Ks"
self.calculate_vapor_space_volume()
self.calculate_vented_vapor_saturation_factor()
self.calculate_vapor_density()
self.calculate_vapor_space_expansion_factor()
self.standing_losses = (
365
* self.vapor_space_volume
* self.vapor_density
* self.vapor_space_expansion_factor
* self.vented_vapor_saturation_factor
)
def calculate_working_losses(self):
"Lw = 0.001 * Mv * Pva * Q * Kn * Kp"
self.annual_net_throughput = self.net_throughput * 24 * 60 * 365 / 42
self.working_tank_volume = (
math.pi * self.tank_diameter ** 2 * self.maximum_liquid_height / 4
)
self.turnovers = 5.615 * self.annual_net_throughput / self.working_tank_volume
if self.turnovers > 36:
self.turnover_factor = (180 + self.turnovers) / (6 * self.turnovers)
else:
self.turnover_factor = 1
self.working_loss_product_factor = 1
self.working_losses = (
0.001
* self.vapor_molecular_weight
* self.vapor_pressure_at_tla
* self.annual_net_throughput
* self.turnover_factor
* self.working_loss_product_factor
)
def calculate_total_losses(self):
"Lt = Ls + Lw"
self.calculate_standing_losses()
self.calculate_working_losses()
self.total_losses = self.standing_losses + self.working_losses
class TankEvap2020(TankEvap):
"""
The modified Ch. 7 equation from June 2020.
Parameters
----------
(reference name) pythonic_name : dtype (eng. units)
..........
(D) tank_diameter : Float (ft)
(Hs) tank_shell_height : Float (ft)
(Hl) average_liquid_height : Float (ft)
(Hx) maximum_liquid_height : Float (ft)
(Hro) roof_outage : Float (ft)
(Mv) vapor_molecular_weight : Float (lb/lb mol)
(Tla) daily_avg_liquid_surface_temp : Float (F)
(a) tank_paint_solar_absorptance : Float (--)
(I) daily_solar_insolation_factor : Float (btu/ft^2-d)
(Tax) daily_max_ambient_temperature : Float (F)
(Tan) daily_min_ambient_temperature : Float (F)
(Pb) breather_vent_pressure_setting : Float (psia)
(Q) net_throughput : Float (gpm)
Examples
--------
Calculating Evaporation Rates
>>> cst = tank.TankEvap2020(
tank_diameter=48,
tank_shell_height=40,
average_liquid_height=25.3,
maximum_liquid_height=36.9,
minimum_liquid_height=13.7,
roof_outage=0,
vapor_molecular_weight=18.0152,
daily_avg_liquid_surface_temp=108,
tank_paint_solar_absorptance=0.1,
daily_solar_insolation_factor=1208,
daily_max_ambient_temperature=63.5,
daily_min_ambient_temperature=44.5,
breather_vent_pressure_setting=0,
annual_sum_liquid_increases=0,
)
>>> cst.calculate_total_losses()
>>> cst.total_losses
32178.064468484252
"""
def __init__(
self,
tank_diameter=None,
tank_shell_height=None,
average_liquid_height=None,
maximum_liquid_height=None,
minimum_liquid_height=None,
roof_outage=None,
vapor_molecular_weight=None,
daily_avg_liquid_surface_temp=None,
tank_paint_solar_absorptance=None,
daily_solar_insolation_factor=None,
daily_max_ambient_temperature=None,
daily_min_ambient_temperature=None,
breather_vent_pressure_setting=None,
annual_sum_liquid_increases=None,
atmospheric_pressure=14.7,
):
def degF_to_degR(value):
Q_ = ureg.Quantity
return Q_(value, ureg.degF).to("degR").magnitude
self.tank_diameter = tank_diameter
self.tank_shell_height = tank_shell_height
self.average_liquid_height = average_liquid_height
self.maximum_liquid_height = maximum_liquid_height
self.minimum_liquid_height = minimum_liquid_height
self.roof_outage = roof_outage
self.vapor_molecular_weight = vapor_molecular_weight
self.daily_avg_liquid_surface_temp = daily_avg_liquid_surface_temp
self.tank_paint_solar_absorptance = tank_paint_solar_absorptance
self.daily_solar_insolation_factor = daily_solar_insolation_factor
self.daily_max_ambient_temperature = daily_max_ambient_temperature
self.daily_min_ambient_temperature = daily_min_ambient_temperature
self.breather_vent_pressure_setting = breather_vent_pressure_setting
self.annual_sum_liquid_increases = annual_sum_liquid_increases
self.daily_avg_liquid_surface_temp_R = degF_to_degR(
daily_avg_liquid_surface_temp
)
self.atmospheric_pressure = atmospheric_pressure
def calculate_net_working_loss_throughput(self):
"Vq = (𝜮Hqi) * (π/4) * D^2"
self.net_working_loss_throughput = (
self.annual_sum_liquid_increases * (math.pi / 4) * self.tank_diameter ** 2
)
def calculate_working_losses(self):
"Lw = Vq * Kn * Kp * Wv * Kb"
self.calculate_vapor_density()
self.calculate_net_working_loss_throughput()
self.working_tank_volume = (
math.pi * self.tank_diameter ** 2 * self.maximum_liquid_height / 4
)
self.turnovers = self.net_working_loss_throughput / (
self.maximum_liquid_height - self.minimum_liquid_height
)
if self.turnovers > 36:
self.turnover_factor = (180 + self.turnovers) / (6 * self.turnovers)
else:
self.turnover_factor = 1
working_loss_product_factor = 1
vent_setting_correction_factor = 1
factors = working_loss_product_factor * vent_setting_correction_factor
self.working_losses = (
self.net_working_loss_throughput
* self.turnover_factor
* self.vapor_density
* factors
)