From e5bbb0e7c6dfd96e0f1ca05864c6c5276f822f49 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 28 Nov 2022 15:43:23 +0100 Subject: [PATCH] [EDF26451] : implementation of MEDFileMesh.addGroupsAtLevel --- src/MEDLoader/MEDFileMesh.cxx | 11 +++++++++++ src/MEDLoader/MEDFileMesh.hxx | 1 + src/MEDLoader/Swig/MEDLoaderCommon.i | 7 +++++++ src/MEDLoader/Swig/MEDLoaderTest4.py | 27 +++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index e61ac9c6d..9a2e20afe 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -1989,6 +1989,17 @@ std::string MEDFileMesh::simpleRepr() const return oss.str(); } +/*! + * Simple loop over MEDFileMesh::addGroup method. + * + * \sa MEDFileMesh::addGroup + */ +void MEDFileMesh::addGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps) +{ + for(auto grp : grps) + this->addGroup(meshDimRelToMaxExt,grp); +} + /*! * This method is nearly like getFamilyFieldAtLevel method. Except that if the array does not exist at the specified level \a meshDimRelToMaxExt * an empty one is created. diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 9eaa94f93..171f6aab2 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -170,6 +170,7 @@ namespace MEDCoupling MEDLOADER_EXPORT virtual int getSpaceDimension() const = 0; MEDLOADER_EXPORT virtual std::string simpleRepr() const; MEDLOADER_EXPORT virtual std::string advancedRepr() const = 0; + MEDLOADER_EXPORT void addGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps); // MEDLOADER_EXPORT virtual void setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector& grps, bool renum=false); MEDLOADER_EXPORT virtual void setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayIdType *famArr) = 0; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index b33167ffc..4befee342 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -1277,6 +1277,13 @@ namespace MEDCoupling self->setGroupsAtLevel(meshDimRelToMaxExt,grps,renum); } + void addGroupsAtLevel(int meshDimRelToMaxExt, PyObject *grps) + { + std::vector grpsCpp; + convertFromPyObjVectorOfObj(grps,SWIGTITraits::TI,"DataArrayInt",grpsCpp); + self->addGroupsAtLevel(meshDimRelToMaxExt,grpsCpp); + } + PyObject *areFamsEqual(const MEDFileMesh *other) const { std::string what; diff --git a/src/MEDLoader/Swig/MEDLoaderTest4.py b/src/MEDLoader/Swig/MEDLoaderTest4.py index c81ec4b0a..c33c092d6 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest4.py +++ b/src/MEDLoader/Swig/MEDLoaderTest4.py @@ -5676,6 +5676,33 @@ class MEDLoaderTest4(unittest.TestCase): self.assertTrue( cas2.getGroupArr(0, "GNODE1").isEqualWithoutConsideringStr( DataArrayInt([]) ) ) # Expected to return empty array on both cases self.assertTrue( cas1.getGroupArr(1, "GCELL1").isEqualWithoutConsideringStr( DataArrayInt([]) ) ) # Expected to return empty array on both cases + def test45(self): + """ + EDF26451 : addGroupsAtLevel + """ + arr = DataArrayDouble([0,1,2,3]) + cmesh = MEDCouplingCMesh("TEST") + cmesh.setCoords(arr, arr, arr) + umesh3d = cmesh.buildUnstructured() + umesh2d = umesh3d.computeSkin() + + cas1 = MEDFileUMesh() + + cas1[0] = umesh3d + cas1[-1] = umesh2d + + gcell1 = DataArrayInt([1,2,4]) ; gcell1.setName("GCELL1") + cas1.setGroupsAtLevel(0, [gcell1]) + + gcell2 = DataArrayInt([2,5,6,7]) ; gcell2.setName("GCELL2") + gcell3 = DataArrayInt([5,16,17,26]) ; gcell3.setName("GCELL3") + + cas1.addGroupsAtLevel(0,[gcell2,gcell3]) # <- the aim of the test is here + self.assertEqual( cas1.getGroupsOnSpecifiedLev(0) , ("GCELL1","GCELL2","GCELL3") ) + self.assertTrue( cas1.getGroupArr(0,"GCELL1").isEqual(gcell1) ) + self.assertTrue( cas1.getGroupArr(0,"GCELL2").isEqual(gcell2) ) + self.assertTrue( cas1.getGroupArr(0,"GCELL3").isEqual(gcell3) ) + pass if __name__ == "__main__": -- 2.39.2