From 7a0c870ba456af9ab7bc3155bb85ea36fd23452e Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 23 Jan 2017 17:04:33 +0100 Subject: [PATCH] Fields have been cut in elements. Now ready for last step --- src/MEDCoupling/MCAuto.hxx | 1 + src/MEDLoader/CMakeLists.txt | 1 + src/MEDLoader/MEDFileBlowStrEltUp.cxx | 40 ++++++++ src/MEDLoader/MEDFileBlowStrEltUp.hxx | 45 +++++++++ src/MEDLoader/MEDFileField.cxx | 122 ++++++++++++++++++++++++- src/MEDLoader/MEDFileField.hxx | 12 ++- src/MEDLoader/Swig/MEDLoaderCommon.i | 14 +++ src/MEDLoader/Swig/MEDLoaderTypemaps.i | 14 +++ 8 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 src/MEDLoader/MEDFileBlowStrEltUp.cxx create mode 100644 src/MEDLoader/MEDFileBlowStrEltUp.hxx diff --git a/src/MEDCoupling/MCAuto.hxx b/src/MEDCoupling/MCAuto.hxx index 0fd3a97af..06f728620 100644 --- a/src/MEDCoupling/MCAuto.hxx +++ b/src/MEDCoupling/MCAuto.hxx @@ -85,6 +85,7 @@ namespace MEDCoupling { public: MCConstAuto(const MCConstAuto& other):_ptr(0) { referPtr(other._ptr); } + MCConstAuto(const typename MEDCoupling::MCAuto & other):_ptr(0) { referPtr( (const T*) other); } MCConstAuto(const T *ptr=0):_ptr(ptr) { } ~MCConstAuto() { destroyPtr(); } bool isNull() const { return _ptr==0; } diff --git a/src/MEDLoader/CMakeLists.txt b/src/MEDLoader/CMakeLists.txt index de68f97d8..e89bfd5bf 100644 --- a/src/MEDLoader/CMakeLists.txt +++ b/src/MEDLoader/CMakeLists.txt @@ -72,6 +72,7 @@ SET(medloader_SOURCES MEDFileMeshSupport.cxx MEDFileStructureElement.cxx MEDFileEntities.cxx + MEDFileBlowStrEltUp.cxx SauvMedConvertor.cxx SauvReader.cxx SauvWriter.cxx diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.cxx b/src/MEDLoader/MEDFileBlowStrEltUp.cxx new file mode 100644 index 000000000..9d10247df --- /dev/null +++ b/src/MEDLoader/MEDFileBlowStrEltUp.cxx @@ -0,0 +1,40 @@ +// Copyright (C) 2007-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#include "MEDFileBlowStrEltUp.hxx" + +using namespace MEDCoupling; + +MEDFileBlowStrEltUp::MEDFileBlowStrEltUp(const MEDFileFields *fsOnlyOnSE, const MEDFileMeshes *ms, const MEDFileStructureElements *ses) +{ + if(!fsOnlyOnSE || !ms || !ses) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp constructor : NULL input pointer !"); + _ms.takeRef(ms); _ses.takeRef(ses); + std::vector< std::pair > ps; + fsOnlyOnSE->getMeshSENames(ps); + std::size_t sz(ps.size()); + _elts.resize(sz); + for(std::size_t i=0;i& p(ps[i]); + MCAuto f(fsOnlyOnSE->partOfThisLyingOnSpecifiedMeshSEName(p.first,p.second)); + _elts[i]=f; + } +} diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.hxx b/src/MEDLoader/MEDFileBlowStrEltUp.hxx new file mode 100644 index 000000000..6930f352c --- /dev/null +++ b/src/MEDLoader/MEDFileBlowStrEltUp.hxx @@ -0,0 +1,45 @@ +// Copyright (C) 2007-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony Geay (EDF R&D) + +#ifndef __MEDFILEBLOWSTRELTUP_HXX__ +#define __MEDFILEBLOWSTRELTUP_HXX__ + +#include "MEDLoaderDefines.hxx" +#include "MEDFileUtilities.txx" +#include "MEDFileMesh.hxx" +#include "MEDFileField.hxx" +#include "MEDFileStructureElement.hxx" + +#include "MEDCouplingRefCountObject.hxx" + +namespace MEDCoupling +{ + class MEDFileBlowStrEltUp + { + public: + MEDFileBlowStrEltUp(const MEDFileFields *fsOnlyOnSE, const MEDFileMeshes *ms, const MEDFileStructureElements *ses); + private: + std::vector< MCAuto > _elts; + MCConstAuto _ms; + MCConstAuto _ses; + }; +} + +#endif diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 61b2b0660..c6c13a44b 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -1720,6 +1720,11 @@ int MEDFileFieldPerMeshPerTypeDyn::getDynGT() const return _se->getDynGT(); } +std::string MEDFileFieldPerMeshPerTypeDyn::getModelName() const +{ + return _se->getName(); +} + void MEDFileFieldPerMeshPerTypeDyn::getDimension(int& dim) const { throw INTERP_KERNEL::Exception("not implemented yet !"); @@ -2033,6 +2038,40 @@ void MEDFileFieldPerMesh::keepOnlyStructureElements() _field_pm_pt=res; } +void MEDFileFieldPerMesh::keepOnlyOnSE(const std::string& seName) +{ + 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) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::keepOnlyOnSE : presence of non SE !"); + if(pt->getModelName()==seName) + res.push_back(*it); + } + } + _field_pm_pt=res; +} + +void MEDFileFieldPerMesh::getMeshSENames(std::vector< std::pair >& ps) const +{ + for(std::vector< MCAuto< MEDFileFieldPerMeshPerTypeCommon > >::const_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) + { + ps.push_back(std::pair(getMeshName(),pt->getModelName())); + } + else + throw INTERP_KERNEL::Exception("MEDFileFieldPerMesh::getMeshSENames : presence of a non structure element part !"); + } + } +} + DataArray *MEDFileFieldPerMesh::getOrCreateAndGetArray() { if(!_father) @@ -5066,6 +5105,20 @@ void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyStructureElements() (*it)->keepOnlyStructureElements(); } +void MEDFileAnyTypeField1TSWithoutSDA::keepOnlyOnSE(const std::string& seName) +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + if((*it).isNotNull()) + (*it)->keepOnlyOnSE(seName); +} + +void MEDFileAnyTypeField1TSWithoutSDA::getMeshSENames(std::vector< std::pair >& ps) const +{ + for(std::vector< MCAuto< MEDFileFieldPerMesh > >::const_iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + if((*it).isNotNull()) + (*it)->getMeshSENames(ps); +} + 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 !"; @@ -7557,6 +7610,41 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyStructureElements() _time_steps=ret; } +void MEDFileAnyTypeFieldMultiTSWithoutSDA::keepOnlyOnSE(const std::string& seName) +{ + std::vector< MCAuto > ret; + for(std::vector< MCAuto >::iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + (*it)->keepOnlyOnSE(seName); +} + +void MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames(std::vector< std::pair >& ps) const +{ + std::vector< std::pair > ps2; + for(std::vector< MCAuto >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + { + (*it)->getMeshSENames(ps2); + break; + } + if(ps2.empty()) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : this appears to not contain SE only !"); + for(std::vector< MCAuto >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + if((*it).isNotNull()) + { + std::vector< std::pair > ps3; + (*it)->getMeshSENames(ps3); + if(ps2!=ps3) + throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTSWithoutSDA::getMeshSENames : For the moment only homogeneous SE def through time managed !"); + } + for(std::vector< std::pair >::const_iterator it=ps2.begin();it!=ps2.end();it++) + { + std::vector< std::pair >::iterator it2(std::find(ps.begin(),ps.end(),*it)); + if(it2==ps.end()) + ps.push_back(*it); + } +} + bool MEDFileAnyTypeFieldMultiTSWithoutSDA::presenceOfMultiDiscPerGeoType() const { for(std::vector< MCAuto >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) @@ -11095,7 +11183,32 @@ void MEDFileFields::keepOnlyStructureElements() } _fields=ret; } - + +void MEDFileFields::keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName) +{ + std::vector< MCAuto > ret; + for(std::vector< MCAuto >::iterator it=_fields.begin();it!=_fields.end();it++) + if((*it).isNotNull()) + { + if((*it)->getMeshName()!=meshName) + continue; + std::vector< std::pair > ps; + (*it)->getMeshSENames(ps); + std::pair p(meshName,seName); + if(std::find(ps.begin(),ps.end(),p)!=ps.end()) + (*it)->keepOnlyOnSE(seName); + ret.push_back(*it); + } + _fields=ret; +} + +void MEDFileFields::getMeshSENames(std::vector< std::pair >& ps) const +{ + for(std::vector< MCAuto >::const_iterator it=_fields.begin();it!=_fields.end();it++) + if((*it).isNotNull()) + (*it)->getMeshSENames(ps); +} + MCAuto MEDFileFields::partOfThisOnStructureElements() const { MCAuto ret(deepCopy()); @@ -11103,6 +11216,13 @@ MCAuto MEDFileFields::partOfThisOnStructureElements() const return ret; } +MCAuto MEDFileFields::partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const +{ + MCAuto ret(deepCopy()); + ret->keepOnlyOnMeshSE(meshName,seName); + return ret; +} + MEDFileFieldsIterator *MEDFileFields::iterator() { return new MEDFileFieldsIterator(this); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index f283c9356..1be649510 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -272,6 +272,7 @@ namespace MEDCoupling public: static MEDFileFieldPerMeshPerTypeDyn *NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, const MEDFileEntities *entities, int idGT, const MEDFileFieldNameScope& nasc); int getDynGT() const; + std::string getModelName() const; public: void getDimension(int& dim) const; INTERP_KERNEL::NormalizedCellType getGeoType() const; @@ -321,6 +322,8 @@ namespace MEDCoupling bool onlyStructureElements() const; void killStructureElements(); void keepOnlyStructureElements(); + void keepOnlyOnSE(const std::string& seName); + void getMeshSENames(std::vector< std::pair >& ps) const; DataArray *getOrCreateAndGetArray(); const DataArray *getOrCreateAndGetArray() const; const std::vector& getInfo() const; @@ -563,6 +566,8 @@ namespace MEDCoupling MEDLOADER_EXPORT bool onlyStructureElements() const; MEDLOADER_EXPORT void killStructureElements(); MEDLOADER_EXPORT void keepOnlyStructureElements(); + MEDLOADER_EXPORT void keepOnlyOnSE(const std::string& seName); + MEDLOADER_EXPORT void getMeshSENames(std::vector< std::pair >& ps) const; MEDLOADER_EXPORT void setInfo(const std::vector& infos); MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; @@ -919,6 +924,8 @@ namespace MEDCoupling MEDLOADER_EXPORT bool onlyStructureElements() const; MEDLOADER_EXPORT void killStructureElements(); MEDLOADER_EXPORT void keepOnlyStructureElements(); + MEDLOADER_EXPORT void keepOnlyOnSE(const std::string& seName); + MEDLOADER_EXPORT void getMeshSENames(std::vector< std::pair >& ps) const; 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; @@ -1069,8 +1076,6 @@ namespace MEDCoupling MEDLOADER_EXPORT bool changeMeshNames(const std::vector< std::pair >& modifTab); 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; @@ -1251,7 +1256,10 @@ namespace MEDCoupling MEDLOADER_EXPORT bool presenceOfStructureElements() const; MEDLOADER_EXPORT void killStructureElements(); MEDLOADER_EXPORT void keepOnlyStructureElements(); + MEDLOADER_EXPORT void keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName); + MEDLOADER_EXPORT void getMeshSENames(std::vector< std::pair >& ps) const; MEDLOADER_EXPORT MCAuto partOfThisOnStructureElements() const; + MEDLOADER_EXPORT MCAuto partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const; MEDLOADER_EXPORT MEDFileFieldsIterator *iterator(); MEDLOADER_EXPORT void destroyFieldAtPos(int i); MEDLOADER_EXPORT void destroyFieldsAtPos(const int *startIds, const int *endIds); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index aa0d5ab2a..abd8b7b33 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -3024,6 +3024,7 @@ namespace MEDCoupling bool presenceOfStructureElements() const throw(INTERP_KERNEL::Exception); void killStructureElements() throw(INTERP_KERNEL::Exception); void keepOnlyStructureElements() throw(INTERP_KERNEL::Exception); + void keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName) throw(INTERP_KERNEL::Exception); void destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception); bool removeFieldsWithoutAnyTimeStep() throw(INTERP_KERNEL::Exception); %extend @@ -3059,6 +3060,12 @@ namespace MEDCoupling MCAuto ret(self->partOfThisOnStructureElements()); return ret.retn(); } + + MEDFileFields *partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const throw(INTERP_KERNEL::Exception) + { + MCAuto ret(self->partOfThisLyingOnSpecifiedMeshSEName(meshName,seName)); + return ret.retn(); + } static MEDFileFields *LoadSpecificEntities(const std::string& fileName, PyObject *entities, bool loadAll=true) throw(INTERP_KERNEL::Exception) { @@ -3073,6 +3080,13 @@ namespace MEDCoupling return MEDFileFields::LoadSpecificEntities(fileName,entitiesCpp,loadAll); } + PyObject *getMeshSENames() const throw(INTERP_KERNEL::Exception) + { + std::vector< std::pair > ps; + self->getMeshSENames(ps); + return convertVectPairStToPy(ps); + } + PyObject *getCommonIterations() const throw(INTERP_KERNEL::Exception) { bool ret1; diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index 9df1cb801..0cf84bc09 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -229,6 +229,20 @@ PyObject *convertVecPairVecStToPy(const std::vector< std::pair >& vec) +{ + int sz=(int)vec.size(); + PyObject *ret=PyList_New(sz); + for(int i=0;i > convertVecPairStStFromPy(PyObject *pyLi) { std::vector< std::pair > ret; -- 2.39.2