Salome HOME
stash
authorgeay <anthony.geay@cea.fr>
Wed, 28 May 2014 15:44:23 +0000 (17:44 +0200)
committergeay <anthony.geay@cea.fr>
Wed, 28 May 2014 15:44:23 +0000 (17:44 +0200)
src/MEDCoupling/MEDCouplingAMRAttribute.cxx
src/MEDCoupling/MEDCouplingAMRAttribute.hxx
src/MEDCoupling/MEDCouplingCartesianAMRMesh.cxx
src/MEDCoupling/MEDCouplingCartesianAMRMesh.hxx
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 875281b0c11578480c98cd28025b518e827bb64c..ca83e5be347a6a228c8e15306a0e78b0832ffabd 100644 (file)
@@ -42,6 +42,18 @@ void DataArrayDoubleCollection::dellocTuples()
     _arrs[i]->reAlloc(0);
 }
 
+void DataArrayDoubleCollection::spillInfoOnComponents(const std::vector< std::vector<std::string> >& 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<sz;i++)
+    {
+      const std::vector<std::string>& names(compNames[i]);
+      _arrs[i]->setInfoOnComponents(names);
+    }
+}
+
 DataArrayDoubleCollection::DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames):_arrs(fieldNames.size())
 {
   std::size_t sz(fieldNames.size());
@@ -76,6 +88,16 @@ std::vector<const BigMemoryObject *> DataArrayDoubleCollection::getDirectChildre
   return ret;
 }
 
+void DataArrayDoubleCollection::updateTime() const
+{
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
+    {
+      const DataArrayDouble *pt(*it);
+      if(pt)
+        updateTimeWith(*pt);
+    }
+}
+
 void DataArrayDoubleCollection::CheckDiscriminantNames(const std::vector<std::string>& names)
 {
   std::set<std::string> s(names.begin(),names.end());
@@ -83,17 +105,65 @@ void DataArrayDoubleCollection::CheckDiscriminantNames(const std::vector<std::st
     throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::CheckDiscriminantNames : The names of fields must be different each other ! It is not the case !");
 }
 
+MEDCouplingGridCollection *MEDCouplingGridCollection::New(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames)
+{
+  return new MEDCouplingGridCollection(ms,fieldNames);
+}
+
+void MEDCouplingGridCollection::alloc(int ghostLev)
+{
+  for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::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<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::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<std::string> >& compNames)
+{
+  for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
+    (*it).second->spillInfoOnComponents(compNames);
+}
+
+MEDCouplingGridCollection::MEDCouplingGridCollection(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames):_map_of_dadc(ms.size())
+{
+  std::size_t sz(ms.size());
+  for(std::size_t i=0;i<sz;i++)
+    {
+      if(!ms[i])
+        throw INTERP_KERNEL::Exception("MEDCouplingGridCollection constructor : presence of NULL MEDCouplingCartesianAMRMeshGen instance !");
+      _map_of_dadc[i].first=ms[i];
+      _map_of_dadc[i].second=DataArrayDoubleCollection::New(fieldNames);
+    }
+}
+
 std::size_t MEDCouplingGridCollection::getHeapMemorySizeWithoutChildren() const
 {
   std::size_t ret(sizeof(MEDCouplingGridCollection));
-  ret+=_map_of_dadc.capacity()*sizeof(std::pair<MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> >);
+  ret+=_map_of_dadc.capacity()*sizeof(std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> >);
   return ret;
 }
 
 std::vector<const BigMemoryObject *> MEDCouplingGridCollection::getDirectChildren() const
 {
   std::vector<const BigMemoryObject *> ret;
-  for(std::vector< std::pair<MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
+  for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::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<const BigMemoryObject *> MEDCouplingGridCollection::getDirectChildre
   return ret;
 }
 
+void MEDCouplingGridCollection::updateTime() const
+{
+  for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::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<std::string,int> >& 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<std::string> >& compNames)
+{
+  _tlc.checkConst();
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::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<MEDCouplingGridCollection> >::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<MEDCouplingGridCollection> >::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<MEDCouplingGridCollection>);
   return ret;
 }
 
 std::vector<const BigMemoryObject *> MEDCouplingAMRAttribute::getDirectChildren() const
-{//tony
-  return std::vector<const BigMemoryObject *>();
+{
+  std::vector<const BigMemoryObject *> ret;
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::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<std::string,int> >& fieldNames):MEDCouplingDataForGodFather(gf)
 {
+  //gf non empty, checked by constructor
+  int maxLev(gf->getMaxNumberOfLevelsRelativeToThis()+1);
+  _levs.resize(maxLev+1);
+  for(int i=0;i<maxLev;i++)
+    {
+      std::vector<MEDCouplingCartesianAMRPatchGen *> patches(gf->retrieveGridsAt(i));
+      std::size_t sz(patches.size());
+      std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRPatchGen> > patchesSafe(patches.size());
+      for(std::size_t j=0;j<sz;j++)
+        patchesSafe[j]=patches[j];
+      std::vector<const MEDCouplingCartesianAMRMeshGen *> ms(sz);
+      for(std::size_t j=0;j<sz;j++)
+        {
+          ms[j]=patches[j]->getMesh();
+        }
+      _levs[i]=MEDCouplingGridCollection::New(ms,fieldNames);
+    }
 }
index 2120a5bac7ff88280d51655b127f6654957ce461..6651aa416a099d7e89a0034eaec6dabb747ec455 100644 (file)
 namespace ParaMEDMEM
 {
   /// @cond INTERNAL
-  class DataArrayDoubleCollection : public RefCountObject
+  class DataArrayDoubleCollection : public RefCountObject, public TimeLabel
   {
   public:
     static DataArrayDoubleCollection *New(const std::vector< std::pair<std::string,int> >& fieldNames);
     void allocTuples(int nbOfTuples);
     void dellocTuples();
+    void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
   private:
     DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames);
     std::size_t getHeapMemorySizeWithoutChildren() const;
     std::vector<const BigMemoryObject *> getDirectChildren() const;
+    void updateTime() const;
     static void CheckDiscriminantNames(const std::vector<std::string>& names);
   private:
     std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > _arrs;
   };
 
-  class MEDCouplingGridCollection : public RefCountObject
+  class MEDCouplingGridCollection : public RefCountObject, public TimeLabel
   {
+  public:
+    static MEDCouplingGridCollection *New(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
+    void alloc(int ghostLev);
+    void dealloc();
+    void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
   private:
+    MEDCouplingGridCollection(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
     std::size_t getHeapMemorySizeWithoutChildren() const;
     std::vector<const BigMemoryObject *> getDirectChildren() const;
+    void updateTime() const;
   private:
-    std::vector< std::pair<MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > > _map_of_dadc;
+    std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > > _map_of_dadc;
   };
   /// @endcond
 
@@ -56,8 +65,9 @@ namespace ParaMEDMEM
   {
   public:
     MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames);
+    MEDCOUPLING_EXPORT void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
     //
-    MEDCOUPLING_EXPORT void alloc();
+    MEDCOUPLING_EXPORT void alloc(int ghostLev);
     MEDCOUPLING_EXPORT void dealloc();
     MEDCOUPLING_EXPORT bool changeGodFather(MEDCouplingCartesianAMRMesh *gf);
     //
index c4d9a38af1527e150a86f4f445b02f943ddc6229..0208d74252444c61d10a36697299ab530b01b0d0 100644 (file)
@@ -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<MEDCouplingIMesh> 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
index 6d6191c30171616089d96b3bbb9150d4463fdc88..272b81028a035e6b79020b8eb03c1f63c1e518e5 100644 (file)
@@ -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<int>& 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,
index ff8136716e5b133353e558840f7be0c064ce7263..b72ee4c40d71cc796bd48c6e1c0af10cf99547ce 100644 (file)
@@ -4851,6 +4851,7 @@ namespace ParaMEDMEM
     void setFactors(const std::vector<int>& 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);