Coverage for /home/caleb/Documents/University/CHE2703/fluids/fluids/safety_valve.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- Copyright (C) 2016, Caleb Bell <Caleb.Andrew.Bell@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.'''
'API520_round_size', 'API520_C', 'API520_F2', 'API520_Kv', 'API520_N', 'API520_SH', 'API520_B', 'API520_W', 'API520_A_g', 'API520_A_steam']
4.34, 6.38, 11.05, 16.00, 26.00] # square inches
r'''Rounds up the area from an API 520 calculation to an API526 standard valve area. The returned area is always larger or equal to the input area.
Parameters ---------- A : float Minimum discharge area [m^2]
Returns ------- area : float Actual discharge area [m^2]
Notes ----- To obtain the letter designation of an input area, lookup the area with the following:
API526_letters[API526_A.index(area)]
An exception is raised if the required relief area is larger than any of the API 526 sizes.
Examples -------- From [1]_, checked with many points on Table 8.
>>> API520_round_size(1E-4) 0.00012645136 >>> API526_letters[API526_A.index(API520_round_size(1E-4))] 'E'
References ---------- .. [1] API Standard 526. '''
r'''Calculates coefficient C for use in API 520 critical flow relief valve sizing.
.. math:: C = 0.03948\sqrt{k\left(\frac{2}{k+1}\right)^\frac{k+1}{k-1}}
Parameters ---------- k : float Isentropic coefficient or ideal gas heat capacity ratio [-]
Returns ------- C : float Coefficient `C` [-]
Notes ----- If C cannot be established, assume a coefficient of 0.0239, the highest value possible for C.
Although not dimensional, C varies with the units used.
If k is exactly equal to 1, the expression is undefined, and the formula must be simplified as follows from an application of L'Hopital's rule.
.. math:: C = 0.03948\sqrt{\frac{1}{e}}
Examples -------- From [1]_, checked with many points on Table 8.
>>> API520_C(1.35) 0.02669419967057233
References ---------- .. [1] API Standard 520, Part 1 - Sizing and Selection. ''' else:
r'''Calculates coefficient F2 for subcritical flow for use in API 520 subcritical flow relief valve sizing.
.. math:: F_2 = \sqrt{\left(\frac{k}{k-1}\right)r^\frac{2}{k} \left[\frac{1-r^\frac{k-1}{k}}{1-r}\right]}
r = \frac{P_2}{P_1}
Parameters ---------- k : float Isentropic coefficient or ideal gas heat capacity ratio [-] P1 : float Upstream relieving pressure; the set pressure plus the allowable overpressure, plus atmospheric pressure, [Pa] P2 : float Built-up backpressure; the increase in pressure during flow at the outlet of a pressure-relief device after it opens, [Pa]
Returns ------- F2 : float Subcritical flow coefficient `F2` [-]
Notes ----- F2 is completely dimensionless.
Examples -------- From [1]_ example 2, matches.
>>> API520_F2(1.8, 1E6, 7E5) 0.8600724121105563
References ---------- .. [1] API Standard 520, Part 1 - Sizing and Selection. '''
r'''Calculates correction due to viscosity for liquid flow for use in API 520 relief valve sizing.
.. math:: K_v = \left(0.9935 + \frac{2.878}{Re^{0.5}} + \frac{342.75} {Re^{1.5}}\right)^{-1}
Parameters ---------- Re : float Reynolds number for flow out the valve [-]
Returns ------- Kv : float Correction due to viscosity [-]
Notes ----- Reynolds number in the standard is defined as follows, with Q in L/min, G1 as specific gravity, mu in centipoise, and area in mm^2:
.. math:: Re = \frac{Q(18800G_1)}{\mu \sqrt{A}}
It is unclear how this expression was derived with a constant of 18800; the following code demonstrates what the constant should be:
>>> from scipy.constants import * >>> liter/minute*1000./(0.001*(milli**2)**0.5) 16666.666666666668
Examples -------- From [1]_, checked with example 5.
>>> API520_Kv(100) 0.6157445891444229
References ---------- .. [1] API Standard 520, Part 1 - Sizing and Selection. '''
r'''Calculates correction due to steam pressure for steam flow for use in API 520 relief valve sizing.
.. math:: K_N = \frac{0.02764P_1-1000}{0.03324P_1-1061}
Parameters ---------- P1 : float Upstream relieving pressure; the set pressure plus the allowable overpressure, plus atmospheric pressure, [Pa]
Returns ------- KN : float Correction due to steam temperature [-]
Notes ----- Although not dimensional, KN varies with the units used.
For temperatures above 922 K or 22057 kPa, KN is not defined.
Internally, units of kPa are used to match the equation in the standard.
Examples -------- Custom example:
>>> API520_N(1774700) 0.9490406958152466
References ---------- .. [1] API Standard 520, Part 1 - Sizing and Selection. '''
280, 300, 350, 400, 500, 600, 800, 1000, 1250, 1500, 1750, 2000, 2500, 3000] [1, 0.98, 0.93, 0.88, 0.84, 0.8, 0.77, 0.74, 0.72, 0.7], [1, 0.99, 0.93, 0.88, 0.84, 0.81, 0.77, 0.74, 0.72, 0.7], [1, 0.99, 0.93, 0.88, 0.84, 0.81, 0.77, 0.75, 0.72, 0.7], [1, 0.99, 0.93, 0.88, 0.84, 0.81, 0.77, 0.75, 0.72, 0.7], [1, 0.99, 0.94, 0.89, 0.84, 0.81, 0.77, 0.75, 0.72, 0.7], [1, 0.99, 0.94, 0.89, 0.84, 0.81, 0.78, 0.75, 0.72, 0.7], [1, 0.99, 0.94, 0.89, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7], [1, 0.99, 0.94, 0.89, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7], [1, 0.99, 0.94, 0.89, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7], [1, 0.99, 0.95, 0.89, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7], [1, 0.99, 0.95, 0.89, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7], [1, 1, 0.95, 0.9, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7], [1, 1, 0.95, 0.9, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7], [1, 1, 0.96, 0.9, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7], [1, 1, 0.96, 0.9, 0.85, 0.81, 0.78, 0.75, 0.72, 0.7], [1, 1, 0.96, 0.9, 0.86, 0.82, 0.78, 0.75, 0.72, 0.7], [1, 1, 0.96, 0.91, 0.86, 0.82, 0.78, 0.75, 0.72, 0.7], [1, 1, 0.96, 0.92, 0.86, 0.82, 0.78, 0.75, 0.73, 0.7], [1, 1, 0.97, 0.92, 0.87, 0.82, 0.79, 0.75, 0.73, 0.7], [1, 1, 1, 0.95, 0.88, 0.83, 0.79, 0.76, 0.73, 0.7], [1, 1, 1, 0.96, 0.89, 0.84, 0.78, 0.76, 0.73, 0.71], [1, 1, 1, 0.97, 0.91, 0.85, 0.8, 0.77, 0.74, 0.71], [1, 1, 1, 1, 0.93, 0.86, 0.81, 0.77, 0.74, 0.71], [1, 1, 1, 1, 0.94, 0.86, 0.81, 0.77, 0.73, 0.7], [1, 1, 1, 1, 0.95, 0.86, 0.8, 0.76, 0.72, 0.69], [1, 1, 1, 1, 0.95, 0.85, 0.78, 0.73, 0.69, 0.66], [1, 1, 1, 1, 1, 0.82, 0.74, 0.69, 0.65, 0.62]]
r'''Calculates correction due to steam superheat for steam flow for use in API 520 relief valve sizing. 2D interpolation among a table with 28 pressures and 10 temperatures is performed.
Parameters ---------- T1 : float Temperature of the fluid entering the valve [K] P1 : float Upstream relieving pressure; the set pressure plus the allowable overpressure, plus atmospheric pressure, [Pa]
Returns ------- KSH : float Correction due to steam superheat [-]
Notes ----- For P above 20679 kPag, use the critical flow model. Superheat cannot be above 649 degrees Celcius. If T1 is above 149 degrees Celcius, returns 1.
Examples -------- Custom example from table 9:
>>> API520_SH(593+273.15, 1066.325E3) 0.7201800000000002
References ---------- .. [1] API Standard 520, Part 1 - Sizing and Selection. '''
# Kw, for liquids. Applicable for all overpressures.
r'''Calculates capacity correction due to backpressure on balanced spring-loaded PRVs in liquid service. For pilot operated valves, this is always 1. Applicable up to 50% of the percent gauge backpressure, For use in API 520 relief valve sizing. 1D interpolation among a table with 53 backpressures is performed.
Parameters ---------- Pset : float Set pressure for relief [Pa] Pback : float Backpressure, [Pa]
Returns ------- KW : float Correction due to liquid backpressure [-]
Notes ----- If the calculated gauge backpressure is less than 15%, a value of 1 is returned.
Examples -------- Custom example from figure 31:
>>> API520_W(1E6, 3E5) # 22% overpressure 0.9511471848008564
References ---------- .. [1] API Standard 520, Part 1 - Sizing and Selection. '''
# Kb Backpressure correction factor, for gases
r'''Calculates capacity correction due to backpressure on balanced spring-loaded PRVs in vapor service. For pilot operated valves, this is always 1. Applicable up to 50% of the percent gauge backpressure, For use in API 520 relief valve sizing. 1D interpolation among a table with 53 backpressures is performed.
Parameters ---------- Pset : float Set pressure for relief [Pa] Pback : float Backpressure, [Pa] overpressure : float, optional The maximum fraction overpressure; one of 0.1, 0.16, or 0.21, []
Returns ------- Kb : float Correction due to vapor backpressure [-]
Notes ----- If the calculated gauge backpressure is less than 30%, 38%, or 50% for overpressures of 0.1, 0.16, or 0.21, a value of 1 is returned.
Percent gauge backpressure must be under 50%.
Examples -------- Custom examples from figure 30:
>>> API520_B(1E6, 5E5) 0.7929945420944432
References ---------- .. [1] API Standard 520, Part 1 - Sizing and Selection. ''' overpressure == 0.16 and gauge_backpressure < 38) or ( overpressure == 0.21 and gauge_backpressure < 50):
#print [API520_B(1E6, 3E5), API520_B(1E6, 5E5), API520_B(1E6, 5E5, overpressure=.16), API520_B(1E6, 5E5, overpressure=.21)]
r'''Calculates required relief valve area for an API 520 valve passing a gas or a vapor, at either critical or sub-critical flow.
For Critical flow:
.. math:: A = \frac{m}{CK_dP_1K_bK_c}\sqrt{\frac{TZ}{M}}
For sub-critical flow:
.. math:: A = \frac{17.9m}{F_2K_dK_c}\sqrt{\frac{TZ}{MP_1(P_1-P_2)}}
Parameters ---------- m : float Mass flow rate of vapor through the valve, [kg/s] T : float Temperature of vapor entering the valve, [K] Z : float Compressibility factor of the vapor, [-] MW : float Molecular weight of the vapor, [g/mol] k : float Isentropic coefficient or ideal gas heat capacity ratio [-] P1 : float Upstream relieving pressure; the set pressure plus the allowable overpressure, plus atmospheric pressure, [Pa] P2 : float, optional Built-up backpressure; the increase in pressure during flow at the outlet of a pressure-relief device after it opens, [Pa] Kd : float, optional The effective coefficient of discharge, from the manufacturer or for preliminary sizing, using 0.975 normally or 0.62 when used with a rupture disc as described in [1]_, [] Kb : float, optional Correction due to vapor backpressure [-] Kc : float, optional Combination correction factor for installation with a ruture disk upstream of the PRV, []
Returns ------- A : float Minimum area for relief valve according to [1]_, [m^2]
Notes ----- Units are interlally kg/hr, kPa, and mm^2 to match [1]_.
Examples -------- Example 1 from [1]_ for critical flow, matches:
>>> API520_A_g(m=24270/3600., T=348., Z=0.90, MW=51., k=1.11, P1=670E3, Kb=1, Kc=1) 0.0036990460646834414
Example 2 from [2]_ for sub-critical flow, matches:
>>> API520_A_g(m=24270/3600., T=348., Z=0.90, MW=51., k=1.11, P1=670E3, P2=532E3, Kd=0.975, Kb=1, Kc=1) 0.004248358775943481
References ---------- .. [1] API Standard 520, Part 1 - Sizing and Selection. ''' else:
#print [API520_A_g(m=24270/3600., T=348., Z=0.90, MW=51., k=1.11, P1=670E3, Kb=1, Kc=1)] #print [API520_A_g(m=24270/3600., T=348., Z=0.90, MW=51., k=1.11, P1=670E3, P2=532E3, Kd=0.975, Kb=1, Kc=1)]
r'''Calculates required relief valve area for an API 520 valve passing a steam, at either saturation or superheat but not partially condensed.
.. math:: A = \frac{190.5m}{P_1 K_d K_b K_c K_N K_{SH}}
Parameters ---------- m : float Mass flow rate of steam through the valve, [kg/s] T : float Temperature of steam entering the valve, [K] P1 : float Upstream relieving pressure; the set pressure plus the allowable overpressure, plus atmospheric pressure, [Pa] Kd : float, optional The effective coefficient of discharge, from the manufacturer or for preliminary sizing, using 0.975 normally or 0.62 when used with a rupture disc as described in [1]_, [] Kb : float, optional Correction due to vapor backpressure [-] Kc : float, optional Combination correction factor for installation with a ruture disk upstream of the PRV, []
Returns ------- A : float Minimum area for relief valve according to [1]_, [m^2]
Notes ----- Units are interlally kg/hr, kPa, and mm^2 to match [1]_. With the provided temperature and pressure, the KN coefficient is calculated with the function API520_N; as is the superheat correction KSH, with the function API520_SH.
Examples -------- Example 4 from [1]_, matches:
>>> API520_A_steam(m=69615/3600., T=592.5, P1=12236E3, Kd=0.975, Kb=1, Kc=1) 0.0011034712423692733
References ---------- .. [1] API Standard 520, Part 1 - Sizing and Selection. '''
#print [API520_A_steam(m=69615/3600., T=592.5, P1=12236E3, Kd=0.975, Kb=1, Kc=1)] |