Salome HOME
bb03588378d392f487a3a938f83ac4f9874387e2
[modules/smesh.git] / doc / examples / creating_meshes_ex02.py
1 # Construction of a Sub-mesh
2
3 import salome
4 salome.salome_init_without_session()
5
6 from salome.geom import geomBuilder
7 from salome.smesh import smeshBuilder
8
9 geom_builder = geomBuilder.New()
10 smesh_builder = smeshBuilder.New()
11
12 # create a box
13 box = geom_builder.MakeBoxDXDYDZ(10., 10., 10.)
14 geom_builder.addToStudy(box, "Box")
15
16 # select one edge of the box for definition of a local hypothesis
17 p5 = geom_builder.MakeVertex(5., 0., 0.)
18 EdgeX = geom_builder.GetEdgeNearPoint(box, p5)
19 geom_builder.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
20
21 # create a hexahedral mesh on the box
22 mesh = smesh_builder.Mesh(box, "Box : hexahedral 3D mesh")
23
24 # create a Regular_1D algorithm for discretization of edges
25 algo1D = mesh.Segment()
26
27 # define "NumberOfSegments" hypothesis to cut
28 # all the edges in a fixed number of segments
29 algo1D.NumberOfSegments(4)
30
31 # create a quadrangle 2D algorithm for the faces
32 mesh.Quadrangle()
33
34 # construct a sub-mesh on the edge with a local Regular_1D algorithm
35 algo_local = mesh.Segment(EdgeX)
36
37 # define "Arithmetic1D" hypothesis to cut EdgeX in several segments with length arithmetically
38 # increasing from 1.0 to 4.0
39 algo_local.Arithmetic1D(1, 4)
40
41 # define "Propagation" hypothesis that propagates algo_local and "Arithmetic1D" hypothesis
42 # from EdgeX to all parallel edges
43 algo_local.Propagation()
44
45 # assign a hexahedral algorithm
46 mesh.Hexahedron()
47
48 # any sub-shape can be meshed individually --
49 # compute mesh on two surfaces using different methods
50
51 # get surfaces
52 surfaces = geom_builder.SubShapeAll(box, geom_builder.ShapeType["FACE"])
53
54 # method 1: no sub-mesh is created
55 if not mesh.Compute( surfaces[0] ): raise Exception("Error when computing Mesh")
56
57 # method 2: a sub-mesh is created
58 submesh = mesh.GetSubMesh( surfaces[2], "submesh 2" )
59 if not submesh.Compute(): raise Exception("Error when computing Mesh")
60
61 # compute the whole mesh
62 if not mesh.Compute(): raise Exception("Error when computing Mesh")