From: Anthony Geay Date: Tue, 28 Aug 2018 11:58:21 +0000 (+0200) Subject: WIP X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4aedfaf07f44e87799b6982b6877ef5fc173550e;p=tools%2Fmedcoupling.git WIP --- diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 7f7decbd5..fa91db76d 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -16,9 +16,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Anthony Geay (CEA/DEN) +// Author : Anthony Geay (EDF R&D) -#include "MEDCoupling1GTUMesh.hxx" +#include "MEDCoupling1GTUMesh.txx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingCMesh.hxx" @@ -1095,24 +1095,17 @@ void MEDCoupling1SGTUMesh::renumberNodesWithOffsetInConn(int offset) */ void MEDCoupling1SGTUMesh::renumberNodesInConn(const INTERP_KERNEL::HashMap& newNodeNumbersO2N) { - getNumberOfCells();//only to check that all is well defined. - int *begPtr(_conn->getPointer()); - int nbElt(_conn->getNumberOfTuples()); - int *endPtr(begPtr+nbElt); - for(int *it=begPtr;it!=endPtr;it++) - { - INTERP_KERNEL::HashMap::const_iterator it2(newNodeNumbersO2N.find(*it)); - if(it2!=newNodeNumbersO2N.end()) - { - *it=(*it2).second; - } - else - { - std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::renumberNodesInConn : At pos #" << std::distance(begPtr,it) << " of nodal connectivity value is " << *it << ". Not in map !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - updateTime(); + this->renumberNodesInConnT< INTERP_KERNEL::HashMap >(newNodeNumbersO2N); +} + +/*! + * Same than renumberNodesInConn(const int *) except that here the format of old-to-new traducer is using map instead + * of array. This method is dedicated for renumbering from a big set of nodes the a tiny set of nodes which is the case during extraction + * of a big mesh. + */ +void MEDCoupling1SGTUMesh::renumberNodesInConn(const std::map& newNodeNumbersO2N) +{ + this->renumberNodesInConnT< std::map >(newNodeNumbersO2N); } /*! @@ -3175,32 +3168,17 @@ void MEDCoupling1DGTUMesh::renumberNodesWithOffsetInConn(int offset) */ void MEDCoupling1DGTUMesh::renumberNodesInConn(const INTERP_KERNEL::HashMap& newNodeNumbersO2N) { - getNumberOfCells();//only to check that all is well defined. - // - int nbElemsIn(getNumberOfNodes()),nbOfTuples(_conn->getNumberOfTuples()); - int *pt(_conn->getPointer()); - for(int i=0;i=0 && *pt::const_iterator it(newNodeNumbersO2N.find(*pt)); - if(it!=newNodeNumbersO2N.end()) - *pt=(*it).second; - else - { - std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberNodesInConn : At pos #" << i << " of connectivity, node id is " << *pt << ". Not in keys of input map !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - else - { - std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberNodesInConn : error on tuple #" << i << " value is " << *pt << " and indirectionnal array as a size equal to " << nbElemsIn; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - // - updateTime(); + this->renumberNodesInConnT< INTERP_KERNEL::HashMap >(newNodeNumbersO2N); +} + +/*! + * Same than renumberNodesInConn(const int *) except that here the format of old-to-new traducer is using map instead + * of array. This method is dedicated for renumbering from a big set of nodes the a tiny set of nodes which is the case during extraction + * of a big mesh. + */ +void MEDCoupling1DGTUMesh::renumberNodesInConn(const std::map& newNodeNumbersO2N) +{ + this->renumberNodesInConnT< std::map >(newNodeNumbersO2N); } /*! diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx index b69f9b130..e8ae6a50a 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx @@ -135,6 +135,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayInt *getNodeIdsInUse(int& nbrOfNodesInUse) const; MEDCOUPLING_EXPORT void renumberNodesWithOffsetInConn(int offset); MEDCOUPLING_EXPORT void renumberNodesInConn(const INTERP_KERNEL::HashMap& newNodeNumbersO2N); + MEDCOUPLING_EXPORT void renumberNodesInConn(const std::map& newNodeNumbersO2N) override; MEDCOUPLING_EXPORT void renumberNodesInConn(const int *newNodeNumbersO2N); MEDCOUPLING_EXPORT void fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const; MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const; @@ -176,6 +177,8 @@ namespace MEDCoupling DataArrayInt *simplexizePlanarFace6(); MEDCoupling1DGTUMesh *computeDualMesh3D() const; MEDCoupling1DGTUMesh *computeDualMesh2D() const; + template + void renumberNodesInConnT(const MAPCLS& newNodeNumbersO2N); private: MCAuto _conn; public: @@ -231,6 +234,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT DataArrayInt *getNodeIdsInUse(int& nbrOfNodesInUse) const; MEDCOUPLING_EXPORT void renumberNodesWithOffsetInConn(int offset); MEDCOUPLING_EXPORT void renumberNodesInConn(const INTERP_KERNEL::HashMap& newNodeNumbersO2N); + MEDCOUPLING_EXPORT void renumberNodesInConn(const std::map& newNodeNumbersO2N) override; MEDCOUPLING_EXPORT void renumberNodesInConn(const int *newNodeNumbersO2N); MEDCOUPLING_EXPORT void fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const; MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const; @@ -267,6 +271,8 @@ namespace MEDCoupling private: void checkDynamicGeoT2ype() const; static MEDCoupling1DGTUMesh *Merge1DGTUMeshesLL(std::vector& a); + template + void renumberNodesInConnT(const MAPCLS& newNodeNumbersO2N); private: MCAuto _conn_indx; MCAuto _conn; diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.txx b/src/MEDCoupling/MEDCoupling1GTUMesh.txx new file mode 100644 index 000000000..e6ee85403 --- /dev/null +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.txx @@ -0,0 +1,78 @@ +// Copyright (C) 2018 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#pragma once +#include "MEDCoupling1GTUMesh.hxx" + +#include + +template +void MEDCoupling::MEDCoupling1SGTUMesh::renumberNodesInConnT(const MAPCLS& newNodeNumbersO2N) +{ + getNumberOfCells();//only to check that all is well defined. + int *begPtr(_conn->getPointer()); + int nbElt(_conn->getNumberOfTuples()); + int *endPtr(begPtr+nbElt); + for(int *it=begPtr;it!=endPtr;it++) + { + auto it2(newNodeNumbersO2N.find(*it)); + if(it2!=newNodeNumbersO2N.end()) + { + *it=(*it2).second; + } + else + { + std::ostringstream oss; oss << "MEDCoupling1SGTUMesh::renumberNodesInConn : At pos #" << std::distance(begPtr,it) << " of nodal connectivity value is " << *it << ". Not in map !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + updateTime(); +} + +template +void MEDCoupling::MEDCoupling1DGTUMesh::renumberNodesInConnT(const MAPCLS& newNodeNumbersO2N) +{ + getNumberOfCells();//only to check that all is well defined. + // + int nbOfTuples(_conn->getNumberOfTuples()); + int *pt(_conn->getPointer()); + for(int i=0;i=0) + { + auto it(newNodeNumbersO2N.find(*pt)); + if(it!=newNodeNumbersO2N.end()) + *pt=(*it).second; + else + { + std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberNodesInConn : At pos #" << i << " of connectivity, node id is " << *pt << ". Not in keys of input map !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + else + { + std::ostringstream oss; oss << "MEDCoupling1DGTUMesh::renumberNodesInConn : error on tuple #" << i << " value is " << *pt << " ! Should be >=0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + // + updateTime(); +} diff --git a/src/MEDCoupling/MEDCouplingMap.hxx b/src/MEDCoupling/MEDCouplingMap.hxx index b63bd5cdc..9a5b1cfe3 100644 --- a/src/MEDCoupling/MEDCouplingMap.hxx +++ b/src/MEDCoupling/MEDCouplingMap.hxx @@ -48,7 +48,7 @@ namespace MEDCoupling std::map _m; }; - typedef MapKeyVal MapII; + using MapII = MapKeyVal; } #endif diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index a3ece6f4d..61ee630db 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -125,6 +125,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT virtual void fillCellIdsToKeepFromNodeIds(const int *begin, const int *end, bool fullyIn, DataArrayInt *&cellIdsKeptArr) const = 0; MEDCOUPLING_EXPORT virtual void renumberNodesInConn(const int *newNodeNumbersO2N) = 0; MEDCOUPLING_EXPORT virtual void renumberNodesInConn(const INTERP_KERNEL::HashMap& newNodeNumbersO2N) = 0; + MEDCOUPLING_EXPORT virtual void renumberNodesInConn(const std::map& newNodeNumbersO2N) = 0; MEDCOUPLING_EXPORT virtual void renumberNodesWithOffsetInConn(int offset) = 0; MEDCOUPLING_EXPORT virtual void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); MEDCOUPLING_EXPORT virtual void renumberNodesCenter(const int *newNodeNumbers, int newNbOfNodes); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index ca95dc944..8d9162b2c 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -18,7 +18,7 @@ // // Author : Anthony Geay (EDF R&D) -#include "MEDCouplingUMesh.hxx" +#include "MEDCouplingUMesh.txx" #include "MEDCouplingCMesh.hxx" #include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" @@ -2480,30 +2480,17 @@ void MEDCouplingUMesh::renumberNodesWithOffsetInConn(int offset) */ void MEDCouplingUMesh::renumberNodesInConn(const INTERP_KERNEL::HashMap& newNodeNumbersO2N) { - checkConnectivityFullyDefined(); - int *conn(getNodalConnectivity()->getPointer()); - const int *connIndex(getNodalConnectivityIndex()->getConstPointer()); - int nbOfCells(getNumberOfCells()); - for(int i=0;i=0)//avoid polyhedron separator - { - INTERP_KERNEL::HashMap::const_iterator it(newNodeNumbersO2N.find(node)); - if(it!=newNodeNumbersO2N.end()) - { - node=(*it).second; - } - else - { - std::ostringstream oss; oss << "MEDCouplingUMesh::renumberNodesInConn(map) : presence in connectivity for cell #" << i << " of node #" << node << " : Not in map !"; - throw INTERP_KERNEL::Exception(oss.str()); - } - } - } - _nodal_connec->declareAsNew(); - updateTime(); + this->renumberNodesInConnT< INTERP_KERNEL::HashMap >(newNodeNumbersO2N); +} + +/*! + * Same than renumberNodesInConn(const int *) except that here the format of old-to-new traducer is using map instead + * of array. This method is dedicated for renumbering from a big set of nodes the a tiny set of nodes which is the case during extraction + * of a big mesh. + */ +void MEDCouplingUMesh::renumberNodesInConn(const std::map& newNodeNumbersO2N) +{ + this->renumberNodesInConnT< std::map >(newNodeNumbersO2N); } /*! diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index a7be645d8..85690d7d2 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -149,6 +149,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT void renumberNodesWithOffsetInConn(int offset); MEDCOUPLING_EXPORT void renumberNodesInConn(const INTERP_KERNEL::HashMap& newNodeNumbersO2N); MEDCOUPLING_EXPORT void renumberNodesInConn(const int *newNodeNumbersO2N); + MEDCOUPLING_EXPORT void renumberNodesInConn(const std::map& newNodeNumbersO2N) override; MEDCOUPLING_EXPORT void shiftNodeNumbersInConn(int delta); MEDCOUPLING_EXPORT void duplicateNodesInConn(const int *nodeIdsToDuplicateBg, const int *nodeIdsToDuplicateEnd, int offset); MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, bool check=true); @@ -361,6 +362,8 @@ namespace MEDCoupling const std::vector& insidePoints, std::vector& modifiedFace); void attractSeg3MidPtsAroundNodesUnderground(double ratio, const int *nodeIdsBg, const int *nodeIdsEnd); DataArrayInt *internalColinearize2D(double eps, bool stayConform); + template + void renumberNodesInConnT(const MAPCLS& newNodeNumbersO2N); public: MEDCOUPLING_EXPORT static DataArrayInt *ComputeRangesFromTypeDistribution(const std::vector& code); MEDCOUPLING_EXPORT static const int N_MEDMEM_ORDER=25; diff --git a/src/MEDCoupling/MEDCouplingUMesh.txx b/src/MEDCoupling/MEDCouplingUMesh.txx new file mode 100644 index 000000000..f2a692b04 --- /dev/null +++ b/src/MEDCoupling/MEDCouplingUMesh.txx @@ -0,0 +1,53 @@ +// Copyright (C) 2018 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#pragma once +#include "MEDCouplingUMesh.hxx" + +#include + +template +void MEDCoupling::MEDCouplingUMesh::renumberNodesInConnT(const MAPCLS& newNodeNumbersO2N) +{ + checkConnectivityFullyDefined(); + int *conn(getNodalConnectivity()->getPointer()); + const int *connIndex(getNodalConnectivityIndex()->getConstPointer()); + int nbOfCells(getNumberOfCells()); + for(int i=0;i=0)//avoid polyhedron separator + { + auto it(newNodeNumbersO2N.find(node)); + if(it!=newNodeNumbersO2N.end()) + { + node=(*it).second; + } + else + { + std::ostringstream oss; oss << "MEDCouplingUMesh::renumberNodesInConn(map) : presence in connectivity for cell #" << i << " of node #" << node << " : Not in map !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + } + } + _nodal_connec->declareAsNew(); + updateTime(); +} diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 45d2fc793..3793ba25c 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -1635,7 +1635,7 @@ namespace MEDCoupling virtual PyObject *findCommonCells(int compType, int startCellId=0) const throw(INTERP_KERNEL::Exception) { - DataArrayInt *v0=0,*v1=0; + DataArrayInt *v0(nullptr),*v1(nullptr); self->findCommonCells(compType,startCellId,v0,v1); PyObject *res = PyList_New(2); PyList_SetItem(res,0,SWIG_NewPointerObj(SWIG_as_voidptr(v0),SWIGTYPE_p_MEDCoupling__DataArrayInt, SWIG_POINTER_OWN | 0 )); @@ -1646,8 +1646,17 @@ namespace MEDCoupling virtual void renumberNodesInConn(PyObject *li) throw(INTERP_KERNEL::Exception) { - void *da=0; - int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__DataArrayInt, 0 | 0 ); + void *da(nullptr); + { + int res1(SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__MapII, 0 | 0 )); + if(SWIG_IsOK(res1)) + { + MapII *da2(reinterpret_cast(da)); + self->renumberNodesInConn(da2->data()); + return ; + } + } + int res1(SWIG_ConvertPtr(li,&da,SWIGTYPE_p_MEDCoupling__DataArrayInt, 0 | 0 )); if (!SWIG_IsOK(res1)) { int size; @@ -1656,7 +1665,7 @@ namespace MEDCoupling } else { - DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + DataArrayInt *da2(reinterpret_cast< DataArrayInt * >(da)); if(!da2) throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); da2->checkAllocated(); @@ -1676,7 +1685,7 @@ namespace MEDCoupling virtual DataArrayInt *fillCellIdsToKeepFromNodeIds(PyObject *li, bool fullyIn) const { - DataArrayInt *ret=0; + DataArrayInt *ret(nullptr); // int szArr,sw,iTypppArr; std::vector stdvecTyyppArr;