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

Contents of /trunk/escript/test/python/test_util_base.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3975 - (show annotations)
Thu Sep 20 01:54:06 2012 UTC (7 years ago) by caltinay
File MIME type: text/x-python
File size: 38979 byte(s)
Merged symbolic branch into trunk. Curious what daniel and spartacus have to
say...

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2012 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2012 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 """
23 basic tests for util.py
24
25 :remark: use see `test_util`
26
27 :var __author__: name of author
28 :var __copyright__: copyrights
29 :var __license__: licence agreement
30 :var __url__: url entry point on documentation
31 :var __version__: version
32 :var __date__: date of the version
33 """
34
35 __author__="Lutz Gross, l.gross@uq.edu.au"
36
37 import unittest
38 import numpy
39 import os
40 from esys.escript import *
41
42 try:
43 ESCRIPT_WORKDIR=os.environ['ESCRIPT_WORKDIR']
44 except KeyError:
45 ESCRIPT_WORKDIR='.'
46
47 class Test_util_base(unittest.TestCase):
48 """
49 basic tests on util.py
50 """
51 RES_TOL=1.e-7 # RES_TOLerance to compare results
52 DIFF_TOL=1.e-7 # RES_TOLerance to derivatices
53 #=========================================================
54 # File writer
55 #=========================================================
56 def __checkContent(self,fn,ref_cont):
57 cont=open(fn,'r').readlines()
58 self.assertTrue(len(cont)==len(ref_cont),"wrong number of records")
59 for i in range(len(cont)):
60 self.assertTrue(cont[i].strip()==ref_cont[i],"wrong records %s"%i)
61 def test_FileWriter_W(self):
62 fn=os.path.join(ESCRIPT_WORKDIR, "filewriter_w.txt")
63 self.assertRaises(IOError,FileWriter,fn="",append=False)
64 f=FileWriter(fn,append=False)
65 self.assertTrue(f.name==fn, "wrong file name.")
66 self.assertTrue(f.mode=='w', "wrong mode")
67 self.assertTrue(f.newlines==os.linesep, "wrong line seps")
68 self.assertTrue(not f.closed,"file shuold not be closed.")
69 f.write("line1"+f.newlines)
70 f.flush()
71 self.__checkContent(fn,["line1"])
72 f.writelines(["line2"+f.newlines, "line3"+f.newlines])
73 f.close()
74 self.assertTrue(f.closed,"file shuold be closed.")
75 self.__checkContent(fn,["line1", "line2", "line3"])
76
77 def test_FileWriter_A(self):
78 fn=os.path.join(ESCRIPT_WORKDIR, "filewriter_a.txt")
79 if getMPIRankWorld()==0: open(fn,'w').write("line1"+os.linesep)
80 self.assertRaises(IOError,FileWriter,fn="",append=True)
81 f=FileWriter(fn,append=True)
82 self.assertTrue(f.name==fn, "wrong file name.")
83 self.assertTrue(f.mode=='a', "wrong mode")
84 self.assertTrue(f.newlines==os.linesep, "wrong line seps")
85 self.assertTrue(not f.closed,"file shuold not be closed.")
86 f.write("line2"+f.newlines)
87 f.flush()
88 self.__checkContent(fn,["line1", "line2"])
89 f.writelines(["line3"+f.newlines, "line4"+f.newlines])
90 f.close()
91 self.assertTrue(f.closed,"file shuold be closed.")
92 self.__checkContent(fn,["line1", "line2", "line3", "line4"])
93
94 def test_FileWriter_A_loc(self):
95 fn=os.path.join(ESCRIPT_WORKDIR, "filewriter_a_loc.txt")
96 if getMPIRankWorld()>0:
97 fn2=fn+".%s"%getMPIRankWorld()
98 else:
99 fn2=fn
100 open(fn2,'w').write("line1"+os.linesep)
101 self.assertRaises(IOError,FileWriter,fn="",append=True, createLocalFiles=True)
102 f=FileWriter(fn,append=True,createLocalFiles=True)
103 self.assertTrue(f.name==fn, "wrong file name.")
104 self.assertTrue(f.mode=='a', "wrong mode")
105 self.assertTrue(f.newlines==os.linesep, "wrong line seps")
106 self.assertTrue(not f.closed,"file shuold not be closed.")
107 f.write("line2"+f.newlines)
108 f.flush()
109 self.__checkContent(fn2,["line1", "line2"])
110 f.writelines(["line3"+f.newlines, "line4"+f.newlines])
111 f.close()
112 self.assertTrue(f.closed,"file shuold be closed.")
113 self.__checkContent(fn2,["line1", "line2", "line3", "line4"])
114
115 def test_FileWriter_W_loc(self):
116 fn=os.path.join(ESCRIPT_WORKDIR, "filewriter_w_loc.txt")
117 if getMPIRankWorld()>0:
118 fn2=fn+".%s"%getMPIRankWorld()
119 else:
120 fn2=fn
121 self.assertRaises(IOError,FileWriter,fn="",append=True, createLocalFiles=True)
122 f=FileWriter(fn,append=False,createLocalFiles=True)
123 self.assertTrue(f.name==fn, "wrong file name.")
124 self.assertTrue(f.mode=='w', "wrong mode")
125 self.assertTrue(f.newlines==os.linesep, "wrong line seps")
126 self.assertTrue(not f.closed,"file shuold not be closed.")
127 f.write("line1"+f.newlines)
128 f.flush()
129 self.__checkContent(fn2,["line1"])
130 f.writelines(["line2"+f.newlines, "line3"+f.newlines])
131 f.close()
132 self.assertTrue(f.closed,"file shuold be closed.")
133 self.__checkContent(fn2,["line1", "line2", "line3"])
134 #=========================================================
135 # constants
136 #=========================================================
137 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
138 def test_kronecker_1(self):
139 val=kronecker(d=1)
140 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
141 self.assertEqual(val[0,0],1.0,"wrong value for (0,0)")
142 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
143 def test_kronecker_2(self):
144 val=kronecker(d=2)
145 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
146 self.assertEqual(val[0,0],1.0,"wrong value for (0,0)")
147 self.assertEqual(val[0,1],0.0,"wrong value for (0,1)")
148 self.assertEqual(val[1,0],0.0,"wrong value for (1,0)")
149 self.assertEqual(val[1,1],1.0,"wrong value for (1,1)")
150 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151 def test_kronecker_3(self):
152 val=kronecker(d=3)
153 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
154 self.assertEqual(val[0,0],1.0,"wrong value for (0,0)")
155 self.assertEqual(val[0,1],0.0,"wrong value for (0,1)")
156 self.assertEqual(val[0,2],0.0,"wrong value for (0,2)")
157 self.assertEqual(val[1,0],0.0,"wrong value for (1,0)")
158 self.assertEqual(val[1,1],1.0,"wrong value for (1,1)")
159 self.assertEqual(val[1,2],0.0,"wrong value for (1,2)")
160 self.assertEqual(val[2,0],0.0,"wrong value for (2,0)")
161 self.assertEqual(val[2,1],0.0,"wrong value for (2,1)")
162 self.assertEqual(val[2,2],1.0,"wrong value for (2,2)")
163 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
164 def test_kronecker_domain(self):
165 val=kronecker(d=self.domain)
166 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
167 self.assertEqual(val.shape,(self.domain.getDim(),self.domain.getDim()),"wrong shape.")
168 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
169 def test_kronecker_functionspace(self):
170 val=kronecker(d=self.functionspace)
171 self.assertTrue(isinstance(val,escript.Data),"wrong type of result.")
172 self.assertEqual(val.getShape(),(self.functionspace.getDim(),self.functionspace.getDim()),"wrong shape.")
173 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
174 def test_identityTensor_1(self):
175 val=identityTensor(d=1)
176 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
177 self.assertEqual(val[0,0],1.0,"wrong value for (0,0)")
178 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
179 def test_identityTensor_2(self):
180 val=identityTensor(d=2)
181 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
182 self.assertEqual(val[0,0],1.0,"wrong value for (0,0)")
183 self.assertEqual(val[0,1],0.0,"wrong value for (0,1)")
184 self.assertEqual(val[1,0],0.0,"wrong value for (1,0)")
185 self.assertEqual(val[1,1],1.0,"wrong value for (1,1)")
186 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
187 def test_identityTensor_3(self):
188 val=identityTensor(d=3)
189 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
190 self.assertEqual(val[0,0],1.0,"wrong value for (0,0)")
191 self.assertEqual(val[0,1],0.0,"wrong value for (0,1)")
192 self.assertEqual(val[0,2],0.0,"wrong value for (0,2)")
193 self.assertEqual(val[1,0],0.0,"wrong value for (1,0)")
194 self.assertEqual(val[1,1],1.0,"wrong value for (1,1)")
195 self.assertEqual(val[1,2],0.0,"wrong value for (1,2)")
196 self.assertEqual(val[2,0],0.0,"wrong value for (2,0)")
197 self.assertEqual(val[2,1],0.0,"wrong value for (2,1)")
198 self.assertEqual(val[2,2],1.0,"wrong value for (2,2)")
199 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
200 def test_identityTensor_domain(self):
201 val=identityTensor(d=self.domain)
202 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
203 self.assertEqual(val.shape,(self.domain.getDim(),self.domain.getDim()),"wrong shape.")
204 if self.domain.getDim()==2:
205 self.assertEqual(val[0,0],1.0,"wrong value for (0,0)")
206 self.assertEqual(val[0,1],0.0,"wrong value for (0,1)")
207 self.assertEqual(val[1,0],0.0,"wrong value for (1,0)")
208 self.assertEqual(val[1,1],1.0,"wrong value for (1,1)")
209 if self.domain.getDim()==3:
210 self.assertEqual(val[0,0],1.0,"wrong value for (0,0)")
211 self.assertEqual(val[0,1],0.0,"wrong value for (0,1)")
212 self.assertEqual(val[0,2],0.0,"wrong value for (0,2)")
213 self.assertEqual(val[1,0],0.0,"wrong value for (1,0)")
214 self.assertEqual(val[1,1],1.0,"wrong value for (1,1)")
215 self.assertEqual(val[1,2],0.0,"wrong value for (1,2)")
216 self.assertEqual(val[2,0],0.0,"wrong value for (2,0)")
217 self.assertEqual(val[2,1],0.0,"wrong value for (2,1)")
218 self.assertEqual(val[2,2],1.0,"wrong value for (2,2)")
219 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
220 def test_identityTensor_functionspace(self):
221 val=identityTensor(d=self.functionspace)
222 self.assertTrue(isinstance(val,escript.Data),"wrong type of result.")
223 self.assertEqual(val.getShape(),(self.functionspace.getDim(),self.functionspace.getDim()),"wrong shape.")
224 if self.domain.getDim()==2:
225 self.assertTrue(Lsup(val[0,0]-1.0)<=self.RES_TOL,"wrong value for (0,0)")
226 self.assertTrue(Lsup(val[0,1]-0.0)<=self.RES_TOL,"wrong value for (0,1)")
227 self.assertTrue(Lsup(val[1,0]-0.0)<=self.RES_TOL,"wrong value for (1,0)")
228 self.assertTrue(Lsup(val[1,1]-1.0)<=self.RES_TOL,"wrong value for (1,1)")
229 if self.domain.getDim()==3:
230 self.assertTrue(Lsup(val[0,0]-1.0)<=self.RES_TOL,"wrong value for (0,0)")
231 self.assertTrue(Lsup(val[0,1]-0.0)<=self.RES_TOL,"wrong value for (0,1)")
232 self.assertTrue(Lsup(val[0,2]-0.0)<=self.RES_TOL,"wrong value for (0,2)")
233 self.assertTrue(Lsup(val[1,0]-0.0)<=self.RES_TOL,"wrong value for (1,0)")
234 self.assertTrue(Lsup(val[1,1]-1.0)<=self.RES_TOL,"wrong value for (1,1)")
235 self.assertTrue(Lsup(val[1,2]-0.0)<=self.RES_TOL,"wrong value for (1,2)")
236 self.assertTrue(Lsup(val[2,0]-0.0)<=self.RES_TOL,"wrong value for (2,0)")
237 self.assertTrue(Lsup(val[2,1]-0.0)<=self.RES_TOL,"wrong value for (2,1)")
238 self.assertTrue(Lsup(val[2,2]-1.0)<=self.RES_TOL,"wrong value for (2,2)")
239 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
240 def test_identityTensor4_1(self):
241 val=identityTensor4(d=1)
242 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
243 self.assertEqual(val[0,0,0,0],1.0,"wrong value for (0,0,0,0)")
244 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
245 def test_identityTensor4_2(self):
246 val=identityTensor4(d=2)
247 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
248 self.assertEqual(val[0,0,0,0],1.0,"wrong value for (0,0,0,0)")
249 self.assertEqual(val[0,0,0,1],0.0,"wrong value for (0,0,0,1)")
250 self.assertEqual(val[0,0,1,0],0.0,"wrong value for (0,0,1,0)")
251 self.assertEqual(val[0,0,1,1],0.0,"wrong value for (0,0,1,1)")
252 self.assertEqual(val[0,1,0,0],0.0,"wrong value for (0,1,0,0)")
253 self.assertEqual(val[0,1,0,1],1.0,"wrong value for (0,1,0,1)")
254 self.assertEqual(val[0,1,1,0],0.0,"wrong value for (0,1,1,0)")
255 self.assertEqual(val[0,1,1,1],0.0,"wrong value for (0,1,1,1)")
256 self.assertEqual(val[1,0,0,0],0.0,"wrong value for (1,0,0,0)")
257 self.assertEqual(val[1,0,0,1],0.0,"wrong value for (1,0,0,1)")
258 self.assertEqual(val[1,0,1,0],1.0,"wrong value for (1,0,1,0)")
259 self.assertEqual(val[1,0,1,1],0.0,"wrong value for (1,0,1,1)")
260 self.assertEqual(val[1,1,0,0],0.0,"wrong value for (1,1,0,0)")
261 self.assertEqual(val[1,1,0,1],0.0,"wrong value for (1,1,0,1)")
262 self.assertEqual(val[1,1,1,0],0.0,"wrong value for (1,1,1,0)")
263 self.assertEqual(val[1,1,1,1],1.0,"wrong value for (1,1,1,1)")
264 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
265 def test_identityTensor4_3(self):
266 val=identityTensor4(d=3)
267 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
268 self.assertEqual(val[0,0,0,0],1.0,"wrong value for (0,0,0,0)")
269 self.assertEqual(val[0,0,0,1],0.0,"wrong value for (0,0,0,1)")
270 self.assertEqual(val[0,0,0,2],0.0,"wrong value for (0,0,0,2)")
271 self.assertEqual(val[0,0,1,0],0.0,"wrong value for (0,0,1,0)")
272 self.assertEqual(val[0,0,1,1],0.0,"wrong value for (0,0,1,1)")
273 self.assertEqual(val[0,0,1,2],0.0,"wrong value for (0,0,1,2)")
274 self.assertEqual(val[0,0,2,0],0.0,"wrong value for (0,0,2,0)")
275 self.assertEqual(val[0,0,2,1],0.0,"wrong value for (0,0,2,1)")
276 self.assertEqual(val[0,0,2,2],0.0,"wrong value for (0,0,2,2)")
277 self.assertEqual(val[0,1,0,0],0.0,"wrong value for (0,1,0,0)")
278 self.assertEqual(val[0,1,0,1],1.0,"wrong value for (0,1,0,1)")
279 self.assertEqual(val[0,1,0,2],0.0,"wrong value for (0,1,0,2)")
280 self.assertEqual(val[0,1,1,0],0.0,"wrong value for (0,1,1,0)")
281 self.assertEqual(val[0,1,1,1],0.0,"wrong value for (0,1,1,1)")
282 self.assertEqual(val[0,1,1,2],0.0,"wrong value for (0,1,1,2)")
283 self.assertEqual(val[0,1,2,0],0.0,"wrong value for (0,1,2,0)")
284 self.assertEqual(val[0,1,2,1],0.0,"wrong value for (0,1,2,1)")
285 self.assertEqual(val[0,1,2,2],0.0,"wrong value for (0,1,2,2)")
286 self.assertEqual(val[0,2,0,0],0.0,"wrong value for (0,2,0,0)")
287 self.assertEqual(val[0,2,0,1],0.0,"wrong value for (0,2,0,1)")
288 self.assertEqual(val[0,2,0,2],1.0,"wrong value for (0,2,0,2)")
289 self.assertEqual(val[0,2,1,0],0.0,"wrong value for (0,2,1,0)")
290 self.assertEqual(val[0,2,1,1],0.0,"wrong value for (0,2,1,1)")
291 self.assertEqual(val[0,2,1,2],0.0,"wrong value for (0,2,1,2)")
292 self.assertEqual(val[0,2,2,0],0.0,"wrong value for (0,2,2,0)")
293 self.assertEqual(val[0,2,2,1],0.0,"wrong value for (0,2,2,1)")
294 self.assertEqual(val[0,2,2,2],0.0,"wrong value for (0,2,2,2)")
295 self.assertEqual(val[1,0,0,0],0.0,"wrong value for (1,0,0,0)")
296 self.assertEqual(val[1,0,0,1],0.0,"wrong value for (1,0,0,1)")
297 self.assertEqual(val[1,0,0,2],0.0,"wrong value for (1,0,0,2)")
298 self.assertEqual(val[1,0,1,0],1.0,"wrong value for (1,0,1,0)")
299 self.assertEqual(val[1,0,1,1],0.0,"wrong value for (1,0,1,1)")
300 self.assertEqual(val[1,0,1,2],0.0,"wrong value for (1,0,1,2)")
301 self.assertEqual(val[1,0,2,0],0.0,"wrong value for (1,0,2,0)")
302 self.assertEqual(val[1,0,2,1],0.0,"wrong value for (1,0,2,1)")
303 self.assertEqual(val[1,0,2,2],0.0,"wrong value for (1,0,2,2)")
304 self.assertEqual(val[1,1,0,0],0.0,"wrong value for (1,1,0,0)")
305 self.assertEqual(val[1,1,0,1],0.0,"wrong value for (1,1,0,1)")
306 self.assertEqual(val[1,1,0,2],0.0,"wrong value for (1,1,0,2)")
307 self.assertEqual(val[1,1,1,0],0.0,"wrong value for (1,1,1,0)")
308 self.assertEqual(val[1,1,1,1],1.0,"wrong value for (1,1,1,1)")
309 self.assertEqual(val[1,1,1,2],0.0,"wrong value for (1,1,1,2)")
310 self.assertEqual(val[1,1,2,0],0.0,"wrong value for (1,1,2,0)")
311 self.assertEqual(val[1,1,2,1],0.0,"wrong value for (1,1,2,1)")
312 self.assertEqual(val[1,1,2,2],0.0,"wrong value for (1,1,2,2)")
313 self.assertEqual(val[1,2,0,0],0.0,"wrong value for (1,2,0,0)")
314 self.assertEqual(val[1,2,0,1],0.0,"wrong value for (1,2,0,1)")
315 self.assertEqual(val[1,2,0,2],0.0,"wrong value for (1,2,0,2)")
316 self.assertEqual(val[1,2,1,0],0.0,"wrong value for (1,2,1,0)")
317 self.assertEqual(val[1,2,1,1],0.0,"wrong value for (1,2,1,1)")
318 self.assertEqual(val[1,2,1,2],1.0,"wrong value for (1,2,1,2)")
319 self.assertEqual(val[1,2,2,0],0.0,"wrong value for (1,2,2,0)")
320 self.assertEqual(val[1,2,2,1],0.0,"wrong value for (1,2,2,1)")
321 self.assertEqual(val[1,2,2,2],0.0,"wrong value for (1,2,2,2)")
322 self.assertEqual(val[2,0,0,0],0.0,"wrong value for (2,0,0,0)")
323 self.assertEqual(val[2,0,0,1],0.0,"wrong value for (2,0,0,1)")
324 self.assertEqual(val[2,0,0,2],0.0,"wrong value for (2,0,0,2)")
325 self.assertEqual(val[2,0,1,0],0.0,"wrong value for (2,0,1,0)")
326 self.assertEqual(val[2,0,1,1],0.0,"wrong value for (2,0,1,1)")
327 self.assertEqual(val[2,0,1,2],0.0,"wrong value for (2,0,1,2)")
328 self.assertEqual(val[2,0,2,0],1.0,"wrong value for (2,0,2,0)")
329 self.assertEqual(val[2,0,2,1],0.0,"wrong value for (2,0,2,1)")
330 self.assertEqual(val[2,0,2,2],0.0,"wrong value for (2,0,2,2)")
331 self.assertEqual(val[2,1,0,0],0.0,"wrong value for (2,1,0,0)")
332 self.assertEqual(val[2,1,0,1],0.0,"wrong value for (2,1,0,1)")
333 self.assertEqual(val[2,1,0,2],0.0,"wrong value for (2,1,0,2)")
334 self.assertEqual(val[2,1,1,0],0.0,"wrong value for (2,1,1,0)")
335 self.assertEqual(val[2,1,1,1],0.0,"wrong value for (2,1,1,1)")
336 self.assertEqual(val[2,1,1,2],0.0,"wrong value for (2,1,1,2)")
337 self.assertEqual(val[2,1,2,0],0.0,"wrong value for (2,1,2,0)")
338 self.assertEqual(val[2,1,2,1],1.0,"wrong value for (2,1,2,1)")
339 self.assertEqual(val[2,1,2,2],0.0,"wrong value for (2,1,2,2)")
340 self.assertEqual(val[2,2,0,0],0.0,"wrong value for (2,2,0,0)")
341 self.assertEqual(val[2,2,0,1],0.0,"wrong value for (2,2,0,1)")
342 self.assertEqual(val[2,2,0,2],0.0,"wrong value for (2,2,0,2)")
343 self.assertEqual(val[2,2,1,0],0.0,"wrong value for (2,2,1,0)")
344 self.assertEqual(val[2,2,1,1],0.0,"wrong value for (2,2,1,1)")
345 self.assertEqual(val[2,2,1,2],0.0,"wrong value for (2,2,1,2)")
346 self.assertEqual(val[2,2,2,0],0.0,"wrong value for (2,2,2,0)")
347 self.assertEqual(val[2,2,2,1],0.0,"wrong value for (2,2,2,1)")
348 self.assertEqual(val[2,2,2,2],1.0,"wrong value for (2,2,2,2)")
349 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
350 def test_identityTensor4_domain(self):
351 val=identityTensor4(d=self.domain)
352 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
353 self.assertEqual(val.shape,(self.domain.getDim(),self.domain.getDim(),self.domain.getDim(),self.domain.getDim()),"wrong shape.")
354 if self.domain.getDim()==2:
355 self.assertEqual(val[0,0,0,0],1.0,"wrong value for (0,0,0,0)")
356 self.assertEqual(val[0,0,0,1],0.0,"wrong value for (0,0,0,1)")
357 self.assertEqual(val[0,0,1,0],0.0,"wrong value for (0,0,1,0)")
358 self.assertEqual(val[0,0,1,1],0.0,"wrong value for (0,0,1,1)")
359 self.assertEqual(val[0,1,0,0],0.0,"wrong value for (0,1,0,0)")
360 self.assertEqual(val[0,1,0,1],1.0,"wrong value for (0,1,0,1)")
361 self.assertEqual(val[0,1,1,0],0.0,"wrong value for (0,1,1,0)")
362 self.assertEqual(val[0,1,1,1],0.0,"wrong value for (0,1,1,1)")
363 self.assertEqual(val[1,0,0,0],0.0,"wrong value for (1,0,0,0)")
364 self.assertEqual(val[1,0,0,1],0.0,"wrong value for (1,0,0,1)")
365 self.assertEqual(val[1,0,1,0],1.0,"wrong value for (1,0,1,0)")
366 self.assertEqual(val[1,0,1,1],0.0,"wrong value for (1,0,1,1)")
367 self.assertEqual(val[1,1,0,0],0.0,"wrong value for (1,1,0,0)")
368 self.assertEqual(val[1,1,0,1],0.0,"wrong value for (1,1,0,1)")
369 self.assertEqual(val[1,1,1,0],0.0,"wrong value for (1,1,1,0)")
370 self.assertEqual(val[1,1,1,1],1.0,"wrong value for (1,1,1,1)")
371 if self.domain.getDim()==3:
372 self.assertEqual(val[0,0,0,0],1.0,"wrong value for (0,0,0,0)")
373 self.assertEqual(val[0,0,0,1],0.0,"wrong value for (0,0,0,1)")
374 self.assertEqual(val[0,0,0,2],0.0,"wrong value for (0,0,0,2)")
375 self.assertEqual(val[0,0,1,0],0.0,"wrong value for (0,0,1,0)")
376 self.assertEqual(val[0,0,1,1],0.0,"wrong value for (0,0,1,1)")
377 self.assertEqual(val[0,0,1,2],0.0,"wrong value for (0,0,1,2)")
378 self.assertEqual(val[0,0,2,0],0.0,"wrong value for (0,0,2,0)")
379 self.assertEqual(val[0,0,2,1],0.0,"wrong value for (0,0,2,1)")
380 self.assertEqual(val[0,0,2,2],0.0,"wrong value for (0,0,2,2)")
381 self.assertEqual(val[0,1,0,0],0.0,"wrong value for (0,1,0,0)")
382 self.assertEqual(val[0,1,0,1],1.0,"wrong value for (0,1,0,1)")
383 self.assertEqual(val[0,1,0,2],0.0,"wrong value for (0,1,0,2)")
384 self.assertEqual(val[0,1,1,0],0.0,"wrong value for (0,1,1,0)")
385 self.assertEqual(val[0,1,1,1],0.0,"wrong value for (0,1,1,1)")
386 self.assertEqual(val[0,1,1,2],0.0,"wrong value for (0,1,1,2)")
387 self.assertEqual(val[0,1,2,0],0.0,"wrong value for (0,1,2,0)")
388 self.assertEqual(val[0,1,2,1],0.0,"wrong value for (0,1,2,1)")
389 self.assertEqual(val[0,1,2,2],0.0,"wrong value for (0,1,2,2)")
390 self.assertEqual(val[0,2,0,0],0.0,"wrong value for (0,2,0,0)")
391 self.assertEqual(val[0,2,0,1],0.0,"wrong value for (0,2,0,1)")
392 self.assertEqual(val[0,2,0,2],1.0,"wrong value for (0,2,0,2)")
393 self.assertEqual(val[0,2,1,0],0.0,"wrong value for (0,2,1,0)")
394 self.assertEqual(val[0,2,1,1],0.0,"wrong value for (0,2,1,1)")
395 self.assertEqual(val[0,2,1,2],0.0,"wrong value for (0,2,1,2)")
396 self.assertEqual(val[0,2,2,0],0.0,"wrong value for (0,2,2,0)")
397 self.assertEqual(val[0,2,2,1],0.0,"wrong value for (0,2,2,1)")
398 self.assertEqual(val[0,2,2,2],0.0,"wrong value for (0,2,2,2)")
399 self.assertEqual(val[1,0,0,0],0.0,"wrong value for (1,0,0,0)")
400 self.assertEqual(val[1,0,0,1],0.0,"wrong value for (1,0,0,1)")
401 self.assertEqual(val[1,0,0,2],0.0,"wrong value for (1,0,0,2)")
402 self.assertEqual(val[1,0,1,0],1.0,"wrong value for (1,0,1,0)")
403 self.assertEqual(val[1,0,1,1],0.0,"wrong value for (1,0,1,1)")
404 self.assertEqual(val[1,0,1,2],0.0,"wrong value for (1,0,1,2)")
405 self.assertEqual(val[1,0,2,0],0.0,"wrong value for (1,0,2,0)")
406 self.assertEqual(val[1,0,2,1],0.0,"wrong value for (1,0,2,1)")
407 self.assertEqual(val[1,0,2,2],0.0,"wrong value for (1,0,2,2)")
408 self.assertEqual(val[1,1,0,0],0.0,"wrong value for (1,1,0,0)")
409 self.assertEqual(val[1,1,0,1],0.0,"wrong value for (1,1,0,1)")
410 self.assertEqual(val[1,1,0,2],0.0,"wrong value for (1,1,0,2)")
411 self.assertEqual(val[1,1,1,0],0.0,"wrong value for (1,1,1,0)")
412 self.assertEqual(val[1,1,1,1],1.0,"wrong value for (1,1,1,1)")
413 self.assertEqual(val[1,1,1,2],0.0,"wrong value for (1,1,1,2)")
414 self.assertEqual(val[1,1,2,0],0.0,"wrong value for (1,1,2,0)")
415 self.assertEqual(val[1,1,2,1],0.0,"wrong value for (1,1,2,1)")
416 self.assertEqual(val[1,1,2,2],0.0,"wrong value for (1,1,2,2)")
417 self.assertEqual(val[1,2,0,0],0.0,"wrong value for (1,2,0,0)")
418 self.assertEqual(val[1,2,0,1],0.0,"wrong value for (1,2,0,1)")
419 self.assertEqual(val[1,2,0,2],0.0,"wrong value for (1,2,0,2)")
420 self.assertEqual(val[1,2,1,0],0.0,"wrong value for (1,2,1,0)")
421 self.assertEqual(val[1,2,1,1],0.0,"wrong value for (1,2,1,1)")
422 self.assertEqual(val[1,2,1,2],1.0,"wrong value for (1,2,1,2)")
423 self.assertEqual(val[1,2,2,0],0.0,"wrong value for (1,2,2,0)")
424 self.assertEqual(val[1,2,2,1],0.0,"wrong value for (1,2,2,1)")
425 self.assertEqual(val[1,2,2,2],0.0,"wrong value for (1,2,2,2)")
426 self.assertEqual(val[2,0,0,0],0.0,"wrong value for (2,0,0,0)")
427 self.assertEqual(val[2,0,0,1],0.0,"wrong value for (2,0,0,1)")
428 self.assertEqual(val[2,0,0,2],0.0,"wrong value for (2,0,0,2)")
429 self.assertEqual(val[2,0,1,0],0.0,"wrong value for (2,0,1,0)")
430 self.assertEqual(val[2,0,1,1],0.0,"wrong value for (2,0,1,1)")
431 self.assertEqual(val[2,0,1,2],0.0,"wrong value for (2,0,1,2)")
432 self.assertEqual(val[2,0,2,0],1.0,"wrong value for (2,0,2,0)")
433 self.assertEqual(val[2,0,2,1],0.0,"wrong value for (2,0,2,1)")
434 self.assertEqual(val[2,0,2,2],0.0,"wrong value for (2,0,2,2)")
435 self.assertEqual(val[2,1,0,0],0.0,"wrong value for (2,1,0,0)")
436 self.assertEqual(val[2,1,0,1],0.0,"wrong value for (2,1,0,1)")
437 self.assertEqual(val[2,1,0,2],0.0,"wrong value for (2,1,0,2)")
438 self.assertEqual(val[2,1,1,0],0.0,"wrong value for (2,1,1,0)")
439 self.assertEqual(val[2,1,1,1],0.0,"wrong value for (2,1,1,1)")
440 self.assertEqual(val[2,1,1,2],0.0,"wrong value for (2,1,1,2)")
441 self.assertEqual(val[2,1,2,0],0.0,"wrong value for (2,1,2,0)")
442 self.assertEqual(val[2,1,2,1],1.0,"wrong value for (2,1,2,1)")
443 self.assertEqual(val[2,1,2,2],0.0,"wrong value for (2,1,2,2)")
444 self.assertEqual(val[2,2,0,0],0.0,"wrong value for (2,2,0,0)")
445 self.assertEqual(val[2,2,0,1],0.0,"wrong value for (2,2,0,1)")
446 self.assertEqual(val[2,2,0,2],0.0,"wrong value for (2,2,0,2)")
447 self.assertEqual(val[2,2,1,0],0.0,"wrong value for (2,2,1,0)")
448 self.assertEqual(val[2,2,1,1],0.0,"wrong value for (2,2,1,1)")
449 self.assertEqual(val[2,2,1,2],0.0,"wrong value for (2,2,1,2)")
450 self.assertEqual(val[2,2,2,0],0.0,"wrong value for (2,2,2,0)")
451 self.assertEqual(val[2,2,2,1],0.0,"wrong value for (2,2,2,1)")
452 self.assertEqual(val[2,2,2,2],1.0,"wrong value for (2,2,2,2)")
453 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
454 def test_identityTensor4_functionspace(self):
455 val=identityTensor4(d=self.functionspace)
456 self.assertTrue(isinstance(val,escript.Data),"wrong type of result.")
457 self.assertEqual(val.getShape(),(self.functionspace.getDim(),self.functionspace.getDim(),self.functionspace.getDim(),self.functionspace.getDim()),"wrong shape.")
458 if self.domain.getDim()==2:
459 self.assertTrue(Lsup(val[0,0,0,0]-1.0)<=self.RES_TOL,"wrong value for (0,0,0,0)")
460 self.assertTrue(Lsup(val[0,0,0,1]-0.0)<=self.RES_TOL,"wrong value for (0,0,0,1)")
461 self.assertTrue(Lsup(val[0,0,1,0]-0.0)<=self.RES_TOL,"wrong value for (0,0,1,0)")
462 self.assertTrue(Lsup(val[0,0,1,1]-0.0)<=self.RES_TOL,"wrong value for (0,0,1,1)")
463 self.assertTrue(Lsup(val[0,1,0,0]-0.0)<=self.RES_TOL,"wrong value for (0,1,0,0)")
464 self.assertTrue(Lsup(val[0,1,0,1]-1.0)<=self.RES_TOL,"wrong value for (0,1,0,1)")
465 self.assertTrue(Lsup(val[0,1,1,0]-0.0)<=self.RES_TOL,"wrong value for (0,1,1,0)")
466 self.assertTrue(Lsup(val[0,1,1,1]-0.0)<=self.RES_TOL,"wrong value for (0,1,1,1)")
467 self.assertTrue(Lsup(val[1,0,0,0]-0.0)<=self.RES_TOL,"wrong value for (1,0,0,0)")
468 self.assertTrue(Lsup(val[1,0,0,1]-0.0)<=self.RES_TOL,"wrong value for (1,0,0,1)")
469 self.assertTrue(Lsup(val[1,0,1,0]-1.0)<=self.RES_TOL,"wrong value for (1,0,1,0)")
470 self.assertTrue(Lsup(val[1,0,1,1]-0.0)<=self.RES_TOL,"wrong value for (1,0,1,1)")
471 self.assertTrue(Lsup(val[1,1,0,0]-0.0)<=self.RES_TOL,"wrong value for (1,1,0,0)")
472 self.assertTrue(Lsup(val[1,1,0,1]-0.0)<=self.RES_TOL,"wrong value for (1,1,0,1)")
473 self.assertTrue(Lsup(val[1,1,1,0]-0.0)<=self.RES_TOL,"wrong value for (1,1,1,0)")
474 self.assertTrue(Lsup(val[1,1,1,1]-1.0)<=self.RES_TOL,"wrong value for (1,1,1,1)")
475 if self.domain.getDim()==3:
476 self.assertTrue(Lsup(val[0,0,0,0]-1.0)<=self.RES_TOL,"wrong value for (0,0,0,0)")
477 self.assertTrue(Lsup(val[0,0,0,1]-0.0)<=self.RES_TOL,"wrong value for (0,0,0,1)")
478 self.assertTrue(Lsup(val[0,0,0,2]-0.0)<=self.RES_TOL,"wrong value for (0,0,0,2)")
479 self.assertTrue(Lsup(val[0,0,1,0]-0.0)<=self.RES_TOL,"wrong value for (0,0,1,0)")
480 self.assertTrue(Lsup(val[0,0,1,1]-0.0)<=self.RES_TOL,"wrong value for (0,0,1,1)")
481 self.assertTrue(Lsup(val[0,0,1,2]-0.0)<=self.RES_TOL,"wrong value for (0,0,1,2)")
482 self.assertTrue(Lsup(val[0,0,2,0]-0.0)<=self.RES_TOL,"wrong value for (0,0,2,0)")
483 self.assertTrue(Lsup(val[0,0,2,1]-0.0)<=self.RES_TOL,"wrong value for (0,0,2,1)")
484 self.assertTrue(Lsup(val[0,0,2,2]-0.0)<=self.RES_TOL,"wrong value for (0,0,2,2)")
485 self.assertTrue(Lsup(val[0,1,0,0]-0.0)<=self.RES_TOL,"wrong value for (0,1,0,0)")
486 self.assertTrue(Lsup(val[0,1,0,1]-1.0)<=self.RES_TOL,"wrong value for (0,1,0,1)")
487 self.assertTrue(Lsup(val[0,1,0,2]-0.0)<=self.RES_TOL,"wrong value for (0,1,0,2)")
488 self.assertTrue(Lsup(val[0,1,1,0]-0.0)<=self.RES_TOL,"wrong value for (0,1,1,0)")
489 self.assertTrue(Lsup(val[0,1,1,1]-0.0)<=self.RES_TOL,"wrong value for (0,1,1,1)")
490 self.assertTrue(Lsup(val[0,1,1,2]-0.0)<=self.RES_TOL,"wrong value for (0,1,1,2)")
491 self.assertTrue(Lsup(val[0,1,2,0]-0.0)<=self.RES_TOL,"wrong value for (0,1,2,0)")
492 self.assertTrue(Lsup(val[0,1,2,1]-0.0)<=self.RES_TOL,"wrong value for (0,1,2,1)")
493 self.assertTrue(Lsup(val[0,1,2,2]-0.0)<=self.RES_TOL,"wrong value for (0,1,2,2)")
494 self.assertTrue(Lsup(val[0,2,0,0]-0.0)<=self.RES_TOL,"wrong value for (0,2,0,0)")
495 self.assertTrue(Lsup(val[0,2,0,1]-0.0)<=self.RES_TOL,"wrong value for (0,2,0,1)")
496 self.assertTrue(Lsup(val[0,2,0,2]-1.0)<=self.RES_TOL,"wrong value for (0,2,0,2)")
497 self.assertTrue(Lsup(val[0,2,1,0]-0.0)<=self.RES_TOL,"wrong value for (0,2,1,0)")
498 self.assertTrue(Lsup(val[0,2,1,1]-0.0)<=self.RES_TOL,"wrong value for (0,2,1,1)")
499 self.assertTrue(Lsup(val[0,2,1,2]-0.0)<=self.RES_TOL,"wrong value for (0,2,1,2)")
500 self.assertTrue(Lsup(val[0,2,2,0]-0.0)<=self.RES_TOL,"wrong value for (0,2,2,0)")
501 self.assertTrue(Lsup(val[0,2,2,1]-0.0)<=self.RES_TOL,"wrong value for (0,2,2,1)")
502 self.assertTrue(Lsup(val[0,2,2,2]-0.0)<=self.RES_TOL,"wrong value for (0,2,2,2)")
503 self.assertTrue(Lsup(val[1,0,0,0]-0.0)<=self.RES_TOL,"wrong value for (1,0,0,0)")
504 self.assertTrue(Lsup(val[1,0,0,1]-0.0)<=self.RES_TOL,"wrong value for (1,0,0,1)")
505 self.assertTrue(Lsup(val[1,0,0,2]-0.0)<=self.RES_TOL,"wrong value for (1,0,0,2)")
506 self.assertTrue(Lsup(val[1,0,1,0]-1.0)<=self.RES_TOL,"wrong value for (1,0,1,0)")
507 self.assertTrue(Lsup(val[1,0,1,1]-0.0)<=self.RES_TOL,"wrong value for (1,0,1,1)")
508 self.assertTrue(Lsup(val[1,0,1,2]-0.0)<=self.RES_TOL,"wrong value for (1,0,1,2)")
509 self.assertTrue(Lsup(val[1,0,2,0]-0.0)<=self.RES_TOL,"wrong value for (1,0,2,0)")
510 self.assertTrue(Lsup(val[1,0,2,1]-0.0)<=self.RES_TOL,"wrong value for (1,0,2,1)")
511 self.assertTrue(Lsup(val[1,0,2,2]-0.0)<=self.RES_TOL,"wrong value for (1,0,2,2)")
512 self.assertTrue(Lsup(val[1,1,0,0]-0.0)<=self.RES_TOL,"wrong value for (1,1,0,0)")
513 self.assertTrue(Lsup(val[1,1,0,1]-0.0)<=self.RES_TOL,"wrong value for (1,1,0,1)")
514 self.assertTrue(Lsup(val[1,1,0,2]-0.0)<=self.RES_TOL,"wrong value for (1,1,0,2)")
515 self.assertTrue(Lsup(val[1,1,1,0]-0.0)<=self.RES_TOL,"wrong value for (1,1,1,0)")
516 self.assertTrue(Lsup(val[1,1,1,1]-1.0)<=self.RES_TOL,"wrong value for (1,1,1,1)")
517 self.assertTrue(Lsup(val[1,1,1,2]-0.0)<=self.RES_TOL,"wrong value for (1,1,1,2)")
518 self.assertTrue(Lsup(val[1,1,2,0]-0.0)<=self.RES_TOL,"wrong value for (1,1,2,0)")
519 self.assertTrue(Lsup(val[1,1,2,1]-0.0)<=self.RES_TOL,"wrong value for (1,1,2,1)")
520 self.assertTrue(Lsup(val[1,1,2,2]-0.0)<=self.RES_TOL,"wrong value for (1,1,2,2)")
521 self.assertTrue(Lsup(val[1,2,0,0]-0.0)<=self.RES_TOL,"wrong value for (1,2,0,0)")
522 self.assertTrue(Lsup(val[1,2,0,1]-0.0)<=self.RES_TOL,"wrong value for (1,2,0,1)")
523 self.assertTrue(Lsup(val[1,2,0,2]-0.0)<=self.RES_TOL,"wrong value for (1,2,0,2)")
524 self.assertTrue(Lsup(val[1,2,1,0]-0.0)<=self.RES_TOL,"wrong value for (1,2,1,0)")
525 self.assertTrue(Lsup(val[1,2,1,1]-0.0)<=self.RES_TOL,"wrong value for (1,2,1,1)")
526 self.assertTrue(Lsup(val[1,2,1,2]-1.0)<=self.RES_TOL,"wrong value for (1,2,1,2)")
527 self.assertTrue(Lsup(val[1,2,2,0]-0.0)<=self.RES_TOL,"wrong value for (1,2,2,0)")
528 self.assertTrue(Lsup(val[1,2,2,1]-0.0)<=self.RES_TOL,"wrong value for (1,2,2,1)")
529 self.assertTrue(Lsup(val[1,2,2,2]-0.0)<=self.RES_TOL,"wrong value for (1,2,2,2)")
530 self.assertTrue(Lsup(val[2,0,0,0]-0.0)<=self.RES_TOL,"wrong value for (2,0,0,0)")
531 self.assertTrue(Lsup(val[2,0,0,1]-0.0)<=self.RES_TOL,"wrong value for (2,0,0,1)")
532 self.assertTrue(Lsup(val[2,0,0,2]-0.0)<=self.RES_TOL,"wrong value for (2,0,0,2)")
533 self.assertTrue(Lsup(val[2,0,1,0]-0.0)<=self.RES_TOL,"wrong value for (2,0,1,0)")
534 self.assertTrue(Lsup(val[2,0,1,1]-0.0)<=self.RES_TOL,"wrong value for (2,0,1,1)")
535 self.assertTrue(Lsup(val[2,0,1,2]-0.0)<=self.RES_TOL,"wrong value for (2,0,1,2)")
536 self.assertTrue(Lsup(val[2,0,2,0]-1.0)<=self.RES_TOL,"wrong value for (2,0,2,0)")
537 self.assertTrue(Lsup(val[2,0,2,1]-0.0)<=self.RES_TOL,"wrong value for (2,0,2,1)")
538 self.assertTrue(Lsup(val[2,0,2,2]-0.0)<=self.RES_TOL,"wrong value for (2,0,2,2)")
539 self.assertTrue(Lsup(val[2,1,0,0]-0.0)<=self.RES_TOL,"wrong value for (2,1,0,0)")
540 self.assertTrue(Lsup(val[2,1,0,1]-0.0)<=self.RES_TOL,"wrong value for (2,1,0,1)")
541 self.assertTrue(Lsup(val[2,1,0,2]-0.0)<=self.RES_TOL,"wrong value for (2,1,0,2)")
542 self.assertTrue(Lsup(val[2,1,1,0]-0.0)<=self.RES_TOL,"wrong value for (2,1,1,0)")
543 self.assertTrue(Lsup(val[2,1,1,1]-0.0)<=self.RES_TOL,"wrong value for (2,1,1,1)")
544 self.assertTrue(Lsup(val[2,1,1,2]-0.0)<=self.RES_TOL,"wrong value for (2,1,1,2)")
545 self.assertTrue(Lsup(val[2,1,2,0]-0.0)<=self.RES_TOL,"wrong value for (2,1,2,0)")
546 self.assertTrue(Lsup(val[2,1,2,1]-1.0)<=self.RES_TOL,"wrong value for (2,1,2,1)")
547 self.assertTrue(Lsup(val[2,1,2,2]-0.0)<=self.RES_TOL,"wrong value for (2,1,2,2)")
548 self.assertTrue(Lsup(val[2,2,0,0]-0.0)<=self.RES_TOL,"wrong value for (2,2,0,0)")
549 self.assertTrue(Lsup(val[2,2,0,1]-0.0)<=self.RES_TOL,"wrong value for (2,2,0,1)")
550 self.assertTrue(Lsup(val[2,2,0,2]-0.0)<=self.RES_TOL,"wrong value for (2,2,0,2)")
551 self.assertTrue(Lsup(val[2,2,1,0]-0.0)<=self.RES_TOL,"wrong value for (2,2,1,0)")
552 self.assertTrue(Lsup(val[2,2,1,1]-0.0)<=self.RES_TOL,"wrong value for (2,2,1,1)")
553 self.assertTrue(Lsup(val[2,2,1,2]-0.0)<=self.RES_TOL,"wrong value for (2,2,1,2)")
554 self.assertTrue(Lsup(val[2,2,2,0]-0.0)<=self.RES_TOL,"wrong value for (2,2,2,0)")
555 self.assertTrue(Lsup(val[2,2,2,1]-0.0)<=self.RES_TOL,"wrong value for (2,2,2,1)")
556 self.assertTrue(Lsup(val[2,2,2,2]-1.0)<=self.RES_TOL,"wrong value for (2,2,2,2)")
557 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
558 def test_unitVector_1(self):
559 val=unitVector(i=0,d=1)
560 self.assertEqual(val[0],1.0,"wrong value for 0 in the 0 vector")
561 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
562 def test_unitVector_2(self):
563 val=unitVector(i=0,d=2)
564 self.assertEqual(val[0],1.0,"wrong value for 0 in the 0 vector")
565 self.assertEqual(val[1],0.0,"wrong value for 1 in the 0 vector")
566 val=unitVector(i=1,d=2)
567 self.assertEqual(val[0],0.0,"wrong value for 0 in the 1 vector")
568 self.assertEqual(val[1],1.0,"wrong value for 1 in the 1 vector")
569 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
570 def test_unitVector_3(self):
571 val=unitVector(i=0,d=3)
572 self.assertEqual(val[0],1.0,"wrong value for 0 in the 0 vector")
573 self.assertEqual(val[1],0.0,"wrong value for 1 in the 0 vector")
574 self.assertEqual(val[2],0.0,"wrong value for 2 in the 0 vector")
575 val=unitVector(i=1,d=3)
576 self.assertEqual(val[0],0.0,"wrong value for 0 in the 1 vector")
577 self.assertEqual(val[1],1.0,"wrong value for 1 in the 1 vector")
578 self.assertEqual(val[2],0.0,"wrong value for 2 in the 1 vector")
579 val=unitVector(i=2,d=3)
580 self.assertEqual(val[0],0.0,"wrong value for 0 in the 2 vector")
581 self.assertEqual(val[1],0.0,"wrong value for 1 in the 2 vector")
582 self.assertEqual(val[2],1.0,"wrong value for 2 in the 2 vector")
583 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
584 def test_unitVector_domain(self):
585 val=unitVector(i=0,d=self.domain)
586 self.assertTrue(isinstance(val,numpy.ndarray),"wrong type of result.")
587 self.assertEqual(val.shape,(self.domain.getDim(),),"wrong shape.")
588 if self.domain.getDim()==2:
589 self.assertEqual(val[0],1.0,"wrong value for 0 in the 0 vector")
590 self.assertEqual(val[1],0.0,"wrong value for 1 in the 0 vector")
591 if self.domain.getDim()==3:
592 self.assertEqual(val[0],1.0,"wrong value for 0 in the 0 vector")
593 self.assertEqual(val[1],0.0,"wrong value for 1 in the 0 vector")
594 self.assertEqual(val[2],0.0,"wrong value for 2 in the 0 vector")
595 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
596 def test_unitVector_functionspace(self):
597 val=unitVector(i=0,d=self.functionspace)
598 self.assertTrue(isinstance(val,escript.Data),"wrong type of result.")
599 self.assertEqual(val.getShape(),(self.functionspace.getDim(),),"wrong shape.")
600 if self.domain.getDim()==2:
601 self.assertTrue(Lsup(val[0]-1.0)<=self.RES_TOL,"wrong value for 0 in the 0 vector")
602 self.assertTrue(Lsup(val[1]-0.0)<=self.RES_TOL,"wrong value for 1 in the 0 vector")
603 if self.domain.getDim()==3:
604 self.assertTrue(Lsup(val[0]-1.0)<=self.RES_TOL,"wrong value for 0 in the 0 vector")
605 self.assertTrue(Lsup(val[1]-0.0)<=self.RES_TOL,"wrong value for 1 in the 0 vector")
606 self.assertTrue(Lsup(val[2]-0.0)<=self.RES_TOL,"wrong value for 2 in the 0 vector")
607

  ViewVC Help
Powered by ViewVC 1.1.26