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):
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,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("--default", 44 action="store", 45 default="{'type':'zeroGradient'}", 46 dest="default", 47 help="The default value for newly created patches as a Python-dictionary (instead of '{ \"type\" : \"zeroGradient\" }')") 48 49 self.parser.add_option("--filter", 50 action="store", 51 default=None, 52 dest="filter", 53 help="A regular expression by which patch names are filtered before they are set") 54 55 self.parser.add_option("--overwrite", 56 action="store_true", 57 default=False, 58 dest="overwrite", 59 help="Overwrites existing boundary conditions") 60 61 self.parser.add_option("--fix-types", 62 action="store_true", 63 default=False, 64 dest="fixtypes", 65 help="Fix inconsistencies")
66
67 - def run(self):
68 fName=self.parser.getArgs()[0] 69 70 try: 71 dictFile=ParsedParameterFile(fName,backup=False) 72 except IOError,e: 73 self.error("Problem with file",fName,":",e) 74 75 fName=path.abspath(fName) 76 case=path.dirname(path.dirname(fName)) 77 region=None 78 79 if not SolutionDirectory(case).isValid(): 80 # checking for a multi-region case 81 case=path.dirname(case) 82 region=path.basename(path.dirname(fName)) 83 print case,region 84 if region not in SolutionDirectory(case).getRegions(): 85 self.error(region,"is not a valid region in the case",case) 86 87 if self.opts.filter==None: 88 flter=re.compile(".+") 89 else: 90 flter=re.compile(self.opts.filter) 91 92 boundaries=dictFile["boundaryField"] 93 94 bFile=BoundaryDict(case,region=region) 95 96 if self.opts.clear: 97 for b in boundaries.keys(): 98 if b not in bFile.patches(): 99 boundaries.pop(b) 100 101 if not self.opts.nocheck: 102 for p in bFile.patches(): 103 if boundaries.has_key(p): 104 typ=boundaries[p]["type"] 105 pTyp=bFile[p]["type"] 106 if pTyp!="patch" and pTyp!="wall" and pTyp!=typ: 107 if self.opts.fixtypes: 108 del boundaries[p] 109 continue 110 else: 111 self.error("Inconsistent type for ",p,": Is",typ,"but should be",pTyp) 112 if typ in ["symmetryPlane","empty","wedge","cyclic","processor"] and pTyp!=typ: 113 if self.opts.fixtypes: 114 del boundaries[p] 115 continue 116 else: 117 self.error("Inconsistent type for ",p,": Is",typ,"but should be some kind of patch type") 118 119 for p in bFile.patches(): 120 if (not boundaries.has_key(p) or self.opts.overwrite) and flter.match(p): 121 pTyp=bFile[p]["type"] 122 if pTyp!="patch" and pTyp!="wall": 123 tmp={"type":pTyp} 124 else: 125 tmp=eval(self.opts.default) 126 boundaries[p]=tmp; 127 128 if self.opts.test: 129 print str(dictFile) 130 else: 131 dictFile.writeFile()
132