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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1101 - (show annotations)
Tue Apr 17 07:11:02 2007 UTC (13 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 2496 byte(s)
Added some test for reading escript objects.
1 from esys.escript import *
2 from esys.escript.linearPDEs import LinearPDE
3 from esys.finley import Rectangle, Brick
4 from esys.pyvisi import Scene, DataCollector, Map, Camera, Velocity, Ellipsoid
5 from esys.pyvisi.constant import *
6 import unittest, os
7 from stat import ST_SIZE
8
9 PYVISI_TEST_ESCRIPT_IMAGES_PATH = "data_sample_images/escript/"
10 MIN_IMAGE_SIZE = 100
11
12 X_SIZE = 400
13 Y_SIZE = 400
14 JPG_RENDERER = Renderer.OFFLINE_JPG
15
16 class TestReadingEscriptObject:
17 def tearDown(self):
18 self.s
19
20 def render(self, file):
21 self.s.render(image_name = PYVISI_TEST_ESCRIPT_IMAGES_PATH + file)
22
23 self.failUnless(os.stat(PYVISI_TEST_ESCRIPT_IMAGES_PATH + \
24 file)[ST_SIZE] > MIN_IMAGE_SIZE)
25
26 class TestEscriptWithPointData(unittest.TestCase, TestReadingEscriptObject):
27 def testPointData(self):
28 #... set some parameters ...
29 xc=[0.02,0.002]
30 r=0.001
31 qc=50.e6
32 Tref=0.
33 rhocp=2.6e6
34 eta=75.
35 kappa=240.
36 tend=5.
37 # ... time, time step size and counter ...
38 t=0
39 h=0.1
40 i=0
41 #... generate domain ...
42 mydomain = Rectangle(l0=0.05,l1=0.01,n0=250, n1=50)
43 #... open PDE ...
44 mypde=LinearPDE(mydomain)
45 mypde.setSymmetryOn()
46 mypde.setValue(A=kappa*kronecker(mydomain),D=rhocp/h,d=eta,y=eta*Tref)
47 # ... set heat source: ....
48 x=mydomain.getX()
49 qH=qc*whereNegative(length(x-xc)-r)
50 # ... set initial temperature ....
51 T=Tref
52
53 # Create a Scene.
54 self.s = Scene(renderer = JPG_RENDERER, x_size = X_SIZE, \
55 y_size = Y_SIZE)
56 s = self.s
57 # Create a DataCollector reading directly from escript objects.
58 dc = DataCollector(source = Source.ESCRIPT)
59
60 # ... start iteration:
61 while t<0.4:
62 i+=1
63 t+=h
64 print "time step :",t
65 mypde.setValue(Y=qH+rhocp/h*T)
66 T=mypde.getSolution()
67
68 dc.setData(temp = T)
69 # Create a Map.
70 Map(scene = s, data_collector = dc,
71 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
72 cell_to_point = False, outline = True)
73
74 # Create a Camera.
75 c= Camera(scene = s, data_collector = dc,
76 viewport = Viewport.SOUTH_WEST)
77
78 # Render the object.
79 self.render("diffusion_%02d.jpg" % i)
80
81
82 #class TestEscriptWithPointAndCellData(unittest.TestCase, TestReadingEscriptObject):
83 # def testPointAndCellData(self):
84
85 ###############################################################################
86 if __name__ == '__main__':
87 suite = unittest.TestSuite()
88 suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestEscriptWithPointData))
89 unittest.TextTestRunner(verbosity=2).run(suite)

  ViewVC Help
Powered by ViewVC 1.1.26