def setup(self): lsm_solver = self.options['lsm_solver'] bpts_xy = self.options['bpts_xy'] upperbound = self.options['ub'] lowerbound = self.options['lb'] num_dvs = 2 # number of lambdas num_bpts = bpts_xy.shape[0] # inputs (IndepVarComp: component) comp = IndepVarComp() comp.add_output('lambdas', val = 0.0, shape = num_dvs) self.add_subsystem('inputs_comp', comp) self.connect('inputs_comp.lambdas', 'objective_comp.lambdas') self.connect('inputs_comp.lambdas', 'constraint_comp.lambdas') self.add_design_var('inputs_comp.lambdas', lower = np.array([lowerbound[0], lowerbound[1]]), upper = np.array([upperbound[0], upperbound[1]])) # constraint setup comp = Callback_conF(lsm_solver = lsm_solver) comp.add_constraint('constraint') self.add_subsystem('constraint_comp', comp) # objective setup comp = Callback_objF(lsm_solver = lsm_solver) comp.add_objective('objective') self.add_subsystem('objective_comp', comp)
def setup(self): fem_solver = self.options['fem_solver'] length_x = self.options['length_x'] length_y = self.options['length_y'] num_nodes_x = self.options['num_nodes_x'] num_nodes_y = self.options['num_nodes_y'] forces = self.options['forces'] p = self.options['p'] w = self.options['w'] nodes = self.options['nodes'] volume_fraction = self.options['volume_fraction'] num = num_nodes_x * num_nodes_y num_el = (num_nodes_x - 1) * (num_nodes_y - 1) state_size = 2 * num_nodes_x * num_nodes_y + 2 * num_nodes_y disp_size = 2 * num_nodes_x * num_nodes_y rhs = np.zeros(state_size) rhs[:disp_size] = forces # inputs comp = IndepVarComp() comp.add_output('rhs', val=rhs) comp.add_output('forces', val=forces) comp.add_output('dvs', val=0.5, shape=num_el) comp.add_design_var('dvs', lower=0.01, upper=1.0) # comp.add_design_var('x', lower=-4, upper=4) self.add_subsystem('inputs_comp', comp) self.connect('inputs_comp.dvs', 'penalization_comp.x') self.connect('inputs_comp.dvs', 'weight_comp.x') # penalization comp = PenalizationComp(num=num_el, p=p) self.add_subsystem('penalization_comp', comp) self.connect('penalization_comp.y', 'states_comp.multipliers') # states comp = StatesComp(fem_solver=fem_solver, num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y, nodes=nodes, isNodal=False) self.add_subsystem('states_comp', comp) self.connect('inputs_comp.rhs', 'states_comp.rhs') # disp comp = DispComp(num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y) self.add_subsystem('disp_comp', comp) self.connect('states_comp.states', 'disp_comp.states') # compliance comp = ComplianceComp(num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y) self.add_subsystem('compliance_comp', comp) self.connect('disp_comp.disp', 'compliance_comp.disp') self.connect('inputs_comp.forces', 'compliance_comp.forces') # weight comp = WeightComp(num=num_el) comp.add_constraint('weight', upper=volume_fraction) self.add_subsystem('weight_comp', comp) # objective comp = ObjectiveComp(w=w) comp.add_objective('objective') self.add_subsystem('objective_comp', comp) self.connect('compliance_comp.compliance', 'objective_comp.compliance') self.connect('weight_comp.weight', 'objective_comp.weight')
def setup(self): fem_solver = self.options['fem_solver'] force = self.options['force'] num_elem_x = self.options['num_elem_x'] num_elem_y = self.options['num_elem_y'] p = self.options['penal'] volume_fraction = self.options['volume_fraction'] (nodes, elem, elem_dof) = fem_solver.get_mesh() (length_x, length_y) = (np.max(nodes[:, 0], 0), np.max(nodes[:, 1], 0)) (num_nodes_x, num_nodes_y) = (num_elem_x + 1, num_elem_y + 1) nNODE = num_nodes_x * num_nodes_y nELEM = (num_nodes_x - 1) * (num_nodes_y - 1) nDOF = nNODE * 2 rhs = force # inputs comp = IndepVarComp() comp.add_output('rhs', val=rhs) comp.add_output('dvs', val=0.8, shape=nELEM) comp.add_design_var('dvs', lower=0.01, upper=1.0) # comp.add_design_var('x', lower=-4, upper=4) // param self.add_subsystem('inputs_comp', comp) self.connect('inputs_comp.dvs', 'filter_comp.dvs') self.connect('inputs_comp.rhs', 'states_comp.rhs') # density filter comp = DensityFilterComp(length_x=length_x, length_y=length_y, num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y, num_dvs=nELEM, radius=length_x / (float(num_nodes_x) - 1) * 2) self.add_subsystem('filter_comp', comp) self.connect('filter_comp.dvs_bar', 'penalization_comp.x') self.connect('filter_comp.dvs_bar', 'weight_comp.x') # penalization comp = PenalizationComp(num=nELEM, p=p) self.add_subsystem('penalization_comp', comp) self.connect('penalization_comp.y', 'states_comp.multipliers') # states comp = StatesComp(fem_solver=fem_solver, num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y, isSIMP=True) self.add_subsystem('states_comp', comp) self.connect('states_comp.states', 'disp_comp.states') # num_states to num_dofs comp = DispComp(num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y) self.add_subsystem('disp_comp', comp) self.connect('disp_comp.disp', 'compliance_comp.disp') comp = DispComp(num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y) self.add_subsystem('GF_comp', comp) self.connect('inputs_comp.rhs', 'GF_comp.states') self.connect('GF_comp.disp', 'compliance_comp.forces') # compliance comp = ComplianceComp(num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y) self.add_subsystem('compliance_comp', comp) # self.connect('inputs_comp.rhs', 'compliance_comp.forces') # weight comp = WeightComp(num=nELEM) comp.add_constraint('weight', upper=volume_fraction) self.add_subsystem('weight_comp', comp) # objective comp = ObjectiveComp(w=0.0) comp.add_objective('objective') self.add_subsystem('objective_comp', comp) self.connect('compliance_comp.compliance', 'objective_comp.compliance') self.connect('weight_comp.weight', 'objective_comp.weight')
def setup(self): num_times = self.options['num_times'] num_cp = self.options['num_cp'] cubesat = self.options['cubesat'] mtx = self.options['mtx'] comp = IndepVarComp() # comp.add_output('roll_cp', val=2. * np.pi * np.random.rand(num_cp)) # comp.add_output('pitch_cp', val=2. * np.pi * np.random.rand(num_cp)) comp.add_output('roll_cp', val=np.ones(num_cp)) comp.add_output('pitch_cp', val=np.ones(num_cp)) comp.add_design_var('roll_cp') comp.add_design_var('pitch_cp') self.add_subsystem('inputs_comp', comp, promotes=['*']) for var_name in ['roll', 'pitch']: comp = BsplineComp( num_pt=num_times, num_cp=num_cp, jac=mtx, in_name='{}_cp'.format(var_name), out_name=var_name, ) self.add_subsystem('{}_comp'.format(var_name), comp, promotes=['*']) comp = RotMtxBIComp(num_times=num_times) self.add_subsystem('rot_mtx_b_i_3x3xn_comp', comp, promotes=['*']) comp = ArrayReorderComp( in_shape=(3, 3, num_times), out_shape=(3, 3, num_times), in_subscripts='ijn', out_subscripts='jin', in_name='rot_mtx_b_i_3x3xn', out_name='rot_mtx_i_b_3x3xn', ) self.add_subsystem('rot_mtx_i_b_3x3xn_comp', comp, promotes=['*']) # for var_name in [ 'times', 'roll', 'pitch', ]: comp = FiniteDifferenceComp( num_times=num_times, in_name=var_name, out_name='d{}'.format(var_name), ) self.add_subsystem('d{}_comp'.format(var_name), comp, promotes=['*']) rad_deg = np.pi / 180. for var_name in [ 'roll', 'pitch', ]: comp = PowerCombinationComp(shape=(num_times, ), out_name='{}_rate'.format(var_name), powers_dict={ 'd{}'.format(var_name): 1., 'dtimes': -1., }) comp.add_constraint('{}_rate'.format(var_name), lower=-10. * rad_deg, upper=10. * rad_deg, linear=True) self.add_subsystem('{}_rate_comp'.format(var_name), comp, promotes=['*'])
def setup(self): fem_solver = self.metadata['fem_solver'] length_x = self.metadata['length_x'] length_y = self.metadata['length_y'] num_nodes_x = self.metadata['num_nodes_x'] num_nodes_y = self.metadata['num_nodes_y'] num_param_x = self.metadata['num_param_x'] num_param_y = self.metadata['num_param_y'] forces = self.metadata['forces'] p = self.metadata['p'] w = self.metadata['w'] nodes = self.metadata['nodes'] quad_order = self.metadata['quad_order'] volume_fraction = self.metadata['volume_fraction'] num = num_nodes_x * num_nodes_y coord_eval_x, coord_eval_y = get_coord_eval(num_nodes_x, num_nodes_y, quad_order) coord_eval_x *= length_x coord_eval_y *= length_y gpt_mesh = np.zeros((coord_eval_x.shape[0], coord_eval_y.shape[0], 2)) gpt_mesh[:, :, 0] = np.outer(coord_eval_x, np.ones(coord_eval_y.shape[0])) gpt_mesh[:, :, 1] = np.outer(np.ones(coord_eval_x.shape[0]), coord_eval_y) state_size = 2 * num_nodes_x * num_nodes_y + 2 * num_nodes_y disp_size = 2 * num_nodes_x * num_nodes_y coord_eval_x, coord_eval_y = get_coord_eval(num_nodes_x, num_nodes_y, quad_order) if 1: param_mtx = get_bspline_mtx(coord_eval_x, coord_eval_y, num_param_x, num_param_y, kx=4, ky=4) else: param_mtx = get_rbf_mtx(coord_eval_x, coord_eval_y, num_param_x, num_param_y, kx=4, ky=4) rhs = np.zeros(state_size) rhs[:disp_size] = forces # inputs comp = IndepVarComp() comp.add_output('rhs', val=rhs) comp.add_output('forces', val=forces) # x = np.linalg.solve( # param_mtx.T.dot(param_mtx), # param_mtx.T.dot(0.5 * np.ones((num_nodes_x - 1) * (num_nodes_y - 1)))) comp.add_output('dvs', val=0., shape=num_param_x * num_param_y) comp.add_design_var('dvs') self.add_subsystem('inputs_comp', comp) self.connect('inputs_comp.dvs', 'parametrization_comp.x') comp = ParametrizationComp( mtx=param_mtx, num_rows=(num_nodes_x - 1) * (num_nodes_y - 1) * quad_order**2, num_cols=num_param_x * num_param_y, ) self.add_subsystem('parametrization_comp', comp) self.connect('parametrization_comp.y', 'states_comp.plot_var') # if 0: # self.connect('parametrization_comp.y', 'averaging_comp.x') # comp = AveragingComp( # num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y, quad_order=quad_order) # self.add_subsystem('averaging_comp', comp) # self.connect('averaging_comp.y', 'heaviside_comp.x') # # comp = HeavisideComp(num=num) # self.add_subsystem('heaviside_comp', comp) # self.connect('heaviside_comp.y', 'penalization_comp.x') # self.connect('heaviside_comp.y', 'weight_comp.x') # # comp = PenalizationComp(num=num, p=p) # self.add_subsystem('penalization_comp', comp) # self.connect('penalization_comp.y', 'states_comp.multipliers') if 1: self.connect('parametrization_comp.y', 'heaviside_comp.x') comp = HeavisideComp(num=(num_nodes_x - 1) * (num_nodes_y - 1) * quad_order**2) self.add_subsystem('heaviside_comp', comp) self.connect('heaviside_comp.y', 'averaging_comp.x') self.connect('heaviside_comp.y', 'states_comp.plot_var2') comp = AveragingComp(num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y, quad_order=quad_order) self.add_subsystem('averaging_comp', comp) self.connect('averaging_comp.y', 'penalization_comp.x') self.connect('averaging_comp.y', 'weight_comp.x') comp = PenalizationComp(num=num, p=p) self.add_subsystem('penalization_comp', comp) self.connect('penalization_comp.y', 'states_comp.multipliers') else: self.connect('parametrization_comp.y', 'heaviside_comp.x') comp = HeavisideComp(num=(num_nodes_x - 1) * (num_nodes_y - 1) * quad_order**2) self.add_subsystem('heaviside_comp', comp) self.connect('heaviside_comp.y', 'penalization_comp.x') self.connect('heaviside_comp.y', 'averaging_comp2.x') self.connect('heaviside_comp.y', 'states_comp.plot_var2') comp = AveragingComp(num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y, quad_order=quad_order) self.add_subsystem('averaging_comp2', comp) self.connect('averaging_comp2.y', 'weight_comp.x') comp = PenalizationComp(num=(num_nodes_x - 1) * (num_nodes_y - 1) * quad_order**2, p=p) self.add_subsystem('penalization_comp', comp) self.connect('penalization_comp.y', 'averaging_comp.x') comp = AveragingComp(num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y, quad_order=quad_order) self.add_subsystem('averaging_comp', comp) self.connect('averaging_comp.y', 'states_comp.multipliers') # states comp = StatesComp(fem_solver=fem_solver, num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y, nodes=nodes, gpt_mesh=gpt_mesh, quad_order=quad_order) self.add_subsystem('states_comp', comp) self.connect('inputs_comp.rhs', 'states_comp.rhs') # disp comp = DispComp(num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y) self.add_subsystem('disp_comp', comp) self.connect('states_comp.states', 'disp_comp.states') # compliance comp = ComplianceComp(num_nodes_x=num_nodes_x, num_nodes_y=num_nodes_y) self.add_subsystem('compliance_comp', comp) self.connect('disp_comp.disp', 'compliance_comp.disp') self.connect('inputs_comp.forces', 'compliance_comp.forces') # weight comp = WeightComp(num=num) comp.add_constraint('weight', upper=volume_fraction) self.add_subsystem('weight_comp', comp) # objective comp = ObjectiveComp(w=w) comp.add_objective('objective') self.add_subsystem('objective_comp', comp) self.connect('compliance_comp.compliance', 'objective_comp.compliance') self.connect('weight_comp.weight', 'objective_comp.weight')
def setup(self): lsm_solver = self.options['lsm_solver'] num_bpts = self.options['num_bpts'] upperbound = self.options['ub'] lowerbound = self.options['lb'] Sf = self.options['Sf'] Sg = self.options['Sg'] constraintDistance = self.options['constraintDistance'] num_dvs = 2 # number of lambdas # inputs (IndepVarComp: component) comp = IndepVarComp() comp.add_output('lambdas', val = 0.0, shape = num_dvs) comp.add_output('Sf', val=Sf) comp.add_output('Sg', val=Sg) comp.add_output('constraintDistance', val=constraintDistance) self.add_subsystem('inputs_comp', comp) self.add_design_var('inputs_comp.lambdas', lower = np.array([lowerbound[0], lowerbound[1]]), upper = np.array([upperbound[0], upperbound[1]])) # scalings setup # verified (10/24) comp = ScalingComp(nBpts= num_bpts, lsm_solver=lsm_solver) self.add_subsystem('scaling_f_comp',comp) self.connect('inputs_comp.Sf', 'scaling_f_comp.x') comp = ScalingComp(nBpts= num_bpts, lsm_solver=lsm_solver) self.add_subsystem('scaling_g_comp',comp) self.connect('inputs_comp.Sg', 'scaling_g_comp.x') # displacements setup comp = DisplacementComp(lsm_solver = lsm_solver, nBpts = num_bpts, ndvs = num_dvs) self.add_subsystem('displacement_comp', comp) self.connect('inputs_comp.lambdas', 'displacement_comp.lambdas') self.connect('inputs_comp.Sf', 'displacement_comp.Sf') self.connect('inputs_comp.Sg', 'displacement_comp.Sg') self.connect('scaling_f_comp.y', 'displacement_comp.Scale_f') self.connect('scaling_g_comp.y', 'displacement_comp.Scale_g') # integration setup comp = IntegralComp(lsm_solver=lsm_solver, nBpts=num_bpts) self.add_subsystem('integral_f_comp', comp) self.connect('inputs_comp.Sf', 'integral_f_comp.x') comp = IntegralComp(lsm_solver=lsm_solver, nBpts=num_bpts) self.add_subsystem('integral_g_comp', comp) self.connect('inputs_comp.Sg', 'integral_g_comp.x') # objective setup comp = ObjectiveComp(lsm_solver = lsm_solver, nBpts = num_bpts) comp.add_objective('delF') self.add_subsystem('objective_comp', comp) self.connect('displacement_comp.displacements', 'objective_comp.displacements') self.connect('integral_f_comp.y', 'objective_comp.Cf') self.connect('scaling_f_comp.y', 'objective_comp.scale_f') # constraint setup comp = ConstraintComp(lsm_solver = lsm_solver, nBpts = num_bpts) comp.add_constraint('delG', upper = 0.0 ) self.add_subsystem('constraint_comp', comp) self.connect('displacement_comp.displacements', 'constraint_comp.displacements') self.connect('integral_g_comp.y', 'constraint_comp.Cg') self.connect('scaling_g_comp.y', 'constraint_comp.scale_g') self.connect('inputs_comp.constraintDistance', 'constraint_comp.constraintDistance')
def setup(self): lsm_solver = self.options['lsm_solver'] bpts_xy = self.options['bpts_xy'] bpts_sens = self.options['bpts_sens'] activeList = self.options['ActiveList'] length_segs = self.options['length_segs'] upperbound = self.options['ub'] lowerbound = self.options['lb'] num_dvs = 2 # number of lambdas num_bpts = bpts_xy.shape[0] Sf = bpts_sens[:, 0] Sg = bpts_sens[:, 1] # inputs (IndepVarComp: component) comp = IndepVarComp() comp.add_output('lambdas', val=0.0, shape=num_dvs) comp.add_output('Sf', val=Sf) comp.add_output('Sg', val=Sg) comp.add_output('length', val=length_segs) self.add_subsystem('inputs_comp', comp) self.add_design_var('inputs_comp.lambdas', lower=np.array([lowerbound[0], lowerbound[1]]), upper=np.array([upperbound[0], upperbound[1]])) self.connect('inputs_comp.lambdas', 'displacement_comp.lambdas') self.connect('inputs_comp.Sf', 'active_Sf_comp.x') self.connect('inputs_comp.Sg', 'active_Sg_comp.x') self.connect('inputs_comp.length', 'integration_f_comp.x') self.connect('inputs_comp.length', 'integration_g_comp.x') # active nodes only comp = ActiveComp(activeid=activeList, nBpts=num_bpts) self.add_subsystem('active_Sf_comp', comp) self.connect('active_Sf_comp.y', 'integration_f_comp.x') comp = ActiveComp(activeid=activeList, nBpts=num_bpts) self.add_subsystem('active_Sg_comp', comp) self.connect('active_Sg_comp.y', 'integration_g_comp.x') # integrations comp = IntegComp(nBpts=num_bpts) self.add_subsystem('active_Sf_comp', comp) self.connect('active_Sf_comp.y', 'integration_f_comp.x') comp = IntegComp(nBpts=num_bpts) self.add_subsystem('active_Sg_comp', comp) self.connect('active_Sg_comp.y', 'integration_g_comp.x') # displacements setup comp = DisplacementComp(lsm_solver=lsm_solver, num_bpts=num_bpts, num_dvs=num_dvs) self.add_subsystem('displacement_comp', comp) self.connect('displacement_comp.displacements', 'objective_comp.displacements') self.connect('displacement_comp.displacements', 'constraint_comp.displacements') # objective setup comp = ObjectiveComp(lsm_solver=lsm_solver, num_bpts=num_bpts) comp.add_objective('objective') self.add_subsystem('objective_comp', comp) # constraint setup comp = ConstraintComp(lsm_solver=lsm_solver, num_bpts=num_bpts) comp.add_constraint('constraint', upper=0.0) self.add_subsystem('constraint_comp', comp)
def setup(self): shape = self.options['shape'] aircraft = self.options['aircraft'] comp = IndepVarComp() comp.add_output('CL_max', val=aircraft['CL_max'], shape=shape) comp.add_output('CL_takeoff', val=aircraft['CL_takeoff'], shape=shape) comp.add_output('climb_gradient', val=aircraft['climb_gradient'], shape=shape) comp.add_output('turn_load_factor', val=aircraft['turn_load_factor'], shape=shape) comp.add_output('TOP', val=aircraft['TOP'], shape=shape) comp.add_output('takeoff_density', val=aircraft['takeoff_density'], shape=shape) comp.add_output('sealevel_density', val=1.225, shape=shape) comp.add_output('stall_speed', val=aircraft['stall_speed'], shape=shape) comp.add_output('climb_speed', val=aircraft['climb_speed'], shape=shape) comp.add_output('turn_speed', val=aircraft['turn_speed'], shape=shape) comp.add_output('landing_distance', val=aircraft['landing_distance'], shape=shape) comp.add_output('approach_distance', val=aircraft['approach_distance'], shape=shape) comp.add_output('wing_loading', val=aircraft['wing_loading'], shape=shape) comp.add_output('thrust_to_weight', val=aircraft['thrust_to_weight'], shape=shape) comp.add_output('ref_wing_loading', val=aircraft['ref_wing_loading'], shape=shape) comp.add_output('ref_thrust_to_weight', val=aircraft['ref_thrust_to_weight'], shape=shape) comp.add_design_var('wing_loading', indices=[0], lower=0.) comp.add_design_var('thrust_to_weight', indices=[0], lower=0.) self.add_subsystem('inputs_comp', comp, promotes=['*']) # comp = PowerCombinationComp( shape=shape, out_name='wing_loading_lbf_ft2', powers_dict=dict(wing_loading=1., ), coeff=units('lbf/ft^2', 'N/m^2'), ) self.add_subsystem('wing_loading_lbf_ft2_comp', comp, promotes=['*']) comp = PowerCombinationComp( shape=shape, out_name='ref_power_to_weight', powers_dict=dict( ref_thrust_to_weight=1., cruise_speed=1., propulsive_efficiency=-1., ), ) self.add_subsystem('ref_power_to_weight_comp', comp, promotes=['*']) comp = PowerCombinationComp( shape=shape, out_name='power_to_weight', powers_dict=dict( thrust_to_weight=1., cruise_speed=1., propulsive_efficiency=-1., ), ) self.add_subsystem('power_to_weight_comp', comp, promotes=['*']) comp = PowerCombinationComp( shape=shape, out_name='wing_area', powers_dict=dict( gross_weight=1., wing_loading=-1., ), ) self.add_subsystem('wing_area_comp', comp, promotes=['*']) comp = PowerCombinationComp( shape=shape, out_name='max_thrust', powers_dict=dict( gross_weight=1., thrust_to_weight=1., ), ) self.add_subsystem('max_thrust_comp', comp, promotes=['*']) # comp = StallWingLoadingComp(shape=shape) self.add_subsystem('stall_wing_loading_comp', comp, promotes=['*']) comp = ClimbThrustToWeightComp(shape=shape) self.add_subsystem('climb_thrust_to_weight_comp', comp, promotes=['*']) comp = TurnThrustToWeightComp(shape=shape) self.add_subsystem('turn_thrust_to_weight_comp', comp, promotes=['*']) if aircraft['thrust_source_type'] == 'jet': TakeoffWingLoadingComp = JetTakeoffWingLoadingComp elif aircraft['thrust_source_type'] == 'propeller': TakeoffWingLoadingComp = PropellerTakeoffWingLoadingComp else: raise Exception() comp = TakeoffWingLoadingComp(shape=shape) self.add_subsystem('takeoff_wing_loading_comp', comp, promotes=['*']) comp = LandingWingLoadingComp(shape=shape) self.add_subsystem('landing_wing_loading_comp', comp, promotes=['*']) # for con_name in [ 'stall', 'takeoff', 'landing', ]: comp = LinearCombinationComp( shape=shape, out_name='{}_wing_loading_constraint'.format(con_name), coeffs_dict={ 'wing_loading': 1., '{}_wing_loading'.format(con_name): -1., }, ) comp.add_constraint('{}_wing_loading_constraint'.format(con_name), indices=[0], upper=0.) self.add_subsystem( '{}_wing_loading_constraint_comp'.format(con_name), comp, promotes=['*']) for con_name in [ 'climb', 'turn', ]: comp = LinearCombinationComp( shape=shape, out_name='{}_thrust_to_weight_constraint'.format(con_name), coeffs_dict={ 'thrust_to_weight': -1., '{}_thrust_to_weight'.format(con_name): 1., }, ) comp.add_constraint( '{}_thrust_to_weight_constraint'.format(con_name), indices=[0], upper=0.) self.add_subsystem( '{}_thrust_to_weight_constraint_comp'.format(con_name), comp, promotes=['*']) comp = PowerCombinationComp( shape=shape, out_name='{}_power_to_weight'.format(con_name), powers_dict={ '{}_thrust_to_weight'.format(con_name): 1., 'cruise_speed': 1., 'propulsive_efficiency': -1., }, ) self.add_subsystem('{}_power_to_weight_comp'.format(con_name), comp, promotes=['*']) a = 0.5 comp = LinearPowerCombinationComp( shape=shape, out_name='sizing_performance_objective', terms_list=[ (1 - a, dict( thrust_to_weight=1., ref_thrust_to_weight=-1., )), (-a, dict( wing_loading=1., ref_wing_loading=-1., )), ], ) self.add_subsystem( 'sizing_performance_objective_comp'.format(con_name), comp, promotes=['*'])
def setup(self): num_times = self.options['num_times'] num_cp = self.options['num_cp'] step_size = self.options['step_size'] cubesat = self.options['cubesat'] mtx = self.options['mtx'] shape = (3, num_times) drag_unit_vec = np.outer( np.array([0., 0., 1.]), np.ones(num_times), ) comp = IndepVarComp() comp.add_output('drag_unit_vec_t_3xn', val=drag_unit_vec) comp.add_output('dry_mass', val=cubesat['dry_mass'], shape=num_times) comp.add_output('radius_earth_km', val=cubesat['radius_earth_km'], shape=num_times) for var_name in ['initial_orbit_state']: comp.add_output(var_name, val=cubesat[var_name]) self.add_subsystem('input_comp', comp, promotes=['*']) # comp = InitialOrbitComp() # self.add_subsystem('initial_orbit_comp', comp, promotes=['*']) comp = LinearCombinationComp( shape=(num_times, ), out_name='mass', coeffs_dict=dict(dry_mass=1., propellant_mass=1.), ) self.add_subsystem('mass_comp', comp, promotes=['*']) if 1: coupled_group = Group() comp = LinearCombinationComp( shape=shape, out_name='force_3xn', coeffs_dict=dict(thrust_3xn=1., drag_3xn=1.), ) coupled_group.add_subsystem('force_3xn_comp', comp, promotes=['*']) comp = RelativeOrbitRK4Comp( num_times=num_times, step_size=step_size, ) coupled_group.add_subsystem('relative_orbit_rk4_comp', comp, promotes=['*']) comp = LinearCombinationComp( shape=(6, num_times), out_name='orbit_state', coeffs_dict=dict( relative_orbit_state=1., reference_orbit_state=1., ), ) coupled_group.add_subsystem('orbit_state_comp', comp, promotes=['*']) comp = LinearCombinationComp( shape=(6, num_times), out_name='orbit_state_km', coeffs_dict=dict(orbit_state=1.e-3), ) coupled_group.add_subsystem('orbit_state_km_comp', comp, promotes=['*']) comp = RotMtxTIComp(num_times=num_times) coupled_group.add_subsystem('rot_mtx_t_i_3x3xn_comp', comp, promotes=['*']) comp = ArrayReorderComp( in_shape=(3, 3, num_times), out_shape=(3, 3, num_times), in_subscripts='ijn', out_subscripts='jin', in_name='rot_mtx_t_i_3x3xn', out_name='rot_mtx_i_t_3x3xn', ) coupled_group.add_subsystem('rot_mtx_i_t_3x3xn_comp', comp, promotes=['*']) comp = MtxVecComp( num_times=num_times, mtx_name='rot_mtx_i_t_3x3xn', vec_name='drag_unit_vec_t_3xn', out_name='drag_unit_vec_3xn', ) coupled_group.add_subsystem('drag_unit_vec_3xn_comp', comp, promotes=['*']) comp = PowerCombinationComp(shape=shape, out_name='drag_3xn', powers_dict=dict( drag_unit_vec_3xn=1., drag_scalar_3xn=1., )) coupled_group.add_subsystem('drag_3xn_comp', comp, promotes=['*']) coupled_group.nonlinear_solver = NonlinearBlockGS(iprint=0, maxiter=40, atol=1e-14, rtol=1e-12) coupled_group.linear_solver = LinearBlockGS(iprint=0, maxiter=40, atol=1e-14, rtol=1e-12) self.add_subsystem('coupled_group', coupled_group, promotes=['*']) comp = OrbitStateDecompositionComp( num_times=num_times, position_name='position_km', velocity_name='velocity_km_s', orbit_state_name='orbit_state_km', ) self.add_subsystem('orbit_state_decomposition_comp', comp, promotes=['*']) comp = LinearCombinationComp( shape=shape, out_name='position', coeffs_dict=dict(position_km=1.e3), ) self.add_subsystem('position_comp', comp, promotes=['*']) comp = LinearCombinationComp( shape=shape, out_name='velocity', coeffs_dict=dict(velocity_km_s=1.e3), ) self.add_subsystem('velocity_comp', comp, promotes=['*']) # group = DecomposeVectorGroup( num_times=num_times, vec_name='position_km', norm_name='radius_km', unit_vec_name='position_unit_vec', ) self.add_subsystem('position_decomposition_group', group, promotes=['*']) group = DecomposeVectorGroup( num_times=num_times, vec_name='velocity_km_s', norm_name='speed_km_s', unit_vec_name='velocity_unit_vec', ) self.add_subsystem('velocity_decomposition_group', group, promotes=['*']) # comp = LinearCombinationComp( shape=(num_times, ), out_name='altitude_km', coeffs_dict=dict(radius_km=1., radius_earth_km=-1.), ) self.add_subsystem('altitude_km_comp', comp, promotes=['*']) comp = KSComp( in_name='altitude_km', out_name='ks_altitude_km', shape=(1, ), constraint_size=num_times, rho=100., lower_flag=True, ) comp.add_constraint('ks_altitude_km', lower=450.) self.add_subsystem('ks_altitude_km_comp', comp, promotes=['*']) comp = PowerCombinationComp(shape=( 6, num_times, ), out_name='relative_orbit_state_sq', powers_dict={ 'relative_orbit_state': 2., }) self.add_subsystem('relative_orbit_state_sq_comp', comp, promotes=['*']) comp = ScalarContractionComp( shape=( 6, num_times, ), out_name='relative_orbit_state_sq_sum', in_name='relative_orbit_state_sq', ) self.add_subsystem('relative_orbit_state_sq_sum_comp', comp, promotes=['*'])
def setup(self): lsm_solver = self.options['lsm_solver'] bpts_xy = self.options['bpts_xy'] segmentLength = self.options['segmentLength'] # area_fraction = self.options['area_fraction'] # fixedGpts_xy = self.options['fixedGpts_xy'] # fixedGpts_sens = self.options['fixedGpts_sens'] radius = self.options['radius'] # movelimit = self.options['movelimit'] bpts_sens = self.options['bpts_sens'] upperbound = self.options['ub'] lowerbound = self.options['lb'] num_dvs = 2 # number of lambdas num_bpts = bpts_xy.shape[0] # inputs (IndepVarComp: component) comp = IndepVarComp() comp.add_output('lambdas', val=0.0, shape=num_dvs) # comp.add_output('fixedGpts_sens', val = fixedGpts_sens) comp.add_output('bpts_sens', val=bpts_sens) self.add_subsystem('inputs_comp', comp) # self.connect('inputs_comp.fixedGpts_sens', 'compl_sens_comp.fixedGpts_sens') self.connect('inputs_comp.lambdas', 'constraint_comp.lambdas') self.connect('inputs_comp.lambdas', 'displacement_comp.lambdas') self.connect('inputs_comp.bpts_sens', 'compliance_scale_comp.x') # # compliance sensitivity at each boundary points # comp = ComplSensComp(lsm_solver = lsm_solver, # bpts_xy = bpts_xy, fixedGpts_xy = fixedGpts_xy, # radius = radius, area_fraction = area_fraction, # movelimit = movelimit, # tmpFix_bpts_sens = tmpFix_bpts_sens,) # self.add_subsystem('compl_sens_comp', comp) # self.connect('compl_sens_comp.bpts_sens', 'compliance_scale_comp.x') # self.add_design_var('inputs_comp.lambdas', # lower = np.array(['compl_sens_comp.lowerbound'[0], 'compl_sens_comp.lowerbound'[1]]), # upper = np.array(['compl_sens_comp.upperbound'[0], 'compl_sens_comp.upperbound'[1]])) self.add_design_var('inputs_comp.lambdas', lower=np.array([lowerbound[0], lowerbound[1]]), upper=np.array([upperbound[0], upperbound[1]])) # constraint setup comp = AreaConstComp(lsm_solver=lsm_solver, num_bpts=num_bpts, num_dvs=num_dvs) comp.add_constraint('G_cons') self.add_subsystem('constraint_comp', comp) self.connect('constraint_comp.bpts_sens', 'constraint_scale_comp.x') # normalize the (compliance sensitivity) comp = ScaleComp(num_bpts=num_bpts) #, num_dvs = num_dvs) self.add_subsystem('compliance_scale_comp', comp) src_indices_tmp = np.zeros((num_bpts, 2), dtype=int) src_indices_tmp[:, 0] = np.arange(num_bpts) self.connect( 'compliance_scale_comp.y', 'displacement_comp.sens_c') #, src_indices=src_indices_tmp) # normalize the (area sensitivity) comp = ScaleComp(num_bpts=num_bpts) #, num_dvs = num_dvs) self.add_subsystem('constraint_scale_comp', comp) src_indices_tmp = np.zeros((num_bpts, 2), dtype=int) src_indices_tmp[:, 1] = np.arange(num_bpts) self.connect( 'constraint_scale_comp.y', 'displacement_comp.sens_a') #,src_indices=src_indices_tmp) # displacement (z) calculation comp = DispComp(lsm_solver=lsm_solver, num_bpts=num_bpts, num_dvs=num_dvs, segmentLength=segmentLength ) #lsm_module = lsm_module, lsm_mesh = lsm_mesh) self.add_subsystem('displacement_comp', comp) self.add_objective('displacement_comp.F_obj')