/[escript]/trunk/escript/test/python/MiscTests.py
ViewVC logotype

Contents of /trunk/escript/test/python/MiscTests.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 614 - (show annotations)
Wed Mar 22 01:37:07 2006 UTC (13 years, 4 months ago) by elspeth
File MIME type: text/x-python
File size: 6097 byte(s)
Corrected spelling of 'license' in url so that the link actually points to the license.

1
2 """
3
4 Miscellaneous escript/Data tests.
5
6 Version $Id$
7
8 """
9
10
11 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
12 http://www.access.edu.au
13 Primary Business: Queensland, Australia"""
14 __license__="""Licensed under the Open Software License version 3.0
15 http://www.opensource.org/licenses/osl-3.0.php"""
16
17 import sys
18 import unittest
19 import os
20
21 from esys.escript import *
22 from esys import bruce
23
24 import numarray
25 from numarray import array,Float64,ones,greater
26
27
28 arglist = [ \
29 3.0, \
30 [3,4], \
31 [[1,2],[3,4]], \
32 [[15,8],[12,8]], \
33 [[[15,8],[12,8]],[[-9,9],[13,8]]] \
34 ]
35
36 def turnToArray(val):
37 out=array(val,Float64)
38 return out
39
40 def prepareArg(val,ex,wh):
41 if ex=="Expanded":
42 exx=True
43 else:
44 exx=False
45 out=Data(val,what=wh,expand=exx)
46 return out
47
48 def checkResult(text,res,val0,val1,val2,wh):
49 ref=Data(val0,what=wh,expand=False)
50 ref.setTaggedValue(Tag1,val1)
51 ref.setTaggedValue(Tag2,val2)
52 norm=Lsup(ref)+tol
53 error=Lsup(ref-res)/norm
54 print "@@ %s, shape %s: error = %e"%(text,ref.getShape(),error)
55 if error>tol:
56 #raise SystemError,"@@ %s at %s: error is too large"%(text,wh)
57 print "**** %s : error is too large"%(text)
58
59 def getRank(arg):
60 if isinstance(arg,Data):
61 return arg.getRank()
62 else:
63 g=array(arg)
64 if g.rank==0:
65 return 1
66 else:
67 return g.rank
68
69 def isScalar(arg):
70 if isinstance(arg,Data):
71 if arg.getRank()==1 and arg.getShape()[0]==1:
72 return not None
73 else:
74 return None
75 else:
76 g=array(arg)
77 if g.rank==0:
78 return not None
79 else:
80 if g.rank==1 and g.shape[0]==1:
81 return not None
82 else:
83 return None
84
85 #
86 # ==============================================================
87
88 print "\n\n"
89
90 msh=bruce.Rectangle()
91
92 for wh in [ContinuousFunction(msh),Function(msh)]:
93
94 print wh
95
96 for ex in ["Constant","Expanded"]:
97
98 for a in arglist:
99
100 print "\n", ex, a, "==>"
101
102 arg=prepareArg(a,ex,wh)
103
104 print "\n\nTests of copy method:"
105
106 arg_copy = Data()
107 arg_copy.copy(arg)
108 print arg
109 print arg_copy
110
111 print "\n\nTests of conversion to numarray:"
112
113 narray1 = arg.convertToNumArray()
114 narray2 = arg.convertToNumArrayFromSampleNo(0)
115 narray3 = arg.convertToNumArrayFromDPNo(0,0)
116
117 print "arg.convertToNumArray()"
118 print narray1
119
120 print "arg.convertToNumArrayFromSampleNo(0)"
121 print narray2
122
123 print "arg.convertToNumArrayFromDPNo(0,0)"
124 print narray3
125
126 if (ex == "Constant"):
127 print "\n\nTest of getTagNumber:"
128 arg_copy = Data()
129 arg_copy.copy(arg)
130 arg_copy.tag()
131 for dpno in range(narray1.shape[0]):
132 print arg_copy.getTagNumber(dpno)
133 print wh.getTagFromDataPointNo(dpno)
134
135 if (ex == "Expanded"):
136 print "\n\nTests of get/setRefValue functions:"
137 result_array = numarray.array(a)
138 print result_array
139 result_array+=1
140 arg.setRefValue(0,result_array)
141 arg.getRefValue(0,result_array)
142 print result_array
143
144 print "\n\nTests of misc python functions:"
145
146 print "\nmindp:"
147 print arg.mindp()
148
149 #print "\nabs:"
150 #print arg._abs()
151
152 print "\nmaxval:"
153 print arg._maxval()
154
155 print "\nminval:"
156 print arg._minval()
157
158 #print "\nlength"
159 #print arg.length()
160
161 print "\ntrace"
162 print arg._trace()
163
164 print "\nsign"
165 print arg._sign()
166
167 print "\nexp"
168 print arg._exp()
169
170 print "\nsqrt"
171 print arg._sqrt()
172
173 #print "\nneg"
174 #print arg._neg()
175
176 #print "\npos"
177 #print arg._pos()
178
179 print "\nsin"
180 print arg._sin()
181
182 print "\ncos"
183 print arg._cos()
184
185 print "\ntan"
186 print arg._tan()
187
188 print "\nasin"
189 print arg._asin()
190
191 print "\nacos"
192 print arg._acos()
193
194 print "\natan"
195 print arg._atan()
196
197 print "\nsinh"
198 print arg._sinh()
199
200 print "\ncosh"
201 print arg._cosh()
202
203 print "\ntanh"
204 print arg._tanh()
205
206 print "\nasinh"
207 print arg._asinh()
208
209 print "\nacosh"
210 print arg._acosh()
211
212 print "\natanh"
213 print arg._atanh()
214
215 print "\nlog"
216 print arg._log()
217
218 #print "\nln"
219 #print arg.ln()
220
221 print "\nLsup"
222 print arg._Lsup()
223
224 print "\nsup"
225 print arg._sup()
226
227 print "\ninf"
228 print arg._inf()
229
230
231 print "\n\nTests of archiveData and extractData:"
232
233 print "\nDataExpanded:"
234 archDataE=Data([[1.00001],[2.00001]],Function(msh),True)
235 archDataE.archiveData("data-archiveE")
236 exDataE=Data()
237 exDataE.extractData("data-archiveE",Function(msh))
238 exDataE.archiveData("data-archive2E");
239
240 print "\nDataTagged:"
241 archDataT=Data([[1.00001],[2.00001]],Function(msh))
242 archDataT.tag()
243 archDataT.archiveData("data-archiveT")
244 exDataT=Data()
245 exDataT.extractData("data-archiveT",Function(msh))
246 exDataT.archiveData("data-archive2T");
247
248 print "\nDataConstant:"
249 archDataC=Data([1.00001], Function(msh))
250 archDataC.archiveData("data-archiveC")
251 exDataC=Data()
252 exDataC.extractData("data-archiveC",Function(msh))
253 exDataC.archiveData("data-archive2C");
254
255 print "\nDataEmpty:"
256 archDataM=Data()
257 archDataM.archiveData("data-archiveE")
258 exDataM=Data()
259 exDataM.extractData("data-archiveE",FunctionSpace())
260 exDataM.archiveData("data-archive2E");
261
262 print "\n\nDo some Tagged data tests:"
263
264 print "\nCreate a Tagged data:"
265 tagData=Data([ [1.0,1.1],[2.0,2.1] ],Function(msh))
266 tagData.setTaggedValue(1,[[3.0,3.1],[4.0,4.1]])
267 tagData.setTaggedValue(2,[[5.0,5.1],[6.0,6.1]])
268 print tagData
269 print "\nSlice it [0:1,:]"
270 print tagData[0:1]
271 print "\nSlice it [0,0:1]"
272 print tagData[0]
273 print "\nSlice it [1:2]"
274 print tagData[1:2]
275 print "\nSlice it [1,1]"
276 print tagData[1,1]
277
278 print "\nSlice to it [1,1]"
279 tagData[0,0] = tagData[1,1]
280 print tagData
281
282 print "\nSlice to it [1:2,0:1]"
283 tagData[1:2,0:1] = tagData[0,1]
284 print tagData
285
286 print "\nSlice to it [0,1]"
287 tagData[0,1] = 9.0
288 print tagData
289
290 sys.exit(0)
291 # end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26