# Decompression Scenarios

May 3rd, 2017
1,406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from math import *
2.
3.
4. #Calculation script for decompression scenarios.  See:
7.
8.
9. #Physics parameters
10. #"μ" is the gas's molar mass: 0.02897 kg mol⁻¹ (unused)
11. #"R" is the gas constant: 8.3144598 J mol⁻¹ K⁻¹ (unused)
12. v_a = 343.15
13.
14. #Human parameters
15. A = 0.7
16. C_D = 1.2
17. m = 65.57
18.
19. #Chamber parameters
20. diameter_chamber = 2.0
21. diameter_hole = 0.1 #2.0
22. h = pi * (diameter_hole*0.5)**2.0
23. H = h / (pi * (diameter_chamber*0.5)**2.0)
24. rho_0 = 1.225
25. T = 273.15 + 20.0
26. V = 30.0
27.
28. #Want to calculate (as applicable)
29. #f(t)
30. #v(t)
31. #a(t)
32. #M(t)
33. #rho(t)
34. #delta-v
35.
36.
37.
38. #Scenario 1:
39. def f(t):
40.     c = (rho_0 * C_D * A) / (2.0 * m)
41.     return m * c / (( c*t + 1.0/v_a )**2.0)
42. def v(t):
43.     c = (rho_0 * C_D * A) / (2.0 * m)
44.     return (c * v_a * t) / (c*t + 1.0/v_a)
45. def a(t):
46.     c = (rho_0 * C_D * A) / (2.0 * m)
47.     result = c / (( c*t + 1.0/v_a )**2.0)
48.     return result, result/9.80665
49. ##print(f(0))
50. ##print(v(0))
51. ##print(a(0))
52. ##print()
53. ##print(f(1))
54. ##print(v(1))
55. ##print(a(1))
56.
57.
58.
59. #Scenario 2 (be sure to set "h" correctly):
60. def f(t):
61.     c = (rho_0 * C_D * A) / (2.0 * m)
62.     return m * c / (( c*t + 1.0/(v_a*H) )**2.0)
63. def v(t):
64.     c = (rho_0 * C_D * A) / (2.0 * m)
65.     return (c * v_a*H * t) / (c*t + 1.0/(v_a*H))
66. def a(t):
67.     c = (rho_0 * C_D * A) / (2.0 * m)
68.     result = c / (( c*t + 1.0/(v_a*H) )**2.0)
69.     return result, result/9.80665
70. ##print(f(0))
71. ##print(v(0))
72. ##print(a(0))
73. ##print()
74. ##print(f(1))
75. ##print(v(1))
76. ##print(a(1))
77.
78.
79.
80. #Scenario 3 (be sure to set "h" correctly):
81. def f(t):
82.     a = (rho_0 * C_D * A) / (2.0 * m)
83.     b = -h * v_a / V
84.     return m * (a * exp(b*t)) / (( (a/b)*(exp(b*t)-1.0) + 1.0/v_a )**2.0)
85. def v(t):
86.     a = (rho_0 * C_D * A) / (2.0 * m)
87.     b = -h * v_a / V
88.     return v_a - ( (a/b)*(exp(b*t)-1.0) + 1.0/v_a )**-1.0
89. def a(t):
90.     a = (rho_0 * C_D * A) / (2.0 * m)
91.     b = -h * v_a / V
92.     result = (a * exp(b*t)) / (( (a/b)*(exp(b*t)-1.0) + 1.0/v_a )**2.0)
93.     return result, result/9.80665
94. def M(t):
95.     b = -h * v_a / V
96.     return V * rho_0 * exp(b * t)
97. def rho(t):
98.     b = -h * v_a / V
99.     return rho_0 * exp(b * t)
100. def delta_v():
101.     a = (rho_0 * C_D * A) / (2.0 * m)
102.     b = -h * v_a / V
103.     return v_a - ( 1.0/v_a - a/b )**-1.0
104. ##print(f(0))
105. ##print(v(0))
106. ##print(a(0))
107. ##print(M(0))
108. ##print(rho(0))
109. ##print()
110. ##print(f(1))
111. ##print(v(1))
112. ##print(a(1))
113. ##print(M(1))
114. ##print(rho(1))
115. ##print()
116. ##print(delta_v())
117. ##t=0.0; step=0.001 #ad-hoc binary search to find time for various ratios (0.99 below)
118. ##r = v(0.0)/delta_v()
119. ##while step>1e-9:
120. ##    t += step
121. ##    r = v(t)/delta_v()
122. ##    if r >= 0.99:
123. ##        t -= step
124. ##        step *= 0.5
125. ##print((t,r))
126.
127.
128.
129. #Scenario 4 (be sure to set "h" correctly):
130. def f(t):
131.     a = (rho_0 * C_D * A) / (2.0 * m)
132.     b = -h * v_a / V
133.     return m * (a * exp(b*t)) / (( (a/b)*(exp(b*t)-1.0) + 1.0/(H*v_a) )**2.0)
134. def v(t):
135.     a = (rho_0 * C_D * A) / (2.0 * m)
136.     b = -h * v_a / V
137.     return (H*v_a) - ( (a/b)*(exp(b*t)-1.0) + 1.0/(H*v_a) )**-1.0
138. def a(t):
139.     a = (rho_0 * C_D * A) / (2.0 * m)
140.     b = -h * v_a / V
141.     result = (a * exp(b*t)) / (( (a/b)*(exp(b*t)-1.0) + 1.0/(H*v_a) )**2.0)
142.     return result, result/9.80665
143. def M(t):
144.     b = -h * v_a / V
145.     return V * rho_0 * exp(b * t)
146. def rho(t):
147.     b = -h * v_a / V
148.     return rho_0 * exp(b * t)
149. def delta_v():
150.     a = (rho_0 * C_D * A) / (2.0 * m)
151.     b = -h * v_a / V
152.     return (H*v_a) - ( 1.0/(H*v_a) - a/b )**-1.0
153. ##print(f(0))
154. ##print(v(0))
155. ##print(a(0))
156. ##print(M(0))
157. ##print(rho(0))
158. ##print()
159. ##print(f(1))
160. ##print(v(1))
161. ##print(a(1))
162. ##print(M(1))
163. ##print(rho(1))
164. ##print()
165. ##print(delta_v())