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

Source Code for Module PyFoam.Execution.GnuplotRunner

  1  #  ICE Revision: $Id: GnuplotRunner.py 10098 2009-03-09 09:32:33Z 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,TimeLineCollection 
 13  from PyFoam.Error import error 
 14   
 15  from os import path 
 16   
17 -class GnuplotCommon(StepAnalyzedCommon):
18 """Class that collects the Gnuplotting-Stuff for two other classes"""
19 - def __init__(self, 20 fname, 21 smallestFreq=0., 22 persist=None, 23 splitThres=2048, 24 plotLinear=True, 25 plotCont=True, 26 plotBound=True, 27 plotIterations=False, 28 plotCourant=False, 29 plotExecution=False, 30 plotDeltaT=False, 31 hardcopy=False, 32 hardcopyFormat="png", 33 customRegexp=None, 34 writeFiles=False, 35 raiseit=False, 36 progress=False, 37 start=None, 38 end=None):
39 """ 40 TODO: Docu 41 """ 42 StepAnalyzedCommon.__init__(self, 43 fname, 44 BoundingLogAnalyzer(doTimelines=True, 45 doFiles=writeFiles, 46 progress=progress), 47 smallestFreq=smallestFreq) 48 49 self.plots={} 50 51 if plotLinear: 52 self.plots["linear"]=GnuplotTimelines(self.getAnalyzer("Linear").lines, 53 persist=persist, 54 raiseit=raiseit, 55 forbidden=["final","iterations"], 56 start=start, 57 end=end, 58 logscale=True) 59 self.getAnalyzer("Linear").lines.setSplitting(splitThres=splitThres, 60 splitFun=max, 61 advancedSplit=True) 62 63 self.plots["linear"].title("Residuals") 64 65 if plotCont: 66 self.plots["cont"]=GnuplotTimelines(self.getAnalyzer("Continuity").lines, 67 persist=persist, 68 alternateAxis=["Global"], 69 raiseit=raiseit, 70 start=start, 71 end=end) 72 self.plots["cont"].set_string("ylabel \"Cumulative\"") 73 self.plots["cont"].set_string("y2label \"Global\"") 74 self.getAnalyzer("Continuity").lines.setSplitting(splitThres=splitThres, 75 advancedSplit=True) 76 77 self.plots["cont"].title("Continuity") 78 79 if plotBound: 80 self.plots["bound"]=GnuplotTimelines(self.getAnalyzer("Bounding").lines, 81 persist=persist, 82 raiseit=raiseit, 83 start=start, 84 end=end) 85 self.getAnalyzer("Bounding").lines.setSplitting(splitThres=splitThres, 86 splitFun=signedMax, 87 advancedSplit=True) 88 self.plots["bound"].title("Bounded variables") 89 90 if plotIterations: 91 self.plots["iter"]=GnuplotTimelines(self.getAnalyzer("Iterations").lines, 92 persist=persist, 93 with_="steps", 94 raiseit=raiseit, 95 start=start, 96 end=end) 97 self.getAnalyzer("Iterations").lines.setSplitting(splitThres=splitThres, 98 advancedSplit=True) 99 100 self.plots["iter"].title("Iterations") 101 102 if plotCourant: 103 self.plots["courant"]=GnuplotTimelines(self.getAnalyzer("Courant").lines, 104 persist=persist, 105 raiseit=raiseit, 106 start=start, 107 end=end) 108 self.getAnalyzer("Courant").lines.setSplitting(splitThres=splitThres, 109 advancedSplit=True) 110 111 self.plots["courant"].title("Courant") 112 113 if plotDeltaT: 114 self.plots["deltaT"]=GnuplotTimelines(self.getAnalyzer("DeltaT").lines, 115 persist=persist, 116 raiseit=raiseit, 117 start=start, 118 end=end, 119 logscale=True) 120 self.getAnalyzer("DeltaT").lines.setSplitting(splitThres=splitThres, 121 advancedSplit=True) 122 123 self.plots["deltaT"].title("DeltaT") 124 125 if plotExecution: 126 self.plots["execution"]=GnuplotTimelines(self.getAnalyzer("Execution").lines, 127 persist=persist, 128 with_="steps", 129 raiseit=raiseit, 130 start=start, 131 end=end) 132 self.getAnalyzer("Execution").lines.setSplitting(splitThres=splitThres, 133 advancedSplit=True) 134 135 self.plots["execution"].title("Execution Time") 136 137 if customRegexp: 138 self.plotCustom=[] 139 for i in range(len(customRegexp)): 140 name="Custom%02d" % i 141 expr=customRegexp[i] 142 titles=[] 143 accumulation="first" 144 theTitle="Custom %d" % i 145 options = { "persist" : persist, 146 "raiseit" : raiseit, 147 "start" : start, 148 "end" : end } 149 150 if expr[0]=="{": 151 data=eval(expr) 152 expr=data["expr"] 153 if "name" in data: 154 name+="_"+data["name"] 155 name=name.replace(" ","_").replace(path.sep,"Slash") 156 theTitle+=" - "+data["name"] 157 if "titles" in data: 158 titles=data["titles"] 159 for o in ["alternateAxis","logscale","with","ylabel","y2label"]: 160 if o=="with": 161 use="with_" 162 else: 163 use=o 164 if o in data: 165 options[use]=data[o] 166 if "accumulation" in data: 167 accumulation=data["accumulation"] 168 169 if accumulation not in TimeLineCollection.possibleAccumulations: 170 error("Accumulation",accumulation,"not in the possible values",TimeLineCollection.possibleAccumulations) 171 172 self.addAnalyzer(name, 173 RegExpLineAnalyzer(name.lower(), 174 expr,titles=titles, 175 doTimelines=True, 176 doFiles=writeFiles, 177 accumulation=accumulation, 178 singleFile=True)) 179 plotCustom=GnuplotTimelines(*[self.getAnalyzer(name).lines], 180 **options) 181 self.getAnalyzer(name).lines.setSplitting(splitThres=splitThres, 182 advancedSplit=True) 183 plotCustom.title(theTitle) 184 self.plots["custom%04d" % i]=plotCustom 185 186 187 self.reset() 188 189 self.hardcopy=hardcopy 190 self.hardcopyFormat=hardcopyFormat
191
192 - def timeHandle(self):
193 for p in self.plots: 194 self.plots[p].redo()
195
196 - def stopHandle(self):
197 self.timeHandle() 198 if self.hardcopy: 199 for p in self.plots: 200 if self.hardcopyFormat=="png": 201 self.plots[p].hardcopy(terminal="png",filename=p+".png",color=True,small=True) 202 elif self.hardcopyFormat=="pdf": 203 self.plots[p].hardcopy(terminal="pdf",filename=p+".pdf",color=True) 204 elif self.hardcopyFormat=="svg": 205 self.plots[p].hardcopy(terminal="svg",filename=p+".svg") 206 elif self.hardcopyFormat=="postscript": 207 self.plots[p].hardcopy(terminal="postscript",filename=p+".ps",color=True) 208 elif self.hardcopyFormat=="eps": 209 self.plots[p].hardcopy(terminal="postscript",filename=p+".eps",color=True,eps=True) 210 else: 211 self.plots[p].hardcopy(filename=p+".ps",color=True)
212
213 -class GnuplotRunner(GnuplotCommon,BasicRunner):
214 - def __init__(self, 215 argv=None, 216 smallestFreq=0., 217 persist=None, 218 plotLinear=True, 219 plotCont=True, 220 plotBound=True, 221 plotIterations=False, 222 plotCourant=False, 223 plotExecution=False, 224 plotDeltaT=False, 225 customRegexp=None, 226 hardcopy=False, 227 hardcopyFormat="png", 228 writeFiles=False, 229 server=False, 230 lam=None, 231 raiseit=False, 232 steady=False, 233 progress=False, 234 restart=False, 235 logname=None, 236 noLog=False):
237 """@param smallestFreq: smallest Frequency of output 238 @param persist: Gnuplot window persistst after run 239 @param steady: Is it a steady run? Then stop it after convergence""" 240 BasicRunner.__init__(self, 241 argv=argv, 242 silent=progress, 243 server=server, 244 lam=lam, 245 restart=restart, 246 logname=logname, 247 noLog=noLog) 248 GnuplotCommon.__init__(self, 249 "Gnuplotting", 250 smallestFreq=smallestFreq, 251 persist=persist, 252 plotLinear=plotLinear, 253 plotCont=plotCont, 254 plotBound=plotBound, 255 plotIterations=plotIterations, 256 plotCourant=plotCourant, 257 plotExecution=plotExecution, 258 plotDeltaT=plotDeltaT, 259 customRegexp=customRegexp, 260 hardcopy=hardcopy, 261 hardcopyFormat=hardcopyFormat, 262 writeFiles=writeFiles, 263 raiseit=raiseit, 264 progress=progress) 265 self.steady=steady 266 if self.steady: 267 self.steadyAnalyzer=SteadyConvergedLineAnalyzer() 268 self.addAnalyzer("Convergence",self.steadyAnalyzer)
269
270 - def lineHandle(self,line):
271 """Not to be called: Stops the solver""" 272 GnuplotCommon.lineHandle(self,line) 273 274 if self.steady: 275 if not self.steadyAnalyzer.goOn(): 276 self.stopGracefully()
277
278 - def stopHandle(self):
279 """Not to be called: Restores controlDict""" 280 GnuplotCommon.stopHandle(self) 281 BasicRunner.stopHandle(self)
282
283 -class GnuplotWatcher(GnuplotCommon,BasicWatcher):
284 - def __init__(self, 285 logfile, 286 smallestFreq=0., 287 persist=None, 288 silent=False, 289 tailLength=1000, 290 sleep=0.1, 291 plotLinear=True, 292 plotCont=True, 293 plotBound=True, 294 plotIterations=False, 295 plotCourant=False, 296 plotExecution=False, 297 plotDeltaT=False, 298 customRegexp=None, 299 writeFiles=False, 300 hardcopy=False, 301 hardcopyFormat="png", 302 raiseit=False, 303 progress=False, 304 start=None, 305 end=None):
306 """@param smallestFreq: smallest Frequency of output 307 @param persist: Gnuplot window persistst after run""" 308 BasicWatcher.__init__(self, 309 logfile, 310 silent=(silent or progress), 311 tailLength=tailLength, 312 sleep=sleep) 313 GnuplotCommon.__init__(self, 314 logfile, 315 smallestFreq=smallestFreq, 316 persist=persist, 317 plotLinear=plotLinear, 318 plotCont=plotCont, 319 plotBound=plotBound, 320 plotIterations=plotIterations, 321 plotCourant=plotCourant, 322 plotExecution=plotExecution, 323 plotDeltaT=plotDeltaT, 324 customRegexp=customRegexp, 325 hardcopy=hardcopy, 326 hardcopyFormat=hardcopyFormat, 327 writeFiles=writeFiles, 328 raiseit=raiseit, 329 progress=progress, 330 start=start, 331 end=end)
332
333 - def startHandle(self):
334 self.bakFreq=self.freq 335 self.freq=3600
336
337 - def tailingHandle(self):
338 self.freq=self.bakFreq 339 self.oldtime=0
340