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
10 from PyFoam.ThirdParty.six import print_
11
14 description="""\
15 Removes all timesteps but the first from a case-directory. Also
16 removes other data that is generated by sovers/utilities/PyFoam
17 """
18 PyFoamApplication.__init__(self,
19 args=args,
20 description=description,
21 usage="%prog <caseDirectory>",
22 interspersed=True,
23 changeVersion=False,
24 nr=1,
25 exactNr=False)
26
28 what=OptionGroup(self.parser,
29 "What",
30 "Define what should be cleared")
31 self.parser.add_option_group(what)
32
33 what.add_option("--after",
34 type="float",
35 dest="after",
36 default=None,
37 help="Only remove timesteps after this time")
38 what.add_option("--processors-remove",
39 action="store_true",
40 dest="processor",
41 default=False,
42 help="Remove the processor directories")
43 what.add_option("--vtk-keep",
44 action="store_false",
45 dest="vtk",
46 default=True,
47 help="Keep the VTK directory")
48 what.add_option("--no-pyfoam",
49 action="store_false",
50 dest="pyfoam",
51 default=True,
52 help="Keep the PyFoam-specific directories and logfiles")
53 what.add_option("--keep-last",
54 action="store_true",
55 dest="latest",
56 default=False,
57 help="Keep the data from the last time-step")
58 what.add_option("--keep-regular",
59 action="store_true",
60 dest="keepRegular",
61 default=False,
62 help="Keep all the timesteps")
63 what.add_option("--keep-postprocessing",
64 action="store_true",
65 dest="keepPostprocessing",
66 default=False,
67 help="Keep the directory 'postProcessing' where functionObjects write their stuff")
68 what.add_option("--additional",
69 action="append",
70 dest="additional",
71 default=[],
72 help="Glob-pattern with additional files to be removes. Can be used more than once")
73 what.add_option("--clear-history",
74 action="store_true",
75 dest="clearHistory",
76 default=False,
77 help="Clear the PyFoamHistory-file")
78 what.add_option("--function-object-data",
79 action="store_true",
80 dest="functionObjectData",
81 default=False,
82 help="Clear data written by functionObjects. Only works if the data directory has the same name as the functionObject")
83
84 output=OptionGroup(self.parser,
85 "Output",
86 "What information should be given")
87 self.parser.add_option_group(output)
88 output.add_option("--fatal",
89 action="store_true",
90 dest="fatal",
91 default=False,
92 help="If non-cases are specified the program should abort")
93 output.add_option("--silent",
94 action="store_true",
95 dest="silent",
96 default=False,
97 help="Don't complain about non-case-files")
98 output.add_option("--verbose",
99 action="store_true",
100 dest="verbose",
101 default=False,
102 help="Print what cases are cleared")
103
104
106 if not self.opts.keepPostprocessing:
107 self.opts.additional.append("postProcessing")
108
109 for cName in self.parser.getArgs():
110 if self.checkCase(cName,fatal=self.opts.fatal,verbose=not self.opts.silent):
111 self.addLocalConfig(cName)
112
113 if self.opts.verbose:
114 print_("Clearing",cName)
115
116 sol=SolutionDirectory(cName,archive=None,paraviewLink=False)
117 sol.clear(after=self.parser.getOptions().after,
118 processor=self.parser.getOptions().processor,
119 pyfoam=self.parser.getOptions().pyfoam,
120 vtk=self.parser.getOptions().vtk,
121 keepRegular=self.parser.getOptions().keepRegular,
122 keepLast=self.parser.getOptions().latest,
123 clearHistory=self.parser.getOptions().clearHistory,
124 additional=self.parser.getOptions().additional,
125 functionObjectData=self.parser.getOptions().functionObjectData)
126
127 self.addToCaseLog(cName)
128