From e36717feb00b623f5bc7ffbbc47d28ea0b95f842 Mon Sep 17 00:00:00 2001
From: abd import salome import geompy First of all see Example
+ of 3d mesh generation, which is an example of good python script style
+ for Mesh module. import StdMeshers Other examples of python
+ scripts will be also updated soon to use smesh package instead of direct
+ usage of idl interface. smesh = salome.lcc.FindOrLoadComponent("FactoryServer",
- "SMESH") smeshgui = salome.ImportComponentGUI("SMESH") import
+ geompy smeshgui.Init(salome.myStudyId); import smesh # create a box # create a box box = geompy.MakeBox(0.,
+ box = geompy.MakeBox(0.,
0., 0., 100., 200., 300.) # add box to the study idbox = geompy.addToStudy(box,
+ idbox = geompy.addToStudy(box,
"box") # create a hypothesis print "--------------------------
- create Hypothesis" print "--------------------------
- NumberOfSegments" numberOfSegments
- = 7 hypNbSeg = smesh.CreateHypothesis("NumberOfSegments",
- "libStdMeshersEngine.so") hypNbSeg.SetNumberOfSegments(numberOfSegments) print hypNbSeg.GetName() print hypNbSeg.GetId() print hypNbSeg.GetNumberOfSegments() smeshgui.SetName(salome.ObjectToID(hypNbSeg),
- "NumberOfSegments_10") print "--------------------------
- MaxElementArea" maxElementArea =
- 800 hypArea = smesh.CreateHypothesis("MaxElementArea",
- "libStdMeshersEngine.so") hypArea.SetMaxElementArea(maxElementArea) # create a mesh print hypArea.GetName() print hypArea.GetId() print hypArea.GetMaxElementArea() smeshgui.SetName(salome.ObjectToID(hypArea),
- "MaxElementArea_500") print "--------------------------
- MaxElementVolume" maxElementVolume
- = 900 hypVolume = smesh.CreateHypothesis("MaxElementVolume",
- "libStdMeshersEngine.so") hypVolume.SetMaxElementVolume(maxElementVolume) print hypVolume.GetName() print hypVolume.GetId() print hypVolume.GetMaxElementVolume() smeshgui.SetName(salome.ObjectToID(hypVolume),
- "MaxElementVolume_500") tetra = smesh.Mesh(box,
+ "MeshBox") # create algorithms print "--------------------------
- create Algorithms" print "--------------------------
- Regular_1D" regular1D = smesh.CreateHypothesis("Regular_1D",
- "libStdMeshersEngine.so") algo1D = tetra.Segment() smeshgui.SetName(salome.ObjectToID(regular1D),
- "Wire Discretisation") algo1D.NumberOfSegments(7) print "--------------------------
- MEFISTO_2D" mefisto2D = smesh.CreateHypothesis("MEFISTO_2D",
- "libStdMeshersEngine.so") algo2D = tetra.Triangle() smeshgui.SetName(salome.ObjectToID(mefisto2D),
- "MEFISTO_2D") algo2D.MaxElementArea(800.) # initialize a mesh with
- the box mesh = smesh.CreateMesh(box) algo3D = tetra.Tetrahedron(smesh.NETGEN) smeshgui.SetName(salome.ObjectToID(mesh),
- "MeshBox") algo3D.MaxElementVolume(900.) # add the hypothesis to
- the box # compute the mesh print "--------------------------
- add hypothesis to the box" ret = tetra.Compute() mesh.AddHypothesis(box,hypNbSeg) if ret == 0: mesh.AddHypothesis(box,hypArea) print
+ "problem when computing the mesh" mesh.AddHypothesis(box,hypVolume) else: mesh.AddHypothesis(box,regular1D) print
+ "mesh computed" mesh.AddHypothesis(box,mefisto2D) pass
+ # compute the mesh print "--------------------------
- compute the mesh of the box" ret = smesh.Compute(mesh,box) print ret if ret == 0: print
- "probleme when computing the mesh" salome.sg.updateObjBrowser(1) from
+ from
geompy import * import smesh import smesh # create vertices Point111 = MakeVertex( 0, 0,
- 0) Point211 = MakeVertex(10, 0,
- 0) # create a box Point121 = MakeVertex( 0, 10, 0) box = MakeBoxDXDYDZ(10., 10., 10.) Point221 = MakeVertex(10, 10, 0) Point112 = MakeVertex( 0, 0,
- 10) Point212 = MakeVertex(10, 0,
- 10) Point122 = MakeVertex( 0, 10, 10) Point222 = MakeVertex(10, 10, 10) addToStudy(box, "Box") # create edges EdgeX111 = MakeEdge(Point111, Point211) EdgeX121 = MakeEdge(Point121, Point221) EdgeX112 = MakeEdge(Point112, Point212) EdgeX122 = MakeEdge(Point122, Point222) EdgeY11 = MakeEdge(Point111, Point121) # select one edge of
+ the box for definition of a local hypothesis EdgeY21 = MakeEdge(Point211, Point221) p5 = MakeVertex(5., 0., 0.) EdgeY12 = MakeEdge(Point112, Point122) EdgeX = GetEdgeNearPoint(box, p5) EdgeY22 = MakeEdge(Point212, Point222) EdgeZ111 = MakeEdge(Point111, Point112) EdgeZ211 = MakeEdge(Point211, Point212) EdgeZ121 = MakeEdge(Point121, Point122) EdgeZ221 = MakeEdge(Point221, Point222) addToStudyInFather(box, EdgeX, "Edge
+ [0,0,0 - 10,0,0]") # create faces FaceX11 = MakeQuad(EdgeY11, EdgeZ111,
- EdgeY12, EdgeZ121) # create a hexahedral
+ mesh on the box FaceX21 = MakeQuad(EdgeY21, EdgeZ211,
- EdgeY22, EdgeZ221) FaceY111 = MakeQuad(EdgeX111, EdgeZ111,
- EdgeX112, EdgeZ211) FaceY121 = MakeQuad(EdgeX121, EdgeZ121,
- EdgeX122, EdgeZ221) FaceZ11 = MakeQuad(EdgeX111, EdgeY11,
- EdgeX121, EdgeY21) FaceZ12 = MakeQuad(EdgeX112, EdgeY12,
- EdgeX122, EdgeY22) quadra = smesh.Mesh(box, "Box : quadrangle
+ 2D mesh") # create a solid # create a regular
+ 1D algorithm for the faces Block = MakeHexa(FaceX11, FaceX21, FaceY111,
- FaceY121, FaceZ11, FaceZ12) algo1D = quadra.Segment() # create a compound # define "NumberOfSegments"
+ hypothesis to cut box = MakeCompound([Block]) # all the edges in
+ a fixed number of segments # add in the study box_id = addToStudy(box, "Box compound") algo1D.NumberOfSegments(4) # create hexahedral mesh
- on the box hexa = smesh.Mesh(box, "Box compound
- : hexahedrical mesh") # create a quadrangle
+ 2D algorithm for the faces algo = hexa.Segment() quadra.Quadrangle() # define "NumberOfSegments"
- hypothesis to cut the edge in a fixed number of segments # construct a submesh
+ on the edge with a local hypothesis algo.NumberOfSegments(4) algo_local = quadra.Segment(EdgeX) # creates a quadrangle
- 2D algorithm for the faces # define "Arithmetic1D"
+ hypothesis to cut the edge
+ in several segments with increasing arithmetic length hexa.Quadrangle() algo_local.Arithmetic1D(1, 4) # construct a submesh with
- a local hypothesis # define "Propagation"
+ hypothesis that propagates all other hypotheses algo = hexa.Segment(EdgeX111) # on all edges of the
+ opposite side in case of quadrangular faces # define "Arithmetic1D"
- hypothesis to cut an edge in several segments with increasing arithmetic
- length algo.Arithmetic1D(1, 4) algo_local.Propagation() # define "Propagation"
- hypothesis that propagates all other hypothesis on all edges on the opposite
- side in case of quadrangular faces # compute the mesh algo.Propagation() quadra.Compute() # compute the mesh hexa.Compute() import
- salome import geompy import SMESH import
+ geompy import StdMeshers import smesh smesh = salome.lcc.FindOrLoadComponent("FactoryServer",
- "SMESH") smesh.SetCurrentStudy(salome.myStudy) def PrintMeshInfo(theMesh): aMesh
+ = theMesh.GetMesh() box =
- geompy.MakeBox(0., 0., 0., 20., 20., 20.) print
+ "Information about mesh:" idbox = geompy.addToStudy(box, "box") print
+ "Number of nodes :
+ ", aMesh.NbNodes() print
+ "Number of edges :
+ ", aMesh.NbEdges() subShapeList = geompy.SubShapeAll(box,
- geompy.ShapeType["EDGE"]) print
+ "Number of faces :
+ ", aMesh.NbFaces() edge =
- subShapeList[0] print
+ "Number of volumes :
+ ", aMesh.NbVolumes() name =
- geompy.SubShapeName(edge, box) pass idedge = geompy.addToStudyInFather(box,
- edge, name) # create a box box =
- salome.IDToObject(idbox) box = geompy.MakeBox(0., 0., 0., 20.,
+ 20., 20.) edge = salome.IDToObject(idedge) geompy.addToStudy(box, "box") hyp1 = smesh.CreateHypothesis("NumberOfSegments",
- "libStdMeshersEngine.so") # select one edge of
+ the box for definition of a local hypothesis hyp1.SetNumberOfSegments(3) subShapeList = geompy.SubShapeAll(box,
+ geompy.ShapeType["EDGE"]) hyp2 = smesh.CreateHypothesis("MaxElementArea",
- "libStdMeshersEngine.so") edge = subShapeList[0] hyp2.SetMaxElementArea(10) name = geompy.SubShapeName(edge, box) hyp3 = smesh.CreateHypothesis("Arithmetic1D",
- "libStdMeshersEngine.so") geompy.addToStudyInFather(box, edge, name) hyp3.SetLength(1,1) hyp3.SetLength(6,0) # create a mesh hyp4 = smesh.CreateHypothesis("Propagation",
- "libStdMeshersEngine.so") tria = smesh.Mesh(box, "Mesh 2D") algo1D = tria.Segment() algo1 = smesh.CreateHypothesis("Regular_1D",
- "libStdMeshersEngine.so") hyp1 = algo1D.NumberOfSegments(3) algo2 = smesh.CreateHypothesis("MEFISTO_2D",
- "libStdMeshersEngine.so") algo2D = tria.Triangle() hyp2 = algo2D.MaxElementArea(10.) mesh = smesh.CreateMesh(box) mesh.AddHypothesis(box,hyp1) # create a sub-mesh mesh.AddHypothesis(box,hyp2) algo_local = tria.Segment(edge) mesh.AddHypothesis(box,algo1) hyp3 = algo_local.Arithmetic1D(1, 6) mesh.AddHypothesis(box,algo2) hyp4 = algo_local.Propagation() mesh.AddHypothesis(edge,hyp3) mesh.AddHypothesis(edge,hyp4) # compute the mesh mesh.AddHypothesis(edge,algo1) tria.Compute() PrintMeshInfo(tria) smesh.Compute(mesh,box) salome.sg.updateObjBrowser(1) # remove a local hypothesis mesh = tria.GetMesh() # remove a hypothesis mesh.RemoveHypothesis(edge, hyp4) mesh.RemoveHypothesis(edge,hyp4) # compute the mesh smesh.Compute(mesh,box) tria.Compute() salome.sg.updateObjBrowser(1) PrintMeshInfo(tria) # change the value
- of the hypothesis hyp2.SetMaxElementArea(2) mesh.AddHypothesis(box,hyp2) smesh.Compute(mesh,box) salome.sg.updateObjBrowser(1) hyp2.SetMaxElementArea(2.) # compute the mesh import
- salome tria.Compute() import geompy PrintMeshInfo(tria) import StdMeshers smesh = salome.lcc.FindOrLoadComponent("FactoryServer",
- "SMESH") smeshgui = salome.ImportComponentGUI("SMESH") import geompy smeshgui.Init(salome.myStudyId); import smesh # create a box # create a box box = geompy.MakeBox(0.,
+ box = geompy.MakeBox(0.,
0., 0., 100., 200., 300.) # add the box to the study idbox = geompy.addToStudy(box,
+ idbox = geompy.addToStudy(box,
"box") # create a hypothesis print "--------------------------
- create Hypothesis" print "--------------------------
- NumberOfSegments" numberOfSegments
- = 7 hypNbSeg = smesh.CreateHypothesis("NumberOfSegments",
- "libStdMeshersEngine.so") hypNbSeg.SetNumberOfSegments(numberOfSegments) print hypNbSeg.GetName() print hypNbSeg.GetId() print hypNbSeg.GetNumberOfSegments() # create a mesh smeshgui.SetName(salome.ObjectToID(hypNbSeg),
- "NumberOfSegments_10") print "--------------------------
- MaxElementArea" maxElementArea =
- 800 hypArea = smesh.CreateHypothesis("MaxElementArea",
- "libStdMeshersEngine.so") hypArea.SetMaxElementArea(maxElementArea) print hypArea.GetName() print hypArea.GetId() print hypArea.GetMaxElementArea() smeshgui.SetName(salome.ObjectToID(hypArea),
- "MaxElementArea_500") print "--------------------------
- MaxElementVolume" maxElementVolume
- = 900 hypVolume = smesh.CreateHypothesis("MaxElementVolume",
- "libStdMeshersEngine.so") hypVolume.SetMaxElementVolume(maxElementVolume) print hypVolume.GetName() print hypVolume.GetId() print hypVolume.GetMaxElementVolume() smeshgui.SetName(salome.ObjectToID(hypVolume),
- "MaxElementVolume_500") # create algorithms print "--------------------------
- create Algorithms" print "--------------------------
- Regular_1D" regular1D = smesh.CreateHypothesis("Regular_1D",
- "libStdMeshersEngine.so") smeshgui.SetName(salome.ObjectToID(regular1D),
- "Wire Discretisation") print "--------------------------
- MEFISTO_2D" mefisto2D = smesh.CreateHypothesis("MEFISTO_2D",
- "libStdMeshersEngine.so") smeshgui.SetName(salome.ObjectToID(mefisto2D),
- "MEFISTO_2D") # initialize a mesh with
- the box mesh = smesh.CreateMesh(box) smeshgui.SetName(salome.ObjectToID(mesh),
+ tetra = smesh.Mesh(box,
"MeshBox") # add the hypothesis to
- the box print "--------------------------
- add hypothesis to the box" algo1D = tetra.Segment() mesh.AddHypothesis(box,hypNbSeg) algo1D.NumberOfSegments(7) mesh.AddHypothesis(box,hypArea) mesh.AddHypothesis(box,hypVolume) algo2D = tetra.Triangle() mesh.AddHypothesis(box,regular1D) algo2D.MaxElementArea(800.) mesh.AddHypothesis(box,mefisto2D) # compute the mesh algo3D = tetra.Tetrahedron(smesh.NETGEN) print "--------------------------
- compute the mesh of the box" algo3D.MaxElementVolume(900.) ret = smesh.Compute(mesh,box) print ret # compute the mesh if ret == 0: tetra.Compute() print
- "probleme when computing the mesh" salome.sg.updateObjBrowser(1) # export the mesh in a
+ MED file mesh.ExportMED("/tmp/meshMED.med",0) tetra.ExportMED("/tmp/meshMED.med",
+ 0) In principle, Extrusion along a path works in the same way as Extrusion,
+ In principle, Extrusion along a path
+ works in the same way as Extrusion,
the main difference is that we define not a vector, but a path of extrusion
- which must be a meshed edge or wire. To get an idea of how this algorithm
- works, let's see the left image, where we have a 1D circle edge and a
- 2D hexagon to be extruded along this path (in the picture they are angular
- because we show the wireframe of the mesh). And now let's see the right
- image, showing the result of the operation. Creating Meshes
-Construction of a Mesh
-
-Construction of a Mesh
-Construction of a Submesh
-Editing of a mesh
-Export of a Mesh
-
-Export of a Mesh
-Extrusion along a path
+Extrusion along a path
-
.
-
- | -- |
+ | ++ |
+
+ +
The left image shows a 1D path mesh, built + on a linear edge, and the initial 2D mesh. The right image shows the result + of extrusion of two edges (#1 and #2) of the initial mesh along the path. + Node #1 of path mesh has been selected as Start + node.
+ ++ +
Extrusion along + a curvilinear edge (with and without angles)
+ | ++ | ++ |
+ The left image shows a 1D path mesh, built on curvilinear edge, and + the initial 2D + mesh. |
+
+ The central image shows the result of extrusion of one edge (#2) of + the initial mesh along the path. Node + #1 of path mesh has been selected as Start + node. |
+
+ The same, but using angles {45, 45, 45, 0, -45, -45, -45} |
+ +
Extrusion + along a sub-mesh.
+ | ++ |
+
+ +
In this example the path mesh has been built + on a wire (polyline with six edges). The first edge of the wire was used + as Shape (edge), node #1 as Start node. The angles have been defined + as {10, 10, 10}. The middle edge (#4) of the initial mesh has been extruded.
+ ++ +
Extrusion + of 2d elements along a sub-mesh.
+ | ++ |
+ +
This extrusion bases on the same path mesh + as in the previous example but the third edge of the wire was set as Shape (edge) and node #4 as Start + node. Please note, that the extrusion has been done in direction + from node #4 to node #3, i.e. against the wire direction. In this example + both faces of the initial mesh have been extruded.
+ ++ +
Extrusion of 2d elements + along a closed path.
+ | ++ | ++ |
+ The left image shows a path mesh built on a closed edge (circle). |
+
+ The central image shows the result of extrusion of both faces of the + initial mesh. Note, that no sewing has been done, so, there are six coincident + nodes and two coincident faces in the resulting mesh. |
+
+ The same, but using angles {45, -45, 45, -45, 45, -45, 45, -45} |
To use Extrusion along a path:
-1. From the Modification
+ 1. From the Modification
menu choose the Extrusion along
- a path item or click button in the toolbar. The
+ a path
+
+ style="margin-left: 80px;"> -
+
-
2. In the dialog box you should
+2. In the dialog box you should
-select the type of +
select the type of elements which will be extruded (1D or 2D),
specify the IDs of - the elements which will be extruded by selecting them in the 3D viewer - or Select the whole mesh, submesh or - group,
specify the IDs + of the elements which will be extruded by selecting them in the + 3D viewer or Select the whole mesh, submesh + or group,
define the Path + along which the elements will be extruded,
Path definition consists of several elements +
+ +Mesh + - containing a 1D sub-mesh on the edge, + along which proceeds the extrusion.
Shape + (edge) - as the mesh can be complex, + the edge is used to define the sub-mesh for the path.
specify the path along - which the elements will be extruded, for this you should specify the Mesh, the Shape, - and the Start point for the extrusion. -
Start + node - the + first or the last node on the edge. It is used to define the direction + of extrusion.
+
-
3. There are two optional parameters, which +
3. There are two optional parameters, which can be very useful.
-If the path of extrusion +
If the path of extrusion is curvilinear, at each iteration the extruded shape is rotated to keep its initial angularity to the curve. By default, the Base - point around which the shape is rotated is the mass center of the + Point around which the shape is rotated is the mass center of the shape, however, you can specify any point as the Base Point and the shape will be rotated with respect to this point.
The shape can also +
The shape can also be rotated around the path to get the resulting mesh in a helical fashion. - At the picture above we see both "oblique-angled" and "right-angled" - mesh elements because Rotation Angles - have not been set for all iterations. You set the values of the angles - at the right and add them to the list of angles at the left by pressing - the button and remove the values from the list by pressing - the button.
4. Click the Apply - or OK button.
+4. Click the Apply + or OK button. Mesh edges + will be extruded into faces, faces into volumes. The external surface + of the resulting 3d mesh (if faces have been extruded) is covered with + faces, and corners with edges. If the path is closed, the resulting mesh + can contain duplicated nodes and faces, because no sewing is done.
-+
diff --git a/doc/salome/gui/SMESH/grouping_elements.htm b/doc/salome/gui/SMESH/grouping_elements.htm index 143be3035..ba562367b 100755 --- a/doc/salome/gui/SMESH/grouping_elements.htm +++ b/doc/salome/gui/SMESH/grouping_elements.htm @@ -7,20 +7,23 @@ + + + + + + + + + +
Package smesh provides + a standard API for creation and edition of meshes .
+ +Below you can see an example + of usage of the package smesh for 3d mesh generation.
+ ++ +
Example of 3d mesh generation + with NETGEN
+ +from geompy import *
+ +import + smesh
+ +# Geometry
+ +# an assembly of a box, + a cylinder and a truncated cone meshed with tetrahedral.
+ ++ +
# Define values
+ +name = "ex21_lamp" +
+ +cote = 60
+ +section = 20
+ +size = 200
+ +radius_1 = 80
+ +radius_2 = 40
+ +height + = 100
+ ++ +
# Build a box
+ +box = MakeBox(-cote, + -cote, -cote, +cote, +cote, +cote)
+ ++ +
# Build a cylinder
+ +pt1 = MakeVertex(0, + 0, cote/3)
+ +di1 = MakeVectorDXDYDZ(0, + 0, 1)
+ +cyl + = MakeCylinder(pt1, di1, section, size)
+ ++ +
# Build a truncated cone +
+ +pt2 = MakeVertex(0, + 0, size)
+ +cone + = MakeCone(pt2, di1, radius_1, radius_2, height)
+ ++ +
# Fuse
+ +box_cyl = MakeFuse(box, + cyl)
+ +piece + = MakeFuse(box_cyl, cone)
+ ++ +
# Add in study
+ +addToStudy(piece, + name)
+ ++ +
# Create a group of faces +
+ +group = CreateGroup(piece, + ShapeType["FACE"])
+ +group_name = name + + "_grp"
+ +addToStudy(group, + group_name)
+ +group.SetName(group_name) +
+ ++ +
# Add faces in the group +
+ +faces = SubShapeAllIDs(piece, + ShapeType["FACE"])
+ +UnionIDs(group, + faces)
+ ++ +
# Create a mesh
+ ++ +
# Define a mesh on a geometry +
+ +tetra = smesh.Mesh(piece, + name)
+ ++ +
# Define 1D hypothesis +
+ +algo1d = tetra.Segment() +
+ +algo1d.LocalLength(10) +
+ ++ +
# Define 2D hypothesis +
+ +algo2d = tetra.Triangle() +
+ +algo2d.LengthFromEdges() +
+ ++ +
# Define 3D hypothesis +
+ +algo3d = tetra.Tetrahedron(smesh.NETGEN) +
+ +algo3d.MaxElementVolume(100) +
+ ++ +
# Compute the mesh
+ +tetra.Compute() +
+ ++ +
# Create a groupe of faces +
+ +tetra.Group(group) +
+ + + +