Salome HOME
[EDF21269] : Reproduce PTScotch graph split between independant runs
[tools/medcoupling.git] / src / MEDPartitioner / MEDPARTITIONER_ConnectZone.cxx
index 31dfdca1633ea9a1d603b621de29e797c980771d..870fd4f0fbb56cfed794b42bbaa5c4e894375f27 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -30,6 +30,8 @@ MEDPARTITIONER::ConnectZone::ConnectZone():
   ,_description("")
   ,_local_domain_number(0)
   ,_distant_domain_number(0)
+  ,_local_mesh(0)
+  ,_distant_mesh(0)
   ,_node_corresp(0)
   ,_face_corresp(0)
 {
@@ -37,11 +39,9 @@ MEDPARTITIONER::ConnectZone::ConnectZone():
 
 MEDPARTITIONER::ConnectZone::~ConnectZone()
 {
-  delete _node_corresp;
-  delete _face_corresp;
-  for(std::map < std::pair <int, int>,MEDCouplingSkyLineArray * >::iterator iter=_entity_corresp.begin(); iter!=_entity_corresp.end();iter++)
+  for(std::map < std::pair <mcIdType, mcIdType>,MEDCouplingSkyLineArray * >::iterator iter=_entity_corresp.begin(); iter!=_entity_corresp.end();iter++)
     {
-      delete iter->second;
+      iter->second->decrRef();
     }
 }
 
@@ -50,6 +50,8 @@ MEDPARTITIONER::ConnectZone::ConnectZone(const ConnectZone & myConnectZone):
   ,_description(myConnectZone._description)
   ,_local_domain_number(myConnectZone._local_domain_number)
   ,_distant_domain_number(myConnectZone._distant_domain_number)
+  ,_local_mesh(0)
+  ,_distant_mesh(0)
   ,_node_corresp(myConnectZone._node_corresp)
   ,_face_corresp(myConnectZone._face_corresp)
   ,_entity_corresp(myConnectZone._entity_corresp)
@@ -76,19 +78,19 @@ int MEDPARTITIONER::ConnectZone::getLocalDomainNumber() const
   return _local_domain_number;
 }
 
-MEDCoupling::MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getLocalMesh() const 
+MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getLocalMesh() const
 {
   return _local_mesh;
 }
 
-MEDCoupling::MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getDistantMesh() const 
+MEDCouplingUMesh *MEDPARTITIONER::ConnectZone::getDistantMesh() const
 {
   return _distant_mesh;
 }
 
-bool MEDPARTITIONER::ConnectZone::isEntityCorrespPresent(int localEntity, int distantEntity) const
+bool MEDPARTITIONER::ConnectZone::isEntityCorrespPresent(mcIdType localEntity, mcIdType distantEntity) const
 {
-  typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
+  typedef std::map<std::pair<mcIdType,mcIdType>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
   for(map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
     {
       if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
@@ -97,50 +99,50 @@ bool MEDPARTITIONER::ConnectZone::isEntityCorrespPresent(int localEntity, int di
   return false;
 }
 
-const int *MEDPARTITIONER::ConnectZone::getNodeCorrespIndex() const
+const mcIdType *MEDPARTITIONER::ConnectZone::getNodeCorrespIndex() const
 {
   return _node_corresp->getIndex();
 }
 
-const int *MEDPARTITIONER::ConnectZone::getNodeCorrespValue() const
+const mcIdType *MEDPARTITIONER::ConnectZone::getNodeCorrespValue() const
 {
-  return _node_corresp->getValue();
+  return _node_corresp->getValues();
 }
 
-int MEDPARTITIONER::ConnectZone::getNodeNumber() const
+mcIdType MEDPARTITIONER::ConnectZone::getNodeNumber() const
 {
   return _node_corresp->getNumberOf();
 }
 
-const MEDCoupling::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getNodeCorresp() const
+const MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getNodeCorresp() const
 {
-  return _node_corresp;
+  return (const MEDCouplingSkyLineArray *)_node_corresp;
 }
 
-const int *MEDPARTITIONER::ConnectZone::getFaceCorrespIndex() const
+const mcIdType *MEDPARTITIONER::ConnectZone::getFaceCorrespIndex() const
 {
   return _face_corresp->getIndex();
 }
 
-const int *MEDPARTITIONER::ConnectZone::getFaceCorrespValue() const
+const mcIdType *MEDPARTITIONER::ConnectZone::getFaceCorrespValue() const
 {
-  return _face_corresp->getValue();
+  return _face_corresp->getValues();
 }
 
-int MEDPARTITIONER::ConnectZone::getFaceNumber() const
+mcIdType MEDPARTITIONER::ConnectZone::getFaceNumber() const
 {
   return _face_corresp->getNumberOf();
 }
 
-const MEDCoupling::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getFaceCorresp() const
+const MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getFaceCorresp() const
 {
   return _face_corresp;
 }
 
-const int *MEDPARTITIONER::ConnectZone::getEntityCorrespIndex(int localEntity,
-                                                              int distantEntity) const
+const mcIdType *MEDPARTITIONER::ConnectZone::getEntityCorrespIndex(mcIdType localEntity,
+                                                                   mcIdType distantEntity) const
 {
-  typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
+  typedef std::map<std::pair<mcIdType,mcIdType>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
 
   for(map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
   {
@@ -150,23 +152,23 @@ const int *MEDPARTITIONER::ConnectZone::getEntityCorrespIndex(int localEntity,
   return 0;
 }
 
-const int *MEDPARTITIONER::ConnectZone::getEntityCorrespValue(int localEntity,
-                                                              int distantEntity) const
+const mcIdType *MEDPARTITIONER::ConnectZone::getEntityCorrespValue(mcIdType localEntity,
+                                                                   mcIdType distantEntity) const
 {
-  typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
+  typedef std::map<std::pair<mcIdType,mcIdType>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
 
   for (map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
   {
     if ((iter->first).first==localEntity && (iter->first).second==distantEntity)
-      return iter->second->getValue();
+      return iter->second->getValues();
   }
   return 0;
 }
 
-int MEDPARTITIONER::ConnectZone::getEntityCorrespNumber(int localEntity,
-                                                        int distantEntity) const
+mcIdType MEDPARTITIONER::ConnectZone::getEntityCorrespNumber(mcIdType localEntity,
+                                                             mcIdType distantEntity) const
 {
-  typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
+  typedef std::map<std::pair<mcIdType,mcIdType>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
 
   for(map_iter iter=_entity_corresp.begin();iter!=_entity_corresp.end();iter++)
   {
@@ -176,10 +178,10 @@ int MEDPARTITIONER::ConnectZone::getEntityCorrespNumber(int localEntity,
   return 0;
 }
 
-int MEDPARTITIONER::ConnectZone::getEntityCorrespLength(int localEntity,
-                                                        int distantEntity) const
+mcIdType MEDPARTITIONER::ConnectZone::getEntityCorrespLength(mcIdType localEntity,
+                                                        mcIdType distantEntity) const
 {
-  typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
+  typedef std::map<std::pair<mcIdType,mcIdType>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
 
   for (map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
   {
@@ -189,10 +191,10 @@ int MEDPARTITIONER::ConnectZone::getEntityCorrespLength(int localEntity,
   return 0;
 }
 
-const MEDCoupling::MEDCouplingSkyLineArray *
-MEDPARTITIONER::ConnectZone::getEntityCorresp(int localEntity, int distantEntity) const
+const MEDCouplingSkyLineArray *
+MEDPARTITIONER::ConnectZone::getEntityCorresp(mcIdType localEntity, mcIdType distantEntity) const
 {
-  typedef std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
+  typedef std::map<std::pair<mcIdType,mcIdType>, MEDCouplingSkyLineArray*>::const_iterator map_iter;
 
   for (map_iter iter=_entity_corresp.begin(); iter != _entity_corresp.end(); iter++)
   {
@@ -202,11 +204,11 @@ MEDPARTITIONER::ConnectZone::getEntityCorresp(int localEntity, int distantEntity
   return 0;
 }
 
-std::vector< std::pair< int,int > > MEDPARTITIONER::ConnectZone::getEntities() const
+std::vector< std::pair< mcIdType,mcIdType > > MEDPARTITIONER::ConnectZone::getEntities() const
 {
-  std::vector< std::pair< int,int > > types;
+  std::vector< std::pair< mcIdType,mcIdType > > types;
 
-  std::map<std::pair<int,int>, MEDCouplingSkyLineArray*>::const_iterator
+  std::map<std::pair<mcIdType,mcIdType>, MEDCouplingSkyLineArray*>::const_iterator
     iter = _entity_corresp.begin();
   for ( ; iter != _entity_corresp.end(); iter++)
     {
@@ -236,12 +238,12 @@ void MEDPARTITIONER::ConnectZone::setLocalDomainNumber(int localDomainNumber)
   _local_domain_number=localDomainNumber;
 }
 
-void MEDPARTITIONER::ConnectZone::setLocalMesh(MEDCoupling::MEDCouplingUMesh * localMesh)
+void MEDPARTITIONER::ConnectZone::setLocalMesh(MEDCouplingUMesh * localMesh)
 {
   _local_mesh=localMesh;
 }
 
-void MEDPARTITIONER::ConnectZone::setDistantMesh(MEDCoupling::MEDCouplingUMesh * distantMesh)
+void MEDPARTITIONER::ConnectZone::setDistantMesh(MEDCouplingUMesh * distantMesh)
 {
   _distant_mesh=distantMesh;
 }
@@ -250,56 +252,56 @@ void MEDPARTITIONER::ConnectZone::setDistantMesh(MEDCoupling::MEDCouplingUMesh *
  * the node-node connections
  * to a MEDCouplingSkyLineArray
  */
-void MEDPARTITIONER::ConnectZone::setNodeCorresp(const int * nodeCorresp, int nbnode)
+void MEDPARTITIONER::ConnectZone::setNodeCorresp(const mcIdType * nodeCorresp, mcIdType nbnode)
 {
-  MCAuto<DataArrayInt> indexArr( DataArrayInt::New() );
-  MCAuto<DataArrayInt> valueArr( DataArrayInt::New() );
+  MCAuto<DataArrayIdType> indexArr( DataArrayIdType::New() );
+  MCAuto<DataArrayIdType> valueArr( DataArrayIdType::New() );
   indexArr->alloc( nbnode+1 );
   valueArr->alloc( 2*nbnode );
-  int * index = indexArr->getPointer();
-  int * value = valueArr->getPointer();
-  for (int i=0; i<nbnode; i++)
+  mcIdType * index = indexArr->getPointer();
+  mcIdType * value = valueArr->getPointer();
+  for (mcIdType i=0; i<nbnode; i++)
     {
       index[i]=2*i;
       value[2*i  ]=nodeCorresp[2*i];
       value[2*i+1]=nodeCorresp[2*i+1];
     }
   index[nbnode]=2*nbnode;
-  setNodeCorresp( new MEDCouplingSkyLineArray( indexArr, valueArr ));
+  setNodeCorresp( MEDCouplingSkyLineArray::New( indexArr, valueArr ));
 }
 
 void MEDPARTITIONER::ConnectZone::setNodeCorresp(MEDCouplingSkyLineArray* array)
 {
-  if ( _node_corresp ) delete _node_corresp;
-  _node_corresp = array;
+  MCAuto<MEDCouplingSkyLineArray> arr(array);
+  _node_corresp = arr;
 }
 
 /*! transforms an int array containing 
  * the face-face connections
  * to a MEDCouplingSkyLineArray
  */
-void MEDPARTITIONER::ConnectZone::setFaceCorresp(const int * faceCorresp, int nbface)
+void MEDPARTITIONER::ConnectZone::setFaceCorresp(const mcIdType * faceCorresp, mcIdType nbface)
 {
-  MCAuto<DataArrayInt> indexArr( DataArrayInt::New() );
-  MCAuto<DataArrayInt> valueArr( DataArrayInt::New() );
+  MCAuto<DataArrayIdType> indexArr( DataArrayIdType::New() );
+  MCAuto<DataArrayIdType> valueArr( DataArrayIdType::New() );
   indexArr->alloc( nbface+1 );
   valueArr->alloc( 2*nbface );
-  int * index = indexArr->getPointer();
-  int * value = valueArr->getPointer();
-  for (int i=0; i<nbface; i++)
+  mcIdType * index = indexArr->getPointer();
+  mcIdType * value = valueArr->getPointer();
+  for (mcIdType i=0; i<nbface; i++)
     {
       index[i]=2*i;
       value[2*i]=faceCorresp[2*i];
       value[2*i+1]=faceCorresp[2*i+1];
     }
   index[nbface]=2*nbface;
-  setFaceCorresp( new MEDCouplingSkyLineArray( indexArr, valueArr ));
+  setFaceCorresp( MEDCouplingSkyLineArray::New( indexArr, valueArr ));
 }
 
 void MEDPARTITIONER::ConnectZone::setFaceCorresp(MEDCouplingSkyLineArray* array)
 {
-  if ( _face_corresp ) delete _face_corresp;
-  _face_corresp = array;
+  MCAuto<MEDCouplingSkyLineArray> arr (array);
+  _face_corresp = arr;
 }
 
 /*! transforms an int array containing 
@@ -308,32 +310,32 @@ void MEDPARTITIONER::ConnectZone::setFaceCorresp(MEDCouplingSkyLineArray* array)
  * 
  * the resulting MEDCouplingSkyLineArray is put in the map
  */
-void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantEntity,
-                                                   const int *entityCorresp, int nbentity)
+void MEDPARTITIONER::ConnectZone::setEntityCorresp(mcIdType localEntity, mcIdType distantEntity,
+                                                   const mcIdType *entityCorresp, mcIdType nbentity)
 { 
-  MCAuto<DataArrayInt> indexArr( DataArrayInt::New() );
-  MCAuto<DataArrayInt> valueArr( DataArrayInt::New() );
+  MCAuto<DataArrayIdType> indexArr( DataArrayIdType::New() );
+  MCAuto<DataArrayIdType> valueArr( DataArrayIdType::New() );
   indexArr->alloc( nbentity+1 );
   valueArr->alloc( 2*nbentity );
-  int * index = indexArr->getPointer();
-  int * value = valueArr->getPointer();
-  for (int i=0; i<nbentity; i++)
+  mcIdType * index = indexArr->getPointer();
+  mcIdType * value = valueArr->getPointer();
+  for (mcIdType i=0; i<nbentity; i++)
     {
       index[i]=2*i;
       value[2*i  ]=entityCorresp[2*i];
       value[2*i+1]=entityCorresp[2*i+1];
     }
   index[nbentity]=2*nbentity;
-  setEntityCorresp( localEntity, distantEntity, new MEDCouplingSkyLineArray(indexArr,valueArr));
+  setEntityCorresp( localEntity, distantEntity, MEDCouplingSkyLineArray::New(indexArr,valueArr));
 }
 
-void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantEntity,
+void MEDPARTITIONER::ConnectZone::setEntityCorresp(mcIdType localEntity, mcIdType distantEntity,
                                                    MEDCouplingSkyLineArray *array)
 {
-  MEDCoupling::MEDCouplingSkyLineArray * nullArray = 0;
-  std::map < std::pair <int,int>, MEDCoupling::MEDCouplingSkyLineArray * >::iterator it;
+  MEDCouplingSkyLineArray * nullArray = 0;
+  std::map < std::pair <mcIdType,mcIdType>, MEDCouplingSkyLineArray * >::iterator it;
   it = _entity_corresp.insert
     ( std::make_pair( std::make_pair(localEntity,distantEntity), nullArray )).first;
-  if ( it->second != nullArray ) delete it->second;
+  if ( it->second != nullArray ) it->second->decrRef();
   it->second = array;
 }