1 """
2 Application-class that implements pyFoamModifyGGIBoundary.py
3
4 Modification of GGI and cyclicGGI interface parameters in
5 constant/polymesh/boundary file.
6
7 Author:
8 Martin Beaudoin, Hydro-Quebec, 2009. All rights reserved
9
10 """
11
12 from PyFoamApplication import PyFoamApplication
13 from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile
14 from os import path
15 import sys
16 import re
17
30
32 self.parser.add_option("--shadowName",
33 action="store",
34 dest="shadowName",
35 default=None,
36 help='Name of the shadowPatch')
37 self.parser.add_option("--patchZoneName",
38 action="store",
39 dest="patchZoneName",
40 default=None,
41 help='Name of the zone for the GGI patch')
42 self.parser.add_option("--bridgeOverlapFlag",
43 action="store",
44 dest="bridgeOverlapFlag",
45 default=None,
46 help='bridgeOverlap flag (on/off)')
47 self.parser.add_option("--rotationAxis",
48 action="store",
49 dest="rotationAxis",
50 default=None,
51 help='rotation axis for cyclicGgi')
52 self.parser.add_option("--rotationAngle",
53 action="store",
54 dest="rotationAngle",
55 default=None,
56 help='rotation axis angle for cyclicGgi')
57 self.parser.add_option("--separationOffset",
58 action="store",
59 dest="separationOffset",
60 default=None,
61 help='separation offset for cyclicGgi')
62
63 self.parser.add_option("--test",
64 action="store_true",
65 default=False,
66 dest="test",
67 help="Only print the new boundary file")
68
70 fName=self.parser.getArgs()[0]
71 bName=self.parser.getArgs()[1]
72
73 boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True)
74
75 bnd=boundary.content
76
77 if type(bnd)!=list:
78 print "Problem with boundary file (not a list)"
79 sys.exit(-1)
80
81 found=False
82
83 for val in bnd:
84 if val==bName:
85 found=True
86 elif found:
87 bcType=val["type"]
88 if re.match("cyclicGgi", bcType)!= None or re.match("ggi", bcType)!= None:
89 if self.parser.getOptions().shadowName!=None:
90 shadowName=self.parser.getOptions().shadowName
91 val["shadowPatch"]=shadowName
92 if shadowName not in bnd:
93 print "Warning: Setting the shadowName option for patch",bName,": there is no patch called",shadowName
94 print " The boundary file was still modified for patch",bName
95
96 if self.parser.getOptions().patchZoneName!=None:
97 val["zone"]=self.parser.getOptions().patchZoneName
98
99 if self.parser.getOptions().bridgeOverlapFlag!=None:
100 val["bridgeOverlap"]=self.parser.getOptions().bridgeOverlapFlag
101
102 if val["type"]=="cyclicGgi":
103 if self.parser.getOptions().rotationAxis!=None:
104 val["rotationAxis"]=self.parser.getOptions().rotationAxis
105
106 if self.parser.getOptions().rotationAngle!=None:
107 val["rotationAngle"]=self.parser.getOptions().rotationAngle
108
109 if self.parser.getOptions().separationOffset!=None:
110 val["separationOffset"]=self.parser.getOptions().separationOffset
111 else:
112 print "Unsupported GGI type '",bcType,"' for patch",bName
113 break
114
115 if not found:
116 print "Boundary",bName,"not found in",bnd[::2]
117 sys.exit(-1)
118
119 if self.parser.getOptions().test:
120 print boundary
121 else:
122 boundary.writeFile()
123