Package PyFoam :: Package Site :: Module InitMixingPlaneInterface
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Site.InitMixingPlaneInterface

  1  """ 
  2  Application-class that implements pyFoamInitMixingPlaneInterface.py 
  3   
  4  Initialize various mixingPlane interface attributes in the 
  5  constant/polymesh/boundary file, and in the time directories. 
  6   
  7  Backups of the modified files are created 
  8   
  9  Author: 
 10    Martin Beaudoin, Hydro-Quebec, 2012.  All rights reserved 
 11   
 12  """ 
 13   
 14  from PyFoam.Applications.PyFoamApplication import PyFoamApplication 
 15  from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile 
 16  from PyFoam.RunDictionary.TimeDirectory import TimeDirectory 
 17  from PyFoam.ThirdParty.six import print_ 
 18  from os import path, listdir 
 19  import sys, fnmatch, re 
 20   
21 -class InitMixingPlaneInterface(PyFoamApplication):
22 - def __init__(self,args=None):
23 description=""" 24 Init MixingPlane boundary condition parameters 25 """ 26 PyFoamApplication.__init__(self, 27 args=args, 28 description=description, 29 usage="%prog <caseDirectory> mixingPlane_MasterPatchName mixingPlane_ShadowPatchName", 30 interspersed=True, 31 changeVersion=False, 32 nr=3)
33
34 - def addOptions(self):
35 # No need for option --shadowPatch since the name of the shadowPatch is a mandatory parameter to the script 36 #self.parser.add_option("--shadowPatch", 37 # action="store", 38 # dest="shadowPatch", 39 # default=None, 40 # help='Name of the shadowPatch') 41 self.parser.add_option("--coordinateSystemName", 42 action="store", 43 dest="coordinateSystemName", 44 default="mixingCS", 45 help='coordinateSystemName (mixingCS)') 46 self.parser.add_option("--coordinateSystemType", 47 action="store", 48 dest="coordinateSystemType", 49 default=None, 50 help='coordinateSystemType (cyindrical/spherical)') 51 self.parser.add_option("--coordinateSystemOrigin", 52 action="store", 53 dest="coordinateSystemOrigin", 54 default=None, 55 help='origin for coordinate system of mixingPlane') 56 self.parser.add_option("--coordinateSystemE1", 57 action="store", 58 dest="coordinateSystemE1", 59 default=None, 60 help='axis E1 for coordinate system of mixingPlane') 61 self.parser.add_option("--coordinateSystemE3", 62 action="store", 63 dest="coordinateSystemE3", 64 default=None, 65 help='axis E3 for coordinate system of mixingPlane') 66 self.parser.add_option("--ribbonPatchSweepAxis", 67 action="store", 68 dest="ribbonPatchSweepAxis", 69 default=None, 70 help='ribbonPatch sweepAxis (X|Y|Z|R|Theta') 71 self.parser.add_option("--ribbonPatchStackAxis", 72 action="store", 73 dest="ribbonPatchStackAxis", 74 default=None, 75 help='ribbonPatch stackAxis (X|Y|Z|R|Theta') 76 self.parser.add_option("--ribbonPatchDiscretisation", 77 action="store", 78 dest="ribbonPatchDiscretisation", 79 default=None, 80 help='ribbonPatch discretisation (masterPatch|slavePatch|bothPatches|uniform|userDefined)') 81 82 self.parser.add_option("--timeDirs", 83 action="store", 84 dest="timeDirs", 85 default=None, 86 help='time directories for the mixingPlane boundaryfields. Accept expressions like "[0-9]*", "0", etc.') 87 88 self.parser.add_option("--test", 89 action="store_true", 90 default=False, 91 dest="test", 92 help="Only print the new boundary file")
93
94 - def createMixingPlanePatch(self, patch, patchName):
95 description="""\ 96 Create a default definition for a mixingPlane patch, and replace 97 the current definition 98 """ 99 print_("Replacing definition of patch: ", patchName, ":", patch) 100 newPatch={ 101 'type' : "mixingPlane", 102 'nFaces' : patch["nFaces"], 103 'startFace' : patch["startFace"], 104 'shadowPatch' : 'unknown', 105 'coordinateSystem' : { 106 'name' : 'mixingCS', 107 'type' : 'cylindrical', 108 'origin' : '(0 0 0)', 109 'e1' : '(1 0 0)', 110 'e3' : '(0 0 1)' 111 }, 112 'ribbonPatch' : { 113 'sweepAxis' : 'Theta', 114 'stackAxis' : 'Z', 115 'discretisation' : 'bothPatches', 116 } 117 } 118 return newPatch
119
120 - def modifyMixinPlanePatchDefinition(self, patch, patchName, shadowName):
121 description="""\ 122 Modify the definition of a mixingPlane patch 123 """ 124 print_(" Modifying mixingPlane boundary definition in constant/polyMesh/boundary for patch", patchName) 125 126 patch["shadowPatch"]=shadowName 127 128 if patch.has_key("coordinateSystem")==False: 129 patch["coordinateSystem"]={} 130 131 if self.parser.getOptions().coordinateSystemName!=None: 132 patch["coordinateSystem"]["name"]=self.parser.getOptions().coordinateSystemName 133 134 if self.parser.getOptions().coordinateSystemType!=None: 135 patch["coordinateSystem"]["type"]=self.parser.getOptions().coordinateSystemType 136 137 if self.parser.getOptions().coordinateSystemOrigin!=None: 138 patch["coordinateSystem"]["origin"]=self.parser.getOptions().coordinateSystemOrigin 139 140 if self.parser.getOptions().coordinateSystemE1!=None: 141 patch["coordinateSystem"]["e1"]=self.parser.getOptions().coordinateSystemE1 142 143 if self.parser.getOptions().coordinateSystemE3!=None: 144 patch["coordinateSystem"]["e3"]=self.parser.getOptions().coordinateSystemE3 145 146 if patch.has_key("ribbonPatch")==False: 147 patch["ribbonPatch"]={} 148 149 if self.parser.getOptions().ribbonPatchSweepAxis!=None: 150 patch["ribbonPatch"]["sweepAxis"]=self.parser.getOptions().ribbonPatchSweepAxis 151 152 if self.parser.getOptions().ribbonPatchStackAxis!=None: 153 patch["ribbonPatch"]["stackAxis"]=self.parser.getOptions().ribbonPatchStackAxis 154 155 if self.parser.getOptions().ribbonPatchDiscretisation!=None: 156 patch["ribbonPatch"]["discretisation"]=self.parser.getOptions().ribbonPatchDiscretisation
157 158 159
160 - def modifyMixinPlanePatchDefinitionInTimeDirs(self, caseDir, patchName, timeDirs):
161 description="""\ 162 Modify the definition of a mixingPlane patch in the time directories 163 """ 164 regex = fnmatch.translate(timeDirs) 165 166 reobj = re.compile(regex) 167 168 for timeDir in listdir(caseDir): 169 if reobj.match(timeDir): 170 print_(" Modifying mixingPlane boundaryFields in timeDir", timeDir, "for patch", patchName) 171 172 td=TimeDirectory(caseDir, timeDir, yieldParsedFiles=True) 173 174 for f in td: 175 print_(" Modifying field", f.name) 176 f["boundaryField"][patchName]["type"]='mixingPlane' 177 f.writeFile()
178
179 - def run(self):
180 fName=self.parser.getArgs()[0] 181 masterbName=self.parser.getArgs()[1] 182 shadowbName=self.parser.getArgs()[2] 183 184 boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True,backup=True) 185 186 bnd=boundary.content 187 188 if type(bnd)!=list: 189 print_("Problem with boundary file (not a list)") 190 sys.exit(-1) 191 192 masterFound=False 193 shadowFound=False 194 updateTimeDirs=False 195 196 timeDirs="0" 197 if self.parser.getOptions().timeDirs!=None: 198 timeDirs=self.parser.getOptions().timeDirs 199 updateTimeDirs=True 200 201 print_("UpdateTimeDirs: ", updateTimeDirs) 202 203 for index in range(len(bnd)): 204 205 indexDefPatch=index+1 206 207 if bnd[index]==masterbName: 208 masterFound=True 209 if bnd[indexDefPatch]["type"]!="mixingPlane": 210 bnd[indexDefPatch] = self.createMixingPlanePatch(bnd[indexDefPatch], masterbName) 211 212 self.modifyMixinPlanePatchDefinition(bnd[indexDefPatch], masterbName, shadowbName) 213 214 if updateTimeDirs: 215 self.modifyMixinPlanePatchDefinitionInTimeDirs(fName, masterbName, timeDirs) 216 217 elif bnd[index]==shadowbName: 218 shadowFound=True 219 if bnd[indexDefPatch]["type"]!="mixingPlane": 220 bnd[indexDefPatch] = self.createMixingPlanePatch(bnd[indexDefPatch], shadowbName) 221 222 self.modifyMixinPlanePatchDefinition(bnd[indexDefPatch], shadowbName, masterbName) 223 224 if updateTimeDirs: 225 self.modifyMixinPlanePatchDefinitionInTimeDirs(fName, shadowbName, timeDirs) 226 227 if masterFound and shadowFound: 228 break; 229 230 if not masterFound: 231 self.error("Boundary patch",masterbName,"not found in",bnd[::2]) 232 233 if not shadowFound: 234 self.error("Boundary patch",shadowbName,"not found in",bnd[::2]) 235 236 if self.parser.getOptions().test: 237 print_(boundary) 238 else: 239 boundary.writeFile()
240