def setUp(self): self.nn = 5 self.p = om.Problem() ivc = om.IndepVarComp() ivc.add_output(name='a', shape=(self.nn, 3)) ivc.add_output(name='b', shape=(self.nn, 3)) self.p.model.add_subsystem(name='ivc', subsys=ivc, promotes_outputs=['a', 'b']) adder = self.p.model.add_subsystem(name='add_subtract_comp', subsys=om.AddSubtractComp()) adder.add_equation('adder_output', ['input_a', 'input_b'], vec_size=self.nn, length=3) self.p.model.connect('a', 'add_subtract_comp.input_a') self.p.model.connect('b', 'add_subtract_comp.input_b') self.p.setup() self.p['a'] = np.random.rand(self.nn, 3) self.p['b'] = np.random.rand(self.nn, 3) self.p.run_model()
def test_for_bad_scale_factors(self): self.nn = 5 self.p = om.Problem() ivc = om.IndepVarComp() ivc.add_output(name='a', shape=(self.nn, 3)) ivc.add_output(name='b', shape=(self.nn, 3)) ivc.add_output(name='c', shape=(self.nn, 3)) self.p.model.add_subsystem(name='ivc', subsys=ivc, promotes_outputs=['a', 'b', 'c']) adder = self.p.model.add_subsystem(name='add_subtract_comp', subsys=om.AddSubtractComp()) with self.assertRaises(ValueError) as err: adder.add_equation('adder_output', ['input_a', 'input_b', 'input_c'], vec_size=self.nn, length=3, scaling_factors=[1, -1]) expected_msg = "'add_subtract_comp' <class AddSubtractComp>: Scaling factors list needs to be " \ "same length as input names" self.assertEqual(str(err.exception), expected_msg)
def setup(self): # Airframe self.add_subsystem("loads", Loads(), promotes=["*"]) self.add_subsystem("wing_weight", WingWeight(), promotes=["*"]) self.add_subsystem("fuselage_weight", FuselageWeight(), promotes=["*"]) self.add_subsystem("empennage_weight", EmpennageWeight(), promotes=["*"]) self.add_subsystem("flight_controls_weight", FlightControlsWeight(), promotes=["*"]) self.add_subsystem("landing_gear_weight", LandingGearWeight(), promotes=["*"]) self.add_subsystem("pylons_weight", PylonsWeight(), promotes=["*"]) self.add_subsystem("paint_weight", PaintWeight(), promotes=["*"]) weight_sum = om.AddSubtractComp() weight_sum.add_equation( "data:weight:airframe:mass", [ "data:weight:airframe:wing:mass", "data:weight:airframe:fuselage:mass", "data:weight:airframe:horizontal_tail:mass", "data:weight:airframe:vertical_tail:mass", "data:weight:airframe:flight_controls:mass", "data:weight:airframe:landing_gear:main:mass", "data:weight:airframe:landing_gear:front:mass", "data:weight:airframe:pylon:mass", "data:weight:airframe:paint:mass", ], units="kg", desc="Mass of airframe", ) self.add_subsystem( "airframe_weight_sum", weight_sum, promotes=["*"], )
def setup(self): # Propulsion should be done before airframe, because it drives pylon mass. self.add_subsystem("propulsion_weight", PropulsionWeight(), promotes=["*"]) self.add_subsystem("airframe_weight", AirframeWeight(), promotes=["*"]) self.add_subsystem("systems_weight", SystemsWeight(), promotes=["*"]) self.add_subsystem("furniture_weight", FurnitureWeight(), promotes=["*"]) self.add_subsystem("crew_weight", CrewWeight(), promotes=["*"]) weight_sum = om.AddSubtractComp() weight_sum.add_equation( "data:weight:aircraft:OWE", [ "data:weight:airframe:mass", "data:weight:propulsion:mass", "data:weight:systems:mass", "data:weight:furniture:mass", "data:weight:crew:mass", ], units="kg", desc="Mass of crew", ) self.add_subsystem("OWE_sum", weight_sum, promotes=["*"])
def setup(self): self.add_subsystem("passenger_seats_weight", PassengerSeatsWeight(), promotes=["*"]) self.add_subsystem("food_water_weight", FoodWaterWeight(), promotes=["*"]) self.add_subsystem("security_kit_weight", SecurityKitWeight(), promotes=["*"]) self.add_subsystem("toilets_weight", ToiletsWeight(), promotes=["*"]) weight_sum = om.AddSubtractComp() weight_sum.add_equation( "data:weight:furniture:mass", [ "data:weight:furniture:passenger_seats:mass", "data:weight:furniture:food_water:mass", "data:weight:furniture:security_kit:mass", "data:weight:furniture:toilets:mass", ], units="kg", desc="Mass of aircraft furniture", ) self.add_subsystem( "furniture_weight_sum", weight_sum, promotes=["*"], )
def setup(self): self.add_subsystem( "passenger_seats_weight", RegisterSubmodel.get_submodel(SERVICE_PASSENGER_SEATS_MASS), promotes=["*"], ) self.add_subsystem( "food_water_weight", RegisterSubmodel.get_submodel(SERVICE_FOOD_WATER_MASS), promotes=["*"], ) self.add_subsystem( "security_kit_weight", RegisterSubmodel.get_submodel(SERVICE_SECURITY_KIT_MASS, ""), promotes=["*"], ) self.add_subsystem("toilets_weight", RegisterSubmodel.get_submodel(SERVICE_TOILETS_MASS), promotes=["*"]) weight_sum = om.AddSubtractComp() weight_sum.add_equation( "data:weight:furniture:mass", [ "data:weight:furniture:passenger_seats:mass", "data:weight:furniture:food_water:mass", "data:weight:furniture:security_kit:mass", "data:weight:furniture:toilets:mass", ], units="kg", desc="Mass of aircraft furniture", ) self.add_subsystem("furniture_weight_sum", weight_sum, promotes=["*"])
def setup(self): # Engine have to be computed before pylons self.add_subsystem("engines_weight", EngineWeight(), promotes=["*"]) self.add_subsystem("fuel_lines_weight", FuelLinesWeight(), promotes=["*"]) self.add_subsystem("unconsumables_weight", UnconsumablesWeight(), promotes=["*"]) weight_sum = om.AddSubtractComp() weight_sum.add_equation( "data:weight:propulsion:mass", [ "data:weight:propulsion:engine:mass", "data:weight:propulsion:fuel_lines:mass", "data:weight:propulsion:unconsumables:mass", ], units="kg", desc="Mass of the propulsion system", ) self.add_subsystem( "propulsion_weight_sum", weight_sum, promotes=["*"], )
def setup(self): # Engine have to be computed before pylons self.add_subsystem( "engines_weight", RegisterSubmodel.get_submodel(SERVICE_ENGINE_MASS), promotes=["*"] ) self.add_subsystem( "fuel_lines_weight", RegisterSubmodel.get_submodel(SERVICE_FUEL_LINES_MASS), promotes=["*"], ) self.add_subsystem( "unconsumables_weight", RegisterSubmodel.get_submodel(SERVICE_UNCONSUMABLES_MASS), promotes=["*"], ) weight_sum = om.AddSubtractComp() weight_sum.add_equation( "data:weight:propulsion:mass", [ "data:weight:propulsion:engine:mass", "data:weight:propulsion:fuel_lines:mass", "data:weight:propulsion:unconsumables:mass", ], units="kg", desc="Mass of the propulsion system", ) self.add_subsystem("propulsion_weight_sum", weight_sum, promotes=["*"])
def setup(self): self.add_subsystem( "power_systems_weight", RegisterSubmodel.get_submodel(SERVICE_POWER_SYSTEMS_MASS), promotes=["*"], ) self.add_subsystem( "life_support_systems_weight", RegisterSubmodel.get_submodel(SERVICE_LIFE_SUPPORT_SYSTEMS_MASS), promotes=["*"], ) self.add_subsystem( "navigation_systems_weight", RegisterSubmodel.get_submodel(SERVICE_NAVIGATION_SYSTEMS_MASS), promotes=["*"], ) self.add_subsystem( "transmission_systems_weight", RegisterSubmodel.get_submodel(SERVICE_TRANSMISSION_SYSTEMS_MASS), promotes=["*"], ) self.add_subsystem( "fixed_operational_systems_weight", RegisterSubmodel.get_submodel(SERVICE_FIXED_OPERATIONAL_SYSTEMS_MASS), promotes=["*"], ) self.add_subsystem( "flight_kit_weight", RegisterSubmodel.get_submodel(SERVICE_FLIGHT_KIT_MASS), promotes=["*"], ) weight_sum = om.AddSubtractComp() weight_sum.add_equation( "data:weight:systems:mass", [ "data:weight:systems:power:auxiliary_power_unit:mass", "data:weight:systems:power:electric_systems:mass", "data:weight:systems:power:hydraulic_systems:mass", "data:weight:systems:life_support:insulation:mass", "data:weight:systems:life_support:air_conditioning:mass", "data:weight:systems:life_support:de-icing:mass", "data:weight:systems:life_support:cabin_lighting:mass", "data:weight:systems:life_support:seats_crew_accommodation:mass", "data:weight:systems:life_support:oxygen:mass", "data:weight:systems:life_support:safety_equipment:mass", "data:weight:systems:navigation:mass", "data:weight:systems:transmission:mass", "data:weight:systems:operational:radar:mass", "data:weight:systems:operational:cargo_hold:mass", "data:weight:systems:flight_kit:mass", ], units="kg", desc="Mass of aircraft systems", ) self.add_subsystem("systems_weight_sum", weight_sum, promotes=["*"])
def test(self): """ A simple example to compute the resultant force on an aircraft and demonstrate the AddSubtract component """ import numpy as np import openmdao.api as om n = 3 p = om.Problem() ivc = om.IndepVarComp() # The vector represents forces at 3 time points (rows) in 2 dimensional plane (cols) ivc.add_output(name='thrust', shape=(n, 2), units='kN') ivc.add_output(name='drag', shape=(n, 2), units='kN') ivc.add_output(name='lift', shape=(n, 2), units='kN') ivc.add_output(name='weight', shape=(n, 2), units='kN') p.model.add_subsystem( name='ivc', subsys=ivc, promotes_outputs=['thrust', 'drag', 'lift', 'weight']) # Construct an adder/subtracter here. create a relationship through the add_equation method adder = om.AddSubtractComp() adder.add_equation('total_force', input_names=['thrust', 'drag', 'lift', 'weight'], vec_size=n, length=2, scaling_factors=[1, -1, 1, -1], units='kN') # Note the scaling factors. we assume all forces are positive sign upstream p.model.add_subsystem(name='totalforcecomp', subsys=adder) p.model.connect('thrust', 'totalforcecomp.thrust') p.model.connect('drag', 'totalforcecomp.drag') p.model.connect('lift', 'totalforcecomp.lift') p.model.connect('weight', 'totalforcecomp.weight') p.setup() # Set thrust to exceed drag, weight to equal lift for this scenario p['thrust'][:, 0] = [500, 600, 700] p['drag'][:, 0] = [400, 400, 400] p['weight'][:, 1] = [1000, 1001, 1002] p['lift'][:, 1] = [1000, 1000, 1000] p.run_model() # print(p.get_val('totalforcecomp.total_force', units='kN')) # Verify the results expected_i = np.array([[100, 200, 300], [0, -1, -2]]).T assert_rel_error(self, p.get_val('totalforcecomp.total_force', units='kN'), expected_i)
def setup(self): # Airframe self.add_subsystem("loads", RegisterSubmodel.get_submodel(SERVICE_GUST_LOADS), promotes=["*"]) self.add_subsystem("wing_weight", RegisterSubmodel.get_submodel(SERVICE_WING_MASS), promotes=["*"]) self.add_subsystem( "fuselage_weight", RegisterSubmodel.get_submodel(SERVICE_FUSELAGE_MASS), promotes=["*"]) self.add_subsystem( "empennage_weight", RegisterSubmodel.get_submodel(SERVICE_EMPENNAGE_MASS), promotes=["*"], ) self.add_subsystem( "flight_controls_weight", RegisterSubmodel.get_submodel(SERVICE_FLIGHT_CONTROLS_MASS), promotes=["*"], ) self.add_subsystem( "landing_gear_weight", RegisterSubmodel.get_submodel(SERVICE_LANDING_GEARS_MASS), promotes=["*"], ) self.add_subsystem("pylons_weight", RegisterSubmodel.get_submodel(SERVICE_PYLONS_MASS), promotes=["*"]) self.add_subsystem("paint_weight", RegisterSubmodel.get_submodel(SERVICE_PAINT_MASS), promotes=["*"]) weight_sum = om.AddSubtractComp() weight_sum.add_equation( "data:weight:airframe:mass", [ "data:weight:airframe:wing:mass", "data:weight:airframe:fuselage:mass", "data:weight:airframe:horizontal_tail:mass", "data:weight:airframe:vertical_tail:mass", "data:weight:airframe:flight_controls:mass", "data:weight:airframe:landing_gear:main:mass", "data:weight:airframe:landing_gear:front:mass", "data:weight:airframe:pylon:mass", "data:weight:airframe:paint:mass", ], units="kg", desc="Mass of airframe", ) self.add_subsystem("airframe_weight_sum", weight_sum, promotes=["*"])
def setup(self): self.add_subsystem("power_systems_weight", PowerSystemsWeight(), promotes=["*"]) self.add_subsystem("life_support_systems_weight", LifeSupportSystemsWeight(), promotes=["*"]) self.add_subsystem("navigation_systems_weight", NavigationSystemsWeight(), promotes=["*"]) self.add_subsystem("transmission_systems_weight", TransmissionSystemsWeight(), promotes=["*"]) self.add_subsystem("fixed_operational_systems_weight", FixedOperationalSystemsWeight(), promotes=["*"]) self.add_subsystem("flight_kit_weight", FlightKitWeight(), promotes=["*"]) weight_sum = om.AddSubtractComp() weight_sum.add_equation( "data:weight:systems:mass", [ "data:weight:systems:power:auxiliary_power_unit:mass", "data:weight:systems:power:electric_systems:mass", "data:weight:systems:power:hydraulic_systems:mass", "data:weight:systems:life_support:insulation:mass", "data:weight:systems:life_support:air_conditioning:mass", "data:weight:systems:life_support:de-icing:mass", "data:weight:systems:life_support:cabin_lighting:mass", "data:weight:systems:life_support:seats_crew_accommodation:mass", "data:weight:systems:life_support:oxygen:mass", "data:weight:systems:life_support:safety_equipment:mass", "data:weight:systems:navigation:mass", "data:weight:systems:transmission:mass", "data:weight:systems:operational:radar:mass", "data:weight:systems:operational:cargo_hold:mass", "data:weight:systems:flight_kit:mass", ], units="kg", desc="Mass of aircraft systems", ) self.add_subsystem( "systems_weight_sum", weight_sum, promotes=["*"], )
def setup(self): nn = self.options['num_nodes'] geom = self.options['geom'] num_cells = self.options['num_cells'] pcm_bool = self.options['pcm_bool'] # Set inputs/outputs based on geometry if geom == 'round': inpts = ['LW:L_flux', 'LW:L_adiabatic', 'XS:t_w', 'XS:t_wk', 'XS:D_v'] outpts = ['XS:D_od','XS:r_i', 'LW:A_flux', 'LW:A_inter'] elif geom == 'flat': inpts = ['LW:L_flux', 'LW:L_adiabatic', 'XS:t_w', 'XS:t_wk'] outpts = ['LW:A_flux', 'LW:A_inter', 'XS:W_hp'] # Size the pack components self.add_subsystem(name = 'size', subsys = HPgeom(num_nodes=nn, geom=geom), promotes_inputs=inpts, promotes_outputs=outpts) # Calculate total mass self.add_subsystem(name='massPCM', subsys = pcmMass(num_nodes=nn), promotes_inputs=['t_pad', 'A_pad', 'porosity'], promotes_outputs=['mass_pcm']) self.add_subsystem(name='massInsulation', subsys = insulationMass(num_nodes=nn), promotes_inputs=['num_cells','batt_l','L_flux','batt_h','ins_thickness'], promotes_outputs=['ins_mass']) if geom == 'flat': self.add_subsystem(name='massHP', subsys = flatHPmass(num_nodes=nn), promotes_inputs=['length_hp', 'width_hp', 'wick_t', 'wall_t','wick_porosity'], promotes_outputs=['mass_hp']) if geom == 'round': self.add_subsystem(name='massHP', subsys = roundHPmass(num_nodes=nn), promotes_inputs=['D_od_hp', 'wick_t', 'wall_t','wick_porosity'], promotes_outputs=['mass_hp']) adder = om.AddSubtractComp() adder.add_equation('mass_total', input_names=['mass_pcm','mass_hp','ins_mass','mass_battery'], vec_size=nn, units='kg') self.add_subsystem(name='mass_comp', subsys = adder, promotes_inputs=['mass_pcm','mass_hp','ins_mass','mass_battery'], promotes_outputs=['mass_total'])
def _get_tow_component(mission_name: str) -> om.AddSubtractComp: """ :param mission_name: :return: component that computes TakeOff Weight from ZFW and needed block fuel """ tow_computation = om.AddSubtractComp() tow_computation.add_equation( "data:mission:%s:TOW" % mission_name, [ "data:mission:%s:ZFW" % mission_name, "data:mission:%s:block_fuel" % mission_name, ], units="kg", ) return tow_computation
def _get_tow_component(mission_name: str) -> om.AddSubtractComp: """ :param mission_name: :return: component that computes TakeOff Weight from ZFW and loaded fuel at takeoff """ tow_computation = om.AddSubtractComp() tow_computation.add_equation( f"data:mission:{mission_name}:TOW", [ f"data:mission:{mission_name}:ZFW", f"data:mission:{mission_name}:onboard_fuel_at_takeoff", ], units="kg", desc=f'TakeOff Weight for mission "{mission_name}"', ) return tow_computation
def _get_tow_component(mission_name: str) -> om.AddSubtractComp: """ :param mission_name: :return: component that computes TakeOff Weight from ZFW and loaded fuel at takeoff """ tow_computation = om.AddSubtractComp() tow_computation.add_equation( "data:mission:%s:TOW" % mission_name, [ "data:mission:%s:ZFW" % mission_name, "data:mission:%s:onboard_fuel_at_takeoff" % mission_name, ], units="kg", desc='TakeOff Weight for mission "%s"' % mission_name, ) return tow_computation
def _get_block_fuel_component(mission_name: str) -> om.AddSubtractComp: """ :param mission_name: :return: component that computes initial block fuel from TOW and ZFW """ block_fuel_computation = om.AddSubtractComp() block_fuel_computation.add_equation( "data:mission:%s:block_fuel" % mission_name, [ "data:mission:%s:TOW" % mission_name, "data:mission:%s:ZFW" % mission_name ], units="kg", scaling_factors=[1, -1], ) return block_fuel_computation
def _get_zfw_component(self, mission_name: str) -> om.AddSubtractComp: """ :param mission_name: :return: component that computes Zero Fuel Weight from OWE and mission payload """ if self.options["is_sizing"]: payload_var = "data:weight:aircraft:payload" else: payload_var = "data:mission:%s:payload" % mission_name zfw_computation = om.AddSubtractComp() zfw_computation.add_equation( "data:mission:%s:ZFW" % mission_name, ["data:weight:aircraft:OWE", payload_var], units="kg", ) return zfw_computation
def _get_block_fuel_component(mission_name: str) -> om.AddSubtractComp: """ :param mission_name: :return: component that computes initial block fuel from TOW and ZFW """ block_fuel_computation = om.AddSubtractComp() block_fuel_computation.add_equation( "data:mission:%s:block_fuel" % mission_name, [ "data:mission:%s:TOW" % mission_name, "data:mission:%s:taxi_out:fuel" % mission_name, "data:mission:%s:takeoff:fuel" % mission_name, "data:mission:%s:ZFW" % mission_name, ], units="kg", scaling_factors=[1, 1, 1, -1], desc='Loaded fuel before taxi-out for mission "%s"' % mission_name, ) return block_fuel_computation
def setUp(self): self.nn = 5 self.p = om.Problem() ivc = om.IndepVarComp() ivc.add_output(name='a', shape=(self.nn, 3)) ivc.add_output(name='b', shape=(self.nn, 3)) ivc.add_output(name='c', shape=(self.nn, 3)) self.p.model.add_subsystem(name='ivc', subsys=ivc, promotes_outputs=['a', 'b','c']) adder=self.p.model.add_subsystem(name='add_subtract_comp', subsys=om.AddSubtractComp()) adder.add_equation('adder_output',['input_a','input_b','input_c'],vec_size=self.nn,length=3,scaling_factors=[1,-1]) self.p.model.connect('a', 'add_subtract_comp.input_a') self.p.model.connect('b', 'add_subtract_comp.input_b') self.p.model.connect('c', 'add_subtract_comp.input_c')
def test_for_bad_input_set(self): self.nn = 5 self.p = om.Problem() ivc = om.IndepVarComp() ivc.add_output(name='a', shape=(self.nn, 3)) ivc.add_output(name='b', shape=(self.nn, 3)) ivc.add_output(name='c', shape=(self.nn, 3)) self.p.model.add_subsystem(name='ivc', subsys=ivc, promotes_outputs=['a', 'b', 'c']) adder = self.p.model.add_subsystem(name='add_subtract_comp', subsys=om.AddSubtractComp()) with self.assertRaises(ValueError) as err: adder.add_equation('adder_output', [ 'input_a', ], vec_size=self.nn, length=3, scaling_factors=[1, -1]) expected_msg = "'add_subtract_comp' <class AddSubtractComp>: must specify more than one input " \ "name for an equation, but only one given" self.assertEqual(str(err.exception), expected_msg) with self.assertRaises(ValueError) as err: adder.add_equation('adder_output', 'input_a', vec_size=self.nn, length=3, scaling_factors=[1, -1]) expected_msg = "'add_subtract_comp' <class AddSubtractComp>: must specify more than one input " \ "name for an equation, but only one given" self.assertEqual(str(err.exception), expected_msg)
def test(self): """ A simple example to compute the resultant force on an aircraft and demonstrate the AddSubtract component """ n = 3 p = om.Problem() model = p.model # Construct an adder/subtracter here. create a relationship through the add_equation method adder = om.AddSubtractComp() adder.add_equation('total_force', input_names=['thrust', 'drag', 'lift', 'weight'], vec_size=n, length=2, scaling_factors=[1, -1, 1, -1], units='kN') # Note the scaling factors. we assume all forces are positive sign upstream # The vector represents forces at 3 time points (rows) in 2 dimensional plane (cols) p.model.add_subsystem( name='totalforcecomp', subsys=adder, promotes_inputs=['thrust', 'drag', 'lift', 'weight']) p.setup() # Set thrust to exceed drag, weight to equal lift for this scenario p['thrust'][:, 0] = [500, 600, 700] p['drag'][:, 0] = [400, 400, 400] p['weight'][:, 1] = [1000, 1001, 1002] p['lift'][:, 1] = [1000, 1000, 1000] p.run_model() # Verify the results expected_i = np.array([[100, 200, 300], [0, -1, -2]]).T assert_near_equal(p.get_val('totalforcecomp.total_force', units='kN'), expected_i)
def setup(self): # Propulsion should be done before airframe, because it drives pylon mass. self.add_subsystem( "propulsion_weight", RegisterSubmodel.get_submodel(SERVICE_PROPULSION_MASS), promotes=["*"], ) self.add_subsystem( "airframe_weight", RegisterSubmodel.get_submodel(SERVICE_AIRFRAME_MASS), promotes=["*"]) self.add_subsystem("systems_weight", RegisterSubmodel.get_submodel(SERVICE_SYSTEMS_MASS), promotes=["*"]) self.add_subsystem( "furniture_weight", RegisterSubmodel.get_submodel(SERVICE_FURNITURE_MASS), promotes=["*"], ) self.add_subsystem("crew_weight", RegisterSubmodel.get_submodel(SERVICE_CREW_MASS), promotes=["*"]) weight_sum = om.AddSubtractComp() weight_sum.add_equation( "data:weight:aircraft:OWE", [ "data:weight:airframe:mass", "data:weight:propulsion:mass", "data:weight:systems:mass", "data:weight:furniture:mass", "data:weight:crew:mass", ], units="kg", desc="Mass of crew", ) self.add_subsystem("OWE_sum", weight_sum, promotes=["*"])
def setUp(self): self.nn = 5 self.p = om.Problem() ivc = om.IndepVarComp() ivc.add_output(name='a', shape=(self.nn, 3), units='ft') ivc.add_output(name='b', shape=(self.nn, 3), units='m') ivc.add_output(name='c', shape=(self.nn, 3), units='m') self.p.model.add_subsystem(name='ivc', subsys=ivc, promotes_outputs=['a', 'b', 'c']) # verify proper handling of constructor args adder = om.AddSubtractComp( output_name='adder_output', input_names=['input_a', 'input_b', 'input_c'], vec_size=self.nn, length=3, scaling_factors=[2., 1., -1], units='ft') self.p.model.add_subsystem(name='add_subtract_comp', subsys=adder) self.p.model.connect('a', 'add_subtract_comp.input_a') self.p.model.connect('b', 'add_subtract_comp.input_b') self.p.model.connect('c', 'add_subtract_comp.input_c') self.p.setup() self.p['a'] = np.random.rand(self.nn, 3) self.p['b'] = np.random.rand(self.nn, 3) self.p['c'] = np.random.rand(self.nn, 3) self.p.run_model()
def setup(self): # Airframe self.add_subsystem("wing_weight", ComputeWingWeight(), promotes=["*"]) self.add_subsystem("fuselage_weight", ComputeFuselageWeight(), promotes=["*"]) self.add_subsystem("empennage_weight", ComputeTailWeight(), promotes=["*"]) self.add_subsystem("flight_controls_weight", ComputeFlightControlsWeight(), promotes=["*"]) self.add_subsystem("landing_gear_weight", ComputeLandingGearWeight(), promotes=["*"]) self.add_subsystem( "engine_weight", ComputeEngineWeight(propulsion_id=self.options["propulsion_id"]), promotes=["*"]) self.add_subsystem("fuel_lines_weight", ComputeFuelLinesWeight(), promotes=["*"]) self.add_subsystem("navigation_systems_weight", ComputeNavigationSystemsWeight(), promotes=["*"]) self.add_subsystem("power_systems_weight", ComputePowerSystemsWeight(), promotes=["*"]) self.add_subsystem("life_support_systems_weight", ComputeLifeSupportSystemsWeight(), promotes=["*"]) self.add_subsystem("passenger_seats_weight", ComputePassengerSeatsWeight(), promotes=["*"]) # Make additions airframe_sum = om.AddSubtractComp() airframe_sum.add_equation( "data:weight:airframe:mass", [ "data:weight:airframe:wing:mass", "data:weight:airframe:fuselage:mass", "data:weight:airframe:horizontal_tail:mass", "data:weight:airframe:vertical_tail:mass", "data:weight:airframe:flight_controls:mass", "data:weight:airframe:landing_gear:main:mass", "data:weight:airframe:landing_gear:front:mass", ], units="kg", desc="Mass of airframe", ) self.add_subsystem( "airframe_weight_sum", airframe_sum, promotes=["*"], ) propulsion_sum = om.AddSubtractComp() propulsion_sum.add_equation( "data:weight:propulsion:mass", [ "data:weight:propulsion:engine:mass", "data:weight:propulsion:fuel_lines:mass", ], units="kg", desc="Mass of the propulsion system", ) self.add_subsystem( "propulsion_weight_sum", propulsion_sum, promotes=["*"], ) systems_sum = om.AddSubtractComp() systems_sum.add_equation( "data:weight:systems:mass", [ "data:weight:systems:power:electric_systems:mass", "data:weight:systems:power:hydraulic_systems:mass", "data:weight:systems:life_support:air_conditioning:mass", "data:weight:systems:navigation:mass", ], units="kg", desc="Mass of aircraft systems", ) self.add_subsystem( "systems_weight_sum", systems_sum, promotes=["*"], ) furniture_sum = om.AddSubtractComp() furniture_sum.add_equation( "data:weight:furniture:mass", [ "data:weight:furniture:passenger_seats:mass", "data:weight:furniture:passenger_seats:mass", ], scaling_factors=[0.5, 0.5], units="kg", desc="Mass of aircraft furniture", ) self.add_subsystem( "furniture_weight_sum", furniture_sum, promotes=["*"], ) owe_sum = om.AddSubtractComp() owe_sum.add_equation( "data:weight:aircraft:OWE", [ "data:weight:airframe:mass", "data:weight:propulsion:mass", "data:weight:systems:mass", "data:weight:furniture:mass", ], units="kg", desc="Mass of aircraft", ) self.add_subsystem( "OWE_sum", owe_sum, promotes=["*"], )