/[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 155 - (show annotations)
Wed Nov 9 02:02:19 2005 UTC (13 years, 11 months ago) by jgs
File MIME type: text/x-python
File size: 5814 byte(s)
move all directories from trunk/esys2 into trunk and remove esys2

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 "\nLinf"
216 print arg.Linf()
217
218 print "\nsup"
219 print arg.sup()
220
221 print "\ninf"
222 print arg.inf()
223
224 print "\n\nTests of archiveData and extractData:"
225
226 print "\nDataExpanded:"
227 archDataE=Data([[1.00001],[2.00001]],Function(msh),True)
228 archDataE.archiveData("data-archiveE")
229 exDataE=Data()
230 exDataE.extractData("data-archiveE",Function(msh))
231 exDataE.archiveData("data-archive2E");
232
233 print "\nDataTagged:"
234 archDataT=Data([[1.00001],[2.00001]],Function(msh))
235 archDataT.tag()
236 archDataT.archiveData("data-archiveT")
237 exDataT=Data()
238 exDataT.extractData("data-archiveT",Function(msh))
239 exDataT.archiveData("data-archive2T");
240
241 print "\nDataConstant:"
242 archDataC=Data([1.00001], Function(msh))
243 archDataC.archiveData("data-archiveC")
244 exDataC=Data()
245 exDataC.extractData("data-archiveC",Function(msh))
246 exDataC.archiveData("data-archive2C");
247
248 print "\nDataEmpty:"
249 archDataM=Data()
250 archDataM.archiveData("data-archiveE")
251 exDataM=Data()
252 exDataM.extractData("data-archiveE",FunctionSpace())
253 exDataM.archiveData("data-archive2E");
254
255 print "\n\nDo some Tagged data tests:"
256
257 print "\nCreate a Tagged data:"
258 tagData=Data([ [1.0,1.1],[2.0,2.1] ],Function(msh))
259 tagData.setTaggedValue(1,[[3.0,3.1],[4.0,4.1]])
260 tagData.setTaggedValue(2,[[5.0,5.1],[6.0,6.1]])
261 print tagData
262 print "\nSlice it [0:1,:]"
263 print tagData[0:1]
264 print "\nSlice it [0,0:1]"
265 print tagData[0]
266 print "\nSlice it [1:2]"
267 print tagData[1:2]
268 print "\nSlice it [1,1]"
269 print tagData[1,1]
270
271 print "\nSlice to it [1,1]"
272 tagData[0,0] = tagData[1,1]
273 print tagData
274
275 print "\nSlice to it [1:2,0:1]"
276 tagData[1:2,0:1] = tagData[0,1]
277 print tagData
278
279 print "\nSlice to it [0,1]"
280 tagData[0,1] = 9.0
281 print tagData
282
283 sys.exit(0)
284 # end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26