1 """
2 Application-class that implements pyFoamClearCase.py
3 """
4 from optparse import OptionGroup
5
6 from PyFoamApplication import PyFoamApplication
7
8 from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
9
12 description="""
13 Removes all timesteps but the first from a case-directory.
14 Also removes other data that is generated by sovers/utilities/PyFoam
15 """
16 PyFoamApplication.__init__(self,
17 args=args,
18 description=description,
19 usage="%prog <caseDirectory>",
20 interspersed=True,
21 changeVersion=False,
22 nr=1,
23 exactNr=False)
24
26 what=OptionGroup(self.parser,
27 "What",
28 "Define what should be cleared")
29 self.parser.add_option_group(what)
30
31 what.add_option("--after",
32 type="float",
33 dest="after",
34 default=None,
35 help="Only remove timesteps after this time")
36 what.add_option("--processors-remove",
37 action="store_true",
38 dest="processor",
39 default=False,
40 help="Remove the processor directories")
41 what.add_option("--vtk-keep",
42 action="store_false",
43 dest="vtk",
44 default=True,
45 help="Keep the VTK directory")
46 what.add_option("--no-pyfoam",
47 action="store_false",
48 dest="pyfoam",
49 default=True,
50 help="Keep the PyFoam-specific directories and logfiles")
51 what.add_option("--keep-last",
52 action="store_true",
53 dest="latest",
54 default=False,
55 help="Keep the data from the last time-step")
56 what.add_option("--keep-regular",
57 action="store_true",
58 dest="keepRegular",
59 default=False,
60 help="Keep all the timesteps")
61
62 output=OptionGroup(self.parser,
63 "Output",
64 "What information should be given")
65 self.parser.add_option_group(output)
66 output.add_option("--fatal",
67 action="store_true",
68 dest="fatal",
69 default=False,
70 help="If non-cases are specified the program should abort")
71 output.add_option("--silent",
72 action="store_true",
73 dest="silent",
74 default=False,
75 help="Don't complain about non-case-files")
76 output.add_option("--verbose",
77 action="store_true",
78 dest="verbose",
79 default=False,
80 help="Print what cases are cleared")
81
82
84 for cName in self.parser.getArgs():
85 if self.checkCase(cName,fatal=self.opts.fatal,verbose=not self.opts.silent):
86 if self.opts.verbose:
87 print "Clearing",cName
88 sol=SolutionDirectory(cName,archive=None,paraviewLink=False)
89 sol.clear(after=self.parser.getOptions().after,
90 processor=self.parser.getOptions().processor,
91 pyfoam=self.parser.getOptions().pyfoam,
92 vtk=self.parser.getOptions().vtk,
93 keepRegular=self.parser.getOptions().keepRegular,
94 keepLast=self.parser.getOptions().latest)
95