1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2021 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 """Maillage du bloc partitionné"""
25 from salome.smesh import smeshBuilder
26 from salome.StdMeshers import StdMeshersBuilder
28 from .geomsmesh import geompy
29 from .geomsmesh import smesh
31 from .putName import putName
33 # -----------------------------------------------------------------------------
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, \
40 """Maillage du bloc partitionné"""
43 # --- edges de bord à respecter
45 _ = smesh.CreateFilterManager()
46 _, internalBoundary, _NoneGroup = internalBoundary.MakeBoundaryElements( SMESH.BND_1DFROM2D, '', '', 0, [ ])
48 unCritere = smesh.GetCriterion(SMESH.EDGE,SMESH.FT_FreeBorders,SMESH.FT_Undefined,0)
49 criteres.append(unCritere)
50 filtre = smesh.GetFilterFromCriteria(criteres)
51 bordsLibres = internalBoundary.MakeGroupByFilter( 'bords', filtre )
52 smesh.SetName(bordsLibres, 'bordsLibres')
56 bloc1 = smesh.Mesh(blocPartition)
58 for i_aux, sharedFaces_i in enumerate(sharedFaces):
59 algo2d = bloc1.Triangle(algo=smeshBuilder.NETGEN, geom=sharedFaces_i)
60 hypo2d = algo2d.Parameters(which=smesh.SIMPLE)
61 hypo2d.SetLocalLength(lensegEllipsoide)
62 hypo2d.LengthFromEdges()
63 hypo2d.SetAllowQuadrangles(0)
64 putName(algo2d.GetSubMesh(), "sharedFaces", i_aux)
65 putName(algo2d, "algo2d_sharedFaces", i_aux)
66 putName(hypo2d, "hypo2d_sharedFaces", i_aux)
68 for i_aux, sharedEdges_i in enumerate(sharedEdges):
69 algo1d = bloc1.Segment(geom=sharedEdges_i)
70 hypo1d = algo1d.LocalLength(lensegEllipsoide)
71 putName(algo1d.GetSubMesh(), "sharedEdges", i_aux)
72 putName(algo1d, "algo1d_sharedEdges", i_aux)
73 putName(hypo1d, "hypo1d_sharedEdges", i_aux)
75 declareAlgoEllipsoideFirst = False
76 if declareAlgoEllipsoideFirst:
77 algo3d = bloc1.Tetrahedron(algo=smeshBuilder.NETGEN,geom=ellipsoidep)
78 hypo3d = algo3d.MaxElementVolume(1000.0)
79 putName(algo3d.GetSubMesh(), "ellipsoide")
80 putName(algo3d, "algo3d_ellipsoide")
81 putName(hypo3d, "hypo3d_ellipsoide")
83 algo3d = bloc1.Prism(geom=tore)
84 algo2d = bloc1.Quadrangle(geom=tore)
85 algo1d = bloc1.Segment(geom=tore)
86 hypo1d = algo1d.NumberOfSegments(nbsegGen)
87 putName(algo3d.GetSubMesh(), "tore")
88 putName(algo3d, "algo3d_tore")
89 putName(algo2d, "algo2d_tore")
90 putName(algo1d, "algo1d_tore")
91 putName(hypo1d, "hypo1d_tore")
93 for i_aux, faces_i in enumerate(faces):
94 algo2d = bloc1.Quadrangle(geom=faces_i)
95 hypo2d = smesh.CreateHypothesis('QuadrangleParams')
96 hypo2d.SetTriaVertex( geompy.GetSubShapeID(blocPartition,centres[i_aux]) )
97 hypo2d.SetQuadType( StdMeshersBuilder.QUAD_STANDARD )
98 _ = bloc1.AddHypothesis(hypo2d,faces_i)
99 putName(algo2d.GetSubMesh(), "faces", i_aux)
100 putName(algo2d, "algo2d_faces", i_aux)
101 putName(hypo2d, "hypo2d_faces", i_aux)
103 for i_aux, edges_i in enumerate(edges):
104 algo1d = bloc1.Segment(geom=edges_i)
105 if reverses[i_aux] > 0:
106 hypo1d = algo1d.NumberOfSegments(nbsegRad, scaleRad,[ geompy.GetSubShapeID(blocPartition,edges_i) ])
108 hypo1d = algo1d.NumberOfSegments(nbsegRad, scaleRad,[ ])
109 putName(algo1d.GetSubMesh(), "edges", i_aux)
110 putName(algo1d, "algo1d_edges", i_aux)
111 putName(hypo1d, "hypo1d_edges", i_aux)
113 for i_aux, circles_i in enumerate(circles):
114 algo1d = bloc1.Segment(geom=circles_i)
115 hypo1d = algo1d.NumberOfSegments(nbsegCercle)
116 putName(algo1d.GetSubMesh(), "circles", i_aux)
117 putName(algo1d, "algo1d_circles", i_aux)
118 putName(hypo1d, "hypo1d_circles", i_aux)
120 if len(edgeext) == 1:
121 densite = int(round(nbsegFis/2))
122 algo1d = bloc1.Segment(geom=edgeext[0])
123 hypo1d = algo1d.NumberOfSegments(nbsegFis)
124 hypo1d.SetDistrType( 2 )
125 hypo1d.SetConversionMode( 1 )
126 hypo1d.SetTableFunction( [ 0, densite, 0.4, 1, 0.6, 1, 1, densite ] )
127 putName(algo1d.GetSubMesh(), "edgeext")
128 putName(algo1d, "algo1d_edgeext")
129 putName(hypo1d, "hypo1d_edgeext")
132 longEdgeExts = list()
133 for edgeext_i in edgeext:
134 props = geompy.BasicProperties(edgeext_i)
135 longEdgeExts.append(props[0])
136 longTotal += props[0]
137 for i_aux, edgeext_i in enumerate(edgeext):
138 nbLocal = int(round(nbsegFis*longEdgeExts[i_aux]/longTotal))
139 densite = int(round(nbLocal/2))
140 algo1d = bloc1.Segment(geom=edgeext_i)
141 hypo1d = algo1d.NumberOfSegments(nbLocal)
142 hypo1d.SetDistrType( 2 )
143 hypo1d.SetConversionMode( 1 )
144 hypo1d.SetTableFunction( [ 0, densite, 0.8, 1, 1, 1 ] )
146 hypo1d.SetReversedEdges([ geompy.GetSubShapeID(blocPartition, edgeext_i) ])
147 putName(algo1d.GetSubMesh(), "edgeext", i_aux)
148 putName(algo1d, "algo1d_edgeext", i_aux)
149 putName(hypo1d, "hypo1d_edgeext", i_aux)
151 algo2d = bloc1.Triangle(algo=smeshBuilder.NETGEN_2D, geom=facefissoutore)
152 hypo2d = algo2d.LengthFromEdges()
153 putName(algo2d.GetSubMesh(), "facefissoutore")
154 putName(algo2d, "algo2d_facefissoutore")
155 putName(hypo2d, "hypo2d_facefissoutore")
158 maxElemArea = 0.5*dmoyen*dmoyen
159 logging.debug("dmoyen %s, maxElemArea %s", dmoyen, maxElemArea)
161 for i_aux, facesExternes_i in enumerate(facesExternes):
162 algo2d = bloc1.Triangle(algo=smeshBuilder.NETGEN_2D, geom=facesExternes_i)
163 hypo2d = algo2d.MaxElementArea(maxElemArea)
164 if edgesBords is None:
165 algo1d = bloc1.Segment(geom=facesExternes_i)
166 hypo1d = algo1d.NumberOfSegments(1)
167 putName(algo2d.GetSubMesh(), "facesExternes", i_aux)
168 putName(algo2d, "algo2d_facesExternes", i_aux)
169 putName(hypo2d, "hypo2d_facesExternes", i_aux)
170 if edgesBords is None:
171 putName(algo1d, "algo1d_facesExternes", i_aux)
172 putName(hypo1d, "hypo1d_facesExternes", i_aux)
174 for i_aux, aretesInternes_i in enumerate(aretesInternes):
175 algo1d = bloc1.Segment(geom=aretesInternes_i)
176 hypo1d = algo1d.NumberOfSegments(nbsegExt)
177 putName(algo1d.GetSubMesh(), "aretesInternes", i_aux)
178 putName(algo1d, "algo1d_aretesInternes", i_aux)
179 putName(hypo1d, "hypo1d_aretesInternes", i_aux)
181 if edgesBords is not None:
182 algo1d = bloc1.UseExisting1DElements(geom=edgesBords)
183 hypo1d = algo1d.SourceEdges([ bordsLibres ],0,0)
184 putName(algo1d.GetSubMesh(), "bordsLibres")
185 putName(algo1d, "algo1d_bordsLibres")
186 putName(hypo1d, "hypo1d_bordsLibres")
188 if not declareAlgoEllipsoideFirst:
189 algo3d = bloc1.Tetrahedron(algo=smeshBuilder.NETGEN,geom=ellipsoidep)
190 hypo3d = algo3d.MaxElementVolume(1000.0)
191 putName(algo3d.GetSubMesh(), "ellipsoide")
192 putName(algo3d, "algo3d_ellipsoide")
193 putName(hypo3d, "hypo3d_ellipsoide")
195 _ = bloc1.GroupOnGeom(faceFissure,'FACE1',SMESH.FACE)
196 _ = bloc1.GroupOnGeom(gencnt,'nfondfis',SMESH.NODE)
198 groups_faceCommuneEllipsoideBloc = list()
199 for i_aux, sharedFaces_i in enumerate(sharedFaces):
200 name = "faceCommuneEllipsoideBloc_{}".format(i_aux)
201 groups_faceCommuneEllipsoideBloc.append(bloc1.GroupOnGeom(sharedFaces_i, name, SMESH.FACE))
202 groups_faceExterneBloc = list()
203 for i_aux, facesExtBloc_i in enumerate(facesExtBloc):
204 name = "faceExterneBloc_{}".format(i_aux)
205 groups_faceExterneBloc.append(bloc1.GroupOnGeom(facesExtBloc_i, name, SMESH.FACE))
207 is_done = bloc1.Compute()
208 text = "bloc1.Compute"
210 logging.info(text+" OK")
212 text = "Erreur au calcul du maillage.\n" + text
214 raise Exception(text)
216 _ = bloc1.RemoveOrphanNodes()
218 skinBlocMeshes = list()
219 for i_aux, groups_faceCommuneEllipsoideBloc_i in enumerate(groups_faceCommuneEllipsoideBloc):
220 name = "faceCommuneEllipsoideBloc_{}".format(i_aux)
221 skinBlocMeshes.append(smesh.CopyMesh(groups_faceCommuneEllipsoideBloc_i, name, 0, 0))
222 for i_aux, groups_faceExterneBloc_i in enumerate(groups_faceExterneBloc):
223 name = "faceExterneBloc_{}".format(i_aux)
224 skinBlocMeshes.append(smesh.CopyMesh(groups_faceExterneBloc_i, name, 0, 0))
226 meshesBloc = [internalBoundary.GetMesh()]
227 for skinBlocMeshes_i in skinBlocMeshes:
228 meshesBloc.append(skinBlocMeshes_i.GetMesh())
229 blocMesh = smesh.Concatenate(meshesBloc, 1, 1, 1e-05,False)
231 algo3d = blocMesh.Tetrahedron(algo=smeshBuilder.NETGEN)
232 hypo3d = algo3d.MaxElementVolume(1000.0)
233 putName(algo3d.GetSubMesh(), "bloc")
234 putName(algo3d, "algo3d_bloc")
235 putName(hypo3d, "hypo3d_bloc")
237 is_done = blocMesh.Compute()
238 text = "blocMesh.Compute"
240 logging.info(text+" OK")
242 text = "Erreur au calcul du maillage.\n" + text
244 raise Exception(text)
246 blocComplet = smesh.Concatenate([bloc1.GetMesh(), blocMesh.GetMesh()], 1, 1, 1e-05,False)
248 return bloc1, blocComplet