X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingIMesh.cxx;h=6ba02d4a028c28aeb404120a8d67d4563977ee67;hb=7de62920cadf9bfcd33addf31d4a8256bffaf1ec;hp=30458429b83f5c11cd7083d2a782ad04add04ecd;hpb=6bfd8d6afb47fa46fd8fa0bc98d7fe057790460c;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingIMesh.cxx b/src/MEDCoupling/MEDCouplingIMesh.cxx index 30458429b..6ba02d4a0 100644 --- a/src/MEDCoupling/MEDCouplingIMesh.cxx +++ b/src/MEDCoupling/MEDCouplingIMesh.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D +// Copyright (C) 2007-2016 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 @@ -16,7 +16,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// Author : Anthony Geay (CEA/DEN) +// Author : Anthony Geay (EDF R&D) #include "MEDCouplingIMesh.hxx" #include "MEDCouplingCMesh.hxx" @@ -28,7 +28,7 @@ #include #include -using namespace ParaMEDMEM; +using namespace MEDCoupling; MEDCouplingIMesh::MEDCouplingIMesh():_space_dim(-1) { @@ -37,7 +37,7 @@ MEDCouplingIMesh::MEDCouplingIMesh():_space_dim(-1) _structure[0]=0; _structure[1]=0; _structure[2]=0; } -MEDCouplingIMesh::MEDCouplingIMesh(const MEDCouplingIMesh& other, bool deepCopy):MEDCouplingStructuredMesh(other,deepCopy),_space_dim(other._space_dim),_axis_unit(other._axis_unit) +MEDCouplingIMesh::MEDCouplingIMesh(const MEDCouplingIMesh& other, bool deepCpy):MEDCouplingStructuredMesh(other,deepCpy),_space_dim(other._space_dim),_axis_unit(other._axis_unit) { _origin[0]=other._origin[0]; _origin[1]=other._origin[1]; _origin[2]=other._origin[2]; _dxyz[0]=other._dxyz[0]; _dxyz[1]=other._dxyz[1]; _dxyz[2]=other._dxyz[2]; @@ -56,7 +56,7 @@ MEDCouplingIMesh *MEDCouplingIMesh::New() MEDCouplingIMesh *MEDCouplingIMesh::New(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop, const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop) { - MEDCouplingAutoRefCountObjectPtr ret(new MEDCouplingIMesh); + MCAuto ret(new MEDCouplingIMesh); ret->setName(meshName); ret->setSpaceDimension(spaceDim); ret->setNodeStruct(nodeStrctStart,nodeStrctStop); @@ -65,7 +65,7 @@ MEDCouplingIMesh *MEDCouplingIMesh::New(const std::string& meshName, int spaceDi return ret.retn(); } -MEDCouplingMesh *MEDCouplingIMesh::deepCpy() const +MEDCouplingIMesh *MEDCouplingIMesh::deepCopy() const { return clone(true); } @@ -75,6 +75,11 @@ MEDCouplingIMesh *MEDCouplingIMesh::clone(bool recDeepCpy) const return new MEDCouplingIMesh(*this,recDeepCpy); } +const DataArrayDouble *MEDCouplingIMesh::getDirectAccessOfCoordsArrIfInStructure() const +{ + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::getDirectAccessOfCoordsArrIfInStructure : MEDCouplingIMesh does not aggregate array of coordinates !"); +} + /*! * This method creates a copy of \a this enlarged by \a ghostLev cells on each axis. * If \a ghostLev equal to 0 this method behaves as MEDCouplingIMesh::clone. @@ -87,7 +92,7 @@ MEDCouplingIMesh *MEDCouplingIMesh::buildWithGhost(int ghostLev) const { if(ghostLev<0) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::buildWithGhost : the ghostLev must be >= 0 !"); - checkCoherency(); + checkConsistencyLight(); int spaceDim(getSpaceDimension()); double origin[3],dxyz[3]; int structure[3]; @@ -97,7 +102,7 @@ MEDCouplingIMesh *MEDCouplingIMesh::buildWithGhost(int ghostLev) const dxyz[i]=_dxyz[i]; structure[i]=_structure[i]+2*ghostLev; } - MEDCouplingAutoRefCountObjectPtr ret(MEDCouplingIMesh::New(getName(),spaceDim,structure,structure+spaceDim,origin,origin+spaceDim,dxyz,dxyz+spaceDim)); + MCAuto ret(MEDCouplingIMesh::New(getName(),spaceDim,structure,structure+spaceDim,origin,origin+spaceDim,dxyz,dxyz+spaceDim)); ret->copyTinyInfoFrom(this); return ret.retn(); } @@ -170,7 +175,7 @@ std::string MEDCouplingIMesh::getAxisUnit() const */ double MEDCouplingIMesh::getMeasureOfAnyCell() const { - checkCoherency(); + checkConsistencyLight(); int dim(getSpaceDimension()); double ret(1.); for(int i=0;i ret(MEDCouplingCMesh::New()); + checkConsistencyLight(); + MCAuto ret(MEDCouplingCMesh::New()); try { ret->copyTinyInfoFrom(this); } catch(INTERP_KERNEL::Exception& ) { } @@ -196,7 +201,7 @@ MEDCouplingCMesh *MEDCouplingIMesh::convertToCartesian() const std::vector infos(buildInfoOnComponents()); for(int i=0;i arr(DataArrayDouble::New()); arr->alloc(_structure[i],1); arr->setInfoOnComponent(0,infos[i]); + MCAuto arr(DataArrayDouble::New()); arr->alloc(_structure[i],1); arr->setInfoOnComponent(0,infos[i]); arr->iota(); arr->applyLin(_dxyz[i],_origin[i]); ret->setCoordsAt(i,arr); } @@ -213,7 +218,7 @@ void MEDCouplingIMesh::refineWithFactor(const std::vector& factors) { if((int)factors.size()!=_space_dim) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::refineWithFactor : refinement factors must have size equal to spaceDim !"); - checkCoherency(); + checkConsistencyLight(); std::vector structure(_structure,_structure+3); std::vector dxyz(_dxyz,_dxyz+3); for(int i=0;i<_space_dim;i++) @@ -238,11 +243,11 @@ void MEDCouplingIMesh::refineWithFactor(const std::vector& factors) * * \return MEDCouplingIMesh * - A newly created object (to be managed by the caller with decrRef) containing simply one cell. * - * \throw if \a this does not pass the \c checkCoherency test. + * \throw if \a this does not pass the \c checkConsistencyLight test. */ MEDCouplingIMesh *MEDCouplingIMesh::asSingleCell() const { - checkCoherency(); + checkConsistencyLight(); int spaceDim(getSpaceDimension()),nodeSt[3]; double dxyz[3]; for(int i=0;i ret(MEDCouplingIMesh::New(getName(),getSpaceDimension(),nodeSt,nodeSt+spaceDim,_origin,_origin+spaceDim,dxyz,dxyz+spaceDim)); + MCAuto ret(MEDCouplingIMesh::New(getName(),getSpaceDimension(),nodeSt,nodeSt+spaceDim,_origin,_origin+spaceDim,dxyz,dxyz+spaceDim)); ret->copyTinyInfoFrom(this); return ret.retn(); } /*! * This static method is useful to condense field on cells of a MEDCouplingIMesh instance coming from a refinement ( MEDCouplingIMesh::refineWithFactor for example) - * to a coarse MEDCouplingIMesh instance. So this method can be seen as a specialization in P0P0 conservative interpolation non overlaping from fine image mesh + * to a coarse MEDCouplingIMesh instance. So this method can be seen as a specialization in P0P0 conservative interpolation non overlapping from fine image mesh * to a coarse image mesh. Only tuples ( deduced from \a fineLocInCoarse ) of \a coarseDA will be modified. Other tuples of \a coarseDA will be let unchanged. * * \param [in] coarseSt The cell structure of coarse mesh. @@ -278,11 +283,13 @@ MEDCouplingIMesh *MEDCouplingIMesh::asSingleCell() const */ void MEDCouplingIMesh::CondenseFineToCoarse(const std::vector& coarseSt, const DataArrayDouble *fineDA, const std::vector< std::pair >& fineLocInCoarse, const std::vector& facts, DataArrayDouble *coarseDA) { + if(coarseSt.size()!=fineLocInCoarse.size() || coarseSt.size()!=facts.size()) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : All input vectors (dimension) must have the same size !"); if(!coarseDA || !coarseDA->isAllocated() || !fineDA || !fineDA->isAllocated()) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : the parameters 1 or 3 are NULL or not allocated !"); int meshDim((int)coarseSt.size()),nbOfTuplesInCoarseExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(coarseSt)),nbOfTuplesInFineExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt(fineLocInCoarse)); int nbCompo(fineDA->getNumberOfComponents()); - if(coarseDA->getNumberOfComponents()!=nbCompo) + if((int)coarseDA->getNumberOfComponents()!=nbCompo) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : the number of components of fine DA and coarse one mismatches !"); if(meshDim!=(int)fineLocInCoarse.size() || meshDim!=(int)facts.size()) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : the size of fineLocInCoarse (4th param) and facts (5th param) must be equal to the sier of coarseSt (2nd param) !"); @@ -292,6 +299,13 @@ void MEDCouplingIMesh::CondenseFineToCoarse(const std::vector& coarseSt, co throw INTERP_KERNEL::Exception(oss.str().c_str()); } int nbTuplesFine(fineDA->getNumberOfTuples()); + if(nbOfTuplesInFineExp==0) + { + if(nbTuplesFine==0) + return ; + else + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : Nothing to condense considering the range specified ! But DataArray is not empty !"); + } if(nbTuplesFine%nbOfTuplesInFineExp!=0) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarse : Invalid nb of tuples in fine DataArray regarding its structure !"); int fact(std::accumulate(facts.begin(),facts.end(),1,std::multiplies())); @@ -382,7 +396,7 @@ void MEDCouplingIMesh::CondenseFineToCoarse(const std::vector& coarseSt, co /*! * This static method is useful to condense field on cells of a MEDCouplingIMesh instance coming from a refinement ( MEDCouplingIMesh::refineWithFactor for example) - * to a coarse MEDCouplingIMesh instance. So this method can be seen as a specialization in P0P0 conservative interpolation non overlaping from fine image mesh + * to a coarse MEDCouplingIMesh instance. So this method can be seen as a specialization in P0P0 conservative interpolation non overlapping from fine image mesh * to a coarse image mesh. Only tuples ( deduced from \a fineLocInCoarse ) of \a coarseDA will be modified. Other tuples of \a coarseDA will be let unchanged. * * \param [in] coarseSt The cell structure of coarse mesh. @@ -397,30 +411,34 @@ void MEDCouplingIMesh::CondenseFineToCoarse(const std::vector& coarseSt, co void MEDCouplingIMesh::CondenseFineToCoarseGhost(const std::vector& coarseSt, const DataArrayDouble *fineDA, const std::vector< std::pair >& fineLocInCoarse, const std::vector& facts, DataArrayDouble *coarseDA, int ghostSize) { if(ghostSize<0) - throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarseGhost : ghost level >= 0 !"); + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarseGhost : ghost level has to be >= 0 !"); + if(coarseSt.size()!=fineLocInCoarse.size() || coarseSt.size()!=facts.size()) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarseGhost : All input vectors (dimension) must have the same size !"); if(!coarseDA || !coarseDA->isAllocated() || !fineDA || !fineDA->isAllocated()) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarseGhost : the parameters 1 or 3 are NULL or not allocated !"); std::vector coarseStG(coarseSt.size()); std::transform(coarseSt.begin(),coarseSt.end(),coarseStG.begin(),std::bind2nd(std::plus(),2*ghostSize)); - //std::vector fineStG(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); - //std::transform(fineStG.begin(),fineStG.end(),fineStG.begin(),std::bind2nd(std::plus(),2*ghostSize)); int meshDim((int)coarseSt.size()),nbOfTuplesInCoarseExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(coarseStG)); int nbCompo(fineDA->getNumberOfComponents()); - if(coarseDA->getNumberOfComponents()!=nbCompo) + if((int)coarseDA->getNumberOfComponents()!=nbCompo) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarseGhost : the number of components of fine DA and coarse one mismatches !"); if(meshDim!=(int)fineLocInCoarse.size() || meshDim!=(int)facts.size()) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarseGhost : the size of fineLocInCoarse (4th param) and facts (5th param) must be equal to the sier of coarseSt (2nd param) !"); if(coarseDA->getNumberOfTuples()!=nbOfTuplesInCoarseExp) { - std::ostringstream oss; oss << "MEDCouplingIMesh::CondenseFineToCoarseGhost : Expecting " << nbOfTuplesInCoarseExp << " tuples having " << coarseDA->getNumberOfTuples() << " !"; + std::ostringstream oss; oss << "MEDCouplingIMesh::CondenseFineToCoarseGhost : Expecting " << nbOfTuplesInCoarseExp << " tuples in coarse DataArray having " << coarseDA->getNumberOfTuples() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - //int nbTuplesFine(fineDA->getNumberOfTuples()); - //int fact(std::accumulate(facts.begin(),facts.end(),1,std::multiplies())); - /*if(nbTuplesFine!=fact*nbOfTuplesInFineExp) + // + std::vector fineStG(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); + std::transform(fineStG.begin(),fineStG.end(),facts.begin(),fineStG.begin(),std::multiplies()); + std::transform(fineStG.begin(),fineStG.end(),fineStG.begin(),std::bind2nd(std::plus(),2*ghostSize)); + int nbTuplesFine(fineDA->getNumberOfTuples()),nbTuplesFineExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(fineStG)); + if(fineDA->getNumberOfTuples()!=nbTuplesFineExp) { - std::ostringstream oss; oss << "MEDCouplingIMesh::CondenseFineToCoarseGhost : Invalid number of tuples (" << nbTuplesFine << ") of fine dataarray is invalid ! Must be " << fact*nbOfTuplesInFineExp << "!"; + std::ostringstream oss; oss << "MEDCouplingIMesh::CondenseFineToCoarseGhost : Expecting " << nbTuplesFineExp << " tuples in fine DataArray having " << nbTuplesFine << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); - }*/ + } + // double *outPtr(coarseDA->getPointer()); const double *inPtr(fineDA->begin()); // @@ -448,7 +466,7 @@ void MEDCouplingIMesh::CondenseFineToCoarseGhost(const std::vector& coarseS { int nxwg(coarseSt[0]+2*ghostSize); int kk(fineLocInCoarse[0].first+ghostSize+nxwg*(fineLocInCoarse[1].first+ghostSize)),fact1(facts[1]),fact0(facts[0]); - inPtr+=(dims[0]*fact0+2*ghostSize)*nbCompo; + inPtr+=(dims[0]*fact0+2*ghostSize)*ghostSize*nbCompo; for(int j=0;j& coarseS } break; } + case 3: + { + int nxwg(coarseSt[0]+2*ghostSize),nxywg((coarseSt[0]+2*ghostSize)*(coarseSt[1]+2*ghostSize)); + int kk(fineLocInCoarse[0].first+ghostSize+nxwg*(fineLocInCoarse[1].first+ghostSize)+nxywg*(fineLocInCoarse[2].first+ghostSize)),fact2(facts[2]),fact1(facts[1]),fact0(facts[0]); + inPtr+=(dims[0]*fact0+2*ghostSize)*(dims[1]*fact1+2*ghostSize)*ghostSize*nbCompo; + for(int k=0;k()); + else + std::copy(inPtr,inPtr+nbCompo,loc); + } + } + inPtr+=ghostSize*nbCompo; + } + } + inPtr+=ghostSize*(dims[0]*fact0+2*ghostSize)*nbCompo; + } + kk+=nxywg; + } + break; + } default: - throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarseGhost : only dimensions 1, 2 supported !"); + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::CondenseFineToCoarseGhost : only dimensions 1, 2, 3 supported !"); } } @@ -488,11 +542,13 @@ void MEDCouplingIMesh::CondenseFineToCoarseGhost(const std::vector& coarseS */ void MEDCouplingIMesh::SpreadCoarseToFine(const DataArrayDouble *coarseDA, const std::vector& coarseSt, DataArrayDouble *fineDA, const std::vector< std::pair >& fineLocInCoarse, const std::vector& facts) { + if(coarseSt.size()!=fineLocInCoarse.size() || coarseSt.size()!=facts.size()) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFine : All input vectors (dimension) must have the same size !"); if(!coarseDA || !coarseDA->isAllocated() || !fineDA || !fineDA->isAllocated()) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFine : the parameters 1 or 3 are NULL or not allocated !"); int meshDim((int)coarseSt.size()),nbOfTuplesInCoarseExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(coarseSt)),nbOfTuplesInFineExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt(fineLocInCoarse)); int nbCompo(fineDA->getNumberOfComponents()); - if(coarseDA->getNumberOfComponents()!=nbCompo) + if((int)coarseDA->getNumberOfComponents()!=nbCompo) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFine : the number of components of fine DA and coarse one mismatches !"); if(meshDim!=(int)fineLocInCoarse.size() || meshDim!=(int)facts.size()) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFine : the size of fineLocInCoarse (4th param) and facts (5th param) must be equal to the sier of coarseSt (2nd param) !"); @@ -584,19 +640,21 @@ void MEDCouplingIMesh::SpreadCoarseToFine(const DataArrayDouble *coarseDA, const * \param [in] fineLocInCoarse The cell localization of refined mesh into the coarse one. * \param [in] facts The refinement coefficient per axis. * \param [in] ghostSize - The size of the ghost zone. The ghost zone is expected to be the same for all axis and both for coarse and fine meshes. - * \sa CondenseFineToCoarse + * + * \sa CondenseFineToCoarse, SpreadCoarseToFineGhostZone */ void MEDCouplingIMesh::SpreadCoarseToFineGhost(const DataArrayDouble *coarseDA, const std::vector& coarseSt, DataArrayDouble *fineDA, const std::vector< std::pair >& fineLocInCoarse, const std::vector& facts, int ghostSize) { if(ghostSize<0) - throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhost : ghost level >= 0 !"); + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhost : ghost level has to be >= 0 !"); + if(coarseSt.size()!=fineLocInCoarse.size() || coarseSt.size()!=facts.size()) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhost : All input vectors (dimension) must have the same size !"); if(!coarseDA || !coarseDA->isAllocated() || !fineDA || !fineDA->isAllocated()) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhost : the parameters 1 or 3 are NULL or not allocated !"); std::vector coarseStG(coarseSt.size()); std::transform(coarseSt.begin(),coarseSt.end(),coarseStG.begin(),std::bind2nd(std::plus(),2*ghostSize)); - //std::vector fineStG(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); std::transform(fineStG.begin(),fineStG.end(),fineStG.begin(),std::bind2nd(std::plus(),2*ghostSize)); int meshDim((int)coarseSt.size()),nbOfTuplesInCoarseExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(coarseStG)); int nbCompo(fineDA->getNumberOfComponents()); - if(coarseDA->getNumberOfComponents()!=nbCompo) + if((int)coarseDA->getNumberOfComponents()!=nbCompo) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhost : the number of components of fine DA and coarse one mismatches !"); if(meshDim!=(int)fineLocInCoarse.size() || meshDim!=(int)facts.size()) throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhost : the size of fineLocInCoarse (4th param) and facts (5th param) must be equal to the sier of coarseSt (2nd param) !"); @@ -605,24 +663,25 @@ void MEDCouplingIMesh::SpreadCoarseToFineGhost(const DataArrayDouble *coarseDA, std::ostringstream oss; oss << "MEDCouplingIMesh::SpreadCoarseToFineGhost : Expecting " << nbOfTuplesInCoarseExp << " tuples having " << coarseDA->getNumberOfTuples() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - /*int nbTuplesFine(fineDA->getNumberOfTuples()); - if(nbTuplesFine%nbOfTuplesInFineExp!=0) - throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhost : Invalid nb of tuples in fine DataArray regarding its structure !"); - int fact(std::accumulate(facts.begin(),facts.end(),1,std::multiplies())); - if(nbTuplesFine!=fact*nbOfTuplesInFineExp) + // + std::vector fineStG(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); + std::transform(fineStG.begin(),fineStG.end(),facts.begin(),fineStG.begin(),std::multiplies()); + std::transform(fineStG.begin(),fineStG.end(),fineStG.begin(),std::bind2nd(std::plus(),2*ghostSize)); + int nbTuplesFine(fineDA->getNumberOfTuples()),nbTuplesFineExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(fineStG)); + if(fineDA->getNumberOfTuples()!=nbTuplesFineExp) { - std::ostringstream oss; oss << "MEDCouplingIMesh::SpreadCoarseToFineGhost : Invalid number of tuples (" << nbTuplesFine << ") of fine dataarray is invalid ! Must be " << fact*nbOfTuplesInFineExp << "!"; + std::ostringstream oss; oss << "MEDCouplingIMesh::SpreadCoarseToFineGhost : Expecting " << nbTuplesFineExp << " tuples in fine DataArray having " << nbTuplesFine << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); - }*/ + } // double *outPtr(fineDA->getPointer()); const double *inPtr(coarseDA->begin()); // - std::vector dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); switch(meshDim) { case 1: { + std::vector dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); int offset(fineLocInCoarse[0].first+ghostSize-1),fact0(facts[0]);//offset is always >=0 thanks to the fact that ghostSize>=1 ! for(int i=0;i=0 thanks to the fact that ghostSize>=1 ! - for(int jg=0;jg dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); + int fact0(facts[0]),fact1(facts[1]),fact2(facts[2]); + int nxyWgCoarse((coarseSt[0]+2*ghostSize)*(coarseSt[1]+2*ghostSize)),nxyWgFine((dims[0]*fact0+2*ghostSize)*(dims[1]*fact1+2*ghostSize)); + int offset((fineLocInCoarse[2].first+ghostSize-1)*nxyWgCoarse);//offset is always >=0 thanks to the fact that ghostSize>=1 ! + for(int i=0;i& coarseSt, DataArrayDouble *fineDA, const std::vector< std::pair >& fineLocInCoarse, const std::vector& facts, int ghostSize) +{ + if(ghostSize<0) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhostZone : ghost level has to be >= 0 !"); + if(coarseSt.size()!=fineLocInCoarse.size() || coarseSt.size()!=facts.size()) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhostZone : All input vectors (dimension) must have the same size !"); + if(!coarseDA || !coarseDA->isAllocated() || !fineDA || !fineDA->isAllocated()) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhostZone : the parameters 1 or 3 are NULL or not allocated !"); + std::vector coarseStG(coarseSt.size()); std::transform(coarseSt.begin(),coarseSt.end(),coarseStG.begin(),std::bind2nd(std::plus(),2*ghostSize)); + int meshDim((int)coarseSt.size()),nbOfTuplesInCoarseExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(coarseStG)); + int nbCompo(fineDA->getNumberOfComponents()); + if((int)coarseDA->getNumberOfComponents()!=nbCompo) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhostZone : the number of components of fine DA and coarse one mismatches !"); + if(meshDim!=(int)fineLocInCoarse.size() || meshDim!=(int)facts.size()) + throw INTERP_KERNEL::Exception("MEDCouplingIMesh::SpreadCoarseToFineGhostZone : the size of fineLocInCoarse (4th param) and facts (5th param) must be equal to the sier of coarseSt (2nd param) !"); + if(coarseDA->getNumberOfTuples()!=nbOfTuplesInCoarseExp) + { + std::ostringstream oss; oss << "MEDCouplingIMesh::SpreadCoarseToFineGhostZone : Expecting " << nbOfTuplesInCoarseExp << " tuples having " << coarseDA->getNumberOfTuples() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + // + std::vector fineStG(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); + std::transform(fineStG.begin(),fineStG.end(),facts.begin(),fineStG.begin(),std::multiplies()); + std::transform(fineStG.begin(),fineStG.end(),fineStG.begin(),std::bind2nd(std::plus(),2*ghostSize)); + int nbTuplesFine(fineDA->getNumberOfTuples()),nbTuplesFineExp(MEDCouplingStructuredMesh::DeduceNumberOfGivenStructure(fineStG)); + if(fineDA->getNumberOfTuples()!=nbTuplesFineExp) + { + std::ostringstream oss; oss << "MEDCouplingIMesh::SpreadCoarseToFineGhostZone : Expecting " << nbTuplesFineExp << " tuples in fine DataArray having " << nbTuplesFine << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + // + double *outPtr(fineDA->getPointer()); + const double *inPtr(coarseDA->begin()); + // + std::vector dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); + switch(meshDim) + { + case 1: + { + int offset(fineLocInCoarse[0].first+ghostSize-1),fact0(facts[0]);//offset is always >=0 thanks to the fact that ghostSize>=1 ! + for(int i=0;i=0 thanks to the fact that ghostSize>=1 ! + for(int i=0;i MEDCouplingIMesh::getDirectChildren() const +std::vector MEDCouplingIMesh::getDirectChildrenWithNull() const { return std::vector(); } @@ -810,8 +928,8 @@ void MEDCouplingIMesh::checkDeepEquivalWith(const MEDCouplingMesh *other, int ce } /*! - * Nothing is done here (except to check that the other is a ParaMEDMEM::MEDCouplingIMesh instance too). - * The user intend that the nodes are the same, so by construction of ParaMEDMEM::MEDCouplingIMesh, \a this and \a other are the same ! + * Nothing is done here (except to check that the other is a MEDCoupling::MEDCouplingIMesh instance too). + * The user intend that the nodes are the same, so by construction of MEDCoupling::MEDCouplingIMesh, \a this and \a other are the same ! */ void MEDCouplingIMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec, DataArrayInt *&cellCor) const @@ -820,25 +938,20 @@ void MEDCouplingIMesh::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *ot throw INTERP_KERNEL::Exception("MEDCouplingIMesh::checkDeepEquivalOnSameNodesWith : Meshes are not the same !"); } -void MEDCouplingIMesh::checkCoherency() const +void MEDCouplingIMesh::checkConsistencyLight() const { checkSpaceDimension(); for(int i=0;i<_space_dim;i++) if(_structure[i]<1) { - std::ostringstream oss; oss << "MEDCouplingIMesh::checkCoherency : On axis " << i << "/" << _space_dim << ", number of nodes is equal to " << _structure[i] << " ! must be >=1 !"; + std::ostringstream oss; oss << "MEDCouplingIMesh::checkConsistencyLight : On axis " << i << "/" << _space_dim << ", number of nodes is equal to " << _structure[i] << " ! must be >=1 !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } } -void MEDCouplingIMesh::checkCoherency1(double eps) const +void MEDCouplingIMesh::checkConsistency(double eps) const { - checkCoherency(); -} - -void MEDCouplingIMesh::checkCoherency2(double eps) const -{ - checkCoherency1(eps); + checkConsistencyLight(); } void MEDCouplingIMesh::getNodeGridStructure(int *res) const @@ -856,7 +969,7 @@ std::vector MEDCouplingIMesh::getNodeGridStructure() const MEDCouplingStructuredMesh *MEDCouplingIMesh::buildStructuredSubPart(const std::vector< std::pair >& cellPart) const { - checkCoherency(); + checkConsistencyLight(); int dim(getSpaceDimension()); if(dim!=(int)cellPart.size()) { @@ -865,7 +978,7 @@ MEDCouplingStructuredMesh *MEDCouplingIMesh::buildStructuredSubPart(const std::v } double retOrigin[3]={0.,0.,0.}; int retStruct[3]={0,0,0}; - MEDCouplingAutoRefCountObjectPtr ret(dynamic_cast(deepCpy())); + MCAuto ret(dynamic_cast(deepCopy())); for(int i=0;isetNodeStruct(retStruct,retStruct+dim); ret->setOrigin(retOrigin,retOrigin+dim); - ret->checkCoherency(); + ret->checkConsistencyLight(); return ret.retn(); } @@ -936,12 +1049,20 @@ std::string MEDCouplingIMesh::advancedRepr() const void MEDCouplingIMesh::getBoundingBox(double *bbox) const { - checkCoherency(); + checkConsistencyLight(); int dim(getSpaceDimension()); for(int idim=0; idim1) + coeff=_structure[idim]-1; + bbox[2*idim+1]=_origin[idim]+_dxyz[idim]*coeff; } } @@ -958,7 +1079,7 @@ void MEDCouplingIMesh::getBoundingBox(double *bbox) const */ MEDCouplingFieldDouble *MEDCouplingIMesh::getMeasureField(bool isAbs) const { - checkCoherency(); + checkConsistencyLight(); std::string name="MeasureOfMesh_"; name+=getName(); int nbelem(getNumberOfCells()); @@ -1002,6 +1123,12 @@ int MEDCouplingIMesh::getCellContainingPoint(const double *pos, double eps) cons return ret; } +void MEDCouplingIMesh::getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const +{ + int ret(getCellContainingPoint(pos,eps)); + elts.push_back(ret); +} + void MEDCouplingIMesh::rotate(const double *center, const double *vector, double angle) { throw INTERP_KERNEL::Exception("No rotation available on IMesh : Traduce it to unstructured mesh to apply it !"); @@ -1053,8 +1180,8 @@ MEDCouplingMesh *MEDCouplingIMesh::mergeMyselfWith(const MEDCouplingMesh *other) */ DataArrayDouble *MEDCouplingIMesh::getCoordinatesAndOwner() const { - checkCoherency(); - MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); + checkConsistencyLight(); + MCAuto ret(DataArrayDouble::New()); int spaceDim(getSpaceDimension()),nbNodes(getNumberOfNodes()); ret->alloc(nbNodes,spaceDim); double *pt(ret->getPointer()); @@ -1078,10 +1205,10 @@ DataArrayDouble *MEDCouplingIMesh::getCoordinatesAndOwner() const * components. The caller is to delete this array using decrRef() as it is * no more needed. */ -DataArrayDouble *MEDCouplingIMesh::getBarycenterAndOwner() const +DataArrayDouble *MEDCouplingIMesh::computeCellCenterOfMass() const { - checkCoherency(); - MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); + checkConsistencyLight(); + MCAuto ret(DataArrayDouble::New()); int spaceDim(getSpaceDimension()),nbCells(getNumberOfCells()),tmp[3],tmp2[3]; ret->alloc(nbCells,spaceDim); double *pt(ret->getPointer()),shiftOrigin[3]; @@ -1100,12 +1227,12 @@ DataArrayDouble *MEDCouplingIMesh::getBarycenterAndOwner() const DataArrayDouble *MEDCouplingIMesh::computeIsoBarycenterOfNodesPerCell() const { - return MEDCouplingIMesh::getBarycenterAndOwner(); + return MEDCouplingIMesh::computeCellCenterOfMass(); } void MEDCouplingIMesh::renumberCells(const int *old2NewBg, bool check) { - throw INTERP_KERNEL::Exception("Functionnality of renumbering cell not available for IMesh !"); + throw INTERP_KERNEL::Exception("Functionality of renumbering cell not available for IMesh !"); } void MEDCouplingIMesh::getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const @@ -1159,7 +1286,7 @@ void MEDCouplingIMesh::unserialization(const std::vector& tinyInfoD, con void MEDCouplingIMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData, DataArrayByte *byteData) const { - checkCoherency(); + checkConsistencyLight(); std::ostringstream extent,origin,spacing; for(int i=0;i<3;i++) { @@ -1213,6 +1340,11 @@ void MEDCouplingIMesh::reprQuickOverview(std::ostream& stream) const stream << stream1.str(); } +std::string MEDCouplingIMesh::getVTKFileExtension() const +{ + return std::string("vti"); +} + std::string MEDCouplingIMesh::getVTKDataSetType() const { return std::string("ImageData"); @@ -1274,3 +1406,96 @@ int MEDCouplingIMesh::FindIntRoot(int val, int order) return ret2; } } + +void MEDCouplingIMesh::SpreadCoarseToFineGhost2D(const double *inPtr, double *outPtr, int nbCompo, const std::vector& coarseSt, const std::vector< std::pair >& fineLocInCoarse, const std::vector& facts, int ghostSize) +{ + double *outPtrWork(outPtr); + std::vector dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); + int nxwg(coarseSt[0]+2*ghostSize),fact0(facts[0]),fact1(facts[1]); + int kk(fineLocInCoarse[0].first+ghostSize-1+nxwg*(fineLocInCoarse[1].first+ghostSize-1));//kk is always >=0 thanks to the fact that ghostSize>=1 ! + for(int jg=0;jg= ghostlev + for(int i=0;i& coarseSt, const std::vector< std::pair >& fineLocInCoarse, const std::vector& facts, int ghostSize) +{ + double *outPtr2(outPtr); + std::vector dims(MEDCouplingStructuredMesh::GetDimensionsFromCompactFrmt(fineLocInCoarse)); + int nxwg(coarseSt[0]+2*ghostSize),fact0(facts[0]),fact1(facts[1]); + int kk(fineLocInCoarse[0].first+ghostSize-1+nxwg*(fineLocInCoarse[1].first+ghostSize-1));//kk is always >=0 thanks to the fact that ghostSize>=1 ! + for(int jg=0;jg= ghostlev + outPtr2+=fact0*nbCompo*dims[0]; + for(int ig=0;ig