From 953d7322d8522478a5d88480d62008471184d21e Mon Sep 17 00:00:00 2001 From: geay Date: Wed, 19 Mar 2014 15:29:01 +0100 Subject: [PATCH] Addition of optimized sublevel methods for structured meshes --- src/MEDCoupling/MEDCouplingStructuredMesh.cxx | 108 +++++++++++++++++- src/MEDCoupling/MEDCouplingStructuredMesh.hxx | 6 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 15 +++ src/MEDCoupling_Swig/MEDCouplingCommon.i | 12 ++ 4 files changed, 139 insertions(+), 2 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx index 98d336b5c..12d5d4efa 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx @@ -167,6 +167,15 @@ void MEDCouplingStructuredMesh::getNodeIdsOfCell(int cellId, std::vector& c }; } +/*! + * This method returns the number of cells of unstructured sub level mesh, without building it. + */ +int MEDCouplingStructuredMesh::getNumberOfCellsOfSubLevelMesh() const +{ + std::vector cgs(getCellGridStructure()); + return GetNumberOfCellsOfSubLevelMesh(cgs,getMeshDimension()); +} + /*! * See MEDCouplingUMesh::getDistributionOfTypes for more information */ @@ -278,7 +287,7 @@ void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile, */ MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const { - int meshDim=getMeshDimension(); + int meshDim(getMeshDimension()); if(meshDim<0 || meshDim>3) throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTUnstructured : meshdim must be in [1,2,3] !"); MEDCouplingAutoRefCountObjectPtr coords(getCoordinatesAndOwner()); @@ -290,6 +299,26 @@ MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const return ret.retn(); } +/*! + * This method returns the unstructured mesh (having single geometric type) of the sub level mesh of \a this. + * This method is equivalent to computing MEDCouplingUMesh::buildDescendingConnectivity on the unstructurized \a this mesh. + * + * The caller is to delete the returned mesh using decrRef() as it is no more needed. + */ +MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTSubLevelMesh() const +{ + int meshDim(getMeshDimension()); + if(meshDim<1 || meshDim>3) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTSubLevelMesh : meshdim must be in [2,3] !"); + MEDCouplingAutoRefCountObjectPtr coords(getCoordinatesAndOwner()); + int ns[3]; + getNodeGridStructure(ns); + MEDCouplingAutoRefCountObjectPtr conn(Build1GTNodalConnectivityOfSubLevelMesh(ns,ns+meshDim)); + MEDCouplingAutoRefCountObjectPtr ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim-1))); + ret->setNodalConnectivity(conn); ret->setCoords(coords); + return ret.retn(); +} + /*! * Creates a new unstructured mesh (MEDCouplingUMesh) from \a this structured one. * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to @@ -537,7 +566,7 @@ void MEDCouplingStructuredMesh::GetReverseNodalConnectivity3(const std::vector ngs(3); + int n0(nodeStBg[0]-1),n1(nodeStBg[1]-1),n2(nodeStBg[2]-1); ngs[0]=n0; ngs[1]=n1; ngs[2]=n2; + int off0(nodeStBg[0]),off1(nodeStBg[0]*nodeStBg[1]); + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()); + conn->alloc(4*GetNumberOfCellsOfSubLevelMesh(ngs,3)); + int *cp(conn->getPointer()),pos(0); + //X + for(int i=0;i ngs(2); + int n0(nodeStBg[0]-1),n1(nodeStBg[1]-1); ngs[0]=n0; ngs[1]=n1; + int off0(nodeStBg[0]); + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()); + conn->alloc(2*GetNumberOfCellsOfSubLevelMesh(ngs,2)); + int *cp(conn->getPointer()),pos(0); + //X + for(int i=0;i& cgs, int mdim) +{ + int ret(0); + for(int i=0;i& st, std::vector< std::pair >& partCompactFormat); MEDCOUPLING_EXPORT static DataArrayInt *BuildExplicitIdsFrom(const std::vector& st, const std::vector< std::pair >& partCompactFormat); MEDCOUPLING_EXPORT static DataArrayInt *Build1GTNodalConnectivity(const int *nodeStBg, const int *nodeStEnd); + MEDCOUPLING_EXPORT static DataArrayInt *Build1GTNodalConnectivityOfSubLevelMesh(const int *nodeStBg, const int *nodeStEnd); private: + static int GetNumberOfCellsOfSubLevelMesh(const std::vector& cgs, int mdim); static void GetReverseNodalConnectivity1(const std::vector& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx); static void GetReverseNodalConnectivity2(const std::vector& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx); static void GetReverseNodalConnectivity3(const std::vector& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx); static DataArrayInt *Build1GTNodalConnectivity1D(const int *nodeStBg); static DataArrayInt *Build1GTNodalConnectivity2D(const int *nodeStBg); static DataArrayInt *Build1GTNodalConnectivity3D(const int *nodeStBg); + static DataArrayInt *Build1GTNodalConnectivityOfSubLevelMesh2D(const int *nodeStBg); + static DataArrayInt *Build1GTNodalConnectivityOfSubLevelMesh3D(const int *nodeStBg); protected: MEDCOUPLING_EXPORT MEDCouplingStructuredMesh(); MEDCOUPLING_EXPORT MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCpy); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index fd9391764..2ecaa6d5b 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -14515,6 +14515,21 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertTrue(arrOfDisc2.isEqual(coo,1e-12)) pass + def testSwig2StructuredDesc1(self): + c=MEDCouplingCMesh() + arr0=DataArrayDouble(3) ; arr0.iota() + arr1=DataArrayDouble(4) ; arr1.iota() + arr2=DataArrayDouble(5) ; arr2.iota() + c.setCoords(arr0,arr1,arr2) + # + self.assertEqual(98,c.getNumberOfCellsOfSubLevelMesh()) + m=c.build1SGTSubLevelMesh() + self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([0,12,15,3,12,24,27,15,24,36,39,27,36,48,51,39,3,15,18,6,15,27,30,18,27,39,42,30,39,51,54,42,6,18,21,9,18,30,33,21,30,42,45,33,42,54,57,45,1,13,16,4,13,25,28,16,25,37,40,28,37,49,52,40,4,16,19,7,16,28,31,19,28,40,43,31,40,52,55,43,7,19,22,10,19,31,34,22,31,43,46,34,43,55,58,46,2,14,17,5,14,26,29,17,26,38,41,29,38,50,53,41,5,17,20,8,17,29,32,20,29,41,44,32,41,53,56,44,8,20,23,11,20,32,35,23,32,44,47,35,44,56,59,47,0,12,13,1,12,24,25,13,24,36,37,25,36,48,49,37,1,13,14,2,13,25,26,14,25,37,38,26,37,49,50,38,3,15,16,4,15,27,28,16,27,39,40,28,39,51,52,40,4,16,17,5,16,28,29,17,28,40,41,29,40,52,53,41,6,18,19,7,18,30,31,19,30,42,43,31,42,54,55,43,7,19,20,8,19,31,32,20,31,43,44,32,43,55,56,44,9,21,22,10,21,33,34,22,33,45,46,34,45,57,58,46,10,22,23,11,22,34,35,23,34,46,47,35,46,58,59,47,0,1,4,3,3,4,7,6,6,7,10,9,1,2,5,4,4,5,8,7,7,8,11,10,12,13,16,15,15,16,19,18,18,19,22,21,13,14,17,16,16,17,20,19,19,20,23,22,24,25,28,27,27,28,31,30,30,31,34,33,25,26,29,28,28,29,32,31,31,32,35,34,36,37,40,39,39,40,43,42,42,43,46,45,37,38,41,40,40,41,44,43,43,44,47,46,48,49,52,51,51,52,55,54,54,55,58,57,49,50,53,52,52,53,56,55,55,56,59,58]))) + self.assertEqual(NORM_QUAD4,m.getCellModelEnum()) + # + self.assertTrue(MEDCouplingStructuredMesh.Build1GTNodalConnectivityOfSubLevelMesh([3,7]).isEqual(DataArrayInt([0,3,3,6,6,9,9,12,12,15,15,18,1,4,4,7,7,10,10,13,13,16,16,19,2,5,5,8,8,11,11,14,14,17,17,20,0,1,1,2,3,4,4,5,6,7,7,8,9,10,10,11,12,13,13,14,15,16,16,17,18,19,19,20]))) + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index eb4e14fcf..e7ebdf73a 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -293,8 +293,10 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingExtrudedMesh::build3DUnstructuredMesh; %newobject ParaMEDMEM::MEDCouplingStructuredMesh::buildStructuredSubPart; %newobject ParaMEDMEM::MEDCouplingStructuredMesh::build1SGTUnstructured; +%newobject ParaMEDMEM::MEDCouplingStructuredMesh::build1SGTSubLevelMesh; %newobject ParaMEDMEM::MEDCouplingStructuredMesh::BuildExplicitIdsFrom; %newobject ParaMEDMEM::MEDCouplingStructuredMesh::Build1GTNodalConnectivity; +%newobject ParaMEDMEM::MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh; %newobject ParaMEDMEM::MEDCouplingCMesh::New; %newobject ParaMEDMEM::MEDCouplingCMesh::clone; %newobject ParaMEDMEM::MEDCouplingCMesh::getCoordsAt; @@ -2730,10 +2732,12 @@ namespace ParaMEDMEM public: int getCellIdFromPos(int i, int j, int k) const throw(INTERP_KERNEL::Exception); int getNodeIdFromPos(int i, int j, int k) const throw(INTERP_KERNEL::Exception); + int getNumberOfCellsOfSubLevelMesh() const throw(INTERP_KERNEL::Exception); virtual std::vector getNodeGridStructure() const throw(INTERP_KERNEL::Exception); std::vector getCellGridStructure() const throw(INTERP_KERNEL::Exception); MEDCoupling1SGTUMesh *build1SGTUnstructured() const throw(INTERP_KERNEL::Exception); static INTERP_KERNEL::NormalizedCellType GetGeoTypeGivenMeshDimension(int meshDim) throw(INTERP_KERNEL::Exception); + MEDCoupling1SGTUMesh *build1SGTSubLevelMesh() const throw(INTERP_KERNEL::Exception); %extend { virtual MEDCouplingStructuredMesh *buildStructuredSubPart(PyObject *cellPart) const throw(INTERP_KERNEL::Exception) @@ -2798,6 +2802,14 @@ namespace ParaMEDMEM return MEDCouplingStructuredMesh::Build1GTNodalConnectivity(tmp,tmp+szArr); } + static DataArrayInt *Build1GTNodalConnectivityOfSubLevelMesh(PyObject *li) throw(INTERP_KERNEL::Exception) + { + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *tmp(convertObjToPossibleCpp1_Safe(li,sw,szArr,iTypppArr,stdvecTyyppArr)); + return MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh(tmp,tmp+szArr); + } + static PyObject *IsPartStructured(PyObject *li, PyObject *st) throw(INTERP_KERNEL::Exception) { int szArr,sw,iTypppArr; -- 2.39.2