From 529a4c0bfc7d5f67647141ed1ed03fe493f51802 Mon Sep 17 00:00:00 2001 From: jfa Date: Fri, 14 Jul 2006 10:40:47 +0000 Subject: [PATCH] PAL12557: SMESH Documentation for scripts is not up to date. --- doc/salome/gui/SMESH/constructing_meshes.htm | 770 +--- .../gui/SMESH/defining_hypotheses_tui.htm | 1420 ++---- doc/salome/gui/SMESH/grouping_elements.htm | 983 ++--- doc/salome/gui/SMESH/modifying_meshes.htm | 3855 +++++++++-------- doc/salome/gui/SMESH/quality_controls.htm | 1978 ++++----- doc/salome/gui/SMESH/transforming_meshes.htm | 731 ++-- doc/salome/gui/SMESH/viewing_meshes.htm | 142 +- 7 files changed, 4543 insertions(+), 5336 deletions(-) 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 @@

Creating Meshes

-

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.

+ +

Other examples of python + scripts will be also updated soon to use smesh package instead of direct + usage of idl interface.

Construction of a Mesh

-

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 + geompy

-

import salome

- -

import geompy

- -

import StdMeshers

- -

smesh = salome.lcc.FindOrLoadComponent("FactoryServer", - "SMESH")

- -

smeshgui = salome.ImportComponentGUI("SMESH")

- -

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

+

# create a mesh

-

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)

- -

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

+

algo1D = tetra.Segment()

-

print "-------------------------- - add hypothesis to the box"

- -

mesh.AddHypothesis(box,hypNbSeg)

- -

mesh.AddHypothesis(box,hypArea)

- -

mesh.AddHypothesis(box,hypVolume)

- -

mesh.AddHypothesis(box,regular1D)

- -

mesh.AddHypothesis(box,mefisto2D)

+

algo1D.NumberOfSegments(7)

 

-

# compute the mesh

+

algo2D = tetra.Triangle()

-

print "-------------------------- - compute the mesh of the box"

+

algo2D.MaxElementArea(800.)

-

ret = smesh.Compute(mesh,box)

+

 

-

print ret

+

algo3D = tetra.Tetrahedron(smesh.NETGEN)

-

if ret == 0:

+

algo3D.MaxElementVolume(900.)

-

    print - "probleme when computing the mesh"

+

 

-

salome.sg.updateObjBrowser(1)

+

# compute the mesh

-

 

+

ret = tetra.Compute()

+ +

if ret == 0:

+ +

    print + "problem when computing the mesh"

+ +

else:

+ +

    print + "mesh computed"

+ +

    pass +

+ +

 

+ +

 

Construction of a Submesh

-

 

- -

from +

from geompy import *

-

import smesh

+

import smesh

 

-

# create vertices

+

# create a box

-

Point111 = MakeVertex( 0,  0, -  0)

+

box = MakeBoxDXDYDZ(10., 10., 10.)

-

Point211 = MakeVertex(10,  0, -  0)

- -

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

+

# select one edge of + the box for definition of a local hypothesis

-

EdgeX111 = MakeEdge(Point111, Point211)

+

p5 = MakeVertex(5., 0., 0.)

-

EdgeX121 = MakeEdge(Point121, Point221)

+

EdgeX = GetEdgeNearPoint(box, p5)

-

EdgeX112 = MakeEdge(Point112, Point212)

- -

EdgeX122 = MakeEdge(Point122, Point222)

- -

EdgeY11 = MakeEdge(Point111, Point121)

- -

EdgeY21 = MakeEdge(Point211, Point221)

- -

EdgeY12 = MakeEdge(Point112, Point122)

- -

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

+

# create a hexahedral + mesh on the box

-

FaceX11 = MakeQuad(EdgeY11, EdgeZ111, - EdgeY12, EdgeZ121)

- -

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

+ +

algo1D.NumberOfSegments(4)

 

-

# add in the study

- -

box_id = addToStudy(box, "Box compound")

- -

 

- -

# create hexahedral mesh - on the box

- -

hexa = smesh.Mesh(box, "Box compound - : hexahedrical mesh")

- -

algo = hexa.Segment()

- -

 

- -

# define "NumberOfSegments" - hypothesis to cut the edge in a fixed number of segments

- -

algo.NumberOfSegments(4)

- -

 

- -

# creates a quadrangle +

# create a quadrangle 2D algorithm for the faces

-

hexa.Quadrangle()

+

quadra.Quadrangle()

 

-

# construct a submesh with - a local hypothesis

+

# construct a submesh + on the edge with a local hypothesis

-

algo = hexa.Segment(EdgeX111)

+

algo_local = quadra.Segment(EdgeX)

 

-

# define "Arithmetic1D" - hypothesis to cut an edge in several segments with increasing arithmetic - length

+

# define "Arithmetic1D" + hypothesis to cut the edge + in several segments with increasing arithmetic length

-

algo.Arithmetic1D(1, 4)

+

algo_local.Arithmetic1D(1, 4)

 

-

# define "Propagation" - hypothesis that propagates all other hypothesis on all edges on the opposite - side in case of quadrangular faces

+

# define "Propagation" + hypothesis that propagates all other hypotheses

-

algo.Propagation()

+

# on all edges of the + opposite side in case of quadrangular faces

+ +

algo_local.Propagation()

 

-

# compute the mesh

+

# compute the mesh

-

hexa.Compute()

+

quadra.Compute()

-

 

+

 

Editing of a mesh

-

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 + geompy

-

 

- -

import - salome

- -

import geompy

- -

import SMESH

- -

import StdMeshers

- -

 

- -

smesh = salome.lcc.FindOrLoadComponent("FactoryServer", - "SMESH")

- -

smesh.SetCurrentStudy(salome.myStudy)

- -

 

- -

box   = - geompy.MakeBox(0., 0., 0., 20., 20., 20.)

- -

idbox = geompy.addToStudy(box, "box")

- -

 

- -

subShapeList = geompy.SubShapeAll(box, - geompy.ShapeType["EDGE"])

- -

edge   = - subShapeList[0]

- -

name   = - geompy.SubShapeName(edge, box)

- -

idedge = geompy.addToStudyInFather(box, - edge, name)

- -

 

- -

box  = - salome.IDToObject(idbox)

- -

edge = salome.IDToObject(idedge)

- -

 

- -

hyp1 = smesh.CreateHypothesis("NumberOfSegments", - "libStdMeshersEngine.so")

- -

hyp1.SetNumberOfSegments(3)

- -

hyp2 = smesh.CreateHypothesis("MaxElementArea", - "libStdMeshersEngine.so")

- -

hyp2.SetMaxElementArea(10)

- -

hyp3 = smesh.CreateHypothesis("Arithmetic1D", - "libStdMeshersEngine.so")

- -

hyp3.SetLength(1,1)

- -

hyp3.SetLength(6,0)

- -

hyp4 = smesh.CreateHypothesis("Propagation", - "libStdMeshersEngine.so")

- -

 

- -

algo1 = smesh.CreateHypothesis("Regular_1D", - "libStdMeshersEngine.so")

- -

algo2 = smesh.CreateHypothesis("MEFISTO_2D", - "libStdMeshersEngine.so")

- -

 

- -

mesh = smesh.CreateMesh(box)

- -

mesh.AddHypothesis(box,hyp1)

- -

mesh.AddHypothesis(box,hyp2)

- -

mesh.AddHypothesis(box,algo1)

- -

mesh.AddHypothesis(box,algo2)

- -

mesh.AddHypothesis(edge,hyp3)

- -

mesh.AddHypothesis(edge,hyp4)

- -

mesh.AddHypothesis(edge,algo1)

- -

 

- -

smesh.Compute(mesh,box)

- -

salome.sg.updateObjBrowser(1)

- -

 

- -

# remove a hypothesis

- -

mesh.RemoveHypothesis(edge,hyp4)

- -

 

- -

smesh.Compute(mesh,box)

- -

salome.sg.updateObjBrowser(1)

- -

 

- -

# change the value - of the hypothesis

- -

hyp2.SetMaxElementArea(2)

- -

mesh.AddHypothesis(box,hyp2)

- -

 

- -

smesh.Compute(mesh,box)

- -

salome.sg.updateObjBrowser(1)

+

import smesh

 

+

def PrintMeshInfo(theMesh):

+ +

    aMesh + = theMesh.GetMesh()

+ +

    print + "Information about mesh:"

+ +

    print + "Number of nodes       : + ", aMesh.NbNodes()

+ +

    print + "Number of edges       : + ", aMesh.NbEdges()

+ +

    print + "Number of faces       : + ", aMesh.NbFaces()

+ +

    print + "Number of volumes     : + ", aMesh.NbVolumes()

+ +

    pass

+ +

 

+ +

# create a box

+ +

box = geompy.MakeBox(0., 0., 0., 20., + 20., 20.)

+ +

geompy.addToStudy(box, "box")

+ +

 

+ +

# select one edge of + the box for definition of a local hypothesis

+ +

subShapeList = geompy.SubShapeAll(box, + geompy.ShapeType["EDGE"])

+ +

edge = subShapeList[0]

+ +

name = geompy.SubShapeName(edge, box)

+ +

geompy.addToStudyInFather(box, edge, name)

+ +

 

+ +

# create a mesh

+ +

tria = smesh.Mesh(box, "Mesh 2D")

+ +

algo1D = tria.Segment()

+ +

hyp1 = algo1D.NumberOfSegments(3)

+ +

algo2D = tria.Triangle()

+ +

hyp2 = algo2D.MaxElementArea(10.)

+ +

 

+ +

# create a sub-mesh

+ +

algo_local = tria.Segment(edge)

+ +

hyp3 = algo_local.Arithmetic1D(1, 6)

+ +

hyp4 = algo_local.Propagation()

+ +

 

+ +

# compute the mesh

+ +

tria.Compute()

+ +

PrintMeshInfo(tria)

+ +

 

+ +

# remove a local hypothesis

+ +

mesh = tria.GetMesh()

+ +

mesh.RemoveHypothesis(edge, hyp4)

+ +

 

+ +

# compute the mesh

+ +

tria.Compute()

+ +

PrintMeshInfo(tria)

+ +

 

+ +

# change the value + of the 2D hypothesis

+ +

hyp2.SetMaxElementArea(2.)

+ +

 

+ +

# compute the mesh

+ +

tria.Compute()

+ +

PrintMeshInfo(tria)

+ +

 

+

Export of a Mesh

-

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 geompy

-

 

+

import smesh

-

import - salome

+

 

-

import geompy

+

# create a box

-

import StdMeshers

- -

smesh = salome.lcc.FindOrLoadComponent("FactoryServer", - "SMESH")

- -

smeshgui = salome.ImportComponentGUI("SMESH")

- -

smeshgui.Init(salome.myStudyId);

- -

 

- -

# 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

+

# create a mesh

-

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)

- -

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

+

algo1D = tetra.Segment()

-

print "-------------------------- - add hypothesis to the box"

+

algo1D.NumberOfSegments(7)

-

mesh.AddHypothesis(box,hypNbSeg)

+

 

-

mesh.AddHypothesis(box,hypArea)

+

algo2D = tetra.Triangle()

-

mesh.AddHypothesis(box,hypVolume)

+

algo2D.MaxElementArea(800.)

-

mesh.AddHypothesis(box,regular1D)

+

 

-

mesh.AddHypothesis(box,mefisto2D)

+

algo3D = tetra.Tetrahedron(smesh.NETGEN)

-

 

+

algo3D.MaxElementVolume(900.)

-

# compute the mesh

+

 

-

print "-------------------------- - compute the mesh of the box"

+

# compute the mesh

-

ret = smesh.Compute(mesh,box)

+

tetra.Compute()

-

print ret

+

 

-

if ret == 0:

+

# export the mesh in a + MED file

-

    print - "probleme when computing the mesh"

- -

salome.sg.updateObjBrowser(1)

- -

mesh.ExportMED("/tmp/meshMED.med",0)

- -

 

- -

 

+

tetra.ExportMED("/tmp/meshMED.med", + 0)

- - - - - - - - - -

Modifying Meshes

- -

Adding Nodes and Elements

- -

Add Node

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# add node

- -

aMeshEditor = mesh.GetMeshEditor()

- -

if aMeshEditor.AddNode(50, - 10, 0) == 1:

- -

    print - "Node addition is OK!"

- -

else:

- -

    print - "KO node addition."

- -

    

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Add Edge

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# add node

- -

aMeshEditor = mesh.GetMeshEditor()

- -

if aMeshEditor.AddNode(50, - 10, 0) == 1:

- -

    print - "Node addition is OK!"

- -

else:

- -

    print - "KO node addition."

- -

 

- -

# add edge

- -

LastNodeId = mesh.NbNodes()

- -

if aMeshEditor.AddEdge([LastNodeId, - 38]) == 1:

- -

    print - "Edge addition is OK!"

- -

else:

- -

    print - "KO edge addition."

- -

 

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Add Triangle

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# add node

- -

aMeshEditor = mesh.GetMeshEditor()

- -

if aMeshEditor.AddNode(50, - 10, 0) == 1:

- -

    print - "Node addition is OK!"

- -

else:

- -

    print - "KO node addition."

- -

 

- -

LastNodeId = mesh.NbNodes()

- -

 

- -

# add triangle

- -

if aMeshEditor.AddFace([LastNodeId, - 38, 39]) == 1:

- -

    print - "Triangle addition is OK!"

- -

else:

- -

    print - "KO triangle addition."

- -

    

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Add Quadrangle

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# add node

- -

aMeshEditor = mesh.GetMeshEditor()

- -

if aMeshEditor.AddNode(50, - 10, 0) == 1:

- -

    print - "Node addition is OK!"

- -

else:

- -

    print - "KO node addition."

- -

 

- -

LastNodeId = mesh.NbNodes()

- -

 

- -

# add quadrangle

- -

if aMeshEditor.AddNode(40, - 20, 0) == 1:

- -

    print - "Node addition is OK!"

- -

else:

- -

    print - "KO node addition."

- -

if aMeshEditor.AddFace([mesh.NbNodes(), - LastNodeId, 38, 39]) == 1:

- -

    print - "Quadrangle addition is OK!"

- -

else:

- -

    print - "KO quadrangle addition."

- -

 

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Add Tetrahedron

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# add node

- -

aMeshEditor = mesh.GetMeshEditor()

- -

if aMeshEditor.AddNode(50, - 10, 0) == 1:

- -

    print - "Node addition is OK!"

- -

else:

- -

    print - "KO node addition."

- -

 

- -

LastNodeId = mesh.NbNodes()

- -

 

- -

# add tetrahedron

- -

if aMeshEditor.AddVolume([LastNodeId, - 38, 39, 246]) == 1:

- -

    print - "Tetrahedron addition is OK!"

- -

else:

- -

    print - "KO tetrahedron addition."

- -

    

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Add Hexahedron

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# add nodes

- -

aMeshEditor = mesh.GetMeshEditor()

- -

if aMeshEditor.AddNode(50, - 10, 0) == 1:

- -

    print - "Node addition is OK!"

- -

else:

- -

    print - "KO node addition."

- -

aNodeId1 = mesh.NbNodes()

- -

 

- -

if aMeshEditor.AddNode(47, - 12, 0) == 1:

- -

    print - "Node addition is OK!"

- -

else:

- -

    print - "KO node addition."

- -

aNodeId2 = mesh.NbNodes()

- -

 

- -

if aMeshEditor.AddNode(50, - 10, 10) == 1:

- -

    print - "Node addition is OK!"

- -

else:

- -

    print - "KO node addition."

- -

aNodeId3 = mesh.NbNodes()

- -

 

- -

if aMeshEditor.AddNode(47, - 12, 10) == 1:

- -

    print - "Node addition is OK!"

- -

else:

- -

    print - "KO node addition."

- -

aNodeId4 = mesh.NbNodes()

- -

 

- -

# add hexahedron

- -

if aMeshEditor.AddVolume([aNodeId2, - aNodeId1, 38, 39, aNodeId4, aNodeId3, 245, 246]) == 1:

- -

    print - "Hexahedron addition is OK!"

- -

else:

- -

    print - "KO Hexahedron addition."

- -

    

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Add Polygon

- -

import salome

- -

import geompy

- -

import math

- -

 

- -

import StdMeshers

- -

 

- -

# GEOM module

- -

shape_mesh = geompy.MakeCylinderRH(13, - 77)

- -

geompy.addToStudy(shape_mesh, - "cylinder")

- -

 

- -

# SMESH module

- -

smesh = salome.lcc.FindOrLoadComponent("FactoryServer", - "SMESH")

- -

smesh.SetCurrentStudy(salome.myStudy)

- -

mesh = smesh.CreateMesh(shape_mesh)

- -

MeshEditor = mesh.GetMeshEditor()

- -

 

- -

# a method to build a polygonal - mesh element with nb_vert angles:

- -

def MakePolygon - (a_mesh, x0, y0, z0, radius, nb_vert):

- -

    node_start_id - = a_mesh.NbNodes() + 1

- -

    al - = 2.0 * math.pi / nb_vert

- -

    node_ids - = []

- -

    

- -

# Create nodes for a polyhedron

- -

    for - ii in range(nb_vert):

- -

        MeshEditor.AddNode(x0 - + radius * math.cos(ii*al),

- -

                           y0 - + radius * math.sin(ii*al),

- -

                           z0)

- -

        node_ids.append(node_start_id - + ii)

- -

        pass

- -

    

- -

# Create a polygon

- -

    MeshEditor.AddPolygonalFace(node_ids)

- -

    return - 0

- -

 

- -

# Create three polygons

- -

MakePolygon(mesh, - 0, 0,  0, - 30, 13)

- -

MakePolygon(mesh, - 0, 0, 10, 21,  9)

- -

MakePolygon(mesh, - 0, 0, 20, 13,  6)

- -

 

- -

salome.sg.updateObjBrowser(1) -  

- -

 

- -

Add polyhedron

- -

import - salome

- -

import geompy

- -

import math

- -

 

- -

#import SMESH

- -

import StdMeshers

- -

 

- -

# GEOM

- -

shape_mesh = geompy.MakeCylinderRH(13, - 77)

- -

geompy.addToStudy(shape_mesh, - "cylinder")

- -

 

- -

# SMESH

- -

smesh = salome.lcc.FindOrLoadComponent("FactoryServer", - "SMESH")

- -

smesh.SetCurrentStudy(salome.myStudy)

- -

mesh = smesh.CreateMesh(shape_mesh)

- -

MeshEditor = mesh.GetMeshEditor()

- -

 

- -

# Now we are going - to create a 12-hedron:

- -

 

- -

# Create nodes for - polyhedron

- -

al = 2 * math.pi - / 5.0

- -

cosal = math.cos(al)

- -

 

- -

aa = 13

- -

rr = aa / (2.0 * - math.sin(al/2.0))

- -

dr = 2.0 * rr * - cosal

- -

r1 = rr + dr

- -

dh = rr * math.sqrt(2.0 - * (1.0 - cosal * (1.0 + 2.0 * cosal)))

- -

hh = 2.0 * dh - - dr * (rr*(cosal - 1) + (rr + dr)*(math.cos(al/2) - 1)) / dh

- -

 

- -

for i in range(5):

- -

    MeshEditor.AddNode(rr*math.cos(i*al), - rr*math.sin(i*al),  0) - # 1,3,5,7, 9 # bottom

- -

    MeshEditor.AddNode(r1*math.cos(i*al), - r1*math.sin(i*al), dh) # - 2,4,6,8,10 # above bottom

- -

 

- -

for i in range(5):

- -

    MeshEditor.AddNode(rr*math.cos(i*al - + al/2.0),

- -

                       rr*math.sin(i*al - + al/2.0), hh) # 11,13,15,17,19 # - top

- -

    MeshEditor.AddNode(r1*math.cos(i*al - + al/2.0),

- -

                       r1*math.sin(i*al - + al/2.0), hh - dh) # 12,14,16,18,20 # - below top

- -

 

- -

# Create a polyhedral - volume

- -

MeshEditor.AddPolyhedralVolume([ - 1,  3,  5, -  7,  9, -  # - bottom

- -

                                 1, -  2, 12, -  4,  3, -  # - .

- -

                                 3, -  4, 14, -  6,  5, -  # - .

- -

                                 5, -  6, 16, -  8,  7, -  # - . above bottom

- -

                                 7, -  8, 18, - 10,  9, -  # - .

- -

                                 9, - 10, 20,  2, -  1,  # - .

- -

                                11, - 12,  4, - 14, 13,  # - -

- -

                                13, - 14,  6, - 16, 15,  # - -

- -

                                15, - 16,  8, - 18, 17,  # - - below top

- -

                                17, - 18, 10, 20, 19,  # - -

- -

                                19, - 20,  2, - 12, 11,  # - -

- -

                                11, - 13, 15, 17, 19], # - top

- -

                               [5,5,5,5,5,5,5,5,5,5,5,5])

- -

 

- -

salome.sg.updateObjBrowser(1) -  

- -

 

- -

Removing Nodes and Elements

- -

Removing Nodes

- -

 

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# add node

- -

aMeshEditor = mesh.GetMeshEditor()

- -

if aMeshEditor.RemoveNodes([246, - 255]) == 1:

- -

    print - "Node removing is OK!"

- -

else:

- -

    print - "KO node removing."

- -

    

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Removing Elements

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

anEditor = mesh.GetMeshEditor()

- -

anEditor.RemoveElements([850, - 859, 814])

- -

 

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Renumbering Nodes and Elements

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

anEditor = mesh.GetMeshEditor()

- -

anEditor.RenumberNodes()

- -

 

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

 

- -

Moving Nodes

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# move node

- -

aMeshEditor = mesh.GetMeshEditor()

- -

aMeshEditor.MoveNode(38, - 20, 10, 0)

- -

    

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Diagonal Inversion

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# inverse diagonal

- -

aMeshEditor = mesh.GetMeshEditor()

- -

aMeshEditor.InverseDiag(700, - 642)

- -

    

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Uniting two Triangles

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# delete diagonal

- -

aMeshEditor = mesh.GetMeshEditor()

- -

aMeshEditor.DeleteDiag(700, - 642)

- -

    

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Uniting a Set of Triangles

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# unite a set of triangles

- -

aFilterMgr = smesh.CreateFilterManager()

- -

aFunctor = aFilterMgr.CreateMinimumAngle()

- -

 

- -

aMeshEditor = mesh.GetMeshEditor()

- -

aMeshEditor.TriToQuad([1145, - 1147, 1159, 1135], aFunctor, 60)

- -

    

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Orientation

- -

import - salome

- -

import geompy

- -

 

- -

import StdMeshers

- -

 

- -

# GEOM module

- -

shape_mesh = geompy.MakeCylinderRH(13, - 77)

- -

geompy.addToStudy(shape_mesh, - "cylinder")

- -

 

- -

# SMESH module

- -

smesh = salome.lcc.FindOrLoadComponent("FactoryServer", - "SMESH")

- -

smesh.SetCurrentStudy(salome.myStudy)

- -

mesh = smesh.CreateMesh(shape_mesh)

- -

MeshEditor = mesh.GetMeshEditor()

- -

 

- -

# build five quadrangles:

- -

node_start_id = mesh.NbNodes() - + 1

- -

dx = 10

- -

dy = 20

- -

 

- -

MeshEditor.AddNode(0.0 - * dx, 0, 0) # 1

- -

MeshEditor.AddNode(1.0 - * dx, 0, 0) # 2

- -

MeshEditor.AddNode(2.0 - * dx, 0, 0) # 3

- -

MeshEditor.AddNode(3.0 - * dx, 0, 0) # 4

- -

MeshEditor.AddNode(4.0 - * dx, 0, 0) # 5

- -

MeshEditor.AddNode(5.0 - * dx, 0, 0) # 6

- -

 

- -

MeshEditor.AddNode(0.0 - * dx, dy, 0) # 7

- -

MeshEditor.AddNode(1.0 - * dx, dy, 0) # 8

- -

MeshEditor.AddNode(2.0 - * dx, dy, 0) # 9

- -

MeshEditor.AddNode(3.0 - * dx, dy, 0) # 10

- -

MeshEditor.AddNode(4.0 - * dx, dy, 0) # 11

- -

MeshEditor.AddNode(5.0 - * dx, dy, 0) # 12

- -

 

- -

MeshEditor.AddFace([1, - 2,  8,  7])

- -

MeshEditor.AddFace([2, - 3,  9,  8])

- -

MeshEditor.AddFace([3, - 4, 10,  9])

- -

MeshEditor.AddFace([4, - 5, 11, 10])

- -

MeshEditor.AddFace([5, - 6, 12, 11])

- -

 

- -

# Change orientation - of the second and the fourth faces.

- -

MeshEditor.Reorient([2, - 4])

- -

 

- -

salome.sg.updateObjBrowser(1) -  

- -

 

- -

Cutting Quadrangles

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# unite a set of triangles

- -

aFilterMgr = smesh.CreateFilterManager()

- -

aFunctor = aFilterMgr.CreateMinimumAngle()

- -

 

- -

aMeshEditor = mesh.GetMeshEditor()

- -

aMeshEditor.QuadToTri([405, - 406], aFunctor)

- -

    

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Smoothing

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# smooth

- -

FacesSmooth = [911, - 931, 950, 864, 932]

- -

GroupSmooth = mesh.CreateGroup(SMESH.FACE,"Group - of faces (smooth)")

- -

GroupSmooth.Add(FacesSmooth)

- -

 

- -

aMeshEditor = mesh.GetMeshEditor()

- -

aMeshEditor.SmoothObject(GroupSmooth, - [], 20, 2, SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH)

- -

 

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

 

- -

Extrusion

- -

import SMESH

- -

import SMESH_mechanic

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# extrusion of the group

- -

point = SMESH.PointStruct(0, - 0, 5)

- -

vector = SMESH.DirStruct(point)

- -

FacesTriToQuad = [2381, - 2382, 2383, 2384, 2385, 2386, 2387, 2388, 2389, 2390, 2391, 2392, 2393, - 2394, 2395, 2396, 2397, 2398, 2399, 2400, 2401, 2402, 2403, 2404, 2405, - 2406, 2407, 2408, 2409, 2410, 2411, 2412, 2413, 2414, 2415, 2416, 2417, - 2418, 2419, 2420, 2421, 2422]

- -

 

- -

GroupTriToQuad = mesh.CreateGroup(SMESH.FACE,"Group - of faces (quad)")

- -

GroupTriToQuad.Add(FacesTriToQuad)

- -

 

- -

aMeshEditor = mesh.GetMeshEditor()

- -

aMeshEditor.ExtrusionSweepObject(GroupTriToQuad, - vector, 5)

- -

 

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Extrusion along a Path

- -

import math

- -

 

- -

import salome

- -

salome.salome_init()

- -

 

- -

# Geometry

- -

import geompy

- -

 

- -

# 1. Create points

- -

points = [[0, 0], - [50, 30], [50, 110], [0, 150], [-80, 150], [-130, 70], [-130, -20]]

- -

 

- -

iv = 1

- -

vertices = []

- -

for point in points:

- -

vert - = geompy.MakeVertex(point[0], point[1], 0)

- -

geompy.addToStudy(vert, - "Vertex_" + `iv`)

- -

vertices.append(vert)

- -

iv - += 1

- -

pass

- -

 

- -

# 2. Create edges and - wires

- -

Edge_straight = geompy.MakeEdge(vertices[0], - vertices[4])

- -

Edge_bezierrr = geompy.MakeBezier(vertices)

- -

Wire_polyline = geompy.MakePolyline(vertices)

- -

Edge_Circle   = - geompy.MakeCircleThreePnt(vertices[0], vertices[1], vertices[2])

- -

 

- -

geompy.addToStudy(Edge_straight, - "Edge_straight")

- -

geompy.addToStudy(Edge_bezierrr, - "Edge_bezierrr")

- -

geompy.addToStudy(Wire_polyline, - "Wire_polyline")

- -

geompy.addToStudy(Edge_Circle -  , "Edge_Circle")

- -

 

- -

# 3. Explode wire on - edges, as they will be used for mesh extrusion

- -

Wire_polyline_edges - = geompy.SubShapeAll(Wire_polyline, geompy.ShapeType["EDGE"])

- -

for ii in range(len(Wire_polyline_edges)):

- -

geompy.addToStudyInFather(Wire_polyline, - Wire_polyline_edges[ii], "Edge_" + `ii + 1`)

- -

pass

- -

 

- -

# Mesh

- -

import smesh

- -

import SMESH

- -

 

- -

gen = smesh.smesh

- -

 

- -

smeshgui = salome.ImportComponentGUI("SMESH")

- -

smeshgui.Init(salome.myStudyId)

- -

 

- -

# 1D algorithm and three - 1D hypotheses

- -

Wire_discretisation - = gen.CreateHypothesis('Regular_1D', 'libStdMeshersEngine.so')

- -

 

- -

Nb_Segments_3 = gen.CreateHypothesis('NumberOfSegments', - 'libStdMeshersEngine.so')

- -

Nb_Segments_7 = gen.CreateHypothesis('NumberOfSegments', - 'libStdMeshersEngine.so')

- -

Nb_Segments_8 = gen.CreateHypothesis('NumberOfSegments', - 'libStdMeshersEngine.so')

- -

 

- -

Nb_Segments_3.SetNumberOfSegments(3)

- -

Nb_Segments_7.SetNumberOfSegments(7)

- -

Nb_Segments_8.SetNumberOfSegments(8)

- -

 

- -

# Mesh given shape with - given 1d hypothesis

- -

def Mesh1D(shape1d, - hyp1d, name):

- -

mesh1d_tool - = smesh.Mesh(shape1d)

- -

mesh1d - = mesh1d_tool.GetMesh()

- -

status - = mesh1d.AddHypothesis(shape1d, hyp1d)

- -

status - = mesh1d.AddHypothesis(shape1d, Wire_discretisation)

- -

isDone - = mesh1d_tool.Compute()

- -

if - not isDone: print 'Mesh ', name, ': computation failed'

- -

return - mesh1d

- -

 

- -

# Create mesh with six - nodes, seven edges and two quadrangle faces

- -

def MakeQuadMesh2(mesh_name):

- -

quad_1 - = gen.CreateEmptyMesh()

- -

smeshgui.SetName(salome.ObjectToID(quad_1), - mesh_name)

- -

editor_1 - = quad_1.GetMeshEditor()

- -

 

- -

# six nodes

- -

n1 - = editor_1.AddNode(0, 20, 10)

- -

n2 - = editor_1.AddNode(0, 40, 10)

- -

n3 - = editor_1.AddNode(0, 40, 30)

- -

n4 - = editor_1.AddNode(0, 20, 30)

- -

n5 - = editor_1.AddNode(0,  0, - 30)

- -

n6 - = editor_1.AddNode(0,  0, - 10)

- -

 

- -

# seven edges

- -

editor_1.AddEdge([n1, - n2]) # 1

- -

editor_1.AddEdge([n2, - n3]) # 2

- -

editor_1.AddEdge([n3, - n4]) # 3

- -

editor_1.AddEdge([n4, - n1]) # 4

- -

editor_1.AddEdge([n4, - n5]) # 5

- -

editor_1.AddEdge([n5, - n6]) # 6

- -

editor_1.AddEdge([n6, - n1]) # 7

- -

 

- -

# two quadrangle faces

- -

editor_1.AddFace([n1, - n2, n3, n4]) # 8

- -

editor_1.AddFace([n1, - n4, n5, n6]) # 9

- -

return - [quad_1, editor_1, [1,2,3,4,5,6,7], [8,9]]

- -

 

- -

# Path meshes

- -

Edge_straight_mesh - = Mesh1D(Edge_straight, Nb_Segments_7, "Edge_straight")

- -

Edge_bezierrr_mesh - = Mesh1D(Edge_bezierrr, Nb_Segments_7, "Edge_bezierrr")

- -

Wire_polyline_mesh - = Mesh1D(Wire_polyline, Nb_Segments_3, "Wire_polyline")

- -

Edge_Circle_mesh   = - Mesh1D(Edge_Circle  , - Nb_Segments_8, "Edge_Circle")

- -

 

- -

# Initial meshes (to - be extruded)

- -

[quad_1, editor_1, - ee_1, ff_1] = MakeQuadMesh2("quad_1")

- -

[quad_2, editor_2, - ee_2, ff_2] = MakeQuadMesh2("quad_2")

- -

[quad_3, editor_3, - ee_3, ff_3] = MakeQuadMesh2("quad_3")

- -

[quad_4, editor_4, - ee_4, ff_4] = MakeQuadMesh2("quad_4")

- -

[quad_5, editor_5, - ee_5, ff_5] = MakeQuadMesh2("quad_5")

- -

[quad_6, editor_6, - ee_6, ff_6] = MakeQuadMesh2("quad_6")

- -

[quad_7, editor_7, - ee_7, ff_7] = MakeQuadMesh2("quad_7")

- -

 

- -

# ExtrusionAlongPath

- -

# IDsOfElements, PathMesh, - PathShape, NodeStart,

- -

# HasAngles, Angles, - HasRefPoint, RefPoint

- -

 

- -

refPoint = SMESH.PointStruct(0, - 0, 0)

- -

 

- -

a10 = 10.0*math.pi/180.0

- -

a45 = 45.0*math.pi/180.0

- -

 

- -

# 1. Extrusion of two - mesh edges along straight path

- -

error = editor_1.ExtrusionAlongPath([1,2], - Edge_straight_mesh, Edge_straight, 1,

- -

    0, - [], 0, refPoint)

- -

 

- -

# 2. Extrusion of one - mesh edge along curved path

- -

error = editor_2.ExtrusionAlongPath([2], - Edge_bezierrr_mesh, Edge_bezierrr, 1,

- -

    0, - [], 0, refPoint)

- -

 

- -

# 3. Extrusion of one - mesh edge along curved path with angles usage

- -

error = editor_3.ExtrusionAlongPath([2], - Edge_bezierrr_mesh, Edge_bezierrr, 1,

- -

    1, - [a45, a45, a45, 0, -a45, -a45, -a45], 0, refPoint)

- -

 

- -

# 4. Extrusion of one - mesh edge along path, which is a part of meshed wire

- -

error = editor_4.ExtrusionAlongPath([4], - Wire_polyline_mesh, Wire_polyline_edges[0], 1,

- -

    1, - [a10, a10, a10], 0, refPoint)

- -

 

- -

# 5. Extrusion of two - mesh faces along path, which is a part of meshed wire

- -

error = editor_5.ExtrusionAlongPath(ff_5 - , Wire_polyline_mesh, Wire_polyline_edges[2], 4,

- -

    0, - [], 0, refPoint)

- -

 

- -

# 6. Extrusion of two - mesh faces along closed path

- -

error = editor_6.ExtrusionAlongPath(ff_6 - , Edge_Circle_mesh, Edge_Circle, 1,

- -

    0, - [], 0, refPoint)

- -

 

- -

# 7. Extrusion of two - mesh faces along closed path with angles usage

- -

error = editor_7.ExtrusionAlongPath(ff_7, - Edge_Circle_mesh, Edge_Circle, 1,

- -

    1, - [a45, -a45, a45, -a45, a45, -a45, a45, -a45], 0, refPoint)

- -

 

- -

if salome.sg.hasDesktop():

- -

salome.sg.updateObjBrowser(1)

- -

pass

- -

Revolution

- -

import SMESH

- -

import SMESH_mechanic

- -

import math

- -

 

- -

smesh  = - SMESH_mechanic.smesh

- -

mesh   = - SMESH_mechanic.mesh

- -

salome = SMESH_mechanic.salome

- -

 

- -

# rotate a sweep object

- -

FacesRotate = [492, - 493, 502, 503]

- -

GroupRotate = mesh.CreateGroup(SMESH.FACE,"Group - of faces (rotate)")

- -

GroupRotate.Add(FacesRotate)

- -

angle45 =  45*math.pi/180

- -

axisXYZ = SMESH.AxisStruct(-38.3128, - -73.3658, -23.321, -13.3402, -13.3265, 6.66632)

- -

 

- -

aMeshEditor = mesh.GetMeshEditor()

- -

aMeshEditor.RotationSweepObject(GroupRotate, - axisXYZ, angle45, 4, 1e-5)

- -

 

- -

salome.sg.updateObjBrowser(1) -

- -

 

- -

Pattern Mapping

- -

import salome

- -

import geompy

- -

import SMESH, smesh

- -

 

- -

geompy.init_geom(salome.myStudy)

- -

smesh.smesh.SetCurrentStudy(salome.myStudy)

- -

 

- -

# define geometry

- -

Box_1 = geompy.MakeBoxDXDYDZ(200, - 200, 200)

- -

geompy.addToStudy(Box_1, - "Box_1")

- -

 

- -

faces = geompy.SubShapeAll(Box_1, - geompy.ShapeType["FACE"])

- -

Face_1 = faces[0]

- -

Face_2 = faces[1]

- -

geompy.addToStudyInFather(Box_1, - Face_1, "Face_1")

- -

geompy.addToStudyInFather(Box_1, - Face_2, "Face_2")

- -

 

- -

# build quadrangle mesh - 3x3 on Face_1

- -

Mesh_1 = smesh.Mesh(Face_1)

- -

Wire_discretisation - = Mesh_1.Segment()

- -

Wire_discretisation.NumberOfSegments(3)

- -

Mesh_1.Quadrangle()

- -

 

- -

isDone = Mesh_1.Compute()

- -

if not isDone: print - 'Mesh Mesh_1 : computation failed'

- -

 

- -

# pattern the mesh

- -

Mesh_2 = smesh.Mesh(Face_2)

- -

Nb_Segments_1 = smesh.smesh.CreateHypothesis('NumberOfSegments', - 'libStdMeshersEngine.so')

- -

Nb_Segments_1.SetNumberOfSegments(1)

- -

status = Mesh_2.GetMesh().AddHypothesis(Face_2, - Nb_Segments_1)

- -

status = Mesh_2.GetMesh().AddHypothesis(Face_2, - Wire_discretisation.GetAlgorithm())

- -

Triangle_Mefisto = - Mesh_2.Triangle()

- -

Max_Element_Area = - Triangle_Mefisto.MaxElementArea(240)

- -

 

- -

isDone = Mesh_2.Compute()

- -

if not isDone: print - 'Mesh Mesh_2 : computation failed'

- -

 

- -

# create a pattern

- -

pattern = smesh.smesh.GetPattern()

- -

isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), - Face_2, 0)

- -

if (isDone != 1):

- -

print - 'LoadFromFace :', pattern.GetErrorCode()

- -

 

- -

# apply the pattern to - a face of the first mesh

- -

pattern.ApplyToMeshFaces(Mesh_1.GetMesh(), - [17], 0, 0)

- -

isDone = pattern.MakeMesh(Mesh_1.GetMesh(), - 0, 0)

- -

if (isDone != 1):

- -

print - 'MakeMesh :', pattern.GetErrorCode()

- -

 

- -

salome.sg.updateObjBrowser(1) -

- - - - + + + + + +Modifying Meshes + + + + + + + + + + + +

Modifying Meshes

+ +

Adding Nodes and Elements

+ +

# Attention! The scripts for Adding nodes + and Elements  have + been written using the old approach basing on direct usage of SMESH idl + interface.

+ +

# For the moment smesh package doesn't provide + methods to add nodes and elements.

+ +

# + In the next SALOME version the scripts will be updated to use only the + commands from smesh package.

+ +

Add Node

+ +

import + SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# add node

+ +

new_id = aMeshEditor.AddNode(50, + 10, 0)

+ +

print ""

+ +

if new_id == 0: + print "KO node addition."

+ +

else:           print + "New Node has been added with ID ", new_id

+ +

 

+ +

Add Edge

+ +

import + SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

print ""

+ +

 

+ +

# add node

+ +

n1 = aMeshEditor.AddNode(50, + 10, 0)

+ +

if n1 == 0: print + "KO node addition."

+ +

 

+ +

# add edge

+ +

e1 = aMeshEditor.AddEdge([n1, + 38])

+ +

if e1 == 0: print + "KO edge addition."

+ +

else:       print + "New Edge has been added with ID ", e1

+ +

 

+ +

Add Triangle

+ +

import + SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

print ""

+ +

 

+ +

# add node

+ +

n1 = aMeshEditor.AddNode(50, + 10, 0)

+ +

if n1 == 0: print + "KO node addition."

+ +

 

+ +

# add triangle

+ +

t1 = aMeshEditor.AddFace([n1, + 38, 39])

+ +

if t1 == 0: print + "KO triangle addition."

+ +

else:       print + "New Triangle has been added with ID ", t1

+ +

Add Quadrangle

+ +

import SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

print ""

+ +

 

+ +

# add node

+ +

n1 = aMeshEditor.AddNode(50, + 10, 0)

+ +

if n1 == 0: print + "KO node addition."

+ +

 

+ +

n2 = aMeshEditor.AddNode(40, + 20, 0)

+ +

if n2 == 0: print + "KO node addition."

+ +

 

+ +

# add quadrangle

+ +

q1 = aMeshEditor.AddFace([n2, + n1, 38, 39])

+ +

if q1 == 0: print + "KO quadrangle addition."

+ +

else: +       print + "New Quadrangle has been added with ID ", q1

+ +

Add Tetrahedron

+ +

import SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

print ""

+ +

 

+ +

# add node

+ +

n1 = aMeshEditor.AddNode(50, + 10, 0)

+ +

if n1 == 0: print + "KO node addition."

+ +

 

+ +

# add tetrahedron

+ +

t1 = aMeshEditor.AddVolume([n1, + 38, 39, 246])

+ +

if t1 == 0: print + "KO tetrahedron addition."

+ +

else: +       print + "New Tetrahedron has been added with ID ", t1

+ +

Add Hexahedron

+ +

import + SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

print ""

+ +

 

+ +

# add nodes

+ +

nId1 = aMeshEditor.AddNode(50, + 10, 0)

+ +

nId2 = aMeshEditor.AddNode(47, + 12, 0)

+ +

nId3 = aMeshEditor.AddNode(50, + 10, 10)

+ +

nId4 = aMeshEditor.AddNode(47, + 12, 10)

+ +

 

+ +

if nId1 == 0 or + nId2 == 0 or nId3 == 0 or nId4 == 0: print "KO node addition."

+ +

 

+ +

# add hexahedron

+ +

vId = aMeshEditor.AddVolume([nId2, + nId1, 38, 39, nId4, nId3, 245, 246])

+ +

if vId == 0: print + "KO Hexahedron addition."

+ +

else:        print + "New Hexahedron has been added with ID ", vId

+ +

 

+ +

Add Polygon

+ +

import + math

+ +

import salome

+ +

import smesh

+ +

 

+ +

# create an empty mesh + structure

+ +

gen = smesh.smesh

+ +

mesh = gen.CreateEmptyMesh()

+ +

MeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# a method to build + a polygonal mesh element with <nb_vert> angles:

+ +

def MakePolygon + (a_mesh, x0, y0, z0, radius, nb_vert):

+ +

    al + = 2.0 * math.pi / nb_vert

+ +

    node_ids + = []

+ +

 

+ +

          # + Create nodes for a polygon

+ +

    for + ii in range(nb_vert):

+ +

        nid + = MeshEditor.AddNode(x0 + radius * math.cos(ii*al),

+ +

                                 y0 + + radius * math.sin(ii*al),

+ +

                                 z0)

+ +

        node_ids.append(nid)

+ +

        pass

+ +

 

+ +

          # + Create a polygon

+ +

    return + MeshEditor.AddPolygonalFace(node_ids)

+ +

 

+ +

# Create three polygons

+ +

f1 = MakePolygon(mesh, + 0, 0,  0, + 30, 13)

+ +

f2 = MakePolygon(mesh, + 0, 0, 10, 21,  9)

+ +

f3 = MakePolygon(mesh, + 0, 0, 20, 13,  6)

+ +

 

+ +

salome.sg.updateObjBrowser(1) +

+ +

Add Polyhedron

+ +

import + salome

+ +

import math

+ +

import smesh

+ +

 

+ +

# create an empty mesh + structure

+ +

gen = smesh.smesh

+ +

mesh = gen.CreateEmptyMesh()

+ +

MeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# Create nodes for + 12-hedron with pentagonal faces

+ +

al = 2 * math.pi + / 5.0

+ +

cosal = math.cos(al)

+ +

aa = 13

+ +

rr = aa / (2.0 * + math.sin(al/2.0))

+ +

dr = 2.0 * rr * + cosal

+ +

r1 = rr + dr

+ +

dh = rr * math.sqrt(2.0 + * (1.0 - cosal * (1.0 + 2.0 * cosal)))

+ +

hh = 2.0 * dh - + dr * (rr*(cosal - 1) + (rr + dr)*(math.cos(al/2) - 1)) / dh

+ +

 

+ +

dd = [] # + top

+ +

cc = [] # + below top

+ +

bb = [] # + above bottom

+ +

aa = [] # + bottom

+ +

 

+ +

for i in range(5):

+ +

    cos_bot + = math.cos(i*al)

+ +

    sin_bot + = math.sin(i*al)

+ +

 

+ +

    cos_top + = math.cos(i*al + al/2.0)

+ +

    sin_top + = math.sin(i*al + al/2.0)

+ +

 

+ +

    nd + = MeshEditor.AddNode(rr * cos_top, rr * sin_top, hh     ) + # top

+ +

    nc + = MeshEditor.AddNode(r1 * cos_top, r1 * sin_top, hh - dh) # + below top

+ +

    nb + = MeshEditor.AddNode(r1 * cos_bot, r1 * sin_bot,      dh) + # above bottom

+ +

    na + = MeshEditor.AddNode(rr * cos_bot, rr * sin_bot,       0) + # bottom

+ +

    dd.append(nd) + # top

+ +

    cc.append(nc) + # below top

+ +

    bb.append(nb) + # above bottom

+ +

    aa.append(na) + # bottom

+ +

 

+ +

    pass

+ +

 

+ +

# Create a polyhedral + volume (12-hedron with pentagonal faces)

+ +

MeshEditor.AddPolyhedralVolume([dd[0], + dd[1], dd[2], dd[3], dd[4],  # + top

+ +

                                dd[0], + cc[0], bb[1], cc[1], dd[1],  # + -

+ +

                                dd[1], + cc[1], bb[2], cc[2], dd[2],  # + -

+ +

                                dd[2], + cc[2], bb[3], cc[3], dd[3],  # + - below top

+ +

                                dd[3], + cc[3], bb[4], cc[4], dd[4],  # + -

+ +

                                dd[4], + cc[4], bb[0], cc[0], dd[0],  # + -

+ +

                                aa[4], + bb[4], cc[4], bb[0], aa[0],  # + .

+ +

                                aa[3], + bb[3], cc[3], bb[4], aa[4],  # + .

+ +

                                aa[2], + bb[2], cc[2], bb[3], aa[3],  # + . above bottom

+ +

                                aa[1], + bb[1], cc[1], bb[2], aa[2],  # + .

+ +

                                aa[0], + bb[0], cc[0], bb[1], aa[1],  # + .

+ +

                                aa[0], + aa[1], aa[2], aa[3], aa[4]], # + bottom

+ +

                               [5,5,5,5,5,5,5,5,5,5,5,5])

+ +

salome.sg.updateObjBrowser(1) +

+ +

 

+ +

Removing Nodes and Elements

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to remove nodes and elements.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

Removing Nodes

+ +

 

+ +

import + SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# remove nodes #246 + and #255

+ +

res = aMeshEditor.RemoveNodes([246, + 255])

+ +

if res == 1: print + "Nodes removing is OK!"

+ +

else:        print + "KO nodes removing."

+ +

 

+ +

Removing Elements

+ +

import + SMESH_mechanic

+ +

mesh = SMESH_mechanic.mesh

+ +

 

+ +

anEditor = mesh.GetMeshEditor()

+ +

 

+ +

# remove three elements: + #850, #859 and #814

+ +

res = anEditor.RemoveElements([850, + 859, 814])

+ +

if res == 1: print + "Elements removing is OK!"

+ +

else:        print + "KO Elements removing."  

+ +

 

+ +

Renumbering Nodes and Elements

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to renumber nodes and elements.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

anEditor = mesh.GetMeshEditor()

+ +

 

+ +

anEditor.RenumberNodes() +

+ +

Moving Nodes

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to move nodes.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# move node #38

+ +

aMeshEditor.MoveNode(38, + 20., 10., 0.)

+ +

 

+ +

Diagonal Inversion

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to produce a diagonal inversion.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import salome

+ +

import smesh

+ +

 

+ +

# create an empty mesh + structure

+ +

gen = smesh.smesh

+ +

mesh = gen.CreateEmptyMesh()

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# create the following + mesh:

+ +

# .----.----.----.

+ +

# |   /| +   /| +   /|

+ +

# |  / + |  / |  / + |

+ +

# | /  | + /  | /  |

+ +

# |/   |/ +   |/ +   |

+ +

# .----.----.----.

+ +

 

+ +

bb = [0, 0, 0, 0]

+ +

tt = [0, 0, 0, 0]

+ +

ff = [0, 0, 0, 0, + 0, 0]

+ +

 

+ +

bb[0] = aMeshEditor.AddNode( + 0., 0., 0.)

+ +

bb[1] = aMeshEditor.AddNode(10., + 0., 0.)

+ +

bb[2] = aMeshEditor.AddNode(20., + 0., 0.)

+ +

bb[3] = aMeshEditor.AddNode(30., + 0., 0.)

+ +

 

+ +

tt[0] = aMeshEditor.AddNode( + 0., 15., 0.)

+ +

tt[1] = aMeshEditor.AddNode(10., + 15., 0.)

+ +

tt[2] = aMeshEditor.AddNode(20., + 15., 0.)

+ +

tt[3] = aMeshEditor.AddNode(30., + 15., 0.)

+ +

 

+ +

ff[0] = aMeshEditor.AddFace([bb[0], + bb[1], tt[1]])

+ +

ff[1] = aMeshEditor.AddFace([bb[0], + tt[1], tt[0]])

+ +

ff[2] = aMeshEditor.AddFace([bb[1], + bb[2], tt[2]])

+ +

ff[3] = aMeshEditor.AddFace([bb[1], + tt[2], tt[1]])

+ +

ff[4] = aMeshEditor.AddFace([bb[2], + bb[3], tt[3]])

+ +

ff[5] = aMeshEditor.AddFace([bb[2], + tt[3], tt[2]])

+ +

 

+ +

# inverse the diagonal + bb[1] - tt[2]

+ +

print "\nDiagonal + inversion ... ",

+ +

res = aMeshEditor.InverseDiag(bb[1], + tt[2])

+ +

if not res: print + "failed!"

+ +

else:       print + "done."

+ +

 

+ +

salome.sg.updateObjBrowser(1) +

+ +

Uniting two Triangles

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to unite two triangles.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import salome

+ +

import smesh

+ +

 

+ +

# create an empty mesh structure

+ +

gen = smesh.smesh

+ +

mesh = gen.CreateEmptyMesh()

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# create the following mesh:

+ +

# .----.----.----.

+ +

# |   /| +   /| +   /|

+ +

# |  / + |  / |  / + |

+ +

# | /  | + /  | /  |

+ +

# |/   |/ +   |/ +   |

+ +

# .----.----.----.

+ +

 

+ +

bb = [0, 0, 0, 0]

+ +

tt = [0, 0, 0, 0]

+ +

ff = [0, 0, 0, 0, + 0, 0]

+ +

 

+ +

bb[0] = aMeshEditor.AddNode( + 0., 0., 0.)

+ +

bb[1] = aMeshEditor.AddNode(10., + 0., 0.)

+ +

bb[2] = aMeshEditor.AddNode(20., + 0., 0.)

+ +

bb[3] = aMeshEditor.AddNode(30., + 0., 0.)

+ +

 

+ +

tt[0] = aMeshEditor.AddNode( + 0., 15., 0.)

+ +

tt[1] = aMeshEditor.AddNode(10., + 15., 0.)

+ +

tt[2] = aMeshEditor.AddNode(20., + 15., 0.)

+ +

tt[3] = aMeshEditor.AddNode(30., + 15., 0.)

+ +

 

+ +

ff[0] = aMeshEditor.AddFace([bb[0], + bb[1], tt[1]])

+ +

ff[1] = aMeshEditor.AddFace([bb[0], + tt[1], tt[0]])

+ +

ff[2] = aMeshEditor.AddFace([bb[1], + bb[2], tt[2]])

+ +

ff[3] = aMeshEditor.AddFace([bb[1], + tt[2], tt[1]])

+ +

ff[4] = aMeshEditor.AddFace([bb[2], + bb[3], tt[3]])

+ +

ff[5] = aMeshEditor.AddFace([bb[2], + tt[3], tt[2]])

+ +

 

+ +

# delete the diagonal bb[1] - tt[2]

+ +

print "\nUnite + two triangles ... ",

+ +

res = aMeshEditor.DeleteDiag(bb[1], + tt[2])

+ +

if not res: print + "failed!"

+ +

else:       print + "done."

+ +

 

+ +

salome.sg.updateObjBrowser(1) +

+ +

Uniting a Set of Triangles

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to unite a set of triangles.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import salome

+ +

import smesh

+ +

 

+ +

# create an empty mesh + structure

+ +

gen = smesh.smesh

+ +

mesh = gen.CreateEmptyMesh()

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# create the following + mesh:

+ +

# .----.----.----.

+ +

# |   /| +   /| +   /|

+ +

# |  / + |  / |  / + |

+ +

# | /  | + /  | /  |

+ +

# |/   |/ +   |/ +   |

+ +

# .----.----.----.

+ +

 

+ +

bb = [0, 0, 0, 0]

+ +

tt = [0, 0, 0, 0]

+ +

ff = [0, 0, 0, 0, + 0, 0]

+ +

 

+ +

bb[0] = aMeshEditor.AddNode( + 0., 0., 0.)

+ +

bb[1] = aMeshEditor.AddNode(10., + 0., 0.)

+ +

bb[2] = aMeshEditor.AddNode(20., + 0., 0.)

+ +

bb[3] = aMeshEditor.AddNode(30., + 0., 0.)

+ +

 

+ +

tt[0] = aMeshEditor.AddNode( + 0., 15., 0.)

+ +

tt[1] = aMeshEditor.AddNode(10., + 15., 0.)

+ +

tt[2] = aMeshEditor.AddNode(20., + 15., 0.)

+ +

tt[3] = aMeshEditor.AddNode(30., + 15., 0.)

+ +

 

+ +

ff[0] = aMeshEditor.AddFace([bb[0], + bb[1], tt[1]])

+ +

ff[1] = aMeshEditor.AddFace([bb[0], + tt[1], tt[0]])

+ +

ff[2] = aMeshEditor.AddFace([bb[1], + bb[2], tt[2]])

+ +

ff[3] = aMeshEditor.AddFace([bb[1], + tt[2], tt[1]])

+ +

ff[4] = aMeshEditor.AddFace([bb[2], + bb[3], tt[3]])

+ +

ff[5] = aMeshEditor.AddFace([bb[2], + tt[3], tt[2]])

+ +

 

+ +

# unite a set of triangles

+ +

aFilterMgr = smesh.smesh.CreateFilterManager()

+ +

aFunctor = aFilterMgr.CreateMinimumAngle()

+ +

print "\nUnite + a set of triangles ... ",

+ +

res = aMeshEditor.TriToQuad([ff[2], + ff[3], ff[4], ff[5]], aFunctor, 60.)

+ +

if not res: print + "failed!"

+ +

else:       print + "done."

+ +

 

+ +

salome.sg.updateObjBrowser(1) +

+ +

Orientation

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to change orientation.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import salome

+ +

import smesh

+ +

 

+ +

# SMESH module

+ +

gen = smesh.smesh

+ +

mesh = gen.CreateEmptyMesh()

+ +

MeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# build five quadrangles:

+ +

dx = 10

+ +

dy = 20

+ +

 

+ +

n1  = + MeshEditor.AddNode(0.0 * dx, 0, 0)

+ +

n2  = + MeshEditor.AddNode(1.0 * dx, 0, 0)

+ +

n3  = + MeshEditor.AddNode(2.0 * dx, 0, 0)

+ +

n4  = + MeshEditor.AddNode(3.0 * dx, 0, 0)

+ +

n5  = + MeshEditor.AddNode(4.0 * dx, 0, 0)

+ +

n6  = + MeshEditor.AddNode(5.0 * dx, 0, 0)

+ +

n7  = + MeshEditor.AddNode(0.0 * dx, dy, 0)

+ +

n8  = + MeshEditor.AddNode(1.0 * dx, dy, 0)

+ +

n9  = + MeshEditor.AddNode(2.0 * dx, dy, 0)

+ +

n10 = MeshEditor.AddNode(3.0 + * dx, dy, 0)

+ +

n11 = MeshEditor.AddNode(4.0 + * dx, dy, 0)

+ +

n12 = MeshEditor.AddNode(5.0 + * dx, dy, 0)

+ +

 

+ +

f1 = MeshEditor.AddFace([n1, + n2, n8 , n7 ])

+ +

f2 = MeshEditor.AddFace([n2, + n3, n9 , n8 ])

+ +

f3 = MeshEditor.AddFace([n3, + n4, n10, n9 ])

+ +

f4 = MeshEditor.AddFace([n4, + n5, n11, n10])

+ +

f5 = MeshEditor.AddFace([n5, + n6, n12, n11])

+ +

 

+ +

# Change the orientation + of the second and the fourth faces.

+ +

MeshEditor.Reorient([2, + 4])

+ +

 

+ +

salome.sg.updateObjBrowser(1) +

+ +

 

+ +

Cutting Quadrangles

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to cut quadrangles.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

smesh = SMESH_mechanic.smesh

+ +

mesh  = + SMESH_mechanic.mesh

+ +

 

+ +

# cut two quadrangles: + 405 and 406

+ +

aFilterMgr = smesh.CreateFilterManager()

+ +

aFunctor = aFilterMgr.CreateMinimumAngle()

+ +

 

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

aMeshEditor.QuadToTri([405, + 406], aFunctor)

+ +

 

+ +

Smoothing

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to perform smoothing.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import salome

+ +

import geompy

+ +

 

+ +

import SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# select the top face

+ +

faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, + geompy.ShapeType["FACE"])

+ +

face = faces[3]

+ +

geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, + face, "face planar with hole")

+ +

 

+ +

# create a group of faces + to be smoothed

+ +

GroupSmooth = mesh.CreateGroupFromGEOM(SMESH.FACE, + "Group of faces (smooth)", face)

+ +

 

+ +

# perform smoothing

+ +

# boolean SmoothObject(Object, + IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method)

+ +

res = aMeshEditor.SmoothObject(GroupSmooth, + [], 20, 2., SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH)

+ +

 

+ +

print "\nSmoothing + ... ",

+ +

if not res: print + "failed!"

+ +

else:       print + "done."

+ +

 

+ +

salome.sg.updateObjBrowser(1) +

+ +

 

+ +

Extrusion

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to perform extrusion.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import salome

+ +

import geompy

+ +

 

+ +

import SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# select the top face

+ +

faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, + geompy.ShapeType["FACE"])

+ +

face = faces[7]

+ +

geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, + face, "face circular top")

+ +

 

+ +

# create a vector for + extrusion

+ +

point = SMESH.PointStruct(0., + 0., 5.)

+ +

vector = SMESH.DirStruct(point)

+ +

 

+ +

# create a group to be + extruded

+ +

GroupTri = mesh.CreateGroupFromGEOM(SMESH.FACE, + "Group of faces (extrusion)", face)

+ +

 

+ +

# perform extrusion of + the group

+ +

aMeshEditor.ExtrusionSweepObject(GroupTri, + vector, 5)

+ +

 

+ +

salome.sg.updateObjBrowser(1) +

+ +

Extrusion along a Path

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to perform extrusion along a path.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import math

+ +

import salome

+ +

 

+ +

# Geometry

+ +

import geompy

+ +

 

+ +

# 1. Create points

+ +

points = [[0, 0], + [50, 30], [50, 110], [0, 150], [-80, 150], [-130, 70], [-130, -20]]

+ +

 

+ +

iv = 1

+ +

vertices = []

+ +

for point in points:

+ +

vert + = geompy.MakeVertex(point[0], point[1], 0)

+ +

geompy.addToStudy(vert, + "Vertex_" + `iv`)

+ +

vertices.append(vert)

+ +

iv + += 1

+ +

pass

+ +

 

+ +

# 2. Create edges and + wires

+ +

Edge_straight = geompy.MakeEdge(vertices[0], + vertices[4])

+ +

Edge_bezierrr = geompy.MakeBezier(vertices)

+ +

Wire_polyline = geompy.MakePolyline(vertices)

+ +

Edge_Circle   = + geompy.MakeCircleThreePnt(vertices[0], vertices[1], vertices[2])

+ +

 

+ +

geompy.addToStudy(Edge_straight, + "Edge_straight")

+ +

geompy.addToStudy(Edge_bezierrr, + "Edge_bezierrr")

+ +

geompy.addToStudy(Wire_polyline, + "Wire_polyline")

+ +

geompy.addToStudy(Edge_Circle +  , "Edge_Circle")

+ +

 

+ +

# 3. Explode wire on + edges, as they will be used for mesh extrusion

+ +

Wire_polyline_edges + = geompy.SubShapeAll(Wire_polyline, geompy.ShapeType["EDGE"])

+ +

for ii in range(len(Wire_polyline_edges)):

+ +

geompy.addToStudyInFather(Wire_polyline, + Wire_polyline_edges[ii], "Edge_" + `ii + 1`)

+ +

pass

+ +

 

+ +

# Mesh

+ +

import smesh

+ +

import SMESH

+ +

 

+ +

gen = smesh.smesh

+ +

 

+ +

smeshgui = salome.ImportComponentGUI("SMESH")

+ +

smeshgui.Init(salome.myStudyId)

+ +

 

+ +

# 1D algorithm and three + 1D hypotheses

+ +

Wire_discretisation + = gen.CreateHypothesis('Regular_1D', 'libStdMeshersEngine.so')

+ +

 

+ +

Nb_Segments_3 = gen.CreateHypothesis('NumberOfSegments', + 'libStdMeshersEngine.so')

+ +

Nb_Segments_7 = gen.CreateHypothesis('NumberOfSegments', + 'libStdMeshersEngine.so')

+ +

Nb_Segments_8 = gen.CreateHypothesis('NumberOfSegments', + 'libStdMeshersEngine.so')

+ +

 

+ +

Nb_Segments_3.SetNumberOfSegments(3)

+ +

Nb_Segments_7.SetNumberOfSegments(7)

+ +

Nb_Segments_8.SetNumberOfSegments(8)

+ +

 

+ +

# Mesh given shape with + given 1d hypothesis

+ +

def Mesh1D(shape1d, + hyp1d, name):

+ +

mesh1d_tool + = smesh.Mesh(shape1d)

+ +

mesh1d + = mesh1d_tool.GetMesh()

+ +

status + = mesh1d.AddHypothesis(shape1d, hyp1d)

+ +

status + = mesh1d.AddHypothesis(shape1d, Wire_discretisation)

+ +

isDone + = mesh1d_tool.Compute()

+ +

if + not isDone: print 'Mesh ', name, ': computation failed'

+ +

return + mesh1d

+ +

 

+ +

# Create a mesh with + six nodes, seven edges and two quadrangle faces

+ +

def MakeQuadMesh2(mesh_name):

+ +

quad_1 + = gen.CreateEmptyMesh()

+ +

smeshgui.SetName(salome.ObjectToID(quad_1), + mesh_name)

+ +

editor_1 + = quad_1.GetMeshEditor()

+ +

 

+ +

# six nodes

+ +

n1 + = editor_1.AddNode(0, 20, 10)

+ +

n2 + = editor_1.AddNode(0, 40, 10)

+ +

n3 + = editor_1.AddNode(0, 40, 30)

+ +

n4 + = editor_1.AddNode(0, 20, 30)

+ +

n5 + = editor_1.AddNode(0,  0, + 30)

+ +

n6 + = editor_1.AddNode(0,  0, + 10)

+ +

 

+ +

# seven edges

+ +

editor_1.AddEdge([n1, + n2]) # 1

+ +

editor_1.AddEdge([n2, + n3]) # 2

+ +

editor_1.AddEdge([n3, + n4]) # 3

+ +

editor_1.AddEdge([n4, + n1]) # 4

+ +

editor_1.AddEdge([n4, + n5]) # 5

+ +

editor_1.AddEdge([n5, + n6]) # 6

+ +

editor_1.AddEdge([n6, + n1]) # 7

+ +

 

+ +

# two quadrangle faces

+ +

editor_1.AddFace([n1, + n2, n3, n4]) # 8

+ +

editor_1.AddFace([n1, + n4, n5, n6]) # 9

+ +

return + [quad_1, editor_1, [1,2,3,4,5,6,7], [8,9]]

+ +

 

+ +

# Path meshes

+ +

Edge_straight_mesh + = Mesh1D(Edge_straight, Nb_Segments_7, "Edge_straight")

+ +

Edge_bezierrr_mesh + = Mesh1D(Edge_bezierrr, Nb_Segments_7, "Edge_bezierrr")

+ +

Wire_polyline_mesh + = Mesh1D(Wire_polyline, Nb_Segments_3, "Wire_polyline")

+ +

Edge_Circle_mesh   = + Mesh1D(Edge_Circle  , + Nb_Segments_8, "Edge_Circle")

+ +

 

+ +

# Initial meshes (to + be extruded)

+ +

[quad_1, editor_1, + ee_1, ff_1] = MakeQuadMesh2("quad_1")

+ +

[quad_2, editor_2, + ee_2, ff_2] = MakeQuadMesh2("quad_2")

+ +

[quad_3, editor_3, + ee_3, ff_3] = MakeQuadMesh2("quad_3")

+ +

[quad_4, editor_4, + ee_4, ff_4] = MakeQuadMesh2("quad_4")

+ +

[quad_5, editor_5, + ee_5, ff_5] = MakeQuadMesh2("quad_5")

+ +

[quad_6, editor_6, + ee_6, ff_6] = MakeQuadMesh2("quad_6")

+ +

[quad_7, editor_7, + ee_7, ff_7] = MakeQuadMesh2("quad_7")

+ +

 

+ +

# ExtrusionAlongPath

+ +

# IDsOfElements, PathMesh, + PathShape, NodeStart,

+ +

# HasAngles, Angles, + HasRefPoint, RefPoint

+ +

 

+ +

refPoint = SMESH.PointStruct(0, + 0, 0)

+ +

 

+ +

a10 = 10.0*math.pi/180.0

+ +

a45 = 45.0*math.pi/180.0

+ +

 

+ +

# 1. Extrusion of two + mesh edges along a straight path

+ +

error = editor_1.ExtrusionAlongPath([1,2], + Edge_straight_mesh, Edge_straight, 1,

+ +

    0, + [], 0, refPoint)

+ +

 

+ +

# 2. Extrusion of one + mesh edge along a curved path

+ +

error = editor_2.ExtrusionAlongPath([2], + Edge_bezierrr_mesh, Edge_bezierrr, 1,

+ +

    0, + [], 0, refPoint)

+ +

 

+ +

# 3. Extrusion of one + mesh edge along a curved path with usage of angles

+ +

error = editor_3.ExtrusionAlongPath([2], + Edge_bezierrr_mesh, Edge_bezierrr, 1,

+ +

    1, + [a45, a45, a45, 0, -a45, -a45, -a45], 0, refPoint)

+ +

 

+ +

# 4. Extrusion of one + mesh edge along the path, which is a part of a meshed wire

+ +

error = editor_4.ExtrusionAlongPath([4], + Wire_polyline_mesh, Wire_polyline_edges[0], 1,

+ +

    1, + [a10, a10, a10], 0, refPoint)

+ +

 

+ +

# 5. Extrusion of two + mesh faces along the path, which is a part of a meshed wire

+ +

error = editor_5.ExtrusionAlongPath(ff_5 + , Wire_polyline_mesh, Wire_polyline_edges[2], 4,

+ +

    0, + [], 0, refPoint)

+ +

 

+ +

# 6. Extrusion of two + mesh faces along a closed path

+ +

error = editor_6.ExtrusionAlongPath(ff_6 + , Edge_Circle_mesh, Edge_Circle, 1,

+ +

    0, + [], 0, refPoint)

+ +

 

+ +

# 7. Extrusion of two + mesh faces along a closed path with usage of angles

+ +

error = editor_7.ExtrusionAlongPath(ff_7, + Edge_Circle_mesh, Edge_Circle, 1,

+ +

    1, + [a45, -a45, a45, -a45, a45, -a45, a45, -a45], 0, refPoint

+ +

 

+ +

salome.sg.updateObjBrowser(1)

+ +

Revolution

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to perform revolution.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import math

+ +

import SMESH

+ +

import SMESH_mechanic

+ +

 

+ +

mesh = SMESH_mechanic.mesh

+ +

aMeshEditor = mesh.GetMeshEditor()

+ +

 

+ +

# create a group of faces + to be revolved

+ +

FacesRotate = [492, + 493, 502, 503]

+ +

GroupRotate = mesh.CreateGroup(SMESH.FACE,"Group + of faces (rotate)")

+ +

GroupRotate.Add(FacesRotate)

+ +

 

+ +

# define revolution angle + and axis

+ +

angle45 = 45 * math.pi + / 180

+ +

axisXYZ = SMESH.AxisStruct(-38.3128, + -73.3658, -23.321, -13.3402, -13.3265, 6.66632)

+ +

 

+ +

# perform revolution + of an object

+ +

aMeshEditor.RotationSweepObject(GroupRotate, + axisXYZ, angle45, 4, 1e-5)

+ +

 

+ +

Pattern Mapping

+ +

# + Attention! This script has been written using the old approach basing + on direct usage of SMESH idl interface.

+ +

# For the moment smesh package doesn't provide + methods to perform pattern mapping.

+ +

# In the next SALOME version the scripts will + be updated to use only the commands from smesh package.

+ +

 

+ +

import geompy

+ +

import smesh

+ +

 

+ +

# define the geometry

+ +

Box_1 = geompy.MakeBoxDXDYDZ(200., + 200., 200.)

+ +

geompy.addToStudy(Box_1, + "Box_1")

+ +

 

+ +

faces = geompy.SubShapeAll(Box_1, + geompy.ShapeType["FACE"])

+ +

Face_1 = faces[0]

+ +

Face_2 = faces[1]

+ +

geompy.addToStudyInFather(Box_1, + Face_1, "Face_1")

+ +

geompy.addToStudyInFather(Box_1, + Face_2, "Face_2")

+ +

 

+ +

# build a quadrangle + mesh 3x3 on Face_1

+ +

Mesh_1 = smesh.Mesh(Face_1)

+ +

algo1D = Mesh_1.Segment()

+ +

algo1D.NumberOfSegments(3)

+ +

Mesh_1.Quadrangle()

+ +

 

+ +

isDone = Mesh_1.Compute()

+ +

if not isDone: print + 'Mesh Mesh_1 : computation failed'

+ +

 

+ +

# build a triangle mesh + on Face_2

+ +

Mesh_2 = smesh.Mesh(Face_2)

+ +

algo1D = Mesh_2.Segment()

+ +

algo1D.NumberOfSegments(1)

+ +

algo2D = Mesh_2.Triangle()

+ +

algo2D.MaxElementArea(240)

+ +

isDone = Mesh_2.Compute()

+ +

if not isDone: print + 'Mesh Mesh_2 : computation failed'

+ +

 

+ +

# create a pattern

+ +

pattern = smesh.smesh.GetPattern()

+ +

isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), + Face_2, 0)

+ +

if (isDone != 1): + print 'LoadFromFace :', pattern.GetErrorCode()

+ +

 

+ +

# apply the pattern to + a face of the first mesh

+ +

pattern.ApplyToMeshFaces(Mesh_1.GetMesh(), + [17], 0, 0)

+ +

isDone = pattern.MakeMesh(Mesh_1.GetMesh(), + 0, 0)

+ +

if (isDone != 1): + print 'MakeMesh :', pattern.GetErrorCode()

+ +

 

+ +

 

+ + + + diff --git a/doc/salome/gui/SMESH/quality_controls.htm b/doc/salome/gui/SMESH/quality_controls.htm index 2af942145..bc5dd720b 100755 --- a/doc/salome/gui/SMESH/quality_controls.htm +++ b/doc/salome/gui/SMESH/quality_controls.htm @@ -7,9 +7,10 @@