/[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 908 - (hide annotations)
Thu Nov 23 06:39:39 2006 UTC (14 years, 11 months ago) by gross
File MIME type: text/x-python
File size: 7334 byte(s)
some fixes
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 gross 814 @ivar t: current time (in)
19     @ivar n: frame counter (in)
20     @ivar scalar: scalar data set (in)
21     @ivar vector: vector data set (in)
22     @ivar tensor: tensor data set (in)
23     @ivar dt: increment for output (in)
24     @ivar filename: name of the output file (in)
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 gross 814 """
44     does some kind of initialisation
45     """
46     self.__last_t=self.t
47 jgs 127
48 gross 423 def writeFrame(self):
49 gross 814 """
50     returns True if the time stamp for writing frame is reached.
51     """
52 gross 423 out=self.t>=self.__last_t+self.dt
53     if out:
54     self.__last_t+=self.dt
55     self.n+=1
56     return out
57    
58     def getFrameCounter(self):
59 gross 814 """
60     returns a frame counter
61     """
62 gross 908 return self.n
63 gross 423
64     def getSafeTimeStepSize(self,dt):
65 gross 814 """
66     returns new step size
67 gross 423
68 gross 814 @param dt: last time step size used
69     @type dt: C{float}
70     @return: time step size that can savely be used
71     @rtype: C{float}
72     """
73     return self.__last_t+self.dt-self.t
74    
75 jgs 148 def doStepPostprocessing(self, dt):
76     """
77 gross 423 renders the scene
78 jgs 127
79 gross 423 @note: to be overwritten
80 jgs 148 """
81 gross 423 if self.writeFrame():
82 gross 814 if self.debug():
83     self.trace("%s-th frame at time %s"%(self.getFrameCounter(),self.t))
84     if not self.scalar==None:
85     self.trace("scalar data: (min,max) =(%s,%s)"%(inf(self.scalar),sup(self.scalar)))
86     if not self.vector==None:
87     self.trace("vector data: (min,max) =(%s,%s)"%(inf(self.vector),sup(self.vector)))
88     if not self.tensor==None:
89     self.trace("tensor data: (min,max) =(%s,%s)"%(inf(self.tensor),sup(self.tensor)))
90 gross 423
91     class WriteVTK(Visualization):
92     """
93     Writes data into VTK files for further processing.
94     """
95    
96     def __init__(self, debug=False):
97     """
98     Initialisation of the WriteVTK object
99    
100     @param debug: Debugging flag
101 gross 814 @type debug: C{bool}
102 gross 423 """
103     super(WriteVTK,self).__init__(debug=debug)
104    
105     def doInitialization(self):
106     """
107 gross 814 does some kind of initialisation
108 gross 423 """
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 gross 908 def doInitialPostprocessing(self):
124     kwargs={}
125     if not self.scalar==None: kwargs["scalar"] = self.scalar
126     if not self.vector==None: kwargs["vector"] = self.vector
127     if not self.tensor==None: kwargs["tensor"] = self.tensor
128     saveVTK(self.__filename%self.getFrameCounter(),**kwargs)
129     self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.__filename%self.getFrameCounter()))
130 gross 423
131     def doStepPostprocessing(self, dt):
132     """
133 gross 814 writes
134     do any necessary postprocessing operations after a timestep.
135 gross 423
136 gross 814 @param dt: current time increment
137     @type dt: C{float}
138 gross 423 """
139     if self.writeFrame():
140     kwargs={}
141     if not self.scalar==None: kwargs["scalar"] = self.scalar
142     if not self.vector==None: kwargs["vector"] = self.vector
143     if not self.tensor==None: kwargs["tensor"] = self.tensor
144     saveVTK(self.__filename%self.getFrameCounter(),**kwargs)
145     self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.__filename%self.getFrameCounter()))
146    
147 jgs 148 class ShadePlot(Visualization):
148     """
149     Shaded contour plots
150     """
151    
152     def __init(self, debug=False):
153     """
154     Initialisation
155     """
156     Visualization.__init__(self, debug)
157     self.declareParameter(filename="shadePlot.%s.png")
158    
159     def doStepPostprocessing(self, dt):
160     """
161     Do any necessary postprocessing operations after a timestep.
162    
163     @param dt:
164     """
165     self.counter += 1
166     if self.counter % self.stride == 0:
167     n = self.counter/self.stride
168    
169     # look for a vtk xml file of the right name and plot it
170     dataFname = "data.s.%d.xml" % n
171     if not os.path.exists(dataFname):
172     print "Data file doesn't exist! Skipping frame generation."
173    
174     else:
175     import pyvisi
176     import pyvisi.renderers.vtk
177    
178     scene = pyvisi.renderers.vtk.Scene()
179     plot = pyvisi.renderers.vtk.ContourPlot(scene)
180     plot.setData(fname=dataFname,
181     format='vtk-xml',
182     scalars='escript_scalar_data')
183     scene.save(fname="shadePlot.%05d.png" % n, format="png")
184    
185    
186     class ArrowPlot(Visualization):
187     """
188     Arrow/vector/quiver plots
189     """
190    
191     def __init(self, debug=False):
192     """
193     Initialisation
194     """
195     Visualization.__init__(self, debug)
196     self.declareParameter(filename="arrowPlot.%s.png")
197    
198     def doStepPostprocessing(self, dt):
199     """
200     Do any necessary postprocessing operations after a timestep.
201    
202     @param dt:
203     """
204     self.counter += 1
205     if self.counter % self.stride == 0:
206     n = self.counter/self.stride
207    
208     # look for a vtk xml file of the right name and plot it
209     dataFname = "data.v.%d.xml" % n
210     if not os.path.exists(dataFname):
211     print "Data file doesn't exist! Skipping frame generation."
212    
213     else:
214     import pyvisi
215     import pyvisi.renderers.vtk
216    
217     scene = pyvisi.renderers.vtk.Scene()
218     plot = pyvisi.renderers.vtk.ArrowPlot3D(scene)
219     plot.setData(fname=dataFname,
220     format='vtk-xml')
221     scene.save(fname="arrowPlot.%05d.png" % n, format="png")
222    
223    
224    
225     class EllipsoidPlot(Visualization):
226     """
227     Ellipsoid plots
228     """
229    
230     def __init(self, debug=False):
231     """
232     Initialisation
233     """
234     Visualization.__init__(self, debug)
235    
236    
237     # 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