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

Source Code for Module PyFoam.Applications.PlotRunner

  1  #  ICE Revision: $Id: PlotRunner.py 9325 2008-09-05 12:01:56Z bgschaid $  
  2  """ 
  3  Class that implements pyFoamPlotRunner 
  4  """ 
  5   
  6  from PyFoamApplication import PyFoamApplication 
  7   
  8  from PyFoam.Execution.GnuplotRunner import GnuplotRunner 
  9   
 10  from PyFoam.Execution.ParallelExecution import LAMMachine 
 11   
 12  from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory 
 13   
 14  from PyFoam.Error import warning 
 15   
 16  from CommonPlotLines import CommonPlotLines 
 17  from CommonPlotOptions import CommonPlotOptions 
 18  from CommonClearCase import CommonClearCase 
 19  from CommonSafeTrigger import CommonSafeTrigger 
 20  from CommonWriteAllTrigger import CommonWriteAllTrigger 
 21  from CommonLibFunctionTrigger import CommonLibFunctionTrigger 
 22   
 23  from os import path 
 24   
25 -class PlotRunner(PyFoamApplication, 26 CommonPlotOptions, 27 CommonPlotLines, 28 CommonSafeTrigger, 29 CommonWriteAllTrigger, 30 CommonLibFunctionTrigger, 31 CommonClearCase):
32 - def __init__(self,args=None):
33 description=""" 34 runs an OpenFoam solver needs the usual 3 arguments (<solver> 35 <directory> <case>) and passes them on (plus additional arguments). 36 Output is sent to stdout and a logfile inside the case directory 37 (PyFoamSolver.logfile) Information about the residuals is output as 38 graphs 39 40 If the directory contains a file customRegexp this is automatically 41 read and the regular expressions in it are displayed 42 """ 43 CommonPlotOptions.__init__(self,persist=True) 44 CommonPlotLines.__init__(self) 45 PyFoamApplication.__init__(self, 46 exactNr=False, 47 args=args, 48 description=description)
49
50 - def addOptions(self):
51 CommonPlotOptions.addOptions(self) 52 53 self.parser.add_option("--procnr", 54 type="int", 55 dest="procnr", 56 default=None, 57 help="The number of processors the run should be started on") 58 59 self.parser.add_option("--machinefile", 60 dest="machinefile", 61 default=None, 62 help="The machinefile that specifies the parallel machine") 63 64 self.parser.add_option("--steady-run", 65 action="store_true", 66 default=False, 67 dest="steady", 68 help="This is a steady run. Stop it after convergence") 69 70 self.parser.add_option("--restart", 71 action="store_true", 72 default=False, 73 dest="restart", 74 help="Restart the simulation from the last time-step") 75 76 self.parser.add_option("--progress", 77 action="store_true", 78 default=False, 79 dest="progress", 80 help="Only prints the progress of the simulation, but swallows all the other output") 81 82 self.parser.add_option("--report-usage", 83 action="store_true", 84 default=False, 85 dest="reportUsage", 86 help="After the execution the maximum memory usage is printed to the screen") 87 88 CommonPlotLines.addOptions(self) 89 CommonClearCase.addOptions(self) 90 CommonSafeTrigger.addOptions(self) 91 CommonWriteAllTrigger.addOptions(self) 92 CommonLibFunctionTrigger.addOptions(self)
93
94 - def run(self):
95 self.processPlotOptions() 96 97 cName=self.parser.casePath() 98 self.checkCase(cName) 99 100 self.processPlotLineOptions(autoPath=cName) 101 102 sol=SolutionDirectory(cName,archive=None) 103 104 self.clearCase(sol) 105 106 lam=None 107 if self.opts.procnr!=None or self.opts.machinefile!=None: 108 lam=LAMMachine(machines=self.opts.machinefile,nr=self.opts.procnr) 109 110 run=GnuplotRunner(argv=self.parser.getArgs(), 111 smallestFreq=self.opts.frequency, 112 persist=self.opts.persist, 113 plotLinear=self.opts.linear, 114 plotCont=self.opts.cont, 115 plotBound=self.opts.bound, 116 plotIterations=self.opts.iterations, 117 plotCourant=self.opts.courant, 118 plotExecution=self.opts.execution, 119 plotDeltaT=self.opts.deltaT, 120 customRegexp=self.plotLines(), 121 writeFiles=self.opts.writeFiles, 122 hardcopy=self.opts.hardcopy, 123 server=True, 124 lam=lam, 125 raiseit=self.opts.raiseit, 126 steady=self.opts.steady, 127 progress=self.opts.progress, 128 restart=self.opts.restart) 129 130 self.addSafeTrigger(run,sol,steady=self.opts.steady) 131 self.addWriteAllTrigger(run,sol) 132 self.addLibFunctionTrigger(run,sol) 133 134 run.start() 135 136 if self.opts.reportUsage: 137 print "\n Used Memory: ",run.run.usedMemory(),"MB"
138