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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 422 by jgs, Wed Nov 9 02:02:19 2005 UTC revision 423 by gross, Fri Jan 6 08:09:43 2006 UTC
# Line 10  class Visualization(Model): Line 10  class Visualization(Model):
10      (not implemeted yet)      (not implemeted yet)
11    
12      @ivar t: current time      @ivar t: current time
13        @ivar n: frame counter
14      @ivar scalar: scalar data set      @ivar scalar: scalar data set
15      @ivar vector: vector data set      @ivar vector: vector data set
16      @ivar tensor: tensor data set      @ivar tensor: tensor data set
17      @ivar stride: visulaization is done every strides time step      @ivar dt: increment for output
18      @ivar filename: name of the movie file      @ivar filename: name of the output file
19      """      """
20    
21      def __init__(self, debug=False):      def __init__(self, debug=False):
# Line 23  class Visualization(Model): Line 24  class Visualization(Model):
24    
25          @param debug: Debugging flag          @param debug: Debugging flag
26          """          """
27          Model.__init__(self, debug=debug)          super(Visualization,self).__init__(debug=debug)
28          self.declareParameter(t=0.,          self.declareParameter(t=0.,
29                  scalar=None, vector=None, tensor=None,                                n=0,
30                  stride=1, movie="movie.mpg", counter=0)                                scalar=None,
31                                  vector=None,
32                                  tensor=None,
33                                  dt=1,
34                                  filename="movie.mpg")
35    
36      def doInitialization(self):      def doInitialization(self):
37          """          """
38          Does some kind of initialisation          Does some kind of initialisation
39          """          """
40          self.__n = 0          self.__last_t=self.t
41          self.__scene = None  
42        def writeFrame(self):
43           out=self.t>=self.__last_t+self.dt
44           if out:
45                self.__last_t+=self.dt
46                self.n+=1
47           return out
48    
49        def getFrameCounter(self):
50            return self.n-1
51    
52        def getSafeTimeStepSize(self,dt):
53               """
54               returns new step size
55    
56               @param dt: last time step size used
57               @type dt: C{float}
58               @return: time step size that can savely be used
59               @rtype: C{float}
60               """
61               return self.__last_t+self.dt-self.t
62    
63    
64      def doStepPostprocessing(self, dt):      def doStepPostprocessing(self, dt):
65          """          """
66          Does any necessary postprocessing after each step          renders the scene
67    
68          @param dt:          @note: to be overwritten
69          """          """
70          self.__n += 1          if self.writeFrame():
71          if self.__n % self.stride:              self.trace("%s-th frame at time %s"%(self.getFrameCounter(),self.t))
72              data = self.scalar              if not self.scalar==None:
73              if data != None:                 self.trace("scalar data: (min,max) =(%s,%s)"%(inf(self.scalar),sup(self.scalar)))
74                  pass              if not self.vector==None:
75              data = self.vector                 self.trace("vector data: (min,max) =(%s,%s)"%(inf(self.vector),sup(self.vector)))
76              if data != None:              if not self.tensor==None:
77                  pass                 self.trace("tensor data: (min,max) =(%s,%s)"%(inf(self.tensor),sup(self.tensor)))
78              data = self.tensor            
             if data != None:  
                 pass  
   
79      def doFinalization(self):      def doFinalization(self):
80          """          """
81          Finalises the visualisation.  For instance, makes a movie of the          Finalises the visualisation.  For instance, makes a movie of the image files.
82          image files.  
83            @note: to be overwritten
84          """          """
         # make the movie into self.filename  
85          pass          pass
86    
87    class WriteVTK(Visualization):
88        """
89        Writes data into VTK files for further processing.
90        """
91    
92        def __init__(self, debug=False):
93            """
94            Initialisation of the WriteVTK object
95    
96            @param debug: Debugging flag
97            """
98            super(WriteVTK,self).__init__(debug=debug)
99    
100        def doInitialization(self):
101            """
102            Does some kind of initialisation
103            """
104            super(WriteVTK,self).doInitialization()
105            fnc=self.filename.split('.')
106            if len(fnc)==0:
107               self.__filename="data.%s.xml"
108            else:
109               n=fnc[0]
110               for i in range(1,len(fnc)-1):
111                  n+="."+fnc[i]
112               if len(fnc)==1:
113                  self.__filename=n+".%s"
114               else:
115                  self.__filename=n+".%s."+fnc[-1]
116            self.trace("output filename is %s."%self.__filename)
117          
118    
119        def doStepPostprocessing(self, dt):
120            """
121            Do any necessary postprocessing operations after a timestep.
122    
123            @param dt:
124            """
125            if self.writeFrame():
126                kwargs={}
127                if not self.scalar==None: kwargs["scalar"] = self.scalar
128                if not self.vector==None: kwargs["vector"] = self.vector
129                if not self.tensor==None: kwargs["tensor"] = self.tensor
130                saveVTK(self.__filename%self.getFrameCounter(),**kwargs)
131                self.trace("%s-th frame at time %s is writen to %s"%(self.getFrameCounter(),self.t,self.__filename%self.getFrameCounter()))
132    
133  class ShadePlot(Visualization):  class ShadePlot(Visualization):
134      """      """
135      Shaded contour plots      Shaded contour plots
# Line 151  class EllipsoidPlot(Visualization): Line 220  class EllipsoidPlot(Visualization):
220          Visualization.__init__(self, debug)          Visualization.__init__(self, debug)
221    
222    
 class WriteVTK(Visualization):  
     """  
     Writes data into a VTK file for further processing. Currently data  
     are written in several files for each data type. This may change  
     in the future.  
   
     scalar: scalar data set  
     vector: vector data set  
     tensor: tensor data set  
     stride: file is written every stride-th time step  
     filename: name of the data files. use %s for indication of data type  
     (s,v,t) and time step id.  
     """  
   
     def __init__(self, debug=False):  
         """  
         Initialisation of the WriteVTK object  
   
         @param debug: Debugging flag  
         """  
         Visualization.__init__(self, debug=debug)  
         self.declareParameter(filename="data.%s.xml")  
   
     def doStepPostprocessing(self, dt):  
         """  
         Do any necessary postprocessing operations after a timestep.  
   
         @param dt:  
         """  
         self.counter += 1  
         if self.counter % self.stride == 0:  
             n = self.counter/self.stride  
             data = self.scalar  
             if hasattr(data, "saveVTK"):  
                 data.saveVTK(self.filename % ("s.%d" % n))  
             data = self.vector  
             if hasattr(data, "saveVTK"):  
                 data.saveVTK(self.filename % ("v.%d" % n))  
             data = self.tensor  
             if hasattr(data, "saveVTK"):  
                 data.saveVTK(self.filename % ("t.%d" % n))  
   
223  # vim: expandtab shiftwidth=4:  # vim: expandtab shiftwidth=4:

Legend:
Removed from v.422  
changed lines
  Added in v.423

  ViewVC Help
Powered by ViewVC 1.1.26