Salome HOME
Copyright update 2021
[modules/smesh.git] / src / Tools / blocFissure / gmu / calculePointsAxiauxPipe.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2021  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
21 import logging
22 import math
23
24 from .geomsmesh import geompy
25 from .geomsmesh import smesh
26   
27 def calculePointsAxiauxPipe(edgesFondFiss, edgesIdByOrientation, facesDefaut, 
28                             centreFondFiss, wireFondFiss, wirePipeFiss,
29                             lenSegPipe, rayonPipe, nbsegCercle, nbsegRad):
30   """
31   preparation maillage du pipe :
32   - détections des points a respecter : jonction des edges/faces constituant
33     la face de fissure externe au pipe
34   - points sur les edges de fond de fissure et edges pipe/face fissure,
35   - vecteurs tangents au fond de fissure (normal au disque maillé)  
36   """
37   
38   logging.info('start')
39
40   # --- option de maillage selon le rayon de courbure du fond de fissure 
41   lenEdgeFondExt = 0
42   for edff in edgesFondFiss:
43     lenEdgeFondExt += geompy.BasicProperties(edff)[0]
44   
45   disfond = []
46   for filling in facesDefaut:
47     disfond.append(geompy.MinDistance(centreFondFiss, filling))
48   disfond.sort()
49   rcourb = disfond[0]
50   nbSegQuart = 5 # on veut 5 segments min sur un quart de cercle
51   alpha = math.pi/(4*nbSegQuart)
52   deflexion = rcourb*(1.0 -math.cos(alpha))
53   lgmin = lenSegPipe*0.25
54   lgmax = lenSegPipe*1.5               
55   logging.debug("rcourb: %s, lenFond:%s, deflexion: %s, lgmin: %s, lgmax: %s", rcourb, lenEdgeFondExt, deflexion, lgmin, lgmax)  
56
57   meshFondExt = smesh.Mesh(wireFondFiss)
58   algo1d = meshFondExt.Segment()
59   hypo1d = algo1d.Adaptive(lgmin, lgmax, deflexion) # a ajuster selon la profondeur de la fissure
60   isDone = meshFondExt.Compute()
61   
62   ptGSdic = {} # dictionnaire [paramètre sur la courbe] --> point géométrique
63   allNodeIds = meshFondExt.GetNodesId()
64   for nodeId in allNodeIds:
65     xyz = meshFondExt.GetNodeXYZ(nodeId)
66     #logging.debug("nodeId %s, coords %s", nodeId, str(xyz))
67     pt = geompy.MakeVertex(xyz[0], xyz[1], xyz[2])
68     u, PointOnEdge, EdgeInWireIndex = geompy.MakeProjectionOnWire(pt, wireFondFiss) # u compris entre 0 et 1
69     edgeOrder = edgesIdByOrientation[EdgeInWireIndex]
70     ptGSdic[(edgeOrder, EdgeInWireIndex, u)] = pt
71     #logging.debug("nodeId %s, u %s", nodeId, str(u))
72   usort = sorted(ptGSdic)  
73   logging.debug("nombre de points obtenus par deflexion %s",len(usort))
74      
75   centres = []
76   origins = []
77   normals = []      
78   for edu in usort:
79     ied = edu[1]
80     u = edu[2]
81     vertcx = ptGSdic[edu]
82     norm = geompy.MakeTangentOnCurve(edgesFondFiss[ied], u)
83     plan = geompy.MakePlane(vertcx, norm, 3*rayonPipe)
84     part = geompy.MakePartition([plan], [wirePipeFiss], [], [], geompy.ShapeType["VERTEX"], 0, [], 0)
85     liste = geompy.ExtractShapes(part, geompy.ShapeType["VERTEX"], True)
86     if len(liste) == 5: # 4 coins du plan plus intersection recherchée
87       for point in liste:
88         if geompy.MinDistance(point, vertcx) < 1.1*rayonPipe: # les quatre coins sont plus loin
89           vertpx = point
90           break
91       centres.append(vertcx)
92       origins.append(vertpx)
93       normals.append(norm)
94 #      name = "vertcx%d"%i
95 #      geompy.addToStudyInFather(wireFondFiss, vertcx, name)
96 #      name = "vertpx%d"%i
97 #      geompy.addToStudyInFather(wireFondFiss, vertpx, name)
98 #      name = "plan%d"%i
99 #      geompy.addToStudyInFather(wireFondFiss, plan, name)
100
101   # --- maillage du pipe étendu, sans tenir compte de l'intersection avec la face de peau
102       
103   logging.debug("nbsegCercle %s", nbsegCercle)
104   
105   # -----------------------------------------------------------------------
106   # --- points géométriques
107   
108   gptsdisks = [] # vertices géométrie de tous les disques
109   raydisks = [[] for i in range(nbsegCercle)]
110   for i in range(len(centres)): # boucle sur les disques
111     gptdsk = [] # vertices géométrie d'un disque
112     vertcx = centres[i]
113     vertpx = origins[i]
114     normal = normals[i]
115     vec1 = geompy.MakeVector(vertcx, vertpx)
116     
117     points = [vertcx] # les points du rayon de référence
118     for j in range(nbsegRad):
119       pt = geompy.MakeTranslationVectorDistance(vertcx, vec1, (j+1)*float(rayonPipe)/nbsegRad)
120       points.append(pt)
121     gptdsk.append(points)
122     pt = geompy.MakeTranslationVectorDistance(vertcx, vec1, 1.5*rayonPipe)
123     rayon = geompy.MakeLineTwoPnt(vertcx, pt)
124     raydisks[0].append(rayon)
125     
126     for k in range(nbsegCercle-1):
127       angle = (k+1)*2*math.pi/nbsegCercle
128       pts = [vertcx] # les points d'un rayon obtenu par rotation
129       for j in range(nbsegRad):
130         pt = geompy.MakeRotation(points[j+1], normal, angle)
131         pts.append(pt)
132       gptdsk.append(pts)
133       ray = geompy.MakeRotation(rayon, normal, angle)
134       raydisks[k+1].append(ray)
135       
136     gptsdisks.append(gptdsk)
137     
138   return (centres, gptsdisks, raydisks)