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

  ViewVC Help
Powered by ViewVC 1.1.26