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

Contents of /trunk/pyvisi/py_src/streamlinemodule.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (11 years, 1 month ago) by jfenwick
File MIME type: text/x-python
File size: 4835 byte(s)
Don't panic.
Updating copyright stamps

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2010 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 """
23 :var __author__: name of author
24 :var __copyright__: copyrights
25 :var __license__: licence agreement
26 :var __url__: url entry point on documentation
27 :var __version__: version
28 :var __date__: date of the version
29 """
30
31 __author__="John Ngui, john.ngui@uq.edu.au"
32
33
34 from esys.escript import getMPISizeWorld
35 if getMPISizeWorld()==1: import vtk
36
37 class StreamLineModule:
38 """
39 Class that defines the streamline module.
40 """
41
42 def __init__(self):
43 """
44 Initialise the streamline module.
45 """
46 if getMPISizeWorld()>1:
47 raise ValueError,"pyvisi.StreamLineModule is not running on more than one processor."
48 self.__vtk_stream_line = vtk.vtkStreamLine()
49
50 def _setupStreamLineModule(self, object, source):
51 """
52 Setup the streamline.
53
54 :type object: vtkUnstructuredGrid, etc
55 :param object: Input for the streamline
56 :type source: vtkPolyData
57 :param source: Source to generate the starting points
58 """
59
60 self.__object = object
61 self.__source = source
62
63 self.__setInput()
64 self.__setSource()
65 # Default maximum propagation time is 100.
66 self.setMaximumPropagationTime(100)
67 # Default step length is 0.01
68 self.setStepLength(0.01)
69 # Default integration step length is 0.01
70 self.setIntegrationStepLength(0.01)
71 # Default integration is set to both directions.
72 self.setIntegrationToBothDirections()
73 # Default integrator is set to vtkRungeKutta4
74 self.setIntegrator(vtk.vtkRungeKutta4())
75
76 def __setInput(self):
77 """
78 Set the input for the streamline.
79 """
80
81 self.__vtk_stream_line.SetInput(self.__object)
82
83 def __setSource(self):
84 """
85 Set the source to generate the starting points for the streamline.
86 """
87
88 self.__vtk_stream_line.SetSource(self.__source)
89
90 def setMaximumPropagationTime(self, time):
91 """
92 Set the maximum length of the streamline expressed in elapsed time.
93
94 :type time: Number
95 :param time: Maximum length of the streamline expressed in elapsed time
96 """
97
98 self.__vtk_stream_line.SetMaximumPropagationTime(time)
99
100 def setStepLength(self, length):
101 """
102 Set the length of the streamline segment expressed in elapsed time.
103 A smaller value results in a smoother streamline
104 (but is more expensive). Setting the step length usually goes
105 hand-in-hand with setting the integration step length. Otherwise,
106 errors such as "... can't compute normals" may arise. If such an
107 error occurs try changing the values.
108
109 :type length: Number
110 :param length: Length of the streamline segment expressed in
111 elapsed time
112 """
113
114 self.__vtk_stream_line.SetStepLength(length)
115
116 def setIntegrationStepLength(self, length):
117 """
118 Set the integration step size expressed as a fraction of the size of
119 each cell. A smaller length results in a better image (but is more
120 expensive).
121
122 :type length: Number
123 :param length: Length of the integration step expressed as a fraction
124 of the size of each cell
125 """
126
127 self.__vtk_stream_line.SetIntegrationStepLength(length)
128
129 def setIntegrationToBothDirections(self):
130 """
131 Set the integration to occur both sides: forward (where the streamline
132 goes) and backward (where the streamline came from).
133 """
134
135 self.__vtk_stream_line.\
136 SetIntegrationDirectionToIntegrateBothDirections()
137
138 def setIntegrator(self, integrator):
139 """
140 Set the integrator to be used in the streamline calculation.
141
142 :type integrator: vtkInitialValueProblemSolver
143 :param integrator: Integrator type. i.e. vtkRungeKutta2, vtkRungeKutta4
144 """
145
146 self.__vtk_stream_line.SetIntegrator(integrator)
147
148 def _setSpeedScalarsOn(self):
149 """
150 Turn on the creation of scalar data from velocity magnitude.
151 """
152
153 self.__vtk_stream_line.SpeedScalarsOn()
154
155 def _setSpeedScalarsOff(self):
156 """
157 Turn off the creation of scalar data from velocity magnitude. If
158 input dataset has scalars, input dataset scalars are used.
159 """
160
161 self.__vtk_stream_line.SpeedScalarsOff()
162
163 def _getStreamLineModuleOutput(self):
164 """
165 Return the output of the streamline.
166
167 :rtype: vtkPolyData
168 :return: Polygonal data
169 """
170
171 return self.__vtk_stream_line.GetOutput()

  ViewVC Help
Powered by ViewVC 1.1.26