Salome HOME
Copyright update 2021
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingUMesh.txx
1 // Copyright (C) 2018-2021  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 // Author : Anthony Geay (EDF R&D)
20
21 #pragma once
22 #include "MEDCouplingUMesh.hxx"
23
24 #include <sstream>
25
26 template<class MAPCLS>
27 void MEDCoupling::MEDCouplingUMesh::renumberNodesInConnT(const MAPCLS& newNodeNumbersO2N)
28 {
29   checkConnectivityFullyDefined();
30   mcIdType *conn(getNodalConnectivity()->getPointer());
31   const mcIdType *connIndex(getNodalConnectivityIndex()->getConstPointer());
32   mcIdType nbOfCells=ToIdType(getNumberOfCells());
33   for(mcIdType i=0;i<nbOfCells;i++)
34     for(mcIdType iconn=connIndex[i]+1;iconn!=connIndex[i+1];iconn++)
35       {
36         mcIdType& node=conn[iconn];
37         if(node>=0)//avoid polyhedron separator
38           {
39             auto it(newNodeNumbersO2N.find(node));
40             if(it!=newNodeNumbersO2N.end())
41               {
42                 node=(*it).second;
43               }
44             else
45               {
46                 std::ostringstream oss; oss << "MEDCouplingUMesh::renumberNodesInConn(map) : presence in connectivity for cell #" << i << " of node #" << node << " : Not in map !";
47                 throw INTERP_KERNEL::Exception(oss.str());
48               }
49           }
50       }
51   _nodal_connec->declareAsNew();
52   updateTime();
53 }