X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=doc%2Fsalome%2Fgui%2FSMESH%2Fconstructing_meshes.htm;h=e32e648fe9946e8a09eb0b5f2f50f1b84651ddf6;hp=d460c302f464e4a8658b49ddde3a67a8936f8645;hb=529a4c0bfc7d5f67647141ed1ed03fe493f51802;hpb=882f929e86abf75507daabc5178dc1ff9c3a87d9 diff --git a/doc/salome/gui/SMESH/constructing_meshes.htm b/doc/salome/gui/SMESH/constructing_meshes.htm index d460c302f..e32e648fe 100755 --- a/doc/salome/gui/SMESH/constructing_meshes.htm +++ b/doc/salome/gui/SMESH/constructing_meshes.htm @@ -7,11 +7,13 @@
At first see Example of 3d mesh generation, using smesh package. -
Other examples of python scripts will be also updated soon to use smesh package instead of direct usage of idl interface. +
First of all see Example + of 3d mesh generation, which is an example of good python script style + for Mesh module.
-Attention! This script was written using old approach, based on direct usage of SMESH idl interface. To be updated for version 3.2.1 to use smesh package.
-
-
-
import salome
- -import geompy
- -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
+# create a mesh
-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")
+tetra = smesh.Mesh(box, + "MeshBox")
-
# create algorithms
- -print "-------------------------- - create Algorithms"
+algo1D = tetra.Segment()
-print "-------------------------- - Regular_1D"
+algo1D.NumberOfSegments(7)
-regular1D = smesh.CreateHypothesis("Regular_1D", - "libStdMeshersEngine.so")
- -smeshgui.SetName(salome.ObjectToID(regular1D), - "Wire Discretisation")
- -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
+algo3D = tetra.Tetrahedron(smesh.NETGEN)
-mesh = smesh.CreateMesh(box)
- -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) # create a box Point211 = MakeVertex(10, 0,
- 0) box = MakeBoxDXDYDZ(10., 10., 10.) Point121 = MakeVertex( 0, 10, 0) 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() Attention! This script was written using old approach, based on direct usage of SMESH idl interface. To be updated for version 3.2.1 to use smesh package.
- import
- salome import geompy import
+ geompy import SMESH import smesh import StdMeshers smesh = salome.lcc.FindOrLoadComponent("FactoryServer",
- "SMESH") def PrintMeshInfo(theMesh): smesh.SetCurrentStudy(salome.myStudy) aMesh
+ = theMesh.GetMesh() print
+ "Information about mesh:" box =
- geompy.MakeBox(0., 0., 0., 20., 20., 20.) print
+ "Number of nodes :
+ ", aMesh.NbNodes() idbox = geompy.addToStudy(box, "box") print
+ "Number of edges :
+ ", aMesh.NbEdges() print
+ "Number of faces :
+ ", aMesh.NbFaces() subShapeList = geompy.SubShapeAll(box,
- geompy.ShapeType["EDGE"]) print
+ "Number of volumes :
+ ", aMesh.NbVolumes() edge =
- subShapeList[0] pass name =
- geompy.SubShapeName(edge, box) 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)Editing of a mesh
-
-
-
- -
smesh.Compute(mesh,box)
- -salome.sg.updateObjBrowser(1)
+hyp2.SetMaxElementArea(2.)
-
Attention! This script was written using old approach, based on direct usage of SMESH idl interface. To be updated for version 3.2.1 to use smesh package.
-
-
-
+
# 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()
+# create a mesh
-print hypNbSeg.GetNumberOfSegments()
- -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)