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