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