Salome HOME
[bos #40653][CEA] New mesh import export formats with meshio.
[modules/smesh.git] / test / SMESH_reg.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 #  File   : SMESH_reg.py
25 #  Module : SMESH
26 #
27 import salome
28 salome.salome_init()
29 import GEOM
30 from salome.geom import geomBuilder
31 geompy = geomBuilder.New()
32
33 import SMESH, SALOMEDS
34 from salome.smesh import smeshBuilder
35 smesh =  smeshBuilder.New()
36
37 from salome.StdMeshers import StdMeshersBuilder
38
39
40 # ---- define a box
41 print("Define box")
42 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
43 idbox = geompy.addToStudy(box, "box")
44
45 # ---- add faces of box to study
46 print("Add faces to study")
47 idface = []
48 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
49 for f in subShapeList:
50   name = geompy.SubShapeName(f, box)
51   print(name)
52   idface.append( geompy.addToStudyInFather(box, f, name) )
53
54 # ---- add edges of box to study
55 print("Add edges to study")
56 idedge = []
57 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["EDGE"])
58 for f in subShapeList:
59   name = geompy.SubShapeName(f, box)
60   print(name)
61   idedge.append( geompy.addToStudyInFather(box, f, name) )
62
63 salome.sg.updateObjBrowser()
64
65 # ---- launch SMESH
66 smeshgui = salome.ImportComponentGUI("SMESH")
67 smeshgui.Init()
68 smesh.UpdateStudy()
69
70 # ---- Creating meshes
71
72 box = salome.IDToObject(idbox)
73 names = [ "MeshBoxReg", "MeshBoxScale", "MeshBoxTable", "MeshBoxExpr", "MeshBoxBeta" ]
74
75
76 print("-------------------------- Create ", names[0], " mesh")
77 mesh = smesh.Mesh(box, names[0])
78 algo = mesh.Segment()
79 hyp = algo.NumberOfSegments(7)
80 hyp.SetDistrType(0)
81 smesh.SetName(hyp, "NumberOfSegmentsReg")
82 algo = mesh.Triangle()
83 algo.MaxElementArea(2500)
84
85 mesh.Compute()
86 mesh.CheckCompute()
87
88 print("-------------------------- Create ", names[1], " mesh")
89 mesh = smesh.Mesh(box, names[1])
90 algo = mesh.Segment()
91 hyp = algo.NumberOfSegments(7)
92 hyp.SetDistrType(1)
93 hyp.SetScaleFactor(2)
94 smesh.SetName(hyp, "NumberOfSegmentsScale")
95 algo = mesh.Triangle()
96 algo.MaxElementArea(2500)
97
98 mesh.Compute()
99 mesh.CheckCompute()
100
101 print("-------------------------- Create ", names[2], " mesh")
102 mesh = smesh.Mesh(box,names[2])
103 algo = mesh.Segment()
104 hyp = algo.NumberOfSegments(7)
105 hyp.SetDistrType(2)
106 hyp.SetTableFunction( [0, 0.1, 0.5, 1.0, 1.0, 0.1] )
107 hyp.SetConversionMode(0)
108 smesh.SetName(hyp, "NumberOfSegmentsTable")
109 algo = mesh.Triangle()
110 algo.MaxElementArea(2500)
111
112 mesh.Compute()
113 mesh.CheckCompute()
114
115 print("-------------------------- Create ", names[3], " mesh")
116 mesh = smesh.Mesh(box, names[3])
117 algo = mesh.Segment()
118 hyp = algo.NumberOfSegments(10)
119 hyp.SetDistrType(3)
120 hyp.SetExpressionFunction("sin(3*t)")
121 hyp.SetConversionMode(1)
122 smesh.SetName(hyp, "NumberOfSegmentsExpr")
123 algo = mesh.Triangle()
124 algo.MaxElementArea(2500)
125
126 mesh.Compute()
127 mesh.CheckCompute()
128
129 print("-------------------------- Create ", names[4], " mesh")
130 mesh = smesh.Mesh(box, names[4])
131 algo = mesh.Segment()
132 hyp = algo.NumberOfSegments(7)
133 hyp.SetDistrType(4)
134 hyp.SetBeta(1.01)
135 smesh.SetName(hyp, "NumberOfSegmentsBeta")
136
137 quad_2d = mesh.Quadrangle()
138 quad_2d.SetName("Quadrangle_2D")
139
140 hexa_3d = mesh.Hexahedron()
141 hexa_3d.SetName("Hexa_3D")
142
143 mesh.Compute()
144 mesh.CheckCompute()
145
146
147 salome.sg.updateObjBrowser()