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

Source Code for Module PyFoam.Execution.AnalyzedCommon

  1  #  ICE Revision: $Id: AnalyzedCommon.py 10976 2009-10-28 10:25:32Z bgschaid $  
  2  """Common stuff for classes that use analyzers""" 
  3   
  4  from os import path,mkdir 
  5   
  6  from PyFoam.Basics.PlotTimelinesFactory import createPlotTimelines,createPlotTimelinesDirect 
  7  from PyFoam.Basics.TimeLineCollection import signedMax 
  8  from PyFoam.LogAnalysis.RegExpLineAnalyzer import RegExpLineAnalyzer 
  9   
 10  from PyFoam.Error import error 
 11   
12 -class AnalyzedCommon(object):
13 """This class collects information and methods that are needed for 14 handling analyzers""" 15
16 - def __init__(self,filename,analyzer):
17 """@param filename: name of the file that is being analyzed 18 @param analyzer: the analyzer itself""" 19 20 self.analyzer=analyzer 21 22 if 'dir' in dir(self): 23 self.logDir=path.join(self.dir,filename+".analyzed") 24 else: 25 self.logDir=filename+".analyzed" 26 27 if not path.exists(self.logDir): 28 mkdir(self.logDir) 29 30 self.reset()
31
32 - def tearDown(self):
33 self.analyzer.tearDown()
34
35 - def listAnalyzers(self):
36 """@returns: A list with the names of the analyzers""" 37 return self.analyzer.listAnalyzers()
38
39 - def getAnalyzer(self,name):
40 """@param name: name of the LineAnalyzer to get""" 41 return self.analyzer.getAnalyzer(name)
42
43 - def hasAnalyzer(self,name):
44 """@param name: name of the LineAnalyzer we ask for""" 45 return self.analyzer.hasAnalyzer(name)
46
47 - def addAnalyzer(self,name,analyzer):
48 """@param name: name of the LineAnalyzer to add 49 @param analyzer: the analyzer to add""" 50 analyzer.setDirectory(self.logDir) 51 return self.analyzer.addAnalyzer(name,analyzer)
52
53 - def lineHandle(self,line):
54 """Not to be called: calls the analyzer for the current line""" 55 self.analyzer.analyzeLine(line)
56
57 - def reset(self):
58 """reset the analyzer""" 59 self.analyzer.setDirectory(self.logDir)
60
61 - def getDirname(self):
62 """Get the name of the directory where the data is written to""" 63 return self.logDir
64
65 - def getTime(self):
66 """Get the execution time""" 67 return self.analyzer.getTime()
68
69 - def addTrigger(self,time,func,once=True,until=None):
70 """Adds a timed trigger to the Analyzer 71 @param time: the time at which the function should be triggered 72 @param func: the trigger function 73 @param once: Should this function be called once or at every time-step 74 @param until: The time until which the trigger should be called""" 75 76 self.analyzer.addTrigger(time,func,once=once,until=until)
77
78 - def createPlots(self, 79 persist=None, 80 raiseit=False, 81 splitThres=2048, 82 plotLinear=True, 83 plotCont=True, 84 plotBound=True, 85 plotIterations=True, 86 plotCourant=True, 87 plotExecution=True, 88 plotDeltaT=True, 89 start=None, 90 end=None, 91 writeFiles=False, 92 customRegexp=None, 93 plottingImplementation="dummy"):
94 95 plots={} 96 97 if plotLinear and self.hasAnalyzer("Linear"): 98 plots["linear"]=createPlotTimelinesDirect("linear", 99 self.getAnalyzer("Linear").lines, 100 persist=persist, 101 raiseit=raiseit, 102 forbidden=["final","iterations"], 103 start=start, 104 end=end, 105 logscale=True, 106 implementation=plottingImplementation) 107 self.getAnalyzer("Linear").lines.setSplitting(splitThres=splitThres, 108 splitFun=max, 109 advancedSplit=True) 110 111 plots["linear"].setTitle("Residuals") 112 113 if plotCont and self.hasAnalyzer("Continuity"): 114 plots["cont"]=createPlotTimelinesDirect("continuity", 115 self.getAnalyzer("Continuity").lines, 116 persist=persist, 117 alternateAxis=["Global"], 118 raiseit=raiseit, 119 start=start, 120 end=end, 121 implementation=plottingImplementation) 122 plots["cont"].setYLabel("Cumulative") 123 plots["cont"].setYLabel2("Global") 124 self.getAnalyzer("Continuity").lines.setSplitting(splitThres=splitThres, 125 advancedSplit=True) 126 127 plots["cont"].setTitle("Continuity") 128 129 if plotBound and self.hasAnalyzer("Bounding"): 130 plots["bound"]=createPlotTimelinesDirect("bounding", 131 self.getAnalyzer("Bounding").lines, 132 persist=persist, 133 raiseit=raiseit, 134 start=start, 135 end=end, 136 implementation=plottingImplementation) 137 self.getAnalyzer("Bounding").lines.setSplitting(splitThres=splitThres, 138 splitFun=signedMax, 139 advancedSplit=True) 140 plots["bound"].setTitle("Bounded variables") 141 142 if plotIterations and self.hasAnalyzer("Iterations"): 143 plots["iter"]=createPlotTimelinesDirect("iterations", 144 self.getAnalyzer("Iterations").lines, 145 persist=persist, 146 with_="steps", 147 raiseit=raiseit, 148 start=start, 149 end=end, 150 implementation=plottingImplementation) 151 self.getAnalyzer("Iterations").lines.setSplitting(splitThres=splitThres, 152 advancedSplit=True) 153 154 plots["iter"].setTitle("Iterations") 155 156 if plotCourant and self.hasAnalyzer("Courant"): 157 plots["courant"]=createPlotTimelinesDirect("courant", 158 self.getAnalyzer("Courant").lines, 159 persist=persist, 160 raiseit=raiseit, 161 start=start, 162 end=end, 163 implementation=plottingImplementation) 164 self.getAnalyzer("Courant").lines.setSplitting(splitThres=splitThres, 165 advancedSplit=True) 166 167 plots["courant"].setTitle("Courant") 168 169 if plotDeltaT and self.hasAnalyzer("DeltaT"): 170 plots["deltaT"]=createPlotTimelinesDirect("timestep", 171 self.getAnalyzer("DeltaT").lines, 172 persist=persist, 173 raiseit=raiseit, 174 start=start, 175 end=end, 176 logscale=True, 177 implementation=plottingImplementation) 178 self.getAnalyzer("DeltaT").lines.setSplitting(splitThres=splitThres, 179 advancedSplit=True) 180 181 plots["deltaT"].setTitle("DeltaT") 182 183 if plotExecution and self.hasAnalyzer("Execution"): 184 plots["execution"]=createPlotTimelinesDirect("execution", 185 self.getAnalyzer("Execution").lines, 186 persist=persist, 187 with_="steps", 188 raiseit=raiseit, 189 start=start, 190 end=end, 191 implementation=plottingImplementation) 192 self.getAnalyzer("Execution").lines.setSplitting(splitThres=splitThres, 193 advancedSplit=True) 194 195 plots["execution"].setTitle("Execution Time") 196 197 if customRegexp: 198 self.plotCustom=[] 199 masters={} 200 slaves=[] 201 for i,custom in enumerate(customRegexp): 202 if persist!=None: 203 custom.persist=persist 204 if start!=None: 205 custom.start=start 206 if end!=None: 207 custom.end=end 208 custom.raiseit=raiseit 209 210 if custom.type=="dynamic": 211 self.addAnalyzer(custom.name, 212 RegExpLineAnalyzer(custom.name.lower(), 213 custom.expr, 214 titles=custom.titles, 215 doTimelines=True, 216 doFiles=writeFiles, 217 accumulation=custom.accumulation, 218 singleFile=True, 219 idNr=custom.idNr, 220 startTime=custom.start, 221 endTime=custom.end)) 222 223 else: 224 self.addAnalyzer(custom.name, 225 RegExpLineAnalyzer(custom.name.lower(), 226 custom.expr, 227 titles=custom.titles, 228 doTimelines=True, 229 doFiles=writeFiles, 230 accumulation=custom.accumulation, 231 singleFile=True, 232 startTime=custom.start, 233 endTime=custom.end)) 234 235 if custom.master==None: 236 masters[custom.id]=custom 237 plotCustom=createPlotTimelines(self.getAnalyzer(custom.name).lines, 238 custom=custom, 239 implementation=plottingImplementation) 240 self.getAnalyzer(custom.name).lines.setSplitting(splitThres=splitThres, 241 advancedSplit=True) 242 plotCustom.setTitle(custom.theTitle) 243 plots["custom%04d" % i]=plotCustom 244 else: 245 slaves.append(custom) 246 247 for s in slaves: 248 if s.master not in masters: 249 error("The custom plot",s.id,"wants the master plot",s.master,"but it is not found in the list of masters",masters.keys()) 250 else: 251 slave=self.getAnalyzer(s.name) 252 master=self.getAnalyzer(masters[s.master].name) 253 slave.setMaster(master) 254 255 self.reset() 256 257 return plots
258