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
*/
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