From 77022c8766919b6855011e9b866f2b6f59d8519b Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 23 Jul 2013 12:23:24 +0000 Subject: [PATCH] MEDCouplingStructuredMesh.IsPartStructured MEDCouplingStructuredMesh.BuildExplicitIdsFrom - behaviour modification MEDCouplingStructuredMesh::buildPartAndReduceNodes returns a structured mesh if possible to reduce the cost in memory --- src/MEDCoupling/MEDCouplingStructuredMesh.cxx | 145 ++++++++---------- src/MEDCoupling/MEDCouplingStructuredMesh.hxx | 8 +- 2 files changed, 68 insertions(+), 85 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx index 7878d83b6..6127b68c6 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx @@ -21,6 +21,7 @@ #include "MEDCouplingStructuredMesh.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingMemArray.hxx" +#include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingUMesh.hxx" #include @@ -261,26 +262,17 @@ void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile, */ MEDCouplingUMesh *MEDCouplingStructuredMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception) { - int meshDim=getMeshDimension(); - MEDCouplingUMesh *ret=MEDCouplingUMesh::New(getName(),meshDim); - DataArrayDouble *coords=getCoordinatesAndOwner(); - ret->setCoords(coords); - coords->decrRef(); - switch(meshDim) - { - case 1: - fill1DUnstructuredMesh(ret); - break; - case 2: - fill2DUnstructuredMesh(ret); - break; - case 3: - fill3DUnstructuredMesh(ret); - break; - default: - throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::buildUnstructured : big problem spacedim must be in 1,2 or 3 !"); - }; - return ret; + int meshDim=getMeshDimension(); + if(meshDim<0 || meshDim>3) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::buildUnstructured : meshdim must be in [1,2,3] !"); + + MEDCouplingAutoRefCountObjectPtr coords(getCoordinatesAndOwner()); + int ns[3]; + getNodeGridStructure(ns); + MEDCouplingAutoRefCountObjectPtr conn(Build1GTNodalConnectivity(ns,ns+meshDim)); + MEDCouplingAutoRefCountObjectPtr ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim))); + ret->setNodalConnectivity(conn); ret->setCoords(coords); + return ret->buildUnstructured(); } /*! @@ -358,93 +350,82 @@ MEDCouplingFieldDouble *MEDCouplingStructuredMesh::buildOrthogonalField() const return ret; } -void MEDCouplingStructuredMesh::fill1DUnstructuredMesh(MEDCouplingUMesh *m) const +/*! + * \return DataArrayInt * - newly allocated instance of nodal connectivity compatible for MEDCoupling1SGTMesh instance + */ +DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity(const int *nodeStBg, const int *nodeStEnd) throw(INTERP_KERNEL::Exception) +{ + std::size_t dim=std::distance(nodeStBg,nodeStEnd); + switch(dim) + { + case 1: + return Build1GTNodalConnectivity1D(nodeStBg); + case 2: + return Build1GTNodalConnectivity2D(nodeStBg); + case 3: + return Build1GTNodalConnectivity3D(nodeStBg); + default: + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::Build1GTNodalConnectivity : only dimension in [1,2,3] supported !"); + } +} + +DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity1D(const int *nodeStBg) throw(INTERP_KERNEL::Exception) { - int nbOfCells=-1; - getNodeGridStructure(&nbOfCells); - nbOfCells--; - DataArrayInt *connI=DataArrayInt::New(); - connI->alloc(nbOfCells+1,1); - int *ci=connI->getPointer(); - DataArrayInt *conn=DataArrayInt::New(); - conn->alloc(3*nbOfCells,1); - ci[0]=0; + int nbOfCells(*nodeStBg-1); + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()); + conn->alloc(2*nbOfCells,1); int *cp=conn->getPointer(); for(int i=0;isetConnectivity(conn,connI,true); - conn->decrRef(); - connI->decrRef(); + return conn.retn(); } -void MEDCouplingStructuredMesh::fill2DUnstructuredMesh(MEDCouplingUMesh *m) const +DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity2D(const int *nodeStBg) throw(INTERP_KERNEL::Exception) { - int ns[2]; - getNodeGridStructure(ns); - int n1=ns[0]-1; - int n2=ns[1]-1; - DataArrayInt *connI=DataArrayInt::New(); - connI->alloc(n1*n2+1,1); - int *ci=connI->getPointer(); - DataArrayInt *conn=DataArrayInt::New(); - conn->alloc(5*n1*n2,1); - ci[0]=0; + int n1=nodeStBg[0]-1; + int n2=nodeStBg[1]-1; + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()); + conn->alloc(4*n1*n2,1); int *cp=conn->getPointer(); int pos=0; for(int j=0;jsetConnectivity(conn,connI,true); - conn->decrRef(); - connI->decrRef(); + return conn.retn(); } -void MEDCouplingStructuredMesh::fill3DUnstructuredMesh(MEDCouplingUMesh *m) const +DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity3D(const int *nodeStBg) throw(INTERP_KERNEL::Exception) { - int ns[3]; - getNodeGridStructure(ns); - int n1=ns[0]-1; - int n2=ns[1]-1; - int n3=ns[2]-1; - DataArrayInt *connI=DataArrayInt::New(); - connI->alloc(n1*n2*n3+1,1); - int *ci=connI->getPointer(); - DataArrayInt *conn=DataArrayInt::New(); - conn->alloc(9*n1*n2*n3,1); - ci[0]=0; + int n1=nodeStBg[0]-1; + int n2=nodeStBg[1]-1; + int n3=nodeStBg[2]-1; + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()); + conn->alloc(8*n1*n2*n3,1); int *cp=conn->getPointer(); int pos=0; for(int k=0;ksetConnectivity(conn,connI,true); - conn->decrRef(); - connI->decrRef(); + return conn.retn(); } /*! diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.hxx b/src/MEDCoupling/MEDCouplingStructuredMesh.hxx index 9b18e21b6..97eb2650d 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.hxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.hxx @@ -50,9 +50,6 @@ namespace ParaMEDMEM MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const; DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildOrthogonalField() const; - void fill1DUnstructuredMesh(MEDCouplingUMesh *m) const; - void fill2DUnstructuredMesh(MEDCouplingUMesh *m) const; - void fill3DUnstructuredMesh(MEDCouplingUMesh *m) const; //some useful methods int getCellIdFromPos(int i, int j, int k) const; int getNodeIdFromPos(int i, int j, int k) const; @@ -64,6 +61,11 @@ namespace ParaMEDMEM virtual MEDCouplingStructuredMesh *buildStructuredSubPart(const std::vector< std::pair >& cellPart) const throw(INTERP_KERNEL::Exception) = 0; static bool IsPartStructured(const int *startIds, const int *stopIds, const std::vector& st, std::vector< std::pair >& partCompactFormat) throw(INTERP_KERNEL::Exception); static DataArrayInt *BuildExplicitIdsFrom(const std::vector& st, const std::vector< std::pair >& partCompactFormat) throw(INTERP_KERNEL::Exception); + static DataArrayInt *Build1GTNodalConnectivity(const int *nodeStBg, const int *nodeStEnd) throw(INTERP_KERNEL::Exception); + private: + static DataArrayInt *Build1GTNodalConnectivity1D(const int *nodeStBg) throw(INTERP_KERNEL::Exception); + static DataArrayInt *Build1GTNodalConnectivity2D(const int *nodeStBg) throw(INTERP_KERNEL::Exception); + static DataArrayInt *Build1GTNodalConnectivity3D(const int *nodeStBg) throw(INTERP_KERNEL::Exception); protected: MEDCouplingStructuredMesh(); MEDCouplingStructuredMesh(const MEDCouplingStructuredMesh& other, bool deepCpy); -- 2.39.2