From ab8c62a7830baeb53f3a0b1652c507419c4bcbfc Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 19 Jun 2013 14:53:10 +0000 Subject: [PATCH] debugs --- src/MEDCoupling/MEDCoupling1GTUMesh.cxx | 50 ++----- src/MEDCoupling/MEDCoupling1GTUMesh.hxx | 2 +- src/MEDCoupling/MEDCouplingMemArray.cxx | 46 +++++- src/MEDCoupling/MEDCouplingPointSet.cxx | 24 +++- src/MEDCoupling/MEDCouplingPointSet.hxx | 2 +- src/MEDCoupling/MEDCouplingRefCountObject.cxx | 5 + src/MEDCoupling/MEDCouplingRefCountObject.hxx | 1 + src/MEDCoupling/MEDCouplingUMesh.cxx | 7 +- src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 40 +++--- src/MEDCoupling_Swig/MEDCouplingCommon.i | 132 ++++++++++-------- 10 files changed, 178 insertions(+), 131 deletions(-) diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index c2bde1a54..fb67f3a0e 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -162,13 +162,14 @@ void MEDCoupling1GTUMesh::splitProfilePerType(const DataArrayInt *profile, std:: int nbTuples=profile->getNumberOfTuples(); int nbOfCells=getNumberOfCells(); code.resize(3); idsInPflPerType.resize(1); - code[0]=(int)getCellModelEnum(); code[1]=nbOfCells; + code[0]=(int)getCellModelEnum(); code[1]=nbTuples; idsInPflPerType.resize(1); if(profile->isIdentity() && nbTuples==nbOfCells) { code[2]=-1; idsInPflPerType[0]=const_cast(profile); idsInPflPerType[0]->incrRef(); - idsPerType.clear(); + idsPerType.clear(); + return ; } code[2]=0; profile->checkAllIdsInRange(0,nbOfCells); @@ -240,7 +241,7 @@ bool MEDCoupling1GTUMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double p reason="mesh given in input is not castable in MEDCouplingSGTUMesh !"; return false; } - if(&_cm!=&otherC->_cm) + if(_cm!=otherC->_cm) { reason="mismatch in geometric type !"; return false; @@ -257,7 +258,7 @@ bool MEDCoupling1GTUMesh::isEqualWithoutConsideringStr(const MEDCouplingMesh *ot const MEDCoupling1GTUMesh *otherC=dynamic_cast(other); if(!otherC) return false; - if(&_cm!=&otherC->_cm) + if(_cm!=otherC->_cm) return false; return true; } @@ -816,28 +817,6 @@ DataArrayInt *MEDCoupling1SGTUMesh::mergeNodes2(double precision, bool& areNodes return ret; } -/*! - * Removes unused nodes (the node coordinates array is shorten) and returns an array - * mapping between new and old node ids in "Old to New" mode. -1 values in the returned - * array mean that the corresponding old node is no more used. - * \return DataArrayInt * - a new instance of DataArrayInt of length \a - * this->getNumberOfNodes() before call of this method. The caller is to - * delete this array using decrRef() as it is no more needed. - * \throw If the coordinates array is not set. - * \throw If the nodal connectivity of cells is not defined. - * \throw If the nodal connectivity includes an invalid id. - * - * \ref cpp_mcumesh_zipCoordsTraducer "Here is a C++ example".
- * \ref py_mcumesh_zipCoordsTraducer "Here is a Python example". - */ -DataArrayInt *MEDCoupling1SGTUMesh::zipCoordsTraducer() throw(INTERP_KERNEL::Exception) -{ - int newNbOfNodes=-1; - DataArrayInt *traducer=getNodeIdsInUse(newNbOfNodes); - renumberNodes(traducer->getConstPointer(),newNbOfNodes); - return traducer; -} - /// @cond INTERNAL struct MEDCouplingAccVisit @@ -874,9 +853,9 @@ DataArrayInt *MEDCoupling1SGTUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const const int *conn=_conn->begin(); int nbNodesPerCell=getNumberOfNodesPerCell(); for(int i=0;i=0 && conn[j]=0 && *connrenumberInPlace(newNodeNumbersO2N); + _conn->transformWithIndArr(newNodeNumbersO2N,newNodeNumbersO2N+getNumberOfNodes()); updateTime(); } @@ -957,6 +936,7 @@ MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesOnSameCoords(std::ve const DataArrayDouble *coords=(*it)->getCoords(); const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel()); int nbNodesPerCell=(*it)->getNumberOfNodesPerCell(); + it++; for(;it!=a.end();it++) { if(cm!=&((*it)->getCellModel())) @@ -990,6 +970,7 @@ MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesLL(std::vectorgetNumberOfCells(); const INTERP_KERNEL::CellModel *cm=&((*it)->getCellModel()); int nbNodesPerCell=(*it)->getNumberOfNodesPerCell(); + it++; for(;it!=a.end();it++) { if(cm!=&((*it)->getCellModel())) @@ -1013,7 +994,7 @@ MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::Merge1SGTUMeshesLL(std::vectorgetNumberOfNodes(); } // - ret->_conn=c; + ret->setNodalConnectivity(c); return ret.retn(); } @@ -1078,10 +1059,7 @@ MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::buildSetInstanceFromThis(int spaceDi tmp1=DataArrayInt::New(); tmp1->alloc(0,1); } else - { - tmp1=_conn; - tmp1->incrRef(); - } + tmp1=_conn; ret->_conn=tmp1; if(!_coords) { @@ -1165,7 +1143,7 @@ DataArrayInt *MEDCoupling1SGTUMesh::simplexizePlanarFace6() throw(INTERP_KERNEL: MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(6*nbOfCells,1); const int *c(_conn->begin()); int *retPtr(ret->getPointer()),*newConnPtr(newConn->getPointer()); - for(int i=0;i& a) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index d8dee0b6a..f6f5243bd 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -1291,7 +1291,16 @@ void DataArrayDouble::renumberInPlace(const int *old2New) throw(INTERP_KERNEL::E double *tmp=new double[nbTuples*nbOfCompo]; const double *iptr=getConstPointer(); for(int i=0;i=0 && v=0 && v=0 && v=0 && v newCoords=_coords->renumberAndReduce(newNodeNumbers,newNbOfNodes); - setCoords(newCoords); renumberNodesInConn(newNodeNumbers); + setCoords(newCoords);//let it here not before renumberNodesInConn because old number of nodes is sometimes used... } /*! @@ -1515,3 +1515,25 @@ DataArrayInt *MEDCouplingPointSet::getCellIdsFullyIncludedInNodeIds(const int *p { return getCellIdsLyingOnNodes(partBg,partEnd,true); } + +/*! + * Removes unused nodes (the node coordinates array is shorten) and returns an array + * mapping between new and old node ids in "Old to New" mode. -1 values in the returned + * array mean that the corresponding old node is no more used. + * \return DataArrayInt * - a new instance of DataArrayInt of length \a + * this->getNumberOfNodes() before call of this method. The caller is to + * delete this array using decrRef() as it is no more needed. + * \throw If the coordinates array is not set. + * \throw If the nodal connectivity of cells is not defined. + * \throw If the nodal connectivity includes an invalid id. + * + * \ref cpp_mcumesh_zipCoordsTraducer "Here is a C++ example".
+ * \ref py_mcumesh_zipCoordsTraducer "Here is a Python example". + */ +DataArrayInt *MEDCouplingPointSet::zipCoordsTraducer() throw(INTERP_KERNEL::Exception) +{ + int newNbOfNodes=-1; + MEDCouplingAutoRefCountObjectPtr traducer=getNodeIdsInUse(newNbOfNodes); + renumberNodes(traducer->getConstPointer(),newNbOfNodes); + return traducer.retn(); +} diff --git a/src/MEDCoupling/MEDCouplingPointSet.hxx b/src/MEDCoupling/MEDCouplingPointSet.hxx index ed2b45056..a815d8508 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.hxx +++ b/src/MEDCoupling/MEDCouplingPointSet.hxx @@ -128,7 +128,7 @@ namespace ParaMEDMEM const std::vector& littleStrings); virtual DataArrayInt *getCellsInBoundingBox(const double *bbox, double eps) const = 0; virtual DataArrayInt *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps) = 0; - virtual DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception) = 0; + virtual DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception); virtual DataArrayInt *zipConnectivityTraducer(int compType, int startCellId=0) throw(INTERP_KERNEL::Exception); virtual void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const throw(INTERP_KERNEL::Exception) = 0; //tools diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.cxx b/src/MEDCoupling/MEDCouplingRefCountObject.cxx index b4ae45f67..c8de20ea9 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.cxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.cxx @@ -67,6 +67,11 @@ void RefCountObject::incrRef() const _cnt++; } +int RefCountObject::getRCValue() const +{ + return _cnt; +} + RefCountObject::~RefCountObject() { } diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.hxx b/src/MEDCoupling/MEDCouplingRefCountObject.hxx index 7d8c1904b..0eb1f4dea 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.hxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.hxx @@ -66,6 +66,7 @@ namespace ParaMEDMEM bool decrRef() const; void incrRef() const; virtual std::size_t getHeapMemorySize() const = 0; + int getRCValue() const; protected: virtual ~RefCountObject(); private: diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 953b9f8f8..d416da071 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1434,10 +1434,7 @@ DataArrayInt *MEDCouplingUMesh::computeNbOfFacesPerCell() const throw(INTERP_KER */ DataArrayInt *MEDCouplingUMesh::zipCoordsTraducer() throw(INTERP_KERNEL::Exception) { - int newNbOfNodes=-1; - DataArrayInt *traducer=getNodeIdsInUse(newNbOfNodes); - renumberNodes(traducer->getConstPointer(),newNbOfNodes); - return traducer; + return MEDCouplingPointSet::zipCoordsTraducer(); } /*! @@ -6717,7 +6714,7 @@ MEDCoupling1GTUMesh *MEDCouplingUMesh::convertIntoSingleGeoTypeMesh() const thro INTERP_KERNEL::NormalizedCellType typ=*_types.begin(); int typi=(int)typ; MEDCouplingAutoRefCountObjectPtr ret=MEDCoupling1GTUMesh::New(getName(),typ); - ret->setCoords(ret->getCoords()); + ret->setCoords(getCoords()); MEDCoupling1SGTUMesh *retC=dynamic_cast((MEDCoupling1GTUMesh*)ret); if(retC) { diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 35a8eb09a..22817182f 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -1852,10 +1852,10 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(check.isEqual(ids)); code, idsInPflPerType, pfls=mesh1.splitProfilePerType(ids); - self.assertEqual(3, len(code)); - self.assertEqual(NORM_HEXA8, code[0]); - self.assertEqual(27, code[1]); - self.assertEqual(0, code[2]); + self.assertEqual(1, len(code)); + self.assertEqual(NORM_HEXA8, code[0][0]); + self.assertEqual(27, code[0][1]); + self.assertEqual(0, code[0][2]); self.assertEqual(1, len(idsInPflPerType)); self.assertEqual(1, len(pfls)); self.assertTrue(idsInPflPerType[0].isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9]))); @@ -7745,12 +7745,10 @@ class MEDCouplingBasicsTest(unittest.TestCase): d.setValues(val1,3,1); d.setName("sup") code,idsInPflPerType,pfls=m.splitProfilePerType(d); - self.assertEqual(6,len(code)); + self.assertEqual(2,len(code)); self.assertEqual(2,len(idsInPflPerType)); - expected1=[3,1,0, 4,2,1] - for i in xrange(6): - self.assertEqual(expected1[i],code[i]); - pass + expected1=[[3,1,0], [4,2,1]] + self.assertEqual(expected1,code) self.assertEqual(2,len(idsInPflPerType)); self.assertEqual(1,idsInPflPerType[0].getNumberOfTuples()); self.assertEqual(0,idsInPflPerType[0].getIJ(0,0)); @@ -7771,12 +7769,10 @@ class MEDCouplingBasicsTest(unittest.TestCase): d=DataArrayInt.New(); d.setValues(val2,4,1); code,idsInPflPerType,pfls=m.splitProfilePerType(d); - self.assertEqual(6,len(code)); + self.assertEqual(2,len(code)); self.assertEqual(2,len(idsInPflPerType)); - expected2=[3,1,0, 4,3,-1] - for i in xrange(6): - self.assertEqual(expected2[i],code[i]); - pass + expected2=[[3,1,0], [4,3,-1]] + self.assertEqual(expected2,code); self.assertEqual(2,len(idsInPflPerType)); self.assertEqual(1,idsInPflPerType[0].getNumberOfTuples()); self.assertEqual(0,idsInPflPerType[0].getIJ(0,0)); @@ -7793,12 +7789,10 @@ class MEDCouplingBasicsTest(unittest.TestCase): d=DataArrayInt.New(); d.setValues(val3,3,1); code,idsInPflPerType,pfls=m.splitProfilePerType(d); - self.assertEqual(6,len(code)); + self.assertEqual(2,len(code)); self.assertEqual(2,len(idsInPflPerType)); - expected3=[3,2,0, 4,1,1] - for i in xrange(6): - self.assertEqual(expected3[i],code[i]); - pass + expected3=[[3,2,0], [4,1,1]] + self.assertEqual(expected3,code); self.assertEqual(2,len(idsInPflPerType)); self.assertEqual(2,idsInPflPerType[0].getNumberOfTuples()); self.assertEqual(0,idsInPflPerType[0].getIJ(0,0)); @@ -7816,12 +7810,10 @@ class MEDCouplingBasicsTest(unittest.TestCase): d=DataArrayInt.New(); d.setValues(val4,2,1); code,idsInPflPerType,pfls=m.splitProfilePerType(d); - self.assertEqual(3,len(code)); + self.assertEqual(1,len(code)); self.assertEqual(1,len(idsInPflPerType)); - expected4=[4,2,0] - for i in xrange(3): - self.assertEqual(expected4[i],code[i]); - pass + expected4=[[4,2,0]] + self.assertEqual(expected4,code); self.assertEqual(1,len(idsInPflPerType)); self.assertEqual(2,idsInPflPerType[0].getNumberOfTuples()); self.assertEqual(0,idsInPflPerType[0].getIJ(0,0)); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index f393ee31c..1b9d202ea 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -338,12 +338,12 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingPointSet::mergeMyselfWithOnSameCoords; %newobject ParaMEDMEM::MEDCouplingPointSet::fillCellIdsToKeepFromNodeIds; %newobject ParaMEDMEM::MEDCouplingPointSet::getCellIdsLyingOnNodes; +%newobject ParaMEDMEM::MEDCouplingPointSet::__getitem__; %newobject ParaMEDMEM::MEDCouplingUMesh::New; %newobject ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivity; %newobject ParaMEDMEM::MEDCouplingUMesh::getNodalConnectivityIndex; %newobject ParaMEDMEM::MEDCouplingUMesh::clone; %newobject ParaMEDMEM::MEDCouplingUMesh::__iter__; -%newobject ParaMEDMEM::MEDCouplingUMesh::__getitem__; %newobject ParaMEDMEM::MEDCouplingUMesh::cellsByType; %newobject ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity; %newobject ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity2; @@ -505,6 +505,7 @@ namespace ParaMEDMEM public: bool decrRef() const; void incrRef() const; + int getRCValue() const; virtual std::size_t getHeapMemorySize() const; }; } @@ -931,6 +932,8 @@ namespace ParaMEDMEM PyObject *getDistributionOfTypes() const throw(INTERP_KERNEL::Exception) { std::vector vals=self->getDistributionOfTypes(); + if(vals.size()%3!=0) + throw INTERP_KERNEL::Exception("Internal Error detected in wrap python ! code returned by MEDCouplingMesh::getDistributionOfTypes is not so that %3==0 !"); PyObject *ret=PyList_New((int)vals.size()/3); for(int j=0;j<(int)vals.size()/3;j++) { @@ -959,7 +962,20 @@ namespace ParaMEDMEM std::vector idsPerType; self->splitProfilePerType(profile,code,idsInPflPerType,idsPerType); PyObject *ret=PyTuple_New(3); - PyTuple_SetItem(ret,0,convertIntArrToPyList2(code)); + // + if(code.size()%3!=0) + throw INTERP_KERNEL::Exception("Internal Error detected in wrap python ! code returned by MEDCouplingMesh::splitProfilePerType is not so that %3==0 !"); + PyObject *ret0=PyList_New((int)code.size()/3); + for(int j=0;j<(int)code.size()/3;j++) + { + PyObject *ret00=PyList_New(3); + PyList_SetItem(ret00,0,SWIG_From_int(code[3*j])); + PyList_SetItem(ret00,1,SWIG_From_int(code[3*j+1])); + PyList_SetItem(ret00,2,SWIG_From_int(code[3*j+2])); + PyList_SetItem(ret0,j,ret00); + } + PyTuple_SetItem(ret,0,ret0); + // PyObject *ret1=PyList_New(idsInPflPerType.size()); for(std::size_t j=0;jgetCellIdsLyingOnNodes(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems(),fullyIn); } } + + MEDCouplingPointSet *__getitem__(PyObject *listOrDataArrI) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + int nbc=self->getNumberOfCells(); + convertObjToPossibleCpp2(listOrDataArrI,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + if(singleVal>=nbc) + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(singleVal>=0) + return self->buildPartOfMySelf(&singleVal,&singleVal+1,true); + else + { + if(nbc+singleVal>0) + { + int tmp=nbc+singleVal; + return self->buildPartOfMySelf(&tmp,&tmp+1,true); + } + else + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } + case 2: + { + return static_cast(self->buildPartOfMySelf(&multiVal[0],&multiVal[0]+multiVal.size(),true)); + } + case 3: + { + return self->buildPartOfMySelf2(slic.first,slic.second.first,slic.second.second,true); + } + case 4: + { + if(!daIntTyypp) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__getitem__ : null instance has been given in input !"); + daIntTyypp->checkAllocated(); + return self->buildPartOfMySelf(daIntTyypp->begin(),daIntTyypp->end(),true); + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__getitem__ : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !"); + } + } static void Rotate2DAlg(PyObject *center, double angle, int nbNodes, PyObject *coords) throw(INTERP_KERNEL::Exception) { @@ -1661,62 +1733,6 @@ namespace ParaMEDMEM { return self->cellIterator(); } - - MEDCouplingPointSet *__getitem__(PyObject *listOrDataArrI) throw(INTERP_KERNEL::Exception) - { - int sw; - int singleVal; - std::vector multiVal; - std::pair > slic; - ParaMEDMEM::DataArrayInt *daIntTyypp=0; - int nbc=self->getNumberOfCells(); - convertObjToPossibleCpp2(listOrDataArrI,nbc,sw,singleVal,multiVal,slic,daIntTyypp); - switch(sw) - { - case 1: - { - if(singleVal>=nbc) - { - std::ostringstream oss; - oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - if(singleVal>=0) - return self->buildPartOfMySelf(&singleVal,&singleVal+1,true); - else - { - if(nbc+singleVal>0) - { - int tmp=nbc+singleVal; - return self->buildPartOfMySelf(&tmp,&tmp+1,true); - } - else - { - std::ostringstream oss; - oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - } - case 2: - { - return static_cast(self->buildPartOfMySelf(&multiVal[0],&multiVal[0]+multiVal.size(),true)); - } - case 3: - { - return self->buildPartOfMySelf2(slic.first,slic.second.first,slic.second.second,true); - } - case 4: - { - if(!daIntTyypp) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__getitem__ : null instance has been given in input !"); - daIntTyypp->checkAllocated(); - return self->buildPartOfMySelf(daIntTyypp->begin(),daIntTyypp->end(),true); - } - default: - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__getitem__ : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !"); - } - } void setPartOfMySelf(PyObject *li, const MEDCouplingUMesh& otherOnSameCoordsThanThis) throw(INTERP_KERNEL::Exception) { -- 2.39.2