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

  ViewVC Help
Powered by ViewVC 1.1.26