/[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 911 - (show annotations)
Tue Dec 5 23:39:39 2006 UTC (12 years, 4 months ago) by gross
File MIME type: text/x-python
File size: 7403 byte(s)
*Constrainer models have been renamed to *ConstrainerOverBox to clarify the fact that they are only work over a box domain
1 # $Id$
2
3 __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 from esys.escript.modelframe import Model
10 from esys.escript import saveVTK, Data
11 import os
12
13 class Visualization(Model):
14 """
15 Generic visualization of scalar, vector and tensorial data
16 (not implemeted yet)
17
18 @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 """
26
27 def __init__(self, debug=False):
28 """
29 Initialisation of the visualisation model object
30
31 @param debug: Debugging flag
32 """
33 super(Visualization,self).__init__(debug=debug)
34 self.declareParameter(t=0.,
35 n=0,
36 scalar=None,
37 vector=None,
38 tensor=None,
39 dt=1,
40 filename="movie.mpg")
41
42 def doInitialization(self):
43 """
44 does some kind of initialisation
45 """
46 self.__last_t=self.t
47
48 def writeFrame(self):
49 """
50 returns True if the time stamp for writing frame is reached.
51 """
52 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 """
60 returns a frame counter
61 """
62 return self.n
63
64 def getSafeTimeStepSize(self,dt):
65 """
66 returns new step size
67
68 @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 def doStepPostprocessing(self, dt):
76 """
77 renders the scene
78
79 @note: to be overwritten
80 """
81 if self.writeFrame():
82 if self.debug():
83 self.trace("%s-th frame at time %s"%(self.getFrameCounter(),self.t))
84 if isinstance(self.scalar,Data):
85 self.trace("scalar data: (min,max) =(%s,%s)"%(inf(self.scalar),sup(self.scalar)))
86 if isinstance(self.vector,Data):
87 self.trace("vector data: (min,max) =(%s,%s)"%(inf(self.vector),sup(self.vector)))
88 if isinstance(self.tensor,Data):
89 self.trace("tensor data: (min,max) =(%s,%s)"%(inf(self.tensor),sup(self.tensor)))
90
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 @type debug: C{bool}
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 def doInitialPostprocessing(self):
124 kwargs={}
125 if isinstance(self.scalar,Data): kwargs["scalar"] = self.scalar
126 if isinstance(self.vector,Data): kwargs["vector"] = self.vector
127 if isinstance(self.tensor,Data): 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
131 def doStepPostprocessing(self, dt):
132 """
133 writes
134 do any necessary postprocessing operations after a timestep.
135
136 @param dt: current time increment
137 @type dt: C{float}
138 """
139 if self.writeFrame():
140 kwargs={}
141 if isinstance(self.scalar,Data): kwargs["scalar"] = self.scalar
142 if isinstance(self.vector,Data): kwargs["vector"] = self.vector
143 if isinstance(self.tensor,Data): 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 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