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

Source Code for Module PyFoam.Execution.GnuplotRunner

  1  """Runner that outputs the residuals of the linear solver with Gnuplot""" 
  2   
  3  from os import path 
  4   
  5  from StepAnalyzedCommon import StepAnalyzedCommon 
  6  from BasicRunner import BasicRunner 
  7  from BasicWatcher import BasicWatcher 
  8   
  9  from PyFoam.LogAnalysis.BoundingLogAnalyzer import BoundingLogAnalyzer 
 10  from PyFoam.LogAnalysis.RegExpLineAnalyzer import RegExpLineAnalyzer 
 11  from PyFoam.LogAnalysis.SteadyConvergedLineAnalyzer import SteadyConvergedLineAnalyzer 
 12  from PyFoam.Basics.GnuplotTimelines import GnuplotTimelines 
 13  from PyFoam.Basics.TimeLineCollection import signedMax 
 14   
15 -class GnuplotCommon(StepAnalyzedCommon):
16 """Class that collects the Gnuplotting-Stuff for two other classes"""
17 - 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):
18 """ 19 TODO: Docu 20 """ 21 StepAnalyzedCommon.__init__(self,fname,BoundingLogAnalyzer(doTimelines=True,doFiles=writeFiles),smallestFreq=smallestFreq) 22 23 self.plot=None 24 self.plotCont=None 25 self.plotBound=None 26 self.plotIter=None 27 self.plotCourant=None 28 self.plotExecution=None 29 self.plotCustom=None 30 self.plotDeltaT=None 31 32 if plotLinear: 33 self.plot=GnuplotTimelines(self.getAnalyzer("Linear").lines,persist=persist,raiseit=raiseit,forbidden=["final","iterations"]) 34 self.getAnalyzer("Linear").lines.setSplitting(splitThres=splitThres,splitFun=max) 35 36 self.plot.set_string("logscale y") 37 self.plot.title("Residuals") 38 39 if plotCont: 40 self.plotCont=GnuplotTimelines(self.getAnalyzer("Continuity").lines,persist=persist,alternateAxis=["Global"],raiseit=raiseit) 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) 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) 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) 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) 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) 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 self.addAnalyzer(name,RegExpLineAnalyzer(name.lower(),customRegexp[i],doTimelines=True,doFiles=writeFiles)) 81 plotCustom=GnuplotTimelines(self.getAnalyzer(name).lines,persist=persist,with="lines",raiseit=raiseit) 82 plotCustom.title("Custom %d" % i) 83 self.plotCustom.append(plotCustom) 84 85 self.reset()
86
87 - def timeHandle(self):
88 if self.plot: 89 self.plot.redo() 90 if self.plotCont: 91 self.plotCont.redo() 92 if self.plotBound: 93 self.plotBound.redo() 94 if self.plotIter: 95 self.plotIter.redo() 96 if self.plotCourant: 97 self.plotCourant.redo() 98 if self.plotExecution: 99 self.plotExecution.redo() 100 if self.plotDeltaT: 101 self.plotDeltaT.redo() 102 if self.plotCustom: 103 for r in self.plotCustom: 104 r.redo()
105
106 - def stopHandle(self):
107 self.timeHandle()
108 109
110 -class GnuplotRunner(GnuplotCommon,BasicRunner):
111 - 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):
112 """@param smallestFreq: smallest Frequency of output 113 @param persist: Gnuplot window persistst after run 114 @param steady: Is it a steady run? Then stop it after convergence""" 115 BasicRunner.__init__(self,argv=argv,server=server,lam=lam) 116 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) 117 self.steady=steady 118 if self.steady: 119 self.steadyAnalyzer=SteadyConvergedLineAnalyzer() 120 self.addAnalyzer("Convergence",self.steadyAnalyzer)
121
122 - def lineHandle(self,line):
123 """Not to be called: Stops the solver""" 124 GnuplotCommon.lineHandle(self,line) 125 126 if self.steady: 127 if not self.steadyAnalyzer.goOn(): 128 self.stopGracefully()
129
130 - def stopHandle(self):
131 """Not to be called: Restores controlDict""" 132 GnuplotCommon.stopHandle(self) 133 BasicRunner.stopHandle(self)
134
135 -class GnuplotWatcher(GnuplotCommon,BasicWatcher):
136 - 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):
137 """@param smallestFreq: smallest Frequency of output 138 @param persist: Gnuplot window persistst after run""" 139 BasicWatcher.__init__(self,logfile,silent=silent,tailLength=tailLength,sleep=sleep) 140 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)
141
142 - def startHandle(self):
143 self.bakFreq=self.freq 144 self.freq=3600
145
146 - def tailingHandle(self):
147 self.freq=self.bakFreq 148 self.oldtime=0
149