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

Source Code for Module PyFoam.Applications.ChangeBoundaryType

 1  #  ICE Revision: $Id: ChangeBoundaryType.py 8219 2007-11-22 18:40:00Z bgschaid $ 
 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 PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile 
11  from PyFoam.RunDictionary.ListFile import ListFile 
12   
13 -class ChangeBoundaryType(PyFoamApplication):
14 - def __init__(self,args=None):
15 description=""" 16 Changes the type of a boundary in the boundary-file 17 """ 18 PyFoamApplication.__init__(self,args=args, 19 description=description, 20 usage="%prog <caseDirectory> <boundaryName> <new type>", 21 nr=3, 22 interspersed=True)
23
24 - def addOptions(self):
25 self.parser.add_option("--test", 26 action="store_true", 27 default=False, 28 dest="test", 29 help="Only print the new boundary file")
30
31 - def run(self):
32 fName=self.parser.getArgs()[0] 33 bName=self.parser.getArgs()[1] 34 tName=self.parser.getArgs()[2] 35 36 boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True) 37 38 bnd=boundary.content 39 40 if type(bnd)!=list: 41 print "Problem with boundary file (not a list)" 42 sys.exit(-1) 43 44 found=False 45 46 for val in bnd: 47 if val==bName: 48 found=True 49 elif found: 50 val["type"]=tName 51 break 52 53 if not found: 54 print "Boundary",bName,"not found in",bnd[::2] 55 sys.exit(-1) 56 57 if self.opts.test: 58 print boundary 59 else: 60 boundary.writeFile()
61