prob.model.nonlinear_solver=NewtonSolver() prob.model.linear_solver = DirectSolver(assemble_jac=True) prob.model.nonlinear_solver.options['solve_subsystems'] = True prob.model.nonlinear_solver.options['maxiter'] = 10 prob.model.nonlinear_solver.options['atol'] = 1e-6 prob.model.nonlinear_solver.options['rtol'] = 1e-6 prob.driver = ScipyOptimizeDriver() return prob if __name__ == "__main__": n_int_per_seg = 5 prob = define_analysis(n_int_per_seg) mission_segments=['climb','cruise','descent'] nn, nn_tot_to, nn_tot_m, nn_tot = compute_num_nodes(n_int_per_seg, mission_segments) run_type = 'analysis' if run_type == 'optimization': print('======Performing Multidisciplinary Design Optimization===========') prob.model.add_design_var('ac|weights|MTOW', lower=2500, upper=3500) prob.model.add_design_var('ac|geom|wing|S_ref',lower=9,upper=30) prob.model.add_design_var('ac|propulsion|engine|rating',lower=500,upper=1400) prob.model.add_design_var('ac|weights|W_fuel_max',lower=800,upper=3000) prob.model.add_constraint('design_mission.residuals.MTOW_margin',equals=0.0) prob.model.add_constraint('design_mission.residuals.fuel_capacity_margin',equals=0.0) prob.model.add_constraint('takeoff.distance_continue',upper=807) prob.model.add_constraint('takeoff.vstall.Vstall_eas',upper=41.88) # prob.model.add_design_var('mission_eas_climb',lower=85,upper=300) # prob.model.add_design_var('mission_eas_cruise',lower=150,upper=300) elif run_type == 'max_range':
def setup(self): n_int_per_seg = self.options['n_int_per_seg'] mission_segments = ['climb','cruise','descent'] nn, nn_tot_to, nn_tot_m, nn_tot = compute_num_nodes(n_int_per_seg, mission_segments) #Define input variables dv_comp = self.add_subsystem('dv_comp',DictIndepVarComp(acdata,seperator='|'),promotes_outputs=["*"]) #eventually replace the following aerodynamic parameters with an analysis module (maybe OpenAeroStruct) dv_comp.add_output_from_dict('ac|aero|CLmax_flaps30') dv_comp.add_output_from_dict('ac|aero|polar|e') dv_comp.add_output_from_dict('ac|aero|polar|CD0_TO') dv_comp.add_output_from_dict('ac|aero|polar|CD0_cruise') dv_comp.add_output_from_dict('ac|geom|wing|S_ref') dv_comp.add_output_from_dict('ac|geom|wing|AR') dv_comp.add_output_from_dict('ac|geom|wing|c4sweep') dv_comp.add_output_from_dict('ac|geom|wing|taper') dv_comp.add_output_from_dict('ac|geom|wing|toverc') dv_comp.add_output_from_dict('ac|geom|hstab|S_ref') dv_comp.add_output_from_dict('ac|geom|hstab|c4_to_wing_c4') dv_comp.add_output_from_dict('ac|geom|vstab|S_ref') dv_comp.add_output_from_dict('ac|geom|fuselage|S_wet') dv_comp.add_output_from_dict('ac|geom|fuselage|width') dv_comp.add_output_from_dict('ac|geom|fuselage|length') dv_comp.add_output_from_dict('ac|geom|fuselage|height') dv_comp.add_output_from_dict('ac|geom|nosegear|length') dv_comp.add_output_from_dict('ac|geom|maingear|length') dv_comp.add_output_from_dict('ac|weights|MTOW') dv_comp.add_output_from_dict('ac|weights|W_fuel_max') dv_comp.add_output_from_dict('ac|weights|MLW') dv_comp.add_output_from_dict('ac|propulsion|engine|rating') dv_comp.add_output_from_dict('ac|propulsion|propeller|diameter') dv_comp.add_output_from_dict('ac|num_passengers_max') dv_comp.add_output_from_dict('ac|q_cruise') mission_data_comp = self.add_subsystem('mission_data_comp',DictIndepVarComp(missiondata),promotes_outputs=["*"]) mission_data_comp.add_output_from_dict('takeoff|h') mission_data_comp.add_output_from_dict('climb|h0') mission_data_comp.add_output_from_dict('climb|time') mission_data_comp.add_output_from_dict('climb|Ueas') mission_data_comp.add_output_from_dict('cruise|h0') mission_data_comp.add_output_from_dict('cruise|Ueas') mission_data_comp.add_output_from_dict('descent|h0') mission_data_comp.add_output_from_dict('descent|hf') mission_data_comp.add_output_from_dict('descent|time') mission_data_comp.add_output_from_dict('descent|Ueas') mission_data_comp.add_output_from_dict('design_range') mission_data_comp.add_output_from_dict('payload') #==Define control settings for the propulsion system. # Recall that all flight points including takeoff roll are calculated all at once # The structure of the takeoff vector should be: #[ nn points (takeoff at full power, v0 to v1), # nn points (takeoff at engine-out power (if applicable), v1 to vr), # nn points (hard braking at zero power or even reverse, vr to v0), # !CAUTION! 1 point (transition at OEI power (if applicable), v_trans) # !CAUTION! 1 point (v2 climb at OEI power (if app), v2) # ] # The mission throttle vector should be set implicitly using the optimizer (driving T = D + sin(gamma)mg residual to 0) controls = self.add_subsystem('controls',IndepVarComp()) #set the prop to 2000 rpm for all time controls.add_output('prop|rpm|takeoff', val=np.ones(nn_tot_to) * 2000, units='rpm') controls.add_output('prop|rpm|mission', val=np.ones(nn_tot_m) * 2000, units='rpm') TO_throttle_vec = np.concatenate([np.ones(nn), np.ones(nn) * 1.0, np.zeros(nn), np.ones(2) * 1.0])/1.21 controls.add_output('motor|throttle|takeoff', val=TO_throttle_vec) self.add_subsystem('takeoff',BalancedFieldLengthTakeoff(n_int_per_seg=n_int_per_seg, track_fuel=True, track_battery=False, propulsion_system=TurbopropPropulsionSystem(num_nodes=nn_tot_to)), promotes_inputs=['ac|aero*','ac|geom|*','ac|propulsion|*','ac|weights|*','takeoff|h']) self.connect('controls.prop|rpm|takeoff','takeoff.propmodel.prop1.rpm') self.connect('controls.motor|throttle|takeoff', 'takeoff.propmodel.throttle') mission_promote_inputs = ["ac|aero|*","ac|geom|*",'ac|propulsion|*','ac|weights|*','OEW','*|Ueas','*|h0','*|hf','*|time','design_range','payload'] self.add_subsystem('design_mission',MissionAnalysis(n_int_per_seg=n_int_per_seg,track_battery=False, propulsion_system=TurbopropPropulsionSystem(num_nodes=nn_tot_m)), promotes_inputs=mission_promote_inputs) self.connect('design_mission.throttle','design_mission.propmodel.throttle') self.connect('takeoff.weight_after_takeoff','design_mission.weight_initial') self.connect('takeoff.total_fuel','design_mission.residuals.takeoff|total_fuel') self.connect('controls.prop|rpm|mission','design_mission.propmodel.prop1.rpm') #==This module is an empirical weight tool specific to a single-engine turboprop airplane. You will need to modify or replace it. self.add_subsystem('OEW',SingleTurboPropEmptyWeight(),promotes_inputs=["*"], promotes_outputs=['OEW']) self.connect('ac|propulsion|engine|rating','P_TO') #Don't forget to couple the propulsion system to the weights module like so: self.connect('design_mission.propmodel.prop1.component_weight','W_propeller') self.connect('design_mission.propmodel.eng1.component_weight','W_engine') components_list = ['eng1'] opcost = self.add_subsystem('operating_cost',OperatingCost(n_components=len(components_list),n_batteries=None)) self.connect('OEW','operating_cost.OEW') self.connect('design_mission.fuel_burn','operating_cost.fuel_burn') for i, component in enumerate(components_list): self.connect('design_mission.propmodel.'+component+'.component_weight','operating_cost.component_'+str(i+1)+'_weight') self.connect('design_mission.propmodel.'+component+'.component_cost','operating_cost.component_'+str(i+1)+'_NR_cost')
def setup(self): n_int_per_seg = self.options['n_int_per_seg'] mission_segments = ['climb', 'cruise', 'descent'] nn, nn_tot_to, nn_tot_m, nn_tot = compute_num_nodes( n_int_per_seg, mission_segments) constant_hybridization = self.options['constant_hybridization'] specific_energy = self.options['specific_energy'] #Define input variables dv_comp = self.add_subsystem('dv_comp', DictIndepVarComp(acdata), promotes_outputs=["*"]) #eventually replace the following aerodynamic parameters with an analysis module (maybe OpenAeroStruct) dv_comp.add_output_from_dict('ac|aero|CLmax_flaps30') dv_comp.add_output_from_dict('ac|aero|polar|e') dv_comp.add_output_from_dict('ac|aero|polar|CD0_TO') dv_comp.add_output_from_dict('ac|aero|polar|CD0_cruise') dv_comp.add_output_from_dict('ac|geom|wing|S_ref') dv_comp.add_output_from_dict('ac|geom|wing|AR') dv_comp.add_output_from_dict('ac|geom|wing|c4sweep') dv_comp.add_output_from_dict('ac|geom|wing|taper') dv_comp.add_output_from_dict('ac|geom|wing|toverc') dv_comp.add_output_from_dict('ac|geom|hstab|S_ref') dv_comp.add_output_from_dict('ac|geom|hstab|c4_to_wing_c4') dv_comp.add_output_from_dict('ac|geom|vstab|S_ref') dv_comp.add_output_from_dict('ac|geom|fuselage|S_wet') dv_comp.add_output_from_dict('ac|geom|fuselage|width') dv_comp.add_output_from_dict('ac|geom|fuselage|length') dv_comp.add_output_from_dict('ac|geom|fuselage|height') dv_comp.add_output_from_dict('ac|geom|nosegear|length') dv_comp.add_output_from_dict('ac|geom|maingear|length') dv_comp.add_output_from_dict('ac|weights|MTOW') dv_comp.add_output_from_dict('ac|weights|W_fuel_max') dv_comp.add_output_from_dict('ac|weights|MLW') dv_comp.add_output_from_dict('ac|weights|W_battery') dv_comp.add_output_from_dict('ac|propulsion|engine|rating') dv_comp.add_output_from_dict('ac|propulsion|propeller|diameter') dv_comp.add_output_from_dict('ac|propulsion|generator|rating') dv_comp.add_output_from_dict('ac|propulsion|motor|rating') dv_comp.add_output_from_dict('ac|num_passengers_max') dv_comp.add_output_from_dict('ac|q_cruise') dv_comp.add_output_from_dict('ac|num_engines') mission_data_comp = self.add_subsystem('mission_data_comp', DictIndepVarComp(missiondata), promotes_outputs=["*"]) mission_data_comp.add_output_from_dict('takeoff|h') mission_data_comp.add_output_from_dict('climb|h0') mission_data_comp.add_output_from_dict('climb|time') mission_data_comp.add_output_from_dict('climb|Ueas') mission_data_comp.add_output_from_dict('cruise|h0') mission_data_comp.add_output_from_dict('cruise|Ueas') mission_data_comp.add_output_from_dict('descent|h0') mission_data_comp.add_output_from_dict('descent|hf') mission_data_comp.add_output_from_dict('descent|time') mission_data_comp.add_output_from_dict('descent|Ueas') mission_data_comp.add_output_from_dict('design_range') mission_data_comp.add_output_from_dict('payload') #==Define control settings for the propulsion system. # Recall that all flight points including takeoff roll are calculated all at once # The structure of the takeoff vector should be: #[ nn points (takeoff at full power, v0 to v1), # nn points (takeoff at engine-out power (if applicable), v1 to vr), # nn points (hard braking at zero power or even reverse, vr to v0), # !CAUTION! 1 point (transition at OEI power (if applicable), v_trans) # !CAUTION! 1 point (v2 climb at OEI power (if app), v2) # ] # The mission throttle vector should be set implicitly using the optimizer (driving T = D + sin(gamma)mg residual to 0) controls = self.add_subsystem('controls', IndepVarComp()) #set the prop to 1900 rpm for all time controls.add_output('prop|rpm|takeoff', val=np.ones(nn_tot_to) * 1900, units='rpm') controls.add_output('prop|rpm|mission', val=np.ones(nn_tot_m) * 1900, units='rpm') motor1_TO_throttle_vec = np.concatenate( [np.ones(nn), np.ones(nn) * 1.0, np.zeros(nn), np.ones(2) * 1.0]) * 1.1 motor2_TO_throttle_vec = np.concatenate( [np.ones(nn), np.zeros(nn) * 0.0, np.zeros(nn), np.zeros(2) * 0.0]) * 1.1 controls.add_output('motor1|throttle|takeoff', val=motor1_TO_throttle_vec) controls.add_output('motor2|throttle|takeoff', val=motor2_TO_throttle_vec) controls.add_output('hybrid_split|takeoff', val=1) controls.add_output('eng1|throttle|takeoff', val=np.zeros(nn_tot_to)) self.add_subsystem('hybrid_TO', LinearInterpolator(num_nodes=nn_tot_to)) self.connect('controls.hybrid_split|takeoff', ['hybrid_TO.start_val', 'hybrid_TO.end_val']) if constant_hybridization: controls.add_output('hybrid_split|percentage', val=0.5) hybrid_comps = [] for segment_name in mission_segments: hybrid_comps.append('hybrid_' + segment_name) self.add_subsystem('hybrid_' + segment_name, LinearInterpolator(num_nodes=nn)) if constant_hybridization: self.connect('controls.hybrid_split|percentage', 'hybrid_' + segment_name + '.start_val') self.connect('controls.hybrid_split|percentage', 'hybrid_' + segment_name + '.end_val') else: controls.add_output('hybrid_split|' + segment_name + '_0', val=0.5) controls.add_output('hybrid_split|' + segment_name + '_f', val=0.5) self.connect('hybrid_split|' + segment_name + '_0', 'hybrid_' + segment_name + '.start_val') self.connect('hybrid_split|' + segment_name + '_f', 'hybrid_' + segment_name + '.end_val') hybrid_combiner = self.add_subsystem( 'hybrid_combiner', VectorConcatenateComp(output_name='hybrid_split|mission', input_names=hybrid_comps, vec_sizes=[nn, nn, nn])) for segment_name in mission_segments: self.connect('hybrid_' + segment_name + '.vec', 'hybrid_combiner.hybrid_' + segment_name) #==Calculate engine thrusts and fuel flows. You will need to override this module to vary number of engines, prop architecture, etc # Your propulsion model must promote up a single variable called "thrust" and a single variable called "fuel_flow". You may need to sum these at a lower level in the prop model group # You will probably need to add more control parameters if you use multiple engines. You may also need to add implicit solver states if, e.g. turbogenerator power setting depends on motor power setting #connect control settings to the various states in the propulsion model #now we have flight conditions and propulsion outputs for all flight conditions. Split into our individual analysis phases #==This next module calculates balanced field length, if applicable. Your optimizer or solver MUST implicitly drive the abort distance and oei takeoff distances to the same value by varying v1 self.add_subsystem( 'takeoff', BalancedFieldLengthTakeoff( n_int_per_seg=n_int_per_seg, track_fuel=True, track_battery=True, propulsion_system=TwinSeriesHybridElectricPropulsionSystem( num_nodes=nn_tot_to, specific_energy=specific_energy)), promotes_inputs=[ 'ac|aero*', 'ac|geom|*', 'ac|propulsion|*', 'ac|weights|*', 'takeoff|h' ]) self.connect( 'controls.prop|rpm|takeoff', ['takeoff.propmodel.prop1.rpm', 'takeoff.propmodel.prop2.rpm']) self.connect('controls.motor1|throttle|takeoff', 'takeoff.propmodel.motor1.throttle') self.connect('controls.motor2|throttle|takeoff', 'takeoff.propmodel.motor2.throttle') self.connect('hybrid_TO.vec', 'takeoff.propmodel.hybrid_split.power_split_fraction') self.connect('controls.eng1|throttle|takeoff', 'takeoff.propmodel.eng1.throttle') #==This module computes fuel consumption during the entire mission mission_promote_inputs = [ "ac|aero|*", "ac|geom|*", 'ac|propulsion|*', 'ac|weights|*', 'OEW', '*|Ueas', '*|h0', '*|hf', '*|time', 'design_range', 'payload' ] self.add_subsystem( 'design_mission', MissionAnalysis( n_int_per_seg=n_int_per_seg, track_battery=True, propulsion_system=TwinSeriesHybridElectricPropulsionSystem( num_nodes=nn_tot_m, specific_energy=specific_energy)), promotes_inputs=mission_promote_inputs) self.connect('design_mission.throttle', [ 'design_mission.propmodel.motor1.throttle', 'design_mission.propmodel.motor2.throttle' ]) self.connect('takeoff.weight_after_takeoff', 'design_mission.weight_initial') self.connect( 'hybrid_combiner.hybrid_split|mission', 'design_mission.propmodel.hybrid_split.power_split_fraction') self.connect('controls.prop|rpm|mission', [ 'design_mission.propmodel.prop1.rpm', 'design_mission.propmodel.prop2.rpm' ]) #==This module is an empirical weight tool specific to a single-engine turboprop airplane. You will need to modify or replace it. self.add_subsystem('OEW', TwinSeriesHybridEmptyWeight(), promotes_inputs=["*"], promotes_outputs=['OEW']) self.connect('ac|propulsion|engine|rating', 'P_TO') self.connect('design_mission.propmodel.propellers_weight', 'W_propeller') self.connect('design_mission.propmodel.eng1.component_weight', 'W_engine') self.connect('design_mission.propmodel.gen1.component_weight', 'W_generator') self.connect('design_mission.propmodel.motors_weight', 'W_motors') #==Finally, we need to compute certain quantities to ensure the airplane is feasible. Compute whether enough fuel volume exists, and whether the airplane burned more fuel than it can carry self.connect('takeoff.total_fuel', 'design_mission.residuals.takeoff|total_fuel') self.connect('takeoff.total_battery_energy', 'design_mission.residuals.takeoff|total_battery_energy') self.connect('design_mission.propmodel.batt1.max_energy', 'design_mission.residuals.battery_max_energy') #==Calculate the difference between the one-engine-out abort distance and one-engine-out takeoff distance with obstacle clearance self.add_subsystem('implicit_solve', SolveImplicitStates(n_int_per_seg=n_int_per_seg)) self.connect('design_mission.propmodel.eng_gen_resid.eng_gen_residual', 'implicit_solve.eng_gen_residual') self.connect('implicit_solve.eng_throttle', 'design_mission.propmodel.eng1.throttle') components_list = ['eng1', 'motor1', 'motor2', 'gen1'] opcost = self.add_subsystem( 'operating_cost', OperatingCost(n_components=len(components_list), n_batteries=1)) self.connect('design_mission.propmodel.batt1.component_cost', 'operating_cost.battery_1_NR_cost') self.connect('design_mission.battery_energy_used', 'operating_cost.battery_1_energy_used') self.connect('OEW', 'operating_cost.OEW') self.connect('design_mission.fuel_burn', 'operating_cost.fuel_burn') for i, component in enumerate(components_list): self.connect( 'design_mission.propmodel.' + component + '.component_weight', 'operating_cost.component_' + str(i + 1) + '_weight') self.connect( 'design_mission.propmodel.' + component + '.component_cost', 'operating_cost.component_' + str(i + 1) + '_NR_cost') dummy_range = self.add_subsystem( 'dummypayload', DummyPayload(), promotes_outputs=['payload_objective']) self.connect('payload', 'dummypayload.payload_DV') dummy_obj = self.add_subsystem('dummyobj', AugmentedFBObjective(), promotes_inputs=['ac|weights|MTOW'], promotes_outputs=['mixed_objective']) self.connect('design_mission.fuel_burn', 'dummyobj.fuel_burn')