本文整理汇总了Python中PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile类的典型用法代码示例。如果您正苦于以下问题:Python ParsedParameterFile类的具体用法?Python ParsedParameterFile怎么用?Python ParsedParameterFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParsedParameterFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: accept
def accept(self):
filename = '%s/system/controlDict'%(self.currentFolder)
parsedData = ParsedParameterFile(filename,createZipped=False)
if 'functions' not in parsedData.getValueDict().keys():
parsedData['functions'] = {}
#Logica para evitar que se llamen T* (como los tracers)
# if len(str(self.name.text()))>=2 and self.name.text()[0]=='T':
# for i in range(1,len(str(self.name.text()))):
# if ()
#Logica para evitar nombres repetidos
for key in parsedData['functions'].keys():
if key == str(self.name.text()):
w = QtGui.QMessageBox(QtGui.QMessageBox.Information, "Error", "The name of the new figure and the name of the field must be different. Please select another name")
w.exec_()
return
if str(self.name.text()) not in parsedData['functions'].keys():
parsedData['functions'][str(self.name.text())] = {}
parsedData['functions'][str(self.name.text())]['type'] = 'residuals'
parsedData['functions'][str(self.name.text())]['outputControl'] = 'timeStep'
parsedData['functions'][str(self.name.text())]['outputInterval'] = self.spinBox.value()
parsedData['functions'][str(self.name.text())]['functionObjectLibs'] = ['"libutilityFunctionObjects.so"']
fields = []
for i in range(self.listWidget.count()):
if self.listWidget.item(i).checkState() == QtCore.Qt.Checked:
fields.append(str(self.listWidget.item(i).text()))
parsedData['functions'][str(self.name.text())]['fields'] = fields
parsedData.writeFile()
self.done(self.Accepted)
示例2: aplicar
def aplicar(self):
filename = '%s/system/controlDict'%self.currentFolder
parsedData = ParsedParameterFile(filename,createZipped=False)
parsedData['startFrom'] = self.cb_start_from_iinv[self.cb_start_from.currentIndex()]
parsedData['startTime'] = str(self.start_from.text())
parsedData['endTime'] = str(self.end_time.text())
parsedData['deltaT'] = str(self.delta_time.text())
if self.adjustable.isChecked():
parsedData['adjustTimeStep'] = 'yes'
else:
parsedData['adjustTimeStep'] = 'no'
parsedData['maxCo'] = str(self.max_cfl.text())
parsedData['maxAlphaCo'] = str(self.max_cfl_alpha.text())
parsedData['maxDeltaT'] = str(self.max_deltat.text())
parsedData['writeControl'] = self.cb_write_control_iinv[self.cb_write_control.currentIndex()]
parsedData['writeInterval'] = str(self.write_control.text())
parsedData['purgeWrite'] = str(self.purge.value())
parsedData['writePrecision'] = str(self.precision.value())
parsedData['writeFormat'] = self.format_iinv[self.format.currentIndex()]
parsedData['timePrecision'] = str(self.precision_time.value())
parsedData['writeCompression'] = self.compression_iinv[self.compression.currentIndex()]
parsedData['stopAt'] = 'endTime'
parsedData.writeFile()
self.pushButton.setEnabled(False)
self.window().updateLogFiles()
return
示例3: changePatchType
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()
for ifield in self.fields:
filename = '%s/%s'%(self.timedir,ifield)
fieldData = ParsedParameterFile(filename,listLengthUnparsed=20,createZipped=False)
newDict = {}
if patchType == 'empty':
newDict['type'] = 'empty'
else:
if ifield in unknowns:
newDict['type'] = 'zeroGradient'
else:
newDict['type'] = 'calculated'
fieldData['boundaryField'][texto] = newDict
fieldData.writeFile()
self.loadData()
示例4: run
def run(self):
fName=self.parser.getArgs()[0]
bName=self.parser.getArgs()[1]
tName=self.parser.getArgs()[2]
boundaryPath=path.join(".",fName,self.opts.time,self.opts.region,"polyMesh","boundary")
try:
boundary=ParsedParameterFile(boundaryPath,debug=False,boundaryDict=True)
except IOError:
self.error("Problem opening boundary file",boundaryPath)
bnd=boundary.content
if type(bnd)!=list:
self.error("Problem with boundary file (not a list)")
found=False
for val in bnd:
if val==bName:
found=True
elif found:
val["type"]=tName
break
if not found:
self.error("Boundary",bName,"not found in",bnd[::2])
if self.opts.test:
print_(boundary)
else:
boundary.writeFile()
self.addToCaseLog(fName)
示例5: resetCase
def resetCase(self):
[self.timedir,self.fields,self.currtime] = currentFields(self.currentFolder,nproc=self.window().nproc)
w = reset()
result = w.exec_()
if result:
self.window().nproc = 1
command = 'pyFoamClearCase.py %s %s'%(w.getParams(), self.currentFolder)
os.system(command)
#if w.deleteSnapshots():
# command = 'rm -rf %s/postProcessing/snapshots'%self.currentFolder
# os.system(command)
if w.resetFigures():
self.window().resetFigures(w.deletePostpro(),True)
filename = '%s/system/controlDict'%self.currentFolder
parsedData = ParsedParameterFile(filename,createZipped=False)
parsedData['startFrom'] = 'startTime'
parsedData['startTime'] = '0'
parsedData.writeFile()
self.window().typeFile = {}
self.window().pending_files = []
self.window().pending_dirs = []
self.window().updateLogFiles()
self.type_serial.setChecked(True)
self.type_parallel.setChecked(False)
self.changeType()
self.window().save_config()
示例6: saveBCs
def saveBCs(self):
ipatch = str(self.listWidget.currentItem().text())
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]
filename = '%s/%s'%(self.timedir,ifield)
parsedData = ParsedParameterFile(filename,listLengthUnparsed=20,createZipped=False)
parsedData['boundaryField'][ipatch] = {}
parsedData['boundaryField'][ipatch]['type'] = itype
#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:
parsedData['boundaryField'][ipatch][extraInfo[iExtra*4]] = '%s %s' %(layout2.itemAt(1).widget().currentText(),layout2.itemAt(2).widget().text())
else:
parsedData['boundaryField'][ipatch][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)
parsedData['boundaryField'][ipatch][extraInfo[iExtra*4]] = ('table',tabla)
iExtra = iExtra+1
parsedData.writeFile()
self.pushButton.setEnabled(False)
return
示例7: run
def run(self):
fName=self.parser.getArgs()[0]
destPatches=self.parser.getArgs()[1:]
if self.opts.patch==None and self.opts.value==None:
self.error("Either a patch or a value must be specified")
if self.opts.patch!=None and self.opts.value!=None:
self.error("Only a patch or a value can be specified")
try:
fieldFile=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)
value=""
if self.opts.patch:
value=fieldFile["boundaryField"][self.opts.patch][self.opts.srckey]
else:
value="uniform "+self.opts.value
for destPatch in destPatches:
fieldFile["boundaryField"][destPatch][self.opts.destkey]=value
if self.opts.test:
print_(str(fieldFile))
else:
fieldFile.writeFile()
示例8: saveUserLibrary
def saveUserLibrary(self):
filename = 'caseDicts/materialProperties.incompressible'
parsedData = ParsedParameterFile(filename,createZipped=False)
parsedData['userLibrary'] = self.userLibrary
parsedData.writeFile()
return
示例9: exportData
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
示例10: processABoundaryFile
def processABoundaryFile(self,func,targetDir):
"""
@param func: the function that transforms the actual boundary file
"""
boundaryPath=path.join(targetDir,self.opts.region,"polyMesh","boundary")
try:
boundary=ParsedParameterFile(boundaryPath,
debug=False,
boundaryDict=True,
treatBinaryAsASCII=True)
except IOError:
self.warning("Problem opening boundary file",boundaryPath)
return False
bnd=boundary.content
if type(bnd)!=list:
self.warning("Problem with boundary file (not a list)")
return False
boundary.content=func(bnd,targetDir)
if boundary.content:
if self.opts.test:
print_(boundary)
else:
boundary.writeFile()
# self.addToCaseLog(boundaryPath)
return True
else:
self.warning(boundaryPath,"unchanged")
return False
开发者ID:mortbauer,项目名称:openfoam-extend-Breeder-other-scripting-PyFoam,代码行数:32,代码来源:CommonChangeBoundary.py
示例11: updateFieldFiles
def updateFieldFiles(self):
#tengo que releer cada uno de los campos en el directorio actual,
#pisar los boundaries por los que aparece en constant/polyMesh/boundary
#imponerles alguna CB por defecto dependiendo del tipo de patch
boundaries = BoundaryDict(self.currentFolder)
#veo los campos que tengo en el directorio inicial
[timedir,fields,currtime] = currentFields(self.currentFolder, False)
for ifield in fields:
filename = '%s/%s'%(timedir,ifield)
fieldData = ParsedParameterFile(filename,createZipped=False)
fieldData['boundaryField'] = {}
for ipatch in boundaries.getValueDict():
if ipatch not in fieldData['boundaryField']:
if boundaries[ipatch]['nFaces']==0:
continue
patchDict={}
if ifield in unknowns:
patchDict['type'] = 'zeroGradient'
else:
patchDict['type'] = 'calculated'
fieldData['boundaryField'][ipatch] = patchDict
fieldData.writeFile()
return
示例12: __init__
def __init__(self,sol,correctors,tolerance,relTol,pRefValue=None,pRefCell=None):
self.solution=ParsedParameterFile(path.join(sol.systemDir(),"fvSolution"),backup=True)
self.schemes=ParsedParameterFile(path.join(sol.systemDir(),"fvSchemes"),backup=True)
self.control=ParsedParameterFile(path.join(sol.systemDir(),"controlDict"),backup=True)
self.controlOrig=ParsedParameterFile(path.join(sol.systemDir(),"controlDict"),backup=False)
pre=environ["FOAM_TUTORIALS"]
if not oldTutorialStructure():
pre=path.join(pre,"basic")
pot=SolutionDirectory(path.join(pre,"potentialFoam","cylinder"),archive=None,paraviewLink=False)
self.fresh=True
try:
if "SIMPLE" not in self.solution:
self.solution["SIMPLE"]=ParsedParameterFile(path.join(pot.systemDir(),"fvSolution"),backup=False)["SIMPLE"]
if "nNonOrthogonalCorrectors" not in self.solution["SIMPLE"] and correctors==None:
correctors=3
warning("Setting number of correctors to default value",correctors)
if correctors!=None:
self.solution["SIMPLE"]["nNonOrthogonalCorrectors"]=correctors
if pRefCell!=None:
self.solution["SIMPLE"]["pRefCell"]=pRefCell
if pRefValue!=None:
self.solution["SIMPLE"]["pRefValue"]=pRefValue
if tolerance!=None:
try:
self.solution["solvers"]["p"][1]["tolerance"]=tolerance
except KeyError:
# 1.6 format
self.solution["solvers"]["p"]["tolerance"]=tolerance
if relTol!=None:
try:
self.solution["solvers"]["p"][1]["relTol"]=relTol
except KeyError:
# 1.6 format
self.solution["solvers"]["p"]["relTol"]=relTol
self.schemes.content=ParsedParameterFile(path.join(pot.systemDir(),"fvSchemes"),backup=False).content
self.control.content=ParsedParameterFile(path.join(pot.systemDir(),"controlDict"),backup=False).content
if "functions" in self.controlOrig:
print "Copying functions over"
self.control["functions"]=self.controlOrig["functions"]
if "libs" in self.controlOrig:
print "Copying libs over"
self.control["libs"]=self.controlOrig["libs"]
self.solution.writeFile()
self.schemes.writeFile()
self.control.writeFile()
except Exception,e:
warning("Restoring defaults")
self.solution.restore()
self.schemes.restore()
self.control.restore()
raise e
示例13: write
def write(self):
"""
Updates the values for the turbulent flow properties and writes all
**turbulent** boundary files. Wallfunctions, if used, are updated as
well.
"""
for bcI in self.turbBC:
for inletPatchI in self.case.inletPatch:
bcFile = ParsedParameterFile(
join(
self.case.name,
self.case.first,
bcI
)
)
# Set the internal field and the inlet patch at first
bcFile['internalField'] = "uniform %f" %(self.vars[bcI])
bcFile['boundaryField'][inletPatchI]['value'] = \
"uniform %f" %(self.vars[bcI])
# Update the wallfunctions if they are used
for patchI in bcFile['boundaryField']:
if "allFunction" in bcFile['boundaryField'][patchI]['type']:
bcFile['boundaryField'][patchI]['value'] = \
"uniform %f" %(self.vars[bcI])
# Write the current boundary file
bcFile.writeFile()
示例14: accept
def accept(self):
filename = '%s/system/controlDict'%(self.currentFolder)
parsedData = ParsedParameterFile(filename,createZipped=False)
if 'functions' not in parsedData.getValueDict().keys():
parsedData['functions'] = {}
#Logica para evitar nombres repetidos
for key in self.parsedData['functions'].keys():
if key == str(self.name.text()):
w = QtGui.QMessageBox(QtGui.QMessageBox.Information, "Error", "The name of the new figure and the name of the tracer must be different. Please select another name")
w.exec_()
return
dicc['outputInterval'] = self.spinBox.value()
fields = []
for i in range(self.listWidget.count()):
if self.listWidget.item(i).checkState() == QtCore.Qt.Checked:
fields.append(str(self.listWidget.item(i).text()))
dicc['fields'] = fields
dicc['sourceName'] = str(self.comboBox.currentText())
parsedData['functions'][str(self.name.text())] = dicc
parsedData.writeFile()
self.done(self.Accepted)
示例15: case_setup
def case_setup(ci):
template_case = SolutionDirectory(
"template", archive=None, paraviewLink=False)
case = template_case.cloneCase(
"{0}{1}".format(ci.name, ci.quadrature_order)
)
phase_properties = ParsedParameterFile(
path.join("./diffs", ci.phase_properties_name))
phase_properties["air"]["PBEDiameterCoeffs"]["QMOMCoeffs"]["quadratureOrder"] = ci.quadrature_order
# manually fix bad pyfoam parsing
phase_properties["blending"]["default"]["type"] = "none"
phase_properties["drag"][1]["swarmCorrection"]["type"] = "none"
phase_properties.writeFileAs(path.join(
case.name, "constant", "phaseProperties"
))
m0 = ParsedParameterFile(path.join(template_case.name, "0", "m0"))
for i in range(ci.number_of_moments):
m0.header["object"] = "m" + str(i)
m0["internalField"].setUniform(ci.initial_moments[i])
m0["dimensions"] = "[0 {0} 0 0 0 0 0]".format(3 * i)
m0.writeFileAs(path.join(case.name, "0", "m" + str(i)))
controlDict = ParsedParameterFile(
path.join(case.name, "system", "controlDict")
)
controlDict["functions"]["probes"]["fields"] = [
"m{0}".format(m) for m in range(ci.number_of_moments)]
controlDict["endTime"] = ci.end_time
controlDict["deltaT"] = ci.delta_t
controlDict.writeFile()