Back to index

salome-med  6.5.0
MEDCouplingBasicsTest.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00003 #
00004 # This library is free software; you can redistribute it and/or
00005 # modify it under the terms of the GNU Lesser General Public
00006 # License as published by the Free Software Foundation; either
00007 # version 2.1 of the License.
00008 #
00009 # This library is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 # Lesser General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU Lesser General Public
00015 # License along with this library; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 #
00018 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 #
00020 
00021 from MEDCoupling import *
00022 import unittest
00023 from math import pi,e,sqrt,cos,sin
00024 from MEDCouplingDataForTest import MEDCouplingDataForTest
00025 
00026 class MEDCouplingBasicsTest(unittest.TestCase):
00027     def testArray2(self):
00028         arr=DataArrayDouble.New()
00029         arr.setValues([12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.],3,4)
00030         arr.setInfoOnComponent(0,"ggg");
00031         arr.setInfoOnComponent(1,"hhhh");
00032         arr.setInfoOnComponent(2,"jj");
00033         arr.setInfoOnComponent(3,"kkkkkk");
00034         arr2=arr.convertToIntArr();
00035         arr3=arr2.convertToDblArr();
00036         self.assertTrue(arr.isEqual(arr3,1e-14))
00037         pass
00038 
00039     def testArray3(self):
00040         arr1=DataArrayInt.New();
00041         arr1Ref=[0,10,1,11,2,12,3,13,4,14,5,15,6,16]
00042         arr1.setValues(arr1Ref,7,2);
00043         self.assertEqual(7,arr1.getNumberOfTuples());
00044         self.assertEqual(2,arr1.getNumberOfComponents());
00045         self.assertEqual(arr1Ref,list(arr1.getValues()));
00046         arr2=arr1.substr(3);
00047         self.assertEqual(4,arr2.getNumberOfTuples());
00048         self.assertEqual(2,arr2.getNumberOfComponents());
00049         self.assertEqual(arr1Ref[6:],list(arr2.getValues()));
00050         arr3=arr1.substr(2,5);
00051         self.assertEqual(3,arr3.getNumberOfTuples());
00052         self.assertEqual(2,arr3.getNumberOfComponents());
00053         self.assertEqual(arr1Ref[4:10],list(arr3.getValues()));
00054         #
00055         arr4=DataArrayDouble.New();
00056         arr4Ref=[0.8,10.8,1.9,11.9,2.1,12.1,3.2,13.2,4.3,14.3,5.4,15.4,6.5,16.5]
00057         arr4.setValues(arr4Ref,7,2);
00058         self.assertEqual(7,arr4.getNumberOfTuples());
00059         self.assertEqual(2,arr4.getNumberOfComponents());
00060         tmp=arr4.getValues()
00061         for i in xrange(14):
00062             self.assertTrue(abs(arr4Ref[i]-tmp[i])<1e-14);
00063             pass
00064         arr5=arr4.substr(3);
00065         self.assertEqual(4,arr5.getNumberOfTuples());
00066         self.assertEqual(2,arr5.getNumberOfComponents());
00067         tmp=arr5.getValues()
00068         for i in xrange(8):
00069             self.assertTrue(abs(arr4Ref[6+i]-tmp[i])<1e-14);
00070             pass
00071         arr6=arr4.substr(2,5);
00072         self.assertEqual(3,arr6.getNumberOfTuples());
00073         self.assertEqual(2,arr6.getNumberOfComponents());
00074         tmp=arr6.getValues()
00075         for i in xrange(6):
00076             self.assertTrue(abs(arr4Ref[4+i]-tmp[i])<1e-14);
00077             pass
00078         pass
00079 
00080     def testMesh(self):
00081         tab4=[1, 2, 8, 7, 2, 3, 9, 8, 3,
00082               4, 10, 9, 4, 5, 11, 10, 5,
00083               0, 6, 11, 0, 1, 7, 6 ]
00084         nbOfNodes=12
00085         nbOfCells=6
00086         coords=[ 0.024155, 0.04183768725682622, -0.305, 0.04831000000000001, -1.015761910347357e-17,
00087                  -0.305, 0.09662000000000001, -1.832979297858306e-18, -0.305, 0.120775, 0.04183768725682623,
00088                  -0.305, 0.09662000000000001, 0.08367537451365245, -0.305, 0.04831000000000001, 0.08367537451365246,
00089                  -0.305, 0.024155, 0.04183768725682622, -0.2863, 0.04831000000000001, -1.015761910347357e-17, -0.2863, 
00090                  0.09662000000000001, -1.832979297858306e-18, -0.2863, 0.120775, 0.04183768725682623, -0.2863, 0.09662000000000001,
00091                  0.08367537451365245, -0.2863, 0.04831000000000001, 0.08367537451365246, -0.2863 ]
00092         mesh=MEDCouplingUMesh.New()
00093         mesh.setMeshDimension(2)
00094         mesh.allocateCells(8);
00095         mesh.setName("mesh1")
00096         self.assertTrue(mesh.getName()=="mesh1")
00097         for i in range(nbOfCells):
00098             mesh.insertNextCell(NORM_QUAD4,4,tab4[4*i:4*(i+1)]);
00099             pass
00100         mesh.finishInsertingCells()
00101         self.assertTrue(mesh.getNumberOfCells()==nbOfCells)
00102         self.assertTrue(mesh.getNodalConnectivity().getNbOfElems()==30)
00103         self.assertTrue(mesh.getNodalConnectivityIndex().getNbOfElems()==nbOfCells+1)
00104         myCoords=DataArrayDouble.New()
00105         myCoords.setValues(coords,nbOfNodes,3);
00106         self.assertTrue(myCoords.getIJ(3,2)==-0.305)
00107         mesh.setCoords(myCoords);
00108         mesh.checkCoherency();
00109         self.assertTrue(mesh.getAllTypes()==[4])
00110         myFalseConn=DataArrayInt.New()
00111         myFalseConn.setValues(tab4,6,4)
00112         self.assertTrue(myFalseConn.getIJ(1,1)==3)
00113         #
00114         field=MEDCouplingFieldDouble.New(ON_CELLS)
00115         field.setMesh(mesh)
00116         field.setNature(Integral)
00117         myCoords=DataArrayDouble.New()
00118         sampleTab=[]
00119         for i in range(nbOfCells*9):
00120             sampleTab.append(float(i))
00121         myCoords.setValues(sampleTab,nbOfCells,9);
00122         field.setArray(myCoords)
00123         self.assertTrue(3==mesh.getSpaceDimension())
00124         field.checkCoherency()
00125         mesh2=mesh.clone(False)
00126         mesh3=mesh.clone(True)
00127         mesh3=0
00128         mesh2=0
00129         ## deep full recursively copy of field -> both field and mesh underneath copied
00130         field2=field.clone(True)
00131         field2.setMesh(field.getMesh().clone(True))
00132         mesh3=mesh.clone(True)
00133         field3=mesh3.fillFromAnalytic(ON_CELLS,2,"x*IVec+(y+z)*JVec")
00134         field3.applyFunc("u*u*u+cos(u)")
00135         pass
00136         
00137     def testMeshPointsCloud(self):
00138         targetCoords=[-0.3,-0.3,0.5, 0.2,-0.3,1., 0.7,-0.3,1.5,
00139                       -0.3,0.2,0.5, 0.2,0.2,1., 0.7,0.2,1.5, -0.3,0.7,0.5, 0.2,0.7,1., 0.7,0.7,1.5]
00140         targetMesh=MEDCouplingUMesh.New();
00141         targetMesh.setMeshDimension(0);
00142         targetMesh.allocateCells(8);
00143         targetMesh.insertNextCell(NORM_POINT1,1,[0]);
00144         targetMesh.insertNextCell(NORM_POINT1,1,[1]);
00145         targetMesh.insertNextCell(NORM_POINT1,1,[2]);
00146         targetMesh.insertNextCell(NORM_POINT1,1,[3]);
00147         targetMesh.insertNextCell(NORM_POINT1,1,[4]);
00148         targetMesh.insertNextCell(NORM_POINT1,1,[5]);
00149         targetMesh.insertNextCell(NORM_POINT1,1,[7]);
00150         targetMesh.insertNextCell(NORM_POINT1,1,[6]);
00151         targetMesh.finishInsertingCells();
00152         myCoords=DataArrayDouble.New();
00153         myCoords.setValues(targetCoords,9,3);
00154         targetMesh.setCoords(myCoords);
00155         self.assertEqual(targetMesh.getSpaceDimension(),3)
00156         self.assertEqual(targetMesh.getNumberOfCells(),8)
00157         self.assertEqual(targetMesh.getNumberOfNodes(),9)
00158         self.assertEqual(targetMesh.getMeshDimension(),0)
00159         pass
00160 
00161     def testMeshM1D(self):
00162         meshM1D=MEDCouplingUMesh.New();
00163         self.assertRaises(InterpKernelException,meshM1D.getMeshDimension);
00164         self.assertRaises(InterpKernelException,meshM1D.getNumberOfNodes);
00165         self.assertRaises(InterpKernelException,meshM1D.getNumberOfCells);
00166         self.assertRaises(InterpKernelException,meshM1D.setMeshDimension,-2)
00167         self.assertRaises(InterpKernelException,meshM1D.setMeshDimension,-10)
00168         meshM1D.setMeshDimension(-1);
00169         meshM1D.checkCoherency();
00170         self.assertEqual(meshM1D.getMeshDimension(),-1);
00171         self.assertEqual(meshM1D.getNumberOfCells(),1);
00172         self.assertRaises(InterpKernelException,meshM1D.getNumberOfNodes);
00173         self.assertRaises(InterpKernelException,meshM1D.getSpaceDimension);
00174         cpy=meshM1D.clone(True);
00175         self.assertTrue(cpy.isEqual(meshM1D,1e-12));
00176         fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS);
00177         fieldOnCells.setMesh(meshM1D);
00178         array=DataArrayDouble.New();
00179         array.setValues(6*[7.],1,6);
00180         fieldOnCells.setArray(array);
00181         fieldOnCells.checkCoherency();
00182         pass
00183     
00184     def testDeepCopy(self):
00185         array=DataArrayDouble.New();
00186         array.setValues(5*3*[7.],5,3);
00187         self.assertEqual(array.getIJ(3,2),7.);
00188         array2=array.deepCpy();
00189         self.assertEqual(array2.getIJ(3,2),7.)
00190         #
00191         array3=DataArrayInt.New();
00192         array3.setValues(5*3*[17],5,3);
00193         self.assertEqual(array3.getIJ(3,2),17);
00194         array4=array3.deepCpy();
00195         self.assertEqual(array4.getIJ(3,2),17);
00196         pass
00197     
00198     def testRevNodal(self):
00199         mesh=MEDCouplingDataForTest.build2DTargetMesh_1()
00200         revNodal,revNodalIndx=mesh.getReverseNodalConnectivity();
00201         revNodalExpected=[0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4];
00202         revNodalIndexExpected=[0,1,3,5,7,12,14,15,17,18];
00203         self.assertEqual(revNodal.getNbOfElems(),18)
00204         self.assertEqual(revNodalIndx.getNbOfElems(),10)
00205         self.assertEqual(list(revNodal.getValues()),revNodalExpected)
00206         self.assertEqual(list(revNodalIndx.getValues()),revNodalIndexExpected)
00207         pass
00208     
00209     def testConvertToPolyTypes(self):
00210         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
00211         elts=[1,3];
00212         mesh.convertToPolyTypes(elts);
00213         mesh.checkCoherency();
00214         self.assertEqual(5,mesh.getNumberOfCells());
00215         self.assertEqual(23,mesh.getNodalConnectivity().getNumberOfTuples());
00216         expected1=[4, 0, 3, 4, 1, 5, 1, 4, 2, 3, 4, 5, 2, 5, 6, 7, 4, 3, 4, 7, 8, 5, 4]
00217         self.assertEqual(expected1,list(mesh.getNodalConnectivity().getValues()));
00218         #
00219         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
00220         mesh.convertToPolyTypes(elts);
00221         mesh.checkCoherency();
00222         self.assertEqual(8,mesh.getNumberOfCells());
00223         self.assertEqual(114,mesh.getNodalConnectivity().getNumberOfTuples());
00224         mesh.convertToPolyTypes(elts);
00225         mesh.checkCoherency();
00226         self.assertEqual(8,mesh.getNumberOfCells());
00227         self.assertEqual(114,mesh.getNodalConnectivity().getNumberOfTuples());
00228         pass
00229 
00230     def testDescConn2D(self):
00231         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
00232         desc=DataArrayInt.New();
00233         descIndx=DataArrayInt.New();
00234         revDesc=DataArrayInt.New();
00235         revDescIndx=DataArrayInt.New();
00236         mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
00237         mesh2.checkCoherency();
00238         self.assertEqual(1,mesh2.getMeshDimension());
00239         self.assertEqual(13,mesh2.getNumberOfCells());
00240         self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples());
00241         self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples());
00242         self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples());
00243         self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples());
00244         expected1=[0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9];
00245         self.assertEqual(expected1,list(desc.getValues()));
00246         expected2=[0,4,7,10,14,18];
00247         self.assertEqual(expected2,list(descIndx.getValues()));
00248         expected3=[0,1,3,5,6,8,9,11,12,13,15,16,17,18];
00249         self.assertEqual(expected3,list(revDescIndx.getValues()));
00250         expected4=[0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4];
00251         self.assertEqual(expected4,list(revDesc.getValues()));
00252         conn=mesh2.getNodalConnectivity();
00253         connIndex=mesh2.getNodalConnectivityIndex();
00254         expected5=[0,3,6,9,12,15,18,21,24,27,30,33,36,39];
00255         self.assertEqual(expected5,list(connIndex.getValues()));
00256         expected6=[1, 0, 3, 1, 3, 4, 1, 4, 1, 1, 1, 0, 1, 4, 2, 1, 2, 1, 1, 4, 5, 1, 5, 2, 1, 6, 7, 1, 7, 4, 1, 3, 6, 1, 7, 8, 1, 8, 5];
00257         self.assertEqual(expected6,list(conn.getValues()));
00258         #
00259         eltsV=[1,3];
00260         mesh.convertToPolyTypes(eltsV);
00261         mesh.checkCoherency();
00262         #
00263         desc=DataArrayInt.New();
00264         descIndx=DataArrayInt.New();
00265         revDesc=DataArrayInt.New();
00266         revDescIndx=DataArrayInt.New();
00267         #
00268         mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
00269         mesh2.checkCoherency();
00270         self.assertEqual(1,mesh2.getMeshDimension());
00271         self.assertEqual(13,mesh2.getNumberOfCells());
00272         self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples());
00273         self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples());
00274         self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples());
00275         self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples());
00276         self.assertEqual(expected1,list(desc.getValues()));
00277         self.assertEqual(expected2,list(descIndx.getValues()));
00278         self.assertEqual(expected3,list(revDescIndx.getValues()));
00279         self.assertEqual(expected4,list(revDesc.getValues()));
00280         conn=mesh2.getNodalConnectivity();
00281         connIndex=mesh2.getNodalConnectivityIndex();
00282         self.assertEqual(expected5,list(connIndex.getValues()));
00283         self.assertEqual(expected6,list(conn.getValues()));
00284         pass
00285     
00286     def testDescConn3D(self):
00287         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
00288         desc=DataArrayInt.New();
00289         descIndx=DataArrayInt.New();
00290         revDesc=DataArrayInt.New();
00291         revDescIndx=DataArrayInt.New();
00292         #
00293         mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
00294         mesh2.checkCoherency();
00295         self.assertEqual(2,mesh2.getMeshDimension());
00296         self.assertEqual(36,mesh2.getNumberOfCells());
00297         self.assertEqual(37,revDescIndx.getNbOfElems()); self.assertEqual(37,revDescIndx.getNumberOfTuples());
00298         self.assertEqual(9,descIndx.getNbOfElems()); self.assertEqual(9,descIndx.getNumberOfTuples());
00299         self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples());
00300         self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples());
00301         expected1=[0, 6, 12, 18, 24, 30, 36, 42, 48]
00302         expected2=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 11, 12, 4, 13, 14, 15, 16, 17, 10, 18, 19, 13, 1, 20, 21, 22, 23, 24, 7, 25, 26, 27, 28, 22, 12, 29, 23, 30, 31, 32, 17, 33, 28, 34, 35, 30]
00303         expected3=[0, 1, 3, 4, 6, 8, 9, 10, 12, 13, 14, 16, 17, 19, 21, 22, 23, 24, 26, 27, 28, 29, 30, 32, 34, 35, 36, 37, 38, 40, 41, 43, 44, 45, 46, 47, 48]
00304         expected4=[0, 0, 4, 0, 0, 1, 0, 2, 0, 1, 1, 5, 1, 1, 1, 3, 2, 2, 6, 2, 3, 2, 2, 3, 3, 7, 3, 3, 4, 4, 4, 5, 4, 6, 4, 5, 5, 5, 5, 7, 6, 6, 7, 6, 6, 7, 7, 7]
00305         expected5=[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180]
00306         expected6=[4, 0, 1, 4, 3, 4, 9, 12, 13, 10, 4, 0, 9, 10, 1, 4, 1, 10, 13, 4, 4, 4, 13, 12, 3, 4, 3, 12, 9, 0, 4, 1, 2, 5, 4, 4, 10, 13, 14, 11, 4, 1, 10, 11, 2, 4, 2, 11, 14,
00307                    5, 4, 5, 14, 13, 4, 4, 3, 4, 7, 6, 4, 12, 15, 16, 13, 4, 4, 13, 16, 7, 4, 7, 16, 15, 6, 4, 6, 15, 12, 3, 4, 4, 5, 8, 7, 4, 13, 16, 17, 14, 4, 5, 14, 17, 8, 4, 8,
00308                    17, 16, 7, 4, 18, 21, 22, 19, 4, 9, 18, 19, 10, 4, 10, 19, 22, 13, 4, 13, 22, 21, 12, 4, 12, 21, 18, 9, 4, 19, 22, 23, 20, 4, 10, 19, 20, 11, 4, 11, 20, 23, 14, 4,
00309                    14, 23, 22, 13, 4, 21, 24, 25, 22, 4, 13, 22, 25, 16, 4, 16, 25, 24, 15, 4, 15, 24, 21, 12, 4, 22, 25, 26, 23, 4, 14, 23, 26, 17, 4, 17, 26, 25, 16]
00310         expected7=[4, 0, 1, 4, 3, 4, 9, 12, 13, 10, 4, 0, 9, 10, 1, 4, 1, 10, 13, 4, 4, 4, 13, 12, 3, 4, 3, 12, 9, 0, 5, 1, 2, 5, 4, 5, 10, 13, 14, 11, 5, 1, 10, 11, 2, 5, 2, 11, 14,
00311                    5, 5, 5, 14, 13, 4, 4, 3, 4, 7, 6, 4, 12, 15, 16, 13, 4, 4, 13, 16, 7, 4, 7, 16, 15, 6, 4, 6, 15, 12, 3, 5, 4, 5, 8, 7, 5, 13, 16, 17, 14, 5, 5, 14, 17, 8, 5, 8,
00312                    17, 16, 7, 4, 18, 21, 22, 19, 4, 9, 18, 19, 10, 4, 10, 19, 22, 13, 4, 13, 22, 21, 12, 4, 12, 21, 18, 9, 4, 19, 22, 23, 20, 4, 10, 19, 20, 11, 4, 11, 20, 23, 14, 4,
00313                    14, 23, 22, 13, 4, 21, 24, 25, 22, 4, 13, 22, 25, 16, 4, 16, 25, 24, 15, 4, 15, 24, 21, 12, 4, 22, 25, 26, 23, 4, 14, 23, 26, 17, 4, 17, 26, 25, 16]
00314         
00315         self.assertEqual(expected1,list(descIndx.getValues()));
00316         self.assertEqual(expected2,list(desc.getValues()));
00317         self.assertEqual(expected3,list(revDescIndx.getValues()));
00318         self.assertEqual(expected4,list(revDesc.getValues()));
00319         self.assertEqual(expected5,list(mesh2.getNodalConnectivityIndex().getValues()));
00320         self.assertEqual(expected6,list(mesh2.getNodalConnectivity().getValues()));
00321         #
00322         eltsV=[1,3]
00323         mesh.convertToPolyTypes(eltsV);
00324         mesh.checkCoherency();
00325         desc=DataArrayInt.New();
00326         descIndx=DataArrayInt.New();
00327         revDesc=DataArrayInt.New();
00328         revDescIndx=DataArrayInt.New();
00329         mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx);
00330         mesh2.checkCoherency();
00331         self.assertEqual(2,mesh2.getMeshDimension());
00332         self.assertEqual(36,mesh2.getNumberOfCells());
00333         self.assertEqual(37,revDescIndx.getNbOfElems()); self.assertEqual(37,revDescIndx.getNumberOfTuples());
00334         self.assertEqual(9,descIndx.getNbOfElems()); self.assertEqual(9,descIndx.getNumberOfTuples());
00335         self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples());
00336         self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples());
00337         self.assertEqual(expected1,list(descIndx.getValues()));
00338         self.assertEqual(expected2,list(desc.getValues()));
00339         self.assertEqual(expected3,list(revDescIndx.getValues()));
00340         self.assertEqual(expected4,list(revDesc.getValues()));
00341         self.assertEqual(expected5,list(mesh2.getNodalConnectivityIndex().getValues()));
00342         self.assertEqual(expected7,list(mesh2.getNodalConnectivity().getValues()));
00343         pass
00344 
00345     def testFindBoundaryNodes(self):
00346         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
00347         boundaryNodes=mesh.findBoundaryNodes();
00348         expected1=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26];
00349         self.assertEqual(expected1,boundaryNodes.getValues());
00350         pass
00351 
00352     def testBoundaryMesh(self):
00353         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
00354         mesh2=mesh.buildBoundaryMesh(False);
00355         self.assertEqual(24,mesh2.getNumberOfCells());
00356         self.assertEqual(26,mesh2.getNumberOfNodes());
00357         pass
00358 
00359     def testBuildPartOfMySelf(self):
00360         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
00361         mesh.setName("Toto");
00362         tab1=[0,4]
00363         tab2=[0,2,3]
00364         #
00365         subMesh=mesh.buildPart(tab1)
00366         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
00367         subMesh=mesh.buildPartOfMySelf(tab1,True);
00368         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
00369         name=subMesh.getName();
00370         self.assertEqual(2,len(mesh.getAllTypes()));
00371         self.assertEqual(NORM_TRI3,mesh.getAllTypes()[0]);
00372         self.assertEqual(NORM_QUAD4,mesh.getAllTypes()[1]);
00373         self.assertEqual(1,len(subMesh.getAllTypes()));
00374         self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]);
00375         self.assertEqual(name,"PartOf_Toto");
00376         self.assertEqual(2,subMesh.getNumberOfCells());
00377         subConn=[4,0,3,4,1,4,7,8,5,4];
00378         subConnIndex=[0,5,10];
00379         self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems());
00380         self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems());
00381         self.assertEqual(subConn[0:10],list(subMesh.getNodalConnectivity().getValues()));
00382         self.assertEqual(subConnIndex[0:3],list(subMesh.getNodalConnectivityIndex().getValues()));
00383         #
00384         subMesh=mesh.buildPartOfMySelf(tab2[0:3],True);
00385         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh));
00386         name=subMesh.getName();
00387         self.assertEqual(2,len(subMesh.getAllTypes()));
00388         self.assertEqual(NORM_TRI3,subMesh.getAllTypes()[0]);
00389         self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[1]);
00390         self.assertEqual(name,"PartOf_Toto");
00391         self.assertEqual(3,subMesh.getNumberOfCells());
00392         subConn2=[4,0,3,4,1,3,4,5,2,4,6,7,4,3]
00393         subConnIndex2=[0,5,9,14]
00394         self.assertEqual(14,subMesh.getNodalConnectivity().getNbOfElems());
00395         self.assertEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems());
00396         self.assertEqual(subConn2[0:14],list(subMesh.getNodalConnectivity().getValues()));
00397         self.assertEqual(subConnIndex2[0:4],list(subMesh.getNodalConnectivityIndex().getValues()));
00398         dd=DataArrayInt.New()
00399         dd.alloc(3,1)
00400         dd.iota(0)
00401         dd.setName("coucou")
00402         subMesh=subMesh.buildPartOfMySelf(dd,True);
00403         self.assertEqual("coucou",subMesh.getName());
00404         pass
00405     
00406     def testBuildPartOfMySelfNode(self):
00407         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
00408         tab1=[5,7,8,4]
00409         subMesh=mesh.buildPartOfMySelfNode(tab1[0:4],True);
00410         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
00411         self.assertEqual(1,len(subMesh.getAllTypes()));
00412         self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]);
00413         self.assertEqual(1,subMesh.getNumberOfCells());
00414         self.assertEqual(5,subMesh.getNodalConnectivity().getNbOfElems());
00415         self.assertEqual(2,subMesh.getNodalConnectivityIndex().getNbOfElems());
00416         subConn=[4,7,8,5,4]
00417         subConnIndex=[0,5]
00418         self.assertEqual(subConn[0:5],list(subMesh.getNodalConnectivity().getValues()));
00419         self.assertEqual(subConnIndex[0:2],list(subMesh.getNodalConnectivityIndex().getValues()));
00420         #
00421         ddd=DataArrayInt.New()
00422         ddd.setValues(tab1[0:2],2,1)
00423         ddd.setName("ddd")
00424         subMesh=mesh.buildPartOfMySelfNode(ddd,False);
00425         self.assertEqual("ddd",subMesh.getName())
00426         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
00427         self.assertEqual(2,len(subMesh.getAllTypes()));
00428         self.assertEqual(NORM_TRI3,subMesh.getAllTypes()[0]);
00429         self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[1]);
00430         self.assertEqual(3,subMesh.getNumberOfCells());
00431         self.assertEqual(14,subMesh.getNodalConnectivity().getNbOfElems());
00432         self.assertEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems());
00433         subConn2=[3,4,5,2,4,6,7,4,3,4,7,8,5,4]
00434         subConnIndex2=[0,4,9,14]
00435         self.assertEqual(subConn2[0:14],list(subMesh.getNodalConnectivity().getValues()));
00436         self.assertEqual(subConnIndex2[0:4],list(subMesh.getNodalConnectivityIndex().getValues()));
00437         #testing the case where length of tab2 is greater than max number of node per cell.
00438         tab2=[0,3,2,1,4,5,6]
00439         subMesh=mesh.buildPartOfMySelfNode(tab2[0:7],True);
00440         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
00441         self.assertEqual(2,len(subMesh.getAllTypes()));
00442         self.assertEqual(NORM_TRI3,subMesh.getAllTypes()[0]);
00443         self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[1]);
00444         self.assertEqual(3,subMesh.getNumberOfCells());
00445         pass
00446     
00447     def testZipCoords(self):
00448         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
00449         self.assertEqual(2,len(mesh.getAllTypes()));
00450         self.assertEqual(2,mesh.getSpaceDimension());
00451         self.assertEqual(9,mesh.getNumberOfNodes());
00452         self.assertEqual(5,mesh.getNumberOfCells());
00453         oldConn=mesh.getNodalConnectivity().getValues()[0:mesh.getNodalConnectivity().getNbOfElems()];
00454         oldConnIndex=mesh.getNodalConnectivityIndex().getValues()[0:mesh.getNumberOfCells()+1]
00455         oldCoords=mesh.getCoords();
00456         mesh.zipCoords();
00457         self.assertEqual(2,len(mesh.getAllTypes()));
00458         self.assertEqual(2,mesh.getSpaceDimension());
00459         self.assertEqual(9,mesh.getNumberOfNodes());
00460         self.assertEqual(5,mesh.getNumberOfCells());
00461         self.assertEqual(mesh.getCoords().getValues()[0:2*9],oldCoords.getValues());
00462         self.assertEqual(list(oldConn),list(mesh.getNodalConnectivity().getValues()));
00463         self.assertEqual(list(oldConnIndex),list(mesh.getNodalConnectivityIndex().getValues()));
00464         #
00465         tab1=[0,4]
00466         subMesh=mesh.buildPartOfMySelf(tab1,True);
00467         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
00468         traducer=subMesh.zipCoordsTraducer();
00469         expectedTraducer=[0, 1, -1, 2, 3, 4, -1, 5, 6]
00470         self.assertEqual(expectedTraducer,list(traducer.getValues()));
00471         self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]);
00472         self.assertEqual(2,subMesh.getNumberOfCells());
00473         subConn=[4,0,2,3,1,4,5,6,4,3]
00474         subConnIndex=[0,5,10]
00475         self.assertEqual(7,subMesh.getNumberOfNodes());
00476         self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems());
00477         self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems());
00478         self.assertEqual(subConn,list(subMesh.getNodalConnectivity().getValues()));
00479         self.assertEqual(subConnIndex,list(subMesh.getNodalConnectivityIndex().getValues()));
00480         #
00481         subMesh=mesh.buildPartOfMySelf(tab1,False);
00482         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
00483         self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]);
00484         self.assertEqual(2,subMesh.getNumberOfCells());
00485         self.assertEqual(7,subMesh.getNumberOfNodes());
00486         self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems());
00487         self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems());
00488         self.assertEqual(subConn,list(subMesh.getNodalConnectivity().getValues()));
00489         self.assertEqual(subConnIndex,list(subMesh.getNodalConnectivityIndex().getValues()));
00490         pass
00491     
00492     def testZipConnectivity(self):
00493         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
00494         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
00495         cells1=[2,3,4]
00496         m3=m2.buildPartOfMySelf(cells1,True);
00497         self.assertTrue(isinstance(m3,MEDCouplingUMesh))
00498         m4=MEDCouplingDataForTest.build2DSourceMesh_1();
00499         m5=MEDCouplingUMesh.MergeUMeshes(m1,m3);
00500         m6=MEDCouplingUMesh.MergeUMeshes(m5,m4);
00501         #
00502         self.assertEqual(10,m6.getNumberOfCells());
00503         self.assertEqual(22,m6.getNumberOfNodes());
00504         (arr,areNodesMerged,newNbOfNodes)=m6.mergeNodes(1e-13);
00505         self.assertTrue(areNodesMerged);
00506         self.assertEqual(10,m6.getNumberOfCells());
00507         self.assertEqual(9,m6.getNumberOfNodes());
00508         #
00509         arr=m6.zipConnectivityTraducer(0);
00510         self.assertEqual(7,m6.getNumberOfCells());
00511         m7=m6.clone(True);
00512         arr=m6.zipConnectivityTraducer(0);
00513         self.assertTrue(m7.isEqual(m6,1e-12));
00514         self.assertEqual(7,m6.getNumberOfCells());
00515         pass
00516     
00517     def testEqualMesh(self):
00518         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
00519         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
00520         #
00521         self.assertTrue(mesh1.isEqual(mesh1,1e-12));
00522         #
00523         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
00524         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
00525         pt=mesh2.getCoords().getValues();
00526         tmp=pt[1]
00527         mesh2.getCoords().setIJ(0,1,5.999);
00528         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
00529         self.assertTrue(not mesh2.isEqual(mesh1,1e-12));
00530         mesh2.getCoords().setIJ(0,1,tmp);
00531         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
00532         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
00533         #
00534         pt2=mesh1.getNodalConnectivity().getValues();
00535         mesh1.getNodalConnectivity().setIJ(5,0,int(pt2[5])+1);
00536         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
00537         self.assertTrue(not mesh2.isEqual(mesh1,1e-12));
00538         mesh1.getNodalConnectivity().setIJ(5,0,int(pt2[5]));
00539         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
00540         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
00541         #
00542         pt2=mesh1.getNodalConnectivityIndex().getValues();
00543         mesh1.getNodalConnectivityIndex().setIJ(1,0,int(pt2[1]+1));
00544         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
00545         self.assertTrue(not mesh2.isEqual(mesh1,1e-12));
00546         mesh1.getNodalConnectivityIndex().setIJ(1,0,int(pt2[1]));
00547         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
00548         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
00549         #
00550         tmp3=mesh1.getName();
00551         mesh1.setName("lllll");
00552         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
00553         self.assertTrue(not mesh2.isEqual(mesh1,1e-12));
00554         mesh1.setName(tmp3);
00555         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
00556         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
00557         #
00558         tmp3=mesh2.getCoords().getInfoOnComponent(1);
00559         mesh2.getCoords().setInfoOnComponent(1,"kkkkkk");
00560         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
00561         self.assertTrue(not mesh2.isEqual(mesh1,1e-12));
00562         mesh2.getCoords().setInfoOnComponent(1,tmp3);
00563         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
00564         self.assertTrue(mesh2.isEqual(mesh1,1e-12));
00565         pass
00566     
00567     def testEqualFieldDouble(self):
00568         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
00569         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
00570         #
00571         fieldOnCells1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
00572         fieldOnCells1.setMesh(mesh1);
00573         fieldOnCells2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
00574         fieldOnCells2.setMesh(mesh2);
00575         #
00576         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00577         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00578         #
00579         fieldOnNodes1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
00580         self.assertTrue(not fieldOnCells1.isEqual(fieldOnNodes1,1e-12,1e-15));
00581         self.assertTrue(not fieldOnNodes1.isEqual(fieldOnCells1,1e-12,1e-15));
00582         #
00583         fieldOnCells2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
00584         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00585         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00586         fieldOnCells1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
00587         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00588         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00589         fieldOnCells1.setTime(4.,6,7);
00590         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00591         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00592         fieldOnCells2.setTime(4.,6,7);
00593         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00594         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00595         fieldOnCells1.setName("Power");
00596         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00597         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00598         fieldOnCells2.setName("Power");
00599         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00600         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00601         #
00602         fieldOnCells1.setMesh(mesh1);
00603         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00604         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00605         fieldOnCells2.setMesh(mesh1);
00606         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00607         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00608         arr=DataArrayDouble.New();
00609         arr.setName("popo");
00610         arr.setValues(mesh1.getNumberOfCells()*3*[6.],mesh1.getNumberOfCells(),3);
00611         fieldOnCells1.setArray(arr);
00612         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00613         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00614         fieldOnCells2.setArray(arr);
00615         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00616         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00617         #
00618         arr2=arr.deepCpy();
00619         fieldOnCells2.setArray(arr2);
00620         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00621         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00622         arr.setIJ(1,2,6.1);
00623         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00624         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00625         arr.setIJ(1,2,6.);
00626         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00627         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00628         arr2.setName("popo2");
00629         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00630         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00631         #
00632         arr2.setName("popo");
00633         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00634         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00635         #
00636         arr2.setInfoOnComponent(2,"jjj");
00637         self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00638         self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00639         arr.setInfoOnComponent(2,"jjj");
00640         self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15));
00641         self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15));
00642         pass
00643 
00644     def testNatureChecking(self):
00645         field=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
00646         field.setNature(Integral);
00647         field.setNature(ConservativeVolumic);
00648         field.setNature(IntegralGlobConstraint);
00649         field=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
00650         field.setNature(ConservativeVolumic);
00651         self.assertRaises(InterpKernelException,field.setNature,Integral);
00652         self.assertRaises(InterpKernelException,field.setNature,IntegralGlobConstraint);
00653         pass
00654 
00655     def testBuildSubMeshData(self):
00656         targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1()
00657         #check buildSubMesh on field on cells
00658         fieldCells=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
00659         fieldCells.setMesh(targetMesh);
00660         elts=[1,2,4]
00661         ret1,di=fieldCells.buildSubMeshData(elts);
00662         self.assertTrue(isinstance(ret1,MEDCouplingUMesh))
00663         self.assertEqual(3,ret1.getNumberOfCells());
00664         self.assertEqual(9,ret1.getNumberOfNodes());
00665         self.assertEqual(3,di.getNumberOfTuples());
00666         self.assertEqual(1,di.getNumberOfComponents());
00667         toCheck=di.getValues();
00668         self.assertTrue(elts,toCheck);
00669         #check buildSubMesh on field on nodes
00670         fieldNodes=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
00671         fieldNodes.setMesh(targetMesh);
00672         ret2,di=fieldNodes.buildSubMeshData(elts);
00673         self.assertTrue(isinstance(ret2,MEDCouplingUMesh))
00674         self.assertEqual(3,ret2.getNumberOfCells());
00675         self.assertEqual(6,ret2.getNumberOfNodes());
00676         self.assertEqual(6,di.getNumberOfTuples());
00677         self.assertEqual(1,di.getNumberOfComponents());
00678         toCheck=di.getValues();
00679         expected=[1,2,4,5,7,8]
00680         self.assertEqual(expected,list(toCheck));
00681         pass
00682     
00683     def testExtrudedMesh1(self):
00684         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
00685         ext=MEDCouplingExtrudedMesh.New(mesh3D,mesh2D,1);
00686         self.assertEqual(18,ext.getNumberOfCells());
00687         self.assertEqual(60,ext.getNumberOfNodes());
00688         ids3D=ext.getMesh3DIds();
00689         ids3DExpected=[5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12]
00690         self.assertEqual(18,ids3D.getNumberOfTuples());
00691         self.assertEqual(1,ids3D.getNumberOfComponents());
00692         self.assertEqual(ids3DExpected,list(ids3D.getValues()));
00693         mesh1D=ext.getMesh1D();
00694         self.assertEqual(4,mesh1D.getNumberOfNodes());
00695         self.assertEqual(3,mesh1D.getNumberOfCells());
00696         mesh1DExpected=[0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663,
00697                         1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333,
00698                         2, 0.66666666666666663, 1.4583333333333333, 3]
00699         mesh1DCoords=mesh1D.getCoords();
00700         self.assertEqual(4,mesh1DCoords.getNumberOfTuples());
00701         self.assertEqual(3,mesh1DCoords.getNumberOfComponents());
00702         self.assertEqual(mesh1DExpected,mesh1DCoords.getValues());
00703         conn1D=mesh1D.getNodalConnectivity();
00704         self.assertEqual(9,conn1D.getNumberOfTuples());
00705         self.assertEqual(1,conn1D.getNumberOfComponents());
00706         conn1DExpected=[1,0,1,1,1,2,1,2,3]
00707         self.assertEqual(conn1DExpected,list(conn1D.getValues()));
00708         pass
00709 
00710     def testExtrudedMesh3(self):
00711         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
00712         m1.changeSpaceDimension(3);
00713         m2=MEDCouplingDataForTest.buildCU1DMesh_U();
00714         m2.changeSpaceDimension(3);
00715         center=[0.,0.,0.]
00716         vector=[0.,1.,0.]
00717         m2.rotate(center,vector,-pi/2.);
00718         m3=m1.buildExtrudedMesh(m2,0);
00719         #
00720         m4=MEDCouplingExtrudedMesh.New(m3,m1,0);
00721         self.assertEqual(15,m4.getNumberOfCells());
00722         self.assertEqual(5,m4.getMesh2D().getNumberOfCells());
00723         self.assertEqual(3,m4.getMesh1D().getNumberOfCells());
00724         m3DIds=m4.getMesh3DIds().getValues();
00725         self.assertEqual(range(15),list(m3DIds));
00726         #some random in cells to check that extrusion alg find it correctly
00727         expected1=[1,3,2,0,6,5,7,10,11,8,12,9,14,13,4]
00728         m3.renumberCells(expected1,False);
00729         m4=MEDCouplingExtrudedMesh.New(m3,m1,0);
00730         self.assertEqual(15,m4.getNumberOfCells());
00731         self.assertEqual(5,m4.getMesh2D().getNumberOfCells());
00732         self.assertEqual(3,m4.getMesh1D().getNumberOfCells());
00733         m3DIds=m4.getMesh3DIds().getValues();
00734         self.assertEqual(expected1,list(m3DIds));
00735         #play with polygons and polyedrons
00736         cells=[2,3]
00737         m1.convertToPolyTypes(cells);
00738         m3=m1.buildExtrudedMesh(m2,0);
00739         self.assertEqual(NORM_HEXA8,m3.getTypeOfCell(0));
00740         self.assertEqual(NORM_PENTA6,m3.getTypeOfCell(1));
00741         self.assertEqual(NORM_POLYHED,m3.getTypeOfCell(2));
00742         self.assertEqual(NORM_POLYHED,m3.getTypeOfCell(3));
00743         self.assertEqual(NORM_HEXA8,m3.getTypeOfCell(4));
00744         m3.renumberCells(expected1,False);
00745         m4=MEDCouplingExtrudedMesh.New(m3,m1,0);
00746         self.assertEqual(15,m4.getNumberOfCells());
00747         self.assertEqual(5,m4.getMesh2D().getNumberOfCells());
00748         self.assertEqual(3,m4.getMesh1D().getNumberOfCells());
00749         m3DIds=m4.getMesh3DIds().getValues();
00750         self.assertEqual(expected1,list(m3DIds));
00751         pass
00752 
00753     def testExtrudedMesh4(self):
00754         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
00755         cells=[2,4];
00756         m1.convertToPolyTypes(cells);
00757         m1.changeSpaceDimension(3);
00758         m2=MEDCouplingDataForTest.buildCU1DMesh_U();
00759         m2.changeSpaceDimension(3);
00760         center=[0.,0.,0.]
00761         vector=[0.,1.,0.]
00762         m2.rotate(center,vector,-pi/2.);
00763         m3=m1.buildExtrudedMesh(m2,0);
00764         expected1=[1,3,2,0,6,5,7,10,11,8,12,9,14,13,4]
00765         rexpected1=[3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12]
00766         m3.renumberCells(expected1,False);
00767         m4=MEDCouplingExtrudedMesh.New(m3,m1,0);
00768         self.assertEqual(NORM_HEXA8,m4.getTypeOfCell(0));
00769         self.assertEqual(NORM_HEXA8,m4.getTypeOfCell(1));
00770         self.assertEqual(NORM_POLYHED,m4.getTypeOfCell(2));
00771         self.assertEqual(NORM_PENTA6,m4.getTypeOfCell(7));
00772         f=m4.getMeasureField(True);
00773         arr=f.getArray();
00774         self.assertEqual(15,arr.getNumberOfTuples());
00775         self.assertEqual(1,arr.getNumberOfComponents());
00776         arrPtr=arr.getValues();
00777         expected2=[0.075,0.0375,0.0375,0.075,0.075,
00778                    0.1125,0.05625,0.05625,0.1125,0.1125,
00779                    0.0625,0.03125,0.03125,0.0625,0.0625]
00780         for i in xrange(15):
00781             self.assertAlmostEqual(expected2[rexpected1[i]],arrPtr[i],16);
00782             pass
00783         m5=m4.build3DUnstructuredMesh();
00784         self.assertTrue(m5.isEqual(m3,1e-12));
00785         f=m5.getMeasureField(True);
00786         f.setMesh(m4)
00787         self.assertTrue(isinstance(f.getMesh(),MEDCouplingExtrudedMesh))
00788         arr=f.getArray();
00789         arrPtr=arr.getValues();
00790         for i in xrange(15):
00791             self.assertAlmostEqual(expected2[rexpected1[i]],arrPtr[i],15);
00792             pass
00793         pass
00794 
00795     def testFindCommonNodes(self):
00796         targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1();
00797         comm,commI=targetMesh.findCommonNodes(1e-10,-1);
00798         self.assertEqual(1,commI.getNumberOfTuples());
00799         self.assertEqual(0,comm.getNumberOfTuples());
00800         o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommonNodesFormat(comm,commI);
00801         self.assertEqual(27,newNbOfNodes);
00802         self.assertEqual(27,o2n.getNumberOfTuples());
00803         o2nExp1=range(27)
00804         self.assertEqual(o2nExp1,list(o2n.getValues()));
00805         #
00806         targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
00807         self.assertEqual(31,targetMesh.getNumberOfNodes());
00808         comm,commI=targetMesh.findCommonNodes(1e-10);# testing default parameter
00809         self.assertEqual(3,commI.getNumberOfTuples());
00810         self.assertEqual(6,comm.getNumberOfTuples());
00811         commExpected=[1,27,28,29,23,30]
00812         commIExpected=[0,4,6]
00813         self.assertEqual(commExpected,list(comm.getValues()));
00814         self.assertEqual(commIExpected,list(commI.getValues()));
00815         o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommonNodesFormat(comm,commI);
00816         self.assertEqual(31,o2n.getNumberOfTuples());
00817         self.assertEqual(27,newNbOfNodes);
00818         o2nExp2=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
00819                  21,22,23,24,25,26,1,1,1,23]
00820         self.assertEqual(o2nExp2,list(o2n.getValues()));
00821         #
00822         targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1();
00823         time=targetMesh.getTimeOfThis();
00824         o2n,areNodesMerged,newNbOfNodes=targetMesh.mergeNodes(1e-10);
00825         targetMesh.updateTime();
00826         self.assertEqual(time,targetMesh.getTimeOfThis());
00827         self.assertTrue(not areNodesMerged);
00828         #
00829         targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
00830         time=targetMesh.getTimeOfThis();
00831         o2n,areNodesMerged,newNbOfNodes=targetMesh.mergeNodes(1e-10);
00832         targetMesh.updateTime();
00833         self.assertTrue(time!=targetMesh.getTimeOfThis());
00834         self.assertTrue(areNodesMerged);
00835         connExp=[18,0,1,4,3,9,10,13,12, 18,1,2,5,4,10,11,14,13, 18,3,4,7,6,12,13,16,15,
00836                  18,4,5,8,7,13,14,17,16,
00837                  18,9,10,13,12,18,19,22,21, 18,10,11,14,13,19,20,23,22, 18,12,13,16,15,21,22,25,24,
00838                  18,13,14,17,16,22,23,26,25]
00839         self.assertEqual(72,targetMesh.getNodalConnectivity().getNumberOfTuples());
00840         self.assertEqual(connExp,list(targetMesh.getNodalConnectivity().getValues()));
00841         self.assertEqual(27,targetMesh.getCoords().getNumberOfTuples());
00842         coordsExp=[ 0., 0., 0., 50., 0., 0. , 200., 0., 0.  , 0., 50., 0., 50., 50., 0. ,
00843                     200., 50., 0.,   0., 200., 0., 50., 200., 0. , 200., 200., 0. ,
00844                     0., 0., 50., 50., 0., 50. , 200., 0., 50.  , 0., 50., 50., 50.,
00845                     50., 50. , 200., 50., 50.,   0., 200., 50., 50., 200., 50. ,
00846                     200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200.  
00847                     , 0., 50., 200., 50., 50., 200. , 200., 50., 200., 
00848                     0., 200., 200., 50., 200., 200. , 200., 200., 200. ]
00849         self.assertEqual(coordsExp,targetMesh.getCoords().getValues());
00850         # 2D
00851         targetMesh=MEDCouplingDataForTest.build2DTargetMeshMergeNode_1();
00852         self.assertEqual(18,targetMesh.getNumberOfNodes());
00853         time=targetMesh.getTimeOfThis();
00854         o2n,areNodesMerged,newNbOfNodes=targetMesh.mergeNodes(1e-10);
00855         self.assertTrue(time!=targetMesh.getTimeOfThis());
00856         self.assertTrue(areNodesMerged);
00857         self.assertEqual(9,targetMesh.getNumberOfNodes());
00858         connExp2=[4,0,4,3,1, 3,1,3,2, 3,3,5,2, 4,4,6,7,3, 4,7,8,5,3]
00859         self.assertEqual(23,targetMesh.getNodalConnectivity().getNumberOfTuples());
00860         self.assertEqual(connExp2,list(targetMesh.getNodalConnectivity().getValues()));
00861         coordsExp2=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, 0.2,0.2, -0.3,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7]
00862         self.assertEqual(9,targetMesh.getCoords().getNumberOfTuples());
00863         self.assertEqual(coordsExp2,targetMesh.getCoords().getValues());
00864         pass
00865 
00866     def testCheckButterflyCells(self):
00867         sourceMesh=MEDCouplingDataForTest.build2DTargetMesh_1();
00868         cells=sourceMesh.checkButterflyCells();
00869         self.assertEqual(0,len(cells));
00870         conn=sourceMesh.getNodalConnectivity()
00871         tmp=conn.getIJ(15,0)
00872         conn.setIJ(15,0,conn.getIJ(16,0))
00873         conn.setIJ(16,0,tmp)
00874         cells=sourceMesh.checkButterflyCells();
00875         self.assertEqual(1,len(cells));
00876         self.assertEqual([3],cells.getValues());
00877         tmp=conn.getIJ(15,0)
00878         conn.setIJ(15,0,conn.getIJ(16,0))
00879         conn.setIJ(16,0,tmp)
00880         cells=sourceMesh.checkButterflyCells();
00881         self.assertEqual(0,len(cells));
00882         # 3D surf
00883         sourceMesh=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
00884         cells=sourceMesh.checkButterflyCells();
00885         self.assertEqual(0,len(cells));
00886         conn=sourceMesh.getNodalConnectivity()
00887         tmp=conn.getIJ(15,0)
00888         conn.setIJ(15,0,conn.getIJ(16,0))
00889         conn.setIJ(16,0,tmp)
00890         cells=sourceMesh.checkButterflyCells();
00891         self.assertEqual(1,len(cells));
00892         self.assertEqual([3],cells.getValues());
00893         tmp=conn.getIJ(15,0)
00894         conn.setIJ(15,0,conn.getIJ(16,0))
00895         conn.setIJ(16,0,tmp)
00896         cells=sourceMesh.checkButterflyCells();
00897         self.assertEqual(0,len(cells));
00898         pass
00899 
00900     def testMergeMesh1(self):
00901         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
00902         m2=MEDCouplingDataForTest.build2DSourceMesh_1();
00903         vec=[1.,0.]
00904         m2.translate(vec);
00905         m3=m1.mergeMyselfWith(m2);
00906         self.assertTrue(isinstance(m3,MEDCouplingUMesh));
00907         m3.checkCoherency();
00908         m4=MEDCouplingDataForTest.build2DTargetMeshMerged_1();
00909         self.assertTrue(m3.isEqual(m4,1.e-12));
00910         da,isMerged,newNbOfNodes=m3.mergeNodes(1.e-12);
00911         self.assertEqual(11,m3.getNumberOfNodes());
00912         self.assertTrue(isMerged);
00913         pass
00914 
00915     def testMergeMeshOnSameCoords1(self):
00916         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
00917         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
00918         cells=range(5);
00919         m2.convertToPolyTypes(cells);
00920         m1.tryToShareSameCoords(m2,1e-12);
00921         m3=MEDCouplingDataForTest.build2DTargetMesh_1();
00922         m3.tryToShareSameCoords(m2,1e-12);
00923         meshes=[m1,m2,m3]
00924         m4=MEDCouplingUMesh.MergeUMeshesOnSameCoords(meshes);
00925         m4.checkCoherency();
00926         self.assertEqual(15,m4.getNumberOfCells());
00927         cells1=[0,1,2,3,4]
00928         m1_1=m4.buildPartOfMySelf(cells1,True);
00929         m1_1.setName(m1.getName());
00930         self.assertTrue(m1.isEqual(m1_1,1e-12));
00931         cells2=[5,6,7,8,9]
00932         m2_1=m4.buildPartOfMySelf(cells2,True);
00933         m2_1.setName(m2.getName());
00934         self.assertTrue(m2.isEqual(m2_1,1e-12));
00935         cells3=[10,11,12,13,14]
00936         m3_1=m4.buildPartOfMySelf(cells3,True);
00937         m3_1.setName(m3.getName());
00938         self.assertTrue(m3.isEqual(m3_1,1e-12));
00939         pass
00940 
00941     def testMergeField1(self):
00942         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
00943         m2=MEDCouplingDataForTest.build2DSourceMesh_1();
00944         vec=[1.,0.]
00945         m2.translate(vec);
00946         f1=m1.getMeasureField(True);
00947         f2=m2.getMeasureField(True);
00948         f3=MEDCouplingFieldDouble.MergeFields(f1,f2);
00949         f3.checkCoherency();
00950         m4=MEDCouplingDataForTest.build2DTargetMeshMerged_1();
00951         self.assertTrue(f3.getMesh().isEqual(m4,1.e-12));
00952         name=f3.getName();
00953         self.assertEqual(name,"MeasureOfMesh_");
00954         self.assertEqual(f3.getTypeOfField(),ON_CELLS);
00955         self.assertEqual(f3.getTimeDiscretization(),NO_TIME);
00956         self.assertEqual(1,f3.getNumberOfComponents());
00957         self.assertEqual(7,f3.getNumberOfTuples());
00958         values=[0.25,0.125,0.125,0.25,0.25,0.5,0.5]
00959         tmp=f3.getArray().getValues();
00960         self.assertEqual(len(values),len(tmp))
00961         for i in xrange(7):
00962             self.assertTrue(abs(values[i]-tmp[i])<1e-12)
00963             pass
00964         pass
00965 
00966     def testFillFromAnalytic(self):
00967         m=MEDCouplingDataForTest.build2DTargetMesh_1();             
00968         f1=m.fillFromAnalytic(ON_CELLS,1,"x+y");
00969         f1.checkCoherency();                    
00970         self.assertEqual(f1.getTypeOfField(),ON_CELLS);
00971         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
00972         self.assertEqual(1,f1.getNumberOfComponents());
00973         self.assertEqual(5,f1.getNumberOfTuples());
00974         values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
00975         tmp=f1.getArray().getValues();
00976         self.assertEqual(len(values1),len(tmp))
00977         for i in xrange(len(tmp)):
00978             self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
00979             pass
00980         #
00981         f1=m.fillFromAnalytic(ON_NODES,1,"x+y");
00982         f1.checkCoherency();
00983         self.assertEqual(f1.getTypeOfField(),ON_NODES);
00984         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
00985         self.assertEqual(1,f1.getNumberOfComponents());
00986         self.assertEqual(9,f1.getNumberOfTuples());
00987         values2=[-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4]
00988         tmp=f1.getArray().getValues();
00989         self.assertEqual(len(values2),len(tmp))
00990         for i in xrange(len(tmp)):
00991             self.assertTrue(abs(tmp[i]-values2[i])<1.e-12)
00992             pass
00993         #
00994         f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+(2*(x+y))*JVec");
00995         f1.checkCoherency();
00996         self.assertEqual(f1.getTypeOfField(),ON_NODES);
00997         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
00998         self.assertEqual(2,f1.getNumberOfComponents());
00999         self.assertEqual(9,f1.getNumberOfTuples());
01000         values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8]
01001         tmp=f1.getArray().getValues();
01002         self.assertEqual(len(values3),len(tmp))
01003         for i in xrange(len(tmp)):
01004             self.assertTrue(abs(tmp[i]-values3[i])<1.e-12)
01005             pass
01006         values4=f1.accumulate();
01007         self.assertEqual(2,len(values4))
01008         self.assertTrue(abs(3.6-values4[0])<1.e-12);
01009         self.assertTrue(abs(7.2-values4[1])<1.e-12);
01010         values4=f1.integral(True);
01011         self.assertEqual(2,len(values4))
01012         self.assertTrue(abs(0.5-values4[0])<1.e-12);
01013         self.assertTrue(abs(1.-values4[1])<1.e-12);
01014         #
01015         self.assertRaises(InterpKernelException,m.fillFromAnalytic,ON_NODES,1,"1./(x-0.2)");
01016         pass
01017 
01018     def testFillFromAnalytic2(self):
01019         m=MEDCouplingDataForTest.build2DTargetMesh_1();
01020         f1=m.fillFromAnalytic(ON_CELLS,1,"y+x");
01021         f1.checkCoherency();
01022         self.assertEqual(f1.getTypeOfField(),ON_CELLS);
01023         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
01024         self.assertEqual(1,f1.getNumberOfComponents());
01025         self.assertEqual(5,f1.getNumberOfTuples());
01026         values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
01027         tmp=f1.getArray().getValues();
01028         self.assertEqual(len(values1),len(tmp))
01029         for i in xrange(len(values1)):
01030             self.assertTrue(abs(values1[i]-tmp[i])<1.e-12);
01031             pass
01032         #
01033         f1=m.fillFromAnalytic(ON_NODES,1,"y+2*x");
01034         f1.checkCoherency();
01035         self.assertEqual(f1.getTypeOfField(),ON_NODES);
01036         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
01037         self.assertEqual(1,f1.getNumberOfComponents());
01038         self.assertEqual(9,f1.getNumberOfTuples());
01039         values2=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
01040         tmp=f1.getArray().getValues();
01041         self.assertEqual(len(values2),len(tmp))
01042         for i in xrange(len(values2)):
01043             self.assertTrue(abs(values2[i]-tmp[i])<1.e-12);
01044             pass
01045         f1=m.fillFromAnalytic(ON_NODES,1,"2.*x+y");
01046         f1.checkCoherency();
01047         self.assertEqual(f1.getTypeOfField(),ON_NODES);
01048         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
01049         self.assertEqual(1,f1.getNumberOfComponents());
01050         self.assertEqual(9,f1.getNumberOfTuples());
01051         tmp=f1.getArray().getValues();
01052         values2Bis=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
01053         self.assertEqual(len(values2Bis),len(tmp))
01054         for i in xrange(len(values2Bis)):
01055             self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
01056             pass
01057         #
01058         f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
01059         f1.checkCoherency();
01060         self.assertEqual(f1.getTypeOfField(),ON_NODES);
01061         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
01062         self.assertEqual(2,f1.getNumberOfComponents());
01063         self.assertEqual(9,f1.getNumberOfTuples());
01064         values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8]
01065         tmp=f1.getArray().getValues();
01066         self.assertEqual(len(values3),len(tmp))
01067         for i in xrange(len(values3)):
01068             self.assertTrue(abs(values3[i]-tmp[i])<1.e-12);
01069             pass
01070         values4=f1.accumulate();
01071         self.assertTrue(abs(3.6-values4[0])<1.e-12);
01072         self.assertTrue(abs(7.2-values4[1])<1.e-12);
01073         values4=f1.integral(True);
01074         self.assertTrue(abs(0.5-values4[0])<1.e-12);
01075         self.assertTrue(abs(1.-values4[1])<1.e-12);
01076         pass
01077 
01078     def testApplyFunc(self):
01079         m=MEDCouplingDataForTest.build2DTargetMesh_1();
01080         f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+(2*(x+y))*JVec");
01081         f1.checkCoherency();
01082         self.assertEqual(f1.getTypeOfField(),ON_NODES);
01083         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
01084         self.assertEqual(2,f1.getNumberOfComponents());
01085         self.assertEqual(9,f1.getNumberOfTuples());
01086         f1.applyFunc(1,"x+y");
01087         self.assertEqual(f1.getTypeOfField(),ON_NODES);
01088         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
01089         self.assertEqual(1,f1.getNumberOfComponents());
01090         self.assertEqual(9,f1.getNumberOfTuples());
01091         values1=[-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2]
01092         tmp=f1.getArray().getValues();
01093         self.assertEqual(len(values1),len(tmp))
01094         for i in xrange(len(tmp)):
01095             self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
01096             pass
01097         pass
01098 
01099     def testApplyFunc2(self):
01100         m=MEDCouplingDataForTest.build2DTargetMesh_1();
01101         f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec");
01102         f1.checkCoherency();
01103         self.assertEqual(f1.getTypeOfField(),ON_NODES);
01104         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
01105         self.assertEqual(2,f1.getNumberOfComponents());
01106         self.assertEqual(9,f1.getNumberOfTuples());
01107         #
01108         f2=f1.clone(True);
01109         self.assertRaises(InterpKernelException, f2.applyFunc, 1, "a+b+c+d");
01110         self.assertRaises(InterpKernelException, f2.applyFunc, 1, "a/0");
01111         self.assertRaises(InterpKernelException, f2.applyFunc, "a/0");
01112         f2.applyFunc("abs(u)^2.4+2*u");
01113         self.assertEqual(f1.getTypeOfField(),ON_NODES);
01114         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
01115         self.assertEqual(2,f1.getNumberOfComponents());
01116         self.assertEqual(9,f1.getNumberOfTuples());
01117         values2=[-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987,
01118                  0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987,
01119                  0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
01120                  0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295,
01121                  5.0423700574830965, 17.435300118916864]
01122         tmp=f2.getArray().getValues();
01123         self.assertEqual(len(tmp),len(values2))
01124         for i in xrange(len(tmp)):
01125             self.assertTrue(abs(tmp[i]-values2[i])<1.e-12)
01126             pass
01127         #
01128         f1.applyFunc(1,"x+y");
01129         self.assertEqual(f1.getTypeOfField(),ON_NODES);
01130         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
01131         self.assertEqual(1,f1.getNumberOfComponents());
01132         self.assertEqual(9,f1.getNumberOfTuples());
01133         values1=[-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2]
01134         tmp=f1.getArray().getValues();
01135         self.assertEqual(len(tmp),len(values1))
01136         for i in xrange(len(tmp)):
01137             self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
01138             pass
01139         pass
01140 
01141     def testOperationsOnFields(self):
01142         m=MEDCouplingDataForTest.build2DTargetMesh_1();
01143         f1=m.fillFromAnalytic(ON_NODES,1,"x+y");
01144         f2=m.fillFromAnalytic(ON_NODES,1,"x+y");
01145         f1.checkCoherency();
01146         f2.checkCoherency();
01147         f3=f1+f2;
01148         f3.checkCoherency();
01149         self.assertEqual(f3.getTypeOfField(),ON_NODES);
01150         self.assertEqual(f3.getTimeDiscretization(),NO_TIME);
01151         values1=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8]
01152         tmp=f3.getArray().getValues();
01153         self.assertEqual(len(values1),len(tmp))
01154         for i in xrange(len(tmp)):
01155             self.assertTrue(abs(tmp[i]-values1[i])<1.e-12)
01156             pass
01157         #
01158         f3=f1*f2;
01159         f3.checkCoherency();
01160         self.assertEqual(f3.getTypeOfField(),ON_NODES);
01161         self.assertEqual(f3.getTimeDiscretization(),NO_TIME);
01162         values2=[0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96]
01163         tmp=f3.getArray().getValues();
01164         self.assertEqual(len(values2),len(tmp))
01165         for i in xrange(len(tmp)):
01166             self.assertTrue(abs(tmp[i]-values2[i])<1.e-12)
01167             pass
01168         #
01169         f3=f1+f2;
01170         f4=f1-f3;
01171         f4.checkCoherency();
01172         self.assertEqual(f4.getTypeOfField(),ON_NODES);
01173         self.assertEqual(f4.getTimeDiscretization(),NO_TIME);
01174         values3=[0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4]
01175         tmp=f4.getArray().getValues();
01176         self.assertEqual(len(values3),len(tmp))
01177         for i in xrange(len(tmp)):
01178             self.assertTrue(abs(tmp[i]-values3[i])<1.e-12)
01179             pass
01180         #
01181         f3=f1+f2;
01182         f4=f3/f2;
01183         f4.checkCoherency();
01184         self.assertEqual(f4.getTypeOfField(),ON_NODES);
01185         self.assertEqual(f4.getTimeDiscretization(),NO_TIME);
01186         tmp=f4.getArray().getValues();
01187         for i in xrange(len(tmp)):
01188             self.assertTrue(abs(tmp[i]-2.)<1.e-12)
01189             pass
01190         #
01191         f4=f2.buildNewTimeReprFromThis(ONE_TIME,False);
01192         f4.checkCoherency();
01193         self.assertEqual(f4.getTypeOfField(),ON_NODES);
01194         self.assertEqual(f4.getTimeDiscretization(),ONE_TIME);
01195         self.assertRaises(InterpKernelException,f1.__add__,f4);
01196         f5=f4.buildNewTimeReprFromThis(NO_TIME,False);
01197         self.assertEqual(f5.getTypeOfField(),ON_NODES);
01198         self.assertEqual(f5.getTimeDiscretization(),NO_TIME);
01199         f3=f1+f5;
01200         tmp=f3.getArray().getValues();
01201         values4=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8]
01202         self.assertEqual(len(values3),len(tmp))
01203         for i in xrange(len(tmp)):
01204             self.assertTrue(abs(tmp[i]-values4[i])<1.e-12)
01205             pass
01206         #
01207         f4=f2.buildNewTimeReprFromThis(ONE_TIME,True);
01208         f4.checkCoherency();
01209         self.assertEqual(f4.getTypeOfField(),ON_NODES);
01210         self.assertEqual(f4.getTimeDiscretization(),ONE_TIME);
01211         self.assertRaises(InterpKernelException,f1.__add__,f4);
01212         f5=f4.buildNewTimeReprFromThis(NO_TIME,True);
01213         self.assertEqual(f5.getTypeOfField(),ON_NODES);
01214         self.assertEqual(f5.getTimeDiscretization(),NO_TIME);
01215         f3=f1+f5;
01216         tmp=f3.getArray().getValues();
01217         values5=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8]
01218         self.assertEqual(len(values5),len(tmp))
01219         for i in xrange(len(tmp)):
01220             self.assertTrue(abs(tmp[i]-values5[i])<1.e-12)
01221             pass
01222         pass
01223 
01224     def testOperationsOnFields2(self):
01225         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
01226         f1=m.fillFromAnalytic(ON_NODES,1,"x+y+z");
01227         f2=m.fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
01228         f3=f1/f2;
01229         f3.checkCoherency();
01230         self.assertEqual(f3.getTypeOfField(),ON_NODES);
01231         self.assertEqual(f3.getTimeDiscretization(),NO_TIME);
01232         expected1=[-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
01233                    0.7407407407407407, 1.129032258064516, 0.81632653061224492,
01234                    0.86538461538461531, 1.0919540229885056, 0.84302325581395343]
01235         self.assertEqual(1,f3.getNumberOfComponents());
01236         self.assertEqual(9,f3.getNumberOfTuples());
01237         val=f3.getArray().getValues();
01238         for i in xrange(9):
01239             self.assertTrue(abs(expected1[i]-val[i])<1.e-12);
01240         #
01241         f1=m.buildOrthogonalField();
01242         f2=m.fillFromAnalytic(ON_CELLS,1,"x");
01243         f3=f1*f2;
01244         expected2=[-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637]
01245         val=f3.getArray().getValues();
01246         for i in xrange(15):
01247             self.assertTrue(abs(expected2[i]-val[i])<1.e-12);
01248             pass
01249         #
01250         f3=f2*f1;
01251         val=f3.getArray().getValues();
01252         for i in xrange(15):
01253             self.assertTrue(abs(expected2[i]-val[i])<1.e-12);
01254             pass
01255         pass
01256 
01257     def testOperationsOnFields3(self):
01258         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
01259         f1=m.fillFromAnalytic(ON_NODES,1,"x+y+z");
01260         f2=m.fillFromAnalytic(ON_NODES,1,"a*a+b+c*c");
01261         f1/=f2
01262         f1.checkCoherency();
01263         self.assertEqual(f1.getTypeOfField(),ON_NODES);
01264         self.assertEqual(f1.getTimeDiscretization(),NO_TIME);
01265         expected1=[-2.4999999999999991, 1.2162162162162162, 0.77868852459016391,
01266                    0.7407407407407407, 1.129032258064516, 0.81632653061224492,
01267                    0.86538461538461531, 1.0919540229885056, 0.84302325581395343]
01268         self.assertEqual(1,f1.getNumberOfComponents());
01269         self.assertEqual(9,f1.getNumberOfTuples());
01270         val=f1.getArray().getValues();
01271         for i in xrange(9):
01272             self.assertTrue(abs(expected1[i]-val[i])<1.e-12);
01273             pass
01274         #
01275         f1=m.buildOrthogonalField();
01276         f2=m.fillFromAnalytic(ON_CELLS,1,"x");
01277         f1*=f2
01278         expected2=[-0.035355339059327376,0.,0.035355339059327376, 0.2592724864350674,0.,-0.2592724864350674, 0.37712361663282529,0.,-0.37712361663282529, -0.035355339059327376,0.,0.035355339059327376, 0.31819805153394637,0.,-0.31819805153394637]
01279         val=f1.getArray().getValues();
01280         for i in xrange(15):
01281             self.assertTrue(abs(expected2[i]-val[i])<1.e-12);
01282             pass
01283         #
01284         f1=m.buildOrthogonalField();
01285         # to avoid valgrind leaks
01286         # self.assertRaises(InterpKernelException,f2.__imul__,f1);
01287         pass
01288 
01289     def testOperationsOnFields4(self):
01290         m=MEDCouplingDataForTest.build2DTargetMesh_1();
01291         nbOfCells=m.getNumberOfCells();
01292         f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
01293         f1.setMesh(m);
01294         array=DataArrayDouble.New();
01295         f1.setArray(array);
01296         self.assertRaises(InterpKernelException,f1.setEndArray,array);
01297         self.assertRaises(InterpKernelException,f1.getEndArray);
01298         arr1=[0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.]
01299         arr2=[5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.]
01300         array.setValues(arr1,nbOfCells,3);
01301         f1.setStartTime(2.,0,0);
01302         f1.setEndTime(3.,0,0);
01303         f1.checkCoherency();
01304         pos=[0.3,-0.2]
01305         res=f1.getValueOn(pos);
01306         self.assertTrue(abs(arr1[3]-res[0])<1.e-12);
01307         self.assertTrue(abs(arr1[4]-res[1])<1.e-12);
01308         self.assertTrue(abs(arr1[5]-res[2])<1.e-12);
01309         res=None
01310         res=f1.getValueOn(pos,2.2);
01311         self.assertTrue(abs(arr1[3]-res[0])<1.e-12);
01312         self.assertTrue(abs(arr1[4]-res[1])<1.e-12);
01313         self.assertTrue(abs(arr1[5]-res[2])<1.e-12);
01314         res=None
01315         self.assertRaises(InterpKernelException,f1.getValueOn,pos,3.2)
01316         f2=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
01317         f2.setMesh(m);
01318         f2.setArray(f1.getArray());
01319         f2.setStartTime(2.,3,0);
01320         f2.setEndTime(4.,13,0);
01321         self.assertRaises(InterpKernelException,f2.checkCoherency)
01322         array2=DataArrayDouble.New();
01323         array2.setValues(arr2,nbOfCells,3);
01324         f2.setEndArray(array2);
01325         f2.checkCoherency();
01326         #
01327         res=None
01328         res=f2.getValueOn(pos,3.21);
01329         self.assertTrue(abs(4.025-res[0])<1.e-12);
01330         self.assertTrue(abs(14.025-res[1])<1.e-12);
01331         self.assertTrue(abs(24.025-res[2])<1.e-12);
01332         f3=f2.clone(True);
01333         self.assertTrue(f2.isEqual(f3,1e-12,1e-12));
01334         f3.getEndArray().setIJ(0,0,5.001);
01335         self.assertTrue(not f2.isEqual(f3,1e-12,1e-12));
01336         self.assertTrue(f2.isEqual(f3,1e-12,1e-2));
01337         f3.setStartTime(2.1,3,0);
01338         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
01339         f3.setStartTime(2.,3,0);
01340         self.assertTrue(f2.isEqual(f3,1e-12,1e-2));
01341         f3.setStartTime(2.,4,0);
01342         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
01343         f3.setStartTime(2.,3,1);
01344         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
01345         f3.setStartTime(2.,3,0);
01346         self.assertTrue(f2.isEqual(f3,1e-12,1e-2));
01347         f3.setEndTime(4.1,13,0);
01348         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
01349         f3.setEndTime(4.,13,0);
01350         self.assertTrue(f2.isEqual(f3,1e-12,1e-2));
01351         f3.setEndTime(4.,14,0);
01352         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
01353         f3.setEndTime(4.,13,1);
01354         self.assertTrue(not f2.isEqual(f3,1e-12,1e-2));
01355         f3.setEndTime(4.,13,0);
01356         self.assertTrue(f2.isEqual(f3,1e-12,1e-2));
01357         f4=f2+f2
01358         res=None
01359         res=f4.getValueOn(pos,3.21);
01360         self.assertTrue(abs(8.05-res[0])<1.e-12);
01361         self.assertTrue(abs(28.05-res[1])<1.e-12);
01362         self.assertTrue(abs(48.05-res[2])<1.e-12);
01363         f4+=f2;
01364         res=None
01365         res=f4.getValueOn(pos,3.21);
01366         self.assertTrue(abs(12.075-res[0])<1.e-12);
01367         self.assertTrue(abs(42.075-res[1])<1.e-12);
01368         self.assertTrue(abs(72.075-res[2])<1.e-12);
01369         pass
01370     
01371     def testMergeNodesOnField(self):
01372         targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
01373         f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z");
01374         f1.mergeNodes(1e-10);
01375         #
01376         targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
01377         f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z");
01378         tmp=f1.getArray()
01379         tmp.setIJ(0,0,1000.);
01380         f1.mergeNodes(1e-10);
01381         #
01382         targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1();
01383         f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z");
01384         tmp=f1.getArray()
01385         tmp.setIJ(1,0,1000.);
01386         self.assertRaises(InterpKernelException,f1.mergeNodes,1.e-10)
01387         pass
01388 
01389     def testCheckConsecutiveCellTypes(self):
01390         sourceMesh=MEDCouplingDataForTest.build2DSourceMesh_1();
01391         targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1();
01392         self.assertTrue(sourceMesh.checkConsecutiveCellTypes());
01393         order1=[NORM_TRI3,NORM_QUAD4]
01394         order2=[NORM_QUAD4,NORM_TRI3]
01395         self.assertTrue(not targetMesh.checkConsecutiveCellTypes());
01396         self.assertTrue(not targetMesh.checkConsecutiveCellTypesAndOrder(order1));
01397         self.assertTrue(not targetMesh.checkConsecutiveCellTypesAndOrder(order2));
01398         da=targetMesh.getRenumArrForConsecutiveCellTypesSpec(order1);
01399         self.assertEqual(5,da.getNumberOfTuples());
01400         self.assertEqual(1,da.getNumberOfComponents());
01401         expected1=[2,0,1,3,4]
01402         self.assertTrue(expected1==list(da.getValues()));
01403         da=targetMesh.getRenumArrForConsecutiveCellTypesSpec(order2);
01404         self.assertEqual(5,da.getNumberOfTuples());
01405         self.assertEqual(1,da.getNumberOfComponents());
01406         expected2=[0,3,4,1,2]
01407         self.assertTrue(expected2==list(da.getValues()));
01408         renumber1=[4,0,1,2,3]
01409         targetMesh.renumberCells(renumber1,False);
01410         self.assertTrue(targetMesh.checkConsecutiveCellTypes());
01411         self.assertTrue(targetMesh.checkConsecutiveCellTypesAndOrder(order1));
01412         self.assertTrue(not targetMesh.checkConsecutiveCellTypesAndOrder(order2));
01413         pass
01414 
01415     def testRearrange2ConsecutiveCellTypes(self):
01416         m1_1=MEDCouplingDataForTest.build2DSourceMesh_1();
01417         m2_1=MEDCouplingDataForTest.build2DTargetMesh_1();
01418         arr1=m1_1.rearrange2ConsecutiveCellTypes();
01419         m1_2=MEDCouplingDataForTest.build2DSourceMesh_1();
01420         self.assertTrue(m1_2.isEqual(m1_1,1e-12));
01421         expected1=[0,1]
01422         self.assertEqual(2,arr1.getNumberOfTuples());
01423         self.assertEqual(1,arr1.getNumberOfComponents());
01424         self.assertEqual(expected1,arr1.getValues());
01425         expected2=[0,3,4,1,2]
01426         arr1=m2_1.rearrange2ConsecutiveCellTypes();
01427         self.assertEqual(5,arr1.getNumberOfTuples());
01428         self.assertEqual(1,arr1.getNumberOfComponents());
01429         self.assertEqual(expected2,list(arr1.getValues()));
01430         m2_2=MEDCouplingDataForTest.build2DTargetMesh_1();
01431         self.assertEqual(5,arr1.getNumberOfTuples());
01432         self.assertEqual(1,arr1.getNumberOfComponents());
01433         self.assertEqual(expected2,list(arr1.getValues()));
01434         self.assertTrue(not m2_2.isEqual(m2_1,1e-12));
01435         m2_2.renumberCells(expected2,False);
01436         self.assertTrue(m2_2.isEqual(m2_1,1e-12));
01437         pass
01438 
01439     def testSplitByType(self):
01440         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
01441         v=m1.splitByType();
01442         self.assertEqual(3,len(v));
01443         m2=MEDCouplingUMesh.MergeUMeshesOnSameCoords(v);
01444         m2.setName(m1.getName());
01445         self.assertTrue(m1.isEqual(m2,1.e-12));
01446         pass
01447 
01448     def testFuseUMeshesOnSameCoords(self):
01449         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
01450         cells1=[2,3,4]
01451         m3=m2.buildPartOfMySelf(cells1,True);
01452         self.assertTrue(isinstance(m3,MEDCouplingUMesh))
01453         cells2=[1,2,4]
01454         m4=m2.buildPartOfMySelf(cells2,True);
01455         self.assertTrue(isinstance(m4,MEDCouplingUMesh))
01456         cells3=[1,2]
01457         m5=m2.buildPartOfMySelf(cells3,True);
01458         self.assertTrue(isinstance(m5,MEDCouplingUMesh))
01459         meshes=[m3,m4,m5]
01460         #
01461         m7,corr=MEDCouplingUMesh.FuseUMeshesOnSameCoords(meshes,0);
01462         self.assertEqual(4,m7.getNumberOfCells());
01463         self.assertEqual(3,len(corr));
01464         expectedVals1=[3,3,2]
01465         expectedVals2=[[0,1,2],[3,0,2],[3,0]]
01466         for i in xrange(3):
01467             arr=corr[i];
01468             self.assertEqual(1,arr.getNumberOfComponents());
01469             nbOfVals=expectedVals1[i];
01470             self.assertEqual(nbOfVals,arr.getNumberOfTuples());
01471             vals=arr.getValues();
01472             self.assertEqual(expectedVals2[i],list(vals));
01473             pass
01474         arr2,fidsOfGroups=DataArrayInt.MakePartition(corr,m7.getNumberOfCells());
01475         fidExp=[5,1,3,4]
01476         fidsGrp=[[1,3,5],[3,4,5],[4,5]]
01477         self.assertEqual(3,len(fidsOfGroups));
01478         self.assertEqual(1,arr2.getNumberOfComponents());
01479         self.assertEqual(4,arr2.getNumberOfTuples());
01480         self.assertEqual(fidExp,list(arr2.getValues()));
01481         for i in xrange(3):
01482             nbOfVals=expectedVals1[i];
01483             self.assertEqual(list(fidsOfGroups[i]),fidsGrp[i]);
01484             pass
01485         pass
01486 
01487     def testFuseUMeshesOnSameCoords2(self):
01488         m1,m2=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
01489         part1=[2,3,6,4,10]
01490         m3=m1.buildPartOfMySelf(part1,True);
01491         part2=[5,6,4,7]
01492         m4=m1.buildPartOfMySelf(part2,True);
01493         meshes=[m1,m3,m3,m4]
01494         m5,corr=MEDCouplingUMesh.FuseUMeshesOnSameCoords(meshes,0);
01495         self.assertEqual(18,m5.getNumberOfCells());
01496         exp2=[
01497             [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],
01498             [2,3,6,4,10],
01499             [2,3,6,4,10],
01500             [5,6,4,7]]
01501         i=0;
01502         for it in corr:
01503             self.assertEqual(exp2[i],list(it.getValues()));
01504             i+=1
01505             pass
01506         pass
01507 
01508     def testBuildOrthogonalField(self):
01509         targetMesh=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
01510         field=targetMesh.buildOrthogonalField();
01511         expected=[0.70710678118654746,0.,-0.70710678118654746]
01512         self.assertEqual(5,field.getNumberOfTuples());
01513         self.assertEqual(3,field.getNumberOfComponents());
01514         vals=field.getArray().getValues();
01515         for i in xrange(15):
01516             self.assertTrue(abs(expected[i%3]-vals[i])<1e-12);
01517         # testing
01518         targetCoords=[0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.]
01519         targetConn=[0,1,2,3]
01520         targetMesh=MEDCouplingUMesh.New();
01521         targetMesh.setMeshDimension(2);
01522         targetMesh.allocateCells(1);
01523         targetMesh.insertNextCell(NORM_QUAD4,targetConn[0:4])
01524         targetMesh.finishInsertingCells();
01525         myCoords=DataArrayDouble.New();
01526         myCoords.setValues(targetCoords,4,3);
01527         targetMesh.setCoords(myCoords);
01528         field=targetMesh.buildOrthogonalField();
01529         self.assertEqual(1,field.getNumberOfTuples());
01530         self.assertEqual(3,field.getNumberOfComponents());
01531         vals=field.getArray().getValues();
01532         self.assertTrue(abs(-0.70710678118654746-vals[0])<1e-12);
01533         self.assertTrue(abs(0.-vals[1])<1e-12);
01534         self.assertTrue(abs(0.70710678118654746-vals[2])<1e-12);
01535         pass
01536 
01537     def testGetCellsContainingPoint(self):
01538         targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1();
01539         pos=[0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.]
01540         #2D basic
01541         t1,t2=targetMesh.getCellsContainingPoints(pos,6,1e-12);
01542         self.assertEqual(6,t1.getNumberOfTuples());
01543         self.assertEqual(1,t1.getNumberOfComponents());
01544         self.assertEqual(7,t2.getNumberOfTuples());
01545         self.assertEqual(1,t2.getNumberOfComponents());
01546         expectedValues1=[0,4,3,0,1,2]
01547         expectedValues2=[0,1,2,3,4,5,6]
01548         self.assertEqual(list(t1.getValues()),expectedValues1);
01549         self.assertEqual(list(t2.getValues()),expectedValues2);
01550         #2D with no help of bounding box.
01551         center=[0.2,0.2]
01552         MEDCouplingPointSet.Rotate2DAlg(center,0.78539816339744830962,6,pos);
01553         targetMesh.rotate(center,[],0.78539816339744830962);
01554         t1=None
01555         t2=None
01556         t1,t2=targetMesh.getCellsContainingPoints(pos,6,1e-12);
01557         self.assertEqual(6,t1.getNumberOfTuples());
01558         self.assertEqual(7,t2.getNumberOfTuples());
01559         self.assertEqual(list(t1.getValues()),expectedValues1);
01560         self.assertEqual(list(t2.getValues()),expectedValues2);
01561         #2D outside
01562         pos1bis=[-0.3303300858899107,-0.11819805153394641]
01563         self.assertEqual(-1,targetMesh.getCellContainingPoint(pos1bis,1e-12));
01564         #test limits 2D
01565         targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1();
01566         pos2=[0.2,-0.05]
01567         t1=None
01568         t1=targetMesh.getCellsContainingPoint(pos2,1e-12)
01569         self.assertEqual(2,len(t1));
01570         expectedValues3=[0,1]
01571         self.assertEqual(list(t1.getValues()),expectedValues3);
01572         pos3=[0.2,0.2]
01573         t1=None
01574         t1=targetMesh.getCellsContainingPoint(pos3,1e-12);
01575         self.assertEqual(5,len(t1));
01576         expectedValues4=[0,1,2,3,4]
01577         self.assertEqual(list(t1.getValues()),expectedValues4);
01578         self.assertEqual(0,targetMesh.getCellContainingPoint(pos3,1e-12));
01579         #3D
01580         targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1();
01581         pos4=[25.,25.,25.]
01582         self.assertEqual(0,targetMesh.getCellContainingPoint(pos4,1e-12));
01583         pos5=[50.,50.,50.]
01584         t1=None
01585         t1=targetMesh.getCellsContainingPoint(pos5,1e-12);
01586         self.assertEqual(8,len(t1));
01587         expectedValues5=[0,1,2,3,4,5,6,7]
01588         self.assertEqual(list(t1.getValues()),expectedValues5);
01589         pos6=[0., 50., 0.]
01590         t1=None
01591         t1=targetMesh.getCellsContainingPoint(pos6,1e-12);
01592         self.assertEqual(2,len(t1));
01593         expectedValues6=[0,2]
01594         self.assertEqual(list(t1.getValues()),expectedValues6);
01595         #3D outside
01596         pos7=[-1.0,-1.0,0.]
01597         self.assertEqual(-1,targetMesh.getCellContainingPoint(pos7,1e-12));
01598         #3D outside 2
01599         center2=[0.,0.,0.]
01600         vec2=[0.,-1.,0.]
01601         targetMesh.rotate(center2,vec2,0.78539816339744830962);
01602         pos8=[-25.,25.,12.]
01603         self.assertEqual(-1,targetMesh.getCellContainingPoint(pos8,1e-12));
01604         pass
01605 
01606     def testGetValueOn1(self):
01607         targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1();
01608         fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS);
01609         nbOfCells=targetMesh.getNumberOfCells();
01610         fieldOnCells.setMesh(targetMesh);
01611         array=DataArrayDouble.New();
01612         tmp=2*nbOfCells*[None]
01613         for i in xrange(nbOfCells):
01614             tmp[2*i]=7.+float(i);
01615             tmp[2*i+1]=17.+float(i)
01616             pass
01617         array.setValues(tmp,nbOfCells,2);
01618         fieldOnCells.setArray(array);
01619         #
01620         pos1=[0.25,0.]
01621         res=fieldOnCells.getValueOn(pos1);
01622         self.assertEqual(2,len(res))
01623         self.assertTrue(abs(8.-res[0])<1e-12);
01624         self.assertTrue(abs(18.-res[1])<1e-12);
01625         #
01626         #
01627         targetMesh=MEDCouplingDataForTest.build2DSourceMesh_1();
01628         fieldOnNodes=MEDCouplingFieldDouble.New(ON_NODES);
01629         nbOfNodes=targetMesh.getNumberOfNodes();
01630         fieldOnNodes.setMesh(targetMesh);
01631         array=DataArrayDouble.New();
01632         tmp=2*nbOfNodes*[None]
01633         for i in xrange(nbOfNodes):
01634             tmp[2*i]=17.+float(i);
01635             tmp[2*i+1]=27.+float(i)
01636             pass
01637         array.setValues(tmp,nbOfNodes,2);
01638         fieldOnNodes.setArray(array);
01639         #
01640         pos2=[-0.13333333333333333,-0.13333333333333333]
01641         res=None
01642         res=fieldOnNodes.getValueOn(pos2);
01643         self.assertEqual(2,len(res))
01644         self.assertTrue(abs(17.5-res[0])<1e-12);
01645         self.assertTrue(abs(27.5-res[1])<1e-12);
01646         pos3=[0.033333333333333326,0.36666666666666664]
01647         res=None
01648         res=fieldOnNodes.getValueOn(pos3);
01649         self.assertEqual(2,len(res))
01650         self.assertTrue(abs(18.666666666666667-res[0])<1e-12);
01651         self.assertTrue(abs(28.666666666666667-res[1])<1e-12);
01652         pass
01653 
01654     def testCMesh0(self):
01655         mesh=MEDCouplingCMesh.New();
01656         meshEmpty=mesh.clone(True);
01657         self.assertTrue(meshEmpty.isEqual(mesh, 1e-12));
01658         
01659         coordsX=DataArrayDouble.New();
01660         arrX=[ -1., 1., 2., 4. ]
01661         coordsX.setValues(arrX, 4, 1);
01662         coordsY=DataArrayDouble.New();
01663         arrY=[ -2., 2., 4., 8. ]
01664         coordsY.setValues(arrY, 4, 1);
01665         coordsZ=DataArrayDouble.New();
01666         arrZ=[ -3., 3., 6., 12. ]
01667         coordsZ.setValues(arrZ, 4, 1);
01668         mesh.setCoords(coordsX, coordsY, coordsZ);
01669         #
01670         fieldOnNodes=mesh.fillFromAnalytic(ON_NODES, 1, "x+y/2.+z/3.");
01671         self.assertEqual(1, fieldOnNodes.getNumberOfComponents());
01672         self.assertEqual(64, fieldOnNodes.getNumberOfTuples());
01673         expected1=[-3., -1., 0., 2., -1., 1., 2., 4., 0., 2., 3., 5., 2., 4., 5., 7., -1., 1., 2.,
01674                     4., 1., 3., 4., 6., 2., 4., 5., 7., 4., 6., 7., 9., 0., 2., 3., 5., 2., 4., 5.,
01675                     7., 3., 5., 6., 8., 5., 7., 8., 10., 2., 4., 5.,
01676                     7., 4., 6., 7., 9., 5., 7., 8., 10., 7., 9., 10., 12.];
01677         
01678         val=fieldOnNodes.getArray().getValues();
01679         for i in xrange(64):
01680           self.assertAlmostEqual(expected1[i], val[i], 12)
01681         res=fieldOnNodes.getValueOnPos(1, 3, 2);
01682         self.assertAlmostEqual(7., res[0], 12);
01683         #
01684         fieldOnCells=mesh.fillFromAnalytic(ON_CELLS, 1, "x+y/2.+z/3.");
01685         self.assertEqual(1, fieldOnCells.getNumberOfComponents());
01686         self.assertEqual(27, fieldOnCells.getNumberOfTuples());
01687         val=fieldOnCells.getArray().getValues();
01688         expected2=[0, 1.5, 3, 1.5, 3, 4.5, 3, 4.5, 6, 1.5, 3, 4.5, 3, 4.5,
01689                     6, 4.5, 6, 7.5, 3, 4.5, 6, 4.5, 6, 7.5, 6, 7.5, 9];
01690         for i in xrange(27):
01691           self.assertAlmostEqual(expected2[i], val[i], 12);
01692         #res=fieldOnCells.getValueOnPos(1,2,1);
01693         #self.assertAlmostEqual(6.,res,12);
01694         #
01695         meshDeepCopy=mesh.deepCpy();
01696         meshClone=mesh.clone(False);
01697         
01698         meshEmpty.copyTinyStringsFrom(mesh);
01699         #no data in meshEmpty, expected False
01700         self.assertTrue(not meshEmpty.isEqual(mesh, 1e-12));
01701         
01702         self.assertTrue(meshDeepCopy.isEqual(mesh, 1e-12));
01703         meshDeepCopy.copyTinyStringsFrom(mesh);
01704         self.assertTrue(meshDeepCopy.isEqual(mesh, 1e-12));
01705         self.assertTrue(meshClone.isEqual(mesh, 1e-12));
01706         
01707         self.assertEqual(CARTESIAN, mesh.getType());
01708         self.assertEqual(CARTESIAN, meshEmpty.getType());
01709         self.assertEqual(CARTESIAN, meshDeepCopy.getType());
01710         self.assertEqual(CARTESIAN, meshClone.getType());
01711         pass
01712 
01713     def testCMesh1(self):
01714         mesh1=MEDCouplingCMesh.New();
01715         coordsX1=DataArrayDouble.New();
01716         arrX1=[ -1., 1., 2., 4. ]
01717         coordsX1.setValues(arrX1, 4, 1);
01718         coordsY1=DataArrayDouble.New();
01719         arrY1=[ -2., 2., 4., 8. ]
01720         coordsY1.setValues(arrY1, 4, 1);
01721         coordsZ1=DataArrayDouble.New();
01722         arrZ1=[ -3., 3., 6., 12. ]
01723         coordsZ1.setValues(arrZ1, 4, 1);
01724         mesh1.setCoords(coordsX1, coordsY1, coordsZ1);
01725         
01726         mesh2=MEDCouplingCMesh.New();
01727         coordsX2=DataArrayDouble.New();
01728         arrX2=[ -1., 1., 2., 4. ]
01729         coordsX2.setValues(arrX2, 4, 1);
01730         coordsY2=DataArrayDouble.New();
01731         arrY2=[ -2., 2., 4., 8. ]
01732         coordsY2.setValues(arrY2, 4, 1);
01733         coordsZ2=DataArrayDouble.New();
01734         arrZ2=[ -3., 3., 6., 12.+1e-6 ]
01735         coordsZ2.setValues(arrZ2, 4, 1);
01736         mesh2.setCoords(coordsX2, coordsY2, coordsZ2);
01737         
01738         mesh3=MEDCouplingCMesh.New();
01739         coordsX3=DataArrayDouble.New();
01740         arrX3=[-1.]
01741         coordsX3.setValues(arrX3, 1, 1);
01742         coordsY3=DataArrayDouble.New();
01743         arrY3=[-2.]
01744         coordsY3.setValues(arrY3, 1, 1);
01745         coordsZ3=DataArrayDouble.New();
01746         arrZ3=[-3.]
01747         coordsZ3.setValues(arrZ3, 1, 1);
01748         mesh3.setCoords(coordsX3, coordsY3, coordsZ3);
01749         
01750         self.assertEqual(3, mesh1.getSpaceDimension());
01751         self.assertEqual(3, mesh1.getMeshDimension());
01752         
01753         self.assertTrue(not mesh1.isEqual(mesh2, 1e-12));
01754         self.assertTrue(not mesh2.isEqual(mesh1, 1e-12));
01755         self.assertTrue(not mesh2.isEqualWithoutConsideringStr(mesh1, 1e-12));
01756         self.assertTrue(mesh1.isEqual(mesh2, 1e-5));
01757         self.assertTrue(not mesh1.isEqual(mesh2, 1e-7));
01758         
01759         self.assertRaises(InterpKernelException, mesh3.checkCoherency1, 1e-12);
01760         mesh1.checkCoherency2(1e-12);
01761         self.assertEqual(NORM_HEXA8, mesh1.getTypeOfCell(1));
01762         
01763         self.assertEqual(NORM_HEXA8, mesh1.getAllGeoTypes()[0]);
01764         self.assertEqual(27, mesh1.getNumberOfCellsWithType(NORM_HEXA8));
01765         self.assertRaises(InterpKernelException, mesh1.getNumberOfCellsWithType, NORM_QUAD4);
01766         
01767         coo=mesh1.getCoordinatesOfNode(0);
01768         self.assertEqual(3, len(coo));
01769         self.assertAlmostEqual(-1., coo[0], 14);
01770         self.assertAlmostEqual(-2., coo[1], 14);
01771         self.assertAlmostEqual(-3., coo[2], 14);
01772         coo=mesh1.getCoordinatesOfNode(63);
01773         self.assertEqual(3, len(coo));
01774         self.assertAlmostEqual(4., coo[0], 14);
01775         self.assertAlmostEqual(8., coo[1], 14);
01776         self.assertAlmostEqual(12., coo[2], 14);
01777         
01778         a=str(mesh1)
01779         repr=mesh1.simpleRepr();
01780         repr=mesh1.advancedRepr();
01781         self.assertTrue("Cartesian" in repr);
01782         self.assertTrue("Number of components : 1" in repr);
01783         self.assertTrue("Number of tuples : 4" in repr);
01784         self.assertTrue("Z Array :" in repr);
01785         pass
01786 
01787     def testCMesh2(self):
01788         mesh1=MEDCouplingCMesh.New();
01789         coordsX1=DataArrayDouble.New();
01790         arrX1=[ -1., 1., 2., 4. ]
01791         coordsX1.setValues(arrX1, 4, 1);
01792         coordsY1=DataArrayDouble.New();
01793         arrY1=[ -2., 2., 4., 8. ]
01794         coordsY1.setValues(arrY1, 4, 1);
01795         coordsZ1=DataArrayDouble.New();
01796         arrZ1=[ -3., 3., 6., 12. ]
01797         coordsZ1.setValues(arrZ1, 4, 1);
01798         mesh1.setCoords(coordsX1, coordsY1, coordsZ1);
01799         
01800         dis=mesh1.getDistributionOfTypes();
01801         self.assertEqual(3, len(dis));
01802         self.assertEqual(NORM_HEXA8, dis[0]);
01803         self.assertEqual(27, dis[1]);
01804         self.assertEqual(0, dis[2]);
01805         
01806         idsPerType=[]
01807         self.assertRaises(InterpKernelException, mesh1.checkTypeConsistencyAndContig, dis, idsPerType);
01808         dis[2]=-1;
01809         idsPerType=[]
01810         self.assertTrue(not mesh1.checkTypeConsistencyAndContig(dis, idsPerType));
01811         dis[0]=NORM_QUAD4;
01812         self.assertRaises(InterpKernelException, mesh1.checkTypeConsistencyAndContig, dis, idsPerType);
01813         
01814         dis[0]=NORM_HEXA8;
01815         dis[2]=0;
01816         ids=DataArrayInt.New();
01817         ids.alloc(10, 1);
01818         ids.fillWithValue(111);
01819         idsPerType=[ids];
01820         check=mesh1.checkTypeConsistencyAndContig(dis, idsPerType);
01821         self.assertTrue(check);
01822         self.assertTrue(check.isEqual(ids));
01823         
01824         code, idsInPflPerType, pfls=mesh1.splitProfilePerType(ids);
01825         self.assertEqual(3, len(code));
01826         self.assertEqual(NORM_HEXA8, code[0]);
01827         self.assertEqual(27, code[1]);
01828         self.assertEqual(0, code[2]);
01829         self.assertEqual(1, len(idsInPflPerType));
01830         self.assertEqual(1, len(pfls));
01831         self.assertTrue(idsInPflPerType[0].isEqual(ids));
01832         self.assertTrue(pfls[0].isEqual(ids));
01833         
01834         cells1=[0, 1, 25, 26]
01835         partMesh1=mesh1.buildPart(cells1)
01836         self.assertTrue(isinstance(partMesh1,MEDCouplingMesh))
01837         self.assertEqual(4, partMesh1.getNumberOfCellsWithType(NORM_HEXA8));
01838         self.assertEqual(64, mesh1.getNumberOfNodes());
01839         self.assertEqual(64, partMesh1.getNumberOfNodes());
01840         
01841         cells2=[25, 26]
01842         partMesh2, arr1=mesh1.buildPartAndReduceNodes(cells2)
01843         self.assertTrue(isinstance(partMesh2,MEDCouplingUMesh))
01844         self.assertEqual(2,partMesh2.getNumberOfCellsWithType(NORM_HEXA8));
01845         self.assertEqual(12,partMesh2.getNumberOfNodes());
01846         
01847         cells3=[2, 3]
01848         partMesh3, arr2=partMesh1.buildPartAndReduceNodes(cells3)
01849         self.assertTrue(isinstance(partMesh3,MEDCouplingUMesh))
01850         self.assertEqual(2, partMesh3.getNumberOfCellsWithType(NORM_HEXA8));
01851         self.assertEqual(12, partMesh3.getNumberOfNodes());
01852         
01853         self.assertRaises(InterpKernelException, mesh1.simplexize, 0);
01854         self.assertRaises(InterpKernelException, mesh1.getMeasureFieldOnNode, True);
01855         
01856         #double bbox1[6];
01857         #double bbox2[6];
01858         bbox1=mesh1.getBoundingBox(); #[(-1.0, 4.0), (-2.0, 8.0), (-3.0, 12.0)]
01859         bbox2=partMesh1.getBoundingBox();
01860         self.assertTrue(bbox1==bbox2);
01861         bbox1=partMesh3.getBoundingBox();
01862         bbox2=partMesh2.getBoundingBox();
01863         self.assertTrue(bbox1==bbox2);
01864         
01865         self.assertRaises(InterpKernelException, mesh1.buildOrthogonalField);
01866         mesh2d=MEDCouplingCMesh.New();
01867         mesh2d.setCoords(coordsX1, coordsY1);
01868         f1=mesh2d.buildOrthogonalField();
01869         
01870         pass
01871 
01872     def testScale(self):
01873         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
01874         pos=[0.2,0.2]
01875         mesh.scale(pos,0.5);
01876         expected1=[-0.05,-0.05, 0.2,-0.05, 0.45,-0.05, -0.05,0.2, 0.2,0.2, 0.45,0.2,
01877                    -0.05,0.45, 0.2,0.45, 0.45,0.45]
01878         val=mesh.getCoords().getValues();
01879         self.assertEqual(18,len(val))
01880         for i in xrange(18):
01881             self.assertTrue(abs(expected1[i]-val[i])<1e-12);
01882             pass
01883         pass
01884 
01885     def testTryToShareSameCoords(self):
01886         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
01887         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
01888         self.assertTrue(m1.getCoords().getHiddenCppPointer()!=m2.getCoords().getHiddenCppPointer());
01889         m1.tryToShareSameCoords(m2,1e-12);
01890         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
01891         m1.tryToShareSameCoords(m2,1e-12);
01892         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
01893         m2.tryToShareSameCoords(m1,1e-12);
01894         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
01895         #
01896         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
01897         m2=MEDCouplingDataForTest.build2DTargetMesh_2();
01898         self.assertTrue(m1.getCoords().getHiddenCppPointer()!=m2.getCoords().getHiddenCppPointer());
01899         m1.tryToShareSameCoords(m2,1e-12);
01900         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
01901         m1.tryToShareSameCoords(m2,1e-12);
01902         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
01903         m2.tryToShareSameCoords(m1,1e-12);
01904         self.assertTrue(m1.getCoords().getHiddenCppPointer()==m2.getCoords().getHiddenCppPointer());
01905         #
01906         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
01907         m2=MEDCouplingDataForTest.build2DSourceMesh_1();
01908         self.assertTrue(m1.getCoords().getHiddenCppPointer()!=m2.getCoords().getHiddenCppPointer());
01909         self.assertRaises(InterpKernelException,m1.tryToShareSameCoords,m2,1e-12)
01910         pass
01911 
01912     def testFindNodeOnPlane(self):
01913         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
01914         pt=[300.,300.,0.]
01915         v=[0.,0.,2.]
01916         n=mesh.findNodesOnPlane(pt,v,1e-12);
01917         self.assertEqual(9,len(n));
01918         m3dSurf=mesh.buildFacePartOfMySelfNode(n,True);
01919         self.assertTrue(isinstance(m3dSurf,MEDCouplingUMesh))
01920         me=MEDCouplingExtrudedMesh.New(mesh,m3dSurf,0);
01921         da=me.getMesh3DIds();
01922         self.assertEqual(8,me.getNumberOfCells());
01923         expected=[0,1,2,3,4,5,6,7]
01924         val=da.getValues();
01925         self.assertEqual(expected,list(val));
01926         #
01927         m3dSurf=mesh.buildFacePartOfMySelfNode(n,True);
01928         self.assertTrue(isinstance(m3dSurf,MEDCouplingUMesh))
01929         me=MEDCouplingExtrudedMesh.New(mesh,m3dSurf,0);
01930         da=me.getMesh3DIds();
01931         self.assertEqual(8,me.getNumberOfCells());
01932         expected=[0,1,2,3,4,5,6,7]
01933         val=da.getValues();
01934         self.assertEqual(expected,list(val));
01935         pass
01936 
01937     def testRenumberCells(self):
01938         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
01939         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
01940         self.assertTrue(m.isEqual(m2,0));
01941         arr=[12,3,25,2,26]
01942         m.renumberCells(arr,True);
01943         self.assertTrue(not m.isEqual(m2,0));
01944         self.assertEqual(NORM_QUAD4,m.getTypeOfCell(0));
01945         self.assertEqual(NORM_TRI3,m.getTypeOfCell(1));
01946         self.assertEqual(NORM_QUAD4,m.getTypeOfCell(2));
01947         self.assertEqual(NORM_TRI3,m.getTypeOfCell(3));
01948         self.assertEqual(NORM_QUAD4,m.getTypeOfCell(4));
01949         arr2=[5,-1,-5,4,8]
01950         m.renumberCells(arr2,True);
01951         self.assertTrue(m.isEqual(m2,0));
01952         pass
01953 
01954     def testChangeSpaceDimension(self):
01955         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
01956         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
01957         #
01958         self.assertEqual(3,m1.getSpaceDimension());
01959         m1.changeSpaceDimension(2);
01960         self.assertEqual(2,m1.getSpaceDimension());
01961         m1.setName(m2.getName());
01962         self.assertTrue(m1.isEqual(m2,1e-12));
01963         m1.changeSpaceDimension(3);
01964         self.assertEqual(3,m1.getSpaceDimension());
01965         expected=[-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0.]
01966         val=m1.getCoords().getValues();
01967         for i in xrange(27):
01968             self.assertTrue(abs(expected[i]-val[i])<1e-14);
01969             pass
01970         pass
01971 
01972     def testGaussPointField1(self):
01973         _a=0.446948490915965;
01974         _b=0.091576213509771;
01975         _p1=0.11169079483905;
01976         _p2=0.0549758718227661;
01977         refCoo1=[ 0.,0., 1.,0., 0.,1. ]
01978         gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
01979                  2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ]
01980         wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ]
01981         _refCoo1=refCoo1
01982         _gsCoo1=gsCoo1
01983         _wg1=wg1
01984         #
01985         m=MEDCouplingDataForTest.build2DTargetMesh_1();
01986         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME);
01987         f.setMesh(m);
01988         self.assertEqual(5,f.getNumberOfMeshPlacesExpected());
01989         self.assertEqual(0,f.getNbOfGaussLocalization());
01990         f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
01991         self.assertRaises(InterpKernelException,f.setGaussLocalizationOnType,NORM_QUAD4,_refCoo1,_gsCoo1,_wg1)
01992         self.assertEqual(1,f.getNbOfGaussLocalization());
01993         refCoo2=[ 0.,0., 1.,0., 1.,1., 0.,1. ]
01994         _refCoo2=refCoo2
01995         _gsCoo1=_gsCoo1[0:4]
01996         _wg1=_wg1[0:2]
01997         f.setGaussLocalizationOnType(NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
01998         self.assertEqual(2,f.getNbOfGaussLocalization());
01999         array=DataArrayDouble.New();
02000         ptr=18*2*[None]
02001         for i in xrange(18*2):
02002             ptr[i]=float(i+1)
02003         array.setValues(ptr,18,2);
02004         ptr=array.getPointer();
02005         f.setArray(array);
02006         f.setName("MyFirstFieldOnGaussPoint");
02007         f.checkCoherency();
02008         self.assertAlmostEqual(27.,f.getIJK(2,5,0),14);
02009         self.assertAlmostEqual(16.,f.getIJK(1,5,1),14);
02010         #
02011         f.clearGaussLocalizations();
02012         self.assertEqual(0,f.getNbOfGaussLocalization());
02013         self.assertRaises(InterpKernelException,f.checkCoherency);
02014         ids1=[0,1,3,4]
02015         self.assertRaises(InterpKernelException,f.setGaussLocalizationOnCells,ids1,_refCoo2,_gsCoo1,_wg1);
02016         self.assertEqual(0,f.getNbOfGaussLocalization());
02017         ids2=[0,4]
02018         f.setGaussLocalizationOnCells(ids2,_refCoo2,_gsCoo1,_wg1);
02019         self.assertEqual(1,f.getNbOfGaussLocalization());
02020         self.assertEqual(0,f.getGaussLocalizationIdOfOneCell(0));
02021         self.assertRaises(InterpKernelException,f.getGaussLocalizationIdOfOneCell,1);
02022         ids3=[1,2]
02023         f.setGaussLocalizationOnCells(ids3,_refCoo1,_gsCoo1,_wg1);
02024         self.assertEqual(2,f.getNbOfGaussLocalization());
02025         self.assertEqual(0,f.getGaussLocalizationIdOfOneCell(0));
02026         self.assertEqual(1,f.getGaussLocalizationIdOfOneCell(1));
02027         self.assertEqual(1,f.getGaussLocalizationIdOfOneCell(2));
02028         self.assertRaises(InterpKernelException,f.checkCoherency);#<- cell 3 has no localization
02029         ids4=[3]
02030         _gsCoo2=_gsCoo1;
02031         _wg2=_wg1;
02032         _gsCoo2[0]=0.8888777776666;
02033         _wg2[0]=0.1234567892377;
02034         f.setGaussLocalizationOnCells(ids4,_refCoo2,_gsCoo2,_wg2);
02035         self.assertEqual(3,f.getNbOfGaussLocalization());
02036         tmpIds=f.getCellIdsHavingGaussLocalization(0);
02037         self.assertEqual(ids2,list(tmpIds.getValues()));
02038         self.assertRaises(InterpKernelException,f.checkCoherency);#<- it's always not ok because undelying array not with the good size.
02039         array2=f.getArray().substr(0,10);
02040         f.setArray(array2);
02041         f.checkCoherency();#<- here it is OK
02042         f2=f.clone(True);
02043         self.assertTrue(f.isEqual(f2,1e-14,1e-14));
02044         gl1=f2.getGaussLocalization(0);
02045         tmp=gl1.getGaussCoord(1,1);
02046         self.assertAlmostEqual(2.07*_b-1,tmp,14);
02047         gl1.setGaussCoord(1,1,0.07);
02048         self.assertTrue(not f.isEqual(f2,1e-14,1e-14));
02049         gl1.setGaussCoord(1,1,tmp);
02050         self.assertTrue(f.isEqual(f2,1e-14,1e-14));
02051         f2.checkCoherency();
02052         pass
02053 
02054     def testGaussPointNEField1(self):
02055         m=MEDCouplingDataForTest.build2DTargetMesh_1();
02056         f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,NO_TIME);
02057         f.setMesh(m);
02058         self.assertEqual(5,f.getNumberOfMeshPlacesExpected());
02059         f.setName("MyFirstFieldOnNE");
02060         f.setDescription("MyDescriptionNE");
02061         array=DataArrayDouble.New();
02062         tmp=18*2*[None]
02063         for i in xrange(18*2):
02064             tmp[i]=float(i+7)
02065             pass
02066         array.setValues(tmp,18,2);
02067         ptr=array.getPointer();
02068         f.setArray(array);
02069         #
02070         f.checkCoherency();
02071         f2=f.clone(True);
02072         self.assertTrue(f.isEqual(f2,1e-14,1e-14));
02073         self.assertAlmostEqual(21.,f.getIJK(2,0,0),14);
02074         self.assertAlmostEqual(18.,f.getIJK(1,1,1),14);
02075         pass
02076 
02077     def testCellOrientation1(self):
02078         m=MEDCouplingDataForTest.build2DTargetMesh_1();
02079         vec=[0.,0.,-1.]
02080         self.assertRaises(InterpKernelException,m.are2DCellsNotCorrectlyOriented,vec,False);
02081         m.changeSpaceDimension(3);
02082         res1=m.are2DCellsNotCorrectlyOriented(vec,False);
02083         self.assertTrue(len(res1)==0);
02084         vec[2]=1.;
02085         res1=m.are2DCellsNotCorrectlyOriented(vec,False);
02086         self.assertEqual(5,len(res1));
02087         #
02088         vec[2]=-1.;
02089         # connectivity inversion
02090         conn=m.getNodalConnectivity().getValues();
02091         tmp=conn[11];
02092         conn[11]=conn[12];
02093         conn[12]=tmp;
02094         m.getNodalConnectivity().setValues(conn,len(conn),1)
02095         res1=m.are2DCellsNotCorrectlyOriented(vec,False);
02096         self.assertEqual(1,len(res1));
02097         self.assertEqual(2,res1.getValues()[0]);
02098         m.orientCorrectly2DCells(vec,False);
02099         res1=m.are2DCellsNotCorrectlyOriented(vec,False);
02100         self.assertTrue(len(res1)==0);
02101         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
02102         m2.changeSpaceDimension(3);
02103         self.assertTrue(m.isEqual(m2,1e-12));
02104         pass
02105 
02106     def testCellOrientation2(self):
02107         m2,m1=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
02108         res1=m2.arePolyhedronsNotCorrectlyOriented();
02109         self.assertEqual(6,len(res1));
02110         m2.orientCorrectlyPolyhedrons();
02111         res1=m2.arePolyhedronsNotCorrectlyOriented();
02112         self.assertTrue(len(res1)==0);
02113         m2.checkCoherency();
02114         self.assertEqual(18,m2.getNumberOfCells());
02115         cellIds2=[0,6,12]
02116         m2.convertToPolyTypes(cellIds2);
02117         m2.orientCorrectlyPolyhedrons();
02118         res1=m2.arePolyhedronsNotCorrectlyOriented();
02119         self.assertTrue(len(res1)==0);
02120         f2=m2.getMeasureField(False);
02121         f2Ptr=f2.getArray().getValues();
02122         #Test to check global reverse in MEDCouplingUMesh::tryToCorrectPolyhedronOrientation
02123         m3=MEDCouplingDataForTest.build2DTargetMesh_1();
02124         vec=[0.,0.,1.]
02125         m3.changeSpaceDimension(3);
02126         ids2=[0,1,2,3,4]
02127         m3.convertToPolyTypes(ids2);
02128         m3.orientCorrectly2DCells(vec,False);
02129         m4=MEDCouplingDataForTest.buildCU1DMesh_U();
02130         m4.changeSpaceDimension(3);
02131         center=[0.,0.,0.]
02132         vector=[0.,1.,0.]
02133         m4.rotate(center,vector,-pi/2.);
02134         m5=m3.buildExtrudedMesh(m4,0);
02135         res1=m5.arePolyhedronsNotCorrectlyOriented();
02136         self.assertEqual(15,len(res1));
02137         m5.orientCorrectlyPolyhedrons();
02138         res1=m5.arePolyhedronsNotCorrectlyOriented();
02139         self.assertTrue(len(res1)==0);
02140         f3=m5.getMeasureField(False);
02141         self.assertEqual(15,f3.getArray().getNumberOfTuples());
02142         self.assertEqual(1,f3.getNumberOfComponents());
02143         f3Ptr=f3.getArray().getValues();
02144         expected1=[0.075,0.0375,0.0375,0.075,0.075, 0.1125,0.05625,0.05625,0.1125,0.1125, 0.0625,0.03125,0.03125,0.0625,0.0625];
02145         for i in xrange(15):
02146             self.assertTrue(abs(expected1[i]-f3Ptr[i])<1e-12);
02147             pass
02148         f4=m5.getBarycenterAndOwner();
02149         self.assertEqual(15,f4.getNumberOfTuples());
02150         self.assertEqual(3,f4.getNumberOfComponents());
02151         f4Ptr=f4.getValues();
02152         expected2=[-0.05,-0.05,0.15, 0.3666666666666667,-0.13333333333333333,0.15, 0.53333333333333333,0.033333333333333333,0.15, -0.05,0.45,0.15, 0.45,0.45,0.15,-0.05,-0.05,0.525, 0.3666666666666667,-0.13333333333333333,0.525, 0.53333333333333333,0.033333333333333333,0.525, -0.05,0.45,0.525, 0.45,0.45,0.525,-0.05,-0.05,0.875, 0.3666666666666667,-0.13333333333333333,0.875, 0.53333333333333333,0.033333333333333333,0.875, -0.05,0.45,0.875, 0.45,0.45,0.875];
02153         for i in xrange(45):
02154             self.assertTrue(abs(expected2[i]-f4Ptr[i])<1e-12);
02155             pass
02156         pass
02157 
02158     def testPolyhedronBarycenter(self):
02159         connN=[0,3,2,1, -1, 4,5,6,7, -1, 0,4,7,3, -1, 3,7,6,2, -1, 2,6,5,1, -1, 1,5,4,0];
02160         coords=[0.,0.,0., 1.,0.,0., 1.,1.,0., 0.,1.,0., 0.,0.,1., 1.,0.,1., 1.,1.,1., 0.,1.,1., 0.5, 0.5, 0.5];
02161         meshN=MEDCouplingUMesh.New();
02162         meshN.setName("ForBary");
02163         meshN.setMeshDimension(3);
02164         meshN.allocateCells(4);
02165         meshN.insertNextCell(NORM_POLYHED,29,connN[0:29])
02166         meshN.finishInsertingCells();
02167         myCoords=DataArrayDouble.New();
02168         myCoords.setValues(coords,9,3);
02169         meshN.setCoords(myCoords);
02170         meshN.checkCoherency();
02171         #
02172         res1=meshN.arePolyhedronsNotCorrectlyOriented();
02173         meshN.orientCorrectlyPolyhedrons();
02174         self.assertTrue(len(res1)==0);
02175         da=meshN.getBarycenterAndOwner();
02176         self.assertEqual(1,da.getNumberOfTuples());
02177         self.assertEqual(3,da.getNumberOfComponents());
02178         daPtr=da.getValues();
02179         ref=meshN.getCoords().getValues()[24:];
02180         for i in xrange(3):
02181             self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
02182             pass
02183         #
02184         center=[0.,0.,0.]
02185         vec=[0.,2.78,0.]
02186         da=meshN.getBarycenterAndOwner();
02187         daPtr=da.getValues();
02188         ref=meshN.getCoords().getValues()[24:];
02189         for i in xrange(3):
02190             self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
02191             pass
02192         #
02193         meshN.rotate(center,vec,pi/7.);
02194         meshN.translate(vec);
02195         da=meshN.getBarycenterAndOwner();
02196         daPtr=da.getValues();
02197         ref=meshN.getCoords().getValues()[24:];
02198         for i in xrange(3):
02199             self.assertTrue(abs(ref[i]-daPtr[i])<1e-12);
02200             pass
02201         #
02202         center2=[1.12,3.45,6.78]
02203         vec2=[4.5,9.3,2.8]
02204         meshN.rotate(center2,vec2,e);
02205         meshN.translate(vec2);
02206         da=meshN.getBarycenterAndOwner();
02207         daPtr=da.getValues();
02208         ref=meshN.getCoords().getValues()[24:];
02209         for i in xrange(3):
02210             self.assertTrue(abs(ref[i]-daPtr[i])<1e-10);
02211             pass
02212         pass
02213 
02214     def testNormL12Integ1D(self):
02215         m1=MEDCouplingDataForTest.build1DTargetMesh_3();
02216         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
02217         f1.setMesh(m1);
02218         array=DataArrayDouble.New();
02219         arr=[-5.23,15.45,-25.56,6.67,-16.78,26.89,-7.91,17.23,-27.43,8.21,-18.63,28.72]
02220         array.setValues(arr,m1.getNumberOfCells(),3);
02221         f1.setArray(array);
02222         #
02223         f3=m1.getBarycenterAndOwner();
02224         self.assertEqual(4,f3.getNumberOfTuples());
02225         self.assertEqual(1,f3.getNumberOfComponents());
02226         expected9=[0.75,5.105,0.8,5.155]
02227         ptr=f3.getValues();
02228         for i in xrange(4):
02229             self.assertTrue(abs(expected9[i]-ptr[i])<1e-12);
02230             pass
02231         #
02232         f2=m1.getMeasureField(False);
02233         self.assertEqual(4,f2.getArray().getNumberOfTuples());
02234         self.assertEqual(1,f2.getNumberOfComponents());
02235         expected1=[0.5,0.21,-0.6,-0.31]
02236         ptr=f2.getArray().getValues();
02237         for i in xrange(4):
02238             self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
02239             pass
02240         expected2=[0.5,0.21,0.6,0.31]
02241         f2=m1.getMeasureField(True);
02242         ptr=f2.getArray().getValues();
02243         for i in xrange(4):
02244             self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
02245             pass
02246         #integral
02247         self.assertTrue(4,f1.getNumberOfTuples())
02248         res=f1.integral(False);
02249         self.assertTrue(3,len(res))
02250         expected3=[0.9866,-0.3615,0.4217]
02251         for i in xrange(3):
02252             self.assertTrue(abs(expected3[i]-res[i])<1e-12);
02253             pass
02254         self.assertTrue(abs(expected3[0]-f1.integral(0,False))<1e-12);
02255         self.assertTrue(abs(expected3[1]-f1.integral(1,False))<1e-12);
02256         self.assertTrue(abs(expected3[2]-f1.integral(2,False))<1e-12);
02257         res=f1.integral(True);
02258         expected4=[-3.4152,8.7639,-14.6879]
02259         for i in xrange(3):
02260             self.assertTrue(abs(expected4[i]-res[i])<1e-12);
02261             pass
02262         #normL1
02263         res=f1.normL1();
02264         self.assertTrue(3,len(res))
02265         expected5=[6.979506172839505, 16.89018518518518, 27.02969135802469]
02266         for i in xrange(3):
02267             self.assertTrue(abs(expected5[i]-res[i])<1e-12);
02268             pass
02269         self.assertTrue(abs(expected5[0]-f1.normL1(0))<1e-12);
02270         self.assertTrue(abs(expected5[1]-f1.normL1(1))<1e-12);
02271         self.assertTrue(abs(expected5[2]-f1.normL1(2))<1e-12);
02272         #normL2
02273         res=f1.normL2();
02274         self.assertTrue(3,len(res))
02275         expected7=[7.090910979452395, 16.9275542960123, 27.053271464160858]
02276         for i in xrange(3):
02277             self.assertTrue(abs(expected7[i]-res[i])<1e-9);
02278             pass
02279         self.assertTrue(abs(expected7[0]-f1.normL2(0))<1e-9);
02280         self.assertTrue(abs(expected7[1]-f1.normL2(1))<1e-9);
02281         self.assertTrue(abs(expected7[2]-f1.normL2(2))<1e-9);
02282         #buildMeasureField
02283         f4=f1.buildMeasureField(False);
02284         self.assertTrue(abs(-0.2-f4.accumulate(0))<1e-12);
02285         f4=f1.buildMeasureField(True);
02286         self.assertTrue(abs(1.62-f4.accumulate(0))<1e-12);
02287         # Testing with 2D Curve
02288         m1=MEDCouplingDataForTest.build2DCurveTargetMesh_3();
02289         f2=m1.getMeasureField(False);
02290         self.assertEqual(4,f2.getArray().getNumberOfTuples());
02291         self.assertEqual(1,f2.getNumberOfComponents());
02292         ptr=f2.getArray().getValues();
02293         for i in xrange(4):
02294             self.assertTrue(abs(sqrt(2.)*expected2[i]-ptr[i])<1e-12);
02295             pass
02296         f2=m1.getMeasureField(True);
02297         self.assertEqual(4,f2.getArray().getNumberOfTuples());
02298         self.assertEqual(1,f2.getNumberOfComponents());
02299         ptr=f2.getArray().getValues();
02300         for i in xrange(4):
02301             self.assertTrue(abs(expected2[i]*sqrt(2.)-ptr[i])<1e-12);
02302             pass
02303         #bary
02304         f3=m1.getBarycenterAndOwner();
02305         self.assertEqual(4,f3.getNumberOfTuples());
02306         self.assertEqual(2,f3.getNumberOfComponents());
02307         expected10=[0.75,0.75,5.105,5.105,0.8,0.8,5.155,5.155]
02308         ptr=f3.getValues();
02309         for i in xrange(8):
02310             self.assertTrue(abs(expected10[i]-ptr[i])<1e-12);
02311             pass
02312         #
02313         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
02314         f1.setMesh(m1);
02315         array=DataArrayDouble.New();
02316         array.setValues(arr,m1.getNumberOfCells(),3);
02317         f1.setArray(array);
02318         res=f1.integral(False);
02319         for i in xrange(3):
02320             self.assertTrue(abs(sqrt(2.)*expected4[i]-res[i])<1e-12);
02321             pass
02322         res=f1.integral(True);
02323         for i in xrange(3):
02324             self.assertTrue(abs(sqrt(2.)*expected4[i]-res[i])<1e-12);
02325             pass
02326         res=f1.normL1();
02327         for i in xrange(3):
02328             self.assertTrue(abs(expected5[i]-res[i])<1e-12);
02329             pass
02330         res=f1.normL2();
02331         for i in xrange(3):
02332             self.assertTrue(abs(expected7[i]-res[i])<1e-12);
02333             pass
02334         pass
02335 
02336     def testAreaBary2D(self):
02337         m1=MEDCouplingDataForTest.build2DTargetMesh_3();
02338         f1=m1.getMeasureField(False);
02339         self.assertEqual(10,f1.getArray().getNumberOfTuples());
02340         self.assertEqual(1,f1.getNumberOfComponents());
02341         expected1=[-0.5,-1,-1.5,-0.5,-1,  0.5,1,1.5,0.5,1]
02342         ptr=f1.getArray().getValues();
02343         for i in xrange(10):
02344             self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
02345             pass
02346         f1=m1.getMeasureField(True);
02347         ptr=f1.getArray().getValues();
02348         for i in xrange(10):
02349             self.assertTrue(abs(abs(expected1[i])-ptr[i])<1e-12);
02350             pass
02351         f2=m1.getBarycenterAndOwner();
02352         self.assertEqual(10,f2.getNumberOfTuples());
02353         self.assertEqual(2,f2.getNumberOfComponents());
02354         expected2=[0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5,0.5,0.3333333333333333,0.5,0.5,0.5,0.77777777777777777,0.5,0.3333333333333333,0.5,0.5]
02355         ptr=f2.getValues();
02356         for i in xrange(20):
02357             self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
02358             pass
02359         m1.changeSpaceDimension(3);
02360         f1=m1.getMeasureField(False);
02361         self.assertEqual(10,f1.getArray().getNumberOfTuples());
02362         self.assertEqual(1,f1.getNumberOfComponents());
02363         ptr=f1.getArray().getValues();
02364         for i in xrange(10):
02365             self.assertTrue(abs(abs(expected1[i])-ptr[i])<1e-12);
02366             pass
02367         f2=m1.getBarycenterAndOwner();
02368         self.assertEqual(10,f2.getNumberOfTuples());
02369         self.assertEqual(3,f2.getNumberOfComponents());
02370         ptr=f2.getValues();
02371         expected3=[0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0., 0.5,0.3333333333333333,0.,0.5,0.5,0.,0.5,0.77777777777777777,0.,0.5,0.3333333333333333,0.,0.5,0.5,0.]
02372         for i in xrange(30):
02373             self.assertTrue(abs(expected3[i]-ptr[i])<1e-12);
02374             pass
02375         pass
02376 
02377     def testAreaBary3D(self):
02378         coords=[ 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
02379                  0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
02380                  0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
02381                  0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
02382                  -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
02383                  -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
02384                  0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
02385                  0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
02386                  -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
02387                  0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
02388                 -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
02389                  -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
02390                  -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
02391                  -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
02392                  -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
02393                  -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
02394                  0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
02395                  0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
02396                  0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
02397                  -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
02398                  -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
02399                 -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
02400                  -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
02401                  0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
02402                  0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
02403                  0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
02404                  -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
02405                  -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
02406                 0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
02407                  0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
02408                  -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
02409                  0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
02410                  0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
02411                  0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
02412                  -0.0372812069535 , -0.286740286332 , 0.00963701291166 ]
02413         
02414         connN = [ #polyhedron 0
02415             0 , 1 , 3 , 4 , 2 , -1 , 1 , 5 , 6 , 7 , 0 , -1 , 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 1 , 5 , 12 , 14 , 15 , 13 , 3 , -1 , 16 , 9 , 2 , 4 , 17 , -1
02416             , 4 , 3 , 13 , 18 , 17 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1 , 6 , 7 , 8 , 23 , 22 , 19 , -1 , 23 , 24 , 10 , 8 , -1 , 25 , 11 , 9 , 16 , -1
02417             , 24 , 26 , 25 , 11 , 10 , -1 , 12 , 14 , 20 , -1 , 27 , 28 , 29 , 15 , 13 , 18 , -1 , 14 , 15 , 29 , 30 , 21 , 20 , -1 , 26 , 27 , 18 , 17 , 16 , 25 , -1
02418             , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
02419             # polyhedron 1
02420             0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 32 , 0 , 7 , 35 , 34 , 33 , -1 , 32 , 0 , 2 , 37 , 36 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1
02421             , 2 , 37 , 41 , 9 , -1 , 40 , 8 , 10 , 44 , 43 , 42 , -1 , 41 , 9 , 11 , 44 , 43 , -1 , 44 , 11 , 10 , -1 , 32 , 33 , 45 , 47 , 46 , 36 , -1
02422             , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
02423             , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
02424             # polyhedron 2
02425             6 , 7 , 8 , 23 , 22 , 19 , -1 , 6 , 35 , 7 , -1 , 6 , 35 , 38 , 19 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1 , 53 , 22 , 19 , 38 , 39 , 54 , -1
02426             , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
02427             # polyhedron 3
02428             35 , 34 , 48 , 50 , 49 , 38 , -1 , 6 , 35 , 34 , 56 , 55 , 5 , -1 , 6 , 35 , 38 , 19 , -1 , 34 , 56 , 57 , 59 , 58 , 48 , -1
02429             , 60 , 61 , 21 , 19 , 38 , 49 , -1 , 62 , 50 , 48 , 58 , -1 , 60 , 63 , 64 , 62 , 50 , 49 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1
02430             , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
02431             , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65]
02432         
02433         barys = [ -0.0165220465527 , -0.0190922868195 , 0.158882733414 ,
02434                   0.0287618656076 , 0.135874379934 , -0.14601588119 ,
02435                   -0.147128055553 , 0.0465995097041 , -0.049391174453 ,
02436                   -0.00142506732317 , -0.0996953090351 , -0.115159183132 ]
02437         meshN=MEDCouplingUMesh.New();
02438         meshN.setName("ForBary");
02439         meshN.setMeshDimension(3);
02440         meshN.allocateCells(4);
02441         meshN.insertNextCell(NORM_POLYHED,113,connN);
02442         meshN.insertNextCell(NORM_POLYHED,99,connN[113:]);
02443         meshN.insertNextCell(NORM_POLYHED,43,connN[212:]);
02444         meshN.insertNextCell(NORM_POLYHED,92,connN[255:]);
02445         meshN.finishInsertingCells();
02446         myCoords=DataArrayDouble.New();
02447         myCoords.setValues(coords,69,3);
02448         meshN.setCoords(myCoords);
02449         meshN.checkCoherency();
02450         res1=meshN.arePolyhedronsNotCorrectlyOriented();
02451         meshN.orientCorrectlyPolyhedrons();
02452         res1=meshN.arePolyhedronsNotCorrectlyOriented();
02453         self.assertTrue(len(res1)==0);
02454         #
02455         da=meshN.getBarycenterAndOwner();
02456         self.assertEqual(4,da.getNumberOfTuples());
02457         self.assertEqual(3,da.getNumberOfComponents());
02458         daPtr=da.getValues();
02459         for i in xrange(12):
02460             self.assertTrue(abs(barys[i]-daPtr[i])<1e-12);
02461             pass
02462         pass
02463 
02464     def testRenumberCellsForFields(self):
02465         m=MEDCouplingDataForTest.build2DTargetMesh_1();
02466         f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
02467         f.setMesh(m);
02468         arr=DataArrayDouble.New();
02469         nbOfCells=m.getNumberOfCells();
02470         values1=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.]
02471         arr.setValues(values1,nbOfCells,3);
02472         f.setArray(arr);
02473         renumber1=[3,1,0,4,2]
02474         loc=[-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45]
02475         for j in xrange(5):
02476             res=f.getValueOn(loc[2*j:2*j+2]);
02477             for i in xrange(3):
02478                 self.assertTrue(abs(values1[i+3*j]-res[i])<1e-12);
02479                 pass
02480             pass
02481         f.renumberCells(renumber1,False);
02482         ptr=f.getArray().getValues();
02483         expected1=[9.,109.,10009.,8.,108.,10008.,11.,111.,10011.,7.,107.,10007.,10.,110.,10010.]
02484         for i in xrange(15):
02485             self.assertTrue(abs(expected1[i]-ptr[i])<1e-12);
02486             pass
02487         #check that fields remains the same geometrically
02488         for j in xrange(5):
02489             res=f.getValueOn(loc[2*j:2*(j+1)]);
02490             for i in xrange(3):
02491                 self.assertTrue(abs(values1[i+3*j]-res[i])<1e-12);
02492                 pass
02493             pass
02494         #On gauss
02495         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME);
02496         f.setMesh(m);
02497         _a=0.446948490915965;
02498         _b=0.091576213509771;
02499         _p1=0.11169079483905;
02500         _p2=0.0549758718227661;
02501         refCoo1=[ 0.,0., 1.,0., 0.,1. ]
02502         gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b, 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ];
02503         wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ]
02504         _refCoo1=refCoo1[0:6];
02505         _gsCoo1=gsCoo1[0:12];
02506         _wg1=wg1[0:6];
02507         f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
02508         refCoo2=[ 0.,0., 1.,0., 1.,1., 0.,1. ]
02509         _refCoo2=refCoo2[0:8];
02510         _gsCoo1=_gsCoo1[0:4]
02511         _wg1=_wg1[0:2]
02512         f.setGaussLocalizationOnType(NORM_QUAD4,_refCoo2,_gsCoo1,_wg1);
02513         arr=DataArrayDouble.New();
02514         values2=[1.,1001.,2.,1002., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 31.,1031.,32.,1032., 41.,1041.,42.,1042.]
02515         arr.setValues(values2,18,2);
02516         f.setArray(arr);
02517         f.checkCoherency();
02518         fCpy=f.clone(True);
02519         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
02520         f.renumberCells(renumber1,False);
02521         self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
02522         expected2=[21.,1021.,22.,1022.,23.,1023.,24.,1024.,25.,1025.,26.,1026., 11.,1011.,12.,1012.,13.,1013.,14.,1014.,15.,1015.,16.,1016., 41.,1041.,42.,1042., 1.,1001.,2.,1002., 31.,1031.,32.,1032.]
02523         ptr=f.getArray().getValues();
02524         for i in xrange(36):
02525             self.assertTrue(abs(expected2[i]-ptr[i])<1e-12);
02526             pass
02527         renumber2=[2,1,4,0,3]
02528         f.renumberCells(renumber2,False);
02529         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
02530         #GaussNE
02531         f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,NO_TIME);
02532         f.setMesh(m);
02533         arr=DataArrayDouble.New();
02534         values3=[1.,1001.,2.,1002.,3.,1003.,4.,1004., 11.,1011.,12.,1012.,13.,1013., 21.,1021.,22.,1022.,23.,1023., 31.,1031.,32.,1032.,33.,1033.,34.,1034., 41.,1041.,42.,1042.,43.,1043.,44.,1044.]
02535         arr.setValues(values3,18,2);
02536         f.setArray(arr);
02537         f.checkCoherency();
02538         fCpy=f.clone(True);
02539         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
02540         f.renumberCells(renumber1,False);
02541         self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
02542         expected3=[21.,1021.,22.,1022.,23.,1023.,11.,1011.,12.,1012.,13.,1013.,41.,1041.,42.,1042.,43.,1043.,44.,1044.,1.,1001.,2.,1002.,3.,1003.,4.,1004.,31.,1031.,32.,1032.,33.,1033.,34.,1034.]
02543         ptr=f.getArray().getValues();
02544         for i in xrange(36):
02545             self.assertTrue(abs(expected3[i]-ptr[i])<1e-12);
02546             pass
02547         f.renumberCells(renumber2,False);#perform reverse operation of renumbering to check that the resulting field is equal.
02548         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
02549         #
02550         pass
02551 
02552     def testRenumberNodesForFields(self):
02553         m=MEDCouplingDataForTest.build2DTargetMesh_1();
02554         f=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
02555         f.setMesh(m);
02556         self.assertEqual(9,f.getNumberOfMeshPlacesExpected());
02557         arr=DataArrayDouble.New();
02558         nbOfNodes=m.getNumberOfNodes();
02559         values1=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.,12.,112.,10012.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.]
02560         arr.setValues(values1,nbOfNodes,3);
02561         f.setArray(arr);
02562         f.checkCoherency();
02563         renumber1=[0,4,1,3,5,2,6,7,8]
02564         loc=[0.5432,-0.2432, 0.5478,0.1528]
02565         expected1=[9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124]
02566         for j in xrange(2):
02567             res=f.getValueOn(loc[2*j:2*j+2]);
02568             for i in xrange(3):
02569                 self.assertTrue(abs(expected1[i+3*j]-res[i])<1e-12);
02570                 pass
02571             pass
02572         fCpy=f.clone(True);
02573         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
02574         f.renumberNodes(renumber1);
02575         self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12));
02576         for j in xrange(2):
02577             res=f.getValueOn(loc[2*j:2*j+2]);
02578             for i in xrange(3):
02579                 self.assertTrue(abs(expected1[i+3*j]-res[i])<1e-12);
02580                 pass
02581             pass
02582         expected2=[7.,107.,10007.,9.,109.,10009.,12.,112.,10012.,10.,110.,10010.,8.,108.,10008.,11.,111.,10011.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.]
02583         for i in xrange(27):
02584             self.assertTrue(abs(expected2[i]-f.getArray().getValues()[i])<1e-12);
02585             pass
02586         renumber2=[0,2,5,3,1,4,6,7,8]
02587         f.renumberNodes(renumber2);
02588         self.assertTrue(f.isEqual(fCpy,1e-12,1e-12));
02589         pass
02590 
02591     def testConvertQuadraticCellsToLinear(self):
02592         mesh=MEDCouplingDataForTest.build2DTargetMesh_3();
02593         mesh.checkCoherency();
02594         types=mesh.getAllTypes();
02595         types.sort()
02596         self.assertEqual(5,len(types));
02597         expected1=[NORM_POLYGON, NORM_TRI3, NORM_QUAD4, NORM_TRI6, NORM_QUAD8]
02598         expected1.sort()
02599         self.assertEqual(expected1,types);
02600         self.assertTrue(mesh.isPresenceOfQuadratic());
02601         self.assertEqual(62,mesh.getMeshLength());
02602         f1=mesh.getMeasureField(False);
02603         #
02604         mesh.convertQuadraticCellsToLinear();
02605         self.assertTrue(not mesh.isPresenceOfQuadratic());
02606         #
02607         mesh.checkCoherency();
02608         f2=mesh.getMeasureField(False);
02609         self.assertTrue(f1.getArray().isEqual(f2.getArray(),1e-12));
02610         self.assertEqual(48,mesh.getMeshLength());
02611         types2=mesh.getAllTypes();
02612         types2.sort()
02613         self.assertEqual(3,len(types2));
02614         expected2=[NORM_POLYGON, NORM_TRI3, NORM_QUAD4]
02615         expected2.sort()
02616         self.assertEqual(expected2,types2);
02617         pass
02618 
02619     def testCheckGeoEquivalWith(self):
02620         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
02621         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
02622         #First test mesh1
02623         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,0,1e-12);#deepEqual
02624         self.assertTrue(cellCor==None);
02625         self.assertTrue(nodeCor==None);
02626         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,1,1e-12);#fastEqual
02627         self.assertTrue(cellCor==None);
02628         self.assertTrue(nodeCor==None);
02629         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,10,1e-12);#deepEqual with geo permutations
02630         self.assertTrue(cellCor==None);
02631         self.assertTrue(nodeCor==None);
02632         #Second test mesh1 and mesh2 are 2 different meshes instance
02633         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,0,1e-12);#deepEqual
02634         self.assertTrue(cellCor==None);
02635         self.assertTrue(nodeCor==None);
02636         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual
02637         self.assertTrue(cellCor==None);
02638         self.assertTrue(nodeCor==None);
02639         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations
02640         self.assertTrue(cellCor==None);
02641         self.assertTrue(nodeCor==None);
02642         #Third test : cell permutation by keeping the first the middle and the last as it is.
02643         renum=[0,2,1,3,4,5,6,8,7,9]
02644         mesh2.renumberCells(renum,False);
02645         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);#deepEqual fails
02646         self.assertTrue(cellCor==None);
02647         self.assertTrue(nodeCor==None);
02648         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual do not see anything
02649         self.assertTrue(cellCor==None);
02650         self.assertTrue(nodeCor==None);
02651         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations
02652         self.assertTrue(cellCor);
02653         self.assertEqual(10,cellCor.getNumberOfTuples());
02654         self.assertEqual(1,cellCor.getNumberOfComponents());
02655         self.assertEqual(renum,list(cellCor.getValues()))
02656         self.assertTrue(nodeCor==None);
02657         cellCor=0;
02658         self.assertTrue(nodeCor==None);
02659         #4th test : cell and node permutation by keeping the first the middle and the last as it is.
02660         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
02661         renum2=[0,2,1,3,4,5,6,8,7,9,10]
02662         mesh2.renumberCells(renum,False);
02663         mesh2.renumberNodes(renum2,11);
02664         cellCor=None
02665         nodeCor=None
02666         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);#deepEqual fails
02667         self.assertTrue(cellCor==None);
02668         self.assertTrue(nodeCor==None);
02669         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual do not see anything
02670         self.assertTrue(cellCor==None);
02671         self.assertTrue(nodeCor==None);
02672         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations
02673         self.assertTrue(cellCor);
02674         self.assertEqual(10,cellCor.getNumberOfTuples());
02675         self.assertEqual(1,cellCor.getNumberOfComponents());
02676         self.assertEqual(renum,list(cellCor.getValues()))
02677         self.assertTrue(nodeCor);
02678         self.assertEqual(11,nodeCor.getNumberOfTuples());
02679         self.assertEqual(1,nodeCor.getNumberOfComponents());
02680         self.assertEqual(renum2,list(nodeCor.getValues()))
02681         cellCor=0;
02682         nodeCor=0;
02683         #5th test : modification of the last cell to check fastCheck detection.
02684         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
02685         renum3=[0,2,1,3,4,5,6,8,9,7]
02686         mesh2.renumberCells(renum3,False);
02687         mesh2.renumberNodes(renum2,11);
02688         cellCor=None
02689         nodeCor=None
02690         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12)
02691         self.assertTrue(cellCor==None);
02692         self.assertTrue(nodeCor==None);
02693         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,1,1e-12)
02694         self.assertTrue(cellCor==None);
02695         self.assertTrue(nodeCor==None);
02696         cellCor,nodeCor=mesh2.checkGeoEquivalWith(mesh1,10,1e-12);#deepEqual with geo permutations
02697         self.assertTrue(cellCor!=None);
02698         self.assertEqual(10,cellCor.getNumberOfTuples());
02699         self.assertEqual(1,cellCor.getNumberOfComponents());
02700         self.assertEqual(renum3,list(cellCor.getValues()))
02701         self.assertTrue(nodeCor!=None);
02702         self.assertEqual(11,nodeCor.getNumberOfTuples());
02703         self.assertEqual(1,nodeCor.getNumberOfComponents());
02704         self.assertEqual(renum2,list(nodeCor.getValues()));
02705         pass
02706 
02707     def testCheckGeoEquivalWith2(self):
02708         mesh1=MEDCouplingDataForTest.build2DTargetMesh_4();
02709         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
02710         cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);
02711         self.assertEqual(None,cellCor);
02712         self.assertNotEqual(None,nodeCor);
02713         expected1=[0, 1, 3, 4, 5, 6, 7, 8, 9]
02714         for i in xrange(9):
02715             self.assertEqual(expected1[i],nodeCor.getIJ(i,0));
02716             pass
02717         pass
02718 
02719     def testCopyTinyStringsFromOnFields(self):
02720         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
02721         nbOfCells=m.getNumberOfCells();
02722         f=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
02723         f.setMesh(m);
02724         self.assertEqual(5,f.getNumberOfMeshPlacesExpected());
02725         f.setName("a");
02726         f.setDescription("b");
02727         a1=DataArrayDouble.New();
02728         a1.alloc(nbOfCells,2);
02729         a1.fillWithZero();
02730         a1.setInfoOnComponent(0,"c");
02731         a1.setInfoOnComponent(1,"d");
02732         a2=a1.deepCpy();
02733         a2.setInfoOnComponent(0,"e");
02734         a2.setInfoOnComponent(1,"f");
02735         f.setArray(a1);
02736         f.setEndArray(a2);
02737         f.setEndTime(3.,3,4);
02738         m.setName("g");
02739         m.getCoords().setInfoOnComponent(0,"h");
02740         m.getCoords().setInfoOnComponent(1,"i");
02741         m.getCoords().setInfoOnComponent(2,"j");
02742         #
02743         f.checkCoherency();
02744         f2=f.clone(True);
02745         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
02746         f2.setName("smth");
02747         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
02748         f2.copyTinyStringsFrom(f);
02749         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
02750         f2.setDescription("GGG");
02751         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
02752         f2.copyTinyStringsFrom(f);
02753         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
02754         f2.getArray().setInfoOnComponent(0,"mmmm");
02755         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
02756         f2.copyTinyStringsFrom(f);
02757         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
02758         f2.getEndArray().setInfoOnComponent(1,"mmmm");
02759         self.assertTrue(not f2.isEqual(f,1e-12,1e-12));
02760         f2.copyTinyStringsFrom(f);
02761         self.assertTrue(f2.isEqual(f,1e-12,1e-12));
02762         m2=m.clone(True);
02763         self.assertTrue(m2.isEqual(m,1e-12));
02764         m2.setName("123");
02765         self.assertTrue(not m2.isEqual(m,1e-12));
02766         m2.copyTinyStringsFrom(m);
02767         self.assertTrue(m2.isEqual(m,1e-12));
02768         m2.getCoords().setInfoOnComponent(1,"eee");
02769         self.assertTrue(not m2.isEqual(m,1e-12));
02770         m2.copyTinyStringsFrom(m);
02771         self.assertTrue(m2.isEqual(m,1e-12));
02772         pass
02773 
02774     def testTryToShareSameCoordsPermute(self):
02775         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
02776         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
02777         #self.assertTrue(m.getCoords()!=m2.getCoords());
02778         m.tryToShareSameCoordsPermute(m2,1e-12);
02779         #self.assertTrue(m.getCoords()==m2.getCoords());
02780         self.assertTrue(m2.isEqual(m,1e-12));
02781         renum1=[1,2,0,5,8,7,4,3,6]
02782         r1=DataArrayInt.New()
02783         r1.setValues(renum1,len(renum1),1)
02784         m.renumberNodes(r1,9);
02785         #self.assertTrue(m.getCoords()!=m2.getCoords());
02786         self.assertTrue(not m2.isEqual(m,1e-12));
02787         m.tryToShareSameCoordsPermute(m2,1e-12);
02788         #self.assertTrue(m.getCoords()==m2.getCoords());
02789         self.assertTrue(m2.isEqual(m,1e-12));
02790         pass
02791 
02792     def testTryToShareSameCoordsPermute2(self):
02793         m1=MEDCouplingDataForTest.build2DTargetMesh_4();
02794         targetCoords=[-0.3,-0.3, 0.2,-0.3, -0.3,0.2, 0.2,0.2 ]
02795         targetConn=[0,2,3,1]
02796         m2=MEDCouplingUMesh.New();
02797         m2.setMeshDimension(2);
02798         m2.allocateCells(1);
02799         m2.insertNextCell(NORM_QUAD4,targetConn[0:4])
02800         m2.finishInsertingCells();
02801         myCoords=DataArrayDouble.New();
02802         myCoords.setValues(targetCoords,4,2);
02803         m2.setCoords(myCoords);
02804         m2.checkCoherency();
02805         m1.checkCoherency();
02806         #
02807         expected1=[0.25,0.125,0.125,0.25,0.25]
02808         f1=m1.getMeasureField(False);
02809         f2=m2.getMeasureField(False);
02810         self.assertEqual(5,f1.getArray().getNumberOfTuples());
02811         self.assertEqual(1,f2.getArray().getNumberOfTuples());
02812         for i in xrange(5):
02813             self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),12);
02814             pass
02815         self.assertAlmostEqual(expected1[0],f2.getIJ(0,0),12);
02816         self.assertRaises(InterpKernelException,m1.tryToShareSameCoordsPermute,m2,1e-12);# <- here in this order the sharing is impossible.
02817         # Let's go for deeper test of tryToShareSameCoordsPermute
02818         m2.tryToShareSameCoordsPermute(m1,1e-12);
02819         f1=m1.getMeasureField(False);
02820         f2=m2.getMeasureField(False);
02821         self.assertEqual(5,f1.getArray().getNumberOfTuples());
02822         self.assertEqual(1,f2.getArray().getNumberOfTuples());
02823         for i in xrange(5):
02824             self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),12);
02825             pass
02826         self.assertAlmostEqual(expected1[0],f2.getIJ(0,0),12);
02827         pass
02828 
02829     def testChangeUnderlyingMesh1(self):
02830         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
02831         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
02832         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
02833         f1.setMesh(mesh1);
02834         array=DataArrayDouble.New();
02835         arr=[7., 107., 8., 108., 9., 109., 10., 110., 11., 111., 12., 112., 13., 113., 14., 114., 15., 115., 16., 116.]
02836         array.setValues(arr,mesh1.getNumberOfCells(),2);
02837         f1.setArray(array);
02838         #
02839         renum=[0,2,1,3,4,5,6,8,7,9]
02840         mesh2.renumberCells(renum,False);
02841         #self.assertTrue(f1.getMesh()==mesh1);
02842         f1.changeUnderlyingMesh(mesh1,10,1e-12);# nothing done only to check that nothing done.
02843         #self.assertTrue(f1.getMesh()==mesh1);
02844         f1.changeUnderlyingMesh(mesh2,10,1e-12);
02845         #self.assertTrue(f1.getMesh()==mesh2);
02846         expected1=[7.,107.,9.,109.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.]
02847         for i in xrange(20):
02848             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
02849             pass
02850         #
02851         f1=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
02852         f1.setMesh(mesh1);
02853         array=DataArrayDouble.New();
02854         arr2=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.,17.,117.]
02855         array.setValues(arr2,mesh1.getNumberOfNodes(),2);
02856         f1.setArray(array);
02857         #
02858         renum2=[0,2,10,3,4,5,6,8,7,9,1]
02859         mesh2.renumberNodes(renum2,11);
02860         #self.assertTrue(f1.getMesh()==mesh1);
02861         f1.changeUnderlyingMesh(mesh2,10,1e-12);
02862         #self.assertTrue(f1.getMesh()==mesh2);
02863         expected2=[7.,107.,17.,117.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.,9.,109.]
02864         for i in xrange(22):
02865             self.assertAlmostEqual(expected2[i],f1.getArray().getIJ(0,i),12);
02866             pass
02867         pass
02868 
02869     def testGetMaxValue1(self):
02870         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
02871         nbOfCells=m.getNumberOfCells();
02872         f=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
02873         f.setMesh(m);
02874         a1=DataArrayDouble.New();
02875         val1=[3.,4.,5.,6.,7.]
02876         a1.setValues(val1,nbOfCells,1);
02877         a2=DataArrayDouble.New();
02878         val2=[0.,1.,2.,8.,7.]
02879         a2.setValues(val2,nbOfCells,1);
02880         f.setArray(a1);
02881         f.setEndArray(a2);
02882         f.setEndTime(3.,3,4);
02883         f.checkCoherency();
02884         #
02885         self.assertAlmostEqual(8.,f.getMaxValue(),14);
02886         self.assertAlmostEqual(0.,f.getMinValue(),14);
02887         self.assertAlmostEqual(5.,f.getAverageValue(),14);
02888         self.assertAlmostEqual(5.125,f.getWeightedAverageValue(),14);
02889         a1.setIJ(0,2,9.5);
02890         self.assertAlmostEqual(9.5,f.getMaxValue(),14);
02891         self.assertAlmostEqual(0.,f.getMinValue(),14);
02892         a2.setIJ(0,0,9.);
02893         self.assertAlmostEqual(9.5,f.getMaxValue(),14);
02894         self.assertAlmostEqual(1.,f.getMinValue(),14);
02895         pass
02896 
02897     def testSubstractInPlaceDM1(self):
02898         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
02899         mesh2=MEDCouplingDataForTest.build2DTargetMesh_3();
02900         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
02901         f1.setMesh(mesh1);
02902         array=DataArrayDouble.New();
02903         arr=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.]
02904         array.setValues(arr,mesh1.getNumberOfCells(),2);
02905         f1.setArray(array);
02906         #
02907         self.assertEqual(10,f1.getNumberOfTuples());
02908         self.assertEqual(2,f1.getNumberOfComponents());
02909         self.assertEqual(20,f1.getNumberOfValues());
02910         #
02911         renum=[0,2,3,1,4,5,6,8,7,9]
02912         mesh2.renumberCells(renum,False);
02913         #
02914         f2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
02915         f2.setMesh(mesh2);
02916         array=DataArrayDouble.New();
02917         arr2=[7.1,107.1,10.1,110.1,8.1,108.1,9.1,109.1,11.1,111.1,12.1,112.1,13.1,113.1,15.1,115.1,14.1,114.1,16.1,116.1]
02918         array.setValues(arr2,mesh2.getNumberOfCells(),2);
02919         f2.setArray(array);
02920         #
02921         f1.substractInPlaceDM(f2,10,1e-12);
02922         f1.applyFunc(1,"abs(x+y+0.2)");
02923         self.assertAlmostEqual(0.,f1.getMaxValue(),13);
02924         pass
02925 
02926     def testDotCrossProduct1(self):
02927         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
02928         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
02929         f1.setTime(2.3,5,6);
02930         f1.setMesh(mesh1);
02931         array=DataArrayDouble.New();
02932         arr1=[7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.]
02933         array.setValues(arr1,mesh1.getNumberOfCells(),3);
02934         f1.setArray(array);
02935         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
02936         f2.setTime(7.8,4,5);
02937         f2.setMesh(mesh1);
02938         array=DataArrayDouble.New();
02939         arr2=[1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.,25.,26.,27.,28.,29.,30.]
02940         array.setValues(arr2,mesh1.getNumberOfCells(),3);
02941         f2.setArray(array);
02942         #
02943         f3=f1.dot(f2);
02944         expected1=[842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.]
02945         for i in xrange(10):
02946             self.assertAlmostEqual(expected1[i],f3.getIJ(i,0),9);
02947             pass
02948         #
02949         f4=f1.crossProduct(f2);
02950         expected2=[-93., 186., -93., -392., 784., -392., -691., 1382., -691., -990., 1980., -990., -1289., 2578., -1289., -1588., 3176., -1588., -1887., 3774., -1887., -2186., 4372., -2186., -2485., 4970., -2485., -2784., 5568., -2784.]
02951         for i in xrange(30):
02952             self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9);
02953             pass
02954         pass
02955 
02956     def testMinMaxFields1(self):
02957         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
02958         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
02959         f1.setTime(2.3,5,6);
02960         f1.setMesh(mesh1);
02961         array=DataArrayDouble.New();
02962         arr1=[7.,107.,207.,8.,108.,208.,9.,109.,209.,10.,110.,210.,11.,111.,211.,12.,112.,212.,13.,113.,213.,14.,114.,214.,15.,115.,215.,16.,116.,216.]
02963         array.setValues(arr1,mesh1.getNumberOfCells(),3);
02964         f1.setArray(array);
02965         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
02966         f2.setTime(7.8,4,5);
02967         f2.setMesh(mesh1);
02968         array=DataArrayDouble.New();
02969         arr2=[6.,108.,206.,9.,107.,209.,8.,110.,208.,11.,109.,211.,10.,112.,210.,13.,111.,213.,12.,114.,212.,15.,113.,215.,14.,116.,214.,17.,115.,217.]
02970         array.setValues(arr2,mesh1.getNumberOfCells(),3);
02971         f2.setArray(array);
02972         #
02973         f3=f1.max(f2);
02974         expected1=[7.,108.,207.,9.,108.,209.,9.,110.,209.,11.,110.,211.,11.,112.,211.,13.,112.,213.,13.,114.,213.,15.,114.,215.,15.,116.,215.,17.,116.,217.]
02975         for i in xrange(30):
02976             self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),9);
02977             pass
02978         #
02979         f4=f1.min(f2);
02980         expected2=[6.,107.,206.,8.,107.,208.,8.,109.,208.,10.,109.,210.,10.,111.,210.,12.,111.,212.,12.,113.,212.,14.,113.,214.,14.,115.,214.,16.,115.,216.]
02981         for i in xrange(30):
02982             self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9);
02983             pass
02984         #
02985         pass
02986 
02987     def testApplyLin1(self):
02988         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
02989         f1=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
02990         f1.setMesh(mesh1);
02991         array=DataArrayDouble.New();
02992         arr=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.]
02993         array.setValues(arr,mesh1.getNumberOfCells(),2);
02994         f1.setArray(array);
02995         #
02996         f1.applyLin(2.,3.,0);
02997         expected1=[17.,107.,19.,108.,21.,109.,23.,110.,25.,111.,27.,112.,29.,113.,31.,114.,33.,115.,35.,116.]
02998         for i in xrange(20):
02999             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),9);
03000             pass
03001         #
03002         arr2=[2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.]
03003         array=DataArrayDouble.New();
03004         array.setValues(arr2,mesh1.getNumberOfCells(),2);
03005         f1.setEndArray(array);
03006         #
03007         f1.applyLin(4.,5.,1);
03008         #
03009         expected2=[17.,433.,19.,437.,21.,441.,23.,445.,25.,449.,27.,453.,29.,457.,31.,461.,33.,465.,35.,469.]
03010         for i in xrange(20):
03011             self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),9);
03012             pass
03013         expected3=[2.,413.,3.,417.,4.,421.,5.,425.,6.,429.,7.,433.,8.,437.,9.,441.,10.,445.,11.,449.]
03014         for i in xrange(20):
03015             self.assertAlmostEqual(expected3[i],f1.getEndArray().getIJ(0,i),9);
03016             pass
03017         #
03018         pass
03019 
03020     def testGetIdsInRange1(self):
03021         mesh1=MEDCouplingDataForTest.build2DTargetMesh_3();
03022         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
03023         f1.setTime(2.3,5,6);
03024         f1.setMesh(mesh1);
03025         array=DataArrayDouble.New();
03026         arr1=[2.,8.,6.,5.,11.,7.,9.,3.,10.,4.]
03027         array.setValues(arr1,mesh1.getNumberOfCells(),1);
03028         f1.setArray(array);
03029         #
03030         f1.checkCoherency();
03031         da=f1.getIdsInRange(2.9,7.1);
03032         self.failUnlessEqual(5,da.getNbOfElems());
03033         expected1=[2,3,5,7,9]
03034         self.failUnlessEqual(expected1,list(da.getValues()));
03035         da=f1.getIdsInRange(8.,12.);
03036         self.failUnlessEqual(4,da.getNbOfElems());
03037         expected2=[1,4,6,8]
03038         self.failUnlessEqual(expected2,list(da.getValues()));
03039         #
03040         pass
03041 
03042     def testBuildSubPart1(self):
03043         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03044         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
03045         f1.setTime(2.3,5,6);
03046         f1.setMesh(mesh1);
03047         array=DataArrayDouble.New();
03048         arr1=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.]
03049         array.setValues(arr1,mesh1.getNumberOfCells(),2);
03050         f1.setArray(array);
03051         #
03052         part1=[2,1,4]
03053         f2=f1.buildSubPart(part1);
03054         f2.zipCoords()
03055         self.failUnlessEqual(3,f2.getNumberOfTuples());
03056         self.failUnlessEqual(2,f2.getNumberOfComponents());
03057         expected1=[5.,105.,4.,104.,7.,107.]
03058         for i in xrange(6):
03059             self.assertAlmostEqual(f2.getIJ(0,i),expected1[i],12);
03060             pass
03061         self.failUnlessEqual(3,f2.getMesh().getNumberOfCells());
03062         self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes());
03063         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
03064         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
03065         m2C=f2.getMesh();
03066         self.failUnlessEqual(13,m2C.getMeshLength());
03067         expected2=[0.2, -0.3, 0.7, -0.3, 0.2, 0.2, 0.7, 0.2, 0.2, 0.7, 0.7, 0.7]
03068         for i in xrange(12):
03069             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
03070             pass
03071         expected3=[3,2,3,1,3,0,2,1,4,4,5,3,2]
03072         self.failUnlessEqual(expected3,list(m2C.getNodalConnectivity().getValues()));
03073         expected4=[0,4,8,13]
03074         self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
03075         # Test with field on nodes.
03076         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
03077         f1.setTime(2.3,5,6);
03078         f1.setMesh(mesh1);
03079         array=DataArrayDouble.New();
03080         arr2=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.]
03081         array.setValues(arr2,mesh1.getNumberOfNodes(),2);
03082         f1.setArray(array);
03083         part2=[1,2]
03084         f2=f1.buildSubPart(part2);
03085         self.failUnlessEqual(4,f2.getNumberOfTuples());
03086         self.failUnlessEqual(2,f2.getNumberOfComponents());
03087         expected5=[4.,104.,5.,105.,7.,107.,8.,108.]
03088         for i in xrange(8):
03089             self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12);
03090             pass
03091         self.failUnlessEqual(2,f2.getMesh().getNumberOfCells());
03092         self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes());
03093         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
03094         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
03095         m2C=f2.getMesh();
03096         self.failUnlessEqual(8,m2C.getMeshLength());
03097         for i in xrange(8):#8 is not an error
03098             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
03099             pass
03100         self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:]);
03101         self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
03102         self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
03103         #idem previous because nodes of cell#4 are not fully present in part3
03104         part3=[1,2]
03105         arrr=DataArrayInt.New();
03106         arrr.setValues(part3,2,1);
03107         f2=f1.buildSubPart(arrr);
03108         self.failUnlessEqual(4,f2.getNumberOfTuples());
03109         self.failUnlessEqual(2,f2.getNumberOfComponents());
03110         for i in xrange(8):
03111             self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12);
03112             pass
03113         self.failUnlessEqual(2,f2.getMesh().getNumberOfCells());
03114         self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes());
03115         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
03116         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
03117         m2C=f2.getMesh();
03118         self.failUnlessEqual(8,m2C.getMeshLength());
03119         for i in xrange(8):#8 is not an error
03120             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
03121             pass
03122         self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
03123         self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]);
03124         self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues()));
03125         #
03126         part4=[1,2,4]
03127         f2=f1.buildSubPart(part4);
03128         self.failUnlessEqual(6,f2.getNumberOfTuples());
03129         self.failUnlessEqual(2,f2.getNumberOfComponents());
03130         expected6=[4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.]
03131         for i in xrange(12):
03132             self.assertAlmostEqual(f2.getIJ(0,i),expected6[i],12);
03133             pass
03134         self.failUnlessEqual(3,f2.getMesh().getNumberOfCells());
03135         self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes());
03136         self.failUnlessEqual(2,f2.getMesh().getSpaceDimension());
03137         self.failUnlessEqual(2,f2.getMesh().getMeshDimension());
03138         m2C=f2.getMesh();
03139         self.failUnlessEqual(13,m2C.getMeshLength());
03140         for i in xrange(12):
03141             self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12);
03142             pass
03143         self.failUnlessEqual(expected3[0:4],list(m2C.getNodalConnectivity().getValues())[4:8]);
03144         self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[0:4]);
03145         self.failUnlessEqual(expected3[8:13],list(m2C.getNodalConnectivity().getValues())[8:13]);
03146         self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues()));
03147         pass
03148 
03149     def testDoublyContractedProduct1(self):
03150         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03151         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
03152         f1.setMesh(mesh1);
03153         array=DataArrayDouble.New();
03154         arr1=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
03155         array.setValues(arr1,mesh1.getNumberOfCells(),6);
03156         f1.setArray(array);
03157         f1.checkCoherency();
03158         #
03159         f2=f1.doublyContractedProduct();
03160         f2.checkCoherency();
03161         self.assertEqual(1,f2.getNumberOfComponents());
03162         self.assertEqual(5,f2.getNumberOfTuples());
03163         for i in xrange(5):
03164             self.assertAlmostEqual(3906.56,f2.getIJ(i,0),9);
03165             pass
03166         #
03167         pass
03168 
03169     def testDeterminant1(self):
03170         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03171         f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
03172         f1.setTime(2.3,5,6);
03173         f1.setEndTime(3.8,7,3);
03174         f1.setMesh(mesh1);
03175         array=DataArrayDouble.New();
03176         arr1=[1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5]
03177         array.setValues(arr1,mesh1.getNumberOfCells(),4);
03178         f1.setArray(array);
03179         #4 components
03180         f1.checkCoherency();
03181         f2=f1.determinant();
03182         f2.checkCoherency();
03183         self.assertEqual(CONST_ON_TIME_INTERVAL,f2.getTimeDiscretization());
03184         self.assertEqual(1,f2.getNumberOfComponents());
03185         self.assertEqual(5,f2.getNumberOfValues());
03186         for i in xrange(5):
03187             self.assertAlmostEqual(-2.42,f2.getIJ(i,0),13);
03188             pass
03189         #6 components multi arrays with end array not defined
03190         f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
03191         f1.setTime(2.3,5,6);
03192         f1.setEndTime(3.8,7,3);
03193         f1.setMesh(mesh1);
03194         array=DataArrayDouble.New();
03195         arr2=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7,
03196               1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
03197         array.setValues(arr2,mesh1.getNumberOfNodes(),6);
03198         f1.setArray(array);
03199         self.assertRaises(InterpKernelException,f1.checkCoherency);#no end array specified !
03200         #
03201         f2=f1.determinant();
03202         self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization());
03203         self.assertEqual(1,f2.getArray().getNumberOfComponents());
03204         self.assertEqual(9,f2.getNumberOfTuples());
03205         for i in xrange(9):
03206             self.assertAlmostEqual(137.335,f2.getIJ(i,0),10);
03207             pass
03208         #6 components multi arrays with end array defined
03209         array=DataArrayDouble.New();
03210         arr3=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5,
03211               7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
03212         array.setValues(arr3,mesh1.getNumberOfNodes(),6);
03213         f1.setEndArray(array);
03214         f1.checkCoherency();
03215         f2=f1.determinant();
03216         f2.checkCoherency();
03217         self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization());
03218         self.assertEqual(1,f2.getNumberOfComponents());
03219         self.assertEqual(9,f2.getNumberOfTuples());
03220         time2,it,order=f2.getTime()
03221         self.assertAlmostEqual(2.3,time2,12);
03222         self.assertEqual(5,it);
03223         self.assertEqual(6,order);
03224         time2,it,order=f2.getEndTime()
03225         self.assertAlmostEqual(3.8,time2,12);
03226         self.assertEqual(7,it);
03227         self.assertEqual(3,order);
03228         for i in xrange(9):
03229             self.assertAlmostEqual(137.335,f2.getIJ(i,0),10);
03230             self.assertAlmostEqual(1289.685,f2.getEndArray().getIJ(i,0),9);
03231             pass
03232         #9 components
03233         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
03234         f1.setTime(7.8,10,2);
03235         f1.setMesh(mesh1);
03236         array=DataArrayDouble.New();
03237         arr4=[1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1]
03238         array.setValues(arr4,mesh1.getNumberOfCells(),9);
03239         f1.setArray(array);
03240         #
03241         f1.checkCoherency();
03242         f2=f1.determinant();
03243         f2.checkCoherency();
03244         self.assertEqual(ONE_TIME,f2.getTimeDiscretization());
03245         self.assertEqual(1,f2.getNumberOfComponents());
03246         self.assertEqual(5,f2.getNumberOfTuples());
03247         time2,it,order=f2.getTime()
03248         self.assertAlmostEqual(7.8,time2,12);
03249         self.assertEqual(10,it);
03250         self.assertEqual(2,order);
03251         for i in xrange(5):
03252             self.assertAlmostEqual(3.267,f2.getIJ(i,0),13);
03253             pass
03254         pass
03255 
03256     def testEigenValues1(self):
03257         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03258         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
03259         f1.setMesh(mesh1);
03260         array=DataArrayDouble.New();
03261         arr1=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
03262         array.setValues(arr1,mesh1.getNumberOfCells(),6);
03263         f1.setArray(array);
03264         f1.checkCoherency();
03265         #
03266         f2=f1.eigenValues();
03267         f2.checkCoherency();
03268         self.assertEqual(3,f2.getNumberOfComponents());
03269         self.assertEqual(5,f2.getNumberOfTuples());
03270         expected1=[13.638813677891717,-4.502313844635971,-2.2364998332557486]
03271         for i in xrange(5):
03272             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
03273             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
03274             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
03275             pass
03276         pass
03277 
03278     def testEigenVectors1(self):
03279         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03280         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
03281         f1.setMesh(mesh1);
03282         array=DataArrayDouble.New();
03283         arr1=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
03284         array.setValues(arr1,mesh1.getNumberOfCells(),6);
03285         f1.setArray(array);
03286         f1.checkCoherency();
03287         #
03288         f2=f1.eigenVectors();
03289         f2.checkCoherency();
03290         self.assertEqual(9,f2.getNumberOfComponents());
03291         self.assertEqual(5,f2.getNumberOfTuples());
03292         expected1=[0.5424262364180696, 0.5351201064614425, 0.6476266283176001,#eigenvect 0
03293                    0.7381111277307373, 0.06458838384003074, -0.6715804522117897,#eigenvect 1
03294                    -0.4012053603397987, 0.8423032781211455, -0.3599436712889738#eigenvect 2
03295                    ]
03296         for i in xrange(5):
03297             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
03298             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
03299             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
03300             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
03301             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
03302             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
03303             self.assertAlmostEqual(expected1[6],f2.getIJ(i,6),13);
03304             self.assertAlmostEqual(expected1[7],f2.getIJ(i,7),13);
03305             self.assertAlmostEqual(expected1[8],f2.getIJ(i,8),13);
03306             pass
03307         #
03308         pass
03309 
03310     def testInverse1(self):
03311         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03312         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
03313         f1.setMesh(mesh1);
03314         array=DataArrayDouble.New();
03315         arr1=[1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1]
03316         array.setValues(arr1,mesh1.getNumberOfCells(),9);
03317         f1.setArray(array);
03318         f1.checkCoherency();
03319         #
03320         f2=f1.inverse();
03321         f2.checkCoherency();
03322         self.assertEqual(9,f2.getNumberOfComponents());
03323         self.assertEqual(5,f2.getNumberOfTuples());
03324         expected1=[-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072]
03325         for i in xrange(5):
03326             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
03327             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
03328             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
03329             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
03330             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
03331             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
03332             self.assertAlmostEqual(expected1[6],f2.getIJ(i,6),13);
03333             self.assertAlmostEqual(expected1[7],f2.getIJ(i,7),13);
03334             self.assertAlmostEqual(expected1[8],f2.getIJ(i,8),13);
03335             pass
03336         #
03337         array=DataArrayDouble.New();
03338         arr3=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
03339         array.setValues(arr3,mesh1.getNumberOfCells(),6);
03340         f1.setArray(array);
03341         f1.checkCoherency();
03342         #
03343         f2=f1.inverse();
03344         f2.checkCoherency();
03345         self.assertEqual(6,f2.getNumberOfComponents());
03346         self.assertEqual(5,f2.getNumberOfTuples());
03347         expected3=[-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887]
03348         for i in xrange(5):
03349             self.assertAlmostEqual(expected3[0],f2.getIJ(i,0),13);
03350             self.assertAlmostEqual(expected3[1],f2.getIJ(i,1),13);
03351             self.assertAlmostEqual(expected3[2],f2.getIJ(i,2),13);
03352             self.assertAlmostEqual(expected3[3],f2.getIJ(i,3),13);
03353             self.assertAlmostEqual(expected3[4],f2.getIJ(i,4),13);
03354             self.assertAlmostEqual(expected3[5],f2.getIJ(i,5),13);
03355             pass
03356         #
03357         array=DataArrayDouble.New();
03358         arr2=[1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5]
03359         array.setValues(arr2,mesh1.getNumberOfCells(),4);
03360         f1.setArray(array);
03361         f1.checkCoherency();
03362         #
03363         f2=f1.inverse();
03364         f2.checkCoherency();
03365         self.assertEqual(4,f2.getNumberOfComponents());
03366         self.assertEqual(5,f2.getNumberOfTuples());
03367         expected2=[-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156]
03368         for i in xrange(5):
03369             self.assertAlmostEqual(expected2[0],f2.getIJ(i,0),13);
03370             self.assertAlmostEqual(expected2[1],f2.getIJ(i,1),13);
03371             self.assertAlmostEqual(expected2[2],f2.getIJ(i,2),13);
03372             self.assertAlmostEqual(expected2[3],f2.getIJ(i,3),13);
03373             pass
03374         #
03375         pass
03376 
03377     def testTrace1(self):
03378         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03379         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
03380         f1.setMesh(mesh1);
03381         array=DataArrayDouble.New();
03382         arr1=[1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1]
03383         array.setValues(arr1,mesh1.getNumberOfCells(),9);
03384         f1.setArray(array);
03385         f1.checkCoherency();
03386         #
03387         f2=f1.trace();
03388         f2.checkCoherency();
03389         self.assertEqual(1,f2.getNumberOfComponents());
03390         self.assertEqual(5,f2.getNumberOfTuples());
03391         for i in xrange(5):
03392             self.assertAlmostEqual(15.9,f2.getIJ(i,0),13);
03393             pass
03394         #
03395         array=DataArrayDouble.New();
03396         arr3=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
03397         array.setValues(arr3,mesh1.getNumberOfCells(),6);
03398         f1.setArray(array);
03399         f1.checkCoherency();
03400         #
03401         f2=f1.trace();
03402         f2.checkCoherency();
03403         self.assertEqual(1,f2.getNumberOfComponents());
03404         self.assertEqual(5,f2.getNumberOfTuples());
03405         for i in xrange(5):
03406             self.assertAlmostEqual(25.8,f2.getIJ(i,0),13);
03407             pass
03408         #
03409         array=DataArrayDouble.New();
03410         arr2=[1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5]
03411         array.setValues(arr2,mesh1.getNumberOfCells(),4);
03412         f1.setArray(array);
03413         f1.checkCoherency();
03414         #
03415         f2=f1.trace();
03416         f2.checkCoherency();
03417         self.assertEqual(1,f2.getNumberOfComponents());
03418         self.assertEqual(5,f2.getNumberOfTuples());
03419         for i in xrange(5):
03420             self.assertAlmostEqual(5.7,f2.getIJ(i,0),13);
03421             pass
03422         #
03423         pass
03424 
03425     def testDeviator1(self):
03426         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03427         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
03428         f1.setMesh(mesh1);
03429         array=DataArrayDouble.New();
03430         arr1=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
03431         array.setValues(arr1,mesh1.getNumberOfCells(),6);
03432         f1.setArray(array);
03433         f1.checkCoherency();
03434         #
03435         f2=f1.deviator();
03436         f2.checkCoherency();
03437         self.assertEqual(6,f2.getNumberOfComponents());
03438         self.assertEqual(5,f2.getNumberOfTuples());
03439         expected1=[-1.1,0.,1.1,4.5,5.6,6.7]
03440         for i in xrange(5):
03441             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
03442             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
03443             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
03444             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
03445             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
03446             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
03447             pass
03448         #
03449         pass
03450 
03451     def testMagnitude1(self):
03452         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03453         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
03454         f1.setMesh(mesh1);
03455         array=DataArrayDouble.New();
03456         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6]
03457         array.setValues(arr1,mesh1.getNumberOfCells(),5);
03458         f1.setArray(array);
03459         f1.checkCoherency();
03460         #
03461         f2=f1.magnitude();
03462         f2.checkCoherency();
03463         self.assertEqual(1,f2.getNumberOfComponents());
03464         self.assertEqual(5,f2.getNumberOfTuples());
03465         for i in xrange(5):
03466             self.assertAlmostEqual(8.3606219864313918,f2.getIJ(i,0),13);
03467             pass
03468         #
03469         pass
03470 
03471     def testMaxPerTuple1(self):
03472         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03473         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
03474         f1.setMesh(mesh1);
03475         array=DataArrayDouble.New();
03476         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4]
03477         array.setValues(arr1,mesh1.getNumberOfCells(),5);
03478         f1.setArray(array);
03479         f1.checkCoherency();
03480         #
03481         f2=f1.maxPerTuple();
03482         f2.checkCoherency();
03483         self.assertEqual(1,f2.getNumberOfComponents());
03484         self.assertEqual(5,f2.getNumberOfTuples());
03485         for i in xrange(5):
03486             self.assertAlmostEqual(5.6,f2.getIJ(i,0),13);
03487             pass
03488         #
03489         pass
03490 
03491     def testChangeNbOfComponents(self):
03492         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03493         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
03494         f1.setMesh(mesh1);
03495         array=DataArrayDouble.New();
03496         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4]
03497         array.setValues(arr1,mesh1.getNumberOfCells(),5);
03498         f1.setArray(array);
03499         f1.checkCoherency();
03500         #
03501         f1.changeNbOfComponents(3,7.77);
03502         f1.checkCoherency();
03503         self.assertEqual(3,f1.getNumberOfComponents());
03504         self.assertEqual(5,f1.getNumberOfTuples());
03505         expected1=[1.2,2.3,3.4, 1.2,3.4,4.5, 3.4,4.5,5.6, 5.6,1.2,2.3, 4.5,5.6,1.2]
03506         for i in xrange(15):
03507             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),13);
03508             pass
03509         f1.changeNbOfComponents(4,7.77);
03510         f1.checkCoherency();
03511         self.assertEqual(4,f1.getNumberOfComponents());
03512         self.assertEqual(5,f1.getNumberOfTuples());
03513         expected2=[1.2,2.3,3.4,7.77, 1.2,3.4,4.5,7.77, 3.4,4.5,5.6,7.77, 5.6,1.2,2.3,7.77, 4.5,5.6,1.2,7.77]
03514         for i in xrange(20):
03515             self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),13);
03516             pass
03517         #
03518         pass
03519 
03520     def testSortPerTuple1(self):
03521         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03522         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
03523         f1.setMesh(mesh1);
03524         array=DataArrayDouble.New();
03525         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4]
03526         array.setValues(arr1,mesh1.getNumberOfCells(),5);
03527         f1.setArray(array);
03528         f1.checkCoherency();
03529         #
03530         f1.sortPerTuple(True);
03531         f1.checkCoherency();
03532         self.assertEqual(5,f1.getNumberOfComponents());
03533         self.assertEqual(5,f1.getNumberOfTuples());
03534         for i in xrange(5):
03535             self.assertAlmostEqual(arr1[0],f1.getIJ(i,0),13);
03536             self.assertAlmostEqual(arr1[1],f1.getIJ(i,1),13);
03537             self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13);
03538             self.assertAlmostEqual(arr1[3],f1.getIJ(i,3),13);
03539             self.assertAlmostEqual(arr1[4],f1.getIJ(i,4),13);
03540             pass
03541         #
03542         f1.sortPerTuple(False);
03543         f1.checkCoherency();
03544         self.assertEqual(5,f1.getNumberOfComponents());
03545         self.assertEqual(5,f1.getNumberOfTuples());
03546         for i in xrange(5):
03547             self.assertAlmostEqual(arr1[4],f1.getIJ(i,0),13);
03548             self.assertAlmostEqual(arr1[3],f1.getIJ(i,1),13);
03549             self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13);
03550             self.assertAlmostEqual(arr1[1],f1.getIJ(i,3),13);
03551             self.assertAlmostEqual(arr1[0],f1.getIJ(i,4),13);
03552             pass
03553         #
03554         pass
03555 
03556     def testIsEqualWithoutConsideringStr1(self):
03557         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03558         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
03559         #
03560         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
03561         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03562         mesh2.setName("rr");
03563         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
03564         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03565         da1,da2=mesh1.checkGeoEquivalWith(mesh2,2,1e-12);
03566         self.assertRaises(InterpKernelException,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);
03567         mesh2.setName("");
03568         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
03569         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03570         mesh2.getCoords().setInfoOnComponent(0,"tty");
03571         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
03572         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03573         mesh2.getCoords().setInfoOnComponent(0,"");
03574         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
03575         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03576         mesh2.getCoords().setInfoOnComponent(1,"tty");
03577         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
03578         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03579         mesh2.getCoords().setInfoOnComponent(1,"");
03580         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
03581         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03582         tmp=mesh2.getCoords().getIJ(0,3);
03583         mesh2.getCoords().setIJ(0,3,9999.);
03584         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
03585         self.assertTrue(not mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03586         mesh2.getCoords().setIJ(0,3,tmp);
03587         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
03588         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03589         tmp2=mesh2.getNodalConnectivity().getIJ(0,4);
03590         mesh2.getNodalConnectivity().setIJ(0,4,0);
03591         self.assertTrue(not mesh1.isEqual(mesh2,1e-12));
03592         self.assertTrue(not mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03593         mesh2.getNodalConnectivity().setIJ(0,4,tmp2);
03594         self.assertTrue(mesh1.isEqual(mesh2,1e-12));
03595         self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12));
03596         #
03597         f1=mesh1.getMeasureField(True);
03598         f2=mesh2.getMeasureField(True);
03599         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
03600         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
03601         f2.setName("ftest");
03602         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12));
03603         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
03604         f1.setName("ftest");
03605         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
03606         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
03607         #
03608         f2.getArray().setInfoOnComponent(0,"eee");
03609         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12));
03610         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
03611         f2.getArray().setInfoOnComponent(0,"");
03612         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
03613         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
03614         #
03615         f2.getArray().setIJ(1,0,0.123);
03616         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12));
03617         self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
03618         f2.getArray().setIJ(1,0,0.125);
03619         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
03620         self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12));
03621         #
03622         pass
03623     
03624     def testGetNodeIdsOfCell1(self):
03625         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
03626         li=mesh1.getNodeIdsOfCell(1)
03627         expected1=[1, 4, 2]
03628         self.assertEqual(expected1,list(li))
03629         li=mesh1.getCoordinatesOfNode(4)
03630         self.assertEqual(2,len(li))
03631         self.assertAlmostEqual(0.2,li[0],13);
03632         self.assertAlmostEqual(0.2,li[1],13);
03633         li=mesh1.getCoords().getValuesAsTuple()
03634         self.assertEqual(9,len(li))
03635         li2=mesh1.getNodalConnectivityIndex().getValuesAsTuple()
03636         self.assertEqual(6,len(li2))
03637         pass
03638 
03639     def testGetEdgeRatioField1(self):
03640         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
03641         f1=m1.getEdgeRatioField();
03642         self.assertEqual(m1.getNumberOfCells(),f1.getNumberOfTuples());
03643         self.assertEqual(5,f1.getNumberOfTuples());
03644         self.assertEqual(1,f1.getNumberOfComponents());
03645         expected1=[1.,1.4142135623730951, 1.4142135623730951,1.,1.]
03646         for i in xrange(5):
03647             self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),14);
03648             pass
03649         #
03650         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
03651         f1=m1.getEdgeRatioField();
03652         self.assertEqual(m1.getNumberOfCells(),f1.getNumberOfTuples());
03653         self.assertEqual(5,f1.getNumberOfTuples());
03654         self.assertEqual(1,f1.getNumberOfComponents());
03655         expected2=[1.4142135623730951, 1.7320508075688772, 1.7320508075688772, 1.4142135623730951, 1.4142135623730951]
03656         for i in xrange(5):
03657             self.assertAlmostEqual(expected2[i],f1.getIJ(i,0),14);
03658             pass
03659         pass
03660 
03661     def testFillFromAnalytic3(self):
03662         m=MEDCouplingDataForTest.build2DTargetMesh_1()
03663         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME)
03664         self.assertRaises(InterpKernelException,f1.fillFromAnalytic,1,"y+x");
03665         f1.setMesh(m)
03666         f1.setName("myField");
03667         f1.fillFromAnalytic(1,"y+x");
03668         f1.checkCoherency();
03669         self.assertEqual(f1.getName(),"myField");
03670         self.assertEqual(f1.getTypeOfField(),ON_CELLS);
03671         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
03672         self.assertEqual(1,f1.getNumberOfComponents());
03673         self.assertEqual(5,f1.getNumberOfTuples());
03674         values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9]
03675         tmp=f1.getArray().getValues();
03676         self.assertEqual(len(values1),len(tmp))
03677         for i in xrange(len(values1)):
03678             self.assertTrue(abs(values1[i]-tmp[i])<1.e-12);
03679             pass
03680         #
03681         f1=MEDCouplingFieldDouble.New(ON_NODES,CONST_ON_TIME_INTERVAL)
03682         f1.setMesh(m)
03683         f1.fillFromAnalytic(1,"y+2*x");
03684         f1.setEndTime(1.2,3,4);
03685         f1.checkCoherency();
03686         self.assertEqual(f1.getTypeOfField(),ON_NODES);
03687         self.assertEqual(f1.getTimeDiscretization(),CONST_ON_TIME_INTERVAL);
03688         self.assertEqual(1,f1.getNumberOfComponents());
03689         self.assertEqual(9,f1.getNumberOfTuples());
03690         values2=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
03691         tmp=f1.getArray().getValues();
03692         self.assertEqual(len(values2),len(tmp))
03693         for i in xrange(len(values2)):
03694             self.assertTrue(abs(values2[i]-tmp[i])<1.e-12);
03695             pass
03696         f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
03697         f1.setMesh(m)
03698         f1.fillFromAnalytic(1,"2.*x+y");
03699         f1.setEndTime(1.2,3,4);
03700         f1.checkCoherency();
03701         self.assertEqual(f1.getTypeOfField(),ON_NODES);
03702         self.assertEqual(f1.getTimeDiscretization(),LINEAR_TIME);
03703         self.assertEqual(1,f1.getNumberOfComponents());
03704         self.assertEqual(9,f1.getNumberOfTuples());
03705         tmp=f1.getArray().getValues();
03706         values2Bis=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1]
03707         self.assertEqual(len(values2Bis),len(tmp))
03708         for i in xrange(len(values2Bis)):
03709             self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
03710             pass
03711         tmp=f1.getEndArray().getValues();
03712         self.assertEqual(len(values2Bis),len(tmp))
03713         for i in xrange(len(values2Bis)):
03714             self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12);
03715             pass
03716         #
03717         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
03718         f1.setMesh(m)
03719         f1.fillFromAnalytic(2,"(x+y)*IVec+2*(x+y)*JVec");
03720         f1.checkCoherency();
03721         self.assertEqual(f1.getTypeOfField(),ON_NODES);
03722         self.assertEqual(f1.getTimeDiscretization(),ONE_TIME);
03723         self.assertEqual(2,f1.getNumberOfComponents());
03724         self.assertEqual(9,f1.getNumberOfTuples());
03725         values3=[-0.6,-1.2,-0.1,-0.2,0.4,0.8,-0.1,-0.2,0.4,0.8,0.9,1.8,0.4,0.8,0.9,1.8,1.4,2.8]
03726         tmp=f1.getArray().getValues();
03727         self.assertEqual(len(values3),len(tmp))
03728         for i in xrange(len(values3)):
03729             self.assertTrue(abs(values3[i]-tmp[i])<1.e-12);
03730             pass
03731         values4=f1.accumulate();
03732         self.assertTrue(abs(3.6-values4[0])<1.e-12);
03733         self.assertTrue(abs(7.2-values4[1])<1.e-12);
03734         values4=f1.integral(True);
03735         self.assertTrue(abs(0.5-values4[0])<1.e-12);
03736         self.assertTrue(abs(1.-values4[1])<1.e-12);
03737         #
03738         f1=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
03739         f1.setMesh(m);
03740         self.assertRaises(InterpKernelException,f1.fillFromAnalytic,1,"1./(x-0.2)");
03741         pass
03742 
03743     def testFieldDoubleOpEqual1(self):
03744         m=MEDCouplingDataForTest.build2DTargetMesh_1();
03745         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
03746         self.assertRaises(InterpKernelException,f1.assign,0.07);
03747         f1.setMesh(m);
03748         f1.assign(0.07);
03749         f1.checkCoherency();
03750         self.assertEqual(1,f1.getNumberOfComponents());
03751         self.assertEqual(5,f1.getNumberOfTuples());
03752         for i in xrange(5):
03753             self.assertAlmostEqual(0.07,f1.getIJ(i,0),16);
03754             pass
03755         f1.assign(0.09);
03756         f1.checkCoherency();
03757         self.assertEqual(1,f1.getNumberOfComponents());
03758         self.assertEqual(5,f1.getNumberOfTuples());
03759         for i in xrange(5):
03760             self.assertAlmostEqual(0.09,f1.getIJ(i,0),16);
03761             pass
03762         #
03763         f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
03764         f1.setEndTime(4.5,2,3);
03765         f1.setMesh(m);
03766         f1.assign(0.08);
03767         f1.checkCoherency();
03768         self.assertEqual(1,f1.getNumberOfComponents());
03769         self.assertEqual(9,f1.getNumberOfTuples());
03770         for i in xrange(9):
03771             self.assertAlmostEqual(0.08,f1.getIJ(i,0),16);
03772             pass
03773         self.assertEqual(1,f1.getEndArray().getNumberOfComponents());
03774         self.assertEqual(9,f1.getEndArray().getNumberOfTuples());
03775         for i in xrange(9):
03776             self.assertAlmostEqual(0.08,f1.getEndArray().getIJ(i,0),16);
03777             pass
03778         pass
03779 
03780     def testAreaBary3D2(self):
03781         coordsForHexa8=[-75.45749305371, 180.95495078401, 39.515472018008,
03782                         -9.755591679144, 23.394927935279, 5.108794294848,
03783                         14.337630157832, 61.705351002702, 160.42422501908,
03784                         -27.273893776752, 167.567731083961, 192.830034145464,
03785                         99.857193154796,264.499264735586,-8.287335493412,
03786                         144.939882761126,156.38626563134,-31.896173894226,
03787                         161.34096835726,182.4654895809,73.832387065572,
03788                         132.680430393685,255.37973247196,96.15235602819];
03789         volHexa8=3258520.29637466;
03790         baryHexa8=[43.925705821778, 155.31893955289, 65.874418109644]
03791         
03792         coordsForPenta6=[-68.199829618726,178.938498373416,62.608505919588,
03793                          8.461744647847,76.653979804423,165.00018874933,
03794                          -27.273893776752,167.567731083961,192.830034145464,
03795                          106.586501038965,262.629609408327,13.124533008813,
03796                          155.465082847275,197.414118382622,78.408350795821,
03797                          132.680430393685,255.37973247196,96.15235602819];
03798         volPenta6=944849.868507338;
03799         baryPenta6=[39.631002313543,182.692711783428,106.98540473964]
03800         
03801         coordsForPyra5=[132.680430393685,255.37973247196,96.15235602819,
03802                         -27.273893776752,167.567731083961,192.830034145464,
03803                         8.461744647847,76.653979804423,165.00018874933,
03804                         155.465082847275,197.414118382622,78.408350795821,
03805                         -68.199829618726,178.938498373416,62.608505919588];
03806         volPyra5=756943.92980254;
03807         baryPyra5=[29.204294116618,172.540129749156,118.01035951483]
03808         mesh=MEDCouplingUMesh.New("Bary3D2",3);
03809         coo=DataArrayDouble.New();
03810         tmp=coordsForHexa8+coordsForPenta6+coordsForPyra5
03811         coo.setValues(tmp,19,3);
03812         mesh.setCoords(coo);
03813         #
03814         tmpConn=[0,1,2,3,4,5,6,7]
03815         mesh.allocateCells(3);
03816         self.assertRaises(InterpKernelException,mesh.insertNextCell,NORM_HEXA8,9,tmpConn[0:8])
03817         mesh.insertNextCell(NORM_HEXA8,tmpConn[0:8])
03818         mesh.insertNextCell(NORM_PENTA6,6,[i+8 for i in tmpConn])
03819         mesh.insertNextCell(NORM_PYRA5,5,[i+14 for i in tmpConn])
03820         mesh.finishInsertingCells();
03821         mesh.checkCoherency();
03822         mesh.mergeNodes(1e-7)
03823         self.assertEqual(12,mesh.getNumberOfNodes());
03824         vols=mesh.getMeasureField(True);
03825         self.assertEqual(3,vols.getNumberOfTuples());
03826         self.assertEqual(1,vols.getNumberOfComponents());
03827         self.assertAlmostEqual(volHexa8,vols.getIJ(0,0),6);
03828         self.assertAlmostEqual(volPenta6,vols.getIJ(1,0),7);
03829         self.assertAlmostEqual(volPyra5,vols.getIJ(2,0),7);
03830         bary=mesh.getBarycenterAndOwner();
03831         self.assertEqual(3,bary.getNumberOfTuples());
03832         self.assertEqual(3,bary.getNumberOfComponents());
03833         self.assertAlmostEqual(baryHexa8[0],bary.getIJ(0,0),11);
03834         self.assertAlmostEqual(baryHexa8[1],bary.getIJ(0,1),11);
03835         self.assertAlmostEqual(baryHexa8[2],bary.getIJ(0,2),11);
03836         self.assertAlmostEqual(baryPenta6[0],bary.getIJ(1,0),11);
03837         self.assertAlmostEqual(baryPenta6[1],bary.getIJ(1,1),11);
03838         self.assertAlmostEqual(baryPenta6[2],bary.getIJ(1,2),11);
03839         self.assertAlmostEqual(baryPyra5[0],bary.getIJ(2,0),11);
03840         self.assertAlmostEqual(baryPyra5[1],bary.getIJ(2,1),11);
03841         self.assertAlmostEqual(baryPyra5[2],bary.getIJ(2,2),11);
03842         pass
03843 
03844     def testGetMeasureFieldCMesh1(self):
03845         m=MEDCouplingCMesh.New();
03846         da=DataArrayDouble.New();
03847         discX=[2.3,3.4,5.8,10.2]
03848         discY=[12.3,23.4,45.8]
03849         discZ=[-0.7,1.2,1.25,2.13,2.67]
03850         da.setValues(discX,4,1);
03851         m.setCoordsAt(0,da);
03852         m.checkCoherency();
03853         self.assertEqual(4,m.getNumberOfNodes());
03854         self.assertEqual(3,m.getNumberOfCells());
03855         self.assertEqual(1,m.getSpaceDimension());
03856         f=m.getMeasureField(True);
03857         self.assertEqual(3,f.getNumberOfTuples());
03858         self.assertEqual(1,f.getNumberOfComponents());
03859         expected1=[1.1,2.4,4.4]
03860         for i in xrange(3):
03861             self.assertAlmostEqual(expected1[i],f.getIJ(i,0),12);
03862             pass
03863         coords=m.getCoordinatesAndOwner();
03864         self.assertEqual(4,coords.getNumberOfTuples());
03865         self.assertEqual(1,coords.getNumberOfComponents());
03866         for i in xrange(4):
03867             self.assertAlmostEqual(discX[i],coords.getIJ(i,0),12);
03868             pass
03869         coords=m.getBarycenterAndOwner();
03870         self.assertEqual(3,coords.getNumberOfTuples());
03871         self.assertEqual(1,coords.getNumberOfComponents());
03872         expected1_3=[2.85,4.6,8.]
03873         for i in xrange(3):
03874             self.assertAlmostEqual(expected1_3[i],coords.getIJ(i,0),12);
03875             pass
03876         #
03877         da=DataArrayDouble.New();
03878         da.setValues(discY,3,1);
03879         m.setCoordsAt(1,da);
03880         m.checkCoherency();
03881         self.assertEqual(12,m.getNumberOfNodes());
03882         self.assertEqual(6,m.getNumberOfCells());
03883         self.assertEqual(2,m.getSpaceDimension());
03884         f=m.getMeasureField(True);
03885         self.assertEqual(6,f.getNumberOfTuples());
03886         self.assertEqual(1,f.getNumberOfComponents());
03887         expected2=[12.21,26.64,48.84,24.64,53.76,98.56]
03888         for i in xrange(6):
03889             self.assertAlmostEqual(expected2[i],f.getIJ(i,0),12);
03890             pass
03891         coords=m.getCoordinatesAndOwner();
03892         self.assertEqual(12,coords.getNumberOfTuples());
03893         self.assertEqual(2,coords.getNumberOfComponents());
03894         expected2_2=[2.3,12.3,3.4,12.3,5.8,12.3,10.2,12.3, 2.3,23.4,3.4,23.4,5.8,23.4,10.2,23.4, 2.3,45.8,3.4,45.8,5.8,45.8,10.2,45.8]
03895         for i in xrange(24):
03896             self.assertAlmostEqual(expected2_2[i],coords.getIJ(0,i),12);
03897             pass
03898         coords=m.getBarycenterAndOwner();
03899         self.assertEqual(6,coords.getNumberOfTuples());
03900         self.assertEqual(2,coords.getNumberOfComponents());
03901         expected2_3=[2.85,17.85,4.6,17.85,8.,17.85, 2.85,34.6,4.6,34.6,8.,34.6]
03902         for i in xrange(12):
03903             self.assertAlmostEqual(expected2_3[i],coords.getIJ(0,i),12);
03904             pass
03905         #
03906         da=DataArrayDouble.New();
03907         da.setValues(discZ,5,1);
03908         m.setCoordsAt(2,da);
03909         m.checkCoherency();
03910         self.assertEqual(60,m.getNumberOfNodes());
03911         self.assertEqual(24,m.getNumberOfCells());
03912         self.assertEqual(3,m.getSpaceDimension());
03913         f=m.getMeasureField(True);
03914         self.assertEqual(24,f.getNumberOfTuples());
03915         self.assertEqual(1,f.getNumberOfComponents());
03916         expected3=[23.199, 50.616, 92.796, 46.816, 102.144, 187.264, 0.6105, 1.332, 2.442, 1.232, 2.688, 4.928, 10.7448, 23.4432, 42.9792, 21.6832, 47.3088, 86.7328, 6.5934, 14.3856, 26.3736, 13.3056, 29.0304, 53.2224]
03917         for i in xrange(24):
03918             self.assertAlmostEqual(expected3[i],f.getIJ(i,0),12);
03919             pass
03920         coords=m.getCoordinatesAndOwner();
03921         self.assertEqual(60,coords.getNumberOfTuples());
03922         self.assertEqual(3,coords.getNumberOfComponents());
03923         expected3_2=[
03924             2.3,12.3,-0.7, 3.4,12.3,-0.7, 5.8,12.3,-0.7, 10.2,12.3,-0.7, 2.3,23.4,-0.7, 3.4,23.4,-0.7, 5.8,23.4,-0.7, 10.2,23.4,-0.7, 2.3,45.8,-0.7, 3.4,45.8,-0.7, 5.8,45.8,-0.7, 10.2,45.8,-0.7,
03925             2.3,12.3,1.2, 3.4,12.3,1.2, 5.8,12.3,1.2, 10.2,12.3,1.2, 2.3,23.4,1.2, 3.4,23.4,1.2, 5.8,23.4,1.2, 10.2,23.4,1.2, 2.3,45.8,1.2, 3.4,45.8,1.2, 5.8,45.8,1.2, 10.2,45.8,1.2,
03926             2.3,12.3,1.25, 3.4,12.3,1.25, 5.8,12.3,1.25, 10.2,12.3,1.25, 2.3,23.4,1.25, 3.4,23.4,1.25, 5.8,23.4,1.25, 10.2,23.4,1.25, 2.3,45.8,1.25, 3.4,45.8,1.25, 5.8,45.8,1.25, 10.2,45.8,1.25,
03927             2.3,12.3,2.13, 3.4,12.3,2.13, 5.8,12.3,2.13, 10.2,12.3,2.13, 2.3,23.4,2.13, 3.4,23.4,2.13, 5.8,23.4,2.13, 10.2,23.4,2.13, 2.3,45.8,2.13, 3.4,45.8,2.13, 5.8,45.8,2.13, 10.2,45.8,2.13,
03928             2.3,12.3,2.67, 3.4,12.3,2.67, 5.8,12.3,2.67, 10.2,12.3,2.67, 2.3,23.4,2.67, 3.4,23.4,2.67, 5.8,23.4,2.67, 10.2,23.4,2.67, 2.3,45.8,2.67, 3.4,45.8,2.67, 5.8,45.8,2.67, 10.2,45.8,2.67];
03929         for i in xrange(180):
03930             self.assertAlmostEqual(expected3_2[i],coords.getIJ(0,i),12);
03931             pass
03932         coords=m.getBarycenterAndOwner();
03933         self.assertEqual(24,coords.getNumberOfTuples());
03934         self.assertEqual(3,coords.getNumberOfComponents());
03935         expected3_3=[
03936             2.85,17.85,0.25,4.6,17.85,0.25,8.,17.85,0.25, 2.85,34.6,0.25,4.6,34.6,0.25,8.,34.6,0.25,
03937             2.85,17.85,1.225,4.6,17.85,1.225,8.,17.85,1.225, 2.85,34.6,1.225,4.6,34.6,1.225,8.,34.6,1.225,
03938             2.85,17.85,1.69,4.6,17.85,1.69,8.,17.85,1.69, 2.85,34.6,1.69,4.6,34.6,1.69,8.,34.6,1.69,
03939             2.85,17.85,2.4,4.6,17.85,2.4,8.,17.85,2.4, 2.85,34.6,2.4,4.6,34.6,2.4,8.,34.6,2.4];
03940         for i in xrange(72):
03941             self.assertAlmostEqual(expected3_3[i],coords.getIJ(0,i),12);
03942             pass
03943         pass
03944 
03945     def testFieldDoubleZipCoords1(self):
03946         m=MEDCouplingDataForTest.build2DTargetMeshMergeNode_1();
03947         f=m.fillFromAnalytic(ON_NODES,2,"x*2.");
03948         f.getArray().setInfoOnComponent(0,"titi");
03949         f.getArray().setInfoOnComponent(1,"tutu");
03950         f.checkCoherency();
03951         self.assertEqual(18,f.getNumberOfTuples());
03952         self.assertEqual(2,f.getNumberOfComponents());
03953         expected1=[-0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4]
03954         for i in xrange(36):
03955             self.assertAlmostEqual(expected1[i],f.getIJ(0,i),12);
03956             pass
03957         self.assertTrue(f.zipCoords());
03958         f.checkCoherency();
03959         expected2=[-0.6, -0.6, 1.4, 1.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 1.4, 1.4, -0.6, -0.6, 0.4, 0.4, 1.4, 1.4, 0.4, 0.4]
03960         for i in xrange(30):
03961             self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
03962             pass
03963         self.assertTrue(not f.zipCoords());
03964         f.checkCoherency();
03965         for i in xrange(30):
03966             self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
03967             pass
03968         self.assertTrue(f.getArray().getInfoOnComponent(0)=="titi");
03969         self.assertTrue(f.getArray().getInfoOnComponent(1)=="tutu");
03970         pass
03971 
03972     def testFieldDoubleZipConnectivity1(self):
03973         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
03974         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
03975         cells1=[2,3,4]
03976         m3_1=m2.buildPartOfMySelf(cells1,True);
03977         m3=m3_1;
03978         m4=MEDCouplingDataForTest.build2DSourceMesh_1();
03979         m5=MEDCouplingUMesh.MergeUMeshes(m1,m3);
03980         m6=MEDCouplingUMesh.MergeUMeshes(m5,m4);
03981         #
03982         self.assertEqual(10,m6.getNumberOfCells());
03983         self.assertEqual(22,m6.getNumberOfNodes());
03984         arr,areNodesMerged,newNbOfNodes=m6.mergeNodes(1e-13);
03985         self.assertEqual(9,m6.getNumberOfNodes());
03986         f=m6.fillFromAnalytic(ON_CELLS,2,"x");
03987         f2=m6.fillFromAnalytic(ON_NODES,2,"x");
03988         self.assertEqual(10,f.getNumberOfTuples());
03989         self.assertEqual(2,f.getNumberOfComponents());
03990         expected1=[-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
03991                    -0.05, -0.05, 0.45, 0.45, 0.53333333333333321, 0.53333333333333321, -0.05, -0.05, 0.45, 0.45,
03992                    0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326];
03993         for i in xrange(20):
03994             self.assertAlmostEqual(expected1[i],f.getIJ(0,i),12);
03995             pass
03996         f.getArray().setInfoOnComponent(0,"titi");
03997         f.getArray().setInfoOnComponent(1,"tutu");
03998         f.checkCoherency();
03999         self.assertTrue(f.zipConnectivity(0));
04000         expected2=[-0.05, -0.05, 0.3666666666666667, 0.3666666666666667, 0.53333333333333321, 0.53333333333333321,
04001                    -0.05, -0.05, 0.45, 0.45, 0.36666666666666659, 0.36666666666666659, 0.033333333333333326, 0.033333333333333326];
04002         self.assertEqual(7,f.getNumberOfTuples());
04003         self.assertEqual(2,f.getNumberOfComponents());
04004         for i in xrange(14):
04005             self.assertAlmostEqual(expected2[i],f.getIJ(0,i),12);
04006             pass
04007         self.assertTrue(f.getArray().getInfoOnComponent(0)=="titi");
04008         self.assertTrue(f.getArray().getInfoOnComponent(1)=="tutu");
04009         self.assertTrue(not f.zipConnectivity(0));
04010         #
04011         expected3=[-0.3, -0.3, 0.2, 0.2, 0.7, 0.7, -0.3, -0.3, 0.2, 0.2, 0.7, 0.7,
04012                    -0.3, -0.3, 0.2, 0.2, 0.7, 0.7];
04013         self.assertEqual(9,f2.getNumberOfTuples());
04014         self.assertEqual(2,f2.getNumberOfComponents());
04015         for i in xrange(18):
04016             self.assertAlmostEqual(expected3[i],f2.getIJ(0,i),12);
04017             pass
04018         self.assertTrue(f2.zipConnectivity(0));
04019         self.assertEqual(9,f2.getNumberOfTuples());
04020         self.assertEqual(2,f2.getNumberOfComponents());
04021         for i in xrange(18):
04022             self.assertAlmostEqual(expected3[i],f2.getIJ(0,i),12);
04023             pass
04024         pass
04025 
04026     def testDaDoubleRenumber1(self):
04027         a=DataArrayDouble.New();
04028         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
04029         a.setValues(arr1,7,2);
04030         a.setInfoOnComponent(0,"toto");
04031         a.setInfoOnComponent(1,"tata");
04032         #
04033         arr2=[3,1,0,6,5,4,2]
04034         b=a.renumber(arr2);
04035         self.assertEqual(7,b.getNumberOfTuples());
04036         self.assertEqual(2,b.getNumberOfComponents());
04037         self.assertTrue(b.getInfoOnComponent(0)=="toto");
04038         self.assertTrue(b.getInfoOnComponent(1)=="tata");
04039         expected1=[3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1]
04040         for i in xrange(14):
04041             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
04042             pass
04043         #
04044         c=DataArrayInt.New();
04045         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
04046         c.setValues(arr3,7,2);
04047         c.setInfoOnComponent(0,"toto");
04048         c.setInfoOnComponent(1,"tata");
04049         d=c.renumber(arr2);
04050         self.assertEqual(7,d.getNumberOfTuples());
04051         self.assertEqual(2,d.getNumberOfComponents());
04052         self.assertTrue(d.getInfoOnComponent(0)=="toto");
04053         self.assertTrue(d.getInfoOnComponent(1)=="tata");
04054         expected2=[3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14]
04055         for i in xrange(14):
04056             self.assertEqual(expected2[i],d.getIJ(0,i));
04057             pass
04058         pass
04059 
04060     def testDaDoubleRenumberAndReduce1(self):
04061         a=DataArrayDouble.New();
04062         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
04063         a.setValues(arr1,7,2);
04064         a.setInfoOnComponent(0,"toto");
04065         a.setInfoOnComponent(1,"tata");
04066         #
04067         arr2=[2,-1,1,-1,0,4,3]
04068         b=a.renumberAndReduce(arr2,5);
04069         self.assertEqual(5,b.getNumberOfTuples());
04070         self.assertEqual(2,b.getNumberOfComponents());
04071         self.assertTrue(b.getInfoOnComponent(0)=="toto");
04072         self.assertTrue(b.getInfoOnComponent(1)=="tata");
04073         expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
04074         for i in xrange(10):
04075             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
04076             pass
04077         #
04078         c=DataArrayInt.New();
04079         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
04080         c.setValues(arr3,7,2);
04081         c.setInfoOnComponent(0,"toto");
04082         c.setInfoOnComponent(1,"tata");
04083         d=c.renumberAndReduce(arr2,5);
04084         self.assertEqual(5,d.getNumberOfTuples());
04085         self.assertEqual(2,d.getNumberOfComponents());
04086         self.assertTrue(d.getInfoOnComponent(0)=="toto");
04087         self.assertTrue(d.getInfoOnComponent(1)=="tata");
04088         expected2=[5,15,3,13,1,11,7,17,6,16]
04089         for i in xrange(10):
04090             self.assertEqual(expected2[i],d.getIJ(0,i));
04091             pass
04092         pass
04093 
04094     def testDaDoubleRenumberInPlace1(self):
04095         a=DataArrayDouble.New();
04096         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
04097         a.setValues(arr1,7,2);
04098         #
04099         arr2=[3,1,0,6,5,4,2]
04100         a.renumberInPlace(arr2);
04101         self.assertEqual(7,a.getNumberOfTuples());
04102         self.assertEqual(2,a.getNumberOfComponents());
04103         expected1=[3.1, 13.1, 2.1, 12.1, 7.1, 17.1, 1.1, 11.1, 6.1, 16.1, 5.1, 15.1, 4.1, 14.1]
04104         for i in xrange(14):
04105             self.assertAlmostEqual(expected1[i],a.getIJ(0,i),14);
04106             pass
04107         #
04108         c=DataArrayInt.New();
04109         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
04110         c.setValues(arr3,7,2);
04111         c.renumberInPlace(arr2);
04112         self.assertEqual(7,c.getNumberOfTuples());
04113         self.assertEqual(2,c.getNumberOfComponents());
04114         expected2=[3, 13, 2, 12, 7, 17, 1, 11, 6, 16, 5, 15, 4, 14]
04115         for i in xrange(14):
04116             self.assertEqual(expected2[i],c.getIJ(0,i));
04117             pass
04118         pass
04119 
04120     def testDaDoubleRenumberR1(self):
04121         a=DataArrayDouble.New();
04122         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
04123         a.setValues(arr1,7,2);
04124         a.setInfoOnComponent(0,"toto");
04125         a.setInfoOnComponent(1,"tata");
04126         #
04127         arr2=[3,1,0,6,5,4,2]
04128         b=a.renumberR(arr2);
04129         self.assertEqual(7,b.getNumberOfTuples());
04130         self.assertEqual(2,b.getNumberOfComponents());
04131         self.assertTrue(b.getInfoOnComponent(0)=="toto");
04132         self.assertTrue(b.getInfoOnComponent(1)=="tata");
04133         expected1=[4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1]
04134         for i in xrange(14):
04135             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
04136             pass
04137         #
04138         c=DataArrayInt.New();
04139         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
04140         c.setValues(arr3,7,2);
04141         c.setInfoOnComponent(0,"toto");
04142         c.setInfoOnComponent(1,"tata");
04143         d=c.renumberR(arr2);
04144         self.assertEqual(7,d.getNumberOfTuples());
04145         self.assertEqual(2,d.getNumberOfComponents());
04146         self.assertTrue(d.getInfoOnComponent(0)=="toto");
04147         self.assertTrue(d.getInfoOnComponent(1)=="tata");
04148         expected2=[4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13]
04149         for i in xrange(14):
04150             self.assertEqual(expected2[i],d.getIJ(0,i));
04151             pass
04152         pass
04153 
04154     def testDaDoubleRenumberInPlaceR1(self):
04155         a=DataArrayDouble.New();
04156         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
04157         a.setValues(arr1,7,2);
04158         #
04159         arr2=[3,1,0,6,5,4,2]
04160         a.renumberInPlaceR(arr2);
04161         self.assertEqual(7,a.getNumberOfTuples());
04162         self.assertEqual(2,a.getNumberOfComponents());
04163         expected1=[4.1, 14.1, 2.1, 12.1, 1.1, 11.1, 7.1, 17.1, 6.1, 16.1, 5.1, 15.1, 3.1, 13.1]
04164         for i in xrange(14):
04165             self.assertAlmostEqual(expected1[i],a.getIJ(0,i),14);
04166             pass
04167         #
04168         c=DataArrayInt.New();
04169         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
04170         c.setValues(arr3,7,2);
04171         c.renumberInPlaceR(arr2);
04172         self.assertEqual(7,c.getNumberOfTuples());
04173         self.assertEqual(2,c.getNumberOfComponents());
04174         expected2=[4, 14, 2, 12, 1, 11, 7, 17, 6, 16, 5, 15, 3, 13]
04175         for i in xrange(14):
04176             self.assertEqual(expected2[i],c.getIJ(0,i));
04177             pass
04178         pass
04179 
04180     def testDaDoubleSelectByTupleId1(self):
04181         a=DataArrayDouble.New();
04182         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
04183         a.setValues(arr1,7,2);
04184         a.setInfoOnComponent(0,"toto");
04185         a.setInfoOnComponent(1,"tata");
04186         #
04187         arr2=[4,2,0,6,5]
04188         b=a.selectByTupleId(arr2);
04189         self.assertEqual(5,b.getNumberOfTuples());
04190         self.assertEqual(2,b.getNumberOfComponents());
04191         self.assertTrue(b.getInfoOnComponent(0)=="toto");
04192         self.assertTrue(b.getInfoOnComponent(1)=="tata");
04193         expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
04194         for i in xrange(10):
04195             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
04196             pass
04197         #
04198         c=DataArrayInt.New();
04199         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
04200         c.setValues(arr3,7,2);
04201         c.setInfoOnComponent(0,"toto");
04202         c.setInfoOnComponent(1,"tata");
04203         d=c.selectByTupleId(arr2);
04204         self.assertEqual(5,d.getNumberOfTuples());
04205         self.assertEqual(2,d.getNumberOfComponents());
04206         self.assertTrue(d.getInfoOnComponent(0)=="toto");
04207         self.assertTrue(d.getInfoOnComponent(1)=="tata");
04208         expected2=[5,15,3,13,1,11,7,17,6,16]
04209         for i in xrange(10):
04210             self.assertEqual(expected2[i],d.getIJ(0,i));
04211             pass
04212         pass
04213 
04214     def testDaDoubleGetMinMaxValues1(self):
04215         a=DataArrayDouble.New();
04216         arr1=[2.34,4.56,-6.77,4.55,4.56,2.24,2.34,1.02,4.56]
04217         a.setValues(arr1,9,1);
04218         m,where=a.getMaxValue();
04219         self.assertEqual(1,where);
04220         self.assertAlmostEqual(4.56,m,12);
04221         m,ws=a.getMaxValue2();
04222         self.assertAlmostEqual(4.56,m,12);
04223         self.assertEqual(3,ws.getNumberOfTuples());
04224         self.assertEqual(1,ws.getNumberOfComponents());
04225         expected1=[1,4,8]
04226         for i in xrange(3):
04227             self.assertEqual(expected1[i],ws.getIJ(i,0));
04228             pass
04229         a=DataArrayDouble.New();
04230         arr2=[-2.34,-4.56,6.77,-4.55,-4.56,-2.24,-2.34,-1.02,-4.56]
04231         a.setValues(arr2,9,1);
04232         m,where=a.getMinValue();
04233         self.assertEqual(1,where);
04234         self.assertAlmostEqual(-4.56,m,12);
04235         m,ws=a.getMinValue2();
04236         self.assertAlmostEqual(-4.56,m,12);
04237         self.assertEqual(3,ws.getNumberOfTuples());
04238         self.assertEqual(1,ws.getNumberOfComponents());
04239         for i in xrange(3):
04240             self.assertEqual(expected1[i],ws.getIJ(i,0));
04241             pass
04242         pass
04243 
04244     def testFieldDoubleGetMinMaxValues2(self):
04245         m2,m1=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
04246         self.assertEqual(18,m2.getNumberOfCells());
04247         arr1=[8.71,4.53,-12.41,8.71,-8.71,8.7099,4.55,8.71,5.55,6.77,-1e-200,4.55,8.7099,0.,1.23,0.,2.22,8.71]
04248         f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04249         a=DataArrayDouble.New();
04250         a.setValues(arr1,18,1);
04251         f.setArray(a);
04252         f.setMesh(m2);
04253         #
04254         f.checkCoherency();
04255         m=f.getMaxValue();
04256         self.assertAlmostEqual(8.71,m,12);
04257         m,ws=f.getMaxValue2();
04258         self.assertAlmostEqual(8.71,m,12);
04259         self.assertEqual(4,ws.getNumberOfTuples());
04260         self.assertEqual(1,ws.getNumberOfComponents());
04261         expected1=[0,3,7,17]
04262         for i in xrange(4):
04263             self.assertEqual(expected1[i],ws.getIJ(i,0));
04264             pass
04265         #
04266         arr2=[-8.71,-4.53,12.41,-8.71,8.71,-8.7099,-4.55,-8.71,-5.55,-6.77,1e-200,-4.55,-8.7099,0.,-1.23,0.,-2.22,-8.71]
04267         a.setValues(arr2,18,1);
04268         f.checkCoherency();
04269         m=f.getMinValue();
04270         self.assertAlmostEqual(-8.71,m,12);
04271         m,ws=f.getMinValue2();
04272         self.assertAlmostEqual(-8.71,m,12);
04273         self.assertEqual(4,ws.getNumberOfTuples());
04274         self.assertEqual(1,ws.getNumberOfComponents());
04275         for i in xrange(4):
04276             self.assertEqual(expected1[i],ws.getIJ(i,0));
04277             pass
04278         pass
04279 
04280     def testBuildUnstructuredCMesh1(self):
04281         m=MEDCouplingCMesh.New();
04282         da=DataArrayDouble.New();
04283         discX=[2.3,3.4,5.8,10.2]
04284         discY=[12.3,23.4,45.8]
04285         discZ=[-0.7,1.2,1.25,2.13,2.67]
04286         da.setValues(discX,4,1);
04287         m.setCoordsAt(0,da);
04288         m.checkCoherency();
04289         self.assertEqual(0,m.getCellContainingPoint([2.4],1e-12));
04290         self.assertEqual(1,m.getCellContainingPoint([3.7],1e-12));
04291         self.assertEqual(2,m.getCellContainingPoint([5.9],1e-12));
04292         self.assertEqual(-1,m.getCellContainingPoint([10.3],1e-12));
04293         self.assertEqual(-1,m.getCellContainingPoint([1.3],1e-12));
04294         #
04295         m2=m.buildUnstructured();
04296         m2.checkCoherency();
04297         f1=m.getMeasureField(False);
04298         f2=m2.getMeasureField(False);
04299         self.assertTrue(isinstance(f1.getMesh(),MEDCouplingCMesh))
04300         self.assertEqual(f1.getNumberOfTuples(),3);
04301         self.assertEqual(f2.getNumberOfTuples(),3);
04302         self.assertEqual(1,m2.getMeshDimension());
04303         self.assertEqual(1,m2.getSpaceDimension());
04304         for i in xrange(3):
04305             self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
04306             pass
04307         da=DataArrayDouble.New();
04308         da.setValues(discY,3,1);
04309         m.setCoordsAt(1,da);
04310         #
04311         m2=m.buildUnstructured();
04312         m2.checkCoherency();
04313         f1=m.getMeasureField(False);
04314         f2=m2.getMeasureField(False);
04315         self.assertEqual(f1.getNumberOfTuples(),6);
04316         self.assertEqual(f2.getNumberOfTuples(),6);
04317         self.assertEqual(2,m2.getMeshDimension());
04318         self.assertEqual(2,m2.getSpaceDimension());
04319         for i in xrange(6):
04320             self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
04321             pass
04322         #
04323         da=DataArrayDouble.New();
04324         da.setValues(discZ,5,1);
04325         m.setCoordsAt(2,da);
04326         m2=m.buildUnstructured();
04327         m2.checkCoherency();
04328         f1=m.getMeasureField(False);
04329         f2=m2.getMeasureField(False);
04330         self.assertEqual(f1.getNumberOfTuples(),24);
04331         self.assertEqual(f2.getNumberOfTuples(),24);
04332         self.assertEqual(3,m2.getMeshDimension());
04333         self.assertEqual(3,m2.getSpaceDimension());
04334         for i in xrange(24):
04335             self.assertAlmostEqual(f1.getIJ(i,0),f2.getIJ(i,0),10);
04336             pass
04337         #
04338         pos1=[5.,30.,2.]
04339         self.assertEqual(16,m.getCellContainingPoint(pos1,1e-12));
04340         #
04341         elems=m2.getCellsInBoundingBox([3.5,6.,12.2,25.,0.,1.5],1e-7)
04342         self.assertEqual([1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17],elems.getValues())
04343         #
04344         pt=[2.4,12.7,-3.4]
04345         m.scale(pt,3.7);
04346         m3=m.buildUnstructured();
04347         m2.scale(pt,3.7);
04348         self.assertTrue(m3.isEqual(m2,1e-12));
04349         pass
04350 
04351     def testDataArrayIntInvertO2NNO21(self):
04352         arr1=[2,0,4,1,5,3]
04353         da=DataArrayInt.New();
04354         da.setValues(arr1,6,1);
04355         da2=da.invertArrayO2N2N2O(6);
04356         self.assertEqual(6,da2.getNumberOfTuples());
04357         self.assertEqual(1,da2.getNumberOfComponents());
04358         expected1=[1,3,0,5,2,4]
04359         for i in xrange(6):
04360             self.assertEqual(expected1[i],da2.getIJ(i,0));
04361             pass
04362         da3=da2.invertArrayN2O2O2N(6);
04363         for i in xrange(6):
04364             self.assertEqual(arr1[i],da3.getIJ(i,0));
04365             pass
04366         #
04367         arr2=[3,-1,5,4,-1,0,-1,1,2,-1]
04368         da=DataArrayInt.New();
04369         da.setValues(arr2,10,1);
04370         da2=da.invertArrayO2N2N2O(6);
04371         self.assertEqual(6,da2.getNumberOfTuples());
04372         self.assertEqual(1,da2.getNumberOfComponents());
04373         expected2=[5,7,8,0,3,2]
04374         for i in xrange(6):
04375             self.assertEqual(expected2[i],da2.getIJ(i,0));
04376             pass
04377         da3=da2.invertArrayN2O2O2N(10);
04378         for i in xrange(10):
04379             self.assertEqual(arr2[i],da3.getIJ(i,0));
04380             pass
04381         pass
04382 
04383     def testDoublyContractedProduct1(self):
04384         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04385         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04386         f1.setMesh(mesh1);
04387         array=DataArrayDouble.New();
04388         arr1=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
04389         array.setValues(arr1,mesh1.getNumberOfCells(),6);
04390         f1.setArray(array);
04391         f1.checkCoherency();
04392         #
04393         f2=f1.doublyContractedProduct();
04394         f2.checkCoherency();
04395         self.assertEqual(1,f2.getNumberOfComponents());
04396         self.assertEqual(5,f2.getNumberOfTuples());
04397         for i in xrange(5):
04398             self.assertAlmostEqual(3906.56,f2.getIJ(i,0),9);
04399             pass
04400         #
04401         pass
04402 
04403     def testDeterminant1(self):
04404         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04405         f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
04406         f1.setTime(2.3,5,6);
04407         f1.setEndTime(3.8,7,3);
04408         f1.setMesh(mesh1);
04409         array=DataArrayDouble.New();
04410         arr1=[1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5]
04411         array.setValues(arr1,mesh1.getNumberOfCells(),4);
04412         f1.setArray(array);
04413         #4 components
04414         f1.checkCoherency();
04415         f2=f1.determinant();
04416         f2.checkCoherency();
04417         self.assertEqual(CONST_ON_TIME_INTERVAL,f2.getTimeDiscretization());
04418         self.assertEqual(1,f2.getNumberOfComponents());
04419         self.assertEqual(5,f2.getNumberOfValues());
04420         for i in xrange(5):
04421             self.assertAlmostEqual(-2.42,f2.getIJ(i,0),13);
04422             pass
04423         #6 components multi arrays with end array not defined
04424         f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME);
04425         f1.setTime(2.3,5,6);
04426         f1.setEndTime(3.8,7,3);
04427         f1.setMesh(mesh1);
04428         array=DataArrayDouble.New();
04429         arr2=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7,
04430               1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
04431         array.setValues(arr2,mesh1.getNumberOfNodes(),6);
04432         f1.setArray(array);
04433         self.assertRaises(InterpKernelException,f1.checkCoherency);#no end array specified !
04434         #
04435         f2=f1.determinant();
04436         self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization());
04437         self.assertEqual(1,f2.getArray().getNumberOfComponents());
04438         self.assertEqual(9,f2.getNumberOfTuples());
04439         for i in xrange(9):
04440             self.assertAlmostEqual(137.335,f2.getIJ(i,0),10);
04441             pass
04442         #6 components multi arrays with end array defined
04443         array=DataArrayDouble.New();
04444         arr3=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5,
04445               7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
04446         array.setValues(arr3,mesh1.getNumberOfNodes(),6);
04447         f1.setEndArray(array);
04448         f1.checkCoherency();
04449         f2=f1.determinant();
04450         f2.checkCoherency();
04451         self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization());
04452         self.assertEqual(1,f2.getNumberOfComponents());
04453         self.assertEqual(9,f2.getNumberOfTuples());
04454         time2,it,order=f2.getTime()
04455         self.assertAlmostEqual(2.3,time2,12);
04456         self.assertEqual(5,it);
04457         self.assertEqual(6,order);
04458         time2,it,order=f2.getEndTime()
04459         self.assertAlmostEqual(3.8,time2,12);
04460         self.assertEqual(7,it);
04461         self.assertEqual(3,order);
04462         for i in xrange(9):
04463             self.assertAlmostEqual(137.335,f2.getIJ(i,0),10);
04464             self.assertAlmostEqual(1289.685,f2.getEndArray().getIJ(i,0),9);
04465             pass
04466         #9 components
04467         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
04468         f1.setTime(7.8,10,2);
04469         f1.setMesh(mesh1);
04470         array=DataArrayDouble.New();
04471         arr4=[1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1]
04472         array.setValues(arr4,mesh1.getNumberOfCells(),9);
04473         f1.setArray(array);
04474         #
04475         f1.checkCoherency();
04476         f2=f1.determinant();
04477         f2.checkCoherency();
04478         self.assertEqual(ONE_TIME,f2.getTimeDiscretization());
04479         self.assertEqual(1,f2.getNumberOfComponents());
04480         self.assertEqual(5,f2.getNumberOfTuples());
04481         time2,it,order=f2.getTime()
04482         self.assertAlmostEqual(7.8,time2,12);
04483         self.assertEqual(10,it);
04484         self.assertEqual(2,order);
04485         for i in xrange(5):
04486             self.assertAlmostEqual(3.267,f2.getIJ(i,0),13);
04487             pass
04488         pass
04489 
04490     def testEigenValues1(self):
04491         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04492         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04493         f1.setMesh(mesh1);
04494         array=DataArrayDouble.New();
04495         arr1=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
04496         array.setValues(arr1,mesh1.getNumberOfCells(),6);
04497         f1.setArray(array);
04498         f1.checkCoherency();
04499         #
04500         f2=f1.eigenValues();
04501         f2.checkCoherency();
04502         self.assertEqual(3,f2.getNumberOfComponents());
04503         self.assertEqual(5,f2.getNumberOfTuples());
04504         expected1=[13.638813677891717,-4.502313844635971,-2.2364998332557486]
04505         for i in xrange(5):
04506             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
04507             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
04508             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
04509             pass
04510         pass
04511 
04512     def testEigenVectors1(self):
04513         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04514         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04515         f1.setMesh(mesh1);
04516         array=DataArrayDouble.New();
04517         arr1=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
04518         array.setValues(arr1,mesh1.getNumberOfCells(),6);
04519         f1.setArray(array);
04520         f1.checkCoherency();
04521         #
04522         f2=f1.eigenVectors();
04523         f2.checkCoherency();
04524         self.assertEqual(9,f2.getNumberOfComponents());
04525         self.assertEqual(5,f2.getNumberOfTuples());
04526         expected1=[0.5424262364180696, 0.5351201064614425, 0.6476266283176001,#eigenvect 0
04527                    0.7381111277307373, 0.06458838384003074, -0.6715804522117897,#eigenvect 1
04528                    -0.4012053603397987, 0.8423032781211455, -0.3599436712889738#eigenvect 2
04529                    ]
04530         for i in xrange(5):
04531             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
04532             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
04533             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
04534             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
04535             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
04536             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
04537             self.assertAlmostEqual(expected1[6],f2.getIJ(i,6),13);
04538             self.assertAlmostEqual(expected1[7],f2.getIJ(i,7),13);
04539             self.assertAlmostEqual(expected1[8],f2.getIJ(i,8),13);
04540             pass
04541         #
04542         pass
04543 
04544     def testInverse1(self):
04545         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04546         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04547         f1.setMesh(mesh1);
04548         array=DataArrayDouble.New();
04549         arr1=[1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1]
04550         array.setValues(arr1,mesh1.getNumberOfCells(),9);
04551         f1.setArray(array);
04552         f1.checkCoherency();
04553         #
04554         f2=f1.inverse();
04555         f2.checkCoherency();
04556         self.assertEqual(9,f2.getNumberOfComponents());
04557         self.assertEqual(5,f2.getNumberOfTuples());
04558         expected1=[-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072]
04559         for i in xrange(5):
04560             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
04561             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
04562             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
04563             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
04564             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
04565             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
04566             self.assertAlmostEqual(expected1[6],f2.getIJ(i,6),13);
04567             self.assertAlmostEqual(expected1[7],f2.getIJ(i,7),13);
04568             self.assertAlmostEqual(expected1[8],f2.getIJ(i,8),13);
04569             pass
04570         #
04571         array=DataArrayDouble.New();
04572         arr3=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
04573         array.setValues(arr3,mesh1.getNumberOfCells(),6);
04574         f1.setArray(array);
04575         f1.checkCoherency();
04576         #
04577         f2=f1.inverse();
04578         f2.checkCoherency();
04579         self.assertEqual(6,f2.getNumberOfComponents());
04580         self.assertEqual(5,f2.getNumberOfTuples());
04581         expected3=[-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887]
04582         for i in xrange(5):
04583             self.assertAlmostEqual(expected3[0],f2.getIJ(i,0),13);
04584             self.assertAlmostEqual(expected3[1],f2.getIJ(i,1),13);
04585             self.assertAlmostEqual(expected3[2],f2.getIJ(i,2),13);
04586             self.assertAlmostEqual(expected3[3],f2.getIJ(i,3),13);
04587             self.assertAlmostEqual(expected3[4],f2.getIJ(i,4),13);
04588             self.assertAlmostEqual(expected3[5],f2.getIJ(i,5),13);
04589             pass
04590         #
04591         array=DataArrayDouble.New();
04592         arr2=[1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5]
04593         array.setValues(arr2,mesh1.getNumberOfCells(),4);
04594         f1.setArray(array);
04595         f1.checkCoherency();
04596         #
04597         f2=f1.inverse();
04598         f2.checkCoherency();
04599         self.assertEqual(4,f2.getNumberOfComponents());
04600         self.assertEqual(5,f2.getNumberOfTuples());
04601         expected2=[-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156]
04602         for i in xrange(5):
04603             self.assertAlmostEqual(expected2[0],f2.getIJ(i,0),13);
04604             self.assertAlmostEqual(expected2[1],f2.getIJ(i,1),13);
04605             self.assertAlmostEqual(expected2[2],f2.getIJ(i,2),13);
04606             self.assertAlmostEqual(expected2[3],f2.getIJ(i,3),13);
04607             pass
04608         #
04609         pass
04610 
04611     def testTrace1(self):
04612         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04613         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04614         f1.setMesh(mesh1);
04615         array=DataArrayDouble.New();
04616         arr1=[1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1, 1.2,2.3,3.4,4.5,5.6,6.7,7.8,8.9,9.1]
04617         array.setValues(arr1,mesh1.getNumberOfCells(),9);
04618         f1.setArray(array);
04619         f1.checkCoherency();
04620         #
04621         f2=f1.trace();
04622         f2.checkCoherency();
04623         self.assertEqual(1,f2.getNumberOfComponents());
04624         self.assertEqual(5,f2.getNumberOfTuples());
04625         for i in xrange(5):
04626             self.assertAlmostEqual(15.9,f2.getIJ(i,0),13);
04627             pass
04628         #
04629         array=DataArrayDouble.New();
04630         arr3=[7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5, 7.8,8.9,9.1,10.2,23.4,34.5]
04631         array.setValues(arr3,mesh1.getNumberOfCells(),6);
04632         f1.setArray(array);
04633         f1.checkCoherency();
04634         #
04635         f2=f1.trace();
04636         f2.checkCoherency();
04637         self.assertEqual(1,f2.getNumberOfComponents());
04638         self.assertEqual(5,f2.getNumberOfTuples());
04639         for i in xrange(5):
04640             self.assertAlmostEqual(25.8,f2.getIJ(i,0),13);
04641             pass
04642         #
04643         array=DataArrayDouble.New();
04644         arr2=[1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5, 1.2,2.3,3.4,4.5]
04645         array.setValues(arr2,mesh1.getNumberOfCells(),4);
04646         f1.setArray(array);
04647         f1.checkCoherency();
04648         #
04649         f2=f1.trace();
04650         f2.checkCoherency();
04651         self.assertEqual(1,f2.getNumberOfComponents());
04652         self.assertEqual(5,f2.getNumberOfTuples());
04653         for i in xrange(5):
04654             self.assertAlmostEqual(5.7,f2.getIJ(i,0),13);
04655             pass
04656         #
04657         pass
04658 
04659     def testDeviator1(self):
04660         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04661         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04662         f1.setMesh(mesh1);
04663         array=DataArrayDouble.New();
04664         arr1=[1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7, 1.2,2.3,3.4,4.5,5.6,6.7]
04665         array.setValues(arr1,mesh1.getNumberOfCells(),6);
04666         f1.setArray(array);
04667         f1.checkCoherency();
04668         #
04669         f2=f1.deviator();
04670         f2.checkCoherency();
04671         self.assertEqual(6,f2.getNumberOfComponents());
04672         self.assertEqual(5,f2.getNumberOfTuples());
04673         expected1=[-1.1,0.,1.1,4.5,5.6,6.7]
04674         for i in xrange(5):
04675             self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13);
04676             self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13);
04677             self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13);
04678             self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13);
04679             self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13);
04680             self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13);
04681             pass
04682         #
04683         pass
04684 
04685     def testMagnitude1(self):
04686         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04687         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04688         f1.setMesh(mesh1);
04689         array=DataArrayDouble.New();
04690         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6, 1.2,2.3,3.4,4.5,5.6]
04691         array.setValues(arr1,mesh1.getNumberOfCells(),5);
04692         f1.setArray(array);
04693         f1.checkCoherency();
04694         #
04695         f2=f1.magnitude();
04696         f2.checkCoherency();
04697         self.assertEqual(1,f2.getNumberOfComponents());
04698         self.assertEqual(5,f2.getNumberOfTuples());
04699         for i in xrange(5):
04700             self.assertAlmostEqual(8.3606219864313918,f2.getIJ(i,0),13);
04701             pass
04702         #
04703         pass
04704 
04705     def testMaxPerTuple1(self):
04706         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04707         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04708         f1.setMesh(mesh1);
04709         array=DataArrayDouble.New();
04710         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4]
04711         array.setValues(arr1,mesh1.getNumberOfCells(),5);
04712         f1.setArray(array);
04713         f1.checkCoherency();
04714         #
04715         f2=f1.maxPerTuple();
04716         f2.checkCoherency();
04717         self.assertEqual(1,f2.getNumberOfComponents());
04718         self.assertEqual(5,f2.getNumberOfTuples());
04719         for i in xrange(5):
04720             self.assertAlmostEqual(5.6,f2.getIJ(i,0),13);
04721             pass
04722         #
04723         pass
04724 
04725     def testChangeNbOfComponents(self):
04726         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04727         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04728         f1.setMesh(mesh1);
04729         array=DataArrayDouble.New();
04730         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4]
04731         array.setValues(arr1,mesh1.getNumberOfCells(),5);
04732         f1.setArray(array);
04733         f1.checkCoherency();
04734         #
04735         f1.changeNbOfComponents(3,7.77);
04736         f1.checkCoherency();
04737         self.assertEqual(3,f1.getNumberOfComponents());
04738         self.assertEqual(5,f1.getNumberOfTuples());
04739         expected1=[1.2,2.3,3.4, 1.2,3.4,4.5, 3.4,4.5,5.6, 5.6,1.2,2.3, 4.5,5.6,1.2]
04740         for i in xrange(15):
04741             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),13);
04742             pass
04743         f1.changeNbOfComponents(4,7.77);
04744         f1.checkCoherency();
04745         self.assertEqual(4,f1.getNumberOfComponents());
04746         self.assertEqual(5,f1.getNumberOfTuples());
04747         expected2=[1.2,2.3,3.4,7.77, 1.2,3.4,4.5,7.77, 3.4,4.5,5.6,7.77, 5.6,1.2,2.3,7.77, 4.5,5.6,1.2,7.77]
04748         for i in xrange(20):
04749             self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),13);
04750             pass
04751         #
04752         pass
04753 
04754     def testSortPerTuple1(self):
04755         mesh1=MEDCouplingDataForTest.build2DTargetMesh_1();
04756         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
04757         f1.setMesh(mesh1);
04758         array=DataArrayDouble.New();
04759         arr1=[1.2,2.3,3.4,4.5,5.6, 1.2,3.4,4.5,5.6,2.3, 3.4,4.5,5.6,1.2,2.3, 5.6,1.2,2.3,3.4,4.5, 4.5,5.6,1.2,2.3,3.4]
04760         array.setValues(arr1,mesh1.getNumberOfCells(),5);
04761         f1.setArray(array);
04762         f1.checkCoherency();
04763         #
04764         f1.sortPerTuple(True);
04765         f1.checkCoherency();
04766         self.assertEqual(5,f1.getNumberOfComponents());
04767         self.assertEqual(5,f1.getNumberOfTuples());
04768         for i in xrange(5):
04769             self.assertAlmostEqual(arr1[0],f1.getIJ(i,0),13);
04770             self.assertAlmostEqual(arr1[1],f1.getIJ(i,1),13);
04771             self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13);
04772             self.assertAlmostEqual(arr1[3],f1.getIJ(i,3),13);
04773             self.assertAlmostEqual(arr1[4],f1.getIJ(i,4),13);
04774             pass
04775         #
04776         f1.sortPerTuple(False);
04777         f1.checkCoherency();
04778         self.assertEqual(5,f1.getNumberOfComponents());
04779         self.assertEqual(5,f1.getNumberOfTuples());
04780         for i in xrange(5):
04781             self.assertAlmostEqual(arr1[4],f1.getIJ(i,0),13);
04782             self.assertAlmostEqual(arr1[3],f1.getIJ(i,1),13);
04783             self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13);
04784             self.assertAlmostEqual(arr1[1],f1.getIJ(i,3),13);
04785             self.assertAlmostEqual(arr1[0],f1.getIJ(i,4),13);
04786             pass
04787         #
04788         pass
04789     
04790     def testKeepSetSelectedComponent1(self):
04791         arr1=[1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.]
04792         a1=DataArrayDouble.New();
04793         a1.setValues(arr1,5,4);
04794         expp=[21.,22.,23.,24.]
04795         self.assertEqual(4,len(a1.getTuple(2)));
04796         for i in xrange(4):
04797             self.assertAlmostEqual(expp[i],a1.getTuple(2)[i],12)
04798             pass
04799         a1.setInfoOnComponent(0,"aaaa");
04800         a1.setInfoOnComponent(1,"bbbb");
04801         a1.setInfoOnComponent(2,"cccc");
04802         a1.setInfoOnComponent(3,"dddd");
04803         arr2V=[1,2,1,2,0,0]
04804         a2=a1.keepSelectedComponents(arr2V);
04805         self.assertEqual(6,a2.getNumberOfComponents());
04806         self.assertEqual(5,a2.getNumberOfTuples());
04807         self.assertTrue(a2.getInfoOnComponent(0)=="bbbb");
04808         self.assertTrue(a2.getInfoOnComponent(1)=="cccc");
04809         self.assertTrue(a2.getInfoOnComponent(2)=="bbbb");
04810         self.assertTrue(a2.getInfoOnComponent(3)=="cccc");
04811         self.assertTrue(a2.getInfoOnComponent(4)=="aaaa");
04812         self.assertTrue(a2.getInfoOnComponent(5)=="aaaa");
04813         expected1=[2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.]
04814         for i in xrange(30):
04815             self.assertAlmostEqual(expected1[i],a2.getIJ(0,i),14);
04816             pass
04817         a3=a1.convertToIntArr();
04818         self.assertEqual([21,22,23,24],a3.getTuple(2))
04819         a4=a3.keepSelectedComponents(arr2V);
04820         self.assertEqual(6,a4.getNumberOfComponents());
04821         self.assertEqual(5,a4.getNumberOfTuples());
04822         self.assertTrue(a4.getInfoOnComponent(0)=="bbbb");
04823         self.assertTrue(a4.getInfoOnComponent(1)=="cccc");
04824         self.assertTrue(a4.getInfoOnComponent(2)=="bbbb");
04825         self.assertTrue(a4.getInfoOnComponent(3)=="cccc");
04826         self.assertTrue(a4.getInfoOnComponent(4)=="aaaa");
04827         self.assertTrue(a4.getInfoOnComponent(5)=="aaaa");
04828         for i in xrange(30):
04829             self.assertEqual(int(expected1[i]),a4.getIJ(0,i));
04830             pass
04831         # setSelectedComponents
04832         arr3V=[3,2]
04833         a5=a1.keepSelectedComponents(arr3V);
04834         a5.setInfoOnComponent(0,"eeee");
04835         a5.setInfoOnComponent(1,"ffff");
04836         arr4V=[1,2]
04837         a2.setSelectedComponents(a5,arr4V);
04838         self.assertEqual(6,a2.getNumberOfComponents());
04839         self.assertEqual(5,a2.getNumberOfTuples());
04840         self.assertTrue(a2.getInfoOnComponent(0)=="bbbb");
04841         self.assertTrue(a2.getInfoOnComponent(1)=="eeee");
04842         self.assertTrue(a2.getInfoOnComponent(2)=="ffff");
04843         self.assertTrue(a2.getInfoOnComponent(3)=="cccc");
04844         self.assertTrue(a2.getInfoOnComponent(4)=="aaaa");
04845         self.assertTrue(a2.getInfoOnComponent(5)=="aaaa");
04846         expected2=[2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.]
04847         for i in xrange(30):
04848             self.assertAlmostEqual(expected2[i],a2.getIJ(0,i),14);
04849             pass
04850         a6=a5.convertToIntArr();
04851         a6.setInfoOnComponent(0,"eeee");
04852         a6.setInfoOnComponent(1,"ffff");
04853         a4.setSelectedComponents(a6,arr4V);
04854         self.assertEqual(6,a4.getNumberOfComponents());
04855         self.assertEqual(5,a4.getNumberOfTuples());
04856         self.assertTrue(a4.getInfoOnComponent(0)=="bbbb");
04857         self.assertTrue(a4.getInfoOnComponent(1)=="eeee");
04858         self.assertTrue(a4.getInfoOnComponent(2)=="ffff");
04859         self.assertTrue(a4.getInfoOnComponent(3)=="cccc");
04860         self.assertTrue(a4.getInfoOnComponent(4)=="aaaa");
04861         self.assertTrue(a4.getInfoOnComponent(5)=="aaaa");
04862         for i in xrange(30):
04863             self.assertEqual(int(expected2[i]),a4.getIJ(0,i));
04864             pass
04865         # test of throw
04866         arr5V=[2,3,6]
04867         arr6V=[2,7,5]
04868         arr7V=[2,1,4,6]
04869         self.assertRaises(InterpKernelException,a2.keepSelectedComponents,arr5V);
04870         self.assertRaises(InterpKernelException,a2.keepSelectedComponents,arr6V);
04871         self.assertRaises(InterpKernelException,a2.setSelectedComponents,a1,arr7V);
04872         arr7V=arr7V[0:3]
04873         self.assertRaises(InterpKernelException,a2.setSelectedComponents,a1,arr7V);
04874         #
04875         pass
04876 
04877     def testKeepSetSelectedComponent2(self):
04878         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
04879         arr1=[1.,2.,3.,4., 11.,12.,13.,14., 21.,22.,23.,24., 31.,32.,33.,34., 41.,42.,43.,44.]
04880         a1=DataArrayDouble.New();
04881         a1.setValues(arr1,5,4);
04882         a1.setInfoOnComponent(0,"aaaa");
04883         a1.setInfoOnComponent(1,"bbbb");
04884         a1.setInfoOnComponent(2,"cccc");
04885         a1.setInfoOnComponent(3,"dddd");
04886         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
04887         f1.setTime(2.3,4,5);
04888         f1.setMesh(m1);
04889         f1.setName("f1");
04890         f1.setArray(a1);
04891         f1.checkCoherency();
04892         #
04893         arr2V=[1,2,1,2,0,0]
04894         f2=f1.keepSelectedComponents(arr2V);
04895         self.assertTrue(f2.getTimeDiscretization()==ONE_TIME);
04896         t,dt,it=f2.getTime()
04897         self.assertAlmostEqual(2.3,t,13);
04898         self.assertEqual(4,dt);
04899         self.assertEqual(5,it);
04900         f2.checkCoherency();
04901         self.assertEqual(6,f2.getNumberOfComponents());
04902         self.assertEqual(5,f2.getNumberOfTuples());
04903         self.assertTrue(f2.getArray().getInfoOnComponent(0)=="bbbb");
04904         self.assertTrue(f2.getArray().getInfoOnComponent(1)=="cccc");
04905         self.assertTrue(f2.getArray().getInfoOnComponent(2)=="bbbb");
04906         self.assertTrue(f2.getArray().getInfoOnComponent(3)=="cccc");
04907         self.assertTrue(f2.getArray().getInfoOnComponent(4)=="aaaa");
04908         self.assertTrue(f2.getArray().getInfoOnComponent(5)=="aaaa");
04909         expected1=[2.,3.,2.,3.,1.,1., 12.,13.,12.,13.,11.,11., 22.,23.,22.,23.,21.,21., 32.,33.,32.,33.,31.,31., 42.,43.,42.,43.,41.,41.]
04910         for i in xrange(30):
04911             self.assertAlmostEqual(expected1[i],f2.getIJ(0,i),14);
04912             pass
04913         #setSelectedComponents
04914         arr3V=[3,2]
04915         f5=f1.keepSelectedComponents(arr3V);
04916         f5.setTime(6.7,8,9);
04917         f5.getArray().setInfoOnComponent(0,"eeee");
04918         f5.getArray().setInfoOnComponent(1,"ffff");
04919         f5.checkCoherency();
04920         arr4V=[1,2]
04921         f2.setSelectedComponents(f5,arr4V);
04922         self.assertEqual(6,f2.getNumberOfComponents());
04923         self.assertEqual(5,f2.getNumberOfTuples());
04924         f2.checkCoherency();
04925         t,dt,it=f2.getTime()
04926         self.assertAlmostEqual(2.3,t,13);
04927         self.assertEqual(4,dt);
04928         self.assertEqual(5,it);
04929         self.assertTrue(f2.getArray().getInfoOnComponent(0)=="bbbb");
04930         self.assertTrue(f2.getArray().getInfoOnComponent(1)=="eeee");
04931         self.assertTrue(f2.getArray().getInfoOnComponent(2)=="ffff");
04932         self.assertTrue(f2.getArray().getInfoOnComponent(3)=="cccc");
04933         self.assertTrue(f2.getArray().getInfoOnComponent(4)=="aaaa");
04934         self.assertTrue(f2.getArray().getInfoOnComponent(5)=="aaaa");
04935         expected2=[2.,4.,3.,3.,1.,1., 12.,14.,13.,13.,11.,11., 22.,24.,23.,23.,21.,21., 32.,34.,33.,33.,31.,31., 42.,44.,43.,43.,41.,41.]
04936         for i in xrange(30):
04937             self.assertAlmostEqual(expected2[i],f2.getIJ(0,i),14);
04938             pass
04939         #
04940         pass
04941     
04942     def testElementaryDAThrowAndSpecialCases(self):
04943         da=DataArrayInt.New();
04944         self.assertRaises(InterpKernelException, da.checkAllocated);
04945         self.assertRaises(InterpKernelException, da.fillWithValue, 1);
04946         self.assertRaises(InterpKernelException, da.iota, 1);
04947         da.alloc(7,1);
04948         da.fillWithValue(11); #11,11,11,11...
04949         da.iota(10); #10,11,12,13...
04950         
04951         db=DataArrayInt.New();
04952         db.alloc(7,2);
04953         
04954         dbl2=DataArrayDouble.New();
04955         dbl2.alloc(7,2);
04956         self.assertRaises(InterpKernelException, dbl2.isUniform, 10., 1e-15);
04957         self.assertRaises(InterpKernelException, dbl2.sort);
04958         self.assertRaises(InterpKernelException, dbl2.reverse);
04959         self.assertRaises(InterpKernelException, dbl2.iota, 10.);
04960         
04961         dbl=DataArrayDouble.New();
04962         #DataArrayDouble not allocated yet
04963         self.assertRaises(InterpKernelException, dbl.iota, 10.);
04964         self.assertRaises(InterpKernelException, dbl.isUniform, 10., 1e-15);
04965         self.assertRaises(InterpKernelException, dbl.sort);
04966         self.assertRaises(InterpKernelException, dbl.reverse);
04967         self.assertRaises(InterpKernelException, dbl.fromNoInterlace);
04968         self.assertRaises(InterpKernelException, dbl.toNoInterlace);
04969         
04970         dbl.alloc(7,1);
04971         dbl.iota(10.);
04972         self.assertTrue(not dbl.isUniform(10.,1e-15));
04973         dbl.sort();
04974         self.assertTrue(dbl.isMonotonic(True, .99));
04975         self.assertTrue(dbl.isMonotonic(True, -.99));
04976         self.assertTrue(not dbl.isMonotonic(True, 1.1));
04977         self.assertTrue(not dbl.isMonotonic(True, -1.1));
04978         dbl.reverse();
04979         self.assertTrue(dbl.isMonotonic(False, .99));
04980         self.assertTrue(not dbl.isMonotonic(False, 1.1));
04981         self.assertTrue(not dbl.isMonotonic(False, -1.1));
04982         
04983         dc=DataArrayInt.New();
04984         dc.alloc(14,1);
04985         
04986         dd=DataArrayDouble.New();
04987         self.assertRaises(InterpKernelException, dd.checkAllocated);
04988         self.assertRaises(InterpKernelException, dd.fillWithValue, 1.);
04989         self.assertRaises(InterpKernelException, dd.iota, 1.);
04990         self.assertTrue(not ((dd.repr().find("No data"))==-1));
04991         
04992         dd.alloc(0,1); #Allocated but nbOfElements==0!
04993         self.assertTrue(not ((dd.repr().find("Number of tuples : 0"))==-1));
04994         self.assertTrue(not ((dd.repr().find("Empty Data"))==-1));
04995         dd.fillWithValue(11); #?!...ok
04996         dd.iota(10); #?!...ok
04997         self.assertTrue(dd.isMonotonic(True, 1.));  #nothing is monotonic
04998         self.assertTrue(dd.isMonotonic(False, 1.));
04999         
05000         self.assertRaises(InterpKernelException, db.copyStringInfoFrom, da);
05001         self.assertRaises(InterpKernelException, db.copyStringInfoFrom, da);
05002         cIds=[2,2]
05003         self.assertRaises(InterpKernelException, da.copyPartOfStringInfoFrom, db, cIds);
05004         cIds[0]=1;
05005         cIds[0]=-1;
05006         self.assertRaises(InterpKernelException, da.copyPartOfStringInfoFrom, db, cIds);
05007         
05008         info=["infoOfOneComponent"]*2;
05009         self.assertRaises(InterpKernelException, da.setInfoOnComponents, info);
05010         self.assertRaises(InterpKernelException, da.setInfoOnComponent, 1, info[0]);
05011         db.setInfoOnComponents(info);
05012         
05013         self.assertRaises(InterpKernelException, da.getInfoOnComponent, -1);
05014         self.assertRaises(InterpKernelException, da.getInfoOnComponent, 2);
05015         self.assertTrue(db.getInfoOnComponent(1)==db.getInfoOnComponent(0));
05016         self.assertRaises(InterpKernelException, db.getVarOnComponent, -1);
05017         self.assertRaises(InterpKernelException, db.getVarOnComponent, 2);
05018         self.assertRaises(InterpKernelException, db.getUnitOnComponent, -1);
05019         self.assertRaises(InterpKernelException, db.getUnitOnComponent, 2);
05020         
05021         self.assertTrue(da.GetVarNameFromInfo("varname unit ")=="varname unit ");
05022         self.assertTrue(da.GetVarNameFromInfo("varname]unit[")=="varname]unit[");
05023         self.assertTrue(da.GetVarNameFromInfo("[unit]")=="");
05024         self.assertTrue(da.GetVarNameFromInfo("varname [unit]")=="varname");
05025         
05026         self.assertTrue(da.GetUnitFromInfo("varname unit ")=="");
05027         self.assertTrue(da.GetUnitFromInfo("varname]unit[")=="");
05028         self.assertTrue(da.GetUnitFromInfo("[unit]")=="unit");
05029         self.assertTrue(da.GetUnitFromInfo("varname [unit]")=="unit");
05030         
05031         self.assertRaises(InterpKernelException, da.checkNbOfTuplesAndComp, db, "theMessageInThrow");
05032         self.assertRaises(InterpKernelException, da.checkNbOfTuplesAndComp, dc, "theMessageInThrow");
05033         self.assertRaises(InterpKernelException, db.checkNbOfTuplesAndComp, dc, "theMessageInThrow");
05034         
05035         self.assertRaises(InterpKernelException, da.checkNbOfTuplesAndComp, 7, 2, "theMessageInThrow");
05036         da.checkNbOfTuplesAndComp(7,1,"theMessageInThrow");
05037         
05038         self.assertRaises(InterpKernelException, db.checkNbOfElems, 7*2+1, "theMessageInThrow");
05039         db.checkNbOfElems(7*2,"theMessageInThrow");
05040         
05041         self.assertRaises(InterpKernelException, db.GetNumberOfItemGivenBES, 10, 9, 1, "theMessageInThrow");
05042         self.assertRaises(InterpKernelException, db.GetNumberOfItemGivenBES, 0, 1, -1, "theMessageInThrow");
05043         self.assertEqual(10,db.GetNumberOfItemGivenBES(0,10,1,"theMessageInThrow"));
05044         self.assertEqual(5,db.GetNumberOfItemGivenBES(0,10,2,"theMessageInThrow"));
05045         self.assertEqual(6,db.GetNumberOfItemGivenBES(0,11,2,"theMessageInThrow"));
05046         
05047         self.assertTrue(not ((da.repr().find("Number of components : 1"))==-1));
05048         self.assertTrue(not ((dd.repr().find("Number of components : 1"))==-1));
05049         self.assertTrue(not ((dbl.repr().find("Number of components : 1"))==-1));
05050         
05051         self.assertTrue(not ((da.reprZip().find("Number of components : 1"))==-1));
05052         self.assertTrue(not ((dd.reprZip().find("Number of components : 1"))==-1));
05053         self.assertTrue(not ((dbl.reprZip().find("Number of components : 1"))==-1));
05054         
05055         self.assertRaises(InterpKernelException, dbl.selectByTupleId2, 0, 1, -1);
05056         self.assertRaises(InterpKernelException, dbl.substr, -1, 1);
05057         self.assertRaises(InterpKernelException, dbl.substr, 8, 1);
05058         self.assertRaises(InterpKernelException, dbl.substr, 0, 8);
05059         self.assertRaises(InterpKernelException, dbl.meldWith, dd);
05060         
05061         self.assertRaises(InterpKernelException, dbl.setPartOfValuesAdv, dbl2, da); #dbl dbl2 not have the same number of components
05062         self.assertRaises(InterpKernelException, dbl.setPartOfValuesAdv, dd, da);  #da tuple selector DataArrayInt instance not have exactly 2 components
05063         
05064         dbl3=DataArrayDouble.New();
05065         dbl3.alloc(6,2);
05066         dbl3.fillWithValue(11.);
05067         #bad number of components
05068         self.assertRaises(InterpKernelException, dbl3.getMaxValue);
05069         self.assertRaises(InterpKernelException, dd.getMaxValue);
05070         self.assertRaises(InterpKernelException, dbl3.getMinValue);
05071         self.assertRaises(InterpKernelException, dd.getMinValue);
05072         self.assertRaises(InterpKernelException, dbl3.getAverageValue);
05073         self.assertRaises(InterpKernelException, dd.getAverageValue);
05074         self.assertRaises(InterpKernelException, dd.accumulate, 100);
05075         self.assertRaises(InterpKernelException, dbl.fromPolarToCart);
05076         self.assertRaises(InterpKernelException, dbl3.fromCylToCart);
05077         self.assertRaises(InterpKernelException, dbl3.fromSpherToCart);
05078         self.assertRaises(InterpKernelException, dbl3.doublyContractedProduct);
05079         self.assertRaises(InterpKernelException, dbl3.determinant);
05080         self.assertRaises(InterpKernelException, dbl3.eigenValues);
05081         self.assertRaises(InterpKernelException, dbl3.eigenVectors);
05082         self.assertRaises(InterpKernelException, dbl3.inverse);
05083         self.assertRaises(InterpKernelException, dbl3.trace);
05084         self.assertRaises(InterpKernelException, dbl3.deviator);
05085         
05086         dbl3.setIJ(5,1,12.);
05087         self.assertTrue(dbl3.getMaxValueInArray()==12.);
05088         self.assertTrue(dbl3.getMinValueInArray()==11.);
05089         
05090         db.fillWithValue(100); #bad Ids
05091         self.assertRaises(InterpKernelException, dbl3.setPartOfValuesAdv, dbl2, db);
05092         db.fillWithValue(-1); #bad Ids
05093         self.assertRaises(InterpKernelException, dbl3.setPartOfValuesAdv, dbl2, db);
05094         db.fillWithValue(6); #bad Ids for dbl3
05095         self.assertRaises(InterpKernelException, dbl3.setPartOfValuesAdv, dbl2, db);
05096         
05097         dbl3.checkNoNullValues();
05098         dbl3.setIJ(5,0,0.);
05099         self.assertRaises(InterpKernelException, dbl3.checkNoNullValues);
05100         self.assertRaises(InterpKernelException, dbl3.applyInv, 1.);  #div by zero
05101         self.assertRaises(InterpKernelException, dbl2.getIdsInRange, 1., 2.);
05102         a=[]
05103         self.assertRaises(InterpKernelException, DataArrayDouble_Aggregate, a);
05104         self.assertRaises(InterpKernelException, DataArrayDouble_Meld, a);
05105         
05106         a=[dbl2,dbl]; #Nb of components mismatch
05107         self.assertRaises(InterpKernelException, DataArrayDouble_Aggregate, a);
05108         
05109         self.assertRaises(InterpKernelException, DataArrayDouble_Dot, dbl2, dbl);
05110         
05111         self.assertRaises(InterpKernelException, DataArrayDouble_CrossProduct, dbl2, dbl); #Nb of components mismatch
05112         self.assertRaises(InterpKernelException, DataArrayDouble_CrossProduct, dbl2, dbl2); #Nb of components must be equal to 3
05113         dbl4=DataArrayDouble.New();
05114         dbl4.alloc(6,3);
05115         dbl5=DataArrayDouble.New();
05116         dbl5.alloc(7,3);
05117         self.assertRaises(InterpKernelException, DataArrayDouble_CrossProduct, dbl4, dbl5); #Nb of tuples mismatch
05118         
05119         a[0]=dbl4; #Nb of tuple mismatch
05120         a[1]=dbl5; #Nb of tuple mismatch
05121         self.assertRaises(InterpKernelException, DataArrayDouble_Meld, a);
05122         self.assertRaises(InterpKernelException, DataArrayDouble_Dot, dbl4, dbl5);
05123         pass
05124 
05125     def testDAIGetIdsEqual1(self):
05126         tab1=[5,-2,-4,-2,3,2,-2];
05127         da=DataArrayInt.New();
05128         da.setValues(tab1,7,1);
05129         da2=da.getIdsEqual(-2);
05130         self.assertEqual(3,da2.getNumberOfTuples());
05131         self.assertEqual(1,da2.getNumberOfComponents());
05132         expected1=[1,3,6];
05133         self.assertEqual(expected1,da2.getValues());
05134         pass
05135 
05136     def testDAIGetIdsEqualList1(self):
05137         tab1=[5,-2,-4,-2,3,2,-2];
05138         da=DataArrayInt.New();
05139         da.setValues(tab1,7,1);
05140         da2=da.getIdsEqualList([3,-2,0]);
05141         self.assertEqual(4,da2.getNumberOfTuples());
05142         self.assertEqual(1,da2.getNumberOfComponents());
05143         expected1=[1,3,4,6];
05144         self.assertEqual(expected1,da2.getValues());
05145         pass
05146 
05147     def testDAFromNoInterlace1(self):
05148         tab1=[1,11,21,31,41,2,12,22,32,42,3,13,23,33,43]
05149         da=DataArrayInt.New();
05150         da.setValues(tab1,5,3);
05151         da2=da.fromNoInterlace();
05152         expected1=[1,2,3,11,12,13,21,22,23,31,32,33,41,42,43]
05153         self.assertEqual(5,da2.getNumberOfTuples());
05154         self.assertEqual(3,da2.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
05155         self.assertEqual(expected1,da2.getValues());
05156         da3=da.convertToDblArr();
05157         da4=da3.fromNoInterlace();
05158         self.assertEqual(5,da4.getNumberOfTuples());
05159         self.assertEqual(3,da4.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
05160         for i in xrange(15):
05161             self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),14);
05162             pass
05163         pass
05164     
05165     def testDAToNoInterlace1(self):
05166         tab1=[1,2,3,11,12,13,21,22,23,31,32,33,41,42,43]
05167         da=DataArrayInt.New();
05168         da.setValues(tab1,5,3);
05169         da2=da.toNoInterlace();
05170         expected1=[1,11,21,31,41,2,12,22,32,42,3,13,23,33,43]
05171         self.assertEqual(5,da2.getNumberOfTuples());
05172         self.assertEqual(3,da2.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
05173         self.assertEqual(expected1,da2.getValues());
05174         da3=da.convertToDblArr();
05175         da4=da3.toNoInterlace();
05176         self.assertEqual(5,da4.getNumberOfTuples());
05177         self.assertEqual(3,da4.getNumberOfComponents());# it's not a bug. Avoid to have 1 million components !
05178         for i in xrange(15):
05179             self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),14);
05180             pass
05181         pass
05182     
05183     def testDAIsUniform1(self):
05184         tab1=[1,1,1,1,1]
05185         da=DataArrayInt.New();
05186         da.setValues(tab1,5,1);
05187         self.assertTrue(da.isUniform(1));
05188         da.setIJ(2,0,2);
05189         self.assertTrue(not da.isUniform(1));
05190         da.setIJ(2,0,1);
05191         self.assertTrue(da.isUniform(1));
05192         da2=da.convertToDblArr();
05193         self.assertTrue(da2.isUniform(1.,1.e-12));
05194         da2.setIJ(1,0,1.+1.e-13);
05195         self.assertTrue(da2.isUniform(1.,1.e-12));
05196         da2.setIJ(1,0,1.+1.e-11);
05197         self.assertTrue(not da2.isUniform(1.,1.e-12));
05198         pass
05199     
05200     def testDADFromPolarToCart1(self):
05201         tab1=[2.,0.2,2.5,0.7]
05202         da=DataArrayDouble.New();
05203         da.setValues(tab1,2,2);
05204         da2=da.fromPolarToCart();
05205         expected1=[1.9601331556824833,0.39733866159012243, 1.9121054682112213,1.6105442180942275]
05206         for i in xrange(4):
05207             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
05208             pass
05209         pass
05210     
05211     def testDADFromCylToCart1(self):
05212         tab1=[2.,0.2,4.,2.5,0.7,9.]
05213         da=DataArrayDouble.New();
05214         da.setValues(tab1,2,3);
05215         da2=da.fromCylToCart();
05216         expected1=[1.9601331556824833,0.39733866159012243,4., 1.9121054682112213,1.6105442180942275,9.]
05217         for i in xrange(6):
05218             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
05219             pass
05220         pass
05221     
05222     def testDADFromSpherToCart1(self):
05223         tab1=[2.,0.2,0.3,2.5,0.7,0.8]
05224         da=DataArrayDouble.New();
05225         da.setValues(tab1,2,3);
05226         da2=da.fromSpherToCart();
05227         expected1=[0.37959212195737485,0.11742160338765303,1.9601331556824833, 1.1220769624465328,1.1553337045129035,1.9121054682112213]
05228         for i in xrange(6):
05229             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),13);
05230             pass
05231         pass
05232 
05233     def testUnPolyze1(self):
05234         elts=[0,1,2,3,4,5,6,7]
05235         eltsV=elts;
05236         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
05237         mesh.convertToPolyTypes(eltsV);
05238         mesh.unPolyze();
05239         mesh2=MEDCouplingDataForTest.build3DTargetMesh_1();
05240         mesh.checkCoherency();
05241         self.assertTrue(mesh.isEqual(mesh2,1e-12));
05242         mesh.convertToPolyTypes(eltsV);
05243         self.assertTrue(not mesh.isEqual(mesh2,1e-12));
05244         mesh.getNodalConnectivity().setIJ(0,6,10);
05245         mesh.getNodalConnectivity().setIJ(0,7,9);
05246         mesh.getNodalConnectivity().setIJ(0,8,12);
05247         mesh.getNodalConnectivity().setIJ(0,9,13);
05248         mesh.unPolyze();
05249         self.assertTrue(mesh.isEqual(mesh2,1e-12));
05250         mesh.convertToPolyTypes(eltsV);
05251         mesh.getNodalConnectivity().setIJ(0,6,12);
05252         mesh.getNodalConnectivity().setIJ(0,7,13);
05253         mesh.getNodalConnectivity().setIJ(0,8,10);
05254         mesh.getNodalConnectivity().setIJ(0,9,9);
05255         mesh.unPolyze();
05256         self.assertTrue(mesh.isEqual(mesh2,1e-12));
05257         mesh.convertToPolyTypes(eltsV);
05258         mesh.getNodalConnectivity().setIJ(0,6,12);
05259         mesh.getNodalConnectivity().setIJ(0,7,10);
05260         mesh.getNodalConnectivity().setIJ(0,8,13);
05261         mesh.getNodalConnectivity().setIJ(0,9,9);
05262         mesh.unPolyze();
05263         self.assertTrue(not mesh.isEqual(mesh2,1e-12));
05264         # Test for 2D mesh
05265         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
05266         mesh2=MEDCouplingDataForTest.build2DTargetMesh_1();
05267         eltsV=eltsV[:5];
05268         mesh.convertToPolyTypes(eltsV);
05269         self.assertTrue(not mesh.isEqual(mesh2,1e-12));
05270         mesh.unPolyze();
05271         self.assertTrue(mesh.isEqual(mesh2,1e-12));
05272         pass
05273 
05274     def testConvertDegeneratedCells1(self):
05275         mesh=MEDCouplingDataForTest.build3DTargetMesh_1();
05276         conn=[0,1,3,3,9,10,12,12, 0,1,3,4,9,9,9,9, 1,1,1,1,10,12,9,10, 10,11,12,9,1,1,1,1]
05277         mesh.allocateCells(4);
05278         mesh.insertNextCell(NORM_HEXA8,8,conn[0:8])
05279         mesh.insertNextCell(NORM_HEXA8,8,conn[8:16])
05280         mesh.insertNextCell(NORM_HEXA8,8,conn[16:24])
05281         mesh.insertNextCell(NORM_HEXA8,8,conn[24:32])
05282         mesh.finishInsertingCells();
05283         mesh.checkCoherency();
05284         self.assertEqual(4,mesh.getNumberOfCells());
05285         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(0));
05286         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(1));
05287         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(2));
05288         self.assertEqual(NORM_HEXA8,mesh.getTypeOfCell(3));
05289         f1=mesh.getMeasureField(True);
05290         mesh.convertDegeneratedCells();
05291         mesh.checkCoherency();
05292         f2=mesh.getMeasureField(True);
05293         self.assertEqual(4,mesh.getNumberOfCells());
05294         self.assertEqual(NORM_PENTA6,mesh.getTypeOfCell(0));
05295         self.assertEqual(NORM_PYRA5,mesh.getTypeOfCell(1));
05296         self.assertEqual(NORM_TETRA4,mesh.getTypeOfCell(2));
05297         self.assertEqual(NORM_PYRA5,mesh.getTypeOfCell(3));
05298         for i in xrange(4):
05299             self.assertAlmostEqual(f1.getArray().getIJ(0,i),f2.getArray().getIJ(0,i),5);
05300             pass
05301         pass
05302 
05303     def testGetNodeIdsNearPoints1(self):
05304         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
05305         coords=mesh.getCoords();
05306         tmp=DataArrayDouble.New();
05307         vals=[0.2,0.2,0.1,0.2,0.2,0.2]
05308         tmp.setValues(vals,3,2);
05309         tmp2=DataArrayDouble.Aggregate(coords,tmp);
05310         mesh.setCoords(tmp2);
05311         pts=[0.2,0.2,0.1,0.3,-0.3,0.7]
05312         c=mesh.getNodeIdsNearPoint(pts,1e-7);
05313         self.assertEqual([4,9,11],c.getValues());
05314         c,cI=mesh.getNodeIdsNearPoints(pts,3,1e-7);
05315         self.assertEqual([0,3,3,4],cI.getValues());
05316         self.assertEqual([4,9,11,6],c.getValues());
05317         pass
05318 
05319     def testFieldCopyTinyAttrFrom1(self):
05320         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
05321         f1.setName("f1");
05322         f1.setTimeTolerance(1.e-5);
05323         f1.setDescription("f1Desc");
05324         f1.setTime(1.23,4,5);
05325         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
05326         f2.setName("f2");
05327         f2.setDescription("f2Desc");
05328         f2.setTime(6.78,9,10);
05329         f2.setTimeTolerance(4.556e-12);
05330         #
05331         f1.copyTinyAttrFrom(f2);
05332         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
05333         t,dt,it=f1.getTime()
05334         self.assertAlmostEqual(6.78,t,12);
05335         self.assertEqual(9,dt);
05336         self.assertEqual(10,it);
05337         self.assertTrue(f1.getName()=="f1");#name unchanged
05338         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
05339         #
05340         f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
05341         f1.setName("f1");
05342         f1.setTimeTolerance(1.e-5);
05343         f1.setDescription("f1Desc");
05344         f2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
05345         f2.setName("f2");
05346         f2.setDescription("f2Desc");
05347         f2.setTimeTolerance(4.556e-12);
05348         #
05349         f1.copyTinyAttrFrom(f2);
05350         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
05351         self.assertTrue(f1.getName()=="f1");#name unchanged
05352         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
05353         #
05354         f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
05355         f1.setName("f1");
05356         f1.setTimeTolerance(1.e-5);
05357         f1.setDescription("f1Desc");
05358         f1.setTime(1.23,4,5);
05359         f1.setEndTime(5.43,2,1);
05360         f2=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL);
05361         f2.setName("f2");
05362         f2.setDescription("f2Desc");
05363         f2.setTimeTolerance(4.556e-12);
05364         f2.setTime(6.78,9,10);
05365         f2.setEndTime(10.98,7,6);
05366         #
05367         f1.copyTinyAttrFrom(f2);
05368         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
05369         self.assertTrue(f1.getName()=="f1");#name unchanged
05370         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
05371         t,dt,it=f1.getTime()
05372         self.assertAlmostEqual(6.78,t,12);
05373         self.assertEqual(9,dt);
05374         self.assertEqual(10,it);
05375         t,dt,it=f1.getEndTime()
05376         self.assertAlmostEqual(10.98,t,12);
05377         self.assertEqual(7,dt);
05378         self.assertEqual(6,it);
05379         #
05380         f1=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
05381         f1.setName("f1");
05382         f1.setTimeTolerance(1.e-5);
05383         f1.setDescription("f1Desc");
05384         f1.setTime(1.23,4,5);
05385         f1.setEndTime(5.43,2,1);
05386         f2=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME);
05387         f2.setName("f2");
05388         f2.setDescription("f2Desc");
05389         f2.setTimeTolerance(4.556e-12);
05390         f2.setTime(6.78,9,10);
05391         f2.setEndTime(10.98,7,6);
05392         #
05393         f1.copyTinyAttrFrom(f2);
05394         self.assertAlmostEqual(4.556e-12,f1.getTimeTolerance(),24);
05395         self.assertTrue(f1.getName()=="f1");#name unchanged
05396         self.assertTrue(f1.getDescription()=="f1Desc");#description unchanged
05397         t,dt,it=f1.getTime()
05398         self.assertAlmostEqual(6.78,t,12);
05399         self.assertEqual(9,dt);
05400         self.assertEqual(10,it);
05401         t,dt,it=f1.getEndTime()
05402         self.assertAlmostEqual(10.98,t,12);
05403         self.assertEqual(7,dt);
05404         self.assertEqual(6,it);
05405         pass
05406 
05407     def testExtrudedMesh5(self):
05408         coo1=[0.,1.,2.,3.5]
05409         a=DataArrayDouble.New();
05410         a.setValues(coo1,4,1);
05411         b=MEDCouplingCMesh.New();
05412         b.setCoordsAt(0,a);
05413         c=b.buildUnstructured();
05414         self.assertEqual(1,c.getSpaceDimension());
05415         c.changeSpaceDimension(2);
05416         #
05417         d=DataArrayDouble.New();
05418         d.alloc(13,1);
05419         d.iota();
05420         e=MEDCouplingCMesh.New();
05421         e.setCoordsAt(0,d);
05422         f=e.buildUnstructured();
05423         g=f.getCoords().applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
05424         h=g.fromPolarToCart();
05425         f.setCoords(h);
05426         i=c.buildExtrudedMesh(f,1);
05427         self.assertEqual(52,i.getNumberOfNodes());
05428         tmp,tmp2,tmp3=i.mergeNodes(1e-9);
05429         self.assertTrue(tmp2);
05430         self.assertEqual(37,tmp3);
05431         i.convertDegeneratedCells();
05432         i.checkCoherency();
05433         self.assertEqual(36,i.getNumberOfCells());
05434         self.assertEqual(37,i.getNumberOfNodes());
05435         self.assertEqual(12,i.getNumberOfCellsWithType(NORM_TRI3));
05436         self.assertEqual(24,i.getNumberOfCellsWithType(NORM_QUAD4));
05437         expected1=[0.25,0.75,2.0625]
05438         j=i.getMeasureField(True);
05439         for ii in xrange(12):
05440             for k in xrange(3):
05441                 self.assertAlmostEqual(expected1[k],j.getIJ(0,ii*3+k),10);
05442                 pass
05443             pass
05444         expected2=[0.62200846792814113, 0.16666666666681595, 1.4513530918323276, 0.38888888888923495, 2.6293994326053212, 0.7045454545460802, 0.45534180126145435, 0.45534180126150181, 1.0624642029433926, 1.0624642029435025, 1.9248539780597826, 1.9248539780599816, 0.16666666666661334, 0.62200846792815856, 0.38888888888876294, 1.4513530918323678, 0.70454545454522521, 2.629399432605394, -0.16666666666674007, 0.62200846792812436, -0.38888888888906142, 1.4513530918322881, -0.70454545454576778, 2.6293994326052488, -0.45534180126154766, 0.45534180126140844, -1.0624642029436118, 1.0624642029432834, -1.9248539780601803, 1.9248539780595841, -0.62200846792817499, 0.1666666666665495, -1.451353091832408, 0.388888888888613, -2.6293994326054668, 0.70454545454495332, -0.62200846792810593, -0.16666666666680507, -1.451353091832247, -0.38888888888921297, -2.6293994326051746, -0.70454545454604123, -0.45534180126135926, -0.45534180126159562, -1.0624642029431723, -1.0624642029437235, -1.9248539780593836, -1.9248539780603811, -0.1666666666664828, -0.62200846792819242, -0.38888888888846079, -1.4513530918324489, -0.70454545454467987, -2.6293994326055397, 0.16666666666687083, -0.62200846792808862, 0.38888888888936374, -1.4513530918322073, 0.70454545454631357, -2.6293994326051022, 0.45534180126164348, -0.45534180126131207, 1.0624642029438327, -1.0624642029430627, 1.9248539780605791, -1.9248539780591853, 0.62200846792821063, -0.16666666666641802, 1.4513530918324888, -0.38888888888831086, 2.6293994326056125, -0.70454545454440853]
05445         m=i.getBarycenterAndOwner();
05446         for i in xrange(72):
05447             self.assertAlmostEqual(expected2[i],m.getIJ(0,i),10);
05448             pass
05449         #
05450         pass
05451 
05452     def testExtrudedMesh6(self):
05453         coo1=[0.,1.,2.,3.5]
05454         a=DataArrayDouble.New();
05455         a.setValues(coo1,4,1);
05456         b=MEDCouplingCMesh.New();
05457         b.setCoordsAt(0,a);
05458         c=b.buildUnstructured();
05459         self.assertEqual(1,c.getSpaceDimension());
05460         c.changeSpaceDimension(2);
05461         #
05462         d=DataArrayDouble.New();
05463         d.alloc(5,1);
05464         d.iota();
05465         e=MEDCouplingCMesh.New();
05466         e.setCoordsAt(0,d);
05467         f=e.buildUnstructured();
05468         d2=f.getCoords().applyFunc("x*x/2");
05469         f.setCoords(d2);
05470         f.changeSpaceDimension(2);
05471         #
05472         center=[0.,0.]
05473         f.rotate(center,[],pi/3);
05474         g=c.buildExtrudedMesh(f,0);
05475         g.checkCoherency();
05476         expected1=[ 0.4330127018922193, 0.4330127018922193, 0.649519052838329, 1.2990381056766578, 1.299038105676658, 1.948557158514987, 2.1650635094610955, 2.1650635094610964, 3.2475952641916446, 3.031088913245533, 3.0310889132455352, 4.546633369868303 ]
05477         f1=g.getMeasureField(True);
05478         for i in xrange(12):
05479             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),12);
05480             pass
05481         expected2=[0.625, 0.21650635094610962, 1.625, 0.21650635094610959, 2.8750000000000004, 0.21650635094610965, 1.1250000000000002, 1.0825317547305482, 2.125, 1.0825317547305482, 3.3750000000000004, 1.0825317547305484, 2.125, 2.8145825622994254, 3.125, 2.8145825622994254, 4.375, 2.8145825622994254, 3.6250000000000009, 5.4126587736527414, 4.625, 5.4126587736527414, 5.875, 5.4126587736527414]
05482         f2=g.getBarycenterAndOwner();
05483         for i in xrange(24):
05484             self.assertAlmostEqual(expected2[i],f2.getIJ(0,i),12);
05485             pass
05486         pass
05487 
05488     def testExtrudedMesh7(self):
05489         coo1=[0.,1.,2.,3.5]
05490         a=DataArrayDouble.New();
05491         a.setValues(coo1,4,1);
05492         b=MEDCouplingCMesh.New();
05493         b.setCoordsAt(0,a);
05494         c=b.buildUnstructured();
05495         self.assertEqual(1,c.getSpaceDimension());
05496         c.changeSpaceDimension(2);
05497         #
05498         d=DataArrayDouble.New();
05499         d.alloc(13,1);
05500         d.iota();
05501         e=MEDCouplingCMesh.New();
05502         e.setCoordsAt(0,d);
05503         f=e.buildUnstructured();
05504         g=f.getCoords().applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec");
05505         h=g.fromPolarToCart();
05506         f.setCoords(h);
05507         i=c.buildExtrudedMesh(f,1);
05508         self.assertEqual(52,i.getNumberOfNodes());
05509         tmp,tmp2,tmp3=i.mergeNodes(1e-9);
05510         self.assertTrue(tmp2);
05511         self.assertEqual(37,tmp3);
05512         i.convertDegeneratedCells();
05513         vec1=[10.,0]
05514         i.translate(vec1);
05515         g2=h.applyFunc(3,"13.5/3.5*x*IVec+0*JVec+13.5/3.5*y*KVec");
05516         f.setCoords(g2);
05517         i.changeSpaceDimension(3);
05518         i3=i.buildExtrudedMesh(f,1);
05519         f2=i3.getMeasureField(True);
05520         tmp,tmp2,tmp3=i.mergeNodes(1e-9);
05521         self.assertTrue(tmp2);
05522         self.assertEqual(444,tmp3);
05523         expected1=[1.327751058489274, 4.2942574094314701, 13.024068164857139, 1.3069177251569044, 4.1484240761012954, 12.297505664866796, 1.270833333332571, 3.8958333333309674, 11.039062499993179, 1.2291666666659207, 3.6041666666644425, 9.585937499993932, 1.1930822748415895, 3.3515759238941376, 8.3274943351204556, 1.1722489415082769, 3.2057425905609289, 7.6009318351210622, 1.1722489415082862, 3.2057425905609884, 7.6009318351213713, 1.1930822748416161, 3.3515759238943001, 8.3274943351212727, 1.2291666666659564, 3.6041666666646734, 9.5859374999950777, 1.2708333333326081, 3.8958333333311868, 11.039062499994293, 1.3069177251569224, 4.1484240761014384, 12.297505664867627, 1.3277510584902354, 4.2942574094346071, 13.024068164866796]
05524         for ii in xrange(12):
05525             for jj in xrange(36):
05526                 self.assertAlmostEqual(expected1[jj],f2.getIJ(0,ii*36+jj),9);
05527                 pass
05528         #
05529         pass
05530 
05531     def testSimplexize1(self):
05532         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
05533         m.convertToPolyTypes([3]);
05534         da=m.simplexize(0);
05535         self.assertEqual(7,da.getNumberOfTuples());
05536         self.assertEqual(1,da.getNumberOfComponents());
05537         expected2=[0,0,1,2,3,4,4]
05538         for i in xrange(7):
05539             self.assertEqual(expected2[i],da.getIJ(i,0));
05540             pass
05541         m.checkCoherency();
05542         self.assertEqual(7,m.getNumberOfCells());
05543         self.assertEqual(NORM_TRI3,m.getTypeOfCell(0));
05544         self.assertEqual(NORM_TRI3,m.getTypeOfCell(1));
05545         self.assertEqual(NORM_TRI3,m.getTypeOfCell(2));
05546         self.assertEqual(NORM_TRI3,m.getTypeOfCell(3));
05547         self.assertEqual(NORM_POLYGON,m.getTypeOfCell(4));
05548         self.assertEqual(NORM_TRI3,m.getTypeOfCell(5));
05549         self.assertEqual(NORM_TRI3,m.getTypeOfCell(6));
05550         expected1=[0.125,0.125,0.125,0.125,0.25,0.125,0.125]
05551         f=m.getMeasureField(False);
05552         for i in xrange(7):
05553             self.assertAlmostEqual(expected1[i]*sqrt(2.),f.getIJ(i,0),10);
05554             pass
05555         types=m.getAllTypes();
05556         self.assertEqual([NORM_TRI3,NORM_POLYGON],types);
05557         #
05558         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
05559         m.convertToPolyTypes([3]);
05560         da=m.simplexize(1);
05561         self.assertEqual(7,da.getNumberOfTuples());
05562         self.assertEqual(1,da.getNumberOfComponents());
05563         for i in xrange(7):
05564             self.assertEqual(expected2[i],da.getIJ(i,0));
05565             pass
05566         m.checkCoherency();
05567         types=m.getAllTypes();
05568         self.assertEqual([NORM_TRI3,NORM_POLYGON],types);
05569         self.assertEqual(7,m.getNumberOfCells());
05570         self.assertEqual(NORM_TRI3,m.getTypeOfCell(0));
05571         self.assertEqual(NORM_TRI3,m.getTypeOfCell(1));
05572         self.assertEqual(NORM_TRI3,m.getTypeOfCell(2));
05573         self.assertEqual(NORM_TRI3,m.getTypeOfCell(3));
05574         self.assertEqual(NORM_POLYGON,m.getTypeOfCell(4));
05575         self.assertEqual(NORM_TRI3,m.getTypeOfCell(5));
05576         self.assertEqual(NORM_TRI3,m.getTypeOfCell(6));
05577         f=m.getMeasureField(False);
05578         for i in xrange(7):
05579             self.assertAlmostEqual(expected1[i]*sqrt(2.),f.getIJ(i,0),10);
05580             pass
05581         pass
05582 
05583     def testSimplexize2(self):
05584         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
05585         m.convertToPolyTypes([3]);
05586         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
05587         f1.setMesh(m);
05588         arr=DataArrayDouble.New();
05589         arr1=[10.,110.,20.,120.,30.,130.,40.,140.,50.,150.]
05590         arr.setValues(arr1,5,2);
05591         f1.setArray(arr);
05592         #
05593         f1.checkCoherency();
05594         self.assertTrue(f1.simplexize(0));
05595         f1.checkCoherency();
05596         expected1=[10.,110.,10.,110.,20.,120.,30.,130.,40.,140.,50.,150.,50.,150.]
05597         for i in xrange(14):
05598             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),10);
05599             pass
05600         self.assertTrue(not f1.simplexize(0));
05601         for i in xrange(14):
05602             self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),10);
05603             pass
05604         #
05605         pass
05606 
05607     def testDAMeld1(self):
05608         da1=DataArrayDouble.New();
05609         da1.alloc(7,2);
05610         da2=DataArrayDouble.New();
05611         da2.alloc(7,1);
05612         #
05613         da1.fillWithValue(7.);
05614         da2.iota(0.);
05615         da3=da2.applyFunc(3,"10*x*IVec+100*x*JVec+1000*x*KVec");
05616         #
05617         da1.setInfoOnComponent(0,"c0da1");
05618         da1.setInfoOnComponent(1,"c1da1");
05619         da3.setInfoOnComponent(0,"c0da3");
05620         da3.setInfoOnComponent(1,"c1da3");
05621         da3.setInfoOnComponent(2,"c2da3");
05622         #
05623         da1C=da1.deepCpy();
05624         da1.meldWith(da3);
05625         self.assertEqual(5,da1.getNumberOfComponents());
05626         self.assertEqual(7,da1.getNumberOfTuples());
05627         self.assertTrue(da1.getInfoOnComponent(0)=="c0da1");
05628         self.assertTrue(da1.getInfoOnComponent(1)=="c1da1");
05629         self.assertTrue(da1.getInfoOnComponent(2)=="c0da3");
05630         self.assertTrue(da1.getInfoOnComponent(3)=="c1da3");
05631         self.assertTrue(da1.getInfoOnComponent(4)=="c2da3");
05632         #
05633         expected1=[7.,7.,0.,0.,0., 7.,7.,10.,100.,1000., 7.,7.,20.,200.,2000., 7.,7.,30.,300.,3000., 7.,7.,40.,400.,4000.,7.,7.,50.,500.,5000.,7.,7.,60.,600.,6000.]
05634         for i in xrange(35):
05635             self.assertAlmostEqual(expected1[i],da1.getIJ(0,i),10);
05636             pass
05637         #
05638         dai1=da1C.convertToIntArr();
05639         dai3=da3.convertToIntArr();
05640         dai1.meldWith(dai3);
05641         self.assertEqual(5,dai1.getNumberOfComponents());
05642         self.assertEqual(7,dai1.getNumberOfTuples());
05643         self.assertTrue(dai1.getInfoOnComponent(0)=="c0da1");
05644         self.assertTrue(dai1.getInfoOnComponent(1)=="c1da1");
05645         self.assertTrue(dai1.getInfoOnComponent(2)=="c0da3");
05646         self.assertTrue(dai1.getInfoOnComponent(3)=="c1da3");
05647         self.assertTrue(dai1.getInfoOnComponent(4)=="c2da3");
05648         for i in xrange(35):
05649             self.assertEqual(int(expected1[i]),dai1.getIJ(0,i));
05650             pass
05651         # test of static method DataArrayDouble::meld
05652         da4=DataArrayDouble.Meld(da1C,da3);
05653         tmp=DataArrayDouble.Meld([da1C,da3]);
05654         self.assertTrue(da4.isEqual(tmp,1e-10))
05655         self.assertEqual(5,da4.getNumberOfComponents());
05656         self.assertEqual(7,da4.getNumberOfTuples());
05657         self.assertTrue(da4.getInfoOnComponent(0)=="c0da1");
05658         self.assertTrue(da4.getInfoOnComponent(1)=="c1da1");
05659         self.assertTrue(da4.getInfoOnComponent(2)=="c0da3");
05660         self.assertTrue(da4.getInfoOnComponent(3)=="c1da3");
05661         self.assertTrue(da4.getInfoOnComponent(4)=="c2da3");
05662         for i in xrange(35):
05663             self.assertAlmostEqual(expected1[i],da4.getIJ(0,i),10);
05664             pass
05665         # test of static method DataArrayInt::meld
05666         dai1=da1C.convertToIntArr();
05667         dai4=DataArrayInt.Meld(dai1,dai3);
05668         tmp=DataArrayInt.Meld([dai1,dai3]);
05669         self.assertTrue(dai4.isEqual(tmp))
05670         self.assertEqual(5,dai4.getNumberOfComponents());
05671         self.assertEqual(7,dai4.getNumberOfTuples());
05672         self.assertTrue(dai4.getInfoOnComponent(0)=="c0da1");
05673         self.assertTrue(dai4.getInfoOnComponent(1)=="c1da1");
05674         self.assertTrue(dai4.getInfoOnComponent(2)=="c0da3");
05675         self.assertTrue(dai4.getInfoOnComponent(3)=="c1da3");
05676         self.assertTrue(dai4.getInfoOnComponent(4)=="c2da3");
05677         for i in xrange(35):
05678             self.assertEqual(int(expected1[i]),dai4.getIJ(0,i));
05679             pass
05680         pass
05681 
05682     def testFieldMeld1(self):
05683         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
05684         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
05685         f1.setMesh(m);
05686         da1=DataArrayDouble.New();
05687         arr1=[12.,23.,34.,45.,56.]
05688         da1.setValues(arr1,5,1);
05689         da1.setInfoOnComponent(0,"aaa");
05690         f1.setArray(da1);
05691         f1.setTime(3.4,2,1);
05692         f1.checkCoherency();
05693         #
05694         f2=f1.deepCpy();
05695         f2.setMesh(f1.getMesh());
05696         f2.checkCoherency();
05697         f2.changeNbOfComponents(2,5.);
05698         f2.assign(5.);
05699         f2.getArray().setInfoOnComponent(0,"bbb");
05700         f2.getArray().setInfoOnComponent(1,"ccc");
05701         f2.checkCoherency();
05702         #
05703         f3=MEDCouplingFieldDouble.MeldFields(f2,f1);
05704         f3.checkCoherency();
05705         self.assertEqual(5,f3.getNumberOfTuples());
05706         self.assertEqual(3,f3.getNumberOfComponents());
05707         self.assertTrue(f3.getArray().getInfoOnComponent(0)=="bbb");
05708         self.assertTrue(f3.getArray().getInfoOnComponent(1)=="ccc");
05709         self.assertTrue(f3.getArray().getInfoOnComponent(2)=="aaa");
05710         expected1=[5.,5.,12.,5.,5.,23.,5.,5.,34.,5.,5.,45.,5.,5.,56.]
05711         for i in xrange(15):
05712             self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),12);
05713             pass
05714         time,dt,it=f3.getTime();
05715         self.assertAlmostEqual(3.4,time,14);
05716         self.assertEqual(2,dt);
05717         self.assertEqual(1,it);
05718         #
05719         f4=f2.buildNewTimeReprFromThis(NO_TIME,False);
05720         f5=f1.buildNewTimeReprFromThis(NO_TIME,False);
05721         f6=MEDCouplingFieldDouble.MeldFields(f4,f5);
05722         f6.checkCoherency();
05723         self.assertEqual(5,f6.getNumberOfTuples());
05724         self.assertEqual(3,f6.getNumberOfComponents());
05725         self.assertTrue(f6.getArray().getInfoOnComponent(0)=="bbb");
05726         self.assertTrue(f6.getArray().getInfoOnComponent(1)=="ccc");
05727         self.assertTrue(f6.getArray().getInfoOnComponent(2)=="aaa");
05728         for i in xrange(15):
05729             self.assertAlmostEqual(expected1[i],f6.getIJ(0,i),12);
05730             pass
05731         #
05732         pass
05733 
05734     def testMergeNodes2(self):
05735         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
05736         m2=MEDCouplingDataForTest.build2DTargetMesh_1();
05737         vec=[0.002,0.]
05738         m2.translate(vec);
05739         #
05740         m3=MEDCouplingUMesh.MergeUMeshes([m1,m2]);
05741         da,b,newNbOfNodes=m3.mergeNodes2(0.01);
05742         self.assertEqual(9,m3.getNumberOfNodes());
05743         expected1=[-0.299,-0.3, 0.201,-0.3, 0.701,-0.3, -0.299,0.2, 0.201,0.2, 0.701,0.2, -0.299,0.7, 0.201,0.7, 0.701,0.7]
05744         for i in xrange(18):
05745             self.assertAlmostEqual(expected1[i],m3.getCoords().getIJ(0,i),13);
05746             pass
05747         #
05748         pass
05749 
05750     def testMergeField2(self):
05751         m=MEDCouplingDataForTest.build2DTargetMesh_1();
05752         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
05753         f1.setMesh(m);
05754         arr=DataArrayDouble.New();
05755         arr.alloc(5,2);
05756         arr.fillWithValue(2.);
05757         f1.setArray(arr);
05758         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
05759         f2.setMesh(m);
05760         arr=DataArrayDouble.New();
05761         arr.alloc(5,2);
05762         arr.fillWithValue(5.);
05763         f2.setArray(arr);
05764         f3=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
05765         f3.setMesh(m);
05766         arr=DataArrayDouble.New();
05767         arr.alloc(5,2);
05768         arr.fillWithValue(7.);
05769         f3.setArray(arr);
05770         #
05771         f4=MEDCouplingFieldDouble.MergeFields([f1,f2,f3]);
05772         self.assertEqual(15,f4.getMesh().getNumberOfCells());
05773         expected1=[2.,2.,2.,2.,2.,2.,2.,2.,2.,2., 5.,5.,5.,5.,5.,5.,5.,5.,5.,5., 7.,7.,7.,7.,7.,7.,7.,7.,7.,7.]
05774         for i in xrange(30):
05775             self.assertAlmostEqual(expected1[i],f4.getIJ(0,i),13);
05776             pass
05777         #
05778         pass
05779 
05780     def testDAIBuildComplement1(self):
05781         a=DataArrayInt.New();
05782         tab=[3,1,7,8]
05783         a.setValues(tab,4,1);
05784         b=a.buildComplement(12);
05785         self.assertEqual(8,b.getNumberOfTuples());
05786         self.assertEqual(1,b.getNumberOfComponents());
05787         expected1=[0,2,4,5,6,9,10,11]
05788         for i in xrange(8):
05789             self.assertEqual(expected1[i],b.getIJ(0,i));
05790             pass
05791         pass
05792 
05793     def testDAIBuildUnion1(self):
05794         a=DataArrayInt.New();
05795         tab1=[3,1,7,8]
05796         a.setValues(tab1,4,1);
05797         c=DataArrayInt.New();
05798         tab2=[5,3,0,18,8]
05799         c.setValues(tab2,5,1);
05800         b=a.buildUnion(c);
05801         self.assertEqual(7,b.getNumberOfTuples());
05802         self.assertEqual(1,b.getNumberOfComponents());
05803         expected1=[0,1,3,5,7,8,18]
05804         for i in xrange(7):
05805             self.assertEqual(expected1[i],b.getIJ(0,i));
05806             pass
05807         b=DataArrayInt.BuildUnion([a,c]);
05808         self.assertEqual(7,b.getNumberOfTuples());
05809         self.assertEqual(1,b.getNumberOfComponents());
05810         expected1=[0,1,3,5,7,8,18]
05811         for i in xrange(7):
05812             self.assertEqual(expected1[i],b.getIJ(0,i));
05813             pass
05814         pass
05815 
05816     def testDAIBuildIntersection1(self):
05817         a=DataArrayInt.New();
05818         tab1=[3,1,7,8]
05819         a.setValues(tab1,4,1);
05820         c=DataArrayInt.New();
05821         tab2=[5,3,0,18,8]
05822         c.setValues(tab2,5,1);
05823         b=a.buildIntersection(c);
05824         self.assertEqual(2,b.getNumberOfTuples());
05825         self.assertEqual(1,b.getNumberOfComponents());
05826         expected1=[3,8]
05827         for i in xrange(2):
05828             self.assertEqual(expected1[i],b.getIJ(0,i));
05829             pass
05830         b=DataArrayInt.BuildIntersection([a,c]);
05831         self.assertEqual(2,b.getNumberOfTuples());
05832         self.assertEqual(1,b.getNumberOfComponents());
05833         expected1=[3,8]
05834         for i in xrange(2):
05835             self.assertEqual(expected1[i],b.getIJ(0,i));
05836             pass
05837         pass
05838 
05839     def testDAIDeltaShiftIndex1(self):
05840         a=DataArrayInt.New();
05841         tab=[1,3,6,7,7,9,15]
05842         a.setValues(tab,7,1);
05843         b=a.deltaShiftIndex();
05844         self.assertEqual(6,b.getNumberOfTuples());
05845         self.assertEqual(1,b.getNumberOfComponents());
05846         expected1=[2,3,1,0,2,6]
05847         for i in xrange(6):
05848             self.assertEqual(expected1[i],b.getIJ(0,i));
05849             pass
05850         pass
05851 
05852     def testDaDoubleSelectByTupleIdSafe1(self):
05853         a=DataArrayDouble.New();
05854         arr1=[1.1,11.1,2.1,12.1,3.1,13.1,4.1,14.1,5.1,15.1,6.1,16.1,7.1,17.1]
05855         a.setValues(arr1,7,2);
05856         a.setInfoOnComponent(0,"toto");
05857         a.setInfoOnComponent(1,"tata");
05858         #
05859         arr2=[4,2,0,6,5]
05860         b=a.selectByTupleIdSafe(arr2);
05861         self.assertEqual(5,b.getNumberOfTuples());
05862         self.assertEqual(2,b.getNumberOfComponents());
05863         self.assertTrue(b.getInfoOnComponent(0)=="toto");
05864         self.assertTrue(b.getInfoOnComponent(1)=="tata");
05865         expected1=[5.1,15.1,3.1,13.1,1.1,11.1,7.1,17.1,6.1,16.1]
05866         for i in xrange(10):
05867             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
05868             pass
05869         arr4=[4,-1,0,6,5]
05870         self.assertRaises(InterpKernelException,a.selectByTupleIdSafe,arr4);
05871         arr5=[4,2,0,6,7]
05872         self.assertRaises(InterpKernelException,a.selectByTupleIdSafe,arr5);
05873         #
05874         c=DataArrayInt.New();
05875         arr3=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
05876         c.setValues(arr3,7,2);
05877         c.setInfoOnComponent(0,"toto");
05878         c.setInfoOnComponent(1,"tata");
05879         d=c.selectByTupleIdSafe(arr2);
05880         self.assertEqual(5,d.getNumberOfTuples());
05881         self.assertEqual(2,d.getNumberOfComponents());
05882         self.assertTrue(d.getInfoOnComponent(0)=="toto");
05883         self.assertTrue(d.getInfoOnComponent(1)=="tata");
05884         expected2=[5,15,3,13,1,11,7,17,6,16]
05885         for i in xrange(10):
05886             self.assertEqual(expected2[i],d.getIJ(0,i));
05887             pass
05888         self.assertRaises(InterpKernelException,c.selectByTupleIdSafe,arr4);
05889         self.assertRaises(InterpKernelException,c.selectByTupleIdSafe,arr5);
05890         pass
05891 
05892     def testAreCellsIncludedIn1(self):
05893         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
05894         pt=[1,3]
05895         m2=m.buildPartOfMySelf(pt,True);
05896         ret,tmp=m.areCellsIncludedIn(m2,0)
05897         self.assertTrue(ret);
05898         self.assertEqual(2,tmp.getNumberOfTuples());
05899         self.assertEqual(1,tmp.getNumberOfComponents());
05900         self.assertEqual(pt[0],tmp.getIJ(0,0));
05901         self.assertEqual(pt[1],tmp.getIJ(0,1));
05902         ret,tmp=m2.areCellsIncludedIn(m,0)
05903         self.assertTrue(not ret);
05904         pass
05905 
05906     def testSwigErrorProtection1(self):
05907         m=MEDCouplingDataForTest.build3DTargetMesh_1();
05908         m.rotate([0.,0.,0.],[0.3,0.6,1.2],0.37)
05909         m.rotate([0.,0.,0.],[0.3,6,1.2],0.37)
05910         self.assertRaises(InterpKernelException,m.rotate,[0.,0.,0.],(0.3,6,"1.2"),0.37)
05911         self.assertRaises(InterpKernelException,m.rotate,[0.,"0.",0.],[0.3,0.6,1.2],0.37)
05912         self.assertRaises(InterpKernelException,m.rotate,[0.,0.,0.],[0.3,'0.6',1.2],0.37)
05913         m2=m.buildPartOfMySelf([2,5],True)
05914         m3=m.buildPartOfMySelf((2,5),True)
05915         self.assertTrue(m2.isEqual(m3,1e-12))
05916         self.assertRaises(InterpKernelException,m.buildPartOfMySelf,[2,5.],True)
05917         da1=m.getCoords().keepSelectedComponents([1])
05918         da2=m.getCoords().keepSelectedComponents((1,))
05919         self.assertTrue(da1.isEqual(da2,1e-12))
05920         self.assertRaises(InterpKernelException,m.getCoords().keepSelectedComponents,["1"])
05921         pass
05922 
05923     def testDAIBuildSubstraction1(self):
05924         a=DataArrayInt.New()
05925         aa=[2,3,6,8,9]
05926         a.setValues(aa,5,1)
05927         b=DataArrayInt.New()
05928         bb=[1,3,5,9,11]
05929         b.setValues(bb,5,1)
05930         self.assertEqual([2,6,8],a.buildSubstraction(b).getValues())
05931         pass
05932 
05933     def testBuildOrthogonalField2(self):
05934         m=MEDCouplingDataForTest.build2DTargetMesh_1();
05935         d1=DataArrayInt.New();
05936         d2=DataArrayInt.New();
05937         d3=DataArrayInt.New();
05938         d4=DataArrayInt.New();
05939         m1=m.buildDescendingConnectivity(d1,d2,d3,d4);
05940         #
05941         f1=m1.buildOrthogonalField();
05942         da1=f1.getArray();
05943         self.assertEqual(2,da1.getNumberOfComponents());
05944         self.assertEqual(13,da1.getNumberOfTuples());
05945         #
05946         expected1=[-1.,0.,0.,1.,1.,0.,0.,-1.,0.707106781186548,0.707106781186548,0.,-1.,0.,1.,1.,0.,0.,1.,1.,0.,-1.,0.,0.,1.,1.,0.];
05947         for i in xrange(26):
05948             self.assertAlmostEqual(expected1[i],da1.getIJ(0,i),14);
05949             pass
05950         pass
05951 
05952     def testSwigErrorProtection2(self):
05953         m=MEDCouplingDataForTest.build2DTargetMesh_1();
05954         coo=m.getCoords()
05955         c=m.getNodalConnectivity()
05956         ci=m.getNodalConnectivityIndex()
05957         del m
05958         self.assertEqual(2,coo.getNumberOfComponents());
05959         self.assertEqual(6,ci.getNumberOfTuples());
05960         self.assertEqual(23,c.getNumberOfTuples());
05961         m=MEDCouplingDataForTest.build2DTargetMesh_1();
05962         f=m.getMeasureField(True)
05963         c=f.getArray()
05964         del f
05965         self.assertEqual(1,c.getNumberOfComponents());
05966         m=MEDCouplingCMesh.New()
05967         x=DataArrayDouble.New()
05968         x.setValues([1.,2.,4.],3,1)
05969         m.setCoordsAt(0,x)
05970         del x
05971         xx=m.getCoordsAt(0)
05972         del m
05973         self.assertEqual(3,xx.getNumberOfTuples());
05974         #
05975         m=MEDCouplingDataForTest.build2DTargetMesh_1();
05976         f=m.getMeasureField(True)
05977         m2=f.getMesh()
05978         del m
05979         del f
05980         self.assertEqual(5,m2.getNumberOfCells());
05981         pass
05982 
05983     def testUMInsertNextCell1(self):
05984         targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ]
05985         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
05986         targetMesh=MEDCouplingUMesh.New();
05987         targetMesh.allocateCells(5);
05988         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_QUAD4,4,targetConn[0:4])
05989         targetMesh.setMeshDimension(2);
05990         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
05991         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_TETRA4,4,targetConn[0:4])
05992         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_SEG2,2,targetConn[0:2])
05993         self.assertRaises(InterpKernelException,targetMesh.insertNextCell,NORM_POINT1,1,targetConn[0:1])
05994         targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7])
05995         targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10])
05996         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
05997         targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
05998         targetMesh.finishInsertingCells();
05999         myCoords=DataArrayDouble.New();
06000         myCoords.setValues(targetCoords,9,2);
06001         targetMesh.setCoords(myCoords);
06002         targetMesh.checkCoherency();
06003         pass
06004 
06005     def testFieldOperatorDivDiffComp1(self):
06006         m=MEDCouplingDataForTest.build2DTargetMesh_1();
06007         m1,d0,d1,d2,d3=m.buildDescendingConnectivity();
06008         #
06009         f1=m1.buildOrthogonalField();
06010         arr1=[2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.]
06011         arr=DataArrayDouble.New();
06012         arr.setValues(arr1,13,1);
06013         f2=MEDCouplingFieldDouble.New(ON_CELLS);
06014         f2.setArray(arr);
06015         f2.setMesh(m1);
06016         f2.checkCoherency();
06017         #
06018         f3=f1/f2;
06019         self.assertRaises(InterpKernelException,f2.__div__,f1)
06020         f3.checkCoherency();
06021         f1/=f2;
06022         #self.assertRaises(InterpKernelException,f2.__idiv__,f1) # mem leaks
06023         self.assertTrue(f1.isEqual(f3,1e-10,1e-10));
06024         expected1=[-0.5, 0.0, 0.0, 0.33333333333333331, 0.25, 0.0, 0.0, -0.20000000000000001, 0.117851130197758, 0.117851130197758, 0.0, -0.14285714285714285, 0.0, 0.125, 0.1111111111111111, 0.0, 0.0, 0.10000000000000001, 0.090909090909090912, 0.0, -0.083333333333333329, 0.0, 0.0, 0.076923076923076927, 0.071428571428571425, 0.0]
06025         for i in xrange(26):
06026             self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),10);
06027             pass
06028         pass
06029 
06030     def testDARearrange1(self):
06031         da1=DataArrayInt.New();
06032         da1.alloc(12,1);
06033         da1.iota(0);
06034         #
06035         self.assertEqual(12,da1.getNbOfElems());
06036         self.assertEqual(1,da1.getNumberOfComponents());
06037         self.assertEqual(12,da1.getNumberOfTuples());
06038         da1.rearrange(4);
06039         self.assertEqual(12,da1.getNbOfElems());
06040         self.assertEqual(4,da1.getNumberOfComponents());
06041         self.assertEqual(3,da1.getNumberOfTuples());
06042         for i in xrange(12):
06043             self.assertEqual(i,da1.getIJ(0,i));
06044         #
06045         da1.rearrange(6);
06046         self.assertEqual(12,da1.getNbOfElems());
06047         self.assertEqual(6,da1.getNumberOfComponents());
06048         self.assertEqual(2,da1.getNumberOfTuples());
06049         for i in xrange(12):
06050             self.assertEqual(i,da1.getIJ(0,i));
06051         #
06052         self.assertRaises(da1.rearrange(7),InterpKernelException);
06053         #
06054         da1.rearrange(12);
06055         self.assertEqual(12,da1.getNbOfElems());
06056         self.assertEqual(12,da1.getNumberOfComponents());
06057         self.assertEqual(1,da1.getNumberOfTuples());
06058         for i in xrange(12):
06059             self.assertEqual(i,da1.getIJ(0,i));
06060         #
06061         da1.rearrange(3);
06062         self.assertEqual(12,da1.getNbOfElems());
06063         self.assertEqual(3,da1.getNumberOfComponents());
06064         self.assertEqual(4,da1.getNumberOfTuples());
06065         for i in xrange(12):
06066             self.assertEqual(i,da1.getIJ(0,i));
06067         #double
06068         da2=da1.convertToDblArr();
06069         #
06070         self.assertEqual(12,da2.getNbOfElems());
06071         self.assertEqual(3,da2.getNumberOfComponents());
06072         self.assertEqual(4,da2.getNumberOfTuples());
06073         da2.rearrange(4);
06074         self.assertEqual(12,da2.getNbOfElems());
06075         self.assertEqual(4,da2.getNumberOfComponents());
06076         self.assertEqual(3,da2.getNumberOfTuples());
06077         for i in xrange(12):
06078             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
06079         #
06080         da2.rearrange(6);
06081         self.assertEqual(12,da2.getNbOfElems());
06082         self.assertEqual(6,da2.getNumberOfComponents());
06083         self.assertEqual(2,da2.getNumberOfTuples());
06084         for i in xrange(12):
06085             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
06086         #
06087         self.assertRaises(da2.rearrange(7),InterpKernelException);
06088         #
06089         da2.rearrange(1);
06090         self.assertTrue(ptr2==da2.getConstPointer());
06091         self.assertEqual(12,da2.getNbOfElems());
06092         self.assertEqual(1,da2.getNumberOfComponents());
06093         self.assertEqual(12,da2.getNumberOfTuples());
06094         for i in xrange(12):
06095             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
06096         #
06097         da2.rearrange(3);
06098         self.assertEqual(12,da2.getNbOfElems());
06099         self.assertEqual(3,da2.getNumberOfComponents());
06100         self.assertEqual(4,da2.getNumberOfTuples());
06101         for i in xrange(12):
06102             self.assertAlmostEqual(float(i),da2.getIJ(0,i),14);
06103         pass
06104 
06105     def testDARearrange1(self):
06106         da1=DataArrayInt.New();
06107         arr=[1,2,3,2,2,3,5,1,5,5,2,2]
06108         da1.setValues(arr,4,3);
06109         s=da1.getDifferentValues(True);# API different from C++ because SWIG complains...
06110         expected1=[1,2,3,5]
06111         self.assertEqual(expected1,s);
06112         pass
06113 
06114     def testSwigErrorProtection3(self):
06115         da=DataArrayInt.New()
06116         da.setValues([1,2,3,4],4,3)
06117         self.assertEqual([1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0],da.getValues())
06118         self.assertEqual(3,da.getNumberOfComponents());
06119         self.assertEqual(4,da.getNumberOfTuples());
06120         da=DataArrayInt.New()
06121         da.setValues((1,2,3,4,4,3),4,3)
06122         self.assertEqual([1, 2, 3, 4, 4, 3, 0, 0, 0, 0, 0, 0],da.getValues())
06123         self.assertEqual(3,da.getNumberOfComponents());
06124         self.assertEqual(4,da.getNumberOfTuples());
06125         da.setValues(10*[1]+290*[2],4,3)
06126         self.assertEqual(10*[1]+[2,2],da.getValues())
06127         self.assertEqual(3,da.getNumberOfComponents());
06128         self.assertEqual(4,da.getNumberOfTuples());
06129         #
06130         da=DataArrayDouble.New()
06131         da.setValues([1,2,3.,4],4,3)
06132         self.assertEqual([1., 2., 3., 4., 0., 0., 0., 0., 0., 0., 0., 0.],da.getValues())
06133         self.assertEqual(3,da.getNumberOfComponents());
06134         self.assertEqual(4,da.getNumberOfTuples());
06135         da=DataArrayDouble.New()
06136         da.setValues((1,2,3,4.,4,3),4,3)
06137         self.assertEqual([1., 2., 3., 4., 4., 3., 0., 0., 0., 0., 0., 0.],da.getValues())
06138         self.assertEqual(3,da.getNumberOfComponents());
06139         self.assertEqual(4,da.getNumberOfTuples());
06140         da.setValues(10*[1]+290*[2],4,3)
06141         self.assertEqual(10*[1.]+[2.,2.],da.getValues())
06142         self.assertEqual(3,da.getNumberOfComponents());
06143         self.assertEqual(4,da.getNumberOfTuples());
06144         pass
06145 
06146     def testDAIBuildPermutationArr1(self):
06147         a=DataArrayInt.New()
06148         a.setValues([4,5,6,7,8],5,1)
06149         b=DataArrayInt.New()
06150         b.setValues([5,4,8,6,7],5,1)
06151         c=a.buildPermutationArr(b)
06152         self.assertEqual([1,0,4,2,3],c.getValues())
06153         self.assertTrue(a.isEqualWithoutConsideringStrAndOrder(b))
06154         b.setIJ(0,0,9)
06155         self.assertTrue(not a.isEqualWithoutConsideringStrAndOrder(b))
06156         self.assertRaises(InterpKernelException,a.buildPermutationArr,b)
06157         a.setIJ(3,0,4)
06158         b.setIJ(0,0,5)
06159         b.setIJ(4,0,4)#a==[4,5,6,4,8] and b==[5,4,8,6,4]
06160         self.assertTrue(a.isEqualWithoutConsideringStrAndOrder(b))
06161         c=a.buildPermutationArr(b)
06162         self.assertEqual([1,3,4,2,3],c.getValues())
06163         d=b.convertToDblArr()
06164         expect3=[4,4,5,6,8]
06165         b.sort()
06166         self.assertEqual(expect3,b.getValues())
06167         d.sort()
06168         self.assertEqual(5,d.getNumberOfTuples());
06169         self.assertEqual(1,d.getNumberOfComponents());
06170         for i in xrange(5):
06171             self.assertAlmostEqual(float(expect3[i]),d.getIJ(i,0),14);
06172             pass
06173         pass
06174 
06175     def testAreCellsIncludedIn2(self):
06176         myName="Vitoo";
06177         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
06178         m2=m.buildPartOfMySelf([],True);
06179         self.assertEqual(0,m2.getNumberOfCells());
06180         self.assertEqual(3,m2.getSpaceDimension());
06181         self.assertEqual(2,m2.getMeshDimension());
06182         m2.setName(myName);
06183         test,tmp=m.areCellsIncludedIn(m2,0)
06184         self.assertTrue(test);
06185         self.assertEqual(myName,tmp.getName());
06186         self.assertEqual(0,tmp.getNumberOfTuples())
06187         self.assertEqual(1,tmp.getNumberOfComponents())
06188         pass
06189 
06190     def testUMeshGetPartBarycenterAndOwner1(self):
06191         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
06192         part1=[1,0,4];
06193         part=DataArrayInt.New();
06194         part.setValues(part1,3,1);
06195         b=m1.getPartBarycenterAndOwner(part);
06196         self.assertEqual(2,b.getNumberOfComponents());
06197         self.assertEqual(3,b.getNumberOfTuples());
06198         expected1=[0.36666666666666665,-0.13333333333333333,-0.05,-0.05,0.45,0.45];
06199         for i in xrange(6):
06200             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
06201             pass
06202         pass
06203 
06204     def testUMeshGetPartMeasureField1(self):
06205         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
06206         part1=[1,0,4];
06207         part=DataArrayInt.New();
06208         part.setValues(part1,3,1);
06209         b=m1.getPartMeasureField(True,part);
06210         self.assertEqual(1,b.getNumberOfComponents());
06211         self.assertEqual(3,b.getNumberOfTuples());
06212         expected1=[0.125,0.25,0.25];
06213         for i in xrange(3):
06214             self.assertAlmostEqual(expected1[i],b.getIJ(0,i),14);
06215             pass
06216         pass
06217 
06218     def testUMeshBuildPartOrthogonalField1(self):
06219         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
06220         m1.changeSpaceDimension(3);
06221         part1=[1,0,4];
06222         part=DataArrayInt.New();
06223         part.setValues(part1,3,1);
06224         b=m1.buildPartOrthogonalField(part);
06225         self.assertEqual(3,b.getArray().getNumberOfComponents());
06226         self.assertEqual(3,b.getArray().getNumberOfTuples());
06227         expected1=[0.,0.,-1.,0.,0.,-1.,0.,0.,-1.];
06228         for i in xrange(9):
06229             self.assertAlmostEqual(expected1[i],b.getArray().getIJ(0,i),14);
06230             pass
06231         pass
06232 
06233     def testUMeshGetTypesOfPart1(self):
06234         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
06235         part1=[0,3,4];
06236         p1=DataArrayInt.New()
06237         p1.setValues(part1,3,1)
06238         s=m1.getTypesOfPart(p1);
06239         self.assertEqual([NORM_QUAD4],s);
06240         part2=[2,2,2,1];
06241         p2=DataArrayInt.New()
06242         p2.setValues(part2,4,1)
06243         s=m1.getTypesOfPart(p2);
06244         self.assertEqual([NORM_TRI3],s);
06245         part3=[3,2,1];
06246         p3=DataArrayInt.New()
06247         p3.setValues(part3,3,1)
06248         s=m1.getTypesOfPart(p3);
06249         self.assertEqual(s,[NORM_TRI3,NORM_QUAD4]);
06250         pass
06251 
06252     def testUMeshKeepCellIdsByType1(self):
06253         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
06254         part1=[0,3,4]
06255         p1=DataArrayInt.New()
06256         p1.setValues(part1,3,1)
06257         p1.setName("p1")
06258         a=m1.keepCellIdsByType(NORM_TRI3,p1);
06259         self.assertEqual("p1",a.getName())
06260         self.assertEqual(1,a.getNumberOfComponents());
06261         self.assertEqual(0,a.getNumberOfTuples());
06262         #
06263         part2=[3,2,0,2,4]
06264         p2=DataArrayInt.New()
06265         p2.setValues(part2,5,1)
06266         p2.setName("p2")
06267         a=m1.keepCellIdsByType(NORM_TRI3,p2);
06268         self.assertEqual("p2",a.getName())
06269         self.assertEqual(1,a.getNumberOfComponents());
06270         self.assertEqual(2,a.getNumberOfTuples());
06271         self.assertEqual(2,a.getIJ(0,0));
06272         self.assertEqual(2,a.getIJ(1,0));
06273         #
06274         a=m1.keepCellIdsByType(NORM_QUAD4,p2);
06275         self.assertEqual("p2",a.getName())
06276         self.assertEqual(1,a.getNumberOfComponents());
06277         self.assertEqual(3,a.getNumberOfTuples());
06278         self.assertEqual(3,a.getIJ(0,0));
06279         self.assertEqual(0,a.getIJ(1,0));
06280         self.assertEqual(4,a.getIJ(2,0));
06281         pass
06282     
06283     def testSwigErrorDaIntSelectByTupleId1(self):
06284         a=DataArrayInt.New();
06285         arr1=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
06286         a.setValues(arr1,7,2);
06287         a.setInfoOnComponent(0,"toto");
06288         a.setInfoOnComponent(1,"tata");
06289         #
06290         arr2=[4,2,0,6,5]
06291         b=a.selectByTupleId(arr2);
06292         self.assertEqual(5,b.getNumberOfTuples());
06293         self.assertEqual(2,b.getNumberOfComponents());
06294         self.assertTrue(b.getInfoOnComponent(0)=="toto");
06295         self.assertTrue(b.getInfoOnComponent(1)=="tata");
06296         expected1=[5,15,3,13,1,11,7,17,6,16]
06297         self.assertEqual(expected1,b.getValues())
06298         #
06299         a2=DataArrayInt.New()
06300         a2.setValues(arr2,5,1)
06301         b=a.selectByTupleId(a2);
06302         self.assertEqual(5,b.getNumberOfTuples());
06303         self.assertEqual(2,b.getNumberOfComponents());
06304         self.assertTrue(b.getInfoOnComponent(0)=="toto");
06305         self.assertTrue(b.getInfoOnComponent(1)=="tata");
06306         expected1=[5,15,3,13,1,11,7,17,6,16]
06307         self.assertEqual(expected1,b.getValues())
06308         pass
06309 
06310     def testSwigErrorRenum(self):
06311         da=DataArrayDouble.New()
06312         da.setValues([7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.],10,2)
06313         d=DataArrayInt.New()
06314         d.setValues([0,2,3,1,4,5,6,8,7,9],10,1)
06315         da.renumberInPlace(d)
06316         da.renumber(d)
06317         pass
06318 
06319     def testSwigGetItem1(self):
06320         da=DataArrayInt.New()
06321         da.alloc(16,3)
06322         da.rearrange(1)
06323         da.iota(7)
06324         da.rearrange(3)
06325         da.setInfoOnComponent(0,"X [m]")
06326         da.setInfoOnComponent(1,"Y [m]")
06327         da.setInfoOnComponent(2,"Z [km]")
06328         da2=da[5:-1]
06329         self.assertEqual([22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51],da2.getValues())
06330         da2=da[4]
06331         self.assertEqual([19, 20, 21],da2.getValues())
06332         try:
06333             da2=da[4:17]
06334         except InterpKernelException as e:
06335             self.assertTrue(True)
06336         else:
06337             self.assertTrue(False)
06338             pass
06339         da2=da[5:-2,2]
06340         self.assertEqual([24, 27, 30, 33, 36, 39, 42, 45, 48],da2.getValues())
06341         da2=da[5:8,:]
06342         self.assertEqual([22, 23, 24, 25, 26, 27, 28, 29, 30],da2.getValues())
06343         da2=da[:]
06344         self.assertTrue(da2.isEqual(da))
06345         da2=da[:,:]
06346         self.assertTrue(da2.isEqual(da))
06347         try:
06348             da2=da[:,:,:]
06349         except InterpKernelException as e:
06350             self.assertTrue(True)
06351         else:
06352             self.assertTrue(False)
06353             pass
06354         try:
06355             da2=da[5:8,-2]
06356         except InterpKernelException as e:
06357             self.assertTrue(True)
06358         else:
06359             self.assertTrue(False)
06360             pass
06361         da2=da[5:8,:-2]
06362         self.assertEqual([22, 25, 28],da2.getValues())
06363         try:
06364             da2=da[5:-18,2]
06365         except InterpKernelException as e:
06366             self.assertTrue(True)
06367         else:
06368             self.assertTrue(False)
06369             pass
06370         da2=da[5:5,2]
06371         self.assertEqual([],da2.getValues())
06372         pass
06373 
06374     def testSwigGetItem2(self):
06375         da=DataArrayDouble.New()
06376         da.alloc(16,3)
06377         da.rearrange(1)
06378         da.iota(7)
06379         da.rearrange(3)
06380         da.setInfoOnComponent(0,"X [m]")
06381         da.setInfoOnComponent(1,"Y [m]")
06382         da.setInfoOnComponent(2,"Z [km]")
06383         da2=da[5:-1]
06384         self.assertEqual([22., 23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51.],da2.getValues())
06385         da2=da[4]
06386         self.assertEqual([19., 20., 21],da2.getValues())
06387         try:
06388             da2=da[4:17]
06389         except InterpKernelException as e:
06390             self.assertTrue(True)
06391         else:
06392             self.assertTrue(False)
06393             pass
06394         da2=da[5:-2,2]
06395         self.assertEqual([24., 27., 30., 33., 36., 39., 42., 45., 48.],da2.getValues())
06396         da2=da[5:8,:]
06397         self.assertEqual([22., 23., 24., 25., 26., 27., 28., 29., 30.],da2.getValues())
06398         da2=da[:]
06399         self.assertTrue(da2.isEqual(da,1e-12))
06400         da2=da[:,:]
06401         self.assertTrue(da2.isEqual(da,1e-12))
06402         try:
06403             da2=da[:,:,:]
06404         except InterpKernelException as e:
06405             self.assertTrue(True)
06406         else:
06407             self.assertTrue(False)
06408             pass
06409         try:
06410             da2=da[5:8,-2]
06411         except InterpKernelException as e:
06412             self.assertTrue(True)
06413         else:
06414             self.assertTrue(False)
06415             pass
06416         da2=da[5:8,:-2]
06417         self.assertEqual([22., 25., 28.],da2.getValues())
06418         try:
06419             da2=da[5:-18,2]
06420         except InterpKernelException as e:
06421             self.assertTrue(True)
06422         else:
06423             self.assertTrue(False)
06424             pass
06425         da2=da[5:5,2]
06426         self.assertEqual([],da2.getValues())
06427         pass
06428 
06429     def testSwigSetItem1(self):
06430         da=DataArrayInt.New()
06431         da.alloc(20,1)
06432         da.iota(7)
06433         da.rearrange(5)
06434         da.setInfoOnComponent(0,"X [m]") ; da.setInfoOnComponent(1,"Y [km]") ; da.setInfoOnComponent(2,"Y [m]")
06435         da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ; 
06436         da[:,2]=3
06437         self.assertEqual([7, 8, 3, 10, 11, 12, 13, 3, 15, 16, 17, 18, 3, 20, 21, 22, 23, 3, 25, 26],da.getValues())
06438         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06439         da[2]=3
06440         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 3, 3, 3, 3, 3, 22, 23, 24, 25, 26],da.getValues())
06441         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06442         da[[0,3]]=-1
06443         self.assertEqual([-1, -1, -1, -1, -1, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, -1, -1, -1, -1, -1],da.getValues())
06444         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06445         da[:,[1,3,4]]=-3
06446         self.assertEqual([7, -3, 9, -3, -3, 12, -3, 14, -3, -3, 17, -3, 19, -3, -3, 22, -3, 24, -3, -3],da.getValues())
06447         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06448         da2=DataArrayInt.New() ; da2.setValues([0,2,3],3,1)
06449         da[da2]=-7
06450         self.assertEqual([-7, -7, -7, -7, -7, 12, 13, 14, 15, 16, -7, -7, -7, -7, -7, -7, -7, -7, -7, -7],da.getValues())
06451         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06452         da[da2,-2:]=-7
06453         self.assertEqual([7, 8, 9, -7, -7, 12, 13, 14, 15, 16, 17, 18, 19, -7, -7, 22, 23, 24, -7, -7],da.getValues())
06454         # Let's test with DAI right hand side
06455         da1=DataArrayInt.New()
06456         da1.setValues([25,26,27,125,126,127],2,3)
06457         #
06458         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06459         da[-2:,1:4]=da1
06460         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 25, 26, 27, 21, 22, 125, 126, 127, 26],da.getValues())
06461         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06462         da[1:,3]=[225,226,227]
06463         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 225, 16, 17, 18, 19, 226, 21, 22, 23, 24, 227, 26],da.getValues())
06464         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06465         da[1,2:]=[225,226,227]
06466         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 225, 226, 227, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26],da.getValues())
06467         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06468         da[da2,-2:]=[88,99,1010,1111,1212,1313]
06469         self.assertEqual([7, 8, 9, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 1010, 1111, 22, 23, 24, 1212, 1313],da.getValues())
06470         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06471         da3=DataArrayInt.New(); da3.setValues([88,99,1010,1111,1212,1313],3,2)
06472         da[da2,-2:]=da3
06473         self.assertEqual([7, 8, 9, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 1010, 1111, 22, 23, 24, 1212, 1313],da.getValues())
06474         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06475         da[da2,[0,2]]=da3
06476         self.assertEqual([88, 8, 99, 10, 11, 12, 13, 14, 15, 16, 1010, 18, 1111, 20, 21, 1212, 23, 1313, 25, 26],da.getValues())
06477         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06478         da[da2,0:3:2]=da3
06479         self.assertEqual([88, 8, 99, 10, 11, 12, 13, 14, 15, 16, 1010, 18, 1111, 20, 21, 1212, 23, 1313, 25, 26],da.getValues())
06480         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06481         da[da2,0:3:2]=-8
06482         self.assertEqual([-8, 8, -8, 10, 11, 12, 13, 14, 15, 16, -8, 18, -8, 20, 21, -8, 23, -8, 25, 26],da.getValues())
06483         pass
06484 
06485     def testSwigSetItem2(self):
06486         da=DataArrayDouble.New()
06487         da.alloc(20,1)
06488         da.iota(7)
06489         da.rearrange(5)
06490         da.setInfoOnComponent(0,"X [m]") ; da.setInfoOnComponent(1,"Y [km]") ; da.setInfoOnComponent(2,"Y [m]")
06491         da.setInfoOnComponent(3,"Z [W]") ; da.setInfoOnComponent(4,"ZZ [km]") ; 
06492         da[:,2]=3.
06493         self.assertEqual([7., 8., 3., 10., 11., 12., 13., 3., 15., 16., 17., 18., 3., 20., 21., 22., 23., 3., 25., 26.],da.getValues())
06494         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06495         da[2]=3.
06496         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 3., 3., 3., 3., 3., 22., 23., 24., 25., 26.],da.getValues())
06497         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06498         da[[0,3]]=-1.
06499         self.assertEqual([-1., -1., -1., -1., -1., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., -1., -1., -1., -1., -1.],da.getValues())
06500         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06501         da[:,[1,3,4]]=-3.
06502         self.assertEqual([7., -3., 9., -3., -3., 12., -3., 14., -3., -3., 17., -3., 19., -3., -3., 22., -3., 24., -3., -3.],da.getValues())
06503         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06504         da2=DataArrayInt.New() ; da2.setValues([0,2,3],3,1)
06505         da[da2]=-7.
06506         self.assertEqual([-7., -7., -7., -7., -7., 12., 13., 14., 15., 16., -7., -7., -7., -7., -7., -7., -7., -7., -7., -7.],da.getValues())
06507         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06508         da[da2,-2:]=-7
06509         self.assertEqual([7., 8., 9., -7., -7., 12., 13., 14., 15., 16., 17., 18., 19., -7., -7., 22., 23., 24., -7., -7.],da.getValues())
06510         # Let's test with DAI right hand side
06511         da1=DataArrayDouble.New()
06512         da1.setValues([25,26,27,125,126,127],2,3)
06513         #
06514         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06515         da[-2:,1:4]=da1
06516         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 25., 26., 27., 21., 22., 125., 126., 127., 26.],da.getValues())
06517         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06518         da[1:,3]=[225.,226.,227.]
06519         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 14., 225., 16., 17., 18., 19., 226., 21., 22., 23., 24., 227., 26.],da.getValues())
06520         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06521         da[1,2:]=[225,226,227]
06522         self.assertEqual([7., 8., 9., 10., 11., 12., 13., 225., 226., 227., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26.],da.getValues())
06523         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06524         da[da2,-2:]=[88,99,1010,1111,1212,1313]
06525         self.assertEqual([7., 8., 9., 88., 99., 12., 13., 14., 15., 16., 17., 18., 19., 1010., 1111., 22., 23., 24., 1212., 1313.],da.getValues())
06526         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06527         da3=DataArrayDouble.New(); da3.setValues([88,99,1010,1111,1212,1313],3,2)
06528         da[da2,-2:]=da3
06529         self.assertEqual([7., 8., 9., 88., 99., 12., 13., 14., 15., 16., 17., 18., 19., 1010., 1111., 22., 23., 24., 1212., 1313.],da.getValues())
06530         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06531         da[da2,[0,2]]=da3
06532         self.assertEqual([88., 8., 99., 10., 11., 12., 13., 14., 15., 16., 1010., 18., 1111., 20., 21., 1212., 23., 1313., 25., 26.],da.getValues())
06533         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06534         da[da2,0:3:2]=da3
06535         self.assertEqual([88., 8., 99., 10., 11., 12., 13., 14., 15., 16., 1010., 18., 1111., 20., 21., 1212., 23., 1313., 25., 26.],da.getValues())
06536         da.rearrange(1) ; da.iota(7) ; da.rearrange(5)
06537         da[da2,0:3:2]=-8.
06538         self.assertEqual([-8., 8., -8., 10., 11., 12., 13., 14., 15., 16., -8., 18., -8., 20., 21., -8., 23., -8., 25., 26.],da.getValues())
06539         pass
06540 
06541     def testSwigDADOp(self):
06542         da=DataArrayDouble.New()
06543         da.alloc(12,1)
06544         da.iota(7.)
06545         da1=DataArrayDouble.New()
06546         da1.alloc(12,1)
06547         da1.iota(8.)
06548         da2=da+da1
06549         self.assertEqual([15., 17., 19., 21., 23., 25., 27., 29., 31., 33., 35., 37.],da2.getValues())
06550         da2=da+3
06551         da3=3+da
06552         self.assertTrue(da2.isEqual(da3,1e-12))
06553         da2=da-1.
06554         self.assertEqual([6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0],da2.getValues())
06555         da2=1-da
06556         self.assertEqual([-6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0, -13.0, -14.0, -15.0, -16.0, -17.0],da2.getValues())
06557         da2=da*3
06558         self.assertEqual([21.0, 24.0, 27.0, 30.0, 33.0, 36.0, 39.0, 42.0, 45.0, 48.0, 51.0, 54.0],da2.getValues())
06559         da2=3.*da
06560         self.assertEqual([21.0, 24.0, 27.0, 30.0, 33.0, 36.0, 39.0, 42.0, 45.0, 48.0, 51.0, 54.0],da2.getValues())
06561         da2=da*da1
06562         self.assertEqual([56.0, 72.0, 90.0, 110.0, 132.0, 156.0, 182.0, 210.0, 240.0, 272.0, 306.0, 342.0],da2.getValues())
06563         da2=da/4.
06564         self.assertEqual([1.75, 2.0, 2.25, 2.5, 2.75, 3.0, 3.25, 3.5, 3.75, 4.0, 4.25, 4.5],da2.getValues())
06565         da3=4./da
06566         da4=da3*da2
06567         self.assertTrue(da4.isUniform(1.,1e-12))
06568         st1=da.getHiddenCppPointer()
06569         da+=1
06570         st2=da.getHiddenCppPointer()
06571         self.assertEqual(st1,st2)
06572         self.assertTrue(da.isEqual(da1,1e-12))
06573         da-=8
06574         st2=da.getHiddenCppPointer()
06575         self.assertEqual(st1,st2)
06576         self.assertEqual(range(12),da.getValues())
06577         da+=da1
06578         st2=da.getHiddenCppPointer()
06579         self.assertEqual(st1,st2)
06580         self.assertEqual([8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0, 28.0, 30.0],da.getValues())
06581         da*=0.5
06582         st2=da.getHiddenCppPointer()
06583         self.assertEqual(st1,st2)
06584         self.assertEqual([4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0],da.getValues())
06585         da*=da1
06586         st2=da.getHiddenCppPointer()
06587         self.assertEqual(st1,st2)
06588         self.assertEqual([32.0, 45.0, 60.0, 77.0, 96.0, 117.0, 140.0, 165.0, 192.0, 221.0, 252.0, 285.0],da.getValues())
06589         da/=da1
06590         self.assertEqual(st1,st2)
06591         self.assertEqual([4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0],da.getValues())
06592         da/=2
06593         st2=da.getHiddenCppPointer()
06594         self.assertEqual(st1,st2)
06595         self.assertEqual([2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5],da.getValues())
06596         da.rearrange(3)
06597         da5=DataArrayDouble.New()
06598         da5.setValues([5.,4.,3.,2.],4,1)
06599         da*=da5 # it works with unmathing number of compo
06600         st2=da.getHiddenCppPointer()
06601         self.assertEqual(st1,st2)
06602         self.assertEqual([10.0, 12.5, 15.0, 14.0, 16.0, 18.0, 15.0, 16.5, 18.0, 13.0, 14.0, 15.0],da.getValues())
06603         #
06604         da.alloc(30,1)
06605         da.iota(7.)
06606         da.rearrange(3)
06607         ids=DataArrayInt.New()
06608         ids.setValues([3,4,7],3,1)
06609         da[ids,:]=[5.,8.,9.]
06610         self.assertEqual([7.,8.,9.,10.,11.,12.,13.,14.,15.,5.,8.,9.,5.,8.,9.,22.,23.,24.,25.,26.,27.,5.,8.,9.,31.,32.,33.,34.,35.,36.0],da.getValues())
06611         #
06612         da.rearrange(1) ; da.iota(7) ; da.rearrange(3)
06613         da[ids,[1,2]]=[5,8]
06614         self.assertEqual([7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,5.,8.,19.,5.,8.,22.,23.,24.,25.,26.,27.,28.,5.,8.,31.,32.,33.,34.,35.,36.],da.getValues())
06615         pass
06616 
06617     def testSwigDAIOp(self):
06618         da=DataArrayInt.New()
06619         da.alloc(12,1)
06620         da.iota(7)
06621         da1=DataArrayInt.New()
06622         da1.alloc(12,1)
06623         da1.iota(8)
06624         da2=da+da1
06625         self.assertEqual([15,17,19,21,23,25,27,29,31,33,35,37],da2.getValues())
06626         da2=da+3
06627         da3=3+da
06628         self.assertTrue(da2.isEqual(da3))
06629         da2=da-1
06630         self.assertEqual([6,7,8,9,10,11,12,13,14,15,16,17],da2.getValues())
06631         da2=1-da
06632         self.assertEqual([-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17],da2.getValues())
06633         da2=da*3
06634         self.assertEqual([21,24,27,30,33,36,39,42,45,48,51,54.0],da2.getValues())
06635         da2=3*da
06636         self.assertEqual([21,24,27,30,33,36,39,42,45,48,51,54.0],da2.getValues())
06637         da2=da*da1
06638         self.assertEqual([56,72,90,110,132,156,182,210,240,272,306,342.0],da2.getValues())
06639         da2=da/4
06640         self.assertEqual([1,2,2,2,2,3,3,3,3,4,4,4],da2.getValues())
06641         da3=4/da
06642         da4=da3*da2
06643         self.assertTrue(da4.isUniform(0))
06644         st1=da.getHiddenCppPointer()
06645         da+=1
06646         st2=da.getHiddenCppPointer()
06647         self.assertEqual(st1,st2)
06648         self.assertTrue(da.isEqual(da1))
06649         da-=8
06650         st2=da.getHiddenCppPointer()
06651         self.assertEqual(st1,st2)
06652         self.assertEqual(range(12),da.getValues())
06653         da+=da1
06654         st2=da.getHiddenCppPointer()
06655         self.assertEqual(st1,st2)
06656         self.assertEqual([8,10,12,14,16,18,20,22,24,26,28,30],da.getValues())
06657         da/=2
06658         st2=da.getHiddenCppPointer()
06659         self.assertEqual(st1,st2)
06660         self.assertEqual([4,5,6,7,8,9,10,11,12,13,14,15],da.getValues())
06661         da*=da1
06662         st2=da.getHiddenCppPointer()
06663         self.assertEqual(st1,st2)
06664         self.assertEqual([32,45,60,77,96,117,140,165,192,221,252,285],da.getValues())
06665         da/=da1
06666         self.assertEqual(st1,st2)
06667         self.assertEqual([4,5,6,7,8,9,10,11,12,13,14,15],da.getValues())
06668         da/=2
06669         st2=da.getHiddenCppPointer()
06670         self.assertEqual(st1,st2)
06671         self.assertEqual([2,2, 3,3, 4,4, 5,5, 6,6, 7,7],da.getValues())
06672         da.rearrange(3)
06673         da5=DataArrayInt.New()
06674         da5.setValues([5,4,3,2],4,1)
06675         da*=da5 # it works with unmathing number of compo
06676         st2=da.getHiddenCppPointer()
06677         self.assertEqual(st1,st2)
06678         self.assertEqual([10,10, 15,12,16,16,15,15, 18,12,14,14],da.getValues())
06679         da%=6
06680         st2=da.getHiddenCppPointer()
06681         self.assertEqual(st1,st2)
06682         self.assertEqual([4,4,3,0,4,4,3,3,0,0,2,2],da.getValues())
06683         #
06684         da.alloc(30,1)
06685         da.iota(7)
06686         da.rearrange(3)
06687         ids=DataArrayInt.New()
06688         ids.setValues([3,4,7],3,1)
06689         da[ids,:]=[5,8,9]
06690         self.assertEqual([7,8,9,10,11,12,13,14,15,5,8,9,5,8,9,22,23,24,25,26,27,5,8,9,31,32,33,34,35,36],da.getValues())
06691         #
06692         da.rearrange(1) ; da.iota(7) ; da.rearrange(3)
06693         da[ids,[1,2]]=[5,8]
06694         self.assertEqual([7,8,9,10,11,12,13,14,15,16,5,8,19,5,8,22,23,24,25,26,27,28,5,8,31,32,33,34,35,36],da.getValues())
06695         pass
06696 
06697     def testSwigDAIOp2(self):
06698         da=DataArrayInt.New()
06699         st=da.getHiddenCppPointer()
06700         da.alloc(10,3)
06701         da.rearrange(1)
06702         da.iota(0)
06703         da.rearrange(3)
06704         da[:,1]+=4
06705         da[-2:,2]+=10
06706         da[-2:,2]+=10
06707         da[:,2]+=da[:,0]
06708         da[da[0],:]=7
06709         self.assertEqual(st,da.getHiddenCppPointer())
06710         self.assertEqual(da.getValues(),[7,7,7,3,8,8,7,7,7,9,14,20,12,17,26,7,7,7,18,23,38,21,26,44,24,29,70,27,32,76])
06711         pass
06712 
06713     def testSwigDAIOp3(self):
06714         da=DataArrayInt.New()
06715         self.assertRaises(InterpKernelException,da.__len__)
06716         self.assertRaises(InterpKernelException,da.__int__)
06717         for elt in da:
06718             self.assertTrue(False)
06719             pass
06720         da.alloc(12,3)
06721         da.rearrange(1) ; da.fillWithZero()
06722         l1=list(da)
06723         self.assertEqual(36,len(da));
06724         da.rearrange(3)
06725         tmp=da[0]
06726         self.assertRaises(InterpKernelException,tmp.__int__)
06727         self.assertEqual(12,len(da));
06728         l=list(da)
06729         for elt in enumerate(l):
06730             elt[1][2]=elt[0]
06731             pass
06732         ref=[0,0,0,0,0,1,0,0,2,0,0,3,0,0,4,0,0,5,0,0,6,0,0,7,0,0,8,0,0,9,0,0,10,0,0,11]
06733         self.assertEqual(ref,da.getValues());
06734         da.rearrange(1)
06735         l=[int(elt) for elt in l1]
06736         self.assertEqual(ref,da.getValues());
06737         self.assertEqual(11,int(da[-1:]))
06738         pass
06739 
06740     def testSwigDADOp3(self):
06741         da=DataArrayDouble.New()
06742         self.assertRaises(InterpKernelException,da.__len__)
06743         self.assertRaises(InterpKernelException,da.__float__)
06744         for elt in da:
06745             self.assertTrue(False)
06746             pass
06747         da.alloc(12,3)
06748         da.rearrange(1) ; da.fillWithZero()
06749         l1=list(da)
06750         self.assertEqual(36,len(da));
06751         da.rearrange(3)
06752         tmp=da[0]
06753         self.assertRaises(InterpKernelException,tmp.__float__)
06754         self.assertEqual(12,len(da));
06755         l=list(da)
06756         for elt in enumerate(l):
06757             elt[1][2]=elt[0]
06758             pass
06759         ref=[0.,0.,0.,0.,0.,1.,0.,0.,2.,0.,0.,3.,0.,0.,4.,0.,0.,5.,0.,0.,6.,0.,0.,7.,0.,0.,8.,0.,0.,9.,0.,0.,10.,0.,0.,11.]
06760         self.assertEqual(ref,da.getValues());
06761         da.rearrange(1)
06762         l=[float(elt) for elt in l1]
06763         self.assertEqual(ref,da.getValues());
06764         self.assertEqual(11.,float(da[-1:]))
06765         pass
06766 
06767     def testSwigDataArrayIntIterator1(self):
06768         da=DataArrayInt.New()
06769         da.alloc(12,1)
06770         da.iota(2)
06771         da.rearrange(3)
06772         # __getitem__ testing
06773         li=[]
06774         for it in da:
06775             li+=it[1:]
06776             pass
06777         self.assertEqual([3, 4, 6, 7, 9, 10, 12, 13],li)
06778         li=[]
06779         for it in da:
06780             li+=[it[-1]]
06781             pass
06782         self.assertEqual([4, 7, 10, 13],li)
06783         li=[]
06784         for it in da:
06785             li+=it[[2,1,0]]
06786             pass
06787         self.assertEqual([4, 3, 2, 7, 6, 5, 10, 9, 8, 13, 12, 11],li)
06788         # __setitem__ testing
06789         da3=da.deepCpy()
06790         da2=DataArrayInt.New()
06791         da2.alloc(12,1)
06792         da2.iota(2002)
06793         da2.rearrange(3)
06794         it2=da2.__iter__()
06795         i=0
06796         for it in da:
06797             pt=it2.next()
06798             it[:]=pt
06799             pass
06800         self.assertTrue(da.isEqual(da2))
06801         da=da3
06802         da3=da.deepCpy()
06803         #
06804         for it in da:
06805             it[:]=5
06806             pass
06807         da.rearrange(1)
06808         self.assertTrue(da.isUniform(5))
06809         da=da3
06810         da3=da.deepCpy()
06811         #
06812         for it in da:
06813             it[:]=[8,9,12]
06814             pass
06815         self.assertEqual([8, 9, 12, 8, 9, 12, 8, 9, 12, 8, 9, 12],da.getValues())
06816         da=da3
06817         da3=da.deepCpy()
06818         #
06819         for it in da:
06820             it[2]=[7]
06821             pass
06822         self.assertEqual([2, 3, 7, 5, 6, 7, 8, 9, 7, 11, 12, 7],da.getValues())
06823         pass
06824 
06825     def testSwigDataArrayDoubleIterator1(self):
06826         da=DataArrayDouble.New()
06827         da.alloc(12,1)
06828         da.iota(2)
06829         da.rearrange(3)
06830         # __getitem__ testing
06831         li=[]
06832         for it in da:
06833             li+=it[1:]
06834             pass
06835         self.assertEqual([3, 4, 6, 7, 9, 10, 12, 13],li)
06836         li=[]
06837         for it in da:
06838             li+=[it[-1]]
06839             pass
06840         self.assertEqual([4, 7, 10, 13],li)
06841         li=[]
06842         for it in da:
06843             li+=it[[2,1,0]]
06844             pass
06845         self.assertEqual([4, 3, 2, 7, 6, 5, 10, 9, 8, 13, 12, 11],li)
06846         # __setitem__ testing
06847         da3=da.deepCpy()
06848         da2=DataArrayDouble.New()
06849         da2.alloc(12,1)
06850         da2.iota(2002)
06851         da2.rearrange(3)
06852         it2=da2.__iter__()
06853         i=0
06854         for it in da:
06855             pt=it2.next()
06856             it[:]=pt
06857             pass
06858         self.assertTrue(da.isEqual(da2,1e-12))
06859         da=da3
06860         da3=da.deepCpy()
06861         #
06862         for it in da:
06863             it[:]=5
06864             pass
06865         da.rearrange(1)
06866         self.assertTrue(da.isUniform(5,1e-12))
06867         da=da3
06868         da3=da.deepCpy()
06869         #
06870         for it in da:
06871             it[:]=[8,9,12]
06872             pass
06873         self.assertEqual([8, 9, 12, 8, 9, 12, 8, 9, 12, 8, 9, 12],da.getValues())
06874         da=da3
06875         da3=da.deepCpy()
06876         #
06877         for it in da:
06878             it[2]=[7]
06879             pass
06880         self.assertEqual([2, 3, 7, 5, 6, 7, 8, 9, 7, 11, 12, 7],da.getValues())
06881         pass
06882 
06883     def testSwigUMeshIterator1(self):
06884         m=MEDCouplingDataForTest.build2DTargetMesh_1()
06885         li1=[]
06886         li2=[]
06887         for cell in m:
06888             li1+=cell.getAllConn()[1:]
06889             li2+=[cell.getType()]
06890             pass
06891         self.assertEqual(li1,[0, 3, 4, 1, 1, 4, 2, 4, 5, 2, 6, 7, 4, 3, 7, 8, 5, 4])
06892         self.assertEqual(li2,[4, 3, 3, 4, 4])
06893         pass
06894 
06895     def testSwigUMeshIterator2(self):
06896         m=MEDCouplingDataForTest.build2DTargetMesh_1()
06897         self.assertRaises(InterpKernelException,m.cellsByType);
06898         m.rearrange2ConsecutiveCellTypes()
06899         li1=[]
06900         li2=[]
06901         li3=[]
06902         for cellsByType in m.cellsByType():
06903             li1.append(cellsByType.getType())
06904             li2.append(cellsByType.getNumberOfElems())
06905             temp=[]
06906             for cell in cellsByType:
06907                 t=[None,None]
06908                 t[0]=cell.getType()
06909                 t[1]=cell.getAllConn()[1:]
06910                 temp.append(t)
06911                 pass
06912             li3.append(temp)
06913             pass
06914         self.assertEqual(li1,[4, 3])
06915         self.assertEqual(li2,[3, 2])
06916         self.assertEqual(li3,[[[4, (0, 3, 4, 1)], [4, (6, 7, 4, 3)], [4, (7, 8, 5, 4)]], [[3, (1, 4, 2)], [3, (4, 5, 2)]]])
06917         pass
06918 
06919     def testDAIAggregateMulti1(self):
06920         a=DataArrayInt.New()
06921         a.setValues(range(4),2,2)
06922         a.setName("aa")
06923         b=DataArrayInt.New()
06924         b.setValues(range(6),3,2)
06925         c=DataArrayInt.Aggregate([a,b])
06926         self.assertEqual(range(4)+range(6),c.getValues())
06927         self.assertEqual("aa",c.getName())
06928         self.assertEqual(5,c.getNumberOfTuples())
06929         self.assertEqual(2,c.getNumberOfComponents())
06930         pass
06931 
06932     def testMergeUMeshes2(self):
06933         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
06934         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
06935         m3=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
06936         #
06937         vec1=[0,2,3]
06938         m2_2=m2.buildPartOfMySelf(vec1,False);
06939         vec2=[1,1]
06940         m3_2=m3.buildPartOfMySelf(vec2,False);
06941         #
06942         ms=[m1,m2_2,m3_2];
06943         #
06944         self.assertRaises(InterpKernelException,MEDCouplingUMesh.MergeUMeshes,ms+[None]);
06945         self.assertRaises(InterpKernelException,MEDCouplingUMesh.MergeUMeshes,ms+[3.4])
06946         m4=MEDCouplingUMesh.MergeUMeshes(ms);
06947         m4.checkCoherency();
06948         self.assertEqual(10,m4.getNumberOfCells());
06949         self.assertEqual(20,m4.getNumberOfNodes());
06950         self.assertEqual(45,m4.getMeshLength());
06951         m4bis=MEDCouplingMesh.MergeMeshes(ms);
06952         self.assertTrue(m4.isEqual(m4bis,1e-12))
06953         del m4bis
06954         #
06955         vec3=[0,1,2,3,4]
06956         m4_1=m4.buildPartOfMySelf(vec3,False);
06957         m4_1.setName(m1.getName());
06958         self.assertTrue(m4_1.isEqual(m1,1e-12));
06959         #
06960         vec4=[5,6,7]
06961         m4_2=m4.buildPartOfMySelf(vec4,False);
06962         cellCor,nodeCor=m4_2.checkGeoEquivalWith(m2_2,10,1e-12);
06963         #
06964         vec5=[8,9]
06965         m4_3=m4.buildPartOfMySelf(vec5,False);
06966         self.assertEqual(2,m4_3.getNumberOfCells());
06967         self.assertEqual(3,m4_3.getNumberOfNodes());
06968         m3_2.zipCoords();
06969         m4_3.setName(m3_2.getName());
06970         self.assertTrue(m4_3.isEqual(m3_2,1e-12));
06971         #
06972         pass
06973 
06974     def testBuild0DMeshFromCoords1(self):
06975         sourceCoords=[-0.3,-0.3,0., 0.7,-0.3,0., -0.3,0.7,0., 0.7,0.7,0.]
06976         coo=DataArrayDouble.New();
06977         coo.setValues(sourceCoords,4,3);
06978         coo.setName("My0D");
06979         m=MEDCouplingUMesh.Build0DMeshFromCoords(coo);
06980         m.checkCoherency();
06981         self.assertEqual(4,m.getNumberOfNodes());
06982         self.assertEqual(4,m.getNumberOfCells());
06983         self.assertEqual(3,m.getSpaceDimension());
06984         self.assertEqual(0,m.getMeshDimension());
06985         types1=m.getAllTypes();
06986         self.assertEqual([NORM_POINT1],types1);
06987         for i in xrange(4):
06988             conn=m.getNodeIdsOfCell(i);
06989             self.assertEqual([i],conn);
06990             self.assertTrue(NORM_POINT1==m.getTypeOfCell(i));
06991             pass
06992         self.assertEqual(m.getName(),"My0D");
06993         pass
06994 
06995     def testDescriptionInMeshTimeUnit1(self):
06996         text1="totoTTEDD";
06997         m=MEDCouplingDataForTest.build2DTargetMesh_1();
06998         m.setDescription(text1);
06999         self.assertEqual(m.getDescription(),text1);
07000         m2=m.deepCpy();
07001         self.assertTrue(m.isEqual(m2,1e-12));
07002         self.assertEqual(m2.getDescription(),text1);
07003         m2.setDescription("ggg");
07004         self.assertTrue(not m.isEqual(m2,1e-12));
07005         #
07006         f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
07007         f.setTimeUnit(text1);
07008         self.assertEqual(f.getTimeUnit(),text1);
07009         f2=f.deepCpy();
07010         self.assertEqual(f2.getTimeUnit(),text1);
07011         #
07012         pass
07013 
07014     def testMultiFields1(self):
07015         mfs=MEDCouplingDataForTest.buildMultiFields_1();
07016         ms=mfs.getMeshes();
07017         dms,refs=mfs.getDifferentMeshes()
07018         das=mfs.getArrays();
07019         das2,refs2=mfs.getDifferentArrays()
07020         self.assertEqual(5,len(mfs.getFields()))
07021         self.assertEqual(1,len(mfs.getFields()[0].getArrays()));
07022         self.assertEqual(2,len(mfs.getFields()[1].getArrays()));
07023         self.assertEqual(1,len(mfs.getFields()[2].getArrays()));
07024         self.assertEqual(1,len(mfs.getFields()[3].getArrays()));
07025         self.assertEqual(1,len(mfs.getFields()[4].getArrays()));
07026         self.assertEqual(5,len(ms));
07027         self.assertEqual(2,len(dms));
07028         self.assertEqual(6,len(das));
07029         self.assertEqual(5,len(das2));
07030         mfs2=mfs.deepCpy();
07031         self.assertTrue(mfs.isEqual(mfs2,1e-12,1e-12))
07032         pass
07033 
07034     def testFieldOverTime1(self):
07035         fs=MEDCouplingDataForTest.buildMultiFields_2();
07036         self.assertRaises(InterpKernelException,MEDCouplingFieldOverTime.New,fs);
07037         f4bis=fs[4].buildNewTimeReprFromThis(ONE_TIME,False);
07038         fs[4]=f4bis;
07039         self.assertRaises(InterpKernelException,MEDCouplingFieldOverTime.New,fs);
07040         f4bis.setTime(2.7,20,21);
07041         fot=MEDCouplingFieldOverTime.New(fs);
07042         dt=fot.getDefinitionTimeZone();
07043         hs=dt.getHotSpotsTime();
07044         self.assertEqual(6,len(hs));
07045         expected1=[0.2,0.7,1.2,1.35,1.7,2.7]
07046         for i in xrange(6):
07047             self.assertAlmostEqual(expected1[i],hs[i],12);
07048             pass
07049         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(0.2);
07050         self.assertEqual(0,meshId);
07051         self.assertEqual(0,arrId);
07052         self.assertEqual(0,arrIdInField);
07053         self.assertEqual(0,fieldId);
07054         #
07055         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(0.7);
07056         self.assertEqual(0,meshId);
07057         self.assertEqual(1,arrId);
07058         self.assertEqual(0,arrIdInField);
07059         self.assertEqual(1,fieldId);
07060         #
07061         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeLeft(1.2);#**** WARNING left here
07062         self.assertEqual(0,meshId);
07063         self.assertEqual(2,arrId);
07064         self.assertEqual(1,arrIdInField);
07065         self.assertEqual(1,fieldId);
07066         #
07067         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(1.2);#**** WARNING right again here
07068         self.assertEqual(1,meshId);
07069         self.assertEqual(3,arrId);
07070         self.assertEqual(0,arrIdInField);
07071         self.assertEqual(2,fieldId);
07072         #
07073         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(1.35);
07074         self.assertEqual(1,meshId);
07075         self.assertEqual(3,arrId);
07076         self.assertEqual(0,arrIdInField);
07077         self.assertEqual(2,fieldId);
07078         #
07079         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(1.7);
07080         self.assertEqual(0,meshId);
07081         self.assertEqual(3,arrId);
07082         self.assertEqual(0,arrIdInField);
07083         self.assertEqual(3,fieldId);
07084         #
07085         meshId,arrId,arrIdInField,fieldId=dt.getIdsOnTimeRight(2.7);
07086         self.assertEqual(1,meshId);
07087         self.assertEqual(4,arrId);
07088         self.assertEqual(0,arrIdInField);
07089         self.assertEqual(4,fieldId);
07090         #
07091         dt2=MEDCouplingDefinitionTime();
07092         self.assertTrue(not dt2.isEqual(dt));
07093         dt2.assign(dt);
07094         dt2.assign(dt);#to check memory management
07095         self.assertTrue(dt2.isEqual(dt));
07096         #
07097         dt3=MEDCouplingDefinitionTime();
07098         #
07099         pass
07100 
07101     def testDAICheckAndPreparePermutation1(self):
07102         vals1=[9,10,0,6,4,11,3,7];
07103         expect1=[5,6,0,3,2,7,1,4];
07104         vals2=[9,10,0,6,10,11,3,7];
07105         da=DataArrayInt.New();
07106         da.setValues(vals1,8,1);
07107         da2=da.checkAndPreparePermutation();
07108         self.assertEqual(8,da2.getNumberOfTuples());
07109         self.assertEqual(1,da2.getNumberOfComponents());
07110         for i in xrange(8):
07111             self.assertEqual(expect1[i],da2.getIJ(i,0));
07112             pass
07113         #
07114         da=DataArrayInt.New();
07115         da.alloc(8,1);
07116         da.iota(0);
07117         da2=da.checkAndPreparePermutation();
07118         self.assertEqual(8,da2.getNumberOfTuples());
07119         self.assertEqual(1,da2.getNumberOfComponents());
07120         self.assertTrue(da2.isIdentity());
07121         #
07122         da=DataArrayInt.New();
07123         da.alloc(8,1);
07124         da.setValues(vals2,8,1);
07125         self.assertRaises(InterpKernelException,da.checkAndPreparePermutation);
07126         pass
07127 
07128     def testDAIChangeSurjectiveFormat1(self):
07129         vals1=[0,3,2,3,2,2,1,2]
07130         expected1=[0,1,2,6,8]
07131         expected2=[0,  6,  2,4,5,7,  1,3]
07132         da=DataArrayInt.New();
07133         da.setValues(vals1,8,1);
07134         #
07135         da2,da2I=da.changeSurjectiveFormat(4);
07136         self.assertEqual(5,da2I.getNumberOfTuples());
07137         self.assertEqual(8,da2.getNumberOfTuples());
07138         self.assertEqual(expected1,da2I.getValues());
07139         self.assertEqual(expected2,da2.getValues());
07140         #
07141         self.assertRaises(InterpKernelException,da.changeSurjectiveFormat,3);
07142         #
07143         pass
07144 
07145     def testUMeshGetCellIdsLyingOnNodes1(self):
07146         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
07147         nodeIds1=[1,2,3,4,6]
07148         nodeIds2=[6,7]
07149         da=m.getCellIdsLyingOnNodes(nodeIds1,True);
07150         self.assertEqual(1,da.getNumberOfTuples());
07151         self.assertEqual(1,da.getNumberOfComponents());
07152         self.assertEqual(1,da.getIJ(0,0));
07153         da2=DataArrayInt.New()
07154         da2.setValues(nodeIds2,2,1)
07155         da=m.getCellIdsLyingOnNodes(da2,False);
07156         self.assertEqual(2,da.getNumberOfTuples());
07157         self.assertEqual(1,da.getNumberOfComponents());
07158         self.assertEqual(3,da.getIJ(0,0));
07159         self.assertEqual(4,da.getIJ(1,0));
07160         pass
07161 
07162     def testUMeshFindCellsIdsOnBoundary1(self):
07163         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
07164         da5=m.findCellsIdsOnBoundary();
07165         self.assertEqual(5,da5.getNumberOfTuples());
07166         self.assertTrue(da5.isIdentity());
07167         pass
07168 
07169     def testMeshSetTime1(self):
07170         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
07171         m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
07172         #
07173         self.assertTrue(m1.isEqual(m2,1e-12));
07174         m1.setTime(3.14,6,7);
07175         tmp3,tmp1,tmp2=m1.getTime();
07176         self.assertEqual(6,tmp1);
07177         self.assertEqual(7,tmp2);
07178         self.assertAlmostEqual(3.14,tmp3,12);
07179         self.assertTrue(not m1.isEqual(m2,1e-12));
07180         m2.setTime(3.14,6,7);
07181         self.assertTrue(m1.isEqual(m2,1e-12));
07182         m1.setTimeUnit("ms");
07183         self.assertTrue(m1.getTimeUnit()=="ms");
07184         m1.setTimeUnit("us");
07185         self.assertTrue(m1.getTimeUnit()=="us");
07186         self.assertTrue(not m1.isEqual(m2,1e-12));
07187         m2.setTimeUnit("us");
07188         self.assertTrue(m1.isEqual(m2,1e-12));
07189         m2.setTime(3.14,6,8);
07190         self.assertTrue(not m1.isEqual(m2,1e-12));
07191         m2.setTime(3.14,7,7);
07192         self.assertTrue(not m1.isEqual(m2,1e-12));
07193         m2.setTime(3.15,6,7);
07194         self.assertTrue(not m1.isEqual(m2,1e-12));
07195         #
07196         m1.setTime(10.34,55,12);
07197         m3=m1.deepCpy();
07198         self.assertTrue(m1.isEqual(m3,1e-12));
07199         tmp3,tmp1,tmp2=m3.getTime();
07200         self.assertEqual(55,tmp1);
07201         self.assertEqual(12,tmp2);
07202         self.assertAlmostEqual(10.34,tmp3,12);
07203         #
07204         # testing CMesh
07205         coo1=[0.,1.,2.,3.5]
07206         a=DataArrayDouble.New();
07207         a.setValues(coo1,4,1);
07208         b=MEDCouplingCMesh.New();
07209         b.setCoordsAt(0,a);
07210         #
07211         b.setTime(5.67,8,100);
07212         tmp3,tmp1,tmp2=b.getTime();
07213         self.assertEqual(8,tmp1);
07214         self.assertEqual(100,tmp2);
07215         self.assertAlmostEqual(5.67,tmp3,12);
07216         c=b.deepCpy();
07217         self.assertTrue(c.isEqual(b,1e-12));
07218         tmp3,tmp1,tmp2=c.getTime();
07219         self.assertEqual(8,tmp1);
07220         self.assertEqual(100,tmp2);
07221         self.assertAlmostEqual(5.67,tmp3,12);
07222         pass
07223 
07224     def testApplyFuncTwo1(self):
07225         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
07226         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
07227         f1.setMesh(m1);
07228         #
07229         vals=[1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.]
07230         da=DataArrayDouble.New();
07231         da.setValues(vals,5,3);
07232         f1.setArray(da);
07233         #
07234         self.assertRaises(InterpKernelException,da.applyFunc2,1,"y+z");
07235         da.setInfoOnComponent(0,"x [m]");
07236         da.setInfoOnComponent(1,"y [mm]");
07237         da.setInfoOnComponent(2,"z [km]");
07238         
07239         self.assertRaises(InterpKernelException, da.applyFunc2, 1, "x+y+zz+zzz");
07240         self.assertRaises(InterpKernelException, da.applyFunc2, 1, "toto(x+y)");
07241         self.assertRaises(InterpKernelException, da.applyFunc2, 1, "x/0");
07242         
07243         da2=da.applyFunc2(1,"y+z");
07244         self.assertEqual(1,da2.getNumberOfComponents());
07245         self.assertEqual(5,da2.getNumberOfTuples());
07246         expected1=[32.,34.,36.,38.,40.]
07247         for i in xrange(5):
07248             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),12);
07249             pass
07250         da2=da.applyFunc(1,"y+z");
07251         expected2=[12.,14.,16.,18.,20.]
07252         for i in xrange(5):
07253             self.assertAlmostEqual(expected2[i],da2.getIJ(0,i),12);
07254             pass
07255         #
07256         self.assertEqual(3,f1.getNumberOfComponents());
07257         self.assertEqual(5,f1.getNumberOfTuples());
07258         f1.applyFunc2(1,"y+z");
07259         self.assertEqual(1,f1.getNumberOfComponents());
07260         self.assertEqual(5,f1.getNumberOfTuples());
07261         for i in xrange(5):
07262             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
07263             pass
07264         #
07265         pass
07266 
07267     def testApplyFuncThree1(self):
07268         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
07269         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
07270         f1.setMesh(m1);
07271         #
07272         vals=[1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.]
07273         da=DataArrayDouble.New();
07274         da.setValues(vals,5,3);
07275         f1.setArray(da);
07276         #
07277         vs=3*[None];
07278         vs[0]="x"; vs[1]="Y"; vs[2]="z";
07279         self.assertRaises(InterpKernelException, da.applyFunc3, 1, vs, "y+z");
07280         self.assertRaises(InterpKernelException, da.applyFunc3, 1, vs, "x+Y+z+zz+zzz");
07281         self.assertRaises(InterpKernelException, da.applyFunc3, 1, vs, "x/0");
07282         vs[1]="y";
07283         da2=da.applyFunc3(1,vs,"y+z");
07284         expected1=[32.,34.,36.,38.,40.]
07285         for i in xrange(5):
07286             self.assertAlmostEqual(expected1[i],da2.getIJ(0,i),12);
07287             pass
07288         f1.setArray(da);
07289         self.assertEqual(3,f1.getNumberOfComponents());
07290         self.assertEqual(5,f1.getNumberOfTuples());
07291         f1.applyFunc3(1,vs,"y+z");
07292         self.assertEqual(1,f1.getNumberOfComponents());
07293         self.assertEqual(5,f1.getNumberOfTuples());
07294         for i in xrange(5):
07295             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
07296             pass
07297         pass
07298 
07299     def testFillFromAnalyticTwo1(self):
07300         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
07301         self.assertRaises(InterpKernelException,m1.fillFromAnalytic2,ON_NODES,1,"y+z");
07302         m1.getCoords().setInfoOnComponent(0,"x [m]");
07303         m1.getCoords().setInfoOnComponent(1,"y");
07304         m1.getCoords().setInfoOnComponent(2,"z");
07305         f1=m1.fillFromAnalytic2(ON_NODES,1,"y+z");
07306         self.assertEqual(1,f1.getNumberOfComponents());
07307         self.assertEqual(9,f1.getNumberOfTuples());
07308         expected1=[0.2, 0.7, 1.2, 0.7, 1.2, 1.7, 1.2, 1.7, 2.2]
07309         for i in xrange(9):
07310             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
07311             pass
07312         pass
07313 
07314     def testFillFromAnalyticThree1(self):
07315         m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
07316         vs=3*[None];
07317         vs[0]="x"; vs[1]="Y"; vs[2]="z";
07318         self.assertRaises(InterpKernelException,m1.fillFromAnalytic3,ON_NODES,1,vs,"y+z");
07319         vs[1]="y";
07320         f1=m1.fillFromAnalytic3(ON_NODES,1,vs,"y+z");
07321         self.assertEqual(1,f1.getNumberOfComponents());
07322         self.assertEqual(9,f1.getNumberOfTuples());
07323         expected1=[0.2, 0.7, 1.2, 0.7, 1.2, 1.7, 1.2, 1.7, 2.2]
07324         for i in xrange(9):
07325             self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12);
07326             pass
07327         pass
07328 
07329     def testDAUnitVar1(self):
07330         da=DataArrayDouble.New();
07331         da.alloc(1,3);
07332         da.setInfoOnComponent(0,"XPS [m]");
07333         st1=da.getVarOnComponent(0);
07334         self.assertTrue(st1=="XPS");
07335         st2=da.getUnitOnComponent(0);
07336         self.assertTrue(st2=="m");
07337         #
07338         da.setInfoOnComponent(0,"XPS         [m]");
07339         st1=da.getVarOnComponent(0);
07340         self.assertTrue(st1=="XPS");
07341         st2=da.getUnitOnComponent(0);
07342         self.assertTrue(st2=="m");
07343         #
07344         da.setInfoOnComponent(0,"XPP         [m]");
07345         st1=da.getVarOnComponent(0);
07346         self.assertTrue(st1=="XPP");
07347         st2=da.getUnitOnComponent(0);
07348         self.assertTrue(st2=="m");
07349         #
07350         da.setInfoOnComponent(0,"XPP kdep  kefer   [ m  ]");
07351         st1=da.getVarOnComponent(0);
07352         self.assertTrue(st1=="XPP kdep  kefer");
07353         st2=da.getUnitOnComponent(0);
07354         self.assertTrue(st2==" m  ");
07355         #
07356         da.setInfoOnComponent(0,"     XPP k[  dep  k]efer   [ m^ 2/s^3*kJ  ]");
07357         st1=da.getVarOnComponent(0);
07358         self.assertTrue(st1=="     XPP k[  dep  k]efer");
07359         st2=da.getUnitOnComponent(0);
07360         self.assertTrue(st2==" m^ 2/s^3*kJ  ");
07361         #
07362         da.setInfoOnComponent(0,"     XPP kefer   ");
07363         st1=da.getVarOnComponent(0);
07364         self.assertTrue(st1=="     XPP kefer   ");
07365         st2=da.getUnitOnComponent(0);
07366         self.assertTrue(st2=="");
07367         #
07368         da.setInfoOnComponent(0,"temperature( bof)");
07369         st1=da.getVarOnComponent(0);
07370         self.assertTrue(st1=="temperature( bof)");
07371         st2=da.getUnitOnComponent(0);
07372         self.assertTrue(st2=="");
07373         #
07374         da.setInfoOnComponent(0,"kkk [m]");
07375         da.setInfoOnComponent(1,"ppp   [m^2/kJ]");
07376         da.setInfoOnComponent(2,"abcde   [MW/s]");
07377         #
07378         vs=da.getVarsOnComponent();
07379         self.assertEqual(3,len(vs));
07380         self.assertTrue(vs[0]=="kkk");
07381         self.assertTrue(vs[1]=="ppp");
07382         self.assertTrue(vs[2]=="abcde");
07383         vs=da.getUnitsOnComponent();
07384         self.assertEqual(3,len(vs));
07385         self.assertTrue(vs[0]=="m");
07386         self.assertTrue(vs[1]=="m^2/kJ");
07387         self.assertTrue(vs[2]=="MW/s");
07388         pass
07389 
07390     def testGaussCoordinates1(self):
07391         #Testing 1D cell types
07392         m1=MEDCouplingDataForTest.build1DMultiTypes_1();
07393         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
07394         f.setMesh(m1);
07395         wg1=[0.3];
07396         gsCoo1=[0.2];
07397         refCoo1=[-1.0,1.0];
07398         f.setGaussLocalizationOnType(NORM_SEG2,refCoo1,gsCoo1,wg1);
07399         wg2=wg1;
07400         gsCoo2=[0.2];
07401         refCoo2=[-1.0,1.0,0.0];
07402         f.setGaussLocalizationOnType(NORM_SEG3,refCoo2,gsCoo2,wg2);
07403         #
07404         resToTest=f.getLocalizationOfDiscr();
07405         self.assertEqual(3,resToTest.getNumberOfComponents());
07406         self.assertEqual(2,resToTest.getNumberOfTuples());
07407         expected1=[0.6,0.6,0.6, 0.6,0.6,0.6]
07408         for i in xrange(6):
07409             self.assertAlmostEqual(expected1[i],resToTest.getIJ(0,i),14);
07410             pass
07411         #
07412         #Testing 2D cell types
07413         m2=MEDCouplingDataForTest.build2DMultiTypes_1();
07414         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
07415         f.setMesh(m2);
07416         wg3=[0.3,0.3];
07417         tria3CooGauss=[ 0.1, 0.8, 0.2, 0.7 ]
07418         gsCoo3=tria3CooGauss
07419         tria3CooRef=[ 0.0, 0.0, 1.0 , 0.0, 0.0, 1.0 ]
07420         refCoo3=tria3CooRef;
07421         f.setGaussLocalizationOnType(NORM_TRI3,refCoo3,gsCoo3,wg3);
07422         wg4=[0.3,0.3,0.3];
07423         tria6CooGauss=[ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4 ]
07424         gsCoo4=tria6CooGauss;
07425         tria6CooRef=[0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.5, 0.0, 0.5, 0.5, 0.0, 0.5]
07426         refCoo4=tria6CooRef;
07427         f.setGaussLocalizationOnType(NORM_TRI6,refCoo4,gsCoo4,wg4);
07428         wg5=[0.3,0.3,0.3,0.3];
07429         quad4CooGauss=[ 0.3, 0.2, 0.2, 0.1, 0.2, 0.4, 0.15, 0.27 ]
07430         gsCoo5=quad4CooGauss;
07431         quad4CooRef=[-1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0]
07432         refCoo5=quad4CooRef;
07433         f.setGaussLocalizationOnType(NORM_QUAD4,refCoo5,gsCoo5,wg5);
07434         wg6=[0.3,0.3,0.3,0.3];
07435         quad8CooGauss=[ 0.34, 0.16, 0.21, 0.3, 0.23, 0.4, 0.14, 0.37 ]
07436         gsCoo6=quad8CooGauss;
07437         quad8CooRef=[ -1.0, -1.0, 1.0, -1.0, 1.0,  1.0, -1.0,  1.0, 0.0, -1.0, 1.0,  0.0, 0.0,  1.0, -1.0,  0.0]
07438         refCoo6=quad8CooRef;
07439         f.setGaussLocalizationOnType(NORM_QUAD8,refCoo6,gsCoo6,wg6);
07440         #
07441         resToTest=f.getLocalizationOfDiscr();
07442         self.assertEqual(3,resToTest.getNumberOfComponents());
07443         self.assertEqual(13,resToTest.getNumberOfTuples());#2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8
07444         expected2=[5.1,1.55,0.0, 4.7,1.65,0.0,
07445                    2.32,1.52,0.0, 1.6,1.32,0.0, 3.52,1.26,0.0,#TRI6
07446                    2.6,1.6,0.0, 2.4,1.8,0.0, 2.4,1.2,0.0, 2.3,1.46,0.0,#QUAD4
07447                    2.32,2.68,0.0, 2.6,2.42,0.0, 2.8,2.46,0.0, 2.74,2.28,0.0 ];#QUAD8
07448         for i in xrange(39):
07449             self.assertAlmostEqual(expected2[i],resToTest.getIJ(0,i),14);
07450             pass
07451         #
07452         #Testing 3D cell types
07453         m3=MEDCouplingDataForTest.build3DMultiTypes_1();
07454         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
07455         f.setMesh(m3);
07456         #
07457         wg7=[0.3];
07458         tetra4CooGauss=[0.34, 0.16, 0.21]
07459         gsCoo7=tetra4CooGauss;
07460         tetra4CooRef=[0.0,1.0,0.0, 0.0,0.0,1.0, 0.0,0.0,0.0, 1.0,0.0,0.0]
07461         refCoo7=tetra4CooRef;
07462         f.setGaussLocalizationOnType(NORM_TETRA4,refCoo7,gsCoo7,wg7);
07463         wg8=[0.3];
07464         tetra10CooGauss=[0.2, 0.3, 0.1]
07465         gsCoo8=tetra10CooGauss;
07466         tetra10CooRef=[0.0,1.0,0.0, 0.0,0.0,0.0, 0.0,0.0,1.0, 1.0,0.0,0.0, 0.0,0.5,0.0, 0.0,0.0,0.5, 0.0,0.5,0.5, 0.5,0.5,0.0, 0.5,0.0,0.0, 0.5,0.0,0.5]
07467         refCoo8=tetra10CooRef;
07468         f.setGaussLocalizationOnType(NORM_TETRA10,refCoo8,gsCoo8,wg8);
07469         wg9=[0.3];
07470         pyra5CooGauss=[0.2, 0.3, 0.1]
07471         gsCoo9=pyra5CooGauss;
07472         pyra5CooRef=[1.0,0.0,0.0, 0.0,1.0,0.0, -1.0,0.0,0.0, 0.0,-1.0,0.0, 0.0,0.0,1.0]
07473         refCoo9=pyra5CooRef;
07474         f.setGaussLocalizationOnType(NORM_PYRA5,refCoo9,gsCoo9,wg9);
07475         wg10=[0.3];
07476         pyra13CooGauss=[0.1, 0.2, 0.7]
07477         gsCoo10=pyra13CooGauss;
07478         pyra13CooRef=[1.0,0.0,0.0, 0.0,1.0,0.0,-1.0,0.0,0.0,0.0,-1.0,0.0,0.0,0.0,1.0,0.5,0.5,0.0,-0.5,0.5,0.0,-0.5,-0.5,0.0,0.5,-0.5,0.0,0.5,0.0,0.5,0.0,0.5,0.5,-0.5,0.0,0.5,0.0,-0.5,0.5]
07479         refCoo10=pyra13CooRef;
07480         f.setGaussLocalizationOnType(NORM_PYRA13,refCoo10,gsCoo10,wg10);
07481         wg11=[0.3];
07482         penta6CooGauss=[0.2, 0.3, 0.1]
07483         gsCoo11=penta6CooGauss;
07484         penta6CooRef=[-1.0,1.0,0.0,-1.0,-0.0,1.0,-1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0]
07485         refCoo11=penta6CooRef;
07486         f.setGaussLocalizationOnType(NORM_PENTA6,refCoo11,gsCoo11,wg11);
07487         wg12=[0.3];
07488         penta15CooGauss=[0.2, 0.3,0.15]
07489         gsCoo12=penta15CooGauss;
07490         penta15CooRef=[-1.0,1.0,0.0,-1.0,0.0,1.0,-1.0,0.0,0.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,0.0,0.0,-1.0,0.5,0.5,-1.0,0.0,0.5,-1.0,0.5,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.5,0.5,1.0,0.0, 0.5,1.0,0.5,0.0]
07491         refCoo12=penta15CooRef;
07492         f.setGaussLocalizationOnType(NORM_PENTA15,refCoo12,gsCoo12,wg12);
07493         wg13=[0.3];
07494         hexa8CooGauss=[0.2,0.3,0.15]
07495         gsCoo13=hexa8CooGauss;
07496         hexa8CooRef=[-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0]
07497         refCoo13=hexa8CooRef;
07498         f.setGaussLocalizationOnType(NORM_HEXA8,refCoo13,gsCoo13,wg13);
07499         wg14=[0.3];
07500         hexa20CooGauss=[0.11,0.3,0.55]
07501         gsCoo14=hexa20CooGauss;
07502         hexa20CooRef=[-1.0,-1.0,-1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0,1.0,-1.0,-1.0,-1.0,1.0,1.0,-1.0,1.0,1.0,1.0,1.0,-1.0,1.0,1.0,0.0,-1.0,-1.0,1.0,0.0,-1.0,0.0,1.0,-1.0,-1.0,0.0,-1.0,-1.0,-1.0,0.0,1.0,-1.0,0.0,1.0,1.0,0.0,-1.0,1.0,0.0,0.0,-1.0,1.0,1.0,0.0,1.0,0.0,1.0,1.0,-1.0,0.0,1.0]
07503         refCoo14=hexa20CooRef;
07504         f.setGaussLocalizationOnType(NORM_HEXA20,refCoo14,gsCoo14,wg14);
07505         #
07506         resToTest=f.getLocalizationOfDiscr();
07507         self.assertEqual(3,resToTest.getNumberOfComponents());
07508         self.assertEqual(8,resToTest.getNumberOfTuples());#2+3+4+4 gauss points for resp TRI3,TRI6,QUAD4,QUAD8
07509         expected3=[1.312,3.15,1.02, 0.56,3.3,0.6, 2.18,1.1,0.2, 1.18,1.54,0.98, 1.56,0.3,3.6, 1.613,0.801,4.374, 2.6,2.4,2.3, 2.31232,2.3933985,1.553255]
07510         for i in xrange(24):
07511             self.assertAlmostEqual(expected3[i],resToTest.getIJ(0,i),14);
07512             pass
07513         #
07514         pass
07515 
07516     def testP2Localization1(self):
07517         m=MEDCouplingUMesh.New("testP2",2);
07518         coords=[0.,2.,3.5,0.,4.5,1.5,1.2,0.32,3.4,1.,2.1,2.4]
07519         conn=[0,1,2,3,4,5]
07520         coo=DataArrayDouble.New();
07521         coo.setValues(coords,6,2);
07522         m.setCoords(coo);
07523         m.allocateCells(1);
07524         m.insertNextCell(NORM_TRI6,6,conn[0:6])
07525         m.finishInsertingCells();
07526         #
07527         f=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
07528         f.setMesh(m);
07529         da=DataArrayDouble.New();
07530         vals1=[1.2,2.3,3.4, 2.2,3.3,4.4, 3.2,4.3,5.4, 4.2,5.3,6.4, 5.2,6.3,7.4, 6.2,7.3,8.4]
07531         da.setValues(vals1,6,3);
07532         f.setArray(da);
07533         #
07534         loc=[2.27,1.3]
07535         locs=f.getValueOnMulti(loc);
07536         expected1=[6.0921164547752236, 7.1921164547752232, 8.2921164547752255]
07537         for i in xrange(3):
07538             self.assertAlmostEqual(expected1[i],locs.getIJ(0,i),12);
07539             pass
07540         pass
07541 
07542     def testP2Localization2(self):
07543         m=MEDCouplingUMesh.New("testP2_2",3);
07544         coords=[0.33312787792955395, -0.35155740179580952, -0.03567564825034563, 1.307146326477638, -0.57234557776250305, -0.08608044208272235, 0.5551834466499993, 0.62324964668794192, -0.014638951108536295, 0.37761817224442129, -0.38324019806913578, 0.96283164472856886, 0.79494856035658679, -0.40628057809270046, 0.0021004190225864614, 1.023740446371799, 0.07665912970471335, -0.072889657161871096, 0.54564584619517376, 0.11132872093429744, 0.039647326652013051, 0.27164784387819052, -0.42018012100866675, 0.46563376500745146, 0.89501965094896418, -0.56148455362735061, 0.43337469695473035, 0.49118025152924394, 0.093884938060727313, 0.47216346905220891]
07545         conn=[0,1,2,3,4,5,6,7,8,9]
07546         coo=DataArrayDouble.New();
07547         coo.setValues(coords,10,3);
07548         m.setCoords(coo);
07549         m.allocateCells(1);
07550         m.insertNextCell(NORM_TETRA10,10,conn[0:10])
07551         m.finishInsertingCells();
07552         #
07553         f=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
07554         f.setMesh(m);
07555         da=DataArrayDouble.New();
07556         vals1=[1.1,2.1,3.1,4.1,5.2,6.2,7.2,8.2,9.2,10.2]
07557         da.setValues(vals1,10,1);
07558         f.setArray(da);
07559         #
07560         loc=[0.64637931739890486, -0.16185896817550552, 0.22678966365273748]
07561         locs=f.getValueOnMulti(loc);
07562         expected1=[10.0844021968047]
07563         for i in xrange(1):
07564             self.assertAlmostEqual(expected1[i],locs.getIJ(0,i),12);
07565             pass
07566         pass
07567 
07568     def testGetValueOn2(self):
07569         m=MEDCouplingDataForTest.build2DTargetMesh_1();
07570         f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME);
07571         f.setMesh(m);
07572         arr=DataArrayDouble.New();
07573         nbOfCells=m.getNumberOfCells();
07574         f.setArray(arr);
07575         values1=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.]
07576         arr.setValues(values1,nbOfCells,3);
07577         loc=[-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45]
07578         f.checkCoherency();
07579         locs=f.getValueOnMulti(loc);
07580         self.assertEqual(5,locs.getNumberOfTuples());
07581         self.assertEqual(3,locs.getNumberOfComponents());
07582         for j in xrange(15):
07583             self.assertAlmostEqual(values1[j],locs.getIJ(0,j),12);
07584             pass
07585         # Testing ON_NODES
07586         f=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME);
07587         f.setMesh(m);
07588         arr=DataArrayDouble.New();
07589         nbOfNodes=m.getNumberOfNodes();
07590         f.setArray(arr);
07591         values2=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.,12.,112.,10012.,13.,113.,10013.,14.,114.,10014.,15.,115.,10015.]
07592         arr.setValues(values2,nbOfNodes,3);
07593         loc2=[0.5432,-0.2432, 0.5478,0.1528, 0.5432,-0.2432, 0.5432,-0.2432]
07594         expected2=[9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124, 9.0272, 109.0272, 10009.0272, 9.0272, 109.0272, 10009.0272]
07595         f.checkCoherency();
07596         loc3=DataArrayDouble.New()
07597         loc3.setValues(loc2,4,2);
07598         locs=f.getValueOnMulti(loc3);
07599         self.assertEqual(4,locs.getNumberOfTuples());
07600         self.assertEqual(3,locs.getNumberOfComponents());
07601         for i in xrange(12):
07602             self.assertAlmostEqual(expected2[i],locs.getIJ(0,i),12);
07603             pass
07604         #
07605         pass
07606 
07607     def testDAIGetIdsNotEqual1(self):
07608         d=DataArrayInt.New();
07609         vals1=[2,3,5,6,8,5,5,6,1,-5]
07610         d.setValues(vals1,10,1);
07611         d2=d.getIdsNotEqual(5);
07612         self.assertEqual(7,d2.getNumberOfTuples());
07613         self.assertEqual(1,d2.getNumberOfComponents());
07614         expected1=[0,1,3,4,7,8,9]
07615         for i in xrange(7):
07616             self.assertEqual(expected1[i],d2.getIJ(0,i));
07617             pass
07618         d.rearrange(2);
07619         self.assertRaises(InterpKernelException,d.getIdsNotEqual,5);
07620         vals2=[-4,5,6]
07621         vals3=vals2;
07622         d.rearrange(1);
07623         d3=d.getIdsNotEqualList(vals3);
07624         self.assertEqual(5,d3.getNumberOfTuples());
07625         self.assertEqual(1,d3.getNumberOfComponents());
07626         expected2=[0,1,4,8,9]
07627         for i in xrange(5):
07628             self.assertEqual(expected2[i],d3.getIJ(0,i));
07629             pass
07630         pass
07631 
07632     def testDAIComputeOffsets1(self):
07633         d=DataArrayInt.New();
07634         vals1=[3,5,1,2,0,8]
07635         expected1=[0,3,8,9,11,11]
07636         d.setValues(vals1,6,1);
07637         d.computeOffsets();
07638         self.assertEqual(6,d.getNumberOfTuples());
07639         self.assertEqual(1,d.getNumberOfComponents());
07640         for i in xrange(6):
07641             self.assertEqual(expected1[i],d.getIJ(0,i));
07642             pass
07643         pass
07644 
07645     def testUMeshHexagonPrism1(self):
07646         coords=[0.8660254037844386, 0.5, 0.0, 0.0, 1.0, 0.0, -0.8660254037844386, 0.5, 0.0, -0.8660254037844386, -0.5, 0.0, 0.0, -1.0, 0.0, 0.8660254037844386, -0.5, 0.0,
07647                 0.8660254037844386, 0.5, 2.0, 0.0, 1.0, 2.0, -0.8660254037844386, 0.5, 2.0, -0.8660254037844386, -0.5, 2.0, 0.0, -1.0, 2.0, 0.8660254037844386, -0.5, 2.0];
07648         conn=[1,2,3,4,5,0,7,8,9,10,11,6]
07649         mesh=MEDCouplingUMesh.New("MyFirstHexagonalPrism",3);
07650         coo=DataArrayDouble.New();
07651         coo.setValues(coords,12,3);
07652         mesh.setCoords(coo);
07653         mesh.allocateCells(1);
07654         mesh.insertNextCell(NORM_HEXGP12,12,conn[0:12])
07655         mesh.finishInsertingCells();
07656         #
07657         mesh.checkCoherency();
07658         vols=mesh.getMeasureField(False);
07659         self.assertEqual(1,vols.getNumberOfTuples());
07660         self.assertEqual(1,vols.getNumberOfComponents());
07661         self.assertAlmostEqual(-5.196152422706632,vols.getIJ(0,0),12);
07662         bary=mesh.getBarycenterAndOwner();
07663         self.assertEqual(1,bary.getNumberOfTuples());
07664         self.assertEqual(3,bary.getNumberOfComponents());
07665         expected1=[0.,0.,1.]
07666         for i in xrange(3):
07667             self.assertAlmostEqual(expected1[i],bary.getIJ(0,i),12);
07668             pass
07669         d1=DataArrayInt.New();
07670         d2=DataArrayInt.New();
07671         d3=DataArrayInt.New();
07672         d4=DataArrayInt.New();
07673         m2=mesh.buildDescendingConnectivity(d1,d2,d3,d4);
07674         self.assertEqual(8,m2.getNumberOfCells());
07675         expected4=[[1,2,3,4,5,0],[7,6,11,10,9,8],[1,7,8,2],[2,8,9,3],[3,9,10,4],[4,10,11,5],[5,11,6,0],[0,6,7,1]];
07676         expected2=[NORM_POLYGON, NORM_POLYGON, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4, NORM_QUAD4];
07677         expected3=[6,6,4,4,4,4,4,4]
07678         for i in xrange(8):
07679             self.assertTrue(m2.getTypeOfCell(i)==expected2[i]);
07680             v=m2.getNodeIdsOfCell(i);
07681             self.assertTrue(len(v)==expected3[i]);
07682             self.assertEqual(expected4[i],v);
07683         #
07684         mesh.convertAllToPoly();
07685         self.assertTrue(NORM_POLYHED==mesh.getTypeOfCell(0));
07686         mesh.unPolyze();
07687         self.assertTrue(NORM_HEXGP12==mesh.getTypeOfCell(0));
07688         self.assertEqual(13,mesh.getMeshLength());
07689         #
07690         pass
07691 
07692     def testDADCheckIsMonotonic(self):
07693         da=DataArrayDouble.New();
07694         da.setValues([-1.,1.01,2.03,6.],2,2);
07695         self.assertRaises(InterpKernelException,da.isMonotonic,True,1e-12);
07696         da.rearrange(1);
07697         self.assertTrue(da.isMonotonic(True,1e-12));
07698         da.checkMonotonic(True,1e-12);
07699         da.setIJ(2,0,6.1);
07700         self.assertTrue(not da.isMonotonic(True,1e-12));
07701         self.assertRaises(InterpKernelException,da.checkMonotonic,True,1e-12);
07702         da.setIJ(2,0,5.99);
07703         self.assertTrue(da.isMonotonic(True,1e-12));
07704         self.assertTrue(not da.isMonotonic(True,1e-1));
07705         pass
07706 
07707     def testCheckCoherencyDeeper1(self):
07708         m=MEDCouplingDataForTest.build3DSourceMesh_1();
07709         m.checkCoherency();
07710         m.checkCoherency1();
07711         m.getNodalConnectivity().setIJ(8,0,-1);
07712         m.checkCoherency();
07713         self.assertRaises(InterpKernelException,m.checkCoherency1);
07714         m.getNodalConnectivity().setIJ(8,0,-6);
07715         m.checkCoherency();
07716         self.assertRaises(InterpKernelException,m.checkCoherency1);
07717         m.getNodalConnectivity().setIJ(8,0,9);#9>=NbOfNodes
07718         m.checkCoherency();
07719         self.assertRaises(InterpKernelException,m.checkCoherency1);
07720         m.getNodalConnectivity().setIJ(8,0,8);#OK
07721         m.checkCoherency();
07722         m.checkCoherency1();
07723         elts=[1,5]
07724         m.convertToPolyTypes(elts);
07725         m.checkCoherency();
07726         m.checkCoherency1();
07727         m.getNodalConnectivity().setIJ(2,0,9);#9>=NbOfNodes
07728         m.checkCoherency();
07729         self.assertRaises(InterpKernelException,m.checkCoherency1);
07730         m.getNodalConnectivity().setIJ(2,0,-3);
07731         m.checkCoherency();
07732         self.assertRaises(InterpKernelException,m.checkCoherency1);
07733         m.getNodalConnectivity().setIJ(2,0,-1);
07734         m.checkCoherency();
07735         self.assertRaises(InterpKernelException,m.checkCoherency1);#Throw because cell#0 is not a polyhedron
07736         m.getNodalConnectivity().setIJ(2,0,4);
07737         m.checkCoherency();
07738         m.checkCoherency1();
07739         m.getNodalConnectivity().setIJ(7,0,-1);
07740         m.checkCoherency();
07741         m.checkCoherency1();#OK because we are in polyhedron connec
07742         m.getNodalConnectivity().setIJ(36,0,14);
07743         m.checkCoherency();
07744         self.assertRaises(InterpKernelException,m.checkCoherency1);#Throw beacause now cell 5 is a TETRA4 (14) so mimatch of number index and static type.
07745         pass
07746 
07747     def testUnPolyze2(self):
07748         m=MEDCouplingUMesh.New("jjj",3);
07749         coo=DataArrayDouble.New();
07750         coo.alloc(4,3);
07751         coo.rearrange(1);
07752         coo.iota(0);
07753         coo.rearrange(3);
07754         m.setCoords(coo);
07755         m.allocateCells(2);
07756         m.insertNextCell(NORM_TETRA4,4,[0,1,2,3]);
07757         m.insertNextCell(NORM_TETRA4,4,[0,1,2,3]);
07758         m.finishInsertingCells();
07759         m2=MEDCouplingUMesh.MergeUMeshesOnSameCoords(4*[m]);
07760         m2.convertToPolyTypes([2]);
07761         m2.unPolyze();
07762         self.assertEqual(NORM_TETRA4,m2.getTypeOfCell(2));
07763         self.assertEqual(40,m2.getMeshLength());
07764         temp2=m2.getNodeIdsOfCell(2);
07765         self.assertEqual(temp2,[0,1,2,3]);
07766         m2.checkCoherency1();
07767         m3=m2.deepCpy();
07768         m2.unPolyze();
07769         self.assertTrue(m3.isEqual(m2,1e-12));
07770         pass
07771 
07772     def testDACpyFrom1(self):
07773         d=DataArrayDouble.New();
07774         d.alloc(12,1);
07775         d.iota(14.);
07776         d.rearrange(3);
07777         d.setName("Toto");
07778         d.setInfoOnComponent(0,"X [m]");
07779         d.setInfoOnComponent(1,"Y [m]");
07780         d.setInfoOnComponent(2,"Z [m]");
07781         #
07782         d1=DataArrayDouble.New();
07783         self.assertTrue(not d.isEqual(d1,1e-12));
07784         d1.cpyFrom(d);
07785         self.assertTrue(d.isEqual(d1,1e-12));
07786         d1.cpyFrom(d);
07787         self.assertTrue(d.isEqual(d1,1e-12));
07788         d1.rearrange(2);
07789         self.assertTrue(not d.isEqual(d1,1e-12));
07790         d1.cpyFrom(d);
07791         self.assertTrue(d.isEqual(d1,1e-12));
07792         #
07793         d2=d.convertToIntArr();
07794         d4=DataArrayInt.New();
07795         self.assertTrue(not d2.isEqual(d4));
07796         d4.cpyFrom(d2);
07797         self.assertTrue(d2.isEqual(d4));
07798         d4.cpyFrom(d2);
07799         self.assertTrue(d2.isEqual(d4));
07800         d4.rearrange(2);
07801         self.assertTrue(not d2.isEqual(d4));
07802         d4.cpyFrom(d2);
07803         self.assertTrue(d2.isEqual(d4));
07804         pass
07805 
07806     def testDAITransformWithIndArr1(self):
07807         tab1=[17,18,22,19]
07808         tab2=[0,1,1,3,3,0,1,3,2,2,3,0]
07809         expected=[17,18,18,19,19,17,18,19,22,22,19,17]
07810         d=DataArrayInt.New();
07811         d.setValues(tab1,4,1);
07812         d1=DataArrayInt.New();
07813         d1.setValues(tab2,12,1);
07814         d2=d1[:]
07815         #
07816         d1.transformWithIndArr(d);
07817         self.assertEqual(12,d1.getNumberOfTuples());
07818         self.assertEqual(1,d1.getNumberOfComponents());
07819         for i in xrange(12):
07820             self.assertEqual(expected[i],d1.getIJ(i,0));
07821             pass
07822         #
07823         d1=d2
07824         d1.transformWithIndArr(tab1)
07825         self.assertEqual(12,d1.getNumberOfTuples());
07826         self.assertEqual(1,d1.getNumberOfComponents());
07827         for i in xrange(12):
07828             self.assertEqual(expected[i],d1.getIJ(i,0));
07829             pass
07830         pass
07831 
07832     def testDAIBuildPermArrPerLevel1(self):
07833         arr=[2,0,1,1,0,1,2,0,1,1,0,0]
07834         expected1=[10,0,5,6,1,7,11,2,8,9,3,4]
07835         da=DataArrayInt.New();
07836         da.setValues(arr,12,1);
07837         da2=da.buildPermArrPerLevel();
07838         self.assertEqual(12,da2.getNumberOfTuples());
07839         self.assertEqual(1,da2.getNumberOfComponents());
07840         for i in xrange(12):
07841             self.assertEqual(expected1[i],da2.getIJ(i,0));
07842             pass
07843         pass
07844 
07845     def testDAIOperations1(self):
07846         arr1=[-1,-2,4,7,3,2,6,6,4,3,0,1]
07847         da=DataArrayInt.New();
07848         da.setValues(arr1,4,3);
07849         da1=DataArrayInt.New();
07850         da1.alloc(12,1);
07851         da1.iota(2);
07852         self.assertRaises(InterpKernelException,DataArrayInt.Add,da,da1);#not same number of tuples/Components
07853         da1.rearrange(3);
07854         da2=DataArrayInt.Add(da,da1);
07855         self.assertEqual(4,da2.getNumberOfTuples());
07856         self.assertEqual(3,da2.getNumberOfComponents());
07857         expected1=[1,1,8,12,9,9,14,15,14,14,12,14]
07858         for i in xrange(12):
07859             self.assertEqual(expected1[i],da2.getIJ(0,i));
07860             pass
07861         da1.substractEqual(da);
07862         expected2=[3,5,0,-2,3,5,2,3,6,8,12,12]
07863         for i in xrange(12):
07864             self.assertEqual(expected2[i],da1.getIJ(0,i));
07865             pass
07866         da1.rearrange(1); da1.iota(2); da1.rearrange(3);
07867         da1.addEqual(da);
07868         for i in xrange(12):
07869             self.assertEqual(expected1[i],da1.getIJ(0,i));
07870             pass
07871         da1.rearrange(1); da1.iota(2); da1.rearrange(3);
07872         da2=DataArrayInt.Multiply(da,da1);
07873         self.assertEqual(4,da2.getNumberOfTuples());
07874         self.assertEqual(3,da2.getNumberOfComponents());
07875         expected3=[-2,-6,16,35,18,14,48,54,40,33,0,13]
07876         for i in xrange(12):
07877             self.assertEqual(expected3[i],da2.getIJ(0,i));
07878             pass
07879         da.divideEqual(da1);
07880         self.assertEqual(4,da.getNumberOfTuples());
07881         self.assertEqual(3,da.getNumberOfComponents());
07882         expected4=[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]
07883         for i in xrange(12):
07884             self.assertEqual(expected4[i],da.getIJ(0,i));
07885             pass
07886         da.setValues(arr1,4,3);
07887         da1.multiplyEqual(da);
07888         self.assertEqual(4,da1.getNumberOfTuples());
07889         self.assertEqual(3,da1.getNumberOfComponents());
07890         for i in xrange(12):
07891             self.assertEqual(expected3[i],da1.getIJ(0,i));
07892             pass
07893         da1.rearrange(1); da1.iota(2); da1.rearrange(3);
07894         da2=DataArrayInt.Divide(da,da1);
07895         self.assertEqual(4,da2.getNumberOfTuples());
07896         self.assertEqual(3,da2.getNumberOfComponents());
07897         for i in xrange(12):
07898             self.assertEqual(expected4[i],da2.getIJ(0,i));
07899             pass
07900         da1.applyInv(321);
07901         self.assertEqual(4,da1.getNumberOfTuples());
07902         self.assertEqual(3,da1.getNumberOfComponents());
07903         expected5=[160,107,80,64,53,45,40,35,32,29,26,24]
07904         for i in xrange(12):
07905             self.assertEqual(expected5[i],da1.getIJ(0,i));
07906             pass
07907         da1.applyDivideBy(2);
07908         self.assertEqual(4,da1.getNumberOfTuples());
07909         self.assertEqual(3,da1.getNumberOfComponents());
07910         expected6=[80,53,40,32,26,22,20,17,16,14,13,12]
07911         for i in xrange(12):
07912             self.assertEqual(expected6[i],da1.getIJ(0,i));
07913             pass
07914         expected7=[3,4,5,4,5,1,6,3,2,0,6,5]
07915         da1.applyModulus(7);
07916         for i in xrange(12):
07917             self.assertEqual(expected7[i],da1.getIJ(0,i));
07918             pass
07919         da1.applyLin(1,1);
07920         expected8=[3,3,3,3,3,1,3,3,0,0,3,3]
07921         da1.applyRModulus(3);
07922         for i in xrange(12):
07923             self.assertEqual(expected8[i],da1.getIJ(0,i));
07924             pass
07925         pass
07926 
07927     def testEmulateMEDMEMBDC1(self):
07928         m,m1=MEDCouplingDataForTest.buildPointe_1();
07929         m2,da1,da2,da3,da4,da5,da0=m.emulateMEDMEMBDC(m1)
07930         expected0=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,36,37,32,33,34,35,38,39,40,41,42,43,44,45,46]
07931         expected1=[1,32,29,23,41,36]
07932         self.assertEqual(47,da0.getNumberOfTuples());
07933         self.assertEqual(1,da0.getNumberOfComponents());
07934         for i in xrange(47):
07935             self.assertEqual(expected0[i],da0.getIJ(0,i));
07936             pass
07937         self.assertEqual(6,da5.getNumberOfTuples());
07938         self.assertEqual(1,da5.getNumberOfComponents());
07939         for i in xrange(6):
07940             self.assertEqual(expected1[i],da5.getIJ(0,i));
07941             pass
07942         expected2=[0,1,2,3,4,0,5,6,7,4,8,9,1,7,10,11,12,13,14,5,15,16,17,8,18,19,20,10,21,22,23,2,13,24,25,21,16,26,27,12,19,28,29,15,22,30,31,18,36,26,28,30,24,37,32,33,34,35,38,36,39,40,41,42,37,38,43,44,45,46]
07943         self.assertEqual(70,da1.getNumberOfTuples());
07944         self.assertEqual(1,da1.getNumberOfComponents());
07945         for i in xrange(70):
07946             self.assertEqual(expected2[i],da1.getIJ(0,i));
07947             pass
07948         expected3=[0,4,8,12,16,20,24,28,32,36,40,44,48,53,58,64,70]
07949         self.assertEqual(17,da2.getNumberOfTuples());
07950         self.assertEqual(1,da2.getNumberOfComponents());
07951         for i in xrange(17):
07952             self.assertEqual(expected3[i],da2.getIJ(0,i));
07953             pass
07954         expected4=[0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,53,54,55,56,58,60,62,63,64,65,66,67,68,69,70]
07955         #expected4=[0,2,4,6,7,9,11,12,14,16,17,19,20,22,24,25,27,29,30,32,34,35,37,39,40,42,43,45,46,48,49,51,52,54,56,57,58,59,60,62,63,64,65,66,67,68,69,70];
07956         self.assertEqual(48,da4.getNumberOfTuples());
07957         self.assertEqual(1,da4.getNumberOfComponents());
07958         for i in xrange(48):
07959             self.assertEqual(expected4[i],da4.getIJ(0,i));
07960             pass
07961         expected5=[0,1,0,3,0,7,0,1,2,1,4,1,2,3,2,5,2,3,6,3,4,9,4,8,4,5,10,5,9,5,6,11,6,10,6,7,8,7,11,7,8,12,8,9,12,9,10,12,10,11,12,11,13,13,13,13,12,14,13,15,14,15,14,14,14,14,15,15,15,15]
07962         self.assertEqual(70,da3.getNumberOfTuples());
07963         self.assertEqual(1,da3.getNumberOfComponents());
07964         for i in xrange(70):
07965             self.assertEqual(expected5[i],da3.getIJ(0,i));
07966             pass
07967         pass
07968 
07969     def testGetLevArrPerCellTypes1(self):
07970         m,m1=MEDCouplingDataForTest.buildPointe_1();
07971         m1,d0,d1,d2,d3=m.buildDescendingConnectivity();
07972         order=[NORM_TRI3,NORM_QUAD4];
07973         da0,da1=m1.getLevArrPerCellTypes(order);
07974         expected0=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1]
07975         expected1=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,36,37,32,33,34,35,38,39,40,41,42,43,44,45,46]
07976         self.assertEqual(47,da0.getNumberOfTuples());
07977         self.assertEqual(1,da0.getNumberOfComponents());
07978         for i in xrange(47):
07979             self.assertEqual(expected0[i],da0.getIJ(0,i));
07980             pass
07981         self.assertEqual(2,da1.getNumberOfTuples());
07982         self.assertEqual(1,da1.getNumberOfComponents());
07983         self.assertEqual(36,da1.getIJ(0,0));#36 TRI3
07984         self.assertEqual(11,da1.getIJ(1,0));#11 QUAD4
07985         #
07986         da2=da0.buildPermArrPerLevel();
07987         #
07988         self.assertEqual(47,da2.getNumberOfTuples());
07989         self.assertEqual(1,da2.getNumberOfComponents());
07990         for i in xrange(47):
07991             self.assertEqual(expected1[i],da2.getIJ(0,i));
07992             pass
07993         pass
07994 
07995     def testSortCellsInMEDFileFrmt1(self):
07996         m,m1=MEDCouplingDataForTest.buildPointe_1();
07997         m2=m.deepCpy()
07998         da=DataArrayInt.New()
07999         da.setValues([0,1,2,14,3,12,4,5,15,6,7,8,9,10,11,13],16,1)
08000         daa=da.invertArrayN2O2O2N(16)
08001         m.renumberCells(daa,False)
08002         da2=m.sortCellsInMEDFileFrmt()
08003         self.assertEqual(da2.getValues(),[0,1,2,14,3,12,4,5,15,6,7,8,9,10,11,13])
08004         self.assertTrue(m.isEqual(m2,1e-12))
08005         self.assertTrue(da.isEqual(da2))
08006         pass
08007 
08008     def testBuildPartAndReduceNodes1(self):
08009         m=MEDCouplingDataForTest.build2DTargetMesh_1();
08010         arr=[1,0]
08011         m2,da=m.buildPartAndReduceNodes(arr);
08012         self.assertEqual(5,m2.getNumberOfNodes());
08013         self.assertEqual(2,m2.getNumberOfCells());
08014         f=m2.getMeasureField(True);
08015         self.assertAlmostEqual(0.125,f.getArray().getIJ(0,0),12);
08016         self.assertAlmostEqual(0.25,f.getArray().getIJ(1,0),12);
08017         #
08018         arr2=DataArrayInt.New()
08019         arr2.setValues(arr,2,1)
08020         m2,da=m.buildPartAndReduceNodes(arr2);
08021         self.assertEqual(5,m2.getNumberOfNodes());
08022         self.assertEqual(2,m2.getNumberOfCells());
08023         f=m2.getMeasureField(True);
08024         self.assertAlmostEqual(0.125,f.getArray().getIJ(0,0),12);
08025         self.assertAlmostEqual(0.25,f.getArray().getIJ(1,0),12);
08026         pass
08027 
08028     def testDAITransformWithIndArrR1(self):
08029         tab1=[2,4,5,3,6,7]
08030         tab2=[-1,-1,0,1,2,3,4,5,-1,-1,-1,-1]
08031         expected=[0,3,1,2,4,5]
08032         d=DataArrayInt.New();
08033         d.setValues(tab1,6,1);
08034         d1=DataArrayInt.New();
08035         d1.setValues(tab2,12,1);
08036         d2=d1[:]
08037         #
08038         d3=d.transformWithIndArrR(d1);
08039         self.assertEqual(6,d3.getNumberOfTuples());
08040         self.assertEqual(1,d3.getNumberOfComponents());
08041         for i in xrange(6):
08042             self.assertEqual(expected[i],d3.getIJ(i,0));
08043             pass
08044         #
08045         d1=d2
08046         d3=d.transformWithIndArrR(tab2)
08047         self.assertEqual(6,d3.getNumberOfTuples());
08048         self.assertEqual(1,d3.getNumberOfComponents());
08049         for i in xrange(6):
08050             self.assertEqual(expected[i],d3.getIJ(i,0));
08051             pass
08052         pass
08053 
08054     def testDAISplitByValueRange1(self):
08055         val1=[6,5,0,3,2,7,8,1,4]
08056         val2=[0,4,9]
08057         d=DataArrayInt.New();
08058         d.setValues(val1,9,1);
08059         e,f,g=d.splitByValueRange(val2);
08060         self.assertEqual(9,e.getNumberOfTuples());
08061         self.assertEqual(1,e.getNumberOfComponents());
08062         self.assertEqual(9,f.getNumberOfTuples());
08063         self.assertEqual(1,f.getNumberOfComponents());
08064         self.assertEqual(2,g.getNumberOfTuples());
08065         self.assertEqual(1,g.getNumberOfComponents());
08066         #
08067         expected1=[1,1,0,0,0,1,1,0,1]
08068         expected2=[2,1,0,3,2,3,4,1,0]
08069         for i in xrange(9):
08070             self.assertEqual(expected1[i],e.getIJ(i,0));
08071             self.assertEqual(expected2[i],f.getIJ(i,0));
08072             pass
08073         self.assertEqual(0,g.getIJ(0,0));
08074         self.assertEqual(1,g.getIJ(1,0));
08075         #
08076         d.setIJ(6,0,9);
08077         self.assertRaises(InterpKernelException,d.splitByValueRange,val2);
08078         pass
08079 
08080     def testUMeshSplitProfilePerType1(self):
08081         val0=[2,0,1,3,4]
08082         m=MEDCouplingDataForTest.build2DTargetMesh_1();
08083         m.renumberCells(val0,False);
08084         #
08085         val1=[0,2,3]
08086         d=DataArrayInt.New();
08087         d.setValues(val1,3,1);
08088         d.setName("sup")
08089         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
08090         self.assertEqual(6,len(code));
08091         self.assertEqual(2,len(idsInPflPerType));
08092         expected1=[3,1,0, 4,2,1]
08093         for i in xrange(6):
08094             self.assertEqual(expected1[i],code[i]);
08095             pass
08096         self.assertEqual(2,len(idsInPflPerType));
08097         self.assertEqual(1,idsInPflPerType[0].getNumberOfTuples());
08098         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
08099         self.assertEqual(2,idsInPflPerType[1].getNumberOfTuples());
08100         self.assertEqual(1,idsInPflPerType[1].getIJ(0,0));
08101         self.assertEqual(2,idsInPflPerType[1].getIJ(1,0));
08102         #
08103         self.assertEqual(2,len(pfls));
08104         self.assertEqual("sup",pfls[0].getName())
08105         self.assertEqual(1,pfls[0].getNumberOfTuples());
08106         self.assertEqual(0,pfls[0].getIJ(0,0));
08107         self.assertEqual("sup",pfls[1].getName())
08108         self.assertEqual(2,pfls[1].getNumberOfTuples());
08109         self.assertEqual(0,pfls[1].getIJ(0,0));
08110         self.assertEqual(1,pfls[1].getIJ(1,0));
08111         #
08112         val2=[0,2,3,4]
08113         d=DataArrayInt.New();
08114         d.setValues(val2,4,1);
08115         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
08116         self.assertEqual(6,len(code));
08117         self.assertEqual(2,len(idsInPflPerType));
08118         expected2=[3,1,0, 4,3,-1]
08119         for i in xrange(6):
08120             self.assertEqual(expected2[i],code[i]);
08121             pass
08122         self.assertEqual(2,len(idsInPflPerType));
08123         self.assertEqual(1,idsInPflPerType[0].getNumberOfTuples());
08124         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
08125         self.assertEqual(3,idsInPflPerType[1].getNumberOfTuples());
08126         self.assertEqual(1,idsInPflPerType[1].getIJ(0,0));
08127         self.assertEqual(2,idsInPflPerType[1].getIJ(1,0));
08128         self.assertEqual(3,idsInPflPerType[1].getIJ(2,0));
08129         #
08130         self.assertEqual(1,len(pfls));
08131         self.assertEqual(1,pfls[0].getNumberOfTuples());
08132         self.assertEqual(0,pfls[0].getIJ(0,0));
08133         #
08134         val3=[1,0,2]
08135         d=DataArrayInt.New();
08136         d.setValues(val3,3,1);
08137         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
08138         self.assertEqual(6,len(code));
08139         self.assertEqual(2,len(idsInPflPerType));
08140         expected3=[3,2,0, 4,1,1]
08141         for i in xrange(6):
08142             self.assertEqual(expected3[i],code[i]);
08143             pass
08144         self.assertEqual(2,len(idsInPflPerType));
08145         self.assertEqual(2,idsInPflPerType[0].getNumberOfTuples());
08146         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
08147         self.assertEqual(1,idsInPflPerType[0].getIJ(1,0));
08148         self.assertEqual(1,idsInPflPerType[1].getNumberOfTuples());
08149         self.assertEqual(2,idsInPflPerType[1].getIJ(0,0));
08150         #
08151         self.assertEqual(2,len(pfls));
08152         self.assertEqual(2,pfls[0].getNumberOfTuples());
08153         self.assertEqual(1,pfls[0].getIJ(0,0));
08154         self.assertEqual(0,pfls[0].getIJ(1,0));
08155         self.assertEqual(0,pfls[1].getIJ(0,0));
08156         #
08157         val4=[3,4]
08158         d=DataArrayInt.New();
08159         d.setValues(val4,2,1);
08160         code,idsInPflPerType,pfls=m.splitProfilePerType(d);
08161         self.assertEqual(3,len(code));
08162         self.assertEqual(1,len(idsInPflPerType));
08163         expected4=[4,2,0]
08164         for i in xrange(3):
08165             self.assertEqual(expected4[i],code[i]);
08166             pass
08167         self.assertEqual(1,len(idsInPflPerType));
08168         self.assertEqual(2,idsInPflPerType[0].getNumberOfTuples());
08169         self.assertEqual(0,idsInPflPerType[0].getIJ(0,0));
08170         self.assertEqual(1,idsInPflPerType[0].getIJ(1,0));
08171         #
08172         self.assertEqual(1,len(pfls));
08173         self.assertEqual(2,pfls[0].getNumberOfTuples());
08174         self.assertEqual(1,pfls[0].getIJ(0,0));
08175         self.assertEqual(2,pfls[0].getIJ(1,0));
08176         pass
08177 
08178     def testDAIBuildExplicitArrByRanges1(self):
08179         d=DataArrayInt.New();
08180         vals1=[0,2,3]
08181         d.setValues(vals1,3,1);
08182         e=DataArrayInt.New();
08183         vals2=[0,3,6,10,14,20]
08184         e.setValues(vals2,6,1);
08185         #
08186         f=d.buildExplicitArrByRanges(e);
08187         self.assertEqual(11,f.getNumberOfTuples());
08188         self.assertEqual(1,f.getNumberOfComponents());
08189         expected1=[0,1,2,6,7,8,9,10,11,12,13]
08190         for i in xrange(11):
08191             self.assertEqual(expected1[i],f.getIJ(i,0));
08192             pass
08193         pass
08194 
08195     def testDAIComputeOffsets2(self):
08196         d=DataArrayInt.New();
08197         vals1=[3,5,1,2,0,8]
08198         expected1=[0,3,8,9,11,11,19]
08199         d.setValues(vals1,6,1);
08200         d.computeOffsets2();
08201         self.assertEqual(7,d.getNumberOfTuples());
08202         self.assertEqual(1,d.getNumberOfComponents());
08203         for i in xrange(7):
08204             self.assertEqual(expected1[i],d.getIJ(0,i));
08205             pass
08206         pass
08207 
08208     def testMergeField3(self):
08209         m=MEDCouplingDataForTest.build2DTargetMesh_1();
08210         m.getCoords().setInfoOnComponent(0,"x [m]");
08211         m.getCoords().setInfoOnComponent(1,"z [km]");
08212         m.setName("m");
08213         m.setDescription("desc");
08214         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
08215         f1.setName("f1");
08216         f1.setMesh(m);
08217         arr=DataArrayDouble.New();
08218         arr.alloc(5,2);
08219         arr.setInfoOnComponent(0,"X [m]");
08220         arr.setInfoOnComponent(1,"YY [mm]");
08221         arr.fillWithValue(2.);
08222         f1.setArray(arr);
08223         #
08224         f2=MEDCouplingFieldDouble.MergeFields([f1]);
08225         self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
08226         #
08227         pass
08228     
08229     def testGetDistributionOfTypes1(self):
08230         m=MEDCouplingDataForTest.build2DTargetMesh_1();
08231         tab1=[2,0,1,3,4]
08232         self.assertRaises(InterpKernelException,m.getDistributionOfTypes);
08233         m.renumberCells(tab1,False);
08234         code=m.getDistributionOfTypes();
08235         self.assertEqual(6,len(code));
08236         self.assertEqual(3,code[0]);
08237         self.assertEqual(2,code[1]);
08238         self.assertEqual(0,code[2]);
08239         self.assertEqual(4,code[3]);
08240         self.assertEqual(3,code[4]);
08241         self.assertEqual(0,code[5]);
08242         pass
08243 
08244     def testNorm2_1(self):
08245         m=MEDCouplingDataForTest.build2DTargetMesh_1();
08246         f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
08247         f.setMesh(m);
08248         #
08249         d=DataArrayDouble.New();
08250         tab=[1.2,1.3,2.2,2.3,3.2,3.3,4.2,4.3,5.2,5.3]
08251         d.setValues(tab,5,2);
08252         f.setArray(d);
08253         f.checkCoherency();
08254         #
08255         self.assertAlmostEqual(11.209371079592289,f.norm2(),14);
08256         #
08257         pass
08258 
08259     def testNormMax1(self):
08260         m=MEDCouplingDataForTest.build2DTargetMesh_1();
08261         f=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
08262         f.setMesh(m);
08263         #
08264         d=DataArrayDouble.New();
08265         tab=[2.3,-1.2,6.3,-7.8,2.9,7.7,2.1,0.,3.6,-7.6]
08266         d.setValues(tab,5,2);
08267         f.setArray(d);
08268         f.checkCoherency();
08269         #
08270         self.assertAlmostEqual(7.8,f.normMax(),14);
08271         #
08272         pass
08273 
08274     def testFindAndCorrectBadOriented3DExtrudedCells1(self):
08275         coords=[0.0011180339887498999, -0.0011755705045849499, 0.0, -0.0012331070204200001, -0.0011755705045849499, 0.0, -0.00067557050458494599, -0.00145964954842536, 0.0, -0.00050000000000000001, -0.00086602540378443902, 0.0, 0.00140211303259031, -0.00061803398874989504, 0.0, 0.00086602540378443902, -0.00050000000000000001, 0.0, 0.001, 0.0, 0.0, 0.00034561537182258202, 0.000269164072574575, 0.0, 0.0, 0.001, 0.0, -0.00050000000000000001, 0.00086602540378443902, 0.0, -0.000269164072574575, 0.00034561537182258202, 0.0, -0.001, 0.0, 0.0, -0.00086602540378443902, -0.00050000000000000001, 0.0, -0.00034561537182258202, -0.000269164072574575, 0.0, 0.0, -0.001, 0.0, 0.00050000000000000001, -0.00086602540378443902, 0.0, 0.000269164072574575, -0.00034561537182258202, 0.0, 0.0015, -6.01853107621011e-36, 0.0, 0.00056049747291484397, -0.00145964954842536, 0.0, 0.0011180339887498999, -0.0011755705045849499, 0.00050000000000000001, -0.0012331070204200001, -0.0011755705045849499, 0.00050000000000000001, -0.00067557050458494599, -0.00145964954842536, 0.00050000000000000001, -0.00050000000000000001, -0.00086602540378443902, 0.00050000000000000001, 0.00140211303259031, -0.00061803398874989504, 0.00050000000000000001, 0.00086602540378443902, -0.00050000000000000001, 0.00050000000000000001, 0.001, 0.0, 0.00050000000000000001, 0.00034561537182258202, 0.000269164072574575, 0.00050000000000000001, 0.0, 0.001, 0.00050000000000000001, -0.00050000000000000001, 0.00086602540378443902, 0.00050000000000000001, -0.000269164072574575, 0.00034561537182258202, 0.00050000000000000001, -0.001, 0.0, 0.00050000000000000001, -0.00086602540378443902, -0.00050000000000000001, 0.00050000000000000001, -0.00034561537182258202, -0.000269164072574575, 0.00050000000000000001, 0.0, -0.001, 0.00050000000000000001, 0.00050000000000000001, -0.00086602540378443902, 0.00050000000000000001, 0.000269164072574575, -0.00034561537182258202, 0.00050000000000000001, 0.0015, -6.01853107621011e-36, 0.00050000000000000001, 0.00056049747291484397, -0.00145964954842536, 0.00050000000000000001];
08276         conn=[2, 1, 3, 21, 20, 22, 4, 0, 5, 23, 19, 24, 8, 9, 10, 27, 28, 29, 11, 12, 13, 30, 31, 32, 0, 18, 15, 5, 19, 37, 34, 24, 6, 17, 4, 5, 25, 36, 23, 24, 3, 14, 16, 13, 22, 33, 35, 32, 13, 16, 7, 10, 32, 35, 26, 29]
08277         connExp=[16, 2, 1, 3, 21, 20, 22, 16, 4, 0, 5, 23, 19, 24, 16, 8, 10, 9, 27, 29, 28, 16, 11, 13, 12, 30, 32, 31, 18, 0, 18, 15, 5, 19, 37, 34, 24,18, 6, 17, 4, 5, 25, 36, 23, 24, 18, 3, 13, 16, 14, 22, 32, 35, 33, 18, 13, 10, 7, 16, 32, 29, 26, 35]
08278         invalidCells=[2,3,6,7]
08279         m=MEDCouplingUMesh.New("Example",3);
08280         coo=DataArrayDouble.New();
08281         coo.setValues(coords,38,3);
08282         m.setCoords(coo);
08283         m.allocateCells(8);
08284         m.insertNextCell(NORM_PENTA6,6,conn[0:6])
08285         m.insertNextCell(NORM_PENTA6,6,conn[6:12])
08286         m.insertNextCell(NORM_PENTA6,6,conn[12:18])
08287         m.insertNextCell(NORM_PENTA6,6,conn[18:24])
08288         m.insertNextCell(NORM_HEXA8,8,conn[24:32])
08289         m.insertNextCell(NORM_HEXA8,8,conn[32:40])
08290         m.insertNextCell(NORM_HEXA8,8,conn[40:48])
08291         m.insertNextCell(NORM_HEXA8,8,conn[48:56])
08292         m.finishInsertingCells();
08293         #
08294         v=m.findAndCorrectBadOriented3DExtrudedCells();
08295         self.assertEqual(4,len(v));
08296         self.assertEqual(v.getValues(),invalidCells);
08297         self.assertEqual(connExp,m.getNodalConnectivity().getValues());
08298         #
08299         pass
08300 
08301     def testConvertExtrudedPolyhedra1(self):
08302         conn=[1,2,3,4, 5,6,7,8,9,10,11,12, 13,14,15,16, 17,18,19,20,21,22, 23,24,25,26,27,28, 29,30,31,32,33,34,35,36,37,38, 39,40,41,42,43,44,45,46, 47,48,49,50,51,52,53,54,55,56,57,58, 59,60,61,62,63,64,65,66,67,68,69,70,71,72]
08303         m=MEDCouplingUMesh.New("Example",3);
08304         coo=DataArrayDouble.New();
08305         coo.alloc(73,3);
08306         coo.rearrange(1); coo.iota(0); coo.rearrange(3);
08307         m.setCoords(coo);
08308         m.allocateCells(9);
08309         m.insertNextCell(NORM_TETRA4,4,conn[0:4])
08310         m.insertNextCell(NORM_HEXA8,8,conn[4:12])
08311         m.insertNextCell(NORM_TETRA4,4,conn[12:16])
08312         m.insertNextCell(NORM_POLYHED,6,conn[16:22])
08313         m.insertNextCell(NORM_PENTA6,6,conn[22:28])
08314         m.insertNextCell(NORM_POLYHED,10,conn[28:38])
08315         m.insertNextCell(NORM_HEXA8,8,conn[38:46])
08316         m.insertNextCell(NORM_HEXGP12,12,conn[46:58])
08317         m.insertNextCell(NORM_POLYHED,14,conn[58:72])
08318         m.finishInsertingCells();
08319         #
08320         m.convertExtrudedPolyhedra();
08321         da=m.getNodalConnectivity();
08322         dai=m.getNodalConnectivityIndex();
08323         self.assertEqual(10,dai.getNbOfElems());
08324         self.assertEqual(159,da.getNbOfElems());
08325         #
08326         expected1=[14, 1, 2, 3, 4,
08327                    18, 5, 6, 7, 8, 9, 10, 11, 12,
08328                    14, 13, 14, 15, 16,
08329                    31, 17, 18, 19, -1, 20, 22, 21, -1, 17, 18, 21, 20, -1, 18, 19, 22, 21, -1, 19, 17, 20, 22,
08330                    16, 23, 24, 25, 26, 27, 28,
08331                    31, 29, 30, 31, 32, 33, -1, 34, 38, 37, 36, 35, -1, 29, 30, 35, 34, -1, 30, 31, 36, 35, -1, 31, 32, 37, 36, -1, 32, 33, 38, 37, -1, 33, 29, 34, 38,
08332                    18, 39, 40, 41, 42, 43, 44, 45, 46,
08333                    22, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
08334                    31, 59, 60, 61, 62, 63, 64, 65, -1, 66, 72, 71, 70, 69, 68, 67, -1, 59, 60, 67, 66, -1, 60, 61, 68, 67, -1, 61, 62, 69, 68, -1, 62, 63, 70, 69, -1, 63, 64, 71, 70, -1, 64, 65, 72, 71, -1, 65, 59, 66, 72];
08335         expected2=[0,5,14,19,42,49,86,95,108,159]
08336         self.assertEqual(expected1,da.getValues());
08337         self.assertEqual(expected2,dai.getValues());
08338         m.checkCoherency2()
08339         pass
08340 
08341     def testNonRegressionCopyTinyStrings(self):
08342         m=MEDCouplingDataForTest.build2DTargetMesh_1()
08343         f1=m.getMeasureField(True)
08344         f1.getArray().setInfoOnComponent(0,"P [N/m^2]")
08345         bary=m.getBarycenterAndOwner()
08346         f2=f1.buildNewTimeReprFromThis(ONE_TIME,False)
08347         f2.setArray(bary)
08348         self.assertRaises(InterpKernelException,f2.copyTinyAttrFrom,f1)
08349         pass
08350 
08351     def testDaDSetPartOfValuesAdv1(self):
08352         tab1=[3.,4.,5., 13.,14.,15., 23.,24.,25., 33.,34.,35., 43.,44.,45., 53.,54.,55.]
08353         tab2=[6.,7.,8., 16.,17.,18., 26.,27.,28.]
08354         tab3=[4,1, 2,2, 3,0]
08355         a=DataArrayDouble.New();
08356         a.setValues(tab1,6,3);
08357         b=DataArrayDouble.New();
08358         b.setValues(tab2,3,3);
08359         c=DataArrayInt.New();
08360         c.setValues(tab3,3,2);
08361         #
08362         a.setPartOfValuesAdv(b,c);
08363         expected1=[3.,4.,5., 13.,14.,15., 26.,27.,28., 6.,7.,8., 16.,17.,18., 53.,54.,55.]
08364         self.assertEqual(expected1,a.getValues());
08365         pass
08366 
08367     def testUMeshBuildSetInstanceFromThis1(self):
08368         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
08369         m2=m.buildSetInstanceFromThis(3);
08370         self.assertTrue(m.isEqual(m2,1e-12));
08371         #
08372         m=MEDCouplingUMesh.New("toto",2);
08373         m2=m.buildSetInstanceFromThis(3);
08374         self.assertEqual(0,m2.getNumberOfNodes());
08375         self.assertEqual(0,m2.getNumberOfCells());
08376         pass
08377 
08378     def testUMeshMergeMeshesCVW1(self):
08379         m=MEDCouplingDataForTest.build3DSurfTargetMesh_1();
08380         m2=MEDCouplingUMesh.New("toto",2);
08381         m3=MEDCouplingUMesh.MergeUMeshes([m,m2]);
08382         m3.setName(m.getName());
08383         self.assertTrue(m.isEqual(m3,1e-12));
08384         pass
08385     
08386     def testChangeUnderlyingMeshWithCMesh1(self):
08387         mesh=MEDCouplingCMesh.New();
08388         coordsX=DataArrayDouble.New();
08389         arrX=[ -1., 1., 2., 4. ]
08390         coordsX.setValues(arrX,4,1);
08391         coordsY=DataArrayDouble.New();
08392         arrY=[ -2., 2., 4., 8. ]
08393         coordsY.setValues(arrY,4,1);
08394         coordsZ=DataArrayDouble.New();
08395         arrZ=[ -3., 3., 6., 12. ]
08396         coordsZ.setValues(arrZ,4,1);
08397         mesh.setCoords(coordsX,coordsY,coordsZ);
08398         f=mesh.getMeasureField(True)
08399         mesh2=mesh.deepCpy()
08400         for myId in [0,1,2,10,11,12,20,21,22]:
08401             f=mesh.getMeasureField(True)
08402             f.changeUnderlyingMesh(mesh2,myId,1e-12);
08403             pass
08404         mesh2.setName("uuuu")
08405         for myId in [1,2,10,11,12,20,21,22]:
08406             f=mesh.getMeasureField(True)
08407             f.changeUnderlyingMesh(mesh2,myId,1e-12);
08408             pass
08409         pass
08410 
08411     def testDADFindCommonTuples1(self):
08412         da=DataArrayDouble.New();
08413         # nbOftuples=1
08414         array1=[2.3,1.2,1.3,2.3,2.301,0.8]
08415         da.setValues(array1,6,1)
08416         c,cI=da.findCommonTuples(1e-2);
08417         expected1=[0,3,4]
08418         expected2=[0,3]
08419         self.assertEqual(3,c.getNbOfElems());
08420         self.assertEqual(2,cI.getNbOfElems());
08421         self.assertEqual(expected1,c.getValues())
08422         self.assertEqual(expected2,cI.getValues())
08423         c,cI=da.findCommonTuples(2e-1)
08424         expected3=[0,3,4,1,2]
08425         expected4=[0,3,5]
08426         self.assertEqual(5,c.getNbOfElems());
08427         self.assertEqual(3,cI.getNbOfElems());
08428         self.assertEqual(expected3,c.getValues())
08429         self.assertEqual(expected4,cI.getValues())
08430         # nbOftuples=2
08431         array2=[2.3,2.3,1.2,1.2,1.3,1.3,2.3,2.3,2.301,2.301,0.8,0.8]
08432         da.setValues(array2,6,2)
08433         c,cI=da.findCommonTuples(1e-2);
08434         self.assertEqual(3,c.getNbOfElems());
08435         self.assertEqual(2,cI.getNbOfElems());
08436         self.assertEqual(expected1,c.getValues())
08437         self.assertEqual(expected2,cI.getValues())
08438         c,cI=da.findCommonTuples(2e-1)
08439         self.assertEqual(5,c.getNbOfElems());
08440         self.assertEqual(3,cI.getNbOfElems());
08441         self.assertEqual(expected3,c.getValues())
08442         self.assertEqual(expected4,cI.getValues())
08443         # nbOftuples=3
08444         array3=[2.3,2.3,2.3,1.2,1.2,1.2,1.3,1.3,1.3,2.3,2.3,2.3,2.301,2.301,2.301,0.8,0.8,0.8]
08445         da.setValues(array3,6,3)
08446         c,cI=da.findCommonTuples(1e-2);
08447         self.assertEqual(3,c.getNbOfElems());
08448         self.assertEqual(2,cI.getNbOfElems());
08449         self.assertEqual(expected1,c.getValues())
08450         self.assertEqual(expected2,cI.getValues())
08451         c,cI=da.findCommonTuples(2e-1)
08452         self.assertEqual(5,c.getNbOfElems());
08453         self.assertEqual(3,cI.getNbOfElems());
08454         self.assertEqual(expected3,c.getValues())
08455         self.assertEqual(expected4,cI.getValues())
08456         # nbOftuples=1, no common groups
08457         array11=[2.3,1.2,1.3,2.4,2.5,0.8]
08458         da.setValues(array11,6,1)
08459         c,cI=da.findCommonTuples(1e-2);
08460         self.assertEqual(0,c.getNbOfElems());
08461         self.assertEqual(1,cI.getNbOfElems());
08462         self.assertEqual([0],cI.getValues())
08463         
08464         array12=[0.]*(6*4)
08465         da.setValues(array12,6,4) #bad NumberOfComponents
08466         self.assertRaises(InterpKernelException, da.findCommonTuples, 1e-2);
08467         pass
08468 
08469     def testDABack1(self):
08470         da=DataArrayDouble.New();
08471         array1=[2.3,1.2,1.3,2.3,2.301,0.8]
08472         da.setValues(array1,6,1);
08473         self.assertAlmostEqual(0.8,da.back(),14);
08474         da.rearrange(2);
08475         self.assertRaises(InterpKernelException,da.back);
08476         da.alloc(0,1);
08477         self.assertRaises(InterpKernelException,da.back);
08478         #
08479         da=DataArrayInt.New();
08480         array2=[4,7,8,2]
08481         da.setValues(array2,4,1);
08482         self.assertEqual(2,da.back());
08483         da.rearrange(2);
08484         self.assertRaises(InterpKernelException,da.back);
08485         da.alloc(0,1);
08486         self.assertRaises(InterpKernelException,da.back);
08487         pass
08488 
08489     def testDADGetDifferentValues1(self):
08490         da=DataArrayDouble.New();
08491         array1=[2.3,1.2,1.3,2.3,2.301,0.8]
08492         da.setValues(array1,6,1)
08493         #
08494         expected1=[2.301,1.2,1.3,0.8]
08495         dv=da.getDifferentValues(1e-2);
08496         self.assertEqual(4,dv.getNbOfElems());
08497         for i in xrange(4):
08498             self.assertAlmostEqual(expected1[i],dv.getIJ(i,0),14);
08499             pass
08500         #
08501         dv=da.getDifferentValues(2e-1);
08502         expected2=[2.301,1.3,0.8]
08503         self.assertEqual(3,dv.getNbOfElems());
08504         for i in xrange(3):
08505             self.assertAlmostEqual(expected2[i],dv.getIJ(i,0),14);
08506             pass
08507         pass
08508 
08509     def testDAIBuildOld2NewArrayFromSurjectiveFormat2(self):
08510         arr=[0,3, 5,7,9]
08511         arrI=[0,2,5]
08512         a=DataArrayInt.New();
08513         a.setValues(arr,5,1);
08514         b=DataArrayInt.New();
08515         b.setValues(arrI,3,1);
08516         ret,newNbTuple=DataArrayInt.BuildOld2NewArrayFromSurjectiveFormat2(10,a,b);
08517         expected=[0,1,2,0,3,4,5,4,6,4]
08518         self.assertEqual(10,ret.getNbOfElems());
08519         self.assertEqual(7,newNbTuple);
08520         self.assertEqual(1,ret.getNumberOfComponents());
08521         self.assertEqual(expected,ret.getValues());
08522         pass
08523 
08524     def testDADIReverse1(self):
08525         arr=[0,3,5,7,9,2]
08526         a=DataArrayInt.New();
08527         a.setValues(arr,6,1);
08528         self.assertEqual(2,a.back());
08529         a.reverse();
08530         for i in xrange(6):
08531             self.assertEqual(arr[5-i],a.getIJ(i,0));
08532             pass
08533         a.setValues(arr[:-1],5,1);
08534         a.reverse();
08535         for i in xrange(5):
08536             self.assertEqual(arr[4-i],a.getIJ(i,0));
08537             pass
08538         #
08539         arr2=[0.,3.,5.,7.,9.,2.]
08540         b=DataArrayDouble.New();
08541         b.setValues(arr2,6,1);
08542         b.reverse();
08543         for i in xrange(6):
08544             self.assertAlmostEqual(arr2[5-i],b.getIJ(i,0),14);
08545             pass
08546         b.setValues(arr2,5,1);
08547         self.assertAlmostEqual(9.,b.back(),14)
08548         b.reverse();
08549         for i in xrange(5):
08550             self.assertAlmostEqual(arr2[4-i],b.getIJ(i,0),14);
08551             pass
08552         pass
08553 
08554     def testGetNodeIdsInUse1(self):
08555         m0=MEDCouplingDataForTest.build2DTargetMesh_1();
08556         CellIds=[1,2]
08557         m1=m0.buildPartOfMySelf(CellIds,True);
08558         arr,newNbOfNodes=m1.getNodeIdsInUse();
08559         expected=[-1,0,1,-1,2,3,-1,-1,-1]
08560         self.assertEqual(4,newNbOfNodes);
08561         self.assertEqual(9,arr.getNbOfElems());
08562         self.assertEqual(expected,arr.getValues());
08563         arr2=arr.invertArrayO2N2N2O(newNbOfNodes);
08564         self.assertEqual(4,arr2.getNbOfElems());
08565         expected2=[1,2,4,5]
08566         self.assertEqual(expected2,arr2.getValues());
08567         pass
08568 
08569     def testBuildDescendingConnec2(self):
08570         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
08571         #
08572         mesh2,desc,descIndx,revDesc,revDescIndx=mesh.buildDescendingConnectivity2();
08573         mesh2.checkCoherency();
08574         self.assertEqual(1,mesh2.getMeshDimension());
08575         self.assertEqual(13,mesh2.getNumberOfCells());
08576         self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples());
08577         self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples());
08578         self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples());
08579         self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples());
08580         expected1=[1,2,3,4,-3,5,6, 7,8,-5,9,10,-2,11, 12,13,-7,-10]
08581         self.assertEqual(expected1,desc.getValues());
08582         expected2=[0,4,7,10,14,18]
08583         self.assertEqual(expected2,descIndx.getValues());
08584         expected3=[0,1,3,5,6,8,9,11,12,13,15,16,17,18]
08585         self.assertEqual(expected3,revDescIndx.getValues());
08586         expected4=[0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4]
08587         self.assertEqual(expected4,revDesc.getValues());
08588         conn=mesh2.getNodalConnectivity();
08589         connIndex=mesh2.getNodalConnectivityIndex();
08590         expected5=[0,3,6,9,12,15,18,21,24,27,30,33,36,39]
08591         self.assertEqual(expected5,connIndex.getValues());
08592         expected6=[1, 0, 3, 1, 3, 4, 1, 4, 1, 1, 1, 0, 1, 4, 2, 1, 2, 1, 1, 4, 5, 1, 5, 2, 1, 6, 7, 1, 7, 4, 1, 3, 6, 1, 7, 8, 1, 8, 5]
08593         self.assertEqual(expected6,conn.getValues());
08594         pass
08595 
08596     def testIntersect2DMeshesTmp1(self):
08597         m1c=MEDCouplingCMesh.New();
08598         coordsX=DataArrayDouble.New();
08599         arrX=[ -1., 1., 2., 4. ]
08600         coordsX.setValues(arrX,4,1);
08601         m1c.setCoordsAt(0,coordsX);
08602         coordsY=DataArrayDouble.New();
08603         arrY=[ -2., 2., 4., 8. ]
08604         coordsY.setValues(arrY,4,1);
08605         m1c.setCoordsAt(1,coordsY);
08606         m1=m1c.buildUnstructured()
08607         m1bis=m1.buildPartOfMySelf([3,4,5],False)
08608         m2=m1.deepCpy()
08609         m2=m2.buildPartOfMySelf([0,1,2],False)
08610         m2.translate([0.5,0.5])
08611         #
08612         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1bis,m2,1e-10)
08613         expected1=[0,1,1,2,2]
08614         expected2=[0,0,1,1,2]
08615         self.assertEqual(5,d1.getNumberOfTuples());
08616         self.assertEqual(5,d2.getNumberOfTuples());
08617         self.assertEqual(5,m3.getNumberOfCells());
08618         self.assertEqual(22,m3.getNumberOfNodes());
08619         self.assertEqual(2,m3.getSpaceDimension());
08620         self.assertEqual(expected1,d1.getValues());
08621         self.assertEqual(expected2,d2.getValues());
08622         expected3=[5,17,1,16,12,5,18,1,17,13,5,19,2,18,13,5,20,2,19,14,5,21,3,20,14]
08623         expected4=[0,5,10,15,20,25]
08624         expected5=[-1.0,2.0,1.0,2.0,2.0,2.0,4.0,2.0,-1.0,4.0,1.0,4.0,2.0,4.0,4.0,4.0,-0.5,-1.5,1.5,-1.5,2.5,-1.5,4.5,-1.5,-0.5,2.5,1.5,2.5,2.5,2.5,4.5,2.5,-0.5,2.0,1.0,2.5,1.5,2.0,2.0,2.5,2.5,2.0,4.0,2.5]
08625         self.assertEqual(25,m3.getNodalConnectivity().getNumberOfTuples());
08626         self.assertEqual(6,m3.getNodalConnectivityIndex().getNumberOfTuples());
08627         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
08628         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
08629         for i in xrange(44):
08630             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
08631             pass
08632         pass
08633 
08634     def testFindNodesOnLine1(self):
08635         mesh=MEDCouplingDataForTest.build2DTargetMesh_1();
08636         pt=[-0.3,-0.3]
08637         pt2=[0.,0.,0.]
08638         pt3=[-0.3,0.,0.]
08639         vec=[0.,1.]
08640         vec2=[1.,0.,0.]
08641         vec3=[0.,1.,1.]
08642         expected1=[0,3,6]
08643         res=mesh.findNodesOnLine(pt,vec,1e-12);
08644         self.assertEqual(3,len(res));
08645         self.assertEqual(expected1,res.getValues());
08646         #
08647         mesh.changeSpaceDimension(3);
08648         mesh.rotate(pt2,vec2,pi/4.);
08649         res=mesh.findNodesOnLine(pt3,vec3,1e-12);
08650         self.assertEqual(3,len(res));
08651         self.assertEqual(expected1,res.getValues());
08652         pass
08653 
08654     def testIntersect2DMeshesTmp2(self):
08655         m1c=MEDCouplingCMesh.New();
08656         coordsX1=DataArrayDouble.New();
08657         arrX1=[ 0., 1., 1.5, 2. ]
08658         coordsX1.setValues(arrX1,4,1);
08659         m1c.setCoordsAt(0,coordsX1);
08660         coordsY1=DataArrayDouble.New();
08661         arrY1=[ 0., 1.5, 3.]
08662         coordsY1.setValues(arrY1,3,1);
08663         m1c.setCoordsAt(1,coordsY1);
08664         m1=m1c.buildUnstructured();
08665         m2c=MEDCouplingCMesh.New();
08666         coordsX2=DataArrayDouble.New();
08667         arrX2=[ 0., 1., 2. ]
08668         coordsX2.setValues(arrX2,3,1);
08669         m2c.setCoordsAt(0,coordsX2);
08670         coordsY2=DataArrayDouble.New();
08671         arrY2=[ 0., 1., 3.]
08672         coordsY2.setValues(arrY2,3,1);
08673         m2c.setCoordsAt(1,coordsY2);
08674         m2=m2c.buildUnstructured();
08675         #
08676         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10)
08677         #
08678         expected1=[0,0,1,1,2,2,3,4,5]
08679         expected2=[0,2,1,3,1,3,2,3,3]
08680         self.assertEqual(9,d1.getNumberOfTuples());
08681         self.assertEqual(9,d2.getNumberOfTuples());
08682         self.assertEqual(9,m3.getNumberOfCells());
08683         self.assertEqual(22,m3.getNumberOfNodes());
08684         self.assertEqual(2,m3.getSpaceDimension());
08685         self.assertEqual(expected1,d1.getValues());
08686         self.assertEqual(expected2,d2.getValues());
08687         expected3=[5,16,13,12,15,5,15,4,5,16,5,21,2,13,16,5,16,5,6,21,5,17,14,2,21,5,21,6,7,17,5,4,18,19,5,5,5,19,10,6,5,6,10,20,7]
08688         expected4=[0,5,10,15,20,25,30,35,40,45]
08689         expected5=[0.0,0.0,1.0,0.0,1.5,0.0,2.0,0.0,0.0,1.5,1.0,1.5,1.5,1.5,2.0,1.5,0.0,3.0,1.0,3.0,1.5,3.0,2.0,3.0,0.0,0.0,1.0,0.0,2.0,0.0,0.0,1.0,1.0,1.0,2.0,1.0,0.0,3.0,1.0,3.0,2.0,3.0,1.5,1.0]
08690         self.assertEqual(45,m3.getNodalConnectivity().getNumberOfTuples());
08691         self.assertEqual(10,m3.getNodalConnectivityIndex().getNumberOfTuples());
08692         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
08693         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
08694         for i in xrange(44):
08695             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
08696             pass
08697         pass
08698     
08699     def testBuildPartOfMySelfSafe1(self):
08700         mesh=MEDCouplingDataForTest.build2DTargetMesh_1()
08701         self.assertRaises(InterpKernelException,mesh.buildPartOfMySelf,[0,-1,4,2],True)
08702         self.assertRaises(InterpKernelException,mesh.buildPartOfMySelf,[0,4,5,4],True)
08703         pass
08704 
08705     def testIntersect2DMeshesTmp3(self):
08706         m1Coords=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214];
08707         m1Conn=[0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23];
08708         m1=MEDCouplingUMesh.New();
08709         m1.setMeshDimension(2);
08710         m1.allocateCells(8);
08711         m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
08712         m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
08713         m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
08714         m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
08715         m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
08716         m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
08717         m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
08718         m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
08719         m1.finishInsertingCells();
08720         myCoords1=DataArrayDouble.New();
08721         myCoords1.setValues(m1Coords,25,2);
08722         m1.setCoords(myCoords1);
08723         #
08724         m2Coords=[0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1,-1.1,-1.,0.,-1.,1.1,-1,1.7,-1.]
08725         m2Conn=[0,3,2,1, 1,2,5,4, 7,6,3,0, 8,9,6,7, 7,0,12,11, 8,7,11,10, 0,1,13,12, 1,4,14,13]
08726         m2=MEDCouplingUMesh.New();
08727         m2.setMeshDimension(2);
08728         m2.allocateCells(8);
08729         for i in xrange(8):
08730             m2.insertNextCell(NORM_QUAD4,4,m2Conn[4*i:4*(i+1)])
08731             pass
08732         m2.finishInsertingCells();
08733         myCoords2=DataArrayDouble.New();
08734         myCoords2.setValues(m2Coords,15,2);
08735         m2.setCoords(myCoords2);
08736         #
08737         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10)
08738         m3.unPolyze()
08739         #
08740         expected1=[0,1,1,2,3,3,4,5,5,6,7,7]
08741         expected2=[0,0,1,2,2,3,4,4,5,6,6,7]
08742         self.assertEqual(12,d1.getNumberOfTuples());
08743         self.assertEqual(12,d2.getNumberOfTuples());
08744         self.assertEqual(12,m3.getNumberOfCells());
08745         self.assertEqual(88,m3.getNumberOfNodes());
08746         self.assertEqual(2,m3.getSpaceDimension());
08747         self.assertEqual(expected1,d1.getValues());
08748         self.assertEqual(expected2,d2.getValues());
08749         expected3=[6,28,1,25,44,45,46,8,26,1,28,27,47,48,49,50,8,40,2,26,27,51,52,53,54,6,28,25,5,55,56,57,8,28,5,32,31,58,59,60,61,8,32,6,41,31,62,63,64,65,6,25,37,5,66,67,68,8,32,5,37,36,69,70,71,72,8,42,6,32,36,73,74,75,76,6,1,37,25,77,78,79,8,37,1,26,38,80,81,82,83,8,26,2,43,38,84,85,86,87]
08750         expected4=[0,7,16,25,32,41,50,57,66,75,82,91,100]
08751         expected5=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,1.118033988749895,1.,-1.118033988749895,1.,-1.118033988749895,-1.,1.118033988749895,-1.,0.7071067811865477,0.7071067811865476,0.5,0.,0.,0.5,1.05,0.,0.7071067811865475,0.7071067811865477,0.55,1.,1.1,0.5,1.4012585384440737,0.535233134659635,1.3,0.,1.1,0.5,1.1090169943749475,1.,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-0.7071067811865475,0.7071067811865477,-1.05,0.,-1.1,0.5,-0.55,1.,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.1090169943749475,1.,-1.1,0.5,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.5,0.,-1.05,0.,-0.7071067811865478,-0.7071067811865475,-0.55,-1.,-1.1,-0.5,-1.4012585384440732,-0.5352331346596354,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,0.7071067811865475,-0.7071067811865477,0.,-0.5,0.5,0.,0.7071067811865477,-0.7071067811865475,1.05,0.,1.1,-0.5,0.55,-1.,1.3,0.,1.4012585384440737,-0.535233134659635,1.1090169943749475,-1.,1.1,-0.5]
08752         self.assertEqual(100,m3.getNodalConnectivity().getNumberOfTuples());
08753         self.assertEqual(13,m3.getNodalConnectivityIndex().getNumberOfTuples());
08754         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
08755         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
08756         for i in xrange(176):
08757             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
08758             pass
08759         pass
08760 
08761     def testUMeshTessellate2D1(self):
08762         m1Coords=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214];
08763         m1Conn=[0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23];
08764         m1=MEDCouplingUMesh.New();
08765         m1.setMeshDimension(2);
08766         m1.allocateCells(8);
08767         m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
08768         m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
08769         m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
08770         m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
08771         m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
08772         m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
08773         m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
08774         m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
08775         m1.finishInsertingCells();
08776         myCoords1=DataArrayDouble.New();
08777         myCoords1.setValues(m1Coords,25,2);
08778         m1.setCoords(myCoords1);
08779         #
08780         m11=m1.deepCpy();
08781         m11.tessellate2D(1.);
08782         self.assertTrue(m11.getCoords().isEqual(m11.getCoords(),1e-12));
08783         expected1=[5,0,3,11,1,5,3,4,12,2,1,11,5,5,15,3,0,5,6,16,4,3,15,5,5,5,0,7,19,5,6,5,19,7,8,20,5,0,1,23,7,5,1,2,24,8,7,23]
08784         expected2=[0,5,12,17,24,29,36,41,48]
08785         self.assertEqual(48,m11.getNodalConnectivity().getNumberOfTuples());
08786         self.assertEqual(9,m11.getNodalConnectivityIndex().getNumberOfTuples());
08787         self.assertEqual(expected1,m11.getNodalConnectivity().getValues());
08788         self.assertEqual(expected2,m11.getNodalConnectivityIndex().getValues());
08789         #
08790         m12=m1.deepCpy();
08791         m12.tessellate2D(0.5);
08792         self.assertEqual(41,m12.getNumberOfNodes());
08793         expected3=[5,0,3,25,26,1,5,3,4,27,28,2,1,26,25,5,5,29,30,3,0,5,6,31,32,4,3,30,29,5,5,5,0,7,33,34,5,6,5,34,33,7,8,35,36,5,0,1,37,38,7,5,1,2,39,40,8,7,38,37]
08794         expected4=[0,6,15,21,30,36,45,51,60]
08795         expected5=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.479425538604203,0.8775825618903728,0.8414709848078964,0.54030230586814,0.7191383079063044,1.3163738428355591,1.2622064772118446,0.8104534588022099,-0.877582561890373,0.4794255386042027,-0.5403023058681399,0.8414709848078964,-1.3163738428355596,0.7191383079063038,-0.8104534588022098,1.2622064772118446,-0.4794255386042031,-0.8775825618903728,-0.8414709848078965,-0.5403023058681399,-0.7191383079063045,-1.3163738428355591,-1.2622064772118449,-0.8104534588022098,0.8775825618903729,-0.47942553860420295,0.54030230586814,-0.8414709848078964,1.3163738428355594,-0.7191383079063043,0.8104534588022099,-1.2622064772118446]
08796         for i in xrange(82):
08797             self.assertAlmostEqual(expected5[i],m12.getCoords().getIJ(0,i),12);
08798             pass
08799         self.assertEqual(60,m12.getNodalConnectivity().getNumberOfTuples());
08800         self.assertEqual(9,m12.getNodalConnectivityIndex().getNumberOfTuples());
08801         self.assertEqual(expected3,m12.getNodalConnectivity().getValues());
08802         self.assertEqual(expected4,m12.getNodalConnectivityIndex().getValues());
08803         pass
08804 
08805     def testIntersect2DMeshesTmp4(self):
08806         m1Coords=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1,0.,-1.5,0.5,0.,1.25,0.,0.70710678118654757,0.70710678118654757,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.70710678118654757,0.70710678118654757,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.70710678118654757,-0.70710678118654757,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.70710678118654757,-0.70710678118654757,1.0606601717798214,-1.0606601717798214];
08807         m1Conn=[0,3,1,13,11,9, 3,4,2,1,14,12,10,11, 5,3,0,15,13,17, 6,4,3,5,16,14,15,18, 5,0,7,17,21,19, 6,5,7,8,18,19,22,20, 0,1,7,9,23,21, 1,2,8,7,10,24,22,23];
08808         m1=MEDCouplingUMesh.New();
08809         m1.setMeshDimension(2);
08810         m1.allocateCells(8);
08811         m1.insertNextCell(NORM_TRI6,6,m1Conn[0:6]);
08812         m1.insertNextCell(NORM_QUAD8,8,m1Conn[6:14]);
08813         m1.insertNextCell(NORM_TRI6,6,m1Conn[14:20]);
08814         m1.insertNextCell(NORM_QUAD8,8,m1Conn[20:28]);
08815         m1.insertNextCell(NORM_TRI6,6,m1Conn[28:34]);
08816         m1.insertNextCell(NORM_QUAD8,8,m1Conn[34:42]);
08817         m1.insertNextCell(NORM_TRI6,6,m1Conn[42:48]);
08818         m1.insertNextCell(NORM_QUAD8,8,m1Conn[48:56]);
08819         m1.finishInsertingCells();
08820         myCoords1=DataArrayDouble.New();
08821         myCoords1.setValues(m1Coords,25,2);
08822         m1.setCoords(myCoords1);
08823         #
08824         m2Coords=[0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1,-1.1,-1.,0.,-1.,1.1,-1,1.7,-1.]
08825         m2Conn=[0,3,2,1, 1,2,5,4, 7,6,3,0, 8,9,6,7, 7,0,12,11, 8,7,11,10, 0,1,13,12, 1,4,14,13]
08826         m2=MEDCouplingUMesh.New();
08827         m2.setMeshDimension(2);
08828         m2.allocateCells(8);
08829         for i in xrange(8):
08830             m2.insertNextCell(NORM_QUAD4,4,m2Conn[4*i:4*(i+1)])
08831             pass
08832         m2.finishInsertingCells();
08833         myCoords2=DataArrayDouble.New();
08834         myCoords2.setValues(m2Coords,15,2);
08835         m2.setCoords(myCoords2);
08836         #
08837         m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m2,m1,1e-10)
08838         m3.unPolyze()
08839         #
08840         expected1=[0,0,1,2,2,3,4,4,5,6,6,7]
08841         expected2=[0,1,1,2,3,3,4,5,5,6,7,7]
08842         self.assertEqual(12,d1.getNumberOfTuples());
08843         self.assertEqual(12,d2.getNumberOfTuples());
08844         self.assertEqual(12,m3.getNumberOfCells());
08845         self.assertEqual(88,m3.getNumberOfNodes());
08846         self.assertEqual(2,m3.getSpaceDimension());
08847         self.assertEqual(expected1,d1.getValues());
08848         self.assertEqual(expected2,d2.getValues());
08849         expected3=[6,16,15,18,44,45,46,8,18,2,1,16,47,48,49,50,8,17,1,2,40,51,52,53,54,6,18,15,20,55,56,57,8,20,7,6,18,58,59,60,61,8,41,6,7,21,62,63,64,65,6,20,15,22,66,67,68,8,22,11,7,20,69,70,71,72,8,21,7,11,42,73,74,75,76,6,22,15,16,77,78,79,8,16,1,13,22,80,81,82,83,8,43,13,1,17,84,85,86,87]
08850         expected4=[0,7,16,25,32,41,50,57,66,75,82,91,100]
08851         expected5=[0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,1.1180339887498951,1.,-1.1180339887498951,1.,-1.1180339887498951,-1.,1.1180339887498951,-1.,0.5,0.,0.,0.5,0.7071067811865477,0.7071067811865476,0.55,1.,1.1,0.5,1.05,0.,0.7071067811865477,0.7071067811865477,1.3,0.,1.1,0.5,1.1090169943749475,1.,1.4012585384440737,0.535233134659635,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-1.05,0.,-1.1,0.5,-0.55,1.,-0.7071067811865477,0.7071067811865477,-1.1090169943749475,1.,-1.1,0.5,-1.3,0.,-1.4012585384440737,0.5352331346596344,-0.5,0.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.55,-1.,-1.1,-0.5,-1.05,0.,-0.7071067811865479,-0.7071067811865476,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,-1.4012585384440734,-0.5352331346596354,0.,-0.5,0.5,0.,0.7071067811865475,-0.7071067811865477,1.05,0.,1.1,-0.5,0.55,-1.,0.7071067811865477,-0.7071067811865476,1.1090169943749475,-1.,1.1,-0.5,1.3,0.,1.4012585384440737,-0.535233134659635]
08852         self.assertEqual(100,m3.getNodalConnectivity().getNumberOfTuples());
08853         self.assertEqual(13,m3.getNodalConnectivityIndex().getNumberOfTuples());
08854         self.assertEqual(expected3,m3.getNodalConnectivity().getValues());
08855         self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues());
08856         for i in xrange(176):
08857             self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12);
08858             pass
08859         pass
08860 
08861     def testGetCellIdsCrossingPlane1(self):
08862         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
08863         vec=[-0.07,1.,0.07]
08864         origin=[1.524,1.4552,1.74768]
08865         ids1=mesh3D.getCellIdsCrossingPlane(origin,vec,1e-10)
08866         self.assertEqual([1,3,4,7,9,10,13,15,16],ids1.getValues())
08867         vec2=[0.,0.,1.]
08868         ids2=mesh3D.getCellIdsCrossingPlane(origin,vec2,1e-10)
08869         self.assertEqual([6,7,8,9,10,11],ids2.getValues())
08870         pass
08871 
08872     def testBuildSlice3D1(self):
08873         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
08874         vec1=[-0.07,1.,0.07]
08875         origin1=[1.524,1.4552,1.74768]
08876         slice1,ids=mesh3D.buildSlice3D(origin1,vec1,1e-10);
08877         expected1=[1,3,4,7,9,10,13,15,16]
08878         expected2=[5,42,41,40,43,44,5,42,46,45,41,5,44,43,40,47,48,5,49,42,44,50,5,49,51,46,42,5,50,44,48,52,5,53,49,50,54,5,53,55,51,49,5,54,50,52,56]
08879         expected3=[0,6,11,17,22,27,32,37,42,47]
08880         expected4=[1.,1.,0.,1.,1.25,0.,1.,1.5,0.,2.,1.,0.,1.,2.,0.,0.,2.,0.,3.,1.,0.,3.,2.,0.,0.,1.,0.,2.,2.,0.,1.,1.,1.,1.,1.25,1.,1.,1.5,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,2.,2.,1.,1.,1.,2.,1.,1.25,2.,1.,1.5,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,2.,2.,2.,1.,1.,3.,1.,1.25,3.,1.,1.5,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,2.,2.,3.,1.,1.5408576,0.,2.,1.6108576000000001,0.,2.,1.5408576,1.,1.,1.5,0.5836800000000008,1.,1.4708576,1.,3.,1.6808576,0.,3.,1.6108576000000001,1.,0.,1.4708576,0.,0.,1.4008576,1.,2.,1.4708576,2.,1.,1.4008576000000001,2.,3.,1.5408575999999998,2.,0.,1.3308575999999999,2.,2.,1.4008576,3.,1.,1.3308576,3.,3.,1.4708576,3.,0.,1.2608576,3.]
08881         self.assertEqual(2,slice1.getMeshDimension());
08882         self.assertEqual(3,slice1.getSpaceDimension());
08883         self.assertEqual(57,slice1.getNumberOfNodes());
08884         self.assertEqual(9,slice1.getNumberOfCells());
08885         self.assertEqual(9,ids.getNumberOfTuples());
08886         self.assertEqual(47,slice1.getNodalConnectivity().getNumberOfTuples());
08887         self.assertEqual(10,slice1.getNodalConnectivityIndex().getNumberOfTuples());
08888         self.assertEqual(expected1,ids.getValues());
08889         self.assertEqual(expected2,slice1.getNodalConnectivity().getValues());
08890         self.assertEqual(expected3,slice1.getNodalConnectivityIndex().getValues());
08891         for i in xrange(171):
08892             self.assertAlmostEqual(expected4[i],slice1.getCoords().getIJ(0,i),12);
08893             pass
08894         # 2nd slice based on already existing nodes of mesh3D.
08895         vec2=[0.,3.,1.]
08896         origin2=[2.5,1.,3.]
08897         slice1,ids=mesh3D.buildSlice3D(origin2,vec2,1e-10);
08898         expected5=[5,50,10,4,51,5,50,52,7,10,5,51,4,5,53,5,54,50,51,55,56,5,54,57,52,50,5,56,55,51,53,58,5,38,59,56,54,43,5,54,57,46,43,5,38,59,56,58,48]
08899         expected6=[0,5,10,15,21,26,32,38,43,49]
08900         expected7=[1.,1.,0.,1.,1.25,0.,1.,1.5,0.,2.,1.,0.,1.,2.,0.,0.,2.,0.,3.,1.,0.,3.,2.,0.,0.,1.,0.,1.,3.,0.,2.,2.,0.,2.,3.,0.,1.,1.,1.,1.,1.25,1.,1.,1.5,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,1.,3.,1.,2.,2.,1.,2.,3.,1.,0.,0.,2.,1.,1.,2.,1.,1.25,2.,1.,0.,2.,1.,1.5,2.,2.,0.,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,2.,2.,2.,0.,0.,3.,1.,1.,3.,1.,1.25,3.,1.,0.,3.,1.,1.5,3.,2.,0.,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,2.,2.,3.,2.,1.6666666666666667,1.,1.,1.6666666666666667,1.,3.,1.6666666666666667,1.,0.,1.6666666666666667,1.,2.,1.3333333333333335,2.,1.,1.5,1.5,1.,1.3333333333333333,2.,3.,1.3333333333333335,2.,0.,1.3333333333333335,2.,1.,1.25,2.25]
08901         self.assertEqual(2,slice1.getMeshDimension());
08902         self.assertEqual(3,slice1.getSpaceDimension());
08903         self.assertEqual(60,slice1.getNumberOfNodes());
08904         self.assertEqual(9,slice1.getNumberOfCells());
08905         self.assertEqual(9,ids.getNumberOfTuples());
08906         self.assertEqual(49,slice1.getNodalConnectivity().getNumberOfTuples());
08907         self.assertEqual(10,slice1.getNodalConnectivityIndex().getNumberOfTuples());
08908         self.assertEqual(expected1,ids.getValues());
08909         self.assertEqual(expected5,slice1.getNodalConnectivity().getValues());
08910         self.assertEqual(expected6,slice1.getNodalConnectivityIndex().getValues());
08911         for i in xrange(180):
08912             self.assertAlmostEqual(expected7[i],slice1.getCoords().getIJ(0,i),12);
08913             pass
08914         # 3rd slice based on shared face of mesh3D.
08915         vec3=[0.,0.,1.]
08916         origin3=[2.5,1.,2.]
08917         slice1,ids=mesh3D.buildSlice3D(origin3,vec3,1e-10);
08918         expected8=[6,7,8,9,10,11,12,13,14,15,16,17]
08919         expected9=[5,15,26,16,18,5,16,21,28,22,19,17,5,18,20,21,16,5,21,24,25,28,5,26,16,17,19,22,23,5,22,27,29,28,5,15,26,16,18,5,16,21,28,22,19,17,5,18,20,21,16,5,21,24,25,28,5,26,16,17,19,22,23,5,22,27,29,28]
08920         expected10=[0,5,12,17,22,29,34,39,46,51,56,63,68]
08921         expected11=[0.,0.,1.,1.,1.,1.,1.,1.25,1.,1.,0.,1.,1.,1.5,1.,2.,0.,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,1.,3.,1.,2.,2.,1.,2.,3.,1.,0.,0.,2.,1.,1.,2.,1.,1.25,2.,1.,0.,2.,1.,1.5,2.,2.,0.,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,1.,3.,2.,2.,2.,2.,2.,3.,2.,0.,0.,3.,1.,1.,3.,1.,1.25,3.,1.,0.,3.,1.,1.5,3.,2.,0.,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,1.,3.,3.,2.,2.,3.,2.,3.,3.]
08922         self.assertEqual(2,slice1.getMeshDimension());
08923         self.assertEqual(3,slice1.getSpaceDimension());
08924         self.assertEqual(45,slice1.getNumberOfNodes());
08925         self.assertEqual(12,slice1.getNumberOfCells());
08926         self.assertEqual(12,ids.getNumberOfTuples());
08927         self.assertEqual(68,slice1.getNodalConnectivity().getNumberOfTuples());
08928         self.assertEqual(13,slice1.getNodalConnectivityIndex().getNumberOfTuples());
08929         self.assertEqual(expected8,ids.getValues());
08930         self.assertEqual(expected9,slice1.getNodalConnectivity().getValues());
08931         self.assertEqual(expected10,slice1.getNodalConnectivityIndex().getValues());
08932         for i in xrange(135):
08933             self.assertAlmostEqual(expected11[i],slice1.getCoords().getIJ(0,i),12);
08934             pass
08935         pass
08936 
08937     def testBuildSlice3DSurf1(self):
08938         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
08939         mesh2D=mesh3D.buildDescendingConnectivity()[0];
08940         vec1=[-0.07,1.,0.07]
08941         origin1=[1.524,1.4552,1.74768]
08942         slice1,ids=mesh2D.buildSlice3DSurf(origin1,vec1,1e-10);
08943         expected1=[6,8,10,11,13,18,19,21,23,25,26,38,41,43,47,49,52,53,64,67,69,73,75,78,79]
08944         expected2=[1,40,41,1,42,41,1,40,43,1,44,43,1,42,44,1,45,41,1,42,46,1,46,45,1,47,40,1,47,48,1,44,48,1,49,42,1,44,50,1,49,50,1,49,51,1,51,46,1,48,52,1,50,52,1,53,49,1,50,54,1,53,54,1,53,55,1,55,51,1,52,56,1,54,56]
08945         expected3=[0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75];
08946         expected4=[1.,1.,0.,1.,1.25,0.,1.,1.5,0.,2.,1.,0.,1.,2.,0.,0.,2.,0.,3.,1.,0.,3.,2.,0.,0.,1.,0.,2.,2.,0.,1.,1.,1.,1.,1.25,1.,1.,1.5,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,2.,2.,1.,1.,1.,2.,1.,1.25,2.,1.,1.5,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,2.,2.,2.,1.,1.,3.,1.,1.25,3.,1.,1.5,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,2.,2.,3.,1.,1.5408576,0.,2.,1.6108576000000001,0.,2.,1.5408576,1.,1.,1.5,0.5836800000000008,1.,1.4708576,1.,3.,1.6808576,0.,3.,1.6108576000000001,1.,0.,1.4708576,0.,0.,1.4008576,1.,2.,1.4708576,2.,1.,1.4008576000000001,2.,3.,1.5408575999999998,2.,0.,1.3308575999999999,2.,2.,1.4008576,3.,1.,1.3308576,3.,3.,1.4708576,3.,0.,1.2608576,3.]
08947         self.assertEqual(1,slice1.getMeshDimension());
08948         self.assertEqual(3,slice1.getSpaceDimension());
08949         self.assertEqual(57,slice1.getNumberOfNodes());
08950         self.assertEqual(25,slice1.getNumberOfCells());
08951         self.assertEqual(25,ids.getNumberOfTuples());
08952         self.assertEqual(75,slice1.getNodalConnectivity().getNumberOfTuples());
08953         self.assertEqual(26,slice1.getNodalConnectivityIndex().getNumberOfTuples());
08954         self.assertEqual(expected1,ids.getValues());
08955         self.assertEqual(expected2,slice1.getNodalConnectivity().getValues());
08956         self.assertEqual(expected3,slice1.getNodalConnectivityIndex().getValues());
08957         for i in xrange(171):
08958             self.assertAlmostEqual(expected4[i],slice1.getCoords().getIJ(0,i),12);
08959             pass
08960         #
08961         vec2=[0.,0.,1.]
08962         origin2=[2.5,1.,2.]
08963         slice1,ids=mesh2D.buildSlice3DSurf(origin2,vec2,1e-10);
08964         expected5=[32,32,32,32,33,34,35,36,37,38,39,40,41,42,43,43,43,43,43,43,44,44,44,44,45,46,47,47,47,47,48,49,50,51,52,53,53,53,53,53,53,54,54,54,54,55,56,57,59,60,61,62,63,64,65,66,67,68,71,72,74,75,76,77,78,81,82,83]
08965         expected6=[1,15,18,1,18,16,1,16,26,1,26,15,1,26,15,1,16,26,1,18,16,1,15,18,1,16,21,1,21,28,1,22,28,1,19,22,1,17,19,1,16,17,1,16,21,1,21,28,1,28,22,1,22,19,1,19,17,1,17,16,1,16,18,1,18,20,1,20,21,1,21,16,1,20,21,1,18,20,1,28,21,1,21,24,1,24,25,1,25,28,1,25,28,1,24,25,1,21,24,1,23,22,1,26,23,1,26,16,1,16,17,1,17,19,1,19,22,1,22,23,1,23,26,1,22,28,1,28,29,1,29,27,1,27,22,1,27,22,1,29,27,1,28,29,1,26,15,1,16,26,1,18,16,1,15,18,1,16,21,1,21,28,1,22,28,1,19,22,1,17,19,1,16,17,1,20,21,1,18,20,1,25,28,1,24,25,1,21,24,1,23,22,1,26,23,1,27,22,1,29,27,1,28,29]
08966         expected7=[0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,183,186,189,192,195,198,201,204];
08967         expected8=[0.,0.,1.,1.,1.,1.,1.,1.25, 1.,1.,0.,1.,1.,1.5, 1.,2.,0.,1.,2.,1.,1.,1.,2.,1.,0.,2.,1.,3.,1.,1.,3.,2.,1.,0.,1.,1.,1.,3.,1.,2.,2.,1.,2.,3.,1.,0.,0.,2.,1.,1.,2.,1.,1.25, 2.,1.,0.,2.,1.,1.5, 2.,2.,0.,2.,2.,1.,2.,1.,2.,2.,0.,2.,2.,3.,1.,2.,3.,2.,2.,0.,1.,2.,1.,3.,2.,2.,2.,2.,2.,3.,2.,0.,0.,3.,1.,1.,3.,1.,1.25, 3.,1.,0.,3.,1.,1.5, 3.,2.,0.,3.,2.,1.,3.,1.,2.,3.,0.,2.,3.,3.,1.,3.,3.,2.,3.,0.,1.,3.,1.,3.,3.,2.,2.,3.,2.,3.,3.]
08968         self.assertEqual(1,slice1.getMeshDimension());
08969         self.assertEqual(3,slice1.getSpaceDimension());
08970         self.assertEqual(45,slice1.getNumberOfNodes());
08971         self.assertEqual(68,slice1.getNumberOfCells());
08972         self.assertEqual(68,ids.getNumberOfTuples());
08973         self.assertEqual(204,slice1.getNodalConnectivity().getNumberOfTuples());
08974         self.assertEqual(69,slice1.getNodalConnectivityIndex().getNumberOfTuples());
08975         self.assertEqual(expected5,ids.getValues());
08976         self.assertEqual(expected6,slice1.getNodalConnectivity().getValues());
08977         self.assertEqual(expected7,slice1.getNodalConnectivityIndex().getValues());
08978         for i in xrange(135):
08979             self.assertAlmostEqual(expected8[i],slice1.getCoords().getIJ(0,i),12);
08980             pass
08981         pass
08982 
08983     def testDataArrayDoubleAdvSetting1(self):
08984         data1=[1.,11.,2.,12.,3.,13.,4.,14.,5.,15.,6.,16.,7.,17.]
08985         data2=[8.,38.,9.,39.,0.,30.,11.,41.,12.,42.]
08986         compsCpp=["comp1","comp2"]
08987         da=DataArrayDouble.New();
08988         da.setInfoAndChangeNbOfCompo(compsCpp);
08989         da.setName("da");
08990         da.alloc(7,2);
08991         compsCpp=compsCpp[:-1]
08992         self.assertRaises(InterpKernelException,da.setInfoAndChangeNbOfCompo,compsCpp);
08993         da.setValues(data1,7,2)
08994         #
08995         p=[(0,3),(3,5),(5,7)]
08996         tmp=da.selectByTupleRanges(p);
08997         self.assertTrue(tmp.isEqual(da,1e-14));
08998         p=[(0,2),(3,4),(5,7)]
08999         tmp=da.selectByTupleRanges(p);
09000         expected1=[1.,11.,2.,12.,4.,14.,6.,16.,7.,17.]
09001         self.assertEqual(5,tmp.getNumberOfTuples());
09002         self.assertEqual(2,tmp.getNumberOfComponents());
09003         for i in xrange(10):
09004             self.assertAlmostEqual(expected1[i],tmp.getIJ(0,i),14);
09005             pass
09006         p=[(0,2),(0,2),(5,6)]
09007         tmp=da.selectByTupleRanges(p);
09008         expected2=[1.,11.,2.,12.,1.,11.,2.,12.,6.,16.]
09009         self.assertEqual(5,tmp.getNumberOfTuples());
09010         self.assertEqual(2,tmp.getNumberOfComponents());
09011         for i in xrange(10):
09012             self.assertAlmostEqual(expected2[i],tmp.getIJ(0,i),14);
09013             pass
09014         p=[(0,2),(-1,2),(5,6)]
09015         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
09016         p=[(0,2),(0,2),(5,8)]
09017         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
09018         #
09019         da2=DataArrayDouble.New();
09020         da2.setValues(data2,5,2);
09021         #
09022         dac=da.deepCpy();
09023         dac.setContigPartOfSelectedValues2(1,da2,2,4,1);
09024         expected3=[1.,11.,0.,30.,11.,41.,4.,14.,5.,15.,6.,16.,7.,17.]
09025         for i in xrange(14):
09026             self.assertAlmostEqual(expected3[i],dac.getIJ(0,i),14);
09027             pass
09028         #
09029         dac=da.deepCpy();
09030         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,0,5,1);
09031         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,0,da2,4,6,1);
09032         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,5,0,1);
09033         dac.setContigPartOfSelectedValues2(3,da2,1,5,1);
09034         expected4=[1.,11.,2.,12.,3.,13.,9.,39.,0.,30.,11.,41.,12.,42.]
09035         for i in xrange(14):
09036             self.assertAlmostEqual(expected4[i],dac.getIJ(0,i),14);
09037             pass
09038         #
09039         ids=DataArrayInt.New();
09040         ids.alloc(3,1);
09041         dac=da.deepCpy();
09042         ids.setIJ(0,0,2); ids.setIJ(1,0,0); ids.setIJ(2,0,4);
09043         dac.setContigPartOfSelectedValues(2,da2,ids);
09044         expected5=[1.,11.,2.,12.,0.,30.,8.,38.,12.,42.,6.,16.,7.,17.]
09045         for i in xrange(14):
09046             self.assertAlmostEqual(expected5[i],dac.getIJ(0,i),14);
09047             pass
09048         #
09049         dac=da.deepCpy();
09050         ids.setIJ(0,0,2); ids.setIJ(1,0,5); ids.setIJ(2,0,4);
09051         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
09052         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,-1);
09053         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
09054         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
09055         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,5,da2,ids);
09056         #
09057         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
09058         dac=da.deepCpy();
09059         dac.setContigPartOfSelectedValues(4,da2,ids);
09060         expected6=[1.,11.,2.,12.,3.,13.,4.,14.,0.,30.,0.,30.,9.,39.]
09061         for i in xrange(14):
09062             self.assertAlmostEqual(expected6[i],dac.getIJ(0,i),14);
09063             pass
09064         pass
09065 
09066     def testDataArrayIntAdvSetting1(self):
09067         data1=[1,11,2,12,3,13,4,14,5,15,6,16,7,17]
09068         data2=[8,38,9,39,0,30,11,41,12,42]
09069         compsCpp=["comp1","comp2"]
09070         da=DataArrayInt.New();
09071         da.setInfoAndChangeNbOfCompo(compsCpp);
09072         da.setName("da");
09073         da.alloc(7,2);
09074         compsCpp=compsCpp[:-1]
09075         self.assertRaises(InterpKernelException,da.setInfoAndChangeNbOfCompo,compsCpp);
09076         da.setValues(data1,7,2)
09077         #
09078         p=[(0,3),(3,5),(5,7)]
09079         tmp=da.selectByTupleRanges(p);
09080         self.assertTrue(tmp.isEqual(da));
09081         p=[(0,2),(3,4),(5,7)]
09082         tmp=da.selectByTupleRanges(p);
09083         expected1=[1,11,2,12,4,14,6,16,7,17]
09084         self.assertEqual(5,tmp.getNumberOfTuples());
09085         self.assertEqual(2,tmp.getNumberOfComponents());
09086         for i in xrange(10):
09087             self.assertEqual(expected1[i],tmp.getIJ(0,i));
09088             pass
09089         p=[(0,2),(0,2),(5,6)]
09090         tmp=da.selectByTupleRanges(p);
09091         expected2=[1,11,2,12,1,11,2,12,6,16]
09092         self.assertEqual(5,tmp.getNumberOfTuples());
09093         self.assertEqual(2,tmp.getNumberOfComponents());
09094         for i in xrange(10):
09095             self.assertEqual(expected2[i],tmp.getIJ(0,i));
09096             pass
09097         p=[(0,2),(-1,2),(5,6)]
09098         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
09099         p=[(0,2),(0,2),(5,8)]
09100         self.assertRaises(InterpKernelException,da.selectByTupleRanges,p);
09101         #
09102         da2=DataArrayInt.New();
09103         da2.setValues(data2,5,2);
09104         #
09105         dac=da.deepCpy();
09106         dac.setContigPartOfSelectedValues2(1,da2,2,4,1);
09107         expected3=[1,11,0,30,11,41,4,14,5,15,6,16,7,17]
09108         for i in xrange(14):
09109             self.assertEqual(expected3[i],dac.getIJ(0,i));
09110             pass
09111         #
09112         dac=da.deepCpy();
09113         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,0,5,1);
09114         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,0,da2,4,6,1);
09115         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues2,3,da2,5,0,1);
09116         dac.setContigPartOfSelectedValues2(3,da2,1,5,1);
09117         expected4=[1,11,2,12,3,13,9,39,0,30,11,41,12,42]
09118         for i in xrange(14):
09119             self.assertEqual(expected4[i],dac.getIJ(0,i));
09120             pass
09121         #
09122         ids=DataArrayInt.New();
09123         ids.alloc(3,1);
09124         dac=da.deepCpy();
09125         ids.setIJ(0,0,2); ids.setIJ(1,0,0); ids.setIJ(2,0,4);
09126         dac.setContigPartOfSelectedValues(2,da2,ids);
09127         expected5=[1,11,2,12,0,30,8,38,12,42,6,16,7,17]
09128         for i in xrange(14):
09129             self.assertEqual(expected5[i],dac.getIJ(0,i));
09130             pass
09131         #
09132         dac=da.deepCpy();
09133         ids.setIJ(0,0,2); ids.setIJ(1,0,5); ids.setIJ(2,0,4);
09134         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
09135         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,-1);
09136         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,1,da2,ids);
09137         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
09138         self.assertRaises(InterpKernelException,dac.setContigPartOfSelectedValues,5,da2,ids);
09139         #
09140         ids.setIJ(0,0,2); ids.setIJ(1,0,2); ids.setIJ(2,0,1);
09141         dac=da.deepCpy();
09142         dac.setContigPartOfSelectedValues(4,da2,ids);
09143         expected6=[1,11,2,12,3,13,4,14,0,30,0,30,9,39]
09144         for i in xrange(14):
09145             self.assertEqual(expected6[i],dac.getIJ(0,i));
09146             pass
09147         pass
09148 
09149     def testBuildDescendingConnec2Of3DMesh1(self):
09150         mesh=MEDCouplingDataForTest.build3DSourceMesh_1();
09151         #
09152         mesh2,desc,descIndx,revDesc,revDescIndx=mesh.buildDescendingConnectivity2();
09153         mesh2.checkCoherency();
09154         self.assertEqual(2,mesh2.getMeshDimension());
09155         self.assertEqual(30,mesh2.getNumberOfCells());
09156         self.assertEqual(31,revDescIndx.getNbOfElems()); self.assertEqual(31,revDescIndx.getNumberOfTuples());
09157         self.assertEqual(13,descIndx.getNbOfElems()); self.assertEqual(13,descIndx.getNumberOfTuples());
09158         self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples());
09159         self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples());
09160         expected1=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,-10,15,-5,-13,16,17,-14,18,-4,19,-2,20,21,22,23,24,25,-11,26,-1,-12,-25,-22,27,28,-7,-20,-24,29,-16,-18,30,-8,-28]
09161         self.assertEqual(expected1,desc.getValues());
09162         expected2=[0,4,8,12,16,20,24,28,32,36,40,44,48]
09163         self.assertEqual(expected2,descIndx.getValues());
09164         expected3=[0,2,4,5,7,9,10,12,14,15,17,19,21,23,25,26,28,29,31,32,34,35,37,38,40,42,43,44,46,47,48]
09165         self.assertEqual(expected3,revDescIndx.getValues());
09166         expected4=[0,8,0,6,0,0,5,1,4,1,1,9,1,11,2,2,3,2,7,2,8,3,4,3,5,3,4,10,4,5,11,5,6,10,6,6,9,7,7,10,7,8,8,9,9,11,10,11]
09167         self.assertEqual(expected4,revDesc.getValues());
09168         conn=mesh2.getNodalConnectivity();
09169         connIndex=mesh2.getNodalConnectivityIndex();
09170         expected5=[0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120]
09171         self.assertEqual(expected5,connIndex.getValues());
09172         expected6=[3,8,1,7,3,8,3,1,3,1,3,7,3,7,3,8,3,6,0,8,3,6,2,0,3,0,2,8,3,8,2,6,3,7,4,5,3,7,8,4,3,4,8,5,3,5,8,7,3,6,8,4,3,6,7,8,3,4,7,6,3,8,4,0,3,0,4,6,3,6,3,8,3,7,3,6,3,8,0,1,3,1,0,3,3,3,0,8,3,4,1,5,3,4,8,1,3,1,8,5,3,1,7,5,3,0,2,3,3,3,2,8,3,1,4,0,3,3,2,6]
09173         self.assertEqual(expected6,conn.getValues());
09174         pass
09175 
09176     def testAre2DCellsNotCorrectlyOriented1(self):
09177         m1Coords=[1.,1.,-1.,-1.,-1.,-1.,1.,-1.]
09178         m1Conn=[0,3,1,2]
09179         m1=MEDCouplingUMesh.New();
09180         m1.setMeshDimension(2);
09181         m1.allocateCells(1);
09182         m1.insertNextCell(NORM_QUAD4,4,m1Conn[0:4])
09183         m1.finishInsertingCells();
09184         myCoords1=DataArrayDouble.New();
09185         myCoords1.setValues(m1Coords,4,2);
09186         m1.setCoords(myCoords1);
09187         #
09188         vec1=[0.,0.,1.]
09189         for i in xrange(18):
09190             vec2=[3.*cos(pi/9.*i),3.*sin(pi/9.*i)];
09191             m1Cpy=m1.deepCpy();
09192             m1Cpy.translate(vec2);
09193             self.assertRaises(InterpKernelException,m1Cpy.are2DCellsNotCorrectlyOriented,vec1,False);
09194             m1Cpy.changeSpaceDimension(3);
09195             res=m1Cpy.are2DCellsNotCorrectlyOriented(vec1,False)
09196             self.assertEqual([0],res.getValues());
09197             pass
09198         pass
09199 
09200     def testDataArrayAbs1(self):
09201         d1=DataArrayDouble.New();
09202         val1=[2.,-3.,-5.,6.,-7.,-8.,9.,10.,-11.,-12.,-13.,-15.]
09203         expected1=[2.,3.,5.,6.,7.,8.,9.,10.,11.,12.,13.,15.]
09204         d1.setValues(val1,6,2);
09205         d2=d1.convertToIntArr();
09206         #
09207         d1.abs();
09208         for i in xrange(12):
09209             self.assertAlmostEqual(expected1[i],d1.getIJ(0,i),14);
09210             pass
09211         #
09212         expected2=[2,3,5,6,7,8,9,10,11,12,13,15]
09213         d2.abs();
09214         for i in xrange(12):
09215             self.assertEqual(expected2[i],d2.getIJ(0,i));
09216             pass
09217         #
09218         pass
09219 
09220     # test on 1D
09221     def testGetValueOn3(self):
09222         v=[0.,1.,1.5,2.]
09223         v2=[0.7,1.25,0.,2.,1.5]
09224         disp=[5.,50.,500.,6.,60.,600.,7.,70.,700.,8.,80.,800.]
09225         m=MEDCouplingUMesh.New("myMesh",1)
09226         nbNodes=len(v)
09227         nbCells=nbNodes-1
09228         m.allocateCells(nbCells)
09229         coords=DataArrayDouble.New() ; coords.setValues(v,nbNodes,1)
09230         m.setCoords(coords)
09231         m.insertNextCell(NORM_SEG2,2,[0,1])
09232         m.insertNextCell(NORM_SEG2,2,[2,1])
09233         m.insertNextCell(NORM_SEG2,2,[2,3])
09234         m.finishInsertingCells()
09235         f=MEDCouplingFieldDouble.New(ON_NODES)
09236         f.setMesh(m)
09237         array=DataArrayDouble.New(); array.setValues(disp,m.getNumberOfNodes(),3)
09238         f.setArray(array)
09239         arr1=f.getValueOnMulti(v2)
09240         self.assertEqual(5,arr1.getNumberOfTuples());
09241         self.assertEqual(3,arr1.getNumberOfComponents());
09242         expected1=[5.7,57.,570.,6.5,65.,650.,5.,50.,500.,8.,80.,800.,7.,70.,700.]
09243         for i in xrange(15):
09244             self.assertAlmostEqual(expected1[i],arr1.getIJ(0,i),14);
09245             pass
09246         pass
09247 
09248     def testGetNodeIdsOfCell2(self):
09249         m1c=MEDCouplingCMesh.New();
09250         coordsX=DataArrayDouble.New();
09251         arrX=[ -1., 1., 2., 4., 4.5 ]
09252         coordsX.setValues(arrX,5,1);
09253         coordsY=DataArrayDouble.New();
09254         arrY=[ -2., 2., 4., 8.]
09255         coordsY.setValues(arrY,4,1);
09256         coordsZ=DataArrayDouble.New();
09257         arrZ=[ -2., 2., 4.]
09258         coordsZ.setValues(arrZ,3,1);
09259         # test in 1D
09260         m1c.setCoordsAt(0,coordsX);
09261         expected1=[[0,1],[1,2],[2,3],[3,4]]
09262         self.assertEqual(4,m1c.getNumberOfCells())
09263         for i in xrange(m1c.getNumberOfCells()):
09264             self.assertEqual(expected1[i],m1c.getNodeIdsOfCell(i))
09265             pass
09266         # test in 2D
09267         m1c.setCoordsAt(1,coordsY);
09268         self.assertEqual(12,m1c.getNumberOfCells())
09269         expected2=[[0,1,6,5],[1,2,7,6],[2,3,8,7],[3,4,9,8],[4,5,11,10],[5,6,12,11],[6,7,13,12],[7,8,14,13],[8,9,16,15],[9,10,17,16],[10,11,18,17],[11,12,19,18]]
09270         for i in xrange(m1c.getNumberOfCells()):
09271             self.assertEqual(expected2[i],m1c.getNodeIdsOfCell(i))
09272             pass
09273         # test in 3D
09274         m1c.setCoordsAt(2,coordsZ);
09275         expected3=[[0,1,6,5,20,21,26,25],[1,2,7,6,21,22,27,26],[2,3,8,7,22,23,28,27],[3,4,9,8,23,24,29,28],[4,5,11,10,24,25,31,30],[5,6,12,11,25,26,32,31],[6,7,13,12,26,27,33,32],[7,8,14,13,27,28,34,33],[8,9,16,15,28,29,36,35],[9,10,17,16,29,30,37,36],[10,11,18,17,30,31,38,37],[11,12,19,18,31,32,39,38],[20,21,26,25,40,41,46,45],[21,22,27,26,41,42,47,46],[22,23,28,27,42,43,48,47],[23,24,29,28,43,44,49,48],[24,25,31,30,44,45,51,50],[25,26,32,31,45,46,52,51],[26,27,33,32,46,47,53,52],[27,28,34,33,47,48,54,53],[28,29,36,35,48,49,56,55],[29,30,37,36,49,50,57,56],[30,31,38,37,50,51,58,57],[31,32,39,38,51,52,59,58]]
09276         self.assertEqual(24,m1c.getNumberOfCells())
09277         for i in xrange(m1c.getNumberOfCells()):
09278             self.assertEqual(expected3[i],m1c.getNodeIdsOfCell(i))
09279             pass
09280         pass
09281     
09282     def testSwigDADOp4(self):
09283         da=DataArrayDouble.New(range(6,30),12,2)
09284         self.assertEqual(12,da.getNumberOfTuples());
09285         self.assertEqual(2,da.getNumberOfComponents());
09286         for i in xrange(24):
09287             self.assertAlmostEqual(da.getIJ(0,i),float(i+6),13)
09288             pass
09289         # operator transpose
09290         da.transpose()
09291         self.assertEqual(2,da.getNumberOfTuples());
09292         self.assertEqual(12,da.getNumberOfComponents());
09293         for i in xrange(24):
09294             self.assertAlmostEqual(da.getIJ(0,i),float(i+6),13)
09295             pass
09296         da.transpose()
09297         # operator __neg__
09298         da2=DataArrayDouble.New(12,1)
09299         da2.iota(0.)
09300         dabis=-da
09301         for i in xrange(24):
09302             self.assertAlmostEqual(dabis.getIJ(0,i),-float(i+6),13)
09303             pass
09304         # operator+=
09305         da+=da2
09306         expected1=[6.,7.,9.,10.,12.,13.,15.,16.,18.,19.,21.,22.,24.,25.,27.,28.,30.,31.,33.,34.,36.,37.,39.,40.]
09307         for i in xrange(24):
09308             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
09309             pass
09310         da=-dabis
09311         da+=[100.,101.]
09312         expected2=[106.,108.,108.,110.,110.,112.,112.,114.,114.,116.,116.,118.,118.,120.,120.,122.,122.,124.,124.,126.,126.,128.,128.,130.]
09313         self.assertEqual(12,da.getNumberOfTuples());
09314         self.assertEqual(2,da.getNumberOfComponents());
09315         for i in xrange(24):
09316             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
09317             pass
09318         for pos,elt in enumerate(dabis):
09319             da[pos]+=elt
09320             pass
09321         self.assertEqual(12,da.getNumberOfTuples());
09322         self.assertEqual(2,da.getNumberOfComponents());
09323         for elt in da:
09324             li=elt[:]
09325             self.assertAlmostEqual(li[0],100.,13) ; self.assertAlmostEqual(li[1],101.,13)
09326             pass
09327         # operator-=
09328         da=DataArrayDouble.New(range(6,30),12,2)
09329         da2=DataArrayDouble.New(range(12),12,1)
09330         dabis=-da
09331         da-=da2
09332         expected1=[6.,7.,7.,8.,8.,9.,9.,10.,10.,11.,11.,12.,12.,13.,13.,14.,14.,15.,15.,16.,16.,17.,17.,18.]
09333         for i in xrange(24):
09334             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
09335             pass
09336         da=-dabis
09337         da-=[100.,101.]
09338         expected2=[-94.,-94.,-92.,-92.,-90.,-90.,-88.,-88.,-86.,-86.,-84.,-84.,-82.,-82.,-80.,-80.,-78.,-78.,-76.,-76.,-74.,-74.,-72.,-72.]
09339         self.assertEqual(12,da.getNumberOfTuples());
09340         self.assertEqual(2,da.getNumberOfComponents());
09341         for i in xrange(24):
09342             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
09343             pass
09344         for pos,elt in enumerate(dabis):
09345             da[pos]-=elt
09346             pass
09347         self.assertEqual(12,da.getNumberOfTuples());
09348         self.assertEqual(2,da.getNumberOfComponents());
09349         expected3=[-88.,-87.,-84.,-83.,-80.,-79.,-76.,-75.,-72.,-71.,-68.,-67.,-64.,-63.,-60.,-59.,-56.,-55.,-52.,-51.,-48.,-47.,-44.,-43.]
09350         for i in xrange(24):
09351             self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
09352             pass
09353         # operator*=
09354         da=DataArrayDouble.New(range(6,30),12,2)
09355         da2=DataArrayDouble.New(range(12),12,1)
09356         dabis=-da
09357         da*=da2
09358         expected1=[0.,0.,8.,9.,20.,22.,36.,39.,56.,60.,80.,85.,108.,114.,140.,147.,176.,184.,216.,225.,260.,270.,308.,319.]
09359         for i in xrange(24):
09360             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
09361             pass
09362         da=-dabis
09363         da*=[100.,101.]
09364         expected2=[600.,707.,800.,909.,1000.,1111.,1200.,1313.,1400.,1515.,1600.,1717.,1800.,1919.,2000.,2121.,2200.,2323.,2400.,2525.,2600.,2727.,2800.,2929.]
09365         self.assertEqual(12,da.getNumberOfTuples());
09366         self.assertEqual(2,da.getNumberOfComponents());
09367         for i in xrange(24):
09368             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
09369             pass
09370         for pos,elt in enumerate(dabis):
09371             da[pos]*=elt
09372             pass
09373         self.assertEqual(12,da.getNumberOfTuples());
09374         self.assertEqual(2,da.getNumberOfComponents());
09375         expected3=[-3600.,-4949.,-6400.,-8181.,-10000.,-12221.,-14400.,-17069.,-19600.,-22725.,-25600.,-29189.,-32400.,-36461.,-40000.,-44541.,-48400.,-53429.,-57600.,-63125.,-67600.,-73629.,-78400.,-84941.0]
09376         for i in xrange(24):
09377             self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
09378             pass
09379         # operator/=
09380         da=DataArrayDouble.New(range(6,30),12,2)
09381         da2=DataArrayDouble.New(range(1,13),12,1)
09382         dabis=-da
09383         da/=da2
09384         expected1=[6.0,7.0,4.0,4.5,3.3333333333333335,3.6666666666666665,3.0,3.25,2.8,3.0,2.6666666666666665,2.8333333333333335,2.5714285714285716,2.7142857142857144,2.5,2.625,2.4444444444444446,2.5555555555555554,2.4,2.5,2.3636363636363638,2.4545454545454546,2.3333333333333335,2.4166666666666665]
09385         for i in xrange(24):
09386             self.assertAlmostEqual(da.getIJ(0,i),expected1[i],13)
09387             pass
09388         da=-dabis
09389         da/=[100.,101.]
09390         expected2=[0.06,0.06930693069306931,0.08,0.0891089108910891,0.1,0.10891089108910891,0.12,0.12871287128712872,0.14,0.1485148514851485,0.16,0.16831683168316833,0.18,0.18811881188118812,0.2,0.2079207920792079,0.22,0.22772277227722773,0.24,0.24752475247524752,0.26,0.26732673267326734,0.28,0.2871287128712871]
09391         self.assertEqual(12,da.getNumberOfTuples());
09392         self.assertEqual(2,da.getNumberOfComponents());
09393         for i in xrange(24):
09394             self.assertAlmostEqual(da.getIJ(0,i),expected2[i],13)
09395             pass
09396         for pos,elt in enumerate(dabis):
09397             da[pos]/=elt
09398             pass
09399         self.assertEqual(12,da.getNumberOfTuples());
09400         self.assertEqual(2,da.getNumberOfComponents());
09401         expected3=[-0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.009900990099009901, -0.01, -0.0099009900990099]
09402         for i in xrange(24):
09403             self.assertAlmostEqual(da.getIJ(0,i),expected3[i],13)
09404             pass
09405         pass
09406 
09407     def testSwigDAIOp4(self):
09408         da=DataArrayInt.New(range(6,30),12,2)
09409         self.assertEqual(12,da.getNumberOfTuples());
09410         self.assertEqual(2,da.getNumberOfComponents());
09411         for i in xrange(24):
09412             self.assertEqual(da.getIJ(0,i),i+6)
09413             pass
09414         # operator transpose
09415         da.transpose()
09416         self.assertEqual(2,da.getNumberOfTuples());
09417         self.assertEqual(12,da.getNumberOfComponents());
09418         for i in xrange(24):
09419             self.assertEqual(da.getIJ(0,i),i+6)
09420             pass
09421         da.transpose()
09422         # operator __neg__
09423         da2=DataArrayInt.New(12,1)
09424         da2.iota(0)
09425         dabis=-da
09426         for i in xrange(24):
09427             self.assertEqual(dabis.getIJ(0,i),-(i+6))
09428             pass
09429         # operator+=
09430         da+=da2
09431         expected1=[6,7,9,10,12,13,15,16,18,19,21,22,24,25,27,28,30,31,33,34,36,37,39,40]
09432         for i in xrange(24):
09433             self.assertEqual(da.getIJ(0,i),expected1[i])
09434             pass
09435         da=-dabis
09436         da+=[100,101]
09437         expected2=[106,108,108,110,110,112,112,114,114,116,116,118,118,120,120,122,122,124,124,126,126,128,128,130]
09438         self.assertEqual(12,da.getNumberOfTuples());
09439         self.assertEqual(2,da.getNumberOfComponents());
09440         for i in xrange(24):
09441             self.assertEqual(da.getIJ(0,i),expected2[i])
09442             pass
09443         for pos,elt in enumerate(dabis):
09444             da[pos]+=elt
09445             pass
09446         self.assertEqual(12,da.getNumberOfTuples());
09447         self.assertEqual(2,da.getNumberOfComponents());
09448         for elt in da:
09449             li=elt[:]
09450             self.assertEqual(li[0],100) ; self.assertEqual(li[1],101)
09451             pass
09452         # operator-=
09453         da=DataArrayInt.New(range(6,30),12,2)
09454         da2=DataArrayInt.New(range(12),12,1)
09455         dabis=-da
09456         da-=da2
09457         expected1=[6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18]
09458         for i in xrange(24):
09459             self.assertEqual(da.getIJ(0,i),expected1[i])
09460             pass
09461         da=-dabis
09462         da-=[100,101]
09463         expected2=[-94,-94,-92,-92,-90,-90,-88,-88,-86,-86,-84,-84,-82,-82,-80,-80,-78,-78,-76,-76,-74,-74,-72,-72]
09464         self.assertEqual(12,da.getNumberOfTuples());
09465         self.assertEqual(2,da.getNumberOfComponents());
09466         for i in xrange(24):
09467             self.assertEqual(da.getIJ(0,i),expected2[i])
09468             pass
09469         for pos,elt in enumerate(dabis):
09470             da[pos]-=elt
09471             pass
09472         self.assertEqual(12,da.getNumberOfTuples());
09473         self.assertEqual(2,da.getNumberOfComponents());
09474         expected3=[-88,-87,-84,-83,-80,-79,-76,-75,-72,-71,-68,-67,-64,-63,-60,-59,-56,-55,-52,-51,-48,-47,-44,-43]
09475         for i in xrange(24):
09476             self.assertEqual(da.getIJ(0,i),expected3[i])
09477             pass
09478         # operator*=
09479         da=DataArrayInt.New(range(6,30),12,2)
09480         da2=DataArrayInt.New(range(12),12,1)
09481         dabis=-da
09482         da*=da2
09483         expected1=[0,0,8,9,20,22,36,39,56,60,80,85,108,114,140,147,176,184,216,225,260,270,308,319]
09484         for i in xrange(24):
09485             self.assertEqual(da.getIJ(0,i),expected1[i])
09486             pass
09487         da=-dabis
09488         da*=[100,101]
09489         expected2=[600,707,800,909,1000,1111,1200,1313,1400,1515,1600,1717,1800,1919,2000,2121,2200,2323,2400,2525,2600,2727,2800,2929]
09490         self.assertEqual(12,da.getNumberOfTuples());
09491         self.assertEqual(2,da.getNumberOfComponents());
09492         for i in xrange(24):
09493             self.assertEqual(da.getIJ(0,i),expected2[i])
09494             pass
09495         for pos,elt in enumerate(dabis):
09496             da[pos]*=elt
09497             pass
09498         self.assertEqual(12,da.getNumberOfTuples());
09499         self.assertEqual(2,da.getNumberOfComponents());
09500         expected3=[-3600,-4949,-6400,-8181,-10000,-12221,-14400,-17069,-19600,-22725,-25600,-29189,-32400,-36461,-40000,-44541,-48400,-53429,-57600,-63125,-67600,-73629,-78400,-84941.0]
09501         for i in xrange(24):
09502             self.assertEqual(da.getIJ(0,i),expected3[i])
09503             pass
09504         # operator/=
09505         da=DataArrayInt.New(range(6,30),12,2)
09506         da2=DataArrayInt.New(range(1,13),12,1)
09507         dabis=-da
09508         da/=da2
09509         expected1=[6,7,4,4,3,3,3,3,2,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
09510         for i in xrange(24):
09511             self.assertEqual(da.getIJ(0,i),expected1[i])
09512             pass
09513         da=-dabis
09514         da/=DataArrayInt.New([2,3],1,2)
09515         self.assertEqual(12,da.getNumberOfTuples());
09516         self.assertEqual(2,da.getNumberOfComponents());
09517         expected2=[3,2,4,3,5,3,6,4,7,5,8,5,9,6,10,7,11,7,12,8,13,9,14,9]
09518         for i in xrange(24):
09519             self.assertEqual(da.getIJ(0,i),expected2[i])
09520             pass
09521         pass
09522 
09523     def testSwigDADOp5(self):
09524         da=DataArrayDouble.New([5,6,7,8,9,6,7,-2,3,9,8,10])
09525         da.rearrange(3)
09526         da2=DataArrayDouble.New([5.,8.,10.,12])
09527         self.assertEqual(4,da2.getNumberOfTuples());
09528         self.assertEqual(1,da2.getNumberOfComponents());
09529         da3=da+da2
09530         self.assertEqual(4,da3.getNumberOfTuples());
09531         self.assertEqual(3,da3.getNumberOfComponents());
09532         expected1=[10.,11.,12.,16.,17.,14.,17.,8.,13.,21.,20.,22.]
09533         for i in xrange(12):
09534             self.assertAlmostEqual(da3.getIJ(0,i),expected1[i],13)
09535             pass
09536         da3=da2+da
09537         self.assertEqual(4,da3.getNumberOfTuples());
09538         self.assertEqual(3,da3.getNumberOfComponents());
09539         for i in xrange(12):
09540             self.assertAlmostEqual(da3.getIJ(0,i),expected1[i],13)
09541             pass
09542         # Test new API of classmethod DataArrayDouble.New
09543         vals=[5,6,7,8,9,6,7,-2,3,9,8,10]
09544         da=DataArrayDouble.New(vals)
09545         self.assertEqual(12,da.getNumberOfTuples());
09546         self.assertEqual(1,da.getNumberOfComponents());
09547         for i in xrange(12):
09548             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
09549             pass
09550         da=DataArrayDouble.New(vals,12)
09551         self.assertEqual(12,da.getNumberOfTuples());
09552         self.assertEqual(1,da.getNumberOfComponents());
09553         for i in xrange(12):
09554             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
09555             pass
09556         da=DataArrayDouble.New(vals,1,12)
09557         self.assertEqual(1,da.getNumberOfTuples());
09558         self.assertEqual(12,da.getNumberOfComponents());
09559         for i in xrange(12):
09560             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
09561             pass
09562         da=DataArrayDouble.New(vals,6,2)
09563         self.assertEqual(6,da.getNumberOfTuples());
09564         self.assertEqual(2,da.getNumberOfComponents());
09565         for i in xrange(12):
09566             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
09567             pass
09568         da=DataArrayDouble.New(vals,4,3)
09569         self.assertEqual(4,da.getNumberOfTuples());
09570         self.assertEqual(3,da.getNumberOfComponents());
09571         for i in xrange(12):
09572             self.assertAlmostEqual(da.getIJ(0,i),vals[i],13)
09573             pass
09574         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,11);
09575         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,13);
09576         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,5,2);
09577         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,7,2);
09578         pass
09579 
09580     def testSwigDADOp6(self):
09581         da=DataArrayInt.New([5,6,7,8,9,6,7,-2,3,9,8,10])
09582         da.rearrange(3)
09583         da2=DataArrayInt.New([5,8,10,12])
09584         self.assertEqual(4,da2.getNumberOfTuples());
09585         self.assertEqual(1,da2.getNumberOfComponents());
09586         da3=da+da2
09587         self.assertEqual(4,da3.getNumberOfTuples());
09588         self.assertEqual(3,da3.getNumberOfComponents());
09589         expected1=[10,11,12,16,17,14,17,8,13,21,20,22]
09590         for i in xrange(12):
09591             self.assertEqual(da3.getIJ(0,i),expected1[i])
09592             pass
09593         da3=da2+da
09594         self.assertEqual(4,da3.getNumberOfTuples());
09595         self.assertEqual(3,da3.getNumberOfComponents());
09596         for i in xrange(12):
09597             self.assertEqual(da3.getIJ(0,i),expected1[i])
09598             pass
09599         da3=da+DataArrayInt.New(da2.getValues())
09600         # Test new API of classmethod DataArrayInt.New
09601         vals=[5,6,7,8,9,6,7,-2,3,9,8,10]
09602         da=DataArrayDouble.New(vals)
09603         self.assertEqual(12,da.getNumberOfTuples());
09604         self.assertEqual(1,da.getNumberOfComponents());
09605         for i in xrange(12):
09606             self.assertEqual(da.getIJ(0,i),vals[i])
09607             pass
09608         da=DataArrayDouble.New(vals,12)
09609         self.assertEqual(12,da.getNumberOfTuples());
09610         self.assertEqual(1,da.getNumberOfComponents());
09611         for i in xrange(12):
09612             self.assertEqual(da.getIJ(0,i),vals[i])
09613             pass
09614         da=DataArrayDouble.New(vals,1,12)
09615         self.assertEqual(1,da.getNumberOfTuples());
09616         self.assertEqual(12,da.getNumberOfComponents());
09617         for i in xrange(12):
09618             self.assertEqual(da.getIJ(0,i),vals[i])
09619             pass
09620         da=DataArrayDouble.New(vals,6,2)
09621         self.assertEqual(6,da.getNumberOfTuples());
09622         self.assertEqual(2,da.getNumberOfComponents());
09623         for i in xrange(12):
09624             self.assertEqual(da.getIJ(0,i),vals[i])
09625             pass
09626         da=DataArrayDouble.New(vals,4,3)
09627         self.assertEqual(4,da.getNumberOfTuples());
09628         self.assertEqual(3,da.getNumberOfComponents());
09629         for i in xrange(12):
09630             self.assertEqual(da.getIJ(0,i),vals[i])
09631             pass
09632         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,11);
09633         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,13);
09634         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,5,2);
09635         self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,7,2);
09636         pass
09637 
09638     def testRenumberNodesInConn1(self):
09639         mesh2DCoords=[-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. ]
09640         mesh2DConn=[1,4,2, 4,5,2, 0,3,4,1, 6,7,4,3, 7,8,5,4]
09641         mesh2D=MEDCouplingUMesh.New("mesh",2);
09642         mesh2D.allocateCells(5);
09643         mesh2D.insertNextCell(NORM_TRI3,3,mesh2DConn[0:3])
09644         mesh2D.insertNextCell(NORM_TRI3,3,mesh2DConn[3:6])
09645         mesh2D.insertNextCell(NORM_QUAD4,4,mesh2DConn[6:10])
09646         mesh2D.insertNextCell(NORM_QUAD4,4,mesh2DConn[10:14])
09647         mesh2D.insertNextCell(NORM_QUAD4,4,mesh2DConn[14:18])
09648         mesh2D.finishInsertingCells();
09649         myCoords=DataArrayDouble.New(mesh2DCoords,9,3);
09650         mesh2D.setCoords(myCoords);
09651         mesh2D.checkCoherency();
09652         #
09653         mesh3DCoords=[-0.3,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.2,-0.3,0., -0.3,-0.3,1., -0.3,0.2,1., 0.2,0.2,1., 0.2,-0.3,1. ]
09654         mesh3DConn=[0,1,2,3,4,5,6,7]
09655         mesh3D=MEDCouplingUMesh.New("mesh",3);
09656         mesh3D.allocateCells(1);
09657         mesh3D.insertNextCell(NORM_HEXA8,8,mesh3DConn[:])
09658         mesh3D.finishInsertingCells();
09659         myCoords3D=DataArrayDouble.New(mesh3DCoords,8,3);
09660         mesh3D.setCoords(myCoords3D);
09661         mesh3D.checkCoherency();
09662         #
09663         mesh3D_2=mesh3D.deepCpy();
09664         mesh2D_2=mesh2D.deepCpy();
09665         mesh3D_4=mesh3D.deepCpy();
09666         mesh2D_4=mesh2D.deepCpy();
09667         oldNbOf3DNodes=mesh3D.getNumberOfNodes();
09668         renumNodes=DataArrayInt.New();
09669         renumNodes.alloc(mesh2D.getNumberOfNodes(),1);
09670         renumNodes.iota(oldNbOf3DNodes);
09671         coo=DataArrayDouble.Aggregate(mesh3D.getCoords(),mesh2D.getCoords());
09672         mesh3D.setCoords(coo);
09673         mesh2D.setCoords(coo);
09674         mesh2DCpy=mesh2D.deepCpy()
09675         mesh2D_3=mesh2D.deepCpy();
09676         mesh2D_3.shiftNodeNumbersInConn(oldNbOf3DNodes);
09677         mesh2D.renumberNodesInConn(renumNodes);
09678         mesh2DCpy.renumberNodesInConn(renumNodes.getValues());
09679         self.assertTrue(mesh2D.isEqual(mesh2DCpy,1e-12))
09680         self.assertTrue(mesh2D.isEqual(mesh2D_3,1e-12))
09681         #
09682         da1,da2=mesh3D.checkGeoEquivalWith(mesh3D_2,10,1e-12);
09683         self.assertTrue(da1==None);
09684         self.assertEqual(8,da2.getNumberOfTuples());
09685         self.assertEqual(1,da2.getNumberOfComponents());
09686         expected1=[8,11,12,9,4,5,6,7]
09687         for i in xrange(8):
09688             self.assertEqual(expected1[i],da2.getIJ(i,0));
09689             pass
09690         #
09691         da1,da2=mesh2D.checkGeoEquivalWith(mesh2D_2,10,1e-12);
09692         self.assertTrue(da1==None);
09693         self.assertEqual(9,da2.getNumberOfTuples());
09694         self.assertEqual(1,da2.getNumberOfComponents());
09695         for i in xrange(9):
09696             self.assertEqual(8+i,da2.getIJ(i,0));
09697             pass
09698         #
09699         mesh2D_5=mesh2D_4.deepCpy();
09700         mesh2D_5.translate([1.,0.,0.]);
09701         meshes=[mesh3D_4,mesh2D_4,mesh2D_5];
09702         MEDCouplingUMesh.PutUMeshesOnSameAggregatedCoords(meshes);
09703         self.assertTrue(mesh3D_4.getCoords().getHiddenCppPointer()==mesh2D_4.getCoords().getHiddenCppPointer());
09704         self.assertTrue(mesh2D_4.getCoords().getHiddenCppPointer()==mesh2D_5.getCoords().getHiddenCppPointer());
09705         mesh3D_4.checkCoherency(); mesh2D_4.checkCoherency(); mesh2D_5.checkCoherency();
09706         self.assertEqual(26,mesh3D_4.getNumberOfNodes());
09707         self.assertEqual(3,mesh3D_4.getSpaceDimension());
09708         self.assertEqual(9,mesh3D_4.getNodalConnectivity().getNumberOfTuples());
09709         self.assertEqual(23,mesh2D_4.getNodalConnectivity().getNumberOfTuples());
09710         self.assertEqual(23,mesh2D_5.getNodalConnectivity().getNumberOfTuples());
09711         expected2=[18,0,1,2,3,4,5,6,7]
09712         expected3=[3,9,12,10, 3,12,13,10, 4,8,11,12,9, 4,14,15,12,11, 4,15,16,13,12]
09713         expected4=[3,18,21,19, 3,21,22,19, 4,17,20,21,18, 4,23,24,21,20, 4,24,25,22,21]
09714         expected5=[-0.3,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.2,-0.3,0., -0.3,-0.3,1., -0.3,0.2,1., 0.2,0.2,1., 0.2,-0.3,1., -0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0., 0.7, -0.3, 0.0, 1.2, -0.3, 0.0, 1.7, -0.3, 0.0, 0.7, 0.2, 0.0, 1.2, 0.2, 0.0, 1.7, 0.2, 0.0, 0.7, 0.7, 0.0, 1.2, 0.7, 0.0, 1.7, 0.7, 0.0]
09715         self.assertEqual(expected2,mesh3D_4.getNodalConnectivity().getValues());
09716         self.assertEqual(expected3,mesh2D_4.getNodalConnectivity().getValues());
09717         self.assertEqual(expected4,mesh2D_5.getNodalConnectivity().getValues());
09718         for i in xrange(78):
09719             self.assertAlmostEqual(expected5[i],mesh3D_4.getCoords().getIJ(0,i),12);
09720             pass
09721         #
09722         MEDCouplingUMesh.MergeNodesOnUMeshesSharingSameCoords(meshes,1e-12);
09723         mesh3D_4.checkCoherency(); mesh2D_4.checkCoherency(); mesh2D_5.checkCoherency();
09724         self.assertTrue(mesh3D_4.getCoords().getHiddenCppPointer()==mesh2D_4.getCoords().getHiddenCppPointer());
09725         self.assertTrue(mesh2D_4.getCoords().getHiddenCppPointer()==mesh2D_5.getCoords().getHiddenCppPointer());
09726         self.assertEqual(19,mesh3D_4.getNumberOfNodes());
09727         self.assertEqual(3,mesh3D_4.getSpaceDimension());
09728         self.assertEqual(9,mesh3D_4.getNodalConnectivity().getNumberOfTuples());
09729         self.assertEqual(23,mesh2D_4.getNodalConnectivity().getNumberOfTuples());
09730         self.assertEqual(23,mesh2D_5.getNodalConnectivity().getNumberOfTuples());
09731         expected6=[18,0,1,2,3,4,5,6,7]
09732         expected7=[3,3,2,8, 3,2,9,8, 4,0,1,2,3, 4,10,11,2,1, 4,11,12,9,2]
09733         expected8=[3,13,15,14, 3,15,16,14, 4,8,9,15,13, 4,12,17,15,9, 4,17,18,16,15]
09734         expected9=[-0.3, -0.3, 0., -0.3, 0.2, 0., 0.2, 0.2, 0., 0.2, -0.3, 0., -0.3, -0.3, 1., -0.3, 0.2, 1.,
09735                     0.2, 0.2, 1., 0.2, -0.3, 1., 0.7, -0.3, 0., 0.7, 0.2, 0., -0.3, 0.7, 0., 0.2, 0.7, 0.,
09736                     0.7, 0.7, 0., 1.2, -0.3, 0., 1.7, -0.3, 0., 1.2, 0.2, 0., 1.7, 0.2, 0., 1.2, 0.7, 0., 1.7, 0.7, 0.]
09737         self.assertEqual(expected6,mesh3D_4.getNodalConnectivity().getValues());
09738         self.assertEqual(expected7,mesh2D_4.getNodalConnectivity().getValues());
09739         self.assertEqual(expected8,mesh2D_5.getNodalConnectivity().getValues());
09740         for i in xrange(57):
09741             self.assertAlmostEqual(expected9[i],mesh3D_4.getCoords().getIJ(0,i),1e-12);
09742             pass
09743         #
09744         pass
09745     
09746     def testComputeNeighborsOfCells1(self):
09747         m=MEDCouplingDataForTest.build2DTargetMesh_1();
09748         d1,d2=m.computeNeighborsOfCells();
09749         self.assertEqual(6,d2.getNumberOfTuples());
09750         self.assertEqual(10,d1.getNumberOfTuples());
09751         expected1=[0,2,4,6,8,10]
09752         expected2=[3,1,0,2,4,1,4,0,2,3]
09753         self.assertEqual(expected1,d2.getValues());
09754         self.assertEqual(expected2,d1.getValues());
09755         pass
09756 
09757     def testCheckButterflyCellsBug1(self):
09758         mesh2DCoords=[323.85,120.983748908684,317.5,131.982271536747,336.55,120.983748908686,330.2,131.982271536751,323.85,142.98079416481]
09759         mesh2DConn=[4,1,0,2,3]
09760         mesh2D=MEDCouplingUMesh.New("mesh",2);
09761         mesh2D.allocateCells(1);
09762         mesh2D.insertNextCell(NORM_POLYGON,5,mesh2DConn[0:5])
09763         mesh2D.finishInsertingCells();
09764         myCoords=DataArrayDouble.New(mesh2DCoords,5,2);
09765         mesh2D.setCoords(myCoords);
09766         mesh2D.checkCoherency();
09767         #
09768         v=mesh2D.checkButterflyCells();
09769         self.assertTrue(v.empty());
09770         pass
09771 
09772     def testDataArrayIntRange1(self):
09773         d=DataArrayInt.Range(2,17,7);
09774         expected1=[2,9,16]
09775         self.assertEqual(3,d.getNumberOfTuples());
09776         self.assertEqual(1,d.getNumberOfComponents());
09777         self.assertEqual(expected1,d.getValues());
09778         #
09779         d=DataArrayInt.Range(2,23,7);
09780         self.assertEqual(3,d.getNumberOfTuples());
09781         self.assertEqual(1,d.getNumberOfComponents());
09782         self.assertEqual(expected1,d.getValues());
09783         #
09784         d=DataArrayInt.Range(2,24,7);
09785         expected2=[2,9,16,23]
09786         self.assertEqual(4,d.getNumberOfTuples());
09787         self.assertEqual(1,d.getNumberOfComponents());
09788         self.assertEqual(expected2,d.getValues());
09789         #
09790         d=DataArrayInt.Range(24,2,-7);
09791         expected3=[24,17,10,3]
09792         self.assertEqual(4,d.getNumberOfTuples());
09793         self.assertEqual(1,d.getNumberOfComponents());
09794         self.assertEqual(expected3,d.getValues());
09795         #
09796         d=DataArrayInt.Range(23,2,-7);
09797         expected4=[23,16,9]
09798         self.assertEqual(3,d.getNumberOfTuples());
09799         self.assertEqual(1,d.getNumberOfComponents());
09800         self.assertEqual(expected4,d.getValues());
09801         #
09802         d=DataArrayInt.Range(23,22,-7);
09803         self.assertEqual(1,d.getNumberOfTuples());
09804         self.assertEqual(1,d.getNumberOfComponents());
09805         self.assertEqual(23,d.getIJ(0,0));
09806         #
09807         d=DataArrayInt.Range(22,23,7);
09808         self.assertEqual(1,d.getNumberOfTuples());
09809         self.assertEqual(1,d.getNumberOfComponents());
09810         self.assertEqual(22,d.getIJ(0,0));
09811         #
09812         d=DataArrayInt.Range(22,22,7);
09813         self.assertEqual(0,d.getNumberOfTuples());
09814         self.assertEqual(1,d.getNumberOfComponents());
09815         #
09816         d=DataArrayInt.Range(22,22,-7);
09817         self.assertEqual(0,d.getNumberOfTuples());
09818         self.assertEqual(1,d.getNumberOfComponents());
09819         #
09820         self.assertRaises(InterpKernelException,DataArrayInt.Range,22,23,-7);
09821         self.assertRaises(InterpKernelException,DataArrayInt.Range,23,22,7);
09822         self.assertRaises(InterpKernelException,DataArrayInt.Range,23,22,0);
09823         self.assertRaises(InterpKernelException,DataArrayInt.Range,22,23,0);
09824         pass
09825 
09826     def testSwigUMeshGetItem1(self):
09827         m=MEDCouplingDataForTest.build2DTargetMesh_1();
09828         subMesh=m.buildPartOfMySelf([1,3],True);
09829         self.assertTrue(isinstance(subMesh,MEDCouplingUMesh))
09830         m1=m[[1,3]]
09831         self.assertTrue(isinstance(m1,MEDCouplingUMesh))
09832         m2=m[(1,3)]
09833         self.assertTrue(isinstance(m2,MEDCouplingUMesh))
09834         m3=m[1::2]
09835         self.assertTrue(isinstance(m3,MEDCouplingUMesh))
09836         m4=m[DataArrayInt.New([1,3])]
09837         m5_1=m[1]
09838         self.assertTrue(isinstance(m5_1,MEDCouplingUMesh))
09839         m5_2=m[3]
09840         self.assertTrue(isinstance(m5_2,MEDCouplingUMesh))
09841         m5=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m5_1,m5_2]);
09842         m5.setName(subMesh.getName())
09843         self.assertTrue(isinstance(m4,MEDCouplingUMesh))
09844         self.assertTrue(subMesh.isEqual(m1,1e-12))
09845         self.assertTrue(subMesh.isEqual(m2,1e-12))
09846         self.assertTrue(subMesh.isEqual(m3,1e-12))
09847         self.assertTrue(subMesh.isEqual(m4,1e-12))
09848         self.assertTrue(subMesh.isEqual(m5,1e-12))
09849         self.assertRaises(InterpKernelException,m.buildPartOfMySelf,[1,5],True);
09850         pass
09851     
09852     def testSwigGetItem3(self):
09853         da=DataArrayInt.New([4,5,6])
09854         self.assertEqual(5,da[1])
09855         self.assertRaises(InterpKernelException,da.__getitem__,-1)
09856         self.assertRaises(InterpKernelException,da.__getitem__,3)
09857         da=DataArrayInt.New([4,5,6,7,8,9],2,3)
09858         self.assertEqual(9,da[1,2])
09859         da=DataArrayDouble.New([4.1,5.2,6.3])
09860         self.assertAlmostEqual(5.2,da[1],12)
09861         self.assertRaises(InterpKernelException,da.__getitem__,-1)
09862         self.assertRaises(InterpKernelException,da.__getitem__,3)
09863         da=DataArrayDouble.New([4.12,5.12,6.12,7.12,8.12,9.12],2,3)
09864         self.assertAlmostEqual(9.12,da[1,2],12)
09865         pass
09866 
09867     def testSwigDADISub1(self):
09868         mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1();
09869         bary=mesh3D.getBarycenterAndOwner()
09870         bary=bary[:,:2]
09871         pts=bary.getDifferentValues(1e-12)
09872         expected=[[0,6,12],[1,7,13],[2,8,14],[3,9,15],[4,10,16],[5,11,17]]
09873         for pos,pt in enumerate(pts):
09874             bary2=bary[:,:2]
09875             bary2[:]-=pt
09876             norm=bary2.magnitude()
09877             self.assertEqual(expected[pos],norm.getIdsInRange(-1.,1e-5).getValues())
09878             pass
09879         expected2=[[3.,54.],[-141.,180.],[21.,54.],[39.,72.],[-15.,90.],[21.,90.]]
09880         for pos,pt in enumerate(pts):
09881             bary2=bary[:,:2]
09882             bary2[:]+=pt
09883             self.assertAlmostEqual(expected2[pos][0],bary2.accumulate()[0],12);
09884             self.assertAlmostEqual(expected2[pos][1],bary2.accumulate()[1],12);
09885             pass
09886         expected3=[[-3.,22.5],[45.,337.5],[-9., 22.5],[-15.,67.5],[3.,112.5],[-9.,112.5]]
09887         for pos,pt in enumerate(pts):
09888             bary2=bary[:,:2]
09889             bary2[:]*=pt
09890             self.assertAlmostEqual(expected3[pos][0],bary2.accumulate()[0],12);
09891             self.assertAlmostEqual(expected3[pos][1],bary2.accumulate()[1],12);
09892             pass
09893         expected4=[[-12.,90.],[0.8,6.],[-4,90.],[-2.4,30.],[12.,18],[-4,18.]]
09894         for pos,pt in enumerate(pts):
09895             bary2=bary[:,:2]
09896             bary2[:]/=pt
09897             self.assertAlmostEqual(expected4[pos][0],bary2.accumulate()[0],12);
09898             self.assertAlmostEqual(expected4[pos][1],bary2.accumulate()[1],12);
09899             pass
09900         #
09901         d=DataArrayInt.New([1,2,0,1,0,2],3,2)
09902         e=DataArrayInt.New([1,11,101,2,12,102,3,13,103,4,14,104],4,3)
09903         expected5=[[1,11,101,77,77,77,77,77,77,4,14,104],[77,77,77,77,77,77,3,13,103,4,14,104],[77,77,77,2,12,102,77,77,77,4,14,104]]
09904         expected6=[[1,77,77,2,77,77,3,77,77,4,77,77],[77,77,101,77,77,102,77,77,103,77,77,104],[77,11,77,77,12,77,77,13,77,77,14,77]]
09905         for pos,tup in enumerate(d):
09906             f=e[:]
09907             self.assertTrue(isinstance(f,DataArrayInt))
09908             f[tup]=77
09909             self.assertEqual(expected5[pos],f.getValues())
09910             self.assertEqual(6*[77],f[tup].getValues())
09911             f=e[:]
09912             f[:,tup]=77
09913             self.assertEqual(expected6[pos],f.getValues())
09914             self.assertEqual(8*[77],f[:,tup].getValues())
09915             pass
09916         #
09917         e=e.convertToDblArr()
09918         for pos,tup in enumerate(d):
09919             f=e[:]
09920             self.assertTrue(isinstance(f,DataArrayDouble))
09921             f[tup]=77.
09922             self.assertEqual(expected5[pos],f.convertToIntArr().getValues())
09923             self.assertEqual(6*[77],f[tup].convertToIntArr().getValues())
09924             f=e[:]
09925             f[:,tup]=77.
09926             self.assertEqual(expected6[pos],f.convertToIntArr().getValues())
09927             self.assertEqual(8*[77],f[:,tup].convertToIntArr().getValues())
09928             pass
09929         pass
09930 
09931     def testDataArrayDoubleGetMinMaxPerComponent1(self):
09932         values1=[1.,2.,3.,-0.9,2.1,3.,1.3,1.7,3.,1.,1.8,3.]
09933         d1=DataArrayDouble.New();
09934         self.assertRaises(InterpKernelException,d1.getMinMaxPerComponent)
09935         d1=DataArrayDouble.New(values1,4,3);
09936         res=d1.getMinMaxPerComponent();
09937         self.assertTrue(isinstance(res,list))
09938         self.assertEqual(3,len(res))
09939         for i in xrange(3):
09940             self.assertTrue(isinstance(res[i],tuple))
09941             self.assertEqual(2,len(res[i]))
09942             pass
09943         expected1=[-0.9,1.3,1.7,2.1,3.,3.]
09944         for i in xrange(6):
09945             self.assertAlmostEqual(expected1[i],res[i/2][i%2],14)
09946             pass
09947         #
09948         d1.rearrange(2);
09949         res=d1.getMinMaxPerComponent();
09950         self.assertTrue(isinstance(res,list))
09951         self.assertEqual(2,len(res))
09952         for i in xrange(2):
09953             self.assertTrue(isinstance(res[i],tuple))
09954             self.assertEqual(2,len(res[i]))
09955             pass
09956         expected2=[1.,3.,-0.9,3.]
09957         for i in xrange(4):
09958             self.assertAlmostEqual(expected2[i],res[i/2][i%2],14)
09959             pass
09960         #
09961         d1.rearrange(1);
09962         res=d1.getMinMaxPerComponent();
09963         self.assertTrue(isinstance(res,list))
09964         self.assertEqual(1,len(res))
09965         for i in xrange(1):
09966             self.assertTrue(isinstance(res[i],tuple))
09967             self.assertEqual(2,len(res[i]))
09968             pass
09969         expected3=[-0.9,3.]
09970         for i in xrange(2):
09971             self.assertAlmostEqual(expected3[i],res[i/2][i%2],14)
09972             pass
09973         pass
09974 
09975     def testDataArrayIntGetHashCode1(self):
09976         d1=DataArrayInt.New(range(3545))
09977         d2=DataArrayInt.New(range(3545))
09978         self.assertEqual(d2.getHashCode(),d1.getHashCode())
09979         self.assertEqual(232341068,d1.getHashCode())
09980         d1[886]=6
09981         self.assertEqual(232340188,d1.getHashCode())
09982         pass
09983 
09984     def testZipConnectivityPol1(self):
09985         m1=MEDCouplingDataForTest.build2DTargetMesh_1();
09986         cells1=[2,3,4]
09987         m2_1=m1.buildPartOfMySelf(cells1,True);
09988         m2=m2_1
09989         self.assertTrue(isinstance(m2,MEDCouplingUMesh))
09990         # no permutation policy 0
09991         isOk,arr=m1.areCellsIncludedIn(m2,0)
09992         self.assertTrue(isOk);
09993         self.assertEqual(3,arr.getNumberOfTuples());
09994         self.assertEqual(1,arr.getNumberOfComponents());
09995         self.assertEqual(cells1,arr.getValues())
09996         # no permutation policy 1
09997         isOk,arr=m1.areCellsIncludedIn(m2,1)
09998         self.assertTrue(isOk);
09999         self.assertEqual(3,arr.getNumberOfTuples());
10000         self.assertEqual(1,arr.getNumberOfComponents());
10001         self.assertEqual(cells1,arr.getValues())
10002         # no permutation policy 2
10003         isOk,arr=m1.areCellsIncludedIn(m2,2)
10004         self.assertTrue(isOk);
10005         self.assertEqual(3,arr.getNumberOfTuples());
10006         self.assertEqual(1,arr.getNumberOfComponents());
10007         self.assertEqual(cells1,arr.getValues())
10008         # some modification into m2
10009         modif1=[2,4,5]
10010         m2.getNodalConnectivity()[1:4]=modif1
10011         #policy 0 fails because cell0 in m2 has same orientation be not same connectivity
10012         expected1=[5,3,4]
10013         isOk,arr=m1.areCellsIncludedIn(m2,0)
10014         self.assertTrue(not isOk);
10015         self.assertEqual(3,arr.getNumberOfTuples());
10016         self.assertEqual(1,arr.getNumberOfComponents());
10017         self.assertEqual(expected1,arr.getValues())
10018         #policy 1 succeeds because cell0 in m2 has not exactly the same conn
10019         isOk,arr=m1.areCellsIncludedIn(m2,1)
10020         self.assertTrue(isOk);
10021         self.assertEqual(3,arr.getNumberOfTuples());
10022         self.assertEqual(1,arr.getNumberOfComponents());
10023         self.assertEqual(cells1,arr.getValues())
10024         #policy 2 succeeds because cell0 in m2 has same nodes in connectivity
10025         isOk,arr=m1.areCellsIncludedIn(m2,2)
10026         self.assertTrue(isOk);
10027         self.assertEqual(3,arr.getNumberOfTuples());
10028         self.assertEqual(1,arr.getNumberOfComponents());
10029         self.assertEqual(cells1,arr.getValues())
10030         #some new modification into m2
10031         modif2=[2,5,4]
10032         m2.getNodalConnectivity()[1:4]=modif2
10033         #policy 0 fails because cell0 in m2 has not exactly the same conn
10034         isOk,arr=m1.areCellsIncludedIn(m2,0)
10035         self.assertTrue(not isOk);
10036         self.assertEqual(3,arr.getNumberOfTuples());
10037         self.assertEqual(1,arr.getNumberOfComponents());
10038         self.assertEqual(expected1,arr.getValues())
10039         #policy 1 fails too because cell0 in m2 has not same orientation
10040         isOk,arr=m1.areCellsIncludedIn(m2,1)
10041         self.assertTrue(not isOk);
10042         self.assertEqual(3,arr.getNumberOfTuples());
10043         self.assertEqual(1,arr.getNumberOfComponents());
10044         self.assertEqual(expected1,arr.getValues())
10045         #policy 2 succeeds because cell0 in m2 has same nodes in connectivity
10046         isOk,arr=m1.areCellsIncludedIn(m2,2)
10047         self.assertTrue(isOk);
10048         self.assertEqual(3,arr.getNumberOfTuples());
10049         self.assertEqual(1,arr.getNumberOfComponents());
10050         self.assertEqual(cells1,arr.getValues())
10051         # Now 1D
10052         cells2=[3,2]
10053         m1=MEDCouplingDataForTest.build1DSourceMesh_2();
10054         m2_1=m1.buildPartOfMySelf(cells2,True);
10055         m2=m2_1
10056         self.assertTrue(isinstance(m2,MEDCouplingUMesh))
10057         # no permutation policy 0
10058         isOk,arr=m1.areCellsIncludedIn(m2,0)
10059         self.assertTrue(isOk);
10060         self.assertEqual(2,arr.getNumberOfTuples());
10061         self.assertEqual(1,arr.getNumberOfComponents());
10062         self.assertEqual(cells2,arr.getValues())
10063         # no permutation policy 1
10064         isOk,arr=m1.areCellsIncludedIn(m2,1)
10065         self.assertTrue(isOk);
10066         self.assertEqual(2,arr.getNumberOfTuples());
10067         self.assertEqual(1,arr.getNumberOfComponents());
10068         self.assertEqual(cells2,arr.getValues())
10069         # no permutation policy 2
10070         isOk,arr=m1.areCellsIncludedIn(m2,2)
10071         self.assertTrue(isOk);
10072         self.assertEqual(2,arr.getNumberOfTuples());
10073         self.assertEqual(1,arr.getNumberOfComponents());
10074         self.assertEqual(cells2,arr.getValues())
10075         # some modification into m2
10076         modif3=[4,3]
10077         m2.getNodalConnectivity()[1:3]=modif3
10078         #policy 0 fails because cell0 in m2 has not exactly the same conn
10079         expected2=[4,2]
10080         isOk,arr=m1.areCellsIncludedIn(m2,0)
10081         self.assertTrue(not isOk);
10082         self.assertEqual(2,arr.getNumberOfTuples());
10083         self.assertEqual(1,arr.getNumberOfComponents());
10084         self.assertEqual(expected2,arr.getValues())
10085         #policy 1 fails too because cell0 in m2 has not same orientation
10086         isOk,arr=m1.areCellsIncludedIn(m2,1)
10087         self.assertTrue(not isOk);
10088         self.assertEqual(2,arr.getNumberOfTuples());
10089         self.assertEqual(1,arr.getNumberOfComponents());
10090         self.assertEqual(expected2,arr.getValues())
10091         #policy 2 succeeds because cell0 in m2 has same nodes in connectivity
10092         isOk,arr=m1.areCellsIncludedIn(m2,2)
10093         self.assertTrue(isOk);
10094         self.assertEqual(2,arr.getNumberOfTuples());
10095         self.assertEqual(1,arr.getNumberOfComponents());
10096         self.assertEqual(cells2,arr.getValues())
10097         pass
10098         
10099     def setUp(self):
10100         pass
10101     pass
10102 
10103 unittest.main()