From: geay Date: Wed, 28 May 2014 15:44:23 +0000 (+0200) Subject: stash X-Git-Tag: V7_5_0a1~2^2~32^2~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e92e242ba1cb78f30c63f208b6bc049869a7d43f;p=tools%2Fmedcoupling.git stash --- diff --git a/src/MEDCoupling/MEDCouplingAMRAttribute.cxx b/src/MEDCoupling/MEDCouplingAMRAttribute.cxx index 875281b0c..ca83e5be3 100644 --- a/src/MEDCoupling/MEDCouplingAMRAttribute.cxx +++ b/src/MEDCoupling/MEDCouplingAMRAttribute.cxx @@ -42,6 +42,18 @@ void DataArrayDoubleCollection::dellocTuples() _arrs[i]->reAlloc(0); } +void DataArrayDoubleCollection::spillInfoOnComponents(const std::vector< std::vector >& compNames) +{ + std::size_t sz(_arrs.size()); + if(sz!=compNames.size()) + throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::spillInfoOnComponents : first size of compNames has to be equal to the number of fields defined !"); + for(std::size_t i=0;i& names(compNames[i]); + _arrs[i]->setInfoOnComponents(names); + } +} + DataArrayDoubleCollection::DataArrayDoubleCollection(const std::vector< std::pair >& fieldNames):_arrs(fieldNames.size()) { std::size_t sz(fieldNames.size()); @@ -76,6 +88,16 @@ std::vector DataArrayDoubleCollection::getDirectChildre return ret; } +void DataArrayDoubleCollection::updateTime() const +{ + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_arrs.begin();it!=_arrs.end();it++) + { + const DataArrayDouble *pt(*it); + if(pt) + updateTimeWith(*pt); + } +} + void DataArrayDoubleCollection::CheckDiscriminantNames(const std::vector& names) { std::set s(names.begin(),names.end()); @@ -83,17 +105,65 @@ void DataArrayDoubleCollection::CheckDiscriminantNames(const std::vector& ms, const std::vector< std::pair >& fieldNames) +{ + return new MEDCouplingGridCollection(ms,fieldNames); +} + +void MEDCouplingGridCollection::alloc(int ghostLev) +{ + for(std::vector< std::pair > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++) + { + int nbTuples((*it).first->getNumberOfCellsAtCurrentLevelGhost(ghostLev)); + DataArrayDoubleCollection *dadc((*it).second); + if(dadc) + dadc->allocTuples(nbTuples); + else + throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::alloc : internal error !"); + } +} + +void MEDCouplingGridCollection::dealloc() +{ + for(std::vector< std::pair > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++) + { + DataArrayDoubleCollection *dadc((*it).second); + if(dadc) + dadc->dellocTuples(); + else + throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::dealloc : internal error !"); + } +} + +void MEDCouplingGridCollection::spillInfoOnComponents(const std::vector< std::vector >& compNames) +{ + for(std::vector< std::pair > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++) + (*it).second->spillInfoOnComponents(compNames); +} + +MEDCouplingGridCollection::MEDCouplingGridCollection(const std::vector& ms, const std::vector< std::pair >& fieldNames):_map_of_dadc(ms.size()) +{ + std::size_t sz(ms.size()); + for(std::size_t i=0;i >); + ret+=_map_of_dadc.capacity()*sizeof(std::pair >); return ret; } std::vector MEDCouplingGridCollection::getDirectChildren() const { std::vector ret; - for(std::vector< std::pair > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++) + for(std::vector< std::pair > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++) { const DataArrayDoubleCollection *col((*it).second); if(col) @@ -102,18 +172,75 @@ std::vector MEDCouplingGridCollection::getDirectChildre return ret; } +void MEDCouplingGridCollection::updateTime() const +{ + for(std::vector< std::pair > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++) + { + const MEDCouplingCartesianAMRMeshGen *a((*it).first); + if(a) + updateTimeWith(*a); + const DataArrayDoubleCollection *b((*it).second); + if(b) + updateTimeWith(*b); + } +} + +/*! + * This method creates, attach to a main AMR mesh \a gf ( called god father :-) ) and returns a data linked to \a gf ready for the computation. + */ MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair >& fieldNames) { return new MEDCouplingAMRAttribute(gf,fieldNames); } -void MEDCouplingAMRAttribute::alloc() +/*! + * Assign the info on components for all DataArrayDouble instance recursively stored in \a this. + * The first dim of input \a compNames is the field id in the same order than those implicitely specified in \a fieldNames parameter of MEDCouplingAMRAttribute::New. + * The second dim of \a compNames represent the component names component per component corresponding to the field. The size of this 2nd dimension has + * to perfectly fit with those specified in MEDCouplingAMRAttribute::New. + */ +void MEDCouplingAMRAttribute::spillInfoOnComponents(const std::vector< std::vector >& compNames) +{ + _tlc.checkConst(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_levs.begin();it!=_levs.end();it++) + (*it)->spillInfoOnComponents(compNames); +} + +/*! + * This method allocates all DataArrayDouble instances stored recursively in \a this. + * + * \param [in] ghostLev - The size of ghost zone. + * + * \sa dealloc + */ +void MEDCouplingAMRAttribute::alloc(int ghostLev) { _tlc.resetState(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_levs.begin();it!=_levs.end();it++) + { + MEDCouplingGridCollection *elt(*it); + if(elt) + elt->alloc(ghostLev); + else + throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::alloc : internal error !"); + } } +/*! + * This method deallocates all DataArrayDouble instances stored recursively in \a this. + * \sa alloc + */ void MEDCouplingAMRAttribute::dealloc() -{//tony +{ + _tlc.checkConst(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_levs.begin();it!=_levs.end();it++) + { + MEDCouplingGridCollection *elt(*it); + if(elt) + elt->dealloc(); + else + throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::dealloc : internal error !"); + } } bool MEDCouplingAMRAttribute::changeGodFather(MEDCouplingCartesianAMRMesh *gf) @@ -125,12 +252,20 @@ bool MEDCouplingAMRAttribute::changeGodFather(MEDCouplingCartesianAMRMesh *gf) std::size_t MEDCouplingAMRAttribute::getHeapMemorySizeWithoutChildren() const { std::size_t ret(sizeof(MEDCouplingAMRAttribute)); + ret+=_levs.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr); return ret; } std::vector MEDCouplingAMRAttribute::getDirectChildren() const -{//tony - return std::vector(); +{ + std::vector ret; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_levs.begin();it!=_levs.end();it++) + { + const MEDCouplingGridCollection *elt(*it); + if(elt) + ret.push_back(elt); + } + return ret; } void MEDCouplingAMRAttribute::updateTime() const @@ -139,4 +274,21 @@ void MEDCouplingAMRAttribute::updateTime() const MEDCouplingAMRAttribute::MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair >& fieldNames):MEDCouplingDataForGodFather(gf) { + //gf non empty, checked by constructor + int maxLev(gf->getMaxNumberOfLevelsRelativeToThis()+1); + _levs.resize(maxLev+1); + for(int i=0;i patches(gf->retrieveGridsAt(i)); + std::size_t sz(patches.size()); + std::vector< MEDCouplingAutoRefCountObjectPtr > patchesSafe(patches.size()); + for(std::size_t j=0;j ms(sz); + for(std::size_t j=0;jgetMesh(); + } + _levs[i]=MEDCouplingGridCollection::New(ms,fieldNames); + } } diff --git a/src/MEDCoupling/MEDCouplingAMRAttribute.hxx b/src/MEDCoupling/MEDCouplingAMRAttribute.hxx index 2120a5bac..6651aa416 100644 --- a/src/MEDCoupling/MEDCouplingAMRAttribute.hxx +++ b/src/MEDCoupling/MEDCouplingAMRAttribute.hxx @@ -27,28 +27,37 @@ namespace ParaMEDMEM { /// @cond INTERNAL - class DataArrayDoubleCollection : public RefCountObject + class DataArrayDoubleCollection : public RefCountObject, public TimeLabel { public: static DataArrayDoubleCollection *New(const std::vector< std::pair >& fieldNames); void allocTuples(int nbOfTuples); void dellocTuples(); + void spillInfoOnComponents(const std::vector< std::vector >& compNames); private: DataArrayDoubleCollection(const std::vector< std::pair >& fieldNames); std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildren() const; + void updateTime() const; static void CheckDiscriminantNames(const std::vector& names); private: std::vector< MEDCouplingAutoRefCountObjectPtr > _arrs; }; - class MEDCouplingGridCollection : public RefCountObject + class MEDCouplingGridCollection : public RefCountObject, public TimeLabel { + public: + static MEDCouplingGridCollection *New(const std::vector& ms, const std::vector< std::pair >& fieldNames); + void alloc(int ghostLev); + void dealloc(); + void spillInfoOnComponents(const std::vector< std::vector >& compNames); private: + MEDCouplingGridCollection(const std::vector& ms, const std::vector< std::pair >& fieldNames); std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildren() const; + void updateTime() const; private: - std::vector< std::pair > > _map_of_dadc; + std::vector< std::pair > > _map_of_dadc; }; /// @endcond @@ -56,8 +65,9 @@ namespace ParaMEDMEM { public: MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair >& fieldNames); + MEDCOUPLING_EXPORT void spillInfoOnComponents(const std::vector< std::vector >& compNames); // - MEDCOUPLING_EXPORT void alloc(); + MEDCOUPLING_EXPORT void alloc(int ghostLev); MEDCOUPLING_EXPORT void dealloc(); MEDCOUPLING_EXPORT bool changeGodFather(MEDCouplingCartesianAMRMesh *gf); // diff --git a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx index c4d9a38af..0208d7425 100644 --- a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx @@ -210,11 +210,33 @@ int MEDCouplingCartesianAMRMeshGen::getMaxNumberOfLevelsRelativeToThis() const return ret; } +/*! + * This method returns the number of cells of \a this with the help of the MEDCouplingIMesh instance representing \a this. + * The patches in \a this are ignored here. + * \sa getNumberOfCellsAtCurrentLevelGhost, getNumberOfCellsRecursiveWithOverlap + */ int MEDCouplingCartesianAMRMeshGen::getNumberOfCellsAtCurrentLevel() const { return _mesh->getNumberOfCells(); } +/*! + * This method returns the number of cells of \a this with the help of the MEDCouplingIMesh instance representing \a this enlarged by \a ghostLev size + * to take into account of the ghost cells for future computation. + * The patches in \a this are ignored here. + * + * \sa getNumberOfCellsAtCurrentLevel + */ +int MEDCouplingCartesianAMRMeshGen::getNumberOfCellsAtCurrentLevelGhost(int ghostLev) const +{ + MEDCouplingAutoRefCountObjectPtr tmp(_mesh->buildWithGhost(ghostLev)); + return tmp->getNumberOfCells(); +} + +/*! + * This method returns the number of cells including the current level but \b also \b including recursively all cells of other levels + * starting from this. The set of cells which size is returned here are generally overlapping each other. + */ int MEDCouplingCartesianAMRMeshGen::getNumberOfCellsRecursiveWithOverlap() const { int ret(_mesh->getNumberOfCells()); @@ -225,6 +247,9 @@ int MEDCouplingCartesianAMRMeshGen::getNumberOfCellsRecursiveWithOverlap() const return ret; } +/*! + * This method returns the max number of cells covering all the space without overlapping. + */ int MEDCouplingCartesianAMRMeshGen::getNumberOfCellsRecursiveWithoutOverlap() const { int ret(_mesh->getNumberOfCells()); @@ -1112,10 +1137,10 @@ void MEDCouplingCartesianAMRMesh::setData(MEDCouplingDataForGodFather *data) data->incrRef(); } -void MEDCouplingCartesianAMRMesh::allocData() const +void MEDCouplingCartesianAMRMesh::allocData(int ghostLev) const { checkData(); - _data->alloc(); + _data->alloc(ghostLev); } void MEDCouplingCartesianAMRMesh::deallocData() const diff --git a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.hxx b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.hxx index 6d6191c30..272b81028 100644 --- a/src/MEDCoupling/MEDCouplingCartesianAMRMesh.hxx +++ b/src/MEDCoupling/MEDCouplingCartesianAMRMesh.hxx @@ -98,7 +98,7 @@ namespace ParaMEDMEM { friend class MEDCouplingCartesianAMRMesh; public: - MEDCOUPLING_EXPORT virtual void alloc() = 0; + MEDCOUPLING_EXPORT virtual void alloc(int ghostLev) = 0; MEDCOUPLING_EXPORT virtual void dealloc() = 0; protected: MEDCouplingDataForGodFather(MEDCouplingCartesianAMRMesh *gf); @@ -124,6 +124,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setFactors(const std::vector& newFactors); MEDCOUPLING_EXPORT int getMaxNumberOfLevelsRelativeToThis() const; MEDCOUPLING_EXPORT int getNumberOfCellsAtCurrentLevel() const; + MEDCOUPLING_EXPORT int getNumberOfCellsAtCurrentLevelGhost(int ghostLev) const; MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithOverlap() const; MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithoutOverlap() const; MEDCOUPLING_EXPORT const MEDCouplingIMesh *getImageMesh() const { return _mesh; } @@ -188,7 +189,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT const MEDCouplingDataForGodFather *getDataConst() const { return _data; } MEDCOUPLING_EXPORT MEDCouplingDataForGodFather *getData() { return _data; } MEDCOUPLING_EXPORT void setData(MEDCouplingDataForGodFather *data); - MEDCOUPLING_EXPORT void allocData() const; + MEDCOUPLING_EXPORT void allocData(int ghostLev) const; MEDCOUPLING_EXPORT void deallocData() const; private: MEDCouplingCartesianAMRMesh(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop, diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index ff8136716..b72ee4c40 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -4851,6 +4851,7 @@ namespace ParaMEDMEM void setFactors(const std::vector& newFactors) throw(INTERP_KERNEL::Exception); int getMaxNumberOfLevelsRelativeToThis() const throw(INTERP_KERNEL::Exception); int getNumberOfCellsAtCurrentLevel() const throw(INTERP_KERNEL::Exception); + int getNumberOfCellsAtCurrentLevelGhost(int ghostLev) const throw(INTERP_KERNEL::Exception); int getNumberOfCellsRecursiveWithOverlap() const throw(INTERP_KERNEL::Exception); int getNumberOfCellsRecursiveWithoutOverlap() const throw(INTERP_KERNEL::Exception); bool isPatchInNeighborhoodOf(int patchId1, int patchId2, int ghostLev) const throw(INTERP_KERNEL::Exception);