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 configure(self): self.add('d1', Discipline1_WithDerivatives()) self.d1.x1 = 1.0 self.d1.y1 = 1.0 self.d1.y2 = 1.0 self.d1.z1 = 5.0 self.d1.z2 = 2.0 self.add('d2', Discipline2_WithDerivatives()) self.d2.y1 = 1.0 self.d2.y2 = 1.0 self.d2.z1 = 5.0 self.d2.z2 = 2.0 self.add('P1', Paraboloid()) self.add('P2', Paraboloid()) self.connect('d1.y1', 'd2.y1') self.connect('P1.f_xy', 'd1.x1') self.connect('d1.y1', 'P2.x') self.connect('d2.y2', 'P2.y') self.add('driver', SimpleDriver()) self.add('driver2', Driver()) self.add('subdriver', NewtonSolver()) self.driver.workflow.add(['P1', 'subdriver', 'P2']) self.subdriver.workflow.add(['d1', 'd2']) self.subdriver.add_parameter('d1.y2', low=-1e99, high=1e99) self.subdriver.add_constraint('d1.y2 = d2.y2') self.driver.add_parameter('P1.x', low=-1e99, high=1e99) self.driver.add_constraint('P2.f_xy < 0')
def configure_AEPWindRose(self): """Generic configure method for AEPSingleWindRose and AEPMultipleWindRoses. After this configure method is called, some connections are hanging loose: - if wind_rose_type == 'single': - case_gen.wind_rose - if wind_rose_type == 'multiple': - case_gen.wt_layout Examples -------- ### In a single wind rose case: def configure(self): self.add('case_gen', SingleWindRoseCaseGenerator()) self.add('postprocess_wind_rose', PostProcessSingleWindRose()) configure_AEPWindRose(self) self.connect('wind_rose', 'case_gen.wind_rose') ### In a multiple wind rose case: def configure(self): self.add('case_gen', MultipleWindRosesCaseGenerator()) self.add('postprocess_wind_rose', PostProcessMultipleWindRoses()) configure_AEPWindRose(self) self.connect('wt_layout', 'case_gen.wt_layout') """ # Adding self.add('driver', Driver()) self.add('wind_rose_driver', CaseIteratorDriver()) self.add_default('wf', GenericWindFarm()) self.add_default('case_gen', GenericWindRoseCaseGenerator()) self.add_default('postprocess_wind_rose', GenericPostProcessWindRose()) # Drivers configuration self.wind_rose_driver.workflow.add('wf') self.wind_rose_driver.add_parameter('wf.wind_speed') self.wind_rose_driver.add_parameter('wf.wind_direction') self.wind_rose_driver.add_responses( ['wf.power', 'wf.wt_power', 'wf.wt_thrust']) self.driver.workflow.add( ['case_gen', 'wind_rose_driver', 'postprocess_wind_rose']) # wiring self.connect('wind_speeds', ['case_gen.wind_speeds', 'postprocess_wind_rose.wind_speeds']) self.connect( 'wind_directions', ['case_gen.wind_directions', 'postprocess_wind_rose.wind_directions']) self.connect('case_gen.all_wind_speeds', 'wind_rose_driver.case_inputs.wf.wind_speed') self.connect('case_gen.all_wind_directions', 'wind_rose_driver.case_inputs.wf.wind_direction') self.connect('case_gen.all_frequencies', 'postprocess_wind_rose.frequencies') self.connect('wind_rose_driver.case_outputs.wf.power', 'postprocess_wind_rose.powers') self.connect('postprocess_wind_rose.net_aep', 'net_aep') self.connect('postprocess_wind_rose.array_aep', 'array_aep')
def test_driver(self): # Ensure we can't add a Driver to a component that is not an Assembly. comp = Component() try: comp.add('driver', Driver()) except Exception as err: self.assertEqual(str(err), "A Driver may only be added to an Assembly") pass
def test_gradient_options(self): options = GradientOptions() assert (options.get_metadata("fd_form")["framework_var"]) assert (options.get_metadata("fd_step")["framework_var"]) assert (options.get_metadata("fd_step_type")["framework_var"]) assert (options.get_metadata("force_fd")["framework_var"]) assert (options.get_metadata("gmres_tolerance")["framework_var"]) assert (options.get_metadata("gmres_maxiter")["framework_var"]) assert (Driver().get_metadata("gradient_options")["framework_var"])
def test_gradient_options(self): options = GradientOptions() assert (options.get_metadata("directional_fd")["framework_var"]) assert (options.get_metadata("derivative_direction")["framework_var"]) assert (options.get_metadata("fd_form")["framework_var"]) assert (options.get_metadata("fd_step")["framework_var"]) assert (options.get_metadata("fd_step_type")["framework_var"]) assert (options.get_metadata("force_fd")["framework_var"]) assert (options.get_metadata("lin_solver")["framework_var"]) assert (options.get_metadata("atol")["framework_var"]) assert (options.get_metadata("rtol")["framework_var"]) assert (options.get_metadata("maxiter")["framework_var"]) assert (Driver().get_metadata("gradient_options")["framework_var"])
def setup(self, compname, kwargs): self.model.add('comp', eval('%s(**kwargs)' % compname)) self.model.add('sub', Driver()) self.model.driver.workflow.add('sub') self.model.sub.workflow.add('comp') self.inputs, self.outputs = self.model.comp.list_deriv_vars() for item in self.inputs: val = self.model.comp.get(item) if hasattr(val, 'shape'): shape1 = val.shape self.model.comp.set(item, np.random.random(shape1)) else: self.model.comp.set(item, random.random())
def test_mimic(self): # Ensure we can mimic a driver. top = Assembly() top.add('c1', Component()) top.add('c2', Component()) top.driver.workflow.add(('c1', 'c2')) top.driver.printvars = ['c1.force_execute', 'c2.force_execute'] recorder1 = FakeRecorder() recorder2 = FakeRecorder() top.driver.recorders = [recorder1, recorder2] workflow_id = id(top.driver.workflow) new_driver = Driver() new_id = id(new_driver) self.assertNotEqual(new_id, id(top.driver)) top.replace('driver', new_driver) self.assertEqual(new_id, id(top.driver)) self.assertEqual(workflow_id, id(top.driver.workflow)) self.assertEqual(top.driver.printvars, ['c1.force_execute', 'c2.force_execute']) self.assertEqual(top.driver.recorders, [recorder1, recorder2])
def configure(self): """ Creates a new Assembly with this problem Optimal Design at (1.9776, 0, 0) Optimal Objective = 3.18339""" #objective = '(dis1.x1)**2 + dis1.z2 + dis1.y1 + exp(-dis2.y2)' #constraint1 = 'dis1.y1 > 3.16' #constraint2 = 'dis2.y2 < 24.0' # Metamodel for sellar discipline 1 self.add("meta_model_dis1", MetaModel()) self.meta_model_dis1.surrogates = {"y1": ResponseSurface()} self.meta_model_dis1.model = SellarDiscipline1() self.meta_model_dis1.recorder = DBCaseRecorder() self.meta_model_dis1.force_execute = True # Metamodel for sellar discipline 2 self.add("meta_model_dis2", MetaModel()) self.meta_model_dis2.surrogates = {"y2": ResponseSurface()} self.meta_model_dis2.model = SellarDiscipline2() self.meta_model_dis2.recorder = DBCaseRecorder() self.meta_model_dis2.force_execute = True #training metalmodel for disc1 # self.add("DOE_Trainer_dis2",NeighborhoodDOEdriver()) # self.DOE_Trainer_dis2.DOEgenerator = CentralComposite() # self.DOE_Trainer_dis2.alpha = .1 # self.DOE_Trainer_dis2.add_parameter("meta_model_dis2.z1",low=-10,high=10,start=5.0) # self.DOE_Trainer_dis2.add_parameter("meta_model_dis2.z2",low=0,high=10,start=2.0) # self.DOE_Trainer_dis2.add_parameter("meta_model_dis2.y1",low=0,high=20) # self.DOE_Trainer_dis2.add_event("meta_model_dis2.train_next") # self.DOE_Trainer_dis2.force_execute = True #optimization of global objective function self.add('sysopt', SLSQPdriver()) self.sysopt.add_objective( '(meta_model_dis1.x1)**2 + meta_model_dis1.z2 + meta_model_dis1.y1 + math.exp(-meta_model_dis2.y2)' ) self.sysopt.add_parameter(['meta_model_dis1.z1', 'meta_model_dis2.z1'], low=-10, high=10.0, start=5.0) self.sysopt.add_parameter(['meta_model_dis1.z2', 'meta_model_dis2.z2'], low=0, high=10.0, start=2.0) self.sysopt.add_parameter('meta_model_dis1.y2', low=-1e99, high=1e99) self.sysopt.add_parameter('meta_model_dis2.y1', low=-1e99, high=1e99) #feasibility constraints self.sysopt.add_constraint('meta_model_dis1.y2 <= meta_model_dis2.y2') self.sysopt.add_constraint('meta_model_dis1.y2 >= meta_model_dis2.y2') self.sysopt.add_constraint('meta_model_dis2.y1 <= meta_model_dis1.y1') self.sysopt.add_constraint('meta_model_dis2.y1 >= meta_model_dis1.y1') self.sysopt.add_constraint('3.16 < meta_model_dis1.y1') self.sysopt.add_constraint('meta_model_dis2.y2 < 24.0') self.sysopt.force_execute = True #optimization of discipline 1 (discipline 2 of the sellar problem has no local variables) self.add('local_opt_dis1', SLSQPdriver()) self.local_opt_dis1.add_objective('meta_model_dis1.y1') self.local_opt_dis1.add_parameter('meta_model_dis1.x1', low=0, high=10.0) self.local_opt_dis1.add_constraint('3.16 < meta_model_dis1.y1') self.local_opt_dis1.add_event('meta_model_dis1.train_next') self.local_opt_dis1.force_execute = True self.local_opt_dis1.workflow.add(['meta_model_dis1']) #training metalmodel for disc1 self.add("DOE_Trainer_dis1", NeighborhoodDOEdriver()) self.DOE_Trainer_dis1.DOEgenerator = CentralComposite() self.DOE_Trainer_dis1.alpha = .1 self.DOE_Trainer_dis1.add_parameter("meta_model_dis1.z1", low=-10, high=10, start=5.0) self.DOE_Trainer_dis1.add_parameter("meta_model_dis1.z2", low=0, high=10, start=2.0) self.DOE_Trainer_dis1.add_parameter("meta_model_dis1.y2", low=-100, high=100) self.DOE_Trainer_dis1.add_event("meta_model_dis1.train_next") self.DOE_Trainer_dis1.force_execute = True self.DOE_Trainer_dis1.workflow.add("local_opt_dis1") self.add('reset_train', Driver()) self.reset_train.add_event('meta_model_dis1.reset_training_data') self.reset_train.add_event('meta_model_dis2.reset_training_data') self.reset_train.workflow.add(['meta_model_dis1', 'meta_model_dis2']) self.reset_train.force_execute = True #build workflow for bliss2000 self.add('driver', FixedPointIterator()) #self.add('main_driver', IterateUntil()) #self.main_driver.max_iterations = 1 self.driver.tolerance = .0001 # self.driver.workflow.add(['local_opt_dis1','reset_train','DOE_Trainer_dis1','DOE_Trainer_dis2','sysopt']) self.driver.workflow.add(['sysopt']) self.driver.add_parameter('x1_store', low=0, high=10.0) self.driver.add_constraint('meta_model_dis1.x1 = x1_store') self.driver.add_parameter('z1_store', low=0, high=10.0) self.driver.add_constraint('meta_model_dis1.z1 = z1_store') self.driver.add_parameter('z2_store', low=0, high=10.0) self.driver.add_constraint('meta_model_dis1.z2 = z2_store')
def _setup(self): """ Setup to begin new run. """ # if params have changed we need to setup systems again if self.workflow._system is None: obj = self while obj.parent is not None: obj = obj.parent obj._setup() if not self.sequential: # Save model to egg. # Must do this before creating any locks or queues. self._replicants += 1 version = 'replicant.%d' % (self._replicants) # If only local host will be used, we can skip determining # distributions required by the egg. allocators = RAM.list_allocators() need_reqs = False if not self.ignore_egg_requirements: for allocator in allocators: if not isinstance(allocator, LocalAllocator): need_reqs = True break # Replicate and mutate model to run our workflow once. # Originally this was done in-place, but that 'invalidated' # various workflow quantities. replicant = self.parent.copy() workflow = replicant.get(self.name + '.workflow') driver = replicant.add('driver', Driver()) workflow.parent = driver workflow.scope = None replicant.driver.workflow = workflow egg_info = replicant.save_to_egg(self.name, version, need_requirements=need_reqs) replicant = workflow = driver = None # Release objects. gc.collect() # Collect/compact before possible fork. self._egg_file = egg_info[0] self._egg_required_distributions = egg_info[1] self._egg_orphan_modules = [name for name, path in egg_info[2]] inp_paths = [] inp_values = [] for path, param in self.get_parameters().items(): if isinstance(path, tuple): path = path[0] # Use first target of ParameterGroup. path = make_legal_path(path) value = self.get('case_inputs.' + path) for target in param.targets: inp_paths.append(target) inp_values.append(value) outputs = self.get_responses().keys() extra_outputs = self.workflow._rec_outputs length = len(inp_values[0]) if inp_values else 0 cases = [] for i in range(length): inputs = [] for j in range(len(inp_paths)): inputs.append((inp_paths[j], inp_values[j][i])) cases.append( _Case(i, inputs, outputs, extra_outputs, parent_uuid=self._case_uuid)) self.init_responses(length) self._iter = iter(cases) self._abort_exc = None
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 execute(self): Driver.execute(self)
def configure(self): """ Set it all up. """ # Place all design variables on the Assembly boundary. self.add('S', Float(0.0, iotype='in', desc='Wing Area')) self.add('ac_w', Float(0.0, iotype='in', desc='Weight of aircraft + payload')) self.add('SFCSL', Float(0.0, iotype='in', desc='sea-level SFC value')) self.add('thrust_sl', Float(0.0, iotype='in', desc='Maximum sea-level thrust')) self.add('AR', Float(0.0, iotype='in', desc='Aspect Ratio')) self.add('oswald', Float(0.0, iotype='in', desc="Oswald's efficiency")) # Splines self.add( 'SysXBspline', SysXBspline(num_elem=self.num_elem, num_pt=self.num_pt, x_init=self.x_pts, jac_h=self.jac_h)) self.SysXBspline.x_pt = self.x_pts self.add( 'SysHBspline', SysHBspline(num_elem=self.num_elem, num_pt=self.num_pt, x_init=self.x_pts, jac_h=self.jac_h)) self.add( 'SysMVBspline', SysMVBspline(num_elem=self.num_elem, num_pt=self.num_pt, x_init=self.x_pts, jac_h=self.jac_h)) self.add( 'SysGammaBspline', SysGammaBspline(num_elem=self.num_elem, num_pt=self.num_pt, x_init=self.x_pts, jac_gamma=self.jac_gamma)) # Atmospherics self.add('SysSFC', SysSFC(num_elem=self.num_elem)) self.add('SysTemp', SysTemp(num_elem=self.num_elem)) self.add('SysRho', SysRho(num_elem=self.num_elem)) self.add('SysSpeed', SysSpeed(num_elem=self.num_elem)) self.connect('SFCSL', 'SysSFC.SFCSL') self.connect('SysHBspline.h', 'SysSFC.h') self.connect('SysHBspline.h', 'SysTemp.h') self.connect('SysHBspline.h', 'SysRho.h') self.connect('SysTemp.temp', 'SysRho.temp') self.connect('SysTemp.temp', 'SysSpeed.temp') self.connect('SysMVBspline.M', 'SysSpeed.M') self.connect('SysMVBspline.v_spline', 'SysSpeed.v_spline') # ----------------------------------- # Comps for Coupled System begin here # ----------------------------------- # Vertical Equilibrium self.add('SysCLTar', SysCLTar(num_elem=self.num_elem)) self.connect('S', 'SysCLTar.S') self.connect('ac_w', 'SysCLTar.ac_w') self.connect('SysRho.rho', 'SysCLTar.rho') self.connect('SysGammaBspline.Gamma', 'SysCLTar.Gamma') self.connect('SysSpeed.v', 'SysCLTar.v') # Tripan Alpha self.add( 'SysTripanCLSurrogate', SysTripanCLSurrogate(num_elem=self.num_elem, num=self.num, CL=self.CL_arr)) self.connect('SysMVBspline.M', 'SysTripanCLSurrogate.M') self.connect('SysHBspline.h', 'SysTripanCLSurrogate.h') self.connect('SysCLTar.CL', 'SysTripanCLSurrogate.CL_tar') # Tripan Eta self.add( 'SysTripanCMSurrogate', SysTripanCMSurrogate(num_elem=self.num_elem, num=self.num, CM=self.CM_arr)) self.connect('SysMVBspline.M', 'SysTripanCMSurrogate.M') self.connect('SysHBspline.h', 'SysTripanCMSurrogate.h') self.connect('SysTripanCLSurrogate.alpha', 'SysTripanCMSurrogate.alpha') # Tripan Drag self.add( 'SysTripanCDSurrogate', SysTripanCDSurrogate(num_elem=self.num_elem, num=self.num, CD=self.CD_arr)) self.connect('SysMVBspline.M', 'SysTripanCDSurrogate.M') self.connect('SysHBspline.h', 'SysTripanCDSurrogate.h') self.connect('SysTripanCMSurrogate.eta', 'SysTripanCDSurrogate.eta') self.connect('SysTripanCLSurrogate.alpha', 'SysTripanCDSurrogate.alpha') # Horizontal Equilibrium self.add('SysCTTar', SysCTTar(num_elem=self.num_elem)) self.connect('SysGammaBspline.Gamma', 'SysCTTar.Gamma') self.connect('SysTripanCDSurrogate.CD', 'SysCTTar.CD') self.connect('SysTripanCLSurrogate.alpha', 'SysCTTar.alpha') self.connect('SysRho.rho', 'SysCTTar.rho') self.connect('SysSpeed.v', 'SysCTTar.v') self.connect('S', 'SysCTTar.S') self.connect('ac_w', 'SysCTTar.ac_w') # Weight self.add('SysFuelWeight', SysFuelWeight(num_elem=self.num_elem)) self.SysFuelWeight.fuel_w = np.linspace(1.0, 0.0, self.num_elem + 1) self.connect('SysSpeed.v', 'SysFuelWeight.v') self.connect('SysGammaBspline.Gamma', 'SysFuelWeight.Gamma') self.connect('SysCTTar.CT_tar', 'SysFuelWeight.CT_tar') self.connect('SysXBspline.x', 'SysFuelWeight.x') self.connect('SysSFC.SFC', 'SysFuelWeight.SFC') self.connect('SysRho.rho', 'SysFuelWeight.rho') self.connect('S', 'SysFuelWeight.S') # ------------------------------------------------ # Coupled Analysis - Newton for outer loop # TODO: replace with GS/Newton cascaded solvers when working # ----------------------------------------------- self.add('coupled_solver', NewtonSolver()) # Direct connections (cycles) are faster. self.connect('SysFuelWeight.fuel_w', 'SysCLTar.fuel_w') self.connect('SysCTTar.CT_tar', 'SysCLTar.CT_tar') self.connect('SysTripanCLSurrogate.alpha', 'SysCLTar.alpha') self.connect('SysTripanCMSurrogate.eta', 'SysTripanCLSurrogate.eta') self.connect('SysFuelWeight.fuel_w', 'SysCTTar.fuel_w') #self.coupled_solver.add_parameter('SysCLTar.fuel_w') #self.coupled_solver.add_constraint('SysFuelWeight.fuel_w = SysCLTar.fuel_w') #self.coupled_solver.add_parameter('SysCLTar.CT_tar') #self.coupled_solver.add_constraint('SysCTTar.CT_tar = SysCLTar.CT_tar') #self.coupled_solver.add_parameter('SysCLTar.alpha') #self.coupled_solver.add_constraint('SysTripanCLSurrogate.alpha = SysCLTar.alpha') #self.coupled_solver.add_parameter('SysTripanCLSurrogate.eta') #self.coupled_solver.add_constraint('SysTripanCMSurrogate.eta = SysTripanCLSurrogate.eta') #self.coupled_solver.add_parameter('SysCTTar.fuel_w') #self.coupled_solver.add_constraint('SysFuelWeight.fuel_w = SysCTTar.fuel_w') # (Implicit comps) self.coupled_solver.add_parameter('SysTripanCLSurrogate.alpha') self.coupled_solver.add_constraint( 'SysTripanCLSurrogate.alpha_res = 0') self.coupled_solver.add_parameter('SysTripanCMSurrogate.eta') self.coupled_solver.add_constraint('SysTripanCMSurrogate.CM = 0') # -------------------- # Downstream of solver # -------------------- # Functionals (i.e., components downstream of the coupled system.) self.add('SysTau', SysTau(num_elem=self.num_elem)) self.add('SysTmin', SysTmin(num_elem=self.num_elem)) self.add('SysTmax', SysTmax(num_elem=self.num_elem)) #self.add('SysSlopeMin', SysSlopeMin(num_elem=self.num_elem)) #self.add('SysSlopeMax', SysSlopeMax(num_elem=self.num_elem)) self.add('SysFuelObj', SysFuelObj(num_elem=self.num_elem)) self.add('SysHi', SysHi(num_elem=self.num_elem)) self.add('SysHf', SysHf(num_elem=self.num_elem)) self.add('SysMi', SysMi(num_elem=self.num_elem)) self.add('SysMf', SysMf(num_elem=self.num_elem)) self.add('SysBlockTime', SysBlockTime(num_elem=self.num_elem)) self.connect('S', 'SysTau.S') self.connect('thrust_sl', 'SysTau.thrust_sl') self.connect('SysRho.rho', 'SysTau.rho') self.connect('SysCTTar.CT_tar', 'SysTau.CT_tar') self.connect('SysHBspline.h', 'SysTau.h') self.connect('SysSpeed.v', 'SysTau.v') self.connect('SysTau.tau', 'SysTmin.tau') self.connect('SysTau.tau', 'SysTmax.tau') #self.connect('SysGammaBspline.Gamma', 'SysSlopeMin.Gamma') #self.connect('SysGammaBspline.Gamma', 'SysSlopeMax.Gamma') self.connect('SysFuelWeight.fuel_w', 'SysFuelObj.fuel_w') self.connect('SysHBspline.h', 'SysHi.h') self.connect('SysHBspline.h', 'SysHf.h') self.connect('SysMVBspline.M', 'SysMi.M') self.connect('SysMVBspline.M', 'SysMf.M') self.connect('SysXBspline.x', 'SysBlockTime.x') self.connect('SysSpeed.v', 'SysBlockTime.v') self.connect('SysGammaBspline.Gamma', 'SysBlockTime.Gamma') # Promote useful variables to the boundary. self.create_passthrough('SysHBspline.h_pt') self.connect('h_pt', 'SysGammaBspline.h_pt') self.create_passthrough('SysMVBspline.v_pt') self.create_passthrough('SysMVBspline.M_pt') self.create_passthrough('SysTmin.Tmin') self.create_passthrough('SysTmax.Tmax') self.create_passthrough('SysFuelObj.fuelburn') self.create_passthrough('SysHi.h_i') self.create_passthrough('SysHf.h_f') #------------------------- # Iteration Hierarchy #------------------------- #self.driver.workflow.add(['SysXBspline', 'SysHBspline', #'SysMVBspline', 'SysGammaBspline', #'SysSFC', 'SysTemp', 'SysRho', 'SysSpeed', #'coupled_solver', #'SysTau', 'SysTmin', 'SysTmax', #'SysFuelObj', 'SysHi', 'SysHf', 'SysMi', 'SysMf', 'SysBlockTime']) self.add('bsplines', Driver()) self.add('atmosphere', Driver()) self.add('SysCLTar_Sub', Driver()) self.add('SysTripanCLSurrogate_Sub', Driver()) self.add('SysTripanCMSurrogate_Sub', Driver()) self.add('SysTripanCDSurrogate_Sub', Driver()) self.add('SysCTTar_Sub', Driver()) self.add('SysFuelWeight_Sub', Driver()) self.driver.workflow.add([ 'bsplines', 'atmosphere', 'coupled_solver', 'SysTau', 'SysTmin', 'SysTmax', 'SysFuelObj', 'SysHi', 'SysHf', 'SysMi', 'SysMf', 'SysBlockTime' ]) self.bsplines.workflow.add( ['SysXBspline', 'SysHBspline', 'SysMVBspline', 'SysGammaBspline']) self.atmosphere.workflow.add( ['SysSFC', 'SysTemp', 'SysRho', 'SysSpeed']) self.coupled_solver.workflow.add([ 'SysCLTar_Sub', 'SysTripanCLSurrogate_Sub', 'SysTripanCMSurrogate_Sub', 'SysTripanCDSurrogate_Sub', 'SysCTTar_Sub', 'SysFuelWeight_Sub' ]) self.SysCLTar_Sub.workflow.add(['SysCLTar']) self.SysTripanCLSurrogate_Sub.workflow.add(['SysTripanCLSurrogate']) self.SysTripanCMSurrogate_Sub.workflow.add(['SysTripanCMSurrogate']) self.SysTripanCDSurrogate_Sub.workflow.add(['SysTripanCDSurrogate']) self.SysCTTar_Sub.workflow.add(['SysCTTar']) self.SysFuelWeight_Sub.workflow.add(['SysFuelWeight']) #------------------------- # Driver Settings #------------------------- self.driver.gradient_options.lin_solver = "linear_gs" self.driver.gradient_options.maxiter = 1 self.driver.gradient_options.derivative_direction = 'adjoint' self.coupled_solver.atol = 1e-9 self.coupled_solver.rtol = 1e-9 self.coupled_solver.max_iteration = 15 self.coupled_solver.gradient_options.atol = 1e-14 self.coupled_solver.gradient_options.rtol = 1e-20 self.coupled_solver.gradient_options.maxiter = 50 self.coupled_solver.iprint = 1
msg = "Component 'sub.comp' is not in the scope of the top assembly." self.assertEqual(str(err), msg) else: self.fail('Expected AttributeError') # Test 3, add a comp that does not exist try: self.model.driver.workflow.add('stuff', check=True) except AttributeError, err: msg = "Component 'stuff' does not exist in the top assembly." self.assertEqual(str(err), msg) else: self.fail('Expected AttributeError') # Test 4, create a driver recursion loop self.model.add('driver2', Driver()) self.model.driver.workflow.add('driver2', check=True) try: self.model.driver2.workflow.add('driver', check=True) except AttributeError, err: msg = "Driver recursion loop detected" self.assertEqual(str(err), msg) else: self.fail('Expected AttributeError') if __name__ == '__main__': import nose import sys sys.argv.append('--cover-package=openmdao') sys.argv.append('--cover-erase')
def test_get_entry_group(self): self.assertEqual(_get_entry_group(Driver()), 'openmdao.driver')