Salome HOME
Corrections cas-tests 14 et 27
[modules/smesh.git] / src / Tools / blocFissure / materielCasTests / tube.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 """Géométrie et maillage de base nécessaire au cas-test :
21 . tube
22 """
23
24 __revision__ = "V02.08"
25
26 import os
27
28 import logging
29
30 import salome
31 from salome.shaper import model
32 from salome.smesh import smeshBuilder
33 from SketchAPI import *
34 import SHAPERSTUDY
35 import SMESH
36
37 from blocFissure import gmu
38 from blocFissure.gmu.putName import putName
39
40 #=============== Options ====================
41 # 1. NOM_OBJET = nom de l'objet
42 NOM_OBJET = "Tube"
43 # 2. CAO
44 # 2.1. Le tube : rayon intérieur, rayon extérieur, hauteur
45 RAYON_INT =  9.84
46 RAYON_EXT = 11.11
47 HAUTEUR = 50.
48 # 2.2. La fissure :
49 F_L_1 = 80.
50 F_THETA_1 = 3.
51 F_C_1 = 1.04
52 F_L_2 = 20.
53 F_C_3 = 0.99
54 # 3. Maillage
55 # Nombre de segments du tube
56 NB_S_E = 4
57 NB_S_H = 60
58 NB_S_P = 30
59 #============================================
60
61 salome.salome_init()
62
63 ###
64 ### SHAPER component
65 ###
66
67 model.begin()
68 partSet = model.moduleDocument()
69
70 ### Create Part
71 Part_1 = model.addPart(partSet)
72 Part_1_doc = Part_1.document()
73 model.addParameter(Part_1_doc, "R_I", "%f" % RAYON_INT)
74 model.addParameter(Part_1_doc, "R_E", "%f" % RAYON_EXT)
75 model.addParameter(Part_1_doc, "H", "%f" % HAUTEUR)
76 model.addParameter(Part_1_doc, "F_L_1", "{}".format(F_L_1))
77 model.addParameter(Part_1_doc, "F_THETA_1", "{}".format(F_THETA_1))
78 model.addParameter(Part_1_doc, "F_R_1", "{}*{}".format(F_C_1,RAYON_INT))
79 model.addParameter(Part_1_doc, "F_L_2", "{}".format(F_L_2))
80 model.addParameter(Part_1_doc, "F_D_3", "{}*{}".format(F_C_3,RAYON_INT))
81
82 ### Create Sketch
83 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
84
85 ### Create SketchLine
86 SketchLine_1 = Sketch_1.addLine(11.11, -22.82842712474619, 9.84, -22.82842712474619)
87
88 ### Create SketchLine
89 SketchLine_2 = Sketch_1.addLine(9.84, -22.82842712474619, 9.84, 27.17157287525381)
90
91 ### Create SketchLine
92 SketchLine_3 = Sketch_1.addLine(9.84, 27.17157287525381, 11.11, 27.17157287525381)
93
94 ### Create SketchLine
95 SketchLine_4 = Sketch_1.addLine(11.11, 27.17157287525381, 11.11, -22.82842712474619)
96 Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
97 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
98 Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
99 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
100 Sketch_1.setHorizontal(SketchLine_1.result())
101 Sketch_1.setVertical(SketchLine_2.result())
102 Sketch_1.setHorizontal(SketchLine_3.result())
103 Sketch_1.setVertical(SketchLine_4.result())
104 Sketch_1.setLength(SketchLine_4.result(), "H")
105
106 ### Create SketchProjection
107 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
108 SketchPoint_1 = SketchProjection_1.createdFeature()
109 Sketch_1.setHorizontalDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_1.endPoint(), "R_I")
110 Sketch_1.setHorizontalDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_1.startPoint(), "R_E")
111 model.do()
112
113 ### Create Revolution
114 Revolution_1 = model.addRevolution(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r")], model.selection("EDGE", "PartSet/OZ"), 180, 0)
115 Revolution_1.result().setName("Tube")
116 Revolution_1.result().setTransparency(0.37)
117
118 ### Create Sketch
119 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("YOZ"))
120
121 ### Create SketchArc
122 SketchArc_1 = Sketch_2.addArc(-80, 0, 10.10993798722564, 4.722461741385164, 10.10993798722563, -4.722461741385561, True)
123
124 ### Create SketchProjection
125 SketchProjection_2 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/OY"), False)
126 SketchLine_5 = SketchProjection_2.createdFeature()
127 Sketch_2.setCoincident(SketchArc_1.center(), SketchLine_5.result())
128
129 ### Create SketchProjection
130 SketchProjection_3 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
131 SketchPoint_2 = SketchProjection_3.createdFeature()
132 Sketch_2.setHorizontalDistance(SketchArc_1.center(), SketchAPI_Point(SketchPoint_2).coordinates(), "F_L_1")
133
134 ### Create SketchPoint
135 SketchPoint_3 = Sketch_2.addPoint(10.2336, 0)
136 SketchPoint_3.setAuxiliary(True)
137 Sketch_2.setCoincident(SketchPoint_3.coordinates(), SketchArc_1.results()[1])
138 Sketch_2.setMiddlePoint(SketchPoint_3.coordinates(), SketchArc_1.results()[1])
139 Sketch_2.setCoincident(SketchPoint_3.coordinates(), SketchLine_5.result())
140
141 ### Create SketchProjection
142 SketchProjection_4 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
143 SketchPoint_4 = SketchProjection_4.createdFeature()
144 Sketch_2.setHorizontalDistance(SketchPoint_3.coordinates(), SketchAPI_Point(SketchPoint_4).coordinates(), "F_R_1")
145
146 ### Create SketchLine
147 SketchLine_6 = Sketch_2.addLine(-80, 0, 10.10993798722564, 4.722461741385164)
148 SketchLine_6.setAuxiliary(True)
149 Sketch_2.setCoincident(SketchArc_1.center(), SketchLine_6.startPoint())
150 Sketch_2.setCoincident(SketchArc_1.startPoint(), SketchLine_6.endPoint())
151
152 ### Create SketchConstraintAngle
153 Sketch_2.setAngle(SketchLine_5.result(), SketchLine_6.result(), "F_THETA_1", type = "Direct")
154
155 ### Create SketchEllipticArc
156 SketchEllipticArc_1 = Sketch_2.addEllipticArc(-20, 8.956370781951521e-27, -10.21629725685072, 9.783702743149284, 10.10993798723031, 4.722461741243296, 9.7416, 8.052073253504034, False)
157 [SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchPoint_8, SketchPoint_9, SketchPoint_10, SketchPoint_11, SketchLine_7, SketchLine_8] = \
158   SketchEllipticArc_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
159 Sketch_2.setCoincident(SketchEllipticArc_1.startPoint(), SketchLine_6.endPoint())
160 Sketch_2.setCoincident(SketchAPI_Point(SketchPoint_5).coordinates(), SketchLine_5.result())
161 Sketch_2.setTangent(SketchEllipticArc_1.result(), SketchArc_1.results()[1])
162
163 ### Create SketchProjection
164 SketchProjection_5 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
165 SketchPoint_12 = SketchProjection_5.createdFeature()
166 Sketch_2.setHorizontalDistance(SketchAPI_Point(SketchPoint_5).coordinates(), SketchAPI_Point(SketchPoint_12).coordinates(), "F_L_2")
167
168 ### Create SketchConstraintAngle
169 Sketch_2.setAngle(SketchLine_5.result(), SketchLine_7.result(), 45, type = "Supplementary")
170
171 ### Create SketchProjection
172 SketchProjection_6 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
173 SketchPoint_13 = SketchProjection_6.createdFeature()
174 Sketch_2.setHorizontalDistance(SketchEllipticArc_1.endPoint(), SketchAPI_Point(SketchPoint_13).coordinates(), "F_D_3")
175
176 ### Create SketchConstraintMirror
177 SketchConstraintMirror_1 = Sketch_2.addMirror(SketchLine_5.result(), [SketchEllipticArc_1.result()])
178 [SketchEllipticArc_2] = SketchConstraintMirror_1.mirrored()
179
180 ### Create SketchLine
181 SketchLine_9 = Sketch_2.addLine(9.7416, 8.052073253504034, 9.7416, -8.052073253504034)
182 Sketch_2.setCoincident(SketchEllipticArc_1.endPoint(), SketchLine_9.startPoint())
183 Sketch_2.setCoincident(SketchAPI_EllipticArc(SketchEllipticArc_2).endPoint(), SketchLine_9.endPoint())
184 model.do()
185
186 ### Create Face
187 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchArc_1_2r-SketchEllipticArc_1f-SketchLine_9f-SketchEllipticArc_2f")])
188 Face_1.result().setName("Fissure")
189
190 ### Create Group
191 Group_1 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "Fissure/Modified_Edge&Sketch_2/SketchEllipticArc_1")])
192
193 ### Create Group
194 Group_2 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "Fissure/Modified_Edge&Sketch_2/SketchArc_1_2")])
195
196 ### Create Group
197 Group_3 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "Fissure/Modified_Edge&Sketch_2/SketchEllipticArc_2")])
198
199 ### Create Group
200 Group_4 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "Fissure/Modified_Edge&Sketch_2/SketchLine_9")])
201
202 ### Create Group
203 Group_5 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "[Tube/Generated_Face&Sketch_1/SketchLine_1][Tube/From_Face]")])
204 Group_5.setName("Epaisseur")
205 Group_5.result().setName("Epaisseur")
206
207 ### Create Group
208 Group_6 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "[Tube/Generated_Face&Sketch_1/SketchLine_4][Tube/From_Face]")])
209 Group_6.setName("Hauteur")
210 Group_6.result().setName("Hauteur")
211
212 ### Create Group
213 Group_7 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "[Tube/Generated_Face&Sketch_1/SketchLine_4][Tube/Generated_Face&Sketch_1/SketchLine_1]")])
214 Group_7.setName("Peripherie")
215 Group_7.result().setName("Peripherie")
216
217 ### Create Export
218 ficcao = os.path.join(gmu.pathBloc, "materielCasTests", "{}Fiss.xao".format(NOM_OBJET))
219 text = ".. Exportation de la géométrie de la fissure dans le fichier '{}'".format(ficcao)
220 logging.info(text)
221 _ = model.exportToXAO(Part_1_doc, ficcao, model.selection("FACE", "Fissure"), 'XAO')
222
223 model.end()
224
225 ###
226 ### SHAPERSTUDY component
227 ###
228
229 model.publishToShaperStudy()
230
231 l_aux = SHAPERSTUDY.shape(model.featureStringId(Revolution_1))
232 objet = l_aux[0]
233 l_groups = l_aux[1:]
234
235 ###
236 ### SMESH component
237 ###
238
239 smesh = smeshBuilder.New()
240 Maillage_tube = smesh.Mesh(objet)
241 putName(Maillage_tube.GetMesh(), NOM_OBJET)
242
243 for groupe in l_groups:
244   groupe_nom = groupe.GetName()
245   if ( groupe_nom[:1] == "E" ):
246     group_e = groupe
247   elif ( groupe_nom[:1] == "H" ):
248     group_h = groupe
249   elif ( groupe_nom[:1] == "P" ):
250     group_p = groupe
251   _ = Maillage_tube.GroupOnGeom(groupe,groupe_nom,SMESH.EDGE)
252
253 Regular_1D = Maillage_tube.Segment()
254 Nb_Segments_1 = Regular_1D.NumberOfSegments(NB_S_P)
255 Nb_Segments_1.SetDistrType( 0 )
256 Quadrangle_2D = Maillage_tube.Quadrangle(algo=smeshBuilder.QUADRANGLE)
257 Hexa_3D = Maillage_tube.Hexahedron(algo=smeshBuilder.Hexa)
258
259 Regular_1D_1 = Maillage_tube.Segment(geom=group_e)
260 Number_of_Segments_1 = Regular_1D_1.NumberOfSegments(NB_S_E)
261 Propagation_of_1D_Hyp = Regular_1D_1.Propagation()
262
263 Regular_1D_2 = Maillage_tube.Segment(geom=group_h)
264 Number_of_Segments_2 = Regular_1D_2.NumberOfSegments(NB_S_H)
265 Propagation_of_1D_Hyp_1 = Regular_1D_2.Propagation()
266
267 ## set object names
268 #smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
269 #smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
270 #smesh.SetName(Hexa_3D.GetAlgorithm(), 'Hexa_3D')
271 putName(Nb_Segments_1, 'Nb. Segments_1', i_pref='tube')
272 putName(Number_of_Segments_1, 'Number_of_Segments_1', i_pref='tube')
273 putName(Number_of_Segments_2, 'Number_of_Segments_2', i_pref='tube')
274 putName(Propagation_of_1D_Hyp, 'Propagation', i_pref='tube')
275
276 is_done = Maillage_tube.Compute()
277 text = "Maillage_tube.Compute"
278 if is_done:
279   logging.info(text+" OK")
280 else:
281   text = "Erreur au calcul du maillage.\n" + text
282   logging.info(text)
283   raise Exception(text)
284
285 ficmed = os.path.join(gmu.pathBloc, "materielCasTests","{}.med".format(NOM_OBJET))
286 text = ".. Archivage du maillage dans le fichier '{}'".format(ficmed)
287 logging.info(text)
288 Maillage_tube.ExportMED(ficmed)
289
290 if salome.sg.hasDesktop():
291   salome.sg.updateObjBrowser()