def configure(self): """ Creates a new Assembly containing a Paraboloid and an optimizer""" # Create Paraboloid component instances self.add('comp', ParaboloidDerivative()) # Create Optimizer instance self.add('driver', CONMINdriver()) # Driver process definition self.driver.workflow.add('comp') # Objective self.driver.add_objective('comp.f_xy') # Design Variables self.driver.add_parameter('comp.x', low=-50., high=50.) self.driver.add_parameter('comp.y', low=-50., high=50.) # Inequality Constraints # self.driver.add_constraint('comp.x-comp.y >= 15.0') # Equality Constraints # self.driver.add_constraint('comp.x-comp.y=15.0') # General flag - suppress output self.driver.iprint = 0 # CONMIN-specific Settings self.driver.itmax = 30 self.driver.fdch = 0.00001 self.driver.fdchm = 0.000001 self.driver.ctlmin = 0.01 self.driver.delfun = 0.001
def configure(self): # pylint: disable-msg=E1101 # Create CONMIN Optimizer instance self.add('driver', CONMINdriver()) # Create Vehicle instance self.add('vehicle', Vehicle()) # Create Driving Simulation instances self.add('sim_acc', SimAcceleration()) self.add('sim_EPA_city', SimEconomy()) self.add('sim_EPA_highway', SimEconomy()) # add Sims to optimizer workflow self.driver.workflow.add( ['sim_acc', 'sim_EPA_city', 'sim_EPA_highway']) # Add vehicle to sim workflows. self.sim_acc.workflow.add('vehicle') self.sim_EPA_city.workflow.add('vehicle') self.sim_EPA_highway.workflow.add('vehicle') # CONMIN Flags self.driver.iprint = 0 self.driver.itmax = 30 # CONMIN Objective self.driver.add_objective('sim_acc.accel_time') # CONMIN Design Variables self.driver.add_parameter('vehicle.spark_angle', -50., 10.) self.driver.add_parameter('vehicle.bore', 65., 100.) # Acceleration Sim setup self.sim_acc.velocity_str = 'vehicle.velocity' self.sim_acc.throttle_str = 'vehicle.throttle' self.sim_acc.gear_str = 'vehicle.current_gear' self.sim_acc.acceleration_str = 'vehicle.acceleration' self.sim_acc.overspeed_str = 'vehicle.overspeed' # EPA City MPG Sim Setup self.sim_EPA_city.velocity_str = 'vehicle.velocity' self.sim_EPA_city.throttle_str = 'vehicle.throttle' self.sim_EPA_city.gear_str = 'vehicle.current_gear' self.sim_EPA_city.acceleration_str = 'vehicle.acceleration' self.sim_EPA_city.fuel_burn_str = 'vehicle.fuel_burn' self.sim_EPA_city.overspeed_str = 'vehicle.overspeed' self.sim_EPA_city.underspeed_str = 'vehicle.underspeed' self.sim_EPA_city.profilename = 'EPA-city.csv' # EPA Highway MPG Sim Setup self.sim_EPA_highway.velocity_str = 'vehicle.velocity' self.sim_EPA_highway.throttle_str = 'vehicle.throttle' self.sim_EPA_highway.gear_str = 'vehicle.current_gear' self.sim_EPA_highway.acceleration_str = 'vehicle.acceleration' self.sim_EPA_highway.fuel_burn_str = 'vehicle.fuel_burn' self.sim_EPA_highway.overspeed_str = 'vehicle.overspeed' self.sim_EPA_highway.underspeed_str = 'vehicle.underspeed' self.sim_EPA_highway.profilename = 'EPA-highway.csv'
def __init__(self): """ Creates a new Assembly containing a Paraboloid and an optimizer""" # pylint: disable-msg=E1101 super(OptimizationConstrained, self).__init__() # Create Paraboloid component instances self.add('paraboloid', Paraboloid()) # Create CONMIN Optimizer instance self.add('driver', CONMINdriver()) # Driver process definition self.driver.workflow.add('paraboloid') # CONMIN Flags self.driver.iprint = 0 self.driver.itmax = 30 self.driver.fdch = .000001 self.driver.fdchm = .000001 # CONMIN Objective self.driver.add_objective('paraboloid.f_xy') # CONMIN Design Variables self.driver.add_parameter('paraboloid.x', low=-50., high=50.) self.driver.add_parameter('paraboloid.y', low=-50., high=50.) # CONMIN Constraints self.driver.add_constraint('paraboloid.x-paraboloid.y >= 15.0')
def __init__(self): """ Creates a new Assembly containing a Bar3_Truss and an optimizer""" super(Bar3Optimization, self).__init__() # Create Bar3_Truss component instances bartruss = Bar3Truss() bartruss.stdout = os.devnull bartruss.stderr = os.devnull bartruss.nastran_filename = "vared_bar3.bdf" bartruss.nastran_command = "/msc/nastran/bin/nastran" self.add('bar3_truss', bartruss) # Create CONMIN Optimizer instance self.add('driver', CONMINdriver()) # CONMIN Flags self.driver.iprint = 0 self.driver.itmax = 30 self.driver.fdch = .00001 self.driver.fdchm = .00001 self.driver.ct = 0.00001 # genetic driver #self.add_container('driver', Genetic()) # CONMIN Objective self.driver.objective = 'bar3_truss.weight' # CONMIN Design Variables self.driver.design_vars = ['bar3_truss.bar1_area', 'bar3_truss.bar2_area', 'bar3_truss.bar3_area'] self.driver.lower_bounds = [0.001, 0.001, 0.001] self.driver.upper_bounds = [10000.0, 10000.0, 10000.0] # CONMIN Constraints bar1_stress_allowable = self.bar1_stress_allowable bar2_stress_allowable = self.bar2_stress_allowable bar3_stress_allowable = self.bar3_stress_allowable displacement_x_dir_allowable = self.displacement_x_dir_allowable displacement_y_dir_allowable = self.displacement_y_dir_allowable frequency_allowable = self.frequency_allowable self.driver.constraints = [ \ '(bar3_truss.bar1_stress/bar1_stress_allowable)-1.0', '(bar3_truss.bar2_stress/bar2_stress_allowable)-1.0', '(bar3_truss.bar3_stress/bar3_stress_allowable)-1.0', '(bar3_truss.displacement_x_dir/displacement_x_dir_allowable)-1.0', '(bar3_truss.displacement_y_dir/displacement_y_dir_allowable)-1.0',]
def __init__(self): """ Creates a new Assembly with this problem Optimal Design at (1.9776, 0, 0) Optimal Objective = 3.18339""" # pylint: disable-msg=E1101 super(SellarMDF, self).__init__() # create Optimizer instance self.add('driver', CONMINdriver()) # Outer Loop - Global Optimization self.add('solver', BroydenSolver()) self.driver.workflow.add('solver') # Inner Loop - Full Multidisciplinary Solve via fixed point iteration self.add('dis1', sellar.Discipline1()) self.add('dis2', sellar.Discipline2()) self.solver.workflow.add(['dis1', 'dis2']) # Make all connections self.connect('dis1.y1','dis2.y1') # Iteration loop self.solver.add_parameter('dis1.y2', low=-9.e99, high=9.e99) self.solver.add_constraint('dis2.y2 = dis1.y2') # equivilent form # self.solver.add_constraint('dis2.y2 - dis1.y2 = 0') #Driver Settings self.solver.itmax = 10 self.solver.alpha = .4 self.solver.tol = .0000001 self.solver.algorithm = "broyden2" # Optimization parameters self.driver.add_objective('(dis1.x1)**2 + dis1.z2 + dis1.y1 + math.exp(-dis2.y2)') for param, low, high in zip([('dis1.z1','dis2.z1'), ('dis1.z2','dis2.z2'), 'dis1.x1'], [-10.0, 0.0, 0.0], [10.0, 10.0, 10.0]): self.driver.add_parameter(param, low=low, high=high) map(self.driver.add_constraint, ['3.16 < dis1.y1', 'dis2.y2 < 24.0' ]) self.driver.cons_is_linear = [1, 1] self.driver.iprint = 0 self.driver.itmax = 30 self.driver.fdch = .001 self.driver.fdchm = .001 self.driver.delfun = .0001 self.driver.dabfun = .000001 self.driver.ctlmin = 0.0001
def __init__(self): """ Creates a new Assembly with this problem Optimal Design at (1.9776, 0, 0) Optimal Objective = 3.18339""" super(SellarMDF, self).__init__() # create Optimizer instance self.add('driver', CONMINdriver()) # Outer Loop - Global Optimization self.add('solver', FixedPointIterator()) self.driver.workflow.add(['solver']) # Inner Loop - Full Multidisciplinary Solve via fixed point iteration self.add('dis1', sellar.Discipline1()) self.add('dis2', sellar.Discipline2()) self.solver.workflow.add(['dis1', 'dis2']) # Add Parameters to optimizer self.driver.add_parameter(('dis1.z1','dis2.z1'), low = -10.0, high = 10.0) self.driver.add_parameter(('dis1.z2','dis2.z2'), low = 0.0, high = 10.0) self.driver.add_parameter('dis1.x1', low = 0.0, high = 10.0) # Make all connections self.connect('dis1.y1','dis2.y1') # Iteration loop self.solver.add_parameter('dis1.y2', low=-9.e99, high=9.e99) self.solver.add_constraint('dis2.y2 = dis1.y2') # equivilent form # self.solver.add_constraint('dis2.y2 - dis1.y2 = 0') #Driver settings self.solver.max_iteration = 1000 self.solver.tolerance = .0001 # Optimization parameters self.driver.add_objective('(dis1.x1)**2 + dis1.z2 + dis1.y1 + math.exp(-dis2.y2)') self.driver.add_constraint('3.16 < dis1.y1') self.driver.add_constraint('dis2.y2 < 24.0') self.driver.cons_is_linear = [1, 1] self.driver.iprint = 0 self.driver.itmax = 30 self.driver.fdch = .001 self.driver.fdchm = .001 self.driver.delfun = .0001 self.driver.dabfun = .000001 self.driver.ctlmin = 0.0001
def __init__(self): """ Creates a new Assembly with this problem Optimal Design at (1.9776, 0, 0) Optimal Objective = 3.18339""" super(SellarIDF, self).__init__() # create Optimizer instance self.add('driver', CONMINdriver()) # Disciplines self.add('dis1', sellar.Discipline1()) self.add('dis2', sellar.Discipline2()) # Driver process definition self.driver.workflow.add(['dis1', 'dis2']) # Optimization parameters self.driver.add_objective( '(dis1.x1)**2 + dis1.z2 + dis1.y1 + math.exp(-dis2.y2)') #Global Design Variables self.driver.add_parameter(('dis1.z1', 'dis2.z1'), low=-10.0, high=10.0) self.driver.add_parameter(('dis1.z2', 'dis2.z2'), low=0.0, high=10.0) #Local Design Variables and Coupling Variables self.driver.add_parameter('dis1.x1', low=0.0, high=10.0) self.driver.add_parameter('dis2.y1', low=3.16, high=10.0) self.driver.add_parameter('dis1.y2', low=-10.0, high=24.0) self.driver.add_constraint('(dis2.y1-dis1.y1)**3 <= 0') self.driver.add_constraint('(dis1.y1-dis2.y1)**3 <= 0') self.driver.add_constraint('(dis2.y2-dis1.y2)**3 <= 0') self.driver.add_constraint('(dis1.y2-dis2.y2)**3 <= 0') self.driver.iprint = 0 self.driver.itmax = 100 self.driver.fdch = .003 self.driver.fdchm = .003 self.driver.delfun = .0001 self.driver.dabfun = .00001 self.driver.ct = -.01 self.driver.ctlmin = 0.001
def test_CONMIN(self): top = set_as_top(Assembly()) top.add('parab1', Parab1()) top.add('parab2', Parab2()) top.add('driver', CONMINdriver()) top.driver.workflow.add(['parab1', 'parab2']) top.driver.add_parameter(['parab1.x', 'parab2.x'], low=-100, high=100) top.driver.add_parameter(['parab1.y', 'parab2.y'], low=-100, high=100) top.driver.add_objective('parab1.f_xy + parab2.f_xy') top.driver.add_constraint('parab1.x-parab1.y >= 15.0') top.run() assert_rel_error(self, top.parab1.x, 7.176, 0.001) assert_rel_error(self, top.parab1.y, -7.824, 0.001) assert_rel_error(self, top._pseudo_0.out0, -27.083, 0.001)
def configure(self): self.add('writer', WriteFile()) self.add('c2', EvalParaboloid()) self.connect('writer.file_out', 'c2.file_in') self.add('driver', CONMINdriver()) self.driver.workflow.add(['writer', 'c2']) self.driver.add_parameter( 'writer.x', low=-50., high=50., ) self.driver.add_parameter( 'writer.y', low=-50., high=50., ) self.driver.add_objective('c2.f_xy') self.driver.conmin_diff = True
def __init__(self): """ Creates a new Assembly containing a Bar3_Truss and an optimizer""" super(Bar3Optimization, self).__init__() # Create CONMIN Optimizer instance self.add('driver', CONMINdriver()) # Create Bar3_Truss component instances self.add('bar3_truss', Bar3Truss()) self.driver.workflow.add('bar3_truss') # CONMIN Flags self.driver.iprint = 0 self.driver.itmax = 30 self.driver.fdch = .00001 self.driver.fdchm = .00001 self.driver.ct = -.001 # CONMIN Objective self.driver.add_objective('bar3_truss.weight') # CONMIN Design Variables for param, low, high in zip([ 'bar3_truss.bar1_area', 'bar3_truss.bar2_area', 'bar3_truss.bar3_area' ], [0.001, 0.001, 0.001], [10000.0, 10000.0, 10000.0]): self.driver.add_parameter(param, low=low, high=high) # CONMIN Constraints constraints = [ '(bar3_truss.bar1_stress/bar1_stress_allowable) <= 1.0', '(bar3_truss.bar2_stress/bar2_stress_allowable) <= 1.0', '(bar3_truss.bar3_stress/bar3_stress_allowable) <= 1.0', '(bar3_truss.displacement_x_dir/displacement_x_dir_allowable) <= 1.0', '(bar3_truss.displacement_y_dir/displacement_y_dir_allowable) <= 1.0', 'frequency_allowable**2 <= bar3_truss.frequency**2' ] map(self.driver.add_constraint, constraints)
def configure(self): """ Creates a new Assembly with this problem Optimal Design at (1.9776, 0, 0) Optimal Objective = 3.18339""" # Disciplines self.add('dis12lin', Dis12Linear()) self.connect('z_store', 'dis12lin.z_store') # Global Optimization self.add('sysopt', CONMINdriver()) self.sysopt.add_parameter('z_store[0]', low=-10.0, high=10.0, start=5.0) self.sysopt.add_objective('dis12lin.obj') self.driver.workflow.add(['sysopt']) self.sysopt.workflow.add(['dis12lin'])
def configure(self): # Create an optimizer instance (Uncomment the following statement if SLSQP driver # is to be used, and comment the next statement. # self.add('driver', SLSQPdriver()) self.add('driver', CONMINdriver()) # Create Anopp2 component instance. self.add('anopp2', Anopp2Component()) # Iteration hierarchy self.driver.workflow.add('anopp2') # SLSQP Flags self.driver.iprint = 1 # Objective self.driver.add_objective('anopp2.Epndb_inverse') # Design variable self.driver.add_parameter('anopp2.x', low=2400., high=3500.0) # Set the SLSQP-specific settings. Uncomment the following if SLSQP Driver is to # be used. # self.driver.accuracy = 1.0e-08 # self.driver.maxiter = 50 # Set the CONMIN-specific settings. Comment the following if SLSQP Driver is to be # used. self.driver.itmax = 30 self.driver.fdch = 0.001 self.driver.fdchm = 0.0001 self.driver.ctlmin = 0.01 self.driver.delfun = 0.01 self.driver.conmin_diff = True self.iIteration = 0
def configure(self): dep_couple_vars = set([c.dep.target for c in self.couple_deps]) self.add(self.component.name,self.component) for i,p in enumerate(self.global_params): name = "global_%d"%i self.var_map[p.target] = name self.add_trait(name,Float(0.0,iotype="in",desc="global design var for %s"%p.target.split(".")[-1])) self.connect(name,p.target) #promote the global des vars #setattr(self,name,self.get(p.target)) if self.local_params: #if there are none, you don't do an optimization self.add('objective_comp',SubSystemObj(len(dep_couple_vars))) self.weights = self.objective_comp.weights self.var_names = self.objective_comp.var_names self.add('driver',CONMINdriver()) self.driver.add_objective("objective_comp.f_wy") self.driver.fdch = .00001 #self.driver.fdchm = .0001 #this is not really necessary, but you might want to track it anyway... self.create_passthrough("objective_comp.f_wy") #promote the objective function for i,p in enumerate(self.local_params): target = p.target var_name = "local_%d"%i self.var_map[target] = var_name #since the local variables are optimized, they become outputs now broadcast_name = 'output_%s'%var_name self.add(broadcast_name,Broadcast()) self.add_trait(var_name,Float(0.0,iotype="out",desc="localy optimized value for %s"%target)) #setattr(self,var_name,self.get(target)) self.connect("%s.output"%broadcast_name,target) #connect broadcast output to input of component self.connect("%s.output"%broadcast_name,var_name) #connect broadcast output to variable in assembly self.driver.add_parameter("%s.input"%broadcast_name,low=p.low,high=p.high) #optimizer varries broadcast input for c in self.constraints: self.driver.add_constraint(str(c)) for i,(w,var,c) in enumerate(zip(self.objective_comp.weights, self.objective_comp.var_names, dep_couple_vars)): name = "couple_dep_%d"%i self.var_map[c] = name self.add_trait(name,Float(0.0,iotype="out",desc="coupling dependent for %s"%c)) self.connect(c,name) #prmote the coupling deps to be outputs self.connect(c,"objective_comp.%s"%var) #also connect the state vars to the inputs of the objective come self.create_passthrough("objective_comp.%s"%w) #promote the weights else: #no locals, so just promote the coupling deps #no optimizer, so add the comp to the default workflow self.driver.workflow.add(self.component.name) for i,c in enumerate(dep_couple_vars): name = "couple_dep_%d"%i self.var_map[c] = name self.add_trait(name,Float(0.0,iotype="out",desc="coupling dependent for %s"%c)) self.connect(c,name) #prmote the coupling deps to be outputs for i,c in enumerate(self.couple_indeps): name = "couple_indep_%d"%i self.var_map[c.indep.target] = name self.add_trait(name,Float(0.0,iotype="in",desc="coupling independent for %s"%c)) self.connect(name,c.indep.target)
def __init__(self): """ Creates a new Assembly for vehicle performance optimization.""" super(EngineOptimization, self).__init__() # pylint: disable-msg=E1101 # Create CONMIN Optimizer instance self.add('optimizer', CONMINdriver()) # Create Vehicle instance self.add('vehicle', Vehicle()) # Create Driving Simulation instances self.add('sim_acc', SimAcceleration()) self.add('sim_EPA_city', SimEconomy()) self.add('sim_EPA_highway', SimEconomy()) # add the optimizer and economy sims to driver workflow self.driver.workflow.add( ['optimizer', 'sim_EPA_city', 'sim_EPA_highway']) # add the acceleration sim to the optimizer workflow self.optimizer.workflow.add('sim_acc') # Add vehicle to sim workflows. self.sim_acc.workflow.add('vehicle') self.sim_EPA_city.workflow.add('vehicle') self.sim_EPA_highway.workflow.add('vehicle') # CONMIN Flags self.optimizer.iprint = 0 self.optimizer.itmax = 30 # CONMIN Objective self.optimizer.add_objective('sim_acc.accel_time') # CONMIN Design Variables self.optimizer.add_parameter('vehicle.spark_angle', -50., 10.) self.optimizer.add_parameter('vehicle.bore', 65., 100.) # Acceleration Sim setup self.sim_acc.velocity_str = 'vehicle.velocity' self.sim_acc.throttle_str = 'vehicle.throttle' self.sim_acc.gear_str = 'vehicle.current_gear' self.sim_acc.acceleration_str = 'vehicle.acceleration' self.sim_acc.overspeed_str = 'vehicle.overspeed' # EPA City MPG Sim Setup self.sim_EPA_city.velocity_str = 'vehicle.velocity' self.sim_EPA_city.throttle_str = 'vehicle.throttle' self.sim_EPA_city.gear_str = 'vehicle.current_gear' self.sim_EPA_city.acceleration_str = 'vehicle.acceleration' self.sim_EPA_city.fuel_burn_str = 'vehicle.fuel_burn' self.sim_EPA_city.overspeed_str = 'vehicle.overspeed' self.sim_EPA_city.underspeed_str = 'vehicle.underspeed' self.sim_EPA_city.profilename = 'EPA-city.csv' self.sim_EPA_city.force_execute = True # EPA Highway MPG Sim Setup self.sim_EPA_highway.velocity_str = 'vehicle.velocity' self.sim_EPA_highway.throttle_str = 'vehicle.throttle' self.sim_EPA_highway.gear_str = 'vehicle.current_gear' self.sim_EPA_highway.acceleration_str = 'vehicle.acceleration' self.sim_EPA_highway.fuel_burn_str = 'vehicle.fuel_burn' self.sim_EPA_highway.overspeed_str = 'vehicle.overspeed' self.sim_EPA_highway.underspeed_str = 'vehicle.underspeed' self.sim_EPA_highway.profilename = 'EPA-highway.csv' self.sim_EPA_highway.force_execute = True
def configure(self): self.add('comp', Conn_Bounds()) self.add('driver', CONMINdriver()) self.driver.workflow.add(('comp'))
#self.driver.add_parameter( #"Orbit_Initial.RAAN", low=-180, high=180) #self.driver.add_parameter( #"Orbit_Initial.Inc", low=0, high=90) #self.driver.add_parameter( #"Orbit_Initial.argPerigee", low=0, high=90) if __name__ == "__main__": import time from scipy.optimize import fmin, fmin_slsqp print 30 * "-" print "with OpenMDAO optimizer:" a = CADRE_Launch(10) a.Orbit_Initial.Inc = 15 #a.add('driver', SLSQPdriver()) a.add('driver', CONMINdriver()) a.driver.conmin_diff = True a.driver.add_objective("-Lat_uniform.k - Lon_uniform.k") a.driver.add_parameter( ["Orbit_Initial.altPerigee", "Orbit_Initial.altApogee"], low=500, high=1000) a.driver.add_parameter( "Orbit_Initial.RAAN", low=-180, high=180) a.driver.add_parameter( "Orbit_Initial.Inc", low=0, high=90) a.driver.add_parameter( "Orbit_Initial.argPerigee", low=0, high=90) tt = time.time() a.run() #outputs = ['Orbit_Dynamics.r_e2b_I'] outputs = None
def configure(self): """ Creates a new Assembly with this problem Optimal Design at (1.9776, 0, 0) Optimal Objective = 3.18339""" # Disciplines self.add('dis1', sellar.Discipline1()) self.add('dis2', sellar.Discipline2()) objective = '(dis1.x1)**2 + dis1.z2 + dis1.y1 + exp(-dis2.y2)' constraint1 = 'dis1.y1 > 3.16' constraint2 = 'dis2.y2 < 24.0' # Top level is Fixed-Point Iteration self.add('driver', FixedPointIterator()) self.driver.add_parameter('dis1.x1', low=0.0, high=10.0, start=1.0) self.driver.add_parameter(['dis1.z1', 'dis2.z1'], low=-10.0, high=10.0, start=5.0) self.driver.add_parameter(['dis1.z2', 'dis2.z2'], low=0.0, high=10.0, start=2.0) self.driver.add_constraint('x1_store = dis1.x1') self.driver.add_constraint('z_store[0] = dis1.z1') self.driver.add_constraint('z_store[1] = dis1.z2') self.driver.max_iteration = 50 self.driver.tolerance = .001 # Multidisciplinary Analysis self.add('mda', BroydenSolver()) self.mda.add_parameter('dis1.y2', low=-9.e99, high=9.e99, start=0.0) self.mda.add_constraint('dis2.y2 = dis1.y2') self.mda.add_parameter('dis2.y1', low=-9.e99, high=9.e99, start=3.16) self.mda.add_constraint('dis2.y1 = dis1.y1') # Discipline 1 Sensitivity Analysis self.add('sa_dis1', SensitivityDriver()) self.sa_dis1.workflow.add(['dis1']) self.sa_dis1.add_parameter('dis1.x1', low=0.0, high=10.0, fd_step=.001) self.sa_dis1.add_constraint(constraint1) self.sa_dis1.add_constraint(constraint2) self.sa_dis1.add_objective(objective, name='obj') # Discipline 2 Sensitivity Analysis # dis2 has no local parameter, so there is no need to treat it as # a subsystem. # System Level Sensitivity Analysis # Note, we cheat here and run an MDA instead of solving the # GSE equations. Have to put this on the TODO list. self.add('ssa', SensitivityDriver()) self.ssa.workflow.add(['mda']) self.ssa.add_parameter(['dis1.z1', 'dis2.z1'], low=-10.0, high=10.0) self.ssa.add_parameter(['dis1.z2', 'dis2.z2'], low=0.0, high=10.0) self.ssa.add_constraint(constraint1) self.ssa.add_constraint(constraint2) self.ssa.add_objective(objective, name='obj') # Discipline Optimization # (Only discipline1 has an optimization input) self.add('bbopt1', CONMINdriver()) self.bbopt1.add_parameter('x1_store', low=0.0, high=10.0, start=1.0) self.bbopt1.add_objective( 'sa_dis1.F[0] + sa_dis1.dF[0][0]*(x1_store-dis1.x1)') self.bbopt1.add_constraint( 'sa_dis1.G[0] + sa_dis1.dG[0][0]*(x1_store-dis1.x1) < 0') #this one is technically unncessary self.bbopt1.add_constraint( 'sa_dis1.G[1] + sa_dis1.dG[1][0]*(x1_store-dis1.x1) < 0') self.bbopt1.add_constraint('(x1_store-dis1.x1)<.5') self.bbopt1.add_constraint('(x1_store-dis1.x1)>-.5') self.bbopt1.iprint = 0 self.bbopt1.linobj = True # Global Optimization self.add('sysopt', CONMINdriver()) self.sysopt.add_parameter('z_store[0]', low=-10.0, high=10.0, start=5.0) self.sysopt.add_parameter('z_store[1]', low=0.0, high=10.0, start=2.0) self.sysopt.add_objective( 'ssa.F[0]+ ssa.dF[0][0]*(z_store[0]-dis1.z1) + ssa.dF[0][1]*(z_store[1]-dis1.z2)' ) self.sysopt.add_constraint( 'ssa.G[0] + ssa.dG[0][0]*(z_store[0]-dis1.z1) + ssa.dG[0][1]*(z_store[1]-dis1.z2) < 0' ) self.sysopt.add_constraint( 'ssa.G[1] + ssa.dG[1][0]*(z_store[0]-dis1.z1) + ssa.dG[1][1]*(z_store[1]-dis1.z2) < 0' ) self.sysopt.add_constraint('z_store[0]-dis1.z1<.5') self.sysopt.add_constraint('z_store[0]-dis1.z1>-.5') self.sysopt.add_constraint('z_store[1]-dis1.z2<.5') self.sysopt.add_constraint('z_store[1]-dis1.z2>-.5') self.sysopt.iprint = 0 self.sysopt.linobj = True self.driver.workflow.add(['ssa', 'sa_dis1', 'bbopt1', 'sysopt'])
def configure(self): """setup and MDF architecture inside this assembly. """ #create the top level optimizer self.parent.add("driver", CONMINdriver()) self.parent.driver.cons_is_linear = [1] * len( self.parent.list_constraints()) self.parent.driver.iprint = 0 self.parent.driver.itmax = 30 self.parent.driver.fdch = .001 self.parent.driver.fdchm = .001 self.parent.driver.delfun = .0001 self.parent.driver.dabfun = .000001 self.parent.driver.ctlmin = 0.0001 params = self.parent.get_parameters() global_dvs = [] local_dvs = [] #For MDF all disciplines get solved in the MDA, but other #architectures might need to identify disciplines on a more granular #level. This is all done via the parameter #disciplines = set() for k, v in self.parent.get_global_des_vars(): global_dvs.append(v) #disciplines.update(v.get_referenced_compnames()) for k, v in self.parent.get_local_des_vars(): local_dvs.append(v) #disciplines.update(v.get_referenced_compnames()) # and add the broadcast parameters to the driver for k, v in self.parent.get_global_des_vars(): self.parent.driver.add_parameter(v, name=k) #add the local design variables to the driver for k, v in self.parent.get_local_des_vars(): print type(v) self.parent.driver.add_parameter(v, name=k) #TODO: possibly add method for passing constraint directly? #add the constraints to the driver for const in self.parent.list_constraints(): self.parent.driver.add_constraint(const) #set the global objective objective = self.parent.get_objectives().items()[0] self.parent.driver.add_objective(objective[1].text, name=objective[0]) #setup the inner loop solver self.parent.add('solver', BroydenSolver()) self.parent.solver.itmax = 10 self.parent.solver.alpha = .4 self.parent.solver.tol = .0000001 self.parent.solver.algorithm = "broyden2" #add the coupling vars parameters/constraints to the solver for key, couple in self.parent.get_coupling_vars().iteritems(): self.parent.solver.add_parameter(couple.indep.target, low=-9.e99, high=9.e99, name=key) self.parent.solver.add_constraint( "%s=%s" % (couple.indep.target, couple.dep.target)) #setup the workflows self.parent.driver.workflow.add(['solver'])
def configure(self): global_dvs = self.parent.get_global_des_vars() local_dvs = self.parent.get_local_des_vars_by_comp() objective = self.parent.get_objectives().items()[0] constraints = self.parent.list_constraints() coupling = self.parent.get_coupling_vars() self.parent.add('driver', FixedPointIterator()) self.parent.driver.max_iteration = 50 self.parent.driver.tolerance = .001 initial_conditions = [ self.parent.get(param.target) for comp, param in global_dvs ] self.parent.add_trait('global_des_vars', Array(initial_conditions)) for i, (comps, param) in enumerate(global_dvs): targets = param.targets self.parent.driver.add_parameter(targets, low=param.low, high=param.high) self.parent.driver.add_constraint("global_des_vars[%d]=%s" % (i, targets[0])) for comp, local_params in local_dvs.iteritems(): initial_conditions = [ self.parent.get(param.targets[0]) for param in local_params ] self.parent.add_trait('%s_local_des_vars' % comp, Array(initial_conditions)) for i, param in enumerate(local_params): self.parent.driver.add_parameter(param.targets, low=param.low, high=param.high) self.parent.driver.add_constraint('%s_local_des_vars[%d]=%s' % (comp, i, param.targets[0])) # Multidisciplinary Analysis mda = self.parent.add('mda', BroydenSolver()) self.parent.force_execute = True for key, couple in coupling.iteritems(): mda.add_parameter(couple.indep.target, low=-9.e99, high=9.e99) mda.add_constraint("%s=%s" % (couple.indep.target, couple.dep.target)) #Global Sensitivity Analysis ssa = self.parent.add("ssa", SensitivityDriver()) ssa.workflow.add("mda") ssa.differentiator = FiniteDifference() ssa.default_stepsize = 1.0e-6 ssa.force_execute = True ssa.add_objective(objective[1].text, name=objective[0]) for comps, param in global_dvs: ssa.add_parameter(param.targets, low=param.low, high=param.high) for constraint in constraints: ssa.add_constraint(constraint) #discipline sensitivity analyses sa_s = [] for comp, local_params in local_dvs.iteritems(): sa = self.parent.add('sa_%s' % comp, SensitivityDriver()) sa.default_stepsize = 1.0e-6 sa.force_execute = True sa_s.append('sa_%s' % comp) for param in local_params: sa.add_parameter(param.targets, low=param.low, high=param.high, fd_step=.001) for constraint in constraints: sa.add_constraint(constraint) sa.add_objective(objective[1].text, name=objective[0]) sa.differentiator = FiniteDifference() #Linear System Optimizations # Discipline Optimization # (Only discipline1 has an optimization input) delta_x = [] df = [] dg = [] bbopts = [] for comp, local_params in local_dvs.iteritems(): bbopt = self.parent.add('bbopt_%s' % comp, CONMINdriver()) bbopt.linobj = True bbopt.iprint = 0 bbopt.force_execute = True bbopts.append('bbopt_%s' % comp) x_store = "%s_local_des_vars" % comp for i, param in enumerate(local_params): x_store_i = "%s[%d]" % (x_store, i) bbopt.add_parameter(x_store_i, low=param.low, high=param.high) dx = "(%s-%s)" % (x_store_i, param.targets[0]) delta_x.append(dx) move_limit = (param.high - param.low) * 20.0 / 100.0 bbopt.add_constraint("%s < %f" % (dx, move_limit)) bbopt.add_constraint("%s > -%f" % (dx, move_limit)) df.append("sa_%s.dF[0][%d]*%s" % (comp, i, dx)) #build the linear constraint string for each constraint for j, const in enumerate(constraints): dg_j = [ "sa_%s.dG[%d][%d]*%s" % (comp, j, i, x) for i, x in enumerate(delta_x) ] constraint_parts = ["sa_%s.G[%d]" % (comp, j)] constraint_parts.extend(dg_j) lin_constraint = "%s < 0" % "+".join(constraint_parts) bbopt.add_constraint(lin_constraint) #build the linear objective string objective_parts = ["sa_%s.F[0]" % comp] objective_parts.extend(df) lin_objective = "+".join(objective_parts) bbopt.add_objective(lin_objective) # Global Optimization delta_z = [] df = [] dg = [] sysopt = self.parent.add('sysopt', CONMINdriver()) sysopt.linobj = True sysopt.iprint = 0 sysopt.force_execute = True for i, (comps, param) in enumerate(global_dvs): z_store = "global_des_vars[%d]" % i target = list(param.targets)[0] sysopt.add_parameter(z_store, low=param.low, high=param.high) dz = "(%s-%s)" % (z_store, target) delta_z.append(dz) move_limit = (param.high - param.low) * 20.00 / 100.0 sysopt.add_constraint("%s < %f" % (dz, move_limit)) sysopt.add_constraint("%s > -%f" % (dz, move_limit)) df.append("ssa.dF[0][%d]*%s" % (i, dz)) dg_j = [ "ssa.dG[%d][%d]*%s" % (j, i, dz) for j, const in enumerate(constraints) ] dg.append(dg_j) objective_parts = ["ssa.F[0]"] objective_parts.extend(df) lin_objective = "+".join(objective_parts) sysopt.add_objective(lin_objective) #build the linear constraint string for each constraint for j, const in enumerate(constraints): dg_j = [ "ssa.dG[%d][%d]*%s" % (j, i, x) for i, x in enumerate(delta_z) ] constraint_parts = ["ssa.G[%d]" % j] constraint_parts.extend(dg_j) lin_constraint = "%s < 0" % "+".join(constraint_parts) sysopt.add_constraint(lin_constraint) self.parent.driver.workflow = SequentialWorkflow() self.parent.driver.workflow.add("ssa") self.parent.driver.workflow.add(sa_s) self.parent.driver.workflow.add(bbopts) self.parent.driver.workflow.add("sysopt")
def configure(self): # pylint: disable-msg=E1101 # Create CONMIN Optimizer instance self.add('optimizer', CONMINdriver()) # Create Vehicle instance self.add('vehicle', Vehicle()) # Create Driving Simulation instances self.add('sim_acc', SimAcceleration()) self.add('sim_EPA_city', SimEconomy()) self.add('sim_EPA_highway', SimEconomy()) # add the optimizer and economy sims to driver workflow self.driver.workflow.add(['optimizer', 'sim_EPA_city', 'sim_EPA_highway']) # add the acceleration sim to the optimizer workflow self.optimizer.workflow.add('sim_acc') # Add vehicle to sim workflows. self.sim_acc.workflow.add('vehicle') self.sim_EPA_city.workflow.add('vehicle') self.sim_EPA_highway.workflow.add('vehicle') # CONMIN Flags self.optimizer.iprint = 0 self.optimizer.itmax = 30 self.optimizer.conmin_diff = True # CONMIN Objective self.optimizer.add_objective('sim_acc.accel_time') # CONMIN Design Variables self.optimizer.add_parameter('vehicle.spark_angle', -50., 10.) self.optimizer.add_parameter('vehicle.bore', 65., 100.) # Acceleration Sim setup self.sim_acc.add_parameter('vehicle.velocity', name='velocity', low=0.0, high=150.0) self.sim_acc.add_parameter('vehicle.throttle', name='throttle', low=0.01, high=1.0) self.sim_acc.add_parameter('vehicle.current_gear', name='gear', low=0, high=5) self.sim_acc.add_objective('vehicle.acceleration', name='acceleration') self.sim_acc.add_objective('vehicle.overspeed', name='overspeed') # EPA City MPG Sim Setup self.sim_EPA_city.add_parameter('vehicle.velocity', name='velocity', low=0.0, high=150.0) self.sim_EPA_city.add_parameter('vehicle.throttle', name='throttle', low=0.01, high=1.0) self.sim_EPA_city.add_parameter('vehicle.current_gear', name='gear', low=0, high=5) self.sim_EPA_city.add_objective('vehicle.acceleration', name='acceleration') self.sim_EPA_city.add_objective('vehicle.fuel_burn', name='fuel_burn') self.sim_EPA_city.add_objective('vehicle.overspeed', name='overspeed') self.sim_EPA_city.add_objective('vehicle.underspeed', name='underspeed') self.sim_EPA_city.profilename = 'EPA-city.csv' # EPA Highway MPG Sim Setup self.sim_EPA_highway.add_parameter('vehicle.velocity', name='velocity', low=0.0, high=150) self.sim_EPA_highway.add_parameter('vehicle.throttle', name='throttle', low=0.01, high=1.0) self.sim_EPA_highway.add_parameter('vehicle.current_gear', name='gear', low=0, high=5) self.sim_EPA_highway.add_objective('vehicle.acceleration', name='acceleration') self.sim_EPA_highway.add_objective('vehicle.fuel_burn', name='fuel_burn') self.sim_EPA_highway.add_objective('vehicle.overspeed', name='overspeed') self.sim_EPA_highway.add_objective('vehicle.underspeed', name='underspeed') self.sim_EPA_highway.profilename = 'EPA-highway.csv'
def configure(self): global_dvs = self.parent.get_global_des_vars() local_dvs = self.parent.get_local_des_vars() all_dvs_by_comp = self.parent.get_des_vars_by_comp() objective = self.parent.get_objectives() constraints = self.parent.list_constraints() constraints_by_comp = self.parent.get_constraints_by_comp() coupling = self.parent.get_coupling_vars() coupl_indeps_by_comp = self.parent.get_coupling_indeps_by_comp() coupl_deps_by_comp = self.parent.get_coupling_deps_by_comp() self.target_var_map = dict() #Global Driver global_opt = self.parent.add('driver', CONMINdriver()) global_opt.print_vars = ['dis1.y1', 'dis2.y2'] global_opt.iprint = 0 global_opt.itmax = 100 global_opt.fdch = .003 global_opt.fdchm = .003 global_opt.delfun = .0001 global_opt.dabfun = .00001 global_opt.ct = -.0008 global_opt.ctlmin = 0.0008 initial_conditions = [param.evaluate() for comp, param in global_dvs] #print "global initial conditions: ", initial_conditions self.parent.add_trait('global_des_var_targets', Array(initial_conditions)) for i, (comp, param) in enumerate(global_dvs): target_var = 'global_des_var_targets[%d]' % i global_opt.add_parameter(target_var, low=param.low, high=param.high) #associate all targets with this target variable for global optimizer for var in param.targets: self.target_var_map[var] = target_var initial_conditions = [ couple.indep.evaluate() for key, couple in coupling.iteritems() ] #print "coupling initial conditions: ", initial_conditions self.parent.add_trait('coupling_var_targets', Array(initial_conditions)) for i, (key, couple) in enumerate(coupling.iteritems()): target_var = 'coupling_var_targets[%d]' % i low = couple.indep.low or -1e99 high = couple.indep.high or 1e99 global_opt.add_parameter(target_var, low=low, high=high) self.target_var_map[couple.indep.target] = target_var self.target_var_map[couple.dep.target] = target_var initial_conditions = [param.evaluate() for comp, param in local_dvs] #print "local initial conditions: ", initial_conditions self.parent.add_trait("local_des_var_targets", Array(initial_conditions)) for i, (comp, param) in enumerate(local_dvs): #Target variables for the local optimizations target_var = 'local_des_var_targets[%d]' % i self.target_var_map[param.target] = target_var global_opt.add_parameter(target_var, low=param.low, high=param.high) #print "param: ",target_var,param.low,param.high #create the new objective with the target variables obj = objective.items()[0] varpaths = obj[1].get_referenced_varpaths() new_objective = obj[1].text for var in varpaths: new_objective = new_objective.replace(var, self.target_var_map[var]) global_opt.add_objective(new_objective, name=obj[1]) #setup the local optimizations for comp, params in all_dvs_by_comp.iteritems(): local_opt = self.parent.add('local_opt_%s' % comp, CONMINdriver()) global_opt.workflow.add(local_opt.name) residuals = [] for param in params: local_opt.add_parameter(param.target, low=param.low, high=param.high) residuals.append( "(%s-%s)**2" % (self.target_var_map[param.target], param.target)) if comp in coupl_indeps_by_comp: for couple in coupl_indeps_by_comp[comp]: low = couple.indep.low or -1e99 high = couple.indep.high or 1e99 local_opt.add_parameter(couple.indep.target, low=low, high=high) residuals.append("(%s-%s)**2" % (self.target_var_map[couple.indep.target], couple.indep.target)) if comp in coupl_deps_by_comp: for couple in coupl_deps_by_comp[comp]: residuals.append("(%s-%s)**2" % (self.target_var_map[couple.dep.target], couple.dep.target)) if comp in constraints_by_comp: for const in constraints_by_comp[comp]: local_opt.add_constraint(str(const)) residuals = "+".join(residuals) global_constraint = "%s<=.001" % residuals global_opt.add_constraint(global_constraint) local_opt.add_objective(residuals) local_opt.iprint = 0 local_opt.itmax = 100 local_opt.fdch = .001 local_opt.fdchm = .001 local_opt.delfun = .0001 local_opt.dabfun = .000001 local_opt.force_execute = True """ print local_opt.name
def __init__(self): super(Scalable, self).__init__() #three components: d0,d1,d2 obj = "d0.z0**2+d0.z1**2+d0.z2**2+d0.y_out**2+d1.y_out**2+d2.y_out**2" d0_const = "1-d0.y_out/c0 <= 0" d1_const = "1-d1.y_out/c1 <= 0" d2_const = "1-d2.y_out/c2 <= 0" #initial MDA mda = self.add("mda", BroydenSolver()) mda.add_parameter("d0.y_in0", low=-1e99, high=1e99) mda.add_parameter("d0.y_in1", low=-1e99, high=1e99) mda.add_constraint("d0.y_out=d1.y_in0") mda.add_constraint("d0.y_out=d2.y_in0") mda.add_parameter("d1.y_in0", low=-1e99, high=1e99) mda.add_parameter("d1.y_in1", low=-1e99, high=1e99) mda.add_constraint("d1.y_out=d0.y_in0") mda.add_constraint("d1.y_out=d2.y_in1") mda.add_parameter("d2.y_in0", low=-1e99, high=1e99) mda.add_parameter("d2.y_in1", low=-1e99, high=1e99) mda.add_constraint("d2.y_out=d0.y_in1") mda.add_constraint("d2.y_out=d1.y_in1") sa0 = self.add('sa0', SensitivityDriver()) sa0.differentiator = FiniteDifference() sa0.add_parameter('d0.x0', low=-10, high=10) sa0.add_parameter('d0.x1', low=-10, high=10) sa0.add_parameter('d0.x2', low=-10, high=10) sa0.add_objective(obj) sa0.add_constraint(d0_const) sa1 = self.add('sa1', SensitivityDriver()) sa1.differentiator = FiniteDifference() sa1.add_parameter('d1.x0', low=-10, high=10) sa1.add_parameter('d1.x1', low=-10, high=10) sa1.add_parameter('d1.x2', low=-10, high=10) sa1.add_objective(obj) sa1.add_constraint(d1_const) sa2 = self.add('sa2', SensitivityDriver()) sa2.differentiator = FiniteDifference() sa2.add_parameter('d0.x0', low=-10, high=10) sa2.add_parameter('d0.x1', low=-10, high=10) sa2.add_parameter('d0.x2', low=-10, high=10) sa2.add_objective(obj) sa2.add_constraint(d2_const) ssa = self.add('ssa', SensitivityDriver()) ssa.differentiator = FiniteDifference() ssa.add_parameter(("d0.z0", "d1.z0", "d2.z0"), low=-10, high=10) ssa.add_parameter(("d0.z1", "d1.z1", "d2.z1"), low=-10, high=10) ssa.add_parameter(("d0.z2", "d1.z2", "d2.z2"), low=-10, high=10) ssa.add_objective(obj) ssa.add_constraint(d0_const) ssa.add_constraint(d1_const) ssa.add_constraint(d2_const) bbopt0 = self.add('bbopt0', CONMINdriver()) bbopt0.add_parameter('d0_local_des_vars[0]', low=-10, high=10) bbopt0.add_parameter('d0_local_des_vars[1]', low=-10, high=10) bbopt0.add_parameter('d0_local_des_vars[2]', low=-10, high=10) bbopt0.add_objective( 'sa0.F[0] + sa0.dF[0][0]*(d0_local_des_vars[0]-d0.x0)' '+ sa0.dF[0][1]*(d0_local_des_vars[1]-d0.x1)' '+ sa0.dF[0][2]*(d0_local_des_vars[2]-d0.x2)') bbopt0.add_constraint( 'sa0.G[0] + sa0.dG[0][0]*(d0_local_des_vars[0]-d0.x0)' '+ sa0.dG[0][1]*(d0_local_des_vars[1]-d0.x1)' '+ sa0.dG[0][2]*(d0_local_des_vars[2]-d0.x2) <= 0') bbopt0.add_constraint( '(d0_local_des_vars[0]-d0.x0)<=(percent*d0.x0+.0001)*factor**(mda.exec_count-offset)' ) bbopt0.add_constraint( '(d0_local_des_vars[1]-d1.x1)<=(percent*d0.x1+.0001)*factor**(mda.exec_count-offset)' ) bbopt0.add_constraint( '(d0_local_des_vars[2]-d2.x2)<=(percent*d0.x2+.0001)*factor**(mda.exec_count-offset)' ) bbopt0.add_constraint( '(d0_local_des_vars[0]-d0.x0)>=(-percent*d0.x0-.0001)*factor**(mda.exec_count-offset)' ) bbopt0.add_constraint( '(d0_local_des_vars[1]-d1.x1)>=(-percent*d0.x1-.0001)*factor**(mda.exec_count-offset)' ) bbopt0.add_constraint( '(d0_local_des_vars[2]-d2.x2)>=(-percent*d0.x2-.0001)*factor**(mda.exec_count-offset)' ) bbopt1 = self.add('bbopt1', CONMINdriver()) bbopt1.add_parameter('d1_local_des_vars[0]', low=-10, high=10) bbopt1.add_parameter('d1_local_des_vars[1]', low=-10, high=10) bbopt1.add_parameter('d1_local_des_vars[2]', low=-10, high=10) bbopt1.add_objective( 'sa1.F[0] + sa1.dF[0][0]*(d1_local_des_vars[0]-d1.x0)' '+ sa1.dF[0][1]*(d1_local_des_vars[1]-d1.x1)' '+ sa1.dF[0][2]*(d1_local_des_vars[2]-d1.x2)') bbopt1.add_constraint( 'sa1.G[0] + sa1.dG[0][0]*(d1_local_des_vars[0]-d1.x0)' '+ sa1.dG[0][1]*(d1_local_des_vars[1]-d1.x1)' '+ sa1.dG[0][2]*(d1_local_des_vars[2]-d1.x2) <= 0') bbopt1.add_constraint( '(d1_local_des_vars[0]-d1.x0)<=(percent*d1.x0+.0001)*factor**(mda.exec_count-offset)' ) bbopt1.add_constraint( '(d1_local_des_vars[1]-d1.x1)<=(percent*d1.x1+.0001)*factor**(mda.exec_count-offset)' ) bbopt1.add_constraint( '(d1_local_des_vars[2]-d1.x2)<=(percent*d1.x2+.0001)*factor**(mda.exec_count-offset)' ) bbopt1.add_constraint( '(d1_local_des_vars[0]-d1.x0)>=(-percent*d1.x0-.0001)*factor**(mda.exec_count-offset)' ) bbopt1.add_constraint( '(d1_local_des_vars[1]-d1.x1)>=(-percent*d1.x1-.0001)*factor**(mda.exec_count-offset)' ) bbopt1.add_constraint( '(d1_local_des_vars[2]-d1.x2)>=(-percent*d1.x2-.0001)*factor**(mda.exec_count-offset)' ) bbopt2 = self.add('bbopt2', CONMINdriver()) bbopt2.add_parameter('d2_local_des_vars[0]', low=-10, high=10) bbopt2.add_parameter('d2_local_des_vars[1]', low=-10, high=10) bbopt2.add_parameter('d2_local_des_vars[2]', low=-10, high=10) bbopt2.add_objective( 'sa2.F[0] + sa2.dF[0][0]*(d2_local_des_vars[0]-d2.x0)' '+ sa2.dF[0][1]*(d2_local_des_vars[1]-d2.x1)' '+ sa2.dF[0][2]*(d2_local_des_vars[2]-d2.x2)') bbopt2.add_constraint( 'sa2.G[0] + sa2.dG[0][0]*(d2_local_des_vars[0]-d2.x0)' '+ sa2.dG[0][1]*(d2_local_des_vars[1]-d2.x1)' '+ sa2.dG[0][2]*(d2_local_des_vars[2]-d2.x2) <= 0') bbopt2.add_constraint( '(d2_local_des_vars[0]-d2.x0)<=(percent*d2.x0+.0001)*factor**(mda.exec_count-offset)' ) bbopt2.add_constraint( '(d2_local_des_vars[1]-d2.x1)<=(percent*d2.x1+.0001)*factor**(mda.exec_count-offset)' ) bbopt2.add_constraint( '(d2_local_des_vars[2]-d2.x2)<=(percent*d2.x2+.0001)*factor**(mda.exec_count-offset)' ) bbopt2.add_constraint( '(d2_local_des_vars[0]-d2.x0)>=(-percent*d2.x0-.0001)*factor**(mda.exec_count-offset)' ) bbopt2.add_constraint( '(d2_local_des_vars[1]-d2.x1)>=(-percent*d2.x1-.0001)*factor**(mda.exec_count-offset)' ) bbopt2.add_constraint( '(d2_local_des_vars[2]-d2.x2)>=(-percent*d2.x2-.0001)*factor**(mda.exec_count-offset)' ) sysopt = self.add('sysopt', CONMINdriver()) sysopt.add_parameter('global_des_vars[0]', low=-10, high=10) sysopt.add_parameter('global_des_vars[1]', low=-10, high=10) sysopt.add_parameter('global_des_vars[2]', low=-10, high=10) sysopt.add_objective( 'ssa.F[0] + ssa.dF[0][0]*(global_des_vars[0]-d0.z0)' '+ ssa.dF[0][1]*(global_des_vars[1]-d0.z1)' '+ ssa.dF[0][2]*(global_des_vars[2]-d0.z2)') sysopt.add_constraint( 'ssa.G[0] + ssa.dG[0][0]*(global_des_vars[0]-d0.z0)' '+ ssa.dG[0][1]*(global_des_vars[1]-d0.z1)' '+ ssa.dG[0][2]*(global_des_vars[2]-d0.z2) <= 0') sysopt.add_constraint( 'ssa.G[1] + ssa.dG[1][0]*(global_des_vars[0]-d0.z0)' '+ ssa.dG[1][1]*(global_des_vars[1]-d0.z1)' '+ ssa.dG[1][2]*(global_des_vars[2]-d0.z2) <= 0') sysopt.add_constraint( 'ssa.G[2] + ssa.dG[2][0]*(global_des_vars[0]-d0.z0)' '+ ssa.dG[2][1]*(global_des_vars[1]-d0.z1)' '+ ssa.dG[2][2]*(global_des_vars[2]-d0.z2) <= 0') sysopt.add_constraint( '(global_des_vars[0]-d0.z0) >= (percent*d0.z0 +.0001)*factor**(mda.exec_count-offset)' ) sysopt.add_constraint( '(global_des_vars[0]-d0.z0) <= (-percent*d0.z0 -.0001)*factor**(mda.exec_count-offset)' ) sysopt.add_constraint( '(global_des_vars[1]-d0.z1) >= (percent*d0.z1 +.0001)*factor**(mda.exec_count-offset)' ) sysopt.add_constraint( '(global_des_vars[1]-d0.z1) <= (-percent*d0.z1 -.0001)*factor**(mda.exec_count-offset)' ) sysopt.add_constraint( '(global_des_vars[2]-d0.z2) >= (percent*d0.z2 +.0001)*factor**(mda.exec_count-offset)' ) sysopt.add_constraint( '(global_des_vars[2]-d0.z2) <= (-percent*d0.z2 -.0001)*factor**(mda.exec_count-offset)' ) debug = self.add('debug', DebugComp()) debug.force_execute = True driver = self.add('driver', FixedPointIterator()) driver.add_parameter('d0.x0', low=-1e99, high=1e99) driver.add_parameter('d0.x1', low=-1e99, high=1e99) driver.add_parameter('d0.x2', low=-1e99, high=1e99) driver.add_constraint('d0_local_des_vars[0]=d0.x0') driver.add_constraint('d0_local_des_vars[1]=d0.x1') driver.add_constraint('d0_local_des_vars[2]=d0.x2') driver.add_parameter('d1.x0', low=-1e99, high=1e99) driver.add_parameter('d1.x1', low=-1e99, high=1e99) driver.add_parameter('d1.x2', low=-1e99, high=1e99) driver.add_constraint('d1_local_des_vars[0]=d1.x0') driver.add_constraint('d1_local_des_vars[1]=d1.x1') driver.add_constraint('d1_local_des_vars[2]=d1.x2') driver.add_parameter('d2.x0', low=-1e99, high=1e99) driver.add_parameter('d2.x1', low=-1e99, high=1e99) driver.add_parameter('d2.x2', low=-1e99, high=1e99) driver.add_constraint('d2_local_des_vars[0]=d2.x0') driver.add_constraint('d2_local_des_vars[1]=d2.x1') driver.add_constraint('d2_local_des_vars[2]=d2.x2') driver.add_parameter(['d0.z0', 'd1.z0', 'd2.z0'], low=-1e99, high=1e99) driver.add_parameter(['d0.z1', 'd1.z1', 'd2.z1'], low=-1e99, high=1e99) driver.add_parameter(['d0.z2', 'd1.z2', 'd2.z2'], low=-1e99, high=1e99) driver.add_constraint('global_des_vars[0]=d0.z0') driver.add_constraint('global_des_vars[1]=d0.z1') driver.add_constraint('global_des_vars[2]=d0.z2') self.driver.workflow.add([ 'mda', 'sa0', 'sa1', 'sa2', 'ssa', 'bbopt0', 'bbopt1', 'bbopt2', 'sysopt', 'debug' ])
def __init__(self): """ Creates a new Assembly with this problem Optimal Design at (1.9776, 0, 0) Optimal Objective = 3.18339""" # pylint: disable-msg=E1101 super(SellarCO_Multi, self).__init__() # Global Optimization self.add('driver', CONMINdriver()) self.add('localopt1', CONMINdriver()) self.add('localopt2', CONMINdriver()) self.driver.workflow.add(['localopt1', 'localopt2']) # Local Optimization 1 self.add('dis1', sellar.Discipline1()) self.localopt1.workflow.add('dis1') # Local Optimization 2 self.add('dis2a', SellarDiscipline2a()) self.add('dis2b', SellarDiscipline2b()) self.add('dis2c', SellarDiscipline2c()) self.connect('dis2a.temp1', 'dis2b.temp1') self.connect('dis2b.temp2', 'dis2c.temp2') self.localopt2.workflow.add(['dis2a', 'dis2b', 'dis2c']) #Parameters - Global Optimization # using group parameters to 'broadcast' same data self.driver.add_objective('x1**2 + z2 + y1 + math.exp(-y2)') for param, low, high in zip([('z1', 'dis1.z1', 'dis2b.z1'), ('z2', 'dis1.z2', 'dis2c.z2'), ('x1', 'dis1.x1'), ('y1', 'dis2a.y1'), ('y2', 'dis1.y2')], [-10.0, 0.0, 0.0, 3.16, -10.0], [10.0, 10.0, 10.0, 10, 24.0]): self.driver.add_parameter(param, low=low, high=high) map(self.driver.add_constraint, [ '(z1-dis1.z1)**2 + (z2-dis1.z2)**2 + (x1-dis1.x1)**2 + ' '(y1-dis1.y1)**2 + (y2-dis1.y2)**2 < 0', '(z1-dis2b.z1)**2 + (z2-dis2c.z2)**2 + (y1-dis2a.y1)**2 + ' '(y2-dis2c.y2)**2 < 0' ]) self.driver.printvars = ['dis1.y1', 'dis2c.y2'] self.driver.iprint = 0 self.driver.itmax = 100 self.driver.fdch = .003 self.driver.fdchm = .003 self.driver.delfun = .0001 self.driver.dabfun = .00001 self.driver.ct = -.0008 self.driver.ctlmin = 0.0008 #Parameters - Local Optimization 1 self.localopt1.add_objective('(z1-dis1.z1)**2 + ' + \ '(z2-dis1.z2)**2 + ' + \ '(x1-dis1.x1)**2 + ' + \ '(y1-dis1.y1)**2 + ' + \ '(y2-dis1.y2)**2') for param, low, high in zip( ['dis1.z1', 'dis1.z2', 'dis1.x1', 'dis1.y2'], [-10.0, 0.0, 0.0, -10.0], [10.0, 10.0, 10.0, 24.0]): self.localopt1.add_parameter(param, low=low, high=high) self.localopt1.iprint = 0 self.localopt1.itmax = 100 self.localopt1.fdch = .003 self.localopt1.fdchm = .003 self.localopt1.delfun = .0001 self.localopt1.dabfun = .000001 #Parameters - Local Optimization 2 self.localopt2.add_objective('(z1-dis2b.z1)**2 + ' + \ '(z2-dis2c.z2)**2 + ' + \ '(y1-dis2a.y1)**2 + ' + \ '(y2-dis2c.y2)**2') for param, low, high in zip(['dis2b.z1', 'dis2c.z2', 'dis2a.y1'], [-10.0, 0.0, 3.16], [10.0, 10.0, 10]): self.localopt2.add_parameter(param, low=low, high=high) self.localopt2.iprint = 0 self.localopt2.itmax = 100 self.localopt2.fdch = .003 self.localopt2.fdchm = .003 self.localopt2.delfun = .001 self.localopt2.dabfun = .00001