pyfoiltools 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyfoiltools/__init__.py +0 -0
- pyfoiltools/airfoil.py +207 -0
- pyfoiltools/fitting/__init__.py +7 -0
- pyfoiltools/fitting/airfoilbspline.py +557 -0
- pyfoiltools/fitting/airfoilpoly.py +1195 -0
- pyfoiltools/fitting/airfoilshape.py +948 -0
- pyfoiltools/fitting/chordspacing.py +147 -0
- pyfoiltools/naca4.py +302 -0
- pyfoiltools-0.0.1.dist-info/METADATA +22 -0
- pyfoiltools-0.0.1.dist-info/RECORD +13 -0
- pyfoiltools-0.0.1.dist-info/WHEEL +5 -0
- pyfoiltools-0.0.1.dist-info/licenses/LICENSE +21 -0
- pyfoiltools-0.0.1.dist-info/top_level.txt +1 -0
pyfoiltools/__init__.py
ADDED
|
File without changes
|
pyfoiltools/airfoil.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
from typing import TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
from matplotlib.pyplot import figure
|
|
5
|
+
from numpy import arctan2, argmax, asarray, cos, flip, sin, sqrt
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from matplotlib.axes import Axes
|
|
9
|
+
from numpy.typing import NDArray
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Airfoil():
|
|
13
|
+
name: str = None
|
|
14
|
+
x: 'NDArray' = None
|
|
15
|
+
y: 'NDArray' = None
|
|
16
|
+
_xte: float = None
|
|
17
|
+
_yte: float = None
|
|
18
|
+
_ile: int = None
|
|
19
|
+
_xle: float = None
|
|
20
|
+
_yle: float = None
|
|
21
|
+
_chord: float = None
|
|
22
|
+
_alrad: float = None
|
|
23
|
+
_tte: float = None
|
|
24
|
+
_area: float = None
|
|
25
|
+
_xu: 'NDArray' = None
|
|
26
|
+
_yu: 'NDArray' = None
|
|
27
|
+
_xl: 'NDArray' = None
|
|
28
|
+
_yl: 'NDArray' = None
|
|
29
|
+
|
|
30
|
+
def __init__(self, name: str, x: Iterable, y: Iterable) -> None:
|
|
31
|
+
self.name = name
|
|
32
|
+
self.x = asarray(x)
|
|
33
|
+
self.y = asarray(y)
|
|
34
|
+
self.validate_area()
|
|
35
|
+
|
|
36
|
+
def reset(self) -> None:
|
|
37
|
+
for attr in self.__dict__:
|
|
38
|
+
if attr.startswith('_'):
|
|
39
|
+
setattr(self, attr, None)
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def xte(self) -> float:
|
|
43
|
+
if self._xte is None:
|
|
44
|
+
self._xte = (self.x[-1] + self.x[0])/2
|
|
45
|
+
return self._xte
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def yte(self) -> float:
|
|
49
|
+
if self._yte is None:
|
|
50
|
+
self._yte = (self.y[-1] + self.y[0])/2
|
|
51
|
+
return self._yte
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def ile(self) -> int:
|
|
55
|
+
if self._ile is None:
|
|
56
|
+
dx = self.x - self.xte
|
|
57
|
+
dy = self.y - self.yte
|
|
58
|
+
d2 = dx**2 + dy**2
|
|
59
|
+
self._ile = argmax(d2)
|
|
60
|
+
return self._ile
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def xle(self) -> float:
|
|
64
|
+
if self._xle is None:
|
|
65
|
+
self._xle = self.x[self.ile]
|
|
66
|
+
return self._xle
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def yle(self) -> float:
|
|
70
|
+
if self._yle is None:
|
|
71
|
+
self._yle = self.y[self.ile]
|
|
72
|
+
return self._yle
|
|
73
|
+
|
|
74
|
+
def calc_alrad_chord(self) -> None:
|
|
75
|
+
dx = self.xte - self.xle
|
|
76
|
+
dy = self.yte - self.yle
|
|
77
|
+
self._chord = sqrt(dx**2 + dy**2)
|
|
78
|
+
self._alrad = arctan2(dy, dx)
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def alrad(self) -> float:
|
|
82
|
+
if self._alrad is None:
|
|
83
|
+
self.calc_alrad_chord()
|
|
84
|
+
return self._alrad
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def chord(self) -> float:
|
|
88
|
+
if self._chord is None:
|
|
89
|
+
self.calc_alrad_chord()
|
|
90
|
+
return self._chord
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def tte(self) -> float:
|
|
94
|
+
if self._tte is None:
|
|
95
|
+
dx = self.x[-1] - self.x[0]
|
|
96
|
+
dy = self.y[-1] - self.y[0]
|
|
97
|
+
self._tte = sqrt(dx**2 + dy**2)
|
|
98
|
+
return self._tte
|
|
99
|
+
|
|
100
|
+
def validate_area(self) -> None:
|
|
101
|
+
xa = self.x[:-1]
|
|
102
|
+
xb = self.x[1:]
|
|
103
|
+
ya = self.y[:-1]
|
|
104
|
+
yb = self.y[1:]
|
|
105
|
+
doubarea = xb*ya - xa*yb
|
|
106
|
+
xa = self.x[-1]
|
|
107
|
+
xb = self.x[0]
|
|
108
|
+
ya = self.y[-1]
|
|
109
|
+
yb = self.y[0]
|
|
110
|
+
doubarea = doubarea.sum() + xb*ya - xa*yb
|
|
111
|
+
if doubarea < 0.0:
|
|
112
|
+
self.reverse()
|
|
113
|
+
self._area = -doubarea/2
|
|
114
|
+
else:
|
|
115
|
+
self._area = doubarea/2
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def area(self) -> float:
|
|
119
|
+
if self._area is None:
|
|
120
|
+
self.validate_area()
|
|
121
|
+
return self._area
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def xu(self) -> 'NDArray':
|
|
125
|
+
if self._xu is None:
|
|
126
|
+
self._xu = self.x[self.ile:]
|
|
127
|
+
return self._xu
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def yu(self) -> 'NDArray':
|
|
131
|
+
if self._yu is None:
|
|
132
|
+
self._yu = self.y[self.ile:]
|
|
133
|
+
return self._yu
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def xl(self) -> 'NDArray':
|
|
137
|
+
if self._xl is None:
|
|
138
|
+
self._xl = flip(self.x[:self.ile+1])
|
|
139
|
+
return self._xl
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def yl(self) -> 'NDArray':
|
|
143
|
+
if self._yl is None:
|
|
144
|
+
self._yl = flip(self.y[:self.ile+1])
|
|
145
|
+
return self._yl
|
|
146
|
+
|
|
147
|
+
def scale(self, scale: float) -> None:
|
|
148
|
+
self.x = self.x*scale
|
|
149
|
+
self.y = self.y*scale
|
|
150
|
+
self.reset()
|
|
151
|
+
|
|
152
|
+
def translate(self, x: float, y: float) -> None:
|
|
153
|
+
self.x = self.x + x
|
|
154
|
+
self.y = self.y + y
|
|
155
|
+
self.reset()
|
|
156
|
+
|
|
157
|
+
def rotate(self, angle: float) -> None:
|
|
158
|
+
cosal = cos(angle)
|
|
159
|
+
sinal = sin(angle)
|
|
160
|
+
self.x = self.x*cosal - self.y*sinal
|
|
161
|
+
self.y = self.x*sinal + self.y*cosal
|
|
162
|
+
self.reset()
|
|
163
|
+
|
|
164
|
+
def normalise(self) -> None:
|
|
165
|
+
self.translate(-self.xle, -self.yle)
|
|
166
|
+
self.scale(1/self.chord)
|
|
167
|
+
self.rotate(-self.alrad)
|
|
168
|
+
|
|
169
|
+
def reverse(self) -> None:
|
|
170
|
+
self.x = self.x[::-1]
|
|
171
|
+
self.y = self.y[::-1]
|
|
172
|
+
self.reset()
|
|
173
|
+
|
|
174
|
+
def plot(self, ax: 'Axes' = None) -> 'Axes':
|
|
175
|
+
if ax is None:
|
|
176
|
+
fig = figure()
|
|
177
|
+
ax = fig.gca()
|
|
178
|
+
ax.grid(True)
|
|
179
|
+
ax.set_aspect('equal')
|
|
180
|
+
ax.plot(self.x, self.y, label=self.name)
|
|
181
|
+
return ax
|
|
182
|
+
|
|
183
|
+
def __repr__(self) -> str:
|
|
184
|
+
return f'<Airfoil: {self.name:s}>'
|
|
185
|
+
|
|
186
|
+
def __str__(self) -> str:
|
|
187
|
+
return f'Airfoil: {self.name:s}'
|
|
188
|
+
|
|
189
|
+
@classmethod
|
|
190
|
+
def from_dat(cls, datfilepath: str) -> 'Airfoil':
|
|
191
|
+
|
|
192
|
+
name = ''
|
|
193
|
+
x = []
|
|
194
|
+
y = []
|
|
195
|
+
|
|
196
|
+
with open(datfilepath, 'rt') as file:
|
|
197
|
+
for i, line in enumerate(file):
|
|
198
|
+
line = line.rstrip('\n')
|
|
199
|
+
if i == 0:
|
|
200
|
+
name = line.strip()
|
|
201
|
+
else:
|
|
202
|
+
split = line.split()
|
|
203
|
+
if len(split) == 2:
|
|
204
|
+
x.append(float(split[0]))
|
|
205
|
+
y.append(float(split[1]))
|
|
206
|
+
|
|
207
|
+
return cls(name, x, y)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from .airfoilbspline import AirfoilBSpline as AirfoilBSpline
|
|
2
|
+
from .airfoilbspline import AirfoilBSplineFit as AirfoilBSplineFit
|
|
3
|
+
from .airfoilpoly import AirfoilPoly as AirfoilPoly
|
|
4
|
+
from .airfoilpoly import AirfoilPolyFit as AirfoilPolyFit
|
|
5
|
+
from .airfoilshape import AirfoilShape as AirfoilShape
|
|
6
|
+
from .airfoilshape import AirfoilShapeFit as AirfoilShapeFit
|
|
7
|
+
from .chordspacing import ChordSpacing as ChordSpacing
|