-
Notifications
You must be signed in to change notification settings - Fork 1
/
bending_inertia.py
125 lines (99 loc) · 4 KB
/
bending_inertia.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
# Python BEM - Blade Element Momentum Theory Software.
# Copyright (C) 2022 M. Smrekar
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import math
import numpy as np
from scipy.interpolate import interp1d
pi = math.pi
def PointsInCircum(r, n=1000):
"""
Generates circle x,y coordinates.
:param r: float: radius
:param n: int: number of points
:return: tuple: (list of x points, list of y points)
"""
x_points = [math.cos(2 * pi / n * x) * r for x in range(0, n + 1)]
y_points = [math.sin(2 * pi / n * x) * r for x in range(0, n + 1)]
return x_points, y_points
def interpolate_airfoil(x, y, num_interp=100):
"""
Interpolates airfoil x,y data. Airfoil has to be non-rotated.
:param x: list of floats: x coordinates
:param y: list of floats: y coordinates
:param num_interp: int: number of interpolated points
:return: tuple: (list of x points, list of y points)
"""
cross = np.where(np.diff(np.signbit(np.gradient(x))))[0][0]
x_up = x[:cross + 2]
y_up = y[:cross + 2]
x_down = x[cross + 1:]
y_down = y[cross + 1:]
interp_up = interp1d(x_up, y_up, 'linear')
interp_down = interp1d(x_down, y_down, 'linear')
_x = np.linspace(np.min(x), np.max(x), num_interp)
_y_up = interp_up(_x)
_y_down = interp_down(_x)
x_out = np.concatenate((np.flip(_x), _x))
y_out = np.concatenate((np.flip(_y_up), _y_down))
return x_out, y_out
def calculate_bending_inertia_2(x, y):
"""
Calculates the bending intertia (second moment of area) for a given set of points.
Any polygon equations: https://en.wikipedia.org/wiki/Second_moment_of_area
Area equation: https://en.wikipedia.org/wiki/Polygon#Area
:param x: list of floats: x coordinates
:param y: list of floats: y coordinates
:return: tuple: (Ix,Iy,Ixy,A)
"""
Iy = 0
Ix = 0
Ixy = 0
A = 0
for i in range(len(x) - 1):
Iy += 1 / 12 * (x[i] * y[i + 1] - x[i + 1] * y[i]) * (x[i] ** 2 + x[i] * x[i + 1] + x[i + 1] ** 2)
Ix += 1 / 12 * (x[i] * y[i + 1] - x[i + 1] * y[i]) * (y[i] ** 2 + y[i] * y[i + 1] + y[i + 1] ** 2)
Ixy += 1 / 24 * (x[i] * y[i + 1] - x[i + 1] * y[i]) * (
x[i] * y[i + 1] + 2 * x[i] * y[i] + 2 * x[i + 1] * y[i + 1] + x[i + 1] * y[i])
A += 0.5 * (x[i] * y[i + 1] - x[i + 1] * y[i])
return Ix, Iy, Ixy, A
def generate_hollow_foil(x, y, thickness):
"""
Generates hollow airfoil from x,y coordinates.
thickness should be given in p.u.
This operation must be done BEFORE ROTATION.
(otherwise, criterion should be modified)
:param x:
:param y:
:param thickness:
:return:
"""
xout, yout = [], []
cross = np.where(np.diff(np.signbit(np.gradient(x))))[0][0]
x_up = x[:cross + 2]
y_up = y[:cross + 2]
x_down = x[cross + 1:]
y_down = y[cross + 1:]
interp_up = interp1d(x_up, y_up, 'linear', fill_value="extrapolate")
interp_down = interp1d(x_down, y_down, 'linear', fill_value="extrapolate")
for i in range(1, len(x)):
if interp_up(x[i]) - interp_down(x[i]) > 2 * thickness:
dx = x[i] - x[i - 1]
dy = y[i] - y[i - 1]
x_90 = -dy
y_90 = dx
vec_len = np.sqrt(x_90 ** 2 + y_90 ** 2)
a = thickness / vec_len
pristeto_x = x[i] + x_90 * a
pristeto_y = y[i] + y_90 * a
xout.append(pristeto_x)
yout.append(pristeto_y)
return xout, yout