6 from salome.geom
import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
10 from salome.smesh
import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
14 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
15 idbox = geompy.addToStudy(box,
"box")
18 tetra = smesh.Mesh(box,
"MeshBox")
20 algo1D = tetra.Segment()
21 algo1D.NumberOfSegments(7)
23 algo2D = tetra.Triangle()
24 algo2D.MaxElementArea(800.)
26 algo3D = tetra.Tetrahedron()
27 algo3D.MaxElementVolume(900.)
32 print "problem when computing the mesh"
6 from salome.geom
import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
10 from salome.smesh
import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
14 box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
15 geompy.addToStudy(box,
"Box")
18 p5 = geompy.MakeVertex(5., 0., 0.)
19 EdgeX = geompy.GetEdgeNearPoint(box, p5)
20 geompy.addToStudyInFather(box, EdgeX,
"Edge [0,0,0 - 10,0,0]")
23 mesh = smesh.Mesh(box,
"Box : hexahedral 3D mesh")
26 algo1D = mesh.Segment()
30 algo1D.NumberOfSegments(4)
36 algo_local = mesh.Segment(EdgeX)
40 algo_local.Arithmetic1D(1, 4)
44 algo_local.Propagation()
54 surfaces = geompy.SubShapeAll(box, geompy.ShapeType[
"FACE"])
57 mesh.Compute( surfaces[0] )
60 submesh = mesh.GetSubMesh( surfaces[2],
"submesh 2" )
6 from salome.geom
import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
10 from salome.smesh
import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
13 Box_1 = geompy.MakeBoxDXDYDZ(200, 200, 200)
14 [Face_1,Face_2,Face_3,Face_4,Face_5,Face_6] = geompy.SubShapeAllSorted(Box_1, geompy.ShapeType[
"FACE"])
17 Mesh_1 = smesh.Mesh(Box_1)
20 Regular_1D = Mesh_1.Segment()
21 Nb_Segments_1 = Regular_1D.NumberOfSegments(20)
22 MEFISTO_2D = Mesh_1.Triangle()
23 Max_Element_Area_1 = MEFISTO_2D.MaxElementArea(1200)
24 Tetrahedron = Mesh_1.Tetrahedron()
25 Max_Element_Volume_1 = Tetrahedron.MaxElementVolume(40000)
28 Regular_1D_1 = Mesh_1.Segment(geom=Face_1)
29 Nb_Segments_2 = Regular_1D_1.NumberOfSegments(4)
30 MEFISTO_2D_1 = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO,geom=Face_1)
31 SubMesh_1 = MEFISTO_2D_1.GetSubMesh()
34 Regular_1D_2 = Mesh_1.Segment(geom=Face_2)
35 Nb_Segments_3 = Regular_1D_2.NumberOfSegments(8)
36 MEFISTO_2D_2 = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO,geom=Face_2)
37 SubMesh_2 = MEFISTO_2D_2.GetSubMesh()
40 Regular_1D_3 = Mesh_1.Segment(geom=Face_3)
41 Nb_Segments_4 = Regular_1D_3.NumberOfSegments(12)
42 MEFISTO_2D_3 = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO,geom=Face_3)
43 SubMesh_3 = MEFISTO_2D_3.GetSubMesh()
46 [ [ SubMesh_1, SubMesh_3, SubMesh_2 ] ] = Mesh_1.GetMeshOrder()
47 isDone = Mesh_1.Compute()
48 print "Nb elements at initial order of sub-meshes:", Mesh_1.NbElements()
51 isDone = Mesh_1.SetMeshOrder( [ [ SubMesh_1, SubMesh_2, SubMesh_3 ] ])
53 isDone = Mesh_1.Compute()
54 print "Nb elements at new order of sub-meshes:", Mesh_1.NbElements()
57 isDone = Mesh_1.SetMeshOrder( [ [ SubMesh_2, SubMesh_1, SubMesh_3 ] ])
58 isDone = Mesh_1.Compute()
59 print "Nb elements at another order of sub-meshes:", Mesh_1.NbElements()
4 from salome.geom
import geomBuilder
5 geompy = geomBuilder.New(salome.myStudy)
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")
24 Sph_Face = geompy.ExtractShapes( Sphere_1, geompy.ShapeType[
"FACE"] )[0]
27 Sph_Face = geompy.GetInPlace(Cut_1, Sph_Face, isNewImplementation=
True, theName=
"Sphere_1")
33 from salome.smesh
import smeshBuilder
34 smesh = smeshBuilder.New(salome.myStudy)
36 Mesh_1 = smesh.Mesh(Cut_1)
39 Regular_1D = Mesh_1.Segment()
40 Local_Length_1 = Regular_1D.LocalLength(20)
41 Quadrangle_2D = Mesh_1.Quadrangle()
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. )
50 isDone = Mesh_1.Compute()
53 isDone = Mesh_1.SplitQuadObject( Mesh_1, Diag13=
True )
61 if salome.sg.hasDesktop():
62 salome.sg.updateObjBrowser(
True)
6 from salome.geom
import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
10 from salome.smesh
import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
13 def PrintMeshInfo(theMesh):
14 aMesh = theMesh.GetMesh()
15 print "Information about mesh:"
16 print "Number of nodes : ", aMesh.NbNodes()
17 print "Number of edges : ", aMesh.NbEdges()
18 print "Number of faces : ", aMesh.NbFaces()
19 print "Number of volumes : ", aMesh.NbVolumes()
23 box = geompy.MakeBox(0., 0., 0., 20., 20., 20.)
24 geompy.addToStudy(box,
"box")
27 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType[
"EDGE"])
28 edge = subShapeList[0]
29 name = geompy.SubShapeName(edge, box)
30 geompy.addToStudyInFather(box, edge, name)
33 tria = smesh.Mesh(box,
"Mesh 2D")
34 algo1D = tria.Segment()
35 hyp1 = algo1D.NumberOfSegments(3)
36 algo2D = tria.Triangle()
37 hyp2 = algo2D.MaxElementArea(10.)
40 algo_local = tria.Segment(edge)
41 hyp3 = algo_local.Arithmetic1D(1, 6)
42 hyp4 = algo_local.Propagation()
49 tria.RemoveHypothesis(hyp4, edge)
56 hyp2.SetMaxElementArea(2.)
6 from salome.geom
import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
10 from salome.smesh
import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
14 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
15 idbox = geompy.addToStudy(box,
"box")
18 tetra = smesh.Mesh(box,
"MeshBox")
28 medFile = tempfile.NamedTemporaryFile(suffix=
".med").name
29 tetra.ExportMED( medFile, 0 )
32 face = geompy.SubShapeAll( box, geompy.ShapeType[
"FACE"])[0]
33 group = tetra.GroupOnGeom( face,
"face group" )
34 tetra.ExportMED( medFile, meshPart=group )
40 face = geompy.MakeFaceHW( 10, 10, 1,
"rectangle" )
41 mesh2D = smesh.Mesh( face,
"mesh2D" )
42 mesh2D.AutomaticHexahedralization(0)
48 mesh2D.ExportMED( medFile )
49 medMesh = MEDLoader.MEDLoader.ReadUMeshFromFile(medFile,mesh2D.GetName(),0)
50 print "autoDimension==True, exported mesh is in %sD"%medMesh.getSpaceDimension()
54 mesh2D.ExportMED( medFile, autoDimension=
False )
55 medMesh = MEDLoader.MEDLoader.ReadUMeshFromFile(medFile,mesh2D.GetName(),0)
56 print "autoDimension==False, exported mesh is in %sD"%medMesh.getSpaceDimension()
Here you can see an example of python script, creating a hexahedral mesh on a cylinder. A picture below the source code of the script demonstrates the resulting mesh.
10 from salome.geom
import geomBuilder
11 geompy = geomBuilder.New(salome.myStudy)
13 import SMESH, SALOMEDS
14 from salome.smesh
import smeshBuilder
15 smesh = smeshBuilder.New(salome.myStudy)
28 base = geompy.MakeVertex(0, 0, 0)
29 direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
31 cylinder = geompy.MakeCylinder(base, direction, radius, height)
33 geompy.addToStudy(cylinder,
"cylinder")
40 box_rot = geompy.MakeBox(-size, -size, 0, +size, +size, height)
41 box_axis = geompy.MakeLine(base, direction)
42 box = geompy.MakeRotation(box_rot, box_axis, math.pi/4)
44 hole = geompy.MakeCut(cylinder, box)
48 plane_a = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
49 plane_b = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
51 blocks_part = geompy.MakePartition([hole], [plane_a, plane_b], [], [], geompy.ShapeType[
"SOLID"])
52 blocks_list = [box] + geompy.SubShapeAll(blocks_part, geompy.ShapeType[
"SOLID"])
53 blocks_all = geompy.MakeCompound(blocks_list)
54 blocks = geompy.MakeGlueFaces(blocks_all, 0.0001)
56 geompy.addToStudy(blocks,
"cylinder:blocks")
61 def group(name, shape, type, base=None, direction=None):
62 t = geompy.ShapeType[type]
63 g = geompy.CreateGroup(shape, t)
65 geompy.addToStudyInFather(shape, g, name)
68 l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
73 group_a = group(
"baseA", blocks,
"FACE", base, direction)
75 base_b = geompy.MakeVertex(0, 0, height)
76 group_b = group(
"baseB", blocks,
"FACE", base_b, direction)
78 group_1 = group(
"limit", blocks,
"SOLID")
79 group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType[
"SOLID"])
80 geompy.UnionIDs(group_1, group_1_all)
81 group_1_box = geompy.GetBlockNearPoint(blocks, base)
82 geompy.DifferenceList(group_1, [group_1_box])
87 smesh.SetCurrentStudy(salome.myStudy)
89 def discretize(x, y, z, nbSeg, shape=blocks):
90 vert = geompy.MakeVertex( x, y, z )
91 edge = geompy.GetEdgeNearPoint( shape, vert )
92 algo = hexa.Segment( edge )
93 algo.NumberOfSegments( nbSeg )
96 hexa = smesh.Mesh(blocks)
98 hexa_1d = hexa.Segment()
99 hexa_1d.NumberOfSegments(1)
101 discretize(+radius , +radius, 0, 5)
102 discretize(-radius , +radius, 0, 8)
103 discretize((radius+size)/2, 0, 0, 10)
104 discretize( +radius, 0, height/2, 20)
6 from salome.geom
import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
10 from salome.smesh
import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
14 Box_inf = geompy.MakeBox(0., 0., 0., 200., 200., 50.)
17 Psup1=geompy.MakeVertex(100., 100., 50.)
18 Fsup1=geompy.GetFaceNearPoint(Box_inf, Psup1)
20 Pinf1=geompy.MakeVertex(100., 100., 0.)
21 Finf1=geompy.GetFaceNearPoint(Box_inf, Pinf1)
24 Box_sup = geompy.MakeBox(100., 100., 50., 200., 200., 100.)
27 Psup2=geompy.MakeVertex(150., 150., 100.)
28 Fsup2=geompy.GetFaceNearPoint(Box_sup, Psup2)
30 Pinf2=geompy.MakeVertex(150., 150., 50.)
31 Finf2=geompy.GetFaceNearPoint(Box_sup, Pinf2)
34 geompy.addToStudy(Box_inf,
"Box_inf")
35 geompy.addToStudyInFather(Box_inf, Fsup1,
"Fsup")
36 geompy.addToStudyInFather(Box_inf, Finf1,
"Finf")
38 geompy.addToStudy(Box_sup,
"Box_sup")
39 geompy.addToStudyInFather(Box_sup, Fsup2,
"Fsup")
40 geompy.addToStudyInFather(Box_sup, Finf2,
"Finf")
42 smesh.SetCurrentStudy(salome.myStudy)
45 Mesh_inf = smesh.Mesh(Box_inf,
"Mesh_inf")
46 algo1D_1=Mesh_inf.Segment()
47 algo1D_1.NumberOfSegments(10)
48 algo2D_1=Mesh_inf.Quadrangle()
49 algo3D_1=Mesh_inf.Hexahedron()
53 Gsup1=Mesh_inf.Group(Fsup1,
"Sup")
55 Ginf1=Mesh_inf.Group(Finf1,
"Inf")
58 Mesh_sup = smesh.Mesh(Box_sup,
"Mesh_sup")
59 algo1D_2=Mesh_sup.Segment()
60 algo1D_2.NumberOfSegments(5)
61 algo2D_2=Mesh_sup.Quadrangle()
62 algo3D_2=Mesh_sup.Hexahedron()
66 Gsup2=Mesh_sup.Group(Fsup2,
"Sup")
68 Ginf2=Mesh_sup.Group(Finf2,
"Inf")
73 Compound1 = smesh.Concatenate([Mesh_inf, Mesh_sup], 0, 1, 1e-05,
74 name=
'Compound with RenamedGrps and MergeElems')
77 Compound2 = smesh.Concatenate([Mesh_inf, Mesh_sup], 1, 0, 1e-05,
True,
78 name=
'Compound with UniteGrps and GrpsOfAllElems')
80 if salome.sg.hasDesktop():
81 salome.sg.updateObjBrowser(
True)
6 from salome.geom
import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
10 from salome.smesh
import smeshBuilder
11 smesh = smeshBuilder.New(salome.myStudy)
14 box = geompy.MakeBoxDXDYDZ(100,100,100)
15 face = geompy.SubShapeAllSorted(box, geompy.ShapeType[
"FACE"])[0]
18 mesh = smesh.Mesh(box)
19 localAlgo = mesh.Triangle(face)
20 mesh.AutomaticHexahedralization()
23 fGroup = mesh.GroupOnGeom( face,
"2D on face")
24 nGroup = mesh.GroupOnGeom( face,
"nodes on face", SMESH.NODE)
25 subMesh = localAlgo.GetSubMesh()
30 newMesh = smesh.CopyMesh( mesh,
"whole mesh copy")
33 newMesh = smesh.CopyMesh( fGroup,
"face group copy with groups",toCopyGroups=
True)
36 newMesh = smesh.CopyMesh( nGroup,
"node group copy")
39 faceIds = fGroup.GetIDs()[-10:]
40 newMesh = smesh.CopyMesh( mesh.GetIDSource( faceIds, SMESH.FACE ),
"some faces copy")
43 nodeIds = nGroup.GetIDs()[-10:]
44 newMesh = smesh.CopyMesh( mesh.GetIDSource( nodeIds, SMESH.NODE),
"some nodes copy")
47 newMesh = smesh.CopyMesh( subMesh,
"sub-mesh copy" )