1
2 """Runner that outputs the residuals of the linear solver with Gnuplot"""
3
4 from StepAnalyzedCommon import StepAnalyzedCommon
5 from BasicRunner import BasicRunner
6 from BasicWatcher import BasicWatcher
7
8 from PyFoam.LogAnalysis.BoundingLogAnalyzer import BoundingLogAnalyzer
9 from PyFoam.LogAnalysis.RegExpLineAnalyzer import RegExpLineAnalyzer
10 from PyFoam.LogAnalysis.SteadyConvergedLineAnalyzer import SteadyConvergedLineAnalyzer
11 from PyFoam.Basics.GnuplotTimelines import GnuplotTimelines
12 from PyFoam.Basics.TimeLineCollection import signedMax
13
14 from os import path
15
17 """Class that collects the Gnuplotting-Stuff for two other classes"""
18 - def __init__(self,
19 fname,
20 smallestFreq=0.,
21 persist=None,
22 splitThres=2048,
23 plotLinear=True,
24 plotCont=True,
25 plotBound=True,
26 plotIterations=False,
27 plotCourant=False,
28 plotExecution=False,
29 plotDeltaT=False,
30 hardcopy=False,
31 customRegexp=None,
32 writeFiles=False,
33 raiseit=False,
34 progress=False,
35 start=None,
36 end=None):
37 """
38 TODO: Docu
39 """
40 StepAnalyzedCommon.__init__(self,
41 fname,
42 BoundingLogAnalyzer(doTimelines=True,
43 doFiles=writeFiles,
44 progress=progress),
45 smallestFreq=smallestFreq)
46
47 self.plots={}
48
49 if plotLinear:
50 self.plots["linear"]=GnuplotTimelines(self.getAnalyzer("Linear").lines,
51 persist=persist,
52 raiseit=raiseit,
53 forbidden=["final","iterations"],
54 start=start,
55 end=end,
56 logscale=True)
57 self.getAnalyzer("Linear").lines.setSplitting(splitThres=splitThres,splitFun=max)
58
59 self.plots["linear"].title("Residuals")
60
61 if plotCont:
62 self.plots["cont"]=GnuplotTimelines(self.getAnalyzer("Continuity").lines,
63 persist=persist,
64 alternateAxis=["Global"],
65 raiseit=raiseit,
66 start=start,
67 end=end)
68 self.plots["cont"].set_string("ylabel \"Cumulative\"")
69 self.plots["cont"].set_string("y2label \"Global\"")
70 self.getAnalyzer("Continuity").lines.setSplitting(splitThres=splitThres)
71
72 self.plots["cont"].title("Continuity")
73
74 if plotBound:
75 self.plots["bound"]=GnuplotTimelines(self.getAnalyzer("Bounding").lines,
76 persist=persist,
77 raiseit=raiseit,
78 start=start,
79 end=end)
80 self.getAnalyzer("Bounding").lines.setSplitting(splitThres=splitThres,splitFun=signedMax)
81 self.plots["bound"].title("Bounded variables")
82
83 if plotIterations:
84 self.plots["iter"]=GnuplotTimelines(self.getAnalyzer("Iterations").lines,
85 persist=persist,
86 with="steps",
87 raiseit=raiseit,
88 start=start,
89 end=end)
90 self.getAnalyzer("Iterations").lines.setSplitting(splitThres=splitThres)
91
92 self.plots["iter"].title("Iterations")
93
94 if plotCourant:
95 self.plots["courant"]=GnuplotTimelines(self.getAnalyzer("Courant").lines,
96 persist=persist,
97 raiseit=raiseit,
98 start=start,
99 end=end)
100 self.getAnalyzer("Courant").lines.setSplitting(splitThres=splitThres)
101
102 self.plots["courant"].title("Courant")
103
104 if plotDeltaT:
105 self.plots["deltaT"]=GnuplotTimelines(self.getAnalyzer("DeltaT").lines,
106 persist=persist,
107 raiseit=raiseit,
108 start=start,
109 end=end,
110 logscale=True)
111 self.getAnalyzer("DeltaT").lines.setSplitting(splitThres=splitThres)
112
113 self.plots["deltaT"].title("DeltaT")
114
115 if plotExecution:
116 self.plots["execution"]=GnuplotTimelines(self.getAnalyzer("Execution").lines,
117 persist=persist,
118 with="steps",
119 raiseit=raiseit,
120 start=start,
121 end=end)
122 self.getAnalyzer("Execution").lines.setSplitting(splitThres=splitThres)
123
124 self.plots["execution"].title("Execution Time")
125
126 if customRegexp:
127 self.plotCustom=[]
128 for i in range(len(customRegexp)):
129 name="Custom%02d" % i
130 expr=customRegexp[i]
131 titles=[]
132 theTitle="Custom %d" % i
133 options = { "persist" : persist,
134 "raiseit" : raiseit,
135 "start" : start,
136 "end" : end }
137
138 if expr[0]=="{":
139 data=eval(expr)
140 expr=data["expr"]
141 if "name" in data:
142 name+="_"+data["name"]
143 name=name.replace(" ","_").replace(path.sep,"Slash")
144 theTitle+=" - "+data["name"]
145 if "titles" in data:
146 titles=data["titles"]
147 for o in ["alternateAxis","logscale","with","ylabel","y2label"]:
148 if o in data:
149 options[o]=data[o]
150
151 self.addAnalyzer(name,
152 RegExpLineAnalyzer(name.lower(),
153 expr,titles=titles,
154 doTimelines=True,
155 doFiles=writeFiles))
156 plotCustom=GnuplotTimelines(*[self.getAnalyzer(name).lines],
157 **options)
158 self.getAnalyzer(name).lines.setSplitting(splitThres=splitThres)
159 plotCustom.title(theTitle)
160 self.plots["custom%04d" % i]=plotCustom
161
162
163 self.reset()
164
165 self.hardcopy=hardcopy
166
168 for p in self.plots:
169 self.plots[p].redo()
170
176
178 - def __init__(self,
179 argv=None,
180 smallestFreq=0.,
181 persist=None,
182 plotLinear=True,
183 plotCont=True,
184 plotBound=True,
185 plotIterations=False,
186 plotCourant=False,
187 plotExecution=False,
188 plotDeltaT=False,
189 customRegexp=None,
190 hardcopy=False,
191 writeFiles=False,
192 server=False,
193 lam=None,
194 raiseit=False,
195 steady=False,
196 progress=False,
197 restart=False,
198 logname=None):
199 """@param smallestFreq: smallest Frequency of output
200 @param persist: Gnuplot window persistst after run
201 @param steady: Is it a steady run? Then stop it after convergence"""
202 BasicRunner.__init__(self,
203 argv=argv,
204 silent=progress,
205 server=server,
206 lam=lam,
207 restart=restart,
208 logname=logname)
209 GnuplotCommon.__init__(self,
210 "Gnuplotting",
211 smallestFreq=smallestFreq,
212 persist=persist,
213 plotLinear=plotLinear,
214 plotCont=plotCont,
215 plotBound=plotBound,
216 plotIterations=plotIterations,
217 plotCourant=plotCourant,
218 plotExecution=plotExecution,
219 plotDeltaT=plotDeltaT,
220 customRegexp=customRegexp,
221 hardcopy=hardcopy,
222 writeFiles=writeFiles,
223 raiseit=raiseit,
224 progress=progress)
225 self.steady=steady
226 if self.steady:
227 self.steadyAnalyzer=SteadyConvergedLineAnalyzer()
228 self.addAnalyzer("Convergence",self.steadyAnalyzer)
229
237
242
244 - def __init__(self,
245 logfile,
246 smallestFreq=0.,
247 persist=None,
248 silent=False,
249 tailLength=1000,
250 sleep=0.1,
251 plotLinear=True,
252 plotCont=True,
253 plotBound=True,
254 plotIterations=False,
255 plotCourant=False,
256 plotExecution=False,
257 plotDeltaT=False,
258 customRegexp=None,
259 writeFiles=False,
260 hardcopy=False,
261 raiseit=False,
262 progress=False,
263 start=None,
264 end=None):
265 """@param smallestFreq: smallest Frequency of output
266 @param persist: Gnuplot window persistst after run"""
267 BasicWatcher.__init__(self,
268 logfile,
269 silent=(silent or progress),
270 tailLength=tailLength,
271 sleep=sleep)
272 GnuplotCommon.__init__(self,
273 logfile,
274 smallestFreq=smallestFreq,
275 persist=persist,
276 plotLinear=plotLinear,
277 plotCont=plotCont,
278 plotBound=plotBound,
279 plotIterations=plotIterations,
280 plotCourant=plotCourant,
281 plotExecution=plotExecution,
282 plotDeltaT=plotDeltaT,
283 customRegexp=customRegexp,
284 hardcopy=hardcopy,
285 writeFiles=writeFiles,
286 raiseit=raiseit,
287 progress=progress,
288 start=start,
289 end=end)
290
292 self.bakFreq=self.freq
293 self.freq=3600
294
296 self.freq=self.bakFreq
297 self.oldtime=0
298