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.parser.add_option("--write-all-timesteps", 15 action="store_true", 16 dest="writeAll", 17 default=False, 18 help="Write all the timesteps to disk")
19
20 - def addWriteAllTrigger(self,run,sol):
21 if self.opts.writeAll: 22 warning("Adding Trigger and resetting to safer start-settings") 23 trig=WriteAllTrigger(sol) 24 run.addEndTrigger(trig.resetIt)
25 26
27 -class WriteAllTrigger:
28 - def __init__(self,sol):
29 self.control=ParsedParameterFile(path.join(sol.systemDir(),"controlDict"),backup=True) 30 31 self.fresh=True 32 33 try: 34 self.control["writeControl"]="timeStep" 35 self.control["writeInterval"]="1" 36 37 self.control.writeFile() 38 except Exception,e: 39 warning("Restoring defaults") 40 self.control.restore() 41 raise e
42
43 - def resetIt(self):
44 if self.fresh: 45 warning("Trigger called: Resetting the controlDict") 46 self.control.restore() 47 self.fresh=False
48