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