Salome HOME
Some debugs and improvements. Tests coming soon !
[modules/med.git] / src / MEDCoupling / MEDCouplingAMRAttribute.cxx
index a3c652165c00a298007e3237774de2b7f91cc0ec..9e601b98825c7f82d9bd5017fd52759315334cbe 100644 (file)
@@ -32,18 +32,23 @@ 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());
   for(std::size_t i=0;i<sz;i++)
-    _arrs[i]->reAlloc(nbOfTuples);
+    _arrs[i].first->reAlloc(nbOfTuples);
 }
 
 void DataArrayDoubleCollection::dellocTuples()
 {
   std::size_t sz(_arrs.size());
   for(std::size_t i=0;i<sz;i++)
-    _arrs[i]->reAlloc(0);
+    _arrs[i].first->reAlloc(0);
 }
 
 void DataArrayDoubleCollection::spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames)
@@ -54,7 +59,19 @@ void DataArrayDoubleCollection::spillInfoOnComponents(const std::vector< std::ve
   for(std::size_t i=0;i<sz;i++)
     {
       const std::vector<std::string>& names(compNames[i]);
-      _arrs[i]->setInfoOnComponents(names);
+      _arrs[i].first->setInfoOnComponents(names);
+    }
+}
+
+void DataArrayDoubleCollection::spillNatures(const std::vector<NatureOfField>& nfs)
+{
+  std::size_t sz(_arrs.size());
+  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<sz;i++)
+    {
+      CheckValidNature(nfs[i]);
+      _arrs[i].second=nfs[i];
     }
 }
 
@@ -64,7 +81,7 @@ std::vector<DataArrayDouble *> DataArrayDoubleCollection::retrieveFields() const
   std::vector<DataArrayDouble *> ret(sz);
   for(std::size_t i=0;i<sz;i++)
     {
-      const DataArrayDouble *tmp(_arrs[i]);
+      const DataArrayDouble *tmp(_arrs[i].first);
       ret[i]=const_cast<DataArrayDouble *>(tmp);
       if(ret[i])
         ret[i]->incrRef();
@@ -75,9 +92,9 @@ std::vector<DataArrayDouble *> DataArrayDoubleCollection::retrieveFields() const
 const DataArrayDouble *DataArrayDoubleCollection::getFieldWithName(const std::string& name) const
 {
   std::vector<std::string> vec;
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
+  for(std::vector< std::pair< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>, NatureOfField > >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
     {
-      const DataArrayDouble *obj(*it);
+      const DataArrayDouble *obj((*it).first);
       if(obj)
         {
           if(obj->getName()==name)
@@ -99,7 +116,10 @@ void DataArrayDoubleCollection::SynchronizeFineToCoarse(int ghostLev, const MEDC
   if(fine->_arrs.size()!=sz)
     throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeFineToCoarse : the input DataArrayDouble collection must have the same size !");
   for(std::size_t i=0;i<sz;i++)
-    fatherOfFineMesh->fillCellFieldComingFromPatchGhost(patchId,fine->_arrs[i],coarse->_arrs[i],ghostLev);
+    {
+      CheckSameNatures(fine->_arrs[i].second,coarse->_arrs[i].second);
+      fatherOfFineMesh->fillCellFieldComingFromPatchGhost(patchId,fine->_arrs[i].first,coarse->_arrs[i].first,ghostLev,IsConservativeNature(coarse->_arrs[i].second));
+    }
 }
 
 void DataArrayDoubleCollection::SynchronizeCoarseToFine(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine)
@@ -110,7 +130,10 @@ void DataArrayDoubleCollection::SynchronizeCoarseToFine(int ghostLev, const MEDC
   if(fine->_arrs.size()!=sz)
     throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeCoarseToFine : the input DataArrayDouble collection must have the same size !");
   for(std::size_t i=0;i<sz;i++)
-    fatherOfFineMesh->fillCellFieldOnPatchGhost(patchId,coarse->_arrs[i],fine->_arrs[i],ghostLev);
+    {
+      CheckSameNatures(fine->_arrs[i].second,coarse->_arrs[i].second);
+      fatherOfFineMesh->fillCellFieldOnPatchGhost(patchId,coarse->_arrs[i].first,fine->_arrs[i].first,ghostLev,IsConservativeNature(coarse->_arrs[i].second));
+    }
 }
 
 void DataArrayDoubleCollection::SynchronizeFineEachOther(int patchId, int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, const std::vector<const MEDCouplingCartesianAMRMeshGen *>& children, const std::vector<DataArrayDoubleCollection *>& fieldsOnFine)
@@ -133,11 +156,28 @@ void DataArrayDoubleCollection::SynchronizeFineEachOther(int patchId, int ghostL
     {
       std::vector<const DataArrayDouble *> arrs(sz);
       for(std::size_t j=0;j<sz;j++)
-        arrs[j]=fieldsOnFine[j]->_arrs[i];
+        arrs[j]=fieldsOnFine[j]->_arrs[i].first;
       fatherOfFineMesh->fillCellFieldOnPatchOnlyGhostAdv(patchId,ghostLev,arrs);
     }
 }
 
+/*!
+ * This method updates \a p1dac ghost zone parts using \a p2dac (which is really const). \a p2 is in the neighborhood of \a p1 (which size is defined by \a ghostLev).
+ */
+void DataArrayDoubleCollection::SynchronizeGhostZoneOfOneUsingTwo(int ghostLev, const MEDCouplingCartesianAMRPatch *p1, const DataArrayDoubleCollection *p1dac, const MEDCouplingCartesianAMRPatch *p2, const DataArrayDoubleCollection *p2dac)
+{
+  if(!p1 || !p1dac || !p2 || !p2dac)
+    throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeGhostZoneOfOneUsingTwo : input pointer must be not NULL !");
+  std::size_t sz(p1dac->_arrs.size());
+  if(p2dac->_arrs.size()!=sz)
+    throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeGhostZoneOfOneUsingTwo : size of DataArrayDouble Collection must be the same !");
+  for(std::size_t i=0;i<sz;i++)
+    {
+      const DataArrayDouble *zeArrWhichGhostsWillBeUpdated(p1dac->_arrs[i].first);
+      MEDCouplingCartesianAMRPatch::UpdateNeighborsOfOneWithTwoMixedLev(ghostLev,p1,p2,const_cast<DataArrayDouble *>(zeArrWhichGhostsWillBeUpdated),p2dac->_arrs[i].first);
+    }
+}
+
 void DataArrayDoubleCollection::SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine)
 {
   if(!fine || !coarse)
@@ -146,7 +186,27 @@ void DataArrayDoubleCollection::SynchronizeCoarseToFineOnlyInGhostZone(int ghost
   if(fine->_arrs.size()!=sz)
     throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::SynchronizeCoarseToFineOnlyInGhostZone : the input DataArrayDouble collection must have the same size !");
   for(std::size_t i=0;i<sz;i++)
-    fatherOfFineMesh->fillCellFieldOnPatchOnlyOnGhostZone(patchId,coarse->_arrs[i],fine->_arrs[i],ghostLev);
+    fatherOfFineMesh->fillCellFieldOnPatchOnlyOnGhostZone(patchId,coarse->_arrs[i].first,fine->_arrs[i].first,ghostLev);
+}
+
+void DataArrayDoubleCollection::synchronizeMyGhostZoneUsing(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp, const MEDCouplingCartesianAMRMeshGen *father) const
+{
+  DataArrayDoubleCollection *thisNC(const_cast<DataArrayDoubleCollection *>(this));
+  std::size_t sz(_arrs.size());
+  if(other._arrs.size()!=sz)
+    throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::synchronizeMyGhostZoneUsing : sizes of collections must match !");
+  for(std::size_t i=0;i<sz;i++)
+    father->fillCellFieldOnPatchOnlyOnGhostZoneWith(ghostLev,thisp,otherp,thisNC->_arrs[i].first,other._arrs[i].first);
+}
+
+void DataArrayDoubleCollection::synchronizeMyGhostZoneUsingExt(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp) const
+{
+  DataArrayDoubleCollection *thisNC(const_cast<DataArrayDoubleCollection *>(this));
+  std::size_t sz(_arrs.size());
+  if(other._arrs.size()!=sz)
+    throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::synchronizeMyGhostZoneUsingExt : sizes of collections must match !");
+  for(std::size_t i=0;i<sz;i++)
+    MEDCouplingCartesianAMRPatch::UpdateNeighborsOfOneWithTwoExt(ghostLev,thisp,otherp,thisNC->_arrs[i].first,other._arrs[i].first);
 }
 
 DataArrayDoubleCollection::DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames):_arrs(fieldNames.size())
@@ -156,14 +216,27 @@ DataArrayDoubleCollection::DataArrayDoubleCollection(const std::vector< std::pai
   for(std::size_t i=0;i<sz;i++)
     {
       const std::pair<std::string,int>& info(fieldNames[i]);
-      _arrs[i]=DataArrayDouble::New();
-      _arrs[i]->alloc(0,info.second);
-      _arrs[i]->setName(info.first);
+      _arrs[i].first=DataArrayDouble::New();
+      _arrs[i].first->alloc(0,info.second);
+      _arrs[i].first->setName(info.first);
       names[i]=info.second;
+      _arrs[i].second=ConservativeVolumic;
     }
   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;i<sz;i++)
+    {
+      _arrs[i].second=other._arrs[i].second;
+      const DataArrayDouble *da(other._arrs[i].first);
+      if(da)
+        _arrs[i].first=da->deepCpy();
+    }
+}
+
 std::size_t DataArrayDoubleCollection::getHeapMemorySizeWithoutChildren() const
 {
   std::size_t ret(sizeof(DataArrayDoubleCollection));
@@ -174,9 +247,9 @@ std::size_t DataArrayDoubleCollection::getHeapMemorySizeWithoutChildren() const
 std::vector<const BigMemoryObject *> DataArrayDoubleCollection::getDirectChildren() const
 {
   std::vector<const BigMemoryObject *> ret;
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
+  for(std::vector< std::pair< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>, NatureOfField > >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
     {
-      const DataArrayDouble *pt(*it);
+      const DataArrayDouble *pt((*it).first);
       if(pt)
         ret.push_back(pt);
     }
@@ -185,9 +258,9 @@ std::vector<const BigMemoryObject *> DataArrayDoubleCollection::getDirectChildre
 
 void DataArrayDoubleCollection::updateTime() const
 {
-  for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
+  for(std::vector< std::pair< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>, NatureOfField > >::const_iterator it=_arrs.begin();it!=_arrs.end();it++)
     {
-      const DataArrayDouble *pt(*it);
+      const DataArrayDouble *pt((*it).first);
       if(pt)
         updateTimeWith(*pt);
     }
@@ -200,11 +273,36 @@ 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 !");
 }
 
+bool DataArrayDoubleCollection::IsConservativeNature(NatureOfField n)
+{
+  CheckValidNature(n);
+  return n==RevIntegral || n==IntegralGlobConstraint;
+}
+
+void DataArrayDoubleCollection::CheckSameNatures(NatureOfField n1, NatureOfField n2)
+{
+  CheckValidNature(n1);
+  CheckValidNature(n2);
+  if(n1!=n2)
+    throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::CheckSameNatures : natures are not the same !");
+}
+
+void DataArrayDoubleCollection::CheckValidNature(NatureOfField n)
+{
+  if(n!=ConservativeVolumic && n!=Integral && n!=IntegralGlobConstraint && n!=RevIntegral)
+    throw INTERP_KERNEL::Exception("DataArrayDoubleCollection::CheckValidNature : unrecognized nature !");
+}
+
 MEDCouplingGridCollection *MEDCouplingGridCollection::New(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames)
 {
   return new MEDCouplingGridCollection(ms,fieldNames);
 }
 
+MEDCouplingGridCollection *MEDCouplingGridCollection::deepCpy(const MEDCouplingCartesianAMRMeshGen *newGf, const MEDCouplingCartesianAMRMeshGen *oldGf) const
+{
+  return new MEDCouplingGridCollection(*this,newGf,oldGf);
+}
+
 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++)
@@ -236,6 +334,12 @@ void MEDCouplingGridCollection::spillInfoOnComponents(const std::vector< std::ve
     (*it).second->spillInfoOnComponents(compNames);
 }
 
+void MEDCouplingGridCollection::spillNatures(const std::vector<NatureOfField>& nfs)
+{
+  for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
+    (*it).second->spillNatures(nfs);
+}
+
 bool MEDCouplingGridCollection::presenceOf(const MEDCouplingCartesianAMRMeshGen *m, int& pos) const
 {
   int ret(0);
@@ -250,10 +354,10 @@ bool MEDCouplingGridCollection::presenceOf(const MEDCouplingCartesianAMRMeshGen
   return false;
 }
 
-const DataArrayDoubleCollection& MEDCouplingGridCollection::retrieveFieldsAt(int pos) const
+const DataArrayDoubleCollection& MEDCouplingGridCollection::getFieldsAt(int pos) const
 {
   if(pos<0 || pos>(int)_map_of_dadc.size())
-    throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::retrieveFieldsAt : invalid pos given in input ! Must be in [0,size) !");
+    throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::getFieldsAt : invalid pos given in input ! Must be in [0,size) !");
   return *_map_of_dadc[pos].second;
 }
 
@@ -311,32 +415,76 @@ void MEDCouplingGridCollection::SynchronizeCoarseToFine(int ghostLev, const MEDC
     }
 }
 
-void MEDCouplingGridCollection::synchronizeFineEachOther(int ghostLev) const
+/*!
+ * All the pairs in \a ps must share the same father. If not call synchronizeFineEachOtherExt instead.
+ *
+ * \sa synchronizeFineEachOtherExt
+ */
+void MEDCouplingGridCollection::synchronizeFineEachOther(int ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const
 {
-  std::map<const MEDCouplingCartesianAMRMeshGen *,std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *, const DataArrayDoubleCollection *> > > m;
+  for(std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >::const_iterator it=ps.begin();it!=ps.end();it++)
+    {
+      int p1,p2;
+      if(!presenceOf((*it).first->getMesh(),p1))
+        throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::synchronizeFineEachOther : internal error #1 !");
+      if(!presenceOf((*it).second->getMesh(),p2))
+        throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::synchronizeFineEachOther : internal error #2 !");
+      const DataArrayDoubleCollection& col1(getFieldsAt(p1));
+      const DataArrayDoubleCollection& col2(getFieldsAt(p2));
+      col1.synchronizeMyGhostZoneUsing(ghostLev,col2,(*it).first,(*it).second,(*it).first->getMesh()->getFather());
+    }
+}
+
+/*!
+ * This method is a generalization of synchronizeFineEachOther because elements in pairs are \b not sharing the same father but are neighbors nevertheless.
+ *
+ * \sa synchronizeFineEachOther
+ */
+void MEDCouplingGridCollection::synchronizeFineEachOtherExt(int ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const
+{
+  for(std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >::const_iterator it=ps.begin();it!=ps.end();it++)
+    {
+      int p1,p2;
+      if(!presenceOf((*it).first->getMesh(),p1))
+        throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::synchronizeFineEachOtherExt : internal error #1 !");
+      if(!presenceOf((*it).second->getMesh(),p2))
+        throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::synchronizeFineEachOtherExt : internal error #2 !");
+      const DataArrayDoubleCollection& col1(getFieldsAt(p1));
+      const DataArrayDoubleCollection& col2(getFieldsAt(p2));
+      col1.synchronizeMyGhostZoneUsingExt(ghostLev,col2,(*it).first,(*it).second);
+    }
+}
+
+/*!
+ * The pairs returned share the same direct father. The number of returned elements must be even.
+ */
+std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > MEDCouplingGridCollection::findNeighbors(int ghostLev) const
+{
+  std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > ret;
+  std::map<const MEDCouplingCartesianAMRMeshGen *,std::vector< const MEDCouplingCartesianAMRMeshGen * > > m;
   for(std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > >::const_iterator it=_map_of_dadc.begin();it!=_map_of_dadc.end();it++)
     {
       const MEDCouplingCartesianAMRMeshGen *fineMesh((*it).first);
       const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh(fineMesh->getFather());
-      m[fatherOfFineMesh].push_back(std::pair<const MEDCouplingCartesianAMRMeshGen *, const DataArrayDoubleCollection *>(fineMesh,(*it).second));
+      m[fatherOfFineMesh].push_back(fineMesh);
     }
-  for(std::map<const MEDCouplingCartesianAMRMeshGen *,std::vector<std::pair<const MEDCouplingCartesianAMRMeshGen *, const DataArrayDoubleCollection *> > >::const_iterator it0=m.begin();it0!=m.end();it0++)
+  for(std::map<const MEDCouplingCartesianAMRMeshGen *,std::vector< const MEDCouplingCartesianAMRMeshGen * > >::const_iterator it0=m.begin();it0!=m.end();it0++)
     {
-      std::size_t sz((*it0).second.size());
-      std::vector<const MEDCouplingCartesianAMRMeshGen *> v0(sz);
-      std::vector<DataArrayDoubleCollection *> v1(sz);
-      for(std::size_t i=0;i<sz;i++)
+      for(std::vector<const MEDCouplingCartesianAMRMeshGen *>::const_iterator it1=(*it0).second.begin();it1!=(*it0).second.end();it1++)
         {
-          v0[i]=(*it0).second[i].first;
-          const DataArrayDoubleCollection *tmp((*it0).second[i].second);
-          v1[i]=const_cast<DataArrayDoubleCollection *>(tmp);
-        }
-      for(std::vector<std::pair<const MEDCouplingCartesianAMRMeshGen *, const DataArrayDoubleCollection *> >::const_iterator it1=(*it0).second.begin();it1!=(*it0).second.end();it1++)
-        {
-          int patchId((*it0).first->getPatchIdFromChildMesh((*it1).first));
-          DataArrayDoubleCollection::SynchronizeFineEachOther(patchId,ghostLev,(*it0).first,v0,v1);
+          int patchId((*it0).first->getPatchIdFromChildMesh(*it1));
+          std::vector<int> neighs((*it0).first->getPatchIdsInTheNeighborhoodOf(patchId,ghostLev));
+          const MEDCouplingCartesianAMRPatch *pRef((*it0).first->getPatch(patchId));
+          for(std::vector<int>::const_iterator it2=neighs.begin();it2!=neighs.end();it2++)
+            {
+              const MEDCouplingCartesianAMRPatch *pLoc((*it0).first->getPatch(*it2));
+              ret.push_back(std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *>(pRef,pLoc));
+            }
         }
     }
+  if(ret.size()%2!=0)
+    throw INTERP_KERNEL::Exception("MEDCouplingGridCollection::findNeighbors : something is wrong ! The number of neighbor pairs must be %2 ==0 !");
+  return ret;
 }
 
 void MEDCouplingGridCollection::SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine)
@@ -391,6 +539,19 @@ MEDCouplingGridCollection::MEDCouplingGridCollection(const std::vector<const MED
     }
 }
 
+MEDCouplingGridCollection::MEDCouplingGridCollection(const MEDCouplingGridCollection& other, const MEDCouplingCartesianAMRMeshGen *newGf, const MEDCouplingCartesianAMRMeshGen *oldGf):RefCountObject(other),_map_of_dadc(other._map_of_dadc.size())
+{
+  std::size_t sz(other._map_of_dadc.size());
+  for(std::size_t i=0;i<sz;i++)
+    {
+      std::vector<int> pos(other._map_of_dadc[i].first->getPositionRelativeTo(oldGf));
+      _map_of_dadc[i].first=newGf->getMeshAtPosition(pos);
+      const DataArrayDoubleCollection *dac(other._map_of_dadc[i].second);
+      if(dac)
+        _map_of_dadc[i].second=dac->deepCpy();
+    }
+}
+
 std::size_t MEDCouplingGridCollection::getHeapMemorySizeWithoutChildren() const
 {
   std::size_t ret(sizeof(MEDCouplingGridCollection));
@@ -423,15 +584,56 @@ void MEDCouplingGridCollection::updateTime() const
     }
 }
 
+MEDCouplingCartesianAMRMesh *MEDCouplingDataForGodFather::getMyGodFather()
+{
+  return _gf;
+}
+
+MEDCouplingDataForGodFather::MEDCouplingDataForGodFather(MEDCouplingCartesianAMRMesh *gf):_gf(gf),_tlc(gf)
+{
+  if(!gf)
+    throw INTERP_KERNEL::Exception("MEDCouplingDataForGodFather constructor : A data has to be attached to a AMR Mesh instance !");
+  gf->incrRef();
+}
+
+void MEDCouplingDataForGodFather::checkGodFatherFrozen() const
+{
+  _tlc.checkConst();
+}
+
+bool MEDCouplingDataForGodFather::changeGodFather(MEDCouplingCartesianAMRMesh *gf)
+{
+  bool ret(_tlc.keepTrackOfNewTL(gf));
+  if(ret)
+    {
+      _gf=gf;
+      if(gf)
+        gf->incrRef();
+    }
+  return ret;
+}
+
+MEDCouplingDataForGodFather::MEDCouplingDataForGodFather(const MEDCouplingDataForGodFather& other, bool deepCpyGF):RefCountObject(other),_gf(other._gf),_tlc(other._gf)
+{
+  other._tlc.checkConst();
+  if(deepCpyGF)
+    {
+      const MEDCouplingCartesianAMRMesh *gf(other._gf);
+      if(gf)
+        _gf=gf->deepCpy(0);
+      _tlc.keepTrackOfNewTL(_gf);
+    }
+}
+
 /*!
  * 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)
+MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev)
 {
-  return new MEDCouplingAMRAttribute(gf,fieldNames);
+  return new MEDCouplingAMRAttribute(gf,fieldNames,ghostLev);
 }
 
-MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string, std::vector<std::string> > >& fieldNames)
+MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string, std::vector<std::string> > >& fieldNames, int ghostLev)
 {
   std::size_t sz(fieldNames.size());
   std::vector< std::pair<std::string,int> > fieldNames2(sz);
@@ -442,7 +644,7 @@ MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::New(MEDCouplingCartesianAMRMes
       fieldNames2[i].second=(int)fieldNames[i].second.size();
       compNames[i]=fieldNames[i].second;
     }
-  MEDCouplingAutoRefCountObjectPtr<MEDCouplingAMRAttribute> ret(New(gf,fieldNames2));
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingAMRAttribute> ret(New(gf,fieldNames2,ghostLev));
   ret->spillInfoOnComponents(compNames);
   return ret.retn();
 }
@@ -460,6 +662,37 @@ void MEDCouplingAMRAttribute::spillInfoOnComponents(const std::vector< std::vect
     (*it)->spillInfoOnComponents(compNames);
 }
 
+/*!
+ * Assign nature for each fields in \a this.
+ * \param [in] nfs
+ */
+void MEDCouplingAMRAttribute::spillNatures(const std::vector<NatureOfField>& nfs)
+{
+  _tlc.checkConst();
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::iterator it=_levs.begin();it!=_levs.end();it++)
+    (*it)->spillNatures(nfs);
+}
+
+MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::deepCpy() const
+{
+  return new MEDCouplingAMRAttribute(*this,true);
+}
+
+MEDCouplingAMRAttribute *MEDCouplingAMRAttribute::deepCpyWithoutGodFather() const
+{
+  return new MEDCouplingAMRAttribute(*this,false);
+}
+
+/*!
+ * 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.
@@ -474,7 +707,7 @@ std::vector<DataArrayDouble *> MEDCouplingAMRAttribute::retrieveFieldsOn(MEDCoup
       int tmp(-1);
       if((*it)->presenceOf(mesh,tmp))
         {
-          const DataArrayDoubleCollection& ddc((*it)->retrieveFieldsAt(tmp));
+          const DataArrayDoubleCollection& ddc((*it)->getFieldsAt(tmp));
           return ddc.retrieveFields();
         }
     }
@@ -491,7 +724,7 @@ const DataArrayDouble *MEDCouplingAMRAttribute::getFieldOn(MEDCouplingCartesianA
       int tmp(-1);
       if((*it)->presenceOf(mesh,tmp))
         {
-          const DataArrayDoubleCollection& ddc((*it)->retrieveFieldsAt(tmp));
+          const DataArrayDoubleCollection& ddc((*it)->getFieldsAt(tmp));
           return ddc.getFieldWithName(fieldName);
         }
     }
@@ -504,7 +737,7 @@ const DataArrayDouble *MEDCouplingAMRAttribute::getFieldOn(MEDCouplingCartesianA
  *
  * \return MEDCouplingFieldDouble * - a field on cells that the caller has to deal with (deallocate it).
  */
-MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnRecurseWithoutOverlapWithoutGhost(int ghostLev, MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const
+MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnRecurseWithoutOverlapWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const
 {
   std::vector<const DataArrayDouble *> recurseArrs;
   std::size_t lev(0);
@@ -513,7 +746,7 @@ MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnRecurseWithoutO
       int tmp(-1);
       if((*it)->presenceOf(mesh,tmp))
         {
-          const DataArrayDoubleCollection& ddc((*it)->retrieveFieldsAt(tmp));
+          const DataArrayDoubleCollection& ddc((*it)->getFieldsAt(tmp));
           recurseArrs.push_back(ddc.getFieldWithName(fieldName));
           break;
         }
@@ -524,7 +757,7 @@ MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnRecurseWithoutO
       const MEDCouplingGridCollection *gc(_levs[i]);
       gc->fillIfInTheProgenyOf(fieldName,mesh,recurseArrs);
     }
-  return mesh->buildCellFieldOnRecurseWithoutOverlapWithoutGhost(ghostLev,recurseArrs);
+  return mesh->buildCellFieldOnRecurseWithoutOverlapWithoutGhost(_ghost_lev,recurseArrs);
 }
 
 /*!
@@ -533,8 +766,9 @@ MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnRecurseWithoutO
  *
  * \return MEDCouplingFieldDouble * - a field on cells that the caller has to deal with (deallocate it).
  *
+ * \sa buildCellFieldOnWithoutGhost
  */
-MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnWithGhost(int ghostLev, MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const
+MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnWithGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const
 {
   const DataArrayDouble *arr(0);
   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::const_iterator it=_levs.begin();it!=_levs.end();it++)
@@ -542,13 +776,13 @@ MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnWithGhost(int g
       int tmp(-1);
       if((*it)->presenceOf(mesh,tmp))
         {
-          const DataArrayDoubleCollection& ddc((*it)->retrieveFieldsAt(tmp));
+          const DataArrayDoubleCollection& ddc((*it)->getFieldsAt(tmp));
           arr=ddc.getFieldWithName(fieldName);
         }
     }
   if(!arr)
     throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::buildCellFieldOnWithGhost : the mesh specified is not in the progeny of this !");
-  MEDCouplingAutoRefCountObjectPtr<MEDCouplingIMesh> im(mesh->getImageMesh()->buildWithGhost(ghostLev));
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingIMesh> im(mesh->getImageMesh()->buildWithGhost(_ghost_lev));
   MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(ON_CELLS));
   ret->setMesh(im);
   ret->setArray(const_cast<DataArrayDouble *>(arr));
@@ -556,11 +790,55 @@ MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnWithGhost(int g
   return ret.retn();
 }
 
+/*!
+ * This method builds a newly created field on cell just lying on mesh \a mesh without its eventual refinement.
+ * The output field does not display ghost cells.
+ *
+ * \return MEDCouplingFieldDouble * - a field on cells that the caller has to deal with (deallocate it).
+ *
+ * \sa buildCellFieldOnWithGhost
+ */
+MEDCouplingFieldDouble *MEDCouplingAMRAttribute::buildCellFieldOnWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const
+{
+  //tony
+  const DataArrayDouble *arr(0);
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::const_iterator it=_levs.begin();it!=_levs.end();it++)
+    {
+      int tmp(-1);
+      if((*it)->presenceOf(mesh,tmp))
+        {
+          const DataArrayDoubleCollection& ddc((*it)->getFieldsAt(tmp));
+          arr=ddc.getFieldWithName(fieldName);
+        }
+    }
+  if(!arr)
+    throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::buildCellFieldOnWithoutGhost : the mesh specified is not in the progeny of this !");
+  //
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingIMesh> im(mesh->getImageMesh()->buildWithGhost(_ghost_lev));
+  std::vector<int> cgs(mesh->getImageMesh()->getCellGridStructure()),cgsWG(im->getCellGridStructure());
+  MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> arr2(DataArrayDouble::New());
+  arr2->alloc(mesh->getImageMesh()->getNumberOfCells(),arr->getNumberOfComponents());
+  std::vector< std::pair<int,int> > cgs2(MEDCouplingStructuredMesh::GetCompactFrmtFromDimensions(cgs));
+  MEDCouplingStructuredMesh::ApplyGhostOnCompactFrmt(cgs2,_ghost_lev);
+  std::vector<int> fakeFactors(mesh->getImageMesh()->getSpaceDimension(),1);
+  MEDCouplingIMesh::SpreadCoarseToFine(arr,cgsWG,arr2,cgs2,fakeFactors);
+  arr2->copyStringInfoFrom(*arr);
+  //
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret(MEDCouplingFieldDouble::New(ON_CELLS));
+  ret->setMesh(mesh->getImageMesh());
+  ret->setArray(arr2);
+  ret->setName(arr->getName());
+  return ret.retn();
+}
+
 /*!
  * 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.
+ * This method \b DOES \b NOT \b UPDATE the ghost zones (neither the fine not the coarse)
+ *
+ * \sa synchronizeFineToCoarseBetween
  */
-void MEDCouplingAMRAttribute::synchronizeFineToCoarse(int ghostLev)
+void MEDCouplingAMRAttribute::synchronizeFineToCoarse()
 {
   if(_levs.empty())
     throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineToCoarse : not any levels in this !");
@@ -569,79 +847,151 @@ void MEDCouplingAMRAttribute::synchronizeFineToCoarse(int ghostLev)
   while(sz>1)
     {
       sz--;
-      const MEDCouplingGridCollection *fine(_levs[sz]),*coarse(_levs[sz-1]);
-      MEDCouplingGridCollection::SynchronizeFineToCoarse(ghostLev,fine,coarse);
+      synchronizeFineToCoarseByOneLevel((int)sz);
     }
 }
 
 /*!
- * This method synchronizes from coarse to fine arrays and fine to fine each other (if ghostLev is >0). This method makes the hypothesis that \a this has been allocated before using
+ * 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.
+ * This method \b DOES \b NOT \b UPDATE the ghost zones (neither the fine not the coarse).
+ *
+ * \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(fromLev<toLev)
+    throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineToCoarseBetween : the fromLev level is lower than toLev level ! Call synchronizeFineToCoarseBetween ");
+  for(int i=fromLev;i>toLev;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.
+ * This method \b DOES \b UPDATE \b the \b ghost \b zone (contrary to synchronizeFineToCoarse method)
  */
-void MEDCouplingAMRAttribute::synchronizeCoarseToFine(int ghostLev)
+void MEDCouplingAMRAttribute::synchronizeCoarseToFine()
 {
   if(_levs.empty())
     throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeCoarseToFine : not any levels in this !");
   std::size_t sz(_levs.size());
   //
-  for(std::size_t i=1;i<sz;i++)
-    {
-      const MEDCouplingGridCollection *fine(_levs[i]),*coarse(_levs[i-1]);
-      MEDCouplingGridCollection::SynchronizeCoarseToFine(ghostLev,coarse,fine);
-    }
+  for(std::size_t i=0;i<sz-1;i++)
+    synchronizeCoarseToFineByOneLevel((int)i);
 }
 
 /*!
- * This method performs coarse to fine spread only in the ghost zone.
+ * This method allows to synchronizes fields on coarse patches on level \a fromLev to their respective refined 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.
+ * This method \b DOES \b UPDATE \b the \b ghost \b zone (contrary to synchronizeFineToCoarseBetween method)
+ *
+ * \param [in] fromLev - an existing level considered as coarse so lower than \a toLev
+ * \param [in] toLev - an existing level considered as the target level to reach.
+ */
+void MEDCouplingAMRAttribute::synchronizeCoarseToFineBetween(int fromLev, int toLev)
+{
+  int nbl(getNumberOfLevels());
+  if(fromLev<0 || toLev<0 || fromLev>=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;i<toLev;i++)
+    synchronizeCoarseToFineByOneLevel(i);
+}
+
+/*!
+ * This method synchronizes the ghost zone of all patches (excepted the god father one).
+ * This method operates in 4 steps. Larger is the number of steps more accurate is the information in the ghost zone.
+ *
+ * - firstly coarse to fine with no interactions between brother patches.
+ * - secondly connected brother patches in a same master patch are updated.
+ * - thirdly connected nephew patches are updated each other.
+ * - forthly nth generation cousin patches are updated each other.
+ *
  * This method makes the hypothesis that \a this has been allocated before using MEDCouplingAMRAttribute::alloc method.
- * So if \a ghostLev == 0 this method has no effect.
+ * So if \a _ghost_lev == 0 this method has no effect.
  */
-void MEDCouplingAMRAttribute::synchronizeCoarseToFineOnlyInGhostZone(int ghostLev)
+void MEDCouplingAMRAttribute::synchronizeAllGhostZones()
 {
-  if(_levs.empty())
-    throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeCoarseToFineOnlyInGhostZone : not any levels in this !");
-  std::size_t sz(_levs.size());
-  //
-  for(std::size_t i=1;i<sz;i++)
+  int sz(getNumberOfLevels());
+  if(sz==0)
+    throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineEachOther : not any levels in this !");
+  // 1st - synchronize from coarse to the finest all the patches (excepted the god father one)
+  for(int i=1;i<sz;i++)
     {
       const MEDCouplingGridCollection *fine(_levs[i]),*coarse(_levs[i-1]);
-      MEDCouplingGridCollection::SynchronizeCoarseToFineOnlyInGhostZone(ghostLev,coarse,fine);
+      MEDCouplingGridCollection::SynchronizeCoarseToFineOnlyInGhostZone(_ghost_lev,coarse,fine);
+    }
+  // 2nd - classical direct sublevel inside common patch
+  for(int i=1;i<sz;i++)
+    {
+      const MEDCouplingGridCollection *curLev(_levs[i]);
+      if(!curLev)
+        throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineEachOtherInGhostZone : presence of a NULL element !");
+      curLev->synchronizeFineEachOther(_ghost_lev,_neighbors[i]);
+    }
+  // 3rd - mixed level
+  for(std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >::const_iterator it=_mixed_lev_neighbors.begin();it!=_mixed_lev_neighbors.end();it++)
+    {
+      const DataArrayDoubleCollection *firstDAC(&findCollectionAttachedTo((*it).first->getMesh())),*secondDAC(&findCollectionAttachedTo((*it).second->getMesh()));
+      DataArrayDoubleCollection::SynchronizeGhostZoneOfOneUsingTwo(_ghost_lev,(*it).first,firstDAC,(*it).second,secondDAC);
+    }
+  // 4th - same level but with far ancestor.
+  for(int i=1;i<sz;i++)
+    {
+      const MEDCouplingGridCollection *fine(_levs[i]);
+      fine->synchronizeFineEachOtherExt(_ghost_lev,_cross_lev_neighbors[i]);
     }
 }
 
 /*!
- * This method synchronizes fine each other only in the ghost zone.
+ * This method synchronizes all direct children of \a mesh each other.
  */
-void MEDCouplingAMRAttribute::synchronizeFineEachOtherInGhostZone(int ghostLev)
+void MEDCouplingAMRAttribute::synchronizeAllGhostZonesOfDirectChidrenOf(const MEDCouplingCartesianAMRMeshGen *mesh)
 {
-  if(_levs.empty())
-    throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineEachOther : not any levels in this !");
-  std::size_t sz(_levs.size());
-  //
-  for(std::size_t i=1;i<sz;i++)
+  if(!mesh)
+    throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeAllGhostZonesOfDirectChidrenOf : input mesh is NULL !");
+  int level(mesh->getAbsoluteLevelRelativeTo(_gf)),sz(getNumberOfLevels());
+  if(level<0 || level>=sz-1)
+    throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeAllGhostZonesOfDirectChidrenOf : the specified level does not exist ! Must be in [0,nbOfLevelsOfThis-1) !");
+  const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& itemsToFilter(_neighbors[level+1]);
+  std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > itemsToSync; itemsToSync.reserve(itemsToFilter.size());
+  for(std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >::const_iterator it=itemsToFilter.begin();it!=itemsToFilter.end();it++)
     {
-      const MEDCouplingGridCollection *fine(_levs[i]);
-      if(!fine)
-        throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeFineEachOtherInGhostZone : presence of a NULL element !");
-      fine->synchronizeFineEachOther(ghostLev);
+      if((*it).first->getMesh()->getFather()==mesh && (*it).second->getMesh()->getFather()==mesh)
+        itemsToSync.push_back(std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *>((*it).first,(*it).second));
     }
+  const MEDCouplingGridCollection *curLev(_levs[level+1]);
+  if(!curLev)
+    throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::synchronizeAllGhostZonesOfDirectChidrenOf : presence of a NULL element !");
+  curLev->synchronizeFineEachOther(_ghost_lev,itemsToSync);
 }
 
 /*!
  * 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)
+void MEDCouplingAMRAttribute::alloc()
 {
   _tlc.resetState();
   for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::iterator it=_levs.begin();it!=_levs.end();it++)
     {
       MEDCouplingGridCollection *elt(*it);
       if(elt)
-        elt->alloc(ghostLev);
+        elt->alloc(_ghost_lev);
       else
         throw INTERP_KERNEL::Exception("MEDCouplingAMRAttribute::alloc : internal error !");
     }
@@ -693,7 +1043,7 @@ void MEDCouplingAMRAttribute::updateTime() const
 {//tony
 }
 
-MEDCouplingAMRAttribute::MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames):MEDCouplingDataForGodFather(gf)
+MEDCouplingAMRAttribute::MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev):MEDCouplingDataForGodFather(gf),_ghost_lev(ghostLev)
 {
   //gf non empty, checked by constructor
   int maxLev(gf->getMaxNumberOfLevelsRelativeToThis());
@@ -712,4 +1062,118 @@ MEDCouplingAMRAttribute::MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf
         }
       _levs[i]=MEDCouplingGridCollection::New(ms,fieldNames);
     }
+  // updates cross levels neighbors
+  _neighbors.resize(_levs.size());
+  _cross_lev_neighbors.resize(_levs.size());
+  if(_levs.empty())
+    throw INTERP_KERNEL::Exception("constructor of MEDCouplingAMRAttribute : not any levels in this !");
+  std::size_t sz(_levs.size());
+  for(std::size_t i=1;i<sz;i++)
+    {
+      const MEDCouplingGridCollection *fine(_levs[i]);
+      if(!fine)
+        throw INTERP_KERNEL::Exception("constructor of MEDCouplingAMRAttribute : presence of a NULL element !");
+      _neighbors[i]=fine->findNeighbors(_ghost_lev);
+      if(i!=sz-1)
+        {
+          for(std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >::const_iterator it=_neighbors[i].begin();it!=_neighbors[i].end();it++)
+            {
+              MEDCouplingCartesianAMRPatch::FindNeighborsOfSubPatchesOf(_ghost_lev,(*it).first,(*it).second,_mixed_lev_neighbors);
+              std::vector< std::vector < std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > neighs2(MEDCouplingCartesianAMRPatch::FindNeighborsOfSubPatchesOfSameLev(_ghost_lev,(*it).first,(*it).second));
+              std::size_t fullLev(i+neighs2.size());
+              if(fullLev>=sz)
+                throw INTERP_KERNEL::Exception("constructor of MEDCouplingAMRAttribute : internal error ! something is wrong in computation of cross level neighbors !");
+              std::size_t ii(i+1);
+              for(std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > >::const_iterator it0=neighs2.begin();it0!=neighs2.end();it0++,ii++)
+                _cross_lev_neighbors[ii].insert(_cross_lev_neighbors[ii].end(),(*it0).begin(),(*it0).end());
+            }
+        }
+    }
+}
+
+MEDCouplingAMRAttribute::MEDCouplingAMRAttribute(const MEDCouplingAMRAttribute& other, bool deepCpyGF):MEDCouplingDataForGodFather(other,deepCpyGF),_ghost_lev(other._ghost_lev),_levs(other._levs.size()),_neighbors(other._neighbors),_mixed_lev_neighbors(other._mixed_lev_neighbors),_cross_lev_neighbors(other._cross_lev_neighbors)
+{
+  std::size_t sz(other._levs.size());
+  for(std::size_t i=0;i<sz;i++)
+    {
+      const MEDCouplingGridCollection *elt(other._levs[i]);
+      if(elt)
+        {
+          _levs[i]=other._levs[i]->deepCpy(_gf,other._gf);
+        }
+    }
+  //_cross_lev_neighbors(other._cross_lev_neighbors)
+  sz=other._neighbors.size();
+  for(std::size_t i=0;i<sz;i++)
+    {
+      const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& neigh2(other._neighbors[i]);
+      std::size_t sz2(neigh2.size());
+      std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& neigh3(_neighbors[i]);
+      for(std::size_t j=0;j<sz2;j++)
+        {
+          const MEDCouplingCartesianAMRPatch *p1(neigh2[j].first),*p2(neigh2[j].second);
+          std::vector<int> pp1(p1->getMesh()->getPositionRelativeTo(other._gf)),pp2(p2->getMesh()->getPositionRelativeTo(other._gf));
+          neigh3[j].first=_gf->getPatchAtPosition(pp1);
+          neigh3[j].second=_gf->getPatchAtPosition(pp2);
+        }
+    }
+  //
+  sz=other._mixed_lev_neighbors.size();
+  for(std::size_t i=0;i<sz;i++)
+    {
+      const MEDCouplingCartesianAMRPatch *p1(other._mixed_lev_neighbors[i].first),*p2(other._mixed_lev_neighbors[i].second);
+      std::vector<int> pp1(p1->getMesh()->getPositionRelativeTo(other._gf)),pp2(p2->getMesh()->getPositionRelativeTo(other._gf));
+      _mixed_lev_neighbors[i].first=_gf->getPatchAtPosition(pp1);
+      _mixed_lev_neighbors[i].second=_gf->getPatchAtPosition(pp2);
+    }
+  //
+  sz=other._cross_lev_neighbors.size();
+  for(std::size_t i=0;i<sz;i++)
+    {
+      const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& neigh2(other._cross_lev_neighbors[i]);
+      std::size_t sz2(neigh2.size());
+      std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& neigh3(_cross_lev_neighbors[i]);
+      for(std::size_t j=0;j<sz2;j++)
+        {
+          const MEDCouplingCartesianAMRPatch *p1(neigh2[j].first),*p2(neigh2[j].second);
+          std::vector<int> pp1(p1->getMesh()->getPositionRelativeTo(other._gf)),pp2(p2->getMesh()->getPositionRelativeTo(other._gf));
+          neigh3[j].first=_gf->getPatchAtPosition(pp1);
+          neigh3[j].second=_gf->getPatchAtPosition(pp2);
+        }
+    }
+}
+
+const DataArrayDoubleCollection& MEDCouplingAMRAttribute::findCollectionAttachedTo(const MEDCouplingCartesianAMRMeshGen *m) const
+{
+  for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> >::const_iterator it=_levs.begin();it!=_levs.end();it++)
+    {
+      const MEDCouplingGridCollection *elt(*it);
+      if(elt)
+        {
+          int tmp(-1);
+          if(elt->presenceOf(m,tmp))
+            {
+              return elt->getFieldsAt(tmp);
+            }
+        }
+    }
+  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);
 }