From: ageay Date: Wed, 5 Feb 2014 12:10:55 +0000 (+0000) Subject: MEDFileMesh::getGeoTypesAtLevel has been virtualized. X-Git-Tag: V7_3_1b1^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=583bd4aac59f1c4e3a4497855b8a76d2cea078b1;p=tools%2Fmedcoupling.git MEDFileMesh::getGeoTypesAtLevel has been virtualized. --- diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index db630e845..cf59a07fe 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -4499,12 +4499,21 @@ int MEDFileStructuredMesh::getSizeAtLevel(int meshDimRelToMaxExt) const int MEDFileStructuredMesh::getNumberOfNodes() const { - const MEDCouplingStructuredMesh *cmesh=getStructuredMesh(); + const MEDCouplingStructuredMesh *cmesh(getStructuredMesh()); if(!cmesh) throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberOfNodes : no cartesian mesh set !"); return cmesh->getNumberOfNodes(); } +std::vector MEDFileStructuredMesh::getGeoTypesAtLevel(int meshDimRelToMax) const +{ + if(meshDimRelToMax!=0) + throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGeoTypesAtLevel : only one level available for structured meshes ! Input 0 is mandatory !"); + const MEDCouplingStructuredMesh *cmesh(getStructuredMesh()); + std::vector ret(1,cmesh->getTypeOfCell(0)); + return ret; +} + void MEDFileStructuredMesh::whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector& nodesFetched) const { if(st.getNumberOfItems()!=1) diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 91021245c..3492065f7 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -65,6 +65,7 @@ namespace ParaMEDMEM MEDLOADER_EXPORT void setTimeUnit(const std::string& unit) { _dt_unit=unit; } MEDLOADER_EXPORT std::string getTimeUnit() const { return _dt_unit; } MEDLOADER_EXPORT virtual int getNumberOfNodes() const = 0; + MEDLOADER_EXPORT virtual std::vector getGeoTypesAtLevel(int meshDimRelToMax) const = 0; MEDLOADER_EXPORT virtual std::vector getNonEmptyLevels() const = 0; MEDLOADER_EXPORT virtual std::vector getNonEmptyLevelsExt() const = 0; MEDLOADER_EXPORT virtual std::vector getFamArrNonEmptyLevelsExt() const = 0; @@ -322,6 +323,7 @@ namespace ParaMEDMEM MEDCouplingMesh *getGenMeshAtLevel(int meshDimRelToMax, bool renum=false) const; MEDLOADER_EXPORT int getSizeAtLevel(int meshDimRelToMaxExt) const; MEDLOADER_EXPORT int getNumberOfNodes() const; + MEDLOADER_EXPORT std::vector getGeoTypesAtLevel(int meshDimRelToMax) const; MEDLOADER_EXPORT void whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector& nodesFetched) const; // tools MEDLOADER_EXPORT bool unPolyze(std::vector& oldCode, std::vector& newCode, DataArrayInt *& o2nRenumCell); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index a5ee0a006..a4a759344 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -624,6 +624,16 @@ namespace ParaMEDMEM return res; } + PyObject *getGeoTypesAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) + { + std::vector result(self->getGeoTypesAtLevel(meshDimRelToMax)); + std::vector::const_iterator iL=result.begin(); + PyObject *res=PyList_New(result.size()); + for(int i=0;iL!=result.end(); i++, iL++) + PyList_SetItem(res,i,PyInt_FromLong(*iL)); + return res; + } + PyObject *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { const DataArrayInt *tmp=self->getFamilyFieldAtLevel(meshDimRelToMaxExt); @@ -759,16 +769,6 @@ namespace ParaMEDMEM { return MEDFileUMesh::New(); } - - PyObject *getGeoTypesAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception) - { - std::vector result(self->getGeoTypesAtLevel(meshDimRelToMax)); - std::vector::const_iterator iL=result.begin(); - PyObject *res=PyList_New(result.size()); - for(int i=0;iL!=result.end(); i++, iL++) - PyList_SetItem(res,i,PyInt_FromLong(*iL)); - return res; - } PyObject *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 0e397fc48..b7de8dbc9 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -347,6 +347,7 @@ class MEDLoaderTest(unittest.TestCase): self.assertTrue(m.getUnivNameWrStatus()) m.write(outFileName,2); mm=MEDFileMesh.New(outFileName) + self.assertEqual([NORM_HEXA8],mm.getGeoTypesAtLevel(0)) self.assertTrue(isinstance(mm,MEDFileCMesh)) self.assertTrue(isinstance(mm.getUnivName(),str)) self.assertTrue(len(mm.getUnivName())!=0) @@ -3476,6 +3477,76 @@ class MEDLoaderTest(unittest.TestCase): pass pass + def testField1TSSetFieldNoProfileSBTPerGeoTypes(self): + """ This test is very important, because the same mechanism is used by the MEDReader to generate a field on all the mesh without any processing and memory. + """ + fname="Pyfile78.med" + coords=DataArrayDouble([-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. ],9,3) + targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]; + m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coords) + m0.allocateCells() + for elt in [[0,1,2,3],[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7],[5,6,7,8]]:#6 + m0.insertNextCell(NORM_TETRA4,elt) + pass + for elt in [[0,1,2,3,4],[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8]]:#5 + m0.insertNextCell(NORM_PYRA5,elt) + pass + for elt in [[0,1,2,3,4,5],[1,2,3,4,5,6],[2,3,4,5,6,7],[3,4,5,6,7,8]]:#4 + m0.insertNextCell(NORM_PENTA6,elt) + pass + m0.checkCoherency2() + m1=MEDCouplingUMesh(); m1.setName("mesh") + m1.setMeshDimension(2); + m1.allocateCells(5); + m1.insertNextCell(NORM_TRI3,3,targetConn[4:7]); + m1.insertNextCell(NORM_TRI3,3,targetConn[7:10]); + m1.insertNextCell(NORM_QUAD4,4,targetConn[0:4]); + m1.insertNextCell(NORM_QUAD4,4,targetConn[10:14]); + m1.insertNextCell(NORM_QUAD4,4,targetConn[14:18]); + m1.setCoords(coords); + m3=MEDCouplingUMesh("mesh",0) ; m3.setCoords(coords) + m3.allocateCells() + m3.insertNextCell(NORM_POINT1,[2]) + m3.insertNextCell(NORM_POINT1,[3]) + m3.insertNextCell(NORM_POINT1,[4]) + m3.insertNextCell(NORM_POINT1,[5]) + # + mm=MEDFileUMesh() + mm.setMeshAtLevel(0,m0) + mm.setMeshAtLevel(-1,m1) + mm.setMeshAtLevel(-3,m3) + mm.write(fname,2) + #### The file is written only with one mesh and no fields. Let's put a field on it geo types per geo types. + mm=MEDFileMesh.New(fname) + fs=MEDFileFields() + fmts=MEDFileFieldMultiTS() + f1ts=MEDFileField1TS() + for lev in mm.getNonEmptyLevels(): + for gt in mm.getGeoTypesAtLevel(lev): + p0=mm.getDirectUndergroundSingleGeoTypeMesh(gt) + f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(p0) + arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota() + f.setArray(arr) ; f.setName("f0") + f1ts.setFieldNoProfileSBT(f) + pass + pass + self.assertEqual(mm.getNonEmptyLevels(),(0,-1,-3)) + for lev in [0,-1,-3]: + mm.getDirectUndergroundSingleGeoTypeMeshes(lev) # please let this line, it is for the test to emulate that + pass + fmts.pushBackTimeStep(f1ts) + fs.pushField(fmts) + fs.write(fname,0) + del fs,fmts,f1ts + #### The file contains now one mesh and one cell field with all cells wathever their level ang type fetched. + fs=MEDFileFields(fname) + self.assertEqual(len(fs),1) + self.assertEqual(len(fs[0]),1) + f1ts=fs[0][0] + self.assertEqual(f1ts.getFieldSplitedByType(),[(0,[(0,(0,4),'','')]),(3,[(0,(4,6),'','')]),(4,[(0,(6,9),'','')]),(14,[(0,(9,15),'','')]),(15,[(0,(15,20),'','')]),(16,[(0,(20,24),'','')])]) + self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0,1,2,3,0,1,0,1,2,0,1,2,3,4,5,0,1,2,3,4,0,1,2,3]),1e-12)) + pass + pass unittest.main()