From: ageay Date: Mon, 7 Jan 2013 10:18:05 +0000 (+0000) Subject: MEDFileUMesh::zipCoords X-Git-Tag: V6_main_FINAL~427 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=874e981656510334d632c284a46905fd73ce8331;p=tools%2Fmedcoupling.git MEDFileUMesh::zipCoords --- diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index c86288ff1..9502459d1 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1104,6 +1104,30 @@ DataArrayInt *MEDCouplingUMesh::computeFetchedNodeIds() const throw(INTERP_KERNE return ret; } +/*! + * \param [in,out] nodeIdsInUse an array of size typically equal to nbOfNodes. + * \sa MEDCouplingUMesh::getNodeIdsInUse + */ +void MEDCouplingUMesh::computeNodeIdsAlg(std::vector& nodeIdsInUse) const throw(INTERP_KERNEL::Exception) +{ + int nbOfNodes=(int)nodeIdsInUse.size(); + int nbOfCells=getNumberOfCells(); + const int *connIndex=_nodal_connec_index->getConstPointer(); + const int *conn=_nodal_connec->getConstPointer(); + for(int i=0;i=0) + { + if(conn[j]= nb of nodes an exception will be thrown. + * \sa MEDCouplingUMesh::computeNodeIdsAlg */ DataArrayInt *MEDCouplingUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception) { nbrOfNodesInUse=-1; int nbOfNodes=getNumberOfNodes(); - DataArrayInt *ret=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfNodes,1); int *traducer=ret->getPointer(); std::fill(traducer,traducer+nbOfNodes,-1); @@ -1127,10 +1153,18 @@ DataArrayInt *MEDCouplingUMesh::getNodeIdsInUse(int& nbrOfNodesInUse) const thro for(int i=0;i=0) - traducer[conn[j]]=1; + { + if(conn[j] partitionBySpreadZone() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *computeFetchedNodeIds() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *getNodeIdsInUse(int& nbrOfNodesInUse) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void computeNodeIdsAlg(std::vector& nodeIdsInUse) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *zipConnectivityTraducer(int compType, int startCellId=0) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 3ecacfe39..71306745f 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -2202,6 +2202,59 @@ bool MEDFileUMesh::unPolyze(std::vector& oldCode, std::vector& newCode return ret; } +struct MEDLoaderAccVisit1 +{ + MEDLoaderAccVisit1():_new_nb_of_nodes(0) { } + int operator()(bool val) { return val?_new_nb_of_nodes++:-1; } + int _new_nb_of_nodes; +}; + +/*! + * Array returned is the correspondance in \b old \b to \b new format. The returned array is newly created and should be dealt by the caller. + * The maximum value stored in returned array is the number of nodes of \a this minus 1 after call of this method. + * The size of returned array is the number of nodes of the old (previous to the call of this method) number of nodes. + * -1 values in returned array means that the corresponding old node is no more used. + * + * \return newly allocated array containing correspondance in \b old \b to \b new format. If all nodes in \a this are fetched NULL pointer is returned and nothing + * is modified in \a this. + * \throw If no coordinates are set in \a this or if there is in any available mesh in \a this a cell having a nodal connectivity containing a node id not in the range of + * set coordinates. + */ +DataArrayInt *MEDFileUMesh::zipCoords() throw(INTERP_KERNEL::Exception) +{ + const DataArrayDouble *coo=getCoords(); + if(!coo) + throw INTERP_KERNEL::Exception("MEDFileUMesh::zipCoords : no coordinates set in this !"); + int nbOfNodes=coo->getNumberOfTuples(); + std::vector nodeIdsInUse(nbOfNodes,false); + std::vector neLevs=getNonEmptyLevels(); + for(std::vector::const_iterator lev=neLevs.begin();lev!=neLevs.end();lev++) + { + MEDCouplingAutoRefCountObjectPtr m=getMeshAtLevel(*lev); + m->computeNodeIdsAlg(nodeIdsInUse); + } + int nbrOfNodesInUse=(int)std::count(nodeIdsInUse.begin(),nodeIdsInUse.end(),true); + if(nbrOfNodesInUse==nbOfNodes) + return 0; + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfNodes,1); + std::transform(nodeIdsInUse.begin(),nodeIdsInUse.end(),ret->getPointer(),MEDLoaderAccVisit1()); + MEDCouplingAutoRefCountObjectPtr ret2=ret->invertArrayO2N2N2OBis(nbrOfNodesInUse); + MEDCouplingAutoRefCountObjectPtr newCoords=coo->selectByTupleId(ret2->begin(),ret2->end()); + MEDCouplingAutoRefCountObjectPtr newFamCoords; + if((const DataArrayInt *)_fam_coords) + newFamCoords=_fam_coords->selectByTupleId(ret2->begin(),ret2->end()); + MEDCouplingAutoRefCountObjectPtr newNumCoords; + if((const DataArrayInt *)_num_coords) + newNumCoords=_num_coords->selectByTupleId(ret2->begin(),ret2->end()); + _coords=newCoords; _fam_coords=newFamCoords; _num_coords=newNumCoords; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_ms.begin();it!=_ms.end();it++) + { + if((MEDFileUMeshSplitL1*)*it) + (*it)->renumberNodesInConn(ret->begin()); + } + return ret.retn(); +} + void MEDFileUMesh::addNodeGroup(const std::string& name, const std::vector& ids) throw(INTERP_KERNEL::Exception) { const DataArrayDouble *coords=_coords; diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index c4133be4f..88d4c5e8c 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -212,6 +212,7 @@ namespace ParaMEDMEM void duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified, DataArrayInt *&cellsNotModified) throw(INTERP_KERNEL::Exception); // tools bool unPolyze(std::vector& oldCode, std::vector& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception); + DataArrayInt *zipCoords() throw(INTERP_KERNEL::Exception); private: void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); MEDFileUMesh(); diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 66e18f5c1..79b166b90 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -695,6 +695,14 @@ void MEDFileUMeshSplitL1::write(med_idt fid, const char *mName, int mdim) const } } +void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N) throw(INTERP_KERNEL::Exception) +{ + MEDCouplingUMesh *m(_m_by_types); + if(!m) + return; + m->renumberNodesInConn(newNodeNumbersO2N); +} + void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception) { DataArrayInt *arr=_fam; diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 19dddd9bd..10b4964c8 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -145,6 +145,8 @@ namespace ParaMEDMEM void setRenumArr(DataArrayInt *renumArr); void changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception); // + void renumberNodesInConn(const int *newNodeNumbersO2N) throw(INTERP_KERNEL::Exception); + // static void ClearNonDiscrAttributes(const MEDCouplingMesh *tmp); static std::vector GetNewFamiliesNumber(int nb, const std::map& families); static void TraduceFamilyNumber(const std::vector< std::vector >& fidsGrps, std::map& familyIds, diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 4710e3baf..a7a8da4f6 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -78,6 +78,7 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM1Mesh; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM2Mesh; %newobject ParaMEDMEM::MEDFileUMesh::getLevelM3Mesh; +%newobject ParaMEDMEM::MEDFileUMesh::zipCoords; %newobject ParaMEDMEM::MEDFileCMesh::New; %newobject ParaMEDMEM::MEDFileMeshMultiTS::New; %newobject ParaMEDMEM::MEDFileMeshMultiTS::getOneTimeStep; @@ -583,6 +584,7 @@ namespace ParaMEDMEM void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms, bool renum) throw(INTERP_KERNEL::Exception); void optimizeFamilies() throw(INTERP_KERNEL::Exception); + DataArrayInt *zipCoords() throw(INTERP_KERNEL::Exception); %extend { MEDFileUMesh(const char *fileName, const char *mName, int dt=-1, int it=-1) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 4284d68cf..361bbe453 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -1770,6 +1770,32 @@ class MEDLoaderTest(unittest.TestCase): pfl1_r.setName(pfl1.getName()) self.assertTrue(pfl1_r.isEqual(pfl1)) pass + + def testMEDFileUMeshZipCoords1(self): + m=MEDFileUMesh() + coo=DataArrayDouble(30) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"]) + m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0) ; m0.insertNextCell(NORM_TRI3,[1,2,3]) ; m0.insertNextCell(NORM_QUAD4,[2,4,3,4]) ; m0.insertNextCell(NORM_POLYGON,[1,6,6,6,2]) + m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3]) + m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8]) + m0.setCoords(coo) ; m.setMeshAtLevel(0,m0) + m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1) + m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2) + numCoo=DataArrayInt(10) ; numCoo.iota(3) ; m.setRenumFieldArr(1,numCoo) + famCoo=DataArrayInt(10) ; famCoo.iota(4) ; m.setFamilyFieldArr(1,famCoo) + da=DataArrayInt([20,30,40]) ; m.setRenumFieldArr(0,da) ; da=DataArrayInt([200,300,400]) ; m.setFamilyFieldArr(0,da) + da=DataArrayInt([50,60]) ; m.setRenumFieldArr(-1,da) ; da=DataArrayInt([500,600]) ; m.setFamilyFieldArr(-1,da) + da=DataArrayInt([70,80,90]) ; m.setRenumFieldArr(-2,da) ; da=DataArrayInt([700,800,900]) ; m.setFamilyFieldArr(-2,da) + o2n=m.zipCoords() + self.assertTrue(o2n.isEqual(DataArrayInt([-1,0,1,2,3,-1,4,5,6,-1]))) + self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt([4,5,6,7,9,10,11]))) + self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([5,6,7,8,10,11,12]))) + self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,4,1,3,2,3,5,0,4,4,4,1]))) + self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,9,15]))) + self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivity().isEqual(DataArrayInt([1,0,4,1,5,2]))) + self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivityIndex().isEqual(DataArrayInt([0,3,6]))) + self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivity().isEqual(DataArrayInt([0,1,0,4,0,6]))) + self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivityIndex().isEqual(DataArrayInt([0,2,4,6]))) + pass pass unittest.main()