From: ageay Date: Thu, 20 Jan 2011 12:16:48 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~1102 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=911a565ffacbdb7b67b757b5b567253e23e10e95;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingDefinitionTime.cxx b/src/MEDCoupling/MEDCouplingDefinitionTime.cxx index 95eaf6f3d..7b7b0af74 100644 --- a/src/MEDCoupling/MEDCouplingDefinitionTime.cxx +++ b/src/MEDCoupling/MEDCouplingDefinitionTime.cxx @@ -56,6 +56,17 @@ MEDCouplingDefinitionTimeSlice *MEDCouplingDefinitionTimeSlice::New(const MEDCou } } +bool MEDCouplingDefinitionTimeSlice::isEqual(const MEDCouplingDefinitionTimeSlice& other, double eps) const +{ + if(_mesh_id!=other._mesh_id) + return false; + if(_array_id!=other._array_id) + return false; + if(_field_id!=other._field_id) + return false; + return true; +} + int MEDCouplingDefinitionTimeSlice::getStartId() const { return _array_id; @@ -114,6 +125,24 @@ bool MEDCouplingDefinitionTimeSlice::isBeforeMe(const MEDCouplingDefinitionTimeS return (o1& ret) const +{ + ret.resize(1); + ret[0]=_instant; +} + +void MEDCouplingDefinitionTimeSliceInst::getIdsOnTime(double tm, double eps, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception) +{ + meshId=_mesh_id; + arrId=_array_id; + arrIdInField=0; + fieldId=_field_id; +} + bool MEDCouplingDefinitionTimeSliceInst::isContaining(double tmp, double eps) const { return fabs(tmp-_instant)& ret) const +{ + ret.resize(1); + ret[0]=(_start+_end)/2.; +} + +void MEDCouplingDefinitionTimeSliceCstOnTI::getIdsOnTime(double tm, double eps, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception) +{ + meshId=_mesh_id; + arrId=_array_id; + arrIdInField=0; + fieldId=_field_id; +} + bool MEDCouplingDefinitionTimeSliceCstOnTI::isContaining(double tmp, double eps) const { - return _start-eps>tmp && _end+epstmp; } void MEDCouplingDefinitionTimeSliceCstOnTI::appendRepr(std::ostream& stream) const @@ -176,9 +223,41 @@ MEDCouplingDefinitionTimeSliceCstOnTI::MEDCouplingDefinitionTimeSliceCstOnTI(con _end=t2; } +bool MEDCouplingDefinitionTimeSliceLT::isEqual(const MEDCouplingDefinitionTimeSlice& other, double eps) const +{ +} + +void MEDCouplingDefinitionTimeSliceLT::getHotSpotsTime(std::vector& ret) const +{ + ret.resize(2); + ret[0]=_start; + ret[1]=_end; +} + +void MEDCouplingDefinitionTimeSliceLT::getIdsOnTime(double tm, double eps, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception) +{ + if(fabs(tm-_start)tmp && _end+epstmp; } void MEDCouplingDefinitionTimeSliceLT::appendRepr(std::ostream& stream) const @@ -283,7 +362,33 @@ void MEDCouplingDefinitionTime::getIdsOnTime(double tm, std::vector& meshId int sz=ids.size(); if(sz>2) throw INTERP_KERNEL::Exception("MEDCouplingDefinitionTime::getIdsOnTime : Too many slices match this time !"); - //tony + // + meshIds.resize(sz); + arrIds.resize(sz); + arrIdsInField.resize(sz); + fieldIds.resize(sz); + for(int i=0;igetIdsOnTime(tm,_eps,meshIds[i],arrIds[i],arrIdsInField[i],fieldIds[i]); +} + +std::vector MEDCouplingDefinitionTime::getHotSpotsTime() const +{ + std::vector ret; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_slices.begin();it!=_slices.end();it++) + { + std::vector tmp; + (*it)->getHotSpotsTime(tmp); + if(!ret.empty()) + { + if(fabs(ret.back()-tmp.front())>_eps) + ret.insert(ret.end(),tmp.begin(),tmp.end()); + else + ret.insert(ret.end(),tmp.begin()+1,tmp.end()); + } + else + ret.insert(ret.end(),tmp.begin(),tmp.end()); + } + return ret; } void MEDCouplingDefinitionTime::appendRepr(std::ostream& stream) const diff --git a/src/MEDCoupling/MEDCouplingDefinitionTime.hxx b/src/MEDCoupling/MEDCouplingDefinitionTime.hxx index 490e428a5..e5becae04 100644 --- a/src/MEDCoupling/MEDCouplingDefinitionTime.hxx +++ b/src/MEDCoupling/MEDCouplingDefinitionTime.hxx @@ -37,6 +37,9 @@ namespace ParaMEDMEM public: static MEDCouplingDefinitionTimeSlice *New(const MEDCouplingFieldDouble *f, int meshId, const std::vector& arrId, int fieldId) throw(INTERP_KERNEL::Exception); int getArrayId() const { return _array_id; } + virtual bool isEqual(const MEDCouplingDefinitionTimeSlice& other, double eps) const; + virtual void getHotSpotsTime(std::vector& ret) const = 0; + virtual void getIdsOnTime(double tm, double eps, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception) = 0; virtual bool isContaining(double tmp, double eps) const = 0; virtual int getStartId() const; virtual int getEndId() const; @@ -58,6 +61,9 @@ namespace ParaMEDMEM class MEDCouplingDefinitionTimeSliceInst : public MEDCouplingDefinitionTimeSlice { public: + bool isEqual(const MEDCouplingDefinitionTimeSlice& other, double eps) const; + void getHotSpotsTime(std::vector& ret) const; + void getIdsOnTime(double tm, double eps, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception); bool isContaining(double tmp, double eps) const; void appendRepr(std::ostream& stream) const; double getStartTime() const; @@ -71,6 +77,9 @@ namespace ParaMEDMEM class MEDCouplingDefinitionTimeSliceCstOnTI : public MEDCouplingDefinitionTimeSlice { public: + bool isEqual(const MEDCouplingDefinitionTimeSlice& other, double eps) const; + void getHotSpotsTime(std::vector& ret) const; + void getIdsOnTime(double tm, double eps, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception); bool isContaining(double tmp, double eps) const; void appendRepr(std::ostream& stream) const; double getStartTime() const; @@ -86,6 +95,9 @@ namespace ParaMEDMEM class MEDCouplingDefinitionTimeSliceLT : public MEDCouplingDefinitionTimeSlice { public: + bool isEqual(const MEDCouplingDefinitionTimeSlice& other, double eps) const; + void getHotSpotsTime(std::vector& ret) const; + void getIdsOnTime(double tm, double eps, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception); bool isContaining(double tmp, double eps) const; void appendRepr(std::ostream& stream) const; double getStartTime() const; @@ -103,10 +115,12 @@ namespace ParaMEDMEM { public: MEDCouplingDefinitionTime(); + bool isEqual(const MEDCouplingDefinitionTime& other, double eps) const; MEDCouplingDefinitionTime(const std::vector& fs, const std::vector& meshRefs, const std::vector >& arrRefs) throw(INTERP_KERNEL::Exception); double getTimeResolution() const { return _eps; } void getIdsOnTimeRight(double tm, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception); void getIdsOnTimeLeft(double tm, int& meshId, int& arrId, int& arrIdInField, int& fieldId) const throw(INTERP_KERNEL::Exception); + std::vector getHotSpotsTime() const; void appendRepr(std::ostream& stream) const; private: void getIdsOnTime(double tm, std::vector& meshIds, std::vector& arrIds, std::vector& arrIdsInField, std::vector& fieldIds) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 443a7e5c8..be053dc68 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -1902,7 +1902,11 @@ DataArrayInt *DataArrayInt::selectByTupleIdSafe(const int *new2OldBg, const int } /*! - * + * This method works only for arrays having single component. + * If this contains the array a1 containing [9,10,0,6,4,11,3,7] this method returns an array a2 [5,6,0,3,2,7,1,4]. + * By doing a1.renumber(a2) the user will obtain array a3 equal to a1 sorted. + * This method is useful for renumbering (in MED file for example). This method is used by MEDCouplingFieldDouble::renumberCells when check is set to true. + * This method throws an exception if more 2 or more elements in 'this' are same. */ DataArrayInt *DataArrayInt::checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 32a0d4e50..032459f89 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1063,6 +1063,20 @@ void MEDCouplingUMesh::fillCellIdsToKeepFromNodeIds(const int *begin, const int } } +/*! + * This method is very close too MEDCouplingUMesh::buildPartOfMySelfNode. The difference is that it returns directly ids. + */ +DataArrayInt *MEDCouplingUMesh::getCellIdsLyingOnNodes(const int *begin, const int *end, bool fullyIn) const +{ + std::vector cellIdsKept; + fillCellIdsToKeepFromNodeIds(begin,end,fullyIn,cellIdsKept); + DataArrayInt *ret=DataArrayInt::New(); + ret->alloc(cellIdsKept.size(),1); + std::copy(cellIdsKept.begin(),cellIdsKept.end(),ret->getPointer()); + ret->setName(getName()); + return ret; +} + /*! * Keeps from 'this' only cells which constituing point id are in the ids specified by ['begin','end'). * The return newly allocated mesh will share the same coordinates as 'this'. @@ -1122,6 +1136,27 @@ MEDCouplingPointSet *MEDCouplingUMesh::buildBoundaryMesh(bool keepCoords) const return ret; } +/*! + * This method returns a newly created DataArrayInt instance containing ids of cells located in boundary. + * A cell is detected to be on boundary if it contains one or more than one face having only one father. + * This method makes the assumption that 'this' is fully defined (coords,connectivity). If not an exception will be thrown. + */ +DataArrayInt *MEDCouplingUMesh::findCellsIdsOnBoundary() const throw(INTERP_KERNEL::Exception) +{ + checkFullyDefined(); + DataArrayInt *desc=DataArrayInt::New(); + DataArrayInt *descIndx=DataArrayInt::New(); + DataArrayInt *revDesc=DataArrayInt::New(); + DataArrayInt *revDescIndx=DataArrayInt::New(); + // + MEDCouplingUMesh *meshDM1=buildDescendingConnectivity(desc,descIndx,revDesc,revDescIndx); + // + revDescIndx->decrRef(); + revDesc->decrRef(); + desc->decrRef(); + descIndx->decrRef(); +} + /*! * This methods returns set of nodes lying on the boundary of this. */ diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 225cbcad1..368d80d0f 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -91,10 +91,12 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT MEDCouplingPointSet *buildPartOfMySelf(const int *begin, const int *end, bool keepCoords) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildPartOfMySelfNode(const int *begin, const int *end, bool fullyIn) const; + MEDCOUPLING_EXPORT DataArrayInt *getCellIdsLyingOnNodes(const int *begin, const int *end, bool fullyIn) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildFacePartOfMySelfNode(const int *begin, const int *end, bool fullyIn) const; MEDCOUPLING_EXPORT MEDCouplingUMesh *buildUnstructured() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void findBoundaryNodes(std::vector& nodes) const; MEDCOUPLING_EXPORT MEDCouplingPointSet *buildBoundaryMesh(bool keepCoords) const; + MEDCOUPLING_EXPORT DataArrayInt *findCellsIdsOnBoundary() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void renumberNodes(const int *newNodeNumbers, int newNbOfNodes); MEDCOUPLING_EXPORT void renumberNodes2(const int *newNodeNumbers, int newNbOfNodes); MEDCOUPLING_EXPORT void renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 1513af1b5..5d1ec045f 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -213,6 +213,8 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingUMesh::buildPartOrthogonalField; %newobject ParaMEDMEM::MEDCouplingUMesh::keepCellIdsByType; %newobject ParaMEDMEM::MEDCouplingUMesh::Build0DMeshFromCoords; +%newobject ParaMEDMEM::MEDCouplingUMesh::findCellsIdsOnBoundary; +%newobject ParaMEDMEM::MEDCouplingUMesh::getCellIdsLyingOnNodes; %newobject ParaMEDMEM::MEDCouplingExtrudedMesh::New; %newobject ParaMEDMEM::MEDCouplingExtrudedMesh::build3DUnstructuredMesh; %newobject ParaMEDMEM::MEDCouplingCMesh::New; @@ -727,6 +729,7 @@ namespace ParaMEDMEM void computeTypes() throw(INTERP_KERNEL::Exception); std::string reprConnectivityOfThis() const throw(INTERP_KERNEL::Exception); //tools + DataArrayInt *findCellsIdsOnBoundary() const throw(INTERP_KERNEL::Exception); bool checkConsecutiveCellTypes() const throw(INTERP_KERNEL::Exception); DataArrayInt *rearrange2ConsecutiveCellTypes() throw(INTERP_KERNEL::Exception); DataArrayInt *convertCellArrayPerGeoType(const DataArrayInt *da) const throw(INTERP_KERNEL::Exception); @@ -1029,6 +1032,26 @@ namespace ParaMEDMEM ret->setName(da->getName().c_str()); return ret; } + + DataArrayInt *getCellIdsLyingOnNodes(PyObject *li, bool fullyIn) const throw(INTERP_KERNEL::Exception) + { + void *da=0; + int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); + if (!SWIG_IsOK(res1)) + { + int size; + INTERP_KERNEL::AutoPtr tmp=convertPyToNewIntArr2(li,&size); + return self->getCellIdsLyingOnNodes(tmp,((const int *)tmp)+size,fullyIn); + } + else + { + DataArrayInt *da2=reinterpret_cast< DataArrayInt * >(da); + if(!da2) + throw INTERP_KERNEL::Exception("Not null DataArrayInt instance expected !"); + da2->checkAllocated(); + return self->getCellIdsLyingOnNodes(da2->getConstPointer(),da2->getConstPointer()+da2->getNbOfElems(),fullyIn); + } + } } void convertToPolyTypes(const std::vector& cellIdsToConvert) throw(INTERP_KERNEL::Exception); void unPolyze() throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 002d8dd0d..eec76d26a 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -6005,6 +6005,33 @@ class MEDCouplingBasicsTest(unittest.TestCase): mfs2=mfs.deepCpy(); self.assertTrue(mfs.isEqual(mfs2,1e-12,1e-12)) pass + + def testDAICheckAndPreparePermutation1(self): + vals1=[9,10,0,6,4,11,3,7]; + expect1=[5,6,0,3,2,7,1,4]; + vals2=[9,10,0,6,10,11,3,7]; + da=DataArrayInt.New(); + da.setValues(vals1,8,1); + da2=da.checkAndPreparePermutation(); + self.assertEqual(8,da2.getNumberOfTuples()); + self.assertEqual(1,da2.getNumberOfComponents()); + for i in xrange(8): + self.assertEqual(expect1[i],da2.getIJ(i,0)); + pass + # + da=DataArrayInt.New(); + da.alloc(8,1); + da.iota(0); + da2=da.checkAndPreparePermutation(); + self.assertEqual(8,da2.getNumberOfTuples()); + self.assertEqual(1,da2.getNumberOfComponents()); + self.assertTrue(da2.isIdentity()); + # + da=DataArrayInt.New(); + da.alloc(8,1); + da.setValues(vals2,8,1); + self.assertRaises(InterpKernelException,da.checkAndPreparePermutation); + pass def setUp(self): pass