Salome HOME
[ParaMEDMEM] Adding SWIG interface for OverlapDEC + py tests of DEC
[tools/medcoupling.git] / src / ParaMEDMEM / ExplicitTopology.hxx
1 // Copyright (C) 2007-2020  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 #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 MEDCoupling
31 {
32   class ParaMESH;
33   class Topology;
34   class ComponentTopology;
35
36   /*!
37    * \anchor ExplicitTopology-det
38    *
39    * An ExplicitTopology typically represents the split of a mesh among the processors of
40    * a common ProcessorGroup. Each processor gets a user-defined part of the cells in the mesh.
41    * \sa BlockTopology
42    */
43   class ExplicitTopology : public Topology
44   {
45   public:
46     ExplicitTopology();
47     ExplicitTopology( const ExplicitTopology& topo, int nbcomponents);
48     ExplicitTopology(const ParaMESH &mesh);
49     virtual ~ExplicitTopology();
50
51     inline mcIdType getNbElements()const;
52     inline mcIdType getNbLocalElements() const;
53     const ProcessorGroup* getProcGroup()const { return _proc_group; }
54     mcIdType localToGlobal (const std::pair<int,mcIdType> local) const { return localToGlobal(local.second); }
55     inline mcIdType localToGlobal(mcIdType) const;
56     inline mcIdType globalToLocal(mcIdType) const;
57     void serialize(mcIdType* & serializer, mcIdType& size) const ;
58     void unserialize(const mcIdType* serializer, const CommInterface& comm_interface);
59     int getNbComponents() const { return _nb_components; }
60   private:
61     //Processor group
62     const ProcessorGroup* _proc_group;
63     //nb of elements
64     mcIdType _nb_elems;
65     //nb of components
66     int _nb_components;
67     //mapping local to global
68     mcIdType* _loc2glob;
69     //mapping global to local
70     INTERP_KERNEL::HashMap<mcIdType,mcIdType> _glob2loc;
71   };
72
73   //!converts a pair <subdomainid,local> to a global number 
74   inline mcIdType ExplicitTopology::globalToLocal(const mcIdType global) const
75   {
76     return (_glob2loc.find(global))->second;
77   }
78
79   //!converts local number to a global number
80   mcIdType ExplicitTopology::localToGlobal(mcIdType local) const
81   {
82     return _loc2glob[local];
83   }
84   
85   //!Retrieves the number of elements for a given topology
86   inline mcIdType ExplicitTopology::getNbElements() const
87   {
88     return _nb_elems;
89   }
90
91   //Retrieves the local number of elements 
92   inline mcIdType ExplicitTopology::getNbLocalElements()const 
93   {
94     return ToIdType(_glob2loc.size());
95   }
96 }
97
98
99 #endif