1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDPARTITIONER_MEDPartitioner.hxx"
21 #include "MEDPARTITIONER_MeshCollection.hxx"
22 #include "MEDPARTITIONER_Topology.hxx"
23 #include "MEDPARTITIONER_ParaDomainSelector.hxx"
24 #include "MEDPARTITIONER_ParallelTopology.hxx"
25 #include "MEDPARTITIONER_Utils.hxx"
26 #include "MEDPARTITIONER_Graph.hxx"
27 #include "MEDPARTITIONER_MetisGraph.hxx"
28 #include "MEDPARTITIONER_ScotchGraph.hxx"
29 #include "MEDPARTITIONER_MeshCollectionDriver.hxx"
30 #include "MEDCouplingUMesh.hxx"
35 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory):
36 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
38 MyGlobals::_World_Size = 1;
40 MyGlobals::_Creates_Boundary_Faces = creates_boundary_faces;
41 MyGlobals::_Create_Joints = create_joints;
43 ParaDomainSelector parallelizer(mesure_memory);
44 _input_collection=new MeshCollection(filename,parallelizer);
45 _input_collection->setParaDomainSelector( ¶llelizer );
47 MEDPARTITIONER::ParallelTopology* aPT =
48 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
49 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
50 _input_collection->prepareFieldDescriptions();
51 createPartitionCollection(ndomains, library, creates_boundary_faces, create_joints, mesure_memory);
53 parallelizer.evaluateMemory();
56 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory):
57 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
59 MyGlobals::_World_Size = 1;
61 MyGlobals::_Creates_Boundary_Faces = creates_boundary_faces;
62 MyGlobals::_Create_Joints = create_joints;
64 ParaDomainSelector parallelizer(mesure_memory);
65 _input_collection=new MeshCollection();
66 _input_collection->setParaDomainSelector( ¶llelizer );
67 _input_collection->retrieveDriver()->readMEDFileData(filedata);
69 MEDPARTITIONER::ParallelTopology* aPT =
70 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
71 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
72 _input_collection->prepareFieldDescriptions();
73 createPartitionCollection(ndomains, library, creates_boundary_faces, create_joints, mesure_memory);
75 parallelizer.evaluateMemory();
78 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, MEDPARTITIONER ::Graph* graph, bool creates_boundary_faces, bool create_joints, bool mesure_memory):
79 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
81 MyGlobals::_World_Size = 1;
83 MyGlobals::_Creates_Boundary_Faces = creates_boundary_faces;
84 MyGlobals::_Create_Joints = create_joints;
86 ParaDomainSelector parallelizer(mesure_memory);
87 _input_collection=new MeshCollection();
88 _input_collection->setParaDomainSelector( ¶llelizer );
89 _input_collection->retrieveDriver()->readMEDFileData(filedata);
91 MEDPARTITIONER::ParallelTopology* aPT =
92 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
93 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
94 _input_collection->prepareFieldDescriptions();
96 _new_topology = new MEDPARTITIONER::ParallelTopology( graph, aPT, graph->nbDomains(), _input_collection->getMeshDimension() );
97 _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false);
98 _output_collection->filterFaceOnCell();
100 parallelizer.evaluateMemory();
103 MEDPARTITIONER::MEDPartitioner::~MEDPartitioner()
105 delete _input_collection; _input_collection = 0;
106 delete _output_collection; _output_collection = 0;
107 delete _new_topology; _new_topology = 0;
110 void MEDPARTITIONER::MEDPartitioner::createPartitionCollection(int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory)
112 //ParallelTopology* aPT = (ParallelTopology*) _input_collection->getTopology();
113 if (library == "metis")
114 _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::METIS);
116 _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH);
117 _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false);
118 _output_collection->filterFaceOnCell();
121 void MEDPARTITIONER::MEDPartitioner::write(const std::string& filename)
123 ParaDomainSelector parallelizer(false);
124 _output_collection->setParaDomainSelector( ¶llelizer );
125 _output_collection->write(filename);
126 parallelizer.evaluateMemory();
129 ParaMEDMEM::MEDFileData* MEDPARTITIONER::MEDPartitioner::getMEDFileData()
131 return _output_collection->retrieveDriver()->getMEDFileData();
134 MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight)
136 MEDPARTITIONER::Graph* cellGraph=0;
137 ParaMEDMEM::MEDCouplingSkyLineArray* arr = new ParaMEDMEM::MEDCouplingSkyLineArray(graph->getIndexArray(), graph->getValueArray());
143 #ifdef MED_ENABLE_METIS
144 cellGraph=new METISGraph(arr,edgeweight);
148 throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : PARMETIS/METIS is not available. Check your products, please.");
151 #ifdef MED_ENABLE_SCOTCH
152 cellGraph=new SCOTCHGraph(arr,edgeweight);
154 throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : SCOTCH is not available. Check your products, please.");