1 """
2 Application-class that implements pyFoamChangeMixingPlaneBoundary.py
3
4 Change various mixingPlane interface attributes in
5 constant/polymesh/boundary file.
6
7 Author:
8 Martin Beaudoin, Hydro-Quebec, 2012. All rights reserved
9
10 """
11
12 from PyFoam.Applications.PyFoamApplication import PyFoamApplication
13 from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile
14 from PyFoam.ThirdParty.six import print_
15 from os import path
16 import sys
17
30
32 self.parser.add_option("--shadowPatch",
33 action="store",
34 dest="shadowPatch",
35 default=None,
36 help='Name of the shadowPatch')
37 self.parser.add_option("--zone",
38 action="store",
39 dest="zone",
40 default=None,
41 help='Name of the zone for mixingPlanePatch')
42 self.parser.add_option("--coordinateSystemName",
43 action="store",
44 dest="coordinateSystemName",
45 default="mixingCS",
46 help='coordinateSystemName (mixingCS)')
47 self.parser.add_option("--coordinateSystemType",
48 action="store",
49 dest="coordinateSystemType",
50 default=None,
51 help='coordinateSystemType (cyindrical/spherical)')
52 self.parser.add_option("--coordinateSystemOrigin",
53 action="store",
54 dest="coordinateSystemOrigin",
55 default=None,
56 help='origin for coordinate system of mixingPlane')
57 self.parser.add_option("--coordinateSystemE1",
58 action="store",
59 dest="coordinateSystemE1",
60 default=None,
61 help='axis E1 for coordinate system of mixingPlane')
62 self.parser.add_option("--coordinateSystemE3",
63 action="store",
64 dest="coordinateSystemE3",
65 default=None,
66 help='axis E3 for coordinate system of mixingPlane')
67 self.parser.add_option("--ribbonPatchSweepAxis",
68 action="store",
69 dest="ribbonPatchSweepAxis",
70 default=None,
71 help='ribbonPatch sweepAxis (X|Y|Z|R|Theta')
72 self.parser.add_option("--ribbonPatchStackAxis",
73 action="store",
74 dest="ribbonPatchStackAxis",
75 default=None,
76 help='ribbonPatch stackAxis (X|Y|Z|R|Theta')
77 self.parser.add_option("--ribbonPatchDiscretisation",
78 action="store",
79 dest="ribbonPatchDiscretisation",
80 default=None,
81 help='ribbonPatch discretisation (masterPatch|slavePatch|bothPatches|uniform|userDefined)')
82
83 self.parser.add_option("--test",
84 action="store_true",
85 default=False,
86 dest="test",
87 help="Only print the new boundary file")
88
90 fName=self.parser.getArgs()[0]
91 bName=self.parser.getArgs()[1]
92
93 boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True)
94
95 bnd=boundary.content
96
97 if type(bnd)!=list:
98 print_("Problem with boundary file (not a list)")
99 sys.exit(-1)
100
101 found=False
102
103 for val in bnd:
104 if val==bName:
105 found=True
106 elif found:
107 if val["type"]=="mixingPlane":
108 if self.parser.getOptions().shadowPatch!=None:
109 val["shadowPatch"]=self.parser.getOptions().shadowPatch
110
111 if self.parser.getOptions().zone!=None:
112 val["zone"]=self.parser.getOptions().zone
113
114 if val.has_key("coordinateSystem")==False:
115 val["coordinateSystem"]={}
116
117 if self.parser.getOptions().coordinateSystemName!=None:
118 val["coordinateSystem"]["name"]=self.parser.getOptions().coordinateSystemName
119
120 if self.parser.getOptions().coordinateSystemType!=None:
121 val["coordinateSystem"]["type"]=self.parser.getOptions().coordinateSystemType
122
123 if self.parser.getOptions().coordinateSystemOrigin!=None:
124 val["coordinateSystem"]["origin"]=self.parser.getOptions().coordinateSystemOrigin
125
126 if self.parser.getOptions().coordinateSystemE1!=None:
127 val["coordinateSystem"]["e1"]=self.parser.getOptions().coordinateSystemE1
128
129 if self.parser.getOptions().coordinateSystemE3!=None:
130 val["coordinateSystem"]["e3"]=self.parser.getOptions().coordinateSystemE3
131
132 if val.has_key("ribbonPatch")==False:
133 val["ribbonPatch"]={}
134
135 if self.parser.getOptions().ribbonPatchSweepAxis!=None:
136 val["ribbonPatch"]["sweepAxis"]=self.parser.getOptions().ribbonPatchSweepAxis
137
138 if self.parser.getOptions().ribbonPatchStackAxis!=None:
139 val["ribbonPatch"]["stackAxis"]=self.parser.getOptions().ribbonPatchStackAxis
140
141 if self.parser.getOptions().ribbonPatchDiscretisation!=None:
142 val["ribbonPatch"]["discretisation"]=self.parser.getOptions().ribbonPatchDiscretisation
143
144 break
145
146 if not found:
147 print_("Boundary",bName,"not found in",bnd[::2])
148 sys.exit(-1)
149
150 if self.parser.getOptions().test:
151 print_(boundary)
152 else:
153 boundary.writeFile()
154