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
10 """ The class that does the actual triggering
11 """
12
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
25
26
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
44 if self.fresh:
45 warning("Trigger called: Resetting the controlDict")
46 self.control.restore()
47 self.fresh=False
48