]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
2D->1D in remapper.
authorageay <ageay>
Tue, 2 Mar 2010 17:02:19 +0000 (17:02 +0000)
committerageay <ageay>
Tue, 2 Mar 2010 17:02:19 +0000 (17:02 +0000)
src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx
src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx
src/INTERP_KERNEL/PointLocator2DIntersector.txx
src/MEDCoupling/MEDCouplingRemapper.cxx
src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx
src/MEDCoupling/Test/MEDCouplingRemapperTest.hxx

index 1078a6a1065755e667b379bd1d3fec5a53ca1214..d223474518548478731b209b1fa2201baee91894 100644 (file)
@@ -196,6 +196,19 @@ void ComposedEdge::getBarycenter(double *bary) const
   bary[1]/=area;
 }
 
+/*!
+ * Idem ComposedEdge::getBarycenter except that the special case where _sub_edges==1 is dealt here.
+ */
+void ComposedEdge::getBarycenterGeneral(double *bary) const
+{
+  if(_sub_edges.empty())
+    throw INTERP_KERNEL::Exception("ComposedEdge::getBarycenterGeneral called on an empty polygon !");
+  if(_sub_edges.size()>2)
+    return getBarycenter(bary);
+  double w;
+  _sub_edges.back()->getBarycenter(bary,w);
+}
+
 double ComposedEdge::normalize(ComposedEdge *other, double& xBary, double& yBary)
 {
   Bounds b;
index dba945f35c01c916aa7d3706f1bf005275fc8842..395b4495178011a7cf63b5f7ee1fdec257251f34 100644 (file)
@@ -52,6 +52,7 @@ namespace INTERP_KERNEL
     double getPerimeter() const;
     double getHydraulicDiameter() const;
     void getBarycenter(double *bary) const;
+    void getBarycenterGeneral(double *bary) const;
     double normalize(ComposedEdge *other, double& xBary, double& yBary);
     void fillBounds(Bounds& output) const;
     void applySimilarity(double xBary, double yBary, double dimChar);
index 7c51853b941641cb41342333045da4b2a852a11e..c47b0138847fea6015db22acc6a90c6dba1961d0 100644 (file)
@@ -54,7 +54,7 @@ namespace INTERP_KERNEL
     NormalizedCellType tT=PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getTypeOfElement(icellT);
     QuadraticPolygon *pT=buildPolygonFrom(CoordsT,tT);
     double baryT[SPACEDIM];
-    pT->getBarycenter(baryT);
+    pT->getBarycenterGeneral(baryT);
     delete pT;
     if(PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(baryT,&CoordsS[0],nbNodesS,InterpType<MyMeshType,MyMatrix,PTLOC2D_INTERSECTOR >::_precision))
       return 1.;
@@ -94,7 +94,7 @@ namespace INTERP_KERNEL
       nodes2[i]=new Node(sourceCoords[i*SPACEDIM],sourceCoords[i*SPACEDIM+1]);
     QuadraticPolygon *p=QuadraticPolygon::buildLinearPolygon(nodes2);
     double bary[SPACEDIM];
-    p->getBarycenter(bary);
+    p->getBarycenterGeneral(bary);
     delete p;
     if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(bary,&targetCoords[0],nbOfTargetNodes) )
       return 1.;
index a8d071306874814b4ef8726ba4d3f02cab16cdc8..8aefe6e14601b66593f18c826e4e9006174f88e6 100644 (file)
@@ -206,6 +206,15 @@ int MEDCouplingRemapper::prepareUU(const char *method)
       reverseMatrix(matrixTmp,nbCols,_matrix);
       nbCols=matrixTmp.size();
     }
+  else if(srcMeshDim==2 && trgMeshDim==1 && srcSpaceDim==2)
+    {
+      if(getIntersectionType()!=INTERP_KERNEL::PointLocator)
+        throw INTERP_KERNEL::Exception("Invalid interpolation requested between 2D and 1D ! Select PointLocator as intersection type !");
+      MEDCouplingNormalizedUnstructuredMesh<2,2> source_mesh_wrapper(src_mesh);
+      MEDCouplingNormalizedUnstructuredMesh<2,2> target_mesh_wrapper(target_mesh);
+      INTERP_KERNEL::Interpolation2D interpolation(*this);
+      nbCols=interpolation.interpolateMeshes(source_mesh_wrapper,target_mesh_wrapper,_matrix,method);
+    }
   else if(trgMeshDim==-1)
     {
       if(srcMeshDim==2 && srcSpaceDim==2)
index fcbbf4b6184959d4feecfb8cad22695ea44c1f06..67cf46cfc10cce972d1e419c1fcace67d888c4c7 100644 (file)
@@ -383,6 +383,30 @@ void MEDCouplingRemapperTest::testMultiDimCombi()
   srcField->decrRef();
   sourceMesh->decrRef();
   targetMesh->decrRef();
+  // ------------- 2D -> 1D
+  sourceMesh=build2DTargetMesh_1();
+  targetMesh=build1DTargetMesh_2();
+  remapper.setIntersectionType(INTERP_KERNEL::PointLocator);
+  CPPUNIT_ASSERT_EQUAL(1,remapper.prepare(sourceMesh,targetMesh,"P0P0"));
+  srcField=MEDCouplingFieldDouble::New(ON_CELLS);
+  srcField->setNature(ConservativeVolumic);
+  srcField->setMesh(sourceMesh);
+  array=DataArrayDouble::New();
+  array->alloc(sourceMesh->getNumberOfCells(),1);
+  srcField->setArray(array);
+  ptr=array->getPointer();
+  for(int i=0;i<sourceMesh->getNumberOfCells();i++)
+    ptr[i]=(double)(i+7);
+  array->decrRef();
+  trgField=remapper.transferField(srcField,4.57);
+  const double valuesExpected8[5]={9.,8.,11.,7.,11.};
+  values=trgField->getArray()->getConstPointer();
+  for(int i0=0;i0<5;i0++)
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected8[i0],values[i0],1e-12);
+  trgField->decrRef();
+  srcField->decrRef();
+  sourceMesh->decrRef();
+  targetMesh->decrRef();
   // ------------- 2D -> -1D
   sourceMesh=build2DTargetMesh_1();
   targetMesh=MEDCouplingUMesh::New("an example of -1 D mesh",-1);
@@ -687,6 +711,27 @@ MEDCouplingUMesh *MEDCouplingRemapperTest::build1DTargetMesh_1()
   return targetMesh;
 }
 
+MEDCouplingUMesh *MEDCouplingRemapperTest::build1DTargetMesh_2()
+{
+  double targetCoords[20]={
+    0.59,0.09, 0.69,0.19, 0.21,-0.29,0.31,-0.19, 0.45,0.25,0.65,0.45,
+    -0.2,-0.2,0.11,0.11, 0.25,0.25, 0.45,0.45
+  };
+  int targetConn[10]={0,1, 2,3, 4,5, 6,7, 8,9};
+
+  MEDCouplingUMesh *targetMesh=MEDCouplingUMesh::New("my name of mesh 1D 2",1);
+  targetMesh->allocateCells(5);
+  for(int i=0;i<5;i++)
+    targetMesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,targetConn+2*i);
+  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 *MEDCouplingRemapperTest::build2DSourceMesh_1()
 {
   double sourceCoords[8]={-0.3,-0.3, 0.7,-0.3, -0.3,0.7, 0.7,0.7};
index 3cba550c511e33fc1099791573b339cc3ad2c3b7..2e3b37a87c63c02f98c29b2c9c36408399d577b0 100644 (file)
@@ -49,6 +49,7 @@ namespace ParaMEDMEM
     MEDCouplingUMesh *build3DSourceMesh_2();
     MEDCouplingUMesh *build3DTargetMesh_2();
     MEDCouplingUMesh *build1DTargetMesh_1();
+    MEDCouplingUMesh *build1DTargetMesh_2();
     MEDCouplingUMesh *build2DSourceMesh_1();
     MEDCouplingUMesh *build2DTargetMesh_1();
     MEDCouplingUMesh *build2DTargetMeshPerm_1();