Salome HOME
b873e7569062f29013baef15f889c4b2a46cb4f1
[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 MEDCoupling
34 {
35
36 ExplicitTopology::ExplicitTopology():
37    _proc_group(NULL), _nb_elems(0), _nb_components(0),
38    _loc2glob(NULL), _glob2loc()
39   {}
40
41 ExplicitTopology::ExplicitTopology(const ParaMESH& paramesh ):
42 _proc_group(paramesh.getBlockTopology()->getProcGroup()),
43 _nb_components(1)
44 {
45   _nb_elems=paramesh.getCellMesh()->getNumberOfCells();
46   const int* global=paramesh.getGlobalNumberingCell();
47   _loc2glob=new int[_nb_elems]; 
48   
49     for (int i=0; i<_nb_elems; i++)
50     {
51       _loc2glob[i]=global[i];
52       _glob2loc[global[i]]=i;
53     }
54 }
55
56 ExplicitTopology::ExplicitTopology(const ExplicitTopology& topo, int nb_components)
57 {
58   _proc_group = topo._proc_group;
59   _nb_elems = topo._nb_elems;
60   _nb_components = nb_components;
61   _loc2glob=new int[_nb_elems];
62   for (int i=0; i<_nb_elems; i++)
63     {
64       _loc2glob[i]=topo._loc2glob[i];
65     }
66   _glob2loc=topo._glob2loc;
67 }
68
69
70 ExplicitTopology::~ExplicitTopology()
71 {
72   if (_loc2glob != 0) delete[] _loc2glob;
73 }
74
75
76 /*! Serializes the data contained in the Explicit Topology
77  * for communication purposes*/
78 void ExplicitTopology::serialize(int* & serializer, int& size) const 
79 {
80   vector <int> buffer;
81   
82   buffer.push_back(_nb_elems);
83   for (int i=0; i<_nb_elems; i++)
84   {
85     buffer.push_back(_loc2glob[i]);
86   }
87     
88   serializer=new int[buffer.size()];
89   size=  buffer.size();
90   copy(buffer.begin(), buffer.end(), serializer);
91   
92 }
93 /*! Unserializes the data contained in the Explicit Topology
94  * after communication. Uses the same structure as the one used for serialize()
95  * 
96  * */
97 void ExplicitTopology::unserialize(const int* serializer,const CommInterface& comm_interface)
98 {
99   const int* ptr_serializer=serializer;
100   cout << "unserialize..."<<endl;
101   _nb_elems=*ptr_serializer++;
102   cout << "nbelems "<<_nb_elems<<endl;
103   _loc2glob=new int[_nb_elems];
104   for (int i=0; i<_nb_elems; i++)
105   {
106     _loc2glob[i]=*ptr_serializer;
107     _glob2loc[*ptr_serializer]=i;
108     ptr_serializer++;
109     
110   }
111
112 }
113
114 }