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