Salome HOME
Copyright update 2022
[modules/smesh.git] / src / Tools / blocFissure / gmu / peauInterne.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2022  EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """Peau interne du defaut dans le maillage sain"""
21
22 import logging
23 import traceback
24
25 import SMESH
26
27 from .geomsmesh import smesh
28
29 from .fissError import fissError
30 from .listOfExtraFunctions import lookForCorner
31 from .fusionMaillageAttributionDefaut import fusionMaillageDefaut
32 from .putName import putName
33
34 def peauInterne(fichierMaillage, shapeDefaut, nomZones, \
35                 nro_cas=None):
36   """Retrouve les groupes de défaut dans le maillage sain modifié par CreateHoleSkin (CreeZoneDefautMaillage)
37
38   On récupère le volume et la peau de la zone de défaut, les éventuelles faces et arêtes internes de cette zone.
39   Remarque : intérêt du passage par fichierMaillage plutôt que par maillageSain ?
40   """
41   logging.info("start")
42   ([maillageSain], _) = smesh.CreateMeshesFromMED(fichierMaillage)
43
44   groups = maillageSain.GetGroups()
45   #print ("groupes :")
46   #for grp in groups:
47     #print ("\t{}".format(grp.GetName()))
48   zoneDefaut = None
49   zoneDefaut_skin = None
50   zoneDefaut_internalFaces = None
51   zoneDefaut_internalEdges = None
52   for grp in groups:
53     nom = grp.GetName()
54     logging.debug("groupe %s",nom)
55     if ( nom == nomZones + "_vol" ):
56       zoneDefaut = grp
57     elif ( nom == nomZones + "_skin" ):
58       zoneDefaut_skin = grp
59     elif ( nom == nomZones + "_internalFaces" ):
60       zoneDefaut_internalFaces = grp
61     elif ( nom == nomZones + "_internalEdges" ):
62       zoneDefaut_internalEdges = grp
63   # --- Le groupe ZoneDefaut ne doit contenir que des Hexaèdres"
64
65   info = maillageSain.GetMeshInfo(zoneDefaut)
66   #print ("info = {}".format(info))
67   nbelem = 0
68   nbhexa = 0
69   for entity_type in info:
70     #print (". {} : {})".format(entity_type, info[entity_type]))
71     nbelem += info[entity_type]
72     if ( str(entity_type) == "Entity_Hexa" ):
73       nbhexa += info[entity_type]
74       nbhexa += info[entity_type]
75   #print ("==> nbelem = {}, nbhexa = {}".format(nbelem,nbhexa))
76
77   if ( (nbelem == 0) or (nbhexa < nbelem) ):
78     print ("==> nbelem = {}, nbhexa = {}".format(nbelem,nbhexa))
79     texte = "La zone a remailler est incorrecte.<br>"
80     texte += "Causes possibles :<ul>"
81     texte += "<li>Les mailles à enlever dans le maillage sain n'ont pas été détectées.</li>"
82     texte += "<li>Certaines faces du maillage sain sont à l'envers : les normales aux faces en paroi de volume doivent être sortantes.</li>"
83     texte += "<li>Il n'y a pas que des hexaèdres réglés linéaires dans la zone à remailler (notamment mailles quadratiques, tetraèdres non traités)</li></ul>"
84     raise fissError(traceback.extract_stack(),texte)
85
86   _, maillageSain, DefautBoundary = maillageSain.MakeBoundaryElements( SMESH.BND_2DFROM3D, 'DefBound', '', 0, [ zoneDefaut ])
87   internal = maillageSain.GetMesh().CutListOfGroups( [ DefautBoundary ], [ zoneDefaut_skin ], 'internal' )
88   internalBoundary = smesh.CopyMesh( internal, 'internalBoundary', 0, 0)
89   putName(internalBoundary, "internalBoundary", i_pref=nro_cas)
90
91   maillageDefautCible = smesh.CopyMesh(zoneDefaut_skin, 'maillageCible', 0, 0)
92   putName(maillageDefautCible, "maillageCible", i_pref=nro_cas)
93   listOfCorner = lookForCorner(maillageDefautCible)
94   texte = "listOfCorner = {}".format(listOfCorner)
95   logging.debug(texte)
96   if listOfCorner:
97     logging.info("présence de coins à la surface externe de la zone à reconstruire")
98     zoneDefaut_skin, internalBoundary = \
99           fusionMaillageDefaut(maillageSain, maillageDefautCible, internalBoundary, zoneDefaut_skin, shapeDefaut, listOfCorner, \
100           nro_cas)
101
102   return maillageSain, internalBoundary, zoneDefaut, zoneDefaut_skin, zoneDefaut_internalFaces, zoneDefaut_internalEdges