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)

 

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)

 

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 geompy

import smesh

import salome

import SMESH

 

# create a 2D mesh on a face

# create vertices

px   = geompy.MakeVertex(100., 0.  , 0.  )

py   = geompy.MakeVertex(0.  , 100., 0.  )

pz   = geompy.MakeVertex(0.  , 0.  , 100.)

 

# create a vector from two points

vxy = geompy.MakeVector(px, py)

 

# create an arc from three points

arc = geompy.MakeArc(py, pz, px)

 

# create a wire

wire = geompy.MakeWire([vxy, arc])

isPlanarFace = 1

 

# create a face from the wire

face1 = geompy.MakeFace(wire, isPlanarFace)

 

# add objects in the study

id_face1 = geompy.addToStudy(face1,"Face1")

 

# create hexahedrical mesh

hexa = smesh.Mesh(face1, "Face compound : hexahedrical mesh")

algo = hexa.Triangle()

 

# define "MaxElementArea" hypothesis to be applied to each triangle

algo.MaxElementArea(30)

 

# create a quadrangle 2D algorithm for faces

hexa.Quadrangle()

 

# create a local hypothesis

algo = hexa.Segment(wire)

 

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

algo.NumberOfSegments(6)

 

# compute the mesh

hexa.Compute()

 

# create path mesh and path shape

# create a circle from three points

px1   = geompy.MakeVertex(100., 100.  , 0.  )

py1   = geompy.MakeVertex(-100.  , -100., 0.  )

pz1   = geompy.MakeVertex(0.  , 0.  , 50.)

circle = geompy.MakeCircleThreePnt(py1, pz1, px1)

 

# add objects in the study

id_circle = geompy.addToStudy(circle,"Path")

circlemesh = smesh.Mesh(circle, "Path mesh")

 

# create a local hypothesis

algo = circlemesh.Segment()

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

algo.NumberOfSegments(10)

 

# compute the mesh

circlemesh.Compute()

 

# extrusion of the mesh

aMeshEditor = hexa.GetMesh().GetMeshEditor()

aMeshEditor.ExtrusionAlongPathObject(hexa.GetMesh(), circlemesh.GetMesh(), circle, 1, 0, [], 0, SMESH.PointStruct(0, 0, 0))

 

salome.sg.updateObjBrowser(1)

 

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)