Salome HOME
ecac4870f44cdf4943cf96f88c7e098d6fa8b925
[modules/smesh.git] / doc / salome / examples / a3DmeshOnModified2Dmesh.py
1 import salome
2 salome.salome_init()
3
4 from salome.geom import geomBuilder
5 geompy = geomBuilder.New(salome.myStudy)
6
7 # This script demonstrates generation of 3D mesh basing on a modified 2D mesh
8 #
9 # Purpose is to get a tetrahedral mesh in a sphere cut by a cube.
10 # The requirement is to have a surface mesh on the cube comprised of
11 # triangles of exactly the same size arranged in a grid pattern.
12 #
13 # To fulfill this requirement we mesh the box using Quadrangle: Mapping
14 # meshing algorithm, split quadrangles into triangles and then generate
15 # tetrahedrons.
16
17
18 # Make the geometry
19
20 Box_1    = geompy.MakeBox(-100,-100,-100, 100, 100, 100)
21 Sphere_1 = geompy.MakeSphereR( 300 )
22 Cut_1    = geompy.MakeCut(Sphere_1, Box_1, theName="Cut_1")
23 # get a spherical face
24 Sph_Face = geompy.ExtractShapes( Sphere_1, geompy.ShapeType["FACE"] )[0]
25
26 # get the shape Sph_Face turned into during MakeCut()
27 Sph_Face = geompy.GetInPlace(Cut_1, Sph_Face, isNewImplementation=True, theName="Sphere_1")
28
29
30 # 1) Define a mesh with 1D and 2D meshers
31
32 import  SMESH
33 from salome.smesh import smeshBuilder
34 smesh = smeshBuilder.New(salome.myStudy)
35
36 Mesh_1 = smesh.Mesh(Cut_1)
37
38 # "global" meshers (assigned to Cut_1) that will be used for the box
39 Regular_1D = Mesh_1.Segment()
40 Local_Length_1 = Regular_1D.LocalLength(20)
41 Quadrangle_2D = Mesh_1.Quadrangle()
42
43 # a "local" mesher (assigned to a sub-mesh on Sphere_1) to mesh the sphere
44 algo_2D = Mesh_1.Triangle( smeshBuilder.NETGEN_1D2D, Sph_Face )
45 algo_2D.SetMaxSize( 70. )
46 algo_2D.SetFineness( smeshBuilder.Moderate )
47 algo_2D.SetMinSize( 7. )
48
49 # 2) Compute 2D mesh
50 isDone = Mesh_1.Compute()
51
52 # 3) Split quadrangles into triangles
53 isDone = Mesh_1.SplitQuadObject( Mesh_1, Diag13=True )
54
55 # 4) Define a 3D mesher
56 Mesh_1.Tetrahedron()
57
58 # 5) Compute 3D mesh
59 Mesh_1.Compute()
60
61 if salome.sg.hasDesktop():
62   salome.sg.updateObjBrowser(1)