1 """
2 Class that implements pyFoamPlotRunner
3 """
4
5 from PyFoamApplication import PyFoamApplication
6
7 from PyFoam.Execution.GnuplotRunner import GnuplotRunner
8
9 from PyFoam.Execution.ParallelExecution import LAMMachine
10
11 from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
12
15 description="""
16 runs an OpenFoam solver needs the usual 3 arguments (<solver>
17 <directory> <case>) and passes them on (plus additional arguments).
18 Output is sent to stdout and a logfile inside the case directory
19 (PyFoamSolver.logfile) Information about the residuals is output as
20 graphs
21 """
22 PyFoamApplication.__init__(self,description=description)
23
25 self.parser.add_option("--frequency",type="float",dest="frequency",default=1.,help="The frequency with which output should be generated (in seconds)")
26 self.parser.add_option("--persist",action="store_true",dest="persist",default=True,help="Gnuplot windows stay after interrupt")
27 self.parser.add_option("--non-persist",action="store_false",dest="persist",help="Gnuplot windows close after interrupt")
28 self.parser.add_option("--raise",action="store_true",dest="raiseit",help="Raise the Gnuplot windows after every replot")
29 self.parser.add_option("--no-linear",action="store_false",default=True,dest="linear",help="Don't plot the linear solver convergence")
30 self.parser.add_option("--no-continuity",action="store_false",default=True,dest="cont",help="Don't plot the continuity info")
31 self.parser.add_option("--no-bound",action="store_false",default=True,dest="bound",help="Don't plot the bounding of variables")
32 self.parser.add_option("--with-iterations",action="store_true",default=False,dest="iterations",help="Plot the number of iterations of the linear solver")
33 self.parser.add_option("--with-courant",action="store_true",default=False,dest="courant",help="Plot the courant-numbers of the flow")
34 self.parser.add_option("--with-execution",action="store_true",default=False,dest="execution",help="Plot the execution time of each time-step")
35 self.parser.add_option("--with-deltat",action="store_true",default=False,dest="deltaT",help="'Plot the timestep-size time-step")
36 self.parser.add_option("--with-all",action="store_true",default=False,dest="withAll",help="Switch all possible plots on")
37 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)")
38 self.parser.add_option("--write-files",action="store_true",default=False,dest="writeFiles",help="Writes the parsed data to files")
39 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")
40 self.parser.add_option("--procnr",type="int",dest="procnr",default=None,help="The number of processors the run should be started on")
41 self.parser.add_option("--machinefile",dest="machinefile",default=None,help="The machinefile that specifies the parallel machine")
42 self.parser.add_option("--clear-case",action="store_true",default=False,dest="clearCase",help="Clear all timesteps except for the first before running")
43 self.parser.add_option("--steady-run",action="store_true",default=False,dest="steady",help="This is a steady run. Stop it after convergence")
44
46 if self.opts.withAll:
47 self.opts.linear=True
48 self.opts.cont=True
49 self.opts.bound=True
50 self.opts.iterations=True
51 self.opts.courant=True
52 self.opts.execution=True
53 self.opts.deltaT=True
54
55 if self.opts.regexpFile!=None:
56 f=open(self.opts.regexpFile)
57
58 for l in f.readlines():
59 l=l.strip()
60 if l[0]=='"' and l[-1]=='"':
61 l=l[1:-1]
62 if len(l)>0:
63 if self.opts.customRegex==None:
64 self.opts.customRegex=[]
65 self.opts.customRegex.append(l)
66 f.close()
67
68 if self.opts.clearCase:
69 print "Clearing out old timesteps ...."
70
71 cName=self.parser.getArgs()[2]
72 sol=SolutionDirectory(cName)
73 sol.clearResults()
74
75 lam=None
76 if self.opts.procnr!=None or self.opts.machinefile!=None:
77 lam=LAMMachine(machines=self.opts.machinefile,nr=self.opts.procnr)
78
79 run=GnuplotRunner(argv=self.parser.getArgs(),smallestFreq=self.opts.frequency,persist=self.opts.persist,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,server=True,lam=lam,raiseit=self.opts.raiseit,steady=self.opts.steady)
80
81 run.start()
82