1
2 """Common stuff for classes that do something at every timestep"""
3
4 from AnalyzedCommon import AnalyzedCommon
5 from time import time
6
7 picklingFreqFactor=50
8
10 """Stuff is performed forevery timestep in the file"""
11
12 - def __init__(self,
13 filename,
14 analyzer,
15 writePickled=True,
16 smallestFreq=0):
17 """@param smallestFreq: the smallest intervall of real time (in seconds) that the time change is honored"""
18 AnalyzedCommon.__init__(self,
19 filename,
20 analyzer,
21 doPickling=writePickled)
22
23 analyzer.addTimeListener(self)
24 self.freq=smallestFreq
25 self.oldtime=0.
26 self.lastPickleDuration=0
27
29 """React to a change of the simulation time in the log"""
30 now=time()
31 if self.freq>0 and (now-self.oldtime)>max(self.lastPickleDuration*picklingFreqFactor,self.freq):
32 self.timeHandle()
33 if self.doPickling:
34 self.picklePlots()
35
36 self.lastPickleDuration=time()-now
37 if self.lastPickleDuration*picklingFreqFactor>self.freq:
38 print "Duration of pickling",self.lastPickleDuration,"too long. Extending frequency from",self.freq,"to",self.lastPickleDuration*picklingFreqFactor
39 self.oldtime=time()
40
42 """Handler that reacts to the change of time. To be overridden be sub-classes"""
43 pass
44
48