From 2b5caa594588bd42ea6c4a19a199d6116bb9638a Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 31 Jan 2012 11:10:14 +0000 Subject: [PATCH] *** empty log message *** --- .../Test/MEDCouplingBasicsTest4.cxx | 55 +++++++++++++++++++ .../Test/MEDCouplingBasicsTest4.hxx | 2 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 38 +++++++++++++ 3 files changed, 95 insertions(+) diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index 7cbbf2a8f..5d7fc310c 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1981,3 +1981,58 @@ void MEDCouplingBasicsTest4::testBuildDescendingConnec2() mesh2->decrRef(); mesh->decrRef(); } + +void MEDCouplingBasicsTest4::testIntersect2DMeshesTmp1() +{ + MEDCouplingCMesh *m1c=MEDCouplingCMesh::New(); + DataArrayDouble *coordX=DataArrayDouble::New(); + const double arrX[4]={-1., 1., 2., 4.}; + coordX->alloc(4,1); + std::copy(arrX,arrX+4,coordX->getPointer()); + m1c->setCoordsAt(0,coordX); + DataArrayDouble *coordY=DataArrayDouble::New(); + const double arrY[4]={-2., 2., 4., 8.}; + coordY->alloc(4,1); + std::copy(arrY,arrY+4,coordY->getPointer()); + m1c->setCoordsAt(1,coordY); + MEDCouplingUMesh *m1=m1c->buildUnstructured(); + const int subPart1[3]={3,4,5}; + MEDCouplingUMesh *m1bis=static_cast(m1->buildPartOfMySelf(subPart1,subPart1+3,false)); + MEDCouplingUMesh *m2tmp=static_cast(m1->deepCpy()); + const int subPart2[3]={0,1,2}; + MEDCouplingUMesh *m2=static_cast(m2tmp->buildPartOfMySelf(subPart2,subPart2+3,false)); + const double vec[2]={0.5,0.5}; + m2->translate(vec); + // End of construction of input meshes m1bis and m2 -> start of specific part of the test + DataArrayInt *d1=0,*d2=0; + MEDCouplingUMesh *m3=MEDCouplingUMesh::Intersect2DMeshes(m1bis,m2,1e-10,d1,d2); + const int expected1[5]={0,1,1,2,2}; + const int expected2[5]={0,0,1,1,2}; + CPPUNIT_ASSERT_EQUAL(5,d1->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(5,d2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(5,m3->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(22,m3->getNumberOfNodes()); + CPPUNIT_ASSERT_EQUAL(2,m3->getSpaceDimension()); + CPPUNIT_ASSERT(std::equal(expected1,expected1+5,d1->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected2,expected2+5,d2->getConstPointer())); + const int expected3[25]={5,17,1,16,12,5,18,1,17,13,5,19,2,18,13,5,20,2,19,14,5,21,3,20,14}; + const int expected4[6]={0,5,10,15,20,25}; + const double expected5[44]={-1.0,2.0,1.0,2.0,2.0,2.0,4.0,2.0,-1.0,4.0,1.0,4.0,2.0,4.0,4.0,4.0,-0.5,-1.5,1.5,-1.5,2.5,-1.5,4.5,-1.5,-0.5,2.5,1.5,2.5,2.5,2.5,4.5,2.5,-0.5,2.0,1.0,2.5,1.5,2.0,2.0,2.5,2.5,2.0,4.0,2.5}; + CPPUNIT_ASSERT_EQUAL(25,m3->getNodalConnectivity()->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(6,m3->getNodalConnectivityIndex()->getNumberOfTuples()); + CPPUNIT_ASSERT(std::equal(expected3,expected3+25,m3->getNodalConnectivity()->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected4,expected4+6,m3->getNodalConnectivityIndex()->getConstPointer())); + for(int i=0;i<44;i++) + CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],m3->getCoords()->getIJ(0,i),1e-12); + d1->decrRef(); + d2->decrRef(); + m3->decrRef(); + // + m2->decrRef(); + m2tmp->decrRef(); + m1bis->decrRef(); + m1->decrRef(); + coordX->decrRef(); + coordY->decrRef(); + m1c->decrRef(); +} diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx index 667f52d02..bcb45a954 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.hxx @@ -88,6 +88,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testDADIReverse1 ); CPPUNIT_TEST( testGetNodeIdsInUse1 ); CPPUNIT_TEST( testBuildDescendingConnec2 ); + CPPUNIT_TEST( testIntersect2DMeshesTmp1 ); CPPUNIT_TEST_SUITE_END(); public: void testDescriptionInMeshTimeUnit1(); @@ -145,6 +146,7 @@ namespace ParaMEDMEM void testDADIReverse1(); void testGetNodeIdsInUse1(); void testBuildDescendingConnec2(); + void testIntersect2DMeshesTmp1(); }; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index f42672e9f..36e41b858 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -8092,6 +8092,44 @@ class MEDCouplingBasicsTest(unittest.TestCase): 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,conn.getValues()); pass + + def testIntersect2DMeshesTmp1(self): + m1c=MEDCouplingCMesh.New(); + coordsX=DataArrayDouble.New(); + arrX=[ -1., 1., 2., 4. ] + coordsX.setValues(arrX,4,1); + m1c.setCoordsAt(0,coordsX); + coordsY=DataArrayDouble.New(); + arrY=[ -2., 2., 4., 8. ] + coordsY.setValues(arrY,4,1); + m1c.setCoordsAt(1,coordsY); + m1=m1c.buildUnstructured() + m1bis=m1.buildPartOfMySelf([3,4,5],False) + m2=m1.deepCpy() + m2=m2.buildPartOfMySelf([0,1,2],False) + m2.translate([0.5,0.5]) + # + m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1bis,m2,1e-10) + expected1=[0,1,1,2,2] + expected2=[0,0,1,1,2] + self.assertEqual(5,d1.getNumberOfTuples()); + self.assertEqual(5,d2.getNumberOfTuples()); + self.assertEqual(5,m3.getNumberOfCells()); + self.assertEqual(22,m3.getNumberOfNodes()); + self.assertEqual(2,m3.getSpaceDimension()); + self.assertEqual(expected1,d1.getValues()); + self.assertEqual(expected2,d2.getValues()); + expected3=[5,17,1,16,12,5,18,1,17,13,5,19,2,18,13,5,20,2,19,14,5,21,3,20,14] + expected4=[0,5,10,15,20,25] + expected5=[-1.0,2.0,1.0,2.0,2.0,2.0,4.0,2.0,-1.0,4.0,1.0,4.0,2.0,4.0,4.0,4.0,-0.5,-1.5,1.5,-1.5,2.5,-1.5,4.5,-1.5,-0.5,2.5,1.5,2.5,2.5,2.5,4.5,2.5,-0.5,2.0,1.0,2.5,1.5,2.0,2.0,2.5,2.5,2.0,4.0,2.5] + self.assertEqual(25,m3.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(6,m3.getNodalConnectivityIndex().getNumberOfTuples()); + self.assertEqual(expected3,m3.getNodalConnectivity().getValues()); + self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues()); + for i in xrange(44): + self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12); + pass + pass def setUp(self): pass -- 2.39.2