本文整理汇总了Python中PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile.writeFile方法的典型用法代码示例。如果您正苦于以下问题:Python ParsedParameterFile.writeFile方法的具体用法?Python ParsedParameterFile.writeFile怎么用?Python ParsedParameterFile.writeFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile
的用法示例。
在下文中一共展示了ParsedParameterFile.writeFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: changePatchType
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
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()
示例2: saveBCs
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
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
示例3: __init__
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
class SafeTrigger:
def __init__(self,sol,factor):
self.solution=ParsedParameterFile(path.join(sol.systemDir(),"fvSolution"),backup=True)
self.schemes=ParsedParameterFile(path.join(sol.systemDir(),"fvSchemes"),backup=True)
self.fresh=True
try:
relax=self.solution["relaxationFactors"]
for var in relax:
relax[var]*=factor
cExp=re.compile("div\((.+),(.+)\)")
conv=self.schemes["divSchemes"]
for nm in conv:
if cExp.match(nm) or nm=="default":
conv[nm]="Gauss upwind"
self.solution.writeFile()
self.schemes.writeFile()
except Exception:
e = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e'
warning("Restoring defaults")
self.solution.restore()
self.schemes.restore()
raise e
def resetIt(self):
if self.fresh:
warning("Trigger called: Resetting fvSchemes and fvSolution")
self.solution.restore()
self.schemes.restore()
self.fresh=False
示例4: aplicar
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
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
示例5: accept
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
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)
示例6: modifyDicts
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
def modifyDicts(self, parserArgs):
if parserArgs.airspeed:
file = ParsedParameterFile(os.path.join(self.casePath, "0", "U"))
file["internalField"].val.vals[0] = parserArgs.airspeed
file.writeFile()
file = ParsedParameterFile(os.path.join(self.casePath, "system", "controlDict"))
file["functions"]["forces"]["magUInf"] = parserArgs.airspeed
file["functions"]["forceCoeffs1"]["magUInf"] = parserArgs.airspeed
file.writeFile()
if parserArgs.cofg:
file = ParsedParameterFile(os.path.join(self.casePath, "system", "controlDict"))
file["functions"]["forces"]["CofR"].vals[0] = parserArgs.cofg
file["functions"]["forceCoeffs1"]["CofR"].vals[0] = parserArgs.cofg
file.writeFile()
if parserArgs.refarea:
file = ParsedParameterFile(os.path.join(self.casePath, "system", "controlDict"))
file["functions"]["forces"]["Aref"] = parserArgs.refarea
file["functions"]["forceCoeffs1"]["Aref"] = parserArgs.refarea
file.writeFile()
# if parserArgs.Lref:
# file = ParsedParameterFile(os.path.join(self.casePath,'system','controlDict'))
# file['functions']['forces']['CofR'].vals[0] = parserArgs.cofg
# file['functions']['forceCoeffs1']['CofR'].vals[0] = parserArgs.cofg
# file.writeFile()
if parserArgs.convergence:
file = ParsedParameterFile(os.path.join(self.casePath, "system", "fvSolution"))
for i in file["SIMPLE"]["residualControl"]:
file["SIMPLE"]["residualControl"][i] = parserArgs.convergence
file.writeFile()
示例7: run
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
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: __init__
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
class LibFunctionTrigger:
def __init__(self,sol,libs,funs):
self.control=ParsedParameterFile(path.join(sol.systemDir(),"controlDict"),backup=True)
self.fresh=False
try:
if libs and ("libs" in self.control):
warning("Temporarily removing the libs-entry from the controlDict")
del self.control["libs"]
self.fresh=True
if funs and ("functions" in self.control):
warning("Temporarily removing the functions-entry from the controlDict")
del self.control["functions"]
self.fresh=True
if self.fresh:
self.control.writeFile()
else:
self.control.restore()
except Exception,e:
warning("Restoring defaults")
self.control.restore()
raise e
示例9: case_setup
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
def case_setup(ci):
template_case = SolutionDirectory(
"template", archive=None, paraviewLink=False)
case = template_case.cloneCase(
"{0}NC{1}".format(ci.name, ci.nr_classes)
)
phase_properties = ParsedParameterFile(
path.join(template_case.name, "constant", "phaseProperties"))
phase_properties["oil"]["PBEDiameterCoeffs"]["MOCCoeffs"]["numberOfClasses"] = ci.nr_classes
phase_properties["oil"]["PBEDiameterCoeffs"]["MOCCoeffs"]["xi1"] = ci.dv
# 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"
))
n0 = ParsedParameterFile(path.join(template_case.name, "0", "n0"))
for i in range(ci.nr_classes):
n0.header["object"] = "n" + str(i)
n0["internalField"].setUniform(ci.Ninit[i])
n0.writeFileAs(path.join(case.name, "0", "n" + str(i)))
controlDict = ParsedParameterFile(
path.join(case.name, "system", "controlDict")
)
controlDict["functions"]["probes"]["fields"] = [
"n{0}".format(n) for n in range(ci.nr_classes)]
controlDict.writeFile()
示例10: write
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
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()
示例11: accept
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
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)
示例12: case_setup
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
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()
示例13: run
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
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)
示例14: setConditions
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
def setConditions(self):
runPotentialFlow = 0
for itab in range(self.tabWidget.count()):
ifield = self.tabWidget.tabText(itab)
layout = self.tabWidget.widget(itab).findChildren(QtGui.QVBoxLayout)[0]
filename = '%s/%s'%(self.timedir,ifield)
parsedData = ParsedParameterFile(filename,listLengthUnparsed=20,createZipped=False)
layout2 = layout.itemAt(0).layout()
if layout2.count()==2:
parsedData['internalField'] = '%s %s'%(layout2.itemAt(0).widget().currentText(),layout2.itemAt(1).widget().text())
else:
parsedData['internalField'] = '%s (%s %s %s)'%(layout2.itemAt(0).widget().currentText(),layout2.itemAt(1).widget().text(),layout2.itemAt(2).widget().text(),layout2.itemAt(3).widget().text())
parsedData.writeFile()
if ifield == 'U': #and self.tabWidget.widget(itab).findChildren(QtGui.QCheckBox)[0].isChecked():
#QtGui.QMessageBox.about(self, "ERROR", 'Debe simularse con potentialFoam, hacer!!')
parsedData['internalField'] = '%s (%s %s %s)'%('uniform',0,0,0)
filename = '%s/system/fvSolution'%self.currentFolder
parsedData2 = ParsedParameterFile(filename,createZipped=False)
if ('potentialFlowEnabled' not in parsedData2.content.keys()): #Si no existe (nunca abrio al gui) la creo
parsedData2['potentialFlowEnabled'] = {}
cb = self.tabWidget.widget(itab).findChildren(QtGui.QCheckBox)[0]
parsedData2['potentialFlowEnabled'] = 'yes' if cb.isChecked() else 'no'
parsedData2.writeFile()
self.pushButton.setEnabled(False)
return
示例15: resetCase
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import writeFile [as 别名]
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()