]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
API modif of duplication of nodes.
authorageay <ageay>
Thu, 21 Jun 2012 14:34:24 +0000 (14:34 +0000)
committerageay <ageay>
Thu, 21 Jun 2012 14:34:24 +0000 (14:34 +0000)
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/MEDCouplingUMesh.hxx
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDLoader/MEDFileMesh.cxx
src/MEDLoader/MEDFileMesh.hxx
src/MEDLoader/Swig/MEDLoader.i
src/MEDLoader/Swig/MEDLoaderTest3.py

index 37928e42d2dea96faff706483f00daeaaee7dd65..b11c90712ff3e01c2e7ec675d86e113cd0afc0f4 100644 (file)
@@ -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<DataArrayInt> neigh00(tmp0);
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> neighI00(tmp1);
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsToModifyConn0_torenum=MEDCouplingUMesh::ComputeSpreadZoneGradually(neigh00,neighI00);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> 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();
 }
 
index 924fa49f11e4fb6bc70ca254208c6df5feb2ec5c..8760441dfb0ffab1d57896591e76a9cb39c1d7cd 100644 (file)
@@ -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);
index 89dddec43b5ac292e039d2a9f5a87b2a12e7e2b5..042016e48f5fb3cf2ebb25eb1abea6fc9edef78a 100644 (file)
@@ -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;
       }
 
index 7403cb787c8568d31118f99f735bf904cc01c82a..19f65abd4ee7a5dbd6f829f353f9f773d6296f9f 100644 (file)
@@ -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<int> 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<MEDCouplingUMesh> m1=getMeshAtLevel(-1);
   int nbNodes=m0->getNumberOfNodes();
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> 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<DataArrayInt> nodeIdsToDuplicate(tmp00);
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsToModifyConn0(tmp11);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsToModifyConn1(tmp22);
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp0=static_cast<MEDCouplingUMesh *>(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<DataArrayInt> 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<int>& ids) throw(INTERP_KERNEL::Exception)
index 9f77de9165016479162858c7e6256de1999d112b..662fc4b1f3a3380375ef95c66a2ba0ebd1459c07 100644 (file)
@@ -200,7 +200,7 @@ namespace ParaMEDMEM
     void setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception);
     void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& 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();
index 6fb38fc4d8ce044384de9c6a7c41fc163c6c4ff5..b3dc04813d2c87e7139905cdfeedd49879480997 100644 (file)
@@ -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<int> getNonEmptyLevels() const;
     std::vector<int> 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;
          }
        }
index c224c6bbd7b3c79be9e6c9d6047efeed072bf466..57f29217aa5665280ff8fa527ec07ef6e205649d 100644 (file)
@@ -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()