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

Source Code for Module PyFoam.Execution.GnuplotRunner

  1  #  ICE Revision: $Id: GnuplotRunner.py 8202 2007-11-19 09:14:09Z bgschaid $  
  2  """Runner that outputs the residuals of the linear solver with Gnuplot""" 
  3   
  4  from StepAnalyzedCommon import StepAnalyzedCommon 
  5  from BasicRunner import BasicRunner 
  6  from BasicWatcher import BasicWatcher 
  7   
  8  from PyFoam.LogAnalysis.BoundingLogAnalyzer import BoundingLogAnalyzer 
  9  from PyFoam.LogAnalysis.RegExpLineAnalyzer import RegExpLineAnalyzer 
 10  from PyFoam.LogAnalysis.SteadyConvergedLineAnalyzer import SteadyConvergedLineAnalyzer 
 11  from PyFoam.Basics.GnuplotTimelines import GnuplotTimelines 
 12  from PyFoam.Basics.TimeLineCollection import signedMax 
 13   
14 -class GnuplotCommon(StepAnalyzedCommon):
15 """Class that collects the Gnuplotting-Stuff for two other classes"""
16 - def __init__(self,fname,smallestFreq=0.,persist=None,splitThres=2048,plotLinear=True,plotCont=True,plotBound=True,plotIterations=False,plotCourant=False,plotExecution=False,plotDeltaT=False,customRegexp=None,writeFiles=False,raiseit=False,progress=False,start=None,end=None):
17 """ 18 TODO: Docu 19 """ 20 StepAnalyzedCommon.__init__(self,fname,BoundingLogAnalyzer(doTimelines=True,doFiles=writeFiles,progress=progress),smallestFreq=smallestFreq) 21 22 self.plot=None 23 self.plotCont=None 24 self.plotBound=None 25 self.plotIter=None 26 self.plotCourant=None 27 self.plotExecution=None 28 self.plotCustom=None 29 self.plotDeltaT=None 30 31 if plotLinear: 32 self.plot=GnuplotTimelines(self.getAnalyzer("Linear").lines,persist=persist,raiseit=raiseit,forbidden=["final","iterations"],start=start,end=end,logscale=True) 33 self.getAnalyzer("Linear").lines.setSplitting(splitThres=splitThres,splitFun=max) 34 35 self.plot.title("Residuals") 36 37 if plotCont: 38 self.plotCont=GnuplotTimelines(self.getAnalyzer("Continuity").lines,persist=persist,alternateAxis=["Global"],raiseit=raiseit,start=start,end=end) 39 self.plotCont.set_string("ylabel \"Cumulative\"") 40 self.plotCont.set_string("y2label \"Global\"") 41 self.getAnalyzer("Continuity").lines.setSplitting(splitThres=splitThres) 42 43 self.plotCont.title("Continuity") 44 45 if plotBound: 46 self.plotBound=GnuplotTimelines(self.getAnalyzer("Bounding").lines,persist=persist,raiseit=raiseit,start=start,end=end) 47 self.getAnalyzer("Bounding").lines.setSplitting(splitThres=splitThres,splitFun=signedMax) 48 self.plotBound.title("Bounded variables") 49 50 if plotIterations: 51 self.plotIter=GnuplotTimelines(self.getAnalyzer("Iterations").lines,persist=persist,with="steps",raiseit=raiseit,start=start,end=end) 52 self.getAnalyzer("Iterations").lines.setSplitting(splitThres=splitThres) 53 54 self.plotIter.title("Iterations") 55 56 if plotCourant: 57 self.plotCourant=GnuplotTimelines(self.getAnalyzer("Courant").lines,persist=persist,raiseit=raiseit,start=start,end=end) 58 self.getAnalyzer("Courant").lines.setSplitting(splitThres=splitThres) 59 60 self.plotCourant.title("Courant") 61 62 if plotDeltaT: 63 self.plotDeltaT=GnuplotTimelines(self.getAnalyzer("DeltaT").lines,persist=persist,raiseit=raiseit,start=start,end=end,logscale=True) 64 self.getAnalyzer("DeltaT").lines.setSplitting(splitThres=splitThres) 65 66 self.plotDeltaT.title("DeltaT") 67 68 if plotExecution: 69 self.plotExecution=GnuplotTimelines(self.getAnalyzer("Execution").lines,persist=persist,with="steps",raiseit=raiseit,start=start,end=end) 70 self.getAnalyzer("Execution").lines.setSplitting(splitThres=splitThres) 71 72 self.plotExecution.title("Execution Time") 73 74 if customRegexp: 75 self.plotCustom=[] 76 for i in range(len(customRegexp)): 77 name="Custom%02d" % i 78 self.addAnalyzer(name,RegExpLineAnalyzer(name.lower(),customRegexp[i],doTimelines=True,doFiles=writeFiles)) 79 plotCustom=GnuplotTimelines(self.getAnalyzer(name).lines,persist=persist,with="lines",raiseit=raiseit,start=start,end=end) 80 plotCustom.title("Custom %d" % i) 81 self.plotCustom.append(plotCustom) 82 83 self.reset()
84
85 - def timeHandle(self):
86 if self.plot: 87 self.plot.redo() 88 if self.plotCont: 89 self.plotCont.redo() 90 if self.plotBound: 91 self.plotBound.redo() 92 if self.plotIter: 93 self.plotIter.redo() 94 if self.plotCourant: 95 self.plotCourant.redo() 96 if self.plotExecution: 97 self.plotExecution.redo() 98 if self.plotDeltaT: 99 self.plotDeltaT.redo() 100 if self.plotCustom: 101 for r in self.plotCustom: 102 r.redo()
103
104 - def stopHandle(self):
105 self.timeHandle()
106 107
108 -class GnuplotRunner(GnuplotCommon,BasicRunner):
109 - def __init__(self,argv=None,smallestFreq=0.,persist=None,plotLinear=True,plotCont=True,plotBound=True,plotIterations=False,plotCourant=False,plotExecution=False,plotDeltaT=False,customRegexp=None,writeFiles=False,server=False,lam=None,raiseit=False,steady=False,progress=False,restart=False):
110 """@param smallestFreq: smallest Frequency of output 111 @param persist: Gnuplot window persistst after run 112 @param steady: Is it a steady run? Then stop it after convergence""" 113 BasicRunner.__init__(self,argv=argv,silent=progress,server=server,lam=lam,restart=restart) 114 GnuplotCommon.__init__(self,"Gnuplotting",smallestFreq=smallestFreq,persist=persist,plotLinear=plotLinear,plotCont=plotCont,plotBound=plotBound,plotIterations=plotIterations,plotCourant=plotCourant,plotExecution=plotExecution,plotDeltaT=plotDeltaT,customRegexp=customRegexp,writeFiles=writeFiles,raiseit=raiseit,progress=progress) 115 self.steady=steady 116 if self.steady: 117 self.steadyAnalyzer=SteadyConvergedLineAnalyzer() 118 self.addAnalyzer("Convergence",self.steadyAnalyzer)
119
120 - def lineHandle(self,line):
121 """Not to be called: Stops the solver""" 122 GnuplotCommon.lineHandle(self,line) 123 124 if self.steady: 125 if not self.steadyAnalyzer.goOn(): 126 self.stopGracefully()
127
128 - def stopHandle(self):
129 """Not to be called: Restores controlDict""" 130 GnuplotCommon.stopHandle(self) 131 BasicRunner.stopHandle(self)
132
133 -class GnuplotWatcher(GnuplotCommon,BasicWatcher):
134 - def __init__(self,logfile,smallestFreq=0.,persist=None,silent=False,tailLength=1000,sleep=0.1,plotLinear=True,plotCont=True,plotBound=True,plotIterations=False,plotCourant=False,plotExecution=False,plotDeltaT=False,customRegexp=None,writeFiles=False,raiseit=False,progress=False,start=None,end=None):
135 """@param smallestFreq: smallest Frequency of output 136 @param persist: Gnuplot window persistst after run""" 137 BasicWatcher.__init__(self,logfile,silent=(silent or progress),tailLength=tailLength,sleep=sleep) 138 GnuplotCommon.__init__(self,logfile,smallestFreq=smallestFreq,persist=persist,plotLinear=plotLinear,plotCont=plotCont,plotBound=plotBound,plotIterations=plotIterations,plotCourant=plotCourant,plotExecution=plotExecution,plotDeltaT=plotDeltaT,customRegexp=customRegexp,writeFiles=writeFiles,raiseit=raiseit,progress=progress,start=start,end=end)
139
140 - def startHandle(self):
141 self.bakFreq=self.freq 142 self.freq=3600
143
144 - def tailingHandle(self):
145 self.freq=self.bakFreq 146 self.oldtime=0
147