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

Source Code for Module PyFoam.Applications.CommonWriteAllTrigger

 1  """Implements a trigger that manipulates the controlDict in 
 2  such a way that every time-step is written to disk""" 
 3   
 4  import re 
 5  from os import path 
 6  from PyFoam.RunDictionary.ParsedParameterFile import ParsedParameterFile 
 7  from PyFoam.Error import warning 
 8   
9 -class CommonWriteAllTrigger(object):
10 """ The class that does the actual triggering 11 """ 12
13 - def addOptions(self):
14 self.ensureGeneralOptions() 15 self.generalOpts.add_option("--write-all-timesteps", 16 action="store_true", 17 dest="writeAll", 18 default=False, 19 help="Write all the timesteps to disk")
20
21 - def addWriteAllTrigger(self,run,sol):
22 if self.opts.writeAll: 23 warning("Adding Trigger and resetting to safer start-settings") 24 trig=WriteAllTrigger(sol) 25 run.addEndTrigger(trig.resetIt)
26 27
28 -class WriteAllTrigger:
29 - def __init__(self,sol):
30 self.control=ParsedParameterFile(path.join(sol.systemDir(),"controlDict"),backup=True) 31 32 self.fresh=True 33 34 try: 35 self.control["writeControl"]="timeStep" 36 self.control["writeInterval"]="1" 37 38 self.control.writeFile() 39 except Exception,e: 40 warning("Restoring defaults") 41 self.control.restore() 42 raise e
43
44 - def resetIt(self):
45 if self.fresh: 46 warning("Trigger called: Resetting the controlDict") 47 self.control.restore() 48 self.fresh=False
49