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 self.parser.add_option("--source-key",
45 action="store",
46 default="value",
47 dest="srckey",
48 help="The key that should be read from the source patch: %default")
49
50
52 fName=self.parser.getArgs()[0]
53
54 if self.opts.patch==None and self.opts.value==None:
55 self.error("Either a patch or a value must be specified")
56 if self.opts.patch!=None and self.opts.value!=None:
57 self.error("Only a patch or a value can be specified")
58
59 try:
60 fieldFile=ParsedParameterFile(fName,backup=False)
61 except IOError,e:
62 self.error("Problem with file",fName,":",e)
63
64 value=""
65 if self.opts.patch:
66 value=fieldFile["boundaryField"][self.opts.patch][self.opts.srckey]
67 else:
68 value="uniform "+self.opts.value
69
70 fieldFile["internalField"]=value
71
72 if self.opts.test:
73 print str(fieldFile)
74 else:
75 fieldFile.writeFile()
76 self.addToCaseLog(path.dirname(path.dirname(path.abspath(fName))))
77