-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxfoil_runner.py
More file actions
114 lines (93 loc) · 3.59 KB
/
xfoil_runner.py
File metadata and controls
114 lines (93 loc) · 3.59 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import multiprocessing
import os
import signal
import time
import wexpect
from config import xfoil_path, step_size, smaller_step_size, XFOIL_C, MDES_C, POLAR_DUMP_P, POLAR_SAVE_P, ALFA_P, \
batch_count, OPER_C
from util import parsed_file_path, seq, parsed_newpolar_file_path, get_unprocessed_files, chunk_it
def load_file(xfoil, parsed_file, foil_name):
xfoil.expect(XFOIL_C)
xfoil.sendline('LOAD ' + parsed_file_path(parsed_file))
xfoil.expect(XFOIL_C)
xfoil.sendline('MDES')
if xfoil.expect([MDES_C, wexpect.EOF, wexpect.TIMEOUT], timeout=120) != 0:
return False
xfoil.sendline('FILT')
xfoil.expect(MDES_C)
xfoil.sendline('EXEC')
xfoil.expect(MDES_C)
xfoil.sendline('')
xfoil.expect(XFOIL_C)
xfoil.sendline('PANE')
xfoil.expect(XFOIL_C)
xfoil.sendline('OPER')
xfoil.expect(OPER_C)
xfoil.sendline('ITER 500')
xfoil.expect(OPER_C)
xfoil.sendline('RE 50000')
xfoil.expect(OPER_C)
xfoil.sendline('VISC 50000')
xfoil.expect(OPER_C)
xfoil.sendline('PACC')
xfoil.expect(POLAR_SAVE_P)
xfoil.sendline(parsed_newpolar_file_path(foil_name))
xfoil.expect(POLAR_DUMP_P)
xfoil.sendline('')
xfoil.expect(OPER_C)
return True
def reset(xfoil):
xfoil.sendline('')
def change_alpha(xfoil, alpha):
xfoil.sendline('ALFA ' + str(alpha))
try:
return xfoil.expect(ALFA_P, timeout=120)
except wexpect.wexpect_util.TIMEOUT:
print('timeout for alpha : ' + str(alpha))
return 1
def run_xfoil(parsed_files):
xfoil = wexpect.spawn(xfoil_path, encoding='utf-8')
with open('processed.txt', 'a') as processed:
with open('unprocessed.txt', 'a') as unprocessed:
for parsed_file in parsed_files:
start = time.time()
foil_name = parsed_file.split('.')[0]
if load_file(xfoil, parsed_file, foil_name):
for alpha in seq(0, 20, step_size):
if change_alpha(xfoil, alpha) == 0:
for smaller_alpha in seq(alpha - 0.25, alpha, smaller_step_size):
change_alpha(xfoil, smaller_alpha)
for alpha in seq(0, -20, -step_size):
if change_alpha(xfoil, alpha) == 0:
for smaller_alpha in seq(alpha + 0.25, alpha, -smaller_step_size):
change_alpha(xfoil, smaller_alpha)
else:
xfoil.kill(signal.SIGINT)
xfoil = wexpect.spawn(xfoil_path, encoding='utf-8')
end = time.time()
print(str(os.getpid()) + ': File was unprocessed ' + parsed_file + ' took ' + str(end - start))
unprocessed.write(parsed_file + '\n')
unprocessed.flush()
continue
reset(xfoil)
end = time.time()
print(str(os.getpid()) + ': File ' + parsed_file + ' took ' + str(end - start))
processed.write(parsed_file + '\n')
processed.flush()
def make_processes():
parsed_files = get_unprocessed_files()
batches = chunk_it(parsed_files, batch_count)
processes = []
# creating processes
for batch in batches:
processes.append(multiprocessing.Process(target=run_xfoil, args=(batch,)))
# starting process
for process in processes:
process.start()
# wait until process is finished
for process in processes:
process.join()
# all processes finished
print("Done!")
if __name__ == '__main__':
make_processes()