-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_suite.py
606 lines (507 loc) · 24.9 KB
/
test_suite.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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
from __future__ import division, print_function
import sys
from time import time
import unittest
import numpy as np
# Append the parent directory to the system path so we can call those Python
# files. If you have OpenAeroStruct in your PYTHONPATH, this is not necessary.
from os import sys, path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
from OpenAeroStruct import OASProblem
try:
import OAS_API
fortran_flag = True
except:
fortran_flag = False
class TestAero(unittest.TestCase):
currentResult = []
def run(self, result=None):
self.currentResult.append(result) # remember result for use in tearDown
unittest.TestCase.run(self, result) # call superclass run method
def test_aero_analysis_flat(self):
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : False,
'record_db' : False})
OAS_prob.add_surface({'span_cos_spacing' : 0})
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CL'], .46173591841167, places=5)
self.assertAlmostEqual(prob['wing_perf.CD'], .005524603647, places=5)
def test_aero_analysis_flat_multiple(self):
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : False,
'record_db' : False})
OAS_prob.add_surface({'span_cos_spacing' : 0.})
OAS_prob.add_surface({'name' : 'tail',
'span_cos_spacing' : 0.,
'offset' : np.array([0., 0., 1000000.])})
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CL'], .46173591841167, places=5)
self.assertAlmostEqual(prob['tail_perf.CL'], .46173591841167, places=5)
def test_aero_analysis_flat_side_by_side(self):
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : False,
'record_db' : False})
OAS_prob.add_surface({'name' : 'wing',
'span' : 5.,
'num_y' : 3,
'span_cos_spacing' : 0.,
'symmetry' : False,
'offset' : np.array([0., -2.5, 0.])})
OAS_prob.add_surface({'name' : 'tail',
'span' : 5.,
'num_y' : 3,
'span_cos_spacing' : 0.,
'symmetry' : False,
'offset' : np.array([0., 2.5, 0.])})
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CL'], 0.46173591841167183, places=5)
self.assertAlmostEqual(prob['tail_perf.CL'], 0.46173591841167183, places=5)
self.assertAlmostEqual(prob['wing_perf.CD'], .005524603647, places=5)
self.assertAlmostEqual(prob['tail_perf.CD'], .005524603647, places=5)
def test_aero_analysis_flat_full(self):
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : False,
'record_db' : False})
surf_dict = {'symmetry' : False}
OAS_prob.add_surface(surf_dict)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CL'], .45655138, places=5)
self.assertAlmostEqual(prob['wing_perf.CD'], 0.0055402121081108589, places=5)
def test_aero_analysis_flat_viscous_full(self):
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : False,
'record_db' : False,
'with_viscous' : True})
surf_dict = {'symmetry' : False}
OAS_prob.add_surface(surf_dict)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CL'], .45655138, places=5)
self.assertAlmostEqual(prob['wing_perf.CD'], 0.018942466133780547, places=5)
if fortran_flag:
def test_aero_optimization(self):
# Need to use SLSQP here because SNOPT finds a different optimum
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : True,
'record_db' : False,
'optimizer' : 'SLSQP'})
OAS_prob.add_surface()
OAS_prob.add_desvar('wing.twist_cp', lower=-10., upper=15.)
OAS_prob.add_desvar('wing.sweep', lower=10., upper=30.)
OAS_prob.add_desvar('wing.dihedral', lower=-10., upper=20.)
OAS_prob.add_constraint('wing_perf.CL', equals=0.5)
OAS_prob.add_objective('wing_perf.CD', scaler=1e4)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CD'], 0.0049392534859265614, places=5)
if fortran_flag:
def test_aero_optimization_fd(self):
# Need to use SLSQP here because SNOPT finds a different optimum
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : True,
'record_db' : False,
'optimizer' : 'SLSQP',
'force_fd' : True})
OAS_prob.add_surface()
OAS_prob.add_desvar('wing.twist_cp', lower=-10., upper=15.)
OAS_prob.add_desvar('wing.sweep', lower=10., upper=30.)
OAS_prob.add_desvar('wing.dihedral', lower=-10., upper=20.)
OAS_prob.add_desvar('wing.taper', lower=.5, upper=2.)
OAS_prob.add_constraint('wing_perf.CL', equals=0.5)
OAS_prob.add_objective('wing_perf.CD', scaler=1e4)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CD'], 0.0038513637269919619, places=5)
if fortran_flag:
def test_aero_optimization_chord_monotonic(self):
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : True,
'record_db' : False,
'with_viscous' : False})
OAS_prob.add_surface({
'chord_cp' : np.random.random(5),
'num_y' : 11,
'monotonic_con' : ['chord'],
'span_cos_spacing' : 0.,
})
OAS_prob.add_desvar('wing.chord_cp', lower=0.1, upper=5.)
OAS_prob.add_desvar('alpha', lower=-10., upper=10.)
OAS_prob.add_constraint('wing_perf.CL', equals=0.1)
OAS_prob.add_constraint('wing.S_ref', equals=20)
OAS_prob.add_constraint('wing.monotonic_chord', upper=0.)
OAS_prob.add_objective('wing_perf.CD', scaler=1e4)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CD'], 0.00057432581266351113, places=5)
self.assertAlmostEqual(prob['wing.monotonic_chord'][0], -1.710374671671999, places=4)
if fortran_flag:
def test_aero_optimization_chord_monotonic_no_sym(self):
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : True,
'record_db' : False,
'symmetry' : False,
'with_viscous' : False})
OAS_prob.add_surface({
'chord_cp' : np.random.random(5),
'num_y' : 11,
'monotonic_con' : ['chord'],
'span_cos_spacing' : 0.,
})
OAS_prob.add_desvar('wing.chord_cp', lower=0.1, upper=5.)
OAS_prob.add_desvar('alpha', lower=-10., upper=10.)
OAS_prob.add_constraint('wing_perf.CL', equals=0.1)
OAS_prob.add_constraint('wing.S_ref', equals=20)
OAS_prob.add_constraint('wing.monotonic_chord', upper=0.)
OAS_prob.add_objective('wing_perf.CD', scaler=1e4)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CD'], 0.00057432581266351113, places=5)
self.assertAlmostEqual(prob['wing.monotonic_chord'][0], -1.710374671671999, places=2)
if fortran_flag:
def test_aero_viscous_optimization(self):
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : True,
'record_db' : False,
'with_viscous' : True})
OAS_prob.add_surface()
OAS_prob.add_desvar('wing.twist_cp', lower=-10., upper=15.)
OAS_prob.add_desvar('wing.sweep', lower=10., upper=30.)
OAS_prob.add_desvar('wing.dihedral', lower=-10., upper=20.)
OAS_prob.add_constraint('wing_perf.CL', equals=0.5)
OAS_prob.add_objective('wing_perf.CD', scaler=1e4)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CD'], 0.019234984422361764, places=5)
if fortran_flag:
def test_aero_viscous_chord_optimization(self):
# Need to use SLSQP here because SNOPT finds a different optimum
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : True,
'record_db' : False,
'optimizer' : 'SLSQP',
'with_viscous' : True})
OAS_prob.add_surface()
OAS_prob.add_desvar('wing.chord_cp', lower=0.1, upper=3.)
OAS_prob.add_desvar('alpha', lower=-10., upper=10.)
OAS_prob.add_constraint('wing_perf.CL', equals=0.5)
OAS_prob.add_constraint('wing.S_ref', equals=20)
OAS_prob.add_objective('wing_perf.CD', scaler=1e4)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CD'], 0.023570021288019886, places=5)
if fortran_flag:
def test_aero_multiple_opt(self):
OAS_prob = OASProblem({'type' : 'aero',
'optimize' : True,
'record_db' : False})
surf_dict = { 'name' : 'wing',
'span' : 5.,
'num_y' : 3,
'span_cos_spacing' : 0.}
OAS_prob.add_surface(surf_dict)
surf_dict.update({'name' : 'tail',
'offset' : np.array([0., 0., 10.])})
OAS_prob.add_surface(surf_dict)
OAS_prob.add_desvar('tail.twist_cp', lower=-10., upper=15.)
OAS_prob.add_desvar('tail.sweep', lower=10., upper=30.)
OAS_prob.add_desvar('tail.dihedral', lower=-10., upper=20.)
OAS_prob.add_desvar('tail.taper', lower=.5, upper=2.)
OAS_prob.add_constraint('tail_perf.CL', equals=0.5)
OAS_prob.add_objective('tail_perf.CD', scaler=1e4)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CL'], 0.41532382375677429, places=4)
self.assertAlmostEqual(prob['tail_perf.CL'], .5, places=5)
self.assertAlmostEqual(prob['wing_perf.CD'], .0075400306289957033, places=5)
self.assertAlmostEqual(prob['tail_perf.CD'], 0.008087914662238814, places=5)
class TestStruct(unittest.TestCase):
currentResult = []
def run(self, result=None):
self.currentResult.append(result) # remember result for use in tearDown
unittest.TestCase.run(self, result) # call superclass run method
def test_struct_analysis(self):
OAS_prob = OASProblem({'type' : 'struct',
'optimize' : False,
'record_db' : False})
surf_dict = {'symmetry' : False,
't_over_c' : 0.15}
OAS_prob.add_surface(surf_dict)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing.structural_weight'], 988.13495481064024, places=3)
def test_struct_analysis_symmetry(self):
OAS_prob = OASProblem({'type' : 'struct',
'optimize' : False,
'record_db' : False})
surf_dict = {'symmetry' : True,
't_over_c' : 0.15}
OAS_prob.add_surface(surf_dict)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing.structural_weight'], 988.13495481063956, places=3)
if fortran_flag:
def test_struct_optimization(self):
OAS_prob = OASProblem({'type' : 'struct',
'optimize' : True,
'record_db' : False})
OAS_prob.add_surface({'symmetry' : False,
't_over_c': 0.15})
OAS_prob.add_desvar('wing.thickness_cp', lower=0.001, upper=0.25, scaler=1e2)
OAS_prob.add_constraint('wing.failure', upper=0.)
OAS_prob.add_constraint('wing.thickness_intersects', upper=0.)
OAS_prob.add_objective('wing.structural_weight', scaler=1e-3)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing.structural_weight'], 1154.4491377169238, places=2)
def test_struct_optimization_symmetry(self):
OAS_prob = OASProblem({'type' : 'struct',
'optimize' : True,
'record_db' : False})
OAS_prob.add_surface({'t_over_c': 0.15})
OAS_prob.add_desvar('wing.thickness_cp', lower=0.001, upper=0.25, scaler=1e2)
OAS_prob.add_constraint('wing.failure', upper=0.)
OAS_prob.add_constraint('wing.thickness_intersects', upper=0.)
OAS_prob.add_objective('wing.structural_weight', scaler=1e-3)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing.structural_weight'], 1144.8503583047038, places=2)
if fortran_flag:
def test_struct_optimization_symmetry_exact(self):
OAS_prob = OASProblem({'type' : 'struct',
'optimize' : True,
'record_db' : False})
OAS_prob.add_surface({'exact_failure_constraint' : True,
't_over_c': 0.15})
OAS_prob.add_desvar('wing.thickness_cp', lower=0.001, upper=0.25, scaler=1e2)
OAS_prob.add_constraint('wing.failure', upper=0.)
OAS_prob.add_constraint('wing.thickness_intersects', upper=0.)
OAS_prob.add_objective('wing.structural_weight', scaler=1e-3)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing.structural_weight'], 1132.0650209475402, places=2)
class TestAeroStruct(unittest.TestCase):
currentResult = []
def run(self, result=None):
self.currentResult.append(result) # remember result for use in tearDown
unittest.TestCase.run(self, result) # call superclass run method
def test_aerostruct_analysis(self):
OAS_prob = OASProblem({'type' : 'aerostruct',
'optimize' : False,
'record_db' : False})
surf_dict = {'num_y' : 13,
'num_x' : 2,
'wing_type' : 'CRM',
'CD0' : 0.015,
'symmetry' : False}
OAS_prob.add_surface(surf_dict)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CL'], 0.6587983088529461, places=5)
self.assertAlmostEqual(prob['wing_perf.failure'], 0.13694402690795321, places=5)
self.assertAlmostEqual(prob['fuelburn'], 55565.087226705218, places=2)
self.assertAlmostEqual(prob['CM'][1], -0.18836163204083048, places=2)
def test_aerostruct_analysis_symmetry(self):
OAS_prob = OASProblem({'type' : 'aerostruct',
'optimize' : False,
'record_db' : False})
surf_dict = {'symmetry' : True,
'num_y' : 13,
'num_x' : 2,
'wing_type' : 'CRM',
'CD0' : 0.015}
OAS_prob.add_surface(surf_dict)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['wing_perf.CL'], 0.69060502679333224, places=5)
self.assertAlmostEqual(prob['wing_perf.failure'], 0.064535555449504969, places=5)
self.assertAlmostEqual(prob['fuelburn'], 57109.065516474155, places=1)
self.assertAlmostEqual(prob['CM'][1], -0.19380236992046351, places=2)
def test_aerostruct_analysis_symmetry_deriv(self):
OAS_prob = OASProblem({'type' : 'aerostruct',
'optimize' : False,
'record_db' : True})
surf_dict = {'symmetry' : True,
'num_y' : 7,
'num_x' : 2,
'wing_type' : 'CRM',
'CD0' : 0.015}
OAS_prob.add_surface(surf_dict)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
data = prob.check_partial_derivatives(out_stream=None)
new_dict = {}
for key1 in data.keys():
for key2 in data[key1].keys():
for key3 in data[key1][key2].keys():
if 'rel' in key3:
error = np.linalg.norm(data[key1][key2][key3])
new_key = key1+'_'+key2[0]+'_'+key2[1]+'_'+key3
new_dict.update({new_key : error})
for key in new_dict.keys():
error = new_dict[key]
if not np.isnan(error):
# The FD check is not valid for these cases
if 'assembly_forces_Iy' in key or 'assembly_forces_J' in key or \
'assembly_forces_A' in key or 'assembly_K_loads' in key or \
'assembly_forces_loads' in key or 'assembly_forces_Iz' in key or \
'assembly_forces_nodes' in key or 'CM_wing_S_ref' in key or \
'CM_rho' in key:
pass
elif 'K' in key or 'vonmises' in key:
self.assertAlmostEqual(0., error, places=0)
else:
self.assertAlmostEqual(0., error, places=2)
if fortran_flag:
def test_aerostruct_optimization(self):
OAS_prob = OASProblem({'type' : 'aerostruct',
'optimize' : True,
'with_viscous' : True,
'record_db' : False})
surf_dict = {'num_y' : 7,
'num_x' : 2,
'wing_type' : 'CRM',
'CD0' : 0.015,
'symmetry' : False,
'num_twist_cp' : 2,
'num_thickness_cp' : 2}
OAS_prob.add_surface(surf_dict)
OAS_prob.add_desvar('wing.twist_cp', lower=-15., upper=15.)
OAS_prob.add_desvar('wing.thickness_cp', lower=0.01, upper=0.5, scaler=1e2)
OAS_prob.add_constraint('wing_perf.failure', upper=0.)
OAS_prob.add_constraint('wing_perf.thickness_intersects', upper=0.)
OAS_prob.add_desvar('alpha', lower=-10., upper=10.)
OAS_prob.add_constraint('L_equals_W', equals=0.)
OAS_prob.add_objective('fuelburn', scaler=1e-5)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['fuelburn'], 96889.255792361335, places=0)
self.assertAlmostEqual(prob['wing_perf.failure'], 0., places=4)
self.assertAlmostEqual(prob['CM'][1], -0.14194155955058388, places=2)
if fortran_flag:
def test_aerostruct_optimization_symmetry(self):
OAS_prob = OASProblem({'type' : 'aerostruct',
'optimize' : True,
'with_viscous' : True,
'record_db' : False})
surf_dict = {'symmetry' : True,
'num_y' : 7,
'num_x' : 3,
'wing_type' : 'CRM',
'CD0' : 0.015,
'num_twist_cp' : 2,
'num_thickness_cp' : 2}
OAS_prob.add_surface(surf_dict)
OAS_prob.add_desvar('wing.twist_cp', lower=-15., upper=15.)
OAS_prob.add_desvar('wing.thickness_cp', lower=0.01, upper=0.5, scaler=1e2)
OAS_prob.add_constraint('wing_perf.failure', upper=0.)
OAS_prob.add_constraint('wing_perf.thickness_intersects', upper=0.)
OAS_prob.add_desvar('alpha', lower=-10., upper=10.)
OAS_prob.add_constraint('L_equals_W', equals=0.)
OAS_prob.add_objective('fuelburn', scaler=1e-4)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['fuelburn'], 96074.934265520889, places=0)
self.assertAlmostEqual(prob['wing_perf.failure'], 0, places=5)
if fortran_flag:
def test_aerostruct_optimization_symmetry_multiple(self):
OAS_prob = OASProblem({'type' : 'aerostruct',
'optimize' : True,
'with_viscous' : True,
'record_db' : False})
surf_dict = {'name' : 'wing',
'symmetry' : True,
'num_y' : 5,
'num_x' : 2,
'wing_type' : 'CRM',
'CD0' : 0.015,
'num_twist_cp' : 2,
'num_thickness_cp' : 2}
OAS_prob.add_surface(surf_dict)
surf_dict.update({'name' : 'tail',
'offset':np.array([10., 0., 10.])})
OAS_prob.add_surface(surf_dict)
# Add design variables and constraints for both the wing and tail
OAS_prob.add_desvar('wing.twist_cp', lower=-15., upper=15.)
OAS_prob.add_desvar('wing.thickness_cp', lower=0.01, upper=0.5, scaler=1e2)
OAS_prob.add_constraint('wing_perf.failure', upper=0.)
OAS_prob.add_constraint('wing_perf.thickness_intersects', upper=0.)
OAS_prob.add_desvar('tail.twist_cp', lower=-15., upper=15.)
OAS_prob.add_desvar('tail.thickness_cp', lower=0.01, upper=0.5, scaler=1e2)
OAS_prob.add_constraint('tail_perf.failure', upper=0.)
OAS_prob.add_constraint('tail_perf.thickness_intersects', upper=0.)
OAS_prob.add_desvar('alpha', lower=-10., upper=10.)
OAS_prob.add_constraint('L_equals_W', equals=0.)
OAS_prob.add_objective('fuelburn', scaler=1e-5)
OAS_prob.setup()
OAS_prob.run()
prob = OAS_prob.prob
self.assertAlmostEqual(prob['fuelburn'], 171158.11644279823, places=1)
self.assertAlmostEqual(prob['wing_perf.failure'], 0, places=5)
if __name__ == "__main__":
# Get user-supplied argument if provided
try:
arg = sys.argv[1]
arg_provided = True
except:
arg_provided = False
# Based on user input, run one subgroup of tests
if arg_provided:
if 'aero' == arg:
test_classes = [TestAero]
elif 'struct' == arg:
test_classes = [TestStruct]
elif 'aerostruct' == arg:
test_classes = [TestAeroStruct]
else:
arg = 'full'
test_classes = [TestAero, TestStruct, TestAeroStruct]
print()
print('+==================================================+')
print(' Running ' + arg + ' test suite')
print('+==================================================+')
print()
failures = []
errors = []
num_tests = 0
# Loop through each requested discipline test
for test_class in test_classes:
# Set up the test suite and run the tests corresponding to this subgroup
suite = unittest.TestLoader().loadTestsFromTestCase(test_class)
unittest.TextTestRunner().run(suite)
failures.extend(test_class.currentResult[-1].failures)
errors.extend(test_class.currentResult[-1].errors)
num_tests += len(test_class.currentResult)
# Print results and force an exit if an error or failure occurred
print()
if len(failures) or len(errors):
print("There have been errors or failures! Please check the log to " +
"see which tests failed.\n")
sys.exit(1)
else:
print("Successfully ran {} tests with no errors!\n".format(num_tests))