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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (show annotations)
Thu Sep 1 03:31:39 2005 UTC (14 years, 2 months ago) by jgs
File MIME type: text/x-python
File size: 5410 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-01

1 import sys
2 import unittest
3 import os
4
5 from esys.escript import *
6 from esys import finley
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=finley.Rectangle(1,1,1)
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 "\nlog"
180 print arg.log()
181
182 print "\nln"
183 print arg.ln()
184
185 print "\nLsup"
186 print arg.Lsup()
187
188 print "\nLinf"
189 print arg.Linf()
190
191 print "\nsup"
192 print arg.sup()
193
194 print "\ninf"
195 print arg.inf()
196
197 print "\n\nTests of archiveData and extractData:"
198
199 print "\nDataExpanded:"
200 archDataE=Data([[1.00001],[2.00001]],Function(msh),True)
201 archDataE.archiveData("data-archiveE")
202 exDataE=Data()
203 exDataE.extractData("data-archiveE",Function(msh))
204 exDataE.archiveData("data-archive2E");
205
206 print "\nDataTagged:"
207 archDataT=Data([[1.00001],[2.00001]],Function(msh))
208 archDataT.tag()
209 archDataT.archiveData("data-archiveT")
210 exDataT=Data()
211 exDataT.extractData("data-archiveT",Function(msh))
212 exDataT.archiveData("data-archive2T");
213
214 print "\nDataConstant:"
215 archDataC=Data([1.00001], Function(msh))
216 archDataC.archiveData("data-archiveC")
217 exDataC=Data()
218 exDataC.extractData("data-archiveC",Function(msh))
219 exDataC.archiveData("data-archive2C");
220
221 print "\nDataEmpty:"
222 archDataM=Data()
223 archDataM.archiveData("data-archiveE")
224 exDataM=Data()
225 exDataM.extractData("data-archiveE",FunctionSpace())
226 exDataM.archiveData("data-archive2E");
227
228 print "\n\nDo some Tagged data tests:"
229
230 print "\nCreate a Tagged data:"
231 tagData=Data([ [1.0,1.1],[2.0,2.1] ],Function(msh))
232 tagData.setTaggedValue(1,[[3.0,3.1],[4.0,4.1]])
233 tagData.setTaggedValue(2,[[5.0,5.1],[6.0,6.1]])
234 print tagData
235 print "\nSlice it [0:1,:]"
236 print tagData[0:1]
237 print "\nSlice it [0,0:1]"
238 print tagData[0]
239 print "\nSlice it [1:2]"
240 print tagData[1:2]
241 print "\nSlice it [1,1]"
242 print tagData[1,1]
243
244 print "\nSlice to it [1,1]"
245 tagData[0,0] = tagData[1,1]
246 print tagData
247
248 print "\nSlice to it [1:2,0:1]"
249 tagData[1:2,0:1] = tagData[0,1]
250 print tagData
251
252 print "\nSlice to it [0,1]"
253 tagData[0,1] = 9.0
254 print tagData
255
256 sys.exit(0)
257 # end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26