|
23 | 23 | # ---------------------------------------------------------------------- |
24 | 24 | def main(): |
25 | 25 | problem = setup() |
26 | | - output = problem.objective() |
27 | | - #uncomment these lines when you want to start an optimization problem from a different initial guess |
28 | | - ''' |
29 | | - inputs = [1.28, 1.38] |
30 | | - scaling = problem.optimization_problem.inputs[:,3] #have to rescale inputs to start problem from here |
31 | | - scaled_inputs = np.multiply(inputs,scaling) |
32 | | - problem.optimization_problem.inputs[:,1] = scaled_inputs |
33 | | - ''' |
34 | | - |
35 | | - #optimize |
| 26 | + |
| 27 | + ## Base Input Values |
| 28 | + #output = problem.objective() |
| 29 | + |
| 30 | + ## Uncomment to view contours of the design space |
| 31 | + #variable_sweep(problem) |
| 32 | + |
| 33 | + ## Uncomment for the first optimization |
36 | 34 | #output = scipy_setup.SciPy_Solve(problem,solver='SLSQP') |
37 | | - #print output |
38 | | - |
| 35 | + #print output |
39 | 36 |
|
40 | | - #variable_sweep(problem) #uncomment this to view some contours of the problem |
| 37 | + ## Uncomment these lines when you want to start an optimization problem from a different initial guess |
| 38 | + #inputs = [1.28, 1.38] |
| 39 | + #scaling = problem.optimization_problem.inputs[:,3] #have to rescale inputs to start problem from here |
| 40 | + #scaled_inputs = np.multiply(inputs,scaling) |
| 41 | + #problem.optimization_problem.inputs[:,1] = scaled_inputs |
| 42 | + |
41 | 43 | print 'fuel burn = ', problem.summary.base_mission_fuelburn |
42 | 44 | print 'fuel margin = ', problem.all_constraints() |
43 | 45 |
|
44 | | - #Plot_Mission.plot_mission(problem) |
| 46 | + Plot_Mission.plot_mission(problem) |
45 | 47 |
|
46 | 48 | return |
47 | 49 |
|
@@ -126,34 +128,24 @@ def setup(): |
126 | 128 | return nexus |
127 | 129 |
|
128 | 130 | def variable_sweep(problem): |
129 | | - number_of_points = 5 |
130 | | - outputs=carpet_plot(problem, number_of_points, 0, 0) #run carpet plot, suppressing default plots |
131 | | - inputs =outputs.inputs |
132 | | - objective=outputs.objective |
133 | | - constraints=outputs.constraint_val |
| 131 | + number_of_points = 20 |
| 132 | + outputs = carpet_plot(problem, number_of_points, 0, 0) #run carpet plot, suppressing default plots |
| 133 | + inputs = outputs.inputs |
| 134 | + objective = outputs.objective |
| 135 | + constraints = outputs.constraint_val |
134 | 136 | plt.figure(0) |
135 | | - CS = plt.contourf(inputs[0,:],inputs[1,:], objective, 20, linewidths=2) |
| 137 | + CS = plt.contourf(inputs[0,:],inputs[1,:], objective, 20, linewidths=2) |
136 | 138 | cbar = plt.colorbar(CS) |
137 | 139 |
|
138 | 140 | cbar.ax.set_ylabel('fuel burn (kg)') |
139 | | - CS_const=plt.contour(inputs[0,:],inputs[1,:], constraints[0,:,:]) |
| 141 | + CS_const = plt.contour(inputs[0,:],inputs[1,:], constraints[0,:,:]) |
140 | 142 | plt.clabel(CS_const, inline=1, fontsize=10) |
141 | 143 | cbar = plt.colorbar(CS_const) |
142 | 144 | cbar.ax.set_ylabel('fuel margin') |
143 | 145 |
|
144 | | - plt.xlabel('wing area (m^2)') |
145 | | - plt.ylabel('cruise_altitude (km)') |
146 | | - |
147 | | - #now plot optimization path (note that these data points were post-processed into a plottable format) |
148 | | - ''' |
149 | | - opt_1 = plt.plot(wing_1, alt_1, label='optimization path 1') |
150 | | - init_1 = plt.plot(wing_1[0], alt_1[0], 'ko') |
151 | | - final_1 = plt.plot(wing_1[-1], alt_1[-1], 'kx') |
| 146 | + plt.xlabel('Wing Area (m^2)') |
| 147 | + plt.ylabel('Cruise Altitude (km)') |
152 | 148 |
|
153 | | - opt_2 = plt.plot(wing_2, alt_2, 'k--', label='optimization path 2') |
154 | | - init_2 = plt.plot(wing_2[0], alt_2[0], 'ko', label= 'initial points') |
155 | | - final_2 = plt.plot(wing_2[-1], alt_2[-1], 'kx', label= 'final points') |
156 | | - ''' |
157 | 149 | plt.legend(loc='upper left') |
158 | 150 | plt.show(block=True) |
159 | 151 |
|
|
0 commit comments