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

Source Code for Module PyFoam.Execution.StepAnalyzedCommon

 1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/Execution/StepAnalyzedCommon.py 7587 2011-09-16T14:48:09.701859Z bgschaid  $  
 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   
9 -class StepAnalyzedCommon(AnalyzedCommon):
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
28 - def timeChanged(self):
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 # store this to make sure that pickling is not the only thing we do 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
41 - def timeHandle(self):
42 """Handler that reacts to the change of time. To be overridden be sub-classes""" 43 pass
44
45 - def stopHandle(self):
46 if self.doPickling: 47 self.picklePlots(wait=True)
48