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 #include "MEDPARTITIONER_MeshCollectionDriver.hxx"
35 #include "MEDCouplingUMesh.hxx"
36 #include "MEDCouplingSkyLineArray.hxx"
41 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory):
42 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
44 MyGlobals::_World_Size = 1;
46 MyGlobals::_Creates_Boundary_Faces = creates_boundary_faces;
47 MyGlobals::_Create_Joints = create_joints;
49 ParaDomainSelector parallelizer(mesure_memory);
50 _input_collection=new MeshCollection(filename,parallelizer);
51 _input_collection->setParaDomainSelector( ¶llelizer );
53 MEDPARTITIONER::ParallelTopology* aPT =
54 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
55 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
56 _input_collection->prepareFieldDescriptions();
57 createPartitionCollection(ndomains, library, creates_boundary_faces, create_joints, mesure_memory);
59 parallelizer.evaluateMemory();
62 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const MEDCoupling::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory):
63 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
65 MyGlobals::_World_Size = 1;
67 MyGlobals::_Creates_Boundary_Faces = creates_boundary_faces;
68 MyGlobals::_Create_Joints = create_joints;
70 ParaDomainSelector parallelizer(mesure_memory);
71 _input_collection=new MeshCollection();
72 _input_collection->setParaDomainSelector( ¶llelizer );
73 _input_collection->retrieveDriver()->readMEDFileData(filedata);
75 MEDPARTITIONER::ParallelTopology* aPT =
76 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
77 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
78 _input_collection->prepareFieldDescriptions();
79 createPartitionCollection(ndomains, library, creates_boundary_faces, create_joints, mesure_memory);
81 parallelizer.evaluateMemory();
84 MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const MEDCoupling::MEDFileData* filedata, MEDPARTITIONER ::Graph* graph, bool creates_boundary_faces, bool create_joints, bool mesure_memory):
85 _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
87 MyGlobals::_World_Size = 1;
89 MyGlobals::_Creates_Boundary_Faces = creates_boundary_faces;
90 MyGlobals::_Create_Joints = create_joints;
92 ParaDomainSelector parallelizer(mesure_memory);
93 _input_collection=new MeshCollection();
94 _input_collection->setParaDomainSelector( ¶llelizer );
95 _input_collection->retrieveDriver()->readMEDFileData(filedata);
97 MEDPARTITIONER::ParallelTopology* aPT =
98 (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
99 aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
100 _input_collection->prepareFieldDescriptions();
102 _new_topology = new MEDPARTITIONER::ParallelTopology( graph, aPT, graph->nbDomains(), _input_collection->getMeshDimension() );
103 _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false);
104 _output_collection->filterFaceOnCell();
106 parallelizer.evaluateMemory();
109 MEDPARTITIONER::MEDPartitioner::~MEDPartitioner()
111 delete _input_collection; _input_collection = 0;
112 delete _output_collection; _output_collection = 0;
113 delete _new_topology; _new_topology = 0;
116 void MEDPARTITIONER::MEDPartitioner::createPartitionCollection(int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory)
118 //ParallelTopology* aPT = (ParallelTopology*) _input_collection->getTopology();
119 if (library == "metis")
120 _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::METIS);
122 _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH);
123 _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false);
124 _output_collection->filterFaceOnCell();
127 void MEDPARTITIONER::MEDPartitioner::write(const std::string& filename)
129 ParaDomainSelector parallelizer(false);
130 _output_collection->setParaDomainSelector( ¶llelizer );
131 _output_collection->write(filename);
132 parallelizer.evaluateMemory();
135 MEDCoupling::MEDFileData* MEDPARTITIONER::MEDPartitioner::getMEDFileData()
137 return _output_collection->retrieveDriver()->getMEDFileData();
140 MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight)
142 MEDPARTITIONER::Graph* cellGraph=0;
143 // will be destroyed by XXXGraph class:
144 MEDCoupling::MEDCouplingSkyLineArray* arr = MEDCoupling::MEDCouplingSkyLineArray::New(graph->getIndexArray(), graph->getValuesArray());
150 #ifdef MED_ENABLE_METIS
151 cellGraph=new METISGraph(arr,edgeweight);
155 throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : PARMETIS/METIS is not available. Check your products, please.");
158 #ifdef MED_ENABLE_SCOTCH
159 cellGraph=new SCOTCHGraph(arr,edgeweight);
161 throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : SCOTCH is not available. Check your products, please.");