# Transforming Meshes

####

#### Translation

import SMESH

import SMESH_mechanic

mesh = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

# translate a mesh

anEditor = mesh.GetMeshEditor()

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

vector = SMESH.DirStruct(point)

anEditor.TranslateObject(mesh, vector, 1)

salome.sg.updateObjBrowser(1)

#### Rotation

import SMESH

import SMESH_mechanic

import math

mesh = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

# rotate a mesh

anEditor = mesh.GetMeshEditor()

axisXYZ = SMESH.AxisStruct(0, 0, 0, 5, 5, 20)

angle180 = 1.5*math.pi

anEditor.RotateObject(mesh, axisXYZ, angle180, 1)

salome.sg.updateObjBrowser(1)

#### Symmetry

import SMESH

import SMESH_mechanic

import math

mesh = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

# create a symmetrical copy of the mesh mirrored through a point

anEditor = mesh.GetMeshEditor()

anEditor.MirrorObject(mesh, SMESH.AxisStruct(0, 0, 0, 0, 0, 0), SMESH.SMESH_MeshEditor.POINT, 1)

salome.sg.updateObjBrowser(1)

#### Merging Nodes

import SMESH

import SMESH_mechanic

smesh = SMESH_mechanic.smesh

mesh = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

# merge nodes

aMeshEditor = mesh.GetMeshEditor()

Tolerance = 25.0

GroupsOfNodes = aMeshEditor.FindCoincidentNodes(Tolerance)

aMeshEditor.MergeNodes(GroupsOfNodes)

salome.sg.updateObjBrowser(1)

#### Merging Elements

import geompy

import smesh

import salome

import SMESH

# create a face to be meshed

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

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

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

vxy = geompy.MakeVector(px, py)

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

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

isPlanarFace = 1

face1 = geompy.MakeFace(wire, isPlanarFace)

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

# create a 2D mesh on the face

trias = smesh.Mesh(face1, "Face : 2D mesh")

algo = trias.Segment()

algo.NumberOfSegments(6)

algo = trias.Triangle()

algo.LengthFromEdges()

trias.Compute()

tri_mesh = trias.GetMesh()

# create a path mesh

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

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

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

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

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

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

algo = circlemesh.Segment()

algo.NumberOfSegments(10)

circlemesh.Compute()

# extrusion of the mesh

aMeshEditor = tri_mesh.GetMeshEditor()

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

# merge nodes

print "Number of nodes before MergeNodes:", tri_mesh.NbNodes()

tolerance = 0.001

array_of_nodes_groups = aMeshEditor.FindCoincidentNodes(tolerance)

aMeshEditor.MergeNodes(array_of_nodes_groups)

print "Number of nodes after MergeNodes:", tri_mesh.NbNodes()

print ""

print "Number of elements before MergeEqualElements:"

print "Edges : ", tri_mesh.NbEdges()

print "Triangles : ", tri_mesh.NbTriangles()

print "Quadrangles: ", tri_mesh.NbQuadrangles()

print "Volumes : ", tri_mesh.NbVolumes()

# merge elements

aMeshEditor.MergeEqualElements()

print "Number of elements after MergeEqualElements:"

print "Edges : ", tri_mesh.NbEdges()

print "Triangles : ", tri_mesh.NbTriangles()

print "Quadrangles: ", tri_mesh.NbQuadrangles()

print "Volumes : ", tri_mesh.NbVolumes()

salome.sg.updateObjBrowser(1)

### Sewing Meshes

#### Sew Meshes Border to Border

import salome

import geompy

import smesh

# create two faces of a box

box1 = geompy.MakeBox(0., 0., -10., 30., 20., 25.)

subShapeList1 = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])

box2 = geompy.MakeBox(0., 5., 0., 20., 20., 15.)

subShapeList2 = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])

EdgesList = geompy.SubShapeAll(subShapeList2[ 1 ], geompy.ShapeType["EDGE"])

aComp = geompy.MakeCompound( [subShapeList1[ 2 ], subShapeList2[ 1 ]] )

idComp = geompy.addToStudy( aComp, "Two faces" )

aCompobj = salome.IDToObject( idComp )

# create a mesh on two faces

mesh = smesh.Mesh(aCompobj, "Two faces : quadrangle mesh")

algo = mesh.Segment()

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

algo.NumberOfSegments(9)

# create a quadrangle 2D algorithm for faces

mesh.Quadrangle()

# create a local hypothesis

algo = mesh.Segment(EdgesList[2])

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

algo.Arithmetic1D(1, 4)

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

algo.Propagation()

mesh.Compute()

# sew free borders

anEditor = mesh.GetMesh().GetMeshEditor()

anEditor.SewBorderToSide(5, 45, 6, 113, 109, 0, 0)

salome.sg.updateObjBrowser(1)

#### Sew Conform Free Borders

import salome

import geompy

import smesh

# create two faces of the box

box1 = geompy.MakeBox(0., 0., -10., 20., 20., 15.)

subShapeList1 = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])

box2 = geompy.MakeBox(0., 5., 0., 20., 20., 15.)

subShapeList2 = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])

EdgesList = geompy.SubShapeAll(subShapeList2[ 1 ], geompy.ShapeType["EDGE"])

aComp = geompy.MakeCompound( [subShapeList1[ 2 ], subShapeList2[ 1 ]] )

idComp = geompy.addToStudy( aComp, "Two faces" )

aCompobj = salome.IDToObject( idComp )

# create a mesh on two faces

mesh = smesh.Mesh(aCompobj, "Two faces : quadrangle mesh")

algo = mesh.Segment()

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

algo.NumberOfSegments(9)

# create a quadrangle 2D algorithm for faces

mesh.Quadrangle()

# create a local hypothesis

algo = mesh.Segment(EdgesList[2])

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

algo.Arithmetic1D(1, 4)

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

algo.Propagation()

mesh.Compute()

# sew free borders

anEditor = mesh.GetMesh().GetMeshEditor()

anEditor.SewConformFreeBorders(5, 45, 6, 3, 24)

salome.sg.updateObjBrowser(1)

#### Sew Free Borders

import salome

import geompy

import smesh

# create two faces of the box

box1 = geompy.MakeBox(0., 0., 0., 20., 20., 15.)

subShapeList1 = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])

box2 = geompy.MakeBox(0., 5., 0., 20., 20., 15.)

subShapeList2 = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])

EdgesList = geompy.SubShapeAll(subShapeList2[ 1 ], geompy.ShapeType["EDGE"])

aComp = geompy.MakeCompound( [subShapeList1[ 2 ], subShapeList2[ 1 ]] )

idComp = geompy.addToStudy( aComp, "Two faces" )

aCompobj = salome.IDToObject( idComp )

# create a mesh on two faces

mesh = smesh.Mesh(aCompobj, "Two faces : quadrangle mesh")

algo = mesh.Segment()

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

algo.NumberOfSegments(4)

# creates a quadrangle 2D algorithm for faces

mesh.Quadrangle()

# create a local hypothesis

algo = mesh.Segment(EdgesList[2])

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

algo.Arithmetic1D(1, 4)

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

algo.Propagation()

mesh.Compute()

# sew free borders

anEditor = mesh.GetMesh().GetMeshEditor()

anEditor.SewFreeBorders(6, 21, 5, 1, 12, 3, 0, 0)

salome.sg.updateObjBrowser(1)

#### Sew Side Elements

import salome

import geompy

import smesh

# create two faces of the box

box1 = geompy.MakeBox(0., 0., 0., 10., 10., 10.)

box2 = geompy.MakeBox(0., 15., 0., 20., 25., 10.)

EdgesList = geompy.SubShapeAll(box2, geompy.ShapeType["EDGE"])

aComp = geompy.MakeCompound( [box1, box2] )

idComp = geompy.addToStudy( aComp, "Two faces" )

aCompobj = salome.IDToObject( idComp )

# create a mesh on two faces

mesh = smesh.Mesh(aCompobj, "Two faces : quadrangle mesh")

algo = mesh.Segment()

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

algo.NumberOfSegments(2)

# create a quadrangle 2D algorithm for faces

mesh.Quadrangle()

# create a local hypothesis

algo = mesh.Segment(EdgesList[8])

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

algo.NumberOfSegments(4)

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

algo.Propagation()

mesh.Compute()

# sew free borders

anEditor = mesh.GetMesh().GetMeshEditor()

anEditor.SewSideElements([69, 70, 71, 72], [91, 92, 89, 90], 8, 38, 23, 58)

salome.sg.updateObjBrowser(1)