]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
staffan :
authorvbd <vbd>
Thu, 2 Aug 2007 14:29:21 +0000 (14:29 +0000)
committervbd <vbd>
Thu, 2 Aug 2007 14:29:21 +0000 (14:29 +0000)
added tests for tetrahedra consisting only of one cell

src/INTERP_KERNEL/Test/Interpolation3DTest.cxx
src/INTERP_KERNEL/Test/Interpolation3DTest.hxx
src/INTERP_KERNEL/Test/TestInterpKernel.cxx

index a00738c20d9bb59bd90eaf7175a2b2636134e304..c887c75d038027bd1f785e1b565e7087296600b6 100644 (file)
@@ -45,6 +45,7 @@ bool Interpolation3DTest::isIntersectionConsistent(IntersectionMatrix m)
 void Interpolation3DTest::dumpIntersectionMatrix(IntersectionMatrix m)
 {
   int i = 0;
+  cout << "Intersection matrix is " << endl;
   for(IntersectionMatrix::const_iterator iter = m.begin() ; iter != m.end() ; ++iter)
     {
       for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
@@ -71,11 +72,12 @@ void Interpolation3DTest::reflexiveTetra()
 {
   std::cout << std::endl << std::endl << "=============================" << std::endl;
   std::cout << " Reflexive tetra " << endl;
-  MESH unitMesh(MED_DRIVER, "meshes/tetra1.med", "Mesh_1");
+  MESH unitMesh(MED_DRIVER, "meshes/UnitTetra.med", "UnitTetra");
 
   std::cout << std::endl << "*** unit tetra" << std::endl;
   IntersectionMatrix matrix1 = interpolator->interpol_maillages(unitMesh, unitMesh);
-  
+
+#if 0  
   std::cout << std::endl << "*** non-unit large tetra" << std::endl;
   MESH largeMesh(MED_DRIVER, "meshes/tetra2.med", "Mesh_1");
   IntersectionMatrix matrix2 = interpolator->interpol_maillages(largeMesh, largeMesh);
@@ -83,33 +85,51 @@ void Interpolation3DTest::reflexiveTetra()
   std::cout << std::endl << "*** non-unit small tetra" << std::endl;
   MESH smallMesh(MED_DRIVER, "meshes/tetra2_scaled.med", "Mesh_2");
   IntersectionMatrix matrix3 = interpolator->interpol_maillages(smallMesh, smallMesh);
-
+#endif
   CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0 / 6.0, sumVolume(matrix1), ERR_TOL);
+#if 0
   CPPUNIT_ASSERT_DOUBLES_EQUAL(48.0, sumVolume(matrix2), ERR_TOL);
   CPPUNIT_ASSERT_DOUBLES_EQUAL(0.75, sumVolume(matrix3), ERR_TOL);
-  
+#endif
+}
+
+void Interpolation3DTest::calcIntersectionMatrix(const char* mesh1path, const char* mesh1, const char* mesh2path, const char* mesh2, IntersectionMatrix& m)
+{
+  std::cout << std::endl << "=== -> intersecting src = " << mesh1 << ", target = " << mesh2 << std::endl;
+
+  std::cout << "Loading " << mesh1 << " from " << mesh1path << endl;
+  MESH sMesh(MED_DRIVER, mesh1path, mesh1);
+
+  std::cout << "Loading " << mesh2 << " from " << mesh2path << endl;
+  MESH tMesh(MED_DRIVER, mesh2path, mesh2);
+
+  m = interpolator->interpol_maillages(sMesh, tMesh);
+
+  dumpIntersectionMatrix(m);
+
+  std::cout << "Intersection calculation done. " << std::endl << std::endl;
 }
 
-void Interpolation3DTest::tetraTetraTransl()
+void Interpolation3DTest::intersectMeshes(const char* mesh1path, const char* mesh1, const char* mesh2path, const char* mesh2, const double correctVol)
 {
   std::cout << std::endl << std::endl << "=============================" << std::endl;
-  std::cout << " Translated tetra  " << endl;
-  MESH srcMesh(MED_DRIVER, "meshes/tetra1.med", "Mesh_1");
 
-  MESH targetMesh(MED_DRIVER, "meshes/tetra1_transl_delta.med", "Mesh_3");
+  IntersectionMatrix matrix1;
+  calcIntersectionMatrix(mesh1path, mesh1, mesh2path, mesh2, matrix1);
 
-  std::cout << std::endl << "*** src - target" << std::endl;
-  IntersectionMatrix matrix1 = interpolator->interpol_maillages(srcMesh, targetMesh);
-  std::cout << std::endl << std::endl << "*** target - src" << std::endl;
-  IntersectionMatrix matrix2 = interpolator->interpol_maillages(targetMesh, srcMesh);
-  std::cout << std::endl << std::endl << "*** target - target" << std::endl;
-  IntersectionMatrix matrix3 = interpolator->interpol_maillages(targetMesh, targetMesh);
+  dumpIntersectionMatrix(matrix1);
 
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.152112, sumVolume(matrix1), 1.0e-6);
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(0.152112, sumVolume(matrix2), 1.0e-6);
-  CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0 / 6.0, sumVolume(matrix3), ERR_TOL);
+  IntersectionMatrix matrix2;
+  calcIntersectionMatrix(mesh2path, mesh2, mesh1path, mesh1, matrix2);
+
+  dumpIntersectionMatrix(matrix2);
+
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(correctVol, sumVolume(matrix1), 1.0e-6);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(correctVol, sumVolume(matrix2), 1.0e-6);
 }
 
+
+
 void Interpolation3DTest::tetraTetraScale()
 {
   std::cout << std::endl << std::endl << "=============================" << std::endl;
index 79a9d2efbc53c4659ffe80a6af90625f11252c31..bc5fd266e4b16624c4befb7d240855e962d05599 100644 (file)
@@ -12,12 +12,21 @@ class Interpolation3DTest : public CppUnit::TestFixture
 {
 
   CPPUNIT_TEST_SUITE( Interpolation3DTest );
-  CPPUNIT_TEST( reflexiveTetra );
-  CPPUNIT_TEST( tetraTetraTransl );
-  CPPUNIT_TEST( tetraTetraScale );
+#if 0
+  CPPUNIT_TEST( tetraReflexiveUnit );
+  CPPUNIT_TEST( tetraReflexiveGeneral );
+  CPPUNIT_TEST( tetraNudgedSimpler );
+  CPPUNIT_TEST( tetraNudged );
+  CPPUNIT_TEST( tetraCorner );
+  CPPUNIT_TEST( tetraHalfstripOnly );
+  CPPUNIT_TEST( tetraHalfstripOnly2 );
+  CPPUNIT_TEST( tetraSimpleHalfstripOnly );
+#endif
+  CPPUNIT_TEST( tetraBoxes );
+  //CPPUNIT_TEST( tetraTetraScale );
   //  CPPUNIT_TEST( box1 );
   // CPPUNIT_TEST( cyl1 );
-  CPPUNIT_TEST( tetra1 );
+  //CPPUNIT_TEST( tetra1 );
   // CPPUNIT_TEST( tetra3 );
   
   CPPUNIT_TEST_SUITE_END();
@@ -29,11 +38,135 @@ public:
   void tearDown();
 
   // tests
+
+  void tetraReflexiveUnit()
+  {
+    intersectMeshes("meshes/UnitTetra.med", "UnitTetra", "meshes/UnitTetra.med", "UnitTetra", 1.0/6.0);
+  }
+
+  void tetraReflexiveGeneral()
+  {
+    intersectMeshes("meshes/GeneralTetra.med", "GeneralTetra", "meshes/GeneralTetra.med", "GeneralTetra", 0.428559);
+  }
+
+  void tetraNudgedSimpler()
+  {
+    intersectMeshes("meshes/UnitTetra.med", "UnitTetra", "meshes/NudgedSimpler.med", "NudgedSimpler", 0.152112);
+  }
+
+  void tetraNudged()
+  {
+    intersectMeshes("meshes/UnitTetra.med", "UnitTetra", "meshes/NudgedTetra.med", "NudgedTetra", 0.142896);
+  }
+
+  void tetraCorner()
+  {
+    intersectMeshes("meshes/UnitTetra.med", "UnitTetra", "meshes/CornerTetra.med", "CornerTetra", 0.0135435);
+  }
+
+  void tetraHalfstripOnly()
+  {
+    // NB this test is not completely significant : we should also verify that 
+    // there are triangles on the element that give a non-zero volume
+    intersectMeshes("meshes/HalfstripOnly.med", "HalfstripOnly", "meshes/UnitTetra.med", "UnitTetra", 0.0);
+  }
+
+   void tetraHalfstripOnly2()
+  {
+    // NB this test is not completely significant : we should also verify that 
+    // there are triangles on the element that give a non-zero volume
+     intersectMeshes("meshes/HalfstripOnly2.med", "HalfstripOnly2", "meshes/UnitTetra.med", "UnitTetra", 0.0);
+  }
   
+  void tetraSimpleHalfstripOnly()
+  {
+    // NB this test is not completely significant : we should also verify that 
+    // there are triangles on the element that give a non-zero volume
+    intersectMeshes("meshes/SimpleHalfstripOnly.med", "SimpleHalfstripOnly", "meshes/UnitTetra.med", "UnitTetra", 0.0);
+  }
+
+  void tetraBoxes()
+  {
+    intersectMeshes("meshes/Box1.med", "Box1", "meshes/Box2.med", "Box2", 124.197);
+  }
+  
+#if 0
+  void tetraHalfstripOnly()
+  {
+    std::cout << std::endl << std::endl << "=============================" << std::endl;
+    IntersectionMatrix matrix;
+    // we want no transformation - unit tetra is target
+    calcIntersectionMatrix("meshes/HalfstripOnly.med", "HalfstripOnly", "meshes/UnitTetra.med", "UnitTetra", matrix);
+
+    // check that the total volume is zero
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, sumVolume(matrix), 1.0e-6);
+
+    // check that we have non-zero volumes that cancel
+    bool allVolumesZero = true;
+
+    for(IntersectionMatrix::const_iterator iter = matrix.begin() ; iter != matrix.end() ; ++iter)
+    {
+      for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
+       {
+         allVolumesZero = allVolumesZero && (iter2->second == 0.0);
+       }
+    }
+
+    CPPUNIT_ASSERT_EQUAL(false, allVolumesZero);
+    
+  }
+
+  void tetraHalfstripOnly2()
+  {
+    std::cout << std::endl << std::endl << "=============================" << std::endl;
+    IntersectionMatrix matrix;
+    // we want no transformation - unit tetra is target
+    calcIntersectionMatrix("meshes/HalfstripOnly2.med", "HalfstripOnly2", "meshes/UnitTetra.med", "UnitTetra", matrix);
+
+    // check that the total volume is zero
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, sumVolume(matrix), 1.0e-6);
+
+    // check that we have non-zero volumes that cancel
+    bool allVolumesZero = true;
+
+    for(IntersectionMatrix::const_iterator iter = matrix.begin() ; iter != matrix.end() ; ++iter)
+    {
+      for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
+       {
+         allVolumesZero = allVolumesZero && (iter2->second == 0.0);
+       }
+    }
+
+    CPPUNIT_ASSERT_EQUAL(false, allVolumesZero);
+    
+  }
+
+   void tetraSimpleHalfstripOnly()
+  {
+    std::cout << std::endl << std::endl << "=============================" << std::endl;
+    IntersectionMatrix matrix;
+    // we want no transformation - unit tetra is target
+    calcIntersectionMatrix("meshes/SimpleHalfstripOnly.med", "SimpleHalfstripOnly", "meshes/UnitTetra.med", "UnitTetra", matrix);
+
+    // check that the total volume is zero
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, sumVolume(matrix), 1.0e-6);
+
+    // check that we have non-zero volumes that cancel
+    bool allVolumesZero = true;
+
+    for(IntersectionMatrix::const_iterator iter = matrix.begin() ; iter != matrix.end() ; ++iter)
+    {
+      for(map<int, double>::const_iterator iter2 = iter->begin() ; iter2 != iter->end() ; ++iter2)
+       {
+         allVolumesZero = allVolumesZero && (iter2->second == 0.0);
+       }
+    }
+    CPPUNIT_ASSERT_EQUAL(false, allVolumesZero);
+    
+  }
+#endif
   void reflexiveTetra();
 
-  void tetraTetraTransl();
-
   void tetraTetraScale();
 
   void cyl1();
@@ -54,6 +187,10 @@ private:
   
   void dumpIntersectionMatrix(IntersectionMatrix m);
 
+  void intersectMeshes(const char* mesh1path, const char* mesh1, const char* mesh2path, const char* mesh2, const double correctVol);
+
+  void calcIntersectionMatrix(const char* mesh1path, const char* mesh1, const char* mesh2path, const char* mesh2, IntersectionMatrix& m);
+
 };
 
 #endif
index a22bbf1589aaf750a3ead1d093e4ea1812a3e806..fb50701656d2e7453a06b9f1febd3165daf97f5d 100644 (file)
 #include "CppUnitTest.hxx"
 #include "TransformedTriangleTest.hxx"
 #include "TransformedTriangleIntersectTest.hxx"
+#include "Interpolation3DTest.hxx"
 
 // --- Registers the fixture into the 'registry'
 
+CPPUNIT_TEST_SUITE_REGISTRATION( Interpolation3DTest );
+#if 0
 CPPUNIT_TEST_SUITE_REGISTRATION( TransformedTriangleIntersectTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( TransformedTriangleTest );
 CPPUNIT_TEST_SUITE_REGISTRATION( TestBogusClass );
-
+#endif
 // --- generic Main program from KERNEL_SRC/src/Basics/Test
 
 #include "BasicMainTest.hxx"