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