From 9b477477cc54b36d544f215af2060ed817a876dd Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 15 Jan 2014 15:46:07 +0000 Subject: [PATCH] getMeshDimension and getSpaceDimension do not return systematically the same thing in CMesh. --- src/MEDCoupling/MEDCouplingCMesh.cxx | 65 +++++++++++++++---- src/MEDCoupling/MEDCouplingStructuredMesh.cxx | 22 +++++-- src/MEDLoader/MEDFileMesh.cxx | 17 ++++- src/MEDLoader/MEDFileMesh.hxx | 1 + 4 files changed, 83 insertions(+), 22 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index 0a2878258..9588dca64 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -217,6 +217,7 @@ void MEDCouplingCMesh::checkCoherency() const const char msg0[]="Invalid "; const char msg1[]=" array ! Must contain more than 1 element."; const char msg2[]=" array ! Must be with only one component."; + getSpaceDimension();// here to check that no holes in arrays ! if(_x_array) { if(_x_array->getNbOfElems()<2) @@ -301,19 +302,19 @@ int MEDCouplingCMesh::getNumberOfNodes() const void MEDCouplingCMesh::getSplitCellValues(int *res) const { - int spaceDim=getSpaceDimension(); - for(int l=0;lgetNbOfElems()-1; - res[spaceDim-l-1]=val; + res[meshDim-l-1]=val; } } void MEDCouplingCMesh::getSplitNodeValues(int *res) const { - int spaceDim=getSpaceDimension(); + int spaceDim(getSpaceDimension()); for(int l=0;lgetNbOfElems(); } std::vector MEDCouplingCMesh::getNodeGridStructure() const { - std::vector ret(getMeshDimension()); + std::vector ret(getSpaceDimension()); getNodeGridStructure(&ret[0]); return ret; } @@ -355,21 +356,61 @@ MEDCouplingStructuredMesh *MEDCouplingCMesh::buildStructuredSubPart(const std::v return ret.retn(); } +/*! + * Return the space dimension of \a this. It only considers the arrays along X, Y and Z to deduce that. + * This method throws exceptions if the not null arrays defining this are not contiguouly at the end. For example X!=0,Y==0,Z!=0 will throw. + */ int MEDCouplingCMesh::getSpaceDimension() const { - int ret=0; + static const char MSG[]="MEDCouplingCMesh::getSpaceDimension : mesh is invalid ! null vectors (X, Y or Z) must be put contiguously at the end !"; + int ret(0); + bool isOK(true); if(_x_array) ret++; + else + isOK=false; if(_y_array) - ret++; + { + if(!isOK) + throw INTERP_KERNEL::Exception(MSG); + ret++; + } + else + isOK=false; if(_z_array) - ret++; + { + if(!isOK) + throw INTERP_KERNEL::Exception(MSG); + ret++; + } return ret; } +/*! + * This method returns the mesh dimension of \a this. It can be different from space dimension in case of a not null dimension contains only one node. + */ int MEDCouplingCMesh::getMeshDimension() const { - return getSpaceDimension(); + int ret(getSpaceDimension()); + if(_x_array) + { + if(_x_array->isAllocated()) + if(_x_array->getNumberOfTuples()==1) + ret--; + } + if(_y_array) + { + if(_y_array->isAllocated()) + if(_y_array->getNumberOfTuples()==1) + ret--; + } + if(_z_array) + { + if(_z_array->isAllocated()) + if(_z_array->getNumberOfTuples()==1) + ret--; + } + return ret; } void MEDCouplingCMesh::getCoordinatesOfNode(int nodeId, std::vector& coo) const diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx index c51f02b92..71b581d3c 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx @@ -70,6 +70,8 @@ INTERP_KERNEL::NormalizedCellType MEDCouplingStructuredMesh::GetGeoTypeGivenMesh return INTERP_KERNEL::NORM_QUAD4; case 1: return INTERP_KERNEL::NORM_SEG2; + case 0: + return INTERP_KERNEL::NORM_POINT1; default: throw INTERP_KERNEL::Exception("Unexpected dimension for MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension !"); } @@ -378,7 +380,7 @@ MEDCouplingFieldDouble *MEDCouplingStructuredMesh::buildOrthogonalField() const void MEDCouplingStructuredMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const { std::vector ngs(getNodeGridStructure()); - int dim(getMeshDimension()); + int dim(getSpaceDimension()); switch(dim) { case 1: @@ -399,7 +401,7 @@ void MEDCouplingStructuredMesh::GetReverseNodalConnectivity1(const std::vectoralloc(0,1); revNodalIndx->setIJ(0,0,0); return ; } if(nbNodes==1) - { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); revNodalIndx->setIJ(1,0,0); return ; } + { revNodal->alloc(1,1); revNodal->setIJ(0,0,0); revNodalIndx->setIJ(0,0,0); revNodalIndx->setIJ(1,0,1); return ; } revNodal->alloc(2*(nbNodes-1),1); int *rn(revNodal->getPointer()),*rni(revNodalIndx->getPointer()); *rni++=0; *rni=1; *rn++=0; @@ -538,6 +540,12 @@ DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity(const int *no std::size_t dim=std::distance(nodeStBg,nodeStEnd); switch(dim) { + case 0: + { + MEDCouplingAutoRefCountObjectPtr conn(DataArrayInt::New()); + conn->alloc(1,1); conn->setIJ(0,0,0); + return conn.retn(); + } case 1: return Build1GTNodalConnectivity1D(nodeStBg); case 2: @@ -545,7 +553,7 @@ DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity(const int *no case 3: return Build1GTNodalConnectivity3D(nodeStBg); default: - throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::Build1GTNodalConnectivity : only dimension in [1,2,3] supported !"); + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::Build1GTNodalConnectivity : only dimension in [0,1,2,3] supported !"); } } @@ -620,7 +628,7 @@ int MEDCouplingStructuredMesh::getCellIdFromPos(int i, int j, int k) const { int tmp[3]={i,j,k}; int tmp2[3]; - int meshDim=getMeshDimension(); + int meshDim(getMeshDimension()); getSplitCellValues(tmp2); std::transform(tmp,tmp+meshDim,tmp2,tmp,std::multiplies()); return std::accumulate(tmp,tmp+meshDim,0); @@ -637,10 +645,10 @@ int MEDCouplingStructuredMesh::getNodeIdFromPos(int i, int j, int k) const { int tmp[3]={i,j,k}; int tmp2[3]; - int meshDim=getMeshDimension(); + int spaceDim(getSpaceDimension()); getSplitNodeValues(tmp2); - std::transform(tmp,tmp+meshDim,tmp2,tmp,std::multiplies()); - return std::accumulate(tmp,tmp+meshDim,0); + std::transform(tmp,tmp+spaceDim,tmp2,tmp,std::multiplies()); + return std::accumulate(tmp,tmp+spaceDim,0); } void MEDCouplingStructuredMesh::GetPosFromId(int nodeId, int meshDim, const int *split, int *res) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index dd31d0a96..165d0a991 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -4752,6 +4752,18 @@ int MEDFileCMesh::getMeshDimension() const return _cmesh->getMeshDimension(); } +/*! + * Returns the dimension on nodes in \a this mesh. + * \return int - the space dimension. + * \throw If there are no cells in this mesh. + */ +int MEDFileCMesh::getSpaceDimension() const +{ + if(!((const MEDCouplingCMesh*)_cmesh)) + throw INTERP_KERNEL::Exception("MEDFileCMesh::getSpaceDimension : unable to get spacedimension because no mesh set !"); + return _cmesh->getSpaceDimension(); +} + /*! * Returns a string describing \a this mesh. * \return std::string - the mesh information string. @@ -4908,8 +4920,7 @@ void MEDFileCMesh::writeLL(med_idt fid) const MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str); MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str); MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str); - int spaceDim=_cmesh->getSpaceDimension(); - int meshDim=_cmesh->getMeshDimension(); + int spaceDim(_cmesh->getSpaceDimension()); INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE); for(int i=0;i