/[escript]/trunk/finley/test/python/dmp.py
ViewVC logotype

Annotation of /trunk/finley/test/python/dmp.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 965 - (hide annotations)
Tue Feb 13 05:38:45 2007 UTC (13 years, 8 months ago) by gross
File MIME type: text/x-python
File size: 14683 byte(s)
johns local setting removed.
1 gross 950 # $Id:$
2    
3     __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
4     http://www.access.edu.au
5     Primary Business: Queensland, Australia"""
6     __license__="""Licensed under the Open Software License version 3.0
7     http://www.opensource.org/licenses/osl-3.0.php"""
8     import unittest
9     import tempfile
10    
11     from esys.escript import *
12     from esys.finley import Rectangle
13     import sys
14     import os
15    
16     try:
17     FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
18     except KeyError:
19     FINLEY_TEST_DATA='.'
20    
21     FINLEY_TEST_MESH_PATH=FINLEY_TEST_DATA+"/data_meshes/"
22    
23    
24     NE=4 # number elements, must be even
25     class Test_Dump(unittest.TestCase):
26     arg0=9.81
27     arg1=numarray.array([3.098, -3.111])
28     arg2=numarray.array([[3.82, -3.81, -0.957, 0.892, -1.367], [-4.589, -1.835, -2.679, -1.517, -4.2515], [-4.909, 1.634, -2.883, -2.135, 1.187], [0.6431, 4.638, -4.616, -0.196, -4.370]])
29     arg3=numarray.array([[[-2.3667, -0.040], [-4.7398, -3.2412]], [[-2.125, -2.240], [2.237, -4.279]], [[0.68720, 2.4059], [-2.4964, 3.17453]], [[-4.907, -4.9431], [-0.3604, 0.4269]], [[1.4179, 3.326], [1.356, -0.4610]], [[3.378, 2.0902], [-2.6857, 1.3585]]])
30     arg4=numarray.array([[[[-3.810, -1.3597, -1.5307, 1.099], [-1.828, 0.2526, -1.4429, 2.326], [4.9732, -2.063, 1.3153, -3.809]], [[-4.8902, -4.714, 1.520, -1.931], [-3.8847, 4.3867, 1.894030, 2.432], [-1.2082, -0.8304, 2.2612, 4.6399]]], [[[-4.5922, -3.309, -0.8171, -0.7210], [2.8051, -4.93047, 0.08450, 4.3824], [0.43204, 2.1908, 4.512633, -1.8218]], [[2.2493, -4.190, -2.3893, -4.147], [-2.104, -4.635, -4.2767, -3.53151], [-2.351, -1.6614, 2.9385, 4.099]]], [[[1.710, 0.2235, -3.4917, 0.8713], [-0.2881, 4.6278, 3.603, -2.1211], [-0.565, 4.294, -2.210827, -0.37651]], [[0.6578, -2.869, -2.490, -4.789], [3.232, 2.483, 0.9531, 2.260], [-1.785, 0.42156, -1.8379, 4.212]]]])
31    
32     def _diffDataObjects(self,d_ref,file):
33     d_ref.dump(file)
34     d=load(file, self.domain)
35     self.failUnless(not d.isEmpty(),"data in %s are empty."%file)
36     self.failUnless(d_ref.getFunctionSpace() == d.getFunctionSpace(), "wrong function space in %s."%file)
37     self.failUnless(d_ref.getRank() == d.getRank(), "different rank in %s. "%file)
38     self.failUnless(d_ref.getShape() == d.getShape(), "different shape %s. "%file)
39     self.failUnless(Lsup(d_ref-d)<=0., "different entries %s."%file)
40    
41     #===========================================================================
42     def test_DumpAndLoad_Constant_Solution_Rank0(self):
43     file="constant_solution_rank0.nc"
44     d=Data(self.arg0,self.solution)
45     self._diffDataObjects(d,file)
46    
47     def test_DumpAndLoad_Constant_Solution_Rank1(self):
48     file="constant_solution_rank1.nc"
49     d=Data(self.arg1,self.solution)
50     self._diffDataObjects(d,file)
51    
52     def test_DumpAndLoad_Constant_Solution_Rank2(self):
53     file="constant_solution_rank2.nc"
54     d=Data(self.arg2,self.solution)
55     self._diffDataObjects(d,file)
56    
57     def test_DumpAndLoad_Constant_Solution_Rank3(self):
58     file="constant_solution_rank3.nc"
59     d=Data(self.arg3,self.solution)
60     self._diffDataObjects(d,file)
61    
62     def test_DumpAndLoad_Constant_Solution_Rank4(self):
63     file="constant_solution_rank4.nc"
64     d=Data(self.arg4,self.solution)
65     self._diffDataObjects(d,file)
66     #===========================================================================
67     def test_DumpAndLoad_Constant_ReducedSolution_Rank0(self):
68     file="constant_reduced_solution_rank0.nc"
69     d=Data(self.arg0,self.reduced_solution)
70     self._diffDataObjects(d,file)
71    
72     def test_DumpAndLoad_Constant_ReducedSolution_Rank1(self):
73     file="constant_reduced_solution_rank1.nc"
74     d=Data(self.arg1,self.reduced_solution)
75     self._diffDataObjects(d,file)
76    
77     def test_DumpAndLoad_Constant_ReducedSolution_Rank2(self):
78     file="constant_reduced_solution_rank2.nc"
79     d=Data(self.arg2,self.reduced_solution)
80     self._diffDataObjects(d,file)
81    
82     def test_DumpAndLoad_Constant_ReducedSolution_Rank3(self):
83     file="constant_reduced_solution_rank3.nc"
84     d=Data(self.arg3,self.reduced_solution)
85     self._diffDataObjects(d,file)
86    
87     def test_DumpAndLoad_Constant_ReducedSolution_Rank4(self):
88     file="constant_reduced_solution_rank4.nc"
89     d=Data(self.arg4,self.reduced_solution)
90     self._diffDataObjects(d,file)
91     #===========================================================================
92     def test_DumpAndLoad_Constant_ContinuousFunction_Rank0(self):
93     file="constant_continuous_function_rank0.nc"
94     d=Data(self.arg0,self.continuous_function)
95     self._diffDataObjects(d,file)
96    
97     def test_DumpAndLoad_Constant_ContinuousFunction_Rank1(self):
98     file="constant_continuous_function_rank1.nc"
99     d=Data(self.arg1,self.continuous_function)
100     self._diffDataObjects(d,file)
101    
102     def test_DumpAndLoad_Constant_ContinuousFunction_Rank2(self):
103     file="constant_continuous_function_rank2.nc"
104     d=Data(self.arg2,self.continuous_function)
105     self._diffDataObjects(d,file)
106    
107     def test_DumpAndLoad_Constant_ContinuousFunction_Rank3(self):
108     file="constant_continuous_function_rank3.nc"
109     d=Data(self.arg3,self.continuous_function)
110     self._diffDataObjects(d,file)
111    
112     def test_DumpAndLoad_Constant_ContinuousFunction_Rank4(self):
113     file="constant_continuous_function_rank4.nc"
114     d=Data(self.arg4,self.continuous_function)
115     self._diffDataObjects(d,file)
116    
117     #===========================================================================
118     def test_DumpAndLoad_Constant_Function_Rank0(self):
119     file="constant_function_rank0.nc"
120     d=Data(self.arg0,self.function)
121     self._diffDataObjects(d,file)
122    
123     def test_DumpAndLoad_Constant_Function_Rank1(self):
124     file="constant_function_rank1.nc"
125     d=Data(self.arg1,self.function)
126     self._diffDataObjects(d,file)
127    
128     def test_DumpAndLoad_Constant_Function_Rank2(self):
129     file="constant_function_rank2.nc"
130     d=Data(self.arg2,self.function)
131     self._diffDataObjects(d,file)
132    
133     def test_DumpAndLoad_Constant_Function_Rank3(self):
134     file="constant_function_rank3.nc"
135     d=Data(self.arg3,self.function)
136     self._diffDataObjects(d,file)
137    
138     def test_DumpAndLoad_Constant_Function_Rank4(self):
139     file="constant_function_rank4.nc"
140     d=Data(self.arg4,self.function)
141     self._diffDataObjects(d,file)
142    
143     #===========================================================================
144     def test_DumpAndLoad_Constant_FunctionOnBoundary_Rank0(self):
145     file="constant_function_on_boundary_rank0.nc"
146     d=Data(self.arg0,self.function_on_boundary)
147     self._diffDataObjects(d,file)
148    
149     def test_DumpAndLoad_Constant_FunctionOnBoundary_Rank1(self):
150     file="constant_function_on_boundary_rank1.nc"
151     d=Data(self.arg1,self.function_on_boundary)
152     self._diffDataObjects(d,file)
153    
154     def test_DumpAndLoad_Constant_FunctionOnBoundary_Rank2(self):
155     file="constant_function_on_boundary_rank2.nc"
156     d=Data(self.arg2,self.function_on_boundary)
157     self._diffDataObjects(d,file)
158    
159     def test_DumpAndLoad_Constant_FunctionOnBoundary_Rank3(self):
160     file="constant_function_on_boundary_rank3.nc"
161     d=Data(self.arg3,self.function_on_boundary)
162     self._diffDataObjects(d,file)
163    
164     def test_DumpAndLoad_Constant_FunctionOnBoundary_Rank4(self):
165     file="constant_function_on_boundary_rank4.nc"
166     d=Data(self.arg4,self.function_on_boundary)
167     self._diffDataObjects(d,file)
168    
169 gross 965 #===========================================================================
170     def test_DumpAndLoad_Expanded_Solution_Rank0(self):
171     file="expanded_solution_rank0.nc"
172     d=Data(length(self.solution.getX())*self.arg0,self.solution)
173     self._diffDataObjects(d,file)
174 gross 950
175 gross 965 def test_DumpAndLoad_Expanded_Solution_Rank1(self):
176     file="expanded_solution_rank1.nc"
177     d=Data(length(self.solution.getX())*self.arg1,self.solution)
178     self._diffDataObjects(d,file)
179    
180     def test_DumpAndLoad_Expanded_Solution_Rank2(self):
181     file="expanded_solution_rank2.nc"
182     d=Data(length(self.solution.getX())*self.arg2,self.solution)
183     self._diffDataObjects(d,file)
184    
185     def test_DumpAndLoad_Expanded_Solution_Rank3(self):
186     file="expanded_solution_rank3.nc"
187     d=Data(length(self.solution.getX())*self.arg3,self.solution)
188     self._diffDataObjects(d,file)
189    
190     def test_DumpAndLoad_Expanded_Solution_Rank4(self):
191     file="expanded_solution_rank4.nc"
192     d=Data(length(self.solution.getX())*self.arg4,self.solution)
193     self._diffDataObjects(d,file)
194     #===========================================================================
195     def test_DumpAndLoad_Expanded_ReducedSolution_Rank0(self):
196     file="expanded_reduced_solution_rank0.nc"
197     d=Data(length(self.reduced_solution.getX())*self.arg0,self.reduced_solution)
198     self._diffDataObjects(d,file)
199    
200     def test_DumpAndLoad_Expanded_ReducedSolution_Rank1(self):
201     file="expanded_reduced_solution_rank1.nc"
202     d=Data(length(self.reduced_solution.getX())*self.arg1,self.reduced_solution)
203     self._diffDataObjects(d,file)
204    
205     def test_DumpAndLoad_Expanded_ReducedSolution_Rank2(self):
206     file="expanded_reduced_solution_rank2.nc"
207     d=Data(length(self.reduced_solution.getX())*self.arg2,self.reduced_solution)
208     self._diffDataObjects(d,file)
209    
210     def test_DumpAndLoad_Expanded_ReducedSolution_Rank3(self):
211     file="expanded_reduced_solution_rank3.nc"
212     d=Data(length(self.reduced_solution.getX())*self.arg3,self.reduced_solution)
213     self._diffDataObjects(d,file)
214    
215     def test_DumpAndLoad_Expanded_ReducedSolution_Rank4(self):
216     file="expanded_reduced_solution_rank4.nc"
217     d=Data(length(self.reduced_solution.getX())*self.arg4,self.reduced_solution)
218     self._diffDataObjects(d,file)
219     #===========================================================================
220     def test_DumpAndLoad_Expanded_ContinuousFunction_Rank0(self):
221     file="expanded_continuous_function_rank0.nc"
222     d=Data(length(self.continuous_function.getX())*self.arg0,self.continuous_function)
223     self._diffDataObjects(d,file)
224    
225     def test_DumpAndLoad_Expanded_ContinuousFunction_Rank1(self):
226     file="expanded_continuous_function_rank1.nc"
227     d=Data(length(self.continuous_function.getX())*self.arg1,self.continuous_function)
228     self._diffDataObjects(d,file)
229    
230     def test_DumpAndLoad_Expanded_ContinuousFunction_Rank2(self):
231     file="expanded_continuous_function_rank2.nc"
232     d=Data(length(self.continuous_function.getX())*self.arg2,self.continuous_function)
233     self._diffDataObjects(d,file)
234    
235     def test_DumpAndLoad_Expanded_ContinuousFunction_Rank3(self):
236     file="expanded_continuous_function_rank3.nc"
237     d=Data(length(self.continuous_function.getX())*self.arg3,self.continuous_function)
238     self._diffDataObjects(d,file)
239    
240     def test_DumpAndLoad_Expanded_ContinuousFunction_Rank4(self):
241     file="expanded_continuous_function_rank4.nc"
242     d=Data(length(self.continuous_function.getX())*self.arg4,self.continuous_function)
243     self._diffDataObjects(d,file)
244    
245     #===========================================================================
246     def test_DumpAndLoad_Expanded_Function_Rank0(self):
247     file="expanded_function_rank0.nc"
248     d=Data(length(self.function.getX())*self.arg0,self.function)
249     self._diffDataObjects(d,file)
250    
251     def test_DumpAndLoad_Expanded_Function_Rank1(self):
252     file="expanded_function_rank1.nc"
253     d=Data(length(self.function.getX())*self.arg1,self.function)
254     self._diffDataObjects(d,file)
255    
256     def test_DumpAndLoad_Expanded_Function_Rank2(self):
257     file="expanded_function_rank2.nc"
258     d=Data(length(self.function.getX())*self.arg2,self.function)
259     self._diffDataObjects(d,file)
260    
261     def test_DumpAndLoad_Expanded_Function_Rank3(self):
262     file="expanded_function_rank3.nc"
263     d=Data(length(self.function.getX())*self.arg3,self.function)
264     self._diffDataObjects(d,file)
265    
266     def test_DumpAndLoad_Expanded_Function_Rank4(self):
267     file="expanded_function_rank4.nc"
268     d=Data(length(self.function.getX())*self.arg4,self.function)
269     self._diffDataObjects(d,file)
270    
271     #===========================================================================
272     def test_DumpAndLoad_Expanded_FunctionOnBoundary_Rank0(self):
273     file="expanded_function_on_boundary_rank0.nc"
274     d=Data(length(self.function_on_boundary.getX())*self.arg0,self.function_on_boundary)
275     self._diffDataObjects(d,file)
276    
277     def test_DumpAndLoad_Expanded_FunctionOnBoundary_Rank1(self):
278     file="expanded_function_on_boundary_rank1.nc"
279     d=Data(length(self.function_on_boundary.getX())*self.arg1,self.function_on_boundary)
280     self._diffDataObjects(d,file)
281    
282     def test_DumpAndLoad_Expanded_FunctionOnBoundary_Rank2(self):
283     file="expanded_function_on_boundary_rank2.nc"
284     d=Data(length(self.function_on_boundary.getX())*self.arg2,self.function_on_boundary)
285     self._diffDataObjects(d,file)
286    
287     def test_DumpAndLoad_Expanded_FunctionOnBoundary_Rank3(self):
288     file="expanded_function_on_boundary_rank3.nc"
289     d=Data(length(self.function_on_boundary.getX())*self.arg3,self.function_on_boundary)
290     self._diffDataObjects(d,file)
291    
292     def test_DumpAndLoad_Expanded_FunctionOnBoundary_Rank4(self):
293     file="expanded_function_on_boundary_rank4.nc"
294     d=Data(length(self.function_on_boundary.getX())*self.arg4,self.function_on_boundary)
295     self._diffDataObjects(d,file)
296    
297    
298 gross 950 class Test_DumpOnFinley(Test_Dump):
299     def setUp(self):
300     self.domain =Rectangle(NE,NE+1,2)
301     self.solution = Solution(self.domain)
302     self.reduced_solution = ReducedSolution(self.domain)
303     self.continuous_function = ContinuousFunction(self.domain)
304     self.function = Function(self.domain)
305     self.function_on_boundary = FunctionOnBoundary(self.domain)
306    
307 gross 965
308     class Test_DumpOnFinley(Test_Dump):
309     def setUp(self):
310     self.domain =Rectangle(NE,NE+1,2)
311     self.solution = Solution(self.domain)
312     self.reduced_solution = ReducedSolution(self.domain)
313     self.continuous_function = ContinuousFunction(self.domain)
314     self.function = Function(self.domain)
315     self.function_on_boundary = FunctionOnBoundary(self.domain)
316    
317 gross 950 def tearDown(self):
318     del self.function
319     del self.function_on_boundary
320     del self.domain
321    
322     if __name__ == '__main__':
323     suite = unittest.TestSuite()
324     suite.addTest(unittest.makeSuite(Test_DumpOnFinley))
325     s=unittest.TextTestRunner(verbosity=2).run(suite)
326     if s.wasSuccessful():
327     sys.exit(0)
328     else:
329     sys.exit(1)
330    

  ViewVC Help
Powered by ViewVC 1.1.26