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 optparse import OptionGroup
11
12 from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile
13 from PyFoam.RunDictionary.ListFile import ListFile
14
26
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
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