1
2 """
3 Application class that implements pyFoamChangeBoundaryType.py
4 """
5
6 from .PyFoamApplication import PyFoamApplication
7
8 from os import path
9 from optparse import OptionGroup
10
11 from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile
12
13 from PyFoam.ThirdParty.six import print_
14
16 - def __init__(self,
17 args=None,
18 **kwargs):
29
31 change=OptionGroup(self.parser,
32 "Change",
33 "Change specific options")
34 self.parser.add_option_group(change)
35
36 change.add_option("--test",
37 action="store_true",
38 default=False,
39 dest="test",
40 help="Only print the new boundary file")
41
42 change.add_option("--region",
43 action="store",
44 default="",
45 dest="region",
46 help="Region to use. If unset the default mesh is used")
47
48 change.add_option("--time-directory",
49 action="store",
50 default="constant",
51 dest="time",
52 help="Time to use. If unset the mesh in 'constant'' is used")
53
55 fName=self.parser.getArgs()[0]
56 bName=self.parser.getArgs()[1]
57 tName=self.parser.getArgs()[2]
58
59 boundaryPath=path.join(".",fName,self.opts.time,self.opts.region,"polyMesh","boundary")
60 try:
61 boundary=ParsedParameterFile(boundaryPath,debug=False,boundaryDict=True)
62 except IOError:
63 self.error("Problem opening boundary file",boundaryPath)
64
65 bnd=boundary.content
66
67 if type(bnd)!=list:
68 self.error("Problem with boundary file (not a list)")
69
70 found=False
71
72 for val in bnd:
73 if val==bName:
74 found=True
75 elif found:
76 val["type"]=tName
77 break
78
79 if not found:
80 self.error("Boundary",bName,"not found in",bnd[::2])
81
82 if self.opts.test:
83 print_(boundary)
84 else:
85 boundary.writeFile()
86 self.addToCaseLog(fName)
87
88
89