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

Source Code for Module PyFoam.Applications.CreateBoundaryPatches

  1  #  ICE Revision: $Id: ReadDictionary.py 7581 2007-06-27 15:29:14Z bgschaid $  
  2  """ 
  3  Application class that implements pyFoamCreateBoundaryPatches.py 
  4  """ 
  5   
  6  import re 
  7  from os import path 
  8   
  9  from PyFoamApplication import PyFoamApplication 
 10   
 11  from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile 
 12  from PyFoam.RunDictionary.BoundaryDict import BoundaryDict 
 13  from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory 
 14   
15 -class CreateBoundaryPatches(PyFoamApplication):
16 - def __init__(self,args=None):
17 description=""" 18 Takes a field-file. Looks up the polyMesh/boundary-file of the case 19 and adds the corresponding patches to the boundary field setting it to 20 zeroGradient for all patches and walls 21 """ 22 23 PyFoamApplication.__init__(self,args=args,description=description,usage="%prog [options] <fieldfile>",nr=1,interspersed=True)
24
25 - def addOptions(self):
26 self.parser.add_option("--clear-unused", 27 action="store_true", 28 default=None, 29 dest="clear", 30 help="Removes all the boundaries that are not in the boundary-file") 31 self.parser.add_option("--no-check", 32 action="store_true", 33 default=None, 34 dest="nocheck", 35 help="Doesn't check whether the boundary tests are consistent") 36 37 self.parser.add_option("--test", 38 action="store_true", 39 default=None, 40 dest="test", 41 help="Does not write the file but only prints it to the screen") 42 43 self.parser.add_option("--verbose", 44 action="store_true", 45 default=None, 46 dest="verbose", 47 help="Writes to the screen what is being modified") 48 49 self.parser.add_option("--default", 50 action="store", 51 default="{'type':'zeroGradient'}", 52 dest="default", 53 help="The default value for newly created patches as a Python-dictionary (instead of '{ \"type\" : \"zeroGradient\" }')") 54 55 self.parser.add_option("--filter", 56 action="store", 57 default=None, 58 dest="filter", 59 help="A regular expression by which patch names are filtered before they are set") 60 61 self.parser.add_option("--overwrite", 62 action="store_true", 63 default=False, 64 dest="overwrite", 65 help="Overwrites existing boundary conditions") 66 67 self.parser.add_option("--fix-types", 68 action="store_true", 69 default=False, 70 dest="fixtypes", 71 help="Fix inconsistencies")
72
73 - def run(self):
74 fName=self.parser.getArgs()[0] 75 76 try: 77 dictFile=ParsedParameterFile(fName,backup=False) 78 except IOError,e: 79 self.error("Problem with file",fName,":",e) 80 81 fName=path.abspath(fName) 82 case=path.dirname(path.dirname(fName)) 83 region=None 84 85 if not SolutionDirectory(case,archive=None,paraviewLink=False).isValid(): 86 # checking for a multi-region case 87 case=path.dirname(case) 88 region=path.basename(path.dirname(fName)) 89 print case,region 90 if region not in SolutionDirectory(case,archive=None,paraviewLink=False).getRegions(): 91 self.error(region,"is not a valid region in the case",case) 92 93 if self.opts.filter==None: 94 flter=re.compile(".+") 95 else: 96 flter=re.compile(self.opts.filter) 97 98 boundaries=dictFile["boundaryField"] 99 100 bFile=BoundaryDict(case,region=region) 101 102 if self.opts.clear: 103 for b in boundaries.keys(): 104 if b not in bFile.patches(): 105 if self.opts.verbose: 106 print "Deleting patch",b 107 del boundaries[b] 108 109 if not self.opts.nocheck: 110 for p in bFile.patches(): 111 if boundaries.has_key(p): 112 typ=boundaries[p]["type"] 113 pTyp=bFile[p]["type"] 114 if pTyp!="patch" and pTyp!="wall" and pTyp!=typ: 115 if self.opts.fixtypes: 116 if self.opts.verbose: 117 print "Fixing wall/patch patch",p 118 del boundaries[p] 119 continue 120 else: 121 self.error("Inconsistent type for ",p,": Is",typ,"but should be",pTyp) 122 if typ in ["symmetryPlane","empty","wedge","cyclic","processor"] and pTyp!=typ: 123 if self.opts.fixtypes: 124 if self.opts.verbose: 125 print "Fixing special patch",p 126 del boundaries[p] 127 continue 128 else: 129 self.error("Inconsistent type for ",p,": Is",typ,"but should be some kind of patch type") 130 131 for p in bFile.patches(): 132 if (not boundaries.has_key(p) or self.opts.overwrite) and flter.match(p): 133 pTyp=bFile[p]["type"] 134 if pTyp!="patch" and pTyp!="wall": 135 tmp={"type":pTyp} 136 else: 137 tmp=eval(self.opts.default) 138 if self.opts.verbose: 139 print "Writing",tmp,"to patch",p 140 boundaries[p]=tmp; 141 142 if self.opts.test: 143 print str(dictFile) 144 else: 145 dictFile.writeFile()
146