-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathtest_profiles.py
More file actions
346 lines (278 loc) · 14.5 KB
/
test_profiles.py
File metadata and controls
346 lines (278 loc) · 14.5 KB
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
from unittest import TestCase
import numpy as np
from bladex import CustomProfile, NacaProfile, ProfileInterface
def create_custom_profile():
"""
xup_coordinates, yup_coordinates, xdown_coordinates, ydown_coordinates
"""
xup = np.linspace(-1.0, 1.0, 5)
yup = np.array([0.0, 0.75, 1.0, 0.75, 0.0])
xdown = np.linspace(-1.0, 1.0, 5)
ydown = np.zeros(5)
return CustomProfile(xup=xup, yup=yup, xdown=xdown, ydown=ydown)
class TestBaseProfileMethods(TestCase):
def test_max_thickness(self):
profile = NacaProfile(digits='2412')
self.assertAlmostEqual(profile.max_thickness(), .12, delta=1e-4)
def test_set_thickness_max(self):
profile = NacaProfile(digits='2412')
profile.set_thickness_max(.24)
self.assertAlmostEqual(profile.max_thickness(), .24, delta=1e-4)
def test_max_camber(self):
profile = NacaProfile(digits='3412')
self.assertAlmostEqual(profile.max_camber(), .03, delta=1e-4)
def test_set_camber_max(self):
profile = NacaProfile(digits='3412')
profile.set_camber_line_max(.05)
self.assertAlmostEqual(profile.max_camber(), .05, delta=1e-4)
class TestCustomProfile(TestCase):
def test_inheritance_custom(self):
self.assertTrue(issubclass(CustomProfile, ProfileInterface))
def test_xup_member(self):
profile = create_custom_profile()
np.testing.assert_equal(profile.xup_coordinates,
np.linspace(-1.0, 1.0, 5))
def test_yup_member(self):
profile = create_custom_profile()
np.testing.assert_equal(profile.yup_coordinates,
np.array([0.0, 0.75, 1.0, 0.75, 0.0]))
def test_xdown_member(self):
profile = create_custom_profile()
np.testing.assert_equal(profile.xdown_coordinates,
np.linspace(-1.0, 1.0, 5))
def test_ydown_member(self):
profile = create_custom_profile()
np.testing.assert_equal(profile.ydown_coordinates, np.zeros(5))
def test_xup_None(self):
profile = create_custom_profile()
profile.xup_coordinates = None
with self.assertRaises(ValueError):
profile._check_coordinates()
def test_yup_None(self):
profile = create_custom_profile()
profile.yup_coordinates = None
with self.assertRaises(ValueError):
profile._check_coordinates()
def test_xdown_None(self):
profile = create_custom_profile()
profile.xdown_coordinates = None
with self.assertRaises(ValueError):
profile._check_coordinates()
def test_ydown_None(self):
profile = create_custom_profile()
profile.ydown_coordinates = None
with self.assertRaises(ValueError):
profile._check_coordinates()
def test_xup_not_ndarray(self):
profile = create_custom_profile()
profile.xup_coordinates = [-1.0, -0.5, 0.0, 0.5, 1.0]
profile._check_coordinates()
self.assertIsInstance(profile.xup_coordinates, np.ndarray)
def test_yup_not_ndarray(self):
profile = create_custom_profile()
profile.yup_coordinates = [0.0, 0.75, 1.0, 0.75, 0.0]
profile._check_coordinates()
self.assertIsInstance(profile.yup_coordinates, np.ndarray)
def test_xdown_not_ndarray(self):
profile = create_custom_profile()
profile.xdown_coordinates = [-1.0, -0.5, 0.0, 0.5, 1.0]
profile._check_coordinates()
self.assertIsInstance(profile.xdown_coordinates, np.ndarray)
def test_ydown_not_ndarray(self):
profile = create_custom_profile()
profile.ydown_coordinates = [0.0, 0.0, 0.0, 0.0, 0.0]
profile._check_coordinates()
self.assertIsInstance(profile.ydown_coordinates, np.ndarray)
def test_upper_profile_not_same_shape(self):
profile = create_custom_profile()
profile.xup_coordinates = np.array([1.0, 2.0])
with self.assertRaises(ValueError):
profile._check_coordinates()
def test_lower_profile_not_same_shape(self):
profile = create_custom_profile()
profile.xdown_coordinates = np.array([1.0, 2.0])
with self.assertRaises(ValueError):
profile._check_coordinates()
def test_yup_lower_ydown(self):
profile = create_custom_profile()
profile.yup_coordinates *= -1.0
with self.assertRaises(ValueError):
profile._check_coordinates()
def test_leading_edge_x(self):
profile = create_custom_profile()
profile.xup_coordinates[0] = -1.5
with self.assertRaises(ValueError):
profile._check_coordinates()
def test_leading_edge_y(self):
profile = create_custom_profile()
profile.yup_coordinates[0] = 1.5
with self.assertRaises(ValueError):
profile._check_coordinates()
def test_trailing_edge_x(self):
profile = create_custom_profile()
profile.xup_coordinates[-1] = -1.5
with self.assertRaises(ValueError):
profile._check_coordinates()
class TestNacaProfile(TestCase):
def test_inheritance_naca(self):
self.assertTrue(issubclass(NacaProfile, ProfileInterface))
def test_digits_member(self):
profile = NacaProfile(digits='0012', n_points=240)
assert profile.digits == '0012'
def test_npoints_member(self):
profile = NacaProfile(digits='0012', n_points=240)
assert profile.n_points == 240
def test_digits_not_entered(self):
with self.assertRaises(TypeError):
NacaProfile()
def test_digits_not_string(self):
with self.assertRaises(TypeError):
NacaProfile(digits=2412, n_points=240)
def test_npoints_float_1(self):
profile = NacaProfile(digits='2412', n_points=240.0)
self.assertIsInstance(profile.n_points, int)
def test_npoints_float_2(self):
profile = NacaProfile(digits='2412', n_points=240.5)
assert profile.n_points == 240
def test_npoints_not_number(self):
with self.assertRaises(TypeError):
NacaProfile(digits='0012', n_points='240')
def test_npoints_negative(self):
with self.assertRaises(ValueError):
NacaProfile(digits='0012', n_points=-240)
def test_naca_series_not_implemented_1(self):
with self.assertRaises(Exception):
NacaProfile(digits='1234-05', n_points=240)
def test_naca_series_not_implemented_2(self):
with self.assertRaises(Exception):
NacaProfile(digits='16-123', n_points=240)
def test_naca_series_not_implemented_3(self):
with self.assertRaises(Exception):
NacaProfile(digits='712A315', n_points=240)
def test_naca_4_symmetric_xup(self):
foil = NacaProfile(digits='0012', n_points=240)
xup_expected = np.load('tests/test_datasets/naca4_0012_xup.npy')
np.testing.assert_almost_equal(foil.xup_coordinates, xup_expected)
def test_naca_4_symmetric_yup(self):
foil = NacaProfile(digits='0012', n_points=240)
yup_expected = np.load('tests/test_datasets/naca4_0012_yup.npy')
np.testing.assert_almost_equal(foil.yup_coordinates, yup_expected)
def test_naca_4_symmetric_xdown(self):
foil = NacaProfile(digits='0012', n_points=240)
xdown_expected = np.load('tests/test_datasets/naca4_0012_xdown.npy')
np.testing.assert_almost_equal(foil.xdown_coordinates, xdown_expected)
def test_naca_4_symmetric_ydown(self):
foil = NacaProfile(digits='0012', n_points=240)
ydown_expected = np.load('tests/test_datasets/naca4_0012_ydown.npy')
np.testing.assert_almost_equal(foil.ydown_coordinates, ydown_expected)
def test_naca_4_cambered_xup_cosine(self):
foil = NacaProfile(digits='2412', n_points=240, cosine_spacing=True)
xup_expected = np.load('tests/test_datasets/naca4_2412_xup_cosine.npy')
np.testing.assert_almost_equal(foil.xup_coordinates, xup_expected)
def test_naca_4_cambered_yup_cosine(self):
foil = NacaProfile(digits='2412', n_points=240, cosine_spacing=True)
yup_expected = np.load('tests/test_datasets/naca4_2412_yup_cosine.npy')
np.testing.assert_almost_equal(foil.yup_coordinates, yup_expected)
def test_naca_4_cambered_xdown_cosine(self):
foil = NacaProfile(digits='2412', n_points=240, cosine_spacing=True)
xdown_expected = np.load(
'tests/test_datasets/naca4_2412_xdown_cosine.npy')
np.testing.assert_almost_equal(foil.xdown_coordinates, xdown_expected)
def test_naca_4_cambered_ydown_cosine(self):
foil = NacaProfile(digits='2412', n_points=240, cosine_spacing=True)
ydown_expected = np.load(
'tests/test_datasets/naca4_2412_ydown_cosine.npy')
np.testing.assert_almost_equal(foil.ydown_coordinates, ydown_expected)
def test_naca_4_cambered_xup_linear(self):
foil = NacaProfile(digits='2412', n_points=240, cosine_spacing=False)
xup_expected = np.load('tests/test_datasets/naca4_2412_xup_linear.npy')
np.testing.assert_almost_equal(foil.xup_coordinates, xup_expected)
def test_naca_4_cambered_yup_linear(self):
foil = NacaProfile(digits='2412', n_points=240, cosine_spacing=False)
yup_expected = np.load('tests/test_datasets/naca4_2412_yup_linear.npy')
np.testing.assert_almost_equal(foil.yup_coordinates, yup_expected)
def test_naca_4_cambered_xdown_linear(self):
foil = NacaProfile(digits='2412', n_points=240, cosine_spacing=False)
xdown_expected = np.load(
'tests/test_datasets/naca4_2412_xdown_linear.npy')
np.testing.assert_almost_equal(foil.xdown_coordinates, xdown_expected)
def test_naca_4_cambered_ydown_linear(self):
foil = NacaProfile(digits='2412', n_points=240, cosine_spacing=False)
ydown_expected = np.load(
'tests/test_datasets/naca4_2412_ydown_linear.npy')
np.testing.assert_almost_equal(foil.ydown_coordinates, ydown_expected)
def test_naca_5_wrong_reflex(self):
with self.assertRaises(ValueError):
NacaProfile(digits='24512', n_points=240)
def test_naca_5_symmetric_xup(self):
foil = NacaProfile(digits='00012', n_points=240)
xup_expected = np.load('tests/test_datasets/naca5_00012_xup.npy')
np.testing.assert_almost_equal(foil.xup_coordinates, xup_expected)
def test_naca_5_symmetric_yup(self):
foil = NacaProfile(digits='00012', n_points=240)
yup_expected = np.load('tests/test_datasets/naca5_00012_yup.npy')
np.testing.assert_almost_equal(foil.yup_coordinates, yup_expected)
def test_naca_5_symmetric_xdown(self):
foil = NacaProfile(digits='00012', n_points=240)
xdown_expected = np.load('tests/test_datasets/naca5_00012_xdown.npy')
np.testing.assert_almost_equal(foil.xdown_coordinates, xdown_expected)
def test_naca_5_symmetric_ydown(self):
foil = NacaProfile(digits='00012', n_points=240)
ydown_expected = np.load('tests/test_datasets/naca5_00012_ydown.npy')
np.testing.assert_almost_equal(foil.ydown_coordinates, ydown_expected)
def test_naca_5_cambered_standard_xup_cosine(self):
foil = NacaProfile(digits='23012', n_points=240, cosine_spacing=True)
xup_expected = np.load('tests/test_datasets/naca5_23012_xup_cosine.npy')
np.testing.assert_almost_equal(foil.xup_coordinates, xup_expected)
def test_naca_5_cambered_standard_yup_cosine(self):
foil = NacaProfile(digits='23012', n_points=240, cosine_spacing=True)
yup_expected = np.load('tests/test_datasets/naca5_23012_yup_cosine.npy')
np.testing.assert_almost_equal(foil.yup_coordinates, yup_expected)
def test_naca_5_cambered_standard_xdown_cosine(self):
foil = NacaProfile(digits='23012', n_points=240, cosine_spacing=True)
xdown_expected = np.load(
'tests/test_datasets/naca5_23012_xdown_cosine.npy')
np.testing.assert_almost_equal(foil.xdown_coordinates, xdown_expected)
def test_naca_5_cambered_standard_ydown_cosine(self):
foil = NacaProfile(digits='23012', n_points=240, cosine_spacing=True)
ydown_expected = np.load(
'tests/test_datasets/naca5_23012_ydown_cosine.npy')
np.testing.assert_almost_equal(foil.ydown_coordinates, ydown_expected)
def test_naca_5_cambered_standard_xup_linear(self):
foil = NacaProfile(
digits='23012', n_points=240, cosine_spacing=False)
xup_expected = np.load('tests/test_datasets/naca5_23012_xup_linear.npy')
np.testing.assert_almost_equal(foil.xup_coordinates, xup_expected)
def test_naca_5_cambered_standard_yup_linear(self):
foil = NacaProfile(
digits='23012', n_points=240, cosine_spacing=False)
yup_expected = np.load('tests/test_datasets/naca5_23012_yup_linear.npy')
np.testing.assert_almost_equal(foil.yup_coordinates, yup_expected)
def test_naca_5_cambered_standard_xdown_linear(self):
foil = NacaProfile(
digits='23012', n_points=240, cosine_spacing=False)
xdown_expected = np.load(
'tests/test_datasets/naca5_23012_xdown_linear.npy')
np.testing.assert_almost_equal(foil.xdown_coordinates, xdown_expected)
def test_naca_5_cambered_standard_ydown_linear(self):
foil = NacaProfile(
digits='23012', n_points=240, cosine_spacing=False)
ydown_expected = np.load(
'tests/test_datasets/naca5_23012_ydown_linear.npy')
np.testing.assert_almost_equal(foil.ydown_coordinates, ydown_expected)
def test_naca_5_cambered_reflexed_xup(self):
foil = NacaProfile(digits='23112', n_points=240)
xup_expected = np.load('tests/test_datasets/naca5_23112_xup.npy')
np.testing.assert_almost_equal(foil.xup_coordinates, xup_expected)
def test_naca_5_cambered_reflexed_yup(self):
foil = NacaProfile(digits='23112', n_points=240)
yup_expected = np.load('tests/test_datasets/naca5_23112_yup.npy')
np.testing.assert_almost_equal(foil.yup_coordinates, yup_expected)
def test_naca_5_cambered_reflexed_xdown(self):
foil = NacaProfile(digits='23112', n_points=240)
xdown_expected = np.load('tests/test_datasets/naca5_23112_xdown.npy')
np.testing.assert_almost_equal(foil.xdown_coordinates, xdown_expected)
def test_naca_5_cambered_reflexed_ydown(self):
foil = NacaProfile(digits='23112', n_points=240)
ydown_expected = np.load('tests/test_datasets/naca5_23112_ydown.npy')
np.testing.assert_almost_equal(foil.ydown_coordinates, ydown_expected)