From: ageay Date: Tue, 2 Mar 2010 17:02:19 +0000 (+0000) Subject: 2D->1D in remapper. X-Git-Tag: V5_1_main_FINAL~173 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3e9d53985b88cab348cb0342c4a6cb23346c7d71;p=tools%2Fmedcoupling.git 2D->1D in remapper. --- diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx index 1078a6a10..d22347451 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx @@ -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; diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx index dba945f35..395b44951 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx @@ -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); diff --git a/src/INTERP_KERNEL/PointLocator2DIntersector.txx b/src/INTERP_KERNEL/PointLocator2DIntersector.txx index 7c51853b9..c47b01388 100644 --- a/src/INTERP_KERNEL/PointLocator2DIntersector.txx +++ b/src/INTERP_KERNEL/PointLocator2DIntersector.txx @@ -54,7 +54,7 @@ namespace INTERP_KERNEL NormalizedCellType tT=PlanarIntersector::_meshT.getTypeOfElement(icellT); QuadraticPolygon *pT=buildPolygonFrom(CoordsT,tT); double baryT[SPACEDIM]; - pT->getBarycenter(baryT); + pT->getBarycenterGeneral(baryT); delete pT; if(PointLocatorAlgos::isElementContainsPointAlg2D(baryT,&CoordsS[0],nbNodesS,InterpType::_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::isElementContainsPointAlg2D(bary,&targetCoords[0],nbOfTargetNodes) ) return 1.; diff --git a/src/MEDCoupling/MEDCouplingRemapper.cxx b/src/MEDCoupling/MEDCouplingRemapper.cxx index a8d071306..8aefe6e14 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.cxx +++ b/src/MEDCoupling/MEDCouplingRemapper.cxx @@ -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) diff --git a/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx b/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx index fcbbf4b61..67cf46cfc 100644 --- a/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx +++ b/src/MEDCoupling/Test/MEDCouplingRemapperTest.cxx @@ -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;igetNumberOfCells();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}; diff --git a/src/MEDCoupling/Test/MEDCouplingRemapperTest.hxx b/src/MEDCoupling/Test/MEDCouplingRemapperTest.hxx index 3cba550c5..2e3b37a87 100644 --- a/src/MEDCoupling/Test/MEDCouplingRemapperTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingRemapperTest.hxx @@ -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();