Salome HOME
Merge branch 'gni/evolution'
[modules/smesh.git] / src / Tools / blocFissure / gmu / meshBlocPart.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 """Maillage du bloc partitionné"""
21
22 import logging
23
24 import SMESH
25 from salome.smesh import smeshBuilder
26 from salome.StdMeshers import StdMeshersBuilder
27
28 from .geomsmesh import geompy
29 from .geomsmesh import smesh
30
31 from .putName import putName
32
33 # -----------------------------------------------------------------------------
34
35 def meshBlocPart(blocPartition, faceFissure, tore, centres, edges, diams, circles, faces, \
36                 gencnt, facefissoutore, edgeext, facesExternes, facesExtBloc, facesExtElli, \
37                 aretesInternes, internalBoundary, ellipsoidep, sharedFaces, sharedEdges, edgesBords, \
38                 nbsegExt, nbsegGen, nbsegRad, scaleRad, reverses, reverext, nbsegCercle, nbsegFis, dmoyen, lensegEllipsoide, \
39                 mailleur="MeshGems", nro_cas=None):
40   """Maillage du bloc partitionné"""
41   logging.info('start')
42   logging.info("Maillage avec %s pour le cas n°%s", mailleur, nro_cas)
43
44   # --- edges de bord à respecter
45
46   _ = smesh.CreateFilterManager()
47   _, internalBoundary, _NoneGroup = internalBoundary.MakeBoundaryElements( SMESH.BND_1DFROM2D, '', '', 0, [ ])
48   criteres = list()
49   unCritere = smesh.GetCriterion(SMESH.EDGE,SMESH.FT_FreeBorders,SMESH.FT_Undefined,0)
50   criteres.append(unCritere)
51   filtre = smesh.GetFilterFromCriteria(criteres)
52   bordsLibres = internalBoundary.MakeGroupByFilter( 'bords', filtre )
53   putName(bordsLibres, 'bordsLibres', i_pref=nro_cas)
54
55   # --- maillage bloc
56
57   bloc1 = smesh.Mesh(blocPartition)
58
59   for i_aux, sharedFaces_i in enumerate(sharedFaces):
60     algo2d = bloc1.Triangle(algo=smeshBuilder.NETGEN, geom=sharedFaces_i)
61     hypo2d = algo2d.Parameters(which=smesh.SIMPLE)
62     hypo2d.SetLocalLength(lensegEllipsoide)
63     hypo2d.LengthFromEdges()
64     hypo2d.SetAllowQuadrangles(0)
65     putName(algo2d.GetSubMesh(), "sharedFaces", i_aux, nro_cas)
66     putName(algo2d, "{}_2d_sharedFaces".format(mailleur), i_aux, nro_cas)
67     putName(hypo2d, "hypo2d_sharedFaces", i_aux, nro_cas)
68
69   for i_aux, sharedEdges_i in enumerate(sharedEdges):
70     algo1d = bloc1.Segment(geom=sharedEdges_i)
71     hypo1d = algo1d.LocalLength(lensegEllipsoide)
72     putName(algo1d.GetSubMesh(), "sharedEdges", i_aux, nro_cas)
73     putName(algo1d, "algo1d_sharedEdges", i_aux, nro_cas)
74     putName(hypo1d, "hypo1d_sharedEdges", i_aux, nro_cas)
75
76   declareAlgoEllipsoideFirst = False
77   if declareAlgoEllipsoideFirst:
78     algo3d = bloc1.Tetrahedron(algo=smeshBuilder.NETGEN,geom=ellipsoidep)
79     hypo3d = algo3d.MaxElementVolume(1000.0)
80     putName(algo3d.GetSubMesh(), "ellipsoide", i_pref=nro_cas)
81     putName(algo3d, "{}_3d_ellipsoide".format(mailleur), i_pref=nro_cas)
82     putName(hypo3d, "hypo3d_ellipsoide", i_pref=nro_cas)
83
84   algo3d = bloc1.Prism(geom=tore)
85   algo2d = bloc1.Quadrangle(geom=tore)
86   algo1d = bloc1.Segment(geom=tore)
87   hypo1d = algo1d.NumberOfSegments(nbsegGen)
88   putName(algo3d.GetSubMesh(), "tore", i_pref=nro_cas)
89   putName(algo3d, "{}_3d_tore".format(mailleur), i_pref=nro_cas)
90   putName(algo2d, "{}_2d_tore".format(mailleur), i_pref=nro_cas)
91   putName(algo1d, "algo1d_tore", i_pref=nro_cas)
92   putName(hypo1d, "hypo1d_tore", i_pref=nro_cas)
93
94   for i_aux, faces_i in enumerate(faces):
95     algo2d = bloc1.Quadrangle(geom=faces_i)
96     hypo2d = smesh.CreateHypothesis('QuadrangleParams')
97     hypo2d.SetTriaVertex( geompy.GetSubShapeID(blocPartition,centres[i_aux]) )
98     hypo2d.SetQuadType( StdMeshersBuilder.QUAD_STANDARD )
99     _ = bloc1.AddHypothesis(hypo2d,faces_i)
100     putName(algo2d.GetSubMesh(), "faces", i_aux, nro_cas)
101     putName(algo2d, "{}_2d_faces".format(mailleur), i_aux, nro_cas)
102     putName(hypo2d, "hypo2d_faces", i_aux, nro_cas)
103
104   for i_aux, edges_i in enumerate(edges):
105     algo1d = bloc1.Segment(geom=edges_i)
106     if reverses[i_aux] > 0:
107       hypo1d = algo1d.NumberOfSegments(nbsegRad, scaleRad,[ geompy.GetSubShapeID(blocPartition,edges_i) ])
108     else:
109       hypo1d = algo1d.NumberOfSegments(nbsegRad, scaleRad,[ ])
110     putName(algo1d.GetSubMesh(), "edges", i_aux, nro_cas)
111     putName(algo1d, "algo1d_edges", i_aux, nro_cas)
112     putName(hypo1d, "hypo1d_edges", i_aux, nro_cas)
113
114   for i_aux, circles_i in enumerate(circles):
115     algo1d = bloc1.Segment(geom=circles_i)
116     hypo1d = algo1d.NumberOfSegments(nbsegCercle)
117     putName(algo1d.GetSubMesh(), "circles", i_aux, nro_cas)
118     putName(algo1d, "algo1d_circles", i_aux, nro_cas)
119     putName(hypo1d, "hypo1d_circles", i_aux, nro_cas)
120
121   if len(edgeext) == 1:
122     densite = int(round(nbsegFis/2))
123     algo1d = bloc1.Segment(geom=edgeext[0])
124     hypo1d = algo1d.NumberOfSegments(nbsegFis)
125     hypo1d.SetDistrType( 2 )
126     hypo1d.SetConversionMode( 1 )
127     hypo1d.SetTableFunction( [ 0, densite, 0.4, 1, 0.6, 1, 1, densite ] )
128     putName(algo1d.GetSubMesh(), "edgeext", i_pref=nro_cas)
129     putName(algo1d, "algo1d_edgeext", i_pref=nro_cas)
130     putName(hypo1d, "hypo1d_edgeext", i_pref=nro_cas)
131   else:
132     longTotal = 0
133     longEdgeExts = list()
134     for edgeext_i in edgeext:
135       props = geompy.BasicProperties(edgeext_i)
136       longEdgeExts.append(props[0])
137       longTotal += props[0]
138     for i_aux, edgeext_i in enumerate(edgeext):
139       nbLocal = int(round(nbsegFis*longEdgeExts[i_aux]/longTotal))
140       densite = int(round(nbLocal/2))
141       algo1d = bloc1.Segment(geom=edgeext_i)
142       hypo1d = algo1d.NumberOfSegments(nbLocal)
143       hypo1d.SetDistrType( 2 )
144       hypo1d.SetConversionMode( 1 )
145       hypo1d.SetTableFunction( [ 0, densite, 0.8, 1, 1, 1 ] )
146       if reverext[i_aux]:
147         hypo1d.SetReversedEdges([ geompy.GetSubShapeID(blocPartition, edgeext_i) ])
148       putName(algo1d.GetSubMesh(), "edgeext", i_aux, nro_cas)
149       putName(algo1d, "algo1d_edgeext", i_aux, nro_cas)
150       putName(hypo1d, "hypo1d_edgeext", i_aux, nro_cas)
151
152   algo2d = bloc1.Triangle(algo=smeshBuilder.NETGEN_2D, geom=facefissoutore)
153   hypo2d = algo2d.LengthFromEdges()
154   putName(algo2d.GetSubMesh(), "facefissoutore", i_pref=nro_cas)
155   putName(algo2d, "{}_2d_facefissoutore".format(mailleur), i_pref=nro_cas)
156   putName(hypo2d, "hypo2d_facefissoutore", i_pref=nro_cas)
157
158
159   maxElemArea = 0.5*dmoyen*dmoyen
160   logging.debug("dmoyen %s, maxElemArea %s", dmoyen, maxElemArea)
161
162   for i_aux, facesExternes_i in enumerate(facesExternes):
163     algo2d = bloc1.Triangle(algo=smeshBuilder.NETGEN_2D, geom=facesExternes_i)
164     hypo2d = algo2d.MaxElementArea(maxElemArea)
165     if edgesBords is None:
166       algo1d = bloc1.Segment(geom=facesExternes_i)
167       hypo1d = algo1d.NumberOfSegments(1)
168     putName(algo2d.GetSubMesh(), "facesExternes", i_aux, nro_cas)
169     putName(algo2d, "{}2d_facesExternes".format(mailleur), i_aux, nro_cas)
170     putName(hypo2d, "hypo2d_facesExternes", i_aux, nro_cas)
171     if edgesBords is None:
172       putName(algo1d, "algo1d_facesExternes", i_aux, nro_cas)
173       putName(hypo1d, "hypo1d_facesExternes", i_aux, nro_cas)
174
175   for i_aux, aretesInternes_i in enumerate(aretesInternes):
176     algo1d = bloc1.Segment(geom=aretesInternes_i)
177     hypo1d = algo1d.NumberOfSegments(nbsegExt)
178     putName(algo1d.GetSubMesh(), "aretesInternes", i_aux, nro_cas)
179     putName(algo1d, "algo1d_aretesInternes", i_aux, nro_cas)
180     putName(hypo1d, "hypo1d_aretesInternes", i_aux, nro_cas)
181
182   if edgesBords is not None:
183     algo1d = bloc1.UseExisting1DElements(geom=edgesBords)
184     hypo1d = algo1d.SourceEdges([ bordsLibres ],0,0)
185     putName(algo1d.GetSubMesh(), "bordsLibres", i_pref=nro_cas)
186     putName(algo1d, "algo1d_bordsLibres", i_pref=nro_cas)
187     putName(hypo1d, "hypo1d_bordsLibres", i_pref=nro_cas)
188
189   if not declareAlgoEllipsoideFirst:
190     algo3d = bloc1.Tetrahedron(algo=smeshBuilder.NETGEN,geom=ellipsoidep)
191     hypo3d = algo3d.MaxElementVolume(1000.0)
192     putName(algo3d.GetSubMesh(), "ellipsoide", i_pref=nro_cas)
193     putName(algo3d, "{}_3d_ellipsoide".format(mailleur), i_pref=nro_cas)
194     putName(hypo3d, "hypo3d_ellipsoide", i_pref=nro_cas)
195
196   _ = bloc1.GroupOnGeom(faceFissure,'FACE1',SMESH.FACE)
197   _ = bloc1.GroupOnGeom(gencnt,'nfondfis',SMESH.NODE)
198
199   groups_faceCommuneEllipsoideBloc = list()
200   for i_aux, sharedFaces_i in enumerate(sharedFaces):
201     name = "faceCommuneEllipsoideBloc_{}".format(i_aux)
202     groups_faceCommuneEllipsoideBloc.append(bloc1.GroupOnGeom(sharedFaces_i, name, SMESH.FACE))
203   groups_faceExterneBloc = list()
204   for i_aux, facesExtBloc_i in enumerate(facesExtBloc):
205     name = "faceExterneBloc_{}".format(i_aux)
206     groups_faceExterneBloc.append(bloc1.GroupOnGeom(facesExtBloc_i, name, SMESH.FACE))
207
208   is_done = bloc1.Compute()
209   text = "bloc1.Compute"
210   if is_done:
211     logging.info(text+" OK")
212   else:
213     text = "Erreur au calcul du maillage.\n" + text
214     logging.info(text)
215     raise Exception(text)
216
217   _ = bloc1.RemoveOrphanNodes()
218
219   skinBlocMeshes = list()
220   for i_aux, groups_faceCommuneEllipsoideBloc_i in enumerate(groups_faceCommuneEllipsoideBloc):
221     name = "faceCommuneEllipsoideBloc_{}".format(i_aux)
222     skinBlocMeshes.append(smesh.CopyMesh(groups_faceCommuneEllipsoideBloc_i, name, 0, 0))
223   for i_aux, groups_faceExterneBloc_i in enumerate(groups_faceExterneBloc):
224     name = "faceExterneBloc_{}".format(i_aux)
225     skinBlocMeshes.append(smesh.CopyMesh(groups_faceExterneBloc_i, name, 0, 0))
226
227   meshesBloc = [internalBoundary.GetMesh()]
228   for skinBlocMeshes_i in skinBlocMeshes:
229     meshesBloc.append(skinBlocMeshes_i.GetMesh())
230   blocMesh = smesh.Concatenate(meshesBloc, 1, 1, 1e-05,False)
231
232   algo3d = blocMesh.Tetrahedron(algo=smeshBuilder.NETGEN)
233   hypo3d = algo3d.MaxElementVolume(1000.0)
234   putName(algo3d.GetSubMesh(), "bloc", i_pref=nro_cas)
235   putName(algo3d, "{}_3d_bloc".format(mailleur), i_pref=nro_cas)
236   putName(hypo3d, "hypo3d_bloc", i_pref=nro_cas)
237
238   is_done = blocMesh.Compute()
239   text = "blocMesh.Compute"
240   if is_done:
241     logging.info(text+" OK")
242   else:
243     text = "Erreur au calcul du maillage.\n" + text
244     logging.info(text)
245     raise Exception(text)
246
247   blocComplet = smesh.Concatenate([bloc1.GetMesh(), blocMesh.GetMesh()], 1, 1, 1e-05,False)
248
249   return bloc1, blocComplet