/[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 121 - (show annotations)
Fri May 6 04:26:16 2005 UTC (14 years, 4 months ago) by jgs
File MIME type: text/x-python
File size: 4746 byte(s)
Merge of development branch back to main trunk on 2005-05-06

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
10 """
11
12 Miscellaneous escript/Data tests.
13
14 Version $Id$
15
16 """
17
18 from numarray import array,Float64,ones,greater
19
20
21 # list of arguments: a list item has the form [a0,a1,a2]
22 # what a0 is the default value and a1 is used for tag Tag1
23 # and a2 for tag2. a0,a1,a2 are converted into numarrays.
24
25 arglist = [ \
26 [3,4], \
27 [[1,2],[3,4]], \
28 [[15,8],[12,8]], \
29 [[[15,8],[12,8]],[[-9,9],[13,8]]], \
30 3.0 \
31 ]
32
33 def turnToArray(val):
34 out=array(val,Float64)
35 return out
36
37 def prepareArg(val,ex,wh):
38 if ex=="Expanded":
39 exx=True
40 else:
41 exx=False
42 out=Data(val,what=wh,expand=exx)
43 return out
44
45 def checkResult(text,res,val0,val1,val2,wh):
46 ref=Data(val0,what=wh,expand=False)
47 ref.setTaggedValue(Tag1,val1)
48 ref.setTaggedValue(Tag2,val2)
49 norm=Lsup(ref)+tol
50 error=Lsup(ref-res)/norm
51 print "@@ %s, shape %s: error = %e"%(text,ref.getShape(),error)
52 if error>tol:
53 #raise SystemError,"@@ %s at %s: error is too large"%(text,wh)
54 print "**** %s : error is too large"%(text)
55
56 def getRank(arg):
57 if isinstance(arg,Data):
58 return arg.getRank()
59 else:
60 g=array(arg)
61 if g.rank==0:
62 return 1
63 else:
64 return g.rank
65
66 def isScalar(arg):
67 if isinstance(arg,Data):
68 if arg.getRank()==1 and arg.getShape()[0]==1:
69 return not None
70 else:
71 return None
72 else:
73 g=array(arg)
74 if g.rank==0:
75 return not None
76 else:
77 if g.rank==1 and g.shape[0]==1:
78 return not None
79 else:
80 return None
81
82 #
83 # ==============================================================
84
85 print "\n\n"
86
87 msh=finley.Rectangle(1,1,1)
88
89 for wh in [ContinuousFunction(msh),Function(msh)]:
90
91 print wh.toString()
92
93 for ex in ["Constant","Expanded"]:
94
95 for a in arglist:
96
97 print "\n", ex, a, "==>"
98
99 arg=prepareArg(a,ex,wh)
100
101 #print "toString", arg.toString()
102 #print "Rank:", getRank(arg)
103 #print "Scalar:", isScalar(arg)
104
105 narry1 = arg.convertToNumArray()
106 narry2 = arg.convertToNumArrayFromSampleNo(0)
107 narry3 = arg.convertToNumArrayFromDPNo(0,0)
108
109 print "arg.convertToNumArray()"
110 print narry1
111
112 print "arg.convertToNumArrayFromSampleNo(0)"
113 print narry2
114
115 print "arg.convertToNumArrayFromDPNo(0,0)"
116 print narry3
117
118 print "\n\nTests of misc python functions"
119
120 print "\nabs:"
121 print arg.abs()
122
123 print "\nmaxval:"
124 print arg.maxval()
125
126 print "\nminval:"
127 print arg.minval()
128
129 print "\nmindp:"
130 print arg.mindp()
131
132 print "\nlength"
133 print arg.length()
134
135 print "\nsign"
136 print arg.sign()
137
138 print "\ntrace"
139 print arg.trace()
140
141 print "\nexp"
142 print arg.exp()
143
144 print "\nsqrt"
145 print arg.sqrt()
146
147 print "\nneg"
148 print arg.neg()
149
150 print "\npos"
151 print arg.pos()
152
153 print "\nsin"
154 print arg.sin()
155
156 print "\ncos"
157 print arg.cos()
158
159 print "\ntan"
160 print arg.tan()
161
162 print "\nlog"
163 print arg.log()
164
165 print "\nln"
166 print arg.ln()
167
168 print "\n\nTests of archiveData and extractData"
169
170 print "\nDataExpanded:"
171 archDataE=Data([[1.0],[2.0]],Function(msh),True)
172 archDataE.archiveData("data-archiveE")
173 exDataE=Data()
174 exDataE.extractData("data-archiveE",Function(msh))
175 exDataE.archiveData("data-archive2E");
176
177 print "\nDataTagged:"
178 archDataT=Data([[1.0],[2.0]],Function(msh))
179 archDataT.tag()
180 archDataT.archiveData("data-archiveT")
181 exDataT=Data()
182 exDataT.extractData("data-archiveT",Function(msh))
183 exDataT.archiveData("data-archive2T");
184
185 print "\nDataConstant:"
186 archDataC=Data([1.0], Function(msh))
187 archDataC.archiveData("data-archiveC")
188 exDataC=Data()
189 exDataC.extractData("data-archiveC",Function(msh))
190 exDataC.archiveData("data-archive2C");
191
192 print "\nDataEmpty:"
193 archDataM=Data()
194 archDataM.archiveData("data-archiveE")
195 exDataM=Data()
196 exDataM.extractData("data-archiveE",FunctionSpace())
197 exDataM.archiveData("data-archive2E");
198
199 print "\nDo some Tagged data tests"
200 print "\nCreate a Tagged data:"
201 tagData=Data([ [1.0,1.1],[2.0,2.1] ],Function(msh))
202 tagData.setTaggedValue(1,[[3.0,3.1],[4.0,4.1]])
203 tagData.setTaggedValue(2,[[5.0,5.1],[6.0,6.1]])
204 print tagData
205 print "\nSlice it [0:1,:]"
206 print tagData[0:1]
207 print "\nSlice it [0,0:1]"
208 print tagData[0]
209 print "\nSlice it [1:2]"
210 print tagData[1:2]
211 print "\nSlice it [1,1]"
212 print tagData[1,1]
213
214 print "\nSlice to it [1,1]"
215 tagData[0,0] = tagData[1,1]
216 print tagData
217
218 print "\nSlice to it [1:2,0:1]"
219 tagData[1:2,0:1] = tagData[0,1]
220 print tagData
221
222 print "\nSlice to it [0,1]"
223 tagData[0,1] = 9.0
224 print tagData
225
226 # end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26