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