From: ageay Date: Tue, 9 Aug 2011 12:03:20 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: V6_main_FINAL~994 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9fce1d3babf8aeafe1ec2bb2f38d297f56587548;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 8c064c361..79bc77431 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -668,6 +668,83 @@ void MEDCouplingUMesh::convertAllToPoly() 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 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 newC=DataArrayInt::New(); + newC->alloc(newci[nbOfCells],1); + int *newc=newC->getPointer(); + for(int i=0;idecrRef(); _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. diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index 893910a26..f8b30bfbe 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -86,6 +86,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool areCellsFrom2MeshEqual(const MEDCouplingUMesh *other, int cellId, double prec) const; MEDCOUPLING_EXPORT void convertToPolyTypes(const std::vector& 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); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx index d98bd584f..b41d28db3 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest.hxx @@ -232,6 +232,7 @@ namespace ParaMEDMEM CPPUNIT_TEST( testNorm2_1 ); CPPUNIT_TEST( testNormMax1 ); CPPUNIT_TEST( testFindAndCorrectBadOriented3DExtrudedCells1 ); + CPPUNIT_TEST( testConvertExtrudedPolyhedra1 ); //MEDCouplingBasicsTestInterp.cxx CPPUNIT_TEST( test2DInterpP0P0_1 ); CPPUNIT_TEST( test2DInterpP0P0PL_1 ); @@ -490,6 +491,7 @@ namespace ParaMEDMEM void testNorm2_1(); void testNormMax1(); void testFindAndCorrectBadOriented3DExtrudedCells1(); + void testConvertExtrudedPolyhedra1(); //MEDCouplingBasicsTestInterp.cxx void test2DInterpP0P0_1(); void test2DInterpP0P0PL_1(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index c8f0fc663..a2b2b6c54 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -1586,3 +1586,49 @@ void MEDCouplingBasicsTest::testFindAndCorrectBadOriented3DExtrudedCells1() // 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(); +} diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 92172c5b4..2dacbbbf1 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -1250,6 +1250,7 @@ namespace ParaMEDMEM } void convertToPolyTypes(const std::vector& 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); }; diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index d45ac3f49..86c7f2ebd 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -7649,6 +7649,46 @@ class MEDCouplingBasicsTest(unittest.TestCase): 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