From a5f8a8347df9809e8c608434b25abc1dc015280c Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 27 May 2015 22:22:02 +0300 Subject: [PATCH] 0022875: memory leaks and wrong joints --- .../MEDPARTITIONER_MeshCollection.cxx | 14 +++++++---- .../MEDPARTITIONER_MeshCollection.hxx | 2 +- .../MEDPARTITIONER_MeshCollectionDriver.cxx | 24 ++++++++++++++----- ...RTITIONER_MeshCollectionMedAsciiDriver.cxx | 6 ++--- ...PARTITIONER_MeshCollectionMedXmlDriver.cxx | 2 +- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx index 1dd9950c2..7643a53f0 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx @@ -1117,6 +1117,7 @@ void MEDPARTITIONER::MeshCollection::buildConnectZones( const NodeMapping& nodeM cz->setName( "Nodal Connect Zone defined by MEDPARTITIONER" ); cz->setLocalDomainNumber ( idomain ); cz->setDistantDomainNumber( idomainNear ); + czVec.push_back(cz); } cz->setNodeCorresp( &corresp[0], corresp.size()/2 ); @@ -1882,19 +1883,22 @@ MEDPARTITIONER::Topology* MEDPARTITIONER::MeshCollection::getTopology() const return _topology; } -void MEDPARTITIONER::MeshCollection::setTopology(Topology* topo) +void MEDPARTITIONER::MeshCollection::setTopology(Topology* topo, bool takeOwneship) { if (_topology!=0) { throw INTERP_KERNEL::Exception("topology is already set"); } else - _topology = topo; + { + _topology = topo; + _owns_topology = takeOwneship; + } } -/*! Method creating the cell graph in serial mode - * - * \param array returns the pointer to the structure that contains the graph +/*! Method creating the cell graph in serial mode + * + * \param array returns the pointer to the structure that contains the graph * \param edgeweight returns the pointer to the table that contains the edgeweights * (only used if indivisible regions are required) */ diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx index 8a04e0117..a4eec9a4c 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.hxx @@ -124,7 +124,7 @@ namespace MEDPARTITIONER ParaDomainSelector* getParaDomainSelector() const { return _domain_selector; } void setParaDomainSelector(ParaDomainSelector* pds) { _domain_selector = pds; } //setting a new topology - void setTopology(Topology* topology); + void setTopology(Topology* topology, bool takeOwneship); //getting/setting the name of the global mesh (as opposed //to the name of a subdomain \a nn, which is name_nn) diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx index 4eab9fc10..e23ed3ccb 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx @@ -82,7 +82,7 @@ int MeshCollectionDriver::readSeq(const char* filename, const char* meshname) (_collection->getCZ()).clear(); ParallelTopology* aPT = new ParallelTopology((_collection->getMesh())); - _collection->setTopology(aPT); + _collection->setTopology(aPT, true); _collection->setName(meshname); _collection->setDomainNames(meshname); return 0; @@ -106,7 +106,7 @@ void MeshCollectionDriver::readMEDFileData(const ParaMEDMEM::MEDFileData* fileda } ParallelTopology* aPT = new ParallelTopology(_collection->getMesh()); - _collection->setTopology(aPT); + _collection->setTopology(aPT, true); if ( nbDomains > 0 ) { _collection->setName( filedata->getMeshes()->getMeshAtPos(0)->getName() ); @@ -186,7 +186,7 @@ void MeshCollectionDriver::readSubdomain(int idomain) localInformation.push_back(str+"meshName="+meshname); MyGlobals::_General_Informations.push_back(SerializeFromVectorOfString(localInformation)); std::vector localFields=BrowseAllFieldsOnMesh(file, meshname, idomain); - if (localFields.size()>0) + if (localFields.size()>0) MyGlobals::_Field_Descriptions.push_back(SerializeFromVectorOfString(localFields)); } @@ -274,7 +274,19 @@ ParaMEDMEM::MEDFileMesh* MeshCollectionDriver::getMesh(int idomain) const for ( size_t i = 0; i < _collection->getCZ().size(); ++i ) { ConnectZone* cz = _collection->getCZ()[i]; - if ( !cz ) continue; + if ( !cz || + cz->getLocalDomainNumber() != idomain ) + continue; + { + std::ostringstream oss; + oss << "joint_" << cz->getDistantDomainNumber(); + cz->setName( oss.str() ); + } + { + std::ostringstream oss; + oss << "connect_zone_" << i; + cz->setDescription( oss.str() ); + } MEDCouplingAutoRefCountObjectPtr< MEDFileJoint> joint = MEDFileJoint::New( cz->getName(), finalMeshName, @@ -289,7 +301,7 @@ ParaMEDMEM::MEDFileMesh* MeshCollectionDriver::getMesh(int idomain) const if ( nodeCorr ) { MEDCouplingAutoRefCountObjectPtr< MEDFileJointCorrespondence > - corr = MEDFileJointCorrespondence::New( nodeCorr->getValueArray() ); + corr = MEDFileJointCorrespondence::New( nodeCorr->getValueArray() ); j1st->pushCorrespondence( corr ); } @@ -299,7 +311,7 @@ ParaMEDMEM::MEDFileMesh* MeshCollectionDriver::getMesh(int idomain) const { const MEDCouplingSkyLineArray * cellCorr = cz->getEntityCorresp( types[it].first, types[it].second ); - if ( cellCorr ) + if ( cellCorr && cellCorr->getNumberOf() > 0 ) { t1 = INTERP_KERNEL::NormalizedCellType( types[it].first ); t2 = INTERP_KERNEL::NormalizedCellType( types[it].second ); diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx index 12a42615c..ffccdb036 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionMedAsciiDriver.cxx @@ -72,9 +72,9 @@ int MeshCollectionMedAsciiDriver::read(ParaMEDMEM::MEDFileData* filedata) if ( (_collection->getMesh())[idomain] && (_collection->getMesh())[idomain]->getNumberOfNodes() > 0 ) _collection->setNonEmptyMesh(idomain); } - ParallelTopology* aPT = new ParallelTopology((_collection->getMesh()), cz, cellglobal, nodeglobal, faceglobal); - _collection->setTopology(aPT); //creation of topology from mesh and connect zones + ParallelTopology* aPT = new ParallelTopology((_collection->getMesh()), cz, cellglobal, nodeglobal, faceglobal); + _collection->setTopology(aPT,true); return 0; } @@ -150,7 +150,7 @@ int MeshCollectionMedAsciiDriver::read(const char* filename, ParaDomainSelector* //creation of topology from mesh and connect zones ParallelTopology* aPT = new ParallelTopology((_collection->getMesh()), (_collection->getCZ()), cellglobal, nodeglobal, faceglobal); - _collection->setTopology(aPT); + _collection->setTopology(aPT, true); for (int i=0; igatherNbOf(_collection->getMesh()); } - _collection->setTopology(aPT); + _collection->setTopology(aPT, true); _collection->setDomainNames(_collection->getName()); return 0; } -- 2.39.2