Salome HOME
Merge branch 'master' into gni/evolution
[modules/smesh.git] / src / Tools / blocFissure / gmu / mailleFacesPeau.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2020  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 faces de peau"""
22
23 import logging
24
25 from .geomsmesh import geompy
26 from .geomsmesh import geomPublish
27 from .geomsmesh import geomPublishInFather
28 from . import initLog
29 from .geomsmesh import smesh
30 from salome.smesh import smeshBuilder
31 import SMESH
32
33 from .putName import putName
34
35 def mailleFacesPeau(partitionsPeauFissFond, idFillingFromBout, facesDefaut,
36                     facesPeaux, edCircPeau, ptCircPeau, gpedgeBord, gpedgeVifs, edFissPeau,
37                     bordsLibres, grpEdgesPeauFissureExterne, grpAretesVives,
38                     edgesCircPipeGroup, dmoyen, rayonPipe, nbsegRad):
39   """maillage faces de peau"""
40   logging.info('start')
41   nbFacesFilling = len(partitionsPeauFissFond)
42   boutFromIfil = [None for i in range(nbFacesFilling)]
43   if idFillingFromBout[0] != idFillingFromBout[1]: # repérage des extremites du pipe quand elles débouchent sur des faces différentes
44     boutFromIfil[idFillingFromBout[0]] = 0
45     boutFromIfil[idFillingFromBout[1]] = 1
46
47   logging.info("---------------------------- maillage faces de peau --------------")
48   logging.info("nbFacesFilling = %d", nbFacesFilling)
49   meshesFacesPeau = list()
50   for ifil in range(nbFacesFilling):
51     meshFacePeau = None
52     if partitionsPeauFissFond[ifil] is None: # face de peau maillage sain intacte
53
54       logging.debug("meshFacePeau %d intacte", ifil)
55       # --- edges de bord de la face de filling
56       filling = facesDefaut[ifil]
57       edgesFilling = geompy.ExtractShapes(filling, geompy.ShapeType["EDGE"], False)
58       groupEdgesBordPeau = geompy.CreateGroup(filling, geompy.ShapeType["EDGE"])
59       geompy.UnionList(groupEdgesBordPeau, edgesFilling)
60       geomPublishInFather(initLog.debug,filling, groupEdgesBordPeau , "EdgesBords")
61
62       meshFacePeau = smesh.Mesh(facesDefaut[ifil])
63
64       algo1d = meshFacePeau.UseExisting1DElements(geom=groupEdgesBordPeau)
65       hypo1d = algo1d.SourceEdges([ bordsLibres ],0,0)
66       putName(algo1d.GetSubMesh(), "bordsLibres", ifil)
67       putName(algo1d, "algo1d_bordsLibres", ifil)
68       putName(hypo1d, "hypo1d_bordsLibres", ifil)
69
70     else:
71
72       logging.info("meshFacePeau %d coupée par la fissure", ifil)
73       facePeau           = facesPeaux[ifil] # pour chaque face : la face de peau finale a mailler (percée des faces débouchantes)
74       edgesCircPeau      = edCircPeau[ifil] # pour chaque face de peau : [subshape edge circulaire aux débouchés du pipe]
75       verticesCircPeau   = ptCircPeau[ifil] # pour chaque face de peau : [subshape point sur edge circulaire aux débouchés du pipe]
76       groupEdgesBordPeau = gpedgeBord[ifil] # pour chaque face de peau : groupe subshape des edges aux bords liés à la partie saine
77       bordsVifs          = gpedgeVifs[ifil] # pour chaque face de peau : groupe subshape des edges aux bords correspondant à des arêtes vives
78       edgesFissurePeau   = edFissPeau[ifil] # pour chaque face de peau : [subshape edge en peau des faces de fissure externes]
79
80       print ("a")
81       meshFacePeau = smesh.Mesh(facePeau)
82
83       algo1d = meshFacePeau.UseExisting1DElements(geom=groupEdgesBordPeau)
84       hypo1d = algo1d.SourceEdges([ bordsLibres ],0,0)
85       putName(algo1d.GetSubMesh(), "bordsLibres", ifil)
86       putName(algo1d, "algo1d_bordsLibres", ifil)
87       putName(hypo1d, "hypo1d_bordsLibres", ifil)
88
89       print ("b")
90       algo1d = meshFacePeau.UseExisting1DElements(geom=geompy.MakeCompound(edgesFissurePeau))
91       hypo1d = algo1d.SourceEdges([ grpEdgesPeauFissureExterne ],0,0)
92       putName(algo1d.GetSubMesh(), "edgePeauFiss", ifil)
93       putName(algo1d, "algo1d_edgePeauFiss", ifil)
94       putName(hypo1d, "hypo1d_edgePeauFiss", ifil)
95
96       print ("bordsVifs = {}".format(bordsVifs))
97       if bordsVifs is not None:
98         algo1d = meshFacePeau.UseExisting1DElements(geom=bordsVifs)
99         hypo1d = algo1d.SourceEdges([ grpAretesVives ],0,0)
100         putName(algo1d.GetSubMesh(), "bordsVifs", ifil)
101         putName(algo1d, "algo1d_bordsVifs", ifil)
102         putName(hypo1d, "hypo1d_bordsVifs", ifil)
103
104       for i, edgeCirc in enumerate(edgesCircPeau):
105         print ("i = {}".format(i))
106         if edgeCirc is not None:
107           algo1d = meshFacePeau.UseExisting1DElements(geom=edgeCirc)
108           if boutFromIfil[ifil] is None:
109             hypo1d = algo1d.SourceEdges([ edgesCircPipeGroup[i] ],0,0)
110           else:
111             hypo1d = algo1d.SourceEdges([ edgesCircPipeGroup[boutFromIfil[ifil]] ],0,0)
112           name = "cercle%d"%i
113           putName(algo1d.GetSubMesh(), name, ifil)
114           putName(algo1d, "algo1d_" + name, ifil)
115           putName(hypo1d, "hypo1d_" + name, ifil)
116
117     print ("c")
118     algo2d = meshFacePeau.Triangle(algo=smeshBuilder.NETGEN_1D2D)
119     hypo2d = algo2d.Parameters()
120     hypo2d.SetMaxSize( dmoyen )
121     hypo2d.SetOptimize( 1 )
122     hypo2d.SetFineness( 2 )
123     hypo2d.SetMinSize( rayonPipe/float(nbsegRad) )
124     hypo2d.SetQuadAllowed( 0 )
125     print ("d")
126     putName(algo2d.GetSubMesh(), "facePeau", ifil)
127     putName(algo2d, "algo2d_facePeau", ifil)
128     putName(hypo2d, "hypo2d_facePeau", ifil)
129
130     is_done = meshFacePeau.Compute()
131     text = "meshFacePeau {} .Compute".format(ifil)
132     if is_done:
133       logging.info(text+" OK")
134     else:
135       text = "Erreur au calcul du maillage.\n" + text
136       logging.info(text)
137       raise Exception(text)
138
139     GroupFaces = meshFacePeau.CreateEmptyGroup( SMESH.FACE, "facePeau%d"%ifil )
140     nbAdd = GroupFaces.AddFrom( meshFacePeau.GetMesh() )
141     meshesFacesPeau.append(meshFacePeau)
142
143   return meshesFacesPeau