From 7f15e88ba9a92c0f2001262da2e4b72a954557f1 Mon Sep 17 00:00:00 2001 From: abn Date: Fri, 17 Feb 2017 14:44:54 +0100 Subject: [PATCH] Preparing skyline: now a RefCount object. --- src/MEDCoupling/MEDCouplingSkyLineArray.cxx | 60 +++++---- src/MEDCoupling/MEDCouplingSkyLineArray.hxx | 42 +++++-- src/MEDCoupling/MEDCouplingUMesh.cxx | 4 +- src/MEDCoupling/MEDCouplingUMesh.hxx | 2 +- src/MEDCoupling_Swig/MEDCouplingCommon.i | 44 ++++--- .../MEDPARTITIONER_ConnectZone.cxx | 50 ++++---- .../MEDPARTITIONER_ConnectZone.hxx | 33 ++--- src/MEDPartitioner/MEDPARTITIONER_Graph.cxx | 64 ++++++---- src/MEDPartitioner/MEDPARTITIONER_Graph.hxx | 17 +-- .../MEDPARTITIONER_MEDPartitioner.cxx | 3 +- .../MEDPARTITIONER_MeshCollection.cxx | 8 +- .../MEDPARTITIONER_MeshCollectionDriver.cxx | 4 +- .../MEDPARTITIONER_MetisGraph.cxx | 4 +- .../MEDPARTITIONER_ParMetisGraph.cxx | 4 +- .../MEDPARTITIONER_ParallelTopology.cxx | 2 +- .../MEDPARTITIONER_ScotchGraph.cxx | 4 +- .../MEDPARTITIONER_UserGraph.cxx | 2 +- src/MEDPartitioner_Swig/MEDPartitioner.i | 119 ------------------ src/MEDPartitioner_Swig/MEDPartitionerTest.py | 5 +- 19 files changed, 211 insertions(+), 260 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx index c17e7b26e..d525524f1 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.cxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.cxx @@ -24,43 +24,61 @@ using namespace MEDCoupling; MEDCouplingSkyLineArray::MEDCouplingSkyLineArray(): - _index( DataArrayInt::New() ), _value( DataArrayInt::New() ) + _index( DataArrayInt::New() ), _values( DataArrayInt::New() ), _sub_values( DataArrayInt::New() ) { } -MEDCouplingSkyLineArray::MEDCouplingSkyLineArray(const MEDCouplingSkyLineArray &myArray) +MEDCouplingSkyLineArray::~MEDCouplingSkyLineArray() { - _index=myArray._index; - _value=myArray._value; } -MEDCouplingSkyLineArray::~MEDCouplingSkyLineArray() +MEDCouplingSkyLineArray* MEDCouplingSkyLineArray::New() +{ + return new MEDCouplingSkyLineArray(); +} + +MEDCouplingSkyLineArray* MEDCouplingSkyLineArray::New( const std::vector& index, + const std::vector& value ) { + MEDCouplingSkyLineArray * ret = new MEDCouplingSkyLineArray(); + ret->_index->reserve( index.size() ); + ret->_index->insertAtTheEnd( index.begin(), index.end() ); + ret->_values->reserve( value.size() ); + ret->_values->insertAtTheEnd( value.begin(), value.end() ); + return ret; } -MEDCouplingSkyLineArray::MEDCouplingSkyLineArray(DataArrayInt* index, DataArrayInt* value) +MEDCouplingSkyLineArray* MEDCouplingSkyLineArray::New( DataArrayInt* index, DataArrayInt* value ) { - set( index, value ); + MEDCouplingSkyLineArray* ret = new MEDCouplingSkyLineArray(); + ret->set(index, value); + return ret; } -MEDCouplingSkyLineArray::MEDCouplingSkyLineArray( const std::vector& index, - const std::vector& value ): - _index( DataArrayInt::New() ), _value( DataArrayInt::New() ) + +std::size_t MEDCouplingSkyLineArray::getHeapMemorySizeWithoutChildren() const { - _index->reserve( index.size() ); - _index->insertAtTheEnd( index.begin(), index.end() ); - _value->reserve( value.size() ); - _value->insertAtTheEnd( value.begin(), value.end() ); + return _index->getHeapMemorySizeWithoutChildren()+_values->getHeapMemorySizeWithoutChildren()+_sub_values->getHeapMemorySizeWithoutChildren(); } +std::vector MEDCouplingSkyLineArray::getDirectChildrenWithNull() const +{ + std::vector ret; + ret.push_back(_index); + ret.push_back(_values); + ret.push_back(_sub_values); + return ret; +} + + void MEDCouplingSkyLineArray::set( DataArrayInt* index, DataArrayInt* value ) { _index=index; - _value=value; + _values=value; if ( (DataArrayInt*)_index ) _index->incrRef(); else _index = DataArrayInt::New(); - if ( (DataArrayInt*)_value ) _value->incrRef(); - else _value = DataArrayInt::New(); + if ( (DataArrayInt*)_values ) _values->incrRef(); + else _values = DataArrayInt::New(); } DataArrayInt* MEDCouplingSkyLineArray::getIndexArray() const @@ -68,9 +86,9 @@ DataArrayInt* MEDCouplingSkyLineArray::getIndexArray() const return ((MEDCouplingSkyLineArray*)this)->_index; } -DataArrayInt* MEDCouplingSkyLineArray::getValueArray() const +DataArrayInt* MEDCouplingSkyLineArray::getValuesArray() const { - return ((MEDCouplingSkyLineArray*)this)->_value; + return ((MEDCouplingSkyLineArray*)this)->_values; } std::string MEDCouplingSkyLineArray::simpleRepr() const @@ -87,9 +105,9 @@ std::string MEDCouplingSkyLineArray::simpleRepr() const oss << std::endl; oss << " Value:" << std::endl; oss << " "; - const int * v = _value->begin(); + const int * v = _values->begin(); int cnt = 0; - for ( i = _index->begin(); v != _value->end(); ++v, ++cnt ) + for ( i = _index->begin(); v != _values->end(); ++v, ++cnt ) { if ( cnt == *i ) { diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx index 632641759..8c3a2f125 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx @@ -23,34 +23,52 @@ #include "MEDCoupling.hxx" #include "MEDCouplingMemArray.hxx" #include "MCAuto.hxx" +#include "NormalizedGeometricTypes" #include namespace MEDCoupling { - class MEDCOUPLING_EXPORT MEDCouplingSkyLineArray + /**! + * Class allowing the easy manipulation of the indexed array format, where the first array is a set of offsets to + * be used in the second array, to extract packs of values. + * + * This class allows to pursuie this logic up to 3 levels, i.e. the first array points to packs in the second, which + * itself points to identifiers in the third array. + * + * This particularly useful for connectivity of pure polygonal/polyhedral meshes. + */ + class MEDCOUPLING_EXPORT MEDCouplingSkyLineArray : public RefCountObject { - private: - MCAuto _index; - MCAuto _value; public: - MEDCouplingSkyLineArray(); - MEDCouplingSkyLineArray( const MEDCouplingSkyLineArray &myArray ); - MEDCouplingSkyLineArray( const std::vector& index, const std::vector& value ); - MEDCouplingSkyLineArray( DataArrayInt* index, DataArrayInt* value ); - ~MEDCouplingSkyLineArray(); + static MEDCouplingSkyLineArray * New(); + static MEDCouplingSkyLineArray * New( const std::vector& index, const std::vector& value); + static MEDCouplingSkyLineArray * New( DataArrayInt* index, DataArrayInt* value ); + + std::size_t getHeapMemorySizeWithoutChildren() const; + std::vector getDirectChildrenWithNull() const; void set( DataArrayInt* index, DataArrayInt* value ); int getNumberOf() const { return _index->getNbOfElems()-1; } - int getLength() const { return _value->getNbOfElems(); } + int getLength() const { return _values->getNbOfElems(); } const int* getIndex() const { return _index->begin(); } - const int* getValue() const { return _value->begin(); } + const int* getValues() const { return _values->begin(); } DataArrayInt* getIndexArray() const; - DataArrayInt* getValueArray() const; + DataArrayInt* getValuesArray() const; std::string simpleRepr() const; + +// replaceWithPackFromOther() + + private: + MEDCouplingSkyLineArray(); + ~MEDCouplingSkyLineArray(); + + MCAuto _index; + MCAuto _values; + MCAuto _sub_values; }; } # endif diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 907b00d6f..31d99c69d 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -7175,7 +7175,7 @@ DataArrayInt *MEDCouplingUMesh::buildUnionOf3DMesh() const * means 6 arcs (0,1), (0,2), (0,3), (1,2), (1,3), (2,3) * Arcs are not doubled but reflexive (1,1) arcs are present for each cell */ -MEDCouplingSkyLineArray *MEDCouplingUMesh::generateGraph() const +MEDCouplingSkyLineArray* MEDCouplingUMesh::generateGraph() const { checkConnectivityFullyDefined(); @@ -7237,7 +7237,7 @@ MEDCouplingSkyLineArray *MEDCouplingUMesh::generateGraph() const cell2cell_index[icell+1]=cell2cell_index[icell]+cell2cell_index[icell+1]; //filling up index and value to create skylinearray structure - MEDCouplingSkyLineArray* array=new MEDCouplingSkyLineArray(cell2cell_index,cell2cell); + MEDCouplingSkyLineArray * array(MEDCouplingSkyLineArray::New(cell2cell_index,cell2cell)); return array; } diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 7604a30c8..1a3e947e0 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -277,7 +277,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayInt *buildUnionOf2DMesh() const; MEDCOUPLING_EXPORT DataArrayInt *buildUnionOf3DMesh() const; MEDCOUPLING_EXPORT DataArrayInt *orderConsecutiveCells1D() const; - MEDCOUPLING_EXPORT MEDCouplingSkyLineArray *generateGraph() const; + MEDCOUPLING_EXPORT MEDCouplingSkyLineArray* generateGraph() const; private: // all private methods are impl in MEDCouplingUMesh_internal.cxx MEDCouplingUMesh(); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index a8036fbba..90c5511a5 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -450,6 +450,7 @@ using namespace INTERP_KERNEL; %feature("unref") PartDefinition "$this->decrRef();" %feature("unref") DataArrayPartDefinition "$this->decrRef();" %feature("unref") SlicePartDefinition "$this->decrRef();" +%feature("unref") MEDCouplingSkyLineArray "$this->decrRef();" %rename(assign) *::operator=; %ignore MEDCoupling::MEDCouplingGaussLocalization::pushTinySerializationIntInfo; @@ -1186,24 +1187,35 @@ namespace MEDCoupling class MEDCouplingSkyLineArray { - public: - MEDCouplingSkyLineArray(); - MEDCouplingSkyLineArray( const MEDCouplingSkyLineArray &myArray ); - MEDCouplingSkyLineArray( DataArrayInt* index, DataArrayInt* value ); - MEDCouplingSkyLineArray( const std::vector& index, const std::vector& value ); - + public: void set( DataArrayInt* index, DataArrayInt* value ); int getNumberOf() const; int getLength() const; DataArrayInt* getIndexArray() const; - DataArrayInt* getValueArray() const; - %extend - { - std::string __str__() const throw(INTERP_KERNEL::Exception) - { - return self->simpleRepr(); - } - } + DataArrayInt* getValuesArray() const; + %extend + { + MEDCouplingSkyLineArray() throw(INTERP_KERNEL::Exception) + { + return MEDCouplingSkyLineArray::New(); + } + + MEDCouplingSkyLineArray( const std::vector& index, const std::vector& value) throw(INTERP_KERNEL::Exception) + { + return MEDCouplingSkyLineArray::New(index, value); + } + + MEDCouplingSkyLineArray( DataArrayInt* index, DataArrayInt* value ) throw(INTERP_KERNEL::Exception) + { + return MEDCouplingSkyLineArray::New(index, value); + } + + std::string __str__() const throw(INTERP_KERNEL::Exception) + { + return self->simpleRepr(); + } + + } }; } @@ -1848,10 +1860,10 @@ namespace MEDCoupling DataArrayInt *findAndCorrectBadOriented3DExtrudedCells() throw(INTERP_KERNEL::Exception); DataArrayInt *findAndCorrectBadOriented3DCells() throw(INTERP_KERNEL::Exception); MEDCoupling::MEDCoupling1GTUMesh *convertIntoSingleGeoTypeMesh() const throw(INTERP_KERNEL::Exception); + MEDCouplingSkyLineArray *generateGraph() const throw(INTERP_KERNEL::Exception); DataArrayInt *convertNodalConnectivityToStaticGeoTypeMesh() const throw(INTERP_KERNEL::Exception); DataArrayInt *buildUnionOf2DMesh() const throw(INTERP_KERNEL::Exception); DataArrayInt *buildUnionOf3DMesh() const throw(INTERP_KERNEL::Exception); - MEDCouplingSkyLineArray *generateGraph() const throw(INTERP_KERNEL::Exception); DataArrayInt *orderConsecutiveCells1D() const throw(INTERP_KERNEL::Exception); DataArrayDouble *getBoundingBoxForBBTreeFast() const throw(INTERP_KERNEL::Exception); DataArrayDouble *getBoundingBoxForBBTree2DQuadratic(double arcDetEps=1e-12) const throw(INTERP_KERNEL::Exception); @@ -2880,7 +2892,7 @@ namespace MEDCoupling default: throw INTERP_KERNEL::Exception("MEDCouplingUMesh::convertToPolyTypes : unexpected input array type recognized !"); } - } + } } void convertAllToPoly(); void convertExtrudedPolyhedra() throw(INTERP_KERNEL::Exception); diff --git a/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.cxx b/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.cxx index 18f43a74d..3a1c9ce67 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.cxx @@ -32,16 +32,16 @@ MEDPARTITIONER::ConnectZone::ConnectZone(): ,_distant_domain_number(0) ,_node_corresp(0) ,_face_corresp(0) + ,_local_mesh(0) + ,_distant_mesh(0) { } MEDPARTITIONER::ConnectZone::~ConnectZone() { - delete _node_corresp; - delete _face_corresp; for(std::map < std::pair ,MEDCouplingSkyLineArray * >::iterator iter=_entity_corresp.begin(); iter!=_entity_corresp.end();iter++) { - delete iter->second; + iter->second->decrRef(); } } @@ -53,6 +53,8 @@ MEDPARTITIONER::ConnectZone::ConnectZone(const ConnectZone & myConnectZone): ,_node_corresp(myConnectZone._node_corresp) ,_face_corresp(myConnectZone._face_corresp) ,_entity_corresp(myConnectZone._entity_corresp) + ,_local_mesh(0) + ,_distant_mesh(0) { } @@ -76,12 +78,12 @@ 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; } @@ -104,7 +106,7 @@ const int *MEDPARTITIONER::ConnectZone::getNodeCorrespIndex() const const int *MEDPARTITIONER::ConnectZone::getNodeCorrespValue() const { - return _node_corresp->getValue(); + return _node_corresp->getValues(); } int MEDPARTITIONER::ConnectZone::getNodeNumber() const @@ -112,9 +114,9 @@ int 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 @@ -124,7 +126,7 @@ const int *MEDPARTITIONER::ConnectZone::getFaceCorrespIndex() const const int *MEDPARTITIONER::ConnectZone::getFaceCorrespValue() const { - return _face_corresp->getValue(); + return _face_corresp->getValues(); } int MEDPARTITIONER::ConnectZone::getFaceNumber() const @@ -132,7 +134,7 @@ int MEDPARTITIONER::ConnectZone::getFaceNumber() const return _face_corresp->getNumberOf(); } -const MEDCoupling::MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getFaceCorresp() const +const MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getFaceCorresp() const { return _face_corresp; } @@ -158,7 +160,7 @@ const int *MEDPARTITIONER::ConnectZone::getEntityCorrespValue(int localEntity, 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; } @@ -189,7 +191,7 @@ int MEDPARTITIONER::ConnectZone::getEntityCorrespLength(int localEntity, return 0; } -const MEDCoupling::MEDCouplingSkyLineArray * +const MEDCouplingSkyLineArray * MEDPARTITIONER::ConnectZone::getEntityCorresp(int localEntity, int distantEntity) const { typedef std::map, MEDCouplingSkyLineArray*>::const_iterator map_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; } @@ -265,13 +267,13 @@ void MEDPARTITIONER::ConnectZone::setNodeCorresp(const int * nodeCorresp, int nb 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 arr(array); + _node_corresp = arr; } /*! transforms an int array containing @@ -293,13 +295,13 @@ void MEDPARTITIONER::ConnectZone::setFaceCorresp(const int * faceCorresp, int nb 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 arr (array); + _face_corresp = arr; } /*! transforms an int array containing @@ -324,16 +326,16 @@ void MEDPARTITIONER::ConnectZone::setEntityCorresp(int localEntity, int distantE 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, MEDCouplingSkyLineArray *array) { - MEDCoupling::MEDCouplingSkyLineArray * nullArray = 0; - std::map < std::pair , MEDCoupling::MEDCouplingSkyLineArray * >::iterator it; + MEDCouplingSkyLineArray * nullArray = 0; + std::map < std::pair , 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; } diff --git a/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.hxx b/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.hxx index acfc6a2e1..0c51ac8e2 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_ConnectZone.hxx @@ -21,6 +21,7 @@ #define __MEDPARTITIONER_CONNECTZONE_HXX__ #include "MEDPARTITIONER.hxx" +#include "MCAuto.hxx" namespace MEDCoupling { @@ -32,6 +33,8 @@ namespace MEDCoupling #include #include +using namespace MEDCoupling; + namespace MEDPARTITIONER { class MEDPARTITIONER_EXPORT ConnectZone @@ -45,18 +48,18 @@ namespace MEDPARTITIONER std::string getDescription() const ; int getDistantDomainNumber() const ; int getLocalDomainNumber() const ; - MEDCoupling::MEDCouplingUMesh *getLocalMesh() const ; - MEDCoupling::MEDCouplingUMesh *getDistantMesh() const ; + MEDCouplingUMesh *getLocalMesh() const ; + MEDCouplingUMesh *getDistantMesh() const ; bool isEntityCorrespPresent(int localEntity,int distantEntity) const; const int *getNodeCorrespIndex() const; const int *getNodeCorrespValue() const; int getNodeNumber() const; - const MEDCoupling::MEDCouplingSkyLineArray * getNodeCorresp() const; + const MEDCouplingSkyLineArray * getNodeCorresp() const; const int *getFaceCorrespIndex() const; const int *getFaceCorrespValue() const; int getFaceNumber() const; - const MEDCoupling::MEDCouplingSkyLineArray * getFaceCorresp() const; + const MEDCouplingSkyLineArray * getFaceCorresp() const; const int *getEntityCorrespIndex(int localEntity, int distantEntity) const; const int *getEntityCorrespValue(int localEntity, @@ -65,7 +68,7 @@ namespace MEDPARTITIONER int distantEntity) const; int getEntityCorrespLength(int localEntity, int distantEntity) const; - const MEDCoupling::MEDCouplingSkyLineArray * getEntityCorresp(int localEntity, + const MEDCouplingSkyLineArray * getEntityCorresp(int localEntity, int distantEntity) const; std::vector< std::pair< int,int > > getEntities() const; @@ -73,30 +76,30 @@ namespace MEDPARTITIONER void setDescription(const std::string& description) ; void setDistantDomainNumber(int distantDomainNumber) ; void setLocalDomainNumber(int distantDomainNumber) ; - void setLocalMesh(MEDCoupling::MEDCouplingUMesh * localMesh) ; - void setDistantMesh(MEDCoupling::MEDCouplingUMesh * distantMesh) ; + void setLocalMesh(MEDCouplingUMesh * localMesh) ; + void setDistantMesh(MEDCouplingUMesh * distantMesh) ; void setNodeCorresp(const int * nodeCorresp, int nbnode); - void setNodeCorresp(MEDCoupling::MEDCouplingSkyLineArray* array); + void setNodeCorresp(MEDCouplingSkyLineArray* array); void setFaceCorresp(const int * faceCorresp, int nbface); - void setFaceCorresp(MEDCoupling::MEDCouplingSkyLineArray* array); + void setFaceCorresp(MEDCouplingSkyLineArray* array); void setEntityCorresp(int localEntity, int distantEntity, const int * entityCorresp, int nbentity); void setEntityCorresp(int localEntity, int distantEntity, - MEDCoupling::MEDCouplingSkyLineArray *array); + MEDCouplingSkyLineArray *array); private : std::string _name; std::string _description; int _local_domain_number; int _distant_domain_number; - MEDCoupling::MEDCouplingUMesh * _local_mesh; - MEDCoupling::MEDCouplingUMesh * _distant_mesh; + MEDCouplingUMesh * _local_mesh; + MEDCouplingUMesh * _distant_mesh; - MEDCoupling::MEDCouplingSkyLineArray * _node_corresp; - MEDCoupling::MEDCouplingSkyLineArray * _face_corresp; + MCAuto _node_corresp; + MCAuto _face_corresp; - std::map < std::pair , MEDCoupling::MEDCouplingSkyLineArray * > _entity_corresp; + std::map < std::pair , MEDCouplingSkyLineArray * > _entity_corresp; }; } # endif diff --git a/src/MEDPartitioner/MEDPARTITIONER_Graph.cxx b/src/MEDPartitioner/MEDPARTITIONER_Graph.cxx index ef0914168..8037cf694 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_Graph.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_Graph.cxx @@ -23,34 +23,44 @@ #include -MEDPARTITIONER::Graph::Graph(MEDCoupling::MEDCouplingSkyLineArray *array, int *edgeweight):_graph(array),_partition(0),_edge_weight(edgeweight),_cell_weight(0) +namespace MEDPARTITIONER { -} + Graph::Graph(): + _graph(0),_partition(0), + _edge_weight(0),_cell_weight(0) + { + } -MEDPARTITIONER::Graph::~Graph() -{ - delete _partition; - delete _graph; -} + Graph::Graph(MEDCoupling::MEDCouplingSkyLineArray *array, int *edgeweight): + _graph(array),_partition(0), + _edge_weight(edgeweight),_cell_weight(0) + { + } -int MEDPARTITIONER::Graph::nbDomains() const -{ - std::set domains; - if ( _partition ) - if ( MEDCoupling::DataArrayInt* array = _partition->getValueArray() ) - { - for ( const int * dom = array->begin(); dom != array->end(); ++dom ) - domains.insert( *dom ); - } - return domains.size(); -} - -const int *MEDPARTITIONER::Graph::getPart() const -{ - return _partition->getValue(); -} + Graph::~Graph() + { + } -int MEDPARTITIONER::Graph::nbVertices() const -{ - return _graph->getNumberOf(); -} + int Graph::nbDomains() const + { + std::set domains; + if ( _partition.isNotNull() ) + if ( MEDCoupling::DataArrayInt* array = _partition->getValuesArray() ) + { + for ( const int * dom = array->begin(); dom != array->end(); ++dom ) + domains.insert( *dom ); + } + return domains.size(); + } + + const int *Graph::getPart() const + { + return _partition->getValues(); + } + + int Graph::nbVertices() const + { + return _graph->getNumberOf(); + } + +}; diff --git a/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx b/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx index 4eb14f9b1..abf927310 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx @@ -21,6 +21,7 @@ #define __MEDPARTITIONER_GRAPH_HXX__ #include "MEDPARTITIONER.hxx" +#include "MCAuto.hxx" #include @@ -29,6 +30,8 @@ namespace MEDCoupling class MEDCouplingSkyLineArray; } +using namespace MEDCoupling; + namespace MEDPARTITIONER { class ParaDomainSelector; @@ -37,9 +40,9 @@ namespace MEDPARTITIONER public: typedef enum {METIS,SCOTCH} splitter_type; - Graph(){}; - //creates a graph from a SKYLINEARRAY - Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, int* edgeweight=0); + Graph(); + //creates a graph from a SKYLINEARRAY- WARNING!! Graph takes ownership of the array. + Graph(MEDCouplingSkyLineArray* graph, int* edgeweight=0); virtual ~Graph(); void setEdgesWeights(int *edgeweight) { _edge_weight=edgeweight; } @@ -57,12 +60,12 @@ namespace MEDPARTITIONER // returns nb of domains in _partition int nbDomains() const; - const MEDCoupling::MEDCouplingSkyLineArray *getGraph() const { return _graph; } - const MEDCoupling::MEDCouplingSkyLineArray *getPartition() const { return _partition; } + const MEDCouplingSkyLineArray *getGraph() const { return (const MEDCouplingSkyLineArray*)_graph; } + const MEDCouplingSkyLineArray *getPartition() const { return (const MEDCouplingSkyLineArray*)_partition; } protected: - MEDCoupling::MEDCouplingSkyLineArray* _graph; - MEDCoupling::MEDCouplingSkyLineArray* _partition; + MCAuto _graph; + MCAuto _partition; int* _edge_weight; int* _cell_weight; }; diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx index a07b56200..6ea40a0e6 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx @@ -140,7 +140,8 @@ MEDCoupling::MEDFileData* MEDPARTITIONER::MEDPartitioner::getMEDFileData() MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight) { MEDPARTITIONER::Graph* cellGraph=0; - MEDCoupling::MEDCouplingSkyLineArray* arr = new MEDCoupling::MEDCouplingSkyLineArray(graph->getIndexArray(), graph->getValueArray()); + // will be destroyed by XXXGraph class: + MEDCoupling::MEDCouplingSkyLineArray* arr = MEDCoupling::MEDCouplingSkyLineArray::New(graph->getIndexArray(), graph->getValuesArray()); switch (split) { case Graph::METIS: diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx index 27a7bb47a..386e097b8 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx @@ -1142,7 +1142,7 @@ void MEDPARTITIONER::MeshCollection::buildConnectZones( const NodeMapping& nodeM // separate ids of two domains const MEDCoupling::MEDCouplingSkyLineArray *corrArray = cz->getEntityCorresp( 0, 0 ); - const DataArrayInt* ids12 = corrArray->getValueArray(); + const DataArrayInt* ids12 = corrArray->getValuesArray(); MCAuto ids1, ids2, ids12Sorted; ids1 = ids12->selectByTupleIdSafeSlice( 0, corrArray->getLength(), 2 ); ids2 = ids12->selectByTupleIdSafeSlice( 1, corrArray->getLength(), 2 ); @@ -1252,7 +1252,7 @@ void MEDPARTITIONER::MeshCollection::buildConnectZones( const NodeMapping& nodeM // separate ids of two domains const MEDCoupling::MEDCouplingSkyLineArray *corrArray = cz->getNodeCorresp(); - const DataArrayInt *ids12 = corrArray->getValueArray(); + const DataArrayInt *ids12 = corrArray->getValuesArray(); MCAuto ids1, ids2, ids12Sorted; ids1 = ids12->selectByTupleIdSafeSlice( 0, corrArray->getLength(), 2 ); ids2 = ids12->selectByTupleIdSafeSlice( 1, corrArray->getLength(), 2 ); @@ -1922,7 +1922,7 @@ void MEDPARTITIONER::MeshCollection::buildCellGraph(MEDCoupling::MEDCouplingSkyL vector value; vector index(1,0); - array=new MEDCoupling::MEDCouplingSkyLineArray(index,value); + array = MEDCoupling::MEDCouplingSkyLineArray::New(index,value); return; } array=mesh->generateGraph(); @@ -2101,7 +2101,7 @@ void MEDPARTITIONER::MeshCollection::buildParallelCellGraph(MEDCoupling::MEDCoup } } - array=new MEDCoupling::MEDCouplingSkyLineArray(index,value); + array=MEDCoupling::MEDCouplingSkyLineArray::New(index,value); if (MyGlobals::_Verbose>100) { diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx index 7289b82ff..aa95be87c 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx @@ -300,7 +300,7 @@ MEDCoupling::MEDFileMesh* MeshCollectionDriver::getMesh(int idomain) const if ( nodeCorr ) { MCAuto< MEDFileJointCorrespondence > - corr = MEDFileJointCorrespondence::New( nodeCorr->getValueArray() ); + corr = MEDFileJointCorrespondence::New( nodeCorr->getValuesArray() ); j1st->pushCorrespondence( corr ); } @@ -315,7 +315,7 @@ MEDCoupling::MEDFileMesh* MeshCollectionDriver::getMesh(int idomain) const t1 = INTERP_KERNEL::NormalizedCellType( types[it].first ); t2 = INTERP_KERNEL::NormalizedCellType( types[it].second ); MCAuto< MEDFileJointCorrespondence> - corr = MEDFileJointCorrespondence::New( cellCorr->getValueArray(), t1, t2 ); + corr = MEDFileJointCorrespondence::New( cellCorr->getValuesArray(), t1, t2 ); j1st->pushCorrespondence( corr ); } } diff --git a/src/MEDPartitioner/MEDPARTITIONER_MetisGraph.cxx b/src/MEDPartitioner/MEDPARTITIONER_MetisGraph.cxx index 0a91cb9a2..ff67136bf 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MetisGraph.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MetisGraph.cxx @@ -58,7 +58,7 @@ void METISGraph::partGraph(int ndomain, int n=_graph->getNumberOf(); //graph int * xadj=const_cast(_graph->getIndex()); - int * adjncy=const_cast(_graph->getValue()); + int * adjncy=const_cast(_graph->getValues()); //constraints int * vwgt=_cell_weight; int * adjwgt=_edge_weight; @@ -113,7 +113,7 @@ void METISGraph::partGraph(int ndomain, //creating a skylinearray with no copy of the index and partition array //the fifth argument true specifies that only the pointers are passed //to the object - _partition = new MEDCoupling::MEDCouplingSkyLineArray(index,value); + _partition = MEDCoupling::MEDCouplingSkyLineArray::New(index,value); #endif } diff --git a/src/MEDPartitioner/MEDPARTITIONER_ParMetisGraph.cxx b/src/MEDPartitioner/MEDPARTITIONER_ParMetisGraph.cxx index 907d79322..8ff1f85fb 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_ParMetisGraph.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_ParMetisGraph.cxx @@ -62,7 +62,7 @@ void ParMETISGraph::partGraph(int ndomain, int n=_graph->getNumberOf(); //graph int * xadj=const_cast(_graph->getIndex()); - int * adjncy=const_cast(_graph->getValue()); + int * adjncy=const_cast(_graph->getValues()); //constraints int * vwgt=_cell_weight; int * adjwgt=_edge_weight; @@ -137,7 +137,7 @@ void ParMETISGraph::partGraph(int ndomain, //the fifth argument true specifies that only the pointers are passed //to the object - _partition = new MEDCoupling::MEDCouplingSkyLineArray(index,value); + _partition = MEDCoupling::MEDCouplingSkyLineArray::New(index,value); #endif } diff --git a/src/MEDPartitioner/MEDPARTITIONER_ParallelTopology.cxx b/src/MEDPartitioner/MEDPARTITIONER_ParallelTopology.cxx index cc5eec318..6ba589222 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_ParallelTopology.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_ParallelTopology.cxx @@ -331,7 +331,7 @@ ParallelTopology::ParallelTopology(Graph* graph, Topology* oldTopology, int nb_d } const MEDCoupling::MEDCouplingSkyLineArray* skylinegraph = graph->getGraph(); const int* index = skylinegraph->getIndex(); - const int* value = skylinegraph->getValue(); + const int* value = skylinegraph->getValues(); const int nbCells = skylinegraph->getNumberOf(); for ( int iGlob = 0; iGlob < nbCells; ++iGlob ) diff --git a/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.cxx b/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.cxx index 73b4c9584..a0d4686bd 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_ScotchGraph.cxx @@ -56,7 +56,7 @@ void SCOTCHGraph::partGraph(int ndomain, const std::string& options_string, Para int n = _graph->getNumberOf(); //graph int * xadj=const_cast(_graph->getIndex()); - int * adjncy=const_cast(_graph->getValue()); + int * adjncy=const_cast(_graph->getValues()); //ndomain int nparts=ndomain; @@ -112,6 +112,6 @@ void SCOTCHGraph::partGraph(int ndomain, const std::string& options_string, Para //creating a skylinearray with no copy of the index and partition array //the fifth argument true specifies that only the pointers are passed //to the object - _partition = new MEDCoupling::MEDCouplingSkyLineArray(index,value); + _partition = MEDCoupling::MEDCouplingSkyLineArray::New(index,value); #endif } diff --git a/src/MEDPartitioner/MEDPARTITIONER_UserGraph.cxx b/src/MEDPartitioner/MEDPARTITIONER_UserGraph.cxx index 24ecebff1..364f7e9f6 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_UserGraph.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_UserGraph.cxx @@ -44,7 +44,7 @@ UserGraph::UserGraph(MEDCoupling::MEDCouplingSkyLineArray *array, const int *par value[i]=partition[i]; } - _partition = new MEDCoupling::MEDCouplingSkyLineArray(index,value); + _partition = MEDCoupling::MEDCouplingSkyLineArray::New(index,value); } diff --git a/src/MEDPartitioner_Swig/MEDPartitioner.i b/src/MEDPartitioner_Swig/MEDPartitioner.i index 8257cc5b2..4bd1dbc4f 100644 --- a/src/MEDPartitioner_Swig/MEDPartitioner.i +++ b/src/MEDPartitioner_Swig/MEDPartitioner.i @@ -19,122 +19,3 @@ %include "MEDPartitionerCommon.i" - -// %pythoncode %{ -// def MEDCouplingDataArrayDoublenew(cls,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayDouble____new___(cls,args) -// def MEDCouplingDataArrayDoubleIadd(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayDouble____iadd___(self, self, *args) -// def MEDCouplingDataArrayDoubleIsub(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayDouble____isub___(self, self, *args) -// def MEDCouplingDataArrayDoubleImul(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayDouble____imul___(self, self, *args) -// def MEDCouplingDataArrayDoubleIdiv(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayDouble____idiv___(self, self, *args) -// def MEDCouplingDataArrayDoubleIpow(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayDouble____ipow___(self, self, *args) -// def MEDCouplingDataArrayIntnew(cls,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayInt____new___(cls,args) -// def MEDCouplingDataArrayIntIadd(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayInt____iadd___(self, self, *args) -// def MEDCouplingDataArrayIntIsub(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayInt____isub___(self, self, *args) -// def MEDCouplingDataArrayIntImul(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayInt____imul___(self, self, *args) -// def MEDCouplingDataArrayIntIdiv(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayInt____idiv___(self, self, *args) -// def MEDCouplingDataArrayIntImod(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayInt____imod___(self, self, *args) -// def MEDCouplingDataArrayIntIpow(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayInt____ipow___(self, self, *args) -// def MEDCouplingDataArrayDoubleTupleIadd(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayDoubleTuple____iadd___(self, self, *args) -// def MEDCouplingDataArrayDoubleTupleIsub(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayDoubleTuple____isub___(self, self, *args) -// def MEDCouplingDataArrayDoubleTupleImul(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayDoubleTuple____imul___(self, self, *args) -// def MEDCouplingDataArrayDoubleTupleIdiv(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayDoubleTuple____idiv___(self, self, *args) -// def MEDCouplingDataArrayIntTupleIadd(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayIntTuple____iadd___(self, self, *args) -// def MEDCouplingDataArrayIntTupleIsub(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayIntTuple____isub___(self, self, *args) -// def MEDCouplingDataArrayIntTupleImul(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayIntTuple____imul___(self, self, *args) -// def MEDCouplingDataArrayIntTupleIdiv(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayIntTuple____idiv___(self, self, *args) -// def MEDCouplingDataArrayIntTupleImod(self,*args): -// import _MEDPartitioner -// return _MEDPartitioner.DataArrayIntTuple____imod___(self, self, *args) -// %} - - -// %pythoncode %{ -// DataArrayDouble.__new__=classmethod(MEDCouplingDataArrayDoublenew) -// DataArrayDouble.__iadd__=MEDCouplingDataArrayDoubleIadd -// DataArrayDouble.__isub__=MEDCouplingDataArrayDoubleIsub -// DataArrayDouble.__imul__=MEDCouplingDataArrayDoubleImul -// DataArrayDouble.__idiv__=MEDCouplingDataArrayDoubleIdiv -// DataArrayDouble.__ipow__=MEDCouplingDataArrayDoubleIpow - -// DataArrayInt.__new__=classmethod(MEDCouplingDataArrayIntnew) -// DataArrayInt.__iadd__=MEDCouplingDataArrayIntIadd -// DataArrayInt.__isub__=MEDCouplingDataArrayIntIsub -// DataArrayInt.__imul__=MEDCouplingDataArrayIntImul -// DataArrayInt.__idiv__=MEDCouplingDataArrayIntIdiv -// DataArrayInt.__imod__=MEDCouplingDataArrayIntImod -// DataArrayInt.__ipow__=MEDCouplingDataArrayIntIpow - -// DataArrayDoubleTuple.__iadd__=MEDCouplingDataArrayDoubleTupleIadd -// DataArrayDoubleTuple.__isub__=MEDCouplingDataArrayDoubleTupleIsub -// DataArrayDoubleTuple.__imul__=MEDCouplingDataArrayDoubleTupleImul -// DataArrayDoubleTuple.__idiv__=MEDCouplingDataArrayDoubleTupleIdiv - -// DataArrayIntTuple.__iadd__=MEDCouplingDataArrayIntTupleIadd -// DataArrayIntTuple.__isub__=MEDCouplingDataArrayIntTupleIsub -// DataArrayIntTuple.__imul__=MEDCouplingDataArrayIntTupleImul -// DataArrayIntTuple.__idiv__=MEDCouplingDataArrayIntTupleIdiv -// DataArrayIntTuple.__imod__=MEDCouplingDataArrayIntTupleImod - -// del MEDCouplingDataArrayDoublenew -// del MEDCouplingDataArrayDoubleIadd -// del MEDCouplingDataArrayDoubleIsub -// del MEDCouplingDataArrayDoubleImul -// del MEDCouplingDataArrayDoubleIdiv -// del MEDCouplingDataArrayIntnew -// del MEDCouplingDataArrayIntIadd -// del MEDCouplingDataArrayIntIsub -// del MEDCouplingDataArrayIntImul -// del MEDCouplingDataArrayIntIdiv -// del MEDCouplingDataArrayIntImod -// del MEDCouplingDataArrayDoubleTupleIadd -// del MEDCouplingDataArrayDoubleTupleIsub -// del MEDCouplingDataArrayDoubleTupleImul -// del MEDCouplingDataArrayDoubleTupleIdiv -// del MEDCouplingDataArrayIntTupleIadd -// del MEDCouplingDataArrayIntTupleIsub -// del MEDCouplingDataArrayIntTupleImul -// del MEDCouplingDataArrayIntTupleIdiv -// del MEDCouplingDataArrayIntTupleImod -// %} diff --git a/src/MEDPartitioner_Swig/MEDPartitionerTest.py b/src/MEDPartitioner_Swig/MEDPartitionerTest.py index 41333adcd..030759f2d 100644 --- a/src/MEDPartitioner_Swig/MEDPartitionerTest.py +++ b/src/MEDPartitioner_Swig/MEDPartitionerTest.py @@ -102,4 +102,7 @@ class MEDPartitionerTest(unittest.TestCase): self.assertTrue(isinstance(p,MEDCouplingSkyLineArray)) self.assertTrue(part.nbVertices() > 0 ) pass -unittest.main() + +if __name__ == "__main__": + unittest.main() + -- 2.39.2