From b1ab3694fadee8da02552f745607ea215a27158f Mon Sep 17 00:00:00 2001 From: "Bernhard F.W. Gschaider" Date: Mon, 24 Nov 2014 15:50:31 +0100 Subject: [PATCH] Adapt the Hydro-Quebec scripts a) to conform to the new PyFoam.Site-package b) Run on Python 2 and Python 3 (by replacing print with the print_ from the six-library) --- .../Hydro-Quebec/PyFoam/ChangeGGIBoundary.py | 18 +++++------ .../PyFoam/ChangeMixingPlaneBoundary.py | 16 +++++----- .../ConvertMixingPlaneBoundaryToNewSyntax.py | 24 +++++++-------- .../Hydro-Quebec/PyFoam/InitGgiInterface.py | 30 +++++++++---------- .../PyFoam/InitMixingPlaneInterface.py | 22 +++++++------- .../PyFoam/pyFoamChangeGGIBoundary.py | 2 +- .../PyFoam/pyFoamChangeMixingPlaneBoundary.py | 2 +- ...amConvertMixingPlaneBoundaryToNewSyntax.py | 2 +- .../PyFoam/pyFoamInitGgiInterface.py | 2 +- .../PyFoam/pyFoamInitMixingPlaneInterface.py | 2 +- 10 files changed, 59 insertions(+), 61 deletions(-) diff --git a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ChangeGGIBoundary.py b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ChangeGGIBoundary.py index be875eb35..21480399c 100644 --- a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ChangeGGIBoundary.py +++ b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ChangeGGIBoundary.py @@ -9,8 +9,9 @@ Author: """ -from PyFoamApplication import PyFoamApplication +from PyFoam.Applications.PyFoamApplication import PyFoamApplication from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile +from PyFoam.ThirdParty.six import print_ from os import path import sys import re @@ -74,7 +75,7 @@ Change GGI boundary condition parameters dest="separationOffset", default=None, help='separation offset for cyclicGgi') - + self.parser.add_option("--test", action="store_true", default=False, @@ -84,7 +85,7 @@ Change GGI boundary condition parameters def run(self): fName=self.parser.getArgs()[0] bName=self.parser.getArgs()[1] - + boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True) bnd=boundary.content @@ -123,7 +124,7 @@ Change GGI boundary condition parameters val["separationOffset"]=self.parser.getOptions().separationOffset - # Deprecated + # Deprecated if self.parser.getOptions().shadowName!=None: self.warning("\n PatchName:",bName,": Option --shadowName is deprecated. Use --shadowPatch instead\n") shadowName=self.parser.getOptions().shadowName @@ -131,26 +132,25 @@ Change GGI boundary condition parameters if shadowName not in bnd: self.error("\n Option --shadowName for patch:",bName,": there is no patch called",shadowName,"\n") - # Deprecated + # Deprecated if self.parser.getOptions().patchZoneName!=None: self.warning("\n PatchName:",bName,": Option --patchZoneName is deprecated. Use --zone instead\n") val["zone"]=self.parser.getOptions().patchZoneName - # Deprecated + # Deprecated if self.parser.getOptions().bridgeOverlapFlag!=None: self.warning("\n PatchName:",bName,": Option --bridgeOverlapFlag is deprecated. Use --bridgeOverlap instead\n") val["bridgeOverlap"]=self.parser.getOptions().bridgeOverlapFlag else: - print "Unsupported GGI type '",bcType,"' for patch",bName + print_("Unsupported GGI type '",bcType,"' for patch",bName) break if not found: self.error("Boundary",bName,"not found in",bnd[::2]) if self.parser.getOptions().test: - print boundary + print_(boundary) else: boundary.writeFile() - diff --git a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ChangeMixingPlaneBoundary.py b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ChangeMixingPlaneBoundary.py index 128c75122..2212d5af7 100644 --- a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ChangeMixingPlaneBoundary.py +++ b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ChangeMixingPlaneBoundary.py @@ -9,8 +9,9 @@ Author: """ -from PyFoamApplication import PyFoamApplication +from PyFoam.Applications.PyFoamApplication import PyFoamApplication from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile +from PyFoam.ThirdParty.six import print_ from os import path import sys @@ -37,7 +38,7 @@ Change MixingPlane boundary condition parameters action="store", dest="zone", default=None, - help='Name of the zone for mixingPlanePatch') + help='Name of the zone for mixingPlanePatch') self.parser.add_option("--coordinateSystemName", action="store", dest="coordinateSystemName", @@ -78,7 +79,7 @@ Change MixingPlane boundary condition parameters dest="ribbonPatchDiscretisation", default=None, help='ribbonPatch discretisation (masterPatch|slavePatch|bothPatches|uniform|userDefined)') - + self.parser.add_option("--test", action="store_true", default=False, @@ -88,13 +89,13 @@ Change MixingPlane boundary condition parameters def run(self): fName=self.parser.getArgs()[0] bName=self.parser.getArgs()[1] - + boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True) bnd=boundary.content if type(bnd)!=list: - print "Problem with boundary file (not a list)" + print_("Problem with boundary file (not a list)") sys.exit(-1) found=False @@ -143,11 +144,10 @@ Change MixingPlane boundary condition parameters break if not found: - print "Boundary",bName,"not found in",bnd[::2] + print_("Boundary",bName,"not found in",bnd[::2]) sys.exit(-1) if self.parser.getOptions().test: - print boundary + print_(boundary) else: boundary.writeFile() - diff --git a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ConvertMixingPlaneBoundaryToNewSyntax.py b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ConvertMixingPlaneBoundaryToNewSyntax.py index c73c9f609..4a5e62512 100644 --- a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ConvertMixingPlaneBoundaryToNewSyntax.py +++ b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/ConvertMixingPlaneBoundaryToNewSyntax.py @@ -9,8 +9,9 @@ Author: """ -from PyFoamApplication import PyFoamApplication +from PyFoam.Applications.PyFoamApplication import PyFoamApplication from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile +from PyFoam.ThirdParty.six import print_ from os import path import sys @@ -46,7 +47,7 @@ class switch(object): """Return the match method once, then stop""" yield self.match raise StopIteration - + def match(self, *args): """Indicate whether or not to enter a case suite""" if self.fall or not args: @@ -87,13 +88,13 @@ Change MixingPlane boundary condition parameters def run(self): fName=self.parser.getArgs()[0] - + boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True) bnd=boundary.content if type(bnd)!=list: - print "Problem with boundary file (not a list)" + print_("Problem with boundary file (not a list)") sys.exit(-1) found=False @@ -107,23 +108,23 @@ Change MixingPlane boundary condition parameters if bnd[indexDefPatch]["type"]=="mixingPlane": if bnd[indexDefPatch].has_key("assembly"): - print " Replacing the parameter 'assembly' for patch", bnd[index] + print_(" Replacing the parameter 'assembly' for patch", bnd[index]) oldAssembly=bnd[indexDefPatch]["assembly"] del bnd[indexDefPatch]["assembly"] if bnd[indexDefPatch].has_key("orientation"): - print " Replacing the parameter 'orientation' for patch", bnd[index] + print_(" Replacing the parameter 'orientation' for patch", bnd[index]) oldOrientation=bnd[indexDefPatch]["orientation"] del bnd[indexDefPatch]["orientation"] if bnd[indexDefPatch].has_key("ribbonPatch")==False: bnd[indexDefPatch]["ribbonPatch"]={} - + if bnd[indexDefPatch].has_key("zone")==False: bnd[indexDefPatch]["zone"]=bnd[index] + "Zone" if oldAssembly != "": - # Converting "assembly" to ribbonPatch/discretisation + # Converting "assembly" to ribbonPatch/discretisation for case in switch(oldAssembly): if case('master'): bnd[indexDefPatch]["ribbonPatch"]["discretisation"]="masterPatch" @@ -138,7 +139,7 @@ Change MixingPlane boundary condition parameters bnd[indexDefPatch]["ribbonPatch"]["discretisation"]="userDefined" break if case(): # default - print "Unsupported assembly type: ", oldAssembly + print_("Unsupported assembly type: ", oldAssembly) if oldOrientation != "": # Converting "orientation" to ribbonPatch/ribbonPatchSweepAxis and @@ -194,10 +195,9 @@ Change MixingPlane boundary condition parameters bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="R" break if case(): # default - print "Unsupported orientation type: ", oldOrientation + print_("Unsupported orientation type: ", oldOrientation) if self.parser.getOptions().test: - print boundary + print_(boundary) else: boundary.writeFile() - diff --git a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/InitGgiInterface.py b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/InitGgiInterface.py index 8120d9076..7a73bcfed 100644 --- a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/InitGgiInterface.py +++ b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/InitGgiInterface.py @@ -19,15 +19,16 @@ import sys, fnmatch, re from os import path, listdir, chmod from stat import * -from PyFoamApplication import PyFoamApplication +from PyFoam.Applications.PyFoamApplication import PyFoamApplication from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile +from PyFoam.ThirdParty.six import print_ from PyFoam.RunDictionary.TimeDirectory import TimeDirectory from PyFoam.Basics.BasicFile import BasicFile class InitGgiInterface(PyFoamApplication): def __init__(self,args=None): description=""" -Init GGI boundary condition parameters in boundary file. +Init GGI boundary condition parameters in boundary file. Init GGI boundary fields in time directories. Generate faceSet scripts for ggi zones. Modify GGI zones information in decomposeParDict file. @@ -105,7 +106,7 @@ Modify GGI zones information in decomposeParDict file. Create a default definition for a ggi patch, and replace the current definition """ - print "Replacing definition of patch: ", patchName, ":", patch + print_("Replacing definition of patch: ", patchName, ":", patch) newPatch={ 'type' : ggiType, 'nFaces' : patch["nFaces"], @@ -123,7 +124,7 @@ the current definition description="""\ Modify the definition of a ggi patch """ - print " Modifying ggi boundary definition in constant/polyMesh/boundary for patch", patchName + print_(" Modifying ggi boundary definition in constant/polyMesh/boundary for patch", patchName) patch["type"]=ggiType @@ -167,12 +168,12 @@ Modify the definition of a ggi patch in the time directories for timeDir in listdir(caseDir): if reobj.match(timeDir): - print " Modifying ggi boundaryFields in timeDir", timeDir, "for patch", patchName + print_(" Modifying ggi boundaryFields in timeDir", timeDir, "for patch", patchName) td=TimeDirectory(caseDir, timeDir, yieldParsedFiles=True) for f in td: - print " Modifying field", f.name + print_(" Modifying field", f.name) f["boundaryField"][patchName]["type"]=ggiType f.writeFile() @@ -183,10 +184,10 @@ Generate a setSet batch file based on the zone info specified in the ggi interfa Generate a bash file for invoking setSet and setsToZones Update GGI zone infoprmation in decomposeParDict """ - # Default file: genFaceSetForGgiZones.setSet + # Default file: genFaceSetForGgiZones.setSet bfGenFaceSets = BasicFile(path.join(caseDir, self.parser.getOptions().genFaceSetForGgiZonesScriptName)) - print " Updating file ", bfGenFaceSets.name, " for generating GGI zones faceSet using the setSet command" + print_(" Updating file ", bfGenFaceSets.name, " for generating GGI zones faceSet using the setSet command") bnd=boundary.content @@ -209,8 +210,8 @@ Update GGI zone infoprmation in decomposeParDict # Default file: initGgiZones.sh bfInitGgiZones = BasicFile(path.join(caseDir, self.parser.getOptions().initGgiZonesScriptName)) - print " Updating file ", bfInitGgiZones.name, " for inititalizing GGI zones" - + print_(" Updating file ", bfInitGgiZones.name, " for inititalizing GGI zones") + bfInitGgiZones.writeLine([ "#!/bin/bash" ]) bfInitGgiZones.writeLine([ "setSet -batch " + self.parser.getOptions().genFaceSetForGgiZonesScriptName ]) bfInitGgiZones.writeLine([ "setsToZones -noFlipMap" ]) @@ -222,7 +223,7 @@ Update GGI zone infoprmation in decomposeParDict # DecomposeParDict decomposeParDictPath=path.join(caseDir,"system","decomposeParDict") if path.exists(decomposeParDictPath): - print " Updating file ", decomposeParDictPath, " for GGI zones" + print_(" Updating file ", decomposeParDictPath, " for GGI zones") decomposeParDict=ParsedParameterFile(decomposeParDictPath,debug=False,backup=True) dcp=decomposeParDict.content dcp["globalFaceZones"]="(\n " + '\n '.join(list(listOfGgiZones)) + "\n)" @@ -232,7 +233,7 @@ Update GGI zone infoprmation in decomposeParDict caseDir=self.parser.getArgs()[0] masterbName=self.parser.getArgs()[1] shadowbName=self.parser.getArgs()[2] - + boundary=ParsedParameterFile(path.join(".",caseDir,"constant","polyMesh","boundary"),debug=False,boundaryDict=True,backup=True) bnd=boundary.content @@ -249,7 +250,7 @@ Update GGI zone infoprmation in decomposeParDict timeDirs=self.parser.getOptions().timeDirs updateTimeDirs=True - ggiType=self.parser.getOptions().ggiType + ggiType=self.parser.getOptions().ggiType rotationAngle=0.0 if self.parser.getOptions().rotationAngle!=None: @@ -287,10 +288,9 @@ Update GGI zone infoprmation in decomposeParDict self.error("Boundary patch",shadowbName,"not found in",bnd[::2]) if self.parser.getOptions().test: - print boundary + print_(boundary) else: boundary.writeFile() # Write companion files self.generateCompanionFiles(caseDir, boundary) - diff --git a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/InitMixingPlaneInterface.py b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/InitMixingPlaneInterface.py index f35e20073..a20deb3b1 100644 --- a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/InitMixingPlaneInterface.py +++ b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/InitMixingPlaneInterface.py @@ -11,9 +11,10 @@ Author: """ -from PyFoamApplication import PyFoamApplication +from PyFoam.Applications.PyFoamApplication import PyFoamApplication from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile from PyFoam.RunDictionary.TimeDirectory import TimeDirectory +from PyFoam.ThirdParty.six import print_ from os import path, listdir import sys, fnmatch, re @@ -95,7 +96,7 @@ Init MixingPlane boundary condition parameters Create a default definition for a mixingPlane patch, and replace the current definition """ - print "Replacing definition of patch: ", patchName, ":", patch + print_("Replacing definition of patch: ", patchName, ":", patch) newPatch={ 'type' : "mixingPlane", 'nFaces' : patch["nFaces"], @@ -120,7 +121,7 @@ the current definition description="""\ Modify the definition of a mixingPlane patch """ - print " Modifying mixingPlane boundary definition in constant/polyMesh/boundary for patch", patchName + print_(" Modifying mixingPlane boundary definition in constant/polyMesh/boundary for patch", patchName) patch["shadowPatch"]=shadowName @@ -166,12 +167,12 @@ Modify the definition of a mixingPlane patch in the time directories for timeDir in listdir(caseDir): if reobj.match(timeDir): - print " Modifying mixingPlane boundaryFields in timeDir", timeDir, "for patch", patchName + print_(" Modifying mixingPlane boundaryFields in timeDir", timeDir, "for patch", patchName) td=TimeDirectory(caseDir, timeDir, yieldParsedFiles=True) for f in td: - print " Modifying field", f.name + print_(" Modifying field", f.name) f["boundaryField"][patchName]["type"]='mixingPlane' f.writeFile() @@ -179,13 +180,13 @@ Modify the definition of a mixingPlane patch in the time directories fName=self.parser.getArgs()[0] masterbName=self.parser.getArgs()[1] shadowbName=self.parser.getArgs()[2] - + boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True,backup=True) bnd=boundary.content if type(bnd)!=list: - print "Problem with boundary file (not a list)" + print_("Problem with boundary file (not a list)") sys.exit(-1) masterFound=False @@ -197,7 +198,7 @@ Modify the definition of a mixingPlane patch in the time directories timeDirs=self.parser.getOptions().timeDirs updateTimeDirs=True - print "UpdateTimeDirs: ", updateTimeDirs + print_("UpdateTimeDirs: ", updateTimeDirs) for index in range(len(bnd)): @@ -233,9 +234,6 @@ Modify the definition of a mixingPlane patch in the time directories self.error("Boundary patch",shadowbName,"not found in",bnd[::2]) if self.parser.getOptions().test: - print boundary + print_(boundary) else: boundary.writeFile() - - - diff --git a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamChangeGGIBoundary.py b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamChangeGGIBoundary.py index 947cf69f9..32c753004 100755 --- a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamChangeGGIBoundary.py +++ b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamChangeGGIBoundary.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from PyFoam.Applications.ChangeGGIBoundary import ChangeGGIBoundary +from PyFoam.Site.ChangeGGIBoundary import ChangeGGIBoundary ChangeGGIBoundary() diff --git a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamChangeMixingPlaneBoundary.py b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamChangeMixingPlaneBoundary.py index f8ba07c1b..2aa0190a6 100755 --- a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamChangeMixingPlaneBoundary.py +++ b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamChangeMixingPlaneBoundary.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from PyFoam.Applications.ChangeMixingPlaneBoundary import ChangeMixingPlaneBoundary +from PyFoam.Site.ChangeMixingPlaneBoundary import ChangeMixingPlaneBoundary ChangeMixingPlaneBoundary() diff --git a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamConvertMixingPlaneBoundaryToNewSyntax.py b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamConvertMixingPlaneBoundaryToNewSyntax.py index bbad29034..5d6540e35 100755 --- a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamConvertMixingPlaneBoundaryToNewSyntax.py +++ b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamConvertMixingPlaneBoundaryToNewSyntax.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from PyFoam.Applications.ConvertMixingPlaneBoundaryToNewSyntax import ConvertMixingPlaneBoundaryToNewSyntax +from PyFoam.Site.ConvertMixingPlaneBoundaryToNewSyntax import ConvertMixingPlaneBoundaryToNewSyntax ConvertMixingPlaneBoundaryToNewSyntax() diff --git a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamInitGgiInterface.py b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamInitGgiInterface.py index 29ebd2830..5a55e886c 100755 --- a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamInitGgiInterface.py +++ b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamInitGgiInterface.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from PyFoam.Applications.InitGgiInterface import InitGgiInterface +from PyFoam.Site.InitGgiInterface import InitGgiInterface InitGgiInterface() diff --git a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamInitMixingPlaneInterface.py b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamInitMixingPlaneInterface.py index e822fe16e..211d83bea 100755 --- a/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamInitMixingPlaneInterface.py +++ b/ThirdParty/LocalDev/Hydro-Quebec/PyFoam/pyFoamInitMixingPlaneInterface.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from PyFoam.Applications.InitMixingPlaneInterface import InitMixingPlaneInterface +from PyFoam.Site.InitMixingPlaneInterface import InitMixingPlaneInterface InitMixingPlaneInterface()