Salome HOME
Mise à niveau python
[modules/smesh.git] / src / Tools / blocFissure / gmu / insereFissureLongue_c.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2020  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 """Insertion de fissure longue - maillage pipe fond fissure"""
21
22 import logging
23 import math
24
25 import salome
26 from salome.smesh import smeshBuilder
27 import SMESH
28
29 from .geomsmesh import geompy
30 from .geomsmesh import smesh
31
32 from .sortEdges import sortEdges
33 from .putName import putName
34 from .distance2 import distance2
35
36 def insereFissureLongue_c (pipeFondFiss, disques, rayons, demiCercles, demiCerclesPeau, generatrices, \
37                            VerticesEndPipeFiss, verticesEdgePeauFiss, \
38                            groupFaceFissInPipe, groupEdgeFondFiss, groupsDemiCerclesPipe, groupGenerFiss, \
39                            profondeur, rayonPipe):
40   """maillage pipe fond fissure"""
41   logging.info('start')
42
43   meshFondFiss = smesh.Mesh(pipeFondFiss)
44   algo2d = meshFondFiss.Quadrangle(algo=smeshBuilder.QUADRANGLE)
45   algo3d = meshFondFiss.Prism()
46   putName(algo3d.GetSubMesh(), "pipe")
47   putName(algo3d, "algo3d_pipe")
48   putName(algo2d, "algo2d_pipe")
49
50   for i, face in enumerate(disques):
51     algo2d = meshFondFiss.Quadrangle(algo=smeshBuilder.RADIAL_QUAD,geom=face)
52     putName(algo2d.GetSubMesh(), "disque", i)
53     putName(algo2d, "algo2d_disque", i)
54
55   for i, edge in enumerate(rayons):
56     algo1d = meshFondFiss.Segment(geom=edge)
57     hypo1d = algo1d.NumberOfSegments(4)
58     putName(algo1d.GetSubMesh(), "rayon", i)
59     putName(algo1d, "algo1d_rayon", i)
60     putName(hypo1d, "hypo1d_rayon", i)
61
62   for i, edge in enumerate(demiCercles):
63     algo1d = meshFondFiss.Segment(geom=edge)
64     hypo1d = algo1d.NumberOfSegments(6)
65     putName(algo1d.GetSubMesh(), "demiCercle", i)
66     putName(algo1d, "algo1d_demiCercle", i)
67     putName(hypo1d, "hypo1d_demiCercle", i)
68
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
71   nbSegGenBout = 6
72   logging.info("min %s, max %s, nombre de segments %s, nombre de generatrices %s", minlg, maxlg, nbSegGenLong, len(generSorted))
73   for i, edge in enumerate(generSorted):
74     algo1d = meshFondFiss.Segment(geom=edge)
75     if i < 6:
76       hypo1d = algo1d.NumberOfSegments(nbSegGenBout)
77     else:
78       hypo1d = algo1d.NumberOfSegments(nbSegGenLong)
79     putName(algo1d.GetSubMesh(), "generatrice", i)
80     putName(algo1d, "algo1d_generatrice", i)
81     putName(hypo1d, "hypo1d_generatrice", i)
82
83   disks = list()
84   for i, face in enumerate(disques[:4]):
85     name = "disk%d"%i
86     disks.append(meshFondFiss.GroupOnGeom(face, name, SMESH.FACE))
87   _ = meshFondFiss.GetMesh().UnionListOfGroups( disks, 'PEAUEXT' )
88
89   _ = meshFondFiss.GroupOnGeom(VerticesEndPipeFiss[0], "PFOR", SMESH.NODE)
90   _ = meshFondFiss.GroupOnGeom(VerticesEndPipeFiss[1], "PFEX", SMESH.NODE)
91
92   _ = meshFondFiss.GroupOnGeom(groupFaceFissInPipe, "fisInPi", SMESH.FACE)
93   _ = meshFondFiss.GroupOnGeom(groupEdgeFondFiss, "FONDFISS", SMESH.EDGE)
94   _ = meshFondFiss.GroupOnGeom(groupEdgeFondFiss, "nfondfis", SMESH.NODE)
95
96   groups_demiCercles = list()
97   groupnodes_demiCercles = list()
98   for i, group in enumerate(groupsDemiCerclesPipe):
99     name = "Cercle%d"%i
100     groups_demiCercles.append(meshFondFiss.GroupOnGeom(group, name, SMESH.EDGE))
101     name = "nCercle%d"%i
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)
105
106   is_done = meshFondFiss.Compute()
107   text = "meshFondFiss.Compute"
108   if is_done:
109     logging.info(text+" OK")
110   else:
111     text = "Erreur au calcul du maillage.\n" + text
112     logging.info(text)
113     raise Exception(text)
114
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)
119   coordsMesh = list()
120   coordsMesh.append(meshFondFiss.GetNodeXYZ(idNode0))
121   coordsMesh.append(meshFondFiss.GetNodeXYZ(idNode1))
122
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])
129
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])
134       minDist = 100000
135       minCoord = None
136       imin = -1
137       for i, edge in enumerate(demiCerclesPeau):
138         discoord = geompy.MinDistanceComponents(vertex, edge)
139         if discoord[0] <minDist:
140           minDist = discoord[0]
141           minCoord = discoord[1:]
142           imin = i
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])
146
147   return meshFondFiss, groups_demiCercles, group_generFiss, nbSegGenLong, nbSegGenBout