1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2023 CEA, EDF
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 def MEDFileUMeshReduceToCells(self, level, keepCells, removeOrphanNodes=True):
23 Method returning a new MEDFileUMesh, restriction of self to level and keepCell cells at this level.
26 :param level: Specifies the top level of the returned MEDFileUMesh expected
27 :param keepCells: A DataArrayInt specifying cell ids at level level of self
28 :param removeOrphanNodes: Specifies if orphan nodes should be removed at the end
30 see also MEDFileUMesh.extractPart
32 import MEDLoader as ml
33 subLevs = [l for l in self.getNonEmptyLevels() if l<=level]
34 subMeshes = [self[lev] for lev in subLevs]
35 allFamilyFields = [self.getFamilyFieldAtLevel(lev) for lev in subLevs]
36 allRefMesh = subMeshes[0]
37 refMesh = allRefMesh[keepCells]
39 mmOut = ml.MEDFileUMesh()
42 mmOut.setFamilyFieldArr(0,allFamilyFields[0][keepCells])
45 for curLev,meshLev,famFieldLev in zip(subLevs[1:],subMeshes[1:],allFamilyFields[1:]):
46 allMeshLev,d,di, rd,rdi = allRefMesh.explodeMeshTo( curLev-level )
47 a,b = allMeshLev.areCellsIncludedIn(meshLev,2)
49 raise RuntimeError("Error in mesh {}")
50 dlev,dlevi = ml.DataArrayInt.ExtractFromIndexedArrays( keepCells, d,di )
51 dlev2 = dlev.buildUniqueNotSorted()
52 cellsToKeepLev = ml.DataArrayInt.BuildIntersection([dlev2,b])
53 cellsToKeepLev = b.indicesOfSubPart(cellsToKeepLev)
55 mmOut[curLev] = meshLev[cellsToKeepLev]
56 mmOut.setFamilyFieldArr(curLev,famFieldLev[cellsToKeepLev])
58 allFamNodes = mmOut.getFamilyFieldAtLevel(1)
60 mmOut.setFamilyFieldArr(1,allFamNodes[:])
65 mmOut.copyFamGrpMapsFrom(self)