-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_spatialbeam.py
102 lines (80 loc) · 3.83 KB
/
run_spatialbeam.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
""" Example runscript to perform structural-only optimization.
Call as `python run_spatialbeam.py 0` to run a single analysis, or
call as `python run_spatialbeam.py 1` to perform optimization.
To run with multiple structural components instead of a single one,
call as `python run_spatialbeam.py 0m` to run a single analysis, or
call as `python run_spatialbeam.py 1m` to perform optimization.
"""
from __future__ import division, print_function
import sys
from time import time
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
# Suppress warnings
import warnings
warnings.filterwarnings("ignore")
if __name__ == "__main__":
# Make sure that the user-supplied input is one of the valid options
input_options = ['0', '0m', '1', '1m']
print_str = ''.join(str(e) + ', ' for e in input_options)
# Parse the user-supplied command-line input and store it as input_arg
try:
input_arg = sys.argv[1]
if input_arg not in input_options:
raise(IndexError)
except IndexError:
print('\n +---------------------------------------------------------------+')
print(' | ERROR: Please supply a correct input argument to this script. |')
print(' | Possible options are ' + print_str[:-2] + ' |')
print(' | See the docstring at the top of this file for more info. |')
print(' +---------------------------------------------------------------+\n')
raise
# Set problem type
prob_dict = {'type' : 'struct'}
if sys.argv[1].startswith('0'): # run analysis once
prob_dict.update({'optimize' : False})
else: # perform optimization
prob_dict.update({'optimize' : True})
num_y = 11
loads = np.zeros(((num_y+1)//2, 6))
loads[:, 1] = 1e5
# Instantiate problem and add default surface
OAS_prob = OASProblem(prob_dict)
OAS_prob.add_surface({'name' : 'wing',
'num_y' : 11,
'symmetry' : True,
'loads' : loads})
# Single lifting surface
if not sys.argv[1].endswith('m'):
# Setup problem and add design variables, constraint, and objective
OAS_prob.add_desvar('wing.thickness_cp', lower=0.001, upper=0.25, scaler=1e2)
OAS_prob.add_constraint('wing.thickness_intersects', upper=0.)
OAS_prob.add_constraint('wing.failure', upper=0.)
OAS_prob.add_objective('wing.structural_weight', scaler=1e-3)
OAS_prob.setup()
# Multiple lifting surfaces
else:
# Add additional lifting surface
OAS_prob.add_surface({'name' : 'tail',
'span' : 3.,
'offset' : np.array([10., 0., 0.])})
OAS_prob.add_desvar('wing.thickness_cp', lower=0.001, upper=0.25, scaler=1e2)
OAS_prob.add_constraint('wing.thickness_intersects', upper=0.)
OAS_prob.add_constraint('wing.failure', upper=0.)
OAS_prob.add_objective('wing.structural_weight', scaler=1e-3)
# Note that these tail variables have no effect on the wing and thus
# have no need to be changed except to satisfy the failure constraint
OAS_prob.add_desvar('tail.thickness_cp', lower=0.001, upper=0.25, scaler=1e2)
OAS_prob.add_constraint('tail.thickness_intersects', upper=0.)
OAS_prob.add_constraint('tail.failure', upper=0.)
# Setup problem
OAS_prob.setup()
st = time()
# Actually run the problem
OAS_prob.run()
print("\nWing structural weight:", OAS_prob.prob['wing.structural_weight'])
print("Time elapsed: {} secs".format(time() - st))