1
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
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,
21 args=args,
22 description=description,
23 usage="%prog [options] <fieldfile>",
24 changeVersion=False,
25 nr=1,
26 interspersed=True)
27
29 self.parser.add_option("--patch",
30 action="store",
31 default=None,
32 dest="patch",
33 help="The name of the patch that should provide the value")
34 self.parser.add_option("--value",
35 action="store",
36 default=None,
37 dest="value",
38 help="The value that should be used for the internal field")
39 self.parser.add_option("--test",
40 action="store_true",
41 default=None,
42 dest="test",
43 help="Does not write the file but only prints it to the screen")
44
45
47 fName=self.parser.getArgs()[0]
48
49 if self.opts.patch==None and self.opts.value==None:
50 self.error("Either a patch or a value must be specified")
51 if self.opts.patch!=None and self.opts.value!=None:
52 self.error("Only a patch or a value can be specified")
53
54 try:
55 fieldFile=ParsedParameterFile(fName,backup=False)
56 except IOError,e:
57 self.error("Problem with file",fName,":",e)
58
59 value=""
60 if self.opts.patch:
61 value=fieldFile["boundaryField"][self.opts.patch]["value"]
62 else:
63 value="uniform "+self.opts.value
64
65 fieldFile["internalField"]=value
66
67 if self.opts.test:
68 print str(fieldFile)
69 else:
70 fieldFile.writeFile()
71