1
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
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 changeVersion=False,
22 nr=3,
23 interspersed=True)
24
26 self.parser.add_option("--test",
27 action="store_true",
28 default=False,
29 dest="test",
30 help="Only print the new boundary file")
31
33 fName=self.parser.getArgs()[0]
34 bName=self.parser.getArgs()[1]
35 tName=self.parser.getArgs()[2]
36
37 boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True)
38
39 bnd=boundary.content
40
41 if type(bnd)!=list:
42 print "Problem with boundary file (not a list)"
43 sys.exit(-1)
44
45 found=False
46
47 for val in bnd:
48 if val==bName:
49 found=True
50 elif found:
51 val["type"]=tName
52 break
53
54 if not found:
55 print "Boundary",bName,"not found in",bnd[::2]
56 sys.exit(-1)
57
58 if self.opts.test:
59 print boundary
60 else:
61 boundary.writeFile()
62