1 // Copyright (C) 2007-2023 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 #ifdef MED_ENABLE_METIS
28 # include "MEDPARTITIONER_MetisGraph.hxx"
30 #ifdef MED_ENABLE_SCOTCH
31 # include "MEDPARTITIONER_ScotchGraph.hxx"
33 #ifdef MED_ENABLE_PTSCOTCH
34 # include "MEDPARTITIONER_PTScotchGraph.hxx"
36 #include "MEDPARTITIONER_MeshCollectionDriver.hxx"
38 #include "MEDCouplingUMesh.hxx"
39 #include "MEDCouplingSkyLineArray.hxx"
44 const char MEDPARTITIONER::MEDPartitioner::METIS_PART_ALG[]="Metis";
45 const char MEDPARTITIONER::MEDPartitioner::SCOTCH_PART_ALG[]="Scotch";
46 const char MEDPARTITIONER::MEDPartitioner::PTSCOTCH_PART_ALG[]="PTScotch";
48 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool create_boundary_faces, bool create_joints, bool mesure_memory):
49 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
51 MyGlobals::_World_Size = 1;
53 MyGlobals::_Create_Boundary_Faces = create_boundary_faces;
54 MyGlobals::_Create_Joints = create_joints;
56 ParaDomainSelector parallelizer(mesure_memory);
57 _input_collection=new MeshCollection(filename,parallelizer);
58 _input_collection->setParaDomainSelector( ¶llelizer );
60 MEDPARTITIONER::ParallelTopology* aPT =
61 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
62 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
63 _input_collection->prepareFieldDescriptions();
64 createPartitionCollection(ndomains, library, create_boundary_faces, create_joints, mesure_memory);
66 parallelizer.evaluateMemory();
69 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const MEDCoupling::MEDFileData* filedata, int ndomains, const std::string& library,bool create_boundary_faces, bool create_joints, bool mesure_memory):
70 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
72 MyGlobals::_World_Size = 1;
74 MyGlobals::_Create_Boundary_Faces = create_boundary_faces;
75 MyGlobals::_Create_Joints = create_joints;
77 ParaDomainSelector parallelizer(mesure_memory);
78 _input_collection=new MeshCollection();
79 _input_collection->setParaDomainSelector( ¶llelizer );
80 _input_collection->retrieveDriver()->readMEDFileData(filedata);
82 MEDPARTITIONER::ParallelTopology* aPT =
83 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
84 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
85 _input_collection->prepareFieldDescriptions();
86 createPartitionCollection(ndomains, library, create_boundary_faces, create_joints, mesure_memory);
88 parallelizer.evaluateMemory();
91 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const MEDCoupling::MEDFileData* filedata, MEDPARTITIONER ::Graph* graph, bool create_boundary_faces, bool create_joints, bool mesure_memory):
92 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
94 MyGlobals::_World_Size = 1;
96 MyGlobals::_Create_Boundary_Faces = create_boundary_faces;
97 MyGlobals::_Create_Joints = create_joints;
99 ParaDomainSelector parallelizer(mesure_memory);
100 _input_collection=new MeshCollection();
101 _input_collection->setParaDomainSelector( ¶llelizer );
102 _input_collection->retrieveDriver()->readMEDFileData(filedata);
104 MEDPARTITIONER::ParallelTopology* aPT =
105 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
106 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
107 _input_collection->prepareFieldDescriptions();
109 _new_topology = new MEDPARTITIONER::ParallelTopology( graph, aPT, graph->nbDomains(), _input_collection->getMeshDimension() );
110 _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false);
111 _output_collection->filterFaceOnCell();
113 parallelizer.evaluateMemory();
116 MEDPARTITIONER::MEDPartitioner::~MEDPartitioner()
118 delete _input_collection; _input_collection = 0;
119 delete _output_collection; _output_collection = 0;
120 delete _new_topology; _new_topology = 0;
123 void MEDPARTITIONER::MEDPartitioner::createPartitionCollection(int ndomains, const std::string& library,bool create_boundary_faces, bool create_joints, bool mesure_memory)
125 //ParallelTopology* aPT = (ParallelTopology*) _input_collection->getTopology();
126 if (library == "metis")
127 _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::METIS);
129 _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH);
130 _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false);
131 _output_collection->filterFaceOnCell();
134 void MEDPARTITIONER::MEDPartitioner::write(const std::string& filename)
136 ParaDomainSelector parallelizer(false);
137 _output_collection->setParaDomainSelector( ¶llelizer );
138 _output_collection->write(filename);
139 parallelizer.evaluateMemory();
142 MEDCoupling::MEDFileData* MEDPARTITIONER::MEDPartitioner::getMEDFileData()
144 return _output_collection->retrieveDriver()->getMEDFileData();
147 MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight, DataArrayIdType *vlbloctab)
149 MEDPARTITIONER::Graph* cellGraph=0;
150 // will be destroyed by XXXGraph class:
151 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingSkyLineArray> arr(MEDCoupling::MEDCouplingSkyLineArray::New(graph->getIndexArray(), graph->getValuesArray()));
157 #ifdef MED_ENABLE_METIS
158 cellGraph=new METISGraph(arr.retn(),edgeweight);
162 throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : PARMETIS/METIS is not available. Check your products, please.");
165 #ifdef MED_ENABLE_SCOTCH
166 cellGraph=new SCOTCHGraph(arr.retn(),edgeweight);
168 throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : SCOTCH is not available. Check your products, please.");
171 case Graph::PTSCOTCH:
173 #ifdef MED_ENABLE_PTSCOTCH
174 cellGraph=new PTSCOTCHGraph(arr.retn(),edgeweight,vlbloctab);
176 throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : PTSCOTCH is not available. Check your products, please.");
181 throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : Not managed split type engine !");
186 std::vector<std::string> MEDPARTITIONER::MEDPartitioner::AvailableAlgorithms()
188 std::vector<std::string> ret;
189 #ifdef MED_ENABLE_METIS
190 ret.push_back(std::string(METIS_PART_ALG));
192 #ifdef MED_ENABLE_SCOTCH
193 ret.push_back(std::string(SCOTCH_PART_ALG));
195 #ifdef MED_ENABLE_PTSCOTCH
196 ret.push_back(std::string(PTSCOTCH_PART_ALG));
201 bool MEDPARTITIONER::MEDPartitioner::HasMetisAlg()
203 #ifdef MED_ENABLE_METIS
210 bool MEDPARTITIONER::MEDPartitioner::HasScotchAlg()
212 #ifdef MED_ENABLE_SCOTCH
219 bool MEDPARTITIONER::MEDPartitioner::HasPTScotchAlg()
221 #ifdef MED_ENABLE_PTSCOTCH
228 std::vector<std::string> MEDPARTITIONER::MEDPartitioner::AllAlgorithms()
230 std::vector<std::string> ret;
231 ret.push_back(std::string(METIS_PART_ALG));
232 ret.push_back(std::string(SCOTCH_PART_ALG));
233 ret.push_back(std::string(PTSCOTCH_PART_ALG));