-
Notifications
You must be signed in to change notification settings - Fork 2
/
plotdraw.py
executable file
·158 lines (145 loc) · 4.91 KB
/
plotdraw.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python3
import matplotlib.pyplot as pyplot
import numpy, sys
wake_iterations = 3
TYPE = None
with open(sys.argv[1]) as f:
if '.history' in sys.argv[1]:
TYPE = 'history'
data_order = ['Mach', 'AoA', 'beta', 'CL', 'CDo', 'CDi', 'CDtot', 'CS',
'L/D', 'E', 'CFx', 'CFz', 'CFy', 'CMx', 'CMy', 'CMz', 'T/QS']
data = {'Mach': [], 'AoA': [], 'beta': [], 'CL': [], 'CDo': [], 'CDi': [],
'CDtot': [], 'CS': [],'L/D': [], 'E': [], 'CFx': [], 'CFz': [],
'CFy': [], 'CMx': [], 'CMy': [], 'CMz': [], 'T/QS': []}
X = 'AoA'
Y = 'CL'
elif '.lod' in sys.argv[1]:
TYPE = 'lod'
# data_order = ['wing', 'yavg', 'chord', 'Cl', 'Cd', 'Cs', 'compname',
# 'Mach', 'AoA', 'beta', 'CL', 'CD', 'CS',
# 'CFx', 'CFy', 'CFz', 'CMx', 'CMy', 'CMz']
data_order = ['wing', 'S', 'yavg', 'chord', 'v/vref',
'Cl', 'Cd', 'Cs', 'compname', 'Mach', 'AoA', 'beta',
'Cx', 'Cy', 'Cz', 'CMx', 'CMy', 'CMz']
data = {'wing': [], 'S': [], 'yavg': [], 'chord': [], 'v/vref': [],
'Cl': [], 'Cd': [], 'Cs': [], 'compname': [], 'Mach': [], 'AoA': [], 'beta': [],
'Cx': [], 'Cy': [], 'Cz': [], 'CMx': [], 'CMy': [], 'CMz': []}
X = 'yavg'
Y = 'Cl'
else:
print('Incorrect filetype')
exit()
input_txt = f.readlines()
db = []
AOA = None
MACH = None
BETA = None
WING = None
HEADLESS = False
for arg in sys.argv:
if arg.startswith('-x'):
X = arg[2:]
elif arg.startswith('-y'):
Y = arg[2:]
elif arg.startswith('-a'):
AOA = float(arg[2:])
elif arg.startswith('-m'):
MACH = float(arg[2:])
elif arg.startswith('-b'):
BETA = float(arg[2:])
elif arg.startswith('-w'):
WING = float(arg[2:])
elif arg == '-h':
HEADLESS = True
def getdata(line):
while ' ' in line:
line = line.replace(' ', ' ')
line = line.split(' ')
line2 = []
for l in line:
if l != '':
line2.append(l)
return line2
if TYPE == 'history':
for i in range(len(input_txt)):
if input_txt[i].startswith('Solver Case:'):
l = i + 2 + wake_iterations
t = input_txt[l].split(' ')
while '' in t:
t.remove('')
t.remove(t[0])
t[len(t) - 1] = t[len(t) - 1][:-1]
dataset = {}
for n in range(0, len(t)):
data_name = data_order[n]
dataset[data_name] = t[n]
db.append(dataset)
else:
collect_w = False
collect_c = False
for l in input_txt:
if l == '\n':
collect_w = False
collect_c = False
elif collect_w:
dataset = {}
for n in range(len(getdata(l[:-2]))):
dataset[data_order[n]] = getdata(l)[n]
db.append(dataset)
elif l.startswith(' Wing'):
collect_w = True
elif l.startswith('Comp'):
collect_c = True
for d in db:
for k in d.keys():
data[k].append(float(d[k]))
if TYPE == 'history':
cases = {'AoA': [AOA, None], 'beta': [BETA, None], 'Mach': [MACH, None]}
elif TYPE == 'lod':
cases = {'AoA': [AOA, None], 'beta': [BETA, None], 'Mach': [MACH, None], 'wing': [WING, None]}
def dataformater(inp, name):
arr = set([a for a in data[name]])
if inp is not None:
arr = set([inp])
return arr
for c in cases.keys():
cases[c][1] = dataformater(cases[c][0], c)
def plotter(first, second, name1, name2):
for f in first:
for s in second:
xres = []
yres = []
for i in range(len(data[X])):
try:
if data[name2][i] == s or second == ['']:
two_is_good = True
else:
two_is_good = False
except KeyError:
two_is_good = True
if data[name1][i] == f and two_is_good:
yres.append(data[Y][i])
xres.append(data[X][i])
if yres != []:
if second == [''] or len(second) == 1:
pyplot.plot(xres, yres, label=name1 + '=' + str(f))
else:
pyplot.plot(xres, yres, label=name1 + '=' + str(f) + ' ' + name2 + '=' + str(s))
if HEADLESS:
print(str(xres) + ', ' + str(yres))
if second is ['']:
break
if X == 'AoA':
plotter(cases['Mach'][1], cases['beta'][1], 'Mach', 'beta')
elif X == 'Mach':
plotter(cases['AoA'][1], cases['beta'][1], 'AoA', 'beta')
elif X == 'beta':
plotter(cases['AoA'][1], cases['Mach'][1], 'AoA', 'Mach')
elif TYPE == 'lod':
print('lod')
plotter(cases['wing'][1], [''], 'wing', '')
pyplot.xlabel(X)
pyplot.ylabel(Y)
pyplot.legend()
if not HEADLESS:
pyplot.show()