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