/[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 315 - (show annotations)
Tue Dec 6 01:13:57 2005 UTC (13 years, 11 months ago) by jgs
File MIME type: text/x-python
File size: 5804 byte(s)
change method calls to match new names for Data methods

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26