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

Source Code for Module PyFoam.Applications.ClearInternalField

 1  #  ICE Revision: $Id: ReadDictionary.py 7581 2007-06-27 15:29:14Z bgschaid $  
 2  """ 
 3  Application class that implements pyFoamClearInternalField.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   
13 -class ClearInternalField(PyFoamApplication):
14 - def __init__(self,args=None):
15 description=""" 16 Takes a field-file and makes the whole internal field uniform. Either taking 17 the value from a patch or using a user-specified value 18 """ 19 20 PyFoamApplication.__init__(self,args=args,description=description,usage="%prog [options] <fieldfile>",nr=1,interspersed=True)
21
22 - def addOptions(self):
23 self.parser.add_option("--patch", 24 action="store", 25 default=None, 26 dest="patch", 27 help="The name of the patch that should provide the value") 28 self.parser.add_option("--value", 29 action="store", 30 default=None, 31 dest="value", 32 help="The value that should be used for the internal field") 33 self.parser.add_option("--test", 34 action="store_true", 35 default=None, 36 dest="test", 37 help="Does not write the file but only prints it to the screen")
38 39
40 - def run(self):
41 fName=self.parser.getArgs()[0] 42 43 if self.opts.patch==None and self.opts.value==None: 44 self.error("Either a patch or a value must be specified") 45 if self.opts.patch!=None and self.opts.value!=None: 46 self.error("Only a patch or a value can be specified") 47 48 try: 49 fieldFile=ParsedParameterFile(fName,backup=False) 50 except IOError,e: 51 self.error("Problem with file",fName,":",e) 52 53 value="" 54 if self.opts.patch: 55 value=fieldFile["boundaryField"][self.opts.patch]["value"] 56 else: 57 value="uniform "+self.opts.value 58 59 fieldFile["internalField"]=value 60 61 if self.opts.test: 62 print str(fieldFile) 63 else: 64 fieldFile.writeFile()
65