Back to index

salome-med  6.5.0
MEDCalculatorBasicsTest.py
Go to the documentation of this file.
00001 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 from MEDCalculator import *
00021 import unittest
00022 
00023 #self.assertEqual(int(expected2[i]),a4.getIJ(0,i));
00024 #self.assertTrue(a2.getInfoOnComponent(2)=="ffff");
00025 #self.assertRaises(Exception,a2.keepSelectedComponents,arr5V);
00026 #self.assertAlmostEqual(2.3,t,13);
00027 
00028 class MEDCalculatorBasicsTest(unittest.TestCase):
00029     def test1(self):
00030         e=MEDCalculatorBrowserLiteStruct("hfile1.med")
00031         f=e.getField(0)
00032         Power=MEDCalculatorDBFieldReal(f)
00033         Power2=Power[:,:,2:4]+Power[:,:,3:5]
00034         Power3=Power[:,:,2:4]+Power(":",":","3:5")
00035         self.assertTrue(Power2.isEqual(Power3,1e-12,1e-12))
00036         Power2=2+Power2
00037         self.assertTrue(not Power2.isEqual(Power3,1e-12,1e-12))
00038         Power2=Power2-2
00039         self.assertTrue(Power2.isEqual(Power3,1e-10,1e-10))
00040         Power2=2*Power2
00041         self.assertTrue(not Power2.isEqual(Power3,1e-12,1e-12))
00042         Power2=Power2/2
00043         self.assertTrue(Power2.isEqual(Power3,1e-12,1e-12))
00044         Power2=Power2*2
00045         Power2.setName('Power2')
00046         Power2.write("hfile2.med",True)
00047         e=MEDCalculatorBrowserLiteStruct("hfile2.med")
00048         f=e.getField(0)
00049         Power4=MEDCalculatorDBFieldReal(f)
00050         self.assertTrue(Power2.isEqual(Power4,1e-12,1e-12))
00051         pass
00052     
00053     def test2(self):
00054         e=MEDCalculatorBrowserLiteStruct("hfile1.med")
00055         f=e.getField(0)
00056         Power=MEDCalculatorDBFieldReal(f)
00057         v=Power.getValues()
00058         self.assertEqual(10,len(v));
00059         for i in xrange(10):
00060             v1=v[i]
00061             self.assertEqual(35,len(v1))
00062             l=0
00063             for j in xrange(5):
00064                 for k in xrange(7):
00065                     self.assertAlmostEqual((i+1)*100.+(j+1)*10.+k+1,v1[l],12);
00066                     l+=1
00067                     pass
00068                 pass
00069             pass
00070         p1=Power[2:4,:,:]
00071         v=p1.getValues()
00072         self.assertEqual(2,len(v));
00073         for i in xrange(2):
00074             v1=v[i]
00075             self.assertEqual(35,len(v1))
00076             l=0
00077             for j in xrange(5):
00078                 for k in xrange(7):
00079                     self.assertAlmostEqual((i+3)*100.+(j+1)*10.+k+1,v1[l],12);
00080                     l+=1
00081                     pass
00082                 pass
00083             pass
00084         p2=Power[3:7,:,2:5]
00085         v=p2.getValues()
00086         self.assertEqual(4,len(v));
00087         for i in xrange(4):
00088             v1=v[i]
00089             self.assertEqual(15,len(v1))
00090             l=0
00091             for j in xrange(5):
00092                 for k in xrange(3):
00093                     self.assertAlmostEqual((i+4)*100.+(j+1)*10.+k+3,v1[l],12);
00094                     l+=1
00095                     pass
00096                 pass
00097             pass
00098         #
00099         p3=Power[0:4,:,2:4].dot(Power[6:,:,3:5])
00100         v=p3.getValues()
00101         self.assertEqual(4,len(v));
00102         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]]
00103         for i in xrange(4):
00104             v1=v[i]
00105             self.assertEqual(5,len(v1))
00106             l=0
00107             for j in xrange(5):
00108                 self.assertAlmostEqual(expected[i][j],v1[l],8);
00109                 l+=1
00110                 pass
00111             pass
00112         #
00113         Power[:,:,2:4]=7.
00114         v=Power.getValues()
00115         self.assertEqual(10,len(v));
00116         for i in xrange(10):
00117             v1=v[i]
00118             self.assertEqual(35,len(v1))
00119             l=0
00120             for j in xrange(5):
00121                 for k in xrange(2):
00122                     self.assertAlmostEqual((i+1)*100.+(j+1)*10.+k+1,v1[l],12);
00123                     l+=1
00124                     pass
00125                 self.assertAlmostEqual(7.,v1[l],12);
00126                 l+=1
00127                 self.assertAlmostEqual(7.,v1[l],12);
00128                 l+=1
00129                 for k in xrange(3):
00130                     self.assertAlmostEqual((i+1)*100.+(j+1)*10.+k+5,v1[l],12);
00131                     l+=1
00132                     pass
00133                 pass
00134             pass
00135         Power[1:5,:,3]=p3
00136         v=Power[1:5,:,:].getValues()
00137         self.assertEqual(4,len(v));
00138         for i in xrange(4):
00139             v1=v[i]
00140             self.assertEqual(35,len(v1))
00141             l=0
00142             for j in xrange(5):
00143                 for k in xrange(2):
00144                     self.assertAlmostEqual((i+2)*100.+(j+1)*10.+k+1,v1[l],12);
00145                     l+=1
00146                     pass
00147                 self.assertAlmostEqual(7.,v1[l],12);
00148                 l+=1
00149                 self.assertAlmostEqual(expected[i][j],v1[l],8);
00150                 l+=1
00151                 for k in xrange(3):
00152                     self.assertAlmostEqual((i+2)*100.+(j+1)*10.+k+5,v1[l],12);
00153                     l+=1
00154                     pass
00155                 pass
00156             pass
00157         Power[:,:,1:].eigenValues()
00158         Power[:]=0.07
00159         pass
00160     def setUp(self):
00161         pass
00162     pass
00163 
00164 unittest.main()