* \ref cpp_mcdataarrayint_invertarrayn2o2o2n "Here is a C++ example".
*
* \ref py_mcdataarrayint_invertarrayn2o2o2n "Here is a Python example".
- * \sa invertArrayN2O2O2N
+ * \sa invertArrayN2O2O2N, giveN2OOptimized, MEDCouplingPointSet::renumberNodesInConn
* \endif
*/
MCAuto< MapKeyVal<int> > DataArrayInt32::invertArrayN2O2O2NOptimized() const
return ret;
}
+/*!
+ * Creates a map, whose contents are computed
+ * from values of \a this array, which is supposed to contain a renumbering map in
+ * "New to Old" mode. The result array contains a renumbering map in "New to Old" mode as C++ map for performance reasons.
+ *
+ * \sa invertArrayN2O2O2NOptimized, MEDCouplingPointSet::renumberNodesInConn
+ */
+MCAuto< MapKeyVal<int> > DataArrayInt32::giveN2OOptimized() const
+{
+ checkAllocated();
+ if(getNumberOfComponents()!=1)
+ throw INTERP_KERNEL::Exception("DataArrayInt32::giveN2OOptimized : single component expected !");
+ MCAuto< MapKeyVal<int> > ret(MapKeyVal<int>::New());
+ std::map<int,int>& m(ret->data());
+ const int *new2Old(begin());
+ std::size_t nbOfNewElems(this->getNumberOfTuples());
+ for(std::size_t i=0;i<nbOfNewElems;i++)
+ {
+ int v(new2Old[i]);
+ m[i]=v;
+ }
+ return ret;
+}
+
/*!
* Returns a new DataArrayInt containing a renumbering map in "Old to New" mode.
* This map, if applied to \a this array, would make it sorted. For example, if
ptsPosExp=DataArrayDouble([6.+a,3.+b,3.+a,6.+a,3.,3.+b,6.+b,3.+b,3.+b,7.,3.+b,3.+b,6.+a,6.+a,3.+a,6.+b,6.+a,3.+b,7.,6.+a,3.+b,6.+a,7.,3.+b,6.+a,3.+b,3.,6.+a,6.+a,3.],10,3)
self.assertTrue(m.getCoords()[ptsExpToBeModified].isEqual(ptsPosExp,1e-12))
pass
+
+ def testRenumberNodesInConnOpt(self):
+ m=MEDCouplingUMesh("mesh",2)
+ m.allocateCells()
+ m.insertNextCell(NORM_QUAD4,[10000,10002,10001,10003])
+ coo=DataArrayDouble([(0,0),(1,1),(1,0),(0,1)])
+ m.setCoords(coo)
+ m.checkConsistencyLight()
+ #
+ d=DataArrayInt([10000,10001,10002,10003])
+ myMap=d.invertArrayN2O2O2NOptimized()
+ myMap2=d.giveN2OOptimized()
+ m.checkConsistencyLight()
+ #
+ m.renumberNodesInConn(myMap) # <- test is here for UMesh
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([4,0,2,1,3])))
+ m.renumberNodesInConn(myMap2) # <- test is here for UMesh
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([4,10000,10002,10001,10003])))
+ #
+ m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4)
+ m.setNodalConnectivity(DataArrayInt([10000,10002,10001,10003]))
+ m.setCoords(coo)
+ m.checkConsistencyLight()
+ m.renumberNodesInConn(myMap) # <- test is here for 1SGTUMesh
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([0,2,1,3])))
+ #
+ m=MEDCoupling1DGTUMesh("mesh",NORM_POLYGON)
+ m.setCoords(coo)
+ m.setNodalConnectivity(DataArrayInt([10000,10002,10001,10003]),DataArrayInt([0,4]))
+ m.checkConsistencyLight()
+ m.renumberNodesInConn(myMap) # <- test is here for 1DGTUMesh
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([0,2,1,3])))
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4])))
+ pass
pass