Salome HOME
Update of CheckDone
[modules/smesh.git] / src / Tools / blocFissure / materielCasTests / vis.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014-2024  EDF
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 . vis_1
22 """
23
24 import os
25 import math
26
27 import logging
28
29 import salome
30 from salome.smesh import smeshBuilder
31 from salome.StdMeshers import StdMeshersBuilder
32 import GEOM
33 import SMESH
34 import SALOMEDS
35
36 from blocFissure import gmu
37 from blocFissure.gmu.geomsmesh import geompy
38 from blocFissure.gmu.geomsmesh import geomPublish
39 from blocFissure.gmu.geomsmesh import geomPublishInFather
40
41 from blocFissure.gmu.triedreBase import triedreBase
42 from blocFissure.gmu.putName import putName
43 from blocFissure.gmu import initLog
44
45 ###
46 ### GEOM component
47 ###
48
49 O, OX, OY, OZ = triedreBase()
50
51 geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
52 geomObj_2 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
53 sk = geompy.Sketcher2D()
54 sk.addPoint(0.000000, 0.000000)
55 sk.addSegmentAbsolute(10.000000, 0.000000)
56 sk.addSegmentAbsolute(10.000000, 98.750000)
57 sk.addArcAngleRadiusLength(0, -1.250000, 90.000000)
58 sk.addSegmentAbsolute(15.000000, 100.000000)
59 sk.addSegmentAbsolute(15.000000, 120.000000)
60 sk.addSegmentAbsolute(9.945000, 120.000000)
61 sk.addSegmentAbsolute(9.945000, 108.000000)
62 sk.addSegmentAbsolute(0.000000, 105.000000)
63 sk.close()
64 Sketch_1 = sk.wire(geomObj_2)
65 Face_1 = geompy.MakeFaceWires([Sketch_1], 1)
66 Vertex_1 = geompy.MakeVertex(15, 108, 0)
67 Vertex_2 = geompy.MakeVertex(0, 94, 0)
68 Vertex_3 = geompy.MakeVertex(10, 94, 0)
69 Face_1_vertex_17 = geompy.GetSubShape(Face_1, [17])
70 Line_1 = geompy.MakeLineTwoPnt(Vertex_1, Face_1_vertex_17)
71 Face_1_vertex_9 = geompy.GetSubShape(Face_1, [9])
72 Line_2 = geompy.MakeLineTwoPnt(Face_1_vertex_17, Face_1_vertex_9)
73 Face_1_vertex_19 = geompy.GetSubShape(Face_1, [19])
74 Face_1_vertex_7 = geompy.GetSubShape(Face_1, [7])
75 Line_3 = geompy.MakeLineTwoPnt(Face_1_vertex_19, Face_1_vertex_7)
76 Line_4 = geompy.MakeLineTwoPnt(Vertex_2, Vertex_3)
77 coupe_vis = geompy.MakePartition([Face_1], [Line_1, Line_2, Line_3, Line_4], [], [], geompy.ShapeType["FACE"], 0, [], 0)
78 [tige, section, tige_haute, rond, tete, section_tete] = geompy.Propagate(coupe_vis)
79 conge = geompy.CreateGroup(coupe_vis, geompy.ShapeType["EDGE"])
80 geompy.UnionIDs(conge, [25])
81 appui = geompy.CreateGroup(coupe_vis, geompy.ShapeType["EDGE"])
82 geompy.UnionIDs(appui, [39])
83 p_imp = geompy.CreateGroup(coupe_vis, geompy.ShapeType["EDGE"])
84 geompy.UnionIDs(p_imp, [11])
85
86 geomPublish(initLog.debug, Sketch_1, 'Sketch_1' )
87 geomPublish(initLog.debug, Face_1, 'Face_1' )
88 geomPublish(initLog.debug, Vertex_1, 'Vertex_1' )
89 geomPublish(initLog.debug, Vertex_2, 'Vertex_2' )
90 geomPublish(initLog.debug, Vertex_3, 'Vertex_3' )
91 geomPublishInFather(initLog.debug, Face_1, Face_1_vertex_17, 'Face_1:vertex_17' )
92 geomPublish(initLog.debug, Line_1, 'Line_1' )
93 geomPublishInFather(initLog.debug, Face_1, Face_1_vertex_9, 'Face_1:vertex_9' )
94 geomPublish(initLog.debug, Line_2, 'Line_2' )
95 geomPublishInFather(initLog.debug, Face_1, Face_1_vertex_19, 'Face_1:vertex_19' )
96 geomPublishInFather(initLog.debug, Face_1, Face_1_vertex_7, 'Face_1:vertex_7' )
97 geomPublish(initLog.debug, Line_3, 'Line_3' )
98 geomPublish(initLog.debug, Line_4, 'Line_4' )
99
100 geompy.addToStudy( coupe_vis, 'coupe_vis' )
101 geompy.addToStudyInFather( coupe_vis, tige, 'tige' )
102 geompy.addToStudyInFather( coupe_vis, section, 'section' )
103 geompy.addToStudyInFather( coupe_vis, tige_haute, 'tige_haute' )
104 geompy.addToStudyInFather( coupe_vis, rond, 'rond' )
105 geompy.addToStudyInFather( coupe_vis, tete, 'tete' )
106 geompy.addToStudyInFather( coupe_vis, section_tete, 'section_tete' )
107 geompy.addToStudyInFather( coupe_vis, conge, 'conge' )
108 geompy.addToStudyInFather( coupe_vis, appui, 'appui' )
109 geompy.addToStudyInFather( coupe_vis, p_imp, 'p_imp' )
110
111 Vertex_4 = geompy.MakeVertex(11.25, 98.75, 0)
112 Vertex_5 = geompy.MakeVertexWithRef(Vertex_4, -0.5, 0.5, 0)
113 Vertex_6 = geompy.MakeVertexWithRef(Vertex_4, -5, 5, 0)
114 Line_5 = geompy.MakeLineTwoPnt(Vertex_5, Vertex_6)
115 Partition_1 = geompy.MakePartition([Line_5], [conge], [], [], geompy.ShapeType["EDGE"], 0, [], 1)
116 [Vertex_7] = geompy.SubShapes(Partition_1, [4])
117 Vertex_8 = geompy.MakeVertexWithRef(Vertex_7, -1.1, 1.1, 0)
118 generatrice = geompy.MakeLineTwoPnt(Vertex_5, Vertex_8)
119 Revolution_1 = geompy.MakeRevolution2Ways(generatrice, OY, 60*math.pi/180.0)
120 Partition_2 = geompy.MakePartition([Revolution_1], [conge], [], [], geompy.ShapeType["FACE"], 0, [], 1)
121 Partition_2_vertex_11 = geompy.GetSubShape(Partition_2, [11])
122 Plane_1 = geompy.MakePlane(Partition_2_vertex_11, OY, 2000)
123 Partition_3 = geompy.MakePartition([Revolution_1], [Plane_1], [], [], geompy.ShapeType["FACE"], 0, [], 0)
124 Vertex_9 = geompy.MakeVertex(0, 99.633883, 1.977320000000001)
125 Vertex_10 = geompy.MakeVertex(0, 99.633883, -8.977320000000001)
126 Vertex_11 = geompy.MakeVertexWithRef(Vertex_9, 0, 0, -1)
127 Vertex11x = geompy.MakeVertexWithRef(Vertex_11, 1, 0, 0)
128 Line_11x = geompy.MakeLineTwoPnt(Vertex_11, Vertex11x)
129 Vertex_12 = geompy.MakeVertexWithRef(Vertex_10, 0, 0, 1)
130 Vertex12x = geompy.MakeVertexWithRef(Vertex_12, 1, 0, 0)
131 Line_12x = geompy.MakeLineTwoPnt(Vertex_12, Vertex12x)
132 Vertex_13 = geompy.MakeVertexWithRef(Vertex_11, 0, 1, 0)
133 Vertex_14 = geompy.MakeVertexWithRef(Vertex_12, 0, 1, 0)
134 Vertex_15 = geompy.MakeRotation(Vertex_9, Line_11x, 30*math.pi/180.0)
135 Vertex_16 = geompy.MakeRotation(Vertex_10, Line_12x, -30*math.pi/180.0)
136 Arc_1 = geompy.MakeArc(Vertex_15, Vertex_9, Vertex_13,False)
137 Arc_2 = geompy.MakeArc(Vertex_14, Vertex_10, Vertex_16,False)
138 Line_6 = geompy.MakeLineTwoPnt(Vertex_13, Vertex_14)
139 Line_8 = geompy.MakeLineTwoPnt(Vertex_16, Vertex_15)
140 Wire_1 = geompy.MakeWire([Arc_1, Arc_2, Line_6, Line_8], 1e-07)
141 Face_2 = geompy.MakeFaceWires([Wire_1], 1)
142 Extrusion_1 = geompy.MakePrismVecH(Face_2, OX, 15)
143 Revolution_2 = geompy.MakeRevolution2Ways(generatrice, OY, 65*math.pi/180.0)
144 Fissure = geompy.MakeCommonList([Extrusion_1, Revolution_2], True)
145 fondFiss = geompy.CreateGroup(Fissure, geompy.ShapeType["EDGE"])
146 geompy.UnionIDs(fondFiss, [6, 8])
147
148 geomPublish(initLog.debug, Vertex_4, 'Vertex_4' )
149 geomPublish(initLog.debug, Vertex_6, 'Vertex_6' )
150 geomPublish(initLog.debug, Vertex_5, 'Vertex_5' )
151 geomPublish(initLog.debug, Line_5, 'Line_5' )
152 geomPublish(initLog.debug, Partition_1, 'Partition_1' )
153 geomPublishInFather(initLog.debug, Partition_1, Vertex_7, 'Vertex_7' )
154 geomPublish(initLog.debug, Vertex_8, 'Vertex_8' )
155 geomPublish(initLog.debug, generatrice, 'generatrice' )
156 geomPublish(initLog.debug, Revolution_1, 'Revolution_1' )
157 geomPublish(initLog.debug, Partition_2, 'Partition_2' )
158 geomPublishInFather(initLog.debug, Partition_2, Partition_2_vertex_11, 'Partition_2:vertex_11' )
159 geomPublish(initLog.debug, Plane_1, 'Plane_1' )
160 geomPublish(initLog.debug, Partition_3, 'Partition_3' )
161 geomPublish(initLog.debug, Vertex_9, 'Vertex_9' )
162 geomPublish(initLog.debug, Vertex_10, 'Vertex_10' )
163 geomPublish(initLog.debug, Vertex_11, 'Vertex_11' )
164 geomPublish(initLog.debug, Vertex_12, 'Vertex_12' )
165 geomPublish(initLog.debug, Vertex_13, 'Vertex_13' )
166 geomPublish(initLog.debug, Vertex_14, 'Vertex_14' )
167 geomPublish(initLog.debug, Vertex_15, 'Vertex_15' )
168 geomPublish(initLog.debug, Vertex_16, 'Vertex_16' )
169 geomPublish(initLog.debug, Arc_1, 'Arc_1' )
170 geomPublish(initLog.debug, Arc_2, 'Arc_2' )
171 geomPublish(initLog.debug, Line_6, 'Line_6' )
172 geomPublish(initLog.debug, Line_8, 'Line_8' )
173 geomPublish(initLog.debug, Wire_1, 'Wire_1' )
174 geomPublish(initLog.debug, Face_2, 'Face_2' )
175 geomPublish(initLog.debug, Extrusion_1, 'Extrusion_1' )
176 geomPublish(initLog.debug, Revolution_2, 'Revolution_2' )
177 geompy.addToStudy( Fissure, 'vis_Fissure' )
178 geompy.addToStudyInFather( Fissure, fondFiss, 'fondFiss' )
179
180 ficcao = os.path.join(gmu.pathBloc, "materielCasTests", "visFiss.brep")
181 text = ".. Exportation de la géométrie de la fissure dans le fichier '{}'".format(ficcao)
182 logging.info(text)
183 geompy.ExportBREP(Fissure, ficcao)
184
185 ###
186 ### SMESH component
187 ###
188
189 logging.info("Maillage de %s", coupe_vis.GetName())
190
191 smesh = smeshBuilder.New()
192 coupe_vis_1 = smesh.Mesh(coupe_vis)
193 putName(coupe_vis_1.GetMesh(), 'coupe_vis')
194
195 Regular_1D = coupe_vis_1.Segment()
196 Nb_Segments_1 = Regular_1D.NumberOfSegments(10)
197 Quadrangle_2D = coupe_vis_1.Quadrangle(algo=smeshBuilder.QUADRANGLE)
198 Regular_1D_1 = coupe_vis_1.Segment(geom=tige)
199 Nb_Segments_2 = Regular_1D_1.NumberOfSegments(30)
200 Regular_1D_2 = coupe_vis_1.Segment(geom=section)
201 Nb_Segments_3 = Regular_1D_2.NumberOfSegments(10,1,[ 7, 11, 16, 23 ])
202
203 _ = coupe_vis_1.GroupOnGeom(tige,'tige',SMESH.EDGE)
204 _ = coupe_vis_1.GroupOnGeom(section,'section',SMESH.EDGE)
205 _ = coupe_vis_1.GroupOnGeom(tige_haute,'tige_haute',SMESH.EDGE)
206 _ = coupe_vis_1.GroupOnGeom(rond,'rond',SMESH.EDGE)
207 _ = coupe_vis_1.GroupOnGeom(tete,'tete',SMESH.EDGE)
208 _ = coupe_vis_1.GroupOnGeom(section_tete,'section_tete',SMESH.EDGE)
209 _ = coupe_vis_1.GroupOnGeom(conge,'conge',SMESH.EDGE)
210 _ = coupe_vis_1.GroupOnGeom(appui,'appui',SMESH.EDGE)
211 _ = coupe_vis_1.GroupOnGeom(p_imp,'p_imp',SMESH.EDGE)
212
213 ## set object names
214 #smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
215 #smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
216 putName(Nb_Segments_1, 'Nb. Segments_1', i_pref='vis')
217 putName(Nb_Segments_2, 'Nb. Segments_2', i_pref='vis')
218 putName(Nb_Segments_3, 'Nb. Segments_3', i_pref='vis')
219
220 is_done = coupe_vis_1.Compute()
221 text = "coupe_vis_1.Compute"
222 if is_done:
223   logging.debug(text+" : OK")
224 else:
225   text = "Erreur au calcul du maillage.\n" + text
226   logging.info(text)
227   raise Exception(text)
228
229 # Découpage en 2 triangles du quadrangle dans l'angle
230 cg_x=0.972772
231 cg_y=104.835
232 cg_z=0.
233 l_ids = coupe_vis_1.FindElementsByPoint( cg_x,cg_y,cg_z, SMESH.FACE )
234 if ( len(l_ids) != 1 ):
235   text = "Maillage {}.\nImpossible de trouver l'élément proche de ({},{},{}).".format(coupe_vis.GetName(),cg_x,cg_y,cg_z)
236   raise Exception(text)
237 isDone = coupe_vis_1.SplitQuad( l_ids, 1 )
238 text = "SplitQuad de l'élément n° {} du maillage de {}".format(l_ids[0],coupe_vis.GetName())
239 if isDone:
240   logging.debug(text+" : OK")
241 else:
242   text = "Erreur.\n" + text
243   logging.info(text)
244   raise Exception(text)
245
246 visHex80 = smesh.CopyMesh( coupe_vis_1, 'visHex80', 1, 0)
247 putName(visHex80.GetMesh(), 'visHex80')
248
249 _ = visHex80.RotationSweepObjects( [ visHex80 ], [ visHex80 ], [ visHex80 ], SMESH.AxisStruct( 0, 0, 0, 0, 10, 0 ), 0.0785398, 40, 1e-05, 1 )
250
251 ficmed = os.path.join(gmu.pathBloc, "materielCasTests","visSain.med")
252 text = ".. Archivage du maillage dans le fichier '{}'".format(ficmed)
253 logging.info(text)
254 visHex80.ExportMED(ficmed)
255
256 ## Set names of Mesh objects
257
258 if salome.sg.hasDesktop():
259   salome.sg.updateObjBrowser()