model.connect('GComp.G','CT1Comp.G') model.connect('CT2Comp.CT2','CT1Comp.CT2') model.add_subsystem('ATComp',ATComp(num_panel=airfoil.NUM_SAMPLES)) model.connect('CT1Comp.CT1','ATComp.CT1') model.connect('CT2Comp.CT2','ATComp.CT2') model.add_subsystem('VelocityComp',VelocityComp(num_panel=airfoil.NUM_SAMPLES,aoa=airfoil.aoa)) model.connect('GammaComp.gamma','VelocityComp.gamma') model.connect('thetaComp.theta','VelocityComp.theta') model.connect('ATComp.AT','VelocityComp.AT') model.add_subsystem('LiftComp',LiftComp(num_panel=airfoil.NUM_SAMPLES)) model.connect('VelocityComp.V','LiftComp.V') model.connect('arcComp.S','LiftComp.S') model.add_design_var('input.y') model.add_objective('LiftComp.CL') leftmost_id = int(airfoil.NUM_SAMPLES/2) model.add_constraint('input.y',indices=[0,leftmost_id,-1],equals=[airfoil.boundaryPoints_Y[0],airfoil.boundaryPoints_Y[leftmost_id],airfoil.boundaryPoints_Y[-1]]) prob = Problem(model=model) prob.driver = ScipyOptimizeDriver() prob.driver.options['optimizer'] = 'SLSQP' prob.driver.options['maxiter'] = 300 prob.driver.options['tol'] = 1e-6 prob.set_solver_print(level=0) prob.model.approx_totals() prob.setup()
def run_open_mdao(): if USE_SCALING: # prepare scaling global offset_weight global offset_stress global scale_weight global scale_stress runner = MultiRun(use_calcu=not USE_ABA, use_aba=USE_ABA, non_liner=False, project_name_prefix=PROJECT_NAME_PREFIX, force_recalc=False) sur = Surrogate(use_abaqus=USE_ABA, pgf=False, show_plots=False, scale_it=False) res, surro = sur.auto_run(SAMPLE_HALTON, 16, SURRO_POLYNOM, run_validation=False) p = runner.new_project_r_t(range_rib[0], range_shell[0]) offset_weight = p.calc_wight() p = runner.new_project_r_t(range_rib[1], range_shell[1]) max_weight = p.calc_wight() offset_stress = surro.predict([range_rib[1], range_shell[1]]) max_stress = surro.predict([range_rib[0], range_shell[0]]) scale_weight = (max_weight - offset_weight) scale_stress = (max_stress - offset_stress) write_mdao_log('iter,time,ribs(float),ribs,shell,stress,weight') model = Group() indeps = IndepVarComp() indeps.add_output('ribs', (22 - offset_rib) / scale_rib) indeps.add_output('shell', (0.0024 - offset_shell) / scale_shell) model.add_subsystem('des_vars', indeps) model.add_subsystem('wing', WingStructureSurro()) model.connect('des_vars.ribs', ['wing.ribs', 'con_cmp1.ribs']) model.connect('des_vars.shell', 'wing.shell') # design variables, limits and constraints model.add_design_var('des_vars.ribs', lower=(range_rib[0] - offset_rib) / scale_rib, upper=(range_rib[1] - offset_rib) / scale_rib) model.add_design_var('des_vars.shell', lower=(range_shell[0] - offset_shell) / scale_shell, upper=(range_shell[1] - offset_shell) / scale_shell) # objective model.add_objective('wing.weight', scaler=0.0001) # constraint print('constrain stress: ' + str((max_shear_strength - offset_stress) / scale_stress)) model.add_constraint('wing.stress', upper=(max_shear_strength - offset_stress) / scale_stress) model.add_subsystem('con_cmp1', ExecComp('con1 = (ribs * '+str(scale_rib)+') - int(ribs[0] * '+str(scale_rib)+')')) model.add_constraint('con_cmp1.con1', upper=.5) prob = Problem(model) # setup the optimization if USE_PYOPTSPARSE: prob.driver = pyOptSparseDriver() prob.driver.options['optimizer'] = OPTIMIZER prob.driver.opt_settings['SwarmSize'] = 8 prob.driver.opt_settings['stopIters'] = 5 else: prob.driver = ScipyOptimizeDriver() prob.driver.options['optimizer'] = OPTIMIZER # ['Nelder-Mead', 'Powell', 'CG', 'BFGS', 'Newton-CG', 'L-BFGS-B', 'TNC', 'COBYLA', 'SLSQP'] prob.driver.options['tol'] = TOL prob.driver.options['disp'] = True prob.driver.options['maxiter'] = 1000 #prob.driver.opt_settings['etol'] = 100 prob.setup() prob.set_solver_print(level=0) prob.model.approx_totals() prob.setup(check=True, mode='fwd') prob.run_driver() print('done') print('ribs: ' + str((prob['wing.ribs'] * scale_rib) + offset_rib)) print('shell: ' + str((prob['wing.shell'] * scale_shell) + offset_shell) + ' m') print('weight= ' + str((prob['wing.weight'] * scale_weight) + offset_weight)) print('stress= ' + str((prob['wing.stress'] * scale_stress) + offset_stress) + ' ~ ' + str(prob['wing.stress'])) print('execution counts wing: ' + str(prob.model.wing.executionCounter))
group.add_subsystem('theta_comp', IndepVarComp('theta', val=np.pi / 3.)) group.add_subsystem('v_comp', IndepVarComp('v', val=1.)) group.add_subsystem('vx_comp', ExecComp('vx = v * cos(theta)')) group.add_subsystem('vy_comp', ExecComp('vy = v * sin(theta)')) group.add_subsystem('integrator_group', integrator) group.connect('final_time_comp.final_time', 'integrator_group.final_time') group.connect('theta_comp.theta', 'vx_comp.theta') group.connect('theta_comp.theta', 'vy_comp.theta') group.connect('v_comp.v', 'vx_comp.v') group.connect('v_comp.v', 'vy_comp.v') group.connect('vx_comp.vx', 'integrator_group.initial_condition:vx') group.connect('vy_comp.vy', 'integrator_group.initial_condition:vy') group.add_design_var('final_time_comp.final_time', lower=1e-3) group.add_design_var('theta_comp.theta', lower=0., upper=np.pi / 2.) group.add_constraint('integrator_group.state:y', indices=[-1], equals=0.) group.add_objective('integrator_group.state:x', index=-1, scaler=-1.) prob = Problem() prob.model = group prob.driver = ScipyOptimizeDriver() prob.driver.options['optimizer'] = 'SLSQP' # from openmdao.api import pyOptSparseDriver # prob.driver = driver = pyOptSparseDriver() # driver.options['optimizer'] = 'SNOPT' # driver.opt_settings['Verify level'] = 0 # driver.opt_settings['Major iterations limit'] = 200 #1000 # driver.opt_settings['Minor iterations limit'] = 1000