From: ageay Date: Thu, 21 Jun 2012 14:34:24 +0000 (+0000) Subject: API modif of duplication of nodes. X-Git-Tag: V6_main_FINAL~628 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bce12649f3356d2146f81c7878aed0caef567ed1;p=tools%2Fmedcoupling.git API modif of duplication of nodes. --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 37928e42d..b11c90712 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1980,10 +1980,12 @@ void MEDCouplingUMesh::renumberNodes2(const int *newNodeNumbers, int newNbOfNode * parameter is altered during the call. * \param [out] nodeIdsToDuplicate node ids needed to be duplicated following the algorithm explain above. * \param [out] cellIdsNeededToBeRenum cell ids in \b this in which the renumber of nodes should be performed. + * \param [out] cellIdsNotModified cell ids int \b this that lies on \b otherDimM1OnSameCoords mesh whose connectivity do \b not need to be modified as it is the case for \b cellIdsNeededToBeRenum. * * \warning This method modifies param \b otherDimM1OnSameCoords (for speed reasons). */ -void MEDCouplingUMesh::findNodesToDuplicate(const MEDCouplingUMesh& otherDimM1OnSameCoords, DataArrayInt *& nodeIdsToDuplicate, DataArrayInt *& cellIdsNeededToBeRenum) const throw(INTERP_KERNEL::Exception) +void MEDCouplingUMesh::findNodesToDuplicate(const MEDCouplingUMesh& otherDimM1OnSameCoords, DataArrayInt *& nodeIdsToDuplicate, + DataArrayInt *& cellIdsNeededToBeRenum, DataArrayInt *& cellIdsNotModified) const throw(INTERP_KERNEL::Exception) { checkFullyDefined(); otherDimM1OnSameCoords.checkFullyDefined(); @@ -2016,9 +2018,12 @@ void MEDCouplingUMesh::findNodesToDuplicate(const MEDCouplingUMesh& otherDimM1On MEDCouplingAutoRefCountObjectPtr neigh00(tmp0); MEDCouplingAutoRefCountObjectPtr neighI00(tmp1); MEDCouplingAutoRefCountObjectPtr cellsToModifyConn0_torenum=MEDCouplingUMesh::ComputeSpreadZoneGradually(neigh00,neighI00); + MEDCouplingAutoRefCountObjectPtr cellsToModifyConn1_torenum=cellsToModifyConn0_torenum->buildComplement(neighI00->getNumberOfTuples()-1); cellsToModifyConn0_torenum->transformWithIndArr(cellIdsRk1->begin(),cellIdsRk1->end()); + cellsToModifyConn1_torenum->transformWithIndArr(cellIdsRk1->begin(),cellIdsRk1->end()); // cellIdsNeededToBeRenum=cellsToModifyConn0_torenum; cellsToModifyConn0_torenum->incrRef(); + cellIdsNotModified=cellsToModifyConn1_torenum; cellsToModifyConn1_torenum->incrRef(); nodeIdsToDuplicate=s3; s3->incrRef(); } diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 924fa49f1..8760441df 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -130,7 +130,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT MEDCouplingUMesh *computeSkin() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); MEDCOUPLING_EXPORT void renumberNodes2(const int *newNodeNumbers, int newNbOfNodes); - MEDCOUPLING_EXPORT void findNodesToDuplicate(const MEDCouplingUMesh& otherDimM1OnSameCoords, DataArrayInt *& nodeIdsToDuplicate, DataArrayInt *& cellIdsNeededToBeRenum) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void findNodesToDuplicate(const MEDCouplingUMesh& otherDimM1OnSameCoords, DataArrayInt *& nodeIdsToDuplicate, + DataArrayInt *& cellIdsNeededToBeRenum, DataArrayInt *& cellIdsNotModified) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void duplicateNodes(const int *nodeIdsToDuplicateBg, const int *nodeIdsToDuplicateEnd) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void renumberNodesInConn(const int *newNodeNumbersO2N); MEDCOUPLING_EXPORT void shiftNodeNumbersInConn(int delta) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 89dddec43..042016e48 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -1364,11 +1364,12 @@ namespace ParaMEDMEM PyObject *findNodesToDuplicate(const MEDCouplingUMesh& otherDimM1OnSameCoords) const throw(INTERP_KERNEL::Exception) { - DataArrayInt *tmp0=0,*tmp1=0; - self->findNodesToDuplicate(otherDimM1OnSameCoords,tmp0,tmp1); - PyObject *ret=PyTuple_New(2); + DataArrayInt *tmp0=0,*tmp1=0,*tmp2=0; + self->findNodesToDuplicate(otherDimM1OnSameCoords,tmp0,tmp1,tmp2); + PyObject *ret=PyTuple_New(3); PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(tmp0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(tmp2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 7403cb787..19f65abd4 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -1997,7 +1997,7 @@ void MEDFileUMesh::optimizeFamilies() throw(INTERP_KERNEL::Exception) _groups.erase(*it); } -void MEDFileUMesh::duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified) throw(INTERP_KERNEL::Exception) +void MEDFileUMesh::duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified, DataArrayInt *&cellsNotModified) throw(INTERP_KERNEL::Exception) { std::vector levs=getNonEmptyLevels(); if(std::find(levs.begin(),levs.end(),0)==levs.end() || std::find(levs.begin(),levs.end(),-1)==levs.end()) @@ -2006,10 +2006,11 @@ void MEDFileUMesh::duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt * MEDCouplingAutoRefCountObjectPtr m1=getMeshAtLevel(-1); int nbNodes=m0->getNumberOfNodes(); MEDCouplingAutoRefCountObjectPtr m11=getGroup(-1,grpNameM1); - DataArrayInt *tmp00=0,*tmp11=0; - m0->findNodesToDuplicate(*m11,tmp00,tmp11); + DataArrayInt *tmp00=0,*tmp11=0,*tmp22=0; + m0->findNodesToDuplicate(*m11,tmp00,tmp11,tmp22); MEDCouplingAutoRefCountObjectPtr nodeIdsToDuplicate(tmp00); MEDCouplingAutoRefCountObjectPtr cellsToModifyConn0(tmp11); + MEDCouplingAutoRefCountObjectPtr cellsToModifyConn1(tmp22); MEDCouplingAutoRefCountObjectPtr tmp0=static_cast(m0->buildPartOfMySelf(cellsToModifyConn0->begin(),cellsToModifyConn0->end(),true)); // node renumbering of cells in m1 impacted by duplication of node but not in group 'grpNameM1' on level -1 MEDCouplingAutoRefCountObjectPtr descTmp0=DataArrayInt::New(),descITmp0=DataArrayInt::New(),revDescTmp0=DataArrayInt::New(),revDescITmp0=DataArrayInt::New(); @@ -2083,6 +2084,7 @@ void MEDFileUMesh::duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt * } nodesDuplicated=nodeIdsToDuplicate; nodeIdsToDuplicate->incrRef(); cellsModified=cellsToModifyConn0; cellsToModifyConn0->incrRef(); + cellsNotModified=cellsToModifyConn1; cellsToModifyConn1->incrRef(); } void MEDFileUMesh::addNodeGroup(const std::string& name, const std::vector& ids) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 9f77de916..662fc4b1f 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -200,7 +200,7 @@ namespace ParaMEDMEM void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms, bool renum) throw(INTERP_KERNEL::Exception); void optimizeFamilies() throw(INTERP_KERNEL::Exception); - void duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified) throw(INTERP_KERNEL::Exception); + void duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified, DataArrayInt *&cellsNotModified) throw(INTERP_KERNEL::Exception); private: void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); MEDFileUMesh(); diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 6fb38fc4d..b3dc04813 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -331,6 +331,7 @@ namespace ParaMEDMEM double getTimeValue() const; void setTimeUnit(const char *unit); const char *getTimeUnit() const; + virtual int getNumberOfNodes() const throw(INTERP_KERNEL::Exception) = 0; std::vector getNonEmptyLevels() const; std::vector getNonEmptyLevelsExt() const; void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); @@ -544,11 +545,12 @@ namespace ParaMEDMEM PyObject *duplicateNodesOnM1Group(const char *grpNameM1) throw(INTERP_KERNEL::Exception) { - DataArrayInt *ret0=0,*ret1=0; - self->duplicateNodesOnM1Group(grpNameM1,ret0,ret1); - PyObject *ret=PyTuple_New(2); + DataArrayInt *ret0=0,*ret1=0,*ret2=0; + self->duplicateNodesOnM1Group(grpNameM1,ret0,ret1,ret2); + PyObject *ret=PyTuple_New(3); PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } } diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index c224c6bbd..57f29217a 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -1150,6 +1150,106 @@ class MEDLoaderTest(unittest.TestCase): self.assertAlmostEqual(expected1[i],tes3.getArray().getIJ(0,i),13); pass pass + + def testDuplicateNodesOnM1Group1(self): + fname="Pyfile44.med" + m=MEDCouplingCMesh.New() + m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5])) + m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.])) + m=m.buildUnstructured() ; m.setName("AnthonyDuplicate") + m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"]) + m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]] + m2.setName(m.getName()) + grp=DataArrayInt.New([4,6,8]) ; grp.setName("Grp") + grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2") + mm=MEDFileUMesh.New() + mm.setMeshAtLevel(0,m) + mm.setMeshAtLevel(-1,m2) + mm.setGroupsAtLevel(-1,[grp,grp2]) + grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode") + mm.setGroupsAtLevel(1,[grpNode]) + ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23] + ref1=[4,9,8,14,15,4,10,9,15,16,4,11,10,16,17] + ref2=[4,9,8,14,30,4,10,9,30,31,4,11,10,31,32] + # + self.assertEqual(30,mm.getNumberOfNodes()) + self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues()) + self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues()) + # + nodes,cells,cells2=mm.duplicateNodesOnM1Group("Grp") + self.assertEqual([15,16,17],nodes.getValues()); + self.assertEqual([7,8,9],cells.getValues()); + self.assertEqual([12,13,14],cells2.getValues()); + self.assertEqual(33,mm.getNumberOfNodes()) + self.assertEqual([4,6,8],mm.getGroupArr(-1,"Grp").getValues()) + self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues()) + self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues()) + self.assertEqual([17,18,19],mm.getGroupArr(-1,"Grp_dup").getValues()) + self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())#cells 7,8,9 and 12,13,14 are lying on "Grp" but only 7,8 and 9 are renumbered + self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())# + self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),2,1e-12);# Grp_dup and Grp are not equal considering connectivity only + mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates + refValues=DataArrayDouble.New([1.21,1.32,1.43,1.54,1.65,1.32,1.44,1.56,1.68,1.8,1.43,1.56,1.69,1.82,1.95,1.54,1.68,1.82,1.96,2.1]) + valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs() + self.assertTrue(delta.getMaxValue()[0]<1e-12) + # + mm.getCoords()[-len(nodes):]+=[0.,-0.3] + self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12); + refValues2=refValues[:] ; refValues2[7:10]=[1.365,1.26,1.35] + valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs() + self.assertTrue(delta.getMaxValue()[0]<1e-12) + mm.write(fname,2) + pass + + def testDuplicateNodesOnM1Group2(self): + fname="Pyfile45.med" + m=MEDCouplingCMesh.New() + m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5])) + m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.])) + m=m.buildUnstructured() ; m.setName("AnthonyDuplicate") + m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"]) + m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]] + m2.setName(m.getName()) + grp=DataArrayInt.New([4,6]) ; grp.setName("Grp") + grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2") + mm=MEDFileUMesh.New() + mm.setMeshAtLevel(0,m) + mm.setMeshAtLevel(-1,m2) + mm.setGroupsAtLevel(-1,[grp,grp2]) + grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode") + mm.setGroupsAtLevel(1,[grpNode]) + ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23] + ref1=[4,9,8,14,15,4,10,9,15,16] + ref2=[4,9,8,14,30,4,10,9,30,16] + # + self.assertEqual(30,mm.getNumberOfNodes()) + self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues()) + self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues()) + # + nodes,cells,cells2=mm.duplicateNodesOnM1Group("Grp") + self.assertEqual([15],nodes.getValues()); + self.assertEqual([7,8],cells.getValues()); + self.assertEqual([12,13],cells2.getValues()); + self.assertEqual(31,mm.getNumberOfNodes()) + self.assertEqual([4,6],mm.getGroupArr(-1,"Grp").getValues()) + self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues()) + self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues()) + self.assertEqual([17,18],mm.getGroupArr(-1,"Grp_dup").getValues()) + self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())#cells 7,8,9 and 12,13,14 are lying on "Grp" but only 7,8 and 9 are renumbered + self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())# + self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),2,1e-12);# Grp_dup and Grp are not equal considering connectivity only + mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates + refValues=DataArrayDouble.New([1.21,1.32,1.43,1.54,1.65,1.32,1.44,1.56,1.68,1.8,1.43,1.56,1.69,1.82,1.95,1.54,1.68,1.82,1.96,2.1]) + valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs() + self.assertTrue(delta.getMaxValue()[0]<1e-12) + # + mm.getCoords()[-len(nodes):]+=[0.,-0.3] + self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12); + refValues2=refValues[:] ; refValues2[7:9]=[1.365,1.47] + valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs() + self.assertTrue(delta.getMaxValue()[0]<1e-12) + mm.write(fname,2) + pass pass unittest.main()