From: Anthony Geay Date: Tue, 3 Sep 2024 06:32:34 +0000 (+0200) Subject: [EDF30179] First implementation of nodes and cells fusion X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b6aeafb8372299e32d871ab356b711dda65f8460;p=tools%2Fmedcoupling.git [EDF30179] First implementation of nodes and cells fusion --- diff --git a/src/MEDLoader/Swig/MEDLoaderFinalize.i b/src/MEDLoader/Swig/MEDLoaderFinalize.i index dedf62d39..75669a3c2 100644 --- a/src/MEDLoader/Swig/MEDLoaderFinalize.i +++ b/src/MEDLoader/Swig/MEDLoaderFinalize.i @@ -21,6 +21,7 @@ %pythoncode %{ import MEDLoaderFinalize MEDFileUMesh.reduceToCells = MEDLoaderFinalize.MEDFileUMeshReduceToCells +MEDFileUMesh.fuseNodesAndCells = MEDLoaderFinalize.MEDFileUMeshFuseNodesAndCells del MEDLoaderFinalize MEDFileMeshesIterator.__next__ = MEDFileMeshesIterator.next MEDFileAnyTypeFieldMultiTSIterator.__next__ = MEDFileAnyTypeFieldMultiTSIterator.next diff --git a/src/MEDLoader/Swig/MEDLoaderFinalize.py b/src/MEDLoader/Swig/MEDLoaderFinalize.py index e5fc856c9..ced823319 100644 --- a/src/MEDLoader/Swig/MEDLoaderFinalize.py +++ b/src/MEDLoader/Swig/MEDLoaderFinalize.py @@ -18,6 +18,87 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +import logging + +def MEDFileUMeshFuseNodesAndCells(self, compType = 2 , eps = 1e-6, logLev = logging.INFO): + """ + [EDF30179] : Method fusing nodes in this, then fusing cells in this. Fusion is done following eps and compType. + + :param compType : see MEDCouplingPointSet.zipConnectivityTraducer method for explanations + :param eps: see DataArrayDouble.findCommonTuples for explanations. + :param logLev: Integer specifying log level + :return: MEDFileUMesh instance containing the result of nodes and cells fusion + """ + import MEDLoader as ml + def getLogger( level = logging.INFO ): + FORMAT = '%(levelname)s : %(asctime)s : [%(filename)s:%(funcName)s:%(lineno)s] : %(message)s' + logging.basicConfig( format = FORMAT, level = level ) + return logging.getLogger() + logger = getLogger( logLev ) + def updateMap( mm : ml.MEDFileUMesh, lev : int, famMap : ml.DataArrayInt, famMapI : ml.DataArrayInt): + """ + mm instance to be updated + """ + def famIdManager(lev, famId): + if lev<= 0: + return -famId + else: + return famId + nbOfPartSetToBeUpdated = len(famMapI) -1 + for partSetId in range( nbOfPartSetToBeUpdated ): + newFamId = famIdManager( lev, famMap[ famMapI[partSetId] ] ) + newFamName = f"Family_{newFamId}" + logger.debug(f"For level {lev} new family : {newFamId}") + mm.addFamily(newFamName,newFamId) + for famId in famMap[ famMapI[partSetId]+1 :famMapI[partSetId+1] ]: + grpsToBeUpdated = mm.getGroupsOnFamily( mm.getFamilyNameGivenId( famIdManager( lev, int(famId) ) ) ) + for grpToBeUpdated in grpsToBeUpdated: + mm.addFamilyOnGrp( grpToBeUpdated, newFamName ) + pass + getLogger( level = logLev ) + initNbNodes = len( self.getCoords() ) + logger.info(f"Begin merging nodes with eps = {eps}") + cc,cci = self.getCoords().findCommonTuples( eps ) + logger.info(f"End of merging nodes with eps = {eps} : Nb of nodes groups to be merged : {len(cci)-1} / {self.getNumberOfNodes()}") + o2n,newNbNodes = ml.DataArrayInt.ConvertIndexArrayToO2N(initNbNodes,cc,cci) + n2oNodes = o2n.invertArrayO2N2N2O( newNbNodes ) + newCoords = self.getCoords()[n2oNodes] + # creation of + mmOut = ml.MEDFileUMesh() + mmOut.copyFamGrpMapsFrom( self ) + + for lev in self.getNonEmptyLevels(): + logger.debug(f"Begin level {lev}") + m1 = self[lev].deepCopy() + logger.debug(f"Begin renumbering connectivity of level {lev}") + m1.renumberNodesInConn( o2n ) + logger.debug(f"End renumbering connectivity of level {lev}") + m1.setCoords( newCoords ) + logger.info(f"Begin of finding of same cells of level {lev}") + cce,ccei = m1.findCommonCells(compType,0) + logger.info(f"End of finding of same cells of level {lev} : Nb of cells groups to be merged : {len(ccei)-1} / {m1.getNumberOfCells()}") + famsCell = self.getFamilyFieldAtLevel(lev) + if famsCell: + famsCell = -famsCell + famsMergedCell,famMap,famMapI = famsCell.forThisAsPartitionBuildReduction(cce,ccei) # <- method updating family field array + updateMap(mmOut,lev,famMap,famMapI) + famsMergedCell = -famsMergedCell + o2nCells,newNbCells = ml.DataArrayInt.ConvertIndexArrayToO2N(m1.getNumberOfCells(),cce,ccei) + n2oCells = o2nCells.invertArrayO2N2N2O( newNbCells ) + m1 = m1[ n2oCells ] + m1.setCoords( newCoords ) + m1.setName( self.getName() ) + mmOut[lev] = m1 + if famsCell: + mmOut.setFamilyFieldArr( lev, famsMergedCell ) + + famsNode = self.getFamilyFieldAtLevel(1) + if famsNode: + famsMergedNode,famMap,famMapI = famsNode.forThisAsPartitionBuildReduction(cc,cci) + updateMap(mmOut,1,famMap,famMapI) + mmOut.setFamilyFieldArr(1, famsMergedNode) + return mmOut + def MEDFileUMeshReduceToCells(self, level, keepCells, removeOrphanNodes=True): """ Method returning a new MEDFileUMesh, restriction of self to level and keepCell cells at this level.