-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmach.py
35 lines (26 loc) · 865 Bytes
/
mach.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
import math
pi = math.pi
uni_gas_const = uni_gas_const = 8.314472 # m2 kg s-2 K-1 mol-1
# this is for the supersoinc region of a nozzle
# do not use this for subsonic region as is
def calc_mach_num(A_ratio, gamma):
gp1 = gamma + 1
gm1 = gamma - 1
arat = A_ratio
aro = 2
macho = 2.2
fac1 = gp1/(2*gm1)
machn = macho + 0.05
while abs(A_ratio - aro) > .0001:
fac = 1 + 0.5 * gm1 * machn**2
arn = 1/(machn * fac**(-fac1) * (gp1/2)**fac1)
try:
deriv = (arn-aro)/(machn-macho)
except ZeroDivisionError:
print("\nFATAL: ZeroDivisionError in Mach number code. Try increasing area ratio.")
input("Press Enter to quit...")
quit()
aro = arn
macho = machn
machn = macho + (arat - aro)/deriv
return macho