Salome HOME
bos #29171 Refactor testing procedure
[modules/smesh.git] / doc / examples / creating_meshes_ex08.py
1 # Mesh Copying
2
3 import salome
4 salome.salome_init_without_session()
5
6 import SMESH
7 from salome.geom import geomBuilder
8 from salome.smesh import smeshBuilder
9
10 geom_builder = geomBuilder.New()
11 smesh_builder = smeshBuilder.New()
12
13 # make geometry of a box
14 box = geom_builder.MakeBoxDXDYDZ(100,100,100)
15 face = geom_builder.SubShapeAllSorted(box, geom_builder.ShapeType["FACE"])[0]
16
17 # generate a prismatic 3D mesh
18 mesh = smesh_builder.Mesh(box, "box")
19 localAlgo = mesh.Triangle(face)
20 mesh.Segment().NumberOfSegments( 3 )
21 mesh.Quadrangle()
22 mesh.Prism()
23 mesh.Compute()
24
25 # objects to copy
26 fGroup = mesh.GroupOnGeom( face, "2D on face")
27 nGroup = mesh.GroupOnGeom( face, "nodes on face", SMESH.NODE)
28 subMesh = localAlgo.GetSubMesh()
29
30 # make a new mesh by copying different parts of the mesh
31
32 # 1. copy the whole mesh
33 newMesh = smesh_builder.CopyMesh( mesh, "whole mesh copy")
34
35 # 2. copy a group of 2D elements along with groups
36 newMesh = smesh_builder.CopyMesh( fGroup,  "face group copy with groups",toCopyGroups=True)
37
38 # 3. copy a group of nodes
39 newMesh = smesh_builder.CopyMesh( nGroup, "node group copy")
40
41 # 4. copy some faces
42 faceIds = fGroup.GetIDs()[-10:]
43 newMesh = smesh_builder.CopyMesh( mesh.GetIDSource( faceIds, SMESH.FACE ), "some faces copy")
44
45 # 5. copy some nodes
46 nodeIds = nGroup.GetIDs()[-10:]
47 newMesh = smesh_builder.CopyMesh( mesh.GetIDSource( nodeIds, SMESH.NODE), "some nodes copy")
48
49 # 6. copy a sub-mesh
50 newMesh = smesh_builder.CopyMesh( subMesh, "sub-mesh copy" )
51
52
53 # make a new mesh with same hypotheses on a modified geometry
54
55 smallBox = geom_builder.MakeScaleAlongAxes( box, None, 1, 0.5, 0.5 )
56 cutBox = geom_builder.MakeCut( box, smallBox, theName="box - smallBox" )
57
58 ok, newMesh, groups, submehses, hyps, invIDs = smesh_builder.CopyMeshWithGeom( mesh, cutBox, "cutBox" )
59 newMesh.Compute()