2013-02-12 20:37:44 +06:00
|
|
|
# Creating a hexahedral mesh on a cylinder.
|
2016-03-17 17:30:10 +05:00
|
|
|
#
|
|
|
|
# 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
|
2013-04-04 13:08:19 +06:00
|
|
|
salome.salome_init()
|
|
|
|
import GEOM
|
|
|
|
from salome.geom import geomBuilder
|
2017-06-13 15:01:10 +05:00
|
|
|
geompy = geomBuilder.New()
|
2013-04-04 13:08:19 +06:00
|
|
|
|
|
|
|
import SMESH, SALOMEDS
|
|
|
|
from salome.smesh import smeshBuilder
|
2017-06-13 15:01:10 +05:00
|
|
|
smesh = smeshBuilder.New()
|
2013-04-04 13:08:19 +06:00
|
|
|
|
|
|
|
import math
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# Parameters
|
|
|
|
# ----------
|
|
|
|
|
|
|
|
radius = 50
|
|
|
|
height = 200
|
|
|
|
|
|
|
|
# Build a cylinder
|
|
|
|
# ----------------
|
|
|
|
|
2016-03-17 21:21:24 +05:00
|
|
|
base = geompy.MakeVertex(0, 0, 0)
|
2013-04-04 13:08:19 +06:00
|
|
|
direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
cylinder = geompy.MakeCylinder(base, direction, radius, height)
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
geompy.addToStudy(cylinder, "cylinder")
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# Build blocks
|
|
|
|
# ------------
|
|
|
|
|
|
|
|
size = radius/2.0
|
|
|
|
|
2016-03-17 21:21:24 +05:00
|
|
|
box_rot = geompy.MakeBox(-size, -size, 0, +size, +size, height)
|
2013-04-04 13:08:19 +06:00
|
|
|
box_axis = geompy.MakeLine(base, direction)
|
2016-03-17 21:21:24 +05:00
|
|
|
box = geompy.MakeRotation(box_rot, box_axis, math.pi/4)
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
hole = geompy.MakeCut(cylinder, box)
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
plane_trim = 2000
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
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
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
blocks_part = geompy.MakePartition([hole], [plane_a, plane_b], [], [], geompy.ShapeType["SOLID"])
|
|
|
|
blocks_list = [box] + geompy.SubShapeAll(blocks_part, geompy.ShapeType["SOLID"])
|
2016-03-17 21:21:24 +05:00
|
|
|
blocks_all = geompy.MakeCompound(blocks_list)
|
|
|
|
blocks = geompy.MakeGlueFaces(blocks_all, 0.0001)
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
geompy.addToStudy(blocks, "cylinder:blocks")
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
# Build geometric groups
|
|
|
|
# ----------------------
|
|
|
|
|
2018-10-31 16:48:24 +05:00
|
|
|
group_a = geompy.CreateGroup(blocks, geompy.ShapeType["FACE"])
|
|
|
|
geompy.addToStudyInFather(blocks, group_a, "baseA")
|
|
|
|
items = geompy.GetShapesOnPlaneWithLocationIDs(blocks, geompy.ShapeType["FACE"], direction, base, GEOM.ST_ON)
|
|
|
|
geompy.UnionIDs(group_a, items)
|
|
|
|
|
|
|
|
base_b = geompy.MakeVertex(0, 0, height)
|
|
|
|
group_b = geompy.CreateGroup(blocks, geompy.ShapeType["FACE"])
|
|
|
|
geompy.addToStudyInFather(blocks, group_b, "baseB")
|
|
|
|
items = geompy.GetShapesOnPlaneWithLocationIDs(blocks, geompy.ShapeType["FACE"], direction, base_b, GEOM.ST_ON)
|
|
|
|
geompy.UnionIDs(group_b, items)
|
|
|
|
|
|
|
|
group_1 = geompy.CreateGroup(blocks, geompy.ShapeType["SOLID"])
|
|
|
|
geompy.addToStudyInFather(blocks, group_1, "limit")
|
2013-04-04 13:08:19 +06:00
|
|
|
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
|
|
|
|
|
|
|
hexa = smesh.Mesh(blocks)
|
|
|
|
|
|
|
|
hexa_1d = hexa.Segment()
|
|
|
|
hexa_1d.NumberOfSegments(1)
|
|
|
|
|
2018-10-31 16:48:24 +05:00
|
|
|
vertex = geompy.MakeVertex(+radius, +radius, 0)
|
|
|
|
edge = geompy.GetEdgeNearPoint(blocks, vertex)
|
|
|
|
algo = hexa.Segment(edge)
|
|
|
|
algo.NumberOfSegments(5)
|
|
|
|
algo.Propagation()
|
|
|
|
|
|
|
|
vertex = geompy.MakeVertex(-radius, +radius, 0)
|
|
|
|
edge = geompy.GetEdgeNearPoint(blocks, vertex)
|
|
|
|
algo = hexa.Segment(edge)
|
|
|
|
algo.NumberOfSegments(8)
|
|
|
|
algo.Propagation()
|
|
|
|
|
|
|
|
vertex = geompy.MakeVertex((radius+size)/2, 0, 0)
|
|
|
|
edge = geompy.GetEdgeNearPoint(blocks, vertex)
|
|
|
|
algo = hexa.Segment(edge)
|
|
|
|
algo.NumberOfSegments(10)
|
|
|
|
algo.Propagation()
|
|
|
|
|
|
|
|
vertex = geompy.MakeVertex(+radius, 0, height/2)
|
|
|
|
edge = geompy.GetEdgeNearPoint(blocks, vertex)
|
|
|
|
algo = hexa.Segment(edge)
|
|
|
|
algo.NumberOfSegments(20)
|
|
|
|
algo.Propagation()
|
2013-02-12 20:37:44 +06:00
|
|
|
|
|
|
|
hexa.Quadrangle()
|
|
|
|
hexa.Hexahedron()
|
|
|
|
|
|
|
|
hexa.Compute()
|
|
|
|
|
|
|
|
hexa.Group(group_a)
|
|
|
|
hexa.Group(group_b)
|
|
|
|
hexa.Group(group_1)
|