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

# get edges from the face

vxy,arc = geompy.SubShapeAll(face1,geompy.ShapeType["EDGE"])

# add objects in the study

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

id_arc = geompy.addToStudyInFather(face1,arc,"Arc Edge")

# 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

algo.MaxElementArea(30)

# create a local hypothesis on the wire

algo = hexa.Segment(wire)

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

algo.NumberOfSegments(6)

# define a local "Deflection1D" hypothesis on the arc

algo = hexa.Segment(arc)

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

# create a face

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

face = geompy.MakeFace(wire, isPlanarFace)

# add the face in the study

id_face = geompy.addToStudy(face, "Face to be meshed")

# create a mesh

tria_mesh = smesh.Mesh(face, "Face : triangulation")

# define 1D meshing:

algo = tria_mesh.Segment()

algo.NumberOfSegments(20)

# define 2D meshing:

# assign triangulation algorithm

algo = tria_mesh.Triangle()

# apply "Max Element Area" hypothesis to each triangle

algo.MaxElementArea(100)

# compute the mesh

tria_mesh.Compute()

#### Maximum Element Volume

import salome

import geompy

import StdMeshers

import NETGENPlugin

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 in the study

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

# create a set of hypotheses

# Number of Segments

numberOfSegments = 7

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

hypNbSeg.SetNumberOfSegments(numberOfSegments)

print hypNbSeg.GetName()

print hypNbSeg.GetNumberOfSegments()

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

# Max Element Area

maxElementArea = 800

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

hypArea.SetMaxElementArea(maxElementArea)

print hypArea.GetName()

print hypArea.GetMaxElementArea()

smeshgui.SetName(salome.ObjectToID(hypArea), "MaxElementArea_800")

# Max Element Volume

maxElementVolume = 900

hypVolume = smesh.CreateHypothesis("MaxElementVolume", "libStdMeshersEngine.so")

hypVolume.SetMaxElementVolume(maxElementVolume)

print hypVolume.GetName()

print hypVolume.GetMaxElementVolume()

smeshgui.SetName(salome.ObjectToID(hypVolume), "MaxElementVolume_900")

# create a set of algorithms

# Regular_1D

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

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

# MEFISTO_2D

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

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

# NETGEN_3D (Tetrahedron meshing algorithm)

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

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

# initialize a mesh with the box

mesh = smesh.CreateMesh(box)

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

# add hypotheses and algorithms 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,tetra3D)

# compute the mesh

ret = smesh.Compute(mesh,box)

if ret == 0:

print "probleme when computing the mesh"

else:

print "Computation succeded"

salome.sg.updateObjBrowser(1)

#### Length from Edges

import salome

import geompy

import smesh

# 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 a face from two wires

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

# add object in the study

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

# create a mesh

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

# Define 1D meshing

algo = tria.Segment()

algo.NumberOfSegments(2)

# create and assign the algorithm for 2D meshing with triangles

algo = tria.Triangle()

# create and assign "LengthFromEdges" hypothesis to build triangles

# based on the length of the edges taken from the wire

algo.LengthFromEdges()

# compute the mesh

tria.Compute()

### Defining Additional Hypotheses

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

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

# add in the study

box_id = addToStudy(box, "Box")

# create a hexahedral mesh on the box

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

# create an 1D algorithm for edges

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 increasing length

algo.Arithmetic1D(1, 4)

# define "Propagation" hypothesis that propagates all other 1D hypotheses

# from all edges on the opposite side of a face 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)