segioaero
segioaero

Reputation: 13

SLSQP does not drive array as a design variable

I am a newbie in openmdao. Recently I am trying to implement a dummy wing optimization problem to learn openmdao. I have come up with a weird problem that I wanted to ask about. I am using a bspline to define twist and t/c distribution. The optimization setup is working when I use COBYLA, DifferentialEvolution or DOEdriver as the driver. But when I set SciPy SLSQP, the control points for these splines does not change during iterations. What could be the problem?

Below is the main section where I define the problem...

if __name__ == '__main__':
    
    driver = om.ScipyOptimizeDriver() ;   
    driver.options['optimizer']='SLSQP' 
    
    driver = om.DOEDriver(om.LatinHypercubeGenerator(samples=10))
       
    
    recorder_name ='cases'
    recorder = om.SqliteRecorder(recorder_name+'.sql')
    
    driver = om.DifferentialEvolutionDriver()
    driver.options['max_gen']=10
    
     
    
    min_step = 0.01
    n_cp = 4
    n_vsp_segment = 4
    
    ivc = om.IndepVarComp()
    ivc.add_output('Mach',0.2)
    ivc.add_output('b',7.)
    ivc.add_output('cr',3.)
    ivc.add_output('taper',0.5)
    ivc.add_output('twist_cp',np.ones(n_cp))
    ivc.add_output('tc_cp',np.ones(n_cp)*0.1)
    
    Scomp = om.SplineComp(method='bsplines',x_interp_val = np.linspace(0.,1.,int(n_vsp_segment)),
                          num_cp = n_cp, interp_options={"order": min(n_cp, 4)})
    Scomp.add_spline(y_cp_name='twist',y_interp_name='twist_vsp')
    Scomp.add_spline(y_cp_name='tc',y_interp_name='tc_vsp')
       
    
    model = om.Group()
    model.add_subsystem('IVC',ivc)
    model.add_subsystem('spline',Scomp)    
    model.add_subsystem('VSP',VSP(n_vsp_segment=n_vsp_segment))  
    model.add_subsystem('AVL',AVL())    
    model.add_subsystem('obj',om.ExecComp('obj = (CD0+CDi)*100+0.1/tr'))
    model.add_subsystem('cons',om.ExecComp('c1 = Sref-40.'))
    
    model.connect('IVC.twist_cp','spline.twist')
    model.connect('spline.twist_vsp','VSP.twist')
    
    model.connect('IVC.tc_cp','spline.tc')
    model.connect('spline.tc_vsp','VSP.tc')
    
    model.connect('IVC.Mach',['VSP.Mach','AVL.Mach'])
    model.connect('IVC.b',['VSP.b','AVL.b'])
    model.connect('IVC.cr','VSP.cr')
    model.connect('IVC.taper','VSP.taper')
    
    model.connect('VSP.CD0','obj.CD0')
    model.connect('VSP.Sref',['AVL.Sref','cons.Sref'])
    model.connect('VSP.Cref','AVL.Cref')
    model.connect('VSP.MOMref','AVL.MOMref')
    model.connect('VSP.tr','obj.tr')
    
    model.connect('AVL.CDi','obj.CDi') 
    
    
    prob = om.Problem(model,driver)
    prob.model.add_design_var('IVC.tc_cp',lower=0.05,upper=0.1,indices=[1,2,3])
    prob.model.add_design_var('IVC.twist_cp',lower=-10.,upper=2.,indices=[1,2,3])
    prob.model.add_design_var('IVC.cr',lower=2,upper=6)
    prob.model.add_design_var('IVC.b',lower=10,upper=20)
    prob.model.add_design_var('IVC.taper',lower=0.2,upper=0.9) 
    prob.model.add_constraint('cons.c1',upper=0)
    prob.model.add_objective('obj.obj',scaler=100)
    
    prob.setup(check=True)
      
    prob.set_val('IVC.cr',4.)
    prob.set_val('IVC.b',10.)
    prob.set_val('IVC.taper',0.8)
    
    prob.driver.options['debug_print'] = ['desvars','ln_cons','nl_cons','objs']
    
    prob.run_driver()

Upvotes: 1

Views: 111

Answers (1)

Justin Gray
Justin Gray

Reputation: 5710

Your problem seems to be working with gradient free methods, but not with gradient based one. Hence it's a safe bet that there is a problem with the derivatives.

I'm going to assume that since you're using VSP and AVL, that you're doing finite differences. You likely need to set up different FD settings to get decent derivative approximations. You probably want to use the [appox_totals][1] method at the top level of your problem.

You will likely need to experiment with larger FD steps sizes and absolute vs relative steps. You can get a visualization of what your intial jacobian looks like using the OpenMDAO scaling report. Your problem doesn't look badly scaled at first glance, but the jacobian visualization in that report might be helpful to you as you test FD step sizes.

Upvotes: 2

Related Questions