Salome HOME
bos #29171 Refactor testing procedure
[modules/smesh.git] / doc / examples / creating_meshes_ex04.py
1 # Editing of a 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 def PrintMeshInfo(theMesh):
13     aMesh = theMesh.GetMesh()
14     print("Information about mesh:")
15     print("Number of nodes       : ", aMesh.NbNodes())
16     print("Number of edges       : ", aMesh.NbEdges())
17     print("Number of faces       : ", aMesh.NbFaces())
18     print("Number of volumes     : ", aMesh.NbVolumes())
19     pass
20
21 # create a box
22 box = geom_builder.MakeBox(0., 0., 0., 20., 20., 20.)
23 geom_builder.addToStudy(box, "box")
24
25 # select one edge of the box for definition of a local hypothesis
26 subShapeList = geom_builder.SubShapeAll(box, geom_builder.ShapeType["EDGE"])
27 edge = subShapeList[0]
28 name = geom_builder.SubShapeName(edge, box)
29 geom_builder.addToStudyInFather(box, edge, name)
30
31 # create a mesh
32 tria = smesh_builder.Mesh(box, "Mesh 2D")
33 algo1D = tria.Segment()
34 hyp1 = algo1D.NumberOfSegments(3)
35 algo2D = tria.Triangle()
36 hyp2 = algo2D.MaxElementArea(10.)
37
38 # create a sub-mesh
39 algo_local = tria.Segment(edge)
40 hyp3 = algo_local.Arithmetic1D(1, 6)
41 hyp4 = algo_local.Propagation()
42
43 # compute the mesh
44 tria.Compute()
45 PrintMeshInfo(tria)
46
47 # remove a local hypothesis
48 tria.RemoveHypothesis(hyp4, edge)
49
50 # compute the mesh
51 tria.Compute()
52 PrintMeshInfo(tria)
53
54 # change the value of the 2D hypothesis
55 hyp2.SetMaxElementArea(2.)
56
57 # compute the mesh
58 tria.Compute()
59 PrintMeshInfo(tria)