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