/[escript]/trunk/pyvisi/test/python/run_velocity_with_lazy_evaluation.py
ViewVC logotype

Contents of /trunk/pyvisi/test/python/run_velocity_with_lazy_evaluation.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (show annotations)
Tue May 22 04:24:01 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 5445 byte(s)
Made some changes to fix the memory leak problem. However, the problem still persists for run_escript_with_lazy_evaluation.py, run_streamline.py and run_streamline_with_lazy_evaluation.py.

1 from esys.pyvisi import DataCollector, Scene, Velocity, VelocityOnPlaneCut
2 from esys.pyvisi import VelocityOnPlaneClip, Camera
3 from esys.pyvisi.constant import *
4 import unittest, os
5 from stat import ST_SIZE
6
7 try:
8 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
9 except KeyError:
10 PYVISI_WORKDIR='.'
11 try:
12 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
13 except KeyError:
14 PYVISI_TEST_DATA_ROOT='.'
15
16 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
17 PYVISI_TEST_VELOCITY_REFERENCE_IMAGES_PATH = \
18 os.path.join(PYVISI_TEST_DATA_ROOT, \
19 "data_reference_images", "velocity")
20 PYVISI_TEST_VELOCITY_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
21 "data_sample_images", "velocity")
22
23 MIN_IMAGE_SIZE = 100
24 FILE_3D = "results.xml"
25 X_SIZE = 400
26 Y_SIZE = 400
27
28 JPG_RENDERER = Renderer.OFFLINE_JPG
29 SCALAR_FIELD_POINT_DATA_1 = "scalar1"
30 SCALAR_FIELD_POINT_DATA_2 = "scalar2"
31 VECTOR_FIELD_POINT_DATA_1 = "vector"
32 VECTOR_FIELD_POINT_DATA_2 = "vector2"
33
34 class TestVelocityWithLazyEvaluation:
35 def render(self, file):
36 self.scene.render(image_name = \
37 os.path.join(PYVISI_TEST_VELOCITY_IMAGES_PATH, file))
38
39 self.failUnless(os.stat(os.path.join(PYVISI_TEST_VELOCITY_IMAGES_PATH,\
40 file))[ST_SIZE] > MIN_IMAGE_SIZE)
41
42 class TestVelocity(unittest.TestCase, TestVelocityWithLazyEvaluation):
43 def tearDown(self):
44 del self.scene
45
46 def testVelocity(self):
47
48 s = Scene(renderer = JPG_RENDERER, num_viewport = 4, x_size = X_SIZE,
49 y_size = Y_SIZE)
50 self.scene = s
51
52 dc1 = DataCollector(source = Source.XML)
53 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
54 FILE_3D))
55 dc1.setActiveVector(VECTOR_FIELD_POINT_DATA_1)
56 dc1.setActiveScalar(SCALAR_FIELD_POINT_DATA_2)
57
58 dc2 = DataCollector(source = Source.XML)
59 dc2.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH,\
60 FILE_3D))
61 dc2.setActiveVector(VECTOR_FIELD_POINT_DATA_1)
62 dc2.setActiveScalar(SCALAR_FIELD_POINT_DATA_1)
63
64 dc3 = DataCollector(source = Source.XML)
65 dc3.setActiveVector(VECTOR_FIELD_POINT_DATA_2)
66 dc3.setActiveScalar(SCALAR_FIELD_POINT_DATA_1)
67
68
69 # Create a velocity instance in the first viewport.
70 v1 = Velocity(scene = s, data_collector = dc1,
71 viewport = Viewport.SOUTH_WEST,
72 arrow = Arrow.THREE_D, color_mode = ColorMode.SCALAR,
73 lut = Lut.COLOR, outline = True)
74 v1.setRepresentationToWireframe()
75 v1.setScaleFactor(scale_factor = 0.3)
76 v1.setScaleModeByScalar()
77
78 # Create a velocity instance in the second viewport.
79 v2 = Velocity(scene = s, data_collector = dc2,
80 viewport = Viewport.NORTH_WEST,
81 arrow = Arrow.THREE_D, color_mode = ColorMode.SCALAR,
82 lut = Lut.COLOR, outline = True)
83 v2.setScaleModeByScalar()
84 v2.setScaleFactor(scale_factor = 0.2)
85
86 # Create a velocity instance in the third viewport.
87 v3 = Velocity(scene = s, data_collector = dc2,
88 viewport = Viewport.NORTH_EAST,
89 arrow = Arrow.TWO_D, color_mode = ColorMode.VECTOR,
90 lut = Lut.COLOR, outline = True)
91
92 # Create a velocity instance in the fourth viewport.
93 v4 = Velocity(scene = s, data_collector = dc3,
94 viewport = Viewport.SOUTH_EAST,
95 arrow = Arrow.TWO_D, color_mode = ColorMode.SCALAR,
96 lut = Lut.COLOR, outline = True)
97 v4.setOpacity(opacity = 0.5)
98 v4.setScaleModeByScalar()
99 v4.setScaleFactor(scale_factor = 0.2)
100
101 v3.setScaleFactor(scale_factor = 0.2)
102 v3.setScaleModeByVector()
103 dc3.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
104 FILE_3D))
105
106 self.render("TestVelocityWithLazyEvaluation.jpg")
107
108
109 class TestVelocityOnPlaneCut(unittest.TestCase, TestVelocityWithLazyEvaluation):
110 def tearDown(self):
111 del self.scene
112
113 def testVelocityOnPlaneCut(self):
114 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
115 y_size = Y_SIZE)
116 self.scene = s
117
118 dc1 = DataCollector(source = Source.XML)
119 dc1.setActiveVector(VECTOR_FIELD_POINT_DATA_1)
120
121 # Create a velocity instance.
122 vopc1 = VelocityOnPlaneCut(scene = s, data_collector = dc1,
123 arrow = Arrow.THREE_D, color_mode = ColorMode.VECTOR)
124 vopc1.setScaleFactor(scale_factor = 0.2)
125 vopc1.setPlaneToXY()
126
127 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
128 FILE_3D))
129
130 self.render("TestVelocityOnPlaneCutWithLazyEvaluation.jpg")
131
132
133 class TestVelocityOnPlaneClip(unittest.TestCase, TestVelocityWithLazyEvaluation):
134 def tearDown(self):
135 del self.scene
136
137 def testVelocityOnPlaneClip(self):
138 s = Scene(renderer = JPG_RENDERER, num_viewport = 1, x_size = X_SIZE,
139 y_size = Y_SIZE)
140 self.scene = s
141
142 dc1 = DataCollector(source = Source.XML)
143
144 # Create a velocity on plane clip instance.
145 vopc1 = VelocityOnPlaneClip(scene = s, data_collector = dc1,
146 arrow = Arrow.THREE_D, color_mode = ColorMode.VECTOR)
147 vopc1.setPlaneToXZ()
148
149 c = Camera(scene = s, viewport = Viewport.SOUTH_WEST)
150 c.isometricView()
151
152 vopc1.setScaleFactor(scale_factor = 0.2)
153 dc1.setFileName(file_name = os.path.join(PYVISI_TEST_MESHES_PATH, \
154 FILE_3D))
155 self.render("TestVelocityOnPlaneClipWithLazyEvaluation.jpg")
156
157
158 ###############################################################################
159
160
161 if __name__ == '__main__':
162 suite = unittest.TestSuite()
163 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVelocity))
164 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVelocityOnPlaneCut))
165 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVelocityOnPlaneClip))
166 unittest.TextTestRunner(verbosity=2).run(suite)

  ViewVC Help
Powered by ViewVC 1.1.26