Salome HOME
Merge branch 'abn/fix_orient' into V7_main
[tools/medcoupling.git] / src / MEDPartitioner / MEDPARTITIONER_ParallelTopology.hxx
1 // Copyright (C) 2007-2014  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 __MEDPARTITIONER_PARALLELTOPOLOGY_HXX__
21 #define __MEDPARTITIONER_PARALLELTOPOLOGY_HXX__
22
23 #include "MEDPARTITIONER.hxx"
24 #include "MEDPARTITIONER_Topology.hxx"
25 #include "MEDPARTITIONER_ParaDomainSelector.hxx"
26
27
28 #include "InterpKernelHashMap.hxx"
29
30 #include <set>
31 #include <vector>
32
33 namespace MEDPARTITIONER
34 {
35   class Graph;
36   class MeshCollection;
37   class MEDPARTITIONER_FaceModel;
38
39   class MEDPARTITIONER_EXPORT ParallelTopology : public Topology
40   {
41
42   public:
43
44     ParallelTopology();
45     ParallelTopology(const std::vector<ParaMEDMEM::MEDCouplingUMesh*>&);
46     ParallelTopology(const std::vector<ParaMEDMEM::MEDCouplingUMesh*>&,
47                      const std::vector<MEDPARTITIONER::ConnectZone*>&,
48                      std::vector<int*>&,
49                      std::vector<int*>&,
50                      std::vector<int*>&);
51     ParallelTopology(Graph* graph, Topology* oldTopology, int nbdomain, int mesh_dimension);
52     ~ParallelTopology();
53     
54     void setGlobalNumerotationDefault(ParaDomainSelector* domainSelector);
55
56     /*! converts a list of global cell numbers
57      * to a distributed array with local cell numbers
58      */
59     void convertGlobalNodeList(const int*, int,int*,int*);
60     void convertGlobalNodeList(const int*, int,int*,int);
61     void convertGlobalNodeListWithTwins(const int* face_list, int nbnode, int*& local, int*& ip, int*& full_array, int& size);
62
63     /*! converts a list of global node numbers
64      * to a distributed array with local cell numbers
65      */
66     void convertGlobalCellList(const int*, int , int*, int *);
67
68     /*! converts a list of global face numbers
69      *  to a distributed array with local face numbers
70      */
71     void convertGlobalFaceList(const int*, int , int*, int *);  
72     void convertGlobalFaceList(const int*, int , int*, int);  
73     void convertGlobalFaceListWithTwins(const int* face_list, int nbface, int*& local, int*& ip, int*& full_array,int& size);
74
75     /*! converting node global numberings to local numberings */
76     void convertToLocal2ndVersion(int* nodes, int nbnodes, int idomain);
77
78     /*! converting node local numbering to global */
79     int convertNodeToGlobal(int ip, int icell) const { return _node_loc_to_glob[ip][icell]; }
80
81     /*! converting face local numbering to global */
82     int convertFaceToGlobal(int ip, int iface) const { return _face_loc_to_glob[ip][iface]; }
83
84     /*! converting cell global numbering to local */
85     int convertCellToGlobal(int ip, int icell) const { return _loc_to_glob[ip][icell]; }
86
87     void convertNodeToGlobal(int ip, const int* local, int n, int *global) const
88     {
89       for (int i=0; i<n; i++)
90         global[i]=_node_loc_to_glob[ip][local[i]];
91     }
92
93     void convertCellToGlobal(int ip, const int* local, int n, int *global) const
94     {
95       for (int i=0; i<n; i++)
96         global[i]=_loc_to_glob[ip][local[i]];  
97     }
98
99     void convertFaceToGlobal(int ip, const int* local, int n, int *global) const
100     {
101       for (int i=0; i<n; i++) 
102         global[i]=_face_loc_to_glob[ip][local[i]];
103     }
104
105     int nbDomain() const { return _nb_domain; }
106
107     int nbCells() const { return _nb_total_cells; }
108     
109     int nbNodes() const { return _nb_total_nodes; }
110
111     int nbCells( int idomain) const { return _nb_cells[idomain]; }
112
113     /*! retrieving number of nodes */
114     int getNodeNumber(int idomain) const { return _nb_nodes[idomain]; }
115
116     int getNodeNumber() const;
117
118     void getNodeList(int idomain, int* list) const;
119
120     /*! retrieving cell numbers after merging in parallel mode */
121     std::vector<int> & getFusedCellNumbers(int idomain) { return _cell_loc_to_glob_fuse[idomain]; }
122     
123     const std::vector<int>& getFusedCellNumbers(int idomain) const { return _cell_loc_to_glob_fuse[idomain]; }
124
125     /*! retrieving face numbers after merging in parallel mode */
126     std::vector<int> & getFusedFaceNumbers(int idomain) { return _face_loc_to_glob_fuse[idomain]; }
127
128     const std::vector<int>& getFusedFaceNumbers(int idomain) const { return _face_loc_to_glob_fuse[idomain]; }
129
130     /*! retrieving number of nodes */
131     int getCellNumber(int idomain) const { return _nb_cells[idomain]; }
132
133     int getCellDomainNumber(int global) const { return (_glob_to_loc.find(global)->second).first; }
134
135     void getCellList(int idomain, int* list) const;
136
137     int getFaceNumber(int idomain) const { return _nb_faces[idomain]; }
138
139     int getFaceNumber() const;
140
141     void getFaceList(int idomain, int* list) const;
142
143     /*! converting a global cell number to a local representation (domain + local number) */
144     std::pair<int,int> convertGlobalCell(int iglobal) const { return _glob_to_loc.find(iglobal)->second; }
145
146     int convertGlobalFace(int iglobal, int idomain);
147
148     int convertGlobalNode(int iglobal, int idomain);
149     
150     //adding a face to the topology
151     void appendFace(int idomain, int ilocal, int iglobal);
152
153     //return max global face number
154     int getMaxGlobalFace() const;
155
156   private:
157     bool hasCellWithNodes( const MeshCollection&, int dom, const std::set<int>& nodes );
158
159   private:
160     //mapping global -> local
161     typedef INTERP_KERNEL::HashMultiMap<int,std::pair<int,int> > TGlob2DomainLoc;
162
163     TGlob2DomainLoc _glob_to_loc;
164     std::vector<std::vector<int> >  _loc_to_glob;
165     INTERP_KERNEL::HashMultiMap<int,std::pair<int,int> > _node_glob_to_loc;
166
167     //mapping local -> global
168     std::vector<std::vector <int> > _node_loc_to_glob;
169
170     // global numbers in parallel mode
171     std::vector<std::vector <int> > _cell_loc_to_glob_fuse; // glob nums after merging
172     std::vector<std::vector <int> > _face_loc_to_glob_fuse; // glob nums after merging
173
174     //mapping global -> local
175     typedef INTERP_KERNEL::HashMultiMap<int,std::pair<int,int> > TGlob2LocsMap;
176     TGlob2LocsMap _face_glob_to_loc;
177
178     //mapping local -> global
179     std::vector<std::vector <int> > _face_loc_to_glob;
180     std::vector<int> _nb_cells;
181     std::vector<int> _nb_nodes;
182     std::vector<int> _nb_faces;
183     int _nb_total_cells;
184     int _nb_total_nodes;
185     int _nb_total_faces;
186     int _nb_domain;
187     int _mesh_dimension;
188   };
189 }
190 #endif