From: ageay Date: Fri, 23 Jul 2010 17:22:47 +0000 (+0000) Subject: More tests in MEDCoupling_Swig. X-Git-Tag: V5_1_main_FINAL~77 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c26722427c409729895a3589eafadd5e2a75c34c;p=tools%2Fmedcoupling.git More tests in MEDCoupling_Swig. --- diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 98db6b0d5..b4ceaec7c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -20,8 +20,21 @@ from libMEDCoupling_Swig import * import unittest +from math import pi +from MEDCouplingDataForTest import MEDCouplingDataForTest class MEDCouplingBasicsTest(unittest.TestCase): + def testArray2(self): + arr=DataArrayDouble.New() + arr.setValues([12.,11.,10.,9.,8.,7.,6.,5.,4.,3.,2.,1.],3,4) + arr.setInfoOnComponent(0,"ggg"); + arr.setInfoOnComponent(1,"hhhh"); + arr.setInfoOnComponent(2,"jj"); + arr.setInfoOnComponent(3,"kkkkkk"); + arr2=arr.convertToIntArr(); + arr3=arr2.convertToDblArr(); + self.failUnless(arr.isEqual(arr3,1e-14)) + pass def testMesh(self): tab4=[1, 2, 8, 7, 2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, @@ -78,6 +91,757 @@ class MEDCouplingBasicsTest(unittest.TestCase): field3=mesh3.fillFromAnalytic(ON_CELLS,2,"x*IVec+(y+z)*JVec") field3.applyFunc("u*u*u+cos(u)") pass + def testMeshPointsCloud(self): + targetCoords=[-0.3,-0.3,0.5, 0.2,-0.3,1., 0.7,-0.3,1.5, + -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] + targetMesh=MEDCouplingUMesh.New(); + targetMesh.setMeshDimension(0); + targetMesh.allocateCells(8); + targetMesh.insertNextCell(NORM_POINT0,0,[]); + targetMesh.insertNextCell(NORM_POINT0,0,[]); + targetMesh.insertNextCell(NORM_POINT0,0,[]); + targetMesh.insertNextCell(NORM_POINT0,0,[]); + targetMesh.insertNextCell(NORM_POINT0,0,[]); + targetMesh.insertNextCell(NORM_POINT0,0,[]); + targetMesh.insertNextCell(NORM_POINT0,0,[]); + targetMesh.insertNextCell(NORM_POINT0,0,[]); + targetMesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(targetCoords,9,3); + targetMesh.setCoords(myCoords); + self.failUnlessEqual(targetMesh.getSpaceDimension(),3) + self.failUnlessEqual(targetMesh.getNumberOfCells(),8) + self.failUnlessEqual(targetMesh.getNumberOfNodes(),9) + self.failUnlessEqual(targetMesh.getMeshDimension(),0) + pass + def testMeshM1D(self): + meshM1D=MEDCouplingUMesh.New(); + ## CPPUNIT_ASSERT_THROW(meshM1D->getMeshDimension(),INTERP_KERNEL::Exception); + ## CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfNodes(),INTERP_KERNEL::Exception); + ## CPPUNIT_ASSERT_THROW(meshM1D->getNumberOfCells(),INTERP_KERNEL::Exception); + ## CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-2),INTERP_KERNEL::Exception); + ## CPPUNIT_ASSERT_THROW(meshM1D->setMeshDimension(-10),INTERP_KERNEL::Exception); + ## CPPUNIT_ASSERT_THROW(meshM1D->checkCoherency(),INTERP_KERNEL::Exception); + meshM1D.setMeshDimension(-1); + meshM1D.checkCoherency(); + self.failUnlessEqual(meshM1D.getMeshDimension(),-1); + self.failUnlessEqual(meshM1D.getNumberOfCells(),1); + ## CPPUNIT_ASSERT_THROW(meshM1D.getNumberOfNodes(),INTERP_KERNEL::Exception); + ## CPPUNIT_ASSERT_THROW(meshM1D.getSpaceDimension(),INTERP_KERNEL::Exception); + cpy=meshM1D.clone(True); + self.failUnless(cpy.isEqual(meshM1D,1e-12)); + fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS); + fieldOnCells.setMesh(meshM1D); + array=DataArrayDouble.New(); + array.setValues(6*[7.],1,6); + fieldOnCells.setArray(array); + fieldOnCells.checkCoherency(); + pass + def testDeepCopy(self): + array=DataArrayDouble.New(); + array.setValues(5*3*[7.],5,3); + self.failUnlessEqual(array.getIJ(3,2),7.); + array2=array.deepCopy(); + self.failUnlessEqual(array2.getIJ(3,2),7.) + # + array3=DataArrayInt.New(); + array3.setValues(5*3*[17],5,3); + self.failUnlessEqual(array3.getIJ(3,2),17); + array4=array3.deepCopy(); + self.failUnlessEqual(array4.getIJ(3,2),17); + pass + def testRevNodal(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1() + revNodal=DataArrayInt.New(); + revNodalIndx=DataArrayInt.New(); + mesh.getReverseNodalConnectivity(revNodal,revNodalIndx); + revNodalExpected=[0,0,1,1,2,0,3,0,1,2,3,4,2,4,3,3,4,4]; + revNodalIndexExpected=[0,1,3,5,7,12,14,15,17,18]; + self.failUnlessEqual(revNodal.getNbOfElems(),18) + self.failUnlessEqual(revNodalIndx.getNbOfElems(),10) + self.failUnlessEqual(revNodal.getValues(),revNodalExpected) + self.failUnlessEqual(revNodalIndx.getValues(),revNodalIndexExpected) + pass + def testConvertToPolyTypes(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + elts=[1,3]; + mesh.convertToPolyTypes(elts); + mesh.checkCoherency(); + self.failUnlessEqual(5,mesh.getNumberOfCells()); + self.failUnlessEqual(23,mesh.getNodalConnectivity().getNumberOfTuples()); + expected1=[4, 0, 3, 4, 1, 5, 1, 4, 2, 3, 4, 5, 2, 5, 6, 7, 4, 3, 4, 7, 8, 5, 4] + self.failUnlessEqual(expected1,mesh.getNodalConnectivity().getValues()); + # + mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + mesh.convertToPolyTypes(elts); + mesh.checkCoherency(); + self.failUnlessEqual(8,mesh.getNumberOfCells()); + self.failUnlessEqual(114,mesh.getNodalConnectivity().getNumberOfTuples()); + mesh.convertToPolyTypes(elts); + mesh.checkCoherency(); + self.failUnlessEqual(8,mesh.getNumberOfCells()); + self.failUnlessEqual(114,mesh.getNodalConnectivity().getNumberOfTuples()); + pass + def testDescConn2D(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + desc=DataArrayInt.New(); + descIndx=DataArrayInt.New(); + revDesc=DataArrayInt.New(); + revDescIndx=DataArrayInt.New(); + mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + mesh2.checkCoherency(); + self.failUnlessEqual(1,mesh2.getMeshDimension()); + self.failUnlessEqual(13,mesh2.getNumberOfCells()); + self.failUnlessEqual(14,revDescIndx.getNbOfElems()); self.failUnlessEqual(14,revDescIndx.getNumberOfTuples()); + self.failUnlessEqual(6,descIndx.getNbOfElems()); self.failUnlessEqual(6,descIndx.getNumberOfTuples()); + self.failUnlessEqual(18,desc.getNbOfElems()); self.failUnlessEqual(18,desc.getNumberOfTuples()); + self.failUnlessEqual(18,revDesc.getNbOfElems()); self.failUnlessEqual(18,revDesc.getNumberOfTuples()); + expected1=[0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9]; + self.failUnlessEqual(expected1,desc.getValues()); + expected2=[0,4,7,10,14,18]; + self.failUnlessEqual(expected2,descIndx.getValues()); + expected3=[0,1,3,5,6,8,9,11,12,13,15,16,17,18]; + self.failUnlessEqual(expected3,revDescIndx.getValues()); + expected4=[0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4]; + self.failUnlessEqual(expected4,revDesc.getValues()); + conn=mesh2.getNodalConnectivity(); + connIndex=mesh2.getNodalConnectivityIndex(); + expected5=[0,3,6,9,12,15,18,21,24,27,30,33,36,39]; + self.failUnlessEqual(expected5,connIndex.getValues()); + 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]; + self.failUnlessEqual(expected6,conn.getValues()); + # + eltsV=[1,3]; + mesh.convertToPolyTypes(eltsV); + mesh.checkCoherency(); + # + desc=DataArrayInt.New(); + descIndx=DataArrayInt.New(); + revDesc=DataArrayInt.New(); + revDescIndx=DataArrayInt.New(); + # + mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + mesh2.checkCoherency(); + self.failUnlessEqual(1,mesh2.getMeshDimension()); + self.failUnlessEqual(13,mesh2.getNumberOfCells()); + self.failUnlessEqual(14,revDescIndx.getNbOfElems()); self.failUnlessEqual(14,revDescIndx.getNumberOfTuples()); + self.failUnlessEqual(6,descIndx.getNbOfElems()); self.failUnlessEqual(6,descIndx.getNumberOfTuples()); + self.failUnlessEqual(18,desc.getNbOfElems()); self.failUnlessEqual(18,desc.getNumberOfTuples()); + self.failUnlessEqual(18,revDesc.getNbOfElems()); self.failUnlessEqual(18,revDesc.getNumberOfTuples()); + self.failUnlessEqual(expected1,desc.getValues()); + self.failUnlessEqual(expected2,descIndx.getValues()); + self.failUnlessEqual(expected3,revDescIndx.getValues()); + self.failUnlessEqual(expected4,revDesc.getValues()); + conn=mesh2.getNodalConnectivity(); + connIndex=mesh2.getNodalConnectivityIndex(); + self.failUnlessEqual(expected5,connIndex.getValues()); + self.failUnlessEqual(expected6,conn.getValues()); + pass + def testDescConn3D(self): + mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + desc=DataArrayInt.New(); + descIndx=DataArrayInt.New(); + revDesc=DataArrayInt.New(); + revDescIndx=DataArrayInt.New(); + # + mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + mesh2.checkCoherency(); + self.failUnlessEqual(2,mesh2.getMeshDimension()); + self.failUnlessEqual(36,mesh2.getNumberOfCells()); + self.failUnlessEqual(37,revDescIndx.getNbOfElems()); self.failUnlessEqual(37,revDescIndx.getNumberOfTuples()); + self.failUnlessEqual(9,descIndx.getNbOfElems()); self.failUnlessEqual(9,descIndx.getNumberOfTuples()); + self.failUnlessEqual(48,desc.getNbOfElems()); self.failUnlessEqual(48,desc.getNumberOfTuples()); + self.failUnlessEqual(48,revDesc.getNbOfElems()); self.failUnlessEqual(48,revDesc.getNumberOfTuples()); + expected1=[0, 6, 12, 18, 24, 30, 36, 42, 48] + 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] + 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] + 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] + 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] + 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, + 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, + 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, + 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] + 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, + 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, + 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, + 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] + + self.failUnlessEqual(expected1,descIndx.getValues()); + self.failUnlessEqual(expected2,desc.getValues()); + self.failUnlessEqual(expected3,revDescIndx.getValues()); + self.failUnlessEqual(expected4,revDesc.getValues()); + self.failUnlessEqual(expected5,mesh2.getNodalConnectivityIndex().getValues()); + self.failUnlessEqual(expected6,mesh2.getNodalConnectivity().getValues()); + # + eltsV=[1,3] + mesh.convertToPolyTypes(eltsV); + mesh.checkCoherency(); + desc=DataArrayInt.New(); + descIndx=DataArrayInt.New(); + revDesc=DataArrayInt.New(); + revDescIndx=DataArrayInt.New(); + mesh2=mesh.buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + mesh2.checkCoherency(); + self.failUnlessEqual(2,mesh2.getMeshDimension()); + self.failUnlessEqual(36,mesh2.getNumberOfCells()); + self.failUnlessEqual(37,revDescIndx.getNbOfElems()); self.failUnlessEqual(37,revDescIndx.getNumberOfTuples()); + self.failUnlessEqual(9,descIndx.getNbOfElems()); self.failUnlessEqual(9,descIndx.getNumberOfTuples()); + self.failUnlessEqual(48,desc.getNbOfElems()); self.failUnlessEqual(48,desc.getNumberOfTuples()); + self.failUnlessEqual(48,revDesc.getNbOfElems()); self.failUnlessEqual(48,revDesc.getNumberOfTuples()); + self.failUnlessEqual(expected1,descIndx.getValues()); + self.failUnlessEqual(expected2,desc.getValues()); + self.failUnlessEqual(expected3,revDescIndx.getValues()); + self.failUnlessEqual(expected4,revDesc.getValues()); + self.failUnlessEqual(expected5,mesh2.getNodalConnectivityIndex().getValues()); + self.failUnlessEqual(expected7,mesh2.getNodalConnectivity().getValues()); + pass + def testFindBoundaryNodes(self): + mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + boundaryNodes=mesh.findBoundaryNodes(); + 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]; + self.failUnlessEqual(expected1,boundaryNodes); + pass + def testBoundaryMesh(self): + mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + mesh2=mesh.buildBoundaryMesh(False); + self.failUnlessEqual(24,mesh2.getNumberOfCells()); + self.failUnlessEqual(26,mesh2.getNumberOfNodes()); + pass + def testBuildPartOfMySelf(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + mesh.setName("Toto"); + tab1=[0,4] + tab2=[0,2,3] + # + subMesh=mesh.buildPartOfMySelf(tab1,True); + self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) + name=subMesh.getName(); + self.failUnlessEqual(2,len(mesh.getAllTypes())); + self.failUnlessEqual(NORM_TRI3,mesh.getAllTypes()[0]); + self.failUnlessEqual(NORM_QUAD4,mesh.getAllTypes()[1]); + self.failUnlessEqual(1,len(subMesh.getAllTypes())); + self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.failUnlessEqual(name,"PartOf_Toto"); + self.failUnlessEqual(2,subMesh.getNumberOfCells()); + subConn=[4,0,3,4,1,4,7,8,5,4]; + subConnIndex=[0,5,10]; + self.failUnlessEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); + self.failUnlessEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.failUnlessEqual(subConn[0:10],subMesh.getNodalConnectivity().getValues()); + self.failUnlessEqual(subConnIndex[0:3],subMesh.getNodalConnectivityIndex().getValues()); + # + subMesh=mesh.buildPartOfMySelf(tab2[0:3],True); + self.failUnless(isinstance(subMesh,MEDCouplingUMesh)); + name=subMesh.getName(); + self.failUnlessEqual(2,len(subMesh.getAllTypes())); + self.failUnlessEqual(NORM_TRI3,subMesh.getAllTypes()[0]); + self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); + self.failUnlessEqual(name,"PartOf_Toto"); + self.failUnlessEqual(3,subMesh.getNumberOfCells()); + subConn2=[4,0,3,4,1,3,4,5,2,4,6,7,4,3] + subConnIndex2=[0,5,9,14] + self.failUnlessEqual(14,subMesh.getNodalConnectivity().getNbOfElems()); + self.failUnlessEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.failUnlessEqual(subConn2[0:14],subMesh.getNodalConnectivity().getValues()); + self.failUnlessEqual(subConnIndex2[0:4],subMesh.getNodalConnectivityIndex().getValues()); + pass + def testBuildPartOfMySelfNode(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + tab1=[5,7] + subMesh=mesh.buildPartOfMySelfNode(tab1[0:2],True); + self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) + self.failUnlessEqual(1,len(subMesh.getAllTypes())); + self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.failUnlessEqual(1,subMesh.getNumberOfCells()); + self.failUnlessEqual(5,subMesh.getNodalConnectivity().getNbOfElems()); + self.failUnlessEqual(2,subMesh.getNodalConnectivityIndex().getNbOfElems()); + subConn=[4,7,8,5,4] + subConnIndex=[0,5] + self.failUnlessEqual(subConn[0:5],subMesh.getNodalConnectivity().getValues()); + self.failUnlessEqual(subConnIndex[0:2],subMesh.getNodalConnectivityIndex().getValues()); + # + subMesh=mesh.buildPartOfMySelfNode(tab1[0:2],False); + self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) + self.failUnlessEqual(2,len(subMesh.getAllTypes())); + self.failUnlessEqual(NORM_TRI3,subMesh.getAllTypes()[0]); + self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); + self.failUnlessEqual(3,subMesh.getNumberOfCells()); + self.failUnlessEqual(14,subMesh.getNodalConnectivity().getNbOfElems()); + self.failUnlessEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems()); + subConn2=[3,4,5,2,4,6,7,4,3,4,7,8,5,4] + subConnIndex2=[0,4,9,14] + self.failUnlessEqual(subConn2[0:14],subMesh.getNodalConnectivity().getValues()); + self.failUnlessEqual(subConnIndex2[0:4],subMesh.getNodalConnectivityIndex().getValues()); + #testing the case where length of tab2 is greater than max number of node per cell. + tab2=[0,3,2,1,4,5,6] + subMesh=mesh.buildPartOfMySelfNode(tab2[0:7],True); + self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) + self.failUnlessEqual(2,len(subMesh.getAllTypes())); + self.failUnlessEqual(NORM_TRI3,subMesh.getAllTypes()[0]); + self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); + self.failUnlessEqual(3,subMesh.getNumberOfCells()); + pass + def testZipCoords(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + self.failUnlessEqual(2,len(mesh.getAllTypes())); + self.failUnlessEqual(2,mesh.getSpaceDimension()); + self.failUnlessEqual(9,mesh.getNumberOfNodes()); + self.failUnlessEqual(5,mesh.getNumberOfCells()); + oldConn=mesh.getNodalConnectivity().getValues()[0:mesh.getNodalConnectivity().getNbOfElems()]; + oldConnIndex=mesh.getNodalConnectivityIndex().getValues()[0:mesh.getNumberOfCells()+1] + oldCoords=mesh.getCoords(); + mesh.zipCoords(); + self.failUnlessEqual(2,len(mesh.getAllTypes())); + self.failUnlessEqual(2,mesh.getSpaceDimension()); + self.failUnlessEqual(9,mesh.getNumberOfNodes()); + self.failUnlessEqual(5,mesh.getNumberOfCells()); + self.failUnlessEqual(mesh.getCoords().getValues()[0:2*9],oldCoords.getValues()); + self.failUnlessEqual(oldConn,mesh.getNodalConnectivity().getValues()); + self.failUnlessEqual(oldConnIndex,mesh.getNodalConnectivityIndex().getValues()); + # + tab1=[0,4] + subMesh=mesh.buildPartOfMySelf(tab1,True); + self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) + traducer=subMesh.zipCoordsTraducer(); + expectedTraducer=[0,1,-1,2,3,4,-1,5,6] + self.failUnlessEqual(expectedTraducer,traducer.getValues()); + self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.failUnlessEqual(2,subMesh.getNumberOfCells()); + subConn=[4,0,2,3,1,4,5,6,4,3] + subConnIndex=[0,5,10] + self.failUnlessEqual(7,subMesh.getNumberOfNodes()); + self.failUnlessEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); + self.failUnlessEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.failUnlessEqual(subConn,subMesh.getNodalConnectivity().getValues()); + self.failUnlessEqual(subConnIndex,subMesh.getNodalConnectivityIndex().getValues()); + # + subMesh=mesh.buildPartOfMySelf(tab1,False); + self.failUnless(isinstance(subMesh,MEDCouplingUMesh)) + self.failUnlessEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.failUnlessEqual(2,subMesh.getNumberOfCells()); + self.failUnlessEqual(7,subMesh.getNumberOfNodes()); + self.failUnlessEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); + self.failUnlessEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.failUnlessEqual(subConn,subMesh.getNodalConnectivity().getValues()); + self.failUnlessEqual(subConnIndex,subMesh.getNodalConnectivityIndex().getValues()); + pass + def testZipConnectivity(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + m2=MEDCouplingDataForTest.build2DTargetMesh_1(); + cells1=[2,3,4] + m3=m2.buildPartOfMySelf(cells1,True); + self.failUnless(isinstance(m3,MEDCouplingUMesh)) + m4=MEDCouplingDataForTest.build2DSourceMesh_1(); + m5=MEDCouplingUMesh.mergeUMeshes(m1,m3); + m6=MEDCouplingUMesh.mergeUMeshes(m5,m4); + # + self.failUnlessEqual(10,m6.getNumberOfCells()); + self.failUnlessEqual(22,m6.getNumberOfNodes()); + (arr,areNodesMerged)=m6.mergeNodes(1e-13); + self.failUnless(areNodesMerged); + self.failUnlessEqual(10,m6.getNumberOfCells()); + self.failUnlessEqual(9,m6.getNumberOfNodes()); + # + arr=m6.zipConnectivityTraducer(0); + self.failUnlessEqual(7,m6.getNumberOfCells()); + m7=m6.clone(True); + arr=m6.zipConnectivityTraducer(0); + self.failUnless(m7.isEqual(m6,1e-12)); + self.failUnlessEqual(7,m6.getNumberOfCells()); + pass + def testEqualMesh(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + mesh2=MEDCouplingDataForTest.build2DTargetMesh_1(); + # + self.failUnless(mesh1.isEqual(mesh1,1e-12)); + # + self.failUnless(mesh1.isEqual(mesh2,1e-12)); + self.failUnless(mesh2.isEqual(mesh1,1e-12)); + pt=mesh2.getCoords().getValues(); + tmp=pt[1] + mesh2.getCoords().setIJ(0,1,5.999); + self.failUnless(not mesh1.isEqual(mesh2,1e-12)); + self.failUnless(not mesh2.isEqual(mesh1,1e-12)); + mesh2.getCoords().setIJ(0,1,tmp); + self.failUnless(mesh1.isEqual(mesh2,1e-12)); + self.failUnless(mesh2.isEqual(mesh1,1e-12)); + # + pt2=mesh1.getNodalConnectivity().getValues(); + mesh1.getNodalConnectivity().setIJ(5,0,pt2[5]+1); + self.failUnless(not mesh1.isEqual(mesh2,1e-12)); + self.failUnless(not mesh2.isEqual(mesh1,1e-12)); + mesh1.getNodalConnectivity().setIJ(5,0,pt2[5]); + self.failUnless(mesh1.isEqual(mesh2,1e-12)); + self.failUnless(mesh2.isEqual(mesh1,1e-12)); + # + pt2=mesh1.getNodalConnectivityIndex().getValues(); + mesh1.getNodalConnectivityIndex().setIJ(1,0,pt2[1]+1); + self.failUnless(not mesh1.isEqual(mesh2,1e-12)); + self.failUnless(not mesh2.isEqual(mesh1,1e-12)); + mesh1.getNodalConnectivityIndex().setIJ(1,0,pt2[1]); + self.failUnless(mesh1.isEqual(mesh2,1e-12)); + self.failUnless(mesh2.isEqual(mesh1,1e-12)); + # + tmp3=mesh1.getName(); + mesh1.setName("lllll"); + self.failUnless(not mesh1.isEqual(mesh2,1e-12)); + self.failUnless(not mesh2.isEqual(mesh1,1e-12)); + mesh1.setName(tmp3); + self.failUnless(mesh1.isEqual(mesh2,1e-12)); + self.failUnless(mesh2.isEqual(mesh1,1e-12)); + # + tmp3=mesh2.getCoords().getInfoOnComponent(1); + mesh2.getCoords().setInfoOnComponent(1,"kkkkkk"); + self.failUnless(not mesh1.isEqual(mesh2,1e-12)); + self.failUnless(not mesh2.isEqual(mesh1,1e-12)); + mesh2.getCoords().setInfoOnComponent(1,tmp3); + self.failUnless(mesh1.isEqual(mesh2,1e-12)); + self.failUnless(mesh2.isEqual(mesh1,1e-12)); + pass + def testEqualFieldDouble(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + mesh2=MEDCouplingDataForTest.build2DTargetMesh_1(); + # + fieldOnCells1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + fieldOnCells1.setMesh(mesh1); + fieldOnCells2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + fieldOnCells2.setMesh(mesh2); + # + self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + # + fieldOnNodes1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + self.failUnless(not fieldOnCells1.isEqual(fieldOnNodes1,1e-12,1e-15)); + self.failUnless(not fieldOnNodes1.isEqual(fieldOnCells1,1e-12,1e-15)); + # + fieldOnCells2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells1.setTime(4.,6,7); + self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2.setTime(4.,6,7); + self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells1.setName("Power"); + self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2.setName("Power"); + self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + # + fieldOnCells1.setMesh(mesh1); + self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2.setMesh(mesh1); + self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + arr=DataArrayDouble.New(); + arr.setName("popo"); + arr.setValues(mesh1.getNumberOfCells()*3*[6.],mesh1.getNumberOfCells(),3); + fieldOnCells1.setArray(arr); + self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2.setArray(arr); + self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + # + arr2=arr.deepCopy(); + fieldOnCells2.setArray(arr2); + self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + arr.setIJ(1,2,6.1); + self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + arr.setIJ(1,2,6.); + self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + arr2.setName("popo2"); + self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + # + arr2.setName("popo"); + self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + # + arr2.setInfoOnComponent(2,"jjj"); + self.failUnless(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + arr.setInfoOnComponent(2,"jjj"); + self.failUnless(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.failUnless(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + pass + def testBuildSubMeshData(self): + targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1() + #check buildSubMesh on field on cells + fieldCells=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + fieldCells.setMesh(targetMesh); + elts=[1,2,4] + ret1,di=fieldCells.buildSubMeshData(elts); + self.failUnless(isinstance(ret1,MEDCouplingUMesh)) + self.failUnlessEqual(3,ret1.getNumberOfCells()); + self.failUnlessEqual(6,ret1.getNumberOfNodes()); + self.failUnlessEqual(3,di.getNumberOfTuples()); + self.failUnlessEqual(1,di.getNumberOfComponents()); + toCheck=di.getValues(); + self.failUnless(elts,toCheck); + #check buildSubMesh on field on nodes + fieldNodes=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME); + fieldNodes.setMesh(targetMesh); + ret2,di=fieldNodes.buildSubMeshData(elts); + self.failUnless(isinstance(ret2,MEDCouplingUMesh)) + self.failUnlessEqual(3,ret2.getNumberOfCells()); + self.failUnlessEqual(6,ret2.getNumberOfNodes()); + self.failUnlessEqual(6,di.getNumberOfTuples()); + self.failUnlessEqual(1,di.getNumberOfComponents()); + toCheck=di.getValues(); + expected=[1,2,4,5,7,8] + self.failUnlessEqual(expected,toCheck); + pass + def testExtrudedMesh1(self): + mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1(); + ext=MEDCouplingExtrudedMesh.New(mesh3D,mesh2D,1); + self.failUnlessEqual(18,ext.getNumberOfCells()); + self.failUnlessEqual(60,ext.getNumberOfNodes()); + ids3D=ext.getMesh3DIds(); + ids3DExpected=[5,4,3,2,1,0, 11,10,9,8,7,6, 17,16,15,14,13,12] + self.failUnlessEqual(18,ids3D.getNumberOfTuples()); + self.failUnlessEqual(1,ids3D.getNumberOfComponents()); + self.failUnlessEqual(ids3DExpected,ids3D.getValues()); + mesh1D=ext.getMesh1D(); + self.failUnlessEqual(4,mesh1D.getNumberOfNodes()); + self.failUnlessEqual(3,mesh1D.getNumberOfCells()); + mesh1DExpected=[0.66666666666666663, 1.4583333333333333, 0, 0.66666666666666663, + 1.4583333333333333, 1, 0.66666666666666663, 1.4583333333333333, + 2, 0.66666666666666663, 1.4583333333333333, 3] + mesh1DCoords=mesh1D.getCoords(); + self.failUnlessEqual(4,mesh1DCoords.getNumberOfTuples()); + self.failUnlessEqual(3,mesh1DCoords.getNumberOfComponents()); + self.failUnlessEqual(mesh1DExpected,mesh1DCoords.getValues()); + conn1D=mesh1D.getNodalConnectivity(); + self.failUnlessEqual(9,conn1D.getNumberOfTuples()); + self.failUnlessEqual(1,conn1D.getNumberOfComponents()); + conn1DExpected=[1,0,1,1,1,2,1,2,3] + self.failUnlessEqual(conn1DExpected,conn1D.getValues()); + pass + + def testExtrudedMesh3(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + m1.changeSpaceDimension(3); + m2=MEDCouplingDataForTest.buildCU1DMesh_U(); + m2.changeSpaceDimension(3); + center=[0.,0.,0.] + vector=[0.,1.,0.] + m2.rotate(center,vector,-pi/2.); + m3=m1.buildExtrudedMeshFromThis(m2,0); + # + m4=MEDCouplingExtrudedMesh.New(m3,m1,0); + self.failUnlessEqual(15,m4.getNumberOfCells()); + self.failUnlessEqual(5,m4.getMesh2D().getNumberOfCells()); + self.failUnlessEqual(3,m4.getMesh1D().getNumberOfCells()); + m3DIds=m4.getMesh3DIds().getValues(); + self.failUnlessEqual(range(15),m3DIds); + #some random in cells to check that extrusion alg find it correctly + expected1=[1,3,2,0,6,5,7,10,11,8,12,9,14,13,4] + m3.renumberCells(expected1,False); + m4=MEDCouplingExtrudedMesh.New(m3,m1,0); + self.failUnlessEqual(15,m4.getNumberOfCells()); + self.failUnlessEqual(5,m4.getMesh2D().getNumberOfCells()); + self.failUnlessEqual(3,m4.getMesh1D().getNumberOfCells()); + m3DIds=m4.getMesh3DIds().getValues(); + self.failUnlessEqual(expected1,m3DIds); + #play with polygons and polyedrons + cells=[2,3] + m1.convertToPolyTypes(cells); + m3=m1.buildExtrudedMeshFromThis(m2,0); + self.failUnlessEqual(NORM_HEXA8,m3.getTypeOfCell(0)); + self.failUnlessEqual(NORM_PENTA6,m3.getTypeOfCell(1)); + self.failUnlessEqual(NORM_POLYHED,m3.getTypeOfCell(2)); + self.failUnlessEqual(NORM_POLYHED,m3.getTypeOfCell(3)); + self.failUnlessEqual(NORM_HEXA8,m3.getTypeOfCell(4)); + m3.renumberCells(expected1,False); + m4=MEDCouplingExtrudedMesh.New(m3,m1,0); + self.failUnlessEqual(15,m4.getNumberOfCells()); + self.failUnlessEqual(5,m4.getMesh2D().getNumberOfCells()); + self.failUnlessEqual(3,m4.getMesh1D().getNumberOfCells()); + m3DIds=m4.getMesh3DIds().getValues(); + self.failUnlessEqual(expected1,m3DIds); + pass + + def testFindCommonNodes(self): + targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + comm,commI=targetMesh.findCommonNodes(1e-10); + self.failUnlessEqual(1,commI.getNumberOfTuples()); + self.failUnlessEqual(0,comm.getNumberOfTuples()); + o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommNodesFrmt(comm,commI); + self.failUnlessEqual(27,newNbOfNodes); + self.failUnlessEqual(27,o2n.getNumberOfTuples()); + o2nExp1=range(27) + self.failUnlessEqual(o2nExp1,o2n.getValues()); + # + targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1(); + self.failUnlessEqual(31,targetMesh.getNumberOfNodes()); + comm,commI=targetMesh.findCommonNodes(1e-10); + self.failUnlessEqual(3,commI.getNumberOfTuples()); + self.failUnlessEqual(6,comm.getNumberOfTuples()); + commExpected=[1,27,28,29,23,30] + commIExpected=[0,4,6] + self.failUnlessEqual(commExpected,comm.getValues()); + self.failUnlessEqual(commIExpected,commI.getValues()); + o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommNodesFrmt(comm,commI); + self.failUnlessEqual(31,o2n.getNumberOfTuples()); + self.failUnlessEqual(27,newNbOfNodes); + o2nExp2=[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,1,1,1,23] + self.failUnlessEqual(o2nExp2,o2n.getValues()); + # + targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + time=targetMesh.getTimeOfThis(); + o2n,areNodesMerged=targetMesh.mergeNodes(1e-10); + targetMesh.updateTime(); + self.failUnlessEqual(time,targetMesh.getTimeOfThis()); + self.failUnless(not areNodesMerged); + # + targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1(); + time=targetMesh.getTimeOfThis(); + o2n,areNodesMerged=targetMesh.mergeNodes(1e-10); + targetMesh.updateTime(); + self.failUnless(time!=targetMesh.getTimeOfThis()); + self.failUnless(areNodesMerged); + 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, + 18,4,5,8,7,13,14,17,16, + 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, + 18,13,14,17,16,22,23,26,25] + self.failUnlessEqual(72,targetMesh.getNodalConnectivity().getNumberOfTuples()); + self.failUnlessEqual(connExp,targetMesh.getNodalConnectivity().getValues()); + self.failUnlessEqual(27,targetMesh.getCoords().getNumberOfTuples()); + coordsExp=[ 0., 0., 0., 50., 0., 0. , 200., 0., 0. , 0., 50., 0., 50., 50., 0. , + 200., 50., 0., 0., 200., 0., 50., 200., 0. , 200., 200., 0. , + 0., 0., 50., 50., 0., 50. , 200., 0., 50. , 0., 50., 50., 50., + 50., 50. , 200., 50., 50., 0., 200., 50., 50., 200., 50. , + 200., 200., 50. , 0., 0., 200., 50., 0., 200. , 200., 0., 200. + , 0., 50., 200., 50., 50., 200. , 200., 50., 200., + 0., 200., 200., 50., 200., 200. , 200., 200., 200. ] + self.failUnlessEqual(coordsExp,targetMesh.getCoords().getValues()); + # 2D + targetMesh=MEDCouplingDataForTest.build2DTargetMeshMergeNode_1(); + self.failUnlessEqual(18,targetMesh.getNumberOfNodes()); + time=targetMesh.getTimeOfThis(); + o2n,areNodesMerged=targetMesh.mergeNodes(1e-10); + self.failUnless(time!=targetMesh.getTimeOfThis()); + self.failUnless(areNodesMerged); + self.failUnlessEqual(9,targetMesh.getNumberOfNodes()); + connExp2=[4,0,4,3,1, 3,1,3,2, 3,3,5,2, 4,4,6,7,3, 4,7,8,5,3] + self.failUnlessEqual(23,targetMesh.getNodalConnectivity().getNumberOfTuples()); + self.failUnlessEqual(connExp2,targetMesh.getNodalConnectivity().getValues()); + 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] + self.failUnlessEqual(9,targetMesh.getCoords().getNumberOfTuples()); + self.failUnlessEqual(coordsExp2,targetMesh.getCoords().getValues()); + pass + + def testCheckButterflyCells(self): + sourceMesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + cells=sourceMesh.checkButterflyCells(); + self.failUnlessEqual(0,len(cells)); + conn=sourceMesh.getNodalConnectivity() + tmp=conn.getIJ(15,0) + conn.setIJ(15,0,conn.getIJ(16,0)) + conn.setIJ(16,0,tmp) + cells=sourceMesh.checkButterflyCells(); + self.failUnlessEqual(1,len(cells)); + self.failUnlessEqual(3,cells[0]); + tmp=conn.getIJ(15,0) + conn.setIJ(15,0,conn.getIJ(16,0)) + conn.setIJ(16,0,tmp) + cells=sourceMesh.checkButterflyCells(); + self.failUnlessEqual(0,len(cells)); + # 3D surf + sourceMesh=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + cells=sourceMesh.checkButterflyCells(); + self.failUnlessEqual(0,len(cells)); + conn=sourceMesh.getNodalConnectivity() + tmp=conn.getIJ(15,0) + conn.setIJ(15,0,conn.getIJ(16,0)) + conn.setIJ(16,0,tmp) + cells=sourceMesh.checkButterflyCells(); + self.failUnlessEqual(1,len(cells)); + self.failUnlessEqual(3,cells[0]); + tmp=conn.getIJ(15,0) + conn.setIJ(15,0,conn.getIJ(16,0)) + conn.setIJ(16,0,tmp) + cells=sourceMesh.checkButterflyCells(); + self.failUnlessEqual(0,len(cells)); + pass + + def testMergeMesh1(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + m2=MEDCouplingDataForTest.build2DSourceMesh_1(); + vec=[1.,0.] + m2.translate(vec); + m3=m1.mergeMyselfWith(m2); + self.failUnless(isinstance(m3,MEDCouplingUMesh)); + m3.checkCoherency(); + m4=MEDCouplingDataForTest.build2DTargetMeshMerged_1(); + self.failUnless(m3.isEqual(m4,1.e-12)); + da,isMerged=m3.mergeNodes(1.e-12); + self.failUnlessEqual(11,m3.getNumberOfNodes()); + self.failUnless(isMerged); + pass + + def testMergeMeshOnSameCoords1(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + m2=MEDCouplingDataForTest.build2DTargetMesh_1(); + cells=range(5); + m2.convertToPolyTypes(cells); + m1.tryToShareSameCoords(m2,1e-12); + m3=MEDCouplingDataForTest.build2DTargetMesh_1(); + m3.tryToShareSameCoords(m2,1e-12); + meshes=[m1,m2,m3] + m4=MEDCouplingUMesh.mergeUMeshesOnSameCoords(meshes); + m4.checkCoherency(); + self.failUnlessEqual(15,m4.getNumberOfCells()); + cells1=[0,1,2,3,4] + m1_1=m4.buildPartOfMySelf(cells1,True); + m1_1.setName(m1.getName()); + self.failUnless(m1.isEqual(m1_1,1e-12)); + cells2=[5,6,7,8,9] + m2_1=m4.buildPartOfMySelf(cells2,True); + m2_1.setName(m2.getName()); + self.failUnless(m2.isEqual(m2_1,1e-12)); + cells3=[10,11,12,13,14] + m3_1=m4.buildPartOfMySelf(cells3,True); + m3_1.setName(m3.getName()); + self.failUnless(m3.isEqual(m3_1,1e-12)); + pass + + def testMergeField1(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + m2=MEDCouplingDataForTest.build2DSourceMesh_1(); + vec=[1.,0.] + m2.translate(vec); + f1=m1.getMeasureField(True); + f2=m2.getMeasureField(True); + f3=MEDCouplingFieldDouble.mergeFields(f1,f2); + f3.checkCoherency(); + m4=MEDCouplingDataForTest.build2DTargetMeshMerged_1(); + self.failUnless(f3.getMesh().isEqual(m4,1.e-12)); + name=f3.getName(); + self.failUnlessEqual(name,"MeasureOfMesh_"); + self.failUnlessEqual(f3.getTypeOfField(),ON_CELLS); + self.failUnlessEqual(f3.getTimeDiscretization(),NO_TIME); + self.failUnlessEqual(1,f3.getNumberOfComponents()); + self.failUnlessEqual(7,f3.getNumberOfTuples()); + values=[0.25,0.125,0.125,0.25,0.25,0.5,0.5] + tmp=f3.getArray().getValues(); + self.failUnlessEqual(len(values),len(tmp)) + for i in xrange(7): + self.failUnless(abs(values[i]-tmp[i])<1e-12) + pass + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingDataForTest.py b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py new file mode 100644 index 000000000..97200ea65 --- /dev/null +++ b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py @@ -0,0 +1,244 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2010 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from libMEDCoupling_Swig import * + +class MEDCouplingDataForTest: + def build2DTargetMesh_1(cls): + 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 ]; + targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + targetMesh=MEDCouplingUMesh.New(); + targetMesh.setMeshDimension(2); + targetMesh.allocateCells(5); + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]); + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7]); + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10]); + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14]); + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18]); + targetMesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(targetCoords,9,2); + targetMesh.setCoords(myCoords); + return targetMesh; + def build2DSourceMesh_1(cls): + sourceCoords=[-0.3,-0.3, 0.7,-0.3, -0.3,0.7, 0.7,0.7] + sourceConn=[0,3,1,0,2,3] + sourceMesh=MEDCouplingUMesh.New("my name of mesh 2D",2); + sourceMesh.allocateCells(2); + sourceMesh.insertNextCell(NORM_TRI3,3,sourceConn[0:3]); + sourceMesh.insertNextCell(NORM_TRI3,3,sourceConn[3:6]); + sourceMesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(sourceCoords,4,2); + sourceMesh.setCoords(myCoords); + return sourceMesh; + + def build3DTargetMesh_1(cls): + targetCoords=[ 0., 0., 0., 50., 0., 0. , 200., 0., 0. , 0., 50., 0., 50., 50., 0. , 200., 50., 0., 0., 200., 0., 50., 200., 0. , 200., 200., 0. , + 0., 0., 50., 50., 0., 50. , 200., 0., 50. , 0., 50., 50., 50., 50., 50. , 200., 50., 50., 0., 200., 50., 50., 200., 50. , 200., 200., 50. , + 0., 0., 200., 50., 0., 200. , 200., 0., 200. , 0., 50., 200., 50., 50., 200. , 200., 50., 200., 0., 200., 200., 50., 200., 200. , 200., 200., 200. ]; + targetConn=[0,1,4,3,9,10,13,12, 1,2,5,4,10,11,14,13, 3,4,7,6,12,13,16,15, 4,5,8,7,13,14,17,16, + 9,10,13,12,18,19,22,21, 10,11,14,13,19,20,23,22, 12,13,16,15,21,22,25,24, 13,14,17,16,22,23,26,25]; + targetMesh=MEDCouplingUMesh.New(); + targetMesh.setMeshDimension(3); + targetMesh.allocateCells(12); + for i in xrange(8): + targetMesh.insertNextCell(NORM_HEXA8,8,targetConn[8*i:8*i+8]); + pass + targetMesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(targetCoords,27,3); + targetMesh.setCoords(myCoords); + return targetMesh + + def build3DSurfTargetMesh_1(self): + targetCoords=[-0.3,-0.3,0.5, 0.2,-0.3,1., 0.7,-0.3,1.5, -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] + targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4] + targetMesh=MEDCouplingUMesh.New(); + targetMesh.setMeshDimension(2); + targetMesh.allocateCells(5); + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10]) + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14]) + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18]) + targetMesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(targetCoords,9,3); + targetMesh.setCoords(myCoords); + return targetMesh; + + def build3DExtrudedUMesh_1(self): + coords=[ + 0.,0.,0., 1.,1.,0., 1.,1.25,0., 0.,1.,0., 1.,1.5,0., 2.,0.,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., + 0.,0.,1., 1.,1.,1., 1.,1.25,1., 0.,1.,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., 0.,1.,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., 0.,1.,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.] + + conn=[ + # 0 + 0,11,1,3,15,26,16,18, 1,2,4,7,13,6,-1,1,16,21,6,-1,6,21,28,13,-1,13,7,22,28,-1,7,4,19,22,-1,4,2,17,19,-1,2,1,16,17,-1,16,21,28,22,19,17, + 1,6,5,3,16,21,20,18, 13,10,9,6,28,25,24,21, + 11,8,7,4,2,1,-1,11,26,16,1,-1,1,16,17,2,-1,2,17,19,4,-1,4,19,22,7,-1,7,8,23,22,-1,8,11,26,23,-1,26,16,17,19,22,23, + 7,12,14,13,22,27,29,28, + # 1 + 15,26,16,18,30,41,31,33, 16,17,19,22,28,21,-1,16,31,36,21,-1,21,36,43,28,-1,28,22,37,43,-1,22,19,34,37,-1,19,17,32,34,-1,17,16,31,32,-1,31,36,43,37,34,32, + 16,21,20,18,31,36,35,33, 28,25,24,21,43,40,39,36, + 26,23,22,19,17,16,-1,26,41,31,16,-1,16,31,32,17,-1,17,32,34,19,-1,19,34,37,22,-1,22,23,38,37,-1,23,26,41,38,-1,41,31,32,34,37,38, + 22,27,29,28,37,42,44,43, + # 2 + 30,41,31,33,45,56,46,48, 31,32,34,37,43,36,-1,31,46,51,36,-1,36,51,58,43,-1,43,37,52,58,-1,37,34,49,52,-1,34,32,47,49,-1,32,31,46,47,-1,46,51,58,52,49,47, + 31,36,35,33,46,51,50,48, 43,40,39,36,58,55,54,51, + 41,38,37,34,32,31,-1,41,56,46,31,-1,31,46,47,32,-1,32,47,49,34,-1,34,49,52,37,-1,37,38,53,52,-1,38,41,56,53,-1,56,46,47,49,52,53, + 37,42,44,43,52,57,59,58] + conn2=[7,12,14,13, 11,8,7,4,2,1, 13,10,9,6, 1,6,5,3, 1,2,4,7,13,6, 0,11,1,3] + # + ret=MEDCouplingUMesh.New(); + ret.setMeshDimension(3); + ret.allocateCells(18); + # + ret.insertNextCell(NORM_HEXA8,8,conn[0:8]); + ret.insertNextCell(NORM_POLYHED,43,conn[8:51]); + ret.insertNextCell(NORM_HEXA8,8,conn[51:59]); + ret.insertNextCell(NORM_HEXA8,8,conn[59:67]); + ret.insertNextCell(NORM_POLYHED,43,conn[67:110]); + ret.insertNextCell(NORM_HEXA8,8,conn[110:118]); + # + ret.insertNextCell(NORM_HEXA8,8,conn[118:126]); + ret.insertNextCell(NORM_POLYHED,43,conn[126:169]); + ret.insertNextCell(NORM_HEXA8,8,conn[169:177]); + ret.insertNextCell(NORM_HEXA8,8,conn[177:185]); + ret.insertNextCell(NORM_POLYHED,43,conn[185:228]); + ret.insertNextCell(NORM_HEXA8,8,conn[228:236]); + # + ret.insertNextCell(NORM_HEXA8,8,conn[236:244]); + ret.insertNextCell(NORM_POLYHED,43,conn[244:287]); + ret.insertNextCell(NORM_HEXA8,8,conn[287:295]); + ret.insertNextCell(NORM_HEXA8,8,conn[295:303]); + ret.insertNextCell(NORM_POLYHED,43,conn[303:346]); + ret.insertNextCell(NORM_HEXA8,8,conn[346:354]); + # + ret.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(coords,60,3); + ret.setCoords(myCoords); + # + mesh2D=MEDCouplingUMesh.New(); + mesh2D.setMeshDimension(2); + mesh2D.allocateCells(6); + mesh2D.insertNextCell(NORM_QUAD4,4,conn2[0:4]); + mesh2D.insertNextCell(NORM_POLYGON,6,conn2[4:10]); + mesh2D.insertNextCell(NORM_QUAD4,4,conn2[10:14]); + mesh2D.insertNextCell(NORM_QUAD4,4,conn2[14:18]); + mesh2D.insertNextCell(NORM_POLYGON,6,conn2[18:24]); + mesh2D.insertNextCell(NORM_QUAD4,4,conn2[24:28]); + mesh2D.setCoords(myCoords); + return ret,mesh2D + + def buildCU1DMesh_U(self): + coords=[ 0.0, 0.3, 0.75, 1.0 ] + conn=[ 0,1, 1,2, 2,3 ] + mesh=MEDCouplingUMesh.New(); + mesh.setMeshDimension(1); + mesh.allocateCells(3); + mesh.insertNextCell(NORM_SEG2,2,conn[0:2]); + mesh.insertNextCell(NORM_SEG2,2,conn[2:4]); + mesh.insertNextCell(NORM_SEG2,2,conn[4:6]); + mesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(coords,4,1); + mesh.setCoords(myCoords); + return mesh; + + def build2DTargetMeshMergeNode_1(self): + targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,-0.3, 0.2,-0.3, 0.2,-0.3, 0.2,0.2, 0.2,0.2, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7, 0.2,0.7 ] + targetConn=[0,9,7,5, 4,6,2, 10,11,8, 9,14,15,7, 17,16,13,6] + targetMesh=MEDCouplingUMesh.New(); + targetMesh.setMeshDimension(2); + targetMesh.allocateCells(5); + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]); + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7]); + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10]); + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14]); + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18]); + targetMesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(targetCoords,18,2); + targetMesh.setCoords(myCoords); + return targetMesh; + + def build3DTargetMeshMergeNode_1(self): + targetCoords=[ 0., 0., 0., 50., 0., 0. , 200., 0., 0. , 0., 50., 0., 50., 50., 0. , 200., 50., 0., 0., 200., 0., 50., 200., 0. , 200., 200., 0. , + 0., 0., 50., 50., 0., 50. , 200., 0., 50. , 0., 50., 50., 50., 50., 50. , 200., 50., 50., 0., 200., 50., 50., 200., 50. , 200., 200., 50. , + 0., 0., 200., 50., 0., 200. , 200., 0., 200. , 0., 50., 200., 50., 50., 200. , 200., 50., 200., 0., 200., 200., 50., 200., 200. , 200., 200., 200., 50.,0.,0., 50.,0.,0., 50.,0.,0., 200., 50., 200.] + targetConn=[0,29,4,3,9,10,13,12, 28,2,5,4,10,11,14,13, 3,4,7,6,12,13,16,15, 4,5,8,7,13,14,17,16, + 9,10,13,12,18,19,22,21, 10,11,14,13,19,20,23,22, 12,13,16,15,21,22,25,24, 13,14,17,16,22,30,26,25] + targetMesh=MEDCouplingUMesh.New(); + targetMesh.setMeshDimension(3); + targetMesh.allocateCells(12); + for i in xrange(8): + targetMesh.insertNextCell(NORM_HEXA8,8,targetConn[8*i:8*(i+1)]); + pass + targetMesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(targetCoords,31,3); + targetMesh.setCoords(myCoords); + return targetMesh; + + def build2DTargetMeshMerged_1(self): + 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, + 0.7,-0.3, 1.7,-0.3, 0.7,0.7, 1.7,0.7 + ] + targetConn=[ + 0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4, + 9,12,10,9,11,12 + ] + targetMesh=MEDCouplingUMesh.New(); + targetMesh.setName("merge"); + targetMesh.setMeshDimension(2); + targetMesh.allocateCells(10); + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[4:7]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[7:10]) + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[10:14]) + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[14:18]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[18:21]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[21:24]) + targetMesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(targetCoords,13,2); + targetMesh.setCoords(myCoords); + return targetMesh; + + build2DTargetMesh_1=classmethod(build2DTargetMesh_1) + build2DSourceMesh_1=classmethod(build2DSourceMesh_1) + build3DTargetMesh_1=classmethod(build3DTargetMesh_1) + build3DSurfTargetMesh_1=classmethod(build3DSurfTargetMesh_1) + build3DExtrudedUMesh_1=classmethod(build3DExtrudedUMesh_1) + buildCU1DMesh_U=classmethod(buildCU1DMesh_U) + build2DTargetMeshMergeNode_1=classmethod(build2DTargetMeshMergeNode_1) + build3DTargetMeshMergeNode_1=classmethod(build3DTargetMeshMergeNode_1) + build2DTargetMeshMerged_1=classmethod(build2DTargetMeshMerged_1) + pass diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index 117cc6102..3408a7898 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -35,6 +35,14 @@ static PyObject *convertIntArrToPyList(const int *ptr, int size) return ret; } +static PyObject *convertIntArrToPyList2(const std::vector& li) +{ + PyObject *ret=PyList_New(li.size()); + for(int i=0;idecrRef();" +%feature("unref") MEDCouplingPointSet "$this->decrRef();" %feature("unref") MEDCouplingUMesh "$this->decrRef();" %feature("unref") MEDCouplingExtrudedMesh "$this->decrRef();" %feature("unref") DataArrayInt "$this->decrRef();" +%feature("unref") MEDCouplingField "$this->decrRef();" %feature("unref") MEDCouplingFieldDouble "$this->decrRef();" %ignore ParaMEDMEM::TimeLabel::operator=; %ignore ParaMEDMEM::MemArray::operator=; %ignore ParaMEDMEM::MemArray::operator[]; +%ignore ParaMEDMEM::MEDCouplingPointSet::getCoords(); %nodefaultctor; %include "MEDCouplingTimeLabel.hxx" %include "MEDCouplingRefCountObject.hxx" %include "MEDCouplingMesh.hxx" -%include "MEDCouplingPointSet.hxx" %include "MEDCouplingMemArray.hxx" %include "MEDCouplingMesh.hxx" %include "NormalizedUnstructuredMesh.hxx" -%include "MEDCouplingField.hxx" %include "MEDCouplingNatureOfField.hxx" +%include "MEDCouplingTimeDiscretization.hxx" namespace ParaMEDMEM { - - %extend MEDCouplingPointSet - { - PyObject *buildPartOfMySelf(PyObject *li, bool keepCoords) const - { - int size; - int *tmp=convertPyToNewIntArr2(li,&size); - MEDCouplingPointSet *ret=self->buildPartOfMySelf(tmp,tmp+size,keepCoords); - delete [] tmp; - return convertMesh(ret, SWIG_POINTER_OWN | 0 ); - } - PyObject *buildPartOfMySelfNode(PyObject *li, bool fullyIn) const - { - int size; - int *tmp=convertPyToNewIntArr2(li,&size); - MEDCouplingPointSet *ret=self->buildPartOfMySelfNode(tmp,tmp+size,fullyIn); - delete [] tmp; - return convertMesh(ret, SWIG_POINTER_OWN | 0 ); - } - PyObject *buildFacePartOfMySelfNode(PyObject *li, bool fullyIn) const - { - int size; - int *tmp=convertPyToNewIntArr2(li,&size); - MEDCouplingPointSet *ret=self->buildFacePartOfMySelfNode(tmp,tmp+size,fullyIn); - delete [] tmp; - return convertMesh(ret, SWIG_POINTER_OWN | 0 ); - } - PyObject *findBoundaryNodes() const - { - std::vector nodes; - self->findBoundaryNodes(nodes); - return convertIntArrToPyList(&nodes[0],nodes.size()); - } - void rotate(PyObject *center, PyObject *vector, double alpha) - { - double *c=convertPyToNewDblArr2(center); - if(!c) - return ; - double *v=convertPyToNewDblArr2(vector); - if(!v) - { delete [] c; return ; } - self->rotate(c,v,alpha); - delete [] c; - delete [] v; - } - void translate(PyObject *vector) - { - double *v=convertPyToNewDblArr2(vector); - self->translate(v); - delete [] v; - } - void scale(PyObject *point, double factor) - { - double *p=convertPyToNewDblArr2(point); - self->scale(p,factor); - delete [] p; - } - void renumberNodes(PyObject *li, int newNbOfNodes) - { - int size; - int *tmp=convertPyToNewIntArr2(li,&size); - self->renumberNodes(tmp,newNbOfNodes); - delete [] tmp; - } - PyObject *findNodesOnPlane(PyObject *pt, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) - { - std::vector nodes; - double *p=convertPyToNewDblArr2(pt); - double *v=convertPyToNewDblArr2(vec); - self->findNodesOnPlane(p,v,eps,nodes); - delete [] v; - delete [] p; - return convertIntArrToPyList(&nodes[0],nodes.size()); - } - } - + class MEDCouplingPointSet : public ParaMEDMEM::MEDCouplingMesh + { + public: + void updateTime(); + bool isStructured() const; + int getNumberOfNodes() const; + int getSpaceDimension() const; + void setCoords(DataArrayDouble *coords); + DataArrayDouble *getCoordinatesAndOwner() const; + bool isEqual(const MEDCouplingMesh *other, double prec) const; + bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const; + virtual DataArrayInt *mergeNodes(double precision, bool& areNodesMerged) = 0; + void getBoundingBox(double *bbox) const; + void zipCoords(); + double getCaracteristicDimension() const; + void rotate(const double *center, const double *vector, double angle); + void translate(const double *vector); + void scale(const double *point, double factor); + void changeSpaceDimension(int newSpaceDim) throw(INTERP_KERNEL::Exception); + void tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); + void findNodesOnPlane(const double *pt, const double *vec, double eps, std::vector& nodes) const throw(INTERP_KERNEL::Exception); + static DataArrayDouble *mergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2); + static MEDCouplingPointSet *buildInstanceFromMeshType(MEDCouplingMeshType type); + static void rotate2DAlg(const double *center, double angle, int nbNodes, double *coords); + static void rotate3DAlg(const double *center, const double *vect, double angle, int nbNodes, double *coords); + virtual MEDCouplingPointSet *buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const = 0; + virtual MEDCouplingPointSet *buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0; + virtual MEDCouplingPointSet *buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const = 0; + virtual void findBoundaryNodes(std::vector& nodes) const = 0; + virtual MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const = 0; + virtual void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); + virtual bool isEmptyMesh(const std::vector& tinyInfo) const = 0; + //! size of returned tinyInfo must be always the same. + void getTinySerializationInformation(std::vector& tinyInfo, std::vector& littleStrings) const; + void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; + void serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const; + void unserialization(const std::vector& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, + const std::vector& littleStrings); + virtual void giveElemsInBoundingBox(const double *bbox, double eps, std::vector& elems) = 0; + virtual void giveElemsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector& elems) = 0; + virtual DataArrayInt *zipCoordsTraducer() = 0; + %extend + { + PyObject *buildNewNumberingFromCommNodesFrmt(const DataArrayInt *comm, const DataArrayInt *commIndex) const + { + int newNbOfNodes; + DataArrayInt *ret0=self->buildNewNumberingFromCommNodesFrmt(comm,commIndex,newNbOfNodes); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_From_int(newNbOfNodes)); + return res; + } + + PyObject *findCommonNodes(double prec) const + { + DataArrayInt *comm, *commIndex; + self->findCommonNodes(comm,commIndex,prec); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(comm),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(commIndex),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return res; + } + + PyObject *getCoords() const + { + DataArrayDouble *ret1=self->getCoords(); + ret1->incrRef(); + return SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,SWIG_POINTER_OWN | 0); + } + PyObject *buildPartOfMySelf(PyObject *li, bool keepCoords) const + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + MEDCouplingPointSet *ret=self->buildPartOfMySelf(tmp,tmp+size,keepCoords); + delete [] tmp; + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); + } + PyObject *buildPartOfMySelfNode(PyObject *li, bool fullyIn) const + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + MEDCouplingPointSet *ret=self->buildPartOfMySelfNode(tmp,tmp+size,fullyIn); + delete [] tmp; + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); + } + PyObject *buildFacePartOfMySelfNode(PyObject *li, bool fullyIn) const + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + MEDCouplingPointSet *ret=self->buildFacePartOfMySelfNode(tmp,tmp+size,fullyIn); + delete [] tmp; + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); + } + PyObject *findBoundaryNodes() const + { + std::vector nodes; + self->findBoundaryNodes(nodes); + return convertIntArrToPyList(&nodes[0],nodes.size()); + } + void rotate(PyObject *center, PyObject *vector, double alpha) + { + double *c=convertPyToNewDblArr2(center); + if(!c) + return ; + double *v=convertPyToNewDblArr2(vector); + if(!v) + { delete [] c; return ; } + self->rotate(c,v,alpha); + delete [] c; + delete [] v; + } + void translate(PyObject *vector) + { + double *v=convertPyToNewDblArr2(vector); + self->translate(v); + delete [] v; + } + void scale(PyObject *point, double factor) + { + double *p=convertPyToNewDblArr2(point); + self->scale(p,factor); + delete [] p; + } + void renumberNodes(PyObject *li, int newNbOfNodes) + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + self->renumberNodes(tmp,newNbOfNodes); + delete [] tmp; + } + PyObject *findNodesOnPlane(PyObject *pt, PyObject *vec, double eps) const throw(INTERP_KERNEL::Exception) + { + std::vector nodes; + double *p=convertPyToNewDblArr2(pt); + double *v=convertPyToNewDblArr2(vec); + self->findNodesOnPlane(p,v,eps,nodes); + delete [] v; + delete [] p; + return convertIntArrToPyList(&nodes[0],nodes.size()); + } + } + }; + class MEDCouplingUMesh : public ParaMEDMEM::MEDCouplingPointSet { public: @@ -179,8 +254,6 @@ namespace ParaMEDMEM void checkCoherency() const throw(INTERP_KERNEL::Exception); void setMeshDimension(int meshDim); void allocateCells(int nbOfCells); - void setCoords(DataArrayDouble *coords); - DataArrayDouble *getCoords() const; void finishInsertingCells(); void setConnectivity(DataArrayInt *conn, DataArrayInt *connIndex, bool isComputingTypes=true); DataArrayInt *getNodalConnectivity() const; @@ -226,6 +299,37 @@ namespace ParaMEDMEM self->renumberCells(tmp,tmp+size,check); delete [] tmp; } + PyObject *checkButterflyCells() + { + std::vector cells; + self->checkButterflyCells(cells); + return convertIntArrToPyList2(cells); + } + + static PyObject *mergeUMeshesOnSameCoords(PyObject *ms) + { + std::vector meshes; + if(PyList_Check(ms)) + { + int sz=PyList_Size(ms); + meshes.resize(sz); + for(int i=0;i(arg); + } + } + else + { + PyErr_SetString(PyExc_TypeError,"mergeUMeshesOnSameCoords : not a list as first parameter"); + PyErr_Print(); + return 0; + } + MEDCouplingUMesh *ret=MEDCouplingUMesh::mergeUMeshesOnSameCoords(meshes); + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); + } } void convertToPolyTypes(const std::vector& cellIdsToConvert); MEDCouplingUMesh *buildExtrudedMeshFromThis(const MEDCouplingUMesh *mesh1D, int policy); @@ -236,6 +340,26 @@ namespace ParaMEDMEM { public: static MEDCouplingExtrudedMesh *New(const MEDCouplingUMesh *mesh3D, MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception); + %extend { + PyObject *getMesh2D() const + { + MEDCouplingUMesh *ret=self->getMesh2D(); + ret->incrRef(); + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); + } + PyObject *getMesh1D() const + { + MEDCouplingUMesh *ret=self->getMesh1D(); + ret->incrRef(); + return convertMesh(ret, SWIG_POINTER_OWN | 0 ); + } + PyObject *getMesh3DIds() const + { + DataArrayInt *ret=self->getMesh3DIds(); + ret->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } + } }; } @@ -270,15 +394,50 @@ namespace ParaMEDMEM } }; -%include "MEDCouplingField.hxx" - namespace ParaMEDMEM { + class MEDCouplingField : public ParaMEDMEM::RefCountObject, public ParaMEDMEM::TimeLabel + { + public: + virtual void checkCoherency() const; + virtual bool areCompatible(const MEDCouplingField *other) const; + virtual bool isEqual(const MEDCouplingField *other, double meshPrec, double valsPrec) const; + void setMesh(const ParaMEDMEM::MEDCouplingMesh *mesh); + void setName(const char *name); + const char *getDescription() const; + void setDescription(const char *desc); + const char *getName() const; + TypeOfField getTypeOfField() const; + MEDCouplingFieldDiscretization *getDiscretization() const; + %extend { + PyObject *getMesh() const + { + MEDCouplingMesh *ret1=(MEDCouplingMesh *)self->getMesh(); + ret1->incrRef(); + return convertMesh(ret1, SWIG_POINTER_OWN | 0 ); + } + + PyObject *buildSubMeshData(PyObject *li) const + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + DataArrayInt *ret1; + MEDCouplingMesh *ret0=self->buildSubMeshData(tmp,tmp+size,ret1); + delete [] tmp; + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,convertMesh(ret0, SWIG_POINTER_OWN | 0 )); + PyList_SetItem(res,1,SWIG_NewPointerObj((void*)ret1,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,SWIG_POINTER_OWN | 0)); + return res; + } + } + }; + class MEDCouplingFieldDouble : public ParaMEDMEM::MEDCouplingField { public: static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=NO_TIME); MEDCouplingFieldDouble *clone(bool recDeepCpy) const; + TypeOfTimeDiscretization getTimeDiscretization() const; void checkCoherency() const throw(INTERP_KERNEL::Exception); double getIJ(int tupleId, int compoId) const; void setArray(DataArrayDouble *array); @@ -286,7 +445,8 @@ namespace ParaMEDMEM void setTime(double val, int dt, int it); void setStartTime(double val, int dt, int it); void setEndTime(double val, int dt, int it); - DataArrayDouble *getArray() const { return _array; } + DataArrayDouble *getArray() const; + DataArrayDouble *getEndArray() const; void applyLin(double a, double b, int compoId); int getNumberOfComponents() const; int getNumberOfTuples() const throw(INTERP_KERNEL::Exception); @@ -297,6 +457,14 @@ namespace ParaMEDMEM void applyFunc(int nbOfComp, const char *func); void applyFunc(const char *func); static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const; + void operator+=(const MEDCouplingFieldDouble& other); + MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const; + void operator-=(const MEDCouplingFieldDouble& other); + MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const; + void operator*=(const MEDCouplingFieldDouble& other); + MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const; + void operator/=(const MEDCouplingFieldDouble& other); %extend { void setValues(PyObject *li) {