Package PyFoam :: Package Applications :: Module ClearCase
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.ClearCase

  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   
12 -class ClearCase(PyFoamApplication):
13 - def __init__(self,args=None):
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
27 - def addOptions(self):
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("--remove-analyzed", 54 action="store_true", 55 dest="removeAnalyzed", 56 default=False, 57 help="Also remove the directories thatend with 'analyzed' (usually created by PyFoam)") 58 what.add_option("--keep-last", 59 action="store_true", 60 dest="latest", 61 default=False, 62 help="Keep the data from the last time-step") 63 what.add_option("--keep-regular", 64 action="store_true", 65 dest="keepRegular", 66 default=False, 67 help="Keep all the 'regular' timesteps") 68 what.add_option("--keep-parallel", 69 action="store_true", 70 dest="keepParallel", 71 default=False, 72 help="Keep all the timesteps in the processor-directories") 73 what.add_option("--keep-interval", 74 action="store", 75 type=float, 76 dest="keepInterval", 77 default=None, 78 help="Keep timesteps that are this far apart") 79 what.add_option("--keep-postprocessing", 80 action="store_true", 81 dest="keepPostprocessing", 82 default=False, 83 help="Keep the directory 'postProcessing' where functionObjects write their stuff") 84 what.add_option("--additional", 85 action="append", 86 dest="additional", 87 default=[], 88 help="Glob-pattern with additional files to be removes. Can be used more than once") 89 what.add_option("--clear-history", 90 action="store_true", 91 dest="clearHistory", 92 default=False, 93 help="Clear the PyFoamHistory-file") 94 what.add_option("--function-object-data", 95 action="store_true", 96 dest="functionObjectData", 97 default=False, 98 help="Clear data written by functionObjects. Only works if the data directory has the same name as the functionObject") 99 100 output=OptionGroup(self.parser, 101 "Output", 102 "What information should be given") 103 self.parser.add_option_group(output) 104 output.add_option("--fatal", 105 action="store_true", 106 dest="fatal", 107 default=False, 108 help="If non-cases are specified the program should abort") 109 output.add_option("--silent", 110 action="store_true", 111 dest="silent", 112 default=False, 113 help="Don't complain about non-case-files") 114 output.add_option("--verbose", 115 action="store_true", 116 dest="verbose", 117 default=False, 118 help="Print what cases are cleared")
119 120
121 - def run(self):
122 if not self.opts.keepPostprocessing: 123 self.opts.additional.append("postProcessing") 124 125 for cName in self.parser.getArgs(): 126 if self.checkCase(cName,fatal=self.opts.fatal,verbose=not self.opts.silent): 127 self.addLocalConfig(cName) 128 129 if self.opts.verbose: 130 print_("Clearing",cName) 131 132 sol=SolutionDirectory(cName,archive=None,paraviewLink=False) 133 sol.clear(after=self.parser.getOptions().after, 134 processor=self.parser.getOptions().processor, 135 pyfoam=self.parser.getOptions().pyfoam, 136 vtk=self.parser.getOptions().vtk, 137 removeAnalyzed=self.parser.getOptions().removeAnalyzed, 138 keepRegular=self.parser.getOptions().keepRegular, 139 keepParallel=self.parser.getOptions().keepParallel, 140 keepLast=self.parser.getOptions().latest, 141 keepInterval=self.parser.getOptions().keepInterval, 142 clearHistory=self.parser.getOptions().clearHistory, 143 additional=self.parser.getOptions().additional, 144 functionObjectData=self.parser.getOptions().functionObjectData) 145 146 self.addToCaseLog(cName)
147