1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2023 EDF
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 """Insertion de fissure longue - maillage pipe fond fissure"""
25 from salome.smesh import smeshBuilder
28 from .geomsmesh import geompy
29 from .geomsmesh import smesh
31 from .sortEdges import sortEdges
32 from .putName import putName
33 from .distance2 import distance2
35 def insereFissureLongue_c (pipeFondFiss, disques, rayons, demiCercles, demiCerclesPeau, generatrices, \
36 VerticesEndPipeFiss, verticesEdgePeauFiss, \
37 groupFaceFissInPipe, groupEdgeFondFiss, groupsDemiCerclesPipe, groupGenerFiss, \
38 profondeur, rayonPipe, \
40 """maillage pipe fond fissure"""
42 logging.info("Maillage pour le cas n°%s", nro_cas)
44 meshFondFiss = smesh.Mesh(pipeFondFiss)
45 putName(meshFondFiss, "pipeFondFiss", i_pref=nro_cas)
47 algo3d = meshFondFiss.Prism()
49 algo2d = meshFondFiss.Quadrangle(algo=smeshBuilder.QUADRANGLE)
51 for i_aux, face in enumerate(disques):
53 # la commande suivante entraîne addToStudy() failed
54 algo2d = meshFondFiss.Quadrangle(algo=smeshBuilder.RADIAL_QUAD,geom=face)
55 putName(algo2d.GetSubMesh(), "disque", i_aux, nro_cas)
57 for i_aux, edge in enumerate(rayons):
58 algo1d = meshFondFiss.Segment(geom=edge)
59 putName(algo1d.GetSubMesh(), "rayon", i_aux, nro_cas)
60 hypo1d = algo1d.NumberOfSegments(4)
61 putName(hypo1d, "rayon={}".format(4), i_aux, nro_cas)
63 for i_aux, edge in enumerate(demiCercles):
64 algo1d = meshFondFiss.Segment(geom=edge)
65 putName(algo1d.GetSubMesh(), "demiCercle", i_aux, nro_cas)
66 hypo1d = algo1d.NumberOfSegments(6)
67 putName(hypo1d, "demiCercle={}".format(6), i_aux, nro_cas)
69 generSorted, minlg, maxlg = sortEdges(generatrices)
70 nbSegGenLong = int(math.sqrt(3.0)*maxlg/(profondeur - rayonPipe)) # on veut 2 triangles equilateraux dans la largeur de la face
72 logging.info("min %s, max %s, nombre de segments %s, nombre de generatrices %s", minlg, maxlg, nbSegGenLong, len(generSorted))
73 for i_aux, edge in enumerate(generSorted):
74 algo1d = meshFondFiss.Segment(geom=edge)
75 putName(algo1d.GetSubMesh(), "generatrice", i_aux, nro_cas)
80 hypo1d = algo1d.NumberOfSegments(nbSeg)
81 putName(hypo1d, "generatrice={}".format(nbSeg), i_aux, nro_cas)
84 for i_aux, face in enumerate(disques[:4]):
85 name = "disk{}".format(i_aux)
86 disks.append(meshFondFiss.GroupOnGeom(face, name, SMESH.FACE))
87 _ = meshFondFiss.GetMesh().UnionListOfGroups( disks, 'PEAUEXT' )
89 _ = meshFondFiss.GroupOnGeom(VerticesEndPipeFiss[0], "PFOR", SMESH.NODE)
90 _ = meshFondFiss.GroupOnGeom(VerticesEndPipeFiss[1], "PFEX", SMESH.NODE)
92 _ = meshFondFiss.GroupOnGeom(groupFaceFissInPipe, "fisInPi", SMESH.FACE)
93 _ = meshFondFiss.GroupOnGeom(groupEdgeFondFiss, "FONDFISS", SMESH.EDGE)
94 _ = meshFondFiss.GroupOnGeom(groupEdgeFondFiss, "nfondfis", SMESH.NODE)
96 groups_demiCercles = list()
97 groupnodes_demiCercles = list()
98 for i_aux, group in enumerate(groupsDemiCerclesPipe):
99 name = "Cercle{}".format(i_aux)
100 groups_demiCercles.append(meshFondFiss.GroupOnGeom(group, name, SMESH.EDGE))
101 name = "nCercle{}".format(i_aux)
102 groupnodes_demiCercles.append(meshFondFiss.GroupOnGeom(group, name, SMESH.NODE))
103 group_generFiss = meshFondFiss.GroupOnGeom(groupGenerFiss, "GenFiss", SMESH.EDGE)
104 groupnode_generFiss = meshFondFiss.GroupOnGeom(groupGenerFiss, "GenFiss", SMESH.NODE)
106 is_done = meshFondFiss.Compute()
107 text = "meshFondFiss.Compute"
109 logging.info(text+" OK")
111 text = "Erreur au calcul du maillage.\n" + text
113 raise Exception(text)
115 grpNode0 = meshFondFiss.IntersectGroups(groupnode_generFiss, groupnodes_demiCercles[0], "Node0")
116 grpNode1 = meshFondFiss.IntersectGroups(groupnode_generFiss, groupnodes_demiCercles[1], "Node1")
117 idNode0 = grpNode0.GetID(1)
118 idNode1 = grpNode1.GetID(1)
120 coordsMesh.append(meshFondFiss.GetNodeXYZ(idNode0))
121 coordsMesh.append(meshFondFiss.GetNodeXYZ(idNode1))
123 for vertex in verticesEdgePeauFiss:
124 coord = geompy.PointCoordinates(vertex)
125 if distance2(coord, coordsMesh[0]) < 0.1:
126 meshFondFiss.MoveNode(idNode0, coord[0], coord[1], coord[2])
127 if distance2(coord, coordsMesh[1]) < 0.1:
128 meshFondFiss.MoveNode(idNode1, coord[0], coord[1], coord[2])
130 for groupNodes in groupnodes_demiCercles:
131 for idNode in groupNodes.GetListOfID():
132 coordMesh = meshFondFiss.GetNodeXYZ(idNode)
133 vertex = geompy.MakeVertex(coordMesh[0], coordMesh[1], coordMesh[2])
137 for i_aux, edge in enumerate(demiCerclesPeau):
138 discoord = geompy.MinDistanceComponents(vertex, edge)
139 if discoord[0] <minDist:
140 minDist = discoord[0]
141 minCoord = discoord[1:]
143 if imin >= 0 and minDist > 1.E-6:
144 logging.debug("node id moved : %s distance=%s", idNode, minDist)
145 meshFondFiss.MoveNode(idNode, coordMesh[0] + minCoord[0], coordMesh[1] + minCoord[1], coordMesh[2] + minCoord[2])
147 return meshFondFiss, groups_demiCercles, group_generFiss, nbSegGenLong, nbSegGenBout