X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FMEDCoupling%2FMEDCouplingStructuredMesh.cxx;h=58ec89f01f767fe0a55e02f76ef62f9eca7cfca7;hb=4cefa2ce2bbd5d65c18b3c3032d42e5ef2679d31;hp=2da06d22b16b493cbc6260de6d1cf5eeaec0686c;hpb=e6d2fdbc0e2aed9c2232db8ea396f75a01cfd297;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx index 2da06d22b..58ec89f01 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -40,17 +40,17 @@ MEDCouplingStructuredMesh::~MEDCouplingStructuredMesh() { } -std::size_t MEDCouplingStructuredMesh::getHeapMemorySize() const +std::size_t MEDCouplingStructuredMesh::getHeapMemorySizeWithoutChildren() const { - return MEDCouplingMesh::getHeapMemorySize(); + return MEDCouplingMesh::getHeapMemorySizeWithoutChildren(); } -void MEDCouplingStructuredMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) throw(INTERP_KERNEL::Exception) +void MEDCouplingStructuredMesh::copyTinyStringsFrom(const MEDCouplingMesh *other) { MEDCouplingMesh::copyTinyStringsFrom(other); } -bool MEDCouplingStructuredMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const throw(INTERP_KERNEL::Exception) +bool MEDCouplingStructuredMesh::isEqualIfNotWhy(const MEDCouplingMesh *other, double prec, std::string& reason) const { return MEDCouplingMesh::isEqualIfNotWhy(other,prec,reason); } @@ -60,19 +60,21 @@ INTERP_KERNEL::NormalizedCellType MEDCouplingStructuredMesh::getTypeOfCell(int c return GetGeoTypeGivenMeshDimension(getMeshDimension()); } -INTERP_KERNEL::NormalizedCellType MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(int meshDim) throw(INTERP_KERNEL::Exception) +INTERP_KERNEL::NormalizedCellType MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(int meshDim) { switch(meshDim) - { + { case 3: return INTERP_KERNEL::NORM_HEXA8; case 2: 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 !"); - } + } } std::set MEDCouplingStructuredMesh::getAllGeoTypes() const @@ -92,7 +94,7 @@ int MEDCouplingStructuredMesh::getNumberOfCellsWithType(INTERP_KERNEL::Normalize throw INTERP_KERNEL::Exception(oss.str().c_str()); } -DataArrayInt *MEDCouplingStructuredMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingStructuredMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const { MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); if(getTypeOfCell(0)==type) @@ -105,7 +107,7 @@ DataArrayInt *MEDCouplingStructuredMesh::giveCellsWithType(INTERP_KERNEL::Normal return ret.retn(); } -DataArrayInt *MEDCouplingStructuredMesh::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingStructuredMesh::computeNbOfNodesPerCell() const { int nbCells=getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); @@ -115,7 +117,7 @@ DataArrayInt *MEDCouplingStructuredMesh::computeNbOfNodesPerCell() const throw(I return ret.retn(); } -DataArrayInt *MEDCouplingStructuredMesh::computeNbOfFacesPerCell() const throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingStructuredMesh::computeNbOfFacesPerCell() const { int nbCells=getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); @@ -125,6 +127,18 @@ DataArrayInt *MEDCouplingStructuredMesh::computeNbOfFacesPerCell() const throw(I return ret.retn(); } +/*! + * This method computes effective number of nodes per cell. That is to say nodes appearing several times in nodal connectivity of a cell, + * will be counted only once here whereas it will be counted several times in MEDCouplingMesh::computeNbOfNodesPerCell method. + * Here for structured mesh it returns exactly as MEDCouplingStructuredMesh::computeNbOfNodesPerCell does. + * + * \return DataArrayInt * - new object to be deallocated by the caller. + */ +DataArrayInt *MEDCouplingStructuredMesh::computeEffectiveNbOfNodesPerCell() const +{ + return computeNbOfNodesPerCell(); +} + void MEDCouplingStructuredMesh::getNodeIdsOfCell(int cellId, std::vector& conn) const { int meshDim=getMeshDimension(); @@ -134,29 +148,94 @@ void MEDCouplingStructuredMesh::getNodeIdsOfCell(int cellId, std::vector& c int tmp2[3]; GetPosFromId(cellId,meshDim,tmpCell,tmp2); switch(meshDim) - { + { case 1: conn.push_back(tmp2[0]); conn.push_back(tmp2[0]+1); break; case 2: - conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]); conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+1); - conn.push_back((tmp2[1]+1)*(tmpCell[1]+1)+tmp2[0]+1); conn.push_back((tmp2[1]+1)*(tmpCell[1]+1)+tmp2[0]); + conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]); conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+1); + conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+1); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]); break; case 3: - conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+tmp2[2]*tmpNode[2]); conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+1+tmp2[2]*tmpNode[2]); + conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+tmp2[2]*tmpNode[2]); conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+1+tmp2[2]*tmpNode[2]); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+1+tmp2[2]*tmpNode[2]); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+tmp2[2]*tmpNode[2]); - conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+(tmp2[2]+1)*tmpNode[2]); conn.push_back(tmp2[1]*tmpCell[1]+tmp2[0]+1+(tmp2[2]+1)*tmpNode[2]); + conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+(tmp2[2]+1)*tmpNode[2]); conn.push_back(tmp2[1]*tmpNode[1]+tmp2[0]+1+(tmp2[2]+1)*tmpNode[2]); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+1+(tmp2[2]+1)*tmpNode[2]); conn.push_back((tmp2[1]+1)*tmpNode[1]+tmp2[0]+(tmp2[2]+1)*tmpNode[2]); break; default: throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::getNodeIdsOfCell : big problem spacedim must be in 1,2 or 3 !"); - }; + }; +} + +/*! + * 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 MEDCouplingStructuredMesh::getMeshDimension() const +{ + std::vector ngs(getNodeGridStructure()); + int ret(0),pos(0); + for(std::vector::const_iterator it=ngs.begin();it!=ngs.end();it++,pos++) + { + if(*it<=0) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::getMeshDimension : At pos #" << pos << " number of nodes is " << *it << " ! Must be > 0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(*it>1) + ret++; + } + return ret; +} + +/*! + * This method returns the space dimension by only considering the node grid structure. + * For cartesian mesh the returned value is equal to those returned by getSpaceDimension. + * But for curvelinear is could be different ! + */ +int MEDCouplingStructuredMesh::getSpaceDimensionOnNodeStruct() const +{ + std::vector nodeStr(getNodeGridStructure()); + int spd1(0),pos(0); + for(std::vector::const_iterator it=nodeStr.begin();it!=nodeStr.end();it++,pos++) + { + int elt(*it); + if(elt<=0) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::getSpaceDimensionOnNodeStruct : At pos #" << pos << " value of node grid structure is " << *it << " ! must be >=1 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + spd1++; + } + return spd1; +} + +void MEDCouplingStructuredMesh::getSplitCellValues(int *res) const +{ + std::vector strct(getCellGridStructure()); + std::vector ret(MEDCouplingStructuredMesh::GetSplitVectFromStruct(strct)); + std::copy(ret.begin(),ret.end(),res); +} + +void MEDCouplingStructuredMesh::getSplitNodeValues(int *res) const +{ + std::vector strct(getNodeGridStructure()); + std::vector ret(MEDCouplingStructuredMesh::GetSplitVectFromStruct(strct)); + std::copy(ret.begin(),ret.end(),res); +} + +/*! + * 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 */ -std::vector MEDCouplingStructuredMesh::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception) +std::vector MEDCouplingStructuredMesh::getDistributionOfTypes() const { //only one type of cell std::vector ret(3); @@ -172,7 +251,7 @@ std::vector MEDCouplingStructuredMesh::getDistributionOfTypes() const throw * * See MEDCouplingUMesh::checkTypeConsistencyAndContig for more information */ -DataArrayInt *MEDCouplingStructuredMesh::checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingStructuredMesh::checkTypeConsistencyAndContig(const std::vector& code, const std::vector& idsPerType) const { int nbOfCells=getNumberOfCells(); if(code.size()!=3) @@ -230,10 +309,10 @@ DataArrayInt *MEDCouplingStructuredMesh::checkTypeConsistencyAndContig(const std * - After \a code contains [NORM_...,nbCells,0], \a idsInPflPerType [[0,1]] and \a idsPerType is [[1,2]]
*/ -void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) +void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const { - if(!profile) - throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile is NULL !"); + if(!profile || !profile->isAllocated()) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile is NULL or not allocated !"); if(profile->getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::splitProfilePerType : input profile should have exactly one component !"); int nbTuples=profile->getNumberOfTuples(); @@ -244,13 +323,15 @@ void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile, if(profile->isIdentity() && nbTuples==nbOfCells) { code[2]=-1; - idsInPflPerType[0]=const_cast(profile); idsInPflPerType[0]->incrRef(); - idsPerType.clear(); + idsInPflPerType[0]=0; + idsPerType.clear(); + return ; } + code[1]=profile->getNumberOfTuples(); code[2]=0; profile->checkAllIdsInRange(0,nbOfCells); idsPerType.resize(1); - idsPerType[0]=const_cast(profile); idsPerType[0]->incrRef(); + idsPerType[0]=profile->deepCpy(); idsInPflPerType[0]=DataArrayInt::Range(0,nbTuples,1); } @@ -260,16 +341,39 @@ void MEDCouplingStructuredMesh::splitProfilePerType(const DataArrayInt *profile, * delete this array using decrRef() as it is no more needed. * \throw If \a this->getMeshDimension() is not among [1,2,3]. */ -MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const throw(INTERP_KERNEL::Exception) +MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const +{ + int meshDim(getMeshDimension()),spaceDim(getSpaceDimensionOnNodeStruct()); + if((meshDim<0 || meshDim>3) || (spaceDim<0 || spaceDim>3)) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTUnstructured : meshdim and spacedim must be in [1,2,3] !"); + MEDCouplingAutoRefCountObjectPtr coords(getCoordinatesAndOwner()); + int ns[3]; + getNodeGridStructure(ns); + MEDCouplingAutoRefCountObjectPtr conn(Build1GTNodalConnectivity(ns,ns+spaceDim)); + MEDCouplingAutoRefCountObjectPtr ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim))); + ret->setNodalConnectivity(conn); ret->setCoords(coords); + try + { ret->copyTinyInfoFrom(this); } + catch(INTERP_KERNEL::Exception&) { } + 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<0 || meshDim>3) - throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTUnstructured : meshdim must be in [1,2,3] !"); + 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(Build1GTNodalConnectivity(ns,ns+meshDim)); - MEDCouplingAutoRefCountObjectPtr ret(MEDCoupling1SGTUMesh::New(getName().c_str(),GetGeoTypeGivenMeshDimension(meshDim))); + MEDCouplingAutoRefCountObjectPtr conn(Build1GTNodalConnectivityOfSubLevelMesh(ns,ns+meshDim)); + MEDCouplingAutoRefCountObjectPtr ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim-1))); ret->setNodalConnectivity(conn); ret->setCoords(coords); return ret.retn(); } @@ -280,9 +384,10 @@ MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const t * delete this array using decrRef() as it is no more needed. * \throw If \a this->getMeshDimension() is not among [1,2,3]. */ -MEDCouplingUMesh *MEDCouplingStructuredMesh::buildUnstructured() const throw(INTERP_KERNEL::Exception) +MEDCouplingUMesh *MEDCouplingStructuredMesh::buildUnstructured() const { - return build1SGTUnstructured()->buildUnstructured(); + MEDCouplingAutoRefCountObjectPtr ret0(build1SGTUnstructured()); + return ret0->buildUnstructured(); } /*! @@ -330,7 +435,7 @@ MEDCouplingMesh *MEDCouplingStructuredMesh::buildPartAndReduceNodes(const int *s } } -DataArrayInt *MEDCouplingStructuredMesh::simplexize(int policy) throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingStructuredMesh::simplexize(int policy) { throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::simplexize : not available for Cartesian mesh !"); } @@ -360,26 +465,475 @@ MEDCouplingFieldDouble *MEDCouplingStructuredMesh::buildOrthogonalField() const return ret; } +void MEDCouplingStructuredMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const +{ + std::vector ngs(getNodeGridStructure()); + int dim(getSpaceDimension()); + switch(dim) + { + case 1: + return GetReverseNodalConnectivity1(ngs,revNodal,revNodalIndx); + case 2: + return GetReverseNodalConnectivity2(ngs,revNodal,revNodalIndx); + case 3: + return GetReverseNodalConnectivity3(ngs,revNodal,revNodalIndx); + default: + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::getReverseNodalConnectivity : only dimensions 1, 2 and 3 are supported !"); + } +} + +void MEDCouplingStructuredMesh::GetReverseNodalConnectivity1(const std::vector& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx) +{ + int nbNodes(ngs[0]); + revNodalIndx->alloc(nbNodes+1,1); + if(nbNodes==0) + { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); return ; } + if(nbNodes==1) + { 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; + for(int i=1;i& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx) +{ + int nbNodesX(ngs[0]),nbNodesY(ngs[1]); + int nbNodes(nbNodesX*nbNodesY); + if(nbNodesX==0 || nbNodesY==0) + { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); return ; } + if(nbNodesX==1 || nbNodesY==1) + { std::vector ngs2(1); ngs2[0]=std::max(nbNodesX,nbNodesY); return GetReverseNodalConnectivity1(ngs2,revNodal,revNodalIndx); } + revNodalIndx->alloc(nbNodes+1,1); + int nbCellsX(nbNodesX-1),nbCellsY(nbNodesY-1); + revNodal->alloc(4*(nbNodesX-2)*(nbNodesY-2)+2*2*(nbNodesX-2)+2*2*(nbNodesY-2)+4,1); + int *rn(revNodal->getPointer()),*rni(revNodalIndx->getPointer()); + *rni++=0; *rni=1; *rn++=0; + for(int i=1;i& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx) +{ + int nbNodesX(ngs[0]),nbNodesY(ngs[1]),nbNodesZ(ngs[2]); + int nbNodes(nbNodesX*nbNodesY*nbNodesZ); + if(nbNodesX==0 || nbNodesY==0 || nbNodesZ==0) + { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); return ; } + if(nbNodesX==1 || nbNodesY==1 || nbNodesZ==1) + { + std::vector ngs2(2); + int pos(0); + bool pass(false); + for(int i=0;i<3;i++) + { + if(pass) + { ngs2[pos++]=ngs[i]; } + else + { + pass=ngs[i]==1; + if(!pass) + { ngs2[pos++]=ngs[i]; } + } + } + return GetReverseNodalConnectivity2(ngs2,revNodal,revNodalIndx); + } + revNodalIndx->alloc(nbNodes+1,1); + int nbCellsX(nbNodesX-1),nbCellsY(nbNodesY-1),nbCellsZ(nbNodesZ-1); + revNodal->alloc(8*(nbNodesX-2)*(nbNodesY-2)*(nbNodesZ-2)+4*(2*(nbNodesX-2)*(nbNodesY-2)+2*(nbNodesX-2)*(nbNodesZ-2)+2*(nbNodesY-2)*(nbNodesZ-2))+2*4*(nbNodesX-2)+2*4*(nbNodesY-2)+2*4*(nbNodesZ-2)+8,1); + int *rn(revNodal->getPointer()),*rni(revNodalIndx->getPointer()); + *rni=0; + for(int k=0;k=1 && j>=1 && i>=1) + *rn++=off00+i-1; + if(k>=1 && j>=1 && i=1 && j=1) + *rn++=off01+i-1; + if(k>=1 && j=1 && i>=1) + *rn++=off10+i-1; + if(k=1 && i=1) + *rn++=off11+i-1; + if(k conn(DataArrayInt::New()); + conn->alloc(1,1); conn->setIJ(0,0,0); + return conn.retn(); + } + case 1: + return Build1GTNodalConnectivity1D(zippedNodeSt); + case 2: + return Build1GTNodalConnectivity2D(zippedNodeSt); + case 3: + return Build1GTNodalConnectivity3D(zippedNodeSt); + default: + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::Build1GTNodalConnectivity : only dimension in [0,1,2,3] supported !"); + } +} + +DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh(const int *nodeStBg, const int *nodeStEnd) +{ + std::size_t dim(std::distance(nodeStBg,nodeStEnd)); + switch(dim) + { + case 3: + return Build1GTNodalConnectivityOfSubLevelMesh3D(nodeStBg); + case 2: + return Build1GTNodalConnectivityOfSubLevelMesh2D(nodeStBg); + default: + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh: only dimension in [2,3] supported !"); + } +} + +/*! + * This method returns the list of ids sorted ascendingly of entities that are in the corner in ghost zone. + * The ids are returned in a newly created DataArrayInt having a single component. + * + * \param [in] st - The structure \b without ghost cells. + * \param [in] ghostLev - The size of the ghost zone (>=0) + * \return DataArrayInt * - The DataArray containing all the ids the caller is to deallocate. + */ +DataArrayInt *MEDCouplingStructuredMesh::ComputeCornersGhost(const std::vector& st, int ghostLev) +{ + if(ghostLev<0) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ComputeCornersGhost : ghost lev must be >= 0 !"); + std::size_t dim(st.size()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); + switch(dim) + { case 1: - return Build1GTNodalConnectivity1D(nodeStBg); + { + ret->alloc(2*ghostLev,1); + int *ptr(ret->getPointer()); + for(int i=0;i= 0 !"); + for(int i=0;i= 0 !"); + ret->alloc(4*ghostLev,1); + int *ptr(ret->getPointer()); + for(int i=0;i= 0 !"); + ret->alloc(8*ghostLev,1); + int *ptr(ret->getPointer()); + int zeOffsetZ((offsetX+2*ghostLev)*(offsetY+2*ghostLev)); + for(int i=0;i=0;i--,j++) + { + *ptr++=i*(2*ghostLev+offsetX+1)+j*zeOffsetZ+zeOffsetZ2; + *ptr++=offsetX+2*ghostLev-1+i*(2*ghostLev+offsetX-1)+j*zeOffsetZ+zeOffsetZ2; + *ptr++=(2*ghostLev+offsetX)*(offsetY+ghostLev)+ghostLev-1+(ghostLev-i-1)*(2*ghostLev+offsetX-1)+j*zeOffsetZ+zeOffsetZ2; + *ptr++=(2*ghostLev+offsetX)*(offsetY+ghostLev)+offsetX+ghostLev+(ghostLev-i-1)*(2*ghostLev+offsetX+1)+j*zeOffsetZ+zeOffsetZ2; + } + break; + } default: - throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::Build1GTNodalConnectivity : only dimension in [1,2,3] supported !"); + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ComputeCornersGhost : Only dimensions 1, 2 and 3 are supported actually !"); + } + return ret.retn(); +} + +/*! + * This method retrieves the number of entities (it can be cells or nodes) given a range in compact standard format + * used in methods like BuildExplicitIdsFrom,IsPartStructured. + * + * \sa BuildExplicitIdsFrom,IsPartStructured + */ +int MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt(const std::vector< std::pair >& partCompactFormat) +{ + int ret(1); + std::size_t ii(0); + for(std::vector< std::pair >::const_iterator it=partCompactFormat.begin();it!=partCompactFormat.end();it++,ii++) + { + int a((*it).first),b((*it).second); + if(a<0 || b<0 || b-a<0) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt : invalid input at dimension " << ii << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + ret*=(b-a); + } + return ret; +} + +int MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(const std::vector& st) +{ + int ret(1); + bool isFetched(false); + for(std::size_t i=0;i >& partCompactFormat, int& axisId, int& sizeOfRange) +{ + int dim((int)partCompactFormat.size()); + int ret(-1); + for(int i=0;iret) + { + axisId=i; sizeOfRange=curDelta; + ret=curDelta; + } + } +} + +/*! + * This method is \b NOT wrapped in python because it has no sense in python (for performance reasons). + * This method starts from a structured mesh with structure \a st on which a boolean field \a crit is set. + * This method find for such minimalist information of mesh and field which is the part of the mesh, given by the range per axis in output parameter + * \a partCompactFormat that contains all the True in \a crit. The returned vector of boolean is the field reduced to that part. + * So the number of True is equal in \a st and in returned vector of boolean. + * + * \param [in] st - The structure per axis of the structured mesh considered. + * \param [in] crit - The field of boolean (for performance reasons) lying on the mesh defined by \a st. + * \param [out] partCompactFormat - The minimal part of \a st containing all the true of \a crit. + * \param [out] reducedCrit - The reduction of \a criterion on \a partCompactFormat. + * \return - The number of True in \a st (that is equal to those in \a reducedCrit) + */ +int MEDCouplingStructuredMesh::FindMinimalPartOf(const std::vector& st, const std::vector& crit, std::vector& reducedCrit, std::vector< std::pair >& partCompactFormat) +{ + if((int)crit.size()!=DeduceNumberOfGivenStructure(st)) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindMinimalPartOf : size of vector of boolean is invalid regarding the declared structure !"); + int ret(-1); + switch((int)st.size()) + { + case 1: + { + ret=FindMinimalPartOf1D(st,crit,partCompactFormat); + break; + } + case 2: + { + ret=FindMinimalPartOf2D(st,crit,partCompactFormat); + break; + } + case 3: + { + ret=FindMinimalPartOf3D(st,crit,partCompactFormat); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindMinimalPartOf : only dimension 1, 2 and 3 are supported actually !"); + } + ExtractFieldOfBoolFrom(st,crit,partCompactFormat,reducedCrit); + return ret; +} + +/*! + * This method is \b NOT wrapped in python. + * This method considers \a crit input parameter as a matrix having dimensions specified by \a st. This method returns for each axis + * the signature, that is to say the number of elems equal to true in \a crit along this axis. + */ +std::vector< std::vector > MEDCouplingStructuredMesh::ComputeSignaturePerAxisOf(const std::vector& st, const std::vector& crit) +{ + int dim((int)st.size()); + std::vector< std::vector > ret(dim); + switch(dim) + { + case 1: + { + int nx(st[0]); + ret[0].resize(nx); + std::vector& retX(ret[0]); + for(int i=0;i& retX(ret[0]); + for(int i=0;i& retY(ret[1]); + for(int j=0;j& retX(ret[0]); + for(int i=0;i& retY(ret[1]); + for(int j=0;j& retZ(ret[2]); + for(int k=0;k conn(DataArrayInt::New()); @@ -393,7 +947,7 @@ DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity1D(const int * return conn.retn(); } -DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity2D(const int *nodeStBg) throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity2D(const int *nodeStBg) { int n1=nodeStBg[0]-1; int n2=nodeStBg[1]-1; @@ -408,11 +962,11 @@ DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity2D(const int * cp[4*pos+1]=i+j*(n1+1); cp[4*pos+2]=i+(j+1)*(n1+1); cp[4*pos+3]=i+1+(j+1)*(n1+1); - } + } return conn.retn(); } -DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity3D(const int *nodeStBg) throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity3D(const int *nodeStBg) { int n1=nodeStBg[0]-1; int n2=nodeStBg[1]-1; @@ -438,66 +992,274 @@ DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity3D(const int * return conn.retn(); } -/*! - * Returns a cell id by its (i,j,k) index. The cell is located between the i-th and - * ( i + 1 )-th nodes along X axis etc. - * \param [in] i - a index of node coordinates array along X axis. - * \param [in] j - a index of node coordinates array along Y axis. - * \param [in] k - a index of node coordinates array along Z axis. - * \return int - a cell id in \a this mesh. - */ -int MEDCouplingStructuredMesh::getCellIdFromPos(int i, int j, int k) const +DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh3D(const int *nodeStBg) { - int tmp[3]={i,j,k}; - int tmp2[3]; - int meshDim=getMeshDimension(); - getSplitCellValues(tmp2); - std::transform(tmp,tmp+meshDim,tmp2,tmp,std::multiplies()); - return std::accumulate(tmp,tmp+meshDim,0); + 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()); + //X + for(int i=0;i()); - return std::accumulate(tmp,tmp+meshDim,0); -} - -void MEDCouplingStructuredMesh::GetPosFromId(int nodeId, int meshDim, const int *split, int *res) +int MEDCouplingStructuredMesh::FindMinimalPartOf1D(const std::vector& st, const std::vector& crit, std::vector< std::pair >& partCompactFormat) { - int work=nodeId; - for(int i=meshDim-1;i>=0;i--) + if(st.size()!=1) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindMinimalPartOf1D : the input size of st must be equal to 1 !"); + int nxMin(std::numeric_limits::max()),nxMax(-std::numeric_limits::max()); + int nx(st[0]),ret(0); + for(int i=0;i MEDCouplingStructuredMesh::getCellGridStructure() const throw(INTERP_KERNEL::Exception) -{ +/*! + * \sa MEDCouplingStructuredMesh::FindMinimalPartOf + */ +int MEDCouplingStructuredMesh::FindMinimalPartOf2D(const std::vector& st, const std::vector& crit, std::vector< std::pair >& partCompactFormat) +{ + if(st.size()!=2) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindMinimalPartOf2D : the input size of st must be equal to 2 !"); + int nxMin(std::numeric_limits::max()),nxMax(-std::numeric_limits::max()),nyMin(std::numeric_limits::max()),nyMax(-std::numeric_limits::max()); + int it(0),nx(st[0]),ny(st[1]); + int ret(0); + for(int i=0;i& st, const std::vector& crit, std::vector< std::pair >& partCompactFormat) +{ + if(st.size()!=3) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindMinimalPartOf3D : the input size of st must be equal to 3 !"); + int nxMin(std::numeric_limits::max()),nxMax(-std::numeric_limits::max()),nyMin(std::numeric_limits::max()),nyMax(-std::numeric_limits::max()),nzMin(std::numeric_limits::max()),nzMax(-std::numeric_limits::max()); + int it(0),nx(st[0]),ny(st[1]),nz(st[2]); + int ret(0); + for(int i=0;i3 || spaceDim<1) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ZipNodeStructure : spaceDim must in [1,2,3] !"); + zipNodeSt[0]=0; zipNodeSt[1]=0; zipNodeSt[2]=0; + int zippedI(0); + for(int i=0;i=2) + zipNodeSt[zippedI++]=elt; + } + return zippedI; +} + +DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh2D(const int *nodeStBg) +{ + std::vector 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()); + //X + for(int i=0;i()); + return std::accumulate(tmp,tmp+meshDim,0); +} + +/*! + * Returns a node id by its (i,j,k) index. + * \param [in] i - a index of node coordinates array along X axis. + * \param [in] j - a index of node coordinates array along Y axis. + * \param [in] k - a index of node coordinates array along Z axis. + * \return int - a node id in \a this mesh. + */ +int MEDCouplingStructuredMesh::getNodeIdFromPos(int i, int j, int k) const +{ + int tmp[3]={i,j,k}; + int tmp2[3]; + int spaceDim(getSpaceDimension()); + getSplitNodeValues(tmp2); + std::transform(tmp,tmp+spaceDim,tmp2,tmp,std::multiplies()); + return std::accumulate(tmp,tmp+spaceDim,0); +} + + +int MEDCouplingStructuredMesh::getNumberOfCells() const +{ + std::vector ngs(getNodeGridStructure()); + int ret(1); + bool isCatched(false); + std::size_t ii(0); + for(std::vector::const_iterator it=ngs.begin();it!=ngs.end();it++,ii++) + { + int elt(*it); + if(elt<=0) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::getNumberOfCells : at pos #" << ii << " the number of nodes in nodeStructure is " << *it << " ! Must be > 0 !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(elt>1) + { + ret*=elt-1; + isCatched=true; + } + } + return isCatched?ret:0; +} + +int MEDCouplingStructuredMesh::getNumberOfNodes() const +{ + std::vector ngs(getNodeGridStructure()); + int ret(1); + for(std::vector::const_iterator it=ngs.begin();it!=ngs.end();it++) + ret*=*it; + return ret; +} + +void MEDCouplingStructuredMesh::GetPosFromId(int nodeId, int meshDim, const int *split, int *res) +{ + int work=nodeId; + for(int i=meshDim-1;i>=0;i--) + { + int pos=work/split[i]; + work=work%split[i]; + res[i]=pos; + } +} + +std::vector MEDCouplingStructuredMesh::getCellGridStructure() const +{ std::vector ret(getNodeGridStructure()); std::transform(ret.begin(),ret.end(),ret.begin(),std::bind2nd(std::plus(),-1)); return ret; } +/*! + * Given a struct \a strct it returns a split vector [1,strct[0],strct[0]*strct[1]...] + * This decomposition allows to quickly find i,j,k given a global id. + */ +std::vector MEDCouplingStructuredMesh::GetSplitVectFromStruct(const std::vector& strct) +{ + int spaceDim((int)strct.size()); + std::vector res(spaceDim); + for(int l=0;l& st, std::vector< std::pair >& partCompactFormat) throw(INTERP_KERNEL::Exception) +bool MEDCouplingStructuredMesh::IsPartStructured(const int *startIds, const int *stopIds, const std::vector& st, std::vector< std::pair >& partCompactFormat) { int dim((int)st.size()); partCompactFormat.resize(dim); @@ -537,7 +1299,7 @@ bool MEDCouplingStructuredMesh::IsPartStructured(const int *startIds, const int return false; const int *w(startIds); switch(dim) - { + { case 3: { for(int i=0;i MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(const std::vector< std::pair >& partCompactFormat) +{ + std::vector ret(partCompactFormat.size()); + for(std::size_t i=0;ipartCompactFormat[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt : For axis #" << i << " end is before start !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + ret[i]=partCompactFormat[i].second-partCompactFormat[i].first; } + return ret; +} + +/*! + * This method takes in input a vector giving the number of entity per axis and returns for each axis a range starting from [0,0...] + * + * \throw if there is an axis in \a dims that is < 0. + * \sa GetDimensionsFromCompactFrmt, ChangeReferenceFromGlobalOfCompactFrmt, ChangeReferenceToGlobalOfCompactFrmt + */ +std::vector< std::pair > MEDCouplingStructuredMesh::GetCompactFrmtFromDimensions(const std::vector& dims) +{ + std::size_t sz(dims.size()); + std::vector< std::pair > ret(sz); + for(std::size_t i=0;i > MEDCouplingStructuredMesh::IntersectRanges(const std::vector< std::pair >& r1, const std::vector< std::pair >& r2) +{ + std::size_t sz(r1.size()); + if(sz!=r2.size()) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::IntersectRanges : the two ranges must have the same dimension !"); + std::vector< std::pair > ret(sz); + for(std::size_t i=0;ir1[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::IntersectRanges : On axis " << i << " of range r1, end is before start !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(r2[i].first>r2[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::IntersectRanges : On axis " << i << " of range r2, end is before start !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + ret[i].first=std::max(r1[i].first,r2[i].first); + ret[i].second=std::min(r1[i].second,r2[i].second); + if(ret[i].first>ret[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::IntersectRanges : On axis " << i << " the intersection of r1 and r2 is empty !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + return ret; +} + +/*! + * This method is close to BuildExplicitIdsFrom except that instead of returning a DataArrayInt instance containing explicit ids it + * enable elems in the vector of booleans (for performance reasons). As it is method for performance, this method is \b not + * available in python. + * + * \param [in] st The entity structure. + * \param [in] partCompactFormat The compact subpart to be enabled. + * \param [in,out] vectToSwitchOn Vector which fetched items are enabled. + * + * \sa MEDCouplingStructuredMesh::BuildExplicitIdsFrom, ExtractFieldOfBoolFrom + */ +void MEDCouplingStructuredMesh::SwitchOnIdsFrom(const std::vector& st, const std::vector< std::pair >& partCompactFormat, std::vector& vectToSwitchOn) +{ + if(st.size()!=partCompactFormat.size()) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::SwitchOnIdsFrom : input arrays must have the same size !"); + if((int)vectToSwitchOn.size()!=DeduceNumberOfGivenStructure(st)) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::SwitchOnIdsFrom : invalid size of input vector of boolean regarding the structure !"); + std::vector dims(GetDimensionsFromCompactFrmt(partCompactFormat)); + switch(st.size()) + { + case 3: + { + for(int i=0;i& st, const std::vector& fieldOfBool, const std::vector< std::pair >& partCompactFormat, std::vector& fieldOut) +{ + if(st.size()!=partCompactFormat.size()) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfBoolFrom : input arrays must have the same size !"); + if((int)fieldOfBool.size()!=DeduceNumberOfGivenStructure(st)) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfBoolFrom : invalid size of input field of boolean regarding the structure !"); + std::vector dims(GetDimensionsFromCompactFrmt(partCompactFormat)); + int nbOfTuplesOfOutField(DeduceNumberOfGivenStructure(dims)); + fieldOut.resize(nbOfTuplesOfOutField); + int it(0); + switch(st.size()) + { + case 3: + { + for(int i=0;i& st, const DataArrayDouble *fieldOfDbl, const std::vector< std::pair >& partCompactFormat) +{ + if(!fieldOfDbl || !fieldOfDbl->isAllocated()) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom : input array of double is NULL or not allocated!"); + if(st.size()!=partCompactFormat.size()) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom : input arrays must have the same size !"); + if(fieldOfDbl->getNumberOfTuples()!=DeduceNumberOfGivenStructure(st)) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ExtractFieldOfDoubleFrom : invalid size of input array of double regarding the structure !"); + std::vector dims(GetDimensionsFromCompactFrmt(partCompactFormat)); + int nbOfTuplesOfOutField(DeduceNumberOfGivenStructure(dims)),nbComp(fieldOfDbl->getNumberOfComponents()); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); ret->alloc(nbOfTuplesOfOutField,nbComp); + ret->copyStringInfoFrom(*fieldOfDbl); + double *ptRet(ret->getPointer()); + const double *fieldOfDblPtr(fieldOfDbl->begin()); + switch(st.size()) + { + case 3: + { + for(int i=0;i >& bigInAbs, const std::vector< std::pair >& partOfBigInAbs, std::vector< std::pair >& partOfBigRelativeToBig, bool check) +{ + std::size_t dim(bigInAbs.size()); + if(dim!=partOfBigInAbs.size()) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : The size of parts (dimension) must be the same !"); + partOfBigRelativeToBig.resize(dim); + for(std::size_t i=0;ibigInAbs[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the input big part invalid, end before start !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(partOfBigInAbs[i].first=bigInAbs[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the part is not included in the big one (start) !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + partOfBigRelativeToBig[i].first=partOfBigInAbs[i].first-bigInAbs[i].first; + if(check) + { + if(partOfBigInAbs[i].secondbigInAbs[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceFromGlobalOfCompactFrmt : Error at axis #" << i << " the part is not included in the big one (end) !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + partOfBigRelativeToBig[i].second=partOfBigInAbs[i].second-bigInAbs[i].first; + } +} + +/* + * This method is performs the opposite reference modification than explained in ChangeReferenceFromGlobalOfCompactFrmt. + * + * \sa ChangeReferenceFromGlobalOfCompactFrmt + */ +void MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt(const std::vector< std::pair >& bigInAbs, const std::vector< std::pair >& partOfBigRelativeToBig, std::vector< std::pair >& partOfBigInAbs, bool check) +{ + std::size_t dim(bigInAbs.size()); + if(dim!=partOfBigRelativeToBig.size()) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : The size of parts (dimension) must be the same !"); + partOfBigInAbs.resize(dim); + for(std::size_t i=0;ibigInAbs[i].second) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the input big part invalid, end before start !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(partOfBigRelativeToBig[i].first<0 || partOfBigRelativeToBig[i].first>=bigInAbs[i].second-bigInAbs[i].first) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the start of part is not in the big one !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + partOfBigInAbs[i].first=partOfBigRelativeToBig[i].first+bigInAbs[i].first; + if(check) + { + if(partOfBigRelativeToBig[i].secondbigInAbs[i].second-bigInAbs[i].first) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::ChangeReferenceToGlobalOfCompactFrmt : Error at axis #" << i << " the end of part is not in the big one !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + partOfBigInAbs[i].second=partOfBigRelativeToBig[i].second+bigInAbs[i].first; + } +} + +/*! + * This method performs a translation (defined by \a translation) of \a part and returns the result of translated part. + * + * \sa FindTranslationFrom + */ +std::vector< std::pair > MEDCouplingStructuredMesh::TranslateCompactFrmt(const std::vector< std::pair >& part, const std::vector& translation) +{ + std::size_t sz(part.size()); + if(translation.size()!=sz) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::TranslateCompactFrmt : the sizes are not equal !"); + std::vector< std::pair > ret(sz); + for(std::size_t i=0;i MEDCouplingStructuredMesh::FindTranslationFrom(const std::vector< std::pair >& startingFrom, const std::vector< std::pair >& goingTo) +{ + std::size_t sz(startingFrom.size()); + if(goingTo.size()!=sz) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::FindTranslationFrom : the sizes are not equal !"); + std::vector< int > ret(sz); + for(std::size_t i=0;i& st, const std::vector< std::pair >& partCompactFormat) throw(INTERP_KERNEL::Exception) +DataArrayInt *MEDCouplingStructuredMesh::BuildExplicitIdsFrom(const std::vector& st, const std::vector< std::pair >& partCompactFormat) { if(st.size()!=partCompactFormat.size()) throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : input arrays must have the same size !"); @@ -601,7 +1734,7 @@ DataArrayInt *MEDCouplingStructuredMesh::BuildExplicitIdsFrom(const std::vector< throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : invalid input range 1 !"); if(partCompactFormat[i].second<0 || partCompactFormat[i].second>st[i]) throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::BuildExplicitIdsFrom : invalid input range 2 !"); - if(partCompactFormat[i].second<=partCompactFormat[i].first) + if(partCompactFormat[i].secondalloc(nbOfItems,1); int *pt(ret->getPointer()); switch(st.size()) - { + { case 3: { for(int i=0;i& st, const std::vector< std::pair >& part, double factor, DataArrayDouble *da) +{ + if(!da || !da->isAllocated()) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : DataArrayDouble instance must be not NULL and allocated !"); + if(st.size()!=part.size()) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : input arrays must have the same size !"); + std::vector dims(st.size()); + for(std::size_t i=0;ist[i]) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : invalid input range 1 !"); + if(part[i].second<0 || part[i].second>st[i]) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : invalid input range 2 !"); + if(part[i].secondgetNumberOfComponents()); + if(da->getNumberOfTuples()!=nbOfTuplesExp) + { + std::ostringstream oss; oss << "MEDCouplingStructuredMesh::MultiplyPartOf : invalid nb of tuples ! Expected " << nbOfTuplesExp << " having " << da->getNumberOfTuples() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + double *pt(da->getPointer()); + switch(st.size()) + { + case 3: + { + for(int i=0;i(),factor)); + } + } + } + break; + } + case 2: + { + for(int j=0;j(),factor)); + } + } + break; + } + case 1: + { + for(int k=0;k(),factor)); + } + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::MultiplyPartOf : Dimension supported are 1,2 or 3 !"); + } +} + +/*! + * This method multiplies by \a factor values in tuples located by \a part in \a da. + * + * \param [in] st - the structure of grid ( \b without considering ghost cells). + * \param [in] part - the part in the structure ( \b without considering ghost cells) contained in grid whose structure is defined by \a st. + * \param [in] ghostSize - \a ghostSize must be >= 0. + * \param [in] factor - the factor, the tuples in \a da will be multiply by. + * \param [in,out] da - The DataArray in wich only tuples specified by \a part will be modified. + * + * \sa MultiplyPartOf, PutInGhostFormat + */ +void MEDCouplingStructuredMesh::MultiplyPartOfByGhost(const std::vector& st, const std::vector< std::pair >& part, int ghostSize, double factor, DataArrayDouble *da) +{ + std::vector stWG; + std::vector< std::pair > partWG; + PutInGhostFormat(ghostSize,st,part,stWG,partWG); + MultiplyPartOf(stWG,partWG,factor,da); +} + +/*! + * This method multiplies by \a factor values in tuples located by \a part in \a da. + * + * \param [in] st - the structure of grid ( \b without considering ghost cells). + * \param [in] part - the part in the structure ( \b without considering ghost cells) contained in grid whose structure is defined by \a st. + * \param [in] ghostSize - \a ghostSize must be >= 0. + * \param [out] stWithGhost - the structure considering ghost cells. + * \param [out] partWithGhost - the part considering the ghost cells. + * + * \sa MultiplyPartOf, PutInGhostFormat + */ +void MEDCouplingStructuredMesh::PutInGhostFormat(int ghostSize, const std::vector& st, const std::vector< std::pair >& part, std::vector& stWithGhost, std::vector< std::pair >&partWithGhost) +{ + if(ghostSize<0) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::PutInGhostFormat : ghost size must be >= 0 !"); + std::size_t dim(part.size()); + if(st.size()!=dim) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::PutInGhostFormat : the dimension of input vectors must be the same !"); + for(std::size_t i=0;ipart[i].second || part[i].second>st[i]) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::PutInGhostFormat : the specified part is invalid ! The begin must be >= 0 and <= end ! The end must be <= to the size at considered dimension !"); + stWithGhost.resize(st.size()); + std::transform(st.begin(),st.end(),stWithGhost.begin(),std::bind2nd(std::plus(),2*ghostSize)); + partWithGhost=part; + ApplyGhostOnCompactFrmt(partWithGhost,ghostSize); +} + +/*! + * \param [in,out] partBeforeFact - the part of a image mesh in compact format that will be put in ghost reference. + * \param [in] ghostSize - the ghost size of zone for all axis. + */ +void MEDCouplingStructuredMesh::ApplyGhostOnCompactFrmt(std::vector< std::pair >& partBeforeFact, int ghostSize) +{ + if(ghostSize<0) + throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::ApplyGhostOnCompactFrmt : ghost size must be >= 0 !"); + std::size_t sz(partBeforeFact.size()); + for(std::size_t i=0;i& cgs, int mdim) +{ + int ret(0); + for(int i=0;i