1 #! /usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 # Copyright (C) 2021 CEA/DEN, EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author : Anthony GEAY (EDF R&D)
23 import medcoupling as mc
25 def __to_geomshape_3D(mcmesh):
27 Precondition mcmesh is a MEDCouplingUMesh containing exactly one linear 3D cell.
33 from salome.geom import geomBuilder
34 geompy = geomBuilder.New()
36 mcmesh2 = mcmesh.deepCopyConnectivityOnly()
37 vertices = [ geompy.MakeVertex(*list(elt)) for elt in mcmesh2.getCoords()]
39 mcfaces = mcmesh2.buildDescendingConnectivity()[0]
40 shell_1 = geompy.MakeShell(
44 geompy.MakePolyline([ vertices[nodeidx] for nodeidx in elt.getAllConn()[1:] ], True)
50 return geompy.MakeSolid([shell_1])
52 def to_geomshape(mcmesh):
54 Method converting a unique 3D linear cell in a MEDCoupling mesh to GEOM Shape solid
56 :param mcmesh: Mesh with single 3D linear cell.
57 :type mcmesh: mc.MEDCouplingUMesh
61 if not isinstance(mcmesh,mc.MEDCouplingUMesh):
62 raise RuntimeError("Input mesh is expected to be of type mc.MEDCouplingUMesh !")
63 if mcmesh.getNumberOfCells() != 1:
64 raise RuntimeError("Input mesh is expected to contain exactly one cell !")
65 if not mc.MEDCouplingUMesh.IsLinearGeometricType( mc.MEDCoupling1SGTUMesh(mcmesh).getCellModelEnum() ) :
66 raise RuntimeError("The unique cell in the mesh is expected to be linear !")
67 dico = { 3 : __to_geomshape_3D }
68 mdim = mcmesh.getMeshDimension()
70 raise RuntimeError( "Input mesh is expected to have mesh dimension in {}".format(list(dico.keys())) )
71 if mcmesh.getSpaceDimension() != 3:
72 mcmesh.changeSpaceDimension(3,0.0)
73 return (dico[mdim])(mcmesh)