]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
More tests.
authorageay <ageay>
Tue, 24 Aug 2010 09:24:53 +0000 (09:24 +0000)
committerageay <ageay>
Tue, 24 Aug 2010 09:24:53 +0000 (09:24 +0000)
src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest0.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx

index d0a40508fdce5b0a8a1a91029540aa081a0956fa..8a25e42d113c1eaa1a31208ebf8c3624c36ff585 100644 (file)
@@ -98,6 +98,11 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( testRenumberCellsForFields );
     CPPUNIT_TEST( testRenumberNodesForFields );
     CPPUNIT_TEST( testConvertQuadraticCellsToLinear );
+    CPPUNIT_TEST( testCheckGeoEquivalWith );
+    CPPUNIT_TEST( testCheckGeoEquivalWith2 );
+    CPPUNIT_TEST( testCopyTinyStringsFromOnFields );
+    CPPUNIT_TEST( testTryToShareSameCoordsPermute );
+    CPPUNIT_TEST( testTryToShareSameCoordsPermute2 );
     //MEDCouplingBasicsTestInterp.cxx
     CPPUNIT_TEST( test2DInterpP0P0_1 );
     CPPUNIT_TEST( test2DInterpP0P0PL_1 );
@@ -224,6 +229,11 @@ namespace ParaMEDMEM
     void testRenumberCellsForFields();
     void testRenumberNodesForFields();
     void testConvertQuadraticCellsToLinear();
+    void testCheckGeoEquivalWith();
+    void testCheckGeoEquivalWith2();
+    void testCopyTinyStringsFromOnFields();
+    void testTryToShareSameCoordsPermute();
+    void testTryToShareSameCoordsPermute2();
     //MEDCouplingBasicsTestInterp.cxx
     void test2DInterpP0P0_1();
     void test2DInterpP0P0PL_1();
@@ -316,6 +326,7 @@ namespace ParaMEDMEM
     static MEDCouplingUMesh *build2DCurveTargetMesh_3();
     static MEDCouplingUMesh *build2DTargetMesh_3();
     static MEDCouplingUMesh *build3DTargetMesh_3();
+    static MEDCouplingUMesh *build2DTargetMesh_4();
     static double sumAll(const std::vector< std::map<int,double> >& matrix);
   };
 }
index 26a5be5d033270d0ccb6c0e1470ccfa875ce6016..2e16a0c070a9e06e754846e5842adc163b2d4d51 100644 (file)
@@ -813,6 +813,30 @@ MEDCouplingUMesh *MEDCouplingBasicsTest::build2DTargetMesh_3()
   return ret;
 }
 
+/*!
+ * Same as build2DTargetMesh_1 but with more nodes than needed. To check tryToShareSameCoordsPermute method.
+ */
+MEDCouplingUMesh *MEDCouplingBasicsTest::build2DTargetMesh_4()
+{
+  double targetCoords[20]={-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 };
+  int targetConn[18]={0,4,5,1, 1,5,3, 5,6,2, 7,8,5,4, 8,9,6,5};
+  MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New();
+  targetMesh->setMeshDimension(2);
+  targetMesh->allocateCells(5);
+  targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
+  targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+4);
+  targetMesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,targetConn+7);
+  targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+10);
+  targetMesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn+14);
+  targetMesh->finishInsertingCells();
+  DataArrayDouble *myCoords=DataArrayDouble::New();
+  myCoords->alloc(10,2);
+  std::copy(targetCoords,targetCoords+20,myCoords->getPointer());
+  targetMesh->setCoords(myCoords);
+  myCoords->decrRef();
+  return targetMesh;
+}
+
 MEDCouplingUMesh *MEDCouplingBasicsTest::build3DTargetMesh_3()
 {
 }
index a2d5d67f8dc21518bf663983d02703505592efa0..f8e6fa1bdfb8505c66edbbaaeef0ec21fbfcffd4 100644 (file)
@@ -774,3 +774,252 @@ void MEDCouplingBasicsTest::testConvertQuadraticCellsToLinear()
   f2->decrRef();
   mesh->decrRef();
 }
+
+void MEDCouplingBasicsTest::testCheckGeoEquivalWith()
+{
+  MEDCouplingUMesh *mesh1=build2DTargetMesh_3();
+  MEDCouplingUMesh *mesh2=build2DTargetMesh_3();
+  DataArrayInt *cellCor,*nodeCor;
+  //First test mesh1
+  mesh1->checkGeoEquivalWith(mesh1,0,1e-12,cellCor,nodeCor);//deepEqual
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  mesh1->checkGeoEquivalWith(mesh1,1,1e-12,cellCor,nodeCor);//fastEqual
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  mesh1->checkGeoEquivalWith(mesh1,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  //Second test mesh1 and mesh2 are 2 different meshes instance
+  mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor);//deepEqual
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  //Third test : cell permutation by keeping the first the middle and the last as it is.
+  const int renum[]={0,2,1,3,4,5,6,8,7,9};
+  mesh2->renumberCells(renum,false);
+  CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor),INTERP_KERNEL::Exception);//deepEqual fails
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual do not see anything
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
+  CPPUNIT_ASSERT(cellCor);
+  CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
+  CPPUNIT_ASSERT(std::equal(renum,renum+10,cellCor->getConstPointer()));
+  CPPUNIT_ASSERT(nodeCor==0);
+  cellCor->decrRef();
+  cellCor=0;
+  CPPUNIT_ASSERT(nodeCor==0);
+  //4th test : cell and node permutation by keeping the first the middle and the last as it is.
+  mesh2->decrRef();
+  mesh2=build2DTargetMesh_3();
+  const int renum2[]={0,2,1,3,4,5,6,8,7,9,10};
+  mesh2->renumberCells(renum,false);
+  mesh2->renumberNodes(renum2,11);
+  CPPUNIT_ASSERT_THROW(mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor),INTERP_KERNEL::Exception);//deepEqual fails
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual do not see anything
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
+  CPPUNIT_ASSERT(cellCor);
+  CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
+  CPPUNIT_ASSERT(std::equal(renum,renum+10,cellCor->getConstPointer()));
+  CPPUNIT_ASSERT(nodeCor);
+  CPPUNIT_ASSERT_EQUAL(11,nodeCor->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,nodeCor->getNumberOfComponents());
+  CPPUNIT_ASSERT(std::equal(renum2,renum2+11,nodeCor->getConstPointer()));
+  cellCor->decrRef();
+  cellCor=0;
+  nodeCor->decrRef();
+  nodeCor=0;
+  //5th test : modification of the last cell to check fastCheck detection.
+  mesh2->decrRef();
+  mesh2=build2DTargetMesh_3();
+  const int renum3[]={0,2,1,3,4,5,6,8,9,7};
+  mesh2->renumberCells(renum3,false);
+  mesh2->renumberNodes(renum2,11);
+  bool isExcep=false;
+  try { mesh1->checkGeoEquivalWith(mesh2,0,1e-12,cellCor,nodeCor);//deepEqual fails
+  }
+  catch(INTERP_KERNEL::Exception& e) { isExcep=true; }
+  CPPUNIT_ASSERT(isExcep); isExcep=false;
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  try { mesh1->checkGeoEquivalWith(mesh2,1,1e-12,cellCor,nodeCor);//fastEqual has detected something
+  }
+  catch(INTERP_KERNEL::Exception& e) { isExcep=true; }
+  CPPUNIT_ASSERT(isExcep); isExcep=false;
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor==0);
+  mesh2->checkGeoEquivalWith(mesh1,10,1e-12,cellCor,nodeCor);//deepEqual with geo permutations
+  CPPUNIT_ASSERT(cellCor);
+  CPPUNIT_ASSERT_EQUAL(10,cellCor->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,cellCor->getNumberOfComponents());
+  CPPUNIT_ASSERT(std::equal(renum3,renum3+10,cellCor->getConstPointer()));
+  CPPUNIT_ASSERT(nodeCor);
+  CPPUNIT_ASSERT_EQUAL(11,nodeCor->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,nodeCor->getNumberOfComponents());
+  CPPUNIT_ASSERT(std::equal(renum2,renum2+11,nodeCor->getConstPointer()));
+  cellCor->decrRef();
+  cellCor=0;
+  nodeCor->decrRef();
+  nodeCor=0;
+  //
+  mesh1->decrRef();
+  mesh2->decrRef();
+}
+
+void MEDCouplingBasicsTest::testCheckGeoEquivalWith2()
+{
+  MEDCouplingUMesh *mesh1=build2DTargetMesh_4();
+  MEDCouplingUMesh *mesh2=build2DTargetMesh_1();
+  DataArrayInt *cellCor,*nodeCor;
+  mesh1->checkGeoEquivalWith(mesh2,10,1e-12,cellCor,nodeCor);
+  CPPUNIT_ASSERT(cellCor==0);
+  CPPUNIT_ASSERT(nodeCor!=0);
+  const int expected1[9]={0, 1, 3, 4, 5, 6, 7, 8, 9};
+  for(int i=0;i<9;i++)
+    CPPUNIT_ASSERT_EQUAL(expected1[i],nodeCor->getIJ(i,0));
+  nodeCor->decrRef();
+  //
+  mesh1->decrRef();
+  mesh2->decrRef();
+}
+
+void MEDCouplingBasicsTest::testCopyTinyStringsFromOnFields()
+{
+  MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+  int nbOfCells=m->getNumberOfCells();
+  MEDCouplingFieldDouble *f=MEDCouplingFieldDouble::New(ON_CELLS,LINEAR_TIME);
+  f->setMesh(m);
+  f->setName("a");
+  f->setDescription("b");
+  DataArrayDouble *a1=DataArrayDouble::New();
+  a1->alloc(nbOfCells,2);
+  a1->fillWithZero();
+  a1->setInfoOnComponent(0,"c");
+  a1->setInfoOnComponent(1,"d");
+  DataArrayDouble *a2=a1->deepCopy();
+  a2->setInfoOnComponent(0,"e");
+  a2->setInfoOnComponent(1,"f");
+  f->setArray(a1);
+  f->setEndArray(a2);
+  f->setEndTime(3.,3,4);
+  a2->decrRef();
+  a1->decrRef();
+  m->setName("g");
+  m->getCoords()->setInfoOnComponent(0,"h");
+  m->getCoords()->setInfoOnComponent(1,"i");
+  m->getCoords()->setInfoOnComponent(2,"j");
+  //
+  f->checkCoherency();
+  MEDCouplingFieldDouble *f2=f->clone(true);
+  CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
+  f2->setName("smth");
+  CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
+  f2->copyTinyStringsFrom(f);
+  CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
+  f2->setDescription("GGG");
+  CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
+  f2->copyTinyStringsFrom(f);
+  CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
+  f2->getArray()->setInfoOnComponent(0,"mmmm");
+  CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
+  f2->copyTinyStringsFrom(f);
+  CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
+  f2->getEndArray()->setInfoOnComponent(1,"mmmm");
+  CPPUNIT_ASSERT(!f2->isEqual(f,1e-12,1e-12));
+  f2->copyTinyStringsFrom(f);
+  CPPUNIT_ASSERT(f2->isEqual(f,1e-12,1e-12));
+  f2->decrRef();
+  MEDCouplingUMesh *m2=m->clone(true);
+  CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
+  m2->setName("123");
+  CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
+  m2->copyTinyStringsFrom(m);
+  CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
+  m2->getCoords()->setInfoOnComponent(1,"eee");
+  CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
+  m2->copyTinyStringsFrom(m);
+  CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
+  m2->decrRef();
+  //
+  f->decrRef();
+  m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testTryToShareSameCoordsPermute()
+{
+  MEDCouplingUMesh *m=build3DSurfTargetMesh_1();
+  MEDCouplingUMesh *m2=build3DSurfTargetMesh_1();
+  CPPUNIT_ASSERT(m->getCoords()!=m2->getCoords());
+  m->tryToShareSameCoordsPermute(*m2,1e-12);
+  CPPUNIT_ASSERT(m->getCoords()==m2->getCoords());
+  CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
+  const int renum1[9]={1,2,0,5,8,7,4,3,6};
+  m->renumberNodes(renum1,9);
+  CPPUNIT_ASSERT(m->getCoords()!=m2->getCoords());
+  CPPUNIT_ASSERT(!m2->isEqual(m,1e-12));
+  m->tryToShareSameCoordsPermute(*m2,1e-12);
+  CPPUNIT_ASSERT(m->getCoords()==m2->getCoords());
+  CPPUNIT_ASSERT(m2->isEqual(m,1e-12));
+  m2->decrRef();
+  m->decrRef();
+}
+
+void MEDCouplingBasicsTest::testTryToShareSameCoordsPermute2()
+{
+  MEDCouplingUMesh *m1=build2DTargetMesh_4();
+  double targetCoords[8]={-0.3,-0.3, 0.2,-0.3, -0.3,0.2, 0.2,0.2 };
+  int targetConn[4]={0,2,3,1};
+  MEDCouplingUMesh *m2=MEDCouplingUMesh::New();
+  m2->setMeshDimension(2);
+  m2->allocateCells(1);
+  m2->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,targetConn);
+  m2->finishInsertingCells();
+  DataArrayDouble *myCoords=DataArrayDouble::New();
+  myCoords->alloc(4,2);
+  std::copy(targetCoords,targetCoords+8,myCoords->getPointer());
+  m2->setCoords(myCoords);
+  myCoords->decrRef();
+  m2->checkCoherency();
+  m1->checkCoherency();
+  //
+  const double expected1[5]={0.25,0.125,0.125,0.25,0.25};
+  MEDCouplingFieldDouble *f1=m1->getMeasureField(false);
+  MEDCouplingFieldDouble *f2=m2->getMeasureField(false);
+  CPPUNIT_ASSERT_EQUAL(5,f1->getArray()->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfTuples());
+  for(int i=0;i<5;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-12);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(0,0),1e-12);
+  f2->decrRef();
+  f1->decrRef();
+  CPPUNIT_ASSERT_THROW(m1->tryToShareSameCoordsPermute(*m2,1e-12),INTERP_KERNEL::Exception);// <- 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);
+  CPPUNIT_ASSERT_EQUAL(5,f1->getArray()->getNumberOfTuples());
+  CPPUNIT_ASSERT_EQUAL(1,f2->getArray()->getNumberOfTuples());
+  for(int i=0;i<5;i++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],f1->getIJ(i,0),1e-12);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[0],f2->getIJ(0,0),1e-12);
+  //
+  f2->decrRef();
+  f1->decrRef();
+  //
+  m1->decrRef();
+  m2->decrRef();
+}