return (INTERP_KERNEL::NormalizedCellType) pt[ptI[cellId]];
}
+/*!
+ * This method returns a newly allocated array containing cell ids (ascendingly sorted) whose geometric type are equal to type.
+ * This method throws an INTERP_KERNEL::Exception if meshdimension of \b this is not equal to those of \b type.
+ * The coordinates array is not considered here.
+ *
+ * \param [in] type the geometric type
+ * \return the
+ */
+DataArrayInt *MEDCouplingUMesh::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
+{
+
+ std::vector<int> v;
+ checkConnectivityFullyDefined();
+ int nbCells=getNumberOfCells();
+ int mdim=getMeshDimension();
+ const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type);
+ if(mdim!=(int)cm.getDimension())
+ throw INTERP_KERNEL::Exception("MEDCouplingUMesh::giveCellsWithType : Mismatch between mesh dimension and dimension of the cell !");
+ const int *ptI=_nodal_connec_index->getConstPointer();
+ const int *pt=_nodal_connec->getConstPointer();
+ for(int i=0;i<nbCells;i++)
+ {
+ if((INTERP_KERNEL::NormalizedCellType)pt[ptI[i]]==type)
+ v.push_back(i);
+ }
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc((int)v.size(),1);
+ std::copy(v.begin(),v.end(),ret->getPointer());
+ ret->incrRef();
+ return ret;
+}
+
/*!
* Returns nb of cells having the geometric type 'type'.
*/
MEDCOUPLING_EXPORT DataArrayInt *getNodalConnectivity() { return _nodal_connec; }
MEDCOUPLING_EXPORT DataArrayInt *getNodalConnectivityIndex() { return _nodal_connec_index; }
MEDCOUPLING_EXPORT INTERP_KERNEL::NormalizedCellType getTypeOfCell(int cellId) const;
+ MEDCOUPLING_EXPORT DataArrayInt *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception);
MEDCOUPLING_EXPORT int getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const;
MEDCOUPLING_EXPORT void getNodeIdsOfCell(int cellId, std::vector<int>& conn) const;
MEDCOUPLING_EXPORT DataArrayInt *getCellIdsFullyIncludedInNodeIds(const int *partBg, const int *partEnd) const;
ard2->decrRef();
ard->decrRef();
}
+
+void MEDCouplingBasicsTest5::testPartitionBySpreadZone1()
+{
+ MEDCouplingUMesh *m=build2DTargetMesh_1();
+ const int part0[3]={2,3,4};
+ const int part1[2]={0,1};
+ MEDCouplingUMesh *m1=static_cast<MEDCouplingUMesh *>(m->buildPartOfMySelf(part0,part0+3));
+ MEDCouplingUMesh *m2=static_cast<MEDCouplingUMesh *>(m->buildPartOfMySelf(part1,part1+2));
+ std::vector<const MEDCouplingUMesh *> v(3); v[0]=m; v[1]=m1; v[2]=m2;
+ MEDCouplingUMesh *m4=MEDCouplingUMesh::MergeUMeshes(v);
+ const int renum[10]={5,2,9,6,4,7,0,1,3,8};
+ m4->renumberCells(renum);
+ //
+ std::vector<DataArrayInt *> v2=m4->partitionBySpreadZone();
+ CPPUNIT_ASSERT_EQUAL(3,(int)v2.size());
+ const int expected0[3]={0,1,7};
+ const int expected1[5]={2,4,5,6,9};
+ const int expected2[2]={3,8};
+ CPPUNIT_ASSERT_EQUAL(3,v2[0]->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,v2[0]->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(5,v2[1]->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,v2[1]->getNumberOfComponents());
+ CPPUNIT_ASSERT_EQUAL(2,v2[2]->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,v2[2]->getNumberOfComponents());
+ //
+ CPPUNIT_ASSERT(std::equal(expected0,expected0+3,v2[0]->getConstPointer()));
+ CPPUNIT_ASSERT(std::equal(expected1,expected1+5,v2[1]->getConstPointer()));
+ CPPUNIT_ASSERT(std::equal(expected2,expected2+2,v2[2]->getConstPointer()));
+ v2[0]->decrRef();
+ v2[1]->decrRef();
+ v2[2]->decrRef();
+ //
+ MEDCouplingUMesh *m5=m4->buildSpreadZonesWithPoly();
+ CPPUNIT_ASSERT_EQUAL(3,m5->getNumberOfCells());
+ CPPUNIT_ASSERT(m5->getCoords()==m4->getCoords());
+ const int expected3[23]={5,15,16,17,14,11,13,12,5,2,1,0,3,6,7,8,5,5,18,21,22,20,19};
+ const int expected4[4]={0,8,17,23};
+ CPPUNIT_ASSERT_EQUAL(23,m5->getNodalConnectivity()->getNumberOfTuples());
+ CPPUNIT_ASSERT(std::equal(expected3,expected3+23,m5->getNodalConnectivity()->getConstPointer()));
+ CPPUNIT_ASSERT_EQUAL(4,m5->getNodalConnectivityIndex()->getNumberOfTuples());
+ CPPUNIT_ASSERT(std::equal(expected4,expected4+4,m5->getNodalConnectivityIndex()->getConstPointer()));
+ //
+ m->decrRef();
+ m1->decrRef();
+ m2->decrRef();
+ m4->decrRef();
+ m5->decrRef();
+}
+
+void MEDCouplingBasicsTest5::testGiveCellsWithType1()
+{
+ const int expected0[2]={1,2};
+ const int expected1[3]={0,3,4};
+ MEDCouplingUMesh *m=build2DTargetMesh_1();
+ DataArrayInt *da=m->giveCellsWithType(INTERP_KERNEL::NORM_TRI3);
+ CPPUNIT_ASSERT_EQUAL(2,da->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::equal(expected0,expected0+2,da->getConstPointer()));
+ da->decrRef();
+ //
+ da=m->giveCellsWithType(INTERP_KERNEL::NORM_QUAD4);
+ CPPUNIT_ASSERT_EQUAL(3,da->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
+ CPPUNIT_ASSERT(std::equal(expected1,expected1+3,da->getConstPointer()));
+ da->decrRef();
+ //
+ da=m->giveCellsWithType(INTERP_KERNEL::NORM_TRI6);
+ CPPUNIT_ASSERT_EQUAL(0,da->getNumberOfTuples());
+ CPPUNIT_ASSERT_EQUAL(1,da->getNumberOfComponents());
+ da->decrRef();
+ //
+ CPPUNIT_ASSERT_THROW(m->giveCellsWithType(INTERP_KERNEL::NORM_SEG2),INTERP_KERNEL::Exception);
+ CPPUNIT_ASSERT_THROW(m->giveCellsWithType(INTERP_KERNEL::NORM_HEXA8),INTERP_KERNEL::Exception);
+ //
+ m->decrRef();
+}
CPPUNIT_TEST( testZipConnectivityPol1 );
CPPUNIT_TEST( testConvexEnvelop2D1 );
CPPUNIT_TEST( testDataArraySort1 );
+ CPPUNIT_TEST( testPartitionBySpreadZone1 );
+ CPPUNIT_TEST( testGiveCellsWithType1 );
CPPUNIT_TEST_SUITE_END();
public:
void testUMeshTessellate2D1();
void testZipConnectivityPol1();
void testConvexEnvelop2D1();
void testDataArraySort1();
+ void testPartitionBySpreadZone1();
+ void testGiveCellsWithType1();
};
}
%newobject ParaMEDMEM::MEDCouplingUMesh::__iter__;
%newobject ParaMEDMEM::MEDCouplingUMesh::__getitem__;
%newobject ParaMEDMEM::MEDCouplingUMesh::cellsByType;
+%newobject ParaMEDMEM::MEDCouplingUMesh::giveCellsWithType;
%newobject ParaMEDMEM::MEDCouplingUMesh::zipConnectivityTraducer;
%newobject ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity;
%newobject ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity2;
int getNumberOfNodesInCell(int cellId) const throw(INTERP_KERNEL::Exception);
int getMeshLength() const throw(INTERP_KERNEL::Exception);
void computeTypes() throw(INTERP_KERNEL::Exception);
+ DataArrayInt *giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception);
std::string reprConnectivityOfThis() const throw(INTERP_KERNEL::Exception);
MEDCouplingUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception);
//tools
self.assertAlmostEqual(expected4[i],ard2.getIJ(i,0),12)
pass
pass
+
+ def testPartitionBySpreadZone1(self):
+ m=MEDCouplingDataForTest.build2DTargetMesh_1();
+ m4=MEDCouplingUMesh.MergeUMeshes([m,m[2:],m[0:2]]);
+ m4.renumberCells([5,2,9,6,4,7,0,1,3,8]);
+ #
+ v2=m4.partitionBySpreadZone();
+ self.assertTrue(3,len(v2));
+ self.assertTrue(v2[0].isEqual(DataArrayInt.New([0,1,7])))
+ self.assertTrue(v2[1].isEqual(DataArrayInt.New([2,4,5,6,9])))
+ self.assertTrue(v2[2].isEqual(DataArrayInt.New([3,8])))
+ #
+ m5=m4.buildSpreadZonesWithPoly();
+ self.assertEqual(3,m5.getNumberOfCells());
+ self.assertTrue(m5.getCoords().getHiddenCppPointer()==m4.getCoords().getHiddenCppPointer());
+ self.assertEqual([5,15,16,17,14,11,13,12,5,2,1,0,3,6,7,8,5,5,18,21,22,20,19],m5.getNodalConnectivity().getValues())
+ self.assertEqual([0,8,17,23],m5.getNodalConnectivityIndex().getValues())
+ #
+ pass
+
+ def testGiveCellsWithType1(self):
+ expected0=[1,2]
+ expected1=[0,3,4]
+ m=MEDCouplingDataForTest.build2DTargetMesh_1();
+ da=m.giveCellsWithType(NORM_TRI3);
+ self.assertEqual(2,da.getNumberOfTuples());
+ self.assertEqual(1,da.getNumberOfComponents());
+ self.assertEqual(expected0,da.getValues())
+ #
+ da=m.giveCellsWithType(NORM_QUAD4);
+ self.assertEqual(3,da.getNumberOfTuples());
+ self.assertEqual(1,da.getNumberOfComponents());
+ self.assertEqual(expected1,da.getValues())
+ #
+ da=m.giveCellsWithType(NORM_TRI6);
+ self.assertEqual(0,da.getNumberOfTuples());
+ self.assertEqual(1,da.getNumberOfComponents());
+ #
+ self.assertRaises(InterpKernelException,m.giveCellsWithType,NORM_SEG2)
+ self.assertRaises(InterpKernelException,m.giveCellsWithType,NORM_HEXA8)
+ pass
def setUp(self):
pass