]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
EHPOC
authoreap <eap@opencascade.com>
Thu, 8 Apr 2010 13:59:10 +0000 (13:59 +0000)
committereap <eap@opencascade.com>
Thu, 8 Apr 2010 13:59:10 +0000 (13:59 +0000)
  * Interpolation of 1D meshes has been implemented

+    CPPUNIT_TEST( test1DInterp_1 );
+    CPPUNIT_TEST( test2DCurveInterpP0P0_1 );
+    CPPUNIT_TEST( test2DCurveInterpP0P0_2 );
+    CPPUNIT_TEST( test2DCurveInterpP0P1_1 );
+    CPPUNIT_TEST( test2DCurveInterpP1P0_1 );
+    CPPUNIT_TEST( test2DCurveInterpP1P1_1 );

src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx
src/MEDCoupling/Test/MEDCouplingBasicsTest0.cxx
src/MEDCoupling/Test/MEDCouplingBasicsTestInterp.cxx

index c09a5ec072a5c7bdc71e13dda8d9003dd59910b5..fc20025f3cdb9f2ec97eea06530d771307817c0f 100644 (file)
@@ -90,10 +90,12 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( test3DSurfInterpP1P1PL_1 );
     CPPUNIT_TEST( test3DSurfInterpP0P0_2 );
     CPPUNIT_TEST( test3DSurfInterpP0P0_3 );
+
     CPPUNIT_TEST( testInterpolationCC );
     CPPUNIT_TEST( testInterpolationCU1D );
     CPPUNIT_TEST( testInterpolationCU2D );
     CPPUNIT_TEST( testInterpolationCU3D );
+
     CPPUNIT_TEST( test3DInterpP0P0_1 );
     CPPUNIT_TEST( test3DInterpP0P0PL_1 );
     CPPUNIT_TEST( test3DInterpP0P0PL_2 );
@@ -115,6 +117,14 @@ namespace ParaMEDMEM
     CPPUNIT_TEST( test3DSurfInterpP1P0Bary_1 );
     CPPUNIT_TEST( test3DInterpP1P0Bary_1 );
     CPPUNIT_TEST( test3DTo1DInterpP0P0PL_1 );
+
+    CPPUNIT_TEST( test1DInterp_1 );
+    CPPUNIT_TEST( test2DCurveInterpP0P0_1 );
+    CPPUNIT_TEST( test2DCurveInterpP0P0_2 );
+    CPPUNIT_TEST( test2DCurveInterpP0P1_1 );
+    CPPUNIT_TEST( test2DCurveInterpP1P0_1 );
+    CPPUNIT_TEST( test2DCurveInterpP1P1_1 );
+
     CPPUNIT_TEST_SUITE_END();
   public:
     void testArray();
@@ -187,10 +197,12 @@ namespace ParaMEDMEM
     void test3DInterpP1P0PL_1();
     void test3DInterpP1P1_1();
     void test3DInterpP1P1PL_1();
+
     void testInterpolationCC();
     void testInterpolationCU1D();
     void testInterpolationCU2D();
     void testInterpolationCU3D();
+
     void test3DInterpP0P0Empty();
     void test2DInterpP0IntegralUniform();
     void test3DSurfInterpP0IntegralUniform();
@@ -201,6 +213,14 @@ namespace ParaMEDMEM
     void test3DSurfInterpP1P0Bary_1();
     void test3DInterpP1P0Bary_1();
     void test3DTo1DInterpP0P0PL_1();
+
+    void test1DInterp_1();
+    void test2DCurveInterpP0P0_1();
+    void test2DCurveInterpP0P0_2();
+    void test2DCurveInterpP0P1_1();
+    void test2DCurveInterpP1P0_1();
+    void test2DCurveInterpP1P1_1();
+
   private:
     MEDCouplingUMesh *build3DSourceMesh_2();
     MEDCouplingUMesh *build3DTargetMesh_2();
@@ -223,6 +243,8 @@ namespace ParaMEDMEM
     MEDCouplingUMesh *build3DTargetMeshMergeNode_1();
     MEDCouplingUMesh *build3DExtrudedUMesh_1(MEDCouplingUMesh *&mesh2D);
     MEDCouplingUMesh *build2DTargetMeshMerged_1();
+    MEDCouplingUMesh *build2DCurveMesh(double dx, double dy);
+    MEDCouplingUMesh *build1DMesh(double dx);
     double sumAll(const std::vector< std::map<int,double> >& matrix);
   };
 }
index 2e9f50d115f026a7b7bc892080afdd34848ca942..e0606fd528d54ed94d161f626403d92ab196f354 100644 (file)
@@ -544,6 +544,53 @@ MEDCouplingUMesh *MEDCouplingBasicsTest::build2DTargetMeshMerged_1()
   return targetMesh;
 }
 
+MEDCouplingUMesh *MEDCouplingBasicsTest::build2DCurveMesh(double dx, double dy)
+{
+  // 1d mesh:
+  //
+  //       *
+  //      /
+  // *---*
+  double targetCoords[3*2]=
+    {
+      0.+dx,0.+dy, 1.+dx,0.+dy, 2.+dx,1.+dy
+    };
+  int targetConn[2*2]={1,2, 0,1};
+
+  MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New("2Dcurve 1D mesh",1);
+  targetMesh->allocateCells(2);
+  for(int i=0;i<2;i++)
+    targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn+2*i);
+  targetMesh->finishInsertingCells();
+  DataArrayDouble *myCoords=DataArrayDouble::New();
+  myCoords->alloc(3,2);
+  std::copy(targetCoords,targetCoords+3*2,myCoords->getPointer());
+  targetMesh->setCoords(myCoords);
+  myCoords->decrRef();
+  return targetMesh;
+}
+
+MEDCouplingUMesh *MEDCouplingBasicsTest::build1DMesh(double dx)
+{
+  double targetCoords[4]=
+    {
+      0.+dx, 1.+dx, 3.+dx, 4.+dx
+    };
+  int targetConn[2*3]={1,2, 0,1, 2,3};
+
+  MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New("1D mesh",1);
+  targetMesh->allocateCells(3);
+  for(int i=0;i<3;i++)
+    targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn+2*i);
+  targetMesh->finishInsertingCells();
+  DataArrayDouble *myCoords=DataArrayDouble::New();
+  myCoords->alloc(4,1);
+  std::copy(targetCoords,targetCoords+4,myCoords->getPointer());
+  targetMesh->setCoords(myCoords);
+  myCoords->decrRef();
+  return targetMesh;
+}
+
 double MEDCouplingBasicsTest::sumAll(const std::vector< std::map<int,double> >& matrix)
 {
   double ret=0.;
index ddb16f44cdef146066c7a8531ef91a8aeddc560d..c31a49cc6f59d0b073ac7fd9b94376fe3b94e4fd 100644 (file)
@@ -26,6 +26,8 @@
 #include "Interpolation3D.txx"
 #include "InterpolationCC.txx"
 #include "InterpolationCU.txx"
+#include "Interpolation2DCurve.txx"
+#include "Interpolation1D.txx"
 
 #include "MEDCouplingNormalizedUnstructuredMesh.txx"
 #include "MEDCouplingNormalizedCartesianMesh.txx"
@@ -2018,3 +2020,194 @@ void MEDCouplingBasicsTest::test3DTo1DInterpP0P0PL_1()
   sourceMesh->decrRef();
   targetMesh->decrRef();
 }
+
+void MEDCouplingBasicsTest::test1DInterp_1()
+{
+  //      c1   c0    c2    - pay attention to cell order!
+  // S: o---o------o---o
+  // T:   o---o------o---o
+  //      n0  n1     n2  n3
+  //
+  // ---+---+------+---+---> X
+  //    0.  1.     3.  4.   
+  MEDCouplingUMesh *sourceMesh=build1DMesh(0);
+  MEDCouplingUMesh *targetMesh=build1DMesh(0.5);
+  //
+  MEDCouplingNormalizedUnstructuredMesh<1,1> sourceWrapper(sourceMesh);
+  MEDCouplingNormalizedUnstructuredMesh<1,1> targetWrapper(targetMesh);
+  INTERP_KERNEL::Interpolation1D myInterpolator;
+  const double precis = 1e-13;
+  myInterpolator.setPrecision(precis);
+
+  // P0P0
+  vector<map<int,double> > res;
+  myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P0");
+  CPPUNIT_ASSERT_EQUAL( 3, int( res.size()) );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.5, res[0][0], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[0][2], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[1][0], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[1][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[2][2], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.5, sumAll(res), precis);
+
+  // P1P0
+  res.clear();
+  myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P1P0");
+  CPPUNIT_ASSERT_EQUAL( 3, int( res.size()) );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[0][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.5, res[0][2], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, res[1][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[2][3], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.5, sumAll(res), precis);
+
+  // P0P1
+  res.clear();
+  myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P1");
+
+  CPPUNIT_ASSERT_EQUAL( 4, int( res.size()) );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[0][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.5, res[1][0], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[2][0], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, res[2][2], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.5, sumAll(res), precis);
+
+  // P1P1
+  res.clear();
+  myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P1P1");
+  CPPUNIT_ASSERT_EQUAL( 4, int( res.size()) );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[0][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, res[1][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[1][2], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, res[2][2], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[2][3], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.5, sumAll(res), precis);
+
+  sourceMesh->decrRef();
+  targetMesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::test2DCurveInterpP0P0_1()
+{
+  // coincident meshes
+  MEDCouplingUMesh *sourceMesh=build2DCurveMesh(0,0);
+  MEDCouplingUMesh *targetMesh=build2DCurveMesh(0,0);
+  //
+  MEDCouplingNormalizedUnstructuredMesh<2,1> sourceWrapper(sourceMesh);
+  MEDCouplingNormalizedUnstructuredMesh<2,1> targetWrapper(targetMesh);
+  INTERP_KERNEL::Interpolation2DCurve myInterpolator;
+  const double precis = 1e-13;
+  myInterpolator.setPrecision(precis);
+  vector<map<int,double> > res;
+  myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P0");
+
+  CPPUNIT_ASSERT_EQUAL( 2, int( res.size()) );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( sqrt(2),res[0][0], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1., res[1][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.+sqrt(2), sumAll(res), precis);
+
+  sourceMesh->decrRef();
+  targetMesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::test2DCurveInterpP0P0_2()
+{
+  // equal meshes shifted one from another along X by 0.5
+  MEDCouplingUMesh *sourceMesh=build2DCurveMesh(0.5,0);
+  MEDCouplingUMesh *targetMesh=build2DCurveMesh(0,0);
+  //
+  MEDCouplingNormalizedUnstructuredMesh<2,1> sourceWrapper(sourceMesh);
+  MEDCouplingNormalizedUnstructuredMesh<2,1> targetWrapper(targetMesh);
+  INTERP_KERNEL::Interpolation2DCurve myInterpolator;
+  const double precis = 1e-13;
+  myInterpolator.setPrecision(precis);
+  myInterpolator.setMedianPlane(1.);// median line on target
+  vector<map<int,double> > res;
+  myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P0");
+
+  double tolInters = myInterpolator.getBoundingBoxAdjustmentAbs() * sqrt(2);
+  CPPUNIT_ASSERT_EQUAL( 2, int( res.size()) );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0,res[0][0], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( tolInters,res[0][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, res[1][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5+tolInters, sumAll(res), precis);
+
+  sourceMesh->decrRef();
+  targetMesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::test2DCurveInterpP0P1_1()
+{
+  // coincident meshes
+  MEDCouplingUMesh *sourceMesh=build2DCurveMesh(0,0);
+  MEDCouplingUMesh *targetMesh=build2DCurveMesh(0,0);
+  //
+  MEDCouplingNormalizedUnstructuredMesh<2,1> sourceWrapper(sourceMesh);
+  MEDCouplingNormalizedUnstructuredMesh<2,1> targetWrapper(targetMesh);
+  INTERP_KERNEL::Interpolation2DCurve myInterpolator;
+  const double precis = 1e-13;
+  myInterpolator.setPrecision(precis);
+  vector<map<int,double> > res;
+  myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P0P1");
+
+  const double len1 = 1., len0 = sqrt(2);
+  CPPUNIT_ASSERT_EQUAL( 3, int( res.size()) );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*len1, res[0][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*len0, res[1][0], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*len1, res[1][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*len0, res[2][0], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( len0+len1, sumAll(res), precis);
+
+  sourceMesh->decrRef();
+  targetMesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::test2DCurveInterpP1P0_1()
+{
+  // coincident meshes
+  MEDCouplingUMesh *sourceMesh=build2DCurveMesh(0,0);
+  MEDCouplingUMesh *targetMesh=build2DCurveMesh(0,0);
+  //
+  MEDCouplingNormalizedUnstructuredMesh<2,1> sourceWrapper(sourceMesh);
+  MEDCouplingNormalizedUnstructuredMesh<2,1> targetWrapper(targetMesh);
+  INTERP_KERNEL::Interpolation2DCurve myInterpolator;
+  const double precis = 1e-13;
+  myInterpolator.setPrecision(precis);
+  vector<map<int,double> > res;
+  myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P1P0");
+
+  const double len1 = 1., len0 = sqrt(2);
+  CPPUNIT_ASSERT_EQUAL( 2, int( res.size()) );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*len1, res[1][0], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*len0, res[0][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*len1, res[1][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*len0, res[0][2], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( len0+len1, sumAll(res), precis);
+
+  sourceMesh->decrRef();
+  targetMesh->decrRef();
+}
+
+void MEDCouplingBasicsTest::test2DCurveInterpP1P1_1()
+{
+  // coincident meshes
+  MEDCouplingUMesh *sourceMesh=build2DCurveMesh(0,0);
+  MEDCouplingUMesh *targetMesh=build2DCurveMesh(0,0);
+  //
+  MEDCouplingNormalizedUnstructuredMesh<2,1> sourceWrapper(sourceMesh);
+  MEDCouplingNormalizedUnstructuredMesh<2,1> targetWrapper(targetMesh);
+  INTERP_KERNEL::Interpolation2DCurve myInterpolator;
+  const double precis = 1e-13;
+  myInterpolator.setPrecision(precis);
+  vector<map<int,double> > res;
+  myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,res,"P1P1");
+
+  const double len1 = 1., len0 = sqrt(2);
+  CPPUNIT_ASSERT_EQUAL( 3, int( res.size()) );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*len1, res[0][0], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*(len0+len1), res[1][1], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5*len0, res[2][2], precis);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( len0+len1, sumAll(res), precis);
+
+  sourceMesh->decrRef();
+  targetMesh->decrRef();
+}