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

Source Code for Module PyFoam.Execution.GnuplotRunner

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