convertToPolyTypes(cellIds);
}
+/*!
+ * This method expects that 'this' has a spacedim equal to 3 and a mesh dimension equal to 3 too, if not an exception will be thrown.
+ * This method work only on cells with type NORM_POLYHED, all other cells with different type, are remains unchanged.
+. For such polyhedra, they are expected to have only 2 faces, and each face should
+ * have the same number of nodes. The first face is expected to be right oriented because all faces of this polyhedron will be deduced.
+ * When called 'this' is an invalid mesh on MED sense. This method will correct that for polyhedra.
+ * In case of presence of polyhedron that has not the extruded aspect (2 faces with the same number of nodes) an exception is thrown and 'this'
+ * remains unchanged.
+ * This method is usefull only for users that wants to build extruded unstructured mesh.
+ * This method is a convenient one that avoids boring polyhedra setting during insertNextCell process.
+ * In case of success, 'this' has be corrected contains the same number of cells and is valid in MED sense.
+ */
+void MEDCouplingUMesh::convertExtrudedPolyhedra() throw(INTERP_KERNEL::Exception)
+{
+ checkFullyDefined();
+ if(getMeshDimension()!=3 || getSpaceDimension()!=3)
+ throw INTERP_KERNEL::Exception("MEDCouplingUMesh::convertExtrudedPolyhedra works on umeshes with meshdim equal to 3 and spaceDim equal to 3 too!");
+ int nbOfCells=getNumberOfCells();
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newCi=DataArrayInt::New();
+ newCi->alloc(nbOfCells+1,1);
+ int *newci=newCi->getPointer();
+ const int *ci=_nodal_connec_index->getConstPointer();
+ const int *c=_nodal_connec->getConstPointer();
+ newci[0]=0;
+ for(int i=0;i<nbOfCells;i++)
+ {
+ INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)c[ci[i]];
+ if(type==INTERP_KERNEL::NORM_POLYHED)
+ {
+ if(std::count(c+ci[i]+1,c+ci[i+1],-1)!=1)
+ {
+ std::ostringstream oss; oss << "MEDCouplingUMesh::convertExtrudedPolyhedra : cell # " << i << " is a polhedron BUT it has NOT exactly 2 faces !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ const int *sp=std::find(c+ci[i]+1,c+ci[i+1],-1);
+ int n1=std::distance(c+ci[i]+1,sp);
+ int n2=std::distance(sp+1,c+ci[i+1]);
+ if(n1!=n2)
+ {
+ std::ostringstream oss; oss << "MEDCouplingUMesh::convertExtrudedPolyhedra : cell # " << i << " is a polhedron with 2 faces but there is a mismatch of number of nodes in faces !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ newci[i+1]=7*n1+2+newci[i];//6*n1 (nodal length) + n1+2 (number of faces) - 1 (number of '-1' separator is equal to number of faces -1) + 1 (for cell type)
+ }
+ else
+ newci[i+1]=(ci[i+1]-ci[i])+newci[i];
+ }
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newC=DataArrayInt::New();
+ newC->alloc(newci[nbOfCells],1);
+ int *newc=newC->getPointer();
+ for(int i=0;i<nbOfCells;i++)
+ {
+ INTERP_KERNEL::NormalizedCellType type=(INTERP_KERNEL::NormalizedCellType)c[ci[i]];
+ if(type==INTERP_KERNEL::NORM_POLYHED)
+ {
+ const int *sp=std::find(c+ci[i]+1,c+ci[i+1],-1);
+ int n1=std::distance(c+ci[i]+1,sp);
+ newc=std::copy(c+ci[i],sp+1,newc);
+ for(int j=0;j<n1;j++)
+ {
+ newc[j]=c[ci[i]+2+n1+(n1-j)%n1];
+ newc[n1+5*j]=-1;
+ newc[n1+5*j+1]=c[ci[i]+1+j];
+ newc[n1+5*j+2]=c[ci[i]+1+(j+1)%n1];
+ newc[n1+5*j+3]=c[ci[i]+1+(j+1)%n1+n1+1];
+ newc[n1+5*j+4]=c[ci[i]+1+j+n1+1];
+ }
+ newc+=n1*6;
+ }
+ else
+ newc=std::copy(c+ci[i],c+ci[i+1],newc);
+ }
+ _nodal_connec_index->decrRef(); _nodal_connec_index=newCi;
+ _nodal_connec->decrRef(); _nodal_connec=newC;
+ newC->incrRef(); newCi->incrRef();
+}
+
/*!
* This method is the opposite of ParaMEDMEM::MEDCouplingUMesh::convertToPolyTypes method.
* The aim is to take all polygons or polyhedrons cell and to try to traduce them into classical cells.
MEDCOUPLING_EXPORT bool areCellsFrom2MeshEqual(const MEDCouplingUMesh *other, int cellId, double prec) const;
MEDCOUPLING_EXPORT void convertToPolyTypes(const std::vector<int>& cellIdsToConvert);
MEDCOUPLING_EXPORT void convertAllToPoly();
+ MEDCOUPLING_EXPORT void convertExtrudedPolyhedra() throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT void unPolyze();
MEDCOUPLING_EXPORT DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT DataArrayInt *zipConnectivityTraducer(int compType) throw(INTERP_KERNEL::Exception);
CPPUNIT_TEST( testNorm2_1 );
CPPUNIT_TEST( testNormMax1 );
CPPUNIT_TEST( testFindAndCorrectBadOriented3DExtrudedCells1 );
+ CPPUNIT_TEST( testConvertExtrudedPolyhedra1 );
//MEDCouplingBasicsTestInterp.cxx
CPPUNIT_TEST( test2DInterpP0P0_1 );
CPPUNIT_TEST( test2DInterpP0P0PL_1 );
void testNorm2_1();
void testNormMax1();
void testFindAndCorrectBadOriented3DExtrudedCells1();
+ void testConvertExtrudedPolyhedra1();
//MEDCouplingBasicsTestInterp.cxx
void test2DInterpP0P0_1();
void test2DInterpP0P0PL_1();
//
m->decrRef();
}
+
+void MEDCouplingBasicsTest::testConvertExtrudedPolyhedra1()
+{
+ const int conn[75]={1,2,3,4, 5,6,7,8,9,10,11,12, 13,14,15,16, 17,18,19,-1,20,21,22, 23,24,25,26,27,28, 29,30,31,32,33,-1,34,35,36,37,38, 39,40,41,42,43,44,45,46, 47,48,49,50,51,52,53,54,55,56,57,58, 59,60,61,62,63,64,65,-1,66,67,68,69,70,71,72};
+ MEDCouplingUMesh *m=MEDCouplingUMesh::New("Example",3);
+ DataArrayDouble *coo=DataArrayDouble::New();
+ coo->alloc(73,3);
+ coo->rearrange(1); coo->iota(0); coo->rearrange(3);
+ m->setCoords(coo);
+ coo->decrRef();
+ m->allocateCells(9);
+ m->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn);
+ m->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+4);
+ m->insertNextCell(INTERP_KERNEL::NORM_TETRA4,4,conn+12);
+ m->insertNextCell(INTERP_KERNEL::NORM_POLYHED,7,conn+16);
+ m->insertNextCell(INTERP_KERNEL::NORM_PENTA6,6,conn+23);
+ m->insertNextCell(INTERP_KERNEL::NORM_POLYHED,11,conn+29);
+ m->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,conn+40);
+ m->insertNextCell(INTERP_KERNEL::NORM_HEXGP12,12,conn+48);
+ m->insertNextCell(INTERP_KERNEL::NORM_POLYHED,15,conn+60);
+ m->finishInsertingCells();
+ //
+ m->convertExtrudedPolyhedra();
+ DataArrayInt *da=m->getNodalConnectivity();
+ DataArrayInt *dai=m->getNodalConnectivityIndex();
+ CPPUNIT_ASSERT_EQUAL(10,dai->getNbOfElems());
+ CPPUNIT_ASSERT_EQUAL(159,da->getNbOfElems());
+ //
+ const int expected1[159]={14, 1, 2, 3, 4,
+ 18, 5, 6, 7, 8, 9, 10, 11, 12,
+ 14, 13, 14, 15, 16,
+ 31, 17, 18, 19, -1, 20, 22, 21, -1, 17, 18, 21, 20, -1, 18, 19, 22, 21, -1, 19, 17, 20,
+ 22,
+ 16, 23, 24, 25, 26, 27, 28,
+ 31, 29, 30, 31, 32, 33, -1, 34, 38, 37, 36, 35, -1, 29, 30, 35, 34, -1, 30, 31, 36, 35, -1, 31, 32, 37, 36, -1, 32, 33, 38, 37,
+ -1, 33, 29, 34, 38,
+ 18, 39, 40, 41, 42, 43, 44, 45, 46,
+ 22, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
+ 31, 59, 60, 61, 62, 63, 64, 65, -1, 66, 72, 71, 70, 69, 68, 67, -1, 59, 60, 67, 66, -1, 60, 61, 68, 67, -1, 61, 62, 69, 68, -1, 62, 63, 70, 69, -1, 63, 64, 71, 70, -1, 64, 65, 72, 71, -1, 65, 59, 66, 72};
+ const int expected2[10]={0,5,14,19,42,49,86,95,108,159};
+ CPPUNIT_ASSERT(std::equal(expected1,expected1+159,da->getConstPointer()));
+ CPPUNIT_ASSERT(std::equal(expected2,expected2+10,dai->getConstPointer()));
+ m->checkCoherency2();
+ //
+ m->decrRef();
+}
}
void convertToPolyTypes(const std::vector<int>& cellIdsToConvert) throw(INTERP_KERNEL::Exception);
void convertAllToPoly();
+ void convertExtrudedPolyhedra() throw(INTERP_KERNEL::Exception);
void unPolyze() throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *buildExtrudedMesh(const MEDCouplingUMesh *mesh1D, int policy) throw(INTERP_KERNEL::Exception);
};
self.assertEqual(connExp,m.getNodalConnectivity().getValues());
#
pass
+
+ def testConvertExtrudedPolyhedra1(self):
+ conn=[1,2,3,4, 5,6,7,8,9,10,11,12, 13,14,15,16, 17,18,19,-1,20,21,22, 23,24,25,26,27,28, 29,30,31,32,33,-1,34,35,36,37,38, 39,40,41,42,43,44,45,46, 47,48,49,50,51,52,53,54,55,56,57,58, 59,60,61,62,63,64,65,-1,66,67,68,69,70,71,72]
+ m=MEDCouplingUMesh.New("Example",3);
+ coo=DataArrayDouble.New();
+ coo.alloc(73,3);
+ coo.rearrange(1); coo.iota(0); coo.rearrange(3);
+ m.setCoords(coo);
+ m.allocateCells(9);
+ m.insertNextCell(NORM_TETRA4,4,conn[0:4])
+ m.insertNextCell(NORM_HEXA8,8,conn[4:12])
+ m.insertNextCell(NORM_TETRA4,4,conn[12:16])
+ m.insertNextCell(NORM_POLYHED,7,conn[16:23])
+ m.insertNextCell(NORM_PENTA6,6,conn[23:29])
+ m.insertNextCell(NORM_POLYHED,11,conn[29:40])
+ m.insertNextCell(NORM_HEXA8,8,conn[40:48])
+ m.insertNextCell(NORM_HEXGP12,12,conn[48:60])
+ m.insertNextCell(NORM_POLYHED,15,conn[60:75])
+ m.finishInsertingCells();
+ #
+ m.convertExtrudedPolyhedra();
+ da=m.getNodalConnectivity();
+ dai=m.getNodalConnectivityIndex();
+ self.assertEqual(10,dai.getNbOfElems());
+ self.assertEqual(159,da.getNbOfElems());
+ #
+ expected1=[14, 1, 2, 3, 4,
+ 18, 5, 6, 7, 8, 9, 10, 11, 12,
+ 14, 13, 14, 15, 16,
+ 31, 17, 18, 19, -1, 20, 22, 21, -1, 17, 18, 21, 20, -1, 18, 19, 22, 21, -1, 19, 17, 20, 22,
+ 16, 23, 24, 25, 26, 27, 28,
+ 31, 29, 30, 31, 32, 33, -1, 34, 38, 37, 36, 35, -1, 29, 30, 35, 34, -1, 30, 31, 36, 35, -1, 31, 32, 37, 36, -1, 32, 33, 38, 37, -1, 33, 29, 34, 38,
+ 18, 39, 40, 41, 42, 43, 44, 45, 46,
+ 22, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
+ 31, 59, 60, 61, 62, 63, 64, 65, -1, 66, 72, 71, 70, 69, 68, 67, -1, 59, 60, 67, 66, -1, 60, 61, 68, 67, -1, 61, 62, 69, 68, -1, 62, 63, 70, 69, -1, 63, 64, 71, 70, -1, 64, 65, 72, 71, -1, 65, 59, 66, 72];
+ expected2=[0,5,14,19,42,49,86,95,108,159]
+ self.assertEqual(expected1,da.getValues());
+ self.assertEqual(expected2,dai.getValues());
+ m.checkCoherency2()
+ pass
def setUp(self):
pass