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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 628 - (hide annotations)
Thu Mar 23 02:27:57 2006 UTC (13 years, 7 months ago) by elspeth
File MIME type: text/x-python
File size: 6996 byte(s)
Copyright information added.

1 jgs 127 # $Id$
2    
3 elspeth 628 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
4     http://www.access.edu.au
5     Primary Business: Queensland, Australia"""
6     __license__="""Licensed under the Open Software License version 3.0
7     http://www.opensource.org/licenses/osl-3.0.php"""
8    
9 jgs 149 from esys.escript.modelframe import Model
10 jgs 151 from esys.escript import saveVTK
11 jgs 148 import os
12 jgs 127
13     class Visualization(Model):
14 jgs 148 """
15     Generic visualization of scalar, vector and tensorial data
16     (not implemeted yet)
17 jgs 127
18 jgs 149 @ivar t: current time
19 gross 423 @ivar n: frame counter
20 jgs 149 @ivar scalar: scalar data set
21     @ivar vector: vector data set
22     @ivar tensor: tensor data set
23 gross 423 @ivar dt: increment for output
24     @ivar filename: name of the output file
25 jgs 148 """
26 jgs 127
27 jgs 148 def __init__(self, debug=False):
28     """
29     Initialisation of the visualisation model object
30 jgs 127
31 jgs 148 @param debug: Debugging flag
32     """
33 gross 423 super(Visualization,self).__init__(debug=debug)
34 jgs 148 self.declareParameter(t=0.,
35 gross 423 n=0,
36     scalar=None,
37     vector=None,
38     tensor=None,
39     dt=1,
40     filename="movie.mpg")
41 jgs 127
42 jgs 148 def doInitialization(self):
43     """
44     Does some kind of initialisation
45     """
46 gross 423 self.__last_t=self.t
47 jgs 127
48 gross 423 def writeFrame(self):
49     out=self.t>=self.__last_t+self.dt
50     if out:
51     self.__last_t+=self.dt
52     self.n+=1
53     return out
54    
55     def getFrameCounter(self):
56     return self.n-1
57    
58     def getSafeTimeStepSize(self,dt):
59     """
60     returns new step size
61 gross 424
62 gross 423 @param dt: last time step size used
63     @type dt: C{float}
64     @return: time step size that can savely be used
65     @rtype: C{float}
66     """
67     return self.__last_t+self.dt-self.t
68    
69 jgs 148 def doStepPostprocessing(self, dt):
70     """
71 gross 423 renders the scene
72 jgs 127
73 gross 423 @note: to be overwritten
74 jgs 148 """
75 gross 423 if self.writeFrame():
76     self.trace("%s-th frame at time %s"%(self.getFrameCounter(),self.t))
77     if not self.scalar==None:
78     self.trace("scalar data: (min,max) =(%s,%s)"%(inf(self.scalar),sup(self.scalar)))
79     if not self.vector==None:
80     self.trace("vector data: (min,max) =(%s,%s)"%(inf(self.vector),sup(self.vector)))
81     if not self.tensor==None:
82     self.trace("tensor data: (min,max) =(%s,%s)"%(inf(self.tensor),sup(self.tensor)))
83    
84 jgs 148 def doFinalization(self):
85     """
86 gross 423 Finalises the visualisation. For instance, makes a movie of the image files.
87    
88     @note: to be overwritten
89 jgs 148 """
90     pass
91    
92 gross 423 class WriteVTK(Visualization):
93     """
94     Writes data into VTK files for further processing.
95     """
96    
97     def __init__(self, debug=False):
98     """
99     Initialisation of the WriteVTK object
100    
101     @param debug: Debugging flag
102     """
103     super(WriteVTK,self).__init__(debug=debug)
104    
105     def doInitialization(self):
106     """
107     Does some kind of initialisation
108     """
109     super(WriteVTK,self).doInitialization()
110     fnc=self.filename.split('.')
111     if len(fnc)==0:
112     self.__filename="data.%s.xml"
113     else:
114     n=fnc[0]
115     for i in range(1,len(fnc)-1):
116     n+="."+fnc[i]
117     if len(fnc)==1:
118     self.__filename=n+".%s"
119     else:
120     self.__filename=n+".%s."+fnc[-1]
121     self.trace("output filename is %s."%self.__filename)
122    
123    
124     def doStepPostprocessing(self, dt):
125     """
126     Do any necessary postprocessing operations after a timestep.
127    
128     @param dt:
129     """
130     if self.writeFrame():
131     kwargs={}
132     if not self.scalar==None: kwargs["scalar"] = self.scalar
133     if not self.vector==None: kwargs["vector"] = self.vector
134     if not self.tensor==None: kwargs["tensor"] = self.tensor
135     saveVTK(self.__filename%self.getFrameCounter(),**kwargs)
136     self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.__filename%self.getFrameCounter()))
137    
138 jgs 148 class ShadePlot(Visualization):
139     """
140     Shaded contour plots
141     """
142    
143     def __init(self, debug=False):
144     """
145     Initialisation
146     """
147     Visualization.__init__(self, debug)
148     self.declareParameter(filename="shadePlot.%s.png")
149    
150     def doStepPostprocessing(self, dt):
151     """
152     Do any necessary postprocessing operations after a timestep.
153    
154     @param dt:
155     """
156     self.counter += 1
157     if self.counter % self.stride == 0:
158     n = self.counter/self.stride
159    
160     # look for a vtk xml file of the right name and plot it
161     dataFname = "data.s.%d.xml" % n
162     if not os.path.exists(dataFname):
163     print "Data file doesn't exist! Skipping frame generation."
164    
165     else:
166     import pyvisi
167     import pyvisi.renderers.vtk
168    
169     scene = pyvisi.renderers.vtk.Scene()
170     plot = pyvisi.renderers.vtk.ContourPlot(scene)
171     plot.setData(fname=dataFname,
172     format='vtk-xml',
173     scalars='escript_scalar_data')
174     scene.save(fname="shadePlot.%05d.png" % n, format="png")
175    
176    
177     class ArrowPlot(Visualization):
178     """
179     Arrow/vector/quiver plots
180     """
181    
182     def __init(self, debug=False):
183     """
184     Initialisation
185     """
186     Visualization.__init__(self, debug)
187     self.declareParameter(filename="arrowPlot.%s.png")
188    
189     def doStepPostprocessing(self, dt):
190     """
191     Do any necessary postprocessing operations after a timestep.
192    
193     @param dt:
194     """
195     self.counter += 1
196     if self.counter % self.stride == 0:
197     n = self.counter/self.stride
198    
199     # look for a vtk xml file of the right name and plot it
200     dataFname = "data.v.%d.xml" % n
201     if not os.path.exists(dataFname):
202     print "Data file doesn't exist! Skipping frame generation."
203    
204     else:
205     import pyvisi
206     import pyvisi.renderers.vtk
207    
208     scene = pyvisi.renderers.vtk.Scene()
209     plot = pyvisi.renderers.vtk.ArrowPlot3D(scene)
210     plot.setData(fname=dataFname,
211     format='vtk-xml')
212     scene.save(fname="arrowPlot.%05d.png" % n, format="png")
213    
214    
215    
216     class EllipsoidPlot(Visualization):
217     """
218     Ellipsoid plots
219     """
220    
221     def __init(self, debug=False):
222     """
223     Initialisation
224     """
225     Visualization.__init__(self, debug)
226    
227    
228     # 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