/[escript]/trunk/modellib/py_src/visualization.py
ViewVC logotype

Contents of /trunk/modellib/py_src/visualization.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (show annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years, 10 months ago) by ksteube
File MIME type: text/x-python
File size: 19602 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

1 #
2 # $Id$
3 #
4 #######################################################
5 #
6 # Copyright 2003-2007 by ACceSS MNRF
7 # Copyright 2007 by University of Queensland
8 #
9 # http://esscc.uq.edu.au
10 # Primary Business: Queensland, Australia
11 # Licensed under the Open Software License version 3.0
12 # http://www.opensource.org/licenses/osl-3.0.php
13 #
14 #######################################################
15 #
16
17 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
18 http://www.access.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22
23 from esys.escript.modelframe import Model, Link
24 from esys.escript import saveVTK, Data
25 import os
26
27 class Visualization(Model):
28 """
29 Generic visualization Model
30
31 @ivar t: current time (in)
32 @ivar n: frame counter (in)
33 @ivar dt: increment for output (in)
34 @ivar filename: name of the output file (in)
35 """
36
37 def __init__(self, **kwargs):
38 """
39 Initialisation of the visualisation model object
40
41 @param debug: Debugging flag
42 """
43 super(Visualization,self).__init__(**kwargs)
44 self.declareParameter(t=0.,
45 n=0,
46 dt=1,
47 filename="movie.mpg")
48
49 def doInitialization(self):
50 """
51 does some kind of initialisation
52 """
53 self.__last_t=self.t
54 fnc=self.filename.split('.')
55 if len(fnc)==0:
56 self.__frame_filename="data.%s.xml"
57 else:
58 n=fnc[0]
59 for i in range(1,len(fnc)-1):
60 n+="."+fnc[i]
61 if len(fnc)==1:
62 self.__frame_filename=n+".%s"
63 else:
64 self.__frame_filename=n+".%s."+fnc[-1]
65 self.trace("output filename is %s."%self.__frame_filename)
66
67 def getFrameFileName(self):
68 return self.__frame_filename%self.getFrameCounter()
69
70 def writeFrame(self):
71 """
72 returns True if the time stamp for writing frame is reached.
73 """
74 out=self.t>=self.__last_t+self.dt
75 if out:
76 self.__last_t+=self.dt
77 self.n+=1
78 return out
79
80 def getFrameCounter(self):
81 """
82 returns a frame counter
83 """
84 return self.n
85
86 def getSafeTimeStepSize(self,dt):
87 """
88 returns new step size
89
90 @param dt: last time step size used
91 @type dt: C{float}
92 @return: time step size that can savely be used
93 @rtype: C{float}
94 """
95 return self.__last_t+self.dt-self.t
96
97 class Movie(Visualization):
98 """
99 Generic visualization of scalar, vector and/or tensorial data
100
101 @ivar scalar: scalar data set (in)
102 @ivar vector: vector data set (in)
103 @ivar tensor: tensor data set (in)
104 """
105
106 def __init__(self, **kwargs):
107 """
108 Initialisation of the visualisation model object
109
110 @param debug: Debugging flag
111 """
112 super(Movie,self).__init__(**kwargs)
113 self.declareParameter(scalar=None,
114 vector=None,
115 tensor=None)
116
117 def doStepPostprocessing(self, dt):
118 """
119 renders the scene
120 """
121 super(Movie, self).doStepPostprocessing(dt)
122 if self.writeFrame():
123 if self.debug():
124 self.trace("%s-th frame at time %s"%(self.getFrameCounter(),self.t))
125 if isinstance(self.scalar,Data):
126 self.trace("scalar data: (min,max) =(%s,%s)"%(inf(self.scalar),sup(self.scalar)))
127 if isinstance(self.vector,Data):
128 self.trace("vector data: (min,max) =(%s,%s)"%(inf(self.vector),sup(self.vector)))
129 if isinstance(self.tensor,Data):
130 self.trace("tensor data: (min,max) =(%s,%s)"%(inf(self.tensor),sup(self.tensor)))
131
132 class ShadePlot(Movie):
133 """
134 Shaded contour plots
135 """
136
137 def __init(self, **kwargs):
138 """
139 Initialisation
140 """
141 Movie.__init__(self, **kwargs)
142 self.declareParameter(filename="shadePlot.%s.png")
143
144 def doStepPostprocessing(self, dt):
145 """
146 Do any necessary postprocessing operations after a timestep.
147
148 @param dt:
149 """
150 self.counter += 1
151 if self.counter % self.stride == 0:
152 n = self.counter/self.stride
153
154 # look for a vtk xml file of the right name and plot it
155 dataFname = "data.s.%d.xml" % n
156 if not os.path.exists(dataFname):
157 print "Data file doesn't exist! Skipping frame generation."
158
159 else:
160 import pyvisi
161 import pyvisi.renderers.vtk
162
163 scene = pyvisi.renderers.vtk.Scene()
164 plot = pyvisi.renderers.vtk.ContourPlot(scene)
165 plot.setData(fname=dataFname,
166 format='vtk-xml',
167 scalars='escript_scalar_data')
168 scene.save(fname="shadePlot.%05d.png" % n, format="png")
169
170
171 class ArrowPlot(Movie):
172 """
173 Arrow/vector/quiver plots
174 """
175
176 def __init(self, **kwargs):
177 """
178 Initialisation
179 """
180 Movie.__init__(self, **kwargs)
181 self.declareParameter(filename="arrowPlot.%s.png")
182
183 def doStepPostprocessing(self, dt):
184 """
185 Do any necessary postprocessing operations after a timestep.
186
187 @param dt:
188 """
189 self.counter += 1
190 if self.counter % self.stride == 0:
191 n = self.counter/self.stride
192
193 # look for a vtk xml file of the right name and plot it
194 dataFname = "data.v.%d.xml" % n
195 if not os.path.exists(dataFname):
196 print "Data file doesn't exist! Skipping frame generation."
197
198 else:
199 import pyvisi
200 import pyvisi.renderers.vtk
201
202 scene = pyvisi.renderers.vtk.Scene()
203 plot = pyvisi.renderers.vtk.ArrowPlot3D(scene)
204 plot.setData(fname=dataFname,
205 format='vtk-xml')
206 scene.save(fname="arrowPlot.%05d.png" % n, format="png")
207
208
209
210 class EllipsoidPlot(Movie):
211 """
212 Ellipsoid plots
213 """
214
215 def __init(self, **kwargs):
216 """
217 Initialisation
218 """
219 Movie.__init__(self, **kwargs)
220
221
222 class WriteVTK(Visualization):
223 """
224 Writes data into a VTK file.
225
226 The Model can handel up to 20 data sets that are written into a single file tagged with the given name. If no name is given and
227 the data are defined by a L{Link} the name of the target attribute is used as a tag.
228
229 @ivar data0: data set 0 to be written
230 @type data0: L{escript.Data}
231 @ivar name0: name tag for data set 0
232 @type name0: C{str} or C{None}
233 @ivar data1: data set 1 to be written
234 @type data1: L{escript.Data}
235 @ivar name1: name tag for data set 1
236 @type name1: C{str} or C{None}
237 @ivar data2: data set 2 to be written
238 @type data2: L{escript.Data}
239 @ivar name2: name tag for data set 2
240 @type name2: C{str} or C{None}
241 @ivar data3: data set 3 to be written
242 @type data3: L{escript.Data}
243 @ivar name3: name tag for data set 3
244 @type name3: C{str} or C{None}
245 @ivar data4: data set 4 to be written
246 @type data4: L{escript.Data}
247 @ivar name4: name tag for data set 4
248 @type name4: C{str} or C{None}
249 @ivar data5: data set 5 to be written
250 @type data5: L{escript.Data}
251 @ivar name5: name tag for data set 5
252 @type name5: C{str} or C{None}
253 @ivar data6: data set 6 to be written
254 @type data6: L{escript.Data}
255 @ivar name6: name tag for data set 6
256 @type name6: C{str} or C{None}
257 @ivar data7: data set 7 to be written
258 @type data7: L{escript.Data}
259 @ivar name7: name tag for data set 7
260 @type name7: C{str} or C{None}
261 @ivar data8: data set 8 to be written
262 @type data8: L{escript.Data}
263 @ivar name8: name tag for data set 8
264 @type name8: C{str} or C{None}
265 @ivar data9: data set 9 to be written
266 @type data9: L{escript.Data}
267 @ivar name9: name tag for data set 9
268 @type name9: C{str} or C{None}
269 @ivar data10: data set 10 to be written
270 @type data10: L{escript.Data}
271 @ivar name10: name tag for data set 10
272 @type name10: C{str} or C{None}
273 @ivar data11: data set 11 to be written
274 @type data11: L{escript.Data}
275 @ivar name11: name tag for data set 11
276 @type name11: C{str} or C{None}
277 @ivar data12: data set 12 to be written
278 @type data12: L{escript.Data}
279 @ivar name12: name tag for data set 12
280 @type name12: C{str} or C{None}
281 @ivar data13: data set 13 to be written
282 @type data13: L{escript.Data}
283 @ivar name13: name tag for data set 13
284 @type name13: C{str} or C{None}
285 @ivar data14: data set 14 to be written
286 @type data14: L{escript.Data}
287 @ivar name14: name tag for data set 14
288 @type name14: C{str} or C{None}
289 @ivar data15: data set 15 to be written
290 @type data15: L{escript.Data}
291 @ivar name15: name tag for data set 15
292 @type name15: C{str} or C{None}
293 @ivar data16: data set 16 to be written
294 @type data16: L{escript.Data}
295 @ivar name16: name tag for data set 16
296 @type name16: C{str} or C{None}
297 @ivar data17: data set 17 to be written
298 @type data17: L{escript.Data}
299 @ivar name17: name tag for data set 17
300 @type name17: C{str} or C{None}
301 @ivar data18: data set 18 to be written
302 @type data18: L{escript.Data}
303 @ivar name18: name tag for data set 18
304 @type name18: C{str} or C{None}
305 @ivar data19: data set 19 to be written
306 @type data19: L{escript.Data}
307 @ivar name19: name tag for data set 19
308 @type name19: C{str} or C{None}
309 """
310 def __init__(self, **kwargs):
311 """
312 Initialisation of the WriteVTK object
313
314 @param debug: debugging flag
315 @type debug: C{bool}
316 """
317 super(WriteVTK,self).__init__(**kwargs)
318 self.declareParameter(data0=None,name0=None,
319 data1=None,name1=None,
320 data2=None,name2=None,
321 data3=None,name3=None,
322 data4=None,name4=None,
323 data5=None,name5=None,
324 data6=None,name6=None,
325 data7=None,name7=None,
326 data8=None,name8=None,
327 data9=None,name9=None,
328 data10=None,name10=None,
329 data11=None,name11=None,
330 data12=None,name12=None,
331 data13=None,name13=None,
332 data14=None,name14=None,
333 data15=None,name15=None,
334 data16=None,name16=None,
335 data17=None,name17=None,
336 data18=None,name18=None,
337 data19=None,name19=None)
338 def collectData(self):
339 kwargs={}
340 if isinstance(self.data0, Data):
341 if self.name0 == None:
342 if isinstance(self.getAttributeObject("data0"),Link):
343 kwargs[self.getAttributeObject("data0").getAttributeName()]=self.data0
344 else:
345 kwargs["data0"]=self.data0
346 else:
347 kwargs[str(self.name0)]=self.data0
348
349
350 if isinstance(self.data1, Data):
351 if self.name1 == None:
352 if isinstance(self.getAttributeObject("data1"),Link):
353 kwargs[self.getAttributeObject("data1").getAttributeName()]=self.data1
354 else:
355 kwargs["data1"]=self.data1
356 else:
357 kwargs[str(self.name1)]=self.data1
358
359
360 if isinstance(self.data2, Data):
361 if self.name2 == None:
362 if isinstance(self.getAttributeObject("data2"),Link):
363 kwargs[self.getAttributeObject("data2").getAttributeName()]=self.data2
364 else:
365 kwargs["data2"]=self.data2
366 else:
367 kwargs[str(self.name2)]=self.data2
368
369
370 if isinstance(self.data3, Data):
371 if self.name3 == None:
372 if isinstance(self.getAttributeObject("data3"),Link):
373 kwargs[self.getAttributeObject("data3").getAttributeName()]=self.data3
374 else:
375 kwargs["data3"]=self.data3
376 else:
377 kwargs[str(self.name3)]=self.data3
378
379
380 if isinstance(self.data4, Data):
381 if self.name4 == None:
382 if isinstance(self.getAttributeObject("data4"),Link):
383 kwargs[self.getAttributeObject("data4").getAttributeName()]=self.data4
384 else:
385 kwargs["data4"]=self.data4
386 else:
387 kwargs[str(self.name4)]=self.data4
388
389
390 if isinstance(self.data5, Data):
391 if self.name5 == None:
392 if isinstance(self.getAttributeObject("data5"),Link):
393 kwargs[self.getAttributeObject("data5").getAttributeName()]=self.data5
394 else:
395 kwargs["data5"]=self.data5
396 else:
397 kwargs[str(self.name5)]=self.data5
398
399
400 if isinstance(self.data6, Data):
401 if self.name6 == None:
402 if isinstance(self.getAttributeObject("data6"),Link):
403 kwargs[self.getAttributeObject("data6").getAttributeName()]=self.data6
404 else:
405 kwargs["data6"]=self.data6
406 else:
407 kwargs[str(self.name6)]=self.data6
408
409
410 if isinstance(self.data7, Data):
411 if self.name7 == None:
412 if isinstance(self.getAttributeObject("data7"),Link):
413 kwargs[self.getAttributeObject("data7").getAttributeName()]=self.data7
414 else:
415 kwargs["data7"]=self.data7
416 else:
417 kwargs[str(self.name7)]=self.data7
418
419
420 if isinstance(self.data8, Data):
421 if self.name8 == None:
422 if isinstance(self.getAttributeObject("data8"),Link):
423 kwargs[self.getAttributeObject("data8").getAttributeName()]=self.data8
424 else:
425 kwargs["data8"]=self.data8
426 else:
427 kwargs[str(self.name8)]=self.data8
428
429
430 if isinstance(self.data9, Data):
431 if self.name9 == None:
432 if isinstance(self.getAttributeObject("data9"),Link):
433 kwargs[self.getAttributeObject("data9").getAttributeName()]=self.data9
434 else:
435 kwargs["data9"]=self.data9
436 else:
437 kwargs[str(self.name9)]=self.data9
438
439
440 if isinstance(self.data10, Data):
441 if self.name10 == None:
442 if isinstance(self.getAttributeObject("data10"),Link):
443 kwargs[self.getAttributeObject("data10").getAttributeName()]=self.data10
444 else:
445 kwargs["data10"]=self.data10
446 else:
447 kwargs[str(self.name10)]=self.data10
448
449
450 if isinstance(self.data11, Data):
451 if self.name11 == None:
452 if isinstance(self.getAttributeObject("data11"),Link):
453 kwargs[self.getAttributeObject("data11").getAttributeName()]=self.data11
454 else:
455 kwargs["data11"]=self.data11
456 else:
457 kwargs[str(self.name11)]=self.data11
458
459
460 if isinstance(self.data12, Data):
461 if self.name12 == None:
462 if isinstance(self.getAttributeObject("data12"),Link):
463 kwargs[self.getAttributeObject("data12").getAttributeName()]=self.data12
464 else:
465 kwargs["data12"]=self.data12
466 else:
467 kwargs[str(self.name12)]=self.data12
468
469
470 if isinstance(self.data13, Data):
471 if self.name13 == None:
472 if isinstance(self.getAttributeObject("data13"),Link):
473 kwargs[self.getAttributeObject("data13").getAttributeName()]=self.data13
474 else:
475 kwargs["data13"]=self.data13
476 else:
477 kwargs[str(self.name13)]=self.data13
478
479
480 if isinstance(self.data14, Data):
481 if self.name14 == None:
482 if isinstance(self.getAttributeObject("data14"),Link):
483 kwargs[self.getAttributeObject("data14").getAttributeName()]=self.data14
484 else:
485 kwargs["data14"]=self.data14
486 else:
487 kwargs[str(self.name14)]=self.data14
488
489
490 if isinstance(self.data15, Data):
491 if self.name15 == None:
492 if isinstance(self.getAttributeObject("data15"),Link):
493 kwargs[self.getAttributeObject("data15").getAttributeName()]=self.data15
494 else:
495 kwargs["data15"]=self.data15
496 else:
497 kwargs[str(self.name15)]=self.data15
498
499
500 if isinstance(self.data16, Data):
501 if self.name16 == None:
502 if isinstance(self.getAttributeObject("data16"),Link):
503 kwargs[self.getAttributeObject("data16").getAttributeName()]=self.data16
504 else:
505 kwargs["data16"]=self.data16
506 else:
507 kwargs[str(self.name16)]=self.data16
508
509
510 if isinstance(self.data17, Data):
511 if self.name17 == None:
512 if isinstance(self.getAttributeObject("data17"),Link):
513 kwargs[self.getAttributeObject("data17").getAttributeName()]=self.data17
514 else:
515 kwargs["data17"]=self.data17
516 else:
517 kwargs[str(self.name17)]=self.data17
518
519
520 if isinstance(self.data18, Data):
521 if self.name18 == None:
522 if isinstance(self.getAttributeObject("data18"),Link):
523 kwargs[self.getAttributeObject("data18").getAttributeName()]=self.data18
524 else:
525 kwargs["data18"]=self.data18
526 else:
527 kwargs[str(self.name18)]=self.data18
528
529
530 if isinstance(self.data19, Data):
531 if self.name19 == None:
532 if isinstance(self.getAttributeObject("data19"),Link):
533 kwargs[self.getAttributeObject("data19").getAttributeName()]=self.data19
534 else:
535 kwargs["data19"]=self.data19
536 else:
537 kwargs[str(self.name19)]=self.data19
538 return kwargs
539
540 def doInitialPostprocessing(self):
541 """
542 writes vtk file at the end of initial iteration
543 """
544 super(WriteVTK,self).doInitialPostprocessing()
545 kwargs=self.collectData()
546 if len(kwargs)>0:
547 saveVTK(self.getFrameFileName(),**kwargs)
548 self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.getFrameFileName()))
549
550 def doStepPostprocessing(self, dt):
551 """
552 writes vtk file at the end of time iteration
553 """
554 super(WriteVTK,self).doStepPostprocessing(dt)
555 if self.writeFrame():
556 kwargs=self.collectData()
557 if len(kwargs)>0:
558 saveVTK(self.getFrameFileName(),**kwargs)
559 self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.getFrameFileName()))
560
561 # vim: expandtab shiftwidth=4:

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26