/[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 141 - (show annotations)
Mon Jul 25 05:15:41 2005 UTC (13 years, 8 months ago) by jgs
File MIME type: text/x-python
File size: 5130 byte(s)
fixed to work with new python source/install directory structure

1 import sys
2 import unittest
3 import os
4
5 from escript.escript import *
6 from finley 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.toString()
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 == "Expanded"):
118 print "\n\nTests of get/setRefValue functions:"
119 result_array = numarray.array(a)
120 print result_array
121 result_array+=1
122 arg.setRefValue(0,result_array)
123 arg.getRefValue(0,result_array)
124 print result_array
125
126 print "\n\nTests of misc python functions:"
127
128 print "\nabs:"
129 print arg.abs()
130
131 print "\nmaxval:"
132 print arg.maxval()
133
134 print "\nminval:"
135 print arg.minval()
136
137 print "\nmindp:"
138 print arg.mindp()
139
140 print "\nlength"
141 print arg.length()
142
143 print "\ntrace"
144 print arg.trace()
145
146 print "\nsign"
147 print arg.sign()
148
149 print "\nexp"
150 print arg.exp()
151
152 print "\nsqrt"
153 print arg.sqrt()
154
155 print "\nneg"
156 print arg.neg()
157
158 print "\npos"
159 print arg.pos()
160
161 print "\nsin"
162 print arg.sin()
163
164 print "\ncos"
165 print arg.cos()
166
167 print "\ntan"
168 print arg.tan()
169
170 print "\nlog"
171 print arg.log()
172
173 print "\nln"
174 print arg.ln()
175
176 print "\nLsup"
177 print arg.Lsup()
178
179 print "\nLinf"
180 print arg.Linf()
181
182 print "\nsup"
183 print arg.sup()
184
185 print "\ninf"
186 print arg.inf()
187
188 print "\n\nTests of archiveData and extractData:"
189
190 print "\nDataExpanded:"
191 archDataE=Data([[1.00001],[2.00001]],Function(msh),True)
192 archDataE.archiveData("data-archiveE")
193 exDataE=Data()
194 exDataE.extractData("data-archiveE",Function(msh))
195 exDataE.archiveData("data-archive2E");
196
197 print "\nDataTagged:"
198 archDataT=Data([[1.00001],[2.00001]],Function(msh))
199 archDataT.tag()
200 archDataT.archiveData("data-archiveT")
201 exDataT=Data()
202 exDataT.extractData("data-archiveT",Function(msh))
203 exDataT.archiveData("data-archive2T");
204
205 print "\nDataConstant:"
206 archDataC=Data([1.00001], Function(msh))
207 archDataC.archiveData("data-archiveC")
208 exDataC=Data()
209 exDataC.extractData("data-archiveC",Function(msh))
210 exDataC.archiveData("data-archive2C");
211
212 print "\nDataEmpty:"
213 archDataM=Data()
214 archDataM.archiveData("data-archiveE")
215 exDataM=Data()
216 exDataM.extractData("data-archiveE",FunctionSpace())
217 exDataM.archiveData("data-archive2E");
218
219 print "\n\nDo some Tagged data tests:"
220
221 print "\nCreate a Tagged data:"
222 tagData=Data([ [1.0,1.1],[2.0,2.1] ],Function(msh))
223 tagData.setTaggedValue(1,[[3.0,3.1],[4.0,4.1]])
224 tagData.setTaggedValue(2,[[5.0,5.1],[6.0,6.1]])
225 print tagData
226 print "\nSlice it [0:1,:]"
227 print tagData[0:1]
228 print "\nSlice it [0,0:1]"
229 print tagData[0]
230 print "\nSlice it [1:2]"
231 print tagData[1:2]
232 print "\nSlice it [1,1]"
233 print tagData[1,1]
234
235 print "\nSlice to it [1,1]"
236 tagData[0,0] = tagData[1,1]
237 print tagData
238
239 print "\nSlice to it [1:2,0:1]"
240 tagData[1:2,0:1] = tagData[0,1]
241 print tagData
242
243 print "\nSlice to it [0,1]"
244 tagData[0,1] = 9.0
245 print tagData
246
247 # end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26