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  from PyFoam.ThirdParty.six import print_ 
16   
17 -class ChangeBoundaryType(PyFoamApplication):
18 - def __init__(self,args=None):
19 description="""\ 20 Changes the type of a boundary in the boundary-file 21 """ 22 PyFoamApplication.__init__(self,args=args, 23 description=description, 24 usage="%prog <caseDirectory> <boundaryName> <new type>", 25 changeVersion=False, 26 nr=3, 27 interspersed=True)
28
29 - def addOptions(self):
30 change=OptionGroup(self.parser, 31 "Change", 32 "Change specific options") 33 self.parser.add_option_group(change) 34 35 change.add_option("--test", 36 action="store_true", 37 default=False, 38 dest="test", 39 help="Only print the new boundary file") 40 41 change.add_option("--region", 42 action="store", 43 default="", 44 dest="region", 45 help="Region to use. If unset the default mesh is used") 46 47 change.add_option("--time-directory", 48 action="store", 49 default="constant", 50 dest="time", 51 help="Time to use. If unset the mesh in 'constant'' is used")
52
53 - def run(self):
54 fName=self.parser.getArgs()[0] 55 bName=self.parser.getArgs()[1] 56 tName=self.parser.getArgs()[2] 57 58 boundaryPath=path.join(".",fName,self.opts.time,self.opts.region,"polyMesh","boundary") 59 try: 60 boundary=ParsedParameterFile(boundaryPath,debug=False,boundaryDict=True) 61 except IOError: 62 self.error("Problem opening boundary file",boundaryPath) 63 64 bnd=boundary.content 65 66 if type(bnd)!=list: 67 self.error("Problem with boundary file (not a list)") 68 69 found=False 70 71 for val in bnd: 72 if val==bName: 73 found=True 74 elif found: 75 val["type"]=tName 76 break 77 78 if not found: 79 self.error("Boundary",bName,"not found in",bnd[::2]) 80 81 if self.opts.test: 82 print_(boundary) 83 else: 84 boundary.writeFile() 85 self.addToCaseLog(fName)
86 87 # Should work with Python3 and Python2 88