def get_sm_vars(tixi): """Retrieves variable in the case of a surrogate. In the case of a surrogate model being used, the entries are retrieved from the dataframe that is saved in the SM file. Args: tixi (Tixi3 handler): Tixi handle of the CPACS file. """ Model = load_surrogate(tixi) df = Model.df.rename(columns={"Unnamed: 0": "Name"}) df.set_index("Name", inplace=True) for name in df.index: name = change_var_name(name) if name not in var["Name"] and df.loc[name]["setcmd"] == "-": var["Name"].append(name) var["type"].append(df.loc[name]["type"]) xpath = df.loc[name]["getcmd"] var["xpath"].append(xpath) value = str(tixi.getDoubleElement(xpath)) var["init"].append(value) add_bounds(value, var) else: log.warning("Variable already exists") log.info(name + " will not be added to the variable file")
def get_sm_vars(tixi): """Retrieves variable in the case of a surrogate. In the case of a surrogate model being used, the entries are retrieved from the dataframe that is saved in the SM file. Args: tixi (Tixi3 handler): Tixi handle of the CPACS file. """ Model = smu.load_surrogate(tixi) df = Model.df.rename(columns={'Unnamed: 0':'Name'}) df.set_index('Name', inplace=True) for name in df.index: name = tls.change_var_name(name) if name not in var['Name'] and df.loc[name]['setcmd'] == '-': var['Name'].append(name) var['type'].append(df.loc[name]['type']) xpath = df.loc[name]['getcmd'] var['xpath'].append(xpath) value = str(tixi.getDoubleElement(xpath)) var['init'].append(value) tls.add_bounds(value, var) else: log.warning('Variable already exists') log.info(name+' will not be added to the variable file')
def setup(self): """Setup inputs and outputs""" module = [m for m in Rt.modules if m.name == self.module_name][0] # Take CPACS file from the optimisation cpacs_path = str(module.cpacs_in) tixi = open_tixi(cpacs_path) self.Model = load_surrogate(tixi) tixi.save(cpacs_path) df = self.Model.df df.set_index("Name", inplace=True) for name in df.index: if df.loc[name, "type"] == "obj": self.add_output(name) elif df.loc[name, "type"] == "des": self.add_input(name) self.xd = df.loc[[name for name in df.index if df.loc[name, "type"] == "des"]] self.yd = df.loc[[name for name in df.index if df.loc[name, "type"] == "obj"]]
def setup(self): """Setup inputs and outputs""" # Take CPACS file from the optimisation cpacs_path = mif.get_toolinput_file_path('SMUse') tixi = cpsf.open_tixi(cpacs_path) self.Model = smu.load_surrogate(tixi) cpsf.close_tixi(tixi, cpacs_path) df = self.Model.df df.set_index('Name', inplace=True) for name in df.index: if df.loc[name, 'type'] == 'obj': self.add_output(name) elif df.loc[name, 'type'] == 'des': self.add_input(name) self.xd = df.loc[[ name for name in df.index if df.loc[name, 'type'] == 'des' ]] self.yd = df.loc[[ name for name in df.index if df.loc[name, 'type'] == 'obj' ]]