def test_2peer_drivers(self):
        #
        #  D1-->
        #  |   |
        #  |<--C1------>|
        #               |
        #          D2-->|
        #          |    |
        #          |<---C2
        global exec_order
        print "*** test_2peer_drivers ***"
        top = set_as_top(Assembly())
        top.add('C1', ExprComp(expr='x+1'))
        top.add('C2', ExprComp2(expr='x+y'))

        top.connect('C1.f_x', 'C2.x')
        top.add('D1', Summer())
        top.D1.add_objective('C1.f_x')
        top.D1.add_parameter('C1.x', low=-999, high=999)
        top.D1.max_iterations = 2
        top.add('D2', Summer())
        top.D2.add_objective('C2.f_xy')
        top.D2.add_parameter('C2.y', low=-999, high=999)
        top.D2.max_iterations = 3

        top.driver.workflow.add(['D1', 'D2'])
        top.D1.workflow = SequentialWorkflow(top.D1, members=['C1'])
        top.D2.workflow = SequentialWorkflow(top.D1, members=['C2'])

        top.run()
        self.assertEqual(top.D2.runcount, 1)
        self.assertEqual(top.D1.runcount, 1)
        self.assertEqual(top.C1.runcount, top.D1.max_iterations)
        self.assertEqual(top.C2.runcount, top.D2.max_iterations)
        self.assertEqual(exec_order,
                         ['D1', 'C1', 'C1',
                          'D2', 'C2', 'C2', 'C2'])

        top.C1.runcount = 0
        top.C2.runcount = 0
        top.D1.runcount = 0
        top.D2.runcount = 0
        top.D1.set('max_iterations', 5)
        top.D2.set('max_iterations', 4)
        exec_order = []
        top.run()
        self.assertEqual(top.D2.runcount, 1)
        self.assertEqual(top.D1.runcount, 1)
        self.assertEqual(top.C1.runcount, top.D1.max_iterations)
        self.assertEqual(top.C2.runcount, top.D2.max_iterations)
        self.assertEqual(exec_order,
                         ['D1', 'C1', 'C1', 'C1', 'C1', 'C1',
                          'D2', 'C2', 'C2', 'C2', 'C2'])
Example #2
0
    def test_tracing(self):
        # Check tracing of iteration coordinates.
        top = Assembly()
        comp = top.add('comp1', Dummy())
        top.add('driverA', Driver())
        comp = top.add('comp2', Dummy())
        top.add('driverB', Driver())

        sub = top.add('subassy', Assembly())
        comp = sub.add('comp3', Dummy())
        sub.driver.workflow.add('comp3')

        top.driver.workflow = SequentialWorkflow()
        top.driver.workflow.add(('comp1', 'driverA', 'driverB'))
        top.driverA.workflow.add(('comp1', 'comp2'))
        top.driverB.workflow.add(('comp2', 'subassy'))

        trace_out = cStringIO.StringIO()
        enable_trace(trace_out)
        top.run()
        expected = """\
1-comp1
1-driverA.1-comp1
1-driverA.1-comp2
1-driverB.1-comp2
1-driverB.1-subassy.1-comp3
"""
        self.assertEqual(trace_out.getvalue(), expected)

        disable_trace()
        top.run()
        self.assertEqual(trace_out.getvalue(), expected)
 def __init__(self):
     super(Simulation,self).__init__()
 
     #Components
     self.add("sin_meta_model",MetaModel())      
     self.sin_meta_model.surrogate = {"default":KrigingSurrogate()}  
     self.sin_meta_model.model = Sin()        
     self.sin_meta_model.recorder = DBCaseRecorder()
     
     #Training the MetaModel
     self.add("DOE_Trainer",DOEdriver())
     self.DOE_Trainer.DOEgenerator = FullFactorial()
     self.DOE_Trainer.DOEgenerator.num_levels = 25
     self.DOE_Trainer.add_parameter("sin_meta_model.x",low=0,high=20)
     self.DOE_Trainer.case_outputs = ["sin_meta_model.f_x"]
     self.DOE_Trainer.add_event("sin_meta_model.train_next")
     self.DOE_Trainer.recorders = [DBCaseRecorder()]
     self.DOE_Trainer.force_execute = True
     
     #MetaModel Validation
     self.add("sin_calc",Sin())
     self.add("DOE_Validate",DOEdriver())
     self.DOE_Validate.DOEgenerator = Uniform()
     self.DOE_Validate.DOEgenerator.num_samples = 100
     self.DOE_Validate.add_parameter(("sin_meta_model.x","sin_calc.x"),low=0,high=20)
     self.DOE_Validate.case_outputs = ["sin_calc.f_x","sin_meta_model.f_x"]
     self.DOE_Validate.recorders = [DBCaseRecorder()]
     self.DOE_Validate.force_execute = True
     
     #Iteration Hierarchy
     self.driver.workflow = SequentialWorkflow()
     self.driver.workflow.add(['DOE_Trainer','DOE_Validate'])
     self.DOE_Trainer.workflow.add('sin_meta_model')
     self.DOE_Validate.workflow.add('sin_meta_model')
     self.DOE_Validate.workflow.add('sin_calc')
    def configure(self):
        # Components
        self.add("sin_meta_model", MetaModel())
        self.sin_meta_model.model = Sin()
        self.sin_meta_model.default_surrogate = FloatKrigingSurrogate()

        # Training the MetaModel
        self.add("DOE_Trainer", DOEdriver())
        self.DOE_Trainer.DOEgenerator = FullFactorial()
        self.DOE_Trainer.DOEgenerator.num_levels = 25
        self.DOE_Trainer.add_parameter("sin_meta_model.x", low=0, high=20)
        self.DOE_Trainer.case_outputs = ["sin_meta_model.f_x"]
        self.DOE_Trainer.add_event("sin_meta_model.train_next")
        self.DOE_Trainer.recorders = [DBCaseRecorder()]

        # MetaModel Validation
        self.add("sin_calc", Sin())
        self.add("DOE_Validate", DOEdriver())
        self.DOE_Validate.DOEgenerator = Uniform()
        self.DOE_Validate.DOEgenerator.num_samples = 200
        self.DOE_Validate.add_parameter(("sin_meta_model.x", "sin_calc.x"), low=0, high=20)
        self.DOE_Validate.case_outputs = ["sin_calc.f_x", "sin_meta_model.f_x"]
        self.DOE_Validate.recorders = [DBCaseRecorder()]

        # Iteration Hierarchy
        self.driver.workflow = SequentialWorkflow()
        self.driver.workflow.add(['DOE_Trainer', 'DOE_Validate'])
        self.DOE_Trainer.workflow.add('sin_meta_model')
        self.DOE_Validate.workflow.add('sin_meta_model')
        self.DOE_Validate.workflow.add('sin_calc')
Example #5
0
    def __init__(self):
        super(Analysis, self).__init__()
        
        # --------------------------------------------------------------------------- #
        # --- Instantiate LHC DOE Driver
        # --------------------------------------------------------------------------- #  
        self.add('doe_driver', DOEdriver())  
        self.doe_driver.DOEgenerator = Uniform(num_samples = 5)
        self.doe_driver.workflow = SequentialWorkflow()
       
        # --------------------------------------------------------------------------- #
        # --- Instantiate Geometry Component
        # --------------------------------------------------------------------------- #  
        self.add('geometry', GeometryComp()) 

        # 1--- Top Level Workflow
        self.driver.workflow.add(['doe_driver']) 
        self.doe_driver.workflow.add(['geometry'])
    
        # --------------------------------------------------------------------------- #
        # --- Add parameters to DOE driver 
        # --------------------------------------------------------------------------- #         
        self.doe_driver.add_parameter('geometry.dC1P_X')
        self.doe_driver.add_parameter('geometry.dC2P_X')
        self.doe_driver.add_parameter('geometry.dC3P_X')
        self.doe_driver.add_parameter('geometry.dC4P_X')

        self.doe_driver.add_parameter('geometry.dC1P_R')
        self.doe_driver.add_parameter('geometry.dC2P_R')
        self.doe_driver.add_parameter('geometry.dC3P_R')
        self.doe_driver.add_parameter('geometry.dC4P_R')

        self.doe_driver.add_parameter('geometry.dC1S_X')
        self.doe_driver.add_parameter('geometry.dC2S_X')
        self.doe_driver.add_parameter('geometry.dC3S_X')
        self.doe_driver.add_parameter('geometry.dC4S_X')

        self.doe_driver.add_parameter('geometry.dC1S_R')
        self.doe_driver.add_parameter('geometry.dC2S_R')
        self.doe_driver.add_parameter('geometry.dC3S_R')
        self.doe_driver.add_parameter('geometry.dC4S_R')
       
        self.doe_driver.add_parameter('geometry.dC1S_T')
        self.doe_driver.add_parameter('geometry.dC2S_T')
        self.doe_driver.add_parameter('geometry.dC3S_T')

        self.doe_driver.add_parameter('geometry.dC1C_X')
        self.doe_driver.add_parameter('geometry.dC2C_X')
        self.doe_driver.add_parameter('geometry.dC3C_X')
        self.doe_driver.add_parameter('geometry.dC4C_X')

        self.doe_driver.add_parameter('geometry.dC1C_R')
        self.doe_driver.add_parameter('geometry.dC2C_R')
        self.doe_driver.add_parameter('geometry.dC3C_R')
        self.doe_driver.add_parameter('geometry.dC4C_R')
       
        self.doe_driver.add_parameter('geometry.dC1C_T')
        self.doe_driver.add_parameter('geometry.dC2C_T')
        self.doe_driver.add_parameter('geometry.dC3C_T')        
Example #6
0
    def configure(self):
        self.add('driver',Smarty())
        self.add('dumcomp',Dummy())
        self.add('dum2',DummyAssembly())

        self.driver.add_parameter(("dumcomp.dummy3",'dum2.dummy3'),low=-1000,high=1000)
        self.driver.add_parameter(("dumcomp.dummy4",'dum2.dummy4'),low=-1000,high=1000)

        self.driver.add_objective('dumcomp.dummy2')  #Doesn't work.

        self.driver.workflow = SequentialWorkflow()
        self.driver.workflow.add(['dumcomp','dum2'])        
Example #7
0
    def __init__(self):
        super(Analysis, self).__init__()

        # --------------------------------------------------------------------------- #
        # --- Instantiate LHC DOE Driver
        # --------------------------------------------------------------------------- #
        self.add('doe_driver', DOEdriver())
        self.doe_driver.DOEgenerator = OptLatinHypercube(num_samples=10)
        self.doe_driver.workflow = SequentialWorkflow()

        # --------------------------------------------------------------------------- #
        # --- Instantiate LHC Adapter Component
        # --- Modifies LHC to convert continuous design variable to discrete
        # --------------------------------------------------------------------------- #
        self.add('adapter', AdapterComp())

        # --------------------------------------------------------------------------- #
        # --- Instantiate Geometry Component
        # --------------------------------------------------------------------------- #
        self.add('geometry', GeometryComp())

        # 1--- Top Level Workflow
        self.driver.workflow.add(['doe_driver'])
        self.doe_driver.workflow.add(['adapter', 'geometry'])

        # --------------------------------------------------------------------------- #
        # --- Add parameters to DOE driver
        # --------------------------------------------------------------------------- #
        self.doe_driver.add_parameter('adapter.vane_num')
        self.doe_driver.add_parameter('adapter.injector_loc')
        self.doe_driver.add_parameter('adapter.injector_dia')
        self.doe_driver.add_parameter('geometry.vane_pitch')
        self.doe_driver.add_parameter('geometry.venturi_angle')

        # --------------------------------------------------------------------------- #
        # Specify DBcaseRecorder for DOE
        # --------------------------------------------------------------------------- #
        self.doe_driver.case_outputs = [
            'adapter.vane_num_out', 'adapter.injector_loc_out',
            'adapter.injector_dia_out', 'geometry.vane_num',
            'geometry.injector_loc', 'geometry.injector_dia'
        ]
        self.doe_driver.recorder = DBCaseRecorder(DOE_OUT_DB)

        #self.add('DOE_restart', DBCaseIterator(DOE_OUT_DB))

        # --------------------------------------------------------------------------- #
        # --- Specify Non-NPSS Data Connections
        # --------------------------------------------------------------------------- #
        self.connect('adapter.vane_num_out', 'geometry.vane_num')
        self.connect('adapter.injector_loc_out', 'geometry.injector_loc')
        self.connect('adapter.injector_dia_out', 'geometry.injector_dia')
Example #8
0
    def configure(self):

        #Components
        self.add("trig_meta_model", MetaModel())
        self.trig_meta_model.surrogate = {
            "f_x_sin": LogisticRegression(),
            "f_x_cos": KrigingSurrogate()
        }
        self.trig_meta_model.model = Trig()
        self.trig_meta_model.recorder = DBCaseRecorder()

        #Training the MetaModel
        self.add("DOE_Trainer", DOEdriver())
        self.DOE_Trainer.DOEgenerator = FullFactorial()
        self.DOE_Trainer.DOEgenerator.num_levels = 20
        self.DOE_Trainer.add_parameter("trig_meta_model.x", low=0, high=20)
        self.DOE_Trainer.case_outputs = [
            "trig_meta_model.f_x_sin", "trig_meta_model.f_x_cos"
        ]
        self.DOE_Trainer.add_event("trig_meta_model.train_next")
        self.DOE_Trainer.recorders = [DBCaseRecorder()]

        #MetaModel Validation
        self.add("trig_calc", Trig())
        self.add("DOE_Validate", DOEdriver())
        self.DOE_Validate.DOEgenerator = Uniform()
        self.DOE_Validate.DOEgenerator.num_samples = 20
        self.DOE_Validate.add_parameter(("trig_meta_model.x", "trig_calc.x"),
                                        low=0,
                                        high=20)
        self.DOE_Validate.case_outputs = [
            "trig_calc.f_x_sin", "trig_calc.f_x_cos",
            "trig_meta_model.f_x_sin", "trig_meta_model.f_x_cos"
        ]
        self.DOE_Validate.recorders = [DBCaseRecorder()]

        #Iteration Hierarchy
        self.driver.workflow = SequentialWorkflow()
        self.driver.workflow.add(['DOE_Trainer', 'DOE_Validate'])
        self.DOE_Trainer.workflow.add('trig_meta_model')
        self.DOE_Validate.workflow.add('trig_meta_model')
        self.DOE_Validate.workflow.add('trig_calc')
Example #9
0
    def configure(self):    
        self._tdir = mkdtemp()        
        
        self.comp_name = None
        #check to make sure no more than one component is being referenced
        compnames = set()
        for param in self.parent.get_parameters().values():
            compnames.update(param.get_referenced_compnames())

        if len(compnames) > 1:
            self.parent.raise_exception('The EGO architecture can only be used on one'
                                        'component at a time, but parameters from %s '
                                        'were added to the problem formulation.' %compnames, 
                                        ValueError)
        self.comp_name = compnames.pop()        
        #change name of component to add '_model' to it. 
        #     lets me name the metamodel as the old name
        self.comp= getattr(self.parent,self.comp_name)
        self.comp.name = "%s_model"%self.comp_name
        
        #add in the metamodel
        meta_model = self.parent.add(self.comp_name,MetaModel()) #metamodel now replaces old component with same name
        meta_model.default_surrogate = KrigingSurrogate()
        meta_model.model = self.comp
        
        meta_model_recorder = DBCaseRecorder(os.path.join(self._tdir,'trainer.db'))
        meta_model.recorder = meta_model_recorder
        
        EI = self.parent.add("EI",ExpectedImprovement())
        self.objective = self.parent.get_objectives().keys()[0]
        EI.criteria = self.objective
        
        pfilter = self.parent.add("filter",ParetoFilter())
        pfilter.criteria = [self.objective]
        pfilter.case_sets = [meta_model_recorder.get_iterator(),]
        
        #Driver Configuration
        DOE_trainer = self.parent.add("DOE_trainer",DOEdriver())
        DOE_trainer.sequential = True
        DOE_trainer.DOEgenerator = OptLatinHypercube(num_samples=self.initial_DOE_size)
        
        for name,param in self.parent.get_parameters().iteritems(): 
            DOE_trainer.add_parameter(param)

        DOE_trainer.add_event("%s.train_next"%self.comp_name)
        
        DOE_trainer.case_outputs = [self.objective]
        DOE_trainer.recorders = [DBCaseRecorder(':memory:')]
        
        EI_opt = self.parent.add("EI_opt",Genetic())
        EI_opt.opt_type = "maximize"
        EI_opt.population_size = 100
        EI_opt.generations = 10
        #EI_opt.selection_method = "tournament"
        
        for name,param in self.parent.get_parameters().iteritems(): 
            EI_opt.add_parameter(param)
        EI_opt.add_objective("EI.%s"%self.EI_PI)
        
        retrain = self.parent.add("retrain",Driver())
        retrain.recorders = self.data_recorders
        
        retrain.add_event("%s.train_next"%self.comp_name)
        
        iter = self.parent.add("iter",IterateUntil())
        iter.max_iterations = self.sample_iterations
        iter.add_stop_condition('EI.PI <= %s'%self.min_ei_pi)
        
        #Data Connections
        self.parent.connect("filter.pareto_set","EI.best_case")
        self.parent.connect(self.objective,"EI.predicted_value")        
        
        #Iteration Heirarchy
        self.parent.driver.workflow.add(['DOE_trainer', 'iter'])
        #DOE_trainer.workflow.add(self.comp_name)
        
        iter.workflow = SequentialWorkflow()
        iter.workflow.add(['filter', 'EI_opt', 'retrain'])
        
        #EI_opt.workflow.add([self.comp_name,'EI'])
        retrain.workflow.add(self.comp_name)
    def configure(self): 
        """Setup a BLISS2000 architecture inside this assembly.
        """
        
        global_dvs = self.parent.get_global_des_vars()
        des_vars=self.parent.get_des_vars_by_comp()
        local_dvs_by_comp = self.parent.get_local_des_vars_by_comp()
        global_dvs_by_comp = self.parent.get_global_des_vars_by_comp()
        
        locals=self.parent.get_local_des_vars()
        
        
        objective = self.parent.get_objectives().items()[0]
        comp_constraints = self.parent.get_constraints_by_comp()
        coupling = self.parent.list_coupling_vars()
        couple_deps = self.parent.get_coupling_deps_by_comp()
        couple_indeps = self.parent.get_coupling_indeps_by_comp()
        
        driver=self.parent.add("driver",FixedPointIterator())
               
        driver.workflow = SequentialWorkflow()           
        driver.max_iteration=15 #should be enough to converge
        driver.tolerance = .005
        meta_models = {}
        self.sub_system_opts = {}
        
        system_var_map = {}
        for comp in des_vars: 
            mm_name = "meta_model_%s"%comp
            meta_model = self.parent.add(mm_name,MetaModel()) #metamodel now replaces old component with same name 
            driver.add_event("%s.reset_training_data"%mm_name)

            meta_models[comp] = meta_model
            meta_model.default_surrogate = ResponseSurface()
            #if there are locals, you need to make a SubSystemOpt assembly
            comp_obj = self.parent.get(comp)
             
            sso = self.parent.add('sub_system_opt_%s'%comp,
                                  SubSystemOpt(comp_obj,
                                  global_dvs_by_comp.get(comp),
                                  local_dvs_by_comp.get(comp),
                                  couple_deps.get(comp),
                                  couple_indeps.get(comp),
                                  comp_constraints.get(comp)))
            self.sub_system_opts[comp] = sso
            meta_model.model = sso 
            for name,mapped_name in sso.var_map.iteritems():
                system_var_map[name] = "%s.%s"%(mm_name,mapped_name)
                                
            meta_model.recorder = DBCaseRecorder()
            
            #add a doe trainer for each metamodel
            dis_doe=self.parent.add("DOE_Trainer_%s"%comp,NeighborhoodDOEdriver())
            
            for couple in couple_indeps[comp] :
                mapped_name = system_var_map[couple.indep.target]
                dis_doe.add_parameter(mapped_name,low=-1e99,high=1e99) #change to -1e99/1e99 
                
            for dv in global_dvs_by_comp[comp]:
                dis_doe.add_parameter(system_var_map[dv.target],low=dv.low, high=dv.high,start=dv.start)
            if local_dvs_by_comp.get(comp): #add weights if they are there
                for w in meta_model.model.weights: 
                    dis_doe.add_parameter("meta_model_%s.%s"%(comp,w),low=-3,high=3)
            num_params = len(dis_doe.get_parameters())        
            dis_doe.DOEgenerator = LatinHypercube((num_params**2+3*num_params+2)/2)
            dis_doe.alpha= .1
            dis_doe.beta = .01

            dis_doe.add_event("meta_model_%s.train_next"%comp)
            dis_doe.force_execute = True
            driver.workflow.add(dis_doe.name) #run all doe training before system optimziation
                
      
        
        #optimization of system objective function using the discipline meta models
        sysopt=self.parent.add('sysopt', SLSQPdriver())   
        sysopt.recorders = self.data_recorders
        sysopt.iprint = 0
        sysopt.differentiator = FiniteDifference()
        
        obj2= objective[1].text
        #for comp in objective[1].get_referenced_compnames():            
        #    obj2=obj2.replace(comp,"meta_model_%s"%comp)  
        for var_name, mapped_name in system_var_map.iteritems(): 
            obj2=obj2.replace(var_name,mapped_name)
        sysopt.add_objective(obj2)
        #add global design variables as parameters

        for param,group in global_dvs:
            plist=[system_var_map[t] for t in group.targets]
            sysopt.add_parameter(plist, low=group.low, high=group.high,start=group.start)
        
        #add the subsytem weights to the system optimization
        for comp,sso in self.sub_system_opts.iteritems(): 
            mm_name = "meta_model_%s"%comp
            for w in sso.weights: 
                sysopt.add_parameter("%s.%s"%(mm_name,w),low=-3,high=3)
        
        for key,couple in coupling.iteritems():
            s=couple.indep.target
            mapped_name = system_var_map[s]
            sysopt.add_parameter(mapped_name, low=-1e99, high=1e99)
            
            #feasibility constraints, referenced to metamodels
            s1,s2= system_var_map[couple.dep.target], system_var_map[couple.indep.target]
            sysopt.add_constraint('(%s-%s)**2<=0.0001'%(s2,s1))
            #sysopt.add_constraint('%s>=%s'%(s2,s1))
            
        
        #add constraints, referenced to metamodels
        for comp,constraints in comp_constraints.iteritems():
            for c in constraints:  
                new_c = str(c)
                for var,mapped_name in system_var_map.iteritems():
                    new_c = new_c.replace(var,mapped_name)
                sysopt.add_constraint(new_c)
        
        driver.workflow.add('sysopt')

        #setup paramter for fixedpointiterator
        
        comp=des_vars.keys()[0]
        mm='meta_model_%s'%comp

        #create some placeholder variables for the fixed point iteration         
        for l in locals:
            s=system_var_map[l[0]].replace(".","_")
            
            s2='%s_store'%s
            self.parent.add(s2,Float(0.0))
            driver.add_parameter(s2 , low=l[1].low, high=l[1].high)
            driver.add_constraint('%s = %s'%(system_var_map[l[1].target],s2))
            
            
        for i,g in enumerate(global_dvs):
            s2='global%d_store'%i
            self.parent.add(s2,Float(0.0)) 
            driver.add_parameter(s2 , low=g[1].low, high=g[1].high)
            driver.add_constraint('%s = %s'%(system_var_map[g[1].target],s2))       
Example #11
0
    def test_itername(self):
        # top
        #     comp1
        #     driverA
        #         comp1
        #         comp2
        #     driverB
        #         comp2
        #         subassy
        #             comp3
        trace_buf = []
        top = TracedAssembly(trace_buf)
        top.add('driver', TracedIterator(trace_buf, 2))
        top.add('comp1', TracedComponent(trace_buf))
        top.add('driverA', TracedIterator(trace_buf, 3))
        top.add('comp2', TracedComponent(trace_buf))
        top.add('driverB', TracedIterator(trace_buf, 2))

        sub = top.add('subassy', TracedAssembly(trace_buf))
        sub.add('driver', TracedIterator(trace_buf, 2))
        sub.add('comp3', TracedComponent(trace_buf))
        sub.driver.workflow.add('comp3')

        # Default didn't execute comp1 first.
        top.driver.workflow = SequentialWorkflow()
        top.driver.workflow.add(('comp1', 'driverA', 'driverB'))
        top.driverA.workflow.add(('comp1', 'comp2'))
        top.driverB.workflow.add(('comp2', 'subassy'))

        top.run()
        top.run(case_id='ReRun')

        expected = """\
: 
driver: 
comp1: 1-1
driverA: 1-2
comp1: 1-2.1-1
comp2: 1-2.1-2
comp1: 1-2.2-1
comp2: 1-2.2-2
comp1: 1-2.3-1
comp2: 1-2.3-2
driverB: 1-3
comp2: 1-3.1-1
subassy: 1-3.1-2
subassy.driver: 1-3.1-2
subassy.comp3: 1-3.1-2.1-1
subassy.comp3: 1-3.1-2.2-1
comp2: 1-3.2-1
subassy: 1-3.2-2
subassy.driver: 1-3.2-2
subassy.comp3: 1-3.2-2.1-1
subassy.comp3: 1-3.2-2.2-1
comp1: 2-1
driverA: 2-2
comp1: 2-2.1-1
comp2: 2-2.1-2
comp1: 2-2.2-1
comp2: 2-2.2-2
comp1: 2-2.3-1
comp2: 2-2.3-2
driverB: 2-3
comp2: 2-3.1-1
subassy: 2-3.1-2
subassy.driver: 2-3.1-2
subassy.comp3: 2-3.1-2.1-1
subassy.comp3: 2-3.1-2.2-1
comp2: 2-3.2-1
subassy: 2-3.2-2
subassy.driver: 2-3.2-2
subassy.comp3: 2-3.2-2.1-1
subassy.comp3: 2-3.2-2.2-1
: 
driver: 
comp1: ReRun.1-1
driverA: ReRun.1-2
comp1: ReRun.1-2.1-1
comp2: ReRun.1-2.1-2
comp1: ReRun.1-2.2-1
comp2: ReRun.1-2.2-2
comp1: ReRun.1-2.3-1
comp2: ReRun.1-2.3-2
driverB: ReRun.1-3
comp2: ReRun.1-3.1-1
subassy: ReRun.1-3.1-2
subassy.driver: ReRun.1-3.1-2
subassy.comp3: ReRun.1-3.1-2.1-1
subassy.comp3: ReRun.1-3.1-2.2-1
comp2: ReRun.1-3.2-1
subassy: ReRun.1-3.2-2
subassy.driver: ReRun.1-3.2-2
subassy.comp3: ReRun.1-3.2-2.1-1
subassy.comp3: ReRun.1-3.2-2.2-1
comp1: ReRun.2-1
driverA: ReRun.2-2
comp1: ReRun.2-2.1-1
comp2: ReRun.2-2.1-2
comp1: ReRun.2-2.2-1
comp2: ReRun.2-2.2-2
comp1: ReRun.2-2.3-1
comp2: ReRun.2-2.3-2
driverB: ReRun.2-3
comp2: ReRun.2-3.1-1
subassy: ReRun.2-3.1-2
subassy.driver: ReRun.2-3.1-2
subassy.comp3: ReRun.2-3.1-2.1-1
subassy.comp3: ReRun.2-3.1-2.2-1
comp2: ReRun.2-3.2-1
subassy: ReRun.2-3.2-2
subassy.driver: ReRun.2-3.2-2
subassy.comp3: ReRun.2-3.2-2.1-1
subassy.comp3: ReRun.2-3.2-2.2-1"""
        expected = expected.split('\n')
        errors = 0
        for i, line in enumerate(trace_buf):
            if line != expected[i]:
                logging.error('%d: expected %r, got %r', i, expected[i], line)
                errors += 1
        self.assertEqual(errors, 0)
        self.assertEqual(len(trace_buf), len(expected))
Example #12
0
    def configure(self):

        # --------------------------------------------------------------------------- #
        # --- Instantiate Counter Component
        # --------------------------------------------------------------------------- #
        self.add('counter', DOECounterComp())

        # --------------------------------------------------------------------------- #
        # --- Instantiate Subcounter Component
        # --------------------------------------------------------------------------- #
        self.add('subcounter', SubCounterComp())

        # --------------------------------------------------------------------------- #
        # --- Instantiate Restart Component
        # --------------------------------------------------------------------------- #
        self.add('restart_doe', RestartComp())

        # --------------------------------------------------------------------------- #
        # --- Instantiate NPSS Non-Reacting Component
        # --------------------------------------------------------------------------- #
        self.add('npss_nonreacting', NpssNonreacting())
        self.npss_nonreacting.Comb_dPqPBase = init_dP()

        # --------------------------------------------------------------------------- #
        # --- Instantiate NPSS Reacting Component
        # --------------------------------------------------------------------------- #
        self.add('npss_reacting', NpssReacting())
        self.npss_reacting.Comb_dPqPBase = init_dP()

        # --------------------------------------------------------------------------- #
        # --- Instantiate Geometry Component
        # --------------------------------------------------------------------------- #
        self.add('geometry', GeometryComp())

        # --------------------------------------------------------------------------- #
        # --- Instantiate Mesh Component
        # --------------------------------------------------------------------------- #
        self.add('mesh', MeshComp())

        # --------------------------------------------------------------------------- #
        # --- Instantiate NCC Non-reacting Component (1-Step Chemistry)
        # --------------------------------------------------------------------------- #
        self.add('ncc_nonreacting', NCCcomponent())
        self.ncc_nonreacting.max_iterations_per_time_step = 40000
        self.ncc_nonreacting.nonreacting = True
        self.ncc_nonreacting.continuity_goal = 2000
        self.ncc_nonreacting.restarts = 40000
        self.ncc_nonreacting.CFL = 0.8
        self.ncc_nonreacting.mass_imbalance_goal = 1.0E-2
        self.ncc_nonreacting.aero2 = -1.0E-3
        self.ncc_nonreacting.k_e2 = -1.0E-3
        self.ncc_nonreacting.species2 = -1.0E-3
        self.ncc_nonreacting.enthalpy2 = -1.0E-3
        self.ncc_nonreacting.aero4 = 0.05
        self.ncc_nonreacting.k_e4 = 0.05
        self.ncc_nonreacting.species4 = 0.05
        self.ncc_nonreacting.enthalpy4 = 0.05
        self.ncc_nonreacting.twall_run = 4.0
        self.ncc_nonreacting._num_procs = 400  # --- Must be divisible by 20 to run on Ivy Bridge

        # --------------------------------------------------------------------------- #
        # --- Instantiate NCC Reacting Component (1-Step Chemistry)
        # --------------------------------------------------------------------------- #
        self.add('ncc_reacting', NCCcomponent())
        self.ncc_reacting.reacting = True
        self.ncc_reacting.continuity_goal = 750
        self.ncc_reacting.max_iterations_per_time_step = 15000
        self.ncc_reacting.restarts = 15000
        self.ncc_reacting.CFL = 0.8
        self.ncc_reacting.pbcfl = 0.375
        self.ncc_reacting.etau_beta = 0.15
        self.ncc_reacting.mass_imbalance_goal = 1.0E-3
        self.ncc_reacting.aux_var_name_list = "'unmixed' 'C12H23'"
        self.ncc_reacting.spec_name_ignite = 'C12H23'
        self.ncc_reacting.fuel_symbol = 'C12H23'
        self.ncc_reacting.combust = True
        self.ncc_reacting.lspray = True
        self.ncc_reacting.aero2 = -2.5E-3
        self.ncc_reacting.k_e2 = -2.5E-3
        self.ncc_reacting.species2 = -2.5E-3
        self.ncc_reacting.enthalpy2 = -2.5E-3
        self.ncc_reacting.aero4 = 0.05
        self.ncc_reacting.k_e4 = 0.05
        self.ncc_reacting.species4 = 0.05
        self.ncc_reacting.enthalpy4 = 0.05
        self.ncc_reacting.ignite_done_model = 0
        self.ncc_reacting.ignition_on = True
        self.ncc_reacting.no_of_streams = 16
        self.ncc_reacting.twall_run = 4.0
        self.ncc_reacting._num_procs = 400  # --- Must be divisible by 20 to run on Ivy Bridge

        # --------------------------------------------------------------------------- #
        # --- Instantiate NCC Reacting Component (Detailed Chemistry)
        # --------------------------------------------------------------------------- #
        self.add('ncc_reacting2', NCCcomponent())
        self.ncc_reacting2.reacting2 = True
        self.ncc_reacting2.continuity_goal = 750
        self.ncc_reacting2.max_iterations_per_time_step = 10000
        self.ncc_reacting2.restarts = 10000
        self.ncc_reacting2.CFL = 0.9
        self.ncc_reacting.pbcfl = 0.5
        self.ncc_reacting2.mass_imbalance_goal = 1.0E-3
        self.ncc_reacting2.aux_var_name_list = "'unmixed' 'C11H21'"
        self.ncc_reacting2.spec_name_ignite = 'C11H21'
        self.ncc_reacting2.fuel_symbol = 'C11H21'
        self.ncc_reacting2.combust = True
        self.ncc_reacting2.lspray = True
        self.ncc_reacting2.aero2 = -1.0E-3
        self.ncc_reacting2.k_e2 = -1.0E-3
        self.ncc_reacting2.species2 = -1.0E-3
        self.ncc_reacting2.enthalpy2 = -1.0E-3
        self.ncc_reacting2.aero4 = 0.05
        self.ncc_reacting2.k_e4 = 0.05
        self.ncc_reacting2.species4 = 0.05
        self.ncc_reacting2.enthalpy4 = 0.05
        self.ncc_reacting2.energy = 0.0001
        self.ncc_reacting2.when_start_spray = 1
        self.ncc_reacting2.ignite_done_model = 0
        self.ncc_reacting2.ignition_on = True
        self.ncc_reacting2.twall_run = 7.5
        self.ncc_reacting2._num_procs = 400  # --- Must be divisible by 20 to Run on Ivy Bridge

        # --------------------------------------------------------------------------- #
        # --- Instantiate Tecplot Nonreacting Component
        # --------------------------------------------------------------------------- #
        self.add('tecplot_nonreacting', TecplotComp())
        self.tecplot_nonreacting.nonreacting = True

        # --------------------------------------------------------------------------- #
        # --- Instantiate Tecplot Reacting Spray Component
        # --------------------------------------------------------------------------- #
        self.add('tecplot_reacting', TecplotComp())
        self.tecplot_reacting.reacting = True

        # --------------------------------------------------------------------------- #
        # --- Instantiate Tecplot Reacting Spray Component
        # --------------------------------------------------------------------------- #
        self.add('tecplot_reacting2', TecplotComp())
        self.tecplot_reacting2.reacting2 = True

        # --------------------------------------------------------------------------- #
        # --- Create Driver Instances
        # --------------------------------------------------------------------------- #
        # --- Top Level Assembly Driver
        self.add('driver', IterateUntil())
        self.driver.max_iterations = 1
        self.driver.workflow = SequentialWorkflow()

        # --- Inner Nonreacting Driver (Fixed Point)
        self.add('nonreacting_driver', FixedPointIterator())
        self.nonreacting_driver.workflow = SequentialWorkflow()
        self.nonreacting_driver.step_size = 0.125
        self.nonreacting_driver.max_iteration = 1
        self.nonreacting_driver.tolerance = 0.001

        # --- Inner Reacting Driver
        self.add('reacting_driver', IterateUntil())
        self.reacting_driver.max_iterations = 1
        self.reacting_driver.workflow = SequentialWorkflow()

        # --- Inner Reacting Driver #2
        self.add('reacting_driver2', IterateUntil())
        self.reacting_driver2.max_iterations = 2
        self.reacting_driver2.workflow = SequentialWorkflow()
        self.reacting_driver2.add_stop_condition(
            'tecplot_reacting2.dTqTBase < 0.0025')

        # --- Run Design at All ICAO Power Settings
        self.add('power_hook', CaseIteratorDriver())
        self.power_hook.workflow = SequentialWorkflow()
        self.power_hook.iterator = CSVCaseIterator(filename='ICAOsettings.csv')
        self.power_hook.workflow.add(['reacting_driver2'])

        # --------------------------------------------------------------------------- #
        # --- Create Main Assembly Workflow
        # --------------------------------------------------------------------------- #
        # --- Add component instances to top-level assembly
        #self.driver.workflow.add(['counter', 'restart_doe', 'geometry', 'mesh', 'nonreacting_driver', 'reacting_driver', 'reacting_driver2'])
        #self.driver.workflow.add(['counter', 'restart_doe', 'geometry', 'nonreacting_driver', 'reacting_driver', 'reacting_driver2'])
        #self.driver.workflow.add(['counter', 'restart_doe', 'geometry', 'reacting_driver2'])
        #self.driver.workflow.add(['counter', 'restart_doe', 'geometry', 'npss_nonreacting', 'npss_reacting'])
        self.driver.workflow.add(
            ['counter', 'restart_doe', 'geometry', 'power_hook'])

        # --------------------------------------------------------------------------- #
        # --- Create Sub-Assembly Workflows
        # --------------------------------------------------------------------------- #
        # --- Inner Nonreacting Loop - Solve via fixed point iteration
        self.nonreacting_driver.workflow.add([
            'subcounter', 'npss_nonreacting', 'ncc_nonreacting',
            'tecplot_nonreacting'
        ])

        # --- Add solver independents and dependents for fixed point iterator
        self.nonreacting_driver.add_parameter(
            ['npss_nonreacting.Comb_dPqPBase', 'npss_reacting.Comb_dPqPBase'],
            low=-9.e99,
            high=9.e99)
        self.nonreacting_driver.add_constraint(
            'tecplot_nonreacting.dPqPBase = npss_nonreacting.Comb_dPqPBase')

        # --- Inner Reacting Loop - Run Once
        self.reacting_driver.workflow.add([
            'subcounter', 'npss_reacting', 'ncc_reacting', 'tecplot_reacting'
        ])

        # --- Inner Reacting Loop #2 - Run Once
        self.reacting_driver2.workflow.add([
            'subcounter', 'npss_reacting', 'ncc_reacting2', 'tecplot_reacting2'
        ])

        # --------------------------------------------------------------------------- #
        # --- Add Driver Events --- Comment this section out to override numbering
        # --------------------------------------------------------------------------- #
        if (self.subcounter._iteration == 0):
            self.driver.add_event('subcounter.reset_iteration')
            self.driver.add_event('ncc_nonreacting.clean_start')

            self.power_hook.add_event('subcounter.reset_iteration')
            self.power_hook.add_event('ncc_nonreacting.clean_start')

        # --------------------------------------------------------------------------- #
        # --- Specify Case Recorders
        # --------------------------------------------------------------------------- #
        self.driver.case_outputs = [
            'geometry.pilot_recession', 'geometry.vane_height',
            'geometry.venturi_angle', 'nonreacting_driver.ncc_nonreacting.FAR',
            'nonreacting_driver.tecplot_nonreacting.dPqPBase'
        ]

        self.power_hook.recorders = [DumpCaseRecorder()]

        # --------------------------------------------------------------------------- #
        # --- Create Data Connections
        # --------------------------------------------------------------------------- #
        self.connect('counter.config', [
            'subcounter.case', 'restart_doe.config', 'geometry.config',
            'mesh.config'
        ])
        self.connect('subcounter.config', [
            'ncc_nonreacting.config', 'ncc_reacting.config',
            'ncc_reacting2.config', 'tecplot_nonreacting.config',
            'tecplot_reacting.config', 'tecplot_reacting2.config'
        ])
        self.connect('restart_doe.pilot_recession',
                     ['geometry.pilot_recession', 'mesh.pilot_recession'])
        self.connect('restart_doe.venturi_angle',
                     ['geometry.venturi_angle', 'mesh.venturi_angle'])
        self.connect('restart_doe.vane_height',
                     ['geometry.vane_height', 'mesh.vane_height'])

        self.connect('geometry.injector_dia', [
            'ncc_nonreacting.injector_dia', 'ncc_nonreacting.bc1_Lmix',
            'ncc_reacting.injector_dia', 'ncc_reacting.bc1_Lmix',
            'ncc_reacting2.injector_dia', 'ncc_reacting2.bc1_Lmix'
        ])
        self.connect('geometry.sector_area', [
            'npss_nonreacting.Inlet_Fl_O_Aphy',
            'npss_nonreacting.Comb_Fl_O_Aphy',
            'npss_nonreacting.Bld1_Fl_O_Aphy',
            'npss_nonreacting.Bld2_Fl_O_Aphy'
        ])
        self.connect('geometry.sector_area', [
            'npss_reacting.Inlet_Fl_O_Aphy', 'npss_reacting.Comb_Fl_O_Aphy',
            'npss_reacting.Bld1_Fl_O_Aphy', 'npss_reacting.Bld2_Fl_O_Aphy'
        ])
        self.connect('geometry.venturi_throat_area', [
            'npss_nonreacting.Conv_Duct_Fl_O_Aphy',
            'npss_reacting.Conv_Duct_Fl_O_Aphy'
        ])
        self.connect('geometry.venturi_exit_area', [
            'npss_nonreacting.Div_Duct_Fl_O_Aphy',
            'npss_reacting.Div_Duct_Fl_O_Aphy'
        ])

        self.connect('npss_nonreacting.Conv_Duct_Fl_O_W',
                     'ncc_nonreacting.bc1_mdot')
        self.connect('npss_nonreacting.Inlet_Fl_O_V', 'ncc_nonreacting.u_init')
        self.connect(
            'npss_nonreacting.Inlet_Fl_O_Ts',
            ['ncc_nonreacting.bc1_Tstatic', 'ncc_nonreacting.Tstatic_init'])
        self.connect(
            'npss_nonreacting.Comb_Fl_O_Ps',
            ['ncc_nonreacting.bc2_Pstatic', 'ncc_nonreacting.Pstatic_init'])
        self.connect('npss_nonreacting.Comb_Fl_O_Ts',
                     'ncc_nonreacting.bc2_Tstatic')
        self.connect('npss_nonreacting.Comb_FAR', 'ncc_nonreacting.FAR')
        self.connect('npss_nonreacting.Inlet_Fl_O_rhos',
                     'ncc_nonreacting.rho_air')
        self.connect('npss_nonreacting.Bld1_BldOut_W',
                     'ncc_nonreacting.bc7_mdot')
        self.connect('npss_nonreacting.Bld1_Fl_O_Ts',
                     'ncc_nonreacting.bc7_Tstatic')

        self.connect('npss_reacting.Conv_Duct_Fl_O_W',
                     ['ncc_reacting.bc1_mdot', 'ncc_reacting2.bc1_mdot'])
        self.connect('npss_reacting.Inlet_Fl_O_Ts',
                     ['ncc_reacting.bc1_Tstatic', 'ncc_reacting2.bc1_Tstatic'])
        self.connect('npss_reacting.Comb_Fl_O_Ps', [
            'ncc_reacting.bc2_Pstatic', 'ncc_reacting2.bc2_Pstatic',
            'ncc_reacting.Pstatic_init', 'ncc_reacting2.Pstatic_init'
        ])
        self.connect('npss_reacting.Comb_Fl_O_Ts', [
            'ncc_reacting.bc2_Tstatic', 'ncc_reacting2.bc2_Tstatic',
            'ncc_reacting.Tstatic_init', 'ncc_reacting2.Tstatic_init'
        ])
        self.connect('npss_reacting.Comb_FAR',
                     ['ncc_reacting.FAR', 'ncc_reacting2.FAR'])
        self.connect('npss_reacting.Inlet_Fl_O_rhos',
                     ['ncc_reacting.rho_air', 'ncc_reacting2.rho_air'])
        self.connect('npss_reacting.Bld1_BldOut_W',
                     ['ncc_reacting.bc7_mdot', 'ncc_reacting2.bc7_mdot'])
        self.connect('npss_reacting.Bld1_Fl_O_Ts',
                     ['ncc_reacting.bc7_Tstatic', 'ncc_reacting2.bc7_Tstatic'])
    def test_itername(self):
        # top
        #     comp1
        #     driverA
        #         comp1
        #         comp2
        #     driverB
        #         comp2
        #         subassy
        #             comp3
        trace_buf = []
        top = set_as_top(TracedAssembly(trace_buf))
        top.add('driver', TracedIterator(trace_buf, 2))
        top.add('comp1', TracedComponent(trace_buf))
        top.add('driverA', TracedIterator(trace_buf, 3))
        top.add('comp2', TracedComponent(trace_buf))
        top.add('driverB', TracedIterator(trace_buf, 2))

        sub = top.add('subassy', TracedAssembly(trace_buf))
        sub.add('driver', TracedIterator(trace_buf, 2))
        sub.add('comp3', TracedComponent(trace_buf))
        sub.driver.workflow.add('comp3')

        # Default didn't execute comp1 first.
        top.driver.workflow = SequentialWorkflow()
        top.driver.workflow.add(('comp1', 'driverA', 'driverB'))
        top.driverA.workflow.add(('comp1', 'comp2'))
        top.driverB.workflow.add(('comp2', 'subassy'))

        top.run()
        top.set_itername('ReRun')
        top.run()

        expected = """\
:
driver:
comp1: 1-comp1
driverA: 1-driverA
comp1: 1-driverA.1-comp1
comp2: 1-driverA.1-comp2
comp1: 1-driverA.2-comp1
comp2: 1-driverA.2-comp2
comp1: 1-driverA.3-comp1
comp2: 1-driverA.3-comp2
driverB: 1-driverB
comp2: 1-driverB.1-comp2
subassy: 1-driverB.1-subassy
subassy.driver: 1-driverB.1-subassy
subassy.comp3: 1-driverB.1-subassy.1-comp3
subassy.comp3: 1-driverB.1-subassy.2-comp3
comp2: 1-driverB.2-comp2
subassy: 1-driverB.2-subassy
subassy.driver: 1-driverB.2-subassy
subassy.comp3: 1-driverB.2-subassy.1-comp3
subassy.comp3: 1-driverB.2-subassy.2-comp3
comp1: 2-comp1
driverA: 2-driverA
comp1: 2-driverA.1-comp1
comp2: 2-driverA.1-comp2
comp1: 2-driverA.2-comp1
comp2: 2-driverA.2-comp2
comp1: 2-driverA.3-comp1
comp2: 2-driverA.3-comp2
driverB: 2-driverB
comp2: 2-driverB.1-comp2
subassy: 2-driverB.1-subassy
subassy.driver: 2-driverB.1-subassy
subassy.comp3: 2-driverB.1-subassy.1-comp3
subassy.comp3: 2-driverB.1-subassy.2-comp3
comp2: 2-driverB.2-comp2
subassy: 2-driverB.2-subassy
subassy.driver: 2-driverB.2-subassy
subassy.comp3: 2-driverB.2-subassy.1-comp3
subassy.comp3: 2-driverB.2-subassy.2-comp3
: ReRun
driver: ReRun
comp1: ReRun.1-comp1
driverA: ReRun.1-driverA
comp1: ReRun.1-driverA.1-comp1
comp2: ReRun.1-driverA.1-comp2
comp1: ReRun.1-driverA.2-comp1
comp2: ReRun.1-driverA.2-comp2
comp1: ReRun.1-driverA.3-comp1
comp2: ReRun.1-driverA.3-comp2
driverB: ReRun.1-driverB
comp2: ReRun.1-driverB.1-comp2
subassy: ReRun.1-driverB.1-subassy
subassy.driver: ReRun.1-driverB.1-subassy
subassy.comp3: ReRun.1-driverB.1-subassy.1-comp3
subassy.comp3: ReRun.1-driverB.1-subassy.2-comp3
comp2: ReRun.1-driverB.2-comp2
subassy: ReRun.1-driverB.2-subassy
subassy.driver: ReRun.1-driverB.2-subassy
subassy.comp3: ReRun.1-driverB.2-subassy.1-comp3
subassy.comp3: ReRun.1-driverB.2-subassy.2-comp3
comp1: ReRun.2-comp1
driverA: ReRun.2-driverA
comp1: ReRun.2-driverA.1-comp1
comp2: ReRun.2-driverA.1-comp2
comp1: ReRun.2-driverA.2-comp1
comp2: ReRun.2-driverA.2-comp2
comp1: ReRun.2-driverA.3-comp1
comp2: ReRun.2-driverA.3-comp2
driverB: ReRun.2-driverB
comp2: ReRun.2-driverB.1-comp2
subassy: ReRun.2-driverB.1-subassy
subassy.driver: ReRun.2-driverB.1-subassy
subassy.comp3: ReRun.2-driverB.1-subassy.1-comp3
subassy.comp3: ReRun.2-driverB.1-subassy.2-comp3
comp2: ReRun.2-driverB.2-comp2
subassy: ReRun.2-driverB.2-subassy
subassy.driver: ReRun.2-driverB.2-subassy
subassy.comp3: ReRun.2-driverB.2-subassy.1-comp3
subassy.comp3: ReRun.2-driverB.2-subassy.2-comp3"""
        expected = expected.split('\n')
        errors = 0

        for i, line in enumerate(trace_buf):
            if line.strip() != expected[i].strip():
                logging.error('%d: expected %r, got %r', i, expected[i], line)
                errors += 1
        self.assertEqual(errors, 0)
        self.assertEqual(len(trace_buf), len(expected))
Example #14
0
    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')
        self.sa_dis1.differentiator = FiniteDifference()
        self.sa_dis1.default_stepsize = 1.0e-6

        # 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')
        self.ssa.differentiator = FiniteDifference()
        self.ssa.default_stepsize = 1.0e-6

        # 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 = SequentialWorkflow()
        self.driver.workflow.add(['ssa', 'sa_dis1', 'bbopt1', 'sysopt'])
    def configure(self):

        self._tdir = mkdtemp()

        #Components
        self.add("branin_meta_model", MetaModel())
        self.branin_meta_model.default_surrogate = KrigingSurrogate()
        self.branin_meta_model.model = BraninComponent()
        self.branin_meta_model.recorder = DBCaseRecorder(':memory:')
        self.branin_meta_model.force_execute = True

        self.add("EI", ExpectedImprovement())
        self.EI.criteria = "branin_meta_model.f_xy"

        self.add("filter", ParetoFilter())
        self.filter.criteria = ['branin_meta_model.f_xy']
        self.filter.case_sets = [
            self.branin_meta_model.recorder.get_iterator(),
        ]
        self.filter.force_execute = True
        #Driver Configuration
        self.add("DOE_trainer", DOEdriver())
        self.DOE_trainer.sequential = True
        self.DOE_trainer.DOEgenerator = OptLatinHypercube(num_samples=15)
        #self.DOE_trainer.DOEgenerator = FullFactorial(num_levels=5)
        self.DOE_trainer.add_parameter("branin_meta_model.x",
                                       low=-5.,
                                       high=10.)
        self.DOE_trainer.add_parameter("branin_meta_model.y", low=0., high=15.)

        self.DOE_trainer.add_event("branin_meta_model.train_next")
        self.DOE_trainer.case_outputs = ["branin_meta_model.f_xy"]
        self.DOE_trainer.recorders = [
            DBCaseRecorder(os.path.join(self._tdir, 'trainer.db'))
        ]

        self.add("EI_opt", Genetic())
        self.EI_opt.opt_type = "maximize"
        self.EI_opt.population_size = 100
        self.EI_opt.generations = 10
        #self.EI_opt.selection_method = "tournament"
        self.EI_opt.add_parameter("branin_meta_model.x", low=-5., high=10.)
        self.EI_opt.add_parameter("branin_meta_model.y", low=0., high=15.)

        self.EI_opt.add_objective("EI.PI")

        self.add("retrain", MyDriver())
        self.retrain.add_event("branin_meta_model.train_next")
        self.retrain.recorders = [
            DBCaseRecorder(os.path.join(self._tdir, 'retrain.db'))
        ]

        self.add("iter", IterateUntil())
        self.iter.max_iterations = 30
        self.iter.add_stop_condition('EI.EI <= .0001')

        #Iteration Heirarchy
        self.driver.workflow.add(['DOE_trainer', 'iter'])

        self.DOE_trainer.workflow.add('branin_meta_model')

        self.iter.workflow = SequentialWorkflow()
        self.iter.workflow.add(['filter', 'EI_opt', 'retrain'])

        self.EI_opt.workflow.add(['branin_meta_model', 'EI'])
        self.retrain.workflow.add('branin_meta_model')

        #Data Connections
        self.connect("filter.pareto_set", "EI.best_case")
        self.connect("branin_meta_model.f_xy", "EI.predicted_value")
Example #16
0
    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()
        comp_constraints = self.parent.get_constraints_by_comp()
        coupling = self.parent.list_coupling_vars()

        self.parent.add('driver', FixedPointIterator())
        self.parent.driver.max_iteration = 15
        self.parent.driver.tolerance = .005

        initial_conditions = [param.start 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 = [param.start 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())
        mda.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.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])
            sa.differentiator = FiniteDifference()

        #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.differentiator = FiniteDifference()
            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)
                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*%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.differentiator = FiniteDifference()
        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)
            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*%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 = SequentialWorkflow()
        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")
Example #17
0
    def configure(self):

        self._tdir = mkdtemp()

        #Components
        self.add("spiral_meta_model", MetaModel())
        self.spiral_meta_model.surrogate = {'default': KrigingSurrogate()}
        self.spiral_meta_model.model = SpiralComponent()
        self.spiral_meta_model.recorder = DBCaseRecorder(':memory:')
        self.spiral_meta_model.force_execute = True

        self.add("MOEI", MultiObjExpectedImprovement())
        self.MOEI.criteria = [
            'spiral_meta_model.f1_xy', 'spiral_meta_model.f2_xy'
        ]

        self.add("filter", ParetoFilter())
        self.filter.criteria = [
            'spiral_meta_model.f1_xy', 'spiral_meta_model.f2_xy'
        ]
        self.filter.case_sets = [
            self.spiral_meta_model.recorder.get_iterator()
        ]
        self.filter.force_execute = True

        #Driver Configuration
        self.add("DOE_trainer", DOEdriver())
        self.DOE_trainer.sequential = True
        self.DOE_trainer.DOEgenerator = OptLatinHypercube(num_samples=25)
        self.DOE_trainer.add_parameter("spiral_meta_model.x")
        self.DOE_trainer.add_parameter("spiral_meta_model.y")
        self.DOE_trainer.add_event("spiral_meta_model.train_next")
        self.DOE_trainer.case_outputs = [
            'spiral_meta_model.f1_xy', 'spiral_meta_model.f2_xy'
        ]
        self.DOE_trainer.recorders = [
            DBCaseRecorder(os.path.join(self._tdir, 'trainer.db'))
        ]

        self.add("MOEI_opt", Genetic())
        self.MOEI_opt.opt_type = "maximize"
        self.MOEI_opt.population_size = 100
        self.MOEI_opt.generations = 10
        #self.MOEI_opt.selection_method = "tournament"
        self.MOEI_opt.add_parameter("spiral_meta_model.x")
        self.MOEI_opt.add_parameter("spiral_meta_model.y")
        self.MOEI_opt.add_objective("MOEI.PI")

        self.add("retrain", MyDriver())
        self.retrain.add_event("spiral_meta_model.train_next")
        self.retrain.recorders = [
            DBCaseRecorder(os.path.join(self._tdir, 'retrain.db'))
        ]

        self.add("iter", IterateUntil())
        self.iter.iterations = 30
        self.iter.add_stop_condition('MOEI.PI <= .0001')

        #Iteration Heirarchy
        self.driver.workflow.add(['DOE_trainer', 'iter'])

        self.DOE_trainer.workflow.add('spiral_meta_model')

        self.iter.workflow = SequentialWorkflow()
        self.iter.workflow.add(['filter', 'MOEI_opt', 'retrain'])

        self.MOEI_opt.workflow.add(['spiral_meta_model', 'MOEI'])
        self.retrain.workflow.add('spiral_meta_model')

        #Data Connections
        self.connect("filter.pareto_set", "MOEI.best_cases")
        self.connect("spiral_meta_model.f1_xy", "MOEI.predicted_values[0]")
        self.connect("spiral_meta_model.f2_xy", "MOEI.predicted_values[1]")