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