From d573e29a9cf7dc5344b501e607d0a149e72ed8fa Mon Sep 17 00:00:00 2001 From: geay Date: Thu, 12 Jun 2014 18:33:35 +0200 Subject: [PATCH] interlevels methods. --- src/MEDCoupling/MEDCouplingAMRAttribute.cxx | 145 ++++++++++++++++++-- src/MEDCoupling/MEDCouplingAMRAttribute.hxx | 14 ++ src/MEDCoupling_Swig/MEDCouplingCommon.i | 7 +- 3 files changed, 157 insertions(+), 9 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingAMRAttribute.cxx b/src/MEDCoupling/MEDCouplingAMRAttribute.cxx index 9ab932819..f27671edd 100644 --- a/src/MEDCoupling/MEDCouplingAMRAttribute.cxx +++ b/src/MEDCoupling/MEDCouplingAMRAttribute.cxx @@ -32,6 +32,11 @@ DataArrayDoubleCollection *DataArrayDoubleCollection::New(const std::vector< std return new DataArrayDoubleCollection(fieldNames); } +DataArrayDoubleCollection *DataArrayDoubleCollection::deepCpy() const +{ + return new DataArrayDoubleCollection(*this); +} + void DataArrayDoubleCollection::allocTuples(int nbOfTuples) { std::size_t sz(_arrs.size()); @@ -64,7 +69,10 @@ void DataArrayDoubleCollection::spillNatures(const std::vector& n if(sz!=nfs.size()) throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::spillNatures : first size of vector of NatureOfField has to be equal to the number of fields defined !"); for(std::size_t i=0;i DataArrayDoubleCollection::retrieveFields() const @@ -217,6 +225,18 @@ DataArrayDoubleCollection::DataArrayDoubleCollection(const std::vector< std::pai CheckDiscriminantNames(names); } +DataArrayDoubleCollection::DataArrayDoubleCollection(const DataArrayDoubleCollection& other):RefCountObject(other),_arrs(other._arrs.size()) +{ + std::size_t sz(other._arrs.size()); + for(std::size_t i=0;ideepCpy(); + } +} + std::size_t DataArrayDoubleCollection::getHeapMemorySizeWithoutChildren() const { std::size_t ret(sizeof(DataArrayDoubleCollection)); @@ -278,6 +298,11 @@ MEDCouplingGridCollection *MEDCouplingGridCollection::New(const std::vector > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++) @@ -514,6 +539,18 @@ MEDCouplingGridCollection::MEDCouplingGridCollection(const std::vectordeepCpy(); + } +} + std::size_t MEDCouplingGridCollection::getHeapMemorySizeWithoutChildren() const { std::size_t ret(sizeof(MEDCouplingGridCollection)); @@ -579,6 +616,11 @@ bool MEDCouplingDataForGodFather::changeGodFather(MEDCouplingCartesianAMRMeshGen return ret; } +MEDCouplingDataForGodFather::MEDCouplingDataForGodFather(const MEDCouplingDataForGodFather& other):RefCountObject(other),_gf(other._gf),_tlc(other._gf) +{ + other._tlc.checkConst(); +} + /*! * 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. */ @@ -627,6 +669,21 @@ void MEDCouplingAMRAttribute::spillNatures(const std::vector& nfs (*it)->spillNatures(nfs); } +MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::deepCpy() const +{ + return new MEDCouplingAMRAttribute(*this); +} + +/*! + * Returns the number of levels by \b only \b considering \a this (god father instance is considered only to see if it has not changed still last update of \a this). + * + */ +int MEDCouplingAMRAttribute::getNumberOfLevels() const +{ + checkGodFatherFrozen(); + return (int)_levs.size(); +} + /*! * This method returns all DataArrayDouble instances lying on the specified mesh \a mesh. * If \a mesh is not part of the progeny of god father object given at construction of \a this an exception will be thrown. @@ -768,6 +825,8 @@ MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnWithoutGhost(ME /*! * This method synchronizes from fine to coarse direction arrays. This method makes the hypothesis that \a this has been allocated before using * MEDCouplingAMRAttribute::alloc method. + * + * \sa synchronizeFineToCoarseBetween */ void MEDCouplingAMRAttribute::synchronizeFineToCoarse() { @@ -778,11 +837,32 @@ void MEDCouplingAMRAttribute::synchronizeFineToCoarse() while(sz>1) { sz--; - const MEDCouplingGridCollection *fine(_levs[sz]),*coarse(_levs[sz-1]); - MEDCouplingGridCollection::SynchronizeFineToCoarse(_ghost_lev,fine,coarse); + synchronizeFineToCoarseByOneLevel((int)sz); } } +/*! + * This method allows to synchronizes fields on fine patches on level \a fromLev to coarser patches at \a toLev level. + * This method operates step by step performing the synchronization the \a fromLev to \a fromLev - 1, then \a fromLev -1 to \a fromLev - 2 ... + * until reaching \a toLev level. + * + * \param [in] fromLev - an existing level considered as fine so bigger than \a toLev + * \param [in] toLev - an existing level considered as the target level to reach. + * + */ +void MEDCouplingAMRAttribute::synchronizeFineToCoarseBetween(int fromLev, int toLev) +{ + int nbl(getNumberOfLevels()); + if(fromLev<0 || toLev<0 || fromLev>=nbl || toLev>=nbl) + throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineToCoarseBetween : fromLev and toLev must be >= 0 and lower than number of levels in this !"); + if(fromLev==toLev) + return ;//nothing to do + if(fromLevtoLev;i--) + synchronizeFineToCoarseByOneLevel(i); +} + /*! * This method synchronizes from coarse to fine arrays and fine to fine each other (if _ghost_lev is >0). This method makes the hypothesis that \a this has been allocated before using * MEDCouplingAMRAttribute::alloc method. @@ -793,11 +873,29 @@ void MEDCouplingAMRAttribute::synchronizeCoarseToFine() throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeCoarseToFine : not any levels in this !"); std::size_t sz(_levs.size()); // - for(std::size_t i=1;i=nbl || toLev>=nbl) + throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeCoarseToFineBetween : fromLev and toLev must be >= 0 and lower than number of levels in this !"); + if(fromLev==toLev) + return ;//nothing to do + if(fromLev>toLev) + throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeCoarseToFineBetween : the fromLev level is greater than toLev level ! Call synchronizeFineToCoarseBetween instead !"); + for(int i=fromLev;ideepCpy(); + } + } +} + const DataArrayDoubleCollection& MEDCouplingAMRAttribute::findCollectionAttachedTo(const MEDCouplingCartesianAMRMeshGen *m) const { for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_levs.begin();it!=_levs.end();it++) @@ -973,3 +1084,21 @@ const DataArrayDoubleCollection& MEDCouplingAMRAttribute::findCollectionAttached } throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::findCollectionAttachedTo : unable to find such part of mesh in this !"); } + +void MEDCouplingAMRAttribute::synchronizeFineToCoarseByOneLevel(int level) +{ + int nbl(getNumberOfLevels()); + if(level<=0 || level>=nbl) + throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineToCoarseByOneLevel : the input level must be in ]0,nb_of_levels[ !"); + const MEDCouplingGridCollection *fine(_levs[level]),*coarse(_levs[level-1]); + MEDCouplingGridCollection::SynchronizeFineToCoarse(_ghost_lev,fine,coarse); +} + +void MEDCouplingAMRAttribute::synchronizeCoarseToFineByOneLevel(int level) +{ + int nbl(getNumberOfLevels()); + if(level<0 || level>=nbl-1) + throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineToCoarseByOneLevel : the input level must be in [0,nb_of_levels[ !"); + const MEDCouplingGridCollection *fine(_levs[level+1]),*coarse(_levs[level]); + MEDCouplingGridCollection::SynchronizeCoarseToFine(_ghost_lev,coarse,fine); +} diff --git a/src/MEDCoupling/MEDCouplingAMRAttribute.hxx b/src/MEDCoupling/MEDCouplingAMRAttribute.hxx index b05f704d8..2b7eb68d3 100644 --- a/src/MEDCoupling/MEDCouplingAMRAttribute.hxx +++ b/src/MEDCoupling/MEDCouplingAMRAttribute.hxx @@ -32,6 +32,7 @@ namespace ParaMEDMEM { public: static DataArrayDoubleCollection *New(const std::vector< std::pair >& fieldNames); + DataArrayDoubleCollection *deepCpy() const; void allocTuples(int nbOfTuples); void dellocTuples(); void spillInfoOnComponents(const std::vector< std::vector >& compNames); @@ -47,6 +48,7 @@ namespace ParaMEDMEM void synchronizeMyGhostZoneUsingExt(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp) const; private: DataArrayDoubleCollection(const std::vector< std::pair >& fieldNames); + DataArrayDoubleCollection(const DataArrayDoubleCollection& other); std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildren() const; void updateTime() const; @@ -62,6 +64,7 @@ namespace ParaMEDMEM { public: static MEDCouplingGridCollection *New(const std::vector& ms, const std::vector< std::pair >& fieldNames); + MEDCouplingGridCollection *deepCpy() const; void alloc(int ghostLev); void dealloc(); void spillInfoOnComponents(const std::vector< std::vector >& compNames); @@ -77,6 +80,7 @@ namespace ParaMEDMEM void fillIfInTheProgenyOf(const std::string& fieldName, const MEDCouplingCartesianAMRMeshGen *head, std::vector& recurseArrs) const; private: MEDCouplingGridCollection(const std::vector& ms, const std::vector< std::pair >& fieldNames); + MEDCouplingGridCollection(const MEDCouplingGridCollection& other); std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildren() const; void updateTime() const; @@ -91,7 +95,9 @@ namespace ParaMEDMEM friend class MEDCouplingCartesianAMRMesh; public: MEDCOUPLING_EXPORT virtual void synchronizeFineToCoarse() = 0; + MEDCOUPLING_EXPORT virtual void synchronizeFineToCoarseBetween(int fromLev, int toLev) = 0; MEDCOUPLING_EXPORT virtual void synchronizeCoarseToFine() = 0; + MEDCOUPLING_EXPORT virtual void synchronizeCoarseToFineBetween(int fromLev, int toLev) = 0; MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZones() = 0; MEDCOUPLING_EXPORT virtual void alloc() = 0; MEDCOUPLING_EXPORT virtual void dealloc() = 0; @@ -100,6 +106,7 @@ namespace ParaMEDMEM void checkGodFatherFrozen() const; protected: virtual bool changeGodFather(MEDCouplingCartesianAMRMeshGen *gf); + MEDCouplingDataForGodFather(const MEDCouplingDataForGodFather& other); protected: MEDCouplingAutoRefCountObjectPtr _gf; TimeLabelConstOverseer _tlc; @@ -112,6 +119,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMeshGen *gf, const std::vector< std::pair > >& fieldNames, int ghostLev); MEDCOUPLING_EXPORT void spillInfoOnComponents(const std::vector< std::vector >& compNames); MEDCOUPLING_EXPORT void spillNatures(const std::vector& nfs); + MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCpy() const; + MEDCOUPLING_EXPORT int getNumberOfLevels() const; MEDCOUPLING_EXPORT std::vector retrieveFieldsOn(MEDCouplingCartesianAMRMeshGen *mesh) const; MEDCOUPLING_EXPORT const DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const; MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnRecurseWithoutOverlapWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const; @@ -119,7 +128,9 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const; // MEDCOUPLING_EXPORT void synchronizeFineToCoarse(); + MEDCOUPLING_EXPORT void synchronizeFineToCoarseBetween(int fromLev, int toLev); MEDCOUPLING_EXPORT void synchronizeCoarseToFine(); + MEDCOUPLING_EXPORT void synchronizeCoarseToFineBetween(int fromLev, int toLev); MEDCOUPLING_EXPORT void synchronizeAllGhostZones(); MEDCOUPLING_EXPORT void alloc(); MEDCOUPLING_EXPORT void dealloc(); @@ -130,7 +141,10 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void updateTime() const; private: MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMeshGen *gf, const std::vector< std::pair >& fieldNames, int ghostLev); + MEDCouplingAMRAttribute(const MEDCouplingAMRAttribute& other); const DataArrayDoubleCollection& findCollectionAttachedTo(const MEDCouplingCartesianAMRMeshGen *m) const; + void synchronizeFineToCoarseByOneLevel(int level); + void synchronizeCoarseToFineByOneLevel(int level); private: int _ghost_lev; std::vector< MEDCouplingAutoRefCountObjectPtr > _levs; diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 1a4313ddf..a0c5c7994 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -353,6 +353,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingCartesianAMRMeshGen::__getitem__; %newobject ParaMEDMEM::MEDCouplingCartesianAMRMesh::New; %newobject ParaMEDMEM::MEDCouplingAMRAttribute::New; +%newobject ParaMEDMEM::MEDCouplingAMRAttribute::deepCpy; %newobject ParaMEDMEM::MEDCouplingAMRAttribute::getFieldOn; %newobject ParaMEDMEM::MEDCouplingAMRAttribute::buildCellFieldOnRecurseWithoutOverlapWithoutGhost; %newobject ParaMEDMEM::MEDCouplingAMRAttribute::buildCellFieldOnWithGhost; @@ -4913,7 +4914,9 @@ namespace ParaMEDMEM { public: virtual void synchronizeFineToCoarse() throw(INTERP_KERNEL::Exception); + virtual void synchronizeFineToCoarseBetween(int fromLev, int toLev) throw(INTERP_KERNEL::Exception); virtual void synchronizeCoarseToFine() throw(INTERP_KERNEL::Exception); + virtual void synchronizeCoarseToFineBetween(int fromLev, int toLev) throw(INTERP_KERNEL::Exception); virtual void synchronizeAllGhostZones() throw(INTERP_KERNEL::Exception); virtual void alloc() throw(INTERP_KERNEL::Exception); virtual void dealloc() throw(INTERP_KERNEL::Exception); @@ -5115,6 +5118,8 @@ namespace ParaMEDMEM class MEDCouplingAMRAttribute : public MEDCouplingDataForGodFather, public TimeLabel { public: + int getNumberOfLevels() const throw(INTERP_KERNEL::Exception); + MEDCouplingAMRAttribute *deepCpy() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildCellFieldOnRecurseWithoutOverlapWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildCellFieldOnWithGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildCellFieldOnWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const throw(INTERP_KERNEL::Exception); @@ -5143,7 +5148,7 @@ namespace ParaMEDMEM { return ParaMEDMEM_MEDCouplingAMRAttribute_New(gf,fieldNames,ghostLev); } - + DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const throw(INTERP_KERNEL::Exception) { const DataArrayDouble *ret(self->getFieldOn(mesh,fieldName)); -- 2.39.2