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

Source Code for Module PyFoam.Applications.ChangeBoundaryName

 1  """ 
 2  Application class that implements pyFoamChangeBoundaryName.py 
 3   
 4  Author: 
 5    Martin Beaudoin, Hydro-Quebec, 2010. 
 6   
 7  """ 
 8   
 9  from PyFoamApplication import PyFoamApplication 
10   
11  from os import path 
12  import sys 
13  from optparse import OptionGroup 
14   
15  from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile 
16  from PyFoam.RunDictionary.TimeDirectory import TimeDirectory 
17   
18 -class ChangeBoundaryName(PyFoamApplication):
19 - def __init__(self,args=None):
20 description=""" 21 Changes the name of a boundary in the boundary-file. Also if a time-step is specified 22 """ 23 PyFoamApplication.__init__(self,args=args, 24 description=description, 25 usage="%prog <caseDirectory> <boundaryName> <new name>", 26 changeVersion=False, 27 nr=3, 28 interspersed=True)
29
30 - def addOptions(self):
31 change=OptionGroup(self.parser, 32 "Change", 33 "Change specific options") 34 self.parser.add_option_group(change) 35 change.add_option("--test", 36 action="store_true", 37 default=False, 38 dest="test", 39 help="Only print the new boundary file") 40 change.add_option("--time-step", 41 action="store", 42 default=None, 43 dest="timestep", 44 help="If specified all the field-files in that directory are updated")
45
46 - def run(self):
47 fName=self.parser.getArgs()[0] 48 bName=self.parser.getArgs()[1] 49 nName=self.parser.getArgs()[2] 50 51 boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True) 52 53 bnd=boundary.content 54 55 if type(bnd)!=list: 56 self.error("Problem with boundary file (not a list)") 57 58 found=False 59 60 for val in bnd: 61 if val==bName: 62 found=True 63 elif found: 64 bnd[bnd.index(bName)]=nName 65 break 66 67 if not found: 68 self.error("Boundary",bName,"not found in",bnd[::2]) 69 70 if self.opts.test: 71 print boundary 72 else: 73 boundary.writeFile() 74 self.addToCaseLog(fName) 75 76 if self.opts.timestep: 77 print "Updating the files of timestep",self.opts.timestep 78 td=TimeDirectory(fName,self.opts.timestep, 79 yieldParsedFiles=True) 80 81 for f in td: 82 print "Updating",f.name 83 f["boundaryField"][nName]=f["boundaryField"][bName] 84 del f["boundaryField"][bName] 85 f.writeFile()
86