1 // Copyright (C) 2007-2016 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 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool create_boundary_faces, bool create_joints, bool mesure_memory):
45 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
47 MyGlobals::_World_Size = 1;
49 MyGlobals::_Create_Boundary_Faces = create_boundary_faces;
50 MyGlobals::_Create_Joints = create_joints;
52 ParaDomainSelector parallelizer(mesure_memory);
53 _input_collection=new MeshCollection(filename,parallelizer);
54 _input_collection->setParaDomainSelector( ¶llelizer );
56 MEDPARTITIONER::ParallelTopology* aPT =
57 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
58 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
59 _input_collection->prepareFieldDescriptions();
60 createPartitionCollection(ndomains, library, create_boundary_faces, create_joints, mesure_memory);
62 parallelizer.evaluateMemory();
65 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const MEDCoupling::MEDFileData* filedata, int ndomains, const std::string& library,bool create_boundary_faces, bool create_joints, bool mesure_memory):
66 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
68 MyGlobals::_World_Size = 1;
70 MyGlobals::_Create_Boundary_Faces = create_boundary_faces;
71 MyGlobals::_Create_Joints = create_joints;
73 ParaDomainSelector parallelizer(mesure_memory);
74 _input_collection=new MeshCollection();
75 _input_collection->setParaDomainSelector( ¶llelizer );
76 _input_collection->retrieveDriver()->readMEDFileData(filedata);
78 MEDPARTITIONER::ParallelTopology* aPT =
79 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
80 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
81 _input_collection->prepareFieldDescriptions();
82 createPartitionCollection(ndomains, library, create_boundary_faces, create_joints, mesure_memory);
84 parallelizer.evaluateMemory();
87 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const MEDCoupling::MEDFileData* filedata, MEDPARTITIONER ::Graph* graph, bool create_boundary_faces, bool create_joints, bool mesure_memory):
88 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
90 MyGlobals::_World_Size = 1;
92 MyGlobals::_Create_Boundary_Faces = create_boundary_faces;
93 MyGlobals::_Create_Joints = create_joints;
95 ParaDomainSelector parallelizer(mesure_memory);
96 _input_collection=new MeshCollection();
97 _input_collection->setParaDomainSelector( ¶llelizer );
98 _input_collection->retrieveDriver()->readMEDFileData(filedata);
100 MEDPARTITIONER::ParallelTopology* aPT =
101 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
102 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
103 _input_collection->prepareFieldDescriptions();
105 _new_topology = new MEDPARTITIONER::ParallelTopology( graph, aPT, graph->nbDomains(), _input_collection->getMeshDimension() );
106 _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false);
107 _output_collection->filterFaceOnCell();
109 parallelizer.evaluateMemory();
112 MEDPARTITIONER::MEDPartitioner::~MEDPartitioner()
114 delete _input_collection; _input_collection = 0;
115 delete _output_collection; _output_collection = 0;
116 delete _new_topology; _new_topology = 0;
119 void MEDPARTITIONER::MEDPartitioner::createPartitionCollection(int ndomains, const std::string& library,bool create_boundary_faces, bool create_joints, bool mesure_memory)
121 //ParallelTopology* aPT = (ParallelTopology*) _input_collection->getTopology();
122 if (library == "metis")
123 _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::METIS);
125 _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH);
126 _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false);
127 _output_collection->filterFaceOnCell();
130 void MEDPARTITIONER::MEDPartitioner::write(const std::string& filename)
132 ParaDomainSelector parallelizer(false);
133 _output_collection->setParaDomainSelector( ¶llelizer );
134 _output_collection->write(filename);
135 parallelizer.evaluateMemory();
138 MEDCoupling::MEDFileData* MEDPARTITIONER::MEDPartitioner::getMEDFileData()
140 return _output_collection->retrieveDriver()->getMEDFileData();
143 MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight, DataArrayInt *vlbloctab)
145 MEDPARTITIONER::Graph* cellGraph=0;
146 // will be destroyed by XXXGraph class:
147 MEDCoupling::MEDCouplingSkyLineArray* arr = MEDCoupling::MEDCouplingSkyLineArray::New(graph->getIndexArray(), graph->getValuesArray());
153 #ifdef MED_ENABLE_METIS
154 cellGraph=new METISGraph(arr,edgeweight);
158 throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : PARMETIS/METIS is not available. Check your products, please.");
161 #ifdef MED_ENABLE_SCOTCH
162 cellGraph=new SCOTCHGraph(arr,edgeweight);
164 #ifdef MED_ENABLE_PTSCOTCH
165 cellGraph=new PTSCOTCHGraph(arr,edgeweight,vlbloctab);
167 throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : PTSCOTCH/SCOTCH is not available. Check your products, please.");