/[escript]/trunk/pyvisi/py_src/datacollector.py
ViewVC logotype

Diff of /trunk/pyvisi/py_src/datacollector.py

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

trunk/pyvisi/py_src/datacollector.py revision 1153 by jongui, Thu May 17 06:33:54 2007 UTC temp/pyvisi/py_src/datacollector.py revision 1387 by trankine, Fri Jan 11 07:45:26 2008 UTC
# Line 1  Line 1 
1  """  """
2  @author: John NGUI  @var __author__: name of author
3    @var __copyright__: copyrights
4    @var __license__: licence agreement
5    @var __url__: url entry point on documentation
6    @var __version__: version
7    @var __date__: date of the version
8  """  """
9    
10    __author__="John Ngui, john.ngui@uq.edu.au"
11    __copyright__="""  Copyright (c) 2006 by ACcESS MNRF
12                        http://www.access.edu.au
13                    Primary Business: Queensland, Australia"""
14    __license__="""Licensed under the Open Software License version 3.0
15                 http://www.opensource.org/licenses/osl-3.0.php"""
16    __url__="http://www.iservo.edu.au/esys"
17    __version__="$Revision$"
18    __date__="$Date$"
19    
20    
21  import vtk  import vtk
22  import tempfile, os, sys  import tempfile, os, sys
23  from constant import Source, ColorMode  from constant import Source, ColorMode
# Line 13  except ImportError: Line 29  except ImportError:
29  class DataCollector:  class DataCollector:
30      """      """
31      Class that defines a data collector. A data collector is used to read      Class that defines a data collector. A data collector is used to read
32      data from an XML file or from an escript object directly. Writing XML      data from a XML file or from an escript object directly. Writing XML
33      files are expensive, but this approach has the advantage given that the      files are expensive, but this approach has the advantage given that the
34      results can be analyzed easily after the simulation has completed.        results can be analyzed easily after the simulation has completed.  
35    
# Line 34  class DataCollector: Line 50  class DataCollector:
50          self.__source = source          self.__source = source
51          # Keeps track on whether DataCollector have been modified.          # Keeps track on whether DataCollector have been modified.
52          self.__modified = True          self.__modified = True
53            # Keeps track of the number of times the 'setFileName' or 'setData'
54            # method have been executed.
55            self.__count = 0
56          # Keeps track on whether any specific scalar, vector or tensor          # Keeps track on whether any specific scalar, vector or tensor
57          # field have been specified.          # field have been specified.
58          self.__set_scalar = False          self.__set_scalar = False
# Line 65  class DataCollector: Line 84  class DataCollector:
84          """          """
85    
86          self.__modified = True          self.__modified = True
87            self.__count += 1
88    
89          if(self.__source == Source.XML):          if(self.__source == Source.XML):
90              # Check whether the specified file exists, otherwise exit.              # Check whether the specified file exists, otherwise an error is
91                # raised.
92              if not(os.access(file_name, os.F_OK)):              if not(os.access(file_name, os.F_OK)):
93                  raise IOError("\nERROR: '%s' file does NOT exists.\n" % \                  raise IOError("\nERROR: '%s' file does NOT exists.\n" % \
94                          file_name)                          file_name)
# Line 88  class DataCollector: Line 109  class DataCollector:
109          """          """
110    
111          self.__modified = True          self.__modified = True
112            self.__count += 1
113    
114          if self.__source == Source.ESCRIPT:          if self.__source == Source.ESCRIPT:
115              esys.escript.saveVTK(self.__tmp_file,**args)              esys.escript.saveVTK(self.__tmp_file,**args)
# Line 98  class DataCollector: Line 120  class DataCollector:
120              # will always be displayed. The reason Modified is used is              # will always be displayed. The reason Modified is used is
121              # because the same temporary file name is always used              # because the same temporary file name is always used
122              # (previous file is overwritten). Modified MUST NOT be used in              # (previous file is overwritten). Modified MUST NOT be used in
123              # setFileName, it can cause incorrect output such as map.              # setFileName, as it can cause incorrect output such as map.
124              self.__vtk_xml_reader.Modified()              self.__vtk_xml_reader.Modified()
125    
126              # Update must be called after Modified. If Update is called before              # Update must be called after Modified. If Update is called before
# Line 129  class DataCollector: Line 151  class DataCollector:
151          """          """
152    
153          # Check whether the specified scalar is available in either point          # Check whether the specified scalar is available in either point
154          # or cell data. If not available, error is raised.          # or cell data. If not available, an error is raised.
155    
156          # NOTE: This check is similar to the check used in _getScalarRange          # NOTE: This check is similar to the check used in _getScalarRange
157          # but this is used only when a scalar attribute has been specified.          # but this is used only when a scalar attribute has been specified.
# Line 262  class DataCollector: Line 284  class DataCollector:
284                  self.__get_attribute_list(                  self.__get_attribute_list(
285                  self._getDataCollectorOutput().GetPointData())                  self._getDataCollectorOutput().GetPointData())
286    
287          # Get all the available cell data attribute into another list.            # Get all the available cell data attributes into another list.
288          self.__cell_attribute = \          self.__cell_attribute = \
289                  self.__get_attribute_list(                  self.__get_attribute_list(
290                  self._getDataCollectorOutput().GetCellData())                  self._getDataCollectorOutput().GetCellData())
# Line 276  class DataCollector: Line 298  class DataCollector:
298          """          """
299    
300          # Check whether any scalar is available in either point or cell data.          # Check whether any scalar is available in either point or cell data.
301          # If not available, program exits.          # If not available, an error is raised.
302    
303          # NOTE: This check is similar to the check used in _setActiveScalar          # NOTE: This check is similar to the check used in _setActiveScalar
304          # but this is used only when no scalar attribute has been specified.          # but this is used only when no scalar attribute has been specified.
# Line 298  class DataCollector: Line 320  class DataCollector:
320          """          """
321                    
322          # Check whether any vector is available in either point or cell data.          # Check whether any vector is available in either point or cell data.
323          # If not available, program exits.          # If not available, an error is raised.
324    
325          # NOTE: This check is similar to the check used in _setActiveVector          # NOTE: This check is similar to the check used in _setActiveVector
326          # but this is used only when no vector attribute has been specified.          # but this is used only when no vector attribute has been specified.
# Line 330  class DataCollector: Line 352  class DataCollector:
352          """          """
353    
354          # Check whether any tensor is available in either point or cell data.          # Check whether any tensor is available in either point or cell data.
355          # If not available, program exits.          # If not available, an error is raised.
356    
357          # NOTE: This check is similar to the check used in _setActiveTensor          # NOTE: This check is similar to the check used in _setActiveTensor
358          # but this is used only when no tensor attribute has been specified.          # but this is used only when no tensor attribute has been specified.
# Line 361  class DataCollector: Line 383  class DataCollector:
383          """          """
384    
385          if(self.__modified == True):          if(self.__modified == True):
386              self.__modified = False              # 'self.__modified' is set to False only if the 'setFileName' or
387                # 'setData' method have been called once. This is to prevent
388                # the scalar range and active field (i.e. scalar, vector or tensor)
389                # from being updated as no changes has taken place (for performance
390                # reasons). However if the 'setFileName' or 'setData' method is
391                # called more than once, then 'self.__modified' remains True.
392                if(self.__count == 1):
393                    self.__modified = False
394              return True              return True
395          else:          else:
396              return False              return False

Legend:
Removed from v.1153  
changed lines
  Added in v.1387

  ViewVC Help
Powered by ViewVC 1.1.26