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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 5228 byte(s)
Change __url__ to launchpad site

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 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-2008 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 from esys.pyvisi import DataCollector, Scene, StreamLine, GlobalPosition
23 from esys.pyvisi.constant import *
24 import unittest, os, sys
25 from stat import ST_SIZE
26 from esys.escript import getMPISizeWorld
27
28 try:
29 PYVISI_WORKDIR=os.environ['PYVISI_WORKDIR']
30 except KeyError:
31 PYVISI_WORKDIR='.'
32 try:
33 PYVISI_TEST_DATA_ROOT=os.environ['PYVISI_TEST_DATA_ROOT']
34 except KeyError:
35 PYVISI_TEST_DATA_ROOT='.'
36
37 PYVISI_TEST_MESHES_PATH = os.path.join(PYVISI_TEST_DATA_ROOT, "data_meshes")
38 PYVISI_TEST_STREAMLINE_IMAGES_PATH = os.path.join(PYVISI_WORKDIR, \
39 "data_sample_images", "streamline")
40
41 MIN_IMAGE_SIZE = 100
42 FILE_3D = "interior_3D.xml"
43 X_SIZE = 400
44 Y_SIZE = 400
45 JPG_RENDERER = Renderer.OFFLINE_JPG
46
47 class TestStreamLine:
48 def render(self, file):
49 self.scene.render(image_name = \
50 os.path.join(PYVISI_TEST_STREAMLINE_IMAGES_PATH, file))
51
52 self.failUnless(os.stat(os.path.join(\
53 PYVISI_TEST_STREAMLINE_IMAGES_PATH, file))[ST_SIZE] > \
54 MIN_IMAGE_SIZE)
55
56 class TestStreamLinePointSource(unittest.TestCase, TestStreamLine):
57 def setUp(self):
58 self.scene = \
59 Scene(renderer = JPG_RENDERER, num_viewport = 1,
60 x_size = X_SIZE, y_size = Y_SIZE)
61
62 self.data_collector = DataCollector(source = Source.XML)
63 self.data_collector.setFileName(file_name = \
64 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
65
66 self.streamline = StreamLine(scene = self.scene,
67 data_collector = self.data_collector,
68 viewport = Viewport.SOUTH_WEST, color_mode = ColorMode.VECTOR,
69 lut = Lut.COLOR, cell_to_point = False, outline = True)
70
71 def tearDown(self):
72 del self.scene
73 del self.data_collector
74 del self.streamline
75
76 def testPointSource(self):
77 self.streamline.setPointSourceRadius(0.1)
78 self.streamline.setPointSourceCenter(GlobalPosition(1.3, 1.3, 0.4))
79 self.streamline.setPointSourceNumberOfPoints(2)
80 self.render("TestStreamLinePointSource.jpg")
81
82 class TestStreamLineModule(unittest.TestCase, TestStreamLine):
83 def setUp(self):
84 self.scene = \
85 Scene(renderer = JPG_RENDERER, num_viewport = 1,
86 x_size = X_SIZE, y_size = Y_SIZE)
87
88 self.data_collector = DataCollector(source = Source.XML)
89 self.data_collector.setFileName(file_name = \
90 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
91
92 self.streamline = StreamLine(scene = self.scene,
93 data_collector = self.data_collector,
94 viewport = Viewport.SOUTH_WEST, color_mode = ColorMode.VECTOR,
95 lut = Lut.COLOR, cell_to_point = False, outline = True)
96
97 def tearDown(self):
98 del self.scene
99 del self.data_collector
100 del self.streamline
101
102 def testStreamLineModule(self):
103 self.streamline.setMaximumPropagationTime(20)
104 self.streamline.setStepLength(0.1)
105 self.streamline.setIntegrationStepLength(0.1)
106 self.streamline.setIntegrationToBothDirections()
107 self.render("TestStreamLineModule.jpg")
108
109 class TestStreamLineTube(unittest.TestCase, TestStreamLine):
110 def setUp(self):
111 self.scene = \
112 Scene(renderer = JPG_RENDERER, num_viewport = 1,
113 x_size = X_SIZE, y_size = Y_SIZE)
114
115 self.data_collector = DataCollector(source = Source.XML)
116 self.data_collector.setFileName(file_name = \
117 os.path.join(PYVISI_TEST_MESHES_PATH, FILE_3D))
118
119 self.streamline = StreamLine(scene = self.scene,
120 data_collector = self.data_collector,
121 viewport = Viewport.SOUTH_WEST, color_mode = ColorMode.SCALAR,
122 lut = Lut.COLOR, cell_to_point = False, outline = True)
123
124 def tearDown(self):
125 del self.scene
126 del self.data_collector
127 del self.streamline
128
129 def testSetTubeRadiusToVaryByVector(self):
130 self.streamline.setTubeRadius(0.02)
131 self.streamline.setTubeNumberOfSides(3)
132 self.streamline.setTubeRadiusToVaryByVector()
133 self.render("TestStreamLineTube_testSetTubeRadiusToVaryByVector.jpg")
134
135 def testSetTubeRadiusToVaryByScalar(self):
136 self.streamline.setTubeRadiusToVaryByScalar()
137 self.render("TestStreamLineTube_testSetTubeRadiusToVaryByScalar.jpg")
138
139
140 ##############################################################################
141
142
143 if __name__ == '__main__':
144 if getMPISizeWorld() == 1:
145 suite = unittest.TestSuite()
146 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestStreamLinePointSource))
147 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestStreamLineModule))
148 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestStreamLineTube))
149 s=unittest.TextTestRunner(verbosity=2).run(suite)
150 if not s.wasSuccessful(): sys.exit(1)
151 else:
152 print "run_streamline.py is not executed as more than one processor is used."
153

  ViewVC Help
Powered by ViewVC 1.1.26