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)
void MEDCouplingCMesh::getSplitCellValues(int *res) const
{
- int spaceDim=getSpaceDimension();
- for(int l=0;l<spaceDim;l++)
+ int meshDim(getMeshDimension());
+ for(int l=0;l<meshDim;l++)
{
int val=1;
- for(int p=0;p<spaceDim-l-1;p++)
+ for(int p=0;p<meshDim-l-1;p++)
val*=getCoordsAt(p)->getNbOfElems()-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;l<spaceDim;l++)
{
int val=1;
void MEDCouplingCMesh::getNodeGridStructure(int *res) const
{
- int meshDim=getMeshDimension();
- for(int i=0;i<meshDim;i++)
+ int spaceDim(getSpaceDimension());
+ for(int i=0;i<spaceDim;i++)
res[i]=getCoordsAt(i)->getNbOfElems();
}
std::vector<int> MEDCouplingCMesh::getNodeGridStructure() const
{
- std::vector<int> ret(getMeshDimension());
+ std::vector<int> ret(getSpaceDimension());
getNodeGridStructure(&ret[0]);
return ret;
}
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<double>& coo) const
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 !");
}
void MEDCouplingStructuredMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const
{
std::vector<int> ngs(getNodeGridStructure());
- int dim(getMeshDimension());
+ int dim(getSpaceDimension());
switch(dim)
{
case 1:
if(nbNodes==0)
{ revNodal->alloc(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;
std::size_t dim=std::distance(nodeStBg,nodeStEnd);
switch(dim)
{
+ case 0:
+ {
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+ conn->alloc(1,1); conn->setIJ(0,0,0);
+ return conn.retn();
+ }
case 1:
return Build1GTNodalConnectivity1D(nodeStBg);
case 2:
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 !");
}
}
{
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<int>());
return std::accumulate(tmp,tmp+meshDim,0);
{
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<int>());
- return std::accumulate(tmp,tmp+meshDim,0);
+ std::transform(tmp,tmp+spaceDim,tmp2,tmp,std::multiplies<int>());
+ return std::accumulate(tmp,tmp+spaceDim,0);
}
void MEDCouplingStructuredMesh::GetPosFromId(int nodeId, int meshDim, const int *split, int *res)
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.
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<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
for(int i=0;i<spaceDim;i++)
MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
}
- MEDmeshCr(fid,maa,spaceDim,meshDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
+ MEDmeshCr(fid,maa,spaceDim,spaceDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
MEDmeshUniversalNameWr(fid,maa);
MEDmeshGridTypeWr(fid,maa,MED_CARTESIAN_GRID);
for(int i=0;i<spaceDim;i++)
MEDLOADER_EXPORT MEDFileMesh *shallowCpy() const;
MEDLOADER_EXPORT bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const;
MEDLOADER_EXPORT int getMeshDimension() const;
+ MEDLOADER_EXPORT int getSpaceDimension() const;
MEDLOADER_EXPORT std::string simpleRepr() const;
MEDLOADER_EXPORT std::string advancedRepr() const;
MEDLOADER_EXPORT void clearNonDiscrAttributes() const;