1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __MEDPARTITIONER_PARALLELTOPOLOGY_HXX__
21 #define __MEDPARTITIONER_PARALLELTOPOLOGY_HXX__
23 #include "MEDPARTITIONER.hxx"
24 #include "MEDPARTITIONER_Topology.hxx"
26 #include "InterpKernelHashMap.hxx"
31 namespace MEDPARTITIONER
35 class ParaDomainSelector;
37 class MEDPARTITIONER_EXPORT ParallelTopology : public Topology
43 ParallelTopology(const std::vector<MEDCoupling::MEDCouplingUMesh*>&);
44 ParallelTopology(const std::vector<MEDCoupling::MEDCouplingUMesh*>&,
45 const std::vector<MEDPARTITIONER::ConnectZone*>&,
46 std::vector<mcIdType*>&,
47 std::vector<mcIdType*>&,
48 std::vector<mcIdType*>&);
49 ParallelTopology(Graph* graph, Topology* oldTopology, int nbdomain, int mesh_dimension);
52 void setGlobalNumerotationDefault(ParaDomainSelector* domainSelector);
54 /*! converts a list of global cell numbers
55 * to a distributed array with local cell numbers
57 void convertGlobalNodeList(const mcIdType*, mcIdType,mcIdType*,int*);
58 void convertGlobalNodeList(const mcIdType*, mcIdType,mcIdType*,int);
59 void convertGlobalNodeListWithTwins(const mcIdType* face_list, mcIdType nbnode, mcIdType*& local, int*& ip, mcIdType*& full_array, mcIdType& size);
61 /*! converts a list of global node numbers
62 * to a distributed array with local cell numbers
64 void convertGlobalCellList(const mcIdType*, mcIdType , mcIdType*, int *);
66 /*! converts a list of global face numbers
67 * to a distributed array with local face numbers
69 void convertGlobalFaceList(const mcIdType*, mcIdType , mcIdType*, int *);
70 void convertGlobalFaceList(const mcIdType*, mcIdType , mcIdType*, int);
71 void convertGlobalFaceListWithTwins(const mcIdType* face_list, mcIdType nbface, mcIdType*& local, int*& ip, mcIdType*& full_array,mcIdType& size);
73 /*! converting node global numberings to local numberings */
74 void convertToLocal2ndVersion(mcIdType* nodes, mcIdType nbnodes, int idomain);
76 /*! converting node local numbering to global */
77 mcIdType convertNodeToGlobal(int ip, mcIdType icell) const { return _node_loc_to_glob[ip][icell]; }
79 /*! converting face local numbering to global */
80 mcIdType convertFaceToGlobal(int ip, mcIdType iface) const { return _face_loc_to_glob[ip][iface]; }
82 /*! converting cell global numbering to local */
83 mcIdType convertCellToGlobal(int ip, mcIdType icell) const { return _loc_to_glob[ip][icell]; }
85 void convertNodeToGlobal(int ip, const mcIdType* local, mcIdType n, mcIdType *global) const
87 for (mcIdType i=0; i<n; i++)
88 global[i]=_node_loc_to_glob[ip][local[i]];
91 void convertCellToGlobal(int ip, const mcIdType* local, mcIdType n, mcIdType *global) const
93 for (mcIdType i=0; i<n; i++)
94 global[i]=_loc_to_glob[ip][local[i]];
97 void convertFaceToGlobal(int ip, const mcIdType* local, mcIdType n, mcIdType *global) const
99 for (mcIdType i=0; i<n; i++)
100 global[i]=_face_loc_to_glob[ip][local[i]];
103 int nbDomain() const { return _nb_domain; }
105 mcIdType nbCells() const { return _nb_total_cells; }
107 mcIdType nbNodes() const { return _nb_total_nodes; }
109 mcIdType nbCells( int idomain) const { return _nb_cells[idomain]; }
111 /*! retrieving number of nodes */
112 mcIdType getNodeNumber(int idomain) const { return _nb_nodes[idomain]; }
114 mcIdType getNodeNumber() const;
116 void getNodeList(int idomain, mcIdType* list) const;
118 /*! retrieving cell numbers after merging in parallel mode */
119 std::vector<mcIdType> & getFusedCellNumbers(int idomain) { return _cell_loc_to_glob_fuse[idomain]; }
121 const std::vector<mcIdType>& getFusedCellNumbers(int idomain) const { return _cell_loc_to_glob_fuse[idomain]; }
123 /*! retrieving face numbers after merging in parallel mode */
124 std::vector<mcIdType> & getFusedFaceNumbers(int idomain) { return _face_loc_to_glob_fuse[idomain]; }
126 const std::vector<mcIdType>& getFusedFaceNumbers(int idomain) const { return _face_loc_to_glob_fuse[idomain]; }
128 /*! retrieving number of nodes */
129 mcIdType getCellNumber(int idomain) const { return _nb_cells[idomain]; }
131 mcIdType getCellDomainNumber(int global) const { return (_glob_to_loc.find(global)->second).first; }
133 void getCellList(int idomain, mcIdType* list) const;
135 mcIdType getFaceNumber(int idomain) const { return _nb_faces[idomain]; }
137 mcIdType getFaceNumber() const;
139 void getFaceList(int idomain, mcIdType* list) const;
141 /*! converting a global cell number to a local representation (domain + local number) */
142 std::pair<int,mcIdType> convertGlobalCell(mcIdType iglobal) const { return _glob_to_loc.find(iglobal)->second; }
144 mcIdType convertGlobalFace(mcIdType iglobal, int idomain);
146 mcIdType convertGlobalNode(mcIdType iglobal, int idomain);
148 std::vector<MEDPARTITIONER::ConnectZone*>& getCZ();
150 //adding a face to the topology
151 void appendFace(int idomain, mcIdType ilocal, mcIdType iglobal);
153 //return max global face number
154 mcIdType getMaxGlobalFace() const;
157 bool hasCellWithNodes( const MeshCollection&, int dom, const std::set<mcIdType>& nodes );
160 //mapping global -> local
161 typedef INTERP_KERNEL::HashMultiMap<mcIdType,std::pair<int,mcIdType> > TGlob2DomainLoc;
163 TGlob2DomainLoc _glob_to_loc;
164 TGlob2DomainLoc _node_glob_to_loc;
166 //mapping local -> global
167 std::vector<std::vector<mcIdType> > _loc_to_glob;
168 std::vector<std::vector <mcIdType> > _node_loc_to_glob;
170 // global numbers in parallel mode
171 std::vector<std::vector <mcIdType> > _cell_loc_to_glob_fuse; // glob nums after merging
172 std::vector<std::vector <mcIdType> > _face_loc_to_glob_fuse; // glob nums after merging
174 //mapping global -> local
175 typedef INTERP_KERNEL::HashMultiMap<mcIdType,std::pair<int,mcIdType> > TGlob2LocsMap;
176 TGlob2LocsMap _face_glob_to_loc;
178 //mapping local -> global
179 std::vector<std::vector <mcIdType> > _face_loc_to_glob;
180 std::vector<mcIdType> _nb_cells;
181 std::vector<mcIdType> _nb_nodes;
182 std::vector<mcIdType> _nb_faces;
183 mcIdType _nb_total_cells;
184 mcIdType _nb_total_nodes;
185 mcIdType _nb_total_faces;
189 //links to connectzones
190 std::vector<MEDPARTITIONER::ConnectZone*> _connect_zones;