From d7c81487995e2eee051b63e1bac8b969ba863bb7 Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 16 Dec 2013 15:00:41 +0000 Subject: [PATCH] Addition of family field on nodes and number field on node for meshes. --- src/MEDLoader/MEDFileFieldOverView.cxx | 256 ++++++++++++++++++------- src/MEDLoader/MEDFileFieldOverView.hxx | 12 +- src/MEDLoader/Swig/MEDLoaderCommon.i | 26 +++ 3 files changed, 226 insertions(+), 68 deletions(-) diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx index 2a6787666..591cb4079 100644 --- a/src/MEDLoader/MEDFileFieldOverView.cxx +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -292,6 +292,72 @@ void MEDMeshMultiLev::retrieveNumberIdsOnCells(DataArrayInt *& numIds, bool& isW numIds=DataArrayInt::Aggregate(ret); } +/*! + * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef). + * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure. + */ +void MEDMeshMultiLev::retrieveFamilyIdsOnNodes(DataArrayInt *& famIds, bool& isWithoutCopy) const +{ + const DataArrayInt *fids(_node_fam_ids); + if(!fids) + { famIds=0; isWithoutCopy=true; return ; } + std::size_t sz(_geo_types.size()); + bool presenceOfPfls(false); + for(std::size_t i=0;i(fids); famIds->incrRef(); isWithoutCopy=_node_fam_ids_nocpy; return ; } + //bad luck the slowest part + const DataArrayInt *nr(_node_reduction); + if(nr) + { + isWithoutCopy=false; + famIds=fids->selectByTupleIdSafe(nr->begin(),nr->end()); + } + else + { + isWithoutCopy=_node_fam_ids_nocpy; + famIds=const_cast(fids); famIds->incrRef(); + } +} + +/*! + * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef). + * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure. + */ +void MEDMeshMultiLev::retrieveNumberIdsOnNodes(DataArrayInt *& numIds, bool& isWithoutCopy) const +{ + const DataArrayInt *fids(_node_num_ids); + if(!fids) + { numIds=0; isWithoutCopy=true; return ; } + std::size_t sz(_geo_types.size()); + bool presenceOfPfls(false); + for(std::size_t i=0;i(fids); numIds->incrRef(); isWithoutCopy=_node_num_ids_nocpy; return ; } + //bad luck the slowest part + const DataArrayInt *nr(_node_reduction); + if(nr) + { + isWithoutCopy=false; + numIds=fids->selectByTupleIdSafe(nr->begin(),nr->end()); + } + else + { + isWithoutCopy=_node_num_ids_nocpy; + numIds=const_cast(fids); numIds->incrRef(); + } +} + void MEDMeshMultiLev::setFamilyIdsOnCells(DataArrayInt *famIds, bool isNoCopy) { _cell_fam_ids=famIds; @@ -308,6 +374,22 @@ void MEDMeshMultiLev::setNumberIdsOnCells(DataArrayInt *numIds, bool isNoCopy) _cell_num_ids_nocpy=isNoCopy; } +void MEDMeshMultiLev::setFamilyIdsOnNodes(DataArrayInt *famIds, bool isNoCopy) +{ + _node_fam_ids=famIds; + if(famIds) + famIds->incrRef(); + _node_fam_ids_nocpy=isNoCopy; +} + +void MEDMeshMultiLev::setNumberIdsOnNodes(DataArrayInt *numIds, bool isNoCopy) +{ + _node_num_ids=numIds; + if(numIds) + numIds->incrRef(); + _node_num_ids_nocpy=isNoCopy; +} + std::string MEDMeshMultiLev::getPflNameOfId(int id) const { std::size_t sz(_pfls.size()); @@ -488,7 +570,7 @@ MEDMeshMultiLev::MEDMeshMultiLev():_nb_nodes(0),_cell_fam_ids_nocpy(false) { } -MEDMeshMultiLev::MEDMeshMultiLev(int nbNodes, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):_geo_types(gts),_nb_entities(nbEntities),_nb_nodes(nbNodes),_cell_fam_ids_nocpy(false),_cell_num_ids_nocpy(false) +MEDMeshMultiLev::MEDMeshMultiLev(int nbNodes, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):_geo_types(gts),_nb_entities(nbEntities),_nb_nodes(nbNodes),_cell_fam_ids_nocpy(false),_cell_num_ids_nocpy(false),_node_fam_ids_nocpy(false),_node_num_ids_nocpy(false) { std::size_t sz(_geo_types.size()); if(sz!=pfls.size() || sz!=nbEntities.size()) @@ -502,7 +584,7 @@ MEDMeshMultiLev::MEDMeshMultiLev(int nbNodes, const std::vector if(n) _cell_num_ids=DataArrayInt::Aggregate(tmps); } + // node part + _node_fam_ids_nocpy=true; + { + const DataArrayInt *tmp(m->getFamilyFieldAtLevel(1)); + if(tmp) + { + tmp->incrRef(); + _node_fam_ids=(const_cast(tmp)); + } + } + _node_num_ids_nocpy=true; + { + const DataArrayInt *tmp(m->getNumberFieldAtLevel(1)); + if(tmp) + { + tmp->incrRef(); + _node_num_ids=(const_cast(tmp)); + } + } } MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities) @@ -624,6 +725,14 @@ MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vectorgetNumberFieldAtLevel(lev)); if(numIds) { _cell_num_ids=const_cast(numIds); numIds->incrRef(); } + _node_fam_ids_nocpy=true; + famIds=m->getFamilyFieldAtLevel(1); + if(famIds) + { _node_fam_ids=const_cast(famIds); famIds->incrRef(); } + _node_num_ids_nocpy=true; + numIds=m->getNumberFieldAtLevel(1); + if(numIds) + { _node_num_ids=const_cast(numIds); numIds->incrRef(); } return ; } // @@ -653,6 +762,15 @@ MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vectorgetFamilyFieldAtLevel(1)); + if(nodeFamIds) + { _node_fam_ids=const_cast(nodeFamIds); nodeFamIds->incrRef(); } + _node_num_ids_nocpy=true; + const DataArrayInt *nodeNumIds(m->getNumberFieldAtLevel(1)); + if(nodeNumIds) + { _node_num_ids=const_cast(nodeNumIds); nodeNumIds->incrRef(); } } void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes) @@ -933,8 +1051,72 @@ MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev() { } -MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(int nbOfNodes, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDMeshMultiLev(nbOfNodes,gts,pfls,nbEntities) +MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector& lev) { + // ids fields management + _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true; + const DataArrayInt *tmp(0); + tmp=m->getFamilyFieldAtLevel(0); + if(tmp) + { + tmp->incrRef(); + _cell_fam_ids=const_cast(tmp); + } + tmp=m->getNumberFieldAtLevel(0); + if(tmp) + { + tmp->incrRef(); + _cell_num_ids=const_cast(tmp); + } + // + _node_fam_ids_nocpy=true; _node_num_ids_nocpy=true; + tmp=0; + tmp=m->getFamilyFieldAtLevel(1); + if(tmp) + { + tmp->incrRef(); + _node_fam_ids=const_cast(tmp); + } + tmp=m->getNumberFieldAtLevel(1); + if(tmp) + { + tmp->incrRef(); + _node_num_ids=const_cast(tmp); + } +} + +MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, int nbOfNodes, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDMeshMultiLev(nbOfNodes,gts,pfls,nbEntities) +{ + // ids fields management + _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true; + const DataArrayInt *tmp(0); + tmp=m->getFamilyFieldAtLevel(0); + if(tmp) + { + tmp->incrRef(); + _cell_fam_ids=const_cast(tmp); + } + tmp=m->getNumberFieldAtLevel(0); + if(tmp) + { + tmp->incrRef(); + _cell_num_ids=const_cast(tmp); + } + // + _node_fam_ids_nocpy=true; _node_num_ids_nocpy=true; + tmp=0; + tmp=m->getFamilyFieldAtLevel(1); + if(tmp) + { + tmp->incrRef(); + _node_fam_ids=const_cast(tmp); + } + tmp=m->getNumberFieldAtLevel(1); + if(tmp) + { + tmp->incrRef(); + _node_num_ids=const_cast(tmp); + } } void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes) @@ -978,7 +1160,7 @@ MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector return new MEDCMeshMultiLev(m,gts,pfls,nbEntities); } -MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector& levs) +MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector& levs):MEDStructuredMeshMultiLev(m,levs) { if(!m) throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !"); @@ -993,24 +1175,9 @@ MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !"); _coords[i]=elt; } - // ids fields management - _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true; - const DataArrayInt *tmp(0); - tmp=m->getFamilyFieldAtLevel(0); - if(tmp) - { - tmp->incrRef(); - _cell_fam_ids=const_cast(tmp); - } - tmp=m->getNumberFieldAtLevel(0); - if(tmp) - { - tmp->incrRef(); - _cell_num_ids=const_cast(tmp); - } } -MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDStructuredMeshMultiLev(m->getNumberOfNodes(),gts,pfls,nbEntities) +MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDStructuredMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities) { if(!m) throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !"); @@ -1028,21 +1195,6 @@ MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vectorincrRef(); } - // ids fields management - _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true; - const DataArrayInt *tmp(0); - tmp=m->getFamilyFieldAtLevel(0); - if(tmp) - { - tmp->incrRef(); - _cell_fam_ids=const_cast(tmp); - } - tmp=m->getNumberFieldAtLevel(0); - if(tmp) - { - tmp->incrRef(); - _cell_num_ids=const_cast(tmp); - } } MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords) @@ -1140,7 +1292,7 @@ MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLi return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities); } -MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector& levs) +MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector& levs):MEDStructuredMeshMultiLev(m,levs) { if(!m) throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !"); @@ -1152,24 +1304,9 @@ MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearM coords->incrRef(); _coords=coords; _structure=m->getMesh()->getNodeGridStructure(); - // ids fields management - _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true; - const DataArrayInt *tmp(0); - tmp=m->getFamilyFieldAtLevel(0); - if(tmp) - { - tmp->incrRef(); - _cell_fam_ids=const_cast(tmp); - } - tmp=m->getNumberFieldAtLevel(0); - if(tmp) - { - tmp->incrRef(); - _cell_num_ids=const_cast(tmp); - } } -MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDStructuredMeshMultiLev(m->getNumberOfNodes(),gts,pfls,nbEntities) +MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities):MEDStructuredMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities) { if(!m) throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !"); @@ -1184,21 +1321,6 @@ MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearM coords->incrRef(); _coords=coords; _structure=m->getMesh()->getNodeGridStructure(); - // ids fields management - _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true; - const DataArrayInt *tmp(0); - tmp=m->getFamilyFieldAtLevel(0); - if(tmp) - { - tmp->incrRef(); - _cell_fam_ids=const_cast(tmp); - } - tmp=m->getNumberFieldAtLevel(0); - if(tmp) - { - tmp->incrRef(); - _cell_num_ids=const_cast(tmp); - } } MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure) diff --git a/src/MEDLoader/MEDFileFieldOverView.hxx b/src/MEDLoader/MEDFileFieldOverView.hxx index cc1bdb67a..e8d13ebfe 100644 --- a/src/MEDLoader/MEDFileFieldOverView.hxx +++ b/src/MEDLoader/MEDFileFieldOverView.hxx @@ -39,6 +39,7 @@ namespace ParaMEDMEM class MEDFileMesh; class MEDFileUMesh; class MEDFileCMesh; + class MEDFileStructuredMesh; class MEDFileCurveLinearMesh; class MEDFileFieldGlobs; class MEDFileFieldGlobsReal; @@ -82,8 +83,12 @@ namespace ParaMEDMEM MEDLOADER_EXPORT DataArray *buildDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const; MEDLOADER_EXPORT void retrieveFamilyIdsOnCells(DataArrayInt *& famIds, bool& isWithoutCopy) const; MEDLOADER_EXPORT void retrieveNumberIdsOnCells(DataArrayInt *& numIds, bool& isWithoutCopy) const; + MEDLOADER_EXPORT void retrieveFamilyIdsOnNodes(DataArrayInt *& famIds, bool& isWithoutCopy) const; + MEDLOADER_EXPORT void retrieveNumberIdsOnNodes(DataArrayInt *& numIds, bool& isWithoutCopy) const; void setFamilyIdsOnCells(DataArrayInt *famIds, bool isNoCopy); void setNumberIdsOnCells(DataArrayInt *numIds, bool isNoCopy); + void setFamilyIdsOnNodes(DataArrayInt *famIds, bool isNoCopy); + void setNumberIdsOnNodes(DataArrayInt *numIds, bool isNoCopy); virtual void selectPartOfNodes(const DataArrayInt *pflNodes) = 0; virtual MEDMeshMultiLev *prepare() const = 0; int getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const; @@ -106,6 +111,10 @@ namespace ParaMEDMEM bool _cell_fam_ids_nocpy; MEDCouplingAutoRefCountObjectPtr _cell_num_ids; bool _cell_num_ids_nocpy; + MEDCouplingAutoRefCountObjectPtr _node_fam_ids; + bool _node_fam_ids_nocpy; + MEDCouplingAutoRefCountObjectPtr _node_num_ids; + bool _node_num_ids_nocpy; public: static const int PARAMEDMEM_2_VTKTYPE_LGTH=34; static const unsigned char PARAMEDMEM_2_VTKTYPE[PARAMEDMEM_2_VTKTYPE_LGTH]; @@ -140,7 +149,8 @@ namespace ParaMEDMEM protected: MEDStructuredMeshMultiLev(); MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other); - MEDStructuredMeshMultiLev(int nbOfNodes, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities); + MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector& lev); + MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, int nbOfNodes, const std::vector& gts, const std::vector& pfls, const std::vector& nbEntities); }; class MEDCMeshMultiLev : public MEDStructuredMeshMultiLev diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 9ee9521c1..06607db5e 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -2898,6 +2898,32 @@ namespace ParaMEDMEM PyTuple_SetItem(ret,1,ret1Py); return ret; } + + PyObject *retrieveFamilyIdsOnNodes() const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *famIds(0); + bool isWithoutCopy(false); + self->retrieveFamilyIdsOnNodes(famIds,isWithoutCopy); + PyObject *ret=PyTuple_New(2); + PyObject *ret1Py=isWithoutCopy?Py_True:Py_False; + Py_XINCREF(ret1Py); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(famIds),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,ret1Py); + return ret; + } + + PyObject *retrieveNumberIdsOnNodes() const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *numIds(0); + bool isWithoutCopy(false); + self->retrieveNumberIdsOnNodes(numIds,isWithoutCopy); + PyObject *ret=PyTuple_New(2); + PyObject *ret1Py=isWithoutCopy?Py_True:Py_False; + Py_XINCREF(ret1Py); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(numIds),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,ret1Py); + return ret; + } } }; -- 2.39.2