本文整理汇总了Python中PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile.restore方法的典型用法代码示例。如果您正苦于以下问题:Python ParsedParameterFile.restore方法的具体用法?Python ParsedParameterFile.restore怎么用?Python ParsedParameterFile.restore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile
的用法示例。
在下文中一共展示了ParsedParameterFile.restore方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import restore [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:
warning("Restoring defaults")
self.solution.restore()
self.schemes.restore()
raise e
示例2: __init__
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import restore [as 别名]
class WriteAllTrigger:
def __init__(self,sol,writeAll,purge,until):
self.control=ParsedParameterFile(path.join(sol.systemDir(),"controlDict"),
backup=True,
doMacroExpansion=True)
self.fresh=True
try:
if writeAll:
self.control["writeControl"]="timeStep"
self.control["writeInterval"]="1"
if purge!=None:
self.control["purgeWrite"]=purge
if until!=None:
self.control["endTime"]=until
self.control.writeFile()
except Exception:
e = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e'
warning("Restoring defaults")
self.control.restore()
raise e
def resetIt(self):
if self.fresh:
warning("Trigger called: Resetting the controlDict")
self.control.restore()
self.fresh=False
示例3: __init__
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import restore [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
示例4: __init__
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import restore [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
示例5: __init__
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import restore [as 别名]
class WriteAllTrigger:
def __init__(self,sol,writeAll,purge,until):
self.control=ParsedParameterFile(path.join(sol.systemDir(),"controlDict"),backup=True)
self.fresh=True
try:
if writeAll:
self.control["writeControl"]="timeStep"
self.control["writeInterval"]="1"
if purge!=None:
self.control["purgeWrite"]=purge
if until!=None:
self.control["endTime"]=until
self.control.writeFile()
except Exception,e:
warning("Restoring defaults")
self.control.restore()
raise e
示例6: __init__
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import restore [as 别名]
class LibFunctionTrigger:
def __init__(self,sol,libs,funs):
self.control=ParsedParameterFile(path.join(sol.systemDir(),"controlDict"),
backup=True,
doMacroExpansion=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 = sys.exc_info()[1] # Needed because python 2.5 does not support 'as e'
warning("Restoring defaults")
self.control.restore()
raise e
def resetIt(self):
if self.fresh:
warning("Trigger called: Resetting controlDict")
self.control.restore()
self.fresh=False
示例7: __init__
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import restore [as 别名]
class PotentialTrigger:
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
示例8: __init__
# 需要导入模块: from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile [as 别名]
# 或者: from PyFoam.RunDictionary.ParsedParameterFile.ParsedParameterFile import restore [as 别名]
class PotentialTrigger:
def __init__(self,
sol,
correctors,
tolerance,
relTol,
pRefValue=None,
pRefCell=None,
removeLibs=False,
removeFunctions=False):
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 and foamVersion()[0]<2:
self.solution["SIMPLE"]=ParsedParameterFile(path.join(pot.systemDir(),"fvSolution"),backup=False)["SIMPLE"]
if foamVersion()[0]<2:
solutionBlock=self.solution["SIMPLE"]
else:
self.solution["potentialFlow"]={}
solutionBlock=self.solution["potentialFlow"]
if "nNonOrthogonalCorrectors" not in solutionBlock and correctors==None:
correctors=3
warning("Setting number of correctors to default value",correctors)
if correctors!=None:
solutionBlock["nNonOrthogonalCorrectors"]=correctors
if pRefCell!=None:
solutionBlock["pRefCell"]=pRefCell
if pRefValue!=None:
solutionBlock["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
for k in ["functions","libs"]:
if k in self.control:
print_("Remove",k,"from controlDict")
del self.control[k]
if "functions" in self.controlOrig and not removeFunctions:
print_("Copying functions over")
self.control["functions"]=self.controlOrig["functions"]
if "libs" in self.controlOrig and not removeLibs:
print_("Copying libs over")
self.control["libs"]=self.controlOrig["libs"]
self.solution.writeFile()
self.schemes.writeFile()
self.control.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()
self.control.restore()
raise e
def resetIt(self):
if self.fresh:
warning("Trigger called: Resetting fvSchemes and fvSolution")
self.solution.restore()
self.schemes.restore()
self.control.restore()
self.fresh=False