Creating Meshes

Construction of a Mesh

import salome

import geompy

import StdMeshers

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

smeshgui = salome.ImportComponentGUI("SMESH")

smeshgui.Init(salome.myStudyId);

 

# create a box

box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)

 

# add box to the study

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

 

# create a hypothesis

print "-------------------------- create Hypothesis"

print "-------------------------- NumberOfSegments"

numberOfSegments = 7

hypNbSeg = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")

hypNbSeg.SetNumberOfSegments(numberOfSegments)

print hypNbSeg.GetName()

print hypNbSeg.GetId()

print hypNbSeg.GetNumberOfSegments()

smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")

print "-------------------------- MaxElementArea"

maxElementArea = 800

hypArea = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")

hypArea.SetMaxElementArea(maxElementArea)

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), "MeshBox")

 

# add the hypothesis to the box

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)

 

# 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)

 

Construction of a Submesh

 

from geompy import *

import smesh

 

# create vertices

Point111 = MakeVertex( 0,  0,  0)

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)

 

# create edges

EdgeX111 = MakeEdge(Point111, Point211)

EdgeX121 = MakeEdge(Point121, Point221)

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)

 

# create faces

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)

 

# create a solid

Block = MakeHexa(FaceX11, FaceX21, FaceY111, FaceY121, FaceZ11, FaceZ12)

 

# create a compound

box = MakeCompound([Block])

 

# 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 2D algorithm for the faces

hexa.Quadrangle()

 

# construct a submesh with a local hypothesis

algo = hexa.Segment(EdgeX111)

 

# 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()

 

# compute the mesh

hexa.Compute() )

 

Editing of a mesh

 

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)

 

Export of a Mesh

 

import salome

import geompy

import StdMeshers

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

smeshgui = salome.ImportComponentGUI("SMESH")

smeshgui.Init(salome.myStudyId);

 

# create a box

box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)

 

# add the box to the study

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

 

# create a hypothesis

print "-------------------------- create Hypothesis"

print "-------------------------- NumberOfSegments"

numberOfSegments = 7

hypNbSeg = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")

hypNbSeg.SetNumberOfSegments(numberOfSegments)

print hypNbSeg.GetName()

print hypNbSeg.GetId()

print hypNbSeg.GetNumberOfSegments()

smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")

print "-------------------------- MaxElementArea"

maxElementArea = 800

hypArea = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")

hypArea.SetMaxElementArea(maxElementArea)

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), "MeshBox")

 

# add the hypothesis to the box

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)

 

# 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)

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