Package PyFoam :: Package Applications :: Module ChangeBoundaryType
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.ChangeBoundaryType

 1  #  ICE Revision: $Id:$ 
 2  """ 
 3  Application class that implements pyFoamChangeBoundaryType.py 
 4  """ 
 5   
 6  from PyFoamApplication import PyFoamApplication 
 7   
 8  from os import path 
 9  import sys 
10  from optparse import OptionGroup 
11   
12  from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile 
13  from PyFoam.RunDictionary.ListFile import ListFile 
14   
15 -class ChangeBoundaryType(PyFoamApplication):
16 - def __init__(self,args=None):
17 description="""\ 18 Changes the type of a boundary in the boundary-file 19 """ 20 PyFoamApplication.__init__(self,args=args, 21 description=description, 22 usage="%prog <caseDirectory> <boundaryName> <new type>", 23 changeVersion=False, 24 nr=3, 25 interspersed=True)
26
27 - def addOptions(self):
28 change=OptionGroup(self.parser, 29 "Change", 30 "Change specific options") 31 self.parser.add_option_group(change) 32 33 change.add_option("--test", 34 action="store_true", 35 default=False, 36 dest="test", 37 help="Only print the new boundary file")
38
39 - def run(self):
40 fName=self.parser.getArgs()[0] 41 bName=self.parser.getArgs()[1] 42 tName=self.parser.getArgs()[2] 43 44 boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True) 45 46 bnd=boundary.content 47 48 if type(bnd)!=list: 49 self.error("Problem with boundary file (not a list)") 50 51 found=False 52 53 for val in bnd: 54 if val==bName: 55 found=True 56 elif found: 57 val["type"]=tName 58 break 59 60 if not found: 61 self.error("Boundary",bName,"not found in",bnd[::2]) 62 63 if self.opts.test: 64 print boundary 65 else: 66 boundary.writeFile() 67 self.addToCaseLog(fName)
68