Salome HOME
Merge branch 'master' into gni/evolution
[modules/smesh.git] / src / Tools / blocFissure / gmu / insereFissureLongue_a.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 salome
24 from .geomsmesh import geompy
25 from .geomsmesh import smesh
26 from salome.smesh import smeshBuilder
27 import SMESH
28
29 from .sortEdges import sortEdges
30 from .putName import putName
31
32 import math
33
34 def insereFissureLongue_a (pipeFondFiss, disques, rayons, demiCercles, demiCerclesPeau, generatrices, \
35                            VerticesEndPipeFiss, verticesEdgePeauFiss, \
36                            groupFaceFissInPipe, groupEdgeFondFiss, groupsDemiCerclesPipe, groupGenerFiss, \
37                            profondeur, rayonPipe, distance2):
38   """maillage pipe fond fissure"""
39   logging.info('start')
40
41   meshFondFiss = smesh.Mesh(pipeFondFiss)
42   algo2d = meshFondFiss.Quadrangle(algo=smeshBuilder.QUADRANGLE)
43   algo3d = meshFondFiss.Prism()
44   putName(algo3d.GetSubMesh(), "pipe")
45   putName(algo3d, "algo3d_pipe")
46   putName(algo2d, "algo2d_pipe")
47
48   for i, face in enumerate(disques):
49     algo2d = meshFondFiss.Quadrangle(algo=smeshBuilder.RADIAL_QUAD,geom=face)
50     putName(algo2d.GetSubMesh(), "disque", i)
51     putName(algo2d, "algo2d_disque", i)
52
53   for i, edge in enumerate(rayons):
54     algo1d = meshFondFiss.Segment(geom=edge)
55     hypo1d = algo1d.NumberOfSegments(4)
56     putName(algo1d.GetSubMesh(), "rayon", i)
57     putName(algo1d, "algo1d_rayon", i)
58     putName(hypo1d, "hypo1d_rayon", i)
59
60   for i, edge in enumerate(demiCercles):
61     algo1d = meshFondFiss.Segment(geom=edge)
62     hypo1d = algo1d.NumberOfSegments(6)
63     putName(algo1d.GetSubMesh(), "demiCercle", i)
64     putName(algo1d, "algo1d_demiCercle", i)
65     putName(hypo1d, "hypo1d_demiCercle", i)
66
67   generSorted, minlg, maxlg = sortEdges(generatrices)
68   nbSegGenLong = int(math.sqrt(3.0)*maxlg/(profondeur - rayonPipe)) # on veut 2 triangles equilateraux dans la largeur de la face
69   nbSegGenBout = 6
70   logging.info("min %s, max %s, nombre de segments %s, nombre de generatrices %s", minlg, maxlg, nbSegGenLong, len(generSorted))
71   for i, edge in enumerate(generSorted):
72     algo1d = meshFondFiss.Segment(geom=edge)
73     if i < 6:
74       hypo1d = algo1d.NumberOfSegments(nbSegGenBout)
75     else:
76       hypo1d = algo1d.NumberOfSegments(nbSegGenLong)
77     putName(algo1d.GetSubMesh(), "generatrice", i)
78     putName(algo1d, "algo1d_generatrice", i)
79     putName(hypo1d, "hypo1d_generatrice", i)
80
81   disks = list()
82   for i, face in enumerate(disques[:4]):
83     name = "disk%d"%i
84     disks.append(meshFondFiss.GroupOnGeom(face, name, SMESH.FACE))
85   _ = meshFondFiss.GetMesh().UnionListOfGroups( disks, 'PEAUEXT' )
86
87   _ = meshFondFiss.GroupOnGeom(VerticesEndPipeFiss[0], "PFOR", SMESH.NODE)
88   _ = meshFondFiss.GroupOnGeom(VerticesEndPipeFiss[1], "PFEX", SMESH.NODE)
89
90   _ = meshFondFiss.GroupOnGeom(groupFaceFissInPipe, "fisInPi", SMESH.FACE)
91   _ = meshFondFiss.GroupOnGeom(groupEdgeFondFiss, "FONDFISS", SMESH.EDGE)
92   _ = meshFondFiss.GroupOnGeom(groupEdgeFondFiss, "nfondfis", SMESH.NODE)
93
94   groups_demiCercles = list()
95   groupnodes_demiCercles = list()
96   for i, group in enumerate(groupsDemiCerclesPipe):
97     name = "Cercle%d"%i
98     groups_demiCercles.append(meshFondFiss.GroupOnGeom(group, name, SMESH.EDGE))
99     name = "nCercle%d"%i
100     groupnodes_demiCercles.append(meshFondFiss.GroupOnGeom(group, name, SMESH.NODE))
101   group_generFiss = meshFondFiss.GroupOnGeom(groupGenerFiss, "GenFiss", SMESH.EDGE)
102   groupnode_generFiss = meshFondFiss.GroupOnGeom(groupGenerFiss, "GenFiss", SMESH.NODE)
103
104   is_done = meshFondFiss.Compute()
105   text = "meshFondFiss.Compute"
106   if is_done:
107     logging.info(text+" OK")
108   else:
109     text = "Erreur au calcul du maillage.\n" + text
110     logging.info(text)
111     raise Exception(text)
112
113   grpNode0 = meshFondFiss.IntersectGroups(groupnode_generFiss, groupnodes_demiCercles[0], "Node0")
114   grpNode1 = meshFondFiss.IntersectGroups(groupnode_generFiss, groupnodes_demiCercles[1], "Node1")
115   idNode0 = grpNode0.GetID(1)
116   idNode1 = grpNode1.GetID(1)
117   coordsMesh = list()
118   coordsMesh.append(meshFondFiss.GetNodeXYZ(idNode0))
119   coordsMesh.append(meshFondFiss.GetNodeXYZ(idNode1))
120
121   for vertex in verticesEdgePeauFiss:
122     coord = geompy.PointCoordinates(vertex)
123     if distance2(coord, coordsMesh[0]) < 0.1:
124       meshFondFiss.MoveNode(idNode0, coord[0], coord[1], coord[2])
125     if distance2(coord, coordsMesh[1]) < 0.1:
126       meshFondFiss.MoveNode(idNode1, coord[0], coord[1], coord[2])
127
128   for groupNodes in groupnodes_demiCercles:
129     for idNode in groupNodes.GetListOfID():
130       coordMesh = meshFondFiss.GetNodeXYZ(idNode)
131       vertex = geompy.MakeVertex(coordMesh[0], coordMesh[1], coordMesh[2])
132       minDist = 100000
133       minCoord = None
134       imin = -1
135       for i, edge in enumerate(demiCerclesPeau):
136         discoord = geompy.MinDistanceComponents(vertex, edge)
137         if discoord[0] <minDist:
138           minDist = discoord[0]
139           minCoord = discoord[1:]
140           imin = i
141       if imin >= 0 and minDist > 1.E-6:
142         logging.debug("node id moved : %s distance=%s", idNode, minDist)
143         meshFondFiss.MoveNode(idNode, coordMesh[0] + minCoord[0], coordMesh[1] + minCoord[1], coordMesh[2] + minCoord[2])
144
145   return meshFondFiss, groups_demiCercles, group_generFiss, nbSegGenLong, nbSegGenBout