/[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 814 - (hide annotations)
Wed Aug 23 09:31:10 2006 UTC (13 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 6887 byte(s)
small bug in general tensor propduct fixed
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     return self.n-1
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    
124     def doStepPostprocessing(self, dt):
125     """
126 gross 814 writes
127     do any necessary postprocessing operations after a timestep.
128 gross 423
129 gross 814 @param dt: current time increment
130     @type dt: C{float}
131 gross 423 """
132     if self.writeFrame():
133     kwargs={}
134     if not self.scalar==None: kwargs["scalar"] = self.scalar
135     if not self.vector==None: kwargs["vector"] = self.vector
136     if not self.tensor==None: kwargs["tensor"] = self.tensor
137     saveVTK(self.__filename%self.getFrameCounter(),**kwargs)
138     self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.__filename%self.getFrameCounter()))
139    
140 jgs 148 class ShadePlot(Visualization):
141     """
142     Shaded contour plots
143     """
144    
145     def __init(self, debug=False):
146     """
147     Initialisation
148     """
149     Visualization.__init__(self, debug)
150     self.declareParameter(filename="shadePlot.%s.png")
151    
152     def doStepPostprocessing(self, dt):
153     """
154     Do any necessary postprocessing operations after a timestep.
155    
156     @param dt:
157     """
158     self.counter += 1
159     if self.counter % self.stride == 0:
160     n = self.counter/self.stride
161    
162     # look for a vtk xml file of the right name and plot it
163     dataFname = "data.s.%d.xml" % n
164     if not os.path.exists(dataFname):
165     print "Data file doesn't exist! Skipping frame generation."
166    
167     else:
168     import pyvisi
169     import pyvisi.renderers.vtk
170    
171     scene = pyvisi.renderers.vtk.Scene()
172     plot = pyvisi.renderers.vtk.ContourPlot(scene)
173     plot.setData(fname=dataFname,
174     format='vtk-xml',
175     scalars='escript_scalar_data')
176     scene.save(fname="shadePlot.%05d.png" % n, format="png")
177    
178    
179     class ArrowPlot(Visualization):
180     """
181     Arrow/vector/quiver plots
182     """
183    
184     def __init(self, debug=False):
185     """
186     Initialisation
187     """
188     Visualization.__init__(self, debug)
189     self.declareParameter(filename="arrowPlot.%s.png")
190    
191     def doStepPostprocessing(self, dt):
192     """
193     Do any necessary postprocessing operations after a timestep.
194    
195     @param dt:
196     """
197     self.counter += 1
198     if self.counter % self.stride == 0:
199     n = self.counter/self.stride
200    
201     # look for a vtk xml file of the right name and plot it
202     dataFname = "data.v.%d.xml" % n
203     if not os.path.exists(dataFname):
204     print "Data file doesn't exist! Skipping frame generation."
205    
206     else:
207     import pyvisi
208     import pyvisi.renderers.vtk
209    
210     scene = pyvisi.renderers.vtk.Scene()
211     plot = pyvisi.renderers.vtk.ArrowPlot3D(scene)
212     plot.setData(fname=dataFname,
213     format='vtk-xml')
214     scene.save(fname="arrowPlot.%05d.png" % n, format="png")
215    
216    
217    
218     class EllipsoidPlot(Visualization):
219     """
220     Ellipsoid plots
221     """
222    
223     def __init(self, debug=False):
224     """
225     Initialisation
226     """
227     Visualization.__init__(self, debug)
228    
229    
230     # 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