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

Source Code for Module PyFoam.Execution.GnuplotRunner

  1  #  ICE Revision: $Id: GnuplotRunner.py 7832 2007-08-28 13:07:26Z 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) 33 self.getAnalyzer("Linear").lines.setSplitting(splitThres=splitThres,splitFun=max) 34 35 self.plot.set_string("logscale y") 36 self.plot.title("Residuals") 37 38 if plotCont: 39 self.plotCont=GnuplotTimelines(self.getAnalyzer("Continuity").lines,persist=persist,alternateAxis=["Global"],raiseit=raiseit,start=start,end=end) 40 self.plotCont.set_string("ylabel \"Cumulative\"") 41 self.plotCont.set_string("y2label \"Global\"") 42 self.getAnalyzer("Continuity").lines.setSplitting(splitThres=splitThres) 43 44 self.plotCont.title("Continuity") 45 46 if plotBound: 47 self.plotBound=GnuplotTimelines(self.getAnalyzer("Bounding").lines,persist=persist,raiseit=raiseit,start=start,end=end) 48 self.getAnalyzer("Bounding").lines.setSplitting(splitThres=splitThres,splitFun=signedMax) 49 self.plotBound.title("Bounded variables") 50 51 if plotIterations: 52 self.plotIter=GnuplotTimelines(self.getAnalyzer("Iterations").lines,persist=persist,with="steps",raiseit=raiseit,start=start,end=end) 53 self.getAnalyzer("Iterations").lines.setSplitting(splitThres=splitThres) 54 55 self.plotIter.title("Iterations") 56 57 if plotCourant: 58 self.plotCourant=GnuplotTimelines(self.getAnalyzer("Courant").lines,persist=persist,raiseit=raiseit,start=start,end=end) 59 self.getAnalyzer("Courant").lines.setSplitting(splitThres=splitThres) 60 61 self.plotCourant.title("Courant") 62 63 if plotDeltaT: 64 self.plotDeltaT=GnuplotTimelines(self.getAnalyzer("DeltaT").lines,persist=persist,raiseit=raiseit,start=start,end=end) 65 self.getAnalyzer("DeltaT").lines.setSplitting(splitThres=splitThres) 66 67 self.plotDeltaT.title("DeltaT") 68 69 if plotExecution: 70 self.plotExecution=GnuplotTimelines(self.getAnalyzer("Execution").lines,persist=persist,with="steps",raiseit=raiseit,start=start,end=end) 71 self.getAnalyzer("Execution").lines.setSplitting(splitThres=splitThres) 72 73 self.plotExecution.title("Execution Time") 74 75 if customRegexp: 76 self.plotCustom=[] 77 for i in range(len(customRegexp)): 78 name="Custom%02d" % i 79 self.addAnalyzer(name,RegExpLineAnalyzer(name.lower(),customRegexp[i],doTimelines=True,doFiles=writeFiles)) 80 plotCustom=GnuplotTimelines(self.getAnalyzer(name).lines,persist=persist,with="lines",raiseit=raiseit,start=start,end=end) 81 plotCustom.title("Custom %d" % i) 82 self.plotCustom.append(plotCustom) 83 84 self.reset()
85
86 - def timeHandle(self):
87 if self.plot: 88 self.plot.redo() 89 if self.plotCont: 90 self.plotCont.redo() 91 if self.plotBound: 92 self.plotBound.redo() 93 if self.plotIter: 94 self.plotIter.redo() 95 if self.plotCourant: 96 self.plotCourant.redo() 97 if self.plotExecution: 98 self.plotExecution.redo() 99 if self.plotDeltaT: 100 self.plotDeltaT.redo() 101 if self.plotCustom: 102 for r in self.plotCustom: 103 r.redo()
104
105 - def stopHandle(self):
106 self.timeHandle()
107 108
109 -class GnuplotRunner(GnuplotCommon,BasicRunner):
110 - 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):
111 """@param smallestFreq: smallest Frequency of output 112 @param persist: Gnuplot window persistst after run 113 @param steady: Is it a steady run? Then stop it after convergence""" 114 BasicRunner.__init__(self,argv=argv,silent=progress,server=server,lam=lam) 115 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) 116 self.steady=steady 117 if self.steady: 118 self.steadyAnalyzer=SteadyConvergedLineAnalyzer() 119 self.addAnalyzer("Convergence",self.steadyAnalyzer)
120
121 - def lineHandle(self,line):
122 """Not to be called: Stops the solver""" 123 GnuplotCommon.lineHandle(self,line) 124 125 if self.steady: 126 if not self.steadyAnalyzer.goOn(): 127 self.stopGracefully()
128
129 - def stopHandle(self):
130 """Not to be called: Restores controlDict""" 131 GnuplotCommon.stopHandle(self) 132 BasicRunner.stopHandle(self)
133
134 -class GnuplotWatcher(GnuplotCommon,BasicWatcher):
135 - 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):
136 """@param smallestFreq: smallest Frequency of output 137 @param persist: Gnuplot window persistst after run""" 138 BasicWatcher.__init__(self,logfile,silent=(silent or progress),tailLength=tailLength,sleep=sleep) 139 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)
140
141 - def startHandle(self):
142 self.bakFreq=self.freq 143 self.freq=3600
144
145 - def tailingHandle(self):
146 self.freq=self.bakFreq 147 self.oldtime=0
148