Defining Hypotheses and Algorithms

Defining 1D Hypotheses

1D Arithmetic

 

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 a hexahedral mesh on the box

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

algo = hexa.Segment()

 

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

algo.NumberOfSegments(4)

 

# create a quadrangle 2D algorithm for faces

hexa.Quadrangle()

 

# create a hexahedron 3D algorithm for solids

hexa.Hexahedron()

 

# create a local hypothesis

algo = hexa.Segment(EdgeX111)

 

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

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

 

Deflection 1D and Number of Segments

 

import smesh

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

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

 

# display faces

gg.createAndDisplayGO(id_face1)

gg.setDisplayMode(id_face1,1)

gg.setTransparency(id_face1,0.2)

 

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

 

# define "Deflection1D" hypothesis

algo.Deflection1D(1)

 

# compute the mesh

hexa.Compute()

 

Start and End Length

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 a hexahedral mesh on the box

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

algo = hexa.Segment()

 

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

algo.NumberOfSegments(4)

 

# create a quadrangle 2D algorithm for faces

hexa.Quadrangle()

 

# create a hexahedron 3D algorithm for solids

hexa.Hexahedron()

 

# create a local hypothesis

algo = hexa.Segment(EdgeX111)

 

# define "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length

algo.StartEndLength(1, 6)

 

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

 

Average Length

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 a hexahedral mesh on the box

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

algo = hexa.Segment()

 

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

algo.NumberOfSegments(4)

 

# create a quadrangle 2D algorithm for faces

hexa.Quadrangle()

 

# create a hexahedron 3D algorithm for solids

hexa.Hexahedron()

 

# create a local hypothesis

algo = hexa.Segment(EdgeX111)

 

# define "LocalLength" hypothesis to cut an edge in several segments with the same length

algo.LocalLength(2)

 

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

 

 

Defining 2D and 3D hypotheses

Maximum Element Area

import smesh

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

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

 

# display faces

gg.createAndDisplayGO(id_face1)

gg.setDisplayMode(id_face1,1)

gg.setTransparency(id_face1,0.2)

 

# create a hexahedral mesh

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

algo = hexa.Triangle()

 

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

algo.MaxElementArea(7)

 

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

 

# compute the mesh

hexa.Compute()

 

Maximum Element Volume

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.MakeCylinderRH(30, 50) #MakeBox(0., 0., 0., 100., 200., 300.)

 

# add the box to the study

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

 

# 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

box = geompy.MakeFace(wire, isPlanarFace)

 

# add objects in the study

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

#geompy.addToStudy(face1,"Face1")

 

# display faces

gg.createAndDisplayGO(id_face1)

gg.setDisplayMode(id_face1,1)

gg.setTransparency(id_face1,0.2)

 

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

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_900")

 

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

#print "-------------------------- Hexa_3D (Hexahedron meshing algorithm)"

hexa3D = smesh.CreateHypothesis("Hexa_3D", "libStdMeshersEngine.so")

smeshgui.SetName(salome.ObjectToID(hexa3D), "HEXA_3D")

 

# initialize a mesh with the box

mesh = smesh.CreateMesh(box)

smeshgui.SetName(salome.ObjectToID(mesh), "MeshBox")

 

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

mesh.AddHypothesis(box,hexa3D)

 

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

 

Defining Additional Hypotheses

Length from Edges

import smesh

import geompy

import salome

gg = salome.ImportComponentGUI("GEOM")

 

# create sketchers

sketcher1 = geompy.MakeSketcher("Sketcher:F 0 0:TT 70 0:TT 70 70:TT 0 70:WW")

sketcher2 = geompy.MakeSketcher("Sketcher:F 20 20:TT 50 20:TT 50 50:TT 20 50:WW")

isPlanarFace = 1

 

# create faces from two wires

face1 = geompy.MakeFaces([sketcher1, sketcher2],isPlanarFace)

 

# add objects in the study

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

 

# display faces

gg.createAndDisplayGO(id_face1)

gg.setDisplayMode(id_face1,1)

gg.setTransparency(id_face1,0.2)

 

# create a mesh

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

algo = hexa.Triangle()

 

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

algo.MaxElementArea(30)

 

# define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire

algo.LengthFromEdges()

 

# create local hypothesis

algo = hexa.Segment()

 

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

algo.NumberOfSegments(2)

 

# compute the mesh

hexa.Compute()

 

Propagation

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 a hexahedral mesh on the box

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

algo = hexa.Segment()

 

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

algo.NumberOfSegments(4)

 

# create a quadrangle 2D algorithm for faces

hexa.Quadrangle()

 

# create a hexahedron 3D algorithm for solids

hexa.Hexahedron()

 

# create a local hypothesis

algo = hexa.Segment(EdgeX111)

 

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

increasing

algo.Arithmetic1D(1, 4)

 

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

algo.Propagation()

 

# compute the mesh

hexa.Compute()

 

Defining Meshing Algorithms

import salome

import StdMeshers

import NETGENPlugin

 

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

smeshgui = salome.ImportComponentGUI("SMESH")

smeshgui.Init(salome.myStudyId);

 

# create algorithms

print "-------------------------- create Algorithms"

print "-------------------------- Regular_1D (Wire discretisation)"

regular1D = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")

smeshgui.SetName(salome.ObjectToID(regular1D), "Wire Discretisation")

 

print "-------------------------- MEFISTO_2D (Triangle meshing algorithm)"

mefisto2D = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")

smeshgui.SetName(salome.ObjectToID(mefisto2D), "MEFISTO_2D")

 

print "-------------------------- Quadrangle_2D (Quadrangle meshing algorithm)"

quad2D = smesh.CreateHypothesis( "Quadrangle_2D", "libStdMeshersEngine.so" )

smeshgui.SetName(salome.ObjectToID(quad2D), "Quadrangle_2D")

 

print "-------------------------- Hexa_3D (Hexahedron meshing algorithm)"

hexa3D = smesh.CreateHypothesis("Hexa_3D", "libStdMeshersEngine.so")

smeshgui.SetName(salome.ObjectToID(hexa3D), "HEXA_3D")

 

print "-------------------------- NETGEN_3D (Tetrahedron meshing algorithm)"

netgen3D = smesh.CreateHypothesis("NETGEN_3D", "libNETGENEngine.so")

smeshgui.SetName(salome.ObjectToID(netgen3D), "NETGEN_3D")

salome.sg.updateObjBrowser(1)