def test_multiple_objectives(self): sout = StringIO() self.top.add('driver', SensitivityDriver()) self.top.driver.workflow.add(['comp1', 'comp2']) self.top.driver.add_parameter(['comp1.x'], low=-100, high=100) self.top.driver.add_objective('comp1.z') self.top.driver.add_objective('comp2.z') self.top.recorders = [JSONCaseRecorder(sout)] self.top.run() # with open('multiobj.new', 'w') as out: # out.write(sout.getvalue()) self.verify(sout, 'multiobj.json')
def configure(self): self.add('p1pre', Paraboloid()) #self.add('p1', Paraboloid()) self.add('down', Downstream()) self.add('driver', SimpleDriver()) self.add('sens', SensitivityDriver()) self.driver.add_parameter('p1pre.x', low=-100, high=101) self.driver.add_objective('down.y') self.sens.add_parameter('p1pre.x', low=100, high=101) self.sens.add_objective('p1pre.f_xy') self.connect('sens.dF', 'down.x') self.driver.workflow.add(['sens', 'down']) self.sens.workflow.add(['p1pre'])
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 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.list_coupling_vars() self.parent.add('driver', FixedPointIterator()) self.parent.driver.max_iteration = 50 self.parent.driver.tolerance = .005 #set initial values for comp, param in global_dvs: param.initialize(self.parent) for comp, local_params in local_dvs.iteritems(): for param in local_params: param.initialize(self.parent) for couple in coupling.values(): couple.indep.set(couple.start) initial_conditions = [param.start for comp, param in global_dvs] self.parent.add_trait('global_des_vars', Array(initial_conditions, iotype="in")) for i, (comps, param) in enumerate(global_dvs): targets = param.targets self.parent.driver.add_parameter(targets, low=param.low, high=param.high, start=param.start) self.parent.driver.add_constraint("global_des_vars[%d]=%s" % (i, targets[0])) for comp, local_params in local_dvs.iteritems(): initial_conditions = [param.start for param in local_params] self.parent.add_trait('%s_local_des_vars' % comp, Array(initial_conditions, iotype="in")) for i, param in enumerate(local_params): self.parent.driver.add_parameter(param.targets, low=param.low, high=param.high, start=param.start) self.parent.driver.add_constraint('%s_local_des_vars[%d]=%s' % (comp, i, param.targets[0])) # Multidisciplinary Analysis mda = self.parent.add('mda', BroydenSolver()) for couple in coupling.values(): mda.add_parameter(couple.indep.target) 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.default_stepsize = 1.0e-6 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_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]) #Linear System Optimizations # Discipline Optimization # (Only discipline1 has an optimization input) bbopts = [] for comp, local_params in local_dvs.iteritems(): bbopt = self.parent.add('bbopt_%s' % comp, SLSQPdriver()) bbopt.iprint = 0 bbopts.append('bbopt_%s' % comp) x_store = "%s_local_des_vars" % comp delta_x = [] df = [] dg = [] 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, start=param.start) dx = "(%s-%s)" % (x_store_i, param.targets[0]) delta_x.append(dx) #bbopt.add_constraint("%s < %f*%s" %(dx, .2, param.targets[0])) #bbopt.add_constraint("%s > -%f*%s "%(dx, .2, param.targets[0])) bbopt.add_constraint("%s < .5" % (dx, )) bbopt.add_constraint("%s > -.5" % (dx, )) 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', SLSQPdriver()) sysopt.recorders = self.data_recorders sysopt.iprint = 0 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, start=param.start) dz = "(%s-%s)" % (z_store, target) delta_z.append(dz) #sysopt.add_constraint("%s < %f*%s" % (dz, .1, target)) #sysopt.add_constraint("%s > -%f*%s" % (dz, .1, target)) sysopt.add_constraint("%s < .5" % (dz, )) sysopt.add_constraint("%s > -.5" % (dz, )) 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.add("mda") self.parent.driver.workflow.add(sa_s) if global_dvs: self.parent.driver.workflow.add("ssa") self.parent.driver.workflow.add(bbopts) if global_dvs: self.parent.driver.workflow.add("sysopt")
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): """ 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'])