]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
+ Field::cellToNode implementation
authorageay <ageay>
Wed, 8 Jan 2014 15:09:19 +0000 (15:09 +0000)
committerageay <ageay>
Wed, 8 Jan 2014 15:09:19 +0000 (15:09 +0000)
 + fast reverseNodal computation for structured mesh.

src/MEDCoupling/MEDCouplingExtrudedMesh.cxx
src/MEDCoupling/MEDCouplingExtrudedMesh.hxx
src/MEDCoupling/MEDCouplingFieldDouble.cxx
src/MEDCoupling/MEDCouplingFieldDouble.hxx
src/MEDCoupling/MEDCouplingMesh.hxx
src/MEDCoupling/MEDCouplingPointSet.hxx
src/MEDCoupling/MEDCouplingStructuredMesh.cxx
src/MEDCoupling/MEDCouplingStructuredMesh.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 3658b43bee4b276b6ffa30d407909fa5501e97d1..8625326705ffc81b6399d591c0ac17afe0519346 100644 (file)
@@ -766,6 +766,12 @@ DataArrayDouble *MEDCouplingExtrudedMesh::computeIsoBarycenterOfNodesPerCell() c
   throw INTERP_KERNEL::Exception("MEDCouplingExtrudedMesh::computeIsoBarycenterOfNodesPerCell: not yet implemented !");
 }
 
+void MEDCouplingExtrudedMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const
+{
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m(buildUnstructured());
+  m->getReverseNodalConnectivity(revNodal,revNodalIndx);
+}
+
 void MEDCouplingExtrudedMesh::computeExtrusionAlg(const MEDCouplingUMesh *mesh3D)
 {
   _mesh3D_ids->alloc(mesh3D->getNumberOfCells(),1);
index ebceee9c3415dfecab98b4fc57cbee07c7b36352..6902eeda9215a0815a710d8c1238872be28b9374 100644 (file)
@@ -97,6 +97,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT DataArrayDouble *getCoordinatesAndOwner() const;
     MEDCOUPLING_EXPORT DataArrayDouble *getBarycenterAndOwner() const;
     MEDCOUPLING_EXPORT DataArrayDouble *computeIsoBarycenterOfNodesPerCell() const;
+    MEDCOUPLING_EXPORT void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const;
     //Serialization unserialisation
     MEDCOUPLING_EXPORT void getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const;
     MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const;
index 097e3a78884c98af707efae18ac9461bc6f3d217..4b3fad76b74b139dde07bd7420bf3da3469d6028 100644 (file)
@@ -273,6 +273,50 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::nodeToCellDiscretization() const
   return ret.retn();
 }
 
+/*!
+ * This method converts a field on cell (\a this) to a node field (returned field). The convertion is a \b non \b conservative remapping !
+ * This method is useful only for users that need a fast convertion from cell to node spatial discretization. The algorithm applied is simply to attach
+ * to each node the average of values on cell sharing this node. If \a this lies on a mesh having orphan nodes the values applied on them will be NaN (division by 0.).
+ *
+ * \return MEDCouplingFieldDouble* - a new instance of MEDCouplingFieldDouble. The
+ *         caller is to delete this field using decrRef() as it is no more needed. The returned field will share the same mesh object object than those in \a this.
+ * \throw If \a this spatial discretization is empty or not ON_CELLS.
+ * \throw If \a this is not coherent (see MEDCouplingFieldDouble::checkCoherency).
+ *
+ * \warning This method is a \b non \b conservative method of remapping from cell spatial discretization to node spatial discretization.
+ * If a conservative method of interpolation is required ParaMEDMEM::MEDCouplingRemapper class should be used instead with "P0P1" method.
+ */
+MEDCouplingFieldDouble *MEDCouplingFieldDouble::cellToNodeDiscretization() const
+{
+  checkCoherency();
+  TypeOfField tf(getTypeOfField());
+  if(tf!=ON_CELLS)
+    throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::cellToNodeDiscretization : this field is expected to be on ON_CELLS !");
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret(clone(false));
+  MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDiscretizationP1> nsp(new MEDCouplingFieldDiscretizationP1);
+  ret->setDiscretization(nsp);
+  const MEDCouplingMesh *m(getMesh());//m is non empty thanks to checkCoherency call
+  int nbCells(m->getNumberOfCells()),nbNodes(m->getNumberOfNodes());
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rn(DataArrayInt::New()),rni(DataArrayInt::New());
+  m->getReverseNodalConnectivity(rn,rni);
+  MEDCouplingAutoRefCountObjectPtr<DataArrayInt> rni2(rni->deltaShiftIndex());
+  MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> rni3(rni2->convertToDblArr()); rni2=0;
+  std::vector<DataArrayDouble *> arrs(getArrays());
+  std::size_t sz(arrs.size());
+  std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > outArrsSafe(sz); std::vector<DataArrayDouble *> outArrs(sz);
+  for(std::size_t j=0;j<sz;j++)
+    {
+      int nbCompo(arrs[j]->getNumberOfComponents());
+      MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(arrs[j]->selectByTupleIdSafe(rn->begin(),rn->end()));
+      outArrsSafe[j]=(tmp->accumulatePerChunck(rni->begin(),rni->end())); tmp=0;
+      outArrsSafe[j]->divideEqual(rni3);
+      outArrsSafe[j]->copyStringInfoFrom(*arrs[j]);
+      outArrs[j]=outArrsSafe[j];
+    }
+  ret->setArrays(outArrs);
+  return ret.retn();
+}
+
 /*!
  * Copies tiny info (component names, name and description) from an \a other field to
  * \a this one.
index b64819edca9f96b709938472c48a4e44d1b92f42..8b2c5e22fb3fcfd7f44f294634d60ea96db10dc9 100644 (file)
@@ -64,6 +64,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *cloneWithMesh(bool recDeepCpy) const;
     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCopy) const;
     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *nodeToCellDiscretization() const;
+    MEDCOUPLING_EXPORT MEDCouplingFieldDouble *cellToNodeDiscretization() const;
     MEDCOUPLING_EXPORT TypeOfTimeDiscretization getTimeDiscretization() const;
     MEDCOUPLING_EXPORT void checkCoherency() const;
     MEDCOUPLING_EXPORT void setNature(NatureOfField nat);
index c8203c56b042d28aaf76396a0440cf5abf1f7d75..57de33976ef3d4f3642451f588f7554f4590f576 100644 (file)
@@ -128,6 +128,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT virtual MEDCouplingMesh *buildPartRangeAndReduceNodes(int beginCellIds, int endCellIds, int stepCellIds, int& beginOut, int& endOut, int& stepOut, DataArrayInt*& arr) const;
     MEDCOUPLING_EXPORT virtual MEDCouplingUMesh *buildUnstructured() const = 0;
     MEDCOUPLING_EXPORT virtual DataArrayInt *simplexize(int policy) = 0;
+    MEDCOUPLING_EXPORT virtual void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const = 0;
     MEDCOUPLING_EXPORT virtual bool areCompatibleForMerge(const MEDCouplingMesh *other) const;
     MEDCOUPLING_EXPORT static MEDCouplingMesh *MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2);
     MEDCOUPLING_EXPORT static MEDCouplingMesh *MergeMeshes(std::vector<const MEDCouplingMesh *>& meshes);
index aa5622b19b926eddfab5bfe2de5c7727141b8580..f63360d3fa8bc04084892d6853c6da6f15d5b2db 100644 (file)
@@ -136,7 +136,6 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT virtual DataArrayInt *getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps) = 0;
     MEDCOUPLING_EXPORT virtual DataArrayInt *zipCoordsTraducer();
     MEDCOUPLING_EXPORT virtual DataArrayInt *zipConnectivityTraducer(int compType, int startCellId=0);
-    MEDCOUPLING_EXPORT virtual void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const = 0;
     //tools
   public:
     MEDCOUPLING_EXPORT bool areCellsFrom2MeshEqual(const MEDCouplingPointSet *other, int cellId, double prec) const;
index 011c49dea6103bec790e257a6d0a3930a57ec25e..c51f02b924b0f726c700ca69ca334bf2ae7b0091 100644 (file)
@@ -375,6 +375,161 @@ MEDCouplingFieldDouble *MEDCouplingStructuredMesh::buildOrthogonalField() const
   return ret;
 }
 
+void MEDCouplingStructuredMesh::getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const
+{
+  std::vector<int> ngs(getNodeGridStructure());
+  int dim(getMeshDimension());
+  switch(dim)
+  {
+    case 1:
+      return GetReverseNodalConnectivity1(ngs,revNodal,revNodalIndx);
+    case 2:
+      return GetReverseNodalConnectivity2(ngs,revNodal,revNodalIndx);
+    case 3:
+      return GetReverseNodalConnectivity3(ngs,revNodal,revNodalIndx);
+    default:
+      throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::getReverseNodalConnectivity : only dimensions 1, 2 and 3 are supported !");
+  }
+}
+
+void MEDCouplingStructuredMesh::GetReverseNodalConnectivity1(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx)
+{
+  int nbNodes(ngs[0]);
+  revNodalIndx->alloc(nbNodes+1,1);
+  if(nbNodes==0)
+    { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); return ; }
+  if(nbNodes==1)
+    { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); revNodalIndx->setIJ(1,0,0); return ; }
+  revNodal->alloc(2*(nbNodes-1),1);
+  int *rn(revNodal->getPointer()),*rni(revNodalIndx->getPointer());
+  *rni++=0; *rni=1; *rn++=0;
+  for(int i=1;i<nbNodes-1;i++,rni++)
+    {
+      rn[0]=i-1; rn[1]=i;
+      rni[1]=rni[0]+2;
+      rn+=2;
+    }
+  rn[0]=nbNodes-2; rni[1]=rni[0]+1;
+}
+
+void MEDCouplingStructuredMesh::GetReverseNodalConnectivity2(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx)
+{
+  int nbNodesX(ngs[0]),nbNodesY(ngs[1]);
+  int nbNodes(nbNodesX*nbNodesY);
+  if(nbNodesX==0 || nbNodesY==0)
+    { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); return ; }
+  if(nbNodesX==1 || nbNodesY==1)
+    { std::vector<int> ngs2(1); ngs2[0]=std::max(nbNodesX,nbNodesY); return GetReverseNodalConnectivity1(ngs2,revNodal,revNodalIndx); }
+  revNodalIndx->alloc(nbNodes+1,1);
+  int nbCellsX(nbNodesX-1),nbCellsY(nbNodesY-1);
+  revNodal->alloc(4*(nbNodesX-2)*(nbNodesY-2)+2*2*(nbNodesX-2)+2*2*(nbNodesY-2)+4,1);
+  int *rn(revNodal->getPointer()),*rni(revNodalIndx->getPointer());
+  *rni++=0; *rni=1; *rn++=0;
+  for(int i=1;i<nbNodesX-1;i++,rni++,rn+=2)
+    {
+      rn[0]=i-1; rn[1]=i;
+      rni[1]=rni[0]+2;
+    }
+  rni[1]=rni[0]+1; *rn++=nbCellsX-1;
+  rni++;
+  for(int j=1;j<nbNodesY-1;j++)
+    {
+      int off(nbCellsX*(j-1)),off2(nbCellsX*j);
+      rni[1]=rni[0]+2; rn[0]=off; rn[1]=off2;
+      rni++; rn+=2;
+      for(int i=1;i<nbNodesX-1;i++,rni++,rn+=4)
+        {
+          rn[0]=i-1+off; rn[1]=i+off; rn[2]=i-1+off2; rn[3]=i+off2;
+          rni[1]=rni[0]+4;
+        }
+      rni[1]=rni[0]+2; rn[0]=off+nbCellsX-1; rn[1]=off2+nbCellsX-1;
+      rni++; rn+=2;
+    }
+  int off3(nbCellsX*(nbCellsY-1));
+  rni[1]=rni[0]+1;
+  rni++; *rn++=off3;
+  for(int i=1;i<nbNodesX-1;i++,rni++,rn+=2)
+    {
+      rn[0]=i-1+off3; rn[1]=i+off3;
+      rni[1]=rni[0]+2;
+    }
+  rni[1]=rni[0]+1; rn[0]=nbCellsX*nbCellsY-1;
+}
+
+void MEDCouplingStructuredMesh::GetReverseNodalConnectivity3(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx)
+{
+  int nbNodesX(ngs[0]),nbNodesY(ngs[1]),nbNodesZ(ngs[2]);
+  int nbNodes(nbNodesX*nbNodesY*nbNodesZ);
+  if(nbNodesX==0 || nbNodesY==0 || nbNodesZ==0)
+    { revNodal->alloc(0,1); revNodalIndx->setIJ(0,0,0); return ; }
+  if(nbNodesX==1 || nbNodesY==1 || nbNodesZ==1)
+    {
+      std::vector<int> ngs2(2);
+      int pos(0);
+      bool pass(false);
+      for(int i=0;i<3;i++)
+        {
+          if(pass)
+            { ngs2[pos++]=ngs[i]; }
+          else
+            {
+              pass=ngs[i]==1;
+              if(!pass)
+                { ngs2[pos++]=ngs[i]; }
+            }
+        }
+      return GetReverseNodalConnectivity2(ngs2,revNodal,revNodalIndx);
+    }
+  revNodalIndx->alloc(nbNodes+1,1);
+  int nbCellsX(nbNodesX-1),nbCellsY(nbNodesY-1),nbCellsZ(nbNodesZ-1);
+  revNodal->alloc(8*(nbNodesX-2)*(nbNodesY-2)*(nbNodesZ-2)+4*(2*(nbNodesX-2)*(nbNodesY-2)+2*(nbNodesX-2)*(nbNodesZ-2)+2*(nbNodesY-2)*(nbNodesZ-2))+2*4*(nbNodesX-2)+2*4*(nbNodesY-2)+2*4*(nbNodesZ-2)+8,1);
+  int *rn(revNodal->getPointer()),*rni(revNodalIndx->getPointer());
+  *rni=0;
+  for(int k=0;k<nbNodesZ;k++)
+    {
+      bool factZ(k!=0 && k!=nbNodesZ-1);
+      int offZ0((k-1)*nbCellsX*nbCellsY),offZ1(k*nbCellsX*nbCellsY);
+      for(int j=0;j<nbNodesY;j++)
+        {
+          bool factYZ(factZ && (j!=0 && j!=nbNodesY-1));
+          int off00((j-1)*nbCellsX+offZ0),off01(j*nbCellsX+offZ0),off10((j-1)*nbCellsX+offZ1),off11(j*nbCellsX+offZ1);
+          for(int i=0;i<nbNodesX;i++,rni++)
+            {
+              int fact(factYZ && (i!=0 && i!=nbNodesX-1));
+              if(fact)
+                {//most of points fall in this part of code
+                  rn[0]=off00+i-1; rn[1]=off00+i; rn[2]=off01+i-1; rn[3]=off01+i;
+                  rn[4]=off10+i-1; rn[5]=off10+i; rn[6]=off11+i-1; rn[7]=off11+i;
+                  rni[1]=rni[0]+8;
+                  rn+=8;
+                }
+              else
+                {
+                  int *rnRef(rn);
+                  if(k>=1 && j>=1 && i>=1)
+                    *rn++=off00+i-1;
+                  if(k>=1 && j>=1 && i<nbCellsX)
+                    *rn++=off00+i;
+                  if(k>=1 && j<nbCellsY && i>=1)
+                    *rn++=off01+i-1;
+                  if(k>=1 && j<nbCellsY && i<nbCellsX)
+                    *rn++=off01+i;
+                  //
+                  if(k<nbCellsZ && j>=1 && i>=1)
+                    *rn++=off10+i-1;
+                  if(k<nbCellsZ && j>=1 && i<nbCellsX)
+                    *rn++=off10+i;
+                  if(k<nbCellsZ && j<nbCellsY && i>=1)
+                    *rn++=off11+i-1;
+                  if(k<nbCellsZ && j<nbCellsY && i<nbCellsX)
+                    *rn++=off11+i;
+                  rni[1]=rni[0]+(int)(std::distance(rnRef,rn));
+                }
+            }
+        }
+    }
+}
+
 /*!
  * \return DataArrayInt * - newly allocated instance of nodal connectivity compatible for MEDCoupling1SGTMesh instance
  */
index e17412345ec7dd9437e6df22cb2befedcad41cd8..70c12d7b9d0fb181c90623ccc4538b2a835b74d7 100644 (file)
@@ -54,6 +54,7 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT MEDCouplingMesh *buildPartAndReduceNodes(const int *start, const int *end, DataArrayInt*& arr) const;
     MEDCOUPLING_EXPORT DataArrayInt *simplexize(int policy);
     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildOrthogonalField() const;
+    MEDCOUPLING_EXPORT void getReverseNodalConnectivity(DataArrayInt *revNodal, DataArrayInt *revNodalIndx) const;
     //some useful methods
     MEDCOUPLING_EXPORT int getCellIdFromPos(int i, int j, int k) const;
     MEDCOUPLING_EXPORT int getNodeIdFromPos(int i, int j, int k) const;
@@ -67,6 +68,9 @@ namespace ParaMEDMEM
     MEDCOUPLING_EXPORT static DataArrayInt *BuildExplicitIdsFrom(const std::vector<int>& st, const std::vector< std::pair<int,int> >& partCompactFormat);
     MEDCOUPLING_EXPORT static DataArrayInt *Build1GTNodalConnectivity(const int *nodeStBg, const int *nodeStEnd);
   private:
+    static void GetReverseNodalConnectivity1(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx);
+    static void GetReverseNodalConnectivity2(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx);
+    static void GetReverseNodalConnectivity3(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx);
     static DataArrayInt *Build1GTNodalConnectivity1D(const int *nodeStBg);
     static DataArrayInt *Build1GTNodalConnectivity2D(const int *nodeStBg);
     static DataArrayInt *Build1GTNodalConnectivity3D(const int *nodeStBg);
index f9337b2b3f72ec6f46608c0c085c09d1b1ec07e1..2acf8e0dc2e7b8c90e917b04cce7cf5bfffce66c 100644 (file)
@@ -14045,6 +14045,90 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetLocsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.6666666666666667,0.16666666666666666,0.16666666666666666,0.6666666666666667]),1e-12))
         pass
 
+    def testSwigReverseNodalConnOnStructuredMesh(self):
+        # 1D - standard
+        c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota()
+        c.setCoordsAt(0,arr)
+        rn,rni=c.getReverseNodalConnectivity()
+        rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+        self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+        self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+        self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+        # 1D - limit
+        c=MEDCouplingCMesh() ; arr=DataArrayDouble(1) ; arr.iota()
+        c.setCoordsAt(0,arr)
+        rn,rni=c.getReverseNodalConnectivity()
+        rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+        self.assertTrue(rn.isEqual(DataArrayInt([])))
+        self.assertTrue(rni.isEqual(DataArrayInt([0,0])))
+        self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+        # 1D - limit
+        c=MEDCouplingCMesh() ; arr=DataArrayDouble(0) ; arr.iota()
+        c.setCoordsAt(0,arr)
+        rn,rni=c.getReverseNodalConnectivity()
+        rn.isEqual(DataArrayInt([]))
+        rni.isEqual(DataArrayInt([0]))
+        # 2D - standard
+        c=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() ; arr2=DataArrayDouble(4) ; arr.iota()
+        c.setCoords(arr,arr2)
+        rn,rni=c.getReverseNodalConnectivity()
+        rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+        self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,0,4,0,1,4,5,1,2,5,6,2,3,6,7,3,7,4,8,4,5,8,9,5,6,9,10,6,7,10,11,7,11,8,8,9,9,10,10,11,11])))
+        self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,8,10,14,18,22,24,26,30,34,38,40,41,43,45,47,48])))
+        self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+        # 2D - limit
+        c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
+        c.setCoords(arr,arr2)
+        rn,rni=c.getReverseNodalConnectivity()
+        self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+        self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+        # 2D - limit
+        c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
+        c.setCoords(arr2,arr)
+        rn,rni=c.getReverseNodalConnectivity()
+        self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+        self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+        # 3D - standard
+        c=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(3) ; arr1.iota() ; arr2=DataArrayDouble(4) ; arr2.iota()
+        c.setCoords(arr0,arr1,arr2)
+        rn,rni=c.getReverseNodalConnectivity()
+        self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,0,4,0,1,4,5,1,2,5,6,2,3,6,7,3,7,4,4,5,5,6,6,7,7,0,8,0,1,8,9,1,2,9,10,2,3,10,11,3,11,0,4,8,12,0,1,4,5,8,9,12,13,1,2,5,6,9,10,13,14,2,3,6,7,10,11,14,15,3,7,11,15,4,12,4,5,12,13,5,6,13,14,6,7,14,15,7,15,8,16,8,9,16,17,9,10,17,18,10,11,18,19,11,19,8,12,16,20,8,9,12,13,16,17,20,21,9,10,13,14,17,18,21,22,10,11,14,15,18,19,22,23,11,15,19,23,12,20,12,13,20,21,13,14,21,22,14,15,22,23,15,23,16,16,17,17,18,18,19,19,16,20,16,17,20,21,17,18,21,22,18,19,22,23,19,23,20,20,21,21,22,22,23,23])))
+        self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,8,10,14,18,22,24,25,27,29,31,32,34,38,42,46,48,52,60,68,76,80,82,86,90,94,96,98,102,106,110,112,116,124,132,140,144,146,150,154,158,160,161,163,165,167,168,170,174,178,182,184,185,187,189,191,192])))
+        rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+        self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+        pass
+
+    def testSwig2CellToNodeDiscretization1(self):
+        m=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(4) ; arr1.iota() ; m.setCoords(arr0,arr1)
+        f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setTime(1.1,5,6)
+        arr=DataArrayDouble(12) ; arr.iota()
+        arr=DataArrayDouble.Meld(arr,arr+100.) ; arr.setInfoOnComponents(["aaa","bbb"])
+        f.setArray(arr)
+        f.checkCoherency()
+        #
+        ref=DataArrayDouble([0.,0.5,1.5,2.5,3.,2.,2.5,3.5,4.5,5.,6.,6.5,7.5,8.5,9.,8.,8.5,9.5,10.5,11.])
+        ref=DataArrayDouble.Meld(ref,ref+100.) ; ref.setInfoOnComponents(["aaa","bbb"])
+        f2=f.cellToNodeDiscretization()
+        f2.checkCoherency()
+        self.assertEqual(f2.getTime()[1:],[5,6])
+        self.assertAlmostEqual(f2.getTime()[0],1.1,15)
+        self.assertEqual(f2.getMesh().getHiddenCppPointer(),m.getHiddenCppPointer())
+        self.assertTrue(f2.getArray().isEqual(ref,1e-12))
+        rn,rni=m.getReverseNodalConnectivity()
+        rni2=(rni.deltaShiftIndex()).convertToDblArr()
+        arr2=(f.getArray()[rn]).accumulatePerChunck(rni)/rni2
+        self.assertTrue(f2.getArray().isEqual(arr2,1e-12))
+        del f2
+        #
+        u=m.buildUnstructured() ; f.setMesh(u) ; del m
+        f3=f.cellToNodeDiscretization()
+        f3.checkCoherency()
+        self.assertEqual(f3.getTime()[1:],[5,6])
+        self.assertAlmostEqual(f3.getTime()[0],1.1,15)
+        self.assertEqual(f3.getMesh().getHiddenCppPointer(),u.getHiddenCppPointer())
+        self.assertTrue(f3.getArray().isEqual(ref,1e-12))
+        pass
+
     def setUp(self):
         pass
     pass
index 9845712543dc131491904492896d70440473d09d..adf980fe1427a347c50828db58682737dac4b88c 100644 (file)
@@ -183,6 +183,7 @@ using namespace INTERP_KERNEL;
 %newobject ParaMEDMEM::MEDCouplingFieldDouble::deepCpy;
 %newobject ParaMEDMEM::MEDCouplingFieldDouble::buildNewTimeReprFromThis;
 %newobject ParaMEDMEM::MEDCouplingFieldDouble::nodeToCellDiscretization;
+%newobject ParaMEDMEM::MEDCouplingFieldDouble::cellToNodeDiscretization;
 %newobject ParaMEDMEM::MEDCouplingFieldDouble::getValueOnMulti;
 %newobject ParaMEDMEM::MEDCouplingFieldTemplate::New;
 %newobject ParaMEDMEM::MEDCouplingMesh::deepCpy;
@@ -554,6 +555,17 @@ namespace ParaMEDMEM
            return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 );
          }
          
+         virtual PyObject *getReverseNodalConnectivity() const throw(INTERP_KERNEL::Exception)
+         {
+           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d0=DataArrayInt::New();
+           MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d1=DataArrayInt::New();
+           self->getReverseNodalConnectivity(d0,d1);
+           PyObject *ret=PyTuple_New(2);
+           PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+           PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+           return ret;
+         }
+         
          void renumberCells(PyObject *li, bool check=true) throw(INTERP_KERNEL::Exception)
          {
            int sw,sz(-1);
@@ -1172,17 +1184,6 @@ namespace ParaMEDMEM
                }
            }
 
-           virtual PyObject *getReverseNodalConnectivity() const throw(INTERP_KERNEL::Exception)
-           {
-             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d0=DataArrayInt::New();
-             MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d1=DataArrayInt::New();
-             self->getReverseNodalConnectivity(d0,d1);
-             PyObject *ret=PyTuple_New(2);
-             PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
-             PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
-             return ret;
-           }
-
            virtual PyObject *findCommonCells(int compType, int startCellId=0) const throw(INTERP_KERNEL::Exception)
            {
              DataArrayInt *v0=0,*v1=0;
@@ -3121,6 +3122,7 @@ namespace ParaMEDMEM
     MEDCouplingFieldDouble *deepCpy() const;
     MEDCouplingFieldDouble *buildNewTimeReprFromThis(TypeOfTimeDiscretization td, bool deepCpy) const throw(INTERP_KERNEL::Exception);
     MEDCouplingFieldDouble *nodeToCellDiscretization() const throw(INTERP_KERNEL::Exception);
+    MEDCouplingFieldDouble *cellToNodeDiscretization() const throw(INTERP_KERNEL::Exception);
     TypeOfTimeDiscretization getTimeDiscretization() const throw(INTERP_KERNEL::Exception);
     double getIJ(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception);
     double getIJK(int cellId, int nodeIdInCell, int compoId) const throw(INTERP_KERNEL::Exception);