Salome HOME
Merge branch 'master' into gni/evolution
[modules/smesh.git] / src / Tools / blocFissure / materielCasTests / decoupeCylindre.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
21 import logging
22
23 import sys
24 import salome
25
26 salome.salome_init()
27
28 import salome_notebook
29 notebook = salome_notebook.notebook
30
31 import os
32 from blocFissure import gmu
33
34 ###
35 ### GEOM component
36 ###
37
38 import GEOM
39 from salome.geom import geomBuilder
40 import math
41 import SALOMEDS
42
43
44 geompy = geomBuilder.New()
45
46 O = geompy.MakeVertex(0, 0, 0)
47 OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
48 OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
49 OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
50 O_1 = geompy.MakeVertex(0, 0, 0)
51 OX_1 = geompy.MakeVectorDXDYDZ(1, 0, 0)
52 OY_1 = geompy.MakeVectorDXDYDZ(0, 1, 0)
53 OZ_1 = geompy.MakeVectorDXDYDZ(0, 0, 1)
54 Vertex_1 = geompy.MakeVertex(0, 0, 500)
55 Vertex_2 = geompy.MakeVertex(100, 0, 500)
56 Vertex_3 = geompy.MakeVertex(110, 0, 500)
57 Vertex_4 = geompy.MakeVertex(117.071068, -2.928932, 500)
58 Vertex_5 = geompy.MakeVertex(120, -10, 500)
59 Vertex_6 = geompy.MakeVertex(120, -30, 500)
60 Vertex_7 = geompy.MakeVertex(122.928932, -37.071068, 500)
61 Vertex_8 = geompy.MakeVertex(130, -40, 500)
62 Vertex_9 = geompy.MakeVertex(135, -40, 500)
63 Vertex_10 = geompy.MakeVertex(160, -40, 500)
64 Plane_1 = geompy.MakePlaneLCS(None, 2000, 2)
65 Mirror_1_1 = geompy.MakeMirrorByPlane(Vertex_2, Plane_1)
66 Mirror_1_2 = geompy.MakeMirrorByPlane(Vertex_3, Plane_1)
67 Mirror_1_3 = geompy.MakeMirrorByPlane(Vertex_4, Plane_1)
68 Mirror_1_4 = geompy.MakeMirrorByPlane(Vertex_5, Plane_1)
69 Mirror_1_5 = geompy.MakeMirrorByPlane(Vertex_6, Plane_1)
70 Mirror_1_6 = geompy.MakeMirrorByPlane(Vertex_7, Plane_1)
71 Mirror_1_7 = geompy.MakeMirrorByPlane(Vertex_8, Plane_1)
72 Mirror_1_8 = geompy.MakeMirrorByPlane(Vertex_9, Plane_1)
73 Mirror_1_9 = geompy.MakeMirrorByPlane(Vertex_10, Plane_1)
74 Curve_2 = geompy.MakeInterpol([Mirror_1_9, Mirror_1_8, Mirror_1_7, Mirror_1_6, Mirror_1_5, Mirror_1_4, Mirror_1_3, Mirror_1_2, Mirror_1_1, Vertex_1, Vertex_2, Vertex_3, Vertex_4, Vertex_5, Vertex_6, Vertex_7, Vertex_8, Vertex_9, Vertex_10], False, False)
75 Circle_1 = geompy.MakeCircle(Vertex_1, None, 145)
76 Vertex_11 = geompy.MakeVertex(0, -165, 500)
77 Curve_2_vertex_2 = geompy.GetSubShape(Curve_2, [2])
78 Curve_2_vertex_3 = geompy.GetSubShape(Curve_2, [3])
79 Arc_1 = geompy.MakeArc(Curve_2_vertex_2, Vertex_11, Curve_2_vertex_3)
80 FissInCylindre = geompy.MakeFaceWires([Curve_2, Arc_1], 1)
81 Divided_Cylinder_1 = geompy.MakeDividedCylinder(145, 800, GEOM.SQUARE)
82 CylindreSain = geompy.MakeRotation(Divided_Cylinder_1, OZ, 45*math.pi/180.0)
83 [Compound_1, vertical, radial, Compound_4] = geompy.Propagate(CylindreSain)
84 geompy.ExportBREP(FissInCylindre, os.path.join(gmu.pathBloc, "materielCasTests", "FissInCylindre.brep"))
85 Vertex_12 = geompy.MakeVertex(0, -145, 500)
86 Circle_2 = geompy.MakeCircle(Vertex_12, None, 145)
87 Face_1 = geompy.MakeFaceWires([Circle_2], 1)
88 Vertex_13 = geompy.MakeVertex(0, 0, 500)
89 Disk_1 = geompy.MakeDiskPntVecR(Vertex_13, OZ_1, 170)
90 FissInCylindre2 = geompy.MakeCommon(Face_1, Disk_1)
91 geompy.ExportBREP(FissInCylindre2, os.path.join(gmu.pathBloc, "materielCasTests", "FissInCylindre2.brep"))
92 geompy.addToStudy( O, 'O' )
93 geompy.addToStudy( OX, 'OX' )
94 geompy.addToStudy( OY, 'OY' )
95 geompy.addToStudy( OZ, 'OZ' )
96 geompy.addToStudy( O_1, 'O' )
97 geompy.addToStudy( OX_1, 'OX' )
98 geompy.addToStudy( OY_1, 'OY' )
99 geompy.addToStudy( OZ_1, 'OZ' )
100 geompy.addToStudy( Vertex_1, 'Vertex_1' )
101 geompy.addToStudy( Vertex_2, 'Vertex_2' )
102 geompy.addToStudy( Vertex_3, 'Vertex_3' )
103 geompy.addToStudy( Vertex_4, 'Vertex_4' )
104 geompy.addToStudy( Vertex_5, 'Vertex_5' )
105 geompy.addToStudy( Vertex_6, 'Vertex_6' )
106 geompy.addToStudy( Vertex_7, 'Vertex_7' )
107 geompy.addToStudy( Vertex_8, 'Vertex_8' )
108 geompy.addToStudy( Vertex_9, 'Vertex_9' )
109 geompy.addToStudy( Vertex_10, 'Vertex_10' )
110 geompy.addToStudy( Plane_1, 'Plane_1' )
111 geompy.addToStudy( Mirror_1_1, 'Mirror_1_1' )
112 geompy.addToStudy( Mirror_1_2, 'Mirror_1_2' )
113 geompy.addToStudy( Mirror_1_3, 'Mirror_1_3' )
114 geompy.addToStudy( Mirror_1_4, 'Mirror_1_4' )
115 geompy.addToStudy( Mirror_1_5, 'Mirror_1_5' )
116 geompy.addToStudy( Mirror_1_6, 'Mirror_1_6' )
117 geompy.addToStudy( Mirror_1_7, 'Mirror_1_7' )
118 geompy.addToStudy( Mirror_1_8, 'Mirror_1_8' )
119 geompy.addToStudy( Mirror_1_9, 'Mirror_1_9' )
120 geompy.addToStudy( Curve_2, 'Curve_2' )
121 geompy.addToStudy( Circle_1, 'Circle_1' )
122 geompy.addToStudy( Vertex_11, 'Vertex_11' )
123 geompy.addToStudyInFather( Curve_2, Curve_2_vertex_2, 'Curve_2:vertex_2' )
124 geompy.addToStudyInFather( Curve_2, Curve_2_vertex_3, 'Curve_2:vertex_3' )
125 geompy.addToStudy( Arc_1, 'Arc_1' )
126 geompy.addToStudy( FissInCylindre, 'FissInCylindre' )
127 geompy.addToStudy( Divided_Cylinder_1, 'Divided Cylinder_1' )
128 geompy.addToStudy( CylindreSain, 'CylindreSain' )
129 geompy.addToStudyInFather( CylindreSain, Compound_1, 'Compound_1' )
130 geompy.addToStudyInFather( CylindreSain, vertical, 'vertical' )
131 geompy.addToStudyInFather( CylindreSain, radial, 'radial' )
132 geompy.addToStudyInFather( CylindreSain, Compound_4, 'Compound_4' )
133 geompy.addToStudy( Vertex_12, 'Vertex_12' )
134 geompy.addToStudy( Circle_2, 'Circle_2' )
135 geompy.addToStudy( Face_1, 'Face_1' )
136 geompy.addToStudy( Vertex_13, 'Vertex_13' )
137 geompy.addToStudy( Disk_1, 'Disk_1' )
138 geompy.addToStudy( FissInCylindre2, 'FissInCylindre2' )
139
140 ###
141 ### SMESH component
142 ###
143
144 import  SMESH, SALOMEDS
145 from salome.smesh import smeshBuilder
146
147 smesh = smeshBuilder.New()
148 from salome.StdMeshers import StdMeshersBuilder
149 smeshObj_1 = smesh.CreateHypothesis('NumberOfSegments')
150 smeshObj_1.SetNumberOfSegments( 5 )
151 smeshObj_1.SetDistrType( 0 )
152 CylindreSain_1 = smesh.Mesh(CylindreSain)
153 smesh.SetName(CylindreSain_1, 'CylindreSain')
154 Regular_1D = CylindreSain_1.Segment()
155 Nb_Segments_1 = Regular_1D.NumberOfSegments(15,[],[  ])
156 Nb_Segments_1.SetDistrType( 0 )
157 Quadrangle_2D = CylindreSain_1.Quadrangle(algo=smeshBuilder.QUADRANGLE)
158 Hexa_3D = CylindreSain_1.Hexahedron(algo=smeshBuilder.Hexa)
159 Regular_1D_1 = CylindreSain_1.Segment(geom=vertical)
160 Nb_Segments_2 = Regular_1D_1.NumberOfSegments(30,[],[  ])
161 Nb_Segments_2.SetDistrType( 0 )
162 Regular_1D_2 = CylindreSain_1.Segment(geom=radial)
163 Nb_Segments_3 = Regular_1D_2.NumberOfSegments(6,[],[  ])
164 Nb_Segments_3.SetDistrType( 0 )
165
166 is_done = CylindreSain_1.Compute()
167 text = "CylindreSain_1.Compute"
168 if is_done:
169   logging.info(text+" OK")
170 else:
171   text = "Erreur au calcul du maillage.\n" + text
172   logging.info(text)
173   raise Exception(text)
174
175 CylindreSain_1.ExportMED(os.path.join(gmu.pathBloc, "materielCasTests", "CylindreSain.med"))
176 SubMesh_1 = Regular_1D_1.GetSubMesh()
177 SubMesh_2 = Regular_1D_2.GetSubMesh()
178
179 ## some objects were removed
180 aStudyBuilder = salome.myStudy.NewBuilder()
181 SO = salome.myStudy.FindObjectIOR(salome.myStudy.ConvertObjectToIOR(smeshObj_1))
182 if SO is not None: aStudyBuilder.RemoveObjectWithChildren(SO)
183 ## set object names
184 smesh.SetName(CylindreSain_1.GetMesh(), 'CylindreSain')
185 smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
186 smesh.SetName(Nb_Segments_1, 'Nb. Segments_1')
187 smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
188 smesh.SetName(Hexa_3D.GetAlgorithm(), 'Hexa_3D')
189 smesh.SetName(Nb_Segments_2, 'Nb. Segments_2')
190 smesh.SetName(Nb_Segments_3, 'Nb. Segments_3')
191 smesh.SetName(SubMesh_1, 'SubMesh_1')
192 smesh.SetName(SubMesh_2, 'SubMesh_2')
193
194 if salome.sg.hasDesktop():
195   salome.sg.updateObjBrowser()