]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDPartitioner/MEDPARTITIONER_MEDPartitioner.cxx
Salome HOME
End of integration of mss/paraspliter
[tools/medcoupling.git] / src / MEDPartitioner / MEDPARTITIONER_MEDPartitioner.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
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"
29 #endif
30 #ifdef MED_ENABLE_SCOTCH
31 #  include "MEDPARTITIONER_ScotchGraph.hxx"
32 #endif
33 #ifdef MED_ENABLE_PTSCOTCH
34 #  include "MEDPARTITIONER_PTScotchGraph.hxx"
35 #endif
36 #include "MEDPARTITIONER_MeshCollectionDriver.hxx"
37
38 #include "MEDCouplingUMesh.hxx"
39 #include "MEDCouplingSkyLineArray.hxx"
40
41 #include <iostream>
42 #include <vector>
43
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 )
46 {
47   MyGlobals::_World_Size = 1;
48   MyGlobals::_Rank = 0;
49   MyGlobals::_Create_Boundary_Faces = create_boundary_faces;
50   MyGlobals::_Create_Joints = create_joints;
51
52   ParaDomainSelector parallelizer(mesure_memory);
53   _input_collection=new MeshCollection(filename,parallelizer);
54   _input_collection->setParaDomainSelector( &parallelizer );
55
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);
61
62   parallelizer.evaluateMemory();
63 }
64
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 )
67 {
68   MyGlobals::_World_Size = 1;
69   MyGlobals::_Rank = 0;
70   MyGlobals::_Create_Boundary_Faces = create_boundary_faces;
71   MyGlobals::_Create_Joints = create_joints;
72
73   ParaDomainSelector parallelizer(mesure_memory);
74   _input_collection=new MeshCollection();
75   _input_collection->setParaDomainSelector( &parallelizer );
76   _input_collection->retrieveDriver()->readMEDFileData(filedata);
77
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);
83
84   parallelizer.evaluateMemory();
85 }
86
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 )
89 {
90   MyGlobals::_World_Size = 1;
91   MyGlobals::_Rank = 0;
92   MyGlobals::_Create_Boundary_Faces = create_boundary_faces;
93   MyGlobals::_Create_Joints = create_joints;
94
95   ParaDomainSelector parallelizer(mesure_memory);
96   _input_collection=new MeshCollection();
97   _input_collection->setParaDomainSelector( &parallelizer );
98   _input_collection->retrieveDriver()->readMEDFileData(filedata);
99
100   MEDPARTITIONER::ParallelTopology* aPT =
101     (MEDPARTITIONER::ParallelTopology*) _input_collection->getTopology();
102   aPT->setGlobalNumerotationDefault( _input_collection->getParaDomainSelector() );
103   _input_collection->prepareFieldDescriptions();
104
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();
108
109   parallelizer.evaluateMemory();
110 }
111
112 MEDPARTITIONER::MEDPartitioner::~MEDPartitioner()
113 {
114   delete _input_collection; _input_collection = 0;
115   delete _output_collection; _output_collection = 0;
116   delete _new_topology; _new_topology = 0;
117 }
118
119 void MEDPARTITIONER::MEDPartitioner::createPartitionCollection(int ndomains, const std::string& library,bool create_boundary_faces, bool create_joints, bool mesure_memory)
120 {
121   //ParallelTopology* aPT = (ParallelTopology*) _input_collection->getTopology();
122   if (library == "metis")
123     _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::METIS);
124   else
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();
128 }
129
130 void MEDPARTITIONER::MEDPartitioner::write(const std::string& filename)
131 {
132   ParaDomainSelector parallelizer(false);
133   _output_collection->setParaDomainSelector( &parallelizer );
134   _output_collection->write(filename);
135   parallelizer.evaluateMemory();
136 }
137
138 MEDCoupling::MEDFileData* MEDPARTITIONER::MEDPartitioner::getMEDFileData()
139 {
140   return _output_collection->retrieveDriver()->getMEDFileData();
141 }
142
143 MEDPARTITIONER::Graph* MEDPARTITIONER::MEDPartitioner::Graph(MEDCoupling::MEDCouplingSkyLineArray* graph, Graph::splitter_type split, int* edgeweight, DataArrayInt *vlbloctab)
144 {
145   MEDPARTITIONER::Graph* cellGraph=0;
146   // will be destroyed by XXXGraph class:
147   MEDCoupling::MEDCouplingSkyLineArray* arr = MEDCoupling::MEDCouplingSkyLineArray::New(graph->getIndexArray(), graph->getValuesArray());
148   switch (split)
149     {
150     case Graph::METIS:
151       if ( !cellGraph )
152         {
153 #ifdef MED_ENABLE_METIS
154           cellGraph=new METISGraph(arr,edgeweight);
155 #endif
156         }
157       if ( !cellGraph )
158         throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : PARMETIS/METIS is not available. Check your products, please.");
159       break;
160     case Graph::SCOTCH:
161 #ifdef MED_ENABLE_SCOTCH
162       cellGraph=new SCOTCHGraph(arr,edgeweight);
163 #else
164 #ifdef MED_ENABLE_PTSCOTCH
165       cellGraph=new PTSCOTCHGraph(arr,edgeweight,vlbloctab);
166 #else
167       throw INTERP_KERNEL::Exception("MEDPartitioner::Graph : PTSCOTCH/SCOTCH is not available. Check your products, please.");
168 #endif
169 #endif
170       break;
171     }
172   return cellGraph;
173 }