From: Anthony Geay Date: Thu, 25 Aug 2016 16:34:58 +0000 (+0200) Subject: extractPart of MEDFile classes easier X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8b77f6d6b85c2d005786688cbe171518ee1d6c17;p=tools%2Fmedcoupling.git extractPart of MEDFile classes easier --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 38da9fe17..ea521f675 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1448,27 +1448,11 @@ void MEDCouplingUMesh::simplifyPolyhedra(double eps) DataArrayInt *MEDCouplingUMesh::computeFetchedNodeIds() const { checkConnectivityFullyDefined(); - int nbOfCells=getNumberOfCells(); - const int *connIndex=_nodal_connec_index->getConstPointer(); - const int *conn=_nodal_connec->getConstPointer(); - const int *maxEltPt=std::max_element(_nodal_connec->begin(),_nodal_connec->end()); - int maxElt=maxEltPt==_nodal_connec->end()?0:std::abs(*maxEltPt)+1; + const int *maxEltPt(std::max_element(_nodal_connec->begin(),_nodal_connec->end())); + int maxElt(maxEltPt==_nodal_connec->end()?0:std::abs(*maxEltPt)+1); std::vector retS(maxElt,false); - for(int i=0;i=0) - retS[conn[j]]=true; - int sz=0; - for(int i=0;ialloc(sz,1); - int *retPtr=ret->getPointer(); - for(int i=0;i& * The keys of \a extractDef is level relative to max ext of \a mm mesh. * * \return A new object that the caller is responsible to deallocate. + * \sa MEDFileUMesh::deduceNodeSubPartFromCellSubPart */ MEDFileField1TS *MEDFileField1TS::extractPart(const std::map >& extractDef, MEDFileMesh *mm) const { diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 90c34e17e..341f08c5d 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -4062,6 +4062,36 @@ DataArrayInt *MEDFileUMesh::zipCoords() return ret.retn(); } +/*! + * This method is a const method. It computes the minimal set of node ids covered by the cell extraction of \a this. + * The extraction of \a this is specified by the extractDef \a input map. + * This map tells for each level of cells, the cells kept in the extraction. + * + * \return - a new reference of DataArrayInt that represents sorted node ids, the extraction is lying on. + * \sa MEDFileField1TS::extractPart + */ +DataArrayInt *MEDFileUMesh::deduceNodeSubPartFromCellSubPart(const std::map >& extractDef) const +{ + std::vector levs(getNonEmptyLevels()); + std::vector fetchedNodes(getNumberOfNodes(),false); + for(std::map >::const_iterator it=extractDef.begin();it!=extractDef.end();it++) + { + if((*it).first>1) + throw INTERP_KERNEL::Exception("MEDFileUMesh::deduceNodeSubPartFromCellSubPart : invalid key ! Must be <=1 !"); + if((*it).first==1) + continue; + if(std::find(levs.begin(),levs.end(),(*it).first)==levs.end()) + { + std::ostringstream oss; oss << "MEDFileUMesh::deduceNodeSubPartFromCellSubPart : invalid level " << (*it).first << " ! Not present in this !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + MCAuto m(getMeshAtLevel((*it).first)); + MCAuto mPart(m->buildPartOfMySelf((*it).second->begin(),(*it).second->end(),true)); + mPart->computeNodeIdsAlg(fetchedNodes); + } + return DataArrayInt::BuildListOfSwitchedOn(fetchedNodes); +} + /*! * This method performs an extrusion along a path defined by \a m1D. * \a this is expected to be a mesh with max mesh dimension equal to 2. diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index f40acc5c7..a5f3ba981 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -329,6 +329,7 @@ namespace MEDCoupling MEDLOADER_EXPORT void buildInnerBoundaryAlongM1Group(const std::string& grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified, DataArrayInt *&cellsNotModified); MEDLOADER_EXPORT bool unPolyze(std::vector& oldCode, std::vector& newCode, DataArrayInt *& o2nRenumCell); MEDLOADER_EXPORT DataArrayInt *zipCoords(); + MEDLOADER_EXPORT DataArrayInt *deduceNodeSubPartFromCellSubPart(const std::map >& extractDef) const; MEDLOADER_EXPORT MEDFileUMesh *buildExtrudedMesh(const MEDCouplingUMesh *m1D, int policy) const; MEDLOADER_EXPORT MEDFileUMesh *linearToQuadratic(int conversionType=0, double eps=1e-12) const; MEDLOADER_EXPORT MEDFileUMesh *quadraticToLinear(double eps=1e-12) const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index b50ddecbf..61002b51a 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -120,6 +120,7 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileUMesh::extractFamilyFieldOnGeoType; %newobject MEDCoupling::MEDFileUMesh::extractNumberFieldOnGeoType; %newobject MEDCoupling::MEDFileUMesh::zipCoords; +%newobject MEDCoupling::MEDFileUMesh::deduceNodeSubPartFromCellSubPart; %newobject MEDCoupling::MEDFileUMesh::buildExtrudedMesh; %newobject MEDCoupling::MEDFileUMesh::linearToQuadratic; %newobject MEDCoupling::MEDFileUMesh::quadraticToLinear; @@ -1392,6 +1393,13 @@ namespace MEDCoupling self->removeMeshAtLevel(meshDimRelToMax); } + DataArrayInt *deduceNodeSubPartFromCellSubPart(PyObject *extractDef) const throw(INTERP_KERNEL::Exception) + { + std::map > extractDefCpp; + convertToMapIntDataArrayInt(extractDef,extractDefCpp); + return self->deduceNodeSubPartFromCellSubPart(extractDefCpp); + } + void setMeshes(PyObject *li, bool renum=false) throw(INTERP_KERNEL::Exception) { std::vector ms;