1 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from MEDCalculator import *
23 #self.assertEqual(int(expected2[i]),a4.getIJ(0,i));
24 #self.assertTrue(a2.getInfoOnComponent(2)=="ffff");
25 #self.assertRaises(Exception,a2.keepSelectedComponents,arr5V);
26 #self.assertAlmostEqual(2.3,t,13);
28 class MEDCalculatorBasicsTest(unittest.TestCase):
30 e=MEDCalculatorBrowserLiteStruct("hfile1.med")
32 Power=MEDCalculatorDBFieldReal(f)
33 Power2=Power[:,:,2:4]+Power[:,:,3:5]
34 Power3=Power[:,:,2:4]+Power(":",":","3:5")
35 self.assertTrue(Power2.isEqual(Power3,1e-12,1e-12))
37 self.assertTrue(not Power2.isEqual(Power3,1e-12,1e-12))
39 self.assertTrue(Power2.isEqual(Power3,1e-10,1e-10))
41 self.assertTrue(not Power2.isEqual(Power3,1e-12,1e-12))
43 self.assertTrue(Power2.isEqual(Power3,1e-12,1e-12))
45 Power2.setName('Power2')
46 Power2.write("hfile2.med",True)
47 e=MEDCalculatorBrowserLiteStruct("hfile2.med")
49 Power4=MEDCalculatorDBFieldReal(f)
50 self.assertTrue(Power2.isEqual(Power4,1e-12,1e-12))
54 e=MEDCalculatorBrowserLiteStruct("hfile1.med")
56 Power=MEDCalculatorDBFieldReal(f)
58 self.assertEqual(10,len(v));
61 self.assertEqual(35,len(v1))
65 self.assertAlmostEqual((i+1)*100.+(j+1)*10.+k+1,v1[l],12);
72 self.assertEqual(2,len(v));
75 self.assertEqual(35,len(v1))
79 self.assertAlmostEqual((i+3)*100.+(j+1)*10.+k+1,v1[l],12);
86 self.assertEqual(4,len(v));
89 self.assertEqual(15,len(v1))
93 self.assertAlmostEqual((i+4)*100.+(j+1)*10.+k+3,v1[l],12);
99 p3=Power[0:4,:,2:4].dot(Power[6:,:,3:5])
101 self.assertEqual(4,len(v));
102 expected=[[162192.0, 178952.0, 196112.0, 213672.0, 231632.0], [347792.0, 368552.0, 389712.0, 411272.0, 433232.0], [573392.0, 598152.0, 623312.0, 648872.0, 674832.0], [838992.0, 867752.0, 896912.0, 926472.0, 956432.0]]
105 self.assertEqual(5,len(v1))
108 self.assertAlmostEqual(expected[i][j],v1[l],8);
115 self.assertEqual(10,len(v));
118 self.assertEqual(35,len(v1))
122 self.assertAlmostEqual((i+1)*100.+(j+1)*10.+k+1,v1[l],12);
125 self.assertAlmostEqual(7.,v1[l],12);
127 self.assertAlmostEqual(7.,v1[l],12);
130 self.assertAlmostEqual((i+1)*100.+(j+1)*10.+k+5,v1[l],12);
136 v=Power[1:5,:,:].getValues()
137 self.assertEqual(4,len(v));
140 self.assertEqual(35,len(v1))
144 self.assertAlmostEqual((i+2)*100.+(j+1)*10.+k+1,v1[l],12);
147 self.assertAlmostEqual(7.,v1[l],12);
149 self.assertAlmostEqual(expected[i][j],v1[l],8);
152 self.assertAlmostEqual((i+2)*100.+(j+1)*10.+k+5,v1[l],12);
157 Power[:,:,1:].eigenValues()