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