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

Source Code for Module PyFoam.Applications.PlotWatcher

  1  #  ICE Revision: $Id: PlotWatcher.py 7831 2007-08-28 08:07:39Z bgschaid $  
  2  """ 
  3  Class that implements pyFoamPlotWatcher 
  4  """ 
  5   
  6  from PyFoam.Execution.GnuplotRunner import GnuplotWatcher 
  7   
  8  from PyFoamApplication import PyFoamApplication 
  9   
10 -class PlotWatcher(PyFoamApplication):
11 - def __init__(self):
12 description=""" 13 Gets the name of a logfile which is assumed to be the output of a 14 OpenFOAM-solver. Parses the logfile for information about the 15 convergence of the solver and generates gnuplot-graphs. Watches the 16 file until interrupted. 17 """ 18 PyFoamApplication.__init__(self,description=description,usage="%prog [options] <logfile>",interspersed=True,nr=1)
19
20 - def addOptions(self):
21 self.parser.add_option("--frequency", 22 type="float", 23 dest="frequency", 24 default=1., 25 help="The frequency with which output should be generated (in seconds)") 26 self.parser.add_option("--persist", 27 action="store_true", 28 dest="persist", 29 default=False, 30 help="Gnuplot windows stay after interrupt") 31 self.parser.add_option("--non-persist", 32 action="store_false", 33 dest="persist", 34 help="Gnuplot windows close after interrupt") 35 self.parser.add_option("--raise", 36 action="store_true", 37 dest="raiseit", 38 help="Raise the Gnuplot windows after every replot") 39 self.parser.add_option("--tail", 40 type="long", 41 dest="tail", 42 default=5000L, 43 help="The length at the end of the file that should be output (in bytes)") 44 self.parser.add_option("--silent", 45 action="store_true", 46 dest="silent", 47 default=False, 48 help="Logfile is not copied to the terminal") 49 self.parser.add_option("--no-linear", 50 action="store_false", 51 default=True, 52 dest="linear", 53 help="Don't plot the linear solver convergence") 54 self.parser.add_option("--no-continuity", 55 action="store_false", 56 default=True, 57 dest="cont", 58 help="Don't plot the continuity info") 59 self.parser.add_option("--no-bound", 60 action="store_false", 61 default=True, 62 dest="bound", 63 help="Don't plot the bounding of variables") 64 self.parser.add_option("--with-iterations", 65 action="store_true", 66 default=False, 67 dest="iterations", 68 help="Plot the number of iterations of the linear solver") 69 self.parser.add_option("--with-courant", 70 action="store_true", 71 default=False, 72 dest="courant", 73 help="Plot the courant-numbers of the flow") 74 self.parser.add_option("--with-execution", 75 action="store_true", 76 default=False, 77 dest="execution", 78 help="Plot the execution time of each time-step") 79 self.parser.add_option("--with-deltat", 80 action="store_true", 81 default=False, 82 dest="deltaT", 83 help="'Plot the timestep-size time-step") 84 self.parser.add_option("--with-all", 85 action="store_true", 86 default=False, 87 dest="withAll", 88 help="Switch all possible plots on") 89 self.parser.add_option("--custom-regexp", 90 action="append", 91 default=None, 92 dest="customRegex", 93 help="Add a custom regular expression to be plotted (can be used more than once)") 94 self.parser.add_option("--regexp-file", 95 action="store", 96 default=None, 97 dest="regexpFile", 98 help="A file with regulare expressions that are treated like the expressions given with --custom-regexp") 99 self.parser.add_option("--write-files", 100 action="store_true", 101 default=False, 102 dest="writeFiles", 103 help="Writes the parsed data to files") 104 self.parser.add_option("--progress", 105 action="store_true", 106 default=False, 107 dest="progress", 108 help="Only prints the progress of the simulation, but swallows all the other output") 109 self.parser.add_option("--start", 110 action="store", 111 type="float", 112 default=None, 113 dest="start", 114 help="Start time starting from which the data should be plotted. If undefined the initial time is used") 115 self.parser.add_option("--end", 116 action="store", 117 type="float", 118 default=None, 119 dest="end", 120 help="End time until which the data should be plotted. If undefined it is plotted till the end")
121
122 - def run(self):
123 if self.opts.withAll: 124 self.opts.linear=True 125 self.opts.cont=True 126 self.opts.bound=True 127 self.opts.iterations=True 128 self.opts.courant=True 129 self.opts.execution=True 130 self.opts.deltaT=True 131 132 if self.opts.regexpFile!=None: 133 f=open(self.opts.regexpFile) 134 135 for l in f.readlines(): 136 l=l.strip() 137 if l[0]=='"' and l[-1]=='"': 138 l=l[1:-1] 139 if len(l)>0: 140 if self.opts.customRegex==None: 141 self.opts.customRegex=[] 142 self.opts.customRegex.append(l) 143 f.close() 144 145 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,progress=self.opts.progress,start=self.opts.start,end=self.opts.end) 146 147 run.start()
148