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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (show annotations)
Tue May 22 04:24:01 2007 UTC (12 years, 5 months ago) by jongui
File MIME type: text/x-python
File size: 4264 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
2 from esys.pyvisi.constant import *
3 import unittest, os
4 from stat import ST_SIZE
5
6 try:
7 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
8 except KeyError:
9 PYVISI_WORKDIR='.'
10 try:
11 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
12 except KeyError:
13 PYVISI_TEST_DATA_ROOT='.'
14
15 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
16 PYVISI_TEST_VELOCITY_REFERENCE_IMAGES_PATH = \
17 os.path.join(PYVISI_TEST_DATA_ROOT, \
18 "data_reference_images", "velocity")
19 PYVISI_TEST_VELOCITY_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
20 "data_sample_images", "velocity")
21
22 MIN_IMAGE_SIZE = 100
23 FILE_2D = "interior_2D.xml"
24 FILE_3D = "interior_3D.xml"
25 FILE_SECOND_ORDER_3D = "vel-000719.vtu"
26 X_SIZE = 400
27 Y_SIZE = 400
28 JPG_RENDERER = Renderer.OFFLINE_JPG
29
30 class TestVelocity:
31 def render(self, file):
32 self.scene.render(image_name = \
33 os.path.join(PYVISI_TEST_VELOCITY_IMAGES_PATH, file))
34
35 self.failUnless(os.stat(os.path.join(PYVISI_TEST_VELOCITY_IMAGES_PATH,\
36 file))[ST_SIZE] > MIN_IMAGE_SIZE)
37
38 class TestVelocity2DArrowVectorColor(unittest.TestCase, TestVelocity):
39 def setUp(self):
40 self.scene = \
41 Scene(renderer = JPG_RENDERER, num_viewport = 1,
42 x_size = X_SIZE, y_size = Y_SIZE)
43
44 self.data_collector = DataCollector(source = Source.XML)
45 self.data_collector.setFileName(file_name = \
46 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
47
48 self.velocity = Velocity(scene = self.scene,
49 data_collector = self.data_collector,
50 viewport = Viewport.SOUTH_WEST, arrow = Arrow.THREE_D,
51 color_mode = ColorMode.VECTOR, lut = Lut.COLOR,
52 cell_to_point = False, outline = True)
53
54 def tearDown(self):
55 del self.scene
56 del self.data_collector
57 del self.velocity
58
59 def testVelocityVectorScale(self):
60 self.velocity.setScaleModeByVector()
61 self.velocity.setScaleFactor(0.5)
62 self.render("TestVelocity2DArrowVectorColor_testVelocityVectorScale.jpg")
63
64 class TestVelocity2DArrowScalarColor(unittest.TestCase, TestVelocity):
65 def setUp(self):
66 self.scene = \
67 Scene(renderer = JPG_RENDERER, num_viewport = 1,
68 x_size = X_SIZE, y_size = Y_SIZE)
69
70 self.data_collector = DataCollector(source = Source.XML)
71 self.data_collector.setFileName(file_name = \
72 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_2D))
73
74 self.velocity = Velocity(scene = self.scene,
75 data_collector = self.data_collector,
76 viewport = Viewport.SOUTH_WEST, arrow = Arrow.TWO_D,
77 color_mode = ColorMode.SCALAR, lut = Lut.COLOR,
78 cell_to_point = False, outline = True)
79
80 def tearDown(self):
81 del self.scene
82 del self.data_collector
83 del self.velocity
84
85 def testScalarScale(self):
86 self.velocity.setScaleModeByScalar()
87 self.velocity.setScaleFactor(1.5)
88 self.render("TestVelocity2DArrowScalarColor_testVelocityScalarScale.jpg")
89
90 def testMask(self):
91 self.velocity.setRatio(2)
92 self.velocity.randomOn()
93 self.render("TestVelocity2DArrowScalarColor_testMask.jpg")
94
95 class TestVelocity3DSecondOrder(unittest.TestCase, TestVelocity):
96 def setUp(self):
97 self.scene = \
98 Scene(renderer = JPG_RENDERER, num_viewport = 1,
99 x_size = X_SIZE, y_size = Y_SIZE)
100
101 self.data_collector = DataCollector(source = Source.XML)
102 self.data_collector.setFileName(file_name = \
103 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_SECOND_ORDER_3D))
104
105 self.velocity = Velocity(scene = self.scene,
106 data_collector = self.data_collector,
107 viewport = Viewport.SOUTH_WEST, arrow = Arrow.THREE_D,
108 color_mode = ColorMode.VECTOR, lut = Lut.COLOR,
109 cell_to_point = False, outline = True)
110
111 def tearDown(self):
112 del self.scene
113 del self.data_collector
114 del self.velocity
115
116 def testVelocity3DSecondOrder(self):
117 self.velocity.setScaleFactor(0.5)
118 self.velocity.setRatio(2)
119 self.render("TestVelocity3DSecondOrder.jpg")
120
121
122
123 ###############################################################################
124
125
126 if __name__ == '__main__':
127 suite = unittest.TestSuite()
128 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVelocity2DArrowVectorColor))
129 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVelocity2DArrowScalarColor))
130 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestVelocity3DSecondOrder))
131 unittest.TextTestRunner(verbosity=2).run(suite)

  ViewVC Help
Powered by ViewVC 1.1.26