Package PyFoam :: Package Applications :: Module ModifyGGIBoundary
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.ModifyGGIBoundary

  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 re 
 16   
 17  from PyFoam.ThirdParty.six import print_ 
 18   
19 -class ModifyGGIBoundary(PyFoamApplication):
20 - def __init__(self, 21 args=None, 22 **kwargs):
23 description="""\ 24 Modify GGI boundary condition parameters 25 """ 26 PyFoamApplication.__init__(self, 27 args=args, 28 description=description, 29 usage="%prog <caseDirectory> ggiPatchName", 30 interspersed=True, 31 changeVersion=False, 32 nr=2, 33 **kwargs)
34
35 - def addOptions(self):
36 self.parser.add_option("--shadowName", 37 action="store", 38 dest="shadowName", 39 default=None, 40 help='Name of the shadowPatch') 41 self.parser.add_option("--patchZoneName", 42 action="store", 43 dest="patchZoneName", 44 default=None, 45 help='Name of the zone for the GGI patch') 46 self.parser.add_option("--bridgeOverlapFlag", 47 action="store", 48 dest="bridgeOverlapFlag", 49 default=None, 50 help='bridgeOverlap flag (on/off)') 51 self.parser.add_option("--rotationAxis", 52 action="store", 53 dest="rotationAxis", 54 default=None, 55 help='rotation axis for cyclicGgi') 56 self.parser.add_option("--rotationAngle", 57 action="store", 58 dest="rotationAngle", 59 default=None, 60 help='rotation axis angle for cyclicGgi') 61 self.parser.add_option("--separationOffset", 62 action="store", 63 dest="separationOffset", 64 default=None, 65 help='separation offset for cyclicGgi') 66 67 self.parser.add_option("--test", 68 action="store_true", 69 default=False, 70 dest="test", 71 help="Only print the new boundary file")
72
73 - def run(self):
74 fName=self.parser.getArgs()[0] 75 bName=self.parser.getArgs()[1] 76 77 boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True) 78 79 bnd=boundary.content 80 81 if type(bnd)!=list: 82 self.error("Problem with boundary file (not a list)") 83 84 found=False 85 86 for val in bnd: 87 if val==bName: 88 found=True 89 elif found: 90 bcType=val["type"] 91 if re.match("cyclicGgi", bcType)!= None or re.match("ggi", bcType)!= None: 92 if self.parser.getOptions().shadowName!=None: 93 shadowName=self.parser.getOptions().shadowName 94 val["shadowPatch"]=shadowName 95 if shadowName not in bnd: 96 print_("Warning: Setting the shadowName option for patch",bName,": there is no patch called",shadowName) 97 print_(" The boundary file was still modified for patch",bName) 98 99 if self.parser.getOptions().patchZoneName!=None: 100 val["zone"]=self.parser.getOptions().patchZoneName 101 102 if self.parser.getOptions().bridgeOverlapFlag!=None: 103 val["bridgeOverlap"]=self.parser.getOptions().bridgeOverlapFlag 104 105 if val["type"]=="cyclicGgi": 106 if self.parser.getOptions().rotationAxis!=None: 107 val["rotationAxis"]=self.parser.getOptions().rotationAxis 108 109 if self.parser.getOptions().rotationAngle!=None: 110 val["rotationAngle"]=self.parser.getOptions().rotationAngle 111 112 if self.parser.getOptions().separationOffset!=None: 113 val["separationOffset"]=self.parser.getOptions().separationOffset 114 else: 115 print_("Unsupported GGI type '",bcType,"' for patch",bName) 116 break 117 118 if not found: 119 self.error("Boundary",bName,"not found in",bnd[::2]) 120 121 if self.parser.getOptions().test: 122 print_(boundary) 123 else: 124 boundary.writeFile()
125 126 # Should work with Python3 and Python2 127