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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 570 - (hide annotations)
Tue Feb 28 06:51:25 2006 UTC (16 years, 9 months ago) by jgs
File MIME type: text/x-python
File size: 5805 byte(s)
extend these tests to test DataTagged objecrs also
1 jgs 117 import sys
2     import unittest
3     import os
4    
5 jgs 149 from esys.escript import *
6 jgs 153 from esys import bruce
7 jgs 117
8     import numarray
9 jgs 126 from numarray import array,Float64,ones,greater
10 jgs 117
11     """
12    
13     Miscellaneous escript/Data tests.
14    
15     Version $Id$
16    
17     """
18    
19     arglist = [ \
20 jgs 126 3.0, \
21 jgs 117 [3,4], \
22     [[1,2],[3,4]], \
23     [[15,8],[12,8]], \
24 jgs 126 [[[15,8],[12,8]],[[-9,9],[13,8]]] \
25 jgs 117 ]
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 jgs 153 msh=bruce.Rectangle()
82 jgs 117
83 jgs 121 for wh in [ContinuousFunction(msh),Function(msh)]:
84 jgs 117
85 jgs 147 print wh
86 jgs 117
87 jgs 121 for ex in ["Constant","Expanded"]:
88 jgs 117
89 jgs 121 for a in arglist:
90 jgs 117
91 jgs 121 print "\n", ex, a, "==>"
92 jgs 117
93 jgs 121 arg=prepareArg(a,ex,wh)
94 jgs 117
95 jgs 126 print "\n\nTests of copy method:"
96 jgs 117
97 jgs 126 arg_copy = Data()
98     arg_copy.copy(arg)
99     print arg
100     print arg_copy
101    
102 jgs 123 print "\n\nTests of conversion to numarray:"
103    
104 jgs 126 narray1 = arg.convertToNumArray()
105     narray2 = arg.convertToNumArrayFromSampleNo(0)
106     narray3 = arg.convertToNumArrayFromDPNo(0,0)
107    
108 jgs 121 print "arg.convertToNumArray()"
109 jgs 126 print narray1
110 jgs 117
111 jgs 121 print "arg.convertToNumArrayFromSampleNo(0)"
112 jgs 126 print narray2
113 jgs 117
114 jgs 121 print "arg.convertToNumArrayFromDPNo(0,0)"
115 jgs 126 print narray3
116 jgs 121
117 jgs 149 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 jgs 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 jgs 123 print "\n\nTests of misc python functions:"
136 jgs 121
137 jgs 149 print "\nmindp:"
138     print arg.mindp()
139    
140 jgs 315 #print "\nabs:"
141     #print arg._abs()
142 jgs 121
143     print "\nmaxval:"
144 jgs 314 print arg._maxval()
145 jgs 121
146     print "\nminval:"
147 jgs 314 print arg._minval()
148 jgs 121
149 jgs 314 #print "\nlength"
150     #print arg.length()
151 jgs 121
152 jgs 123 print "\ntrace"
153 jgs 314 print arg._trace()
154 jgs 123
155 jgs 121 print "\nsign"
156 jgs 314 print arg._sign()
157 jgs 121
158     print "\nexp"
159 jgs 314 print arg._exp()
160 jgs 121
161     print "\nsqrt"
162 jgs 314 print arg._sqrt()
163 jgs 121
164 jgs 315 #print "\nneg"
165     #print arg._neg()
166 jgs 121
167 jgs 315 #print "\npos"
168     #print arg._pos()
169 jgs 121
170     print "\nsin"
171 jgs 314 print arg._sin()
172 jgs 121
173     print "\ncos"
174 jgs 314 print arg._cos()
175 jgs 121
176     print "\ntan"
177 jgs 314 print arg._tan()
178 jgs 121
179 jgs 150 print "\nasin"
180 jgs 314 print arg._asin()
181 jgs 150
182     print "\nacos"
183 jgs 314 print arg._acos()
184 jgs 150
185     print "\natan"
186 jgs 314 print arg._atan()
187 jgs 150
188     print "\nsinh"
189 jgs 314 print arg._sinh()
190 jgs 150
191     print "\ncosh"
192 jgs 314 print arg._cosh()
193 jgs 150
194     print "\ntanh"
195 jgs 314 print arg._tanh()
196 jgs 150
197     print "\nasinh"
198 jgs 314 print arg._asinh()
199 jgs 150
200     print "\nacosh"
201 jgs 314 print arg._acosh()
202 jgs 150
203     print "\natanh"
204 jgs 314 print arg._atanh()
205 jgs 150
206 jgs 121 print "\nlog"
207 jgs 314 print arg._log()
208 jgs 121
209 jgs 314 #print "\nln"
210     #print arg.ln()
211 jgs 121
212 jgs 123 print "\nLsup"
213 jgs 314 print arg._Lsup()
214 jgs 119
215 jgs 123 print "\nsup"
216 jgs 314 print arg._sup()
217 jgs 123
218     print "\ninf"
219 jgs 314 print arg._inf()
220 jgs 123
221 jgs 570
222 jgs 123 print "\n\nTests of archiveData and extractData:"
223    
224 jgs 119 print "\nDataExpanded:"
225 jgs 123 archDataE=Data([[1.00001],[2.00001]],Function(msh),True)
226 jgs 119 archDataE.archiveData("data-archiveE")
227     exDataE=Data()
228     exDataE.extractData("data-archiveE",Function(msh))
229     exDataE.archiveData("data-archive2E");
230    
231     print "\nDataTagged:"
232 jgs 123 archDataT=Data([[1.00001],[2.00001]],Function(msh))
233 jgs 119 archDataT.tag()
234     archDataT.archiveData("data-archiveT")
235     exDataT=Data()
236     exDataT.extractData("data-archiveT",Function(msh))
237     exDataT.archiveData("data-archive2T");
238    
239     print "\nDataConstant:"
240 jgs 123 archDataC=Data([1.00001], Function(msh))
241 jgs 119 archDataC.archiveData("data-archiveC")
242     exDataC=Data()
243     exDataC.extractData("data-archiveC",Function(msh))
244     exDataC.archiveData("data-archive2C");
245    
246     print "\nDataEmpty:"
247     archDataM=Data()
248     archDataM.archiveData("data-archiveE")
249     exDataM=Data()
250     exDataM.extractData("data-archiveE",FunctionSpace())
251     exDataM.archiveData("data-archive2E");
252    
253 jgs 123 print "\n\nDo some Tagged data tests:"
254    
255 jgs 121 print "\nCreate a Tagged data:"
256     tagData=Data([ [1.0,1.1],[2.0,2.1] ],Function(msh))
257     tagData.setTaggedValue(1,[[3.0,3.1],[4.0,4.1]])
258     tagData.setTaggedValue(2,[[5.0,5.1],[6.0,6.1]])
259     print tagData
260     print "\nSlice it [0:1,:]"
261     print tagData[0:1]
262     print "\nSlice it [0,0:1]"
263     print tagData[0]
264     print "\nSlice it [1:2]"
265     print tagData[1:2]
266     print "\nSlice it [1,1]"
267     print tagData[1,1]
268    
269     print "\nSlice to it [1,1]"
270     tagData[0,0] = tagData[1,1]
271     print tagData
272    
273     print "\nSlice to it [1:2,0:1]"
274     tagData[1:2,0:1] = tagData[0,1]
275     print tagData
276    
277     print "\nSlice to it [0,1]"
278     tagData[0,1] = 9.0
279     print tagData
280    
281 jgs 147 sys.exit(0)
282 jgs 117 # end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26