Package PyFoam :: Package Applications :: Module PlotWatcher
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.PlotWatcher

 1  """ 
 2  Class that implements pyFoamPlotWatcher 
 3  """ 
 4   
 5  from PyFoam.Execution.GnuplotRunner import GnuplotWatcher 
 6   
 7  from PyFoamApplication import PyFoamApplication 
 8   
9 -class PlotWatcher(PyFoamApplication):
10 - def __init__(self):
11 description=""" 12 Gets the name of a logfile which is assumed to be the output of a 13 OpenFOAM-solver. Parses the logfile for information about the 14 convergence of the solver and generates gnuplot-graphs. Watches the 15 file until interrupted. 16 """ 17 PyFoamApplication.__init__(self,description=description,usage="%prog [options] <logfile>",interspersed=True,nr=1)
18
19 - def addOptions(self):
20 self.parser.add_option("--frequency",type="float",dest="frequency",default=1.,help="The frequency with which output should be generated (in seconds)") 21 self.parser.add_option("--persist",action="store_true",dest="persist",default=False,help="Gnuplot windows stay after interrupt") 22 self.parser.add_option("--non-persist",action="store_false",dest="persist",help="Gnuplot windows close after interrupt") 23 self.parser.add_option("--raise",action="store_true",dest="raiseit",help="Raise the Gnuplot windows after every replot") 24 self.parser.add_option("--tail",type="long",dest="tail",default=5000L,help="The length at the end of the file that should be output (in bytes)") 25 self.parser.add_option("--silent",action="store_true",dest="silent",default=False,help="Logfile is not copied to the terminal") 26 self.parser.add_option("--no-linear",action="store_false",default=True,dest="linear",help="Don't plot the linear solver convergence") 27 self.parser.add_option("--no-continuity",action="store_false",default=True,dest="cont",help="Don't plot the continuity info") 28 self.parser.add_option("--no-bound",action="store_false",default=True,dest="bound",help="Don't plot the bounding of variables") 29 self.parser.add_option("--with-iterations",action="store_true",default=False,dest="iterations",help="Plot the number of iterations of the linear solver") 30 self.parser.add_option("--with-courant",action="store_true",default=False,dest="courant",help="Plot the courant-numbers of the flow") 31 self.parser.add_option("--with-execution",action="store_true",default=False,dest="execution",help="Plot the execution time of each time-step") 32 self.parser.add_option("--with-deltat",action="store_true",default=False,dest="deltaT",help="'Plot the timestep-size time-step") 33 self.parser.add_option("--with-all",action="store_true",default=False,dest="withAll",help="Switch all possible plots on") 34 self.parser.add_option("--custom-regexp",action="append",default=None,dest="customRegex",help="Add a custom regular expression to be plotted (can be used more than once)") 35 self.parser.add_option("--regexp-file",action="store",default=None,dest="regexpFile",help="A file with regulare expressions that are treated like the expressions given with --custom-regexp") 36 self.parser.add_option("--write-files",action="store_true",default=False,dest="writeFiles",help="Writes the parsed data to files")
37
38 - def run(self):
39 if self.opts.withAll: 40 self.opts.linear=True 41 self.opts.cont=True 42 self.opts.bound=True 43 self.opts.iterations=True 44 self.opts.courant=True 45 self.opts.execution=True 46 self.opts.deltaT=True 47 48 if self.opts.regexpFile!=None: 49 f=open(self.opts.regexpFile) 50 51 for l in f.readlines(): 52 l=l.strip() 53 if l[0]=='"' and l[-1]=='"': 54 l=l[1:-1] 55 if len(l)>0: 56 if self.opts.customRegex==None: 57 self.opts.customRegex=[] 58 self.opts.customRegex.append(l) 59 f.close() 60 61 run=GnuplotWatcher(self.parser.getArgs()[0],smallestFreq=self.opts.frequency,persist=self.opts.persist,tailLength=self.opts.tail,silent=self.opts.silent,plotLinear=self.opts.linear,plotCont=self.opts.cont,plotBound=self.opts.bound,plotIterations=self.opts.iterations,plotCourant=self.opts.courant,plotExecution=self.opts.execution,plotDeltaT=self.opts.deltaT,customRegexp=self.opts.customRegex,writeFiles=self.opts.writeFiles,raiseit=self.opts.raiseit) 62 63 run.start()
64