};
}
+/*!
+ * This method returns the number of cells of unstructured sub level mesh, without building it.
+ */
+int MEDCouplingStructuredMesh::getNumberOfCellsOfSubLevelMesh() const
+{
+ std::vector<int> cgs(getCellGridStructure());
+ return GetNumberOfCellsOfSubLevelMesh(cgs,getMeshDimension());
+}
+
/*!
* See MEDCouplingUMesh::getDistributionOfTypes for more information
*/
*/
MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const
{
- int meshDim=getMeshDimension();
+ int meshDim(getMeshDimension());
if(meshDim<0 || meshDim>3)
throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTUnstructured : meshdim must be in [1,2,3] !");
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(getCoordinatesAndOwner());
return ret.retn();
}
+/*!
+ * This method returns the unstructured mesh (having single geometric type) of the sub level mesh of \a this.
+ * This method is equivalent to computing MEDCouplingUMesh::buildDescendingConnectivity on the unstructurized \a this mesh.
+ *
+ * The caller is to delete the returned mesh using decrRef() as it is no more needed.
+ */
+MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTSubLevelMesh() const
+{
+ int meshDim(getMeshDimension());
+ if(meshDim<1 || meshDim>3)
+ throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::build1SGTSubLevelMesh : meshdim must be in [2,3] !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> coords(getCoordinatesAndOwner());
+ int ns[3];
+ getNodeGridStructure(ns);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(Build1GTNodalConnectivityOfSubLevelMesh(ns,ns+meshDim));
+ MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim-1)));
+ ret->setNodalConnectivity(conn); ret->setCoords(coords);
+ return ret.retn();
+}
+
/*!
* Creates a new unstructured mesh (MEDCouplingUMesh) from \a this structured one.
* \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
*/
DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity(const int *nodeStBg, const int *nodeStEnd)
{
- std::size_t dim=std::distance(nodeStBg,nodeStEnd);
+ std::size_t dim(std::distance(nodeStBg,nodeStEnd));
switch(dim)
{
case 0:
}
}
+DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh(const int *nodeStBg, const int *nodeStEnd)
+{
+ std::size_t dim(std::distance(nodeStBg,nodeStEnd));
+ switch(dim)
+ {
+ case 3:
+ return Build1GTNodalConnectivityOfSubLevelMesh3D(nodeStBg);
+ case 2:
+ return Build1GTNodalConnectivityOfSubLevelMesh2D(nodeStBg);
+ default:
+ throw INTERP_KERNEL::Exception("MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh: only dimension in [2,3] supported !");
+ }
+}
+
DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity1D(const int *nodeStBg)
{
int nbOfCells(*nodeStBg-1);
return conn.retn();
}
+DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh3D(const int *nodeStBg)
+{
+ std::vector<int> ngs(3);
+ int n0(nodeStBg[0]-1),n1(nodeStBg[1]-1),n2(nodeStBg[2]-1); ngs[0]=n0; ngs[1]=n1; ngs[2]=n2;
+ int off0(nodeStBg[0]),off1(nodeStBg[0]*nodeStBg[1]);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+ conn->alloc(4*GetNumberOfCellsOfSubLevelMesh(ngs,3));
+ int *cp(conn->getPointer()),pos(0);
+ //X
+ for(int i=0;i<nodeStBg[0];i++)
+ for(int j=0;j<n1;j++)
+ for(int k=0;k<n2;k++,cp+=4)
+ { cp[0]=k*off1+j*off0+i; cp[1]=(k+1)*off1+j*off0+i; cp[2]=(k+1)*off1+(j+1)*off0+i; cp[3]=k*off1+(j+1)*off0+i; }
+ //Y
+ for(int j=0;j<nodeStBg[1];j++)
+ for(int i=0;i<n0;i++)
+ for(int k=0;k<n2;k++,cp+=4)
+ { cp[0]=k*off1+j*off0+i; cp[1]=(k+1)*off1+j*off0+i; cp[2]=(k+1)*off1+j*off0+(i+1); cp[3]=k*off1+j*off0+(i+1); }
+ //Z
+ for(int k=0;k<nodeStBg[2];k++)
+ for(int i=0;i<n0;i++)
+ for(int j=0;j<n1;j++,cp+=4)
+ { cp[0]=k*off1+j*off0+i; cp[1]=k*off1+j*off0+(i+1); cp[2]=k*off1+(j+1)*off0+(i+1); cp[3]=k*off1+(j+1)*off0+i; }
+ return conn.retn();
+}
+
+DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivityOfSubLevelMesh2D(const int *nodeStBg)
+{
+ std::vector<int> ngs(2);
+ int n0(nodeStBg[0]-1),n1(nodeStBg[1]-1); ngs[0]=n0; ngs[1]=n1;
+ int off0(nodeStBg[0]);
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(DataArrayInt::New());
+ conn->alloc(2*GetNumberOfCellsOfSubLevelMesh(ngs,2));
+ int *cp(conn->getPointer()),pos(0);
+ //X
+ for(int i=0;i<nodeStBg[0];i++)
+ for(int j=0;j<n1;j++,cp+=2)
+ { cp[0]=j*off0+i; cp[1]=(j+1)*off0+i; }
+ //Y
+ for(int j=0;j<nodeStBg[1];j++)
+ for(int i=0;i<n0;i++,cp+=2)
+ { cp[0]=j*off0+i; cp[1]=j*off0+(i+1); }
+ return conn.retn();
+}
+
/*!
* Returns a cell id by its (i,j,k) index. The cell is located between the i-th and
* ( i + 1 )-th nodes along X axis etc.
}
return ret.retn();
}
+
+int MEDCouplingStructuredMesh::GetNumberOfCellsOfSubLevelMesh(const std::vector<int>& cgs, int mdim)
+{
+ int ret(0);
+ for(int i=0;i<mdim;i++)
+ {
+ int locRet(1);
+ for(int j=0;j<mdim;j++)
+ if(j!=i)
+ locRet*=cgs[j];
+ else
+ locRet*=cgs[j]+1;
+ ret+=locRet;
+ }
+ return ret;
+}
self.assertTrue(arrOfDisc2.isEqual(coo,1e-12))
pass
+ def testSwig2StructuredDesc1(self):
+ c=MEDCouplingCMesh()
+ arr0=DataArrayDouble(3) ; arr0.iota()
+ arr1=DataArrayDouble(4) ; arr1.iota()
+ arr2=DataArrayDouble(5) ; arr2.iota()
+ c.setCoords(arr0,arr1,arr2)
+ #
+ self.assertEqual(98,c.getNumberOfCellsOfSubLevelMesh())
+ m=c.build1SGTSubLevelMesh()
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([0,12,15,3,12,24,27,15,24,36,39,27,36,48,51,39,3,15,18,6,15,27,30,18,27,39,42,30,39,51,54,42,6,18,21,9,18,30,33,21,30,42,45,33,42,54,57,45,1,13,16,4,13,25,28,16,25,37,40,28,37,49,52,40,4,16,19,7,16,28,31,19,28,40,43,31,40,52,55,43,7,19,22,10,19,31,34,22,31,43,46,34,43,55,58,46,2,14,17,5,14,26,29,17,26,38,41,29,38,50,53,41,5,17,20,8,17,29,32,20,29,41,44,32,41,53,56,44,8,20,23,11,20,32,35,23,32,44,47,35,44,56,59,47,0,12,13,1,12,24,25,13,24,36,37,25,36,48,49,37,1,13,14,2,13,25,26,14,25,37,38,26,37,49,50,38,3,15,16,4,15,27,28,16,27,39,40,28,39,51,52,40,4,16,17,5,16,28,29,17,28,40,41,29,40,52,53,41,6,18,19,7,18,30,31,19,30,42,43,31,42,54,55,43,7,19,20,8,19,31,32,20,31,43,44,32,43,55,56,44,9,21,22,10,21,33,34,22,33,45,46,34,45,57,58,46,10,22,23,11,22,34,35,23,34,46,47,35,46,58,59,47,0,1,4,3,3,4,7,6,6,7,10,9,1,2,5,4,4,5,8,7,7,8,11,10,12,13,16,15,15,16,19,18,18,19,22,21,13,14,17,16,16,17,20,19,19,20,23,22,24,25,28,27,27,28,31,30,30,31,34,33,25,26,29,28,28,29,32,31,31,32,35,34,36,37,40,39,39,40,43,42,42,43,46,45,37,38,41,40,40,41,44,43,43,44,47,46,48,49,52,51,51,52,55,54,54,55,58,57,49,50,53,52,52,53,56,55,55,56,59,58])))
+ self.assertEqual(NORM_QUAD4,m.getCellModelEnum())
+ #
+ self.assertTrue(MEDCouplingStructuredMesh.Build1GTNodalConnectivityOfSubLevelMesh([3,7]).isEqual(DataArrayInt([0,3,3,6,6,9,9,12,12,15,15,18,1,4,4,7,7,10,10,13,13,16,16,19,2,5,5,8,8,11,11,14,14,17,17,20,0,1,1,2,3,4,4,5,6,7,7,8,9,10,10,11,12,13,13,14,15,16,16,17,18,19,19,20])))
+ pass
+
def setUp(self):
pass
pass