From: ageay Date: Wed, 13 Oct 2010 10:30:10 +0000 (+0000) Subject: Update from V515BR X-Git-Tag: Step0_WithoutSPLITTER~16 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9041153709ce9c59203e07e289601deb3ddde405;p=tools%2Fmedcoupling.git Update from V515BR --- diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 98db6b0d5..103638a6a 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -20,8 +20,63 @@ from libMEDCoupling_Swig import * import unittest +from math import pi,e,sqrt +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.assertTrue(arr.isEqual(arr3,1e-14)) + pass + + def testArray3(self): + arr1=DataArrayInt.New(); + arr1Ref=[0,10,1,11,2,12,3,13,4,14,5,15,6,16] + arr1.setValues(arr1Ref,7,2); + self.assertEqual(7,arr1.getNumberOfTuples()); + self.assertEqual(2,arr1.getNumberOfComponents()); + self.assertEqual(arr1Ref,list(arr1.getValues())); + arr2=arr1.substr(3); + self.assertEqual(4,arr2.getNumberOfTuples()); + self.assertEqual(2,arr2.getNumberOfComponents()); + self.assertEqual(arr1Ref[6:],list(arr2.getValues())); + arr3=arr1.substr(2,5); + self.assertEqual(3,arr3.getNumberOfTuples()); + self.assertEqual(2,arr3.getNumberOfComponents()); + self.assertEqual(arr1Ref[4:10],list(arr3.getValues())); + # + arr4=DataArrayDouble.New(); + 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] + arr4.setValues(arr4Ref,7,2); + self.assertEqual(7,arr4.getNumberOfTuples()); + self.assertEqual(2,arr4.getNumberOfComponents()); + tmp=arr4.getValues() + for i in xrange(14): + self.assertTrue(abs(arr4Ref[i]-tmp[i])<1e-14); + pass + arr5=arr4.substr(3); + self.assertEqual(4,arr5.getNumberOfTuples()); + self.assertEqual(2,arr5.getNumberOfComponents()); + tmp=arr5.getValues() + for i in xrange(8): + self.assertTrue(abs(arr4Ref[6+i]-tmp[i])<1e-14); + pass + arr6=arr4.substr(2,5); + self.assertEqual(3,arr6.getNumberOfTuples()); + self.assertEqual(2,arr6.getNumberOfComponents()); + tmp=arr6.getValues() + for i in xrange(6): + self.assertTrue(abs(arr4Ref[4+i]-tmp[i])<1e-14); + pass + pass + def testMesh(self): tab4=[1, 2, 8, 7, 2, 3, 9, 8, 3, 4, 10, 9, 4, 5, 11, 10, 5, @@ -38,23 +93,23 @@ class MEDCouplingBasicsTest(unittest.TestCase): mesh.setMeshDimension(2) mesh.allocateCells(8); mesh.setName("mesh1") - self.failUnless(mesh.getName()=="mesh1") + self.assertTrue(mesh.getName()=="mesh1") for i in range(nbOfCells): mesh.insertNextCell(NORM_QUAD4,4,tab4[4*i:4*(i+1)]); pass mesh.finishInsertingCells() - self.failUnless(mesh.getNumberOfCells()==nbOfCells) - self.failUnless(mesh.getNodalConnectivity().getNbOfElems()==30) - self.failUnless(mesh.getNodalConnectivityIndex().getNbOfElems()==nbOfCells+1) + self.assertTrue(mesh.getNumberOfCells()==nbOfCells) + self.assertTrue(mesh.getNodalConnectivity().getNbOfElems()==30) + self.assertTrue(mesh.getNodalConnectivityIndex().getNbOfElems()==nbOfCells+1) myCoords=DataArrayDouble.New() myCoords.setValues(coords,nbOfNodes,3); - self.failUnless(myCoords.getIJ(3,2)==-0.305) + self.assertTrue(myCoords.getIJ(3,2)==-0.305) mesh.setCoords(myCoords); mesh.checkCoherency(); - self.failUnless(mesh.getAllTypes()==[4]) + self.assertTrue(mesh.getAllTypes()==[4]) myFalseConn=DataArrayInt.New() myFalseConn.setValues(tab4,6,4) - self.failUnless(myFalseConn.getIJ(1,1)==3) + self.assertTrue(myFalseConn.getIJ(1,1)==3) # field=MEDCouplingFieldDouble.New(ON_CELLS) field.setMesh(mesh) @@ -65,7 +120,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): sampleTab.append(float(i)) myCoords.setValues(sampleTab,nbOfCells,9); field.setArray(myCoords) - self.failUnless(3==mesh.getSpaceDimension()) + self.assertTrue(3==mesh.getSpaceDimension()) field.checkCoherency() mesh2=mesh.clone(False) mesh3=mesh.clone(True) @@ -78,6 +133,3251 @@ 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.assertEqual(targetMesh.getSpaceDimension(),3) + self.assertEqual(targetMesh.getNumberOfCells(),8) + self.assertEqual(targetMesh.getNumberOfNodes(),9) + self.assertEqual(targetMesh.getMeshDimension(),0) + pass + def testMeshM1D(self): + meshM1D=MEDCouplingUMesh.New(); + self.assertRaises(Exception,meshM1D.getMeshDimension); + self.assertRaises(Exception,meshM1D.getNumberOfNodes); + self.assertRaises(Exception,meshM1D.getNumberOfCells); + self.assertRaises(Exception,meshM1D.setMeshDimension,-2) + self.assertRaises(Exception,meshM1D.setMeshDimension,-10) + meshM1D.setMeshDimension(-1); + meshM1D.checkCoherency(); + self.assertEqual(meshM1D.getMeshDimension(),-1); + self.assertEqual(meshM1D.getNumberOfCells(),1); + self.assertRaises(Exception,meshM1D.getNumberOfNodes); + self.assertRaises(Exception,meshM1D.getSpaceDimension); + cpy=meshM1D.clone(True); + self.assertTrue(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.assertEqual(array.getIJ(3,2),7.); + array2=array.deepCopy(); + self.assertEqual(array2.getIJ(3,2),7.) + # + array3=DataArrayInt.New(); + array3.setValues(5*3*[17],5,3); + self.assertEqual(array3.getIJ(3,2),17); + array4=array3.deepCopy(); + self.assertEqual(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.assertEqual(revNodal.getNbOfElems(),18) + self.assertEqual(revNodalIndx.getNbOfElems(),10) + self.assertEqual(list(revNodal.getValues()),revNodalExpected) + self.assertEqual(list(revNodalIndx.getValues()),revNodalIndexExpected) + pass + def testConvertToPolyTypes(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + elts=[1,3]; + mesh.convertToPolyTypes(elts); + mesh.checkCoherency(); + self.assertEqual(5,mesh.getNumberOfCells()); + self.assertEqual(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.assertEqual(expected1,list(mesh.getNodalConnectivity().getValues())); + # + mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + mesh.convertToPolyTypes(elts); + mesh.checkCoherency(); + self.assertEqual(8,mesh.getNumberOfCells()); + self.assertEqual(114,mesh.getNodalConnectivity().getNumberOfTuples()); + mesh.convertToPolyTypes(elts); + mesh.checkCoherency(); + self.assertEqual(8,mesh.getNumberOfCells()); + self.assertEqual(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.assertEqual(1,mesh2.getMeshDimension()); + self.assertEqual(13,mesh2.getNumberOfCells()); + self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples()); + self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples()); + self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples()); + self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples()); + expected1=[0,1,2,3, 2,4,5, 6,7,4, 8,9,1,10, 11,12,6,9]; + self.assertEqual(expected1,list(desc.getValues())); + expected2=[0,4,7,10,14,18]; + self.assertEqual(expected2,list(descIndx.getValues())); + expected3=[0,1,3,5,6,8,9,11,12,13,15,16,17,18]; + self.assertEqual(expected3,list(revDescIndx.getValues())); + expected4=[0, 0,3, 0,1, 0, 1,2, 1, 2,4, 2, 3, 3,4, 3, 4, 4]; + self.assertEqual(expected4,list(revDesc.getValues())); + conn=mesh2.getNodalConnectivity(); + connIndex=mesh2.getNodalConnectivityIndex(); + expected5=[0,3,6,9,12,15,18,21,24,27,30,33,36,39]; + self.assertEqual(expected5,list(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.assertEqual(expected6,list(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.assertEqual(1,mesh2.getMeshDimension()); + self.assertEqual(13,mesh2.getNumberOfCells()); + self.assertEqual(14,revDescIndx.getNbOfElems()); self.assertEqual(14,revDescIndx.getNumberOfTuples()); + self.assertEqual(6,descIndx.getNbOfElems()); self.assertEqual(6,descIndx.getNumberOfTuples()); + self.assertEqual(18,desc.getNbOfElems()); self.assertEqual(18,desc.getNumberOfTuples()); + self.assertEqual(18,revDesc.getNbOfElems()); self.assertEqual(18,revDesc.getNumberOfTuples()); + self.assertEqual(expected1,list(desc.getValues())); + self.assertEqual(expected2,list(descIndx.getValues())); + self.assertEqual(expected3,list(revDescIndx.getValues())); + self.assertEqual(expected4,list(revDesc.getValues())); + conn=mesh2.getNodalConnectivity(); + connIndex=mesh2.getNodalConnectivityIndex(); + self.assertEqual(expected5,list(connIndex.getValues())); + self.assertEqual(expected6,list(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.assertEqual(2,mesh2.getMeshDimension()); + self.assertEqual(36,mesh2.getNumberOfCells()); + self.assertEqual(37,revDescIndx.getNbOfElems()); self.assertEqual(37,revDescIndx.getNumberOfTuples()); + self.assertEqual(9,descIndx.getNbOfElems()); self.assertEqual(9,descIndx.getNumberOfTuples()); + self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples()); + self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(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.assertEqual(expected1,list(descIndx.getValues())); + self.assertEqual(expected2,list(desc.getValues())); + self.assertEqual(expected3,list(revDescIndx.getValues())); + self.assertEqual(expected4,list(revDesc.getValues())); + self.assertEqual(expected5,list(mesh2.getNodalConnectivityIndex().getValues())); + self.assertEqual(expected6,list(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.assertEqual(2,mesh2.getMeshDimension()); + self.assertEqual(36,mesh2.getNumberOfCells()); + self.assertEqual(37,revDescIndx.getNbOfElems()); self.assertEqual(37,revDescIndx.getNumberOfTuples()); + self.assertEqual(9,descIndx.getNbOfElems()); self.assertEqual(9,descIndx.getNumberOfTuples()); + self.assertEqual(48,desc.getNbOfElems()); self.assertEqual(48,desc.getNumberOfTuples()); + self.assertEqual(48,revDesc.getNbOfElems()); self.assertEqual(48,revDesc.getNumberOfTuples()); + self.assertEqual(expected1,list(descIndx.getValues())); + self.assertEqual(expected2,list(desc.getValues())); + self.assertEqual(expected3,list(revDescIndx.getValues())); + self.assertEqual(expected4,list(revDesc.getValues())); + self.assertEqual(expected5,list(mesh2.getNodalConnectivityIndex().getValues())); + self.assertEqual(expected7,list(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.assertEqual(expected1,list(boundaryNodes)); + pass + def testBoundaryMesh(self): + mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + mesh2=mesh.buildBoundaryMesh(False); + self.assertEqual(24,mesh2.getNumberOfCells()); + self.assertEqual(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.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) + name=subMesh.getName(); + self.assertEqual(2,len(mesh.getAllTypes())); + self.assertEqual(NORM_TRI3,mesh.getAllTypes()[0]); + self.assertEqual(NORM_QUAD4,mesh.getAllTypes()[1]); + self.assertEqual(1,len(subMesh.getAllTypes())); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.assertEqual(name,"PartOf_Toto"); + self.assertEqual(2,subMesh.getNumberOfCells()); + subConn=[4,0,3,4,1,4,7,8,5,4]; + subConnIndex=[0,5,10]; + self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.assertEqual(subConn[0:10],list(subMesh.getNodalConnectivity().getValues())); + self.assertEqual(subConnIndex[0:3],list(subMesh.getNodalConnectivityIndex().getValues())); + # + subMesh=mesh.buildPartOfMySelf(tab2[0:3],True); + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)); + name=subMesh.getName(); + self.assertEqual(2,len(subMesh.getAllTypes())); + self.assertEqual(NORM_TRI3,subMesh.getAllTypes()[0]); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); + self.assertEqual(name,"PartOf_Toto"); + self.assertEqual(3,subMesh.getNumberOfCells()); + subConn2=[4,0,3,4,1,3,4,5,2,4,6,7,4,3] + subConnIndex2=[0,5,9,14] + self.assertEqual(14,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(4,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.assertEqual(subConn2[0:14],list(subMesh.getNodalConnectivity().getValues())); + self.assertEqual(subConnIndex2[0:4],list(subMesh.getNodalConnectivityIndex().getValues())); + subMesh=subMesh.buildPartOfMySelf(range(3),True); + self.assertEqual("PartOf_Toto",subMesh.getName()); + pass + def testBuildPartOfMySelfNode(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + tab1=[5,7] + subMesh=mesh.buildPartOfMySelfNode(tab1[0:2],True); + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) + self.assertEqual(1,len(subMesh.getAllTypes())); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.assertEqual(1,subMesh.getNumberOfCells()); + self.assertEqual(5,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(2,subMesh.getNodalConnectivityIndex().getNbOfElems()); + subConn=[4,7,8,5,4] + subConnIndex=[0,5] + self.assertEqual(subConn[0:5],list(subMesh.getNodalConnectivity().getValues())); + self.assertEqual(subConnIndex[0:2],list(subMesh.getNodalConnectivityIndex().getValues())); + # + subMesh=mesh.buildPartOfMySelfNode(tab1[0:2],False); + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) + self.assertEqual(2,len(subMesh.getAllTypes())); + self.assertEqual(NORM_TRI3,subMesh.getAllTypes()[0]); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); + self.assertEqual(3,subMesh.getNumberOfCells()); + self.assertEqual(14,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(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.assertEqual(subConn2[0:14],list(subMesh.getNodalConnectivity().getValues())); + self.assertEqual(subConnIndex2[0:4],list(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.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) + self.assertEqual(2,len(subMesh.getAllTypes())); + self.assertEqual(NORM_TRI3,subMesh.getAllTypes()[0]); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[1]); + self.assertEqual(3,subMesh.getNumberOfCells()); + pass + def testZipCoords(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + self.assertEqual(2,len(mesh.getAllTypes())); + self.assertEqual(2,mesh.getSpaceDimension()); + self.assertEqual(9,mesh.getNumberOfNodes()); + self.assertEqual(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.assertEqual(2,len(mesh.getAllTypes())); + self.assertEqual(2,mesh.getSpaceDimension()); + self.assertEqual(9,mesh.getNumberOfNodes()); + self.assertEqual(5,mesh.getNumberOfCells()); + self.assertEqual(mesh.getCoords().getValues()[0:2*9],oldCoords.getValues()); + self.assertEqual(list(oldConn),list(mesh.getNodalConnectivity().getValues())); + self.assertEqual(list(oldConnIndex),list(mesh.getNodalConnectivityIndex().getValues())); + # + tab1=[0,4] + subMesh=mesh.buildPartOfMySelf(tab1,True); + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) + traducer=subMesh.zipCoordsTraducer(); + expectedTraducer=[0,1,3,4,5,7,8] + self.assertEqual(expectedTraducer,list(traducer.getValues())); + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.assertEqual(2,subMesh.getNumberOfCells()); + subConn=[4,0,2,3,1,4,5,6,4,3] + subConnIndex=[0,5,10] + self.assertEqual(7,subMesh.getNumberOfNodes()); + self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.assertEqual(subConn,list(subMesh.getNodalConnectivity().getValues())); + self.assertEqual(subConnIndex,list(subMesh.getNodalConnectivityIndex().getValues())); + # + subMesh=mesh.buildPartOfMySelf(tab1,False); + self.assertTrue(isinstance(subMesh,MEDCouplingUMesh)) + self.assertEqual(NORM_QUAD4,subMesh.getAllTypes()[0]); + self.assertEqual(2,subMesh.getNumberOfCells()); + self.assertEqual(7,subMesh.getNumberOfNodes()); + self.assertEqual(10,subMesh.getNodalConnectivity().getNbOfElems()); + self.assertEqual(3,subMesh.getNodalConnectivityIndex().getNbOfElems()); + self.assertEqual(subConn,list(subMesh.getNodalConnectivity().getValues())); + self.assertEqual(subConnIndex,list(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.assertTrue(isinstance(m3,MEDCouplingUMesh)) + m4=MEDCouplingDataForTest.build2DSourceMesh_1(); + m5=MEDCouplingUMesh.mergeUMeshes(m1,m3); + m6=MEDCouplingUMesh.mergeUMeshes(m5,m4); + # + self.assertEqual(10,m6.getNumberOfCells()); + self.assertEqual(22,m6.getNumberOfNodes()); + (arr,areNodesMerged,newNbOfNodes)=m6.mergeNodes(1e-13); + self.assertTrue(areNodesMerged); + self.assertEqual(10,m6.getNumberOfCells()); + self.assertEqual(9,m6.getNumberOfNodes()); + # + arr=m6.zipConnectivityTraducer(0); + self.assertEqual(7,m6.getNumberOfCells()); + m7=m6.clone(True); + arr=m6.zipConnectivityTraducer(0); + self.assertTrue(m7.isEqual(m6,1e-12)); + self.assertEqual(7,m6.getNumberOfCells()); + pass + def testEqualMesh(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + mesh2=MEDCouplingDataForTest.build2DTargetMesh_1(); + # + self.assertTrue(mesh1.isEqual(mesh1,1e-12)); + # + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); + pt=mesh2.getCoords().getValues(); + tmp=pt[1] + mesh2.getCoords().setIJ(0,1,5.999); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh2.isEqual(mesh1,1e-12)); + mesh2.getCoords().setIJ(0,1,tmp); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); + # + pt2=mesh1.getNodalConnectivity().getValues(); + mesh1.getNodalConnectivity().setIJ(5,0,int(pt2[5])+1); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh2.isEqual(mesh1,1e-12)); + mesh1.getNodalConnectivity().setIJ(5,0,int(pt2[5])); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); + # + pt2=mesh1.getNodalConnectivityIndex().getValues(); + mesh1.getNodalConnectivityIndex().setIJ(1,0,int(pt2[1]+1)); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh2.isEqual(mesh1,1e-12)); + mesh1.getNodalConnectivityIndex().setIJ(1,0,int(pt2[1])); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); + # + tmp3=mesh1.getName(); + mesh1.setName("lllll"); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh2.isEqual(mesh1,1e-12)); + mesh1.setName(tmp3); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh2.isEqual(mesh1,1e-12)); + # + tmp3=mesh2.getCoords().getInfoOnComponent(1); + mesh2.getCoords().setInfoOnComponent(1,"kkkkkk"); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh2.isEqual(mesh1,1e-12)); + mesh2.getCoords().setInfoOnComponent(1,tmp3); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(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.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + # + fieldOnNodes1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnNodes1,1e-12,1e-15)); + self.assertTrue(not fieldOnNodes1.isEqual(fieldOnCells1,1e-12,1e-15)); + # + fieldOnCells2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells1.setTime(4.,6,7); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2.setTime(4.,6,7); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells1.setName("Power"); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2.setName("Power"); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + # + fieldOnCells1.setMesh(mesh1); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2.setMesh(mesh1); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(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.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + fieldOnCells2.setArray(arr); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + # + arr2=arr.deepCopy(); + fieldOnCells2.setArray(arr2); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + arr.setIJ(1,2,6.1); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + arr.setIJ(1,2,6.); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + arr2.setName("popo2"); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + # + arr2.setName("popo"); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + # + arr2.setInfoOnComponent(2,"jjj"); + self.assertTrue(not fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(not fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + arr.setInfoOnComponent(2,"jjj"); + self.assertTrue(fieldOnCells1.isEqual(fieldOnCells2,1e-12,1e-15)); + self.assertTrue(fieldOnCells2.isEqual(fieldOnCells1,1e-12,1e-15)); + pass + + def testNatureChecking(self): + field=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + field.setNature(Integral); + field.setNature(ConservativeVolumic); + field.setNature(IntegralGlobConstraint); + field=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME); + field.setNature(ConservativeVolumic); + self.assertRaises(Exception,field.setNature,Integral); + self.assertRaises(Exception,field.setNature,IntegralGlobConstraint); + 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.assertTrue(isinstance(ret1,MEDCouplingUMesh)) + self.assertEqual(3,ret1.getNumberOfCells()); + self.assertEqual(6,ret1.getNumberOfNodes()); + self.assertEqual(3,di.getNumberOfTuples()); + self.assertEqual(1,di.getNumberOfComponents()); + toCheck=di.getValues(); + self.assertTrue(elts,toCheck); + #check buildSubMesh on field on nodes + fieldNodes=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME); + fieldNodes.setMesh(targetMesh); + ret2,di=fieldNodes.buildSubMeshData(elts); + self.assertTrue(isinstance(ret2,MEDCouplingUMesh)) + self.assertEqual(3,ret2.getNumberOfCells()); + self.assertEqual(6,ret2.getNumberOfNodes()); + self.assertEqual(6,di.getNumberOfTuples()); + self.assertEqual(1,di.getNumberOfComponents()); + toCheck=di.getValues(); + expected=[1,2,4,5,7,8] + self.assertEqual(expected,list(toCheck)); + pass + def testExtrudedMesh1(self): + mesh3D,mesh2D=MEDCouplingDataForTest.build3DExtrudedUMesh_1(); + ext=MEDCouplingExtrudedMesh.New(mesh3D,mesh2D,1); + self.assertEqual(18,ext.getNumberOfCells()); + self.assertEqual(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.assertEqual(18,ids3D.getNumberOfTuples()); + self.assertEqual(1,ids3D.getNumberOfComponents()); + self.assertEqual(ids3DExpected,list(ids3D.getValues())); + mesh1D=ext.getMesh1D(); + self.assertEqual(4,mesh1D.getNumberOfNodes()); + self.assertEqual(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.assertEqual(4,mesh1DCoords.getNumberOfTuples()); + self.assertEqual(3,mesh1DCoords.getNumberOfComponents()); + self.assertEqual(mesh1DExpected,mesh1DCoords.getValues()); + conn1D=mesh1D.getNodalConnectivity(); + self.assertEqual(9,conn1D.getNumberOfTuples()); + self.assertEqual(1,conn1D.getNumberOfComponents()); + conn1DExpected=[1,0,1,1,1,2,1,2,3] + self.assertEqual(conn1DExpected,list(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.assertEqual(15,m4.getNumberOfCells()); + self.assertEqual(5,m4.getMesh2D().getNumberOfCells()); + self.assertEqual(3,m4.getMesh1D().getNumberOfCells()); + m3DIds=m4.getMesh3DIds().getValues(); + self.assertEqual(range(15),list(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.assertEqual(15,m4.getNumberOfCells()); + self.assertEqual(5,m4.getMesh2D().getNumberOfCells()); + self.assertEqual(3,m4.getMesh1D().getNumberOfCells()); + m3DIds=m4.getMesh3DIds().getValues(); + self.assertEqual(expected1,list(m3DIds)); + #play with polygons and polyedrons + cells=[2,3] + m1.convertToPolyTypes(cells); + m3=m1.buildExtrudedMeshFromThis(m2,0); + self.assertEqual(NORM_HEXA8,m3.getTypeOfCell(0)); + self.assertEqual(NORM_PENTA6,m3.getTypeOfCell(1)); + self.assertEqual(NORM_POLYHED,m3.getTypeOfCell(2)); + self.assertEqual(NORM_POLYHED,m3.getTypeOfCell(3)); + self.assertEqual(NORM_HEXA8,m3.getTypeOfCell(4)); + m3.renumberCells(expected1,False); + m4=MEDCouplingExtrudedMesh.New(m3,m1,0); + self.assertEqual(15,m4.getNumberOfCells()); + self.assertEqual(5,m4.getMesh2D().getNumberOfCells()); + self.assertEqual(3,m4.getMesh1D().getNumberOfCells()); + m3DIds=m4.getMesh3DIds().getValues(); + self.assertEqual(expected1,list(m3DIds)); + pass + + def testExtrudedMesh4(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + cells=[2,4]; + m1.convertToPolyTypes(cells); + 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); + expected1=[1,3,2,0,6,5,7,10,11,8,12,9,14,13,4] + rexpected1=[3, 0, 2, 1, 14, 5, 4, 6, 9, 11, 7, 8, 10, 13, 12] + m3.renumberCells(expected1,False); + m4=MEDCouplingExtrudedMesh.New(m3,m1,0); + self.assertEqual(NORM_HEXA8,m4.getTypeOfCell(0)); + self.assertEqual(NORM_HEXA8,m4.getTypeOfCell(1)); + self.assertEqual(NORM_POLYHED,m4.getTypeOfCell(2)); + self.assertEqual(NORM_PENTA6,m4.getTypeOfCell(7)); + f=m4.getMeasureField(True); + arr=f.getArray(); + self.assertEqual(15,arr.getNumberOfTuples()); + self.assertEqual(1,arr.getNumberOfComponents()); + arrPtr=arr.getValues(); + expected2=[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] + for i in xrange(15): + self.assertAlmostEqual(expected2[rexpected1[i]],arrPtr[i],16); + pass + m5=m4.build3DUnstructuredMesh(); + self.assertTrue(m5.isEqual(m3,1e-12)); + f=m5.getMeasureField(True); + arr=f.getArray(); + arrPtr=arr.getValues(); + for i in xrange(15): + self.assertAlmostEqual(expected2[rexpected1[i]],arrPtr[i],15); + pass + pass + + def testFindCommonNodes(self): + targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + comm,commI=targetMesh.findCommonNodes(-1,1e-10); + self.assertEqual(1,commI.getNumberOfTuples()); + self.assertEqual(0,comm.getNumberOfTuples()); + o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommNodesFrmt(comm,commI); + self.assertEqual(27,newNbOfNodes); + self.assertEqual(27,o2n.getNumberOfTuples()); + o2nExp1=range(27) + self.assertEqual(o2nExp1,list(o2n.getValues())); + # + targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1(); + self.assertEqual(31,targetMesh.getNumberOfNodes()); + comm,commI=targetMesh.findCommonNodes(-1,1e-10); + self.assertEqual(3,commI.getNumberOfTuples()); + self.assertEqual(6,comm.getNumberOfTuples()); + commExpected=[1,27,28,29,23,30] + commIExpected=[0,4,6] + self.assertEqual(commExpected,list(comm.getValues())); + self.assertEqual(commIExpected,list(commI.getValues())); + o2n,newNbOfNodes=targetMesh.buildNewNumberingFromCommNodesFrmt(comm,commI); + self.assertEqual(31,o2n.getNumberOfTuples()); + self.assertEqual(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.assertEqual(o2nExp2,list(o2n.getValues())); + # + targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + time=targetMesh.getTimeOfThis(); + o2n,areNodesMerged,newNbOfNodes=targetMesh.mergeNodes(1e-10); + targetMesh.updateTime(); + self.assertEqual(time,targetMesh.getTimeOfThis()); + self.assertTrue(not areNodesMerged); + # + targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1(); + time=targetMesh.getTimeOfThis(); + o2n,areNodesMerged,newNbOfNodes=targetMesh.mergeNodes(1e-10); + targetMesh.updateTime(); + self.assertTrue(time!=targetMesh.getTimeOfThis()); + self.assertTrue(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.assertEqual(72,targetMesh.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(connExp,list(targetMesh.getNodalConnectivity().getValues())); + self.assertEqual(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.assertEqual(coordsExp,targetMesh.getCoords().getValues()); + # 2D + targetMesh=MEDCouplingDataForTest.build2DTargetMeshMergeNode_1(); + self.assertEqual(18,targetMesh.getNumberOfNodes()); + time=targetMesh.getTimeOfThis(); + o2n,areNodesMerged,newNbOfNodes=targetMesh.mergeNodes(1e-10); + self.assertTrue(time!=targetMesh.getTimeOfThis()); + self.assertTrue(areNodesMerged); + self.assertEqual(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.assertEqual(23,targetMesh.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(connExp2,list(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.assertEqual(9,targetMesh.getCoords().getNumberOfTuples()); + self.assertEqual(coordsExp2,targetMesh.getCoords().getValues()); + pass + + def testCheckButterflyCells(self): + sourceMesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + cells=sourceMesh.checkButterflyCells(); + self.assertEqual(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.assertEqual(1,len(cells)); + self.assertEqual(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.assertEqual(0,len(cells)); + # 3D surf + sourceMesh=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + cells=sourceMesh.checkButterflyCells(); + self.assertEqual(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.assertEqual(1,len(cells)); + self.assertEqual(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.assertEqual(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.assertTrue(isinstance(m3,MEDCouplingUMesh)); + m3.checkCoherency(); + m4=MEDCouplingDataForTest.build2DTargetMeshMerged_1(); + self.assertTrue(m3.isEqual(m4,1.e-12)); + da,isMerged,newNbOfNodes=m3.mergeNodes(1.e-12); + self.assertEqual(11,m3.getNumberOfNodes()); + self.assertTrue(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.assertEqual(15,m4.getNumberOfCells()); + cells1=[0,1,2,3,4] + m1_1=m4.buildPartOfMySelf(cells1,True); + m1_1.setName(m1.getName()); + self.assertTrue(m1.isEqual(m1_1,1e-12)); + cells2=[5,6,7,8,9] + m2_1=m4.buildPartOfMySelf(cells2,True); + m2_1.setName(m2.getName()); + self.assertTrue(m2.isEqual(m2_1,1e-12)); + cells3=[10,11,12,13,14] + m3_1=m4.buildPartOfMySelf(cells3,True); + m3_1.setName(m3.getName()); + self.assertTrue(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.assertTrue(f3.getMesh().isEqual(m4,1.e-12)); + name=f3.getName(); + self.assertEqual(name,"MeasureOfMesh_"); + self.assertEqual(f3.getTypeOfField(),ON_CELLS); + self.assertEqual(f3.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f3.getNumberOfComponents()); + self.assertEqual(7,f3.getNumberOfTuples()); + values=[0.25,0.125,0.125,0.25,0.25,0.5,0.5] + tmp=f3.getArray().getValues(); + self.assertEqual(len(values),len(tmp)) + for i in xrange(7): + self.assertTrue(abs(values[i]-tmp[i])<1e-12) + pass + pass + + def testFillFromAnalytic(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=m.fillFromAnalytic(ON_CELLS,1,"x+y"); + f1.checkCoherency(); + self.assertEqual(f1.getTypeOfField(),ON_CELLS); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(5,f1.getNumberOfTuples()); + values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9] + tmp=f1.getArray().getValues(); + self.assertEqual(len(values1),len(tmp)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values1[i])<1.e-12) + pass + # + f1=m.fillFromAnalytic(ON_NODES,1,"x+y"); + f1.checkCoherency(); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + values2=[-0.6,-0.1,0.4,-0.1,0.4,0.9,0.4,0.9,1.4] + tmp=f1.getArray().getValues(); + self.assertEqual(len(values2),len(tmp)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values2[i])<1.e-12) + pass + # + f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+(2*(x+y))*JVec"); + f1.checkCoherency(); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + 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] + tmp=f1.getArray().getValues(); + self.assertEqual(len(values3),len(tmp)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values3[i])<1.e-12) + pass + values4=f1.accumulate(); + self.assertTrue(abs(3.6-values4[0])<1.e-12); + self.assertTrue(abs(7.2-values4[1])<1.e-12); + values4=f1.integral(True); + self.assertTrue(abs(0.5-values4[0])<1.e-12); + self.assertTrue(abs(1.-values4[1])<1.e-12); + # + self.assertRaises(Exception,m.fillFromAnalytic,ON_NODES,1,"1./(x-0.2)"); + pass + + def testFillFromAnalytic2(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=m.fillFromAnalytic(ON_CELLS,1,"y+x"); + f1.checkCoherency(); + self.assertEqual(f1.getTypeOfField(),ON_CELLS); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(5,f1.getNumberOfTuples()); + values1=[-0.1,0.23333333333333336,0.56666666666666665,0.4,0.9] + tmp=f1.getArray().getValues(); + self.assertEqual(len(values1),len(tmp)) + for i in xrange(len(values1)): + self.assertTrue(abs(values1[i]-tmp[i])<1.e-12); + pass + # + f1=m.fillFromAnalytic(ON_NODES,1,"y+2*x"); + f1.checkCoherency(); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + values2=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1] + tmp=f1.getArray().getValues(); + self.assertEqual(len(values2),len(tmp)) + for i in xrange(len(values2)): + self.assertTrue(abs(values2[i]-tmp[i])<1.e-12); + pass + f1=m.fillFromAnalytic(ON_NODES,1,"2.*x+y"); + f1.checkCoherency(); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + tmp=f1.getArray().getValues(); + values2Bis=[-0.9,0.1,1.1,-0.4,0.6,1.6,0.1,1.1,2.1] + self.assertEqual(len(values2Bis),len(tmp)) + for i in xrange(len(values2Bis)): + self.assertTrue(abs(values2Bis[i]-tmp[i])<1.e-12); + pass + # + f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec"); + f1.checkCoherency(); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + 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] + tmp=f1.getArray().getValues(); + self.assertEqual(len(values3),len(tmp)) + for i in xrange(len(values3)): + self.assertTrue(abs(values3[i]-tmp[i])<1.e-12); + pass + values4=f1.accumulate(); + self.assertTrue(abs(3.6-values4[0])<1.e-12); + self.assertTrue(abs(7.2-values4[1])<1.e-12); + values4=f1.integral(True); + self.assertTrue(abs(0.5-values4[0])<1.e-12); + self.assertTrue(abs(1.-values4[1])<1.e-12); + pass + + def testApplyFunc(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+(2*(x+y))*JVec"); + f1.checkCoherency(); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + f1.applyFunc(1,"x+y"); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + values1=[-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2] + tmp=f1.getArray().getValues(); + self.assertEqual(len(values1),len(tmp)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values1[i])<1.e-12) + pass + pass + + def testApplyFunc2(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=m.fillFromAnalytic(ON_NODES,2,"(x+y)*IVec+2*(x+y)*JVec"); + f1.checkCoherency(); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + # + f2=f1.clone(True); + f2.applyFunc("abs(u)^2.4+2*u"); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + values2=[-0.9065304805418678, -0.85105859001709905, -0.19601892829446504, -0.37898777756476987, + 0.91090317490482353, 2.1853504664669781, -0.19601892829446504, -0.37898777756476987, + 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295, + 0.91090317490482353, 2.1853504664669781, 2.5765725275664879, 7.6987743736515295, + 5.0423700574830965, 17.435300118916864] + tmp=f2.getArray().getValues(); + self.assertEqual(len(tmp),len(values2)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values2[i])<1.e-12) + pass + # + f1.applyFunc(1,"x+y"); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + values1=[-1.8,-0.3,1.2,-0.3,1.2,2.7,1.2,2.7,4.2] + tmp=f1.getArray().getValues(); + self.assertEqual(len(tmp),len(values1)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values1[i])<1.e-12) + pass + pass + + def testOperationsOnFields(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=m.fillFromAnalytic(ON_NODES,1,"x+y"); + f2=m.fillFromAnalytic(ON_NODES,1,"x+y"); + f1.checkCoherency(); + f2.checkCoherency(); + f3=f1+f2; + f3.checkCoherency(); + self.assertEqual(f3.getTypeOfField(),ON_NODES); + self.assertEqual(f3.getTimeDiscretization(),NO_TIME); + values1=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8] + tmp=f3.getArray().getValues(); + self.assertEqual(len(values1),len(tmp)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values1[i])<1.e-12) + pass + # + f3=f1*f2; + f3.checkCoherency(); + self.assertEqual(f3.getTypeOfField(),ON_NODES); + self.assertEqual(f3.getTimeDiscretization(),NO_TIME); + values2=[0.36,0.01,0.16,0.01,0.16,0.81,0.16,0.81,1.96] + tmp=f3.getArray().getValues(); + self.assertEqual(len(values2),len(tmp)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values2[i])<1.e-12) + pass + # + f3=f1+f2; + f4=f1-f3; + f4.checkCoherency(); + self.assertEqual(f4.getTypeOfField(),ON_NODES); + self.assertEqual(f4.getTimeDiscretization(),NO_TIME); + values3=[0.6,0.1,-0.4,0.1,-0.4,-0.9,-0.4,-0.9,-1.4] + tmp=f4.getArray().getValues(); + self.assertEqual(len(values3),len(tmp)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values3[i])<1.e-12) + pass + # + f3=f1+f2; + f4=f3/f2; + f4.checkCoherency(); + self.assertEqual(f4.getTypeOfField(),ON_NODES); + self.assertEqual(f4.getTimeDiscretization(),NO_TIME); + tmp=f4.getArray().getValues(); + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-2.)<1.e-12) + pass + # + f4=f2.buildNewTimeReprFromThis(ONE_TIME,False); + f4.checkCoherency(); + self.assertEqual(f4.getTypeOfField(),ON_NODES); + self.assertEqual(f4.getTimeDiscretization(),ONE_TIME); + self.assertRaises(Exception,f1.__add__,f4); + f5=f4.buildNewTimeReprFromThis(NO_TIME,False); + self.assertEqual(f5.getTypeOfField(),ON_NODES); + self.assertEqual(f5.getTimeDiscretization(),NO_TIME); + f3=f1+f5; + tmp=f3.getArray().getValues(); + values4=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8] + self.assertEqual(len(values3),len(tmp)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values4[i])<1.e-12) + pass + # + f4=f2.buildNewTimeReprFromThis(ONE_TIME,True); + f4.checkCoherency(); + self.assertEqual(f4.getTypeOfField(),ON_NODES); + self.assertEqual(f4.getTimeDiscretization(),ONE_TIME); + self.assertRaises(Exception,f1.__add__,f4); + f5=f4.buildNewTimeReprFromThis(NO_TIME,True); + self.assertEqual(f5.getTypeOfField(),ON_NODES); + self.assertEqual(f5.getTimeDiscretization(),NO_TIME); + f3=f1+f5; + tmp=f3.getArray().getValues(); + values5=[-1.2,-0.2,0.8,-0.2,0.8,1.8,0.8,1.8,2.8] + self.assertEqual(len(values5),len(tmp)) + for i in xrange(len(tmp)): + self.assertTrue(abs(tmp[i]-values5[i])<1.e-12) + pass + pass + + def testOperationsOnFields2(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + f1=m.fillFromAnalytic(ON_NODES,1,"x+y+z"); + f2=m.fillFromAnalytic(ON_NODES,1,"a*a+b+c*c"); + f3=f1/f2; + f3.checkCoherency(); + self.assertEqual(f3.getTypeOfField(),ON_NODES); + self.assertEqual(f3.getTimeDiscretization(),NO_TIME); + expected1=[-2.4999999999999991, 1.2162162162162162, 0.77868852459016391, + 0.7407407407407407, 1.129032258064516, 0.81632653061224492, + 0.86538461538461531, 1.0919540229885056, 0.84302325581395343] + self.assertEqual(1,f3.getNumberOfComponents()); + self.assertEqual(9,f3.getNumberOfTuples()); + val=f3.getArray().getValues(); + for i in xrange(9): + self.assertTrue(abs(expected1[i]-val[i])<1.e-12); + # + f1=m.buildOrthogonalField(); + f2=m.fillFromAnalytic(ON_CELLS,1,"x"); + f3=f1*f2; + 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] + val=f3.getArray().getValues(); + for i in xrange(15): + self.assertTrue(abs(expected2[i]-val[i])<1.e-12); + pass + # + f3=f2*f1; + val=f3.getArray().getValues(); + for i in xrange(15): + self.assertTrue(abs(expected2[i]-val[i])<1.e-12); + pass + pass + + def testOperationsOnFields3(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + f1=m.fillFromAnalytic(ON_NODES,1,"x+y+z"); + f2=m.fillFromAnalytic(ON_NODES,1,"a*a+b+c*c"); + f1/=f2 + f1.checkCoherency(); + self.assertEqual(f1.getTypeOfField(),ON_NODES); + self.assertEqual(f1.getTimeDiscretization(),NO_TIME); + expected1=[-2.4999999999999991, 1.2162162162162162, 0.77868852459016391, + 0.7407407407407407, 1.129032258064516, 0.81632653061224492, + 0.86538461538461531, 1.0919540229885056, 0.84302325581395343] + self.assertEqual(1,f1.getNumberOfComponents()); + self.assertEqual(9,f1.getNumberOfTuples()); + val=f1.getArray().getValues(); + for i in xrange(9): + self.assertTrue(abs(expected1[i]-val[i])<1.e-12); + pass + # + f1=m.buildOrthogonalField(); + f2=m.fillFromAnalytic(ON_CELLS,1,"x"); + f1*=f2 + 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] + val=f1.getArray().getValues(); + for i in xrange(15): + self.assertTrue(abs(expected2[i]-val[i])<1.e-12); + pass + # + f1=m.buildOrthogonalField(); + # to avoid valgrind leaks + # self.assertRaises(Exception,f2.__imul__,f1); + pass + + def testOperationsOnFields4(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + nbOfCells=m.getNumberOfCells(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL); + f1.setMesh(m); + array=DataArrayDouble.New(); + f1.setArray(array); + self.assertRaises(Exception,f1.setEndArray,array); + self.assertRaises(Exception,f1.getEndArray); + arr1=[0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.] + arr2=[5.,15.,25.,6.,16.,26.,7.,17.,27.,8.,18.,28.,9.,19.,29.] + array.setValues(arr1,nbOfCells,3); + f1.setStartTime(2.,0,0); + f1.setEndTime(3.,0,0); + f1.checkCoherency(); + pos=[0.3,-0.2] + res=f1.getValueOn(pos); + self.assertTrue(abs(arr1[3]-res[0])<1.e-12); + self.assertTrue(abs(arr1[4]-res[1])<1.e-12); + self.assertTrue(abs(arr1[5]-res[2])<1.e-12); + res=None + res=f1.getValueOn(pos,2.2); + self.assertTrue(abs(arr1[3]-res[0])<1.e-12); + self.assertTrue(abs(arr1[4]-res[1])<1.e-12); + self.assertTrue(abs(arr1[5]-res[2])<1.e-12); + res=None + self.assertRaises(Exception,f1.getValueOn,pos,3.2) + f2=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME); + f2.setMesh(m); + f2.setArray(f1.getArray()); + f2.setStartTime(2.,3,0); + f2.setEndTime(4.,13,0); + self.assertRaises(Exception,f2.checkCoherency) + array2=DataArrayDouble.New(); + array2.setValues(arr2,nbOfCells,3); + f2.setEndArray(array2); + f2.checkCoherency(); + # + res=None + res=f2.getValueOn(pos,3.21); + self.assertTrue(abs(4.025-res[0])<1.e-12); + self.assertTrue(abs(14.025-res[1])<1.e-12); + self.assertTrue(abs(24.025-res[2])<1.e-12); + f3=f2.clone(True); + self.assertTrue(f2.isEqual(f3,1e-12,1e-12)); + f3.getEndArray().setIJ(0,0,5.001); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-12)); + self.assertTrue(f2.isEqual(f3,1e-12,1e-2)); + f3.setStartTime(2.1,3,0); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); + f3.setStartTime(2.,3,0); + self.assertTrue(f2.isEqual(f3,1e-12,1e-2)); + f3.setStartTime(2.,4,0); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); + f3.setStartTime(2.,3,1); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); + f3.setStartTime(2.,3,0); + self.assertTrue(f2.isEqual(f3,1e-12,1e-2)); + f3.setEndTime(4.1,13,0); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); + f3.setEndTime(4.,13,0); + self.assertTrue(f2.isEqual(f3,1e-12,1e-2)); + f3.setEndTime(4.,14,0); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); + f3.setEndTime(4.,13,1); + self.assertTrue(not f2.isEqual(f3,1e-12,1e-2)); + f3.setEndTime(4.,13,0); + self.assertTrue(f2.isEqual(f3,1e-12,1e-2)); + f4=f2+f2 + res=None + res=f4.getValueOn(pos,3.21); + self.assertTrue(abs(8.05-res[0])<1.e-12); + self.assertTrue(abs(28.05-res[1])<1.e-12); + self.assertTrue(abs(48.05-res[2])<1.e-12); + f4+=f2; + res=None + res=f4.getValueOn(pos,3.21); + self.assertTrue(abs(12.075-res[0])<1.e-12); + self.assertTrue(abs(42.075-res[1])<1.e-12); + self.assertTrue(abs(72.075-res[2])<1.e-12); + pass + + def testMergeNodesOnField(self): + targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1(); + f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z"); + f1.mergeNodes(1e-10); + # + targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1(); + f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z"); + tmp=f1.getArray() + tmp.setIJ(0,0,1000.); + f1.mergeNodes(1e-10); + # + targetMesh=MEDCouplingDataForTest.build3DTargetMeshMergeNode_1(); + f1=targetMesh.fillFromAnalytic(ON_NODES,1,"x+y+z"); + tmp=f1.getArray() + tmp.setIJ(1,0,1000.); + self.assertRaises(Exception,f1.mergeNodes,1.e-10) + pass + + def testCheckConsecutiveCellTypes(self): + sourceMesh=MEDCouplingDataForTest.build2DSourceMesh_1(); + targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + self.assertTrue(sourceMesh.checkConsecutiveCellTypes()); + order1=[NORM_TRI3,NORM_QUAD4] + order2=[NORM_QUAD4,NORM_TRI3] + self.assertTrue(not targetMesh.checkConsecutiveCellTypes()); + self.assertTrue(not targetMesh.checkConsecutiveCellTypesAndOrder(order1)); + self.assertTrue(not targetMesh.checkConsecutiveCellTypesAndOrder(order2)); + da=targetMesh.getRenumArrForConsctvCellTypesSpe(order1); + self.assertEqual(5,da.getNumberOfTuples()); + self.assertEqual(1,da.getNumberOfComponents()); + expected1=[2,0,1,3,4] + self.assertTrue(expected1==list(da.getValues())); + da=targetMesh.getRenumArrForConsctvCellTypesSpe(order2); + self.assertEqual(5,da.getNumberOfTuples()); + self.assertEqual(1,da.getNumberOfComponents()); + expected2=[0,3,4,1,2] + self.assertTrue(expected2==list(da.getValues())); + renumber1=[4,0,1,2,3] + targetMesh.renumberCells(renumber1,False); + self.assertTrue(targetMesh.checkConsecutiveCellTypes()); + self.assertTrue(targetMesh.checkConsecutiveCellTypesAndOrder(order1)); + self.assertTrue(not targetMesh.checkConsecutiveCellTypesAndOrder(order2)); + pass + + def testRearrange2ConsecutiveCellTypes(self): + m1_1=MEDCouplingDataForTest.build2DSourceMesh_1(); + m2_1=MEDCouplingDataForTest.build2DTargetMesh_1(); + arr1=m1_1.rearrange2ConsecutiveCellTypes(); + m1_2=MEDCouplingDataForTest.build2DSourceMesh_1(); + self.assertTrue(m1_2.isEqual(m1_1,1e-12)); + expected1=[0,1] + self.assertEqual(2,arr1.getNumberOfTuples()); + self.assertEqual(1,arr1.getNumberOfComponents()); + self.assertTrue(expected1,arr1.getValues()); + expected2=[0,3,4,1,2] + arr1=m2_1.rearrange2ConsecutiveCellTypes(); + self.assertEqual(5,arr1.getNumberOfTuples()); + self.assertEqual(1,arr1.getNumberOfComponents()); + self.assertEqual(expected2,list(arr1.getValues())); + m2_2=MEDCouplingDataForTest.build2DTargetMesh_1(); + self.assertEqual(5,arr1.getNumberOfTuples()); + self.assertEqual(1,arr1.getNumberOfComponents()); + self.assertEqual(expected2,list(arr1.getValues())); + self.assertTrue(not m2_2.isEqual(m2_1,1e-12)); + m2_2.renumberCells(expected2,False); + self.assertTrue(m2_2.isEqual(m2_1,1e-12)); + pass + + def testSplitByType(self): + m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + v=m1.splitByType(); + self.assertEqual(3,len(v)); + m2=MEDCouplingUMesh.mergeUMeshesOnSameCoords(v); + m2.setName(m1.getName()); + self.assertTrue(m1.isEqual(m2,1.e-12)); + pass + + def testFuseUMeshesOnSameCoords(self): + m2=MEDCouplingDataForTest.build2DTargetMesh_1(); + cells1=[2,3,4] + m3=m2.buildPartOfMySelf(cells1,True); + self.assertTrue(isinstance(m3,MEDCouplingUMesh)) + cells2=[1,2,4] + m4=m2.buildPartOfMySelf(cells2,True); + self.assertTrue(isinstance(m4,MEDCouplingUMesh)) + cells3=[1,2] + m5=m2.buildPartOfMySelf(cells3,True); + self.assertTrue(isinstance(m5,MEDCouplingUMesh)) + meshes=[m3,m4,m5] + # + m7,corr=MEDCouplingUMesh.fuseUMeshesOnSameCoords(meshes,0); + self.assertEqual(4,m7.getNumberOfCells()); + self.assertEqual(3,len(corr)); + expectedVals1=[3,3,2] + expectedVals2=[[0,1,2],[3,0,2],[3,0]] + for i in xrange(3): + arr=corr[i]; + self.assertEqual(1,arr.getNumberOfComponents()); + nbOfVals=expectedVals1[i]; + self.assertEqual(nbOfVals,arr.getNumberOfTuples()); + vals=arr.getValues(); + self.assertEqual(expectedVals2[i],list(vals)); + pass + arr2,fidsOfGroups=DataArrayInt.makePartition(corr,m7.getNumberOfCells()); + fidExp=[5,1,3,4] + fidsGrp=[[1,3,5],[3,4,5],[4,5]] + self.assertEqual(3,len(fidsOfGroups)); + self.assertEqual(1,arr2.getNumberOfComponents()); + self.assertEqual(4,arr2.getNumberOfTuples()); + self.assertEqual(fidExp,list(arr2.getValues())); + for i in xrange(3): + nbOfVals=expectedVals1[i]; + self.assertEqual(list(fidsOfGroups[i]),fidsGrp[i]); + pass + pass + + def testFuseUMeshesOnSameCoords2(self): + m1,m2=MEDCouplingDataForTest.build3DExtrudedUMesh_1(); + part1=[2,3,6,4,10] + m3=m1.buildPartOfMySelf(part1,True); + part2=[5,6,4,7] + m4=m1.buildPartOfMySelf(part2,True); + meshes=[m1,m3,m3,m4] + m5,corr=MEDCouplingUMesh.fuseUMeshesOnSameCoords(meshes,0); + self.assertEqual(18,m5.getNumberOfCells()); + exp2=[ + [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17], + [2,3,6,4,10], + [2,3,6,4,10], + [5,6,4,7]] + i=0; + for it in corr: + self.assertEqual(exp2[i],list(it.getValues())); + i+=1 + pass + pass + + def testBuildOrthogonalField(self): + targetMesh=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + field=targetMesh.buildOrthogonalField(); + expected=[0.70710678118654746,0.,-0.70710678118654746] + self.assertEqual(5,field.getNumberOfTuples()); + self.assertEqual(3,field.getNumberOfComponents()); + vals=field.getArray().getValues(); + for i in xrange(15): + self.assertTrue(abs(expected[i%3]-vals[i])<1e-12); + # testing + targetCoords=[0.,0.,0.,0.5,0.,0.5,1.,0.,1.,0.,1.,0.] + targetConn=[0,1,2,3] + targetMesh=MEDCouplingUMesh.New(); + targetMesh.setMeshDimension(2); + targetMesh.allocateCells(1); + targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[0:4]) + targetMesh.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(targetCoords,4,3); + targetMesh.setCoords(myCoords); + field=targetMesh.buildOrthogonalField(); + self.assertEqual(1,field.getNumberOfTuples()); + self.assertEqual(3,field.getNumberOfComponents()); + vals=field.getArray().getValues(); + self.assertTrue(abs(-0.70710678118654746-vals[0])<1e-12); + self.assertTrue(abs(0.-vals[1])<1e-12); + self.assertTrue(abs(0.70710678118654746-vals[2])<1e-12); + pass + + def testGetCellsContainingPoint(self): + targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + pos=[0.,0.,0.4,0.4,0.,0.4,0.1,0.1,0.25,0.,0.65,0.] + #2D basic + t1,t2=targetMesh.getCellsContainingPoints(pos,6,1e-12); + self.assertEqual(6,len(t1)); + self.assertEqual(7,len(t2)); + expectedValues1=[0,4,3,0,1,2] + expectedValues2=[0,1,2,3,4,5,6] + self.assertEqual(list(t1),expectedValues1); + self.assertEqual(list(t2),expectedValues2); + #2D with no help of bounding box. + center=[0.2,0.2] + MEDCouplingPointSet.rotate2DAlg(center,0.78539816339744830962,6,pos); + targetMesh.rotate(center,[],0.78539816339744830962); + t1=None + t2=None + t1,t2=targetMesh.getCellsContainingPoints(pos,6,1e-12); + self.assertEqual(6,len(t1)); + self.assertEqual(7,len(t2)); + self.assertEqual(list(t1),expectedValues1); + self.assertEqual(list(t2),expectedValues2); + #2D outside + pos1bis=[-0.3303300858899107,-0.11819805153394641] + self.assertEqual(-1,targetMesh.getCellContainingPoint(pos1bis,1e-12)); + #test limits 2D + targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + pos2=[0.2,-0.05] + t1=None + t1=targetMesh.getCellsContainingPoint(pos2,1e-12) + self.assertEqual(2,len(t1)); + expectedValues3=[0,1] + self.assertEqual(list(t1),expectedValues3); + pos3=[0.2,0.2] + t1=None + t1=targetMesh.getCellsContainingPoint(pos3,1e-12); + self.assertEqual(5,len(t1)); + expectedValues4=[0,1,2,3,4] + self.assertEqual(list(t1),expectedValues4); + self.assertEqual(0,targetMesh.getCellContainingPoint(pos3,1e-12)); + #3D + targetMesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + pos4=[25.,25.,25.] + self.assertEqual(0,targetMesh.getCellContainingPoint(pos4,1e-12)); + pos5=[50.,50.,50.] + t1=None + t1=targetMesh.getCellsContainingPoint(pos5,1e-12); + self.assertEqual(8,len(t1)); + expectedValues5=[0,1,2,3,4,5,6,7] + self.assertEqual(list(t1),expectedValues5); + pos6=[0., 50., 0.] + t1=None + t1=targetMesh.getCellsContainingPoint(pos6,1e-12); + self.assertEqual(2,len(t1)); + expectedValues6=[0,2] + self.assertEqual(list(t1),expectedValues6); + #3D outside + pos7=[-1.0,-1.0,0.] + self.assertEqual(-1,targetMesh.getCellContainingPoint(pos7,1e-12)); + #3D outside 2 + center2=[0.,0.,0.] + vec2=[0.,-1.,0.] + targetMesh.rotate(center2,vec2,0.78539816339744830962); + pos8=[-25.,25.,12.] + self.assertEqual(-1,targetMesh.getCellContainingPoint(pos8,1e-12)); + pass + + def testGetValueOn1(self): + targetMesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + fieldOnCells=MEDCouplingFieldDouble.New(ON_CELLS); + nbOfCells=targetMesh.getNumberOfCells(); + fieldOnCells.setMesh(targetMesh); + array=DataArrayDouble.New(); + tmp=2*nbOfCells*[None] + for i in xrange(nbOfCells): + tmp[2*i]=7.+float(i); + tmp[2*i+1]=17.+float(i) + pass + array.setValues(tmp,nbOfCells,2); + fieldOnCells.setArray(array); + # + pos1=[0.25,0.] + res=fieldOnCells.getValueOn(pos1); + self.assertEqual(2,len(res)) + self.assertTrue(abs(8.-res[0])<1e-12); + self.assertTrue(abs(18.-res[1])<1e-12); + # + # + targetMesh=MEDCouplingDataForTest.build2DSourceMesh_1(); + fieldOnNodes=MEDCouplingFieldDouble.New(ON_NODES); + nbOfNodes=targetMesh.getNumberOfNodes(); + fieldOnNodes.setMesh(targetMesh); + array=DataArrayDouble.New(); + tmp=2*nbOfNodes*[None] + for i in xrange(nbOfNodes): + tmp[2*i]=17.+float(i); + tmp[2*i+1]=27.+float(i) + pass + array.setValues(tmp,nbOfNodes,2); + fieldOnNodes.setArray(array); + # + pos2=[-0.13333333333333333,-0.13333333333333333] + res=None + res=fieldOnNodes.getValueOn(pos2); + self.assertEqual(2,len(res)) + self.assertTrue(abs(17.5-res[0])<1e-12); + self.assertTrue(abs(27.5-res[1])<1e-12); + pos3=[0.033333333333333326,0.36666666666666664] + res=None + res=fieldOnNodes.getValueOn(pos3); + self.assertEqual(2,len(res)) + self.assertTrue(abs(18.666666666666667-res[0])<1e-12); + self.assertTrue(abs(28.666666666666667-res[1])<1e-12); + pass + + def testCMesh0(self): + mesh=MEDCouplingCMesh.New(); + coordsX=DataArrayDouble.New(); + arrX=[ -1., 1., 2., 4. ] + coordsX.setValues(arrX,4,1); + coordsY=DataArrayDouble.New(); + arrY=[ -2., 2., 4., 8. ] + coordsY.setValues(arrY,4,1); + coordsZ=DataArrayDouble.New(); + arrZ=[ -3., 3., 6., 12. ] + coordsZ.setValues(arrZ,4,1); + mesh.setCoords(coordsX,coordsY,coordsZ); + pass + + def testScale(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_1(); + pos=[0.2,0.2] + mesh.scale(pos,0.5); + 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, + -0.05,0.45, 0.2,0.45, 0.45,0.45] + val=mesh.getCoords().getValues(); + self.assertEqual(18,len(val)) + for i in xrange(18): + self.assertTrue(abs(expected1[i]-val[i])<1e-12); + pass + pass + + def testTryToShareSameCoords(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + m2=MEDCouplingDataForTest.build2DTargetMesh_1(); + #self.assertEqual(m1.getCoords()!=m2.getCoords()); + m1.tryToShareSameCoords(m2,1e-12); + #self.assertEqual(m1.getCoords()==m2.getCoords()); + m1.tryToShareSameCoords(m2,1e-12); + #self.assertEqual(m1.getCoords()==m2.getCoords()); + m2.tryToShareSameCoords(m1,1e-12); + #self.assertEqual(m1.getCoords()==m2.getCoords()); + # + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + m2=MEDCouplingDataForTest.build2DTargetMesh_2(); + #self.assertEqual(m1.getCoords()!=m2.getCoords()); + m1.tryToShareSameCoords(m2,1e-12); + #self.assertEqual(m1.getCoords()==m2.getCoords()); + m1.tryToShareSameCoords(m2,1e-12); + #self.assertEqual(m1.getCoords()==m2.getCoords()); + m2.tryToShareSameCoords(m1,1e-12); + #self.assertEqual(m1.getCoords()==m2.getCoords()); + # + m1=MEDCouplingDataForTest.build2DTargetMesh_1(); + m2=MEDCouplingDataForTest.build2DSourceMesh_1(); + #self.assertEqual(m1.getCoords()!=m2.getCoords()); + self.assertRaises(Exception,m1.tryToShareSameCoords,m2,1e-12) + pass + + def testFindNodeOnPlane(self): + mesh=MEDCouplingDataForTest.build3DTargetMesh_1(); + pt=[300.,300.,0.] + v=[0.,0.,2.] + n=mesh.findNodesOnPlane(pt,v,1e-12); + self.assertEqual(9,len(n)); + m3dSurf=mesh.buildFacePartOfMySelfNode(n,True); + self.assertTrue(isinstance(m3dSurf,MEDCouplingUMesh)) + me=MEDCouplingExtrudedMesh.New(mesh,m3dSurf,0); + da=me.getMesh3DIds(); + self.assertEqual(8,me.getNumberOfCells()); + expected=[0,1,2,3,4,5,6,7] + val=da.getValues(); + self.assertEqual(expected,list(val)); + pass + + def testRenumberCells(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + self.assertTrue(m.isEqual(m2,0)); + arr=[12,3,25,2,26] + m.renumberCells(arr,True); + self.assertTrue(not m.isEqual(m2,0)); + self.assertEqual(NORM_QUAD4,m.getTypeOfCell(0)); + self.assertEqual(NORM_TRI3,m.getTypeOfCell(1)); + self.assertEqual(NORM_QUAD4,m.getTypeOfCell(2)); + self.assertEqual(NORM_TRI3,m.getTypeOfCell(3)); + self.assertEqual(NORM_QUAD4,m.getTypeOfCell(4)); + arr2=[5,-1,-5,4,8] + m.renumberCells(arr2,True); + self.assertTrue(m.isEqual(m2,0)); + pass + + def testChangeSpaceDimension(self): + m1=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + m2=MEDCouplingDataForTest.build2DTargetMesh_1(); + # + self.assertEqual(3,m1.getSpaceDimension()); + m1.changeSpaceDimension(2); + self.assertEqual(2,m1.getSpaceDimension()); + m1.setName(m2.getName()); + self.assertTrue(m1.isEqual(m2,1e-12)); + m1.changeSpaceDimension(3); + self.assertEqual(3,m1.getSpaceDimension()); + 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.] + val=m1.getCoords().getValues(); + for i in xrange(27): + self.assertTrue(abs(expected[i]-val[i])<1e-14); + pass + pass + + def testGaussPointField1(self): + _a=0.446948490915965; + _b=0.091576213509771; + _p1=0.11169079483905; + _p2=0.0549758718227661; + refCoo1=[ 0.,0., 1.,0., 0.,1. ] + 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 ] + wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ] + _refCoo1=refCoo1 + _gsCoo1=gsCoo1 + _wg1=wg1 + # + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME); + f.setMesh(m); + self.assertEqual(0,f.getNbOfGaussLocalization()); + f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1); + self.assertRaises(Exception,f.setGaussLocalizationOnType,NORM_QUAD4,_refCoo1,_gsCoo1,_wg1) + self.assertEqual(1,f.getNbOfGaussLocalization()); + refCoo2=[ 0.,0., 1.,0., 1.,1., 0.,1. ] + _refCoo2=refCoo2 + _gsCoo1=_gsCoo1[0:4] + _wg1=_wg1[0:2] + f.setGaussLocalizationOnType(NORM_QUAD4,_refCoo2,_gsCoo1,_wg1); + self.assertEqual(2,f.getNbOfGaussLocalization()); + array=DataArrayDouble.New(); + ptr=18*2*[None] + for i in xrange(18*2): + ptr[i]=float(i+1) + array.setValues(ptr,18,2); + ptr=array.getPointer(); + f.setArray(array); + f.setName("MyFirstFieldOnGaussPoint"); + f.checkCoherency(); + self.assertAlmostEqual(27.,f.getIJK(2,5,0),14); + self.assertAlmostEqual(16.,f.getIJK(1,5,1),14); + # + f.clearGaussLocalizations(); + self.assertEqual(0,f.getNbOfGaussLocalization()); + self.assertRaises(Exception,f.checkCoherency); + ids1=[0,1,3,4] + self.assertRaises(Exception,f.setGaussLocalizationOnCells,ids1,_refCoo2,_gsCoo1,_wg1); + self.assertEqual(0,f.getNbOfGaussLocalization()); + ids2=[0,4] + f.setGaussLocalizationOnCells(ids2,_refCoo2,_gsCoo1,_wg1); + self.assertEqual(1,f.getNbOfGaussLocalization()); + self.assertEqual(0,f.getGaussLocalizationIdOfOneCell(0)); + self.assertRaises(Exception,f.getGaussLocalizationIdOfOneCell,1); + ids3=[1,2] + f.setGaussLocalizationOnCells(ids3,_refCoo1,_gsCoo1,_wg1); + self.assertEqual(2,f.getNbOfGaussLocalization()); + self.assertEqual(0,f.getGaussLocalizationIdOfOneCell(0)); + self.assertEqual(1,f.getGaussLocalizationIdOfOneCell(1)); + self.assertEqual(1,f.getGaussLocalizationIdOfOneCell(2)); + self.assertRaises(Exception,f.checkCoherency);#<- cell 3 has no localization + ids4=[3] + _gsCoo2=_gsCoo1; + _wg2=_wg1; + _gsCoo2[0]=0.8888777776666; + _wg2[0]=0.1234567892377; + f.setGaussLocalizationOnCells(ids4,_refCoo2,_gsCoo2,_wg2); + self.assertEqual(3,f.getNbOfGaussLocalization()); + tmpIds=f.getCellIdsHavingGaussLocalization(0); + self.assertEqual(ids2,list(tmpIds)); + self.assertRaises(Exception,f.checkCoherency);#<- it's always not ok because undelying array not with the good size. + array2=f.getArray().substr(0,10); + f.setArray(array2); + f.checkCoherency();#<- here it is OK + f2=f.clone(True); + self.assertTrue(f.isEqual(f2,1e-14,1e-14)); + gl1=f2.getGaussLocalization(0); + tmp=gl1.getGaussCoord(1,1); + self.assertAlmostEqual(2.07*_b-1,tmp,14); + gl1.setGaussCoord(1,1,0.07); + self.assertTrue(not f.isEqual(f2,1e-14,1e-14)); + gl1.setGaussCoord(1,1,tmp); + self.assertTrue(f.isEqual(f2,1e-14,1e-14)); + f2.checkCoherency(); + pass + + def testGaussPointNEField1(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,NO_TIME); + f.setMesh(m); + f.setName("MyFirstFieldOnNE"); + f.setDescription("MyDescriptionNE"); + array=DataArrayDouble.New(); + tmp=18*2*[None] + for i in xrange(18*2): + tmp[i]=float(i+7) + pass + array.setValues(tmp,18,2); + ptr=array.getPointer(); + f.setArray(array); + # + f.checkCoherency(); + f2=f.clone(True); + self.assertTrue(f.isEqual(f2,1e-14,1e-14)); + self.assertAlmostEqual(21.,f.getIJK(2,0,0),14); + self.assertAlmostEqual(18.,f.getIJK(1,1,1),14); + pass + + def testCellOrientation1(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + vec=[0.,0.,1.] + self.assertRaises(Exception,m.are2DCellsNotCorrectlyOriented,vec,False); + m.changeSpaceDimension(3); + res1=m.are2DCellsNotCorrectlyOriented(vec,False); + self.assertTrue(len(res1)==0); + vec[2]=-1.; + res1=m.are2DCellsNotCorrectlyOriented(vec,False); + self.assertEqual(5,len(res1)); + # + vec[2]=1.; + # connectivity inversion + conn=m.getNodalConnectivity().getValues(); + tmp=conn[11]; + conn[11]=conn[12]; + conn[12]=tmp; + m.getNodalConnectivity().setValues(conn,len(conn),1) + res1=m.are2DCellsNotCorrectlyOriented(vec,False); + self.assertEqual(1,len(res1)); + self.assertEqual(2,res1[0]); + m.orientCorrectly2DCells(vec,False); + res1=m.are2DCellsNotCorrectlyOriented(vec,False); + self.assertTrue(len(res1)==0); + m2=MEDCouplingDataForTest.build2DTargetMesh_1(); + m2.changeSpaceDimension(3); + self.assertTrue(m.isEqual(m2,1e-12)); + pass + + def testCellOrientation2(self): + m2,m1=MEDCouplingDataForTest.build3DExtrudedUMesh_1(); + res1=m2.arePolyhedronsNotCorrectlyOriented(); + self.assertEqual(6,len(res1)); + m2.orientCorrectlyPolyhedrons(); + res1=m2.arePolyhedronsNotCorrectlyOriented(); + self.assertTrue(len(res1)==0); + m2.checkCoherency(); + self.assertEqual(18,m2.getNumberOfCells()); + cellIds2=[0,6,12] + m2.convertToPolyTypes(cellIds2); + m2.orientCorrectlyPolyhedrons(); + res1=m2.arePolyhedronsNotCorrectlyOriented(); + self.assertTrue(len(res1)==0); + f2=m2.getMeasureField(False); + f2Ptr=f2.getArray().getValues(); + #Test to check global reverse in MEDCouplingUMesh::tryToCorrectPolyhedronOrientation + m3=MEDCouplingDataForTest.build2DTargetMesh_1(); + vec=[0.,0.,-1.] + m3.changeSpaceDimension(3); + ids2=[0,1,2,3,4] + m3.convertToPolyTypes(ids2); + m3.orientCorrectly2DCells(vec,False); + m4=MEDCouplingDataForTest.buildCU1DMesh_U(); + m4.changeSpaceDimension(3); + center=[0.,0.,0.] + vector=[0.,1.,0.] + m4.rotate(center,vector,-pi/2.); + m5=m3.buildExtrudedMeshFromThis(m4,0); + res1=m5.arePolyhedronsNotCorrectlyOriented(); + self.assertEqual(15,len(res1)); + m5.orientCorrectlyPolyhedrons(); + res1=m5.arePolyhedronsNotCorrectlyOriented(); + self.assertTrue(len(res1)==0); + f3=m5.getMeasureField(False); + self.assertEqual(15,f3.getArray().getNumberOfTuples()); + self.assertEqual(1,f3.getNumberOfComponents()); + f3Ptr=f3.getArray().getValues(); + 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]; + for i in xrange(15): + self.assertTrue(abs(expected1[i]-f3Ptr[i])<1e-12); + pass + f4=m5.getBarycenterAndOwner(); + self.assertEqual(15,f4.getNumberOfTuples()); + self.assertEqual(3,f4.getNumberOfComponents()); + f4Ptr=f4.getValues(); + 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]; + for i in xrange(45): + self.assertTrue(abs(expected2[i]-f4Ptr[i])<1e-12); + pass + pass + + def testPolyhedronBarycenter(self): + 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]; + 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]; + meshN=MEDCouplingUMesh.New(); + meshN.setName("ForBary"); + meshN.setMeshDimension(3); + meshN.allocateCells(4); + meshN.insertNextCell(NORM_POLYHED,29,connN[0:29]) + meshN.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(coords,9,3); + meshN.setCoords(myCoords); + meshN.checkCoherency(); + # + res1=meshN.arePolyhedronsNotCorrectlyOriented(); + meshN.orientCorrectlyPolyhedrons(); + self.assertTrue(len(res1)==0); + da=meshN.getBarycenterAndOwner(); + self.assertEqual(1,da.getNumberOfTuples()); + self.assertEqual(3,da.getNumberOfComponents()); + daPtr=da.getValues(); + ref=meshN.getCoords().getValues()[24:]; + for i in xrange(3): + self.assertTrue(abs(ref[i]-daPtr[i])<1e-12); + pass + # + center=[0.,0.,0.] + vec=[0.,2.78,0.] + da=meshN.getBarycenterAndOwner(); + daPtr=da.getValues(); + ref=meshN.getCoords().getValues()[24:]; + for i in xrange(3): + self.assertTrue(abs(ref[i]-daPtr[i])<1e-12); + pass + # + meshN.rotate(center,vec,pi/7.); + meshN.translate(vec); + da=meshN.getBarycenterAndOwner(); + daPtr=da.getValues(); + ref=meshN.getCoords().getValues()[24:]; + for i in xrange(3): + self.assertTrue(abs(ref[i]-daPtr[i])<1e-12); + pass + # + center2=[1.12,3.45,6.78] + vec2=[4.5,9.3,2.8] + meshN.rotate(center2,vec2,e); + meshN.translate(vec2); + da=meshN.getBarycenterAndOwner(); + daPtr=da.getValues(); + ref=meshN.getCoords().getValues()[24:]; + for i in xrange(3): + self.assertTrue(abs(ref[i]-daPtr[i])<1e-10); + pass + pass + + def testNormL12Integ1D(self): + m1=MEDCouplingDataForTest.build1DTargetMesh_3(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(m1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr,m1.getNumberOfCells(),3); + f1.setArray(array); + # + f3=m1.getBarycenterAndOwner(); + self.assertEqual(4,f3.getNumberOfTuples()); + self.assertEqual(1,f3.getNumberOfComponents()); + expected9=[0.75,5.105,0.8,5.155] + ptr=f3.getValues(); + for i in xrange(4): + self.assertTrue(abs(expected9[i]-ptr[i])<1e-12); + pass + # + f2=m1.getMeasureField(False); + self.assertEqual(4,f2.getArray().getNumberOfTuples()); + self.assertEqual(1,f2.getNumberOfComponents()); + expected1=[0.5,0.21,-0.6,-0.31] + ptr=f2.getArray().getValues(); + for i in xrange(4): + self.assertTrue(abs(expected1[i]-ptr[i])<1e-12); + pass + expected2=[0.5,0.21,0.6,0.31] + f2=m1.getMeasureField(True); + ptr=f2.getArray().getValues(); + for i in xrange(4): + self.assertTrue(abs(expected2[i]-ptr[i])<1e-12); + pass + #integral + res=f1.integral(False); + expected3=[0.9866,-0.3615,0.4217] + for i in xrange(3): + self.assertTrue(abs(expected3[i]-res[i])<1e-12); + pass + self.assertTrue(abs(expected3[0]-f1.integral(0,False))<1e-12); + self.assertTrue(abs(expected3[1]-f1.integral(1,False))<1e-12); + self.assertTrue(abs(expected3[2]-f1.integral(2,False))<1e-12); + res=f1.integral(True); + expected4=[-3.4152,8.7639,-14.6879] + for i in xrange(3): + self.assertTrue(abs(expected4[i]-res[i])<1e-12); + pass + #normL1 + res=f1.normL1(); + expected5=[11.3068,27.3621,43.7881] + for i in xrange(3): + self.assertTrue(abs(expected5[i]-res[i])<1e-12); + pass + self.assertTrue(abs(expected5[0]-f1.normL1(0))<1e-12); + self.assertTrue(abs(expected5[1]-f1.normL1(1))<1e-12); + self.assertTrue(abs(expected5[2]-f1.normL1(2))<1e-12); + #normL2 + res=f1.normL2(); + expected7=[9.0252562290496776, 21.545259176904789, 34.433193070059595] + for i in xrange(3): + self.assertTrue(abs(expected7[i]-res[i])<1e-9); + pass + self.assertTrue(abs(expected7[0]-f1.normL2(0))<1e-9); + self.assertTrue(abs(expected7[1]-f1.normL2(1))<1e-9); + self.assertTrue(abs(expected7[2]-f1.normL2(2))<1e-9); + #buildWeightingField + f4=f1.buildWeightingField(False); + self.assertTrue(abs(-0.2-f4.accumulate(0))<1e-12); + f4=f1.buildWeightingField(True); + self.assertTrue(abs(1.62-f4.accumulate(0))<1e-12); + # Testing with 2D Curve + m1=MEDCouplingDataForTest.build2DCurveTargetMesh_3(); + f2=m1.getMeasureField(False); + self.assertEqual(4,f2.getArray().getNumberOfTuples()); + self.assertEqual(1,f2.getNumberOfComponents()); + ptr=f2.getArray().getValues(); + for i in xrange(4): + self.assertTrue(abs(sqrt(2.)*expected2[i]-ptr[i])<1e-12); + pass + f2=m1.getMeasureField(True); + self.assertEqual(4,f2.getArray().getNumberOfTuples()); + self.assertEqual(1,f2.getNumberOfComponents()); + ptr=f2.getArray().getValues(); + for i in xrange(4): + self.assertTrue(abs(expected2[i]*sqrt(2.)-ptr[i])<1e-12); + pass + #bary + f3=m1.getBarycenterAndOwner(); + self.assertEqual(4,f3.getNumberOfTuples()); + self.assertEqual(2,f3.getNumberOfComponents()); + expected10=[0.75,0.75,5.105,5.105,0.8,0.8,5.155,5.155] + ptr=f3.getValues(); + for i in xrange(8): + self.assertTrue(abs(expected10[i]-ptr[i])<1e-12); + pass + # + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(m1); + array=DataArrayDouble.New(); + array.setValues(arr,m1.getNumberOfCells(),3); + f1.setArray(array); + res=f1.integral(False); + for i in xrange(3): + self.assertTrue(abs(sqrt(2.)*expected4[i]-res[i])<1e-12); + pass + res=f1.integral(True); + for i in xrange(3): + self.assertTrue(abs(sqrt(2.)*expected4[i]-res[i])<1e-12); + pass + res=f1.normL1(); + for i in xrange(3): + self.assertTrue(abs(sqrt(2.)*expected5[i]-res[i])<1e-12); + pass + res=f1.normL2(); + for i in xrange(3): + self.assertTrue(abs(sqrt(sqrt(2.))*expected7[i]-res[i])<1e-12); + pass + pass + + def testAreaBary2D(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_3(); + f1=m1.getMeasureField(False); + self.assertEqual(10,f1.getArray().getNumberOfTuples()); + self.assertEqual(1,f1.getNumberOfComponents()); + expected1=[-0.5,-1,-1.5,-0.5,-1, 0.5,1,1.5,0.5,1] + ptr=f1.getArray().getValues(); + for i in xrange(10): + self.assertTrue(abs(expected1[i]-ptr[i])<1e-12); + pass + f1=m1.getMeasureField(True); + ptr=f1.getArray().getValues(); + for i in xrange(10): + self.assertTrue(abs(abs(expected1[i])-ptr[i])<1e-12); + pass + f2=m1.getBarycenterAndOwner(); + self.assertEqual(10,f2.getNumberOfTuples()); + self.assertEqual(2,f2.getNumberOfComponents()); + 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] + ptr=f2.getValues(); + for i in xrange(20): + self.assertTrue(abs(expected2[i]-ptr[i])<1e-12); + pass + m1.changeSpaceDimension(3); + f1=m1.getMeasureField(False); + self.assertEqual(10,f1.getArray().getNumberOfTuples()); + self.assertEqual(1,f1.getNumberOfComponents()); + ptr=f1.getArray().getValues(); + for i in xrange(10): + self.assertTrue(abs(abs(expected1[i])-ptr[i])<1e-12); + pass + f2=m1.getBarycenterAndOwner(); + self.assertEqual(10,f2.getNumberOfTuples()); + self.assertEqual(3,f2.getNumberOfComponents()); + ptr=f2.getValues(); + 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.] + for i in xrange(30): + self.assertTrue(abs(expected3[i]-ptr[i])<1e-12); + pass + pass + + def testAreaBary3D(self): + coords=[ 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 , + 0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 , + 0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 , + 0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 , + -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 , + -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 , + 0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 , + 0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 , + -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 , + 0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 , + -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 , + -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 , + -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 , + -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 , + -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 , + -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 , + 0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 , + 0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 , + 0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 , + -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 , + -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 , + -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 , + -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 , + 0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 , + 0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 , + 0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 , + -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 , + -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 , + 0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 , + 0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 , + -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 , + 0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 , + 0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 , + 0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 , + -0.0372812069535 , -0.286740286332 , 0.00963701291166 ] + + connN = [ #polyhedron 0 + 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 + , 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 + , 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 + , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28, + # polyhedron 1 + 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 + , 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 + , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1 + , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50, + # polyhedron 2 + 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 + , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40, + # polyhedron 3 + 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 + , 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 + , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1 + , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65] + + barys = [ -0.0165220465527 , -0.0190922868195 , 0.158882733414 , + 0.0287618656076 , 0.135874379934 , -0.14601588119 , + -0.147128055553 , 0.0465995097041 , -0.049391174453 , + -0.00142506732317 , -0.0996953090351 , -0.115159183132 ] + meshN=MEDCouplingUMesh.New(); + meshN.setName("ForBary"); + meshN.setMeshDimension(3); + meshN.allocateCells(4); + meshN.insertNextCell(NORM_POLYHED,113,connN); + meshN.insertNextCell(NORM_POLYHED,99,connN[113:]); + meshN.insertNextCell(NORM_POLYHED,43,connN[212:]); + meshN.insertNextCell(NORM_POLYHED,92,connN[255:]); + meshN.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(coords,69,3); + meshN.setCoords(myCoords); + meshN.checkCoherency(); + res1=meshN.arePolyhedronsNotCorrectlyOriented(); + meshN.orientCorrectlyPolyhedrons(); + res1=meshN.arePolyhedronsNotCorrectlyOriented(); + self.assertTrue(len(res1)==0); + # + da=meshN.getBarycenterAndOwner(); + self.assertEqual(4,da.getNumberOfTuples()); + self.assertEqual(3,da.getNumberOfComponents()); + daPtr=da.getValues(); + for i in xrange(12): + self.assertTrue(abs(barys[i]-daPtr[i])<1e-12); + pass + pass + + def testRenumberCellsForFields(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f.setMesh(m); + arr=DataArrayDouble.New(); + nbOfCells=m.getNumberOfCells(); + values1=[7.,107.,10007.,8.,108.,10008.,9.,109.,10009.,10.,110.,10010.,11.,111.,10011.] + arr.setValues(values1,nbOfCells,3); + f.setArray(arr); + renumber1=[3,1,0,4,2] + loc=[-0.05,-0.05, 0.55,-0.25, 0.55,0.15, -0.05,0.45, 0.45,0.45] + for j in xrange(5): + res=f.getValueOn(loc[2*j:2*j+2]); + for i in xrange(3): + self.assertTrue(abs(values1[i+3*j]-res[i])<1e-12); + pass + pass + f.renumberCells(renumber1,False); + ptr=f.getArray().getValues(); + expected1=[9.,109.,10009.,8.,108.,10008.,11.,111.,10011.,7.,107.,10007.,10.,110.,10010.] + for i in xrange(15): + self.assertTrue(abs(expected1[i]-ptr[i])<1e-12); + pass + #check that fields remains the same geometrically + for j in xrange(5): + res=f.getValueOn(loc[2*j:2*(j+1)]); + for i in xrange(3): + self.assertTrue(abs(values1[i+3*j]-res[i])<1e-12); + pass + pass + #On gauss + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME); + f.setMesh(m); + _a=0.446948490915965; + _b=0.091576213509771; + _p1=0.11169079483905; + _p2=0.0549758718227661; + refCoo1=[ 0.,0., 1.,0., 0.,1. ] + 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 ]; + wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ] + _refCoo1=refCoo1[0:6]; + _gsCoo1=gsCoo1[0:12]; + _wg1=wg1[0:6]; + f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1); + refCoo2=[ 0.,0., 1.,0., 1.,1., 0.,1. ] + _refCoo2=refCoo2[0:8]; + _gsCoo1=_gsCoo1[0:4] + _wg1=_wg1[0:2] + f.setGaussLocalizationOnType(NORM_QUAD4,_refCoo2,_gsCoo1,_wg1); + arr=DataArrayDouble.New(); + 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.] + arr.setValues(values2,18,2); + f.setArray(arr); + f.checkCoherency(); + fCpy=f.clone(True); + self.assertTrue(f.isEqual(fCpy,1e-12,1e-12)); + f.renumberCells(renumber1,False); + self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12)); + 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.] + ptr=f.getArray().getValues(); + for i in xrange(36): + self.assertTrue(abs(expected2[i]-ptr[i])<1e-12); + pass + renumber2=[2,1,4,0,3] + f.renumberCells(renumber2,False); + self.assertTrue(f.isEqual(fCpy,1e-12,1e-12)); + #GaussNE + f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,NO_TIME); + f.setMesh(m); + arr=DataArrayDouble.New(); + 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.] + arr.setValues(values3,18,2); + f.setArray(arr); + f.checkCoherency(); + fCpy=f.clone(True); + self.assertTrue(f.isEqual(fCpy,1e-12,1e-12)); + f.renumberCells(renumber1,False); + self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12)); + 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.] + ptr=f.getArray().getValues(); + for i in xrange(36): + self.assertTrue(abs(expected3[i]-ptr[i])<1e-12); + pass + f.renumberCells(renumber2,False);#perform reverse operation of renumbering to check that the resulting field is equal. + self.assertTrue(f.isEqual(fCpy,1e-12,1e-12)); + # + pass + + def testRenumberNodesForFields(self): + m=MEDCouplingDataForTest.build2DTargetMesh_1(); + f=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME); + f.setMesh(m); + arr=DataArrayDouble.New(); + nbOfNodes=m.getNumberOfNodes(); + 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.] + arr.setValues(values1,nbOfNodes,3); + f.setArray(arr); + f.checkCoherency(); + renumber1=[0,4,1,3,5,2,6,7,8] + loc=[0.5432,-0.2432, 0.5478,0.1528] + expected1=[9.0272, 109.0272, 10009.0272, 11.4124,111.4124,10011.4124] + for j in xrange(2): + res=f.getValueOn(loc[2*j:2*j+2]); + for i in xrange(3): + self.assertTrue(abs(expected1[i+3*j]-res[i])<1e-12); + pass + pass + fCpy=f.clone(True); + self.assertTrue(f.isEqual(fCpy,1e-12,1e-12)); + f.renumberNodes(renumber1); + self.assertTrue(not f.isEqual(fCpy,1e-12,1e-12)); + for j in xrange(2): + res=f.getValueOn(loc[2*j:2*j+2]); + for i in xrange(3): + self.assertTrue(abs(expected1[i+3*j]-res[i])<1e-12); + pass + pass + 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.] + for i in xrange(27): + self.assertTrue(abs(expected2[i]-f.getArray().getValues()[i])<1e-12); + pass + renumber2=[0,2,5,3,1,4,6,7,8] + f.renumberNodes(renumber2); + self.assertTrue(f.isEqual(fCpy,1e-12,1e-12)); + pass + + def testConvertQuadraticCellsToLinear(self): + mesh=MEDCouplingDataForTest.build2DTargetMesh_3(); + mesh.checkCoherency(); + types=mesh.getAllTypes(); + types.sort() + self.assertEqual(5,len(types)); + expected1=[NORM_POLYGON, NORM_TRI3, NORM_QUAD4, NORM_TRI6, NORM_QUAD8] + expected1.sort() + self.assertTrue(expected1==types); + self.assertTrue(mesh.isPresenceOfQuadratic()); + self.assertEqual(62,mesh.getMeshLength()); + f1=mesh.getMeasureField(False); + # + mesh.convertQuadraticCellsToLinear(); + self.assertTrue(not mesh.isPresenceOfQuadratic()); + # + mesh.checkCoherency(); + f2=mesh.getMeasureField(False); + self.assertTrue(f1.getArray().isEqual(f2.getArray(),1e-12)); + self.assertEqual(48,mesh.getMeshLength()); + types2=mesh.getAllTypes(); + types2.sort() + self.assertEqual(3,len(types2)); + expected2=[NORM_POLYGON, NORM_TRI3, NORM_QUAD4] + expected2.sort() + self.assertTrue(expected2==types2); + pass + + def testCheckGeoEquivalWith(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_3(); + mesh2=MEDCouplingDataForTest.build2DTargetMesh_3(); + #First test mesh1 + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,0,1e-12);#deepEqual + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,1,1e-12);#fastEqual + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh1,10,1e-12);#deepEqual with geo permutations + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + #Second test mesh1 and mesh2 are 2 different meshes instance + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,0,1e-12);#deepEqual + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + #Third test : cell permutation by keeping the first the middle and the last as it is. + renum=[0,2,1,3,4,5,6,8,7,9] + mesh2.renumberCells(renum,False); + self.assertRaises(Exception,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);#deepEqual fails + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual do not see anything + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations + self.assertTrue(cellCor); + self.assertEqual(10,cellCor.getNumberOfTuples()); + self.assertEqual(1,cellCor.getNumberOfComponents()); + self.assertEqual(renum,list(cellCor.getValues())) + self.assertTrue(nodeCor==None); + cellCor=0; + self.assertTrue(nodeCor==None); + #4th test : cell and node permutation by keeping the first the middle and the last as it is. + mesh2=MEDCouplingDataForTest.build2DTargetMesh_3(); + renum2=[0,2,1,3,4,5,6,8,7,9,10] + mesh2.renumberCells(renum,False); + mesh2.renumberNodes(renum2,11); + cellCor=None + nodeCor=None + self.assertRaises(Exception,mesh1.checkGeoEquivalWith,mesh2,0,1e-12);#deepEqual fails + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,1,1e-12);#fastEqual do not see anything + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12);#deepEqual with geo permutations + self.assertTrue(cellCor); + self.assertEqual(10,cellCor.getNumberOfTuples()); + self.assertEqual(1,cellCor.getNumberOfComponents()); + self.assertEqual(renum,list(cellCor.getValues())) + self.assertTrue(nodeCor); + self.assertEqual(11,nodeCor.getNumberOfTuples()); + self.assertEqual(1,nodeCor.getNumberOfComponents()); + self.assertEqual(renum2,list(nodeCor.getValues())) + cellCor=0; + nodeCor=0; + #5th test : modification of the last cell to check fastCheck detection. + mesh2=MEDCouplingDataForTest.build2DTargetMesh_3(); + renum3=[0,2,1,3,4,5,6,8,9,7] + mesh2.renumberCells(renum3,False); + mesh2.renumberNodes(renum2,11); + cellCor=None + nodeCor=None + self.assertRaises(Exception,mesh1.checkGeoEquivalWith,mesh2,0,1e-12) + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + self.assertRaises(Exception,mesh1.checkGeoEquivalWith,mesh2,1,1e-12) + self.assertTrue(cellCor==None); + self.assertTrue(nodeCor==None); + cellCor,nodeCor=mesh2.checkGeoEquivalWith(mesh1,10,1e-12);#deepEqual with geo permutations + self.assertTrue(cellCor!=None); + self.assertEqual(10,cellCor.getNumberOfTuples()); + self.assertEqual(1,cellCor.getNumberOfComponents()); + self.assertEqual(renum3,list(cellCor.getValues())) + self.assertTrue(nodeCor!=None); + self.assertEqual(11,nodeCor.getNumberOfTuples()); + self.assertEqual(1,nodeCor.getNumberOfComponents()); + self.assertEqual(renum2,list(nodeCor.getValues())); + pass + + def testCheckGeoEquivalWith2(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_4(); + mesh2=MEDCouplingDataForTest.build2DTargetMesh_1(); + cellCor,nodeCor=mesh1.checkGeoEquivalWith(mesh2,10,1e-12); + self.assertEqual(None,cellCor); + self.assertNotEqual(None,nodeCor); + expected1=[0, 1, 3, 4, 5, 6, 7, 8, 9] + for i in xrange(9): + self.assertEqual(expected1[i],nodeCor.getIJ(i,0)); + pass + pass + + def testCopyTinyStringsFromOnFields(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + nbOfCells=m.getNumberOfCells(); + f=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME); + f.setMesh(m); + f.setName("a"); + f.setDescription("b"); + a1=DataArrayDouble.New(); + a1.alloc(nbOfCells,2); + a1.fillWithZero(); + a1.setInfoOnComponent(0,"c"); + a1.setInfoOnComponent(1,"d"); + a2=a1.deepCopy(); + a2.setInfoOnComponent(0,"e"); + a2.setInfoOnComponent(1,"f"); + f.setArray(a1); + f.setEndArray(a2); + f.setEndTime(3.,3,4); + m.setName("g"); + m.getCoords().setInfoOnComponent(0,"h"); + m.getCoords().setInfoOnComponent(1,"i"); + m.getCoords().setInfoOnComponent(2,"j"); + # + f.checkCoherency(); + f2=f.clone(True); + self.assertTrue(f2.isEqual(f,1e-12,1e-12)); + f2.setName("smth"); + self.assertTrue(not f2.isEqual(f,1e-12,1e-12)); + f2.copyTinyStringsFrom(f); + self.assertTrue(f2.isEqual(f,1e-12,1e-12)); + f2.setDescription("GGG"); + self.assertTrue(not f2.isEqual(f,1e-12,1e-12)); + f2.copyTinyStringsFrom(f); + self.assertTrue(f2.isEqual(f,1e-12,1e-12)); + f2.getArray().setInfoOnComponent(0,"mmmm"); + self.assertTrue(not f2.isEqual(f,1e-12,1e-12)); + f2.copyTinyStringsFrom(f); + self.assertTrue(f2.isEqual(f,1e-12,1e-12)); + f2.getEndArray().setInfoOnComponent(1,"mmmm"); + self.assertTrue(not f2.isEqual(f,1e-12,1e-12)); + f2.copyTinyStringsFrom(f); + self.assertTrue(f2.isEqual(f,1e-12,1e-12)); + m2=m.clone(True); + self.assertTrue(m2.isEqual(m,1e-12)); + m2.setName("123"); + self.assertTrue(not m2.isEqual(m,1e-12)); + m2.copyTinyStringsFrom(m); + self.assertTrue(m2.isEqual(m,1e-12)); + m2.getCoords().setInfoOnComponent(1,"eee"); + self.assertTrue(not m2.isEqual(m,1e-12)); + m2.copyTinyStringsFrom(m); + self.assertTrue(m2.isEqual(m,1e-12)); + pass + + def testTryToShareSameCoordsPermute(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + m2=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + #self.assertTrue(m.getCoords()!=m2.getCoords()); + m.tryToShareSameCoordsPermute(m2,1e-12); + #self.assertTrue(m.getCoords()==m2.getCoords()); + self.assertTrue(m2.isEqual(m,1e-12)); + renum1=[1,2,0,5,8,7,4,3,6] + m.renumberNodes(renum1,9); + #self.assertTrue(m.getCoords()!=m2.getCoords()); + self.assertTrue(not m2.isEqual(m,1e-12)); + m.tryToShareSameCoordsPermute(m2,1e-12); + #self.assertTrue(m.getCoords()==m2.getCoords()); + self.assertTrue(m2.isEqual(m,1e-12)); + pass + + def testTryToShareSameCoordsPermute2(self): + m1=MEDCouplingDataForTest.build2DTargetMesh_4(); + targetCoords=[-0.3,-0.3, 0.2,-0.3, -0.3,0.2, 0.2,0.2 ] + targetConn=[0,2,3,1] + m2=MEDCouplingUMesh.New(); + m2.setMeshDimension(2); + m2.allocateCells(1); + m2.insertNextCell(NORM_QUAD4,4,targetConn[0:4]) + m2.finishInsertingCells(); + myCoords=DataArrayDouble.New(); + myCoords.setValues(targetCoords,4,2); + m2.setCoords(myCoords); + m2.checkCoherency(); + m1.checkCoherency(); + # + expected1=[0.25,0.125,0.125,0.25,0.25] + f1=m1.getMeasureField(False); + f2=m2.getMeasureField(False); + self.assertEqual(5,f1.getArray().getNumberOfTuples()); + self.assertEqual(1,f2.getArray().getNumberOfTuples()); + for i in xrange(5): + self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),12); + pass + self.assertAlmostEqual(expected1[0],f2.getIJ(0,0),12); + self.assertRaises(Exception,m1.tryToShareSameCoordsPermute,m2,1e-12);# <- here in this order the sharing is impossible. + # Let's go for deeper test of tryToShareSameCoordsPermute + m2.tryToShareSameCoordsPermute(m1,1e-12); + f1=m1.getMeasureField(False); + f2=m2.getMeasureField(False); + self.assertEqual(5,f1.getArray().getNumberOfTuples()); + self.assertEqual(1,f2.getArray().getNumberOfTuples()); + for i in xrange(5): + self.assertAlmostEqual(expected1[i],f1.getIJ(i,0),12); + pass + self.assertAlmostEqual(expected1[0],f2.getIJ(0,0),12); + pass + + def testChangeUnderlyingMesh1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_3(); + mesh2=MEDCouplingDataForTest.build2DTargetMesh_3(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + arr=[7., 107., 8., 108., 9., 109., 10., 110., 11., 111., 12., 112., 13., 113., 14., 114., 15., 115., 16., 116.] + array.setValues(arr,mesh1.getNumberOfCells(),2); + f1.setArray(array); + # + renum=[0,2,1,3,4,5,6,8,7,9] + mesh2.renumberCells(renum,False); + #self.assertTrue(f1.getMesh()==mesh1); + f1.changeUnderlyingMesh(mesh1,10,1e-12);# nothing done only to check that nothing done. + #self.assertTrue(f1.getMesh()==mesh1); + f1.changeUnderlyingMesh(mesh2,10,1e-12); + #self.assertTrue(f1.getMesh()==mesh2); + expected1=[7.,107.,9.,109.,8.,108.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.] + for i in xrange(20): + self.assertAlmostEqual(expected1[i],f1.getArray().getIJ(0,i),12); + pass + # + f1=MEDCouplingFieldDouble.New(ON_NODES,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + arr2=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.,17.,117.] + array.setValues(arr2,mesh1.getNumberOfNodes(),2); + f1.setArray(array); + # + renum2=[0,2,10,3,4,5,6,8,7,9,1] + mesh2.renumberNodes(renum2,11); + #self.assertTrue(f1.getMesh()==mesh1); + f1.changeUnderlyingMesh(mesh2,10,1e-12); + #self.assertTrue(f1.getMesh()==mesh2); + expected2=[7.,107.,9.,109.,17.,117.,10.,110.,11.,111.,12.,112.,13.,113.,15.,115.,14.,114.,16.,116.,8.,108.] + for i in xrange(22): + self.assertAlmostEqual(expected2[i],f1.getArray().getIJ(0,i),12); + pass + pass + + def testGetMaxValue1(self): + m=MEDCouplingDataForTest.build3DSurfTargetMesh_1(); + nbOfCells=m.getNumberOfCells(); + f=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME); + f.setMesh(m); + a1=DataArrayDouble.New(); + val1=[3.,4.,5.,6.,7.] + a1.setValues(val1,nbOfCells,1); + a2=DataArrayDouble.New(); + val2=[0.,1.,2.,8.,7.] + a2.setValues(val2,nbOfCells,1); + f.setArray(a1); + f.setEndArray(a2); + f.setEndTime(3.,3,4); + f.checkCoherency(); + # + self.assertAlmostEqual(8.,f.getMaxValue(),14); + self.assertAlmostEqual(0.,f.getMinValue(),14); + self.assertAlmostEqual(5.,f.getAverageValue(),14); + self.assertAlmostEqual(5.125,f.getWeightedAverageValue(),14); + a1.setIJ(0,2,9.5); + self.assertAlmostEqual(9.5,f.getMaxValue(),14); + self.assertAlmostEqual(0.,f.getMinValue(),14); + a2.setIJ(0,0,9.); + self.assertAlmostEqual(9.5,f.getMaxValue(),14); + self.assertAlmostEqual(1.,f.getMinValue(),14); + pass + + def testSubstractInPlaceDM1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_3(); + mesh2=MEDCouplingDataForTest.build2DTargetMesh_3(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + arr=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.] + array.setValues(arr,mesh1.getNumberOfCells(),2); + f1.setArray(array); + # + self.assertEqual(10,f1.getNumberOfTuples()); + self.assertEqual(2,f1.getNumberOfComponents()); + self.assertEqual(20,f1.getNumberOfValues()); + # + renum=[0,2,1,3,4,5,6,8,7,9] + mesh2.renumberCells(renum,False); + # + f2=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f2.setMesh(mesh2); + array=DataArrayDouble.New(); + arr2=[7.1,107.1,9.1,109.1,8.1,108.1,10.1,110.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] + array.setValues(arr2,mesh2.getNumberOfCells(),2); + f2.setArray(array); + # + f1.substractInPlaceDM(f2,10,1e-12); + f1.applyFunc(1,"abs(x+y+0.2)"); + self.assertAlmostEqual(0.,f1.getMaxValue(),13); + pass + + def testDotCrossProduct1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_3(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setTime(2.3,5,6); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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.] + array.setValues(arr1,mesh1.getNumberOfCells(),3); + f1.setArray(array); + f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f2.setTime(7.8,4,5); + f2.setMesh(mesh1); + array=DataArrayDouble.New(); + 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.] + array.setValues(arr2,mesh1.getNumberOfCells(),3); + f2.setArray(array); + # + f3=f1.dot(f2); + expected1=[842.,1820.,2816.,3830.,4862.,5912.,6980.,8066.,9170.,10292.] + for i in xrange(10): + self.assertAlmostEqual(expected1[i],f3.getIJ(i,0),9); + pass + # + f4=f1.crossProduct(f2); + 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.] + for i in xrange(30): + self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9); + pass + pass + + def testMinMaxFields1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_3(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setTime(2.3,5,6); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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.] + array.setValues(arr1,mesh1.getNumberOfCells(),3); + f1.setArray(array); + f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f2.setTime(7.8,4,5); + f2.setMesh(mesh1); + array=DataArrayDouble.New(); + 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.] + array.setValues(arr2,mesh1.getNumberOfCells(),3); + f2.setArray(array); + # + f3=f1.max(f2); + 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.] + for i in xrange(30): + self.assertAlmostEqual(expected1[i],f3.getIJ(0,i),9); + pass + # + f4=f1.min(f2); + 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.] + for i in xrange(30): + self.assertAlmostEqual(expected2[i],f4.getIJ(0,i),9); + pass + # + pass + + def testApplyLin1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_3(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,LINEAR_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + arr=[7.,107.,8.,108.,9.,109.,10.,110.,11.,111.,12.,112.,13.,113.,14.,114.,15.,115.,16.,116.] + array.setValues(arr,mesh1.getNumberOfCells(),2); + f1.setArray(array); + # + f1.applyLin(2.,3.,0); + expected1=[17.,107.,19.,108.,21.,109.,23.,110.,25.,111.,27.,112.,29.,113.,31.,114.,33.,115.,35.,116.] + for i in xrange(20): + self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),9); + pass + # + arr2=[2.,102.,3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.] + array=DataArrayDouble.New(); + array.setValues(arr2,mesh1.getNumberOfCells(),2); + f1.setEndArray(array); + # + f1.applyLin(4.,5.,1); + # + expected2=[17.,433.,19.,437.,21.,441.,23.,445.,25.,449.,27.,453.,29.,457.,31.,461.,33.,465.,35.,469.] + for i in xrange(20): + self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),9); + pass + expected3=[2.,413.,3.,417.,4.,421.,5.,425.,6.,429.,7.,433.,8.,437.,9.,441.,10.,445.,11.,449.] + for i in xrange(20): + self.assertAlmostEqual(expected3[i],f1.getEndArray().getIJ(0,i),9); + pass + # + pass + + def testGetIdsInRange1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_3(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setTime(2.3,5,6); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + arr1=[2.,8.,6.,5.,11.,7.,9.,3.,10.,4.] + array.setValues(arr1,mesh1.getNumberOfCells(),1); + f1.setArray(array); + # + f1.checkCoherency(); + da=f1.getIdsInRange(2.9,7.1); + self.failUnlessEqual(5,da.getNbOfElems()); + expected1=[2,3,5,7,9] + self.failUnlessEqual(expected1,list(da.getValues())); + da=f1.getIdsInRange(8.,12.); + self.failUnlessEqual(4,da.getNbOfElems()); + expected2=[1,4,6,8] + self.failUnlessEqual(expected2,list(da.getValues())); + # + pass + + def testBuildSubPart1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setTime(2.3,5,6); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + arr1=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.] + array.setValues(arr1,mesh1.getNumberOfCells(),2); + f1.setArray(array); + # + part1=[2,1,4] + f2=f1.buildSubPart(part1); + self.failUnlessEqual(3,f2.getNumberOfTuples()); + self.failUnlessEqual(2,f2.getNumberOfComponents()); + expected1=[5.,105.,4.,104.,7.,107.] + for i in xrange(6): + self.assertAlmostEqual(f2.getIJ(0,i),expected1[i],12); + pass + self.failUnlessEqual(3,f2.getMesh().getNumberOfCells()); + self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes()); + self.failUnlessEqual(2,f2.getMesh().getSpaceDimension()); + self.failUnlessEqual(2,f2.getMesh().getMeshDimension()); + m2C=f2.getMesh(); + self.failUnlessEqual(13,m2C.getMeshLength()); + 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] + for i in xrange(12): + self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12); + pass + expected3=[3,2,3,1,3,0,2,1,4,4,5,3,2] + self.failUnlessEqual(expected3,list(m2C.getNodalConnectivity().getValues())); + expected4=[0,4,8,13] + self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues())); + # Test with field on nodes. + f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME); + f1.setTime(2.3,5,6); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + arr2=[3.,103.,4.,104.,5.,105.,6.,106.,7.,107.,8.,108.,9.,109.,10.,110.,11.,111.] + array.setValues(arr2,mesh1.getNumberOfNodes(),2); + f1.setArray(array); + part2=[1,4,2,5] + f2=f1.buildSubPart(part2); + self.failUnlessEqual(4,f2.getNumberOfTuples()); + self.failUnlessEqual(2,f2.getNumberOfComponents()); + expected5=[4.,104.,5.,105.,7.,107.,8.,108.] + for i in xrange(8): + self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12); + pass + self.failUnlessEqual(2,f2.getMesh().getNumberOfCells()); + self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes()); + self.failUnlessEqual(2,f2.getMesh().getSpaceDimension()); + self.failUnlessEqual(2,f2.getMesh().getMeshDimension()); + m2C=f2.getMesh(); + self.failUnlessEqual(8,m2C.getMeshLength()); + for i in xrange(8):#8 is not an error + self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12); + pass + self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:]); + self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]); + self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues())); + #idem previous because nodes of cell#4 are not fully present in part3 + part3=[1,4,2,5,7] + arrr=DataArrayInt.New(); + arrr.setValues(part3,5,1); + f2=f1.buildSubPart(arrr); + self.failUnlessEqual(4,f2.getNumberOfTuples()); + self.failUnlessEqual(2,f2.getNumberOfComponents()); + for i in xrange(8): + self.assertAlmostEqual(f2.getIJ(0,i),expected5[i],12); + pass + self.failUnlessEqual(2,f2.getMesh().getNumberOfCells()); + self.failUnlessEqual(4,f2.getMesh().getNumberOfNodes()); + self.failUnlessEqual(2,f2.getMesh().getSpaceDimension()); + self.failUnlessEqual(2,f2.getMesh().getMeshDimension()); + m2C=f2.getMesh(); + self.failUnlessEqual(8,m2C.getMeshLength()); + for i in xrange(8):#8 is not an error + self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12); + pass + self.failUnlessEqual(expected3[:4],list(m2C.getNodalConnectivity().getValues())[4:8]); + self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[:4]); + self.failUnlessEqual(expected4[:3],list(m2C.getNodalConnectivityIndex().getValues())); + # + part4=[1,4,2,5,7,8] + f2=f1.buildSubPart(part4); + self.failUnlessEqual(6,f2.getNumberOfTuples()); + self.failUnlessEqual(2,f2.getNumberOfComponents()); + expected6=[4.,104.,5.,105.,7.,107.,8.,108.,10.,110.,11.,111.] + for i in xrange(12): + self.assertAlmostEqual(f2.getIJ(0,i),expected6[i],12); + pass + self.failUnlessEqual(3,f2.getMesh().getNumberOfCells()); + self.failUnlessEqual(6,f2.getMesh().getNumberOfNodes()); + self.failUnlessEqual(2,f2.getMesh().getSpaceDimension()); + self.failUnlessEqual(2,f2.getMesh().getMeshDimension()); + m2C=f2.getMesh(); + self.failUnlessEqual(13,m2C.getMeshLength()); + for i in xrange(12): + self.assertAlmostEqual(expected2[i],m2C.getCoords().getIJ(0,i),12); + pass + self.failUnlessEqual(expected3[0:4],list(m2C.getNodalConnectivity().getValues())[4:8]); + self.failUnlessEqual(expected3[4:8],list(m2C.getNodalConnectivity().getValues())[0:4]); + self.failUnlessEqual(expected3[8:13],list(m2C.getNodalConnectivity().getValues())[8:13]); + self.failUnlessEqual(expected4,list(m2C.getNodalConnectivityIndex().getValues())); + pass + + def testDoublyContractedProduct1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),6); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.doublyContractedProduct(); + f2.checkCoherency(); + self.assertEqual(1,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + for i in xrange(5): + self.assertAlmostEqual(3906.56,f2.getIJ(i,0),9); + pass + # + pass + + def testDeterminant1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,CONST_ON_TIME_INTERVAL); + f1.setTime(2.3,5,6); + f1.setEndTime(3.8,7,3); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),4); + f1.setArray(array); + #4 components + f1.checkCoherency(); + f2=f1.determinant(); + f2.checkCoherency(); + self.assertEqual(CONST_ON_TIME_INTERVAL,f2.getTimeDiscretization()); + self.assertEqual(1,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfValues()); + for i in xrange(5): + self.assertAlmostEqual(-2.42,f2.getIJ(i,0),13); + pass + #6 components multi arrays with end array not defined + f1=MEDCouplingFieldDouble.New(ON_NODES,LINEAR_TIME); + f1.setTime(2.3,5,6); + f1.setEndTime(3.8,7,3); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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, + 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] + array.setValues(arr2,mesh1.getNumberOfNodes(),6); + f1.setArray(array); + self.assertRaises(Exception,f1.checkCoherency);#no end array specified ! + # + f2=f1.determinant(); + self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization()); + self.assertEqual(1,f2.getArray().getNumberOfComponents()); + self.assertEqual(9,f2.getNumberOfTuples()); + for i in xrange(9): + self.assertAlmostEqual(137.335,f2.getIJ(i,0),10); + pass + #6 components multi arrays with end array defined + array=DataArrayDouble.New(); + 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, + 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] + array.setValues(arr3,mesh1.getNumberOfNodes(),6); + f1.setEndArray(array); + f1.checkCoherency(); + f2=f1.determinant(); + f2.checkCoherency(); + self.assertEqual(LINEAR_TIME,f2.getTimeDiscretization()); + self.assertEqual(1,f2.getNumberOfComponents()); + self.assertEqual(9,f2.getNumberOfTuples()); + time2,it,order=f2.getTime() + self.assertAlmostEqual(2.3,time2,12); + self.assertEqual(5,it); + self.assertEqual(6,order); + time2,it,order=f2.getEndTime() + self.assertAlmostEqual(3.8,time2,12); + self.assertEqual(7,it); + self.assertEqual(3,order); + for i in xrange(9): + self.assertAlmostEqual(137.335,f2.getIJ(i,0),10); + self.assertAlmostEqual(1289.685,f2.getEndArray().getIJ(i,0),9); + pass + #9 components + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME); + f1.setTime(7.8,10,2); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr4,mesh1.getNumberOfCells(),9); + f1.setArray(array); + # + f1.checkCoherency(); + f2=f1.determinant(); + f2.checkCoherency(); + self.assertEqual(ONE_TIME,f2.getTimeDiscretization()); + self.assertEqual(1,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + time2,it,order=f2.getTime() + self.assertAlmostEqual(7.8,time2,12); + self.assertEqual(10,it); + self.assertEqual(2,order); + for i in xrange(5): + self.assertAlmostEqual(3.267,f2.getIJ(i,0),13); + pass + pass + + def testEigenValues1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),6); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.eigenValues(); + f2.checkCoherency(); + self.assertEqual(3,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + expected1=[13.638813677891717,-4.502313844635971,-2.2364998332557486] + for i in xrange(5): + self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13); + self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13); + self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13); + pass + pass + + def testEigenVectors1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),6); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.eigenVectors(); + f2.checkCoherency(); + self.assertEqual(9,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + expected1=[0.5424262364180696, 0.5351201064614425, 0.6476266283176001,#eigenvect 0 + 0.7381111277307373, 0.06458838384003074, -0.6715804522117897,#eigenvect 1 + -0.4012053603397987, 0.8423032781211455, -0.3599436712889738#eigenvect 2 + ] + for i in xrange(5): + self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13); + self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13); + self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13); + self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13); + self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13); + self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13); + self.assertAlmostEqual(expected1[6],f2.getIJ(i,6),13); + self.assertAlmostEqual(expected1[7],f2.getIJ(i,7),13); + self.assertAlmostEqual(expected1[8],f2.getIJ(i,8),13); + pass + # + pass + + def testInverse1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),9); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.inverse(); + f2.checkCoherency(); + self.assertEqual(9,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + expected1=[-2.6538108356290113, 2.855831037649208, -1.1111111111111067, 3.461891643709813, -4.775022956841121, 2.2222222222222143, -1.1111111111111054, 2.222222222222214, -1.1111111111111072] + for i in xrange(5): + self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13); + self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13); + self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13); + self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13); + self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13); + self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13); + self.assertAlmostEqual(expected1[6],f2.getIJ(i,6),13); + self.assertAlmostEqual(expected1[7],f2.getIJ(i,7),13); + self.assertAlmostEqual(expected1[8],f2.getIJ(i,8),13); + pass + # + array=DataArrayDouble.New(); + 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] + array.setValues(arr3,mesh1.getNumberOfCells(),6); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.inverse(); + f2.checkCoherency(); + self.assertEqual(6,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + expected3=[-0.3617705098531818, -0.8678630828458127, -0.026843764174972983, 0.5539957431465833, 0.13133439560823013, -0.05301294502145887] + for i in xrange(5): + self.assertAlmostEqual(expected3[0],f2.getIJ(i,0),13); + self.assertAlmostEqual(expected3[1],f2.getIJ(i,1),13); + self.assertAlmostEqual(expected3[2],f2.getIJ(i,2),13); + self.assertAlmostEqual(expected3[3],f2.getIJ(i,3),13); + self.assertAlmostEqual(expected3[4],f2.getIJ(i,4),13); + self.assertAlmostEqual(expected3[5],f2.getIJ(i,5),13); + pass + # + array=DataArrayDouble.New(); + 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] + array.setValues(arr2,mesh1.getNumberOfCells(),4); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.inverse(); + f2.checkCoherency(); + self.assertEqual(4,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + expected2=[-1.8595041322314059, 0.9504132231404963, 1.404958677685951, -0.49586776859504156] + for i in xrange(5): + self.assertAlmostEqual(expected2[0],f2.getIJ(i,0),13); + self.assertAlmostEqual(expected2[1],f2.getIJ(i,1),13); + self.assertAlmostEqual(expected2[2],f2.getIJ(i,2),13); + self.assertAlmostEqual(expected2[3],f2.getIJ(i,3),13); + pass + # + pass + + def testTrace1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),9); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.trace(); + f2.checkCoherency(); + self.assertEqual(1,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + for i in xrange(5): + self.assertAlmostEqual(15.9,f2.getIJ(i,0),13); + pass + # + array=DataArrayDouble.New(); + 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] + array.setValues(arr3,mesh1.getNumberOfCells(),6); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.trace(); + f2.checkCoherency(); + self.assertEqual(1,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + for i in xrange(5): + self.assertAlmostEqual(25.8,f2.getIJ(i,0),13); + pass + # + array=DataArrayDouble.New(); + 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] + array.setValues(arr2,mesh1.getNumberOfCells(),4); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.trace(); + f2.checkCoherency(); + self.assertEqual(1,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + for i in xrange(5): + self.assertAlmostEqual(5.7,f2.getIJ(i,0),13); + pass + # + pass + + def testDeviator1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),6); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.deviator(); + f2.checkCoherency(); + self.assertEqual(6,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + expected1=[-1.1,0.,1.1,4.5,5.6,6.7] + for i in xrange(5): + self.assertAlmostEqual(expected1[0],f2.getIJ(i,0),13); + self.assertAlmostEqual(expected1[1],f2.getIJ(i,1),13); + self.assertAlmostEqual(expected1[2],f2.getIJ(i,2),13); + self.assertAlmostEqual(expected1[3],f2.getIJ(i,3),13); + self.assertAlmostEqual(expected1[4],f2.getIJ(i,4),13); + self.assertAlmostEqual(expected1[5],f2.getIJ(i,5),13); + pass + # + pass + + def testMagnitude1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),5); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.magnitude(); + f2.checkCoherency(); + self.assertEqual(1,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + for i in xrange(5): + self.assertAlmostEqual(8.3606219864313918,f2.getIJ(i,0),13); + pass + # + pass + + def testMaxPerTuple1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),5); + f1.setArray(array); + f1.checkCoherency(); + # + f2=f1.maxPerTuple(); + f2.checkCoherency(); + self.assertEqual(1,f2.getNumberOfComponents()); + self.assertEqual(5,f2.getNumberOfTuples()); + for i in xrange(5): + self.assertAlmostEqual(5.6,f2.getIJ(i,0),13); + pass + # + pass + + def testChangeNbOfComponents(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),5); + f1.setArray(array); + f1.checkCoherency(); + # + f1.changeNbOfComponents(3,7.77); + f1.checkCoherency(); + self.assertEqual(3,f1.getNumberOfComponents()); + self.assertEqual(5,f1.getNumberOfTuples()); + 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] + for i in xrange(15): + self.assertAlmostEqual(expected1[i],f1.getIJ(0,i),13); + pass + f1.changeNbOfComponents(4,7.77); + f1.checkCoherency(); + self.assertEqual(4,f1.getNumberOfComponents()); + self.assertEqual(5,f1.getNumberOfTuples()); + 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] + for i in xrange(20): + self.assertAlmostEqual(expected2[i],f1.getIJ(0,i),13); + pass + # + pass + + def testSortPerTuple1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + f1=MEDCouplingFieldDouble.New(ON_CELLS,NO_TIME); + f1.setMesh(mesh1); + array=DataArrayDouble.New(); + 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] + array.setValues(arr1,mesh1.getNumberOfCells(),5); + f1.setArray(array); + f1.checkCoherency(); + # + f1.sortPerTuple(True); + f1.checkCoherency(); + self.assertEqual(5,f1.getNumberOfComponents()); + self.assertEqual(5,f1.getNumberOfTuples()); + for i in xrange(5): + self.assertAlmostEqual(arr1[0],f1.getIJ(i,0),13); + self.assertAlmostEqual(arr1[1],f1.getIJ(i,1),13); + self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13); + self.assertAlmostEqual(arr1[3],f1.getIJ(i,3),13); + self.assertAlmostEqual(arr1[4],f1.getIJ(i,4),13); + pass + # + f1.sortPerTuple(False); + f1.checkCoherency(); + self.assertEqual(5,f1.getNumberOfComponents()); + self.assertEqual(5,f1.getNumberOfTuples()); + for i in xrange(5): + self.assertAlmostEqual(arr1[4],f1.getIJ(i,0),13); + self.assertAlmostEqual(arr1[3],f1.getIJ(i,1),13); + self.assertAlmostEqual(arr1[2],f1.getIJ(i,2),13); + self.assertAlmostEqual(arr1[1],f1.getIJ(i,3),13); + self.assertAlmostEqual(arr1[0],f1.getIJ(i,4),13); + pass + # + pass + + def testIsEqualWithoutConsideringStr1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + mesh2=MEDCouplingDataForTest.build2DTargetMesh_1(); + # + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2.setName("rr"); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + da1,da2=mesh1.checkGeoEquivalWith(mesh2,2,1e-12); + self.assertRaises(Exception,mesh1.checkGeoEquivalWith,mesh2,0,1e-12); + mesh2.setName(""); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2.getCoords().setInfoOnComponent(0,"tty"); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2.getCoords().setInfoOnComponent(0,""); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2.getCoords().setInfoOnComponent(1,"tty"); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2.getCoords().setInfoOnComponent(1,""); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + tmp=mesh2.getCoords().getIJ(0,3); + mesh2.getCoords().setIJ(0,3,9999.); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2.getCoords().setIJ(0,3,tmp); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + tmp2=mesh2.getNodalConnectivity().getIJ(0,4); + mesh2.getNodalConnectivity().setIJ(0,4,0); + self.assertTrue(not mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(not mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + mesh2.getNodalConnectivity().setIJ(0,4,tmp2); + self.assertTrue(mesh1.isEqual(mesh2,1e-12)); + self.assertTrue(mesh1.isEqualWithoutConsideringStr(mesh2,1e-12)); + # + f1=mesh1.getMeasureField(True); + f2=mesh2.getMeasureField(True); + self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + f2.setName("ftest"); + self.assertTrue(not f1.isEqual(f2,1e-12,1e-12)); + self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + f1.setName("ftest"); + self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + # + f2.getArray().setInfoOnComponent(0,"eee"); + self.assertTrue(not f1.isEqual(f2,1e-12,1e-12)); + self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + f2.getArray().setInfoOnComponent(0,""); + self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + # + f2.getArray().setIJ(1,0,0.123); + self.assertTrue(not f1.isEqual(f2,1e-12,1e-12)); + self.assertTrue(not f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + f2.getArray().setIJ(1,0,0.125); + self.assertTrue(f1.isEqual(f2,1e-12,1e-12)); + self.assertTrue(f1.isEqualWithoutConsideringStr(f2,1e-12,1e-12)); + # + pass + def testGetNodeIdsOfCell1(self): + mesh1=MEDCouplingDataForTest.build2DTargetMesh_1(); + li=mesh1.getNodeIdsOfCell(1) + expected1=[1, 4, 2] + self.assertEqual(expected1,list(li)) + li=mesh1.getCoordinatesOfNode(4) + self.assertEqual(2,len(li)) + self.assertAlmostEqual(0.2,li[0],13); + self.assertAlmostEqual(0.2,li[1],13); + li=mesh1.getCoords().getValuesAsTuple() + self.assertEqual(9,len(li)) + li2=mesh1.getNodalConnectivityIndex().getValuesAsTuple() + self.assertEqual(6,len(li2)) + 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..d152e2a4b --- /dev/null +++ b/src/MEDCoupling_Swig/MEDCouplingDataForTest.py @@ -0,0 +1,338 @@ +# -*- 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; + + def build2DTargetMesh_2(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, 0,4,1, 1,4,2, 4,5,2, 3,6,4, 6,7,4, 4,7,5, 7,8,5 ] + targetMesh=MEDCouplingUMesh.New(); + targetMesh.setMeshDimension(2); + targetMesh.allocateCells(8); + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[0:3]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[3:6]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[6:9]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[9:12]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[12:15]) + targetMesh.insertNextCell(NORM_TRI3,3,targetConn[15: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,9,2); + targetMesh.setCoords(myCoords); + return targetMesh; + + def build1DTargetMesh_3(cls): + ret=MEDCouplingUMesh.New("1DMesh_3",1); + ret.allocateCells(4); + conn=[0,1,2, 3,4, 6,5,7 ,9,8] + ret.insertNextCell(NORM_SEG3,3,conn[0:3]) + ret.insertNextCell(NORM_SEG2,2,conn[3:5]) + ret.insertNextCell(NORM_SEG3,3,conn[5:8]) + ret.insertNextCell(NORM_SEG2,2,conn[8:10]) + ret.finishInsertingCells(); + coords=[0.5,1.,0.8,5.,5.21,0.5,1.1,0.7,5.,5.31] + myCoords=DataArrayDouble.New(); + myCoords.setValues(coords,10,1); + ret.setCoords(myCoords); + return ret; + + def build2DCurveTargetMesh_3(cls): + ret=MEDCouplingUMesh.New("2DCurveMesh_3",1); + ret.allocateCells(4); + conn=[0,1,2, 3,4, 6,5,7 ,9,8] + ret.insertNextCell(NORM_SEG3,3,conn[0:3]) + ret.insertNextCell(NORM_SEG2,2,conn[3:5]) + ret.insertNextCell(NORM_SEG3,3,conn[5:8]) + ret.insertNextCell(NORM_SEG2,2,conn[8:10]) + ret.finishInsertingCells(); + coords=[0.5,0.5,1.,1.,0.8,0.8,5.,5.,5.21,5.21,0.5,0.5,1.1,1.1,0.7,0.7,5.,5.,5.31,5.31] + myCoords=DataArrayDouble.New(); + myCoords.setValues(coords,10,2); + ret.setCoords(myCoords); + return ret; + + def build2DTargetMesh_3(cls): + ret=MEDCouplingUMesh.New("2DMesh_3",2); + ret.allocateCells(10); + conn=[0,1,2, 0,1,3,4, 0,1,3,5,4, 0,1,2,6,7,8, 0,1,3,4,6,9,2,10, 0,2,1, 0,4,3,1, 0,4,5,3,1, 0,2,1,8,7,6, 0,4,3,1,10,2,9,6] + ret.insertNextCell(NORM_TRI3,3,conn[0:3]) + ret.insertNextCell(NORM_QUAD4,4,conn[3:7]) + ret.insertNextCell(NORM_POLYGON,5,conn[7:12]) + ret.insertNextCell(NORM_TRI6,6,conn[12:18]) + ret.insertNextCell(NORM_QUAD8,8,conn[18:26]) + ret.insertNextCell(NORM_TRI3,3,conn[26:29]) + ret.insertNextCell(NORM_QUAD4,4,conn[29:33]) + ret.insertNextCell(NORM_POLYGON,5,conn[33:38]) + ret.insertNextCell(NORM_TRI6,6,conn[38:44]) + ret.insertNextCell(NORM_QUAD8,8,conn[44:52]) + ret.finishInsertingCells(); + coords=[0.,0.,1.,0.,0.5,1.,1.,1.,0.,1.,0.5,2.,0.5,0.,0.75,0.5,0.25,0.5,1.,0.5,0.,0.5] + myCoords=DataArrayDouble.New(); + myCoords.setValues(coords,11,2); + ret.setCoords(myCoords); + ret.checkCoherency(); + return ret; + + def build2DTargetMesh_4(cls): + targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-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,4,5,1, 1,5,3, 5,6,2, 7,8,5,4, 8,9,6,5] + 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,10,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) + build2DTargetMesh_2=classmethod(build2DTargetMesh_2) + build1DTargetMesh_3=classmethod(build1DTargetMesh_3) + build2DCurveTargetMesh_3=classmethod(build2DCurveTargetMesh_3) + build2DTargetMesh_3=classmethod(build2DTargetMesh_3) + build2DTargetMesh_4=classmethod(build2DTargetMesh_4) + pass diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index 4b8e950b2..b5d9b2a29 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -17,28 +17,71 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +#ifdef WITH_NUMPY2 +#include +#endif + static PyObject* convertMesh(ParaMEDMEM::MEDCouplingMesh* mesh, int owner) { PyObject *ret; if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner); return ret; } static PyObject *convertIntArrToPyList(const int *ptr, int size) { +#ifndef WITH_NUMPY2 PyObject *ret=PyList_New(size); for(int i=0;i(tmp)); +#endif } -static int *convertPyToNewIntArr(PyObject *pyLi, int size) +static PyObject *convertIntArrToPyList2(const std::vector& v) +{ +#ifndef WITH_NUMPY2 + int size=v.size(); + PyObject *ret=PyList_New(size); + for(int i=0;i& arr) { if(PyList_Check(pyLi)) { int size=PyList_Size(pyLi); - int *tmp=new int[size]; + arr.resize(size); for(int i=0;i& v) +{ + int size=v.size(); + PyObject *ret=PyList_New(size); + for(int i=0;i& v) +{ + if(PyList_Check(ms)) + { + int size=PyList_Size(ms); + v.resize(size); + for(int i=0;i(argp); + v[i]=arg; + } + } + else + { + PyErr_SetString(PyExc_TypeError,"convertPyObjToVecUMeshes : not a list"); + PyErr_Print(); + } +} + +void convertPyObjToVecDataArrayInt(PyObject *ms, std::vector& v) +{ + if(PyList_Check(ms)) + { + int size=PyList_Size(ms); + v.resize(size); + for(int i=0;i(argp); + v[i]=arg; + } + } + else + { + PyErr_SetString(PyExc_TypeError,"convertPyObjToVecDataArrayInt : not a list"); + PyErr_Print(); + } +} diff --git a/src/MEDCoupling_Swig/Makefile.am b/src/MEDCoupling_Swig/Makefile.am index 483a7e8e1..fd14551f1 100644 --- a/src/MEDCoupling_Swig/Makefile.am +++ b/src/MEDCoupling_Swig/Makefile.am @@ -58,4 +58,8 @@ _libMEDCouplingRemapper_Swig_la_LDFLAGS = -module $(PYTHON_LIBS) \ CLEANFILES = libMEDCoupling_SwigWRAP.cxx libMEDCoupling_Swig.py libMEDCouplingRemapper_SwigWRAP.cxx libMEDCouplingRemapper_Swig.py -dist_salomescript_DATA= MEDCouplingBasicsTest.py MEDCouplingRemapperTest.py libMEDCoupling_Swig.py libMEDCouplingRemapper_Swig.py +dist_salomescript_DATA= MEDCouplingBasicsTest.py MEDCouplingRemapperTest.py libMEDCoupling_Swig.py libMEDCouplingRemapper_Swig.py MEDCouplingDataForTest.py + +UNIT_TEST_PROG = MEDCouplingBasicsTest.py MEDCouplingRemapperTest.py + +#check : tests diff --git a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i index ec02326ac..bd343a1d1 100644 --- a/src/MEDCoupling_Swig/libMEDCoupling_Swig.i +++ b/src/MEDCoupling_Swig/libMEDCoupling_Swig.i @@ -21,61 +21,433 @@ #define MEDCOUPLING_EXPORT +%include std_vector.i +%include std_string.i + %{ #include "MEDCouplingMemArray.hxx" #include "MEDCouplingUMesh.hxx" +#include "MEDCouplingExtrudedMesh.hxx" +#include "MEDCouplingCMesh.hxx" #include "MEDCouplingField.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingGaussLocalization.hxx" #include "MEDCouplingTypemaps.i" using namespace ParaMEDMEM; using namespace INTERP_KERNEL; %} +%template(ivec) std::vector; +%template(dvec) std::vector; +%template(svec) std::vector; + %typemap(out) ParaMEDMEM::MEDCouplingMesh* { $result=convertMesh($1,$owner); } +%typemap(out) ParaMEDMEM::MEDCouplingPointSet* +{ + $result=convertMesh($1,$owner); +} + +#ifdef WITH_NUMPY2 +%init %{ import_array(); %} +#endif + +%feature("autodoc", "1"); +%feature("docstring"); + %newobject ParaMEDMEM::DataArrayDouble::New; %newobject ParaMEDMEM::DataArrayInt::New; +%newobject ParaMEDMEM::DataArrayDouble::convertToIntArr; +%newobject ParaMEDMEM::DataArrayInt::convertToDblArr; %newobject ParaMEDMEM::MEDCouplingUMesh::New; +%newobject ParaMEDMEM::MEDCouplingField::buildWeightingField; %newobject ParaMEDMEM::MEDCouplingFieldDouble::New; %newobject ParaMEDMEM::MEDCouplingFieldDouble::mergeFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::doublyContractedProduct; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::determinant; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::eigenValues; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::eigenVectors; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::inverse; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::trace; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::deviator; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::magnitude; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::maxPerTuple; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::dotFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::dot; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::crossProductFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::crossProduct; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::maxFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::max; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::minFields; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::min; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::getIdsInRange; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::buildSubPart; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator+; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator-; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator*; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::operator/; %newobject ParaMEDMEM::MEDCouplingUMesh::clone; %newobject ParaMEDMEM::DataArrayDouble::deepCopy; %newobject ParaMEDMEM::DataArrayDouble::performCpy; %newobject ParaMEDMEM::DataArrayInt::deepCopy; %newobject ParaMEDMEM::DataArrayInt::performCpy; +%newobject ParaMEDMEM::DataArrayInt::substr; +%newobject ParaMEDMEM::DataArrayInt::changeNbOfComponents; +%newobject ParaMEDMEM::DataArrayInt::selectByTupleId; +%newobject ParaMEDMEM::DataArrayDouble::aggregate; +%newobject ParaMEDMEM::DataArrayDouble::dot; +%newobject ParaMEDMEM::DataArrayDouble::crossProduct; +%newobject ParaMEDMEM::DataArrayDouble::add; +%newobject ParaMEDMEM::DataArrayDouble::substract; +%newobject ParaMEDMEM::DataArrayDouble::multiply; +%newobject ParaMEDMEM::DataArrayDouble::divide; +%newobject ParaMEDMEM::DataArrayDouble::substr; +%newobject ParaMEDMEM::DataArrayDouble::changeNbOfComponents; +%newobject ParaMEDMEM::DataArrayDouble::getIdsInRange; +%newobject ParaMEDMEM::DataArrayDouble::selectByTupleId; +%newobject ParaMEDMEM::DataArrayDouble::applyFunc; +%newobject ParaMEDMEM::DataArrayDouble::doublyContractedProduct; +%newobject ParaMEDMEM::DataArrayDouble::determinant; +%newobject ParaMEDMEM::DataArrayDouble::eigenValues; +%newobject ParaMEDMEM::DataArrayDouble::eigenVectors; +%newobject ParaMEDMEM::DataArrayDouble::inverse; +%newobject ParaMEDMEM::DataArrayDouble::trace; +%newobject ParaMEDMEM::DataArrayDouble::deviator; +%newobject ParaMEDMEM::DataArrayDouble::magnitude; +%newobject ParaMEDMEM::DataArrayDouble::maxPerTuple; %newobject ParaMEDMEM::MEDCouplingFieldDouble::clone; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::cloneWithMesh; +%newobject ParaMEDMEM::MEDCouplingFieldDouble::buildNewTimeReprFromThis; +%newobject ParaMEDMEM::MEDCouplingMesh::getCoordinatesAndOwner; +%newobject ParaMEDMEM::MEDCouplingMesh::getBarycenterAndOwner; +%newobject ParaMEDMEM::MEDCouplingMesh::buildOrthogonalField; +%newobject ParaMEDMEM::MEDCouplingMesh::getCellIdsFullyIncludedInNodeIds; +%newobject ParaMEDMEM::MEDCouplingMesh::buildPart; %newobject ParaMEDMEM::MEDCouplingMesh::mergeMyselfWith; %newobject ParaMEDMEM::MEDCouplingMesh::fillFromAnalytic; -%newobject ParaMEDMEM::MEDCouplingUMesh::buildPartOfMySelf; %newobject ParaMEDMEM::MEDCouplingPointSet::zipCoordsTraducer; -%newobject ParaMEDMEM::MEDCouplingUMesh::getMeasureField; +%newobject ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer; +%newobject ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity; +%newobject ParaMEDMEM::MEDCouplingPointSet::buildBoundaryMesh; +%newobject ParaMEDMEM::MEDCouplingMesh::getMeasureField; +%newobject ParaMEDMEM::MEDCouplingUMesh::buildExtrudedMeshFromThis; %newobject ParaMEDMEM::MEDCouplingUMesh::mergeUMeshes; +%newobject ParaMEDMEM::MEDCouplingUMesh::buildNewNumberingFromCommNodesFrmt; +%newobject ParaMEDMEM::MEDCouplingUMesh::rearrange2ConsecutiveCellTypes; +%newobject ParaMEDMEM::MEDCouplingUMesh::convertCellArrayPerGeoType; +%newobject ParaMEDMEM::MEDCouplingUMesh::getRenumArrForConsctvCellTypesSpe; +%newobject ParaMEDMEM::MEDCouplingExtrudedMesh::New; +%newobject ParaMEDMEM::MEDCouplingExtrudedMesh::build3DUnstructuredMesh; +%newobject ParaMEDMEM::MEDCouplingCMesh::New; %feature("unref") DataArrayDouble "$this->decrRef();" +%feature("unref") MEDCouplingPointSet "$this->decrRef();" +%feature("unref") MEDCouplingMesh "$this->decrRef();" %feature("unref") MEDCouplingUMesh "$this->decrRef();" +%feature("unref") MEDCouplingExtrudedMesh "$this->decrRef();" +%feature("unref") MEDCouplingCMesh "$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(); +%ignore ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationIntInfo; +%ignore ParaMEDMEM::MEDCouplingGaussLocalization::pushTinySerializationDblInfo; +%ignore ParaMEDMEM::MEDCouplingGaussLocalization::fillWithValues; +%ignore ParaMEDMEM::MEDCouplingGaussLocalization::buildNewInstanceFromTinyInfo; +%rename (Exception) InterpKernelException; %nodefaultctor; + +namespace INTERP_KERNEL +{ + class Exception + { + public: + Exception(const char* what); + ~Exception() throw (); + const char *what() const throw (); + }; +} + %include "MEDCouplingTimeLabel.hxx" %include "MEDCouplingRefCountObject.hxx" -%include "MEDCouplingMesh.hxx" -%include "MEDCouplingPointSet.hxx" + +namespace ParaMEDMEM +{ + typedef enum + { + UNSTRUCTURED = 5, + UNSTRUCTURED_DESC = 6, + CARTESIAN = 7, + EXTRUDED = 8 + } MEDCouplingMeshType; + + class DataArrayInt; + class DataArrayDouble; + class MEDCouplingFieldDouble; + + class MEDCouplingMesh : public RefCountObject, public TimeLabel + { + public: + void setName(const char *name) { _name=name; } + const char *getName() const { return _name.c_str(); } + virtual MEDCouplingMeshType getType() const = 0; + bool isStructured() const; + virtual bool isEqual(const MEDCouplingMesh *other, double prec) const; + virtual bool isEqualWithoutConsideringStr(const MEDCouplingMesh *other, double prec) const = 0; + virtual void copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception); + virtual void checkCoherency() const throw(INTERP_KERNEL::Exception) = 0; + virtual int getNumberOfCells() const throw(INTERP_KERNEL::Exception) = 0; + virtual int getNumberOfNodes() const throw(INTERP_KERNEL::Exception) = 0; + virtual int getSpaceDimension() const throw(INTERP_KERNEL::Exception) = 0; + virtual int getMeshDimension() const throw(INTERP_KERNEL::Exception) = 0; + virtual DataArrayDouble *getCoordinatesAndOwner() const = 0; + virtual DataArrayDouble *getBarycenterAndOwner() const = 0; + virtual INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const = 0; + virtual std::string simpleRepr() const = 0; + virtual std::string advancedRepr() const = 0; + // tools + virtual void getBoundingBox(double *bbox) const = 0; + virtual MEDCouplingFieldDouble *getMeasureField(bool isAbs) const = 0; + virtual MEDCouplingFieldDouble *getMeasureFieldOnNode(bool isAbs) const = 0; + virtual int getCellContainingPoint(const double *pos, double eps) const = 0; + virtual MEDCouplingFieldDouble *fillFromAnalytic(TypeOfField t, int nbOfComp, const char *func) const throw(INTERP_KERNEL::Exception); + virtual MEDCouplingFieldDouble *buildOrthogonalField() const = 0; + virtual void rotate(const double *center, const double *vector, double angle) = 0; + virtual void translate(const double *vector) = 0; + virtual MEDCouplingMesh *buildPart(const int *start, const int *end) const = 0; + virtual MEDCouplingMesh *mergeMyselfWith(const MEDCouplingMesh *other) const throw(INTERP_KERNEL::Exception) = 0; + virtual bool areCompatibleForMerge(const MEDCouplingMesh *other) const; + static MEDCouplingMesh *mergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2); + %extend + { + std::string __str__() const + { + return self->simpleRepr(); + } + + void renumberCells(PyObject *li, bool check) throw(INTERP_KERNEL::Exception) + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + self->renumberCells(tmp,check); + delete [] tmp; + } + + PyObject *checkGeoEquivalWith(const MEDCouplingMesh *other, int levOfCheck, double prec) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *cellCor, *nodeCor; + self->checkGeoEquivalWith(other,levOfCheck,prec,cellCor,nodeCor); + PyObject *res = PyList_New(2); + PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(cellCor),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, cellCor?SWIG_POINTER_OWN | 0:0 )); + PyList_SetItem(res,1,SWIG_NewPointerObj(SWIG_as_voidptr(nodeCor),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, nodeCor?SWIG_POINTER_OWN | 0:0 )); + return res; + } + DataArrayInt *getCellIdsFullyIncludedInNodeIds(PyObject *li) const + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + DataArrayInt *ret=self->getCellIdsFullyIncludedInNodeIds(tmp,tmp+size); + delete [] tmp; + return ret; + } + PyObject *getNodeIdsOfCell(int cellId) const + { + std::vector conn; + self->getNodeIdsOfCell(cellId,conn); + return convertIntArrToPyList2(conn); + } + + PyObject *getCoordinatesOfNode(int nodeId) const + { + std::vector coo; + self->getCoordinatesOfNode(nodeId,coo); + return convertDblArrToPyList2(coo); + } + } + }; +} + %include "MEDCouplingMemArray.hxx" -%include "MEDCouplingMesh.hxx" %include "NormalizedUnstructuredMesh.hxx" -%include "MEDCouplingField.hxx" %include "MEDCouplingNatureOfField.hxx" +%include "MEDCouplingTimeDiscretization.hxx" +%include "MEDCouplingGaussLocalization.hxx" namespace ParaMEDMEM { + class MEDCouplingPointSet : public ParaMEDMEM::MEDCouplingMesh + { + public: + void updateTime(); + void setCoords(DataArrayDouble *coords); + DataArrayDouble *getCoordinatesAndOwner() const; + bool areCoordsEqual(const MEDCouplingPointSet& other, double prec) const; + void getBoundingBox(double *bbox) const; + void zipCoords(); + double getCaracteristicDimension() const; + void translate(const double *vector); + void scale(const double *point, double factor); + void changeSpaceDimension(int newSpaceDim, double dftVal=0.) throw(INTERP_KERNEL::Exception); + void tryToShareSameCoords(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); + virtual void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception) = 0; + static DataArrayDouble *mergeNodesArray(const MEDCouplingPointSet *m1, const MEDCouplingPointSet *m2); + static MEDCouplingPointSet *buildInstanceFromMeshType(MEDCouplingMeshType type); + 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 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 + { + std::string __str__() const + { + return self->simpleRepr(); + } + + 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(int limitNodeId, double prec) const + { + DataArrayInt *comm, *commIndex; + self->findCommonNodes(limitNodeId,prec,comm,commIndex); + 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 convertIntArrToPyList2(nodes); + } + void rotate(PyObject *center, PyObject *vector, double alpha) + { + int sz; + double *c=convertPyToNewDblArr2(center,&sz); + if(!c) + return ; + double *v=convertPyToNewDblArr2(vector,&sz); + if(!v) + { delete [] c; return ; } + self->rotate(c,v,alpha); + delete [] c; + delete [] v; + } + void translate(PyObject *vector) + { + int sz; + double *v=convertPyToNewDblArr2(vector,&sz); + self->translate(v); + delete [] v; + } + void scale(PyObject *point, double factor) + { + int sz; + double *p=convertPyToNewDblArr2(point,&sz); + 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; + int sz; + double *p=convertPyToNewDblArr2(pt,&sz); + double *v=convertPyToNewDblArr2(vec,&sz); + self->findNodesOnPlane(p,v,eps,nodes); + delete [] v; + delete [] p; + return convertIntArrToPyList2(nodes); + } + static void rotate2DAlg(PyObject *center, double angle, int nbNodes, PyObject *coords) + { + int sz; + double *c=convertPyToNewDblArr2(center,&sz); + double *coo=convertPyToNewDblArr2(coords,&sz); + ParaMEDMEM::MEDCouplingPointSet::rotate2DAlg(c,angle,nbNodes,coo); + for(int i=0;isimpleRepr(); + } + + int getCellContainingPoint(PyObject *p, double eps) const + { + int sz; + double *pos=convertPyToNewDblArr2(p,&sz); + int ret=self->getCellContainingPoint(pos,eps); + delete [] pos; + return ret; + } void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, PyObject *li) { - int *tmp=convertPyToNewIntArr(li,size); + int sz; + int *tmp=convertPyToNewIntArr2(li,&sz); self->insertNextCell(type,size,tmp); delete [] tmp; } @@ -124,23 +510,227 @@ namespace ParaMEDMEM PyObject *mergeNodes(double precision) { bool ret1; - DataArrayInt *ret0=self->mergeNodes(precision,ret1); - PyObject *res = PyList_New(2); + int ret2; + DataArrayInt *ret0=self->mergeNodes(precision,ret1,ret2); + PyObject *res = PyList_New(3); PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyList_SetItem(res,1,SWIG_From_bool(ret1)); + PyList_SetItem(res,2,SWIG_From_int(ret2)); return res; } + PyObject *checkButterflyCells() + { + std::vector cells; + self->checkButterflyCells(cells); + return convertIntArrToPyList2(cells); + } + + PyObject *splitByType() const + { + std::vector ms=self->splitByType(); + int sz=ms.size(); + PyObject *ret = PyList_New(sz); + for(int i=0;i idsPerGeoType; + convertPyToNewIntArr3(ids,idsPerGeoType); + MEDCouplingUMesh *ret=self->keepSpecifiedCells(type,idsPerGeoType); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 ); + } + + bool checkConsecutiveCellTypesAndOrder(PyObject *li) const + { + int sz; + INTERP_KERNEL::NormalizedCellType *order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + bool ret=self->checkConsecutiveCellTypesAndOrder(order,order+sz); + delete [] order; + return ret; + } + + DataArrayInt *getRenumArrForConsctvCellTypesSpe(PyObject *li) const + { + int sz; + INTERP_KERNEL::NormalizedCellType *order=(INTERP_KERNEL::NormalizedCellType *)convertPyToNewIntArr2(li,&sz); + DataArrayInt *ret=self->getRenumArrForConsctvCellTypesSpe(order,order+sz); + delete [] order; + return ret; + } + + PyObject *getCellsContainingPoints(PyObject *p, int nbOfPoints, double eps) const + { + int sz; + double *pos=convertPyToNewDblArr2(p,&sz); + std::vector elts,eltsIndex; + self->getCellsContainingPoints(pos,nbOfPoints,eps,elts,eltsIndex); + delete [] pos; + PyObject *ret=PyList_New(2); + PyList_SetItem(ret,0,convertIntArrToPyList2(elts)); + PyList_SetItem(ret,1,convertIntArrToPyList2(eltsIndex)); + return ret; + } + + PyObject *getCellsContainingPoint(PyObject *p, double eps) const + { + int sz; + double *pos=convertPyToNewDblArr2(p,&sz); + std::vector elts; + self->getCellsContainingPoint(pos,eps,elts); + delete [] pos; + return convertIntArrToPyList2(elts); + } + + static PyObject *mergeUMeshesOnSameCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) + { + 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 ); + } + + static PyObject *fuseUMeshesOnSameCoords(PyObject *ms, int compType) + { + int sz; + std::vector meshes; + convertPyObjToVecUMeshes(ms,meshes); + std::vector corr; + MEDCouplingUMesh *um=MEDCouplingUMesh::fuseUMeshesOnSameCoords(meshes,compType,corr); + sz=corr.size(); + PyObject *ret1=PyList_New(sz); + for(int i=0;i cells; + int sz; + double *v=convertPyToNewDblArr2(vec,&sz); + try + { + self->are2DCellsNotCorrectlyOriented(v,polyOnly,cells); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] v; + throw e; + } + delete [] v; + return convertIntArrToPyList2(cells); + } + + void orientCorrectly2DCells(PyObject *vec, bool polyOnly) throw(INTERP_KERNEL::Exception) + { + int sz; + double *v=convertPyToNewDblArr2(vec,&sz); + try + { + self->orientCorrectly2DCells(v,polyOnly); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] v; + throw e; + } + delete [] v; + } + + PyObject *arePolyhedronsNotCorrectlyOriented() const throw(INTERP_KERNEL::Exception) + { + std::vector cells; + self->arePolyhedronsNotCorrectlyOriented(cells); + return convertIntArrToPyList2(cells); + } + } + void convertToPolyTypes(const std::vector& cellIdsToConvert); + MEDCouplingUMesh *buildExtrudedMeshFromThis(const MEDCouplingUMesh *mesh1D, int policy); + static MEDCouplingUMesh *mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); + }; + + class MEDCouplingExtrudedMesh : public ParaMEDMEM::MEDCouplingMesh + { + public: + static MEDCouplingExtrudedMesh *New(const MEDCouplingUMesh *mesh3D, MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception); + MEDCouplingUMesh *build3DUnstructuredMesh() const; + %extend { + std::string __str__() const + { + return self->simpleRepr(); + } + 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 ); + } + } + }; + + class MEDCouplingCMesh : public ParaMEDMEM::MEDCouplingMesh + { + public: + static MEDCouplingCMesh *New(); + void setCoords(DataArrayDouble *coordsX, + DataArrayDouble *coordsY=0, + DataArrayDouble *coordsZ=0); + void setCoordsAt(int i, DataArrayDouble *arr) throw(INTERP_KERNEL::Exception); + %extend { + std::string __str__() const + { + return self->simpleRepr(); + } } - MEDCouplingFieldDouble *getMeasureField(bool isAbs) const; - static MEDCouplingUMesh *mergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2); }; } %extend ParaMEDMEM::DataArrayDouble { + std::string __str__() const + { + return self->repr(); + } + void setValues(PyObject *li, int nbOfTuples, int nbOfElsPerTuple) { - double *tmp=convertPyToNewDblArr2(li); + int sz; + double *tmp=convertPyToNewDblArr2(li,&sz); self->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,nbOfElsPerTuple); } @@ -149,13 +739,27 @@ namespace ParaMEDMEM const double *vals=self->getPointer(); return convertDblArrToPyList(vals,self->getNbOfElems()); } + + PyObject *getValuesAsTuple() + { + const double *vals=self->getPointer(); + int nbOfComp=self->getNumberOfComponents(); + int nbOfTuples=self->getNumberOfTuples(); + return convertDblArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + } }; %extend ParaMEDMEM::DataArrayInt { + std::string __str__() const + { + return self->repr(); + } + void setValues(PyObject *li, int nbOfTuples, int nbOfElsPerTuple) { - int *tmp=convertPyToNewIntArr2(li); + int size; + int *tmp=convertPyToNewIntArr2(li,&size); self->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,nbOfElsPerTuple); } @@ -164,40 +768,227 @@ namespace ParaMEDMEM const int *vals=self->getPointer(); return convertIntArrToPyList(vals,self->getNbOfElems()); } - }; -%include "MEDCouplingField.hxx" + PyObject *getValuesAsTuple() + { + const int *vals=self->getPointer(); + int nbOfComp=self->getNumberOfComponents(); + int nbOfTuples=self->getNumberOfTuples(); + return convertIntArrToPyListOfTuple(vals,nbOfComp,nbOfTuples); + } + + static PyObject *makePartition(PyObject *gps, int newNb) + { + std::vector groups; + std::vector< std::vector > fidsOfGroups; + convertPyObjToVecDataArrayInt(gps,groups); + ParaMEDMEM::DataArrayInt *ret0=ParaMEDMEM::DataArrayInt::makePartition(groups,newNb,fidsOfGroups); + PyObject *ret = PyList_New(2); + PyList_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + int sz=fidsOfGroups.size(); + PyObject *ret1 = PyList_New(sz); + for(int i=0;i& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); + void clearGaussLocalizations(); + MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception); + int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); + int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); + const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); + %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; + } + void setGaussLocalizationOnCells(PyObject *li, const std::vector& refCoo, + const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception) + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + try + { + self->setGaussLocalizationOnCells(tmp,tmp+size,refCoo,gsCoo,wg); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] tmp; + throw e; + } + delete [] tmp; + } + PyObject *getCellIdsHavingGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception) + { + std::vector tmp; + self->getCellIdsHavingGaussLocalization(locId,tmp); + return convertIntArrToPyList2(tmp); + } + } + }; + class MEDCouplingFieldDouble : public ParaMEDMEM::MEDCouplingField { public: static MEDCouplingFieldDouble *New(TypeOfField type, TypeOfTimeDiscretization td=NO_TIME); + void copyTinyStringsFrom(const MEDCouplingFieldDouble *other) throw(INTERP_KERNEL::Exception); + std::string simpleRepr() const; + std::string advancedRepr() const; MEDCouplingFieldDouble *clone(bool recDeepCpy) const; + MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const; + MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const; + TypeOfTimeDiscretization getTimeDiscretization() const; void checkCoherency() const throw(INTERP_KERNEL::Exception); double getIJ(int tupleId, int compoId) const; - void setArray(DataArrayDouble *array); - 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; } - void applyLin(double a, double b, int compoId); - int getNumberOfComponents() const; + double getIJK(int cellId, int nodeIdInCell, int compoId) const; + void setArray(DataArrayDouble *array) throw(INTERP_KERNEL::Exception); + void setEndArray(DataArrayDouble *array) throw(INTERP_KERNEL::Exception); + void setTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception); + void setStartTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception); + void setEndTime(double val, int iteration, int order) throw(INTERP_KERNEL::Exception); + DataArrayDouble *getArray() const throw(INTERP_KERNEL::Exception); + DataArrayDouble *getEndArray() const throw(INTERP_KERNEL::Exception); + void applyLin(double a, double b, int compoId) throw(INTERP_KERNEL::Exception); + int getNumberOfComponents() const throw(INTERP_KERNEL::Exception); int getNumberOfTuples() const throw(INTERP_KERNEL::Exception); + int getNumberOfValues() const throw(INTERP_KERNEL::Exception); NatureOfField getNature() const { return _nature; } void setNature(NatureOfField nat) throw(INTERP_KERNEL::Exception); void updateTime(); - bool mergeNodes(double eps); - void applyFunc(int nbOfComp, const char *func); - void applyFunc(const char *func); - static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + void changeUnderlyingMesh(const MEDCouplingMesh *other, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception); + void substractInPlaceDM(const MEDCouplingFieldDouble *f, int levOfCheck, double prec) throw(INTERP_KERNEL::Exception); + bool mergeNodes(double eps) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *doublyContractedProduct() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *determinant() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *eigenValues() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *eigenVectors() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *inverse() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *trace() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *deviator() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *magnitude() const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *maxPerTuple() const throw(INTERP_KERNEL::Exception); + void changeNbOfComponents(int newNbOfComp, double dftValue=0.) throw(INTERP_KERNEL::Exception); + void sortPerTuple(bool asc) throw(INTERP_KERNEL::Exception); + void applyFunc(int nbOfComp, const char *func) throw(INTERP_KERNEL::Exception); + void applyFunc(const char *func) throw(INTERP_KERNEL::Exception); + void applyFuncFast32(const char *func) throw(INTERP_KERNEL::Exception); + void applyFuncFast64(const char *func) throw(INTERP_KERNEL::Exception); + double accumulate(int compId) const throw(INTERP_KERNEL::Exception); + double getMaxValue() const throw(INTERP_KERNEL::Exception); + double getMinValue() const throw(INTERP_KERNEL::Exception); + double getAverageValue() const throw(INTERP_KERNEL::Exception); + double getWeightedAverageValue() const throw(INTERP_KERNEL::Exception); + double integral(int compId, bool isWAbs) const throw(INTERP_KERNEL::Exception); + double normL1(int compId) const throw(INTERP_KERNEL::Exception); + double normL2(int compId) const throw(INTERP_KERNEL::Exception); + DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *buildSubPart(const DataArrayInt *part) const throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *mergeFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2) throw(INTERP_KERNEL::Exception); + static MEDCouplingFieldDouble *dotFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *dot(const MEDCouplingFieldDouble& other) const; + static MEDCouplingFieldDouble *crossProductFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *crossProduct(const MEDCouplingFieldDouble& other) const; + static MEDCouplingFieldDouble *maxFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *max(const MEDCouplingFieldDouble& other) const; + static MEDCouplingFieldDouble *minFields(const MEDCouplingFieldDouble *f1, const MEDCouplingFieldDouble *f2); + MEDCouplingFieldDouble *min(const MEDCouplingFieldDouble& other) const; + MEDCouplingFieldDouble *operator+(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + const MEDCouplingFieldDouble &operator+=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator-(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + const MEDCouplingFieldDouble &operator-=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator*(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + const MEDCouplingFieldDouble &operator*=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); + MEDCouplingFieldDouble *operator/(const MEDCouplingFieldDouble& other) const throw(INTERP_KERNEL::Exception); + const MEDCouplingFieldDouble &operator/=(const MEDCouplingFieldDouble& other) throw(INTERP_KERNEL::Exception); %extend { + std::string __str__() const + { + return self->simpleRepr(); + } + PyObject *getValueOn(PyObject *sl) const throw(INTERP_KERNEL::Exception) + { + int sz; + double *spaceLoc=convertPyToNewDblArr2(sl,&sz); + sz=self->getNumberOfComponents(); + double *res=new double[sz]; + try + { + self->getValueOn(spaceLoc,res); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] spaceLoc; + delete [] res; + throw e; + } + delete [] spaceLoc; + PyObject *ret=convertDblArrToPyList(res,sz); + delete [] res; + return ret; + } + PyObject *getValueOn(PyObject *sl, double time) const throw(INTERP_KERNEL::Exception) + { + int sz; + double *spaceLoc=convertPyToNewDblArr2(sl,&sz); + sz=self->getNumberOfComponents(); + double *res=new double[sz]; + try + { + self->getValueOn(spaceLoc,time,res); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] spaceLoc; + delete [] res; + throw e; + } + delete [] spaceLoc; + PyObject *ret=convertDblArrToPyList(res,sz); + delete [] res; + return ret; + } void setValues(PyObject *li) { if(self->getArray()!=0) { - double *tmp=convertPyToNewDblArr2(li); + int sz; + double *tmp=convertPyToNewDblArr2(li,&sz); int nbTuples=self->getArray()->getNumberOfTuples(); int nbOfCompo=self->getArray()->getNumberOfComponents(); self->getArray()->useArray(tmp,true,CPP_DEALLOC,nbTuples,nbOfCompo); @@ -237,6 +1028,91 @@ namespace ParaMEDMEM PyList_SetItem(res,2,SWIG_From_int(tmp2)); return res; } + PyObject *accumulate() const + { + int sz=self->getNumberOfTuples(); + double *tmp=new double[sz]; + self->accumulate(tmp); + PyObject *ret=convertDblArrToPyList(tmp,sz); + delete [] tmp; + return ret; + } + PyObject *integral(bool isWAbs) const + { + int sz=self->getNumberOfTuples(); + double *tmp=new double[sz]; + self->integral(isWAbs,tmp); + PyObject *ret=convertDblArrToPyList(tmp,sz); + delete [] tmp; + return ret; + } + PyObject *normL1() const throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfTuples(); + double *tmp=new double[sz]; + self->normL1(tmp); + PyObject *ret=convertDblArrToPyList(tmp,sz); + delete [] tmp; + return ret; + } + PyObject *normL2() const throw(INTERP_KERNEL::Exception) + { + int sz=self->getNumberOfTuples(); + double *tmp=new double[sz]; + self->normL2(tmp); + PyObject *ret=convertDblArrToPyList(tmp,sz); + delete [] tmp; + return ret; + } + + void renumberCells(PyObject *li, bool check) throw(INTERP_KERNEL::Exception) + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + try + { + self->renumberCells(tmp,check); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] tmp; + throw e; + } + delete [] tmp; + } + void renumberNodes(PyObject *li) throw(INTERP_KERNEL::Exception) + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + try + { + self->renumberNodes(tmp); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] tmp; + throw e; + } + delete [] tmp; + } + + MEDCouplingFieldDouble *buildSubPart(PyObject *li) const throw(INTERP_KERNEL::Exception) + { + int size; + int *tmp=convertPyToNewIntArr2(li,&size); + MEDCouplingFieldDouble *ret=0; + try + { + ret=self->buildSubPart(tmp,tmp+size); + } + catch(INTERP_KERNEL::Exception& e) + { + delete [] tmp; + throw e; + } + delete [] tmp; + return ret; + } } }; }