Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / ParaMEDMEM / ExplicitTopology.hxx
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 #ifndef __EXPLICITTOPOLOGY_HXX__
20 #define __EXPLICITTOPOLOGY_HXX__
21
22 #include "ProcessorGroup.hxx"
23
24 #include <vector>
25 #include <utility>
26 #include <iostream>
27 #include <ext/hash_map>
28
29 namespace ParaMEDMEM
30 {
31   class ParaMESH;
32   class Topology;
33   class ComponentTopology;
34
35   class ExplicitTopology : public Topology
36   {
37   public:
38     ExplicitTopology() { }
39     ExplicitTopology( const ExplicitTopology& topo, int nbcomponents);
40     ExplicitTopology(const ParaMESH &mesh);
41     virtual ~ExplicitTopology();
42     
43     inline int getNbElements()const;
44     inline int getNbLocalElements() const;
45     const ProcessorGroup* getProcGroup()const { return _proc_group; }
46     int localToGlobal (const std::pair<int,int> local) const { return localToGlobal(local.second); }
47     inline int localToGlobal(int) const;
48     inline int globalToLocal(int) const;
49     void serialize(int* & serializer, int& size) const ;
50     void unserialize(const int* serializer, const CommInterface& comm_interface);
51     int getNbComponents() const { return _nb_components; }
52   private:
53     //Processor group
54     const ProcessorGroup* _proc_group;
55     //nb of elements
56     int _nb_elems;
57     //nb of components
58     int _nb_components;
59     //mapping local to global
60     int* _loc2glob;
61     //mapping global to local
62     __gnu_cxx::hash_map<int,int> _glob2loc;
63   };
64
65   //!converts a pair <subdomainid,local> to a global number 
66   inline int ExplicitTopology::globalToLocal(const int global) const
67   {
68     return (_glob2loc.find(global))->second;;
69   }
70
71   //!converts local number to a global number
72   int ExplicitTopology::localToGlobal(int local) const
73   {
74     return _loc2glob[local];
75   }
76   
77   //!Retrieves the number of elements for a given topology
78   inline int ExplicitTopology::getNbElements() const
79   {
80     return _nb_elems;
81   }
82
83   //Retrieves the local number of elements 
84   inline int ExplicitTopology::getNbLocalElements()const 
85   {
86     return _glob2loc.size();
87   }
88 }
89
90
91 #endif