-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxfoil.py
144 lines (115 loc) · 3.95 KB
/
xfoil.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
# -*- coding: utf-8 -*-
import os
import numpy as np
import subprocess as sp
import re
def polar(afile, re, *args,**kwargs):
"""Berechnet Profilpolaren und liest diese ein.
:param afile: Pfad zu Profilkoordinatendatei oder NACA4 Code
:type afile: string
:param re: Reynoldszahl
:type re: int
:param alfaseq: Sequenz von Anstellwinkeln
:type alfaseq: iterateable
:rtype: dict
"""
calcPolar(afile, re,'polar.txt', *args, **kwargs)
data = readPolar('polar.txt')
#raw_input('EnterKex')
deletePolar('polar.txt')
return data
def calcPolar(afile, re, polarfile, alfaseq=[], clseq=[], refine=False, max_iter=200, n=None):
"""Führt XFOIL aus und lässt Profilpolaren generieren.
:param afile: Pfad zu Profilkoordinatendatei oder NACA4 Code
:type afile: string
:param re: Reynoldszahl
:type re: int
:param polarfile: Ausgabedatei für XFOIL, darf nicht existieren
:param alfaseq: Sequenz von Anstellwinkeln
:type alfaseq: iterateable
:param clseq: Sequenz von Auftriebsbeiwerten, Alternativparameter zu alfaseq
:type clseq: iterateable
:param refine: Soll XFOIL ein refinement des Profils durchführen
:type refine: bool
:param max_iter: Maximale Iterationsanzahl
:type max_iter: int
:param n: Grenzschichtparameter
:type n: int
:rtype: None
"""
import subprocess as sp
import numpy as np
import sys,os
if(os.name == 'posix'):
xfoilbin = 'xfoil'
elif(os.name == 'nt'):
xfoilbin = 'xfoil.exe'
else:
print('Betriebssystem %s wird nicht unterstützt'%os.name)
pxfoil = sp.Popen([xfoilbin], stdin=sp.PIPE, stdout=None, stderr=None)
def write2xfoil(string):
if(sys.version_info > (3,0)):
string = string.encode('ascii')
pxfoil.stdin.write(string)
if(afile.isdigit()):
write2xfoil('NACA ' + afile + '\n')
else:
write2xfoil('LOAD ' + afile + '\n')
if(refine):
write2xfoil('GDES\n')
write2xfoil('CADD\n')
write2xfoil('\n')
write2xfoil('\n')
write2xfoil('\n')
write2xfoil('X\n ')
write2xfoil('\n')
write2xfoil('PANEL\n')
write2xfoil('OPER\n')
if n != None:
write2xfoil('VPAR\n')
write2xfoil('N '+str(n)+'\n')
write2xfoil('\n')
write2xfoil('ITER '+str(max_iter)+'\n')
write2xfoil('VISC\n')
write2xfoil(str(re) + '\n')
write2xfoil('PACC\n')
write2xfoil('\n')
write2xfoil('\n')
for alfa in alfaseq:
write2xfoil('A ' + str(alfa) + '\n')
for cl in clseq:
write2xfoil('CL ' + str(cl) + '\n')
write2xfoil('PWRT 1\n')
write2xfoil(polarfile + '\n')
write2xfoil('\n')
pxfoil.communicate(str('quit').encode('ascii'))
def readPolar(infile):
""" Liest XFOIL-Polarendatei ein.
:param infile: Polarendatei
:rtype: dict
"""
regex = re.compile('(?:\s*([+-]?\d*.\d*))')
with open(infile) as f:
lines = f.readlines()
a = []
cl = []
cd = []
cdp = []
cm = []
xtr_top = []
xtr_bottom = []
for line in lines[12:]:
linedata = regex.findall(line)
a.append(float(linedata[0]))
cl.append(float(linedata[1]))
cd.append(float(linedata[2]))
cdp.append(float(linedata[3]))
cm.append(float(linedata[4]))
xtr_top.append(float(linedata[5]))
xtr_bottom.append(float(linedata[6]))
data = {'a': np.array(a), 'cl': np.array(cl) , 'cd': np.array(cd), 'cdp': np.array(cdp),
'cm': np.array(cm), 'xtr_top': np.array(xtr_top), 'xtr_bottom': np.array(xtr_bottom)}
return data
def deletePolar(infile):
""" Löscht Datei. """
os.remove(infile)