1 """
2 Application-class that implements pyFoamConvertMixingPlaneToNewSyntax.py
3
4 Adjust the mixingPlane interface definition in the boundary
5 file to the latest supported syntax.
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
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
45
47 """Return the match method once, then stop"""
48 yield self.match
49 raise StopIteration
50
52 """Indicate whether or not to enter a case suite"""
53 if self.fall or not args:
54 return True
55 elif self.value in args:
56 self.fall = True
57 return True
58 else:
59 return False
60
61
62
63
64
65
66
67
80
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
92 boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True)
93
94 bnd=boundary.content
95
96 if type(bnd)!=list:
97 print_("Problem with boundary file (not a list)")
98 sys.exit(-1)
99
100 found=False
101
102 for index in range(0, len(bnd), 2):
103
104 indexDefPatch=index+1
105
106 oldAssembly=""
107 oldOrientation=""
108
109 if bnd[indexDefPatch]["type"]=="mixingPlane":
110 if bnd[indexDefPatch].has_key("assembly"):
111 print_(" Replacing the parameter 'assembly' for patch", bnd[index])
112 oldAssembly=bnd[indexDefPatch]["assembly"]
113 del bnd[indexDefPatch]["assembly"]
114
115 if bnd[indexDefPatch].has_key("orientation"):
116 print_(" Replacing the parameter 'orientation' for patch", bnd[index])
117 oldOrientation=bnd[indexDefPatch]["orientation"]
118 del bnd[indexDefPatch]["orientation"]
119
120 if bnd[indexDefPatch].has_key("ribbonPatch")==False:
121 bnd[indexDefPatch]["ribbonPatch"]={}
122
123 if bnd[indexDefPatch].has_key("zone")==False:
124 bnd[indexDefPatch]["zone"]=bnd[index] + "Zone"
125
126 if oldAssembly != "":
127
128 for case in switch(oldAssembly):
129 if case('master'):
130 bnd[indexDefPatch]["ribbonPatch"]["discretisation"]="masterPatch"
131 break
132 if case('slave'):
133 bnd[indexDefPatch]["ribbonPatch"]["discretisation"]="slavePatch"
134 break
135 if case('both'):
136 bnd[indexDefPatch]["ribbonPatch"]["discretisation"]="bothPatches"
137 break
138 if case('userdefined'):
139 bnd[indexDefPatch]["ribbonPatch"]["discretisation"]="userDefined"
140 break
141 if case():
142 print_("Unsupported assembly type: ", oldAssembly)
143
144 if oldOrientation != "":
145
146
147 for case in switch(oldOrientation):
148
149 if case('dirX_spanY'):
150 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="X"
151 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="Y"
152 break
153 if case('dirX_spanZ'):
154 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="X"
155 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="Z"
156 break
157 if case('dirY_spanX'):
158 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="Y"
159 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="X"
160 break
161 if case('dirY_spanZ'):
162 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="Y"
163 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="Z"
164 break
165 if case('dirZ_spanX'):
166 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="Z"
167 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="X"
168 break
169 if case('dirZ_spanY'):
170 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="Z"
171 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="Y"
172 break
173 if case('dirR_spanTheta'):
174 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="R"
175 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="Theta"
176 break
177 if case('dirR_spanZ'):
178 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="R"
179 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="Z"
180 break
181 if case('dirTheta_spanZ'):
182 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="Theta"
183 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="Z"
184 break
185 if case('dirTheta_spanR'):
186 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="Theta"
187 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="R"
188 break
189 if case('dirZ_spanTheta'):
190 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="Z"
191 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="Theta"
192 break
193 if case('dirZ_spanR'):
194 bnd[indexDefPatch]["ribbonPatch"]["stackAxis"]="Z"
195 bnd[indexDefPatch]["ribbonPatch"]["sweepAxis"]="R"
196 break
197 if case():
198 print_("Unsupported orientation type: ", oldOrientation)
199
200 if self.parser.getOptions().test:
201 print_(boundary)
202 else:
203 boundary.writeFile()
204