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