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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4938 - (show annotations)
Wed May 14 01:13:23 2014 UTC (5 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 39307 byte(s)
Modify unit tests to read their classes from
esys.escriptcore.utestselect

Change the line in that file to switch between unittest and unittest2


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

  ViewVC Help
Powered by ViewVC 1.1.26