-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimization.html
More file actions
290 lines (215 loc) · 14.6 KB
/
optimization.html
File metadata and controls
290 lines (215 loc) · 14.6 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
<!DOCTYPE HTML>
<!--
Arcana by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Optimization Code Structure</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="https://suave.stanford.edu/assets/css/main.css" />
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-132339206-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-132339206-1');
</script>
</head>
<body class="is-preload">
<div id="page-wrapper">
<!-- Header -->
<div id="header">
<!-- Logo -->
<a hidden id="logo">SUAVE</a>
<!-- Nav -->
<nav id="nav">
<ul>
<li><a href="https://suave.stanford.edu/index.html"> SUAVE</a></li>
<li><a href="https://suave.stanford.edu/download.html">Download</a></li>
<li><a href="https://suave.stanford.edu/tutorials.html">Tutorials</a></li>
<li class="current"><a href="https://suave.stanford.edu/documentation.html">Documentation</a></li>
<li><a href="https://suave.stanford.edu/forum.html">Forum</a></li>
<li><a href="https://suave.stanford.edu/publications.html">Publications</a></li>
<li><a href="https://github.com/suavecode/SUAVE">
<span class="icon2 icon-github">
<img src="https://suave.stanford.edu/images/github_white.svg">
</span>
</a></li>
<li><a href="https://travis-ci.org/suavecode/SUAVE">
<span class="icon2 icon-travis">
<img src="https://suave.stanford.edu/images/travis_white.svg">
</span>
</a></li>
<li><a href="https://coveralls.io/github/suavecode/SUAVE">
<span class="icon2 icon-coveralls">
<img src="https://suave.stanford.edu/images/coveralls.svg">
</span>
</a></li>
</ul>
</nav>
</div>
<!-- Main -->
<section class="wrapper style1">
<div class="container">
<div id="content">
<!-- Content -->
<article class="content">
<h2 id="optimization-code-structure">Optimization Code Structure</h2>
<p>This is an overview of how optimization is done in SUAVE. A specific tutorial case is also available <a href="https://suave.stanford.edu/tutorials/jet_optimization.html">here</a>.</p>
<h3 id="nexus-class">Nexus Class</h3>
<p>The Nexus class is the underlying data structure that is used for optimization. It is created to hold all data and functionality needed to link together optimizers and the various analysis modules in SUAVE. Detailed information on each of the functions can be found on our <a href="/doxygen">doxygen page</a>.</p>
<h3 id="standard-optimization-file-structure">Standard Optimization File Structure</h3>
<p>These are the standard files that are used in the optimization process. They are typically stored as Optimize.py, Vehicle.py, Analysis.py, Mission.py, Procedure.py, and Plot_Mission.py. These names can be changed if desired.</p>
<h4 id="optimize">Optimize</h4>
<p>This is the top level file that is run to perform the optimization. Inputs, objective, constraints, and aliases are specified here. The inputs have an initial value, bounds, a scaling factor, and the units used. This provides later functions with the information needed to vary the parameters. Units.less indicates a unitless quantity. SI units are the default in SUAVE’s internal calculations, so Units.meter will not modify the internal value, while something like Units.foot will.</p>
<div class="highlight_code"><div class="highlight_code"><pre class="highlight_code"><code>problem.inputs = np.array([
[ 'wing_area' , 125. , ( 120. , 180. ) , 100. , Units.meter**2],
[ 'aspect_ratio' , 3.3 , ( 2.0 , 6.0 ) , 10. , Units.less],
])
</code></pre></div></div>
<p>Constraints and the objective are similar. Both have scaling quantities and constraints also have bounds.</p>
<div class="highlight_code"><div class="highlight_code"><pre class="highlight_code"><code>problem.constraints = np.array([
[ 'design_range_fuel_margin', '>', 0., 1E-1, Units.less]
])
problem.objective = np.array([
['fuel_burn_rate', 1., Units.kg/Units.s]
])
</code></pre></div></div>
<p>Finally we have aliases. This provides the optimization process with the position of the various parameters in the data structure. Aliases are used so that short names can be used for variables and a single variable can control multiple items in the data structure. Controlling multiple items can be important if different vehicle configurations are used at different points in the mission, and one of the vehicle parameters should change in the same way for all of the configurations. We can use * as a wildcard. This is used below to change the aspect ratio of the main wing in every vehicle configuration.</p>
<div class="highlight_code"><div class="highlight_code"><pre class="highlight_code"><code>problem.aliases = [
[ 'wing_area' , ['vehicle_configurations.base.wings.main_wing.areas.reference',
'vehicle_configurations.base.reference_area']],
[ 'aspect_ratio' , 'vehicle_configurations.*.wings.main_wing.aspect_ratio' ],
[ 'fuel_burn_rate' , 'summary.fuel_burn_rate' ],
]
</code></pre></div></div>
<p>This file then specifies the configurations, analyses, missions, and procedure that will be used. This are typically contained in separate files and more details on each are below. Once all of this is specified, the desired optimizer is called with the nexus class created by this setup.</p>
<h4 id="vehicle-setup">Vehicle Setup</h4>
<p>This contains the vehicle information such as geometric data and configurations. It is the same as the vehicle setup used for basic analysis purposes.</p>
<h4 id="analysis-setup">Analysis Setup</h4>
<p>This contains information on what analyses should be run for the vehicle. For example if correlation-based aerodynamics or AVL should be used for computations. It requires vehicle information from the previous step.</p>
<h4 id="mission-setup">Mission Setup</h4>
<p>This is also the same as the standard mission setup. It determines how the mission will be flown. It requires analysis information from the previous step.</p>
<h4 id="procedure">Procedure</h4>
<p>This is an optimization specific file that determines how the vehicle, analysis, or mission is modified with the input values in the optimization and also runs the mission. For example, changing the wing area will usually require changes to other wing parameters, such as root chord length. This module reads the new inputs and changes other values accordingly based on user specified processes.</p>
<h4 id="plotting">Plotting</h4>
<p>This function is not necessary to the optimization, but is often included in the files used and is added to the optimize main call as a way to visualize the results.</p>
<h3 id="optimizer-interface">Optimizer Interface</h3>
<p>The other step that must be taken to perform an optimization is to convert the standardized input above into values that can be used by the selected optimizer. This is done through a separate script for each optimizer, all of which are found in the <a href="https://github.com/suavecode/SUAVE/tree/develop/trunk/SUAVE/Optimization">optimization folder</a>.</p>
<p>For example, if we are using PyOpt to optimize, we might use <code class="highlight_code">output = pyopt_setup.Pyopt_Solve(problem,solver='SNOPT')</code> in the main function of the top level optimizer. This function reads the inputs, constraints, and objective and converts them to a format that the selected optimizer (SNOPT here) can understand.</p>
<h3 id="evaluation-process">Evaluation Process</h3>
<p>This shows the typical evaluation process, including where items like inputs and aliases are used. This chart assumes a single objective call, but some optimizers will include calls such as <code class="highlight_code">all_constraints</code> which require another evaluation. If the evaluation is a duplicate, data from the previous evaluation will be used instead of stepping through the procedure again.</p>
<p> </p>
<p><img src="https://suave.stanford.edu/images/opt_flow.png" width="600" height="338" /></p>
<p> </p>
<h3 id="incorporating-multi-fidelity">Incorporating Multi-fidelity</h3>
<p>Multiple levels of fidelity are designed to be relatively easy to incorporate in SUAVE, but there are still a few things to keep in mind. First, the chosen optimizer must support multi-fidelity and be able to change the <code class="highlight_code">nexus.fidelity_level</code> value. Once this is done, it is also important to remember that the mission is set up based on the analyses. This means that if a change is made to the analyses then the mission must be rebuilt with the new settings. As an example, code below for changing the analysis level is shown. This is a function that has been added to the procedure file.</p>
<div class="highlight_code"><div class="highlight_code"><pre class="highlight_code"><code>def set_fidelity_level(nexus):
if nexus.has_key('fidelity_level') == False:
print 'Fidelity level not set, defaulting to 1'
nexus.fidelity_level = 1
if nexus.fidelity_level == 2:
aerodynamics = SUAVE.Analyses.Aerodynamics.Supersonic_OpenVSP_Wave_Drag()
aerodynamics.settings.number_slices = 20
aerodynamics.settings.number_rotations = 10
elif nexus.fidelity_level == 1:
aerodynamics = SUAVE.Analyses.Aerodynamics.Supersonic_Zero()
else:
raise ValueError('Selected fidelity level not supported')
aerodynamics.geometry = copy.deepcopy(nexus.vehicle_configurations.base)
nexus.analyses.base.append(aerodynamics)
nexus.missions = mission_as2.setup(nexus.analyses)
return nexus
</code></pre></div></div>
<p>Here we see that <code class="highlight_code">nexus.missions</code> has been updated in addition to <code class="highlight_code">nexus.analyses</code>, since failing to do this would have the mission run with the previous analysis settings.</p>
<h3 id="key-functions-in-the-optimizer-setup">Key Functions in the Optimizer Setup</h3>
<p>We briefly mentioned how optimization parameters would need to be converted so that they could run with a particular optimizer. Here we show how this is managed and show which functions are likely to be useful in building a new optimizer setup.</p>
<p>The key items that will be needed for most optimizers are shown below, taken from the PyOpt setup:</p>
<div class="highlight_code"><div class="highlight_code"><pre class="highlight_code"><code>inp = problem.optimization_problem.inputs
obj = problem.optimization_problem.objective
con = problem.optimization_problem.constraints
# Set inputs
nam = inp[:,0] # Names
ini = inp[:,1] # Initials
bnd = inp[:,2] # Bounds
scl = inp[:,3] # Scale
typ = inp[:,4] # Type
</code></pre></div></div>
<p>These can be scaled with two helper functions that are part of the SUAVE distribution:</p>
<div class="highlight_code"><div class="highlight_code"><pre class="highlight_code"><code>from SUAVE.Optimization import helper_functions as help_fun
bnd_constraints = help_fun.scale_const_bnds(con)
scaled_constraints = help_fun.scale_const_values(con,bnd_constraints)
x = ini/scl
</code></pre></div></div>
<p>What happens next is entirely dependent on what optimizer you want to use. Some may require that constraint bounds happen at 0 or are either > or <. However this setup is done, you will likely need to create a function that can accept the problem and inputs and give required outputs such as the objective value and constraints. In the PyOpt case, this is done with a simple wrapper and an added function:</p>
<div class="highlight_code"><div class="highlight_code"><pre class="highlight_code"><code>mywrap = lambda x:PyOpt_Problem(problem,x)
</code></pre></div></div>
<p>…</p>
<div class="highlight_code"><div class="highlight_code"><pre class="highlight_code"><code>def PyOpt_Problem(problem,x):
obj = problem.objective(x)
const = problem.all_constraints(x).tolist()
fail = np.array(np.isnan(obj.tolist()) or np.isnan(np.array(const).any())).astype(int)
print 'Inputs'
print x
print 'Obj'
print obj
print 'Con'
print const
return obj,const,fail
</code></pre></div></div>
<p>Please visit our <a href="https://suave.stanford.edu/forum.html">forum</a> if you have any other questions on how the optimizer interface works or how to convert the values to what you need.</p>
<br>
</article>
</div>
</div>
</section>
<!-- Footer -->
<div id="footer">
<div class="container">
<div class="row">
<section class="col-3 col-6-narrower col-12-mobilep">
<h3>Download</h3>
<ul class="links">
<li><a href="https://suave.stanford.edu/registration.html">Registration</a></li>
<li><a href="https://github.com/suavecode/SUAVE">Github Site</a></li>
</ul>
</section>
<section class="col-3 col-6-narrower col-12-mobilep">
<h3>Learn</h3>
<ul class="links">
<li><a href="https://suave.stanford.edu/tutorials.html">Tutorials</a></li>
<li><a href="https://suave.stanford.edu/documentation.html">Documentation</a></li>
<li><a href="https://suave.stanford.edu/forum.html">Forum</a></li>
</ul>
</section>
<section class="col-3 col-6-narrower col-12-mobilep">
<h3>External Links</h3>
<ul class="links">
<li><a href="http://adl.stanford.edu">Aerospace Design Lab</a></li>
<li><a href="https://aa.stanford.edu">Stanford Aero/Astro</a></li>
<li><a href="https://su2code.github.io">SU2</a></li>
</ul>
</section>
</div>
<!-- Copyright -->
<div class="copyright">
<ul class="menu">
<li>© <script>document.write(new Date().getFullYear())</script> Stanford Aerospace Design Lab <br/>
All rights reserved</li>
</ul>
</div>
</div>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.dropotron.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>