Salome HOME
Copyright update 2022
[modules/smesh.git] / src / Tools / blocFissure / gmu / regroupeSainEtDefaut.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 """Maillage sain sans la zone de defaut"""
21
22 import logging
23
24 import SMESH
25
26 from .geomsmesh import geompy
27 from .geomsmesh import smesh
28
29 def RegroupeSainEtDefaut(maillageSain, blocComplet, extrusionFaceFissure, faceGeomFissure, nomVolume, normal = None):
30   """Maillage sain sans la zone de defaut"""
31   logging.info('Concatenation')
32
33   maillageComplet = smesh.Concatenate([maillageSain.GetMesh(), blocComplet.GetMesh()], 1, 1, 1e-05,False)
34
35   groups = maillageComplet.GetGroups()
36   for grp in groups:
37     grp_nom = grp.GetName()
38     if ( grp_nom == "FACE1" ):
39       faceFissure = grp
40     elif ( grp_nom == "nfondfis" ):
41       noeudsFondFissure = grp
42     elif ( grp_nom == "fisInPi" ):
43       fisInPi = grp
44     elif ( grp_nom == "fisOutPi" ):
45       fisOutPi = grp
46
47   # --- TODO: fiabiliser l'orientation dans le cas general
48   if normal is None:
49     normal  = smesh.MakeDirStruct( 0, 0, 1 )
50   texte = 'après normal = {}'.format(normal)
51   logging.debug(texte)
52   maillageComplet.Reorient2D( fisInPi,  normal, [0,0,0])
53   logging.debug('après Reorient2D In')
54   maillageComplet.Reorient2D( fisOutPi, normal, [0,0,0])
55
56   shapes = list()
57   if extrusionFaceFissure is not None:
58     subIds = geompy.SubShapeAllIDs(extrusionFaceFissure, geompy.ShapeType["SOLID"])
59     if ( len(subIds) > 1 ):
60       shapes = geompy.ExtractShapes(extrusionFaceFissure, geompy.ShapeType["SOLID"], False)
61     else:
62       shapes = [extrusionFaceFissure]
63 #  else:
64 #    subIds = geompy.SubShapeAllIDs(faceGeomFissure, geompy.ShapeType["FACE"])
65 #    if len(subIds) > 1:
66 #      shapes = geompy.ExtractShapes(faceGeomFissure, geompy.ShapeType["FACE"], False)
67 #    else:
68 #      shapes = [faceGeomFissure]
69
70   grpEdges = list()
71   grpFaces = list()
72   grpVolumes = list()
73   if not shapes:
74     shapes = [None] # calcul uniquement avec les normales des faces mailles de la fissure
75   for i, aShape in enumerate(shapes):
76     texte = "Detection elements affectes par le dedoublement de la face n° {}".format(i)
77     logging.debug(texte)
78     affectedGroups = maillageComplet.AffectedElemGroupsInRegion([faceFissure], [noeudsFondFissure], aShape)
79     for grp in affectedGroups:
80       grp_nom = grp.GetName()
81       if ( grp_nom == "affectedEdges" ):
82         affectedEdges = grp
83       elif ( grp_nom == "affectedFaces" ):
84         affectedFaces = grp
85       elif ( grp_nom == "affectedVolumes" ):
86         affectedVolumes = grp
87     #grps = [ grp for grp in affectedGroups if grp.GetName() == 'affectedEdges']
88     #affectedEdges = grps[0]
89     affectedEdges.SetName('affEd%d'%i)
90     grpEdges.append(affectedEdges)
91     #grps = [ grp for grp in affectedGroups if grp.GetName() == 'affectedFaces']
92     #affectedFaces = grps[0]
93     affectedFaces.SetName('affFa%d'%i)
94     grpFaces.append(affectedFaces)
95     #grps = [ grp for grp in affectedGroups if grp.GetName() == 'affectedVolumes']
96     #affectedVolumes = grps[0]
97     affectedVolumes.SetName('affVo%d'%i)
98     grpVolumes.append(affectedVolumes)
99   affectedEdges = maillageComplet.UnionListOfGroups(grpEdges, 'affEdges')
100   affectedFaces = maillageComplet.UnionListOfGroups(grpFaces, 'affFaces')
101   affectedVolumes = maillageComplet.UnionListOfGroups(grpVolumes, 'affVols')
102   for grp in affectedGroups:
103     texte = "Traitement du groupe '{}'".format(grp.GetName())
104     logging.debug(texte)
105   [ FACE2, _ ] = maillageComplet.DoubleNodeElemGroups([faceFissure], [noeudsFondFissure], affectedGroups, True, True)
106   FACE2.SetName( 'FACE2' )
107
108   # Groupe de toutes les mailles volumiques
109   GroupVol = maillageComplet.CreateEmptyGroup( SMESH.VOLUME, nomVolume )
110   _ = GroupVol.AddFrom( maillageComplet.GetMesh() )
111
112   return maillageComplet