Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / doc / salome / examples / creating_meshes_ex08.py
1 # Mesh Copying
2
3 import salome
4 salome.salome_init_without_session()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New()
8
9 import SMESH, SALOMEDS
10 from salome.smesh import smeshBuilder
11 smesh =  smeshBuilder.New()
12
13 # make geometry of a box
14 box = geompy.MakeBoxDXDYDZ(100,100,100)
15 face = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])[0]
16
17 # generate a prismatic 3D mesh
18 mesh = smesh.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.CopyMesh( mesh, "whole mesh copy")
34
35 # 2. copy a group of 2D elements along with groups
36 newMesh = smesh.CopyMesh( fGroup,  "face group copy with groups",toCopyGroups=True)
37
38 # 3. copy a group of nodes
39 newMesh = smesh.CopyMesh( nGroup, "node group copy")
40
41 # 4. copy some faces
42 faceIds = fGroup.GetIDs()[-10:]
43 newMesh = smesh.CopyMesh( mesh.GetIDSource( faceIds, SMESH.FACE ), "some faces copy")
44
45 # 5. copy some nodes
46 nodeIds = nGroup.GetIDs()[-10:]
47 newMesh = smesh.CopyMesh( mesh.GetIDSource( nodeIds, SMESH.NODE), "some nodes copy")
48
49 # 6. copy a sub-mesh
50 newMesh = smesh.CopyMesh( subMesh, "sub-mesh copy" )
51
52
53 # make a new mesh with same hypotheses on a modified geometry
54
55 smallBox = geompy.MakeScaleAlongAxes( box, None, 1, 0.5, 0.5 )
56 cutBox = geompy.MakeCut( box, smallBox, theName="box - smallBox" )
57
58 ok, newMesh, groups, submehses, hyps, invIDs = smesh.CopyMeshWithGeom( mesh, cutBox, "cutBox" )
59 newMesh.Compute()