def test_get_specs_for_module(): """ Test that 'get_specs_for_module()' works """ # Return None for non-existent modules... specs = m.get_specs_for_module(module_name='SomeModuleThatDoesNotExist') assert specs is None # ... but raise an error if explicitly told to do so with pytest.raises(ImportError): m.get_specs_for_module(module_name='SomeModuleThatDoesNotExist', raise_error=True)
def create_settings_gui(cpacs_path, cpacs_out_path, submodule_list): """Create a GUI with Tkinter to fill CEASIOMpy settings Args: cpacs_path (str): Path to the CPACS file cpacs_out_path (str): Path to the output CPACS file submodule_list (list): List of module to inclue in the GUI """ root = tk.Tk() root.title("CEASIOMpy Settings GUI") # Automatically set the size of the windows gui_modules = 1 max_inputs = 0 for module_name in submodule_list: specs = mi.get_specs_for_module(module_name) if specs: inputs = specs.cpacs_inout.get_gui_dict() if inputs: gui_modules += 1 max_inputs = max(max_inputs, len(inputs)) tot_width = max(415, gui_modules * 82) tot_height = max(350, max_inputs * 50) root.geometry(f"{tot_width}x{tot_height}+400+150") my_setting_gui = SettingGUI(root, cpacs_path, cpacs_out_path, submodule_list) my_setting_gui.mainloop() root.iconify() root.destroy()
def add_subsystems(prob, ivc): """Add subsystems to problem. All subsystem classes are added to the problem model. Args: prob (om.Problem object): Current problem that is being defined ivc (om.IndepVarComp object): Independent variables of the problem Returns: None. """ global mod geom = geom_param() obj = objective() # Independent variables prob.model.add_subsystem('indeps', ivc, promotes=['*']) # Geometric parameters mod = [Rt.modules[0], Rt.modules[-1]] prob.model.add_subsystem('Geometry', geom, promotes=['*']) # Modules for name in Rt.modules: mod = name spec = mif.get_specs_for_module(name) if spec.cpacs_inout.inputs or spec.cpacs_inout.outputs: prob.model.add_subsystem(name, moduleComp(), promotes=['*']) # Objectives prob.model.add_subsystem('objective', obj, promotes=['*'])
def setup(self): """ Setup inputs and outputs""" declared = [] spec = mif.get_specs_for_module(self.module_name) #Inputs for entry in spec.cpacs_inout.inputs: if entry.var_name in declared: log.info('Already declared') elif entry.var_name in optim_var_dict: var = optim_var_dict[entry.var_name] if entry.var_name in optim_var_dict: self.add_input(entry.var_name, val=var[1][0]) declared.append(entry.var_name) if declared == []: self.add_input(self.module_name + '_in') declared = [] # Outputs # To remove #is_skf = (self.module_name == 'SkinFriction') for entry in spec.cpacs_inout.outputs: # Replace special characters from the name of the entry and checks for accronyms entry.var_name = tls.change_var_name(entry.var_name) if entry.var_name in declared: log.info('Already declared') elif entry.var_name in optim_var_dict: var = optim_var_dict[entry.var_name] self.add_output(entry.var_name, val=var[1][0]) declared.append(entry.var_name) elif 'aeromap' in entry.var_name and self.module_name == last_am_module: #== 'PyTornado': #not skf^is_skf: # Condition to avoid any conflict with skinfriction for name in apmf.XSTATES: if name in optim_var_dict: var = optim_var_dict[name] self.add_input(name, val=var[1][0]) declared.append(entry.var_name) for name in apmf.COEF_LIST: if name in optim_var_dict: var = optim_var_dict[name] if tls.is_digit(var[1][0]): self.add_output(name, val=var[1][0]) else: self.add_output(name) declared.append(entry.var_name) if declared == []: self.add_output(self.module_name + '_out')
def setup(self): """Setup inputs and outputs""" declared = [] spec = mif.get_specs_for_module(self.module_name) # Inputs for entry in spec.cpacs_inout.inputs: if entry.var_name in declared: log.info("Already declared") elif entry.var_name in Rt.optim_var_dict: var = Rt.optim_var_dict[entry.var_name] if entry.var_name in Rt.optim_var_dict: self.add_input(entry.var_name, val=var[1][0]) declared.append(entry.var_name) if declared == []: self.add_input(self.module_name + "_in") declared = [] for entry in spec.cpacs_inout.outputs: # Replace special characters from the name of the entry and checks for accronyms entry.var_name = change_var_name(entry.var_name) if entry.var_name in declared: log.info("Already declared") elif entry.var_name in Rt.optim_var_dict: var = Rt.optim_var_dict[entry.var_name] self.add_output(entry.var_name, val=var[1][0]) declared.append(entry.var_name) elif ( "aeromap" in entry.var_name and self.module_name == Rt.last_am_module ): # == 'PyTornado': #not skf^is_skf: # Condition to avoid any conflict with skinfriction for name in PARAMS: if name in Rt.optim_var_dict: var = Rt.optim_var_dict[name] self.add_input(name, val=var[1][0]) declared.append(entry.var_name) for name in COEFS: if name in Rt.optim_var_dict: var = Rt.optim_var_dict[name] if is_digit(var[1][0]): self.add_output(name, val=var[1][0]) else: self.add_output(name) declared.append(entry.var_name) if declared == []: self.add_output(self.module_name + "_out")
def add_subsystems(prob, ivc): """Add subsystems to problem. All subsystem classes are added to the problem model. Args: prob (om.Problem object): Current problem that is being defined ivc (om.IndepVarComp object): Independent variables of the problem """ global mod, geom_dict geom = Geom_param() obj = Objective() # Independent variables prob.model.add_subsystem('indeps', ivc, promotes=['*']) # Geometric parameters mod = [Rt.modules[0], Rt.modules[-1]] geom_dict = {k: v for k, v in optim_var_dict.items() if v[5] != '-'} if geom_dict: prob.model.add_subsystem('Geometry', geom, promotes=['*']) # Find last module to use an aeromap am_module = ['SU2Run', 'PyTornado', 'SkinFriction'] global last_am_module last_am_module = '' for name in Rt.modules: if name in am_module: last_am_module = name # Modules for n, name in enumerate(Rt.modules): if name == 'SMUse': prob.model.add_subsystem(name, SmComp(), promotes=['*']) else: mod = name spec = mif.get_specs_for_module(name) if spec.cpacs_inout.inputs or spec.cpacs_inout.outputs: prob.model.add_subsystem(name, ModuleComp(), promotes=['*']) # Objectives prob.model.add_subsystem('objective', obj, promotes=['*'])
def _update_all(self): # Remove existing AutoTab if len(self.tab_list) > 0 : for i in range(len(self.tab_list)): self.tabs.forget(1) self.tab_list = [] # Generate new Auto Tab for module_name in self.submodule_list: specs = mif.get_specs_for_module(module_name) if specs is None: # Specs does not exist continue self.gui_dict = specs.cpacs_inout.get_gui_dict() if not self.gui_dict: # Empty dict --> nothing to do continue tab = AutoTab(self.tabs, self.tixi, module_name) self.tab_list.append(tab)
def add_subsystems(prob, ivc): """Add subsystems to problem. All subsystem classes are added to the problem model. Args: prob (om.Problem object): Current problem that is being defined ivc (om.IndepVarComp object): Independent variables of the problem """ geom = Geom_param() obj = Objective() # Independent variables prob.model.add_subsystem("indeps", ivc, promotes=["*"]) # Geometric parameters Rt.geom_dict = {k: v for k, v in Rt.optim_var_dict.items() if v[5] != "-"} if Rt.geom_dict: prob.model.add_subsystem("Geometry", geom, promotes=["*"]) # Loop throuth Modules for module in Rt.modules: if module.name in ["SU2Run", "PyTornado", "SkinFriction"]: Rt.last_am_module = module.name if module.name == "SMUse": prob.model.add_subsystem(module.name, SmComp(module), promotes=["*"]) else: spec = mif.get_specs_for_module(module.name) if spec.cpacs_inout.inputs or spec.cpacs_inout.outputs: prob.model.add_subsystem(module.name, ModuleComp(module), promotes=["*"]) # Objectives prob.model.add_subsystem("objective", obj, promotes=["*"])
def setup(self): """ Setup inputs and outputs""" spec = mif.get_specs_for_module(self.module_name) #Inputs for entry in spec.cpacs_inout.inputs: if entry.var_name in optim_var_dict: var = optim_var_dict[entry.var_name] if var[0] == 'des': self.add_input(entry.var_name, val=var[1][0]) elif var[0] in ['const', 'obj']: self.add_output(entry.var_name, val=var[1][0]) # Outputs for entry in spec.cpacs_inout.outputs: if entry.var_name in optim_var_dict: var = optim_var_dict[entry.var_name] self.add_output(entry.var_name, val=var[1][0]) elif 'aeromap' in entry.var_name: for name in [ 'altitude', 'machNumber', 'angleOfAttack', 'angleOfSideslip' ]: if name in optim_var_dict: var = optim_var_dict[name] self.add_input(name, val=var[1][0]) for name in ['cl', 'cd', 'cs', 'cml', 'cmd', 'cms']: if name in optim_var_dict: var = optim_var_dict[name] if tls.is_digit(var[1][0]): self.add_output(name, val=var[1][0]) else: self.add_output(name) # Add output by default as it may be an input for the next module else: self.add_output(entry.var_name)
def __init__(self, tabs, tixi, module_name): """Tab class Note: A tab will only be created if the module actually has any settings which are to be shown Args: tabs (TODO): TODO tixi (handle): Tixi handle module_name (str): String of the module name for which a tab is to be created """ self.var_dict = {} self.group_dict = {} self.module_name = module_name self.tabs = tabs self.tixi = tixi self.tab = tk.Frame(tabs, borderwidth=1) tabs.add(self.tab, text=module_name) # Get GUI dict from specs specs = mif.get_specs_for_module(module_name) self.gui_dict = specs.cpacs_inout.get_gui_dict() #canvas has replaced self.tab in the following lines space_label = tk.Label(self.tab, text=' ') space_label.grid(column=0, row=0) row_pos = 1 for key, (name, def_value, dtype, unit, xpath, description, group) in self.gui_dict.items(): # Create a LabelFrame for new groupe if group: if not group in self.group_dict: self.labelframe = tk.LabelFrame(self.tab, text=group) self.labelframe.grid(column=0, row=row_pos, columnspan=3,sticky= tk.W, padx=5, pady=5) self.group_dict[group] = self.labelframe parent = self.group_dict[group] else: # if not a group, use tab as parent parent = self.tab # Name label for variable if (name is not '__AEROMAP_SELECTION' and name is not '__AEROMAP_CHECHBOX'): self.name_label = tk.Label(parent, text= name) self.name_label.grid(column=0, row=row_pos, sticky= tk.W, padx=5, pady=5) # Type and Value if dtype is bool: self.var_dict[key] = tk.BooleanVar() value = cpsf.get_value_or_default(self.tixi,xpath,def_value) self.var_dict[key].set(value) bool_entry = tk.Checkbutton(parent, text='', variable=self.var_dict[key]) bool_entry.grid(column=1, row=row_pos, padx=5, pady=5) elif dtype is int: value = cpsf.get_value_or_default(self.tixi, xpath, def_value) self.var_dict[key] = tk.IntVar() self.var_dict[key].set(int(value)) value_entry = tk.Entry(parent, bd=2, textvariable=self.var_dict[key]) value_entry.grid(column=1, row=row_pos, padx=5, pady=5) elif dtype is float: value = cpsf.get_value_or_default(self.tixi, xpath, def_value) self.var_dict[key] = tk.DoubleVar() self.var_dict[key].set(value) value_entry = tk.Entry(parent, bd=2, textvariable=self.var_dict[key]) value_entry.grid(column=1, row=row_pos, padx=5, pady=5) elif dtype is 'pathtype': value = cpsf.get_value_or_default(self.tixi,xpath,def_value) self.var_dict[key] = tk.StringVar() self.var_dict[key].set(value) value_entry = tk.Entry(parent, textvariable=self.var_dict[key]) value_entry.grid(column=1, row=row_pos, padx=5, pady=5) self.key = key self.browse_button = tk.Button(parent, text="Browse", command=self._browse_file) self.browse_button.grid(column=2, row=row_pos, padx=5, pady=5) elif dtype is list: if name == '__AEROMAP_SELECTION': # Get the list of all AeroMaps self.aeromap_uid_list = apm.get_aeromap_uid_list(self.tixi) # Try to get the pre-selected AeroMap from the xpath try: selected_aeromap = cpsf.get_value(self.tixi,xpath) selected_aeromap_index = self.aeromap_uid_list.index(selected_aeromap) except: selected_aeromap = '' selected_aeromap_index = 0 self.labelframe = tk.LabelFrame(parent, text='Choose an AeroMap') self.labelframe.grid(column=0, row=row_pos, columnspan=3, sticky=tk.W, padx=5, pady=5) # The Combobox is directly use as the varaible self.var_dict[key] = ttk.Combobox(self.labelframe, values=self.aeromap_uid_list) self.var_dict[key].current(selected_aeromap_index) self.var_dict[key].grid(column=1, row=row_pos, padx=5, pady=5) elif name == '__AEROMAP_CHECHBOX': # Just to find back the name when data are saved self.var_dict[key] = None # __AEROMAP_CHECHBOX is a bit different, data are saved in their own dictionary self.aeromap_var_dict = {} # Get the list of all AeroMaps self.aeromap_uid_list = apm.get_aeromap_uid_list(self.tixi) self.labelframe = tk.LabelFrame(parent, text='Selecte AeroMap(s)') self.labelframe.grid(column=0, row=row_pos, columnspan=3, sticky=tk.W, padx=5, pady=5) # Try to get pre-selected AeroMaps from the xpath try: selected_aeromap = cpsf.get_string_vector(self.tixi,xpath) except: selected_aeromap = '' # Create one checkbox for each AeroMap for aeromap in self.aeromap_uid_list: self.aeromap_var_dict[aeromap] = tk.BooleanVar() #if aeromap in selected_aeromap: # For now, set all to True self.aeromap_var_dict[aeromap].set(True) aeromap_entry = tk.Checkbutton(self.labelframe,text=aeromap,variable=self.aeromap_var_dict[aeromap]) aeromap_entry.pack()#side=tk.TOP, anchor='w') else: # Other kind of list (not aeroMap) # 'def_value' will be the list of possibilies in this case # Try to get the pre-selected AeroMap from the xpath try: # TODO Should be retested... selected_value = cpsf.get_value(self.tixi,xpath) selected_value_index = def_value.index(selected_value) except: selected_value = '' selected_value_index = 0 # The Combobox is directly use as the varaible self.var_dict[key] = ttk.Combobox(parent, values=def_value) self.var_dict[key].current(selected_value_index) self.var_dict[key].grid(column=1, row=row_pos, padx=5, pady=5) else: value = cpsf.get_value_or_default(self.tixi,xpath,def_value) self.var_dict[key] = tk.StringVar() self.var_dict[key].set(value) value_entry = tk.Entry(parent, textvariable=self.var_dict[key]) value_entry.grid(column=1, row=row_pos, padx=5, pady=5) # Units if unit and unit != '1': unit_label = tk.Label(parent, text=pretty_unit(unit)) unit_label.grid(column=2, row=row_pos, padx=5, pady=5) row_pos += 1