Package PyFoam :: Package Execution :: Module StepAnalyzedCommon
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Execution.StepAnalyzedCommon

 1  #  ICE Revision: $Id$ 
 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   
11 -class StepAnalyzedCommon(AnalyzedCommon):
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 adaptFrequency=True):
20 """@param smallestFreq: the smallest intervall of real time (in seconds) that the time change is honored""" 21 AnalyzedCommon.__init__(self, 22 filename, 23 analyzer, 24 doPickling=writePickled) 25 26 analyzer.addTimeListener(self) 27 self.freq=smallestFreq 28 self.oldtime=0. 29 self.lastPickleDuration=0 30 self.adaptFrequency=adaptFrequency
31
32 - def timeChanged(self):
33 """React to a change of the simulation time in the log""" 34 now=time() 35 36 if self.freq>0 and (now-self.oldtime)>max(self.lastPickleDuration*picklingFreqFactor,self.freq): 37 self.timeHandle() 38 if self.doPickling: 39 self.picklePlots() 40 # store this to make sure that pickling is not the only thing we do 41 if self.adaptFrequency: 42 self.lastPickleDuration=time()-now 43 else: 44 self.lastPickleDuration=0 45 46 if self.lastPickleDuration*picklingFreqFactor>self.freq: 47 print_("Duration of pickling",self.lastPickleDuration, 48 "too long. Extending frequency from",self.freq, 49 "to",self.lastPickleDuration*picklingFreqFactor) 50 self.oldtime=time()
51
52 - def timeHandle(self):
53 """Handler that reacts to the change of time. To be overridden be sub-classes""" 54 pass
55
56 - def stopHandle(self):
57 if self.doPickling: 58 self.picklePlots(wait=True)
59