From: geay Date: Wed, 5 Mar 2014 11:46:47 +0000 (+0100) Subject: Addition of a method in MEDFileFields to filter empty fields X-Git-Tag: V7_4_0a1~23 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5a1441203b390592f0154134c602738c0e741361;p=tools%2Fmedcoupling.git Addition of a method in MEDFileFields to filter empty fields --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 04ad5b5b7..ffed76bff 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -9925,6 +9925,30 @@ MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldWithName(const std::string& f return getFieldAtPos(getPosFromFieldName(fieldName)); } +/*! + * This method removes, if any, fields in \a this having no time steps. + * If there is one or more than one such field in \a this true is returned and those fields will not be referenced anymore in \a this. + * + * If false is returned \a this does not contain such fields. If false is returned this method can be considered as const. + */ +bool MEDFileFields::removeFieldsWithoutAnyTimeStep() +{ + std::vector > newFields; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_fields.begin();it!=_fields.end();it++) + { + const MEDFileAnyTypeFieldMultiTSWithoutSDA *elt(*it); + if(elt) + { + if(elt->getNumberOfTS()>0) + newFields.push_back(*it); + } + } + if(_fields.size()==newFields.size()) + return false; + _fields=newFields; + return true; +} + /*! * This method returns a new object containing part of \a this fields lying on mesh name specified by the input parameter \a meshName. * This method can be seen as a filter applied on \a this, that returns an object containing diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index c63f95cf8..4a8f1e552 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -1101,6 +1101,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *getFieldAtPos(int i) const; MEDLOADER_EXPORT MEDFileAnyTypeFieldMultiTS *getFieldWithName(const std::string& fieldName) const; MEDLOADER_EXPORT MEDFileFields *buildSubPart(const int *startIds, const int *endIds) const; + MEDLOADER_EXPORT bool removeFieldsWithoutAnyTimeStep(); MEDLOADER_EXPORT MEDFileFields *partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const; MEDLOADER_EXPORT MEDFileFields *partOfThisLyingOnSpecifiedTimeSteps(const std::vector< std::pair >& timeSteps) const; MEDLOADER_EXPORT MEDFileFields *partOfThisNotLyingOnSpecifiedTimeSteps(const std::vector< std::pair >& timeSteps) const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index c88e65e15..851cb7374 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -2236,6 +2236,7 @@ namespace ParaMEDMEM MEDFileAnyTypeFieldMultiTS *getFieldWithName(const std::string& fieldName) const throw(INTERP_KERNEL::Exception); MEDFileFields *partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const throw(INTERP_KERNEL::Exception); void destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception); + bool removeFieldsWithoutAnyTimeStep() throw(INTERP_KERNEL::Exception); %extend { MEDFileFields() diff --git a/src/MEDLoader/Swig/MEDLoaderTest4.py b/src/MEDLoader/Swig/MEDLoaderTest4.py index 24d7f25c5..b176a7c7b 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest4.py +++ b/src/MEDLoader/Swig/MEDLoaderTest4.py @@ -151,6 +151,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) # False is important to not read the values + fields.removeFieldsWithoutAnyTimeStep() refMem=fields.getHeapMemorySize() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] @@ -362,6 +363,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -523,6 +525,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -773,6 +776,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -900,6 +904,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -1061,6 +1066,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -1265,6 +1271,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -1459,6 +1466,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -1602,6 +1610,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -1730,6 +1739,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -1828,6 +1838,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -1918,6 +1929,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -2030,6 +2042,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -2181,6 +2194,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -2338,6 +2352,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -2525,6 +2540,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -2596,6 +2612,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -2707,6 +2724,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -2872,6 +2890,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -3051,6 +3070,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -3247,6 +3267,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -3354,6 +3375,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -3454,6 +3476,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -3557,6 +3580,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) # false is absolutely necessary for the test + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -3766,6 +3790,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: @@ -3876,6 +3901,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() self.assertEqual(fields[0].getMeshName(),"mesh") self.assertEqual(fields[1].getMeshName(),"mesh") fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] @@ -4017,6 +4043,7 @@ class MEDLoaderTest4(unittest.TestCase): ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values ms=MEDFileMeshes(fname) fields=MEDFileFields(fname,False) + fields.removeFieldsWithoutAnyTimeStep() fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()] allFMTSLeavesToDisplay=[] for fields in fields_per_mesh: