1
2 """
3 Class that implements pyFoamPlotRunner
4 """
5
6 from PyFoamApplication import PyFoamApplication
7
8 from PyFoam.FoamInformation import changeFoamVersion
9
10 from PyFoam.Execution.GnuplotRunner import GnuplotRunner
11
12 from PyFoam.Execution.ParallelExecution import LAMMachine
13
14 from PyFoam.RunDictionary.SolutionDirectory import SolutionDirectory
15
16 from os import path
17
20 description="""
21 runs an OpenFoam solver needs the usual 3 arguments (<solver>
22 <directory> <case>) and passes them on (plus additional arguments).
23 Output is sent to stdout and a logfile inside the case directory
24 (PyFoamSolver.logfile) Information about the residuals is output as
25 graphs
26
27 If the directory contains a file customRegexp this is automatically
28 read and the regular expressions in it are displayed
29 """
30 PyFoamApplication.__init__(self,description=description)
31
33 self.parser.add_option("--frequency",
34 type="float",
35 dest="frequency",
36 default=1.,
37 help="The frequency with which output should be generated (in seconds)")
38
39 self.parser.add_option("--persist",
40 action="store_true",
41 dest="persist",
42 default=True,
43 help="Gnuplot windows stay after interrupt")
44
45 self.parser.add_option("--non-persist",
46 action="store_false",
47 dest="persist",
48 help="Gnuplot windows close after interrupt")
49
50 self.parser.add_option("--raise",
51 action="store_true",
52 dest="raiseit",
53 help="Raise the Gnuplot windows after every replot")
54
55 self.parser.add_option("--no-default",
56 action="store_true",
57 default=False,
58 dest="nodefault",
59 help="Switch off the default plots (linear, continuity and bound)")
60
61 self.parser.add_option("--no-linear",
62 action="store_false",
63 default=True,
64 dest="linear",
65 help="Don't plot the linear solver convergence")
66
67 self.parser.add_option("--no-continuity",
68 action="store_false",
69 default=True,
70 dest="cont",
71 help="Don't plot the continuity info")
72
73 self.parser.add_option("--no-bound",
74 action="store_false",
75 default=True,
76 dest="bound",
77 help="Don't plot the bounding of variables")
78
79 self.parser.add_option("--with-iterations",
80 action="store_true",
81 default=False,
82 dest="iterations",
83 help="Plot the number of iterations of the linear solver")
84
85 self.parser.add_option("--with-courant",
86 action="store_true",
87 default=False,
88 dest="courant",
89 help="Plot the courant-numbers of the flow")
90
91 self.parser.add_option("--with-execution",
92 action="store_true",
93 default=False,
94 dest="execution",
95 help="Plot the execution time of each time-step")
96
97 self.parser.add_option("--with-deltat",
98 action="store_true",
99 default=False,
100 dest="deltaT",
101 help="'Plot the timestep-size time-step")
102
103 self.parser.add_option("--with-all",
104 action="store_true",
105 default=False,
106 dest="withAll",
107 help="Switch all possible plots on")
108
109 self.parser.add_option("--custom-regexp",
110 action="append",
111 default=None,
112 dest="customRegex",
113 help="Add a custom regular expression to be plotted (can be used more than once)")
114
115 self.parser.add_option("--write-files",
116 action="store_true",
117 default=False,
118 dest="writeFiles",
119 help="Writes the parsed data to files")
120
121 self.parser.add_option("--regexp-file",
122 action="store",
123 default=None,
124 dest="regexpFile",
125 help="A file with regulare expressions that are treated like the expressions given with --custom-regexp")
126
127 self.parser.add_option("--procnr",
128 type="int",
129 dest="procnr",
130 default=None,
131 help="The number of processors the run should be started on")
132
133 self.parser.add_option("--machinefile",
134 dest="machinefile",
135 default=None,
136 help="The machinefile that specifies the parallel machine")
137
138 self.parser.add_option("--clear-case",
139 action="store_true",
140 default=False,
141 dest="clearCase",
142 help="Clear all timesteps except for the first before running")
143
144 self.parser.add_option("--steady-run",
145 action="store_true",
146 default=False,
147 dest="steady",
148 help="This is a steady run. Stop it after convergence")
149
150 self.parser.add_option("--progress",
151 action="store_true",
152 default=False,
153 dest="progress",
154 help="Only prints the progress of the simulation, but swallows all the other output")
155
156 self.parser.add_option("--foamVersion",
157 dest="foamVersion",
158 default=None,
159 help="Change the OpenFOAM-version that is to be used")
160
162 """Adds the lines from a file to the custom regular expressions
163 @param fName: The name of the file"""
164 f=open(fName)
165
166 for l in f.readlines():
167 l=l.strip()
168 if l[0]=='"' and l[-1]=='"':
169 l=l[1:-1]
170 if len(l)>0:
171 if self.opts.customRegex==None:
172 self.opts.customRegex=[]
173 self.opts.customRegex.append(l)
174 f.close()
175
176
178 if self.opts.foamVersion!=None:
179 changeFoamVersion(self.opts.foamVersion)
180
181 if self.opts.nodefault:
182 self.opts.linear=False
183 self.opts.cont=False
184 self.opts.bound=False
185
186 if self.opts.withAll:
187 self.opts.linear=True
188 self.opts.cont=True
189 self.opts.bound=True
190 self.opts.iterations=True
191 self.opts.courant=True
192 self.opts.execution=True
193 self.opts.deltaT=True
194
195 if self.opts.regexpFile!=None:
196 self.addFileRegexps(self.opts.regexpFile)
197
198 autoFile=path.join(self.parser.getArgs()[1],self.parser.getArgs()[2],"customRegexp")
199 if path.exists(autoFile):
200 print " Reading regular expressions from",autoFile
201 self.addFileRegexps(autoFile)
202
203 if self.opts.clearCase:
204 print "Clearing out old timesteps ...."
205
206 cName=self.parser.getArgs()[2]
207 sol=SolutionDirectory(cName)
208 sol.clearResults()
209
210 lam=None
211 if self.opts.procnr!=None or self.opts.machinefile!=None:
212 lam=LAMMachine(machines=self.opts.machinefile,nr=self.opts.procnr)
213
214 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,progress=self.opts.progress)
215
216 run.start()
217