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

Annotation of /trunk/escriptcore/test/python/test_util_base.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4448 - (hide annotations)
Wed Jun 12 23:05:12 2013 UTC (5 years, 1 month ago) by caltinay
Original Path: trunk/escript/test/python/test_util_base.py
File MIME type: text/x-python
File size: 39207 byte(s)
Only one rank should delete file in tests.

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

  ViewVC Help
Powered by ViewVC 1.1.26