-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaero.py
305 lines (252 loc) · 10.7 KB
/
aero.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import scipy.interpolate, csv
import matplotlib.pyplot as plt
import numpy as np
__copyright__ = """
Copyright 2021 Jago Strong-Wright & Daniel Gibbons
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/>.
"""
class AeroData:
"""Object holding aerodynamic data for the rocket.
Assumes an axially symmetric body. Uses scipy.interpolate.interp2d to interpolate data from arrays.
Args:
CA_grid (array, 2D): Axial force coefficient data.
CN_grid (array, 2D): Normal force coefficient data.
COP_grid (array, 2D): Centre of pressure data (m), containing distances between the nose tip and the centre of pressure.
Mach_grid (array, 1D or 2D): Mach number data.
alpha_grid (array, 1D or 2D): Angle of attack data (radians).
ref_area (float): Referance area used to normalise coefficients (m^2).
pitch_damping_coefficient (float, optional): Pitch damping coefficient, defined by moment = C * ρ * ω^2. Defaults to zero.
roll_damping_coefficient (float, optional): Roll damping coefficient, defined by moment = C * ρ * ω^2. Defaults to zero.
error(dictionary, optional): Used for running stochastic analyses. Defaults to {"CA":1.0,"CN":1.0,"COP":1.0}.
Attributes:
CA_grid (array): Axial force coefficient data.
CN_grid (array): Normal force coefficient data.
COP_grid (array): Centre of pressure data, containing distances between the nose tip and the centre of pressure (m).
Mach_grid (array): Mach number data.
alpha_grid (array): Angle of attack data (rad).
ref_area (float): Reference area used to normalise coefficients (m^2).
pitch_damping_coefficient (float): Pitch damping coefficient, defined by moment = C * ρ * ω^2.
roll_damping_coefficient (float): Roll damping coefficient, defined by moment = C * ρ * ω^2.
error(dictionary): Used for running stochastic analyses.
"""
def __init__(
self,
CA_grid,
CN_grid,
COP_grid,
Mach_grid,
alpha_grid,
ref_area,
pitch_damping_coefficient=0.0,
roll_damping_coefficient=0.0,
error={"CA": 1.0, "CN": 1.0, "COP": 1.0},
):
self.ref_area = ref_area
self.pitch_damping_coefficient = pitch_damping_coefficient
self.roll_damping_coefficient = roll_damping_coefficient
self.Mach_grid = Mach_grid
self.alpha_grid = alpha_grid
self.CA_grid = CA_grid
self.CN_grid = CN_grid
self.COP_grid = COP_grid
self.error = error
# These can be overridden to custom functions if you wanted - in which case the _grid attributes are irrelevant.
self.CA_func = scipy.interpolate.interp2d(
self.Mach_grid, self.alpha_grid, self.CA_grid
)
self.CN_func = scipy.interpolate.interp2d(
self.Mach_grid, self.alpha_grid, self.CN_grid
)
self.COP_func = scipy.interpolate.interp2d(
self.Mach_grid, self.alpha_grid, self.COP_grid
)
def CA(self, Mach, alpha):
return self.error["CA"] * self.CA_func(Mach, alpha)
def CN(self, Mach, alpha):
return self.error["CN"] * self.CN_func(Mach, alpha)
def COP(self, Mach, alpha):
return self.error["COP"] * self.COP_func(Mach, alpha)
def show_plot(
self, Mach=np.linspace(0, 25, 500), alpha=np.linspace(0, 4, 5) * np.pi / 180
):
""" "Shows plots of the CA, CN and COP functions, so you can visually check if the system has interpreted your data correctly.
Args:
Mach (array): Array of Mach numbers to plot over. Defaults to np.linspace(0, 25, 500).
alpha (array): Array of angles of attack to plot over (rad). Defaults to np.linspace(0, 4, 5)*np.pi/180.
"""
CA = []
CN = []
COP = []
for j in range(len(alpha)):
# For each angle of attack
CA.append([])
CN.append([])
COP.append([])
for i in range(len(Mach)):
# For each Mach number
CA[j].append(self.CA(Mach[i], alpha[j]))
CN[j].append(self.CN(Mach[i], alpha[j]))
COP[j].append(self.COP(Mach[i], alpha[j]))
# Create figure
fig, axs = plt.subplots(2, 2)
# Convert back to deg
alpha = alpha * 180 / np.pi
# Plot
for i in range(len(alpha)):
axs[0, 0].plot(Mach, CA[i], label=f"alpha = {alpha[i]} deg")
axs[0, 1].plot(Mach, CN[i], label=f"alpha = {alpha[i]} deg")
axs[1, 0].plot(Mach, COP[i], label=f"alpha = {alpha[i]} deg")
# Aesthetics
axs[0, 0].set_xlabel("Mach")
axs[0, 0].set_ylabel("CA")
axs[0, 0].grid()
axs[0, 0].legend()
axs[0, 1].set_xlabel("Mach")
axs[0, 1].set_ylabel("CN")
axs[0, 1].grid()
axs[0, 1].legend()
axs[1, 0].set_xlabel("Mach")
axs[1, 0].set_ylabel("COP (m)")
axs[1, 0].grid()
axs[1, 0].legend()
plt.show()
@staticmethod
def from_lists(
CA_list,
CN_list,
COP_list,
Mach_list,
alpha_list,
ref_area,
pitch_damping_coefficient=0,
roll_damping_coefficient=0,
error={"CA": 1.0, "CN": 1.0, "COP": 1.0},
):
"""Takes in 1D lists of data, and converts them into 2D arrays so they can be used for 2D interpolation.
Args:
CA_list (array, 1D): List of CA data at each Mach and alpha.
CN_list (array, 1D): List of CN data at each Mach and alpha
COP_list (array, 1D): List of COP data (m) at each mach and alph.
Mach_list (array, 1D): List of Mach numbers for each data point.
alpha_list (array, 1D): List of angles of attack (rad) for each data point.
ref_area (array, 1D): Reference area used to normalise coefficients (m^2).
pitch_damping_coefficient (int, optional): Pitch damping coefficient, defined by moment = C * ρ * ω^2. Defaults to 0.
roll_damping_coefficient (int, optional): Roll damping coefficient, defined by moment = C * ρ * ω^2. Defaults to 0.
error (dict, optional): Used for running stochastic analyses. Defaults to {"CA":1.0,"CN":1.0,"COP":1.0}.
Returns:
AeroData: AeroData object.
"""
# Convert into the right shapes
Mach_unique = np.unique(Mach_list)
alpha_unique = np.unique(alpha_list)
CA_grid = np.reshape(CA_list, (len(alpha_unique), len(Mach_unique)))
CN_grid = np.reshape(CN_list, (len(alpha_unique), len(Mach_unique)))
COP_grid = np.reshape(COP_list, (len(alpha_unique), len(Mach_unique)))
return AeroData(
CA_grid,
CN_grid,
COP_grid,
Mach_unique,
alpha_unique,
ref_area,
pitch_damping_coefficient,
roll_damping_coefficient,
error,
)
@staticmethod
def from_rasaero(
csv_directory,
ref_area,
pitch_damping_coefficient=0,
roll_damping_coefficient=0,
error={"CA": 1.0, "CN": 1.0, "COP": 1.0},
):
"""Convert an aerodynamic data .CSV file from RASAero II into an AeroData object.
Args:
csv_directory (string): Directory to .CSV file.
ref_area (float): Referance area used to normalise coefficients (m^2).
pitch_damping_coefficient (float, optional): Pitch damping coefficient, defined by moment = C * ρ * ω^2. Defaults to zero.
roll_damping_coefficient (float, optional): Roll damping coefficient, defined by moment = C * ρ * ω^2. Defaults to zero.
error(dictionary, optional): Used for running stochastic analyses.
Returns:
AeroData: AeroData object.
"""
with open(csv_directory) as csvfile:
aero_data = csv.reader(csvfile)
Mach_raw = []
alpha_raw = []
CA_raw = []
COP_raw = []
CN_raw = []
# Extract the raw data from the .csv file
next(aero_data)
for row in aero_data:
Mach_raw.append(float(row[0]))
alpha_raw.append(float(row[1]))
CA_raw.append(float(row[5]))
COP_raw.append(float(row[12]))
CN_raw.append(float(row[8]))
# The data has length 7499 when it should be 7500 (3x2500). We'll just add the last datapoint on twice.
Mach_raw.append(Mach_raw[-1])
alpha_raw.append(alpha_raw[-1])
CA_raw.append(CA_raw[-1])
COP_raw.append(COP_raw[-1])
CN_raw.append(CN_raw[-1])
# Convert alpha from degrees to radians
alpha_raw = np.array(alpha_raw) * np.pi / 180
# Convert COP from inches to m
COP_raw = np.array(COP_raw) * 0.0254
return AeroData.from_lists(
CA_raw,
CN_raw,
COP_raw,
Mach_raw,
alpha_raw,
ref_area,
pitch_damping_coefficient,
roll_damping_coefficient,
error,
)
def pitch_damping_coefficient(length, radius, fin_number, area_per_fin):
"""Gives approximate values for the pitch damping coefficient. Uses equations (3.59) and (3.60) from the OpenRocket documentation.
Note
----
In this model we define the pitch damping coefficient as:
m = C * ρ * ω^2
Where:
m = moment
ρ = free-stream density
ω = pitch rate
C = pitch damping coefficient.
Assumptions:
- Fins are at the very bottom of the rocket
- COG of the rocket is half way up the length
Parameters
----------
length : float
Length of the rocket (m)
radius : float
Radius of the rocket (assuming it's a cylinder) (m)
fin_number: int
Number of fins on the rocket
area_per_fin : float
Area of a single fin (m^2)
Returns
----------
Pitch damping cofficient
"""
if fin_number > 4:
fin_number = 4
return (
0.275 * radius * (length ** 4)
+ 0.3 * fin_number * area_per_fin * (length / 2) ** 3
)