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')
Esempio n. 3
0
model = Group()

comp = IndepVarComp()
comp.add_output('W0', val=50000)
comp.add_output('Swing', val=1000)
comp.add_design_var('W0', lower=30000)
model.add_subsystem('inputs_comp', comp, promotes=['*'])


comp = wingWeightComp(N=3.,tc=0.3,AR=9.,sweep=30.)
model.add_subsystem('wingWeight', comp, promotes=['*'])


comp = ExecComp('totalWeight = Wwing')
comp.add_objective('totalWeight', scaler=40000.) 
model.add_subsystem('total_comp', comp, promotes=['*'])


prob.model = model

prob.driver = ScipyOptimizeDriver()
prob.driver.options['optimizer'] = 'SLSQP'
prob.driver.options['tol'] = 1e-15
prob.driver.options['disp'] = True

prob.setup()
prob.run_model()
prob.run_driver()

prob.check_partials(compact_print=True)
    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')
Esempio n. 5
0
    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')
Esempio n. 6
0
comp.add_output('Cl', val=1.0)
comp.add_design_var('density', upper=0.0)
model.add_subsystem('inputs_comp', comp, promotes=['*'])

# atmosphere_group = Atmosphere()
# # model.add_subsystem('atmosphere_group', atmosphere_group)
# model.add_subsystem('atmosphere_group', subsys=Atmosphere())


comp = liftComp()
model.add_subsystem('lift', comp, promotes=['*'])



comp = ExecComp('Weight = lift')
comp.add_objective('Weight', scaler=120000.)  #weight in kg
model.add_subsystem('vertEqui_comp', comp, promotes=['*'])



prob.model = model

prob.driver = ScipyOptimizeDriver()
prob.driver.options['optimizer'] = 'SLSQP'
prob.driver.options['tol'] = 1e-15
prob.driver.options['disp'] = True

prob.setup()
prob.run_model()
prob.run_driver()
prob.model.list_outputs()
Esempio n. 7
0
else:
    from lsdo_utils.api import PowerCombinationComp
    comp = PowerCombinationComp(shape=(1, ),
                                out_name='CDi',
                                coeff=1. / np.pi / e,
                                powers_dict=dict(
                                    CL=2.,
                                    AR=-1.,
                                ))
    model.add_subsystem('cdi_comp', comp, promotes=['*'])

comp = ExecComp('CD = CD0 + CDi')
model.add_subsystem('cd_comp', comp, promotes=['*'])

comp = ExecComp('LD = CL/CD')
comp.add_objective('LD', scaler=-1.)
model.add_subsystem('ld_comp', comp, promotes=['*'])

prob.model = model

prob.driver = ScipyOptimizeDriver()
prob.driver.options['optimizer'] = 'SLSQP'
prob.driver.options['tol'] = 1e-15
prob.driver.options['disp'] = True

prob.setup()
prob.run_model()
prob.run_driver()

prob.check_partials(compact_print=True)
Esempio n. 8
0
    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)