Salome HOME
Update copyrights
[tools/medcoupling.git] / src / MEDCoupling / MEDCoupling1GTUMesh.txx
1 // Copyright (C) 2018-2019  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 "MEDCoupling1GTUMesh.hxx"
23
24 #include <sstream>
25
26 template<class MAPCLS>
27 void MEDCoupling::MEDCoupling1SGTUMesh::renumberNodesInConnT(const MAPCLS& newNodeNumbersO2N)
28 {
29   getNumberOfCells();//only to check that all is well defined.
30   int *begPtr(_conn->getPointer());
31   int nbElt(_conn->getNumberOfTuples());
32   int *endPtr(begPtr+nbElt);
33   for(int *it=begPtr;it!=endPtr;it++)
34     {
35       auto it2(newNodeNumbersO2N.find(*it));
36       if(it2!=newNodeNumbersO2N.end())
37         {
38           *it=(*it2).second;
39         }
40       else
41         {
42           std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::renumberNodesInConn : At pos #" << std::distance(begPtr,it) << " of nodal connectivity value is " << *it << ". Not in map !";
43           throw INTERP_KERNEL::Exception(oss.str().c_str());
44         }
45     }
46   updateTime();
47 }
48
49 template<class MAPCLS>
50 void MEDCoupling::MEDCoupling1DGTUMesh::renumberNodesInConnT(const MAPCLS& newNodeNumbersO2N)
51 {
52   getNumberOfCells();//only to check that all is well defined.
53   //
54   int nbOfTuples(_conn->getNumberOfTuples());
55   int *pt(_conn->getPointer());
56   for(int i=0;i<nbOfTuples;i++,pt++)
57     {
58       if(*pt==-1) continue;
59       if(*pt>=0)
60         {
61           auto it(newNodeNumbersO2N.find(*pt));
62           if(it!=newNodeNumbersO2N.end())
63             *pt=(*it).second;
64           else
65             {
66               std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberNodesInConn : At pos #" << i << " of connectivity, node id is " << *pt << ". Not in keys of input map !";
67               throw INTERP_KERNEL::Exception(oss.str().c_str());
68             }
69         }
70       else
71         {
72           std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberNodesInConn : error on tuple #" << i << " value is " << *pt << " ! Should be >=0 !";
73           throw INTERP_KERNEL::Exception(oss.str().c_str());
74         }
75     }
76   //
77   updateTime();
78 }