1
2 """
3 Application class that implements pyFoamClearBoundaryValue.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> <patchnames>",
24 changeVersion=False,
25 nr=2,
26 interspersed=True,
27 exactNr=False)
28
30 self.parser.add_option("--patch",
31 action="store",
32 default=None,
33 dest="patch",
34 help="The name of the patch that should provide the value")
35 self.parser.add_option("--value",
36 action="store",
37 default=None,
38 dest="value",
39 help="The value that should be used for the internal field")
40 self.parser.add_option("--test",
41 action="store_true",
42 default=None,
43 dest="test",
44 help="Does not write the file but only prints it to the screen")
45 self.parser.add_option("--destination-key",
46 action="store",
47 default="value",
48 dest="destkey",
49 help="The key that should be set on the target patch: %default")
50 self.parser.add_option("--source-key",
51 action="store",
52 default="value",
53 dest="srckey",
54 help="The key that should be read from the source patch: %default")
55
56
58 fName=self.parser.getArgs()[0]
59 destPatches=self.parser.getArgs()[1:]
60 if self.opts.patch==None and self.opts.value==None:
61 self.error("Either a patch or a value must be specified")
62 if self.opts.patch!=None and self.opts.value!=None:
63 self.error("Only a patch or a value can be specified")
64
65 try:
66 fieldFile=ParsedParameterFile(fName,backup=False)
67 except IOError,e:
68 self.error("Problem with file",fName,":",e)
69
70 value=""
71 if self.opts.patch:
72 value=fieldFile["boundaryField"][self.opts.patch][self.opts.srckey]
73 else:
74 value="uniform "+self.opts.value
75
76 for destPatch in destPatches:
77 fieldFile["boundaryField"][destPatch][self.opts.destkey]=value
78
79 if self.opts.test:
80 print str(fieldFile)
81 else:
82 fieldFile.writeFile()
83