def testBoundaryWrite(self): bnd=BoundaryDict(self.dest) test1={"type":"wall" , "nFaces":0,"startFace":666} bnd["testIt"]=test1 self.assertEqual(len(bnd.patches()),6) bnd["leftWall"]=test1 self.assertEqual(len(bnd.patches()),6) test2={"type":"wall" , "Faces":0,"startFace":666} try: bnd["nix"]=test2 self.fail() except PyFoamException: pass
def testBoundaryWrite(self): bnd = BoundaryDict(self.dest) test1 = {"type": "wall", "nFaces": 0, "startFace": 666} bnd["testIt"] = test1 self.assertEqual(len(bnd.patches()), 6) bnd["leftWall"] = test1 self.assertEqual(len(bnd.patches()), 6) test2 = {"type": "wall", "Faces": 0, "startFace": 666} try: bnd["nix"] = test2 self.fail() except PyFoamException: pass
def loadCaseData(self): filename = '%s/system/controlDict' % self.currentFolder backupFile(filename) self.parsedData = ParsedParameterFile(filename, createZipped=False) self.tracersData = [] if 'functions' in self.parsedData.getValueDict().keys(): for key in self.parsedData['functions'].keys(): if self.parsedData['functions'][key][ 'type'] == 'scalarTransport': tracer = {} tracer['name'] = key tracer['patchName'] = self.parsedData['functions'][key][ 'patchName'] tracer['startTime'] = self.parsedData['functions'][key][ 'fvOptions']['S']['timeStart'] #TODO: cargar aca if tracer['patchName'] == 'box': tracer['p0'] = self.parsedData['functions'][key][ 'fvOptions']['S']['p0'] tracer['p1'] = self.parsedData['functions'][key][ 'fvOptions']['S']['p1'] self.tracersData.append(tracer) if self.patches == []: boundaries = BoundaryDict(str(self.currentFolder)) self.patches = boundaries.patches() for ipatch in self.patches: if boundaries[ipatch]['type'] == 'empty': self.emptys.append(ipatch) self.pushButton_3.setEnabled(True)
def loadCaseData(self): filename = '%s/system/controlDict'%self.currentFolder backupFile(filename) self.parsedData = ParsedParameterFile(filename,createZipped=False) self.tracersData = [] if 'functions' in self.parsedData.getValueDict().keys(): for key in self.parsedData['functions'].keys(): if self.parsedData['functions'][key]['type'] == 'scalarTransport': tracer = {} tracer['name'] = key tracer['patchName'] = self.parsedData['functions'][key]['patchName'] tracer['startTime'] = self.parsedData['functions'][key]['fvOptions']['S']['timeStart'] #TODO: cargar aca if tracer['patchName']=='box': tracer['p0'] = self.parsedData['functions'][key]['fvOptions']['S']['p0'] tracer['p1'] = self.parsedData['functions'][key]['fvOptions']['S']['p1'] self.tracersData.append(tracer) if self.patches==[]: boundaries = BoundaryDict(str(self.currentFolder)) self.patches = boundaries.patches() for ipatch in self.patches: if boundaries[ipatch]['type']=='empty': self.emptys.append(ipatch) self.pushButton_3.setEnabled(True)
from PyFoam.RunDictionary.BoundaryDict import BoundaryDict from PyFoam.RunDictionary.MeshInformation import MeshInformation from PyFoam.ThirdParty.six import print_ parse = FoamOptionParser(description=description, usage="%prog <caseDirectory> <boundaryName>") parse.parse(nr=2) fName = parse.getArgs()[0] bName = parse.getArgs()[1] boundary = BoundaryDict(fName) lastFace = MeshInformation(fName).nrOfFaces() if bName in boundary.patches(): print_("Patch", bName, "already exists in file") sys.exit(-1) val = {} val["type"] = "wall" val["nFaces"] = "0" val["startFace"] = str(lastFace) boundary[bName] = val boundary.writeFile() # Should work with Python3 and Python2
def testBoundaryRead(self): bnd = BoundaryDict(self.dest) self.assertEqual(bnd["leftWall"]["type"], "wall") self.assertEqual(bnd["leftWall"]["nFaces"], 50) self.assertEqual(len(bnd.patches()), 5) self.assertEqual(len(bnd.patches(patchType="wall")), 3)
class postproWidget(postproUI): def __init__(self,currentFolder): postproUI.__init__(self) def setCurrentFolder(self, currentFolder): self.currentFolder = currentFolder #filling data [timedir,self.fields,currtime] = currentFields(str(self.currentFolder)) self.field_3.clear() self.field_3.addItems(self.fields) self.boundaries = BoundaryDict(str(self.currentFolder)) self.bou_3.clear() self.bou_3.addItems(self.boundaries.patches()) def openParaview(self): os.system('paraFoam -builtin -case %s &'%self.currentFolder) def exportData(self): opt = str(self.comboBox.currentText()) filename = '%s/export.log'%self.currentFolder self.window().newLogTab('Export',filename) if opt=='VTK': action = 'foamToVTK -case %s > %s &' %(self.currentFolder,filename) elif opt=='Fluent': action = 'foamMeshToFluent -case %s &' %(self.currentFolder) os.system(action) 'cp caseDicts/foamDataToFluentDict %s/system/foamDataToFluentDict'%self.currentFolder os.system(action) parsedData = ParsedParameterFile('%s/system/foamDataToFluentDict'%self.currentFolder,createZipped=False) ii = 10 for ifield in self.fields: if ifield not in parsedData.getValueDict().keys(): parsedData[ifield] = ii ii = ii + 1 action = 'foamDataToFluent -case %s > %s &' %(self.currentFolder,filename) elif opt=='Ensight': action = 'foamToEnsight -case %s > %s &' %(self.currentFolder,filename) os.system(action) return def calculate1(self): tt = '' if self.time_1.currentText()=='Latest Time': tt = '-latestTime' filename = '%s/field_calculation.log'%self.currentFolder self.window().newLogTab('Postpro Field',filename) action = '%s -case %s %s > %s'%(apps[str(self.field_1.currentText())],self.currentFolder, tt, filename) os.system(action) return def calculate2(self): tt = '' if self.time_2.currentText()=='Latest Time': tt = '-latestTime' filename = '%s/walls_calculation.log'%self.currentFolder if self.field_2.currentText()=='y Plus RAS': if not os.path.isfile('%s/constant/RASProperties'%self.currentFolder): QtGui.QMessageBox(QtGui.QMessageBox.Information, "Caution", "Action can not be done!").exec_() return if self.field_2.currentText()=='y Plus LES': if not os.path.isfile('%s/constant/LESProperties'%self.currentFolder): QtGui.QMessageBox(QtGui.QMessageBox.Information, "Caution", "Action can not be done!").exec_() return self.window().newLogTab('Postpro Wall',filename) action = '%s -case %s %s > %s'%(apps[str(self.field_2.currentText())],self.currentFolder, tt, filename) os.system(action) return def calculate3(self): tt = '' if self.time_3.currentText()=='Latest Time': tt = '-latestTime' filename = '%s/patch_calculation.log'%self.currentFolder self.window().newLogTab('Postpro Patch',filename) fieldName = str(self.field_3.currentText()) patchName = str(self.bou_3.currentText()) action = '%s -case %s %s %s %s > %s &' %(apps[str(self.type_3.currentText())],self.currentFolder,tt,fieldName,patchName,filename) os.system(action) return
polyMesh/boundaries file """ from PyFoam.Basics.FoamOptionParser import FoamOptionParser from os import path import sys from PyFoam.RunDictionary.BoundaryDict import BoundaryDict from PyFoam.RunDictionary.MeshInformation import MeshInformation parse=FoamOptionParser(description=description,usage="%prog <caseDirectory>") parse.parse(nr=1) fName=parse.getArgs()[0] boundary=BoundaryDict(fName) cleared=[] for b in boundary.patches(): if boundary[b]["nFaces"]==0: cleared.append(b) del boundary[b] if len(cleared)>0: print "Cleared boundaries",", ".join(cleared) boundary.writeFile() else: print "No empty boundaries"
def testBoundaryRead(self): bnd=BoundaryDict(self.dest) self.assertEqual(bnd["walls"]["type"],"wall") self.assertEqual(bnd["walls"]["nFaces"],78) self.assertEqual(len(bnd.patches()),4) self.assertEqual(len(bnd.patches(patchType="patch")),2)
def testBoundaryRead(self): bnd = BoundaryDict(self.dest) self.assertEqual(bnd["walls"]["type"], "wall") self.assertEqual(bnd["walls"]["nFaces"], 78) self.assertEqual(len(bnd.patches()), 4) self.assertEqual(len(bnd.patches(patchType="patch")), 2)
def testBoundaryRead(self): bnd=BoundaryDict(self.dest) self.assertEqual(bnd["leftWall"]["type"],"wall") self.assertEqual(bnd["leftWall"]["nFaces"],50) self.assertEqual(len(bnd.patches()),5) self.assertEqual(len(bnd.patches(patchType="wall")),3)
class bcWidget(bcUI): def __init__(self, folder, nproc): self.currentFolder = folder bcUI.__init__(self) self.icones = {} self.icones['wall'] = QtGui.QIcon() self.icones['wall'].addPixmap( QtGui.QPixmap( _fromUtf8(":/newPrefix/images/fromHelyx/wall16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['empty'] = QtGui.QIcon() self.icones['empty'].addPixmap( QtGui.QPixmap( _fromUtf8(":/newPrefix/images/fromHelyx/empty16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['patch'] = QtGui.QIcon() self.icones['patch'].addPixmap( QtGui.QPixmap( _fromUtf8(":/newPrefix/images/fromHelyx/patch16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['cyclic'] = QtGui.QIcon() self.icones['cyclic'].addPixmap( QtGui.QPixmap( _fromUtf8(":/newPrefix/images/fromHelyx/cyclic16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['cyclicAMI'] = QtGui.QIcon() self.icones['cyclicAMI'].addPixmap( QtGui.QPixmap( _fromUtf8(":/newPrefix/images/fromHelyx/cyclicAMI16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['wedge'] = QtGui.QIcon() self.icones['wedge'].addPixmap( QtGui.QPixmap( _fromUtf8(":/newPrefix/images/fromHelyx/wedge16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['symmetry'] = QtGui.QIcon() self.icones['symmetry'].addPixmap( QtGui.QPixmap( _fromUtf8(":/newPrefix/images/fromHelyx/symmetry16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.boundaries = BoundaryDict(str(self.currentFolder)) self.nproc = nproc #veo los campos que tengo en el directorio inicial [self.timedir, self.fields, self.currtime] = currentFields(self.currentFolder, nproc=self.nproc) #print self.fields self.loadData() self.comboBox.setEnabled(False) def loadData(self): self.listWidget.clear() for ipatch in self.boundaries.patches(): Item = QtGui.QListWidgetItem() Item.setIcon(self.icones[self.boundaries[ipatch]['type']]) Item.setText(_translate("bcWidget", ipatch, None)) self.listWidget.addItem(Item) self.pushButton.setEnabled(False) self.addTabs() def changeSelection(self): ipatch = str(self.listWidget.currentItem().text()) self.comboBox.clear() self.comboBox.addItems(prototypes[self.boundaries[ipatch]['type']]) self.addTabs(ipatch) return def addTabs(self, ipatch=None): for itab in range(self.tabWidget.count()): layout = self.tabWidget.widget(itab).findChildren( QtGui.QVBoxLayout)[0] self.clearLayout(layout, 0) self.tabWidget.clear() fileDict = '%s/system/changeDictionaryPetroSym' % self.currentFolder dictDict = [] if os.path.isfile(fileDict): dictDict = ParsedParameterFile(fileDict, createZipped=False) for ifield in self.fields: if ifield not in unknowns: continue widget = QtGui.QWidget() layout = QtGui.QVBoxLayout(widget) if ipatch: if dictDict == []: filename = '%s/%s' % (self.timedir, ifield) parsedData = ParsedParameterFile(filename, listLengthUnparsed=20, createZipped=False) thisPatch = parsedData['boundaryField'][ipatch] else: thisPatch = dictDict['dictionaryReplacement'][ifield][ 'boundaryField'][ipatch] newComboBox = QtGui.QComboBox() newComboBox.addItems( types[self.boundaries[ipatch]['type']][ifield]) #aca hay que llamar a este evento solo si se cambia index = newComboBox.findText(thisPatch['type']) newComboBox.setCurrentIndex(index) if index != -1 else None layout.addWidget(newComboBox) extraInfo = extras[ifield][thisPatch['type']] self.addExtraInfo(layout, extraInfo) QtCore.QObject.connect( newComboBox, QtCore.SIGNAL(_fromUtf8("currentIndexChanged(int)")), self.onChangeComboType) #cargo los datos desde el diccionario L = range(layout.count()) L = L[1:-1] iExtra = 0 for l in L: layout2 = layout.itemAt(l).layout() if layout2: if layout2.itemAt(1).widget().currentText() != 'table': data = str(thisPatch[extraInfo[iExtra * 4]]) data = data.replace('(', '').replace( ')', '').replace('[', '').replace(']', '').replace( ',', '').replace('\'', '').split() if layout2.count() == 3: layout2.itemAt(1).widget().setCurrentIndex( layout2.itemAt(1).widget().findText( data[0])) layout2.itemAt(2).widget().setText(data[1]) else: layout2.itemAt(1).widget().setCurrentIndex( layout2.itemAt(1).widget().findText( data[0])) layout2.itemAt(2).widget().setText(data[1]) layout2.itemAt(3).widget().setText(data[2]) layout2.itemAt(4).widget().setText(data[3]) else: None #determinar que hacer si quiero cargar una table!!! #('table', [[0, 0.0], [1e6-0.01, 0.0], [1e6, 1.0], [1e6, 1.0]]) #tabla = self.getTabla(itab) #parsedData['boundaryField'][ipatch][extraInfo[iExtra*4]] = ('table',tabla) iExtra = iExtra + 1 spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) layout.addItem(spacerItem) self.tabWidget.addTab(widget, ifield) self.tabWidget.setTabText(self.tabWidget.count(), ifield) def onChangeComboType(self): ii = self.tabWidget.currentIndex() ifield = str(self.tabWidget.tabText(ii)) widget = self.tabWidget.currentWidget() if widget: itype = str(widget.findChildren(QtGui.QComboBox)[0].currentText()) layout = widget.findChildren(QtGui.QVBoxLayout)[0] self.clearLayout(layout, 1) self.addExtraInfo(layout, extras[ifield][itype]) self.checkData() def onEditValue(self): return def clearLayout(self, layout, dejar): for i in reversed(range(layout.count())): if i >= dejar: item = layout.itemAt(i) if isinstance(item, QtGui.QWidgetItem): item.widget().close() item.widget().deleteLater() # or # item.widget().setParent(None) elif isinstance(item, QtGui.QSpacerItem): None # no need to do extra stuff else: self.clearLayout(item.layout(), 0) # remove the item from layout layout.removeItem(item) def addExtraInfo(self, layout, extraInfo): if extraInfo != []: for i in range(len(extraInfo) / 4): layout2 = QtGui.QHBoxLayout() label = QtGui.QLabel() label.setText('%s %s' % (extraInfo[i * 4], extraInfo[i * 4 + 1])) layout2.addWidget(label) if extraInfo[i * 4 + 2]: cb = QtGui.QComboBox() cb.addItems(extraInfo[i * 4 + 2]) layout2.addWidget(cb) for j in range(extraInfo[i * 4 + 3]): ledit = QtGui.QLineEdit() ledit.setValidator(QtGui.QDoubleValidator()) layout2.addWidget(ledit) QtCore.QObject.connect( ledit, QtCore.SIGNAL(_fromUtf8("textEdited(QString)")), self.checkData) layout.addLayout(layout2) spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) layout.addItem(spacerItem) def changePrototype(self): return def saveBCs(self): ipatch = str(self.listWidget.currentItem().text()) fileDict = '%s/system/changeDictionaryPetroSym' % self.currentFolder dictDict = [] if os.path.isfile(fileDict): dictDict = ParsedParameterFile(fileDict, createZipped=False) for itab in range(self.tabWidget.count()): ifield = str(self.tabWidget.tabText(itab)) itype = str( self.tabWidget.widget(itab).findChildren( QtGui.QComboBox)[0].currentText()) layout = self.tabWidget.widget(itab).findChildren( QtGui.QVBoxLayout)[0] if dictDict == []: filename = '%s/%s' % (self.timedir, ifield) parsedData = ParsedParameterFile(filename, listLengthUnparsed=20, createZipped=False) thisPatch = parsedData['boundaryField'][ipatch] else: thisPatch = dictDict['dictionaryReplacement'][ifield][ 'boundaryField'][ipatch] thisPatch = {} thisPatch['type'] = itype if itype == 'zeroGradient': thisPatch['ZZvalue'] = '0' #debo tomar los valores extras, si los tiene extraInfo = extras[ifield][itype] L = range(layout.count()) L = L[1:-1] iExtra = 0 #print ipatch for l in L: layout2 = layout.itemAt(l).layout() if layout2: if layout2.itemAt(1).widget().currentText() != 'table': if layout2.count() == 3: thisPatch[extraInfo[iExtra * 4]] = '%s %s' % ( layout2.itemAt(1).widget().currentText(), layout2.itemAt(2).widget().text()) else: thisPatch[extraInfo[ iExtra * 4]] = '%s (%s %s %s)' % ( layout2.itemAt(1).widget().currentText(), layout2.itemAt(2).widget().text(), layout2.itemAt(3).widget().text(), layout2.itemAt(4).widget().text()) else: #determinar que hacer si quiero cargar una table!!! #('table', [[0, 0.0], [1e6-0.01, 0.0], [1e6, 1.0], [1e6, 1.0]]) tabla = self.getTabla(itab) thisPatch[extraInfo[iExtra * 4]] = ('table', tabla) iExtra = iExtra + 1 if dictDict == []: parsedData['boundaryField'][ipatch] = thisPatch parsedData.writeFile() else: dictDict['dictionaryReplacement'][ifield]['boundaryField'][ ipatch] = thisPatch dictDict.writeFile() dictDictBak = ParsedParameterFile(fileDict, createZipped=False) keysDict = dictDict['dictionaryReplacement'].keys() dictDictBak['dictionaryReplacement'] = {} for ikey in keysDict: if ikey in self.fields: dictDictBak['dictionaryReplacement'][ikey] = {} dictDictBak['dictionaryReplacement'][ikey][ 'boundaryField'] = dictDict[ 'dictionaryReplacement'][ikey]['boundaryField'] dictDictBak.writeFileAs( '%s/system/changeDictionaryPetroSym.bak' % self.currentFolder) command = 'sed -i "s/ZZ/~/g" %s/system/changeDictionaryPetroSym.bak' % ( self.currentFolder) os.system(command) #chequear que no bloquee if self.nproc <= 1: command = 'changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak 1> %s/changeDictionary.log 2> %s/error.log &' % ( self.currentFolder, self.currentFolder, self.currentFolder, self.currentFolder) else: command = 'mpirun -np %s changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak -parallel 1> %s/changeDictionary.log 2> %s/error.log &' % ( str(self.nproc), self.currentFolder, self.currentFolder, self.currentFolder, self.currentFolder) os.system(command) self.pushButton.setEnabled(False) return def getTable(self, itab): table = [[0, 0], [1, 0]] return table def checkData(self): ready = True for itab in range(self.tabWidget.count()): edits = self.tabWidget.widget(itab).findChildren(QtGui.QLineEdit) for E in edits: if E.isEnabled(): if not E.text(): ready = False if ready: self.pushButton.setEnabled(True) else: self.pushButton.setEnabled(False) def changePatchType(self, item): texto = str(item.text()) w = bcPatch(self.boundaries[texto]['type']) result = w.exec_() if result: patchType = w.getPatchType() self.boundaries[texto]['type'] = patchType self.boundaries.writeFile() fileDict = '%s/system/changeDictionaryPetroSym' % self.currentFolder dictDict = [] if os.path.isfile(fileDict): dictDict = ParsedParameterFile(fileDict, createZipped=False) for ifield in self.fields: if dictDict == []: filename = '%s/%s' % (self.timedir, ifield) fieldData = ParsedParameterFile(filename, listLengthUnparsed=20, createZipped=False) else: fieldData = dictDict['dictionaryReplacement'][ifield] newDict = {} if patchType == 'empty': newDict['type'] = 'empty' newDict['ZZvalue'] = '0' else: if ifield in unknowns: newDict['type'] = 'zeroGradient' newDict['ZZvalue'] = '0' else: newDict['type'] = 'calculated' newDict['ZZvalue'] = '0' fieldData['boundaryField'][texto] = newDict if dictDict == []: fieldData.writeFile() else: dictDict['dictionaryReplacement'][ifield] = fieldData if dictDict != []: dictDict.writeFile() dictDictBak = ParsedParameterFile(fileDict, createZipped=False) keysDict = dictDict['dictionaryReplacement'].keys() dictDictBak['dictionaryReplacement'] = {} for ikey in keysDict: if ikey in self.fields: dictDictBak['dictionaryReplacement'][ikey] = {} dictDictBak['dictionaryReplacement'][ikey][ 'boundaryField'] = dictDict[ 'dictionaryReplacement'][ikey]['boundaryField'] dictDictBak.writeFileAs( '%s/system/changeDictionaryPetroSym.bak' % self.currentFolder) command = 'sed -i "s/ZZ/~/g" %s/system/changeDictionaryPetroSym.bak' % ( self.currentFolder) os.system(command) #chequear que no bloquee if self.nproc <= 1: command = 'changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak 1> %s/changeDictionary.log 2> %s/error.log &' % ( self.currentFolder, self.currentFolder, self.currentFolder, self.currentFolder) else: command = 'mpirun -np %s changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak -parallel 1> %s/changeDictionary.log 2> %s/error.log &' % ( str(self.nproc), self.currentFolder, self.currentFolder, self.currentFolder, self.currentFolder) os.system(command) self.loadData()
class bcWidget(bcUI): def __init__(self,folder,nproc): self.currentFolder = folder bcUI.__init__(self) self.icones = {} self.icones['wall'] = QtGui.QIcon() self.icones['wall'].addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/fromHelyx/wall16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['empty'] = QtGui.QIcon() self.icones['empty'].addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/fromHelyx/empty16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['patch'] = QtGui.QIcon() self.icones['patch'].addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/fromHelyx/patch16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['cyclic'] = QtGui.QIcon() self.icones['cyclic'].addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/fromHelyx/cyclic16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['cyclicAMI'] = QtGui.QIcon() self.icones['cyclicAMI'].addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/fromHelyx/cyclicAMI16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['wedge'] = QtGui.QIcon() self.icones['wedge'].addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/fromHelyx/wedge16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.icones['symmetry'] = QtGui.QIcon() self.icones['symmetry'].addPixmap(QtGui.QPixmap(_fromUtf8(":/newPrefix/images/fromHelyx/symmetry16.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.boundaries = BoundaryDict(str(self.currentFolder)) self.nproc = nproc #veo los campos que tengo en el directorio inicial [self.timedir,self.fields,self.currtime] = currentFields(self.currentFolder,nproc=self.nproc) #print self.fields self.loadData() self.comboBox.setEnabled(False) def loadData(self): self.listWidget.clear() for ipatch in self.boundaries.patches(): Item = QtGui.QListWidgetItem() Item.setIcon(self.icones[self.boundaries[ipatch]['type']]) Item.setText(_translate("bcWidget", ipatch, None)) self.listWidget.addItem(Item) self.pushButton.setEnabled(False) self.addTabs() def changeSelection(self): ipatch = str(self.listWidget.currentItem().text()) self.comboBox.clear() self.comboBox.addItems(prototypes[self.boundaries[ipatch]['type']]) self.addTabs(ipatch) return def addTabs(self,ipatch=None): for itab in range(self.tabWidget.count()): layout = self.tabWidget.widget(itab).findChildren(QtGui.QVBoxLayout)[0] self.clearLayout(layout,0) self.tabWidget.clear() fileDict = '%s/system/changeDictionaryPetroSym'%self.currentFolder dictDict = [] if os.path.isfile(fileDict): dictDict = ParsedParameterFile(fileDict,createZipped=False) for ifield in self.fields: if ifield not in unknowns: continue widget = QtGui.QWidget() layout = QtGui.QVBoxLayout(widget) if ipatch: if dictDict==[]: filename = '%s/%s'%(self.timedir,ifield) parsedData = ParsedParameterFile(filename,listLengthUnparsed=20,createZipped=False) thisPatch = parsedData['boundaryField'][ipatch] else: thisPatch = dictDict['dictionaryReplacement'][ifield]['boundaryField'][ipatch] newComboBox = QtGui.QComboBox() newComboBox.addItems(types[self.boundaries[ipatch]['type']][ifield]) #aca hay que llamar a este evento solo si se cambia index = newComboBox.findText(thisPatch['type']) newComboBox.setCurrentIndex(index) if index!=-1 else None layout.addWidget(newComboBox) extraInfo = extras[ifield][thisPatch['type']] self.addExtraInfo(layout,extraInfo) QtCore.QObject.connect(newComboBox, QtCore.SIGNAL(_fromUtf8("currentIndexChanged(int)")), self.onChangeComboType) #cargo los datos desde el diccionario L = range(layout.count()) L = L[1:-1] iExtra = 0 for l in L: layout2 = layout.itemAt(l).layout() if layout2: if layout2.itemAt(1).widget().currentText() != 'table': data = str(thisPatch[extraInfo[iExtra*4]]) data = data.replace('(','').replace(')','').replace('[','').replace(']','').replace(',','').replace('\'','').split() if layout2.count()==3: layout2.itemAt(1).widget().setCurrentIndex(layout2.itemAt(1).widget().findText(data[0])) layout2.itemAt(2).widget().setText(data[1]) else: layout2.itemAt(1).widget().setCurrentIndex(layout2.itemAt(1).widget().findText(data[0])) layout2.itemAt(2).widget().setText(data[1]) layout2.itemAt(3).widget().setText(data[2]) layout2.itemAt(4).widget().setText(data[3]) else: None #determinar que hacer si quiero cargar una table!!! #('table', [[0, 0.0], [1e6-0.01, 0.0], [1e6, 1.0], [1e6, 1.0]]) #tabla = self.getTabla(itab) #parsedData['boundaryField'][ipatch][extraInfo[iExtra*4]] = ('table',tabla) iExtra = iExtra+1 spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) layout.addItem(spacerItem) self.tabWidget.addTab(widget, ifield) self.tabWidget.setTabText(self.tabWidget.count(),ifield) def onChangeComboType(self): ii = self.tabWidget.currentIndex() ifield = str(self.tabWidget.tabText(ii)) widget = self.tabWidget.currentWidget() if widget: itype = str(widget.findChildren(QtGui.QComboBox)[0].currentText()) layout = widget.findChildren(QtGui.QVBoxLayout)[0] self.clearLayout(layout, 1) self.addExtraInfo(layout,extras[ifield][itype]) self.checkData() def onEditValue(self): return def clearLayout(self, layout, dejar): for i in reversed(range(layout.count())): if i>= dejar: item = layout.itemAt(i) if isinstance(item, QtGui.QWidgetItem): item.widget().close() item.widget().deleteLater() # or # item.widget().setParent(None) elif isinstance(item, QtGui.QSpacerItem): None # no need to do extra stuff else: self.clearLayout(item.layout(),0) # remove the item from layout layout.removeItem(item) def addExtraInfo(self,layout,extraInfo): if extraInfo != []: for i in range(len(extraInfo)/4): layout2 = QtGui.QHBoxLayout() label = QtGui.QLabel() label.setText('%s %s'%(extraInfo[i*4],extraInfo[i*4+1])) layout2.addWidget(label) if extraInfo[i*4+2]: cb = QtGui.QComboBox() cb.addItems(extraInfo[i*4+2]) layout2.addWidget(cb) for j in range(extraInfo[i*4+3]): ledit = QtGui.QLineEdit() ledit.setValidator(QtGui.QDoubleValidator()) layout2.addWidget(ledit) QtCore.QObject.connect(ledit, QtCore.SIGNAL(_fromUtf8("textEdited(QString)")), self.checkData) layout.addLayout(layout2) spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) layout.addItem(spacerItem) def changePrototype(self): return def saveBCs(self): ipatch = str(self.listWidget.currentItem().text()) fileDict = '%s/system/changeDictionaryPetroSym'%self.currentFolder dictDict = [] if os.path.isfile(fileDict): dictDict = ParsedParameterFile(fileDict,createZipped=False) for itab in range(self.tabWidget.count()): ifield = str(self.tabWidget.tabText(itab)) itype = str(self.tabWidget.widget(itab).findChildren(QtGui.QComboBox)[0].currentText()) layout = self.tabWidget.widget(itab).findChildren(QtGui.QVBoxLayout)[0] if dictDict == []: filename = '%s/%s'%(self.timedir,ifield) parsedData = ParsedParameterFile(filename,listLengthUnparsed=20,createZipped=False) thisPatch = parsedData['boundaryField'][ipatch] else: thisPatch = dictDict['dictionaryReplacement'][ifield]['boundaryField'][ipatch] thisPatch = {} thisPatch['type'] = itype if itype == 'zeroGradient': thisPatch['ZZvalue'] = '0' #debo tomar los valores extras, si los tiene extraInfo = extras[ifield][itype] L = range(layout.count()) L = L[1:-1] iExtra = 0 #print ipatch for l in L: layout2 = layout.itemAt(l).layout() if layout2: if layout2.itemAt(1).widget().currentText() != 'table': if layout2.count()==3: thisPatch[extraInfo[iExtra*4]] = '%s %s' %(layout2.itemAt(1).widget().currentText(),layout2.itemAt(2).widget().text()) else: thisPatch[extraInfo[iExtra*4]] = '%s (%s %s %s)' %(layout2.itemAt(1).widget().currentText(),layout2.itemAt(2).widget().text(),layout2.itemAt(3).widget().text(),layout2.itemAt(4).widget().text()) else: #determinar que hacer si quiero cargar una table!!! #('table', [[0, 0.0], [1e6-0.01, 0.0], [1e6, 1.0], [1e6, 1.0]]) tabla = self.getTabla(itab) thisPatch[extraInfo[iExtra*4]] = ('table',tabla) iExtra = iExtra+1 if dictDict == []: parsedData['boundaryField'][ipatch] = thisPatch parsedData.writeFile() else: dictDict['dictionaryReplacement'][ifield]['boundaryField'][ipatch] = thisPatch dictDict.writeFile() dictDictBak = ParsedParameterFile(fileDict,createZipped=False) keysDict = dictDict['dictionaryReplacement'].keys() dictDictBak['dictionaryReplacement'] = {} for ikey in keysDict: if ikey in self.fields: dictDictBak['dictionaryReplacement'][ikey] = {} dictDictBak['dictionaryReplacement'][ikey]['boundaryField'] = dictDict['dictionaryReplacement'][ikey]['boundaryField'] dictDictBak.writeFileAs('%s/system/changeDictionaryPetroSym.bak'%self.currentFolder) command = 'sed -i "s/ZZ/~/g" %s/system/changeDictionaryPetroSym.bak'%(self.currentFolder) os.system(command) #chequear que no bloquee if self.nproc<=1: command = 'changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak 1> %s/changeDictionary.log 2> %s/error.log &'%(self.currentFolder,self.currentFolder,self.currentFolder,self.currentFolder) else: command = 'mpirun -np %s changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak -parallel 1> %s/changeDictionary.log 2> %s/error.log &'%(str(self.nproc),self.currentFolder,self.currentFolder,self.currentFolder,self.currentFolder) os.system(command) self.pushButton.setEnabled(False) return def getTable(self,itab): table = [[0, 0],[1, 0]] return table def checkData(self): ready = True for itab in range(self.tabWidget.count()): edits = self.tabWidget.widget(itab).findChildren(QtGui.QLineEdit) for E in edits: if E.isEnabled(): if not E.text(): ready = False if ready: self.pushButton.setEnabled(True) else: self.pushButton.setEnabled(False) def changePatchType(self,item): texto = str(item.text()) w = bcPatch(self.boundaries[texto]['type']) result = w.exec_() if result: patchType = w.getPatchType() self.boundaries[texto]['type'] = patchType self.boundaries.writeFile() fileDict = '%s/system/changeDictionaryPetroSym'%self.currentFolder dictDict = [] if os.path.isfile(fileDict): dictDict = ParsedParameterFile(fileDict,createZipped=False) for ifield in self.fields: if dictDict==[]: filename = '%s/%s'%(self.timedir,ifield) fieldData = ParsedParameterFile(filename,listLengthUnparsed=20,createZipped=False) else: fieldData = dictDict['dictionaryReplacement'][ifield] newDict = {} if patchType == 'empty': newDict['type'] = 'empty' newDict['ZZvalue'] = '0' else: if ifield in unknowns: newDict['type'] = 'zeroGradient' newDict['ZZvalue'] = '0' else: newDict['type'] = 'calculated' newDict['ZZvalue'] = '0' fieldData['boundaryField'][texto] = newDict if dictDict==[]: fieldData.writeFile() else: dictDict['dictionaryReplacement'][ifield] = fieldData if dictDict!=[]: dictDict.writeFile() dictDictBak = ParsedParameterFile(fileDict,createZipped=False) keysDict = dictDict['dictionaryReplacement'].keys() dictDictBak['dictionaryReplacement'] = {} for ikey in keysDict: if ikey in self.fields: dictDictBak['dictionaryReplacement'][ikey] = {} dictDictBak['dictionaryReplacement'][ikey]['boundaryField'] = dictDict['dictionaryReplacement'][ikey]['boundaryField'] dictDictBak.writeFileAs('%s/system/changeDictionaryPetroSym.bak'%self.currentFolder) command = 'sed -i "s/ZZ/~/g" %s/system/changeDictionaryPetroSym.bak'%(self.currentFolder) os.system(command) #chequear que no bloquee if self.nproc<=1: command = 'changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak 1> %s/changeDictionary.log 2> %s/error.log &'%(self.currentFolder,self.currentFolder,self.currentFolder,self.currentFolder) else: command = 'mpirun -np %s changeDictionary -case %s -dict %s/system/changeDictionaryPetroSym.bak -parallel 1> %s/changeDictionary.log 2> %s/error.log &'%(str(self.nproc),self.currentFolder,self.currentFolder,self.currentFolder,self.currentFolder) os.system(command) self.loadData()
from PyFoam.Basics.FoamOptionParser import FoamOptionParser from os import path import sys from PyFoam.RunDictionary.BoundaryDict import BoundaryDict from PyFoam.RunDictionary.MeshInformation import MeshInformation parse=FoamOptionParser(description=description,usage="%prog <caseDirectory> <boundaryName>") parse.parse(nr=2) fName=parse.getArgs()[0] bName=parse.getArgs()[1] boundary=BoundaryDict(fName) lastFace=MeshInformation(fName).nrOfFaces() if bName in boundary.patches(): print "Patch",bName,"already exists in file" sys.exit(-1) val={} val["type"]="wall" val["nFaces"]="0" val["startFace"]=str(lastFace) boundary[bName]=val boundary.writeFile()
from PyFoam.Basics.FoamOptionParser import FoamOptionParser from os import path import sys from PyFoam.RunDictionary.BoundaryDict import BoundaryDict from PyFoam.RunDictionary.MeshInformation import MeshInformation from PyFoam.ThirdParty.six import print_ parse=FoamOptionParser(description=description,usage="%prog <caseDirectory>") parse.parse(nr=1) fName=parse.getArgs()[0] boundary=BoundaryDict(fName) cleared=[] for b in boundary.patches(): if boundary[b]["nFaces"]==0: cleared.append(b) del boundary[b] if len(cleared)>0: print_("Cleared boundaries",", ".join(cleared)) boundary.writeFile() else: print_("No empty boundaries") # Should work with Python3 and Python2
class postproWidget(postproUI): def __init__(self, currentFolder): postproUI.__init__(self) def setCurrentFolder(self, currentFolder): self.currentFolder = currentFolder # filling data self.nproc = self.window().nproc [timedir, self.fields, currtime] = currentFields(str(self.currentFolder), nproc=self.nproc) self.field_3.clear() self.field_3.addItems(self.fields) self.boundaries = BoundaryDict(str(self.currentFolder)) self.bou_3.clear() self.bou_3.addItems(self.boundaries.patches()) def openParaview(self): os.system("paraFoam -builtin -case %s &" % self.currentFolder) def exportData(self): if self.nproc > 1: w = QtGui.QMessageBox( QtGui.QMessageBox.Information, "Error", "Data only can be exported in reconstructed cases" ) w.exec_() return tt = "" if self.time_4.currentText() == "Latest Time": tt = "-latestTime" opt = str(self.comboBox.currentText()) filename = "%s/export.log" % self.currentFolder self.window().newLogTab("Export", filename) if opt == "VTK": action = "foamToVTK -case %s %s > %s &" % (self.currentFolder, tt, filename) elif opt == "Fluent": action = "foamMeshToFluent -case %s &" % (self.currentFolder) os.system(action) action = "cp %s/caseDicts/foamDataToFluentDict %s/system/foamDataToFluentDict" % ( os.path.dirname(os.path.realpath(__file__)), self.currentFolder, ) os.system(action) parsedData = ParsedParameterFile("%s/system/foamDataToFluentDict" % self.currentFolder, createZipped=False) ii = 10 for ifield in self.fields: if ifield not in parsedData.getValueDict().keys(): parsedData[ifield] = ii ii = ii + 1 action = "foamDataToFluent -case %s %s > %s &" % (self.currentFolder, tt, filename) elif opt == "Ensight": action = "foamToEnsight -case %s %s > %s &" % (self.currentFolder, tt, filename) os.system(action) return def calculate1(self): tt = "" if self.time_1.currentText() == "Latest Time": tt = "-latestTime" filename = "%s/field_calculation.log" % self.currentFolder self.window().newLogTab("Postpro Field", filename) if self.nproc <= 1: action = "%s -case %s %s > %s" % (apps[str(self.field_1.currentText())], self.currentFolder, tt, filename) else: action = "mpirun -np %s %s -case %s %s -parallel > %s" % ( str(self.nproc), apps[str(self.field_1.currentText())], self.currentFolder, tt, filename, ) os.system(action) return def calculate2(self): tt = "" if self.time_2.currentText() == "Latest Time": tt = "-latestTime" filename = "%s/walls_calculation.log" % self.currentFolder if self.field_2.currentText() == "y Plus RAS": if not os.path.isfile("%s/constant/RASProperties" % self.currentFolder): QtGui.QMessageBox(QtGui.QMessageBox.Information, "Caution", "Action can not be done!").exec_() return if self.field_2.currentText() == "y Plus LES": if not os.path.isfile("%s/constant/LESProperties" % self.currentFolder): QtGui.QMessageBox(QtGui.QMessageBox.Information, "Caution", "Action can not be done!").exec_() return self.window().newLogTab("Postpro Wall", filename) if self.nproc <= 1: action = "%s -case %s %s > %s" % (apps[str(self.field_2.currentText())], self.currentFolder, tt, filename) else: action = "mpirun -np %s %s -case %s %s -parallel > %s" % ( str(self.nproc), apps[str(self.field_2.currentText())], self.currentFolder, tt, filename, ) os.system(action) return def calculate3(self): tt = "" if self.time_3.currentText() == "Latest Time": tt = "-latestTime" filename = "%s/patch_calculation.log" % self.currentFolder self.window().newLogTab("Postpro Patch", filename) fieldName = str(self.field_3.currentText()) patchName = str(self.bou_3.currentText()) if self.nproc <= 1: action = "%s -case %s %s %s %s > %s &" % ( apps[str(self.type_3.currentText())], self.currentFolder, tt, fieldName, patchName, filename, ) else: action = "mpirun -np %s %s -case %s %s %s %s -parallel > %s &" % ( str(self.nproc), apps[str(self.type_3.currentText())], self.currentFolder, tt, fieldName, patchName, filename, ) os.system(action) return
def run(self): fName=self.parser.getArgs()[0] try: dictFile=ParsedParameterFile(fName,backup=False) except IOError: e = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e' self.error("Problem with file",fName,":",e) fName=path.abspath(fName) case=path.dirname(path.dirname(fName)) region=None if not SolutionDirectory(case,archive=None,paraviewLink=False).isValid(): # checking for a multi-region case case=path.dirname(case) region=path.basename(path.dirname(fName)) print_(case,region) if region not in SolutionDirectory(case,archive=None,paraviewLink=False).getRegions(): self.error(region,"is not a valid region in the case",case) if self.opts.filter==None: flter=re.compile(".+") else: flter=re.compile(self.opts.filter) boundaries=dictFile["boundaryField"] try: bFile=BoundaryDict(case,region=region) except IOError: e = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e' self.error("Problem reading the boundary file:",e) if self.opts.clear: for b in list(boundaries.keys()): if b not in bFile.patches(): if self.opts.verbose: print_("Deleting patch",b) del boundaries[b] if not self.opts.nocheck: for p in bFile.patches(): if p in boundaries: typ=boundaries[p]["type"] pTyp=bFile[p]["type"] if pTyp!="patch" and pTyp!="wall" and pTyp!=typ: if self.opts.fixtypes: if self.opts.verbose: print_("Fixing wall/patch patch",p) del boundaries[p] continue else: self.error("Inconsistent type for ",p,": Is",typ,"but should be",pTyp) if typ in ["symmetryPlane","empty","wedge","cyclic","processor"] and pTyp!=typ: if self.opts.fixtypes: if self.opts.verbose: print_("Fixing special patch",p) del boundaries[p] continue else: self.error("Inconsistent type for ",p,": Is",typ,"but should be some kind of patch type") for p in bFile.patches(): if (not p in boundaries or self.opts.overwrite) and flter.match(p): pTyp=bFile[p]["type"] if pTyp!="patch" and pTyp!="wall": tmp={"type":pTyp} else: tmp=eval(self.opts.default) if self.opts.verbose: print_("Writing",tmp,"to patch",p) boundaries[p]=tmp; if self.opts.test: print_(str(dictFile)) else: dictFile.writeFile() self.addToCaseLog(case)
class postproWidget(postproUI): def __init__(self, currentFolder): postproUI.__init__(self) def setCurrentFolder(self, currentFolder): self.currentFolder = currentFolder #filling data self.nproc = self.window().nproc [timedir, self.fields, currtime] = currentFields(str(self.currentFolder), nproc=self.nproc) self.field_3.clear() self.field_3.addItems(self.fields) self.boundaries = BoundaryDict(str(self.currentFolder)) self.bou_3.clear() self.bou_3.addItems(self.boundaries.patches()) def openParaview(self): os.system('paraFoam -builtin -case %s &' % self.currentFolder) def exportData(self): if self.nproc > 1: w = QtGui.QMessageBox( QtGui.QMessageBox.Information, "Error", "Data only can be exported in reconstructed cases") w.exec_() return tt = '' if self.time_4.currentText() == 'Latest Time': tt = '-latestTime' opt = str(self.comboBox.currentText()) filename = '%s/export.log' % self.currentFolder self.window().newLogTab('Export', filename) if opt == 'VTK': action = 'foamToVTK -case %s %s > %s &' % (self.currentFolder, tt, filename) elif opt == 'Fluent': action = 'foamMeshToFluent -case %s &' % (self.currentFolder) os.system(action) action = 'cp %s/caseDicts/foamDataToFluentDict %s/system/foamDataToFluentDict' % ( os.path.dirname( os.path.realpath(__file__)), self.currentFolder) os.system(action) parsedData = ParsedParameterFile('%s/system/foamDataToFluentDict' % self.currentFolder, createZipped=False) ii = 10 for ifield in self.fields: if ifield not in parsedData.getValueDict().keys(): parsedData[ifield] = ii ii = ii + 1 action = 'foamDataToFluent -case %s %s > %s &' % ( self.currentFolder, tt, filename) elif opt == 'Ensight': action = 'foamToEnsight -case %s %s > %s &' % (self.currentFolder, tt, filename) os.system(action) return def calculate1(self): tt = '' if self.time_1.currentText() == 'Latest Time': tt = '-latestTime' filename = '%s/field_calculation.log' % self.currentFolder self.window().newLogTab('Postpro Field', filename) if self.nproc <= 1: action = '%s -case %s %s > %s' % (apps[str( self.field_1.currentText())], self.currentFolder, tt, filename) else: action = 'mpirun -np %s %s -case %s %s -parallel > %s' % ( str(self.nproc), apps[str(self.field_1.currentText())], self.currentFolder, tt, filename) os.system(action) return def calculate2(self): tt = '' if self.time_2.currentText() == 'Latest Time': tt = '-latestTime' filename = '%s/walls_calculation.log' % self.currentFolder if self.field_2.currentText() == 'y Plus RAS': if not os.path.isfile( '%s/constant/RASProperties' % self.currentFolder): QtGui.QMessageBox(QtGui.QMessageBox.Information, "Caution", "Action can not be done!").exec_() return if self.field_2.currentText() == 'y Plus LES': if not os.path.isfile( '%s/constant/LESProperties' % self.currentFolder): QtGui.QMessageBox(QtGui.QMessageBox.Information, "Caution", "Action can not be done!").exec_() return self.window().newLogTab('Postpro Wall', filename) if self.nproc <= 1: action = '%s -case %s %s > %s' % (apps[str( self.field_2.currentText())], self.currentFolder, tt, filename) else: action = 'mpirun -np %s %s -case %s %s -parallel > %s' % ( str(self.nproc), apps[str(self.field_2.currentText())], self.currentFolder, tt, filename) os.system(action) return def calculate3(self): tt = '' if self.time_3.currentText() == 'Latest Time': tt = '-latestTime' filename = '%s/patch_calculation.log' % self.currentFolder self.window().newLogTab('Postpro Patch', filename) fieldName = str(self.field_3.currentText()) patchName = str(self.bou_3.currentText()) if self.nproc <= 1: action = '%s -case %s %s %s %s > %s &' % (apps[str( self.type_3.currentText())], self.currentFolder, tt, fieldName, patchName, filename) else: action = 'mpirun -np %s %s -case %s %s %s %s -parallel > %s &' % ( str(self.nproc), apps[str(self.type_3.currentText())], self.currentFolder, tt, fieldName, patchName, filename) os.system(action) return