#include "MEDPARTITIONER_Graph.hxx"
+#include <set>
+
MEDPARTITIONER::Graph::Graph(ParaMEDMEM::MEDCouplingSkyLineArray *array, int *edgeweight):_graph(array),_partition(0),_edge_weight(edgeweight),_cell_weight(0)
{
}
delete _partition;
delete _graph;
}
+
+int MEDPARTITIONER::Graph::nbDomains() const
+{
+ std::set<int> 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();
+}
//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;
#include <iostream>
#include <vector>
-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 )
{
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;
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);
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])
{
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() ];
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++;
}
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();
}
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();
}
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<std::string,ParaMEDMEM::DataArrayDouble*>::iterator it;
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);
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);
- }
- }
};
}
+
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()
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()
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()