/[escript]/branches/domexper/finley/test/python/run_escriptOnFinley.py
ViewVC logotype

Annotation of /branches/domexper/finley/test/python/run_escriptOnFinley.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2628 - (hide annotations)
Tue Aug 25 03:50:00 2009 UTC (9 years, 10 months ago) by jfenwick
Original Path: trunk/finley/test/python/run_escriptOnFinley.py
File MIME type: text/x-python
File size: 7232 byte(s)
Fixed linkage on getTestDomainFunctionSpace.

added Data.interpolateTable to perform 2D interpolation.
It needs better unit tests though.
1 ksteube 1809
2     ########################################################
3 ksteube 1312 #
4 jfenwick 2548 # Copyright (c) 2003-2009 by University of Queensland
5 ksteube 1809 # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7 ksteube 1312 #
8 ksteube 1809 # 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 ksteube 1312 #
12 ksteube 1809 ########################################################
13 gross 983
14 jfenwick 2549 __copyright__="""Copyright (c) 2003-2009 by University of Queensland
15 ksteube 1809 Earth Systems Science Computational Center (ESSCC)
16     http://www.uq.edu.au/esscc
17     Primary Business: Queensland, Australia"""
18 gross 983 __license__="""Licensed under the Open Software License version 3.0
19 ksteube 1809 http://www.opensource.org/licenses/osl-3.0.php"""
20 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
21 ksteube 1809
22 gross 983 import unittest
23     import tempfile
24    
25     from esys.escript import *
26     from esys.finley import Rectangle
27     import sys
28     import os
29 gross 1141 from test_objects import Test_Dump, Test_SetDataPointValue
30     from test_objects import Test_Domain
31 gross 983
32 jfenwick 2271 from test_shared import Test_Shared
33    
34 gross 983 try:
35     FINLEY_WORKDIR=os.environ['FINLEY_WORKDIR']
36     except KeyError:
37     FINLEY_WORKDIR='.'
38    
39     NE=4 # number elements, must be even
40 jfenwick 2271
41     class Test_SharedOnFinley(Test_Shared):
42     def setUp(self):
43     self.domain=Rectangle(NE,NE)
44     self.tol=0.001
45     def tearDown(self):
46     del self.domain
47     del self.tol
48    
49 gross 1044 class Test_DomainOnFinley(Test_Domain):
50     def setUp(self):
51 gross 2425 self.boundary_tag_list = [1, 2, 10, 20]
52 gross 1044 self.domain =Rectangle(NE,NE+1,2)
53     def tearDown(self):
54     del self.domain
55 gross 2425 del self.boundary_tag_list
56 gross 1716
57     def test_tagsContinuousFunction(self):
58     ref_tags=[0]
59     tags=ContinuousFunction(self.domain).getListOfTags()
60     self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
61     for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
62    
63     def test_tagsFunction(self):
64     ref_tags=[0]
65     tags=Function(self.domain).getListOfTags()
66     self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
67     for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
68     def test_tagsReducedFunction(self):
69     ref_tags=[0]
70     tags=ReducedFunction(self.domain).getListOfTags()
71     self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
72     for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
73     def test_tagsFunctionOnBoundary(self):
74 ksteube 1829 ref_tags=[1, 2, 10, 20]
75     tags=FunctionOnBoundary(self.domain).getListOfTags()
76     # For an MPI-distributed domain some tags may be missing
77     if getMPISizeWorld() == 1: self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
78     for i in tags: self.failUnless(i in ref_tags,"tag %s is missing."%i)
79 gross 1716 def test_tagsReducedFunctionOnBoundary(self):
80 ksteube 1829 ref_tags=[1, 2, 10, 20]
81     tags=ReducedFunctionOnBoundary(self.domain).getListOfTags()
82     # For an MPI-distributed domain some tags may be missing
83     if getMPISizeWorld() == 1: self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
84     for i in tags: self.failUnless(i in ref_tags,"tag %s is missing."%i)
85 gross 1716 def test_tagsFunctionOnContactOne(self):
86     ref_tags=[]
87     tags=FunctionOnContactOne(self.domain).getListOfTags()
88     self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
89     for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
90     def test_tagsFunctionOnContactZero(self):
91     ref_tags=[]
92     tags=FunctionOnContactZero(self.domain).getListOfTags()
93     self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
94     for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
95     def test_tagsReducedFunctionOnContactOne(self):
96     ref_tags=[]
97     tags=ReducedFunctionOnContactOne(self.domain).getListOfTags()
98     self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
99     for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
100     def test_tagsReducedFunctionOnContactZero(self):
101     ref_tags=[]
102     tags=ReducedFunctionOnContactZero(self.domain).getListOfTags()
103     self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
104     for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
105    
106     class Test_DataOpsOnFinley(Test_Dump, Test_SetDataPointValue):
107 gross 983 def setUp(self):
108     self.domain =Rectangle(NE,NE+1,2)
109     self.domain_with_different_number_of_samples =Rectangle(2*NE,NE+1,2)
110     self.domain_with_different_number_of_data_points_per_sample =Rectangle(2*NE,NE+1,2,integrationOrder=2)
111 gross 1856 self.domain_with_different_sample_ordering =Rectangle(NE,NE+1,2, optimize=True)
112 gross 1141 self.filename_base=FINLEY_WORKDIR
113 gross 983
114     def tearDown(self):
115     del self.domain
116     del self.domain_with_different_number_of_samples
117     del self.domain_with_different_number_of_data_points_per_sample
118     del self.domain_with_different_sample_ordering
119    
120 jfenwick 2628 #Some of this functionality could be tested in escript but we need
121     #the rectangle domain for the rest of it
122     class Test_TableInterpolation(unittest.TestCase):
123    
124     RES_TOL=1.e-7 # RES_TOLerance to compare results
125    
126    
127     def test_NullFunctionSpace(self):
128     arL=[[0, -1, -2, -3, -4], [1, 1, -2, -3, -4], [2, 2, 2, -3, -4], [3, 3, 3, 3, -4], [4, 4, 4, 4, 4]]
129     arn=numpy.array(arL)
130     ars=[arL,arn]
131     d0=Data(0)
132     d1=Data(1)
133     d2=Data(2)
134     d35=Data(3.5)
135     d4=Data(4)
136     dm05=Data(-0.5)
137     d175=Data(1.75)
138     d225=Data(2.25)
139     for arr in ars:
140     self.failUnless(Lsup(d1.interpolateTable(arL,0, 1, 100, d2, 0, 1)+2)<self.RES_TOL)
141     self.failUnless(Lsup(d1.interpolateTable(arL,0, 1, 100, d35, 0, 1)+3.5)<self.RES_TOL)
142     self.failUnless(Lsup(d35.interpolateTable(arL,0,1, 100, d2, 0, 1)-3.5)<self.RES_TOL)
143     self.failUnless(Lsup(d175.interpolateTable(arL,0,1,100,d225,0,1)-0)<self.RES_TOL)
144     self.failUnless(Lsup(d2.interpolateTable(arL, 1, 4, 100, d2, -1, 4)-0.25)<self.RES_TOL)
145     # Point out of bounds
146     self.failUnlessRaises(RuntimeError, d1.interpolateTable,arL,0, 1, 100, d4, 0, 1 )
147     self.failUnlessRaises(RuntimeError, d4.interpolateTable, arL,0, 1, 100, d1, 0, 1 )
148     self.failUnlessRaises(RuntimeError, dm05.interpolateTable, arL,0,1, 100, d1 , 0,1 )
149     self.failUnlessRaises(RuntimeError, d1.interpolateTable, arL,0,1, 100, dm05 , 0,1 )
150     # interpolated value too large
151     self.failUnlessRaises(RuntimeError, d2.interpolateTable, arL, 0, 1, 1, d2, 0, 1 )
152    
153     def test_Rectangle(self):
154     bounds=2
155     r=Rectangle(n0=bounds, n1=bounds, l0=bounds, l1=bounds)
156     x=r.getX()
157     arr=[]
158     for j in xrange(bounds+2):
159     v=[]
160     for k in xrange(bounds+2):
161     v.append(k)
162     arr.append(v)
163     arr=numpy.array(arr)
164     x0=x[0]
165     x1=x[1]
166     d100=Data(100)
167     self.failUnlessRaises(RuntimeError, d100.interpolateTable, arr, 0, 1, 5, d100,0,1)
168     zz=x0.interpolateTable(arr,0,1,100,x1,0,1)
169    
170    
171 gross 983 if __name__ == '__main__':
172     suite = unittest.TestSuite()
173 jfenwick 2271 suite.addTest(unittest.makeSuite(Test_SharedOnFinley))
174 gross 1141 suite.addTest(unittest.makeSuite(Test_DataOpsOnFinley))
175 gross 1185 suite.addTest(unittest.makeSuite(Test_DomainOnFinley))
176 jfenwick 2628 suite.addTest(unittest.makeSuite(Test_TableInterpolation))
177 gross 983 s=unittest.TextTestRunner(verbosity=2).run(suite)
178 gross 1376 if not s.wasSuccessful(): sys.exit(1)
179    

  ViewVC Help
Powered by ViewVC 1.1.26