}
}
+/*!
+ * This method retrieves the number of entities (it can be cells or nodes) given a range in compact standard format
+ * used in methods like BuildExplicitIdsFrom,IsPartStructured.
+ *
+ * \sa BuildExplicitIdsFrom,IsPartStructured
+ */
+int MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt(const std::vector< std::pair<int,int> >& partCompactFormat)
+{
+ int ret(1);
+ bool isFetched(false);
+ std::size_t ii(0);
+ for(std::vector< std::pair<int,int> >::const_iterator it=partCompactFormat.begin();it!=partCompactFormat.end();it++,ii++)
+ {
+ int a((*it).first),b((*it).second);
+ if(a<0 || b<0 || b-a<0)
+ {
+ std::ostringstream oss; oss << "MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt : invalid input at dimension " << ii << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ if(b-a>0)
+ {
+ isFetched=true;
+ ret*=(b-a);
+ }
+ }
+ return isFetched?ret:0;
+}
+
DataArrayInt *MEDCouplingStructuredMesh::Build1GTNodalConnectivity1D(const int *nodeStBg)
{
int nbOfCells(*nodeStBg-1);
* This method states if given part ids [ \a startIds, \a stopIds) and a structure \a st returns if it can be considered as a structured dataset.
* If true is returned \a partCompactFormat will contain the information to build the corresponding part.
*
- * \sa MEDCouplingStructuredMesh::BuildExplicitIdsFrom
+ * \sa MEDCouplingStructuredMesh::BuildExplicitIdsFrom, MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt
*/
bool MEDCouplingStructuredMesh::IsPartStructured(const int *startIds, const int *stopIds, const std::vector<int>& st, std::vector< std::pair<int,int> >& partCompactFormat)
{
/*!
* This method builds the explicit entity array from the structure in \a st and the range in \a partCompactFormat.
- *If the range contains invalid values regarding sructure an exception will be thrown.
+ * If the range contains invalid values regarding sructure an exception will be thrown.
*
* \return DataArrayInt * - a new object.
- * \sa MEDCouplingStructuredMesh::IsPartStructured
+ * \sa MEDCouplingStructuredMesh::IsPartStructured, MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt
*/
DataArrayInt *MEDCouplingStructuredMesh::BuildExplicitIdsFrom(const std::vector<int>& st, const std::vector< std::pair<int,int> >& partCompactFormat)
{
MEDCOUPLING_EXPORT static DataArrayInt *BuildExplicitIdsFrom(const std::vector<int>& st, const std::vector< std::pair<int,int> >& partCompactFormat);
MEDCOUPLING_EXPORT static DataArrayInt *Build1GTNodalConnectivity(const int *nodeStBg, const int *nodeStEnd);
MEDCOUPLING_EXPORT static DataArrayInt *Build1GTNodalConnectivityOfSubLevelMesh(const int *nodeStBg, const int *nodeStEnd);
+ MEDCOUPLING_EXPORT static int DeduceNumberOfGivenRangeInCompactFrmt(const std::vector< std::pair<int,int> >& partCompactFormat);
private:
static int GetNumberOfCellsOfSubLevelMesh(const std::vector<int>& cgs, int mdim);
static void GetReverseNodalConnectivity1(const std::vector<int>& ngs, DataArrayInt *revNodal, DataArrayInt *revNodalIndx);
d20=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24])
a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,3)])
+ self.assertEqual(12,MEDCouplingStructuredMesh.DeduceNumberOfGivenRangeInCompactFrmt(b))
+ self.assertEqual(8,MEDCouplingStructuredMesh.DeduceNumberOfGivenRangeInCompactFrmt([(1,5),(1,3),(2,2)]))
+ self.assertEqual(0,MEDCouplingStructuredMesh.DeduceNumberOfGivenRangeInCompactFrmt([(5,5),(3,3),(2,2)]))
d20=DataArrayInt([1,2,3,4,12,11,13,14,21,22,23,24])
a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
self.assertTrue(not a)
return MEDCouplingStructuredMesh::BuildExplicitIdsFrom(tmp5,inp);
}
+ static int DeduceNumberOfGivenRangeInCompactFrmt(PyObject *part) throw(INTERP_KERNEL::Exception)
+ {
+ int tmpp1=-1,tmpp2=-1;
+ std::vector<int> tmp=fillArrayWithPyListInt2(part,tmpp1,tmpp2);
+ std::vector< std::pair<int,int> > inp;
+ if(tmpp2==2)
+ {
+ inp.resize(tmpp1);
+ for(int i=0;i<tmpp1;i++)
+ { inp[i].first=tmp[2*i]; inp[i].second=tmp[2*i+1]; }
+ }
+ else if(tmpp2==1)
+ {
+ if(tmpp1%2!=0)
+ throw INTERP_KERNEL::Exception("Wrap of MEDCouplingStructuredMesh.BuildExplicitIdsFrom : invalid input size ! Must be even size !");
+ inp.resize(tmpp1/2);
+ for(int i=0;i<tmpp1/2;i++)
+ { inp[i].first=tmp[2*i]; inp[i].second=tmp[2*i+1]; }
+ }
+ else
+ throw INTERP_KERNEL::Exception("Wrap of MEDCouplingStructuredMesh.BuildExplicitIdsFrom : invalid input size !");
+ return MEDCouplingStructuredMesh::DeduceNumberOfGivenRangeInCompactFrmt(inp);
+ }
+
static DataArrayInt *Build1GTNodalConnectivity(PyObject *li) throw(INTERP_KERNEL::Exception)
{
int szArr,sw,iTypppArr;