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