def setUp(self): """This method is executed before all "check" methods.""" from code_saturne.Base.XMLengine import Case, XMLDocument from code_saturne.Base.XMLinitialize import XMLinit Tool.GuiParam.lang = 'en' self.case = Case(None) XMLinit(self.case).initialize() self.doc = XMLDocument()
def setUp(self): """ This method is executed before all "check" methods. """ from code_saturne.Base.XMLengine import Case from code_saturne.Base.XMLinitialize import XMLinit self.case = Case() XMLinit(self.case).initialize()
def __setCsCase__(self): """ Initialize the cs_case structure according to the user provided data """ from code_saturne.Base.XMLengine import Case from code_saturne.Base.XMLinitialize import XMLinit paramfile = self.cfg.get('study_parameters', 'xmlfile') fp = os.path.join(self.study_path, self.case_id, 'DATA', paramfile) print("=======================================") print(fp) print("=======================================") self.case = Case(package=self.pkg, file_name=fp) self.case['xmlfile'] = fp self.case.xmlCleanAllBlank(self.case.xmlRootNode()) XMLinit(self.case).initialize()
def setUp(self): """ This method is executed before all 'check' methods. """ from code_saturne.Base.XMLengine import Case from code_saturne.Base.XMLinitialize import XMLinit from code_saturne.Base.Toolbox import GuiParam GuiParam.lang = 'en' self.case = Case(None) XMLinit(self.case).initialize() domain = SolutionDomainModel(self.case) domain.addMesh('mail1.des', 'des') domain.addMesh('mail2.des', 'des') domain.addMesh('mail3.des', 'des') self.case['xmlfile'] = 'NEW.xml'
def setUp(self): """ This method is executed before all 'check' methods. """ from code_saturne.Base.XMLengine import Case from code_saturne.Base.XMLinitialize import XMLinit from code_saturne.Base.Toolbox import GuiParam GuiParam.lang = 'en' self.case = Case(None) XMLinit(self.case).initialize() self.case['batch_type'] = None self.case['scripts_path'] = os.getcwd() self.case['runcase'] = cs_runcase.runcase('runcase') lance_PBS = '# test \n'\ '#\n'\ '# CARTES BATCH POUR CLUSTERS sous PBS\n'\ '#\n'\ '#PBS -l nodes=16:ppn=1,walltime=34:77:22\n'\ '#PBS -j eo -N super_toto\n' lance_LSF = '# test \n'\ '#\n'\ '# CARTES BATCH POUR LE CCRT (Platine sous LSF)\n'\ '#\n'\ '#BSUB -n 2\n'\ '#BSUB -c 00:05\n'\ '#BSUB -o super_tataco.%J\n'\ '#BSUB -e super_tatace.%J\n'\ '#BSUB -J super_truc\n' self.f = open('lance_PBS','w') self.f.write(lance_PBS) self.f.close() self.f = open('lance_LSF','w') self.f.write(lance_LSF) self.f.close()
def __init__(self, parent, case): """ Constructor """ QWidget.__init__(self, parent) Ui_SolutionVerifForm.__init__(self) self.setupUi(self) self.parent = parent self.case = case self.case.undoStopGlobal() self.mdl = SolutionDomainModel(self.case) self.out = OutputControlModel(self.case) self.case2 = Case(package = self.case['package'], file_name = None) XMLinit(self.case2).initialize() self.case2['xmlfile'] = 'cs_cmd' self.case2['salome'] = self.case['salome'] self.node_domain = self.case.xmlGetNode('solution_domain') faces_cutting = self.node_domain.xmlGetNode('faces_cutting') joining = self.node_domain.xmlGetNode('joining') periodicity = self.node_domain.xmlGetNode('periodicity') sd_node = self.case2.xmlGetNode('solution_domain') if faces_cutting != None: if (faces_cutting)['status'] == 'on': sd_node.xmlInitNode('faces_cutting', status='on').xmlChildsCopy(faces_cutting) if joining != None: sd_node.xmlInitNode('joining').xmlChildsCopy(joining) if periodicity != None: sd_node.xmlInitNode('periodicity').xmlChildsCopy(periodicity) self.out2 = OutputControlModel(self.case2) # combo models self.modelFMTCHR = ComboModel(self.comboBoxFMTCHR, 3, 1) self.modelFormat = ComboModel(self.comboBoxFormat, 2, 1) self.modelPolygon = ComboModel(self.comboBoxPolygon, 3, 1) self.modelPolyhedra = ComboModel(self.comboBoxPolyhedra, 3, 1) self.modelFMTCHR.addItem(self.tr("EnSight Gold"), 'ensight') self.modelFMTCHR.addItem(self.tr("MED"), 'med') self.modelFMTCHR.addItem(self.tr("CGNS"), 'cgns') self.modelFMTCHR.addItem(self.tr("Catalyst"), 'catalyst') self.modelFMTCHR.addItem(self.tr("CCM-IO"), 'ccm') import cs_config cfg = cs_config.config() if cfg.libs['med'].have == "no": self.comboBoxFMTCHR.setItemData(1, QColor(Qt.red), Qt.TextColorRole); if cfg.libs['cgns'].have == "no": self.comboBoxFMTCHR.setItemData(2, QColor(Qt.red), Qt.TextColorRole); if cfg.libs['catalyst'].have == "no": self.comboBoxFMTCHR.setItemData(3, QColor(Qt.red), Qt.TextColorRole); if cfg.libs['ccm'].have == "no": self.comboBoxFMTCHR.setItemData(4, QColor(Qt.red), Qt.TextColorRole); self.modelFormat.addItem(self.tr("binary"), 'binary') self.modelFormat.addItem(self.tr("text"), 'text') self.modelPolygon.addItem(self.tr("display"), 'display') self.modelPolygon.addItem(self.tr("discard"), 'discard_polygons') self.modelPolygon.addItem(self.tr("subdivide"), 'divide_polygons') self.modelPolyhedra.addItem(self.tr("display"), 'display') self.modelPolyhedra.addItem(self.tr("discard"), 'discard_polyhedra') self.modelPolyhedra.addItem(self.tr("subdivide"), 'divide_polyhedra') # connections self.connect(self.comboBoxFMTCHR, SIGNAL("activated(const QString&)"), self.slotOutputFormat) self.connect(self.comboBoxFormat, SIGNAL("activated(const QString&)"), self.slotOutputOptions) self.connect(self.comboBoxPolygon, SIGNAL("activated(const QString&)"), self.slotOutputOptions) self.connect(self.comboBoxPolyhedra, SIGNAL("activated(const QString&)"), self.slotOutputOptions) self.connect(self.checkBoxBigEndian, SIGNAL("clicked()"), self.slotOutputOptions) self.connect(self.toolButtonBatch, SIGNAL("clicked()"), self.slotMeshChecking) # INITIALISATIONS # 1 - Values of post processing's format fmt = self.out.getWriterFormat("-1") self.modelFMTCHR.setItem(str_model=fmt) line = self.out.getWriterOptions("-1") self.__updateOptionsFormat(line) if not (self.mdl.getMeshList() or self.mdl.getMeshInput()): self.toolButtonBatch.setEnabled(False) self.case.undoStartGlobal()
class SolutionVerifView(QWidget, Ui_SolutionVerifForm): """ """ def __init__(self, parent, case): """ Constructor """ QWidget.__init__(self, parent) Ui_SolutionVerifForm.__init__(self) self.setupUi(self) self.parent = parent self.case = case self.case.undoStopGlobal() self.mdl = SolutionDomainModel(self.case) self.out = OutputControlModel(self.case) self.case2 = Case(package = self.case['package'], file_name = None) XMLinit(self.case2).initialize() self.case2['xmlfile'] = 'cs_cmd' self.case2['salome'] = self.case['salome'] self.node_domain = self.case.xmlGetNode('solution_domain') faces_cutting = self.node_domain.xmlGetNode('faces_cutting') joining = self.node_domain.xmlGetNode('joining') periodicity = self.node_domain.xmlGetNode('periodicity') sd_node = self.case2.xmlGetNode('solution_domain') if faces_cutting != None: if (faces_cutting)['status'] == 'on': sd_node.xmlInitNode('faces_cutting', status='on').xmlChildsCopy(faces_cutting) if joining != None: sd_node.xmlInitNode('joining').xmlChildsCopy(joining) if periodicity != None: sd_node.xmlInitNode('periodicity').xmlChildsCopy(periodicity) self.out2 = OutputControlModel(self.case2) # combo models self.modelFMTCHR = ComboModel(self.comboBoxFMTCHR, 3, 1) self.modelFormat = ComboModel(self.comboBoxFormat, 2, 1) self.modelPolygon = ComboModel(self.comboBoxPolygon, 3, 1) self.modelPolyhedra = ComboModel(self.comboBoxPolyhedra, 3, 1) self.modelFMTCHR.addItem(self.tr("EnSight Gold"), 'ensight') self.modelFMTCHR.addItem(self.tr("MED"), 'med') self.modelFMTCHR.addItem(self.tr("CGNS"), 'cgns') self.modelFMTCHR.addItem(self.tr("Catalyst"), 'catalyst') self.modelFMTCHR.addItem(self.tr("CCM-IO"), 'ccm') import cs_config cfg = cs_config.config() if cfg.libs['med'].have == "no": self.comboBoxFMTCHR.setItemData(1, QColor(Qt.red), Qt.TextColorRole); if cfg.libs['cgns'].have == "no": self.comboBoxFMTCHR.setItemData(2, QColor(Qt.red), Qt.TextColorRole); if cfg.libs['catalyst'].have == "no": self.comboBoxFMTCHR.setItemData(3, QColor(Qt.red), Qt.TextColorRole); if cfg.libs['ccm'].have == "no": self.comboBoxFMTCHR.setItemData(4, QColor(Qt.red), Qt.TextColorRole); self.modelFormat.addItem(self.tr("binary"), 'binary') self.modelFormat.addItem(self.tr("text"), 'text') self.modelPolygon.addItem(self.tr("display"), 'display') self.modelPolygon.addItem(self.tr("discard"), 'discard_polygons') self.modelPolygon.addItem(self.tr("subdivide"), 'divide_polygons') self.modelPolyhedra.addItem(self.tr("display"), 'display') self.modelPolyhedra.addItem(self.tr("discard"), 'discard_polyhedra') self.modelPolyhedra.addItem(self.tr("subdivide"), 'divide_polyhedra') # connections self.connect(self.comboBoxFMTCHR, SIGNAL("activated(const QString&)"), self.slotOutputFormat) self.connect(self.comboBoxFormat, SIGNAL("activated(const QString&)"), self.slotOutputOptions) self.connect(self.comboBoxPolygon, SIGNAL("activated(const QString&)"), self.slotOutputOptions) self.connect(self.comboBoxPolyhedra, SIGNAL("activated(const QString&)"), self.slotOutputOptions) self.connect(self.checkBoxBigEndian, SIGNAL("clicked()"), self.slotOutputOptions) self.connect(self.toolButtonBatch, SIGNAL("clicked()"), self.slotMeshChecking) # INITIALISATIONS # 1 - Values of post processing's format fmt = self.out.getWriterFormat("-1") self.modelFMTCHR.setItem(str_model=fmt) line = self.out.getWriterOptions("-1") self.__updateOptionsFormat(line) if not (self.mdl.getMeshList() or self.mdl.getMeshInput()): self.toolButtonBatch.setEnabled(False) self.case.undoStartGlobal() @pyqtSignature("const QString &") def slotOutputFormat(self, text): """ Input format of post-processing """ format = self.modelFMTCHR.dicoV2M[str(text)] if self.out.getWriterFormat("-1") != format: self.out.setWriterFormat("-1",format) l = self.out.defaultWriterValues()['options'] self.out.setWriterOptions("-1",l) if self.out2.getWriterFormat("-1") != format: self.out2.setWriterFormat("-1",format) l = self.out2.defaultWriterValues()['options'] self.out2.setWriterOptions("-1",l) self.__updateOptionsFormat(l) @pyqtSignature("") def slotOutputOptions(self): """ Create format's command line options """ line = [] opt_format = self.modelFormat.dicoV2M[str(self.comboBoxFormat.currentText())] line.append(opt_format) if self.checkBoxBigEndian.isChecked(): line.append('big_endian') opt_polygon = self.modelPolygon.dicoV2M[str(self.comboBoxPolygon.currentText())] opt_polyhed = self.modelPolyhedra.dicoV2M[str(self.comboBoxPolyhedra.currentText())] if opt_polygon != 'display': line.append(opt_polygon) if opt_polyhed != 'display': line.append(opt_polyhed) l = string.join(line, ',') log.debug("slotOutputOptions-> OPTCHR = %s" % l) self.out.setWriterOptions("-1",l) self.out2.setWriterOptions("-1",l) def __updateOptionsFormat(self, line): """ Update command-line options at each modification of post processing format """ lst = line.split(',') format = self.modelFMTCHR.dicoV2M[str(self.comboBoxFMTCHR.currentText())] log.debug("__updateOptionsFormat-> FMTCHR = %s" % format) log.debug("__updateOptionsFormat-> OPTCHR = %s" % line) # update widgets from the options list for opt in lst: if opt == 'binary' or opt == 'text' : self.modelFormat.setItem(str_model=opt) if opt == 'discard_polygons' or opt == 'divide_polygons': self.modelPolygon.setItem(str_model=opt) if opt == 'discard_polyhedra' or opt == 'divide_polyhedra': self.modelPolyhedra.setItem(str_model=opt) if format == 'ensight': if opt == 'big_endian': self.checkBoxBigEndian.setChecked(True) if 'discard_polygons' not in lst and 'divide_polygons' not in lst: self.modelPolygon.setItem(str_model="display") if 'discard_polyhedra' not in lst and 'divide_polyhedra' not in lst: self.modelPolyhedra.setItem(str_model="display") if 'big_endian' not in lst: self.checkBoxBigEndian.setChecked(False) # enable and disable options related to the format self.modelPolygon.enableItem(str_model='discard_polygons') self.modelPolygon.enableItem(str_model='divide_polygons') self.modelPolyhedra.enableItem(str_model='discard_polyhedra') self.modelPolyhedra.enableItem(str_model='divide_polyhedra') self.comboBoxPolygon.setEnabled(True) self.comboBoxPolyhedra.setEnabled(True) if format != "ensight": if format == "cgns": self.modelPolyhedra.setItem(str_model='divide_polyhedra') self.modelPolyhedra.disableItem(str_model='display') elif format in ["catalyst", "ccm"]: self.modelPolyhedra.setItem(str_model='display') self.modelPolygon.setItem(str_model='display') self.comboBoxPolygon.setEnabled(False) self.comboBoxPolyhedra.setEnabled(False) self.modelFormat.setItem(str_model="binary") self.modelFormat.disableItem(str_model='text') self.labelBigEndian.setEnabled(False) self.checkBoxBigEndian.setEnabled(False) else: self.modelFormat.enableItem(str_model='text') self.comboBoxFormat.setEnabled(True) self.labelBigEndian.setEnabled(True) self.checkBoxBigEndian.setEnabled(True) def __setButtonEnabled(self): """ Block the QButton during the display of the dialog. """ try: self.toolButtonBatch.setEnabled(not self.toolButtonBatch.isEnabled()) except: pass def slotMeshChecking(self): """ """ self.__setButtonEnabled() dialog = MeshQualityCriteriaLogDialogView(self.parent, self.case, self.case2) dialog.show() self.connect(dialog, SIGNAL("accepted()"), self.__setButtonEnabled) self.connect(dialog, SIGNAL("rejected()"), self.__setButtonEnabled) def tr(self, text): """ Translation """ return text
class cfd_openturns_study: """ Class used for an OpenTurns study within SALOME_CFD Public methods: - init - run - study2code - code2study """ # ------------------------------------------------------------------------------ # PUBLIC FUNCTIONS # ------------------------------------------------------------------------------ # --------------------------------------- def __init__(self, study_path, study_cfg, vars_dico): ''' Classs constructor ''' # -------------------------- # Init from user values self.study_path = study_path self.cfg_name = study_cfg cfg_path = os.path.join(study_path, study_cfg) self.cfg_path = cfg_path print("-----------------------------------") print(cfg_path) print("-----------------------------------") self.cfg = configparser.ConfigParser() self.cfg.read(cfg_path) self.vars_dico = vars_dico self.cs_launcher = None self.ref_case = self.cfg.get('study_parameters', 'ref_case') if self.cfg.get('host_parameters', 'host_name') == 'localhost': self.run_type = 'local' else: self.run_type = 'distant' # -------------------------- self.__setPackage__() self.__setCaseId__() # --------------------------------------- # --------------------------------------- def load_launcher(self, case_dir): new_launcher = None if self.run_type == 'local': from CFDSTUDYOTURNS_LocalLauncher import cfd_openturns_local_launcher new_launcher = cfd_openturns_local_launcher(case_dir = case_dir, params_cfg = self.cfg, package = self.pkg) elif self.run_type == 'distant': from CFDSTUDYOTURNS_DistantLauncher import CFDSTUDY_DistantLauncher new_launcher = CFDSTUDY_DistantLauncher(case_dir = case_dir, params_cfg = self.cfg, package = self.pkg) self.cs_launcher = new_launcher # --------------------------------------- # --------------------------------------- def study2code(self): ''' A function which takes into account the variables values given by OpenTurns and creating a Code_Saturne case thanks to it. ''' from glob import glob case_dir = os.path.join(self.study_path, self.case_id) if os.path.isdir(case_dir): # Check if the case directory allready exists. # if it exists, check if a case has allready been run case_resu_dir = os.path.join(case_dir, "RESU") dirs = filter(os.path.isdir, glob(case_resu_dir + "/*")) self.__setCsCase__() self.case['case_path'] = case_dir self.load_launcher(case_dir) if self.run_type == 'distant' and len(dirs) > 0: dirs.sort(key=lambda x: os.path.getmtime(x)) resu_dir = dirs[-1] self.cs_launcher.run_id = os.path.split(resu_dir)[-1] self.cs_launcher.reload_job(resu_dir) else: self.__createCase__() self.load_launcher(case_dir) # --------------------------------------- # --------------------------------------- def run(self): ''' This method launches a Code_Saturne computation based on the values provided by OpenTurns ''' self.cs_launcher.launch(force_submit=False) if self.run_type == 'distant': while True: if self.cs_launcher.need_restart(): old_run = self.cs_launcher.run_id rst_dir = os.path.join(self.study_path, self.case_id, 'RESU', old_run) self.__setRestartPath__(rst_dir) self.cs_launcher.__setRunId__() self.cs_launcher.launch(force_submit=True) if self.cs_launcher.job_failed: break else: break self.cs_launcher.sync_results() # --------------------------------------- # --------------------------------------- def code2study(self): """ Opens the results file specified by the user. Returns a tuple of all the required values (needed by OpenTurns) """ resfile = self.cfg.get('study_parameters', 'results_file') rspth = os.path.join(self.study_path, self.case_id, 'RESU', self.cs_launcher.run_id, resfile) r = open(rspth, 'r').readlines() d = r[-1].split() if len(d) > 1: results = () for ed in d: results += (float(ed),) else: results = float(d[0]) return results; # --------------------------------------- # ------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------ # INTERNAL UTILITY FUNCTIONS # ------------------------------------------------------------------------------ # --------------------------------------- def __setCaseId__(self): """ Setting the case id based on the variables names and values """ self.case_id = '' items = [] for key in self.vars_dico.keys(): items.append(str(key[:4])+'_'+str(self.vars_dico[key])) self.case_id = "_".join(items) # --------------------------------------- # --------------------------------------- def __setPackage__(self): """ Setting the package according to the requested code by the user """ pkg_name = self.cfg.get('study_parameters', 'code_name') if pkg_name == 'code_saturne': from code_saturne.cs_package import package elif pkg_name == 'neptune_cfd': from neptune_cfd.nc_package import package else: raise Exception("Uknown package: "+pkg_name) self.pkg = package() # --------------------------------------- # --------------------------------------- def __createCase__(self): """ Creating the case for a given evaluation based on the user defined reference case """ from code_saturne.Pages.NotebookModel import NotebookModel # Creating the case from the ref case from code_saturne.cs_script import master_script case_create_args = ['create', '-c', os.path.join(self.study_path, self.case_id), '--copy-from', os.path.join(self.study_path, self.ref_case) ] ms = master_script(case_create_args, self.pkg) retcode = ms.execute() self.__setCsCase__() self.__setOtVarsVals__() # --------------------------------------- # --------------------------------------- def __setCsCase__(self): """ Initialize the cs_case structure according to the user provided data """ from code_saturne.Base.XMLengine import Case from code_saturne.Base.XMLinitialize import XMLinit paramfile = self.cfg.get('study_parameters', 'xmlfile') fp = os.path.join(self.study_path, self.case_id, 'DATA', paramfile) print("=======================================") print(fp) print("=======================================") self.case = Case(package=self.pkg, file_name=fp) self.case['xmlfile'] = fp self.case.xmlCleanAllBlank(self.case.xmlRootNode()) XMLinit(self.case).initialize() # --------------------------------------- # --------------------------------------- def __setOtVarsVals__(self): """ This method translates the values provided by OpenTURNS into the code xml input file """ # Update xml file from code_saturne.Pages.NotebookModel import NotebookModel nb = NotebookModel(self.case) nb_ids = nb.getVarList() nb_names = nb.getVarNameList() for key in self.vars_dico.keys(): try: ix = nb_names.index(key) except: ix = -1 if ix != -1: idx = nb_ids[ix] nb.setVariableValue(idx=idx, val=str(self.vars_dico[key])) self.case.xmlSaveDocument() # --------------------------------------- # --------------------------------------- def __setRestartPath__(self, restart_path): """ This method sets the restart path in the code xml input file """ from code_saturne.Pages.StartRestartModel import StartRestartModel rs = StartRestartModel(self.case) rp = os.path.join(restart_path, 'checkpoint') rs.setRestartPath(rp) rs.setRestartWithAuxiliaryStatus('on') self.case.xmlSaveDocument()