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

Source Code for Module PyFoam.Applications.PlotWatcher

  1  #  ICE Revision: $Id$ 
  2  """ 
  3  Class that implements pyFoamPlotWatcher 
  4  """ 
  5   
  6  from PyFoam.Execution.GnuplotRunner import GnuplotWatcher 
  7   
  8  from .PyFoamApplication import PyFoamApplication 
  9   
 10  from .CommonPlotLines import CommonPlotLines 
 11  from .CommonPlotOptions import CommonPlotOptions 
 12   
 13  from os import path 
 14  from optparse import OptionGroup 
 15   
 16  from PyFoam.ThirdParty.six import PY3 
 17   
 18  if PY3: 
 19      long=int 
 20   
 21   
22 -class PlotWatcher(PyFoamApplication, 23 CommonPlotOptions, 24 CommonPlotLines):
25 - def __init__(self,args=None):
26 description="""\ 27 Gets the name of a logfile which is assumed to be the output of a 28 OpenFOAM-solver. Parses the logfile for information about the 29 convergence of the solver and generates gnuplot-graphs. Watches the 30 file until interrupted. 31 """ 32 33 CommonPlotOptions.__init__(self,persist=False) 34 CommonPlotLines.__init__(self) 35 PyFoamApplication.__init__(self, 36 args=args, 37 description=description, 38 usage="%prog [options] <logfile>", 39 changeVersion=False, 40 interspersed=True, 41 nr=1)
42
43 - def addOptions(self):
44 CommonPlotOptions.addOptions(self) 45 46 input=OptionGroup(self.parser, 47 "Input", 48 "Specifics of the input") 49 self.parser.add_option_group(input) 50 51 input.add_option("--solver-not-running-anymore", 52 action="store_true", 53 dest="solverNotRunning", 54 default=False, 55 help="It makes no sense to wait for further output, because the solver is not running anymore. Watcher ends as soon as he encounters the end of the file. Only makes sense with --persist or --hardcopy") 56 57 output=OptionGroup(self.parser, 58 "Output", 59 "What should be output to the terminal") 60 self.parser.add_option_group(output) 61 62 output.add_option("--tail", 63 type="long", 64 dest="tail", 65 default=long(5000), 66 help="The length at the end of the file that should be output (in bytes. Default: %default)") 67 output.add_option("--silent", 68 action="store_true", 69 dest="silent", 70 default=False, 71 help="Logfile is not copied to the terminal") 72 output.add_option("--progress", 73 action="store_true", 74 default=False, 75 dest="progress", 76 help="Only prints the progress of the simulation, but swallows all the other output") 77 output.add_option("--replot-frequency", 78 action="store", 79 default=10, 80 type="float", 81 dest="replotFrequency", 82 help="If the tail of the file is not yet reached, how often the data should be plotted: Default: %default") 83 84 limit=OptionGroup(self.parser, 85 "Limits", 86 "Where the plots should start and end") 87 self.parser.add_option_group(limit) 88 89 limit.add_option("--start", 90 action="store", 91 type="float", 92 default=None, 93 dest="start", 94 help="Start time starting from which the data should be plotted. If undefined the initial time is used") 95 96 limit.add_option("--end", 97 action="store", 98 type="float", 99 default=None, 100 dest="end", 101 help="End time until which the data should be plotted. If undefined it is plotted till the end") 102 103 CommonPlotLines.addOptions(self)
104
105 - def run(self):
106 self.processPlotOptions() 107 hereDir=path.dirname(self.parser.getArgs()[0]) 108 self.processPlotLineOptions(autoPath=hereDir) 109 self.addLocalConfig(hereDir) 110 111 run=GnuplotWatcher(self.parser.getArgs()[0], 112 smallestFreq=self.opts.frequency, 113 persist=self.opts.persist, 114 tailLength=self.opts.tail, 115 silent=self.opts.silent, 116 hardcopy=self.opts.hardcopy, 117 hardcopyPrefix=self.opts.hardcopyPrefix, 118 hardcopyFormat=self.opts.hardcopyformat, 119 plotLinear=self.opts.linear, 120 plotCont=self.opts.cont, 121 plotBound=self.opts.bound, 122 plotIterations=self.opts.iterations, 123 plotCourant=self.opts.courant, 124 plotExecution=self.opts.execution, 125 plotDeltaT=self.opts.deltaT, 126 customRegexp=self.plotLines(), 127 writeFiles=self.opts.writeFiles, 128 raiseit=self.opts.raiseit, 129 progress=self.opts.progress, 130 start=self.opts.start, 131 end=self.opts.end, 132 singleFile=self.opts.singleDataFilesOnly, 133 replotFrequency=self.opts.replotFrequency, 134 writePickled=self.opts.writePickled, 135 plottingImplementation=self.opts.implementation, 136 solverNotRunning=self.opts.solverNotRunning) 137 138 run.start()
139 140 # Should work with Python3 and Python2 141