From: Anthony Geay Date: Mon, 23 Jan 2017 13:57:12 +0000 (+0100) Subject: Debugging before generation of classic fields/meshes from structure elements... X-Git-Tag: V8_3_0a2~38^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b3e28553eab4c76446ec4214ad4a8d71528905ab;p=tools%2Fmedcoupling.git Debugging before generation of classic fields/meshes from structure elements... --- diff --git a/src/MEDCoupling/MCAuto.hxx b/src/MEDCoupling/MCAuto.hxx index 6614cbfdf..0fd3a97af 100644 --- a/src/MEDCoupling/MCAuto.hxx +++ b/src/MEDCoupling/MCAuto.hxx @@ -101,7 +101,7 @@ namespace MEDCoupling const T& operator*() const { return *_ptr; } operator const T *() const { return _ptr; } private: - void referPtr(T *ptr) { _ptr=ptr; if(_ptr) _ptr->incrRef(); } + void referPtr(const T *ptr) { _ptr=ptr; if(_ptr) _ptr->incrRef(); } void destroyPtr() { if(_ptr) _ptr->decrRef(); } private: const T *_ptr; diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 117d694b6..61b2b0660 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -432,7 +432,7 @@ std::vector MEDFileFieldPerMeshPerTypePerDisc::getDirec MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::deepCopy(MEDFileFieldPerMeshPerTypeCommon *father) const { - MCAuto ret=new MEDFileFieldPerMeshPerTypePerDisc(*this); + MCAuto ret(new MEDFileFieldPerMeshPerTypePerDisc(*this)); ret->_father=father; return ret.retn(); } @@ -1761,9 +1761,12 @@ std::string MEDFileFieldPerMeshPerTypeDyn::getGeoTypeRepr() const throw INTERP_KERNEL::Exception("not implemented yet !"); } -MEDFileFieldPerMeshPerType *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const +MEDFileFieldPerMeshPerTypeDyn *MEDFileFieldPerMeshPerTypeDyn::deepCopy(MEDFileFieldPerMesh *father) const { - throw INTERP_KERNEL::Exception("not implemented yet !"); + MCAuto ret(new MEDFileFieldPerMeshPerTypeDyn(*this)); + ret->setFather(father); + ret->deepCopyElements(); + return ret.retn(); } void MEDFileFieldPerMeshPerTypeDyn::getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair >& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const @@ -2015,6 +2018,21 @@ void MEDFileFieldPerMesh::killStructureElements() _field_pm_pt=res; } +void MEDFileFieldPerMesh::keepOnlyStructureElements() +{ + std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > > res; + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) + { + if((*it).isNotNull()) + { + const MEDFileFieldPerMeshPerTypeDyn *pt(dynamic_cast((const MEDFileFieldPerMeshPerTypeCommon *)*it)); + if(pt) + res.push_back(*it); + } + } + _field_pm_pt=res; +} + DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() { if(!_father) @@ -5041,6 +5059,13 @@ void MEDFileAnyTypeField1TSWithoutSDA::killStructureElements() (*it)->killStructureElements(); } +void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements() +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + if((*it).isNotNull()) + (*it)->keepOnlyStructureElements(); +} + MEDCouplingFieldDouble *MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh(const MEDFileFieldGlobsReal *glob, const MEDFileMesh *mesh, MCAuto& arrOut, const MEDFileFieldNameScope& nasc) const { static const char MSG0[]="MEDFileAnyTypeField1TSWithoutSDA::fieldOnMesh : the field is too complex to be able to be extracted with \"field\" method ! Call getFieldOnMeshAtLevel method instead to deal with complexity !"; @@ -7496,7 +7521,7 @@ bool MEDFileAnyTypeFieldMultiTSWithoutSDA::onlyStructureElements() const void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements() { - std::vector< MCAuto > res; + std::vector< MCAuto > ret; for(std::vector< MCAuto >::iterator it=_time_steps.begin();it!=_time_steps.end();it++) if((*it).isNotNull()) { @@ -7505,15 +7530,31 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::killStructureElements() if(!(*it)->onlyStructureElements()) { (*it)->killStructureElements(); - res.push_back(*it); + ret.push_back(*it); } } else { - res.push_back(*it); + ret.push_back(*it); + } + } + _time_steps=ret; +} + +void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements() +{ + std::vector< MCAuto > ret; + for(std::vector< MCAuto >::iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + { + if((*it)->presenceOfStructureElements()) + { + if(!(*it)->onlyStructureElements()) + (*it)->keepOnlyStructureElements(); + ret.push_back(*it); } } - _time_steps=res; + _time_steps=ret; } bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const @@ -11031,17 +11072,35 @@ void MEDFileFields::killStructureElements() ret.push_back(*it); } } + else + { + ret.push_back(*it); + } } - else + _fields=ret; +} + +void MEDFileFields::keepOnlyStructureElements() +{ + std::vector< MCAuto > ret; + for(std::vector< MCAuto >::iterator it=_fields.begin();it!=_fields.end();it++) + if((*it).isNotNull()) { - ret.push_back(*it); + if((*it)->presenceOfStructureElements()) + { + if(!(*it)->onlyStructureElements()) + (*it)->keepOnlyStructureElements(); + ret.push_back(*it); + } } _fields=ret; } - + MCAuto MEDFileFields::partOfThisOnStructureElements() const { - throw INTERP_KERNEL::Exception("partOfThisOnStructureElements : not implemented yet !"); + MCAuto ret(deepCopy()); + ret->keepOnlyStructureElements(); + return ret; } MEDFileFieldsIterator *MEDFileFields::iterator() diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 8995fc045..f283c9356 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -278,7 +278,7 @@ namespace MEDCoupling void entriesForMEDfile(TypeOfField mct, med_geometry_type& gt, med_entity_type& ent) const; void simpleRepr(int bkOffset, std::ostream& oss, int id) const; std::string getGeoTypeRepr() const; - MEDFileFieldPerMeshPerType *deepCopy(MEDFileFieldPerMesh *father) const; + MEDFileFieldPerMeshPerTypeDyn *deepCopy(MEDFileFieldPerMesh *father) const; void getFieldAtLevel(int meshDim, TypeOfField type, const MEDFileFieldGlobsReal *glob, std::vector< std::pair >& dads, std::vector& pfls, std::vector& locs, std::vector& geoTypes) const; private: MEDFileFieldPerMeshPerTypeDyn(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileStructureElement *se, const MEDFileFieldNameScope& nasc); @@ -320,6 +320,7 @@ namespace MEDCoupling bool presenceOfStructureElements() const; bool onlyStructureElements() const; void killStructureElements(); + void keepOnlyStructureElements(); DataArray *getOrCreateAndGetArray(); const DataArray *getOrCreateAndGetArray() const; const std::vector& getInfo() const; @@ -561,6 +562,7 @@ namespace MEDCoupling MEDLOADER_EXPORT bool presenceOfStructureElements() const; MEDLOADER_EXPORT bool onlyStructureElements() const; MEDLOADER_EXPORT void killStructureElements(); + MEDLOADER_EXPORT void keepOnlyStructureElements(); MEDLOADER_EXPORT void setInfo(const std::vector& infos); MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; @@ -916,6 +918,7 @@ namespace MEDCoupling MEDLOADER_EXPORT bool presenceOfStructureElements() const; MEDLOADER_EXPORT bool onlyStructureElements() const; MEDLOADER_EXPORT void killStructureElements(); + MEDLOADER_EXPORT void keepOnlyStructureElements(); MEDLOADER_EXPORT int getPosOfTimeStep(int iteration, int order) const; MEDLOADER_EXPORT int getPosGivenTime(double time, double eps=1e-8) const; MEDLOADER_EXPORT std::vector< std::pair > getIterations() const; @@ -1067,6 +1070,7 @@ namespace MEDCoupling MEDLOADER_EXPORT const std::vector& getInfo() const; MEDLOADER_EXPORT bool presenceOfMultiDiscPerGeoType() const; MEDLOADER_EXPORT void killStructureElements(); + MEDLOADER_EXPORT void keepOnlyStructureElements(); MEDLOADER_EXPORT void setInfo(const std::vector& info); MEDLOADER_EXPORT int getNumberOfComponents() const; MEDLOADER_EXPORT int getNonEmptyLevels(int iteration, int order, const std::string& mname, std::vector& levs) const; @@ -1246,6 +1250,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileFields *partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair >& timeSteps) const; MEDLOADER_EXPORT bool presenceOfStructureElements() const; MEDLOADER_EXPORT void killStructureElements(); + MEDLOADER_EXPORT void keepOnlyStructureElements(); MEDLOADER_EXPORT MCAuto partOfThisOnStructureElements() const; MEDLOADER_EXPORT MEDFileFieldsIterator *iterator(); MEDLOADER_EXPORT void destroyFieldAtPos(int i); diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index b3a76b444..d3e93c441 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -2091,8 +2091,8 @@ MEDFileEltStruct4Mesh::MEDFileEltStruct4Mesh(med_idt fid, const std::string& mNa } MCAuto mss(MEDFileMeshSupports::New(fid)); MCAuto mse(MEDFileStructureElements::New(fid,mss)); - int nbOfNodesPerCell(mse->getNumberOfNodesPerCellOf(_geo_type_name)); - _conn=DataArrayInt::New(); _conn->alloc(nCells,nbOfNodesPerCell); + int nbEntities(mse->getNumberOfNodesPerSE(_geo_type_name)); + _conn=DataArrayInt::New(); _conn->alloc(nCells,nbEntities); MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,_geo_type,MED_NODAL,MED_FULL_INTERLACE,_conn->getPointer())); _common=MEDFileUMeshPerTypeCommon::New(); _common->loadCommonPart(fid,mName.c_str(),dt,it,nCells,geoType,MED_STRUCT_ELEMENT,mrs); diff --git a/src/MEDLoader/MEDFileMeshSupport.cxx b/src/MEDLoader/MEDFileMeshSupport.cxx index 6958cb02a..9f8daa813 100644 --- a/src/MEDLoader/MEDFileMeshSupport.cxx +++ b/src/MEDLoader/MEDFileMeshSupport.cxx @@ -111,8 +111,22 @@ const MEDFileUMesh *MEDFileMeshSupports::getSupMeshWithName(const std::string& n throw INTERP_KERNEL::Exception(oss.str()); } -int MEDFileMeshSupports::getNumberOfNodesPerCellOf(const std::string& name) const +int MEDFileMeshSupports::getNumberOfNodesInConnOf(TypeOfField entity, const std::string& name) const { const MEDFileUMesh *sup(getSupMeshWithName(name)); - return sup->getNumberOfNodes(); + switch(entity) + { + case ON_NODES: + return sup->getNumberOfNodes(); + case ON_CELLS: + { + std::vector gt(sup->getAllGeoTypes()); + if(gt.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileMeshSupports::getNumberOfNodesInConnOf : on cells only one geometric type allowed !"); + const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(gt[0])); + return sup->getNumberOfCellsAtLevel(0)*cm.getNumberOfNodes(); + } + default: + throw INTERP_KERNEL::Exception("MEDFileMeshSupports::getNumberOfNodesInConnOf : not recognized entity type !"); + } } diff --git a/src/MEDLoader/MEDFileMeshSupport.hxx b/src/MEDLoader/MEDFileMeshSupport.hxx index 7f7569422..b47d69b8c 100644 --- a/src/MEDLoader/MEDFileMeshSupport.hxx +++ b/src/MEDLoader/MEDFileMeshSupport.hxx @@ -40,7 +40,7 @@ namespace MEDCoupling std::size_t getHeapMemorySizeWithoutChildren() const; void writeLL(med_idt fid) const; const MEDFileUMesh *getSupMeshWithName(const std::string& name) const; - int getNumberOfNodesPerCellOf(const std::string& name) const; + int getNumberOfNodesInConnOf(TypeOfField entity, const std::string& name) const; private: MEDFileMeshSupports(med_idt fid); MEDFileMeshSupports(); diff --git a/src/MEDLoader/MEDFileStructureElement.cxx b/src/MEDLoader/MEDFileStructureElement.cxx index e174bf60b..c8b2e1729 100644 --- a/src/MEDLoader/MEDFileStructureElement.cxx +++ b/src/MEDLoader/MEDFileStructureElement.cxx @@ -371,11 +371,13 @@ const MEDFileStructureElement *MEDFileStructureElements::getWithGT(int idGT) con throw INTERP_KERNEL::Exception(oss.str()); } -int MEDFileStructureElements::getNumberOfNodesPerCellOf(const std::string& seName) const +int MEDFileStructureElements::getNumberOfNodesPerSE(const std::string& seName) const { + if(seName=="MED_PARTICLE") + return 1; const MEDFileStructureElement *se(getSEWithName(seName)); std::string meshName(se->getMeshName()); - return _sup->getNumberOfNodesPerCellOf(meshName); + return _sup->getNumberOfNodesInConnOf(se->getEntity(),meshName); } const MEDFileStructureElement *MEDFileStructureElements::getSEWithName(const std::string& seName) const diff --git a/src/MEDLoader/MEDFileStructureElement.hxx b/src/MEDLoader/MEDFileStructureElement.hxx index 05efa66b1..083ab5aef 100644 --- a/src/MEDLoader/MEDFileStructureElement.hxx +++ b/src/MEDLoader/MEDFileStructureElement.hxx @@ -121,7 +121,7 @@ class MEDFileSEConstAtt : public RefCountObject, public MEDFileWritableStandAlon MEDLOADER_EXPORT int getNumberOf() const; MEDLOADER_EXPORT std::vector getDynGTAvail() const; MEDLOADER_EXPORT const MEDFileStructureElement *getWithGT(int idGT) const; - MEDLOADER_EXPORT int getNumberOfNodesPerCellOf(const std::string& seName) const; + MEDLOADER_EXPORT int getNumberOfNodesPerSE(const std::string& seName) const; MEDLOADER_EXPORT const MEDFileStructureElement *getSEWithName(const std::string& seName) const; MEDLOADER_EXPORT std::vector getVarAttsOf(const std::string& seName) const; MEDLOADER_EXPORT const MEDFileSEVarAtt *getVarAttOf(const std::string &seName, const std::string& varName) const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index da768d905..aa0d5ab2a 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -3023,6 +3023,7 @@ namespace MEDCoupling MEDFileFields *partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const throw(INTERP_KERNEL::Exception); bool presenceOfStructureElements() const throw(INTERP_KERNEL::Exception); void killStructureElements() throw(INTERP_KERNEL::Exception); + void keepOnlyStructureElements() throw(INTERP_KERNEL::Exception); void destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception); bool removeFieldsWithoutAnyTimeStep() throw(INTERP_KERNEL::Exception); %extend