Coverage for /home/caleb/Documents/University/CHE2703/fluids/fluids/geometry.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.'''
'V_horiz_conical', 'V_horiz_ellipsoidal', 'V_horiz_guppy', 'V_horiz_spherical', 'V_horiz_torispherical', 'V_vertical_conical', 'V_vertical_ellipsoidal', 'V_vertical_spherical', 'V_vertical_torispherical', 'V_vertical_conical_concave', 'V_vertical_ellipsoidal_concave', 'V_vertical_spherical_concave', 'V_vertical_torispherical_concave', 'a_torispherical', 'SA_ellipsoidal_head', 'SA_conical_head', 'SA_guppy_head', 'SA_torispheroidal', 'V_from_h', 'SA_tank', 'sphericity', 'aspect_ratio', 'circularity', 'A_cylinder', 'V_cylinder', 'A_hollow_cylinder', 'V_hollow_cylinder', 'A_multiple_hole_cylinder', 'V_multiple_hole_cylinder']
### Spherical Vessels, partially filled
r'''Calculates surface area of a partial sphere according to [1]_. If h is half of D, the shape is half a sphere. No bottom is considered in this function. Valid inputs are positive values of D and h, with h always smaller or equal to D.
.. math:: a = \sqrt{h(2r - h)}
A = \pi(a^2 + h^2)
Parameters ---------- D : float Diameter of the sphere, [m] h : float Height, as measured from the cap to where the sphere is cut off [m]
Returns ------- SA : float Surface area [m^2]
Examples -------- >>> SA_partial_sphere(1., 0.7) 2.199114857512855
References ---------- .. [1] Weisstein, Eric W. "Spherical Cap." Text. Accessed December 22, 2015. http://mathworld.wolfram.com/SphericalCap.html.'''
r'''Calculates volume of a partial sphere according to [1]_. If h is half of D, the shape is half a sphere. No bottom is considered in this function. Valid inputs are positive values of D and h, with h always smaller or equal to D.
.. math:: a = \sqrt{h(2r - h)}
V = 1/6 \pi h(3a^2 + h^2)
Parameters ---------- D : float Diameter of the sphere, [m] h : float Height, as measured up to where the sphere is cut off, [m]
Returns ------- V : float Volume [m^3]
Examples -------- >>> V_partial_sphere(1., 0.7) 0.4105014400690663
References ---------- .. [1] Weisstein, Eric W. "Spherical Cap." Text. Accessed December 22, 2015. http://mathworld.wolfram.com/SphericalCap.html.'''
#def V_horizontal_bullet(D, L, H, b=None): # # As in GPSA # if not b: # b = 0.25*D # elliptical 2:1 heads # Ze = H/D # Zc = H/D # K1 = 2*b/D # alpha = 2*atan(H/sqrt(2*H*D/2 - H**2)) # fZc = (alpha - sin(alpha)*cos(alpha))/pi # fZe = -H**2/D**2*(-3 + 2*H/D) # V = 1/6.*pi*K1*D**3*fZe + 1/4.*pi*D**2*L*fZc # return V
#print(V_horizontal_bullet(1., 5., .4999999999999, 0.000000000000000001))
#def V_vertical_bullet(D, L, H, b=None): # K1 = 2*b/D # Ze = (H1 + H2)/K1*D # is divided by D? # fZe = -((H1 + H2)) # # V = 1/6.*pi*K1*D**3*fZe + 1/4.*pi*D**2*L*fZc # return V
### Functions as developed by Dan Jones
r'''Calculates volume of a tank with conical ends, according to [1]_.
.. math:: V_f = A_fL + \frac{2aR^2}{3}K, \;\;0 \le h < R\\
V_f = A_fL + \frac{2aR^2}{3}\pi/2,\;\; h = R\\
V_f = A_fL + \frac{2aR^2}{3}(\pi-K), \;\; R< h \le 2R
K = \cos^{-1} M + M^3\cosh^{-1} \frac{1}{M} - 2M\sqrt{1 - M^2}
M = \left|\frac{R-h}{R}\right|
Af = R^2\cos^{-1}\frac{R-h}{R} - (R-h)\sqrt{2Rh - h^2}
Parameters ---------- D : float Diameter of the main cylindrical section, [m] L : float Length of the main cylindrical section, [m] a : float Distance the cone head extends on one side, [m] h : float Height, as measured up to where the fluid ends, [m] headonly : bool, optional Function returns only the volume of a single head side if True
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_horiz_conical(D=108., L=156., a=42., h=36)/231 2041.1923581273443
References ---------- .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015. http://www.webcalc.com.br/blog/Tank_Volume.PDF''' else: else:
r'''Calculates volume of a tank with ellipsoidal ends, according to [1]_.
.. math:: V_f = A_fL + \pi a h^2\left(1 - \frac{h}{3R}\right)
Af = R^2\cos^{-1}\frac{R-h}{R} - (R-h)\sqrt{2Rh - h^2}
Parameters ---------- D : float Diameter of the main cylindrical section, [m] L : float Length of the main cylindrical section, [m] a : float Distance the ellipsoidal head extends on one side, [m] h : float Height, as measured up to where the fluid ends, [m] headonly : bool, optional Function returns only the volume of a single head side if True
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_horiz_ellipsoidal(D=108, L=156, a=42, h=36)/231. 2380.9565415578145
References ---------- .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015. http://www.webcalc.com.br/blog/Tank_Volume.PDF''' else:
r'''Calculates volume of a tank with guppy heads, according to [1]_.
.. math:: V_f = A_fL + \frac{2aR^2}{3}\cos^{-1}\left(1 - \frac{h}{R}\right) +\frac{2a}{9R}\sqrt{2Rh - h^2}(2h-3R)(h+R)
Af = R^2\cos^{-1}\frac{R-h}{R} - (R-h)\sqrt{2Rh - h^2}
Parameters ---------- D : float Diameter of the main cylindrical section, [m] L : float Length of the main cylindrical section, [m] a : float Distance the guppy head extends on one side, [m] h : float Height, as measured up to where the fluid ends, [m] headonly : bool, optional Function returns only the volume of a single head side if True
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_horiz_guppy(D=108., L=156., a=42., h=36)/231. 1931.7208029476762
References ---------- .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015. http://www.webcalc.com.br/blog/Tank_Volume.PDF''' else:
r'''Calculates volume of a tank with spherical heads, according to [1]_.
.. math:: V_f = A_fL + \frac{\pi a}{6}(3R^2 + a^2),\;\; h = R, |a|\le R
V_f = A_fL + \frac{\pi a}{3}(3R^2 + a^2),\;\; h = D, |a|\le R
V_f = A_fL + \pi a h^2\left(1 - \frac{h}{3R}\right),\;\; h = 0, \text{ or } |a| = 0, R, -R
V_f = A_fL + \frac{a}{|a|}\left\{\frac{2r^3}{3}\left[\cos^{-1} \frac{R^2 - rw}{R(w-r)} + \cos^{-1}\frac{R^2 + rw}{R(w+r)} - \frac{z}{r}\left(2 + \left(\frac{R}{r}\right)^2\right) \cos^{-1}\frac{w}{R}\right] - 2\left(wr^2 - \frac{w^3}{3}\right) \tan^{-1}\frac{y}{z} + \frac{4wyz}{3}\right\} ,\;\; h \ne R, D; a \ne 0, R, -R, |a| \ge 0.01D
V_f = A_fL + \frac{a}{|a|}\left[2\int_w^R(r^2 - x^2)\tan^{-1} \sqrt{\frac{R^2-x^2}{r^2-R^2}}dx - A_f z\right] ,\;\; h \ne R, D; a \ne 0, R, -R, |a| < 0.01D
Af = R^2\cos^{-1}\frac{R-h}{R} - (R-h)\sqrt{2Rh - h^2}
r = \frac{a^2 + R^2}{2|a|}
w = R - h
y = \sqrt{2Rh-h^2}
z = \sqrt{r^2 - R^2}
Parameters ---------- D : float Diameter of the main cylindrical section, [m] L : float Length of the main cylindrical section, [m] a : float Distance the spherical head extends on one side, [m] h : float Height, as measured up to where the fluid ends, [m] headonly : bool, optional Function returns only the volume of a single head side if True
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_horiz_spherical(D=108., L=156., a=42., h=36)/231. 2303.9615116986183
References ---------- .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015. http://www.webcalc.com.br/blog/Tank_Volume.PDF'''
2*r**3/3.*(acos((R**2 - r*w)/(R*(w-r))) + acos((R**2+r*w)/(R*(w+r))) - z/r*(2+(R/r)**2)*acos(w/R)) - 2*(w*r**2 - w**3/3)*atan(y/z) + 4*w*y*z/3) else: else:
r'''Calculates volume of a tank with torispherical heads, according to [1]_.
.. math:: V_f = A_fL + 2V_1, \;\; 0 \le h \le h_1\\ V_f = A_fL + 2(V_{1,max} + V_2 + V_3), \;\; h_1 < h < h_2\\ V_f = A_fL + 2[2V_{1,max} - V_1(h=D-h) + V_{2,max} + V_{3,max}] , \;\; h_2 \le h \le D
V_1 = \int_0^{\sqrt{2kDh - h^2}} \left[n^2\sin^{-1}\frac{\sqrt {n^2-w^2}}{n} - w\sqrt{n^2-w^2}\right]dx
V_2 = \int_0^{kD\cos\alpha}\left[n^2\left(\cos^{-1}\frac{w}{n} - \cos^{-1}\frac{g}{n}\right) - w\sqrt{n^2 - w^2} + g\sqrt{n^2 - g^2}\right]dx
V_3 = \int_w^g(r^2 - x^2)\tan^{-1}\frac{\sqrt{g^2 - x^2}}{z}dx - \frac{z}{2}\left(g^2\cos^{-1}\frac{w}{g} - w\sqrt{2g(h-h_1) - (h-h_1)^2}\right)
V_{1,max} = v_1(h=h_1)
v_{2,max} = v_2(h=h_2)
v_{3,max} = \frac{\pi a_1}{6}(3g^2 + a_1^2)
a_1 = fD(1-\cos\alpha)
\alpha = \sin^{-1}\frac{1-2k}{2(f-k)}
n = R - kD + \sqrt{k^2D^2-x^2}
g = r\sin\alpha
r = fD
h_2 = D - h_1
w = R - h
z = \sqrt{r^2- g^2}
Parameters ---------- D : float Diameter of the main cylindrical section, [m] L : float Length of the main cylindrical section, [m] f : float Dish-radius parameter; fD = dish radius [] k : float knucle-radius parameter ; kD = knucle radius [] h : float Height, as measured up to where the fluid ends, [m] headonly : bool, optional Function returns only the volume of a single head side if True
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_horiz_torispherical(D=108., L=156., f=1., k=0.06, h=36)/231. 2028.626670842139
References ---------- .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015. http://www.webcalc.com.br/blog/Tank_Volume.PDF'''
else:
else:
### Begin vertical tanks
r'''Calculates volume of a vertical tank with a convex conical bottom, according to [1]_. No provision for the top of the tank is made here.
.. math:: V_f = \frac{\pi}{4}\left(\frac{Dh}{a}\right)^2\left(\frac{h}{3}\right),\; h < a
V_f = \frac{\pi D^2}{4}\left(h - \frac{2a}{3}\right),\; h\ge a
Parameters ---------- D : float Diameter of the main cylindrical section, [m] a : float Distance the cone head extends under the main cylinder, [m] h : float Height, as measured up to where the fluid ends, [m]
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_conical(132., 33., 24)/231. 250.67461381371024
References ---------- .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015. http://www.webcalc.com.br/blog/Tank_Volume.PDF''' else:
r'''Calculates volume of a vertical tank with a convex ellipsoidal bottom, according to [1]_. No provision for the top of the tank is made here.
.. math:: V_f = \frac{\pi}{4}\left(\frac{Dh}{a}\right)^2 \left(a - \frac{h}{3}\right),\; h < a
V_f = \frac{\pi D^2}{4}\left(h - \frac{a}{3}\right),\; h \ge a
Parameters ---------- D : float Diameter of the main cylindrical section, [m] a : float Distance the ellipsoid head extends under the main cylinder, [m] h : float Height, as measured up to where the fluid ends, [m]
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_ellipsoidal(132., 33., 24)/231. 783.3581681678445
References ---------- .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015. http://www.webcalc.com.br/blog/Tank_Volume.PDF''' else:
r'''Calculates volume of a vertical tank with a convex spherical bottom, according to [1]_. No provision for the top of the tank is made here.
.. math:: V_f = \frac{\pi h^2}{4}\left(2a + \frac{D^2}{2a} - \frac{4h}{3}\right),\; h < a
V_f = \frac{\pi}{4}\left(\frac{2a^3}{3} - \frac{aD^2}{2} + hD^2\right),\; h\ge a
Parameters ---------- D : float Diameter of the main cylindrical section, [m] a : float Distance the spherical head extends under the main cylinder, [m] h : float Height, as measured up to where the fluid ends, [m]
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_spherical(132., 33., 24)/231. 583.6018352850442
References ---------- .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015. http://www.webcalc.com.br/blog/Tank_Volume.PDF''' else:
r'''Calculates volume of a vertical tank with a convex torispherical bottom, according to [1]_. No provision for the top of the tank is made here.
.. math:: V_f = \frac{\pi h^2}{4}\left(2a_1 + \frac{D_1^2}{2a_1} - \frac{4h}{3}\right),\; 0 \le h \le a_1
V_f = \frac{\pi}{4}\left(\frac{2a_1^3}{3} + \frac{a_1D_1^2}{2}\right) +\pi u\left[\left(\frac{D}{2}-kD\right)^2 +s\right] + \frac{\pi tu^2}{2} - \frac{\pi u^3}{3} + \pi D(1-2k)\left[ \frac{2u-t}{4}\sqrt{s+tu-u^2} + \frac{t\sqrt{s}}{4} + \frac{k^2D^2}{2}\left(\cos^{-1}\frac{t-2u}{2kD}-\alpha\right)\right] ,\; a_1 < h \le a_1 + a_2
V_f = \frac{\pi}{4}\left(\frac{2a_1^3}{3} + \frac{a_1D_1^2}{2}\right) +\frac{\pi t}{2}\left[\left(\frac{D}{2}-kD\right)^2 +s\right] +\frac{\pi t^3}{12} + \pi D(1-2k)\left[\frac{t\sqrt{s}}{4} + \frac{k^2D^2}{2}\sin^{-1}(\cos\alpha)\right] + \frac{\pi D^2}{4}[h-(a_1+a_2)] ,\; a_1 + a_2 < h
\alpha = \sin^{-1}\frac{1-2k}{2(f-k)}
a_1 = fD(1-\cos\alpha)
a_2 = kD\cos\alpha
D_1 = 2fD\sin\alpha
s = (kD\sin\alpha)^2
t = 2a_2
u = h - fD(1-\cos\alpha)
Parameters ---------- D : float Diameter of the main cylindrical section, [m] f : float Dish-radius parameter; fD = dish radius [] k : float knucle-radius parameter ; kD = knucle radius [] h : float Height, as measured up to where the fluid ends, [m]
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_torispherical(D=132., f=1.0, k=0.06, h=24)/231. 904.0688283793511
References ---------- .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015. http://www.webcalc.com.br/blog/Tank_Volume.PDF'''
+ pi*t*u**2/2. - pi*u**3/3. + pi*D*(1 - 2*k)*((2*u-t)/4.*(s + t*u - u**2)**0.5 + t*s**0.5/4. + k**2*D**2/2*(acos((t-2*u)/(2*k*D))-alpha))) else: + s) + pi*t**3/12. + pi*D*(1 - 2*k)*(t*s**0.5/4 + k**2*D**2/2*asin(cos(alpha))) + pi*D**2/4*(h - (a1 + a2))
### Begin vertical tanks with concave heads
r'''Calculates volume of a vertical tank with a concave conical bottom, according to [1]_. No provision for the top of the tank is made here.
.. math:: V = \frac{\pi D^2}{12} \left(3h + a - \frac{(a+h)^3}{a^2}\right) ,\;\; 0 \le h < |a|
V = \frac{\pi D^2}{12} (3h + a ),\;\; h \ge |a|
Parameters ---------- D : float Diameter of the main cylindrical section, [m] a : float Negative distance the cone head extends inside the main cylinder, [m] h : float Height, as measured up to where the fluid ends, [m]
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_conical_concave(D=113., a=-33, h=15)/231 251.15825565795188
References ---------- .. [1] Jones, D. "Compute Fluid Volumes in Vertical Tanks." Chemical Processing. December 18, 2003. http://www.chemicalprocessing.com/articles/2003/193/ ''' else:
r'''Calculates volume of a vertical tank with a concave ellipsoidal bottom, according to [1]_. No provision for the top of the tank is made here.
.. math:: V = \frac{\pi D^2}{12} \left(3h + 2a - \frac{(a+h)^2(2a-h)}{a^2}\right) ,\;\; 0 \le h < |a|
V = \frac{\pi D^2}{12} (3h + 2a ),\;\; h \ge |a|
Parameters ---------- D : float Diameter of the main cylindrical section, [m] a : float Negative distance the eppilsoid head extends inside the main cylinder, [m] h : float Height, as measured up to where the fluid ends, [m]
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_ellipsoidal_concave(D=113., a=-33, h=15)/231 44.84968851034856
References ---------- .. [1] Jones, D. "Compute Fluid Volumes in Vertical Tanks." Chemical Processing. December 18, 2003. http://www.chemicalprocessing.com/articles/2003/193/ ''' else:
r'''Calculates volume of a vertical tank with a concave spherical bottom, according to [1]_. No provision for the top of the tank is made here.
.. math:: V = \frac{\pi}{12}\left[3D^2h + \frac{a}{2}(3D^2 + 4a^2) + (a+h)^3 \left(4 - \frac{3D^2 + 12a^2}{2a(a+h)}\right)\right],\;\; 0 \le h < |a|
V = \frac{\pi}{12}\left[3D^2h + \frac{a}{2}(3D^2 + 4a^2) \right] ,\;\; h \ge |a|
Parameters ---------- D : float Diameter of the main cylindrical section, [m] a : float Negative distance the spherical head extends inside the main cylinder, [m] h : float Height, as measured up to where the fluid ends, [m]
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_spherical_concave(D=113., a=-33, h=15)/231 112.81405437348528
References ---------- .. [1] Jones, D. "Compute Fluid Volumes in Vertical Tanks." Chemical Processing. December 18, 2003. http://www.chemicalprocessing.com/articles/2003/193/ ''' else:
r'''Calculates volume of a vertical tank with a concave torispherical bottom, according to [1]_. No provision for the top of the tank is made here.
.. math:: V = \frac{\pi D^2 h}{4} - v_1(h=a_1+a_2) + v_1(h=a_1 + a_2 -h),\; 0 \le h < a_2
V = \frac{\pi D^2 h}{4} - v_1(h=a_1+a_2) + v_2(h=a_1 + a_2 -h),\; a_2 \le h < a_1 + a_2
V = \frac{\pi D^2 h}{4} - v_1(h=a_1+a_2) + 0,\; h \ge a_1 + a_2
v_1 = \frac{\pi}{4}\left(\frac{2a_1^3}{3} + \frac{a_1D_1^2}{2}\right) +\pi u\left[\left(\frac{D}{2}-kD\right)^2 +s\right] + \frac{\pi tu^2}{2} - \frac{\pi u^3}{3} + \pi D(1-2k)\left[ \frac{2u-t}{4}\sqrt{s+tu-u^2} + \frac{t\sqrt{s}}{4} + \frac{k^2D^2}{2}\left(\cos^{-1}\frac{t-2u}{2kD}-\alpha\right)\right]
v_2 = \frac{\pi h^2}{4}\left(2a_1 + \frac{D_1^2}{2a_1} - \frac{4h}{3}\right)
\alpha = \sin^{-1}\frac{1-2k}{2(f-k)}
a_1 = fD(1-\cos\alpha)
a_2 = kD\cos\alpha
D_1 = 2fD\sin\alpha
s = (kD\sin\alpha)^2
t = 2a_2
u = h - fD(1-\cos\alpha)
Parameters ---------- D : float Diameter of the main cylindrical section, [m] f : float Dish-radius parameter; fD = dish radius [] k : float knucle-radius parameter ; kD = knucle radius [] h : float Height, as measured up to where the fluid ends, [m]
Returns ------- V : float Volume [m^3]
Examples -------- Matching example from [1]_, with inputs in inches and volume in gallons.
>>> V_vertical_torispherical_concave(D=113., f=0.71, k=0.081, h=15)/231 103.88569287163769
References ---------- .. [1] Jones, D. "Compute Fluid Volumes in Vertical Tanks." Chemical Processing. December 18, 2003. http://www.chemicalprocessing.com/articles/2003/193/ ''' + k**2*D**2/2.*(acos((t-2*u)/(2*k*D)) -alpha)) else:
### Total surface area of heads, orientation-independent
r'''Calculates the surface area of an ellipsoidal head according to [1]_. Formula below is for the full shape, the result of which is halved. The formula also does not support `D` being larger than `a`; this is ensured by simply swapping the variables if necessary, as geometrically the result is the same. In the equations
.. math:: SA = 2\pi a^2 + \frac{\pi c^2}{e_1}\ln\left(\frac{1+e_1}{1-e_1}\right)
e_1 = \sqrt{1 - \frac{c^2}{a^2}}
Parameters ---------- D : float Diameter of the main cylindrical section, [m] a : float Distance the ellipsoidal head extends, [m]
Returns ------- SA : float Surface area [m^2]
Examples -------- Spherical case
>>> SA_ellipsoidal_head(2, 1) 6.283185307179586
References ---------- .. [1] Weisstein, Eric W. "Spheroid." Text. Accessed March 14, 2016. http://mathworld.wolfram.com/Spheroid.html. '''
r'''Calculates the surface area of a conical head according to [1]_.
.. math:: SA = \frac{\pi D}{2} \sqrt{a^2 + \left(\frac{D}{2}\right)^2}
Parameters ---------- D : float Diameter of the main cylindrical section, [m] a : float Distance the conical head extends, [m]
Returns ------- SA : float Surface area [m^2]
Examples -------- >>> SA_conical_head(2, 1) 4.442882938158366
References ---------- .. [1] Weisstein, Eric W. "Cone." Text. Accessed March 14, 2016. http://mathworld.wolfram.com/Cone.html.'''
r'''Calculates the surface area of a guppy head according to [1]_. Some work was involved in combining formulas for the ellipse of the head, and the conic section on the sides.
.. math:: SA = \frac{\pi D}{4}\sqrt{D^2 + a^2} + \frac{\pi D}{2}a
Parameters ---------- D : float Diameter of the main cylindrical section, [m] a : float Distance the conical head extends, [m]
Returns ------- SA : float Surface area [m^2]
Examples -------- >>> SA_guppy_head(2, 1) 6.654000019110157
References ---------- .. [1] Weisstein, Eric W. "Cone." Text. Accessed March 14, 2016. http://mathworld.wolfram.com/Cone.html.'''
r'''Calculates surface area of a torispherical head according to [1]_. Somewhat involved. Equations are adapted to be used for a full head.
.. math:: SA = S_1 + S_2
S_1 = 2\pi D^2 f_d \alpha
S_2 = 2\pi D^2 f_k\left(\alpha - \alpha_1 + (0.5 - f_k)\left(\sin^{-1} \left(\frac{\alpha-\alpha_2}{f_k}\right) - \sin^{-1}\left(\frac{ \alpha_1-\alpha_2}{f_k}\right)\right)\right)
\alpha_1 = f_d\left(1 - \sqrt{1 - \left(\frac{0.5 - f_k}{f_d-f_k} \right)^2}\right)
\alpha_2 = f_d - \sqrt{f_d^2 - 2f_d f_k + f_k - 0.25}
\alpha = \frac{a}{D_i}
Parameters ---------- D : float Diameter of the main cylindrical section, [m] fd : float Dish-radius parameter = f; fD = dish radius [] fk : float knucle-radius parameter = k; kD = knucle radius []
Returns ------- SA : float Surface area [m^2]
Examples -------- Example from [1]_.
>>> SA_torispheroidal(D=2.54, fd=1.039370079, fk=0.062362205) 6.00394283477063
References ---------- .. [1] Honeywell. "Calculate Surface Areas and Cross-sectional Areas in Vessels with Dished Heads". https://www.honeywellprocess.com/library/marketing/whitepapers/WP-VesselsWithDishedHeads-UniSimDesign.pdf Whitepaper. 2014. '''
sideB_a=0, sideA_f=None, sideA_k=None, sideB_f=None, sideB_k=None, full_output=False): r'''Calculates the surface are of a cylindrical tank with optional heads. In the degenerate case of being provided with only `D` and `L`, provides the surface area of a cylinder.
Parameters ---------- D : float Diameter of the cylindrical section of the tank. L : float Length of the main cylindrical section of the tank. sideA : string, optional The left (or bottom for vertical) head of the tank's type; one of [None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical']. sideB : string, optional The right (or top for vertical) head of the tank's type; one of [None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical']. sideA_a : float, optional The distance the head as specified by sideA extends down or to the left from the main cylindrical section sideB_a : float, optional The distance the head as specified by sideB extends up or to the right from the main cylindrical section sideA_f : float, optional Dish-radius parameter for side A; fD = dish radius [] sideA_k : float, optional knucle-radius parameter for side A; kD = knucle radius [] sideB_f : float, optional Dish-radius parameter for side B; fD = dish radius [] sideB_k : float, optional knucle-radius parameter for side B; kD = knucle radius []
Returns ------- SA : float Surface area of the tank [m^2] areas : tuple, only returned if full_output == True (sideA_SA, sideB_SA, lateral_SA)
Other Parameters ---------------- full_output : bool, optional Returns a tuple of (sideA_SA, sideB_SA, lateral_SA) if True
Examples -------- Cylinder, Spheroid, Long Cones, and spheres. All checked.
>>> SA_tank(D=2, L=2) 18.84955592153876 >>> SA_tank(D=1., L=0, sideA='ellipsoidal', sideA_a=2, sideB='ellipsoidal', ... sideB_a=2) 28.480278854014387 >>> SA_tank(D=1., L=5, sideA='conical', sideA_a=2, sideB='conical', ... sideB_a=2) 22.18452243965656 >>> SA_tank(D=1., L=5, sideA='spherical', sideA_a=0.5, sideB='spherical', ... sideB_a=0.5) 18.84955592153876 ''' # Side A else: # Side B else:
else:
r'''Calculates depth of a torispherical head according to [1]_.
.. math:: a = a_1 + a_2
\alpha = \sin^{-1}\frac{1-2k}{2(f-k)}
a_1 = fD(1-\cos\alpha)
a_2 = kD\cos\alpha
Parameters ---------- D : float Diameter of the main cylindrical section, [m] f : float Dish-radius parameter; fD = dish radius [] k : float knucle-radius parameter ; kD = knucle radius []
Returns ------- a : float Depth of head [m]
Examples -------- Example from [1]_.
>>> a_torispherical(D=96., f=0.9, k=0.2) 25.684268924767125
References ---------- .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015. http://www.webcalc.com.br/blog/Tank_Volume.PDF'''
sideB_a=0, sideA_f=None, sideA_k=None, sideB_f=None, sideB_k=None): r'''Calculates partially full volume of a vertical or horizontal tank with different head types according to [1]_.
Parameters ---------- h : float Heifht of the liquid in the tank D : float Diameter of the cylindrical section of the tank. L : float Length of the main cylindrical section of the tank. horizontal : bool, optional Whether or not the tank is a horizontal or vertical tank sideA : string, optional The left (or bottom for vertical) head of the tank's type; one of [None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical']. sideB : string, optional The right (or top for vertical) head of the tank's type; one of [None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical']. sideA_a : float, optional The distance the head as specified by sideA extends down or to the left from the main cylindrical section sideB_a : float, optional The distance the head as specified by sideB extends up or to the right from the main cylindrical section sideA_f : float, optional Dish-radius parameter for side A; fD = dish radius [] sideA_k : float, optional knucle-radius parameter for side A; kD = knucle radius [] sideB_f : float, optional Dish-radius parameter for side B; fD = dish radius [] sideB_k : float, optional knucle-radius parameter for side B; kD = knucle radius []
Returns ------- V : float Volume up to h [m^3]
Examples -------- >>> V_from_h(h=7, D=1.5, L=5., horizontal=False, sideA='conical', ... sideB='conical', sideA_a=2., sideB_a=1.) 10.013826583317465
References ---------- .. [1] Jones, D. "Compute Fluid Volumes in Vertical Tanks." Chemical Processing. December 18, 2003. http://www.chemicalprocessing.com/articles/2003/193/ ''' # Conical case # Elliosoidal case # Guppy case # Spherical case # Torispherical case else: # Bottom head # Cylindrical section # Top head
'''Class representing tank volumes and levels. All parameters are also attributes.
Parameters ---------- D : float Diameter of the cylindrical section of the tank, [m] L : float Length of the main cylindrical section of the tank, [m] horizontal : bool, optional Whether or not the tank is a horizontal or vertical tank sideA : string, optional The left (or bottom for vertical) head of the tank's type; one of [None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical']. sideB : string, optional The right (or top for vertical) head of the tank's type; one of [None, 'conical', 'ellipsoidal', 'torispherical', 'guppy', 'spherical']. sideA_a : float, optional The distance the head as specified by sideA extends down or to the left from the main cylindrical section sideB_a : float, optional The distance the head as specified by sideB extends up or to the right from the main cylindrical section sideA_f : float, optional Dish-radius parameter for side A; fD = dish radius [] sideA_k : float, optional knucle-radius parameter for side A; kD = knucle radius [] sideB_f : float, optional Dish-radius parameter for side B; fD = dish radius [] sideB_k : float, optional knucle-radius parameter for side B; kD = knucle radius [] L_over_D : float, optional Ratio of length over diameter, used only when D and L are both unspecified but V is, [] V : float, optional Volume of the tank; solved for if specified, using sideA_a_ratio/sideB_a_ratio, sideA, sideB, horizontal, and one of L_over_D, L, or D, [m^3]
Attributes ---------- table : bool Whether or not a table of heights-volumes has been generated h_max : float Height of the tank, [m] V_total : float Total volume of the tank as calculated [m^3] heights : ndarray Array of heights between 0 and h_max, [m] volumes : ndarray Array of volumes calculated from the heights [m^3] A : float Total surface area of the tank A_sideA : float Surface area of sideA A_sideB : float Surface area of sideB A_lateral : float Surface area of the lateral side
Examples -------- Total volume of a tank:
>>> TANK(D=1.2, L=4, horizontal=False).V_total 4.523893421169302
Volume of a tank at a given height:
>>> TANK(D=1.2, L=4, horizontal=False).V_from_h(.5) 0.5654866776461628
Height of liquid for a given volume:
>>> TANK(D=1.2, L=4, horizontal=False).h_from_V(.5) 0.44209706414415373
Surface area of a tank with a conical head:
>>> T1 = TANK(V=10, L_over_D=0.7, sideB='conical', sideB_a=0.5) >>> T1.A, T1.A_sideA, T1.A_sideB, T1.A_lateral (24.94775907657148, 5.118555935958284, 5.497246519930003, 14.331956620683192)
Solving for tank volumes, first horizontal, then vertical:
>>> TANK(D=10., horizontal=True, sideA='conical', sideB='conical', V=500).L 4.699531057009147 >>> TANK(L=4.69953105701, horizontal=True, sideA='conical', sideB='conical', V=500).D 9.999999999999407 >>> TANK(L_over_D=0.469953105701, horizontal=True, sideA='conical', sideB='conical', V=500).L 4.69953105700979
>>> TANK(D=10., horizontal=False, sideA='conical', sideB='conical', V=500).L 4.699531057009147 >>> TANK(L=4.69953105701, horizontal=False, sideA='conical', sideB='conical', V=500).D 9.999999999999407 >>> TANK(L_over_D=0.469953105701, horizontal=False, sideA='conical', sideB='conical', V=500).L 4.699531057009791 '''
def __repr__(self): # pragma: no cover orient = 'Horizontal' if self.horizontal else 'Vertical' if self.sideA is None and self.sideB is None: sides = 'no heads' elif self.sideA == self.sideB: if self.sideA_a == self.sideB_a: sides = self.sideA + (' heads, a=%f m' %(self.sideA_a)) else: sides = self.sideA + ' heads, sideA a=%f m, sideB a=%f m' % (self.sideA_a, self.sideB_a) else: if self.sideA: A = '%s head on sideA with a=%f m' % (self.sideA, self.sideA_a) else: A = 'no head on sideA' if self.sideB: B = ' and %s head on sideB with a=%f m' % (self.sideB, self.sideB_a) else: B = ' and no head on sideB' sides = A + B
return '%s tank, V=%f m^3, D=%f m, L=%f m, %s.' %(orient, self.V_total, self.D, self.L, sides)
sideA=None, sideB=None, sideA_a=0, sideB_a=0, sideA_f=1., sideA_k=0.06, sideB_f=1., sideB_k=0.06, sideA_a_ratio=0.25, sideB_a_ratio=0.25, L_over_D=None, V=None):
else:
# If V is specified and either L or D are known, solve for L, D, L_over_D
'''Set more parameters, after the tank is better defined than in the __init__ function.
Notes ----- Two of D, L, and L_over_D must be known when this function runs. The other one is set from the other two first thing in this function. a_ratio parameters are used to calculate a values for the heads here, if applicable. Radius is calculated here. Maximum tank height is calculated here. V_total is calculated here. ''' # If L and D are known, get L_over_D # Otherwise, if L_over_D and D are provided, get L # Otherwise, if L_over_D and L are provided, get D
# Calculate diameter
# If a_ratio is provided for either heads, use it.
# Calculate a for torispherical heads
# Calculate maximum tank height, h_max else:
# Set maximum height
# Set surface areas D=self.D, L=self.L, sideA=self.sideA, sideB=self.sideB, sideA_a=self.sideA_a, sideB_a=self.sideB_a, sideA_f=self.sideA_f, sideA_k=self.sideA_k, sideB_f=self.sideB_f, sideB_k=self.sideB_k, full_output=True)
r'''Method to calculate the volume of liquid in a fully defined tank given a specified height `h`. `h` must be under the maximum height.
Parameters ---------- h : float Height specified, [m]
Returns ------- V : float Volume of liquid in the tank up to the specified height, [m^3] ''' self.sideA_a, self.sideB_a, self.sideA_f, self.sideA_k, self.sideB_f, self.sideB_k)
r'''Method to calculate the height of liquid in a fully defined tank given a specified volume of liquid in it `V`. `V` must be under the maximum volume. If interpolation table is not yet defined, creates it by calling the method set_table.
Parameters ---------- V : float Volume of liquid in the tank up to the desired height, [m^3]
Returns ------- h : float Height of liquid at which the volume is as desired, [m] '''
r'''Method to set an interpolation table of liquids levels versus volumes in the tank, for a fully defined tank. Normally run by the h_from_V method, this may be run prior to its use with a custom specification. Either the number of points on the table, or the vertical distance between steps may be specified.
Parameters ---------- n : float, optional Number of points in the interpolation table, [-] dx : float, optional Vertical distance between steps in the interpolation table, [m] ''' else:
sideB_a, sideA_f, sideA_k, sideB_f, sideB_k, sideA_a_ratio, sideB_a_ratio): '''Function which uses only the variables given, and the TANK class itself, to determine how far from the desired volume, Vtarget, the volume produced by the specified parameters in a new TANK instance is. Should only be used by solve_tank_for_V method. ''' sideA_a=sideA_a, sideB_a=sideB_a, sideA_f=sideA_f, sideA_k=sideA_k, sideB_f=sideB_f, sideB_k=sideB_k, sideA_a_ratio=sideA_a_ratio, sideB_a_ratio=sideB_a_ratio)
'''Method which is called to solve for tank geometry when a certain volume is specified. Will be called by the __init__ method if V is set.
Notes ----- Raises an error if L and either of sideA_a or sideB_a are specified; these can only be set once D is known. Raises an error if more than one of D, L, or L_over_D are specified. Raises an error if the head ratios are not provided.
Calculates initial guesses assuming no heads are present, and then uses fsolve to determine the correct dimentions for the tank.
Tested, but bugs and limitations are expected here. ''' when solving for V')
# Iterate until L is appropriate # Iterate until D is appropriate else: # Use L_over_D until L and D are appropriate
r'''Class representing a helical coiled tube, as are found in many heated tanks and some small nuclear reactors. All parameters are also attributes.
One set of the following parameters is required; inner tube diameter is optional.
* Tube outer diameter, coil outer diameter, pitch, number of coil turns * Tube outer diameter, coil outer diameter, pitch, height * Tube outer diameter, coil outer diameter, number of coil turns, height
Parameters ---------- Dt : float Outer diameter of the tube wound to make up the helical spiral, [m] Do : float, optional Diameter of the spiral as measured from the center of the coil on one side to the center of the coil on the other side, [m] Do_total : float, optional Diameter of the spiral as measured from one edge of the tube to the other edge; equal to Do + Dt; either `Do` or `Do_total` may be specified and the other will be calculated [m] pitch : float, optional Height change from one coil to the next as measured from the middles of the tube, [m] H : float, optional Height of the spiral, as measured from the middle of the bottom of the tube to the middle of the top of the tube, [m] H_total : float, optional Height of the spiral as measured from one edge of the tube to the other edge; equal to `H_total` + `Dt`; either may be specified and the other will be calculated [m] N : float, optional Number of coil turns; may be specified along with `pitch` instead of specifying `H` or `H_total`, [-] Di : float, optional Inner diameter of the tube; if specified, inside and annulus properties will be calculated, [m]
Attributes ---------- tube_circumference : float Circumference of the tube as measured though its center, not inner or outer edges; :math:`C = \pi D_o`, [m] tube_length : float Length of tube used to make the helical coil; :math:`L = \sqrt{(\pi D_o\cdot N)^2 + H^2}`, [m] surface_area : float Surface area of the outer surface of the helical coil; :math:`A_t = \pi D_t L`, [m^2] inner_surface_area : float Surface area of the inner surface of the helical coil; calculated if `Di` is supplied; :math:`A_{inside} = \pi D_i L`, [m^2] inlet_area : float Area of the inlet to the helical coil; calculated if `Di` is supplied; :math:`A_{inlet} = \frac{\pi}{4} D_i^2`, [m^2] inner_volume : float Volume of the tube as would be filled by a fluid, useful for weight calculations; calculated if `Di` is supplied; :math:`V_{inside} = A_i L`, [m^3] annulus_area : float Area of the annulus (wall of the pipe); calculated if `Di` is supplied; :math:`A_a = \frac{\pi}{4} (D_t^2 - D_i^2)`, [m^2] annulus_volume : float Volume of the annulus (wall of the pipe); calculated if `Di` is supplied, useful for weight calculations; :math:`V_a = A_a L`, [m^3] total_volume : float Total volume occupied by the pipe and the fluid inside it; :math:`V = D_t L`, [m^3] helix_angle : float Angle between the pitch and coil diameter; used in some calculations; :math:`\alpha = \arctan \left(\frac{p_t}{\pi D_o}\right)`, [-] curvature : float Coil curvature, useful in some calculations; :math:`\delta = \frac{D_t}{D_o[1 + 4\pi^2 \tan^2(\alpha)]}`, [-]
Notes ----- `Do` must be larger than `Dt`.
Examples -------- >>> C1 = HelicalCoil(Do=30, H=20, pitch=5, Dt=2) >>> C1.N, C1.tube_length, C1.surface_area (4.0, 377.5212621504738, 2372.0360474917497)
Same coil, with the inputs one would physically measure from the coil, and a specified inlet diameter:
>>> C1 = HelicalCoil(Do_total=32, H_total=22, pitch=5, Dt=2, Di=1.8) >>> C1.N, C1.tube_length, C1.surface_area (4.0, 377.5212621504738, 2372.0360474917497) >>> C1.inner_surface_area, C1.inlet_area, C1.inner_volume, C1.total_volume, C1.annulus_volume (2134.832442742575, 2.5446900494077327, 960.6745992341587, 1186.0180237458749, 225.3434245117162)
References ---------- .. [1] El-Genk, Mohamed S., and Timothy M. Schriener. "A Review and Correlations for Convection Heat Transfer and Pressure Losses in Toroidal and Helically Coiled Tubes." Heat Transfer Engineering 0, no. 0 (June 7, 2016): 1-28. doi:10.1080/01457632.2016.1194693. ''' Do_total=None, Di=None): # H goes from center of tube in bottom of coil to center of tube in top of coil # Do goes from the center of the spiral to the center of the outer tube
#print(pi*self.tube_length*self.Dt) == surface_area #print(self.N*pi*self.Do/cos(self.helix_angle)) # Confirms the length with another formula
r'''Returns the sphericity of a particle of surface area `A` and volume `V`.
.. math:: \Psi = \frac{\text{A of sphere with } V_p } {{A}_p} = \frac{\pi^{\frac{1}{3}}(6V_p)^{\frac{2}{3}}}{A_p}
Parameters ---------- A : float Surface area of particle, [m^2] V : float Volume of particle, [m^3]
Returns ------- Psi : float Sphericity [-]
Examples -------- >>> sphericity(10., 2.) 0.767663317071005
References ---------- .. [1] Rhodes, Martin J., ed. Introduction to Particle Technology. 2E. Chichester, England ; Hoboken, NJ: Wiley, 2008. '''
r'''Returns the aspect ratio of a shape with minimum and maximum dimension, `Dmin` and `Dmax`.
.. math:: A_R = \frac{D_{min}}{D_{max}}
Parameters ---------- Dmin : float Minimum dimension, [m] Dmax : float Maximum dimension, [m]
Returns ------- a_r : float Aspect ratio [-]
Examples -------- >>> aspect_ratio(.2, 2) 0.1 '''
r'''Returns the circularity of a shape with area `A` and perimeter `P`.
.. math:: f_{circ} = \frac {4 \pi A} {P^2}
Parameters ---------- A : float Area of the shape, [m^2] P : float Perimeter of the shape, [m]
Returns ------- f_circ : float Circularity of the shape [-]
Examples -------- >>> circularity(1.5, .1) 1884.9555921538756 '''
r'''Returns the surface area of a cylinder.
.. math:: A = \pi D L + 2\cdot \frac{\pi D^2}{4}
Parameters ---------- D : float Diameter of the cylinder, [m] L : float Length of the cylinder, [m]
Returns ------- A : float Surface area [m]
Examples -------- >>> A_cylinder(0.01, .1) 0.0032986722862692833 '''
r'''Returns the volume of a cylinder.
.. math:: V = \frac{\pi D^2}{4}L
Parameters ---------- D : float Diameter of the cylinder, [m] L : float Length of the cylinder, [m]
Returns ------- V : float Volume [m^3]
Examples -------- >>> V_cylinder(0.01, .1) 7.853981633974484e-06 '''
r'''Returns the surface area of a hollow cylinder.
.. math:: A = \pi D_o L + \pi D_i L + 2\cdot \frac{\pi D_o^2}{4} - 2\cdot \frac{\pi D_i^2}{4}
Parameters ---------- Di : float Diameter of the hollow in the cylinder, [m] Do : float Diameter of the exterior of the cylinder, [m] L : float Length of the cylinder, [m]
Returns ------- A : float Surface area [m]
Examples -------- >>> A_hollow_cylinder(0.005, 0.01, 0.1) 0.004830198704894308 '''
r'''Returns the volume of a hollow cylinder.
.. math:: V = \frac{\pi D_o^2}{4}L - L\frac{\pi D_i^2}{4}
Parameters ---------- Di : float Diameter of the hollow in the cylinder, [m] Do : float Diameter of the exterior of the cylinder, [m] L : float Length of the cylinder, [m]
Returns ------- V : float Volume [m^3]
Examples -------- >>> V_hollow_cylinder(0.005, 0.01, 0.1) 5.890486225480862e-06 '''
r'''Returns the surface area of a cylinder with multiple holes. Calculation will naively return a negative value or other impossible result if the number of cylinders added is physically impossible. Holes may be of different shapes, but must be perpendicular to the axis of the cylinder.
.. math:: A = \pi D_o L + 2\cdot \frac{\pi D_o^2}{4} + \sum_{i}^n \left( \pi D_i L - 2\cdot \frac{\pi D_i^2}{4}\right)
Parameters ---------- Do : float Diameter of the exterior of the cylinder, [m] L : float Length of the cylinder, [m] holes : list List of tuples containing (diameter, count) pairs of descriptions for each of the holes sizes.
Returns ------- A : float Surface area [m]
Examples -------- >>> A_multiple_hole_cylinder(0.01, 0.1, [(0.005, 1)]) 0.004830198704894308 '''
r'''Returns the solid volume of a cylinder with multiple cylindrical holes. Calculation will naively return a negative value or other impossible result if the number of cylinders added is physically impossible.
.. math:: V = \frac{\pi D_o^2}{4}L - L\frac{\pi D_i^2}{4}
Parameters ---------- Do : float Diameter of the exterior of the cylinder, [m] L : float Length of the cylinder, [m] holes : list List of tuples containing (diameter, count) pairs of descriptions for each of the holes sizes.
Returns ------- V : float Volume [m^3]
Examples -------- >>> V_multiple_hole_cylinder(0.01, 0.1, [(0.005, 1)]) 5.890486225480862e-06 '''
|