Skip to content

Commit

Permalink
regression updates
Browse files Browse the repository at this point in the history
  • Loading branch information
planes committed May 11, 2020
1 parent a427678 commit 0e1c885
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 96 deletions.
8 changes: 4 additions & 4 deletions regression/scripts/Regional_Jet_Optimization/Optimize2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def main():

actual = Data()

actual.obj = 0.6597376929765844
actual.con = 1.1472174
actual.obj2 = 0.6739732443282955
actual.con3 = 1.21059794
actual.obj = 0.6472697676582065
actual.con = 2.25820087
actual.obj2 = 0.6797630188805102
actual.con3 = 2.44649677

print('Fuel Burn =', obj)
print('Fuel Margin =', con)
Expand Down
18 changes: 9 additions & 9 deletions regression/scripts/aerodynamics/aerodynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ def main():
#compute_aircraft_lift(conditions, configuration, geometry)

lift = state.conditions.aerodynamics.lift_coefficient
lift_r = np.array([-1.22715059, -0.48562864, -0.4312893 , -0.3442654 , -0.19773265,
0.12732151, 0.37221063, 0.60102923, 0.90031948, 1.26978863,
1.2846731 ])[:,None]
lift_r = np.array([-1.07644788, -0.42599003, -0.37832394, -0.30198719, -0.1734497 ,
0.11168553, 0.32650055, 0.52721862, 0.78975393, 1.11384968,
1.12690623])[:,None]

print('lift = ', lift)

Expand Down Expand Up @@ -244,9 +244,9 @@ def reg_values():
1.97066436e-04, 3.69256330e-05, 1.88894447e-09, 3.54759275e-11,
6.37419857e-05, 3.95877837e-03, 7.35755549e-14]]).T

cd_i_r = np.array([[0.06105457, 0.00969473, 0.00833303, 0.00485191, 0.00161951,
0.00064978, 0.00571189, 0.0154989 , 0.03335475, 0.06541178,
0.06815139]]).T
cd_i_r = np.array([[0.02050313, 0.00826837, 0.0073281 , 0.00489907, 0.00166702,
0.00107478, 0.00470895, 0.01120806, 0.02173496, 0.03730588,
0.04865803]]).T

cd_m_r = np.array([[ 0.0011752,0.0011752,0.0011752,0.0011752,0.0011752,
0.0011752,0.0011752,0.0011752,0.0011752,0.0011752,
Expand Down Expand Up @@ -275,9 +275,9 @@ def reg_values():
0.00653004,0.00501665,0.00599058,0.00759737,
0.00600963,0.00556283,0.00602578]]).T

cd_tot_r = np.array([[0.08031175, 0.02817425, 0.03669165, 0.02277785, 0.02127734,
0.0162443 , 0.02443606, 0.03891821, 0.05248558, 0.08775736,
0.08829963]]).T
cd_tot_r = np.array([[0.03894927, 0.02671936, 0.03566663, 0.02282595, 0.0213258 ,
0.0166778 , 0.02341306, 0.03454155, 0.0406334 , 0.05908934,
0.0684164 ]]).T

return cd_c_r, cd_i_r, cd_m_r, cd_m_fuse_base_r, cd_m_fuse_up_r, \
cd_m_nac_base_r, cd_m_ctrl_r, cd_p_fuse_r, cd_p_wing_r, cd_tot_r
Expand Down
2 changes: 1 addition & 1 deletion regression/scripts/concorde/results_mission_concorde.res

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions regression/scripts/lifting_line/lifting_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ def main():
# Test compute Lift
# --------------------------------------------------------------------
lift = state.conditions.aerodynamics.lift_coefficient
lift_r = np.array([-1.27291303,-0.9966004 ,-0.72028776,-0.44397513,
-0.16766249, 0.10865015, 0.38496278, 0.66127542,
0.93758805, 1.21390069, 1.49021333])[:,None]
lift_r = np.array([-1.11659038, -0.87421087, -0.63183137, -0.38945186, -0.14707236,
0.09530715, 0.33768665, 0.58006616, 0.82244566, 1.06482517,
1.30720467])[:,None]

print('lift = ', lift)

Expand Down
2 changes: 1 addition & 1 deletion regression/scripts/noise_optimization/Noise_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def main():
noise_cumulative_margin = objectives[0]

actual = Data()
actual.noise_cumulative_margin = 20.98780244500979
actual.noise_cumulative_margin = 21.085590711765263

error = Data()
error.noise_cumulative_margin = abs(actual.noise_cumulative_margin - noise_cumulative_margin)/actual.noise_cumulative_margin
Expand Down
4 changes: 2 additions & 2 deletions regression/scripts/noise_optimization/Procedure.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def estimate_clmax(nexus):
# Condition to CLmax calculation: 90KTAS @ 10000ft, ISA
conditions = Data()
conditions.freestream = Data()
conditions.freestream.density = 0.90477283
conditions.freestream.dynamic_viscosity = 1.69220918e-05
conditions.freestream.density = [0.90477283]
conditions.freestream.dynamic_viscosity = [1.69220918e-05]
conditions.freestream.velocity = 90. * Units.knots

#Takeoff CL_max
Expand Down
32 changes: 16 additions & 16 deletions regression/scripts/segments/segment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ def main():
descent_throttle_2 = results.segments.descent_2.conditions.propulsion.throttle[3][0]

# Truth values
climb_throttle_1_truth = 0.9857468628944336
climb_throttle_2_truth = 0.7952188198483993
climb_throttle_3_truth = 0.5066828579416367
climb_throttle_4_truth = 0.878134600022338
climb_throttle_5_truth = 1.021806039249955
climb_throttle_6_truth = 0.7136864572517849
climb_throttle_7_truth = 0.8877493204092387
climb_throttle_8_truth = 1.0868679444818625
cruise_CL_1_truth = 0.634777526547744
cruise_CL_2_truth = 0.6250634424249245
cruise_CL_3_truth = 0.7081424772096907
descent_throttle_1_truth = 0.17517658209416148
single_pt_CL_1_truth = 0.2588077147541633
single_pt_CL_2_truth = 0.25874688162066317
loiter_CL_truth = 0.5273996120576298
descent_throttle_2_truth = 0.15532873504026581
climb_throttle_1_truth = 1.2161368583680352
climb_throttle_2_truth = 1.0286455601603097
climb_throttle_3_truth = 0.4914388256260948
climb_throttle_4_truth = 0.8571027568586671
climb_throttle_5_truth = 0.9894122714719386
climb_throttle_6_truth = 0.6762603498943198
climb_throttle_7_truth = 0.8519667257766178
climb_throttle_8_truth = 1.0464547236050787
cruise_CL_1_truth = 0.6341101279210396
cruise_CL_2_truth = 0.6257545720064928
cruise_CL_3_truth = 0.705480454862047
descent_throttle_1_truth = 0.0807508137286019
single_pt_CL_1_truth = 0.25937963745079545
single_pt_CL_2_truth = 1.4915004256240918
loiter_CL_truth = 0.5284986930857494
descent_throttle_2_truth = 0.13671073467701336

# Store errors
error = Data()
Expand Down
4 changes: 2 additions & 2 deletions regression/scripts/sizing_loop/sizing_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def main():
results = nexus.results
err = nexus.sizing_loop.norm_error

err_true = 0.0017121126327114442
err_true = 0.0035657111473885845
error = abs((err-err_true)/err_true)

data_inputs, data_outputs, read_success = read_sizing_residuals(sizing_loop, problem.inputs)
check_read_res = -0.08366387990897325
check_read_res = -0.11199816214846839

error_res = abs((data_outputs[1][0]-check_read_res)/check_read_res)

Expand Down
40 changes: 20 additions & 20 deletions regression/scripts/slipstream/slipstream_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main():

# lift coefficient
lift_coefficient = results.segments.cruise.conditions.aerodynamics.lift_coefficient[1][0]
lift_coefficient_true = 0.47277854912172756
lift_coefficient_true = 0.47195035931255075
print(lift_coefficient)
diff_CL = np.abs(lift_coefficient - lift_coefficient_true)
print('CL difference')
Expand All @@ -48,21 +48,21 @@ def main():

# sectional lift coefficient check
sectional_lift_coeff = results.segments.cruise.conditions.aerodynamics.lift_breakdown.inviscid_wings_sectional_lift[0]
sectional_lift_coeff_true = np.array([1.30785100e-01, 1.29573061e-01, 1.25529913e-01, 1.19252449e-01,
1.11143124e-01, 1.01521133e-01, 9.06611205e-02, 7.88194883e-02,
6.62645393e-02, 5.33188318e-02, 4.04067325e-02, 2.80607103e-02,
1.68588961e-02, 7.56561908e-03, 1.51112918e-03, 1.30847294e-01,
1.29743713e-01, 1.25770313e-01, 1.19520253e-01, 1.11404695e-01,
1.01755340e-01, 9.08577590e-02, 7.89758953e-02, 6.63824787e-02,
5.34023668e-02, 4.04611083e-02, 2.80919505e-02, 1.68735644e-02,
7.57031938e-03, 1.51169375e-03, 2.28686698e-03, 2.39010336e-03,
2.48594024e-03, 2.56050765e-03, 2.59254004e-03, 2.56508092e-03,
2.46776333e-03, 2.29377774e-03, 2.04285167e-03, 1.72410497e-03,
1.35485739e-03, 9.60298290e-04, 5.77024161e-04, 2.55662292e-04,
5.08508154e-05, 2.28750242e-03, 2.39200290e-03, 2.48885107e-03,
2.56406472e-03, 2.59638239e-03, 2.56889806e-03, 2.47131117e-03,
2.29687440e-03, 2.04537787e-03, 1.72600969e-03, 1.35615751e-03,
9.61070620e-04, 5.77392626e-04, 2.55779663e-04, 5.08646276e-05,
sectional_lift_coeff_true = np.array([1.46119243e-01, 1.44958967e-01, 1.40691164e-01, 1.33934602e-01,
1.25106762e-01, 1.14539760e-01, 1.02522103e-01, 8.93282976e-02,
7.52534595e-02, 6.06620465e-02, 4.60423586e-02, 3.20130513e-02,
1.92496660e-02, 8.64213099e-03, 1.72540808e-03, 1.46196644e-01,
1.45171946e-01, 1.40992335e-01, 1.34271561e-01, 1.25437402e-01,
1.14837212e-01, 1.02773015e-01, 8.95287753e-02, 7.54052650e-02,
6.07699716e-02, 4.61128354e-02, 3.20536469e-02, 1.92687646e-02,
8.64825925e-03, 1.72614457e-03, 4.38671022e-03, 4.55001036e-03,
4.66682694e-03, 4.72118604e-03, 4.68980769e-03, 4.55491812e-03,
4.30701096e-03, 3.94199437e-03, 3.46475306e-03, 2.89241422e-03,
2.25312811e-03, 1.58632336e-03, 9.48729145e-04, 4.19170945e-04,
8.32865503e-05, 4.38914132e-03, 4.55717251e-03, 4.67748090e-03,
4.73370729e-03, 4.70277821e-03, 4.56728781e-03, 4.31807938e-03,
3.95133440e-03, 3.47215673e-03, 2.89786562e-03, 2.25677825e-03,
1.58845898e-03, 9.49736436e-04, 4.19489381e-04, 8.33239105e-05,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
Expand Down Expand Up @@ -146,7 +146,7 @@ def base_analysis(vehicle):

# ------------------------------------------------------------------
# Weights
weights = SUAVE.Analyses.Weights.Weights_Tube_Wing()
weights = SUAVE.Analyses.Weights.Weights_Transport()
weights.vehicle = vehicle
analyses.append(weights)

Expand Down Expand Up @@ -216,10 +216,10 @@ def mission_setup(analyses,vehicle):
base_segment.process.iterate.initials.initialize_battery = SUAVE.Methods.Missions.Segments.Common.Energy.initialize_battery
base_segment.process.iterate.conditions.planet_position = SUAVE.Methods.skip
base_segment.state.numerics.number_control_points = 2
base_segment.process.iterate.unknowns.network = vehicle.propulsors.propulsor.unpack_unknowns
base_segment.process.iterate.residuals.network = vehicle.propulsors.propulsor.residuals
base_segment.process.iterate.unknowns.network = vehicle.propulsors.battery_propeller.unpack_unknowns
base_segment.process.iterate.residuals.network = vehicle.propulsors.battery_propeller.residuals
base_segment.state.unknowns.propeller_power_coefficient = 0.2 * ones_row(1)
bat = vehicle.propulsors.propulsor.battery
bat = vehicle.propulsors.battery_propeller.battery
base_segment.state.unknowns.battery_voltage_under_load = bat.max_voltage * ones_row(1)
base_segment.state.residuals.network = 0. * ones_row(2)
base_segment.max_energy = bat.max_energy
Expand Down
8 changes: 4 additions & 4 deletions regression/scripts/solar_network/solar_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ def main():
energy = results.segments.cruise1.conditions.propulsion.battery_energy[8,0]

# Truth results
truth_F = 106.17937888428949
truth_rpm = 160.76100043739908
truth_i = 131.4126494489281
truth_bat = 88521341.18491648
truth_F = 362.85769809909533
truth_rpm = 253.22473731901562
truth_i = 142.1902845645215
truth_bat = 100157292.65998347

print('battery energy')
print(energy)
Expand Down
2 changes: 1 addition & 1 deletion regression/scripts/solar_network/solar_uav_mission.res

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions regression/scripts/sweeps/test_sweeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main():
[ 'cruise_altitude' , 11, ( 10 , 13. ) , 10. , Units.km]])

outputs_sweep = linear_sweep(problem)
truth_obj_sweeps = [[6739.73244319, 6595.26198099]]
truth_obj_sweeps = [[6797.67968084, 6522.77993438]]

#print outputs_sweep
max_err_sweeps = (np.max(np.abs(outputs_sweep['objective']-truth_obj_sweeps )/truth_obj_sweeps))
Expand All @@ -40,7 +40,7 @@ def main():
outputs_carpet = variable_sweep(problem)

#print outputs_carpet
truth_obj_carp = [[6641.92992406, 6631.87070262],[6923.62495863, 6476.54755072]]
truth_obj_carp = [[6551.06765041, 6451.17553565],[6997.00098209, 6500.79231882]]
max_err_carp = np.max(np.abs(outputs_carpet['objective']-truth_obj_carp)/truth_obj_carp)
print(' max_err_carp = ', max_err_carp)
assert(max_err_carp<1e-6)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def main():

plot_results(results)

distance_regression = 4178523.102867511
distance_regression = 4255957.25870598
distance_calc = results.conditions.frames.inertial.position_vector[-1,0]
error_distance = abs((distance_regression - distance_calc )/distance_regression)
assert error_distance < 1e-6

error_weight = abs(mission.target_landing_weight - results.conditions.weights.total_mass[-1,0])
print('landing weight error' , error_weight)
assert error_weight < 1e-4
assert error_weight < 1e-3

return

Expand Down
35 changes: 6 additions & 29 deletions trunk/SUAVE/Methods/Missions/Segments/converge_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
# Created: Jul 2014, SUAVE Team
# Modified: Jan 2016, E. Botero
# May 2019, E. Botero

# ----------------------------------------------------------------------
# Imports
Expand Down Expand Up @@ -36,27 +35,13 @@ def converge_root(segment):
Outputs:
state.unknowns [Any]
segment.state.numerics.converged [Unitless]
segment.state.normalization_factor [Array]
Properties Used:
N/A
"""

unknowns = segment.state.unknowns.pack_array()

# Find the normalization factors
segment.state.unknowns_normalization_factor = unknowns*1.
segment.state.unknowns_normalization_factor[segment.state.unknowns_normalization_factor==0] = 1e-16

# Run one iteration to get the scaling
segment.process.iterate(segment)
segment.state.residual_normalization_factor = 1*segment.state.residuals.pack_array()
segment.state.residual_normalization_factor[segment.state.residual_normalization_factor==0] = 1e-16

# Normalize the unknowns
unknowns = unknowns/segment.state.unknowns_normalization_factor


try:
root_finder = segment.settings.root_finder
except AttributeError:
Expand All @@ -72,10 +57,8 @@ def converge_root(segment):
print("Segment did not converge. Segment Tag: " + segment.tag)
print("Error Message:\n" + msg)
segment.state.numerics.converged = False
segment.converged = False
else:
segment.state.numerics.converged = True
segment.converged = True


return
Expand All @@ -96,28 +79,22 @@ def iterate(unknowns, segment):
N/A
Inputs:
state.unknowns [Data]
segment.process.iterate [Data]
segment.state.normalization_factor [array]
state.unknowns [Data]
segment.process.iterate [Data]
Outputs:
residuals [Unitless]
Properties Used:
N/A
"""

unknowns_normal = segment.state.unknowns_normalization_factor * unknowns

if isinstance(unknowns_normal,array_type):
segment.state.unknowns.unpack_array(unknowns_normal)
if isinstance(unknowns,array_type):
segment.state.unknowns.unpack_array(unknowns)
else:
segment.state.unknowns_normal = unknowns_normal
segment.state.unknowns = unknowns

segment.process.iterate(segment)

residuals = segment.state.residuals.pack_array()

residuals_normalized = residuals/segment.state.residual_normalization_factor

return residuals_normalized
return residuals

0 comments on commit 0e1c885

Please sign in to comment.