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

Source Code for Module PyFoam.Execution.GnuplotRunner

  1  #  ICE Revision: $Id: GnuplotRunner.py 10948 2009-10-13 08:37:46Z 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.SteadyConvergedLineAnalyzer import SteadyConvergedLineAnalyzer 
 10  from PyFoam.Basics.TimeLineCollection import TimeLineCollection 
 11  from PyFoam.Error import error 
 12   
 13  from os import path 
 14   
15 -class GnuplotCommon(StepAnalyzedCommon):
16 """Class that collects the Gnuplotting-Stuff for two other classes"""
17 - def __init__(self, 18 fname, 19 smallestFreq=0., 20 persist=None, 21 splitThres=2048, 22 plotLinear=True, 23 plotCont=True, 24 plotBound=True, 25 plotIterations=False, 26 plotCourant=False, 27 plotExecution=False, 28 plotDeltaT=False, 29 hardcopy=False, 30 hardcopyFormat="png", 31 hardcopyPrefix=None, 32 customRegexp=None, 33 writeFiles=False, 34 raiseit=False, 35 progress=False, 36 start=None, 37 end=None, 38 singleFile=False, 39 plottingImplementation=None):
40 """ 41 TODO: Docu 42 """ 43 StepAnalyzedCommon.__init__(self, 44 fname, 45 BoundingLogAnalyzer(doTimelines=True, 46 doFiles=writeFiles, 47 progress=progress, 48 singleFile=singleFile, 49 startTime=start, 50 endTime=end), 51 smallestFreq=smallestFreq) 52 53 self.startTime=start 54 self.endTime=end 55 56 self.plots=self.createPlots(persist=persist, 57 raiseit=raiseit, 58 start=start, 59 end=end, 60 writeFiles=writeFiles, 61 splitThres=splitThres, 62 plotLinear=plotLinear, 63 plotCont=plotCont, 64 plotBound=plotBound, 65 plotIterations=plotIterations, 66 plotCourant=plotCourant, 67 plotExecution=plotExecution, 68 plotDeltaT=plotDeltaT, 69 customRegexp=customRegexp, 70 plottingImplementation=plottingImplementation) 71 72 self.hardcopy=hardcopy 73 self.hardcopyFormat=hardcopyFormat 74 self.hardcopyPrefix=hardcopyPrefix
75
76 - def timeHandle(self):
77 for p in self.plots: 78 self.plots[p].redo()
79
80 - def stopHandle(self):
81 self.timeHandle() 82 if self.hardcopy: 83 if self.hardcopyPrefix: 84 prefix=self.hardcopyPrefix+"." 85 else: 86 prefix="" 87 88 for p in self.plots: 89 if not self.plots[p].hasData(): 90 continue 91 self.plots[p].doHardcopy(prefix+p,self.hardcopyFormat)
92
93 -class GnuplotRunner(GnuplotCommon,BasicRunner):
94 - def __init__(self, 95 argv=None, 96 smallestFreq=0., 97 persist=None, 98 plotLinear=True, 99 plotCont=True, 100 plotBound=True, 101 plotIterations=False, 102 plotCourant=False, 103 plotExecution=False, 104 plotDeltaT=False, 105 customRegexp=None, 106 hardcopy=False, 107 hardcopyFormat="png", 108 hardcopyPrefix=None, 109 writeFiles=False, 110 server=False, 111 lam=None, 112 raiseit=False, 113 steady=False, 114 progress=False, 115 restart=False, 116 logname=None, 117 compressLog=False, 118 noLog=False, 119 singleFile=False, 120 plottingImplementation=None, 121 remark=None, 122 jobId=None):
123 """@param smallestFreq: smallest Frequency of output 124 @param persist: Gnuplot window persistst after run 125 @param steady: Is it a steady run? Then stop it after convergence""" 126 BasicRunner.__init__(self, 127 argv=argv, 128 silent=progress, 129 server=server, 130 lam=lam, 131 restart=restart, 132 logname=logname, 133 compressLog=compressLog, 134 noLog=noLog, 135 remark=remark, 136 jobId=jobId) 137 GnuplotCommon.__init__(self, 138 "Gnuplotting", 139 smallestFreq=smallestFreq, 140 persist=persist, 141 plotLinear=plotLinear, 142 plotCont=plotCont, 143 plotBound=plotBound, 144 plotIterations=plotIterations, 145 plotCourant=plotCourant, 146 plotExecution=plotExecution, 147 plotDeltaT=plotDeltaT, 148 customRegexp=customRegexp, 149 hardcopy=hardcopy, 150 hardcopyFormat=hardcopyFormat, 151 hardcopyPrefix=hardcopyPrefix, 152 writeFiles=writeFiles, 153 raiseit=raiseit, 154 progress=progress, 155 singleFile=singleFile, 156 plottingImplementation=plottingImplementation) 157 self.steady=steady 158 if self.steady: 159 self.steadyAnalyzer=SteadyConvergedLineAnalyzer() 160 self.addAnalyzer("Convergence",self.steadyAnalyzer)
161
162 - def lineHandle(self,line):
163 """Not to be called: Stops the solver""" 164 GnuplotCommon.lineHandle(self,line) 165 166 if self.steady: 167 if not self.steadyAnalyzer.goOn(): 168 self.stopGracefully()
169
170 - def stopHandle(self):
171 """Not to be called: Restores controlDict""" 172 GnuplotCommon.stopHandle(self) 173 BasicRunner.stopHandle(self)
174
175 -class GnuplotWatcher(GnuplotCommon,BasicWatcher):
176 - def __init__(self, 177 logfile, 178 smallestFreq=0., 179 persist=None, 180 silent=False, 181 tailLength=1000, 182 sleep=0.1, 183 replotFrequency=3600, 184 plotLinear=True, 185 plotCont=True, 186 plotBound=True, 187 plotIterations=False, 188 plotCourant=False, 189 plotExecution=False, 190 plotDeltaT=False, 191 customRegexp=None, 192 writeFiles=False, 193 hardcopy=False, 194 hardcopyFormat="png", 195 hardcopyPrefix=None, 196 raiseit=False, 197 progress=False, 198 start=None, 199 end=None, 200 singleFile=False, 201 plottingImplementation=None):
202 """@param smallestFreq: smallest Frequency of output 203 @param persist: Gnuplot window persistst after run""" 204 BasicWatcher.__init__(self, 205 logfile, 206 silent=(silent or progress), 207 tailLength=tailLength, 208 sleep=sleep) 209 GnuplotCommon.__init__(self, 210 logfile, 211 smallestFreq=smallestFreq, 212 persist=persist, 213 plotLinear=plotLinear, 214 plotCont=plotCont, 215 plotBound=plotBound, 216 plotIterations=plotIterations, 217 plotCourant=plotCourant, 218 plotExecution=plotExecution, 219 plotDeltaT=plotDeltaT, 220 customRegexp=customRegexp, 221 hardcopy=hardcopy, 222 hardcopyFormat=hardcopyFormat, 223 hardcopyPrefix=hardcopyPrefix, 224 writeFiles=writeFiles, 225 raiseit=raiseit, 226 progress=progress, 227 start=start, 228 end=end, 229 singleFile=singleFile, 230 plottingImplementation=plottingImplementation) 231 232 self.hasPlotted=False 233 self.replotFrequency=replotFrequency
234
235 - def startHandle(self):
236 self.bakFreq=self.freq 237 if self.endTime!=None: 238 self.freq=1 239 else: 240 self.freq=self.replotFrequency
241
242 - def tailingHandle(self):
243 self.freq=self.bakFreq 244 self.oldtime=0
245
246 - def timeHandle(self):
247 plotNow=True 248 if not self.hasPlotted and self.endTime!=None: 249 try: 250 if float(self.getTime())>self.endTime: 251 self.hasPlotted=True 252 except ValueError: 253 pass 254 elif self.hasPlotted: 255 plotNow=False 256 if plotNow: 257 for p in self.plots: 258 self.plots[p].redo()
259