smesh/doc/salome/examples/creating_meshes_ex06.py

114 lines
3.0 KiB
Python
Raw Normal View History

2013-02-12 20:37:44 +06:00
# Creating a hexahedral mesh on a cylinder.
#
# This example uses Partition to divide the cylinder into blocks, which is
# a general approach. But for the case of cylinder there is a dedicated
# command creating a blocked cylinder: geompy.MakeDividedCylinder()
2013-02-12 20:37:44 +06:00
import salome
salome.salome_init()
import GEOM
from salome.geom import geomBuilder
2017-06-13 15:01:10 +05:00
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.smesh import smeshBuilder
2017-06-13 15:01:10 +05:00
smesh = smeshBuilder.New()
import math
2013-02-12 20:37:44 +06:00
# Parameters
# ----------
radius = 50
height = 200
# Build a cylinder
# ----------------
base = geompy.MakeVertex(0, 0, 0)
direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
2013-02-12 20:37:44 +06:00
cylinder = geompy.MakeCylinder(base, direction, radius, height)
2013-02-12 20:37:44 +06:00
geompy.addToStudy(cylinder, "cylinder")
2013-02-12 20:37:44 +06:00
# Build blocks
# ------------
size = radius/2.0
box_rot = geompy.MakeBox(-size, -size, 0, +size, +size, height)
box_axis = geompy.MakeLine(base, direction)
box = geompy.MakeRotation(box_rot, box_axis, math.pi/4)
2013-02-12 20:37:44 +06:00
hole = geompy.MakeCut(cylinder, box)
2013-02-12 20:37:44 +06:00
plane_trim = 2000
plane_a = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
plane_b = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
2013-02-12 20:37:44 +06:00
blocks_part = geompy.MakePartition([hole], [plane_a, plane_b], [], [], geompy.ShapeType["SOLID"])
blocks_list = [box] + geompy.SubShapeAll(blocks_part, geompy.ShapeType["SOLID"])
blocks_all = geompy.MakeCompound(blocks_list)
blocks = geompy.MakeGlueFaces(blocks_all, 0.0001)
2013-02-12 20:37:44 +06:00
geompy.addToStudy(blocks, "cylinder:blocks")
2013-02-12 20:37:44 +06:00
# Build geometric groups
# ----------------------
def group(name, shape, type, base=None, direction=None):
t = geompy.ShapeType[type]
g = geompy.CreateGroup(shape, t)
2013-02-12 20:37:44 +06:00
geompy.addToStudyInFather(shape, g, name)
2013-02-12 20:37:44 +06:00
if base!=None:
l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
geompy.UnionIDs(g, l)
2013-02-12 20:37:44 +06:00
return g
group_a = group("baseA", blocks, "FACE", base, direction)
base_b = geompy.MakeVertex(0, 0, height)
2013-02-12 20:37:44 +06:00
group_b = group("baseB", blocks, "FACE", base_b, direction)
group_1 = group("limit", blocks, "SOLID")
group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType["SOLID"])
geompy.UnionIDs(group_1, group_1_all)
group_1_box = geompy.GetBlockNearPoint(blocks, base)
geompy.DifferenceList(group_1, [group_1_box])
2013-02-12 20:37:44 +06:00
# Mesh the blocks with hexahedral
# -------------------------------
2017-06-13 15:01:10 +05:00
smesh.UpdateStudy()
2013-02-12 20:37:44 +06:00
def discretize(x, y, z, nbSeg, shape=blocks):
vert = geompy.MakeVertex( x, y, z )
edge = geompy.GetEdgeNearPoint( shape, vert )
algo = hexa.Segment( edge )
algo.NumberOfSegments( nbSeg )
algo.Propagation()
2013-02-12 20:37:44 +06:00
hexa = smesh.Mesh(blocks)
hexa_1d = hexa.Segment()
hexa_1d.NumberOfSegments(1)
discretize(+radius , +radius, 0, 5)
discretize(-radius , +radius, 0, 8)
discretize((radius+size)/2, 0, 0, 10)
discretize( +radius, 0, height/2, 20)
hexa.Quadrangle()
hexa.Hexahedron()
hexa.Compute()
hexa.Group(group_a)
hexa.Group(group_b)
hexa.Group(group_1)