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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 950 - (show annotations)
Tue Feb 6 07:01:11 2007 UTC (12 years, 1 month ago) by gross
File MIME type: text/x-python
File size: 8248 byte(s)
escript data objects can now be saved to netCDF files, see http://www.unidata.ucar.edu/software/netcdf/.
Currently only constant data are implemented with expanded and tagged data to follow.
There are two new functions to dump a data object

   s=Data(...)
   s.dump(<filename>)

and to recover it

   s=load(<filename>, domain)

Notice that the function space of s is recovered but domain is still need. 

dump and load will replace archive and extract.

The installation needs now the netCDF installed. 


1 # $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
170 class Test_DumpOnFinley(Test_Dump):
171 def setUp(self):
172 self.domain =Rectangle(NE,NE+1,2)
173 self.solution = Solution(self.domain)
174 self.reduced_solution = ReducedSolution(self.domain)
175 self.continuous_function = ContinuousFunction(self.domain)
176 self.function = Function(self.domain)
177 self.function_on_boundary = FunctionOnBoundary(self.domain)
178
179 def tearDown(self):
180 del self.function
181 del self.function_on_boundary
182 del self.domain
183
184 if __name__ == '__main__':
185 suite = unittest.TestSuite()
186 suite.addTest(unittest.makeSuite(Test_DumpOnFinley))
187 s=unittest.TextTestRunner(verbosity=2).run(suite)
188 if s.wasSuccessful():
189 sys.exit(0)
190 else:
191 sys.exit(1)
192

  ViewVC Help
Powered by ViewVC 1.1.26