1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # ==================================
28 from salome.geom import geomBuilder
29 geompy = geomBuilder.New()
31 import SMESH, SALOMEDS
32 from salome.smesh import smeshBuilder
33 smesh = smeshBuilder.New()
46 base = geompy.MakeVertex(0, 0, 0)
47 direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
49 cylinder = geompy.MakeCylinder(base, direction, radius, height)
51 geompy.addToStudy(cylinder, "cylinder")
58 box_rot = geompy.MakeBox(-size, -size, 0, +size, +size, height)
59 box_axis = geompy.MakeLine(base, direction)
60 box = geompy.MakeRotation(box_rot, box_axis, math.pi/4)
62 hole = geompy.MakeCut(cylinder, box)
66 plane_a = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
67 plane_b = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
69 blocks_part = geompy.MakePartition([hole], [plane_a, plane_b], [], [], geompy.ShapeType["SOLID"])
70 blocks_list = [box] + geompy.SubShapeAll(blocks_part, geompy.ShapeType["SOLID"])
71 blocks_all = geompy.MakeCompound(blocks_list)
72 blocks = geompy.MakeGlueFaces(blocks_all, 0.0001)
74 geompy.addToStudy(blocks, "cylinder:blocks")
76 # Build geometric groups
77 # ----------------------
79 def group(name, shape, type, base=None, direction=None):
80 t = geompy.ShapeType[type]
81 g = geompy.CreateGroup(shape, t)
83 geompy.addToStudy(g, name)
87 l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
92 group_a = group("baseA", blocks, "FACE", base, direction)
94 base_b = geompy.MakeVertex(0, 0, height)
95 group_b = group("baseB", blocks, "FACE", base_b, direction)
97 group_1 = group("limit", blocks, "SOLID")
98 group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType["SOLID"])
99 geompy.UnionIDs(group_1, group_1_all)
100 group_1_box = geompy.GetBlockNearPoint(blocks, base)
101 geompy.DifferenceList(group_1, [group_1_box])
103 # Mesh the blocks with hexahedral
104 # -------------------------------
108 def discretize(x, y, z, n, s=blocks):
109 p = geompy.MakeVertex(x, y, z)
110 e = geompy.GetEdgeNearPoint(s, p)
112 a.NumberOfSegments(n)
115 hexa = smesh.Mesh(blocks)
117 hexa_1d = hexa.Segment()
118 hexa_1d.NumberOfSegments(1)
120 discretize(+radius , +radius, 0, 5)
121 discretize(-radius , +radius, 0, 8)
122 discretize((radius+size)/2, 0, 0, 10)
123 discretize( +radius, 0, height/2, 20)
128 isDone = hexa.Compute()
130 raise Exception("Error when computing Mesh")
136 # Update object browser
137 # ---------------------
139 salome.sg.updateObjBrowser()