From d7b48514c9cb2c87baab6719fa7ddef157182c32 Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 29 May 2015 20:13:02 +0300 Subject: [PATCH] 22875: EDF 7690 MED: Creating joints with medpartitioner in the MEDCoupling API Final fixes --- src/MEDPartitioner/MEDPARTITIONER_Graph.cxx | 14 +++++++ src/MEDPartitioner/MEDPARTITIONER_Graph.hxx | 4 ++ .../MEDPARTITIONER_MEDPartitioner.cxx | 35 +++++++++++----- .../MEDPARTITIONER_MEDPartitioner.hxx | 8 ++-- .../MEDPARTITIONER_MeshCollection.cxx | 12 +++--- .../MEDPARTITIONER_MeshCollectionDriver.cxx | 4 +- .../MEDPartitionerCommon.i | 19 +++------ src/MEDPartitioner_Swig/MEDPartitionerTest.py | 40 ++++++++++++------- 8 files changed, 86 insertions(+), 50 deletions(-) diff --git a/src/MEDPartitioner/MEDPARTITIONER_Graph.cxx b/src/MEDPartitioner/MEDPARTITIONER_Graph.cxx index e4056c1f2..62a273a6a 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_Graph.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_Graph.cxx @@ -19,6 +19,8 @@ #include "MEDPARTITIONER_Graph.hxx" +#include + MEDPARTITIONER::Graph::Graph(ParaMEDMEM::MEDCouplingSkyLineArray *array, int *edgeweight):_graph(array),_partition(0),_edge_weight(edgeweight),_cell_weight(0) { } @@ -28,3 +30,15 @@ MEDPARTITIONER::Graph::~Graph() delete _partition; delete _graph; } + +int MEDPARTITIONER::Graph::nbDomains() const +{ + std::set domains; + if ( _partition ) + if ( ParaMEDMEM::DataArrayInt* array = _partition->getValueArray() ) + { + for ( const int * dom = array->begin(); dom != array->end(); ++dom ) + domains.insert( *dom ); + } + return domains.size(); +} diff --git a/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx b/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx index fe3cf84cf..33ea67601 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_Graph.hxx @@ -54,8 +54,12 @@ namespace MEDPARTITIONER //returns the number of graph vertices (which can correspond to the cells in the mesh!) int nbVertices() const { return _graph->getNumberOf(); } + + // returns nb of domains in _partition + int nbDomains() const; const ParaMEDMEM::MEDCouplingSkyLineArray *getGraph() const { return _graph; } + const ParaMEDMEM::MEDCouplingSkyLineArray *getPartition() const { return _partition; } protected: ParaMEDMEM::MEDCouplingSkyLineArray* _graph; diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx index ec1db5778..4ecca4e64 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx @@ -32,16 +32,6 @@ #include #include -MEDPARTITIONER::MEDPartitioner *MEDPARTITIONER::MEDPartitioner::New(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) -{ - return new MEDPartitioner(filename,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); -} - -MEDPARTITIONER::MEDPartitioner *MEDPARTITIONER::MEDPartitioner::New(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory) -{ - return new MEDPartitioner(filedata,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); -} - MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory): _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 ) { @@ -85,6 +75,31 @@ MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* fi parallelizer.evaluateMemory(); } +MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, MEDPARTITIONER ::Graph* graph, bool creates_boundary_faces, bool create_joints, bool mesure_memory): + _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 ) +{ + MyGlobals::_World_Size = 1; + MyGlobals::_Rank = 0; + MyGlobals::_Creates_Boundary_Faces = creates_boundary_faces; + MyGlobals::_Create_Joints = create_joints; + + ParaDomainSelector parallelizer(mesure_memory); + _input_collection=new MeshCollection(); + _input_collection->setParaDomainSelector( ¶llelizer ); + _input_collection->retrieveDriver()->readMEDFileData(filedata); + + MEDPARTITIONER::ParallelTopology* aPT = + (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology(); + aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() ); + _input_collection->prepareFieldDescriptions(); + + _new_topology = new MEDPARTITIONER::ParallelTopology( graph, aPT, graph->nbDomains(), _input_collection->getMeshDimension() ); + _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false); + _output_collection->filterFaceOnCell(); + + parallelizer.evaluateMemory(); +} + MEDPARTITIONER::MEDPartitioner::~MEDPartitioner() { delete _input_collection; _input_collection = 0; diff --git a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx index 5417edfed..d7c31ffda 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.hxx @@ -42,16 +42,14 @@ namespace MEDPARTITIONER class MEDPartitioner { public: - static MEDPartitioner *New(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false); - static MEDPartitioner *New(const ParaMEDMEM::MEDFileData* filedata, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false); + MEDPartitioner(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false); + MEDPartitioner(const ParaMEDMEM::MEDFileData* fileData, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false); + MEDPartitioner(const ParaMEDMEM::MEDFileData* fileData, Graph* graph, bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false); static MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0); void write(const std::string& filename); ParaMEDMEM::MEDFileData* getMEDFileData(); ~MEDPartitioner(); - private: - MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory); - MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory); ParaMEDMEM::MEDFileData *convertToMEDFileData(MeshCollection* meshcollection); void createPartitionCollection(int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory); diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx index 310853359..ec806a93b 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollection.cxx @@ -174,7 +174,7 @@ MEDPARTITIONER::MeshCollection::MeshCollection(MeshCollection& initialCollection castAllFields(initialCollection,"cellFieldDouble"); if (_i_non_empty_mesh<0) { - for (unsigned int i=0; i<_mesh.size(); i++) + for (size_t i=0; i<_mesh.size(); i++) { if (_mesh[i]) { @@ -1133,8 +1133,8 @@ void MEDPARTITIONER::MeshCollection::buildConnectZones( const NodeMapping& nodeM MEDPARTITIONER::ConnectZone* cz = czVec[i]; if ( !cz || cz->getEntityCorrespNumber( 0,0 ) == 0 || - (unsigned int)cz->getLocalDomainNumber () > _mesh.size() || - (unsigned int)cz->getDistantDomainNumber() > _mesh.size() ) + cz->getLocalDomainNumber () > (int)_mesh.size() || + cz->getDistantDomainNumber() > (int)_mesh.size() ) continue; ParaMEDMEM::MEDCouplingUMesh* mesh1 = _mesh[ cz->getLocalDomainNumber () ]; ParaMEDMEM::MEDCouplingUMesh* mesh2 = _mesh[ cz->getDistantDomainNumber() ]; @@ -1822,7 +1822,7 @@ int MEDPARTITIONER::MeshCollection::getMeshDimension() const int MEDPARTITIONER::MeshCollection::getNbOfLocalMeshes() const { int nb=0; - for (unsigned int i=0; i<_mesh.size(); i++) + for (size_t i=0; i<_mesh.size(); i++) { if (_mesh[i]) nb++; } @@ -1832,7 +1832,7 @@ int MEDPARTITIONER::MeshCollection::getNbOfLocalMeshes() const int MEDPARTITIONER::MeshCollection::getNbOfLocalCells() const { int nb=0; - for (unsigned int i=0; i<_mesh.size(); i++) + for (size_t i=0; i<_mesh.size(); i++) { if (_mesh[i]) nb=nb+_mesh[i]->getNumberOfCells(); } @@ -1842,7 +1842,7 @@ int MEDPARTITIONER::MeshCollection::getNbOfLocalCells() const int MEDPARTITIONER::MeshCollection::getNbOfLocalFaces() const { int nb=0; - for (unsigned int i=0; i<_face_mesh.size(); i++) + for (size_t i=0; i<_face_mesh.size(); i++) { if (_face_mesh[i]) nb=nb+_face_mesh[i]->getNumberOfCells(); } diff --git a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx index da34f9b3d..f13015f77 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_MeshCollectionDriver.cxx @@ -386,7 +386,7 @@ ParaMEDMEM::MEDCouplingFieldDouble* MeshCollectionDriver::getField(std::string k void MeshCollectionDriver::writeMedFile(int idomain, const std::string& distfilename) const { ParaMEDMEM::MEDFileMesh* mfm = getMesh( idomain ); - mfm->write(distfilename,0); + mfm->write(distfilename,2); std::string key="/inewFieldDouble="+IntToStr(idomain)+"/"; std::map::iterator it; @@ -427,7 +427,7 @@ ParaMEDMEM::MEDFileData* MeshCollectionDriver::getMEDFileData() meshes = ParaMEDMEM::MEDFileMeshes::New(); fields = ParaMEDMEM::MEDFileFields::New(); - for (unsigned int i=0; i<(_collection->getMesh()).size(); i++) + for (size_t i=0; i<_collection->getMesh().size(); i++) { ParaMEDMEM::MEDFileMesh* mfm = getMesh( i ); meshes->pushMesh(mfm); diff --git a/src/MEDPartitioner_Swig/MEDPartitionerCommon.i b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i index e82d1414c..93a390a81 100644 --- a/src/MEDPartitioner_Swig/MEDPartitionerCommon.i +++ b/src/MEDPartitioner_Swig/MEDPartitionerCommon.i @@ -52,26 +52,19 @@ namespace MEDPARTITIONER public: virtual void partGraph(int ndomain, const std::string& options_string="", ParaDomainSelector *sel=0) throw(INTERP_KERNEL::Exception); const ParaMEDMEM::MEDCouplingSkyLineArray *getGraph() const; + const ParaMEDMEM::MEDCouplingSkyLineArray *getPartition() const; + int nbVertices() const; }; class MEDPartitioner { public: - static MEDPartitioner *New(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception); - static MEDPartitioner *New(const ParaMEDMEM::MEDFileData* filedata, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception); + MEDPartitioner(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception); + MEDPartitioner(const ParaMEDMEM::MEDFileData* fileData, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception); + MEDPartitioner(const ParaMEDMEM::MEDFileData* fileData, Graph* graph, bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception); static MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0) throw(INTERP_KERNEL::Exception); ParaMEDMEM::MEDFileData* getMEDFileData() throw(INTERP_KERNEL::Exception); void write(const std::string& filename) throw(INTERP_KERNEL::Exception); - %extend - { - MEDPartitioner(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception) - { - return MEDPartitioner::New(filename,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); - } - MEDPartitioner(const ParaMEDMEM::MEDFileData* fileData, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception) - { - return MEDPartitioner::New(fileData,ndomains,library,creates_boundary_faces, create_joints, mesure_memory); - } - } }; } + diff --git a/src/MEDPartitioner_Swig/MEDPartitionerTest.py b/src/MEDPartitioner_Swig/MEDPartitionerTest.py index e359a6fde..8ad3c3064 100644 --- a/src/MEDPartitioner_Swig/MEDPartitionerTest.py +++ b/src/MEDPartitioner_Swig/MEDPartitionerTest.py @@ -39,6 +39,15 @@ class MEDPartitionerTest(unittest.TestCase): m2d=data2.getMeshes().getMeshAtPos(0) self.assertTrue(m1d.isEqual(m2d,1e-12)) pass + def testPartitionGraph(self): + data=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1() + m=data.getMeshes().getMeshAtPos(0) + graph=MEDPartitioner.Graph(m.getLevel0Mesh().generateGraph()) + graph.partGraph(2) + tool=MEDPartitioner(data,graph) + data2=tool.getMEDFileData() + self.assertEqual( 2, data2.getMeshes().getNumberOfMeshes() ) + pass def testPartitionWithJoints(self): # cartesian mesh 4x4 arr=DataArrayDouble(5) ; arr.iota() @@ -53,28 +62,28 @@ class MEDPartitionerTest(unittest.TestCase): part_file=MEDPartitioner(data,4,"metis",True,True,True) data_file=part_file.getMEDFileData() meshes=data_file.getMeshes() - self.assertEqual( meshes.getNumberOfMeshes(), 4) - self.assertEqual( meshes.getMeshAtPos(0).getJoints().getNumberOfJoints(), 3) - self.assertEqual( meshes.getMeshAtPos(1).getJoints().getNumberOfJoints(), 3) - self.assertEqual( meshes.getMeshAtPos(2).getJoints().getNumberOfJoints(), 3) - self.assertEqual( meshes.getMeshAtPos(3).getJoints().getNumberOfJoints(), 3) + self.assertEqual( 4, meshes.getNumberOfMeshes()) + self.assertEqual( 3, meshes.getMeshAtPos(0).getJoints().getNumberOfJoints()) + self.assertEqual( 3, meshes.getMeshAtPos(1).getJoints().getNumberOfJoints()) + self.assertEqual( 3, meshes.getMeshAtPos(2).getJoints().getNumberOfJoints()) + self.assertEqual( 3, meshes.getMeshAtPos(3).getJoints().getNumberOfJoints()) joints=meshes.getMeshAtPos(0).getJoints() - self.assertEqual( joints.getJointAtPos(0).getDomainNumber(), 1) - self.assertEqual( joints.getJointAtPos(1).getDomainNumber(), 2) - self.assertEqual( joints.getJointAtPos(2).getDomainNumber(), 3) - self.assertEqual( joints.getJointAtPos(0).getStepAtPos(0).getNumberOfCorrespondences(), 2) - self.assertEqual( joints.getJointAtPos(1).getStepAtPos(0).getNumberOfCorrespondences(), 2) - self.assertEqual( joints.getJointAtPos(2).getStepAtPos(0).getNumberOfCorrespondences(), 1) + self.assertEqual( 1, joints.getJointAtPos(0).getDomainNumber(), 1) + self.assertEqual( 2, joints.getJointAtPos(1).getDomainNumber(), 2) + self.assertEqual( 3, joints.getJointAtPos(2).getDomainNumber(), 3) + self.assertEqual( 2, joints.getJointAtPos(0).getStepAtPos(0).getNumberOfCorrespondences()) + self.assertEqual( 2, joints.getJointAtPos(1).getStepAtPos(0).getNumberOfCorrespondences()) + self.assertEqual( 1, joints.getJointAtPos(2).getStepAtPos(0).getNumberOfCorrespondences()) found=0 for ii in xrange(joints.getJointAtPos(0).getStepAtPos(0).getNumberOfCorrespondences()): correspond=joints.getJointAtPos(0).getStepAtPos(0).getCorrespondenceAtPos(ii) if correspond.getCorrespondence().isEqual(DataArrayInt([1,3,2,4])): found+=1 - self.assertEqual(correspond.getLocalGeometryType(),NORM_QUAD4) - self.assertEqual(correspond.getRemoteGeometryType(),NORM_QUAD4) + self.assertEqual(NORM_QUAD4, correspond.getLocalGeometryType()) + self.assertEqual(NORM_QUAD4, correspond.getRemoteGeometryType()) pass pass - self.assertEqual(found,1) + self.assertEqual(1,found) pass def testPartitionPartGraph(self): arr=DataArrayDouble(5) ; arr.iota() @@ -83,6 +92,9 @@ class MEDPartitionerTest(unittest.TestCase): part=MEDPartitioner.Graph(m.generateGraph()) part.partGraph(2) a=part.getGraph() + p=part.getPartition() self.assertTrue(isinstance(a,MEDCouplingSkyLineArray)) + self.assertTrue(isinstance(p,MEDCouplingSkyLineArray)) + self.assertTrue(part.nbVertices() > 0 ) pass unittest.main() -- 2.39.2