-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·49 lines (38 loc) · 1.49 KB
/
main.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
#!/usr/bin/python3
import variables
import functions
from scipy import optimize
import os
def main():
variables.init()
os.makedirs('results', exist_ok=True)
functions.plot_nozzle_area()
print("Input pressure:\t\t%f"%variables.pi)
print("Output pressure:\t%f"%variables.po)
pi = variables.pi
po = variables.po
k = variables.k
# find out mach distribution for nozzle without shock
variables.Astar = 1
for i, variables.A in enumerate(variables.vA(variables.x)):
variables.mach_under[i] = optimize.newton(functions.area_mach_relation, 0)
variables.mach_over[i] = optimize.newton(functions.area_mach_relation, 2)
# calculate upper and lower bounds of pressure ratio to reach
# transsonic speed
po_pi_under = (1 + ((k-1)/2)*variables.mach_under[-1]**2)**(-k/(k-1))
po_pi_over = (1 + ((k-1)/2)*variables.mach_over[-1]**2)**(-k/(k-1))
print("Min pressure ratio po/pi for subsonic flow:\n\t%f"%po_pi_under)
print("Max pressure ratio po/pi for flow with shock inside nozzle:\n\t%f"%po_pi_over)
if po/pi > po_pi_under or po/pi < po_pi_over:
print("There is no shock!")
else:
print("Start guessing loops to find shock location..")
mach, p = functions.guessing_method(pi, po, 0.0001, 0.01)
functions.save_as_csv(mach, p)
functions.plot_mach_number_with_shock(mach)
functions.plot_pressure_with_shock(p)
print("Finished guessing loops to find shock location..")
shock_location = functions.find_shock(mach)
print("Shock location:\t\t%s"%shock_location)
if __name__ == "__main__":
main()