Salome HOME
Merge branch 'master' of https://git.salome-platform.org/git/modules/med
[tools/medcoupling.git] / src / ParaMEDMEM / ExplicitTopology.cxx
1 // Copyright (C) 2007-2015  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 "CommInterface.hxx"
21 #include "ProcessorGroup.hxx"
22 #include "MPIProcessorGroup.hxx"
23 #include "ParaMESH.hxx"
24 #include "Topology.hxx"
25 #include "ExplicitTopology.hxx"
26 #include "BlockTopology.hxx"
27 #include "ComponentTopology.hxx"
28
29 #include <vector>
30 #include <algorithm>
31
32 using namespace std;
33 namespace ParaMEDMEM
34 {
35
36 ExplicitTopology::ExplicitTopology(const ParaMESH& paramesh ):
37 _proc_group(paramesh.getBlockTopology()->getProcGroup()),
38 _nb_components(1)
39 {
40   _nb_elems=paramesh.getCellMesh()->getNumberOfCells();
41   const int* global=paramesh.getGlobalNumberingCell();
42   _loc2glob=new int[_nb_elems]; 
43   
44     for (int i=0; i<_nb_elems; i++)
45     {
46       _loc2glob[i]=global[i];
47       _glob2loc[global[i]]=i;
48     }
49 }
50
51 ExplicitTopology::ExplicitTopology(const ExplicitTopology& topo, int nb_components)
52 {
53   _proc_group = topo._proc_group;
54   _nb_elems = topo._nb_elems;
55   _nb_components = nb_components;
56   _loc2glob=new int[_nb_elems];
57   for (int i=0; i<_nb_elems; i++)
58     {
59       _loc2glob[i]=topo._loc2glob[i];
60     }
61   _glob2loc=topo._glob2loc;
62 }
63
64
65 ExplicitTopology::~ExplicitTopology()
66 {
67   if (_loc2glob != 0) delete[] _loc2glob;
68 }
69
70
71 /*! Serializes the data contained in the Explicit Topology
72  * for communication purposes*/
73 void ExplicitTopology::serialize(int* & serializer, int& size) const 
74 {
75   vector <int> buffer;
76   
77   buffer.push_back(_nb_elems);
78   for (int i=0; i<_nb_elems; i++)
79   {
80     buffer.push_back(_loc2glob[i]);
81   }
82     
83   serializer=new int[buffer.size()];
84   size=  buffer.size();
85   copy(buffer.begin(), buffer.end(), serializer);
86   
87 }
88 /*! Unserializes the data contained in the Explicit Topology
89  * after communication. Uses the same structure as the one used for serialize()
90  * 
91  * */
92 void ExplicitTopology::unserialize(const int* serializer,const CommInterface& comm_interface)
93 {
94   const int* ptr_serializer=serializer;
95   cout << "unserialize..."<<endl;
96   _nb_elems=*ptr_serializer++;
97   cout << "nbelems "<<_nb_elems<<endl;
98   _loc2glob=new int[_nb_elems];
99   for (int i=0; i<_nb_elems; i++)
100   {
101     _loc2glob[i]=*ptr_serializer;
102     _glob2loc[*ptr_serializer]=i;
103     ptr_serializer++;
104     
105   }
106
107 }
108
109 }