/[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 155 - (hide annotations)
Wed Nov 9 02:02:19 2005 UTC (17 years, 4 months ago) by jgs
File MIME type: text/x-python
File size: 5551 byte(s)
move all directories from trunk/esys2 into trunk and remove esys2

1 jgs 127 # $Id$
2    
3 jgs 149 from esys.escript.modelframe import Model
4 jgs 151 from esys.escript import saveVTK
5 jgs 148 import os
6 jgs 127
7     class Visualization(Model):
8 jgs 148 """
9     Generic visualization of scalar, vector and tensorial data
10     (not implemeted yet)
11 jgs 127
12 jgs 149 @ivar t: current time
13     @ivar scalar: scalar data set
14     @ivar vector: vector data set
15     @ivar tensor: tensor data set
16     @ivar stride: visulaization is done every strides time step
17     @ivar filename: name of the movie file
18 jgs 148 """
19 jgs 127
20 jgs 148 def __init__(self, debug=False):
21     """
22     Initialisation of the visualisation model object
23 jgs 127
24 jgs 148 @param debug: Debugging flag
25     """
26     Model.__init__(self, debug=debug)
27     self.declareParameter(t=0.,
28     scalar=None, vector=None, tensor=None,
29     stride=1, movie="movie.mpg", counter=0)
30 jgs 127
31 jgs 148 def doInitialization(self):
32     """
33     Does some kind of initialisation
34     """
35     self.__n = 0
36     self.__scene = None
37 jgs 127
38 jgs 148 def doStepPostprocessing(self, dt):
39     """
40     Does any necessary postprocessing after each step
41 jgs 127
42 jgs 148 @param dt:
43     """
44     self.__n += 1
45     if self.__n % self.stride:
46     data = self.scalar
47     if data != None:
48     pass
49     data = self.vector
50     if data != None:
51     pass
52     data = self.tensor
53     if data != None:
54     pass
55 jgs 127
56 jgs 148 def doFinalization(self):
57     """
58     Finalises the visualisation. For instance, makes a movie of the
59     image files.
60     """
61     # make the movie into self.filename
62     pass
63    
64     class ShadePlot(Visualization):
65     """
66     Shaded contour plots
67     """
68    
69     def __init(self, debug=False):
70     """
71     Initialisation
72     """
73     Visualization.__init__(self, debug)
74     self.declareParameter(filename="shadePlot.%s.png")
75    
76     def doStepPostprocessing(self, dt):
77     """
78     Do any necessary postprocessing operations after a timestep.
79    
80     @param dt:
81     """
82     self.counter += 1
83     if self.counter % self.stride == 0:
84     n = self.counter/self.stride
85    
86     # look for a vtk xml file of the right name and plot it
87     dataFname = "data.s.%d.xml" % n
88     if not os.path.exists(dataFname):
89     print "Data file doesn't exist! Skipping frame generation."
90    
91     else:
92     import pyvisi
93     import pyvisi.renderers.vtk
94    
95     scene = pyvisi.renderers.vtk.Scene()
96     plot = pyvisi.renderers.vtk.ContourPlot(scene)
97     plot.setData(fname=dataFname,
98     format='vtk-xml',
99     scalars='escript_scalar_data')
100     scene.save(fname="shadePlot.%05d.png" % n, format="png")
101    
102    
103     class ArrowPlot(Visualization):
104     """
105     Arrow/vector/quiver plots
106     """
107    
108     def __init(self, debug=False):
109     """
110     Initialisation
111     """
112     Visualization.__init__(self, debug)
113     self.declareParameter(filename="arrowPlot.%s.png")
114    
115     def doStepPostprocessing(self, dt):
116     """
117     Do any necessary postprocessing operations after a timestep.
118    
119     @param dt:
120     """
121     self.counter += 1
122     if self.counter % self.stride == 0:
123     n = self.counter/self.stride
124    
125     # look for a vtk xml file of the right name and plot it
126     dataFname = "data.v.%d.xml" % n
127     if not os.path.exists(dataFname):
128     print "Data file doesn't exist! Skipping frame generation."
129    
130     else:
131     import pyvisi
132     import pyvisi.renderers.vtk
133    
134     scene = pyvisi.renderers.vtk.Scene()
135     plot = pyvisi.renderers.vtk.ArrowPlot3D(scene)
136     plot.setData(fname=dataFname,
137     format='vtk-xml')
138     scene.save(fname="arrowPlot.%05d.png" % n, format="png")
139    
140    
141    
142     class EllipsoidPlot(Visualization):
143     """
144     Ellipsoid plots
145     """
146    
147     def __init(self, debug=False):
148     """
149     Initialisation
150     """
151     Visualization.__init__(self, debug)
152    
153    
154 jgs 127 class WriteVTK(Visualization):
155 jgs 148 """
156     Writes data into a VTK file for further processing. Currently data
157     are written in several files for each data type. This may change
158     in the future.
159 jgs 127
160 jgs 148 scalar: scalar data set
161     vector: vector data set
162     tensor: tensor data set
163     stride: file is written every stride-th time step
164     filename: name of the data files. use %s for indication of data type
165     (s,v,t) and time step id.
166     """
167 jgs 127
168 jgs 148 def __init__(self, debug=False):
169     """
170     Initialisation of the WriteVTK object
171 jgs 127
172 jgs 148 @param debug: Debugging flag
173     """
174     Visualization.__init__(self, debug=debug)
175     self.declareParameter(filename="data.%s.xml")
176    
177     def doStepPostprocessing(self, dt):
178     """
179     Do any necessary postprocessing operations after a timestep.
180    
181     @param dt:
182     """
183     self.counter += 1
184     if self.counter % self.stride == 0:
185     n = self.counter/self.stride
186     data = self.scalar
187     if hasattr(data, "saveVTK"):
188     data.saveVTK(self.filename % ("s.%d" % n))
189     data = self.vector
190     if hasattr(data, "saveVTK"):
191     data.saveVTK(self.filename % ("v.%d" % n))
192     data = self.tensor
193     if hasattr(data, "saveVTK"):
194     data.saveVTK(self.filename % ("t.%d" % n))
195    
196     # 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