Back to index

salome-smesh  6.5.0
ex13_hole1partial.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 # ==================================
00025 #
00026 from geompy import *
00027 
00028 import smesh
00029 
00030 # Geometry
00031 # ========
00032 
00033 # With hexahedral, build a box partially holed by a not centered cylinder with a thickness
00034 
00035 # Values
00036 # ------
00037 
00038 box_dx = 1000
00039 box_dy =  900
00040 box_dz =  800
00041 
00042 cyl_x      = 500
00043 cyl_y      = 300
00044 cyl_dz     = 600
00045 cyl_radius = 150
00046 cyl_thick  =  30
00047 
00048 # Triangular face
00049 # ---------------
00050 
00051 def triangle(p1, p2, p3):
00052     l = []
00053     l.append(MakeEdge(p1, p2))
00054     l.append(MakeEdge(p2, p3))
00055     l.append(MakeEdge(p3, p1))
00056     w = MakeWire(l)
00057     return MakeFace(w, 1)
00058 
00059 # The holed part
00060 # ==============
00061 
00062 # Vertex of the holed part
00063 # ------------------------
00064 
00065 hole_point_11 = MakeVertex(0     , 0     , 0)
00066 hole_point_21 = MakeVertex(box_dx, 0     , 0)
00067 hole_point_12 = MakeVertex(0     , box_dy, 0)
00068 hole_point_22 = MakeVertex(box_dx, box_dy, 0)
00069 
00070 hole_center   = MakeVertex(cyl_x, cyl_y, 0)
00071 
00072 # Faces of the holed part
00073 # -----------------------
00074 
00075 hole_face_1 = triangle(hole_point_11, hole_point_21, hole_center)
00076 hole_face_2 = triangle(hole_point_21, hole_point_22, hole_center)
00077 hole_face_3 = triangle(hole_point_12, hole_point_22, hole_center)
00078 hole_face_4 = triangle(hole_point_11, hole_point_12, hole_center)
00079 
00080 # Solids of the holed part
00081 # ------------------------
00082 
00083 cyl_dir = MakeVectorDXDYDZ(0, 0, 1)
00084 
00085 hole_solid_1 = MakePrismVecH(hole_face_1, cyl_dir, cyl_dz)
00086 hole_solid_2 = MakePrismVecH(hole_face_2, cyl_dir, cyl_dz)
00087 hole_solid_3 = MakePrismVecH(hole_face_3, cyl_dir, cyl_dz)
00088 hole_solid_4 = MakePrismVecH(hole_face_4, cyl_dir, cyl_dz)
00089 
00090 hole_internal = MakeCylinder(hole_center, cyl_dir, cyl_radius          , cyl_dz)
00091 hole_external = MakeCylinder(hole_center, cyl_dir, cyl_radius+cyl_thick, cyl_dz)
00092 hole_median   = MakeCut(hole_external, hole_internal)
00093 
00094 # Boolean operations
00095 # ------------------
00096 
00097 blocks = []
00098 
00099 blocks.append(   MakeCut(hole_solid_1, hole_external))
00100 blocks.append(MakeCommon(hole_solid_1, hole_median  ))
00101 
00102 blocks.append(   MakeCut(hole_solid_2, hole_external))
00103 blocks.append(MakeCommon(hole_solid_2, hole_median  ))
00104 
00105 blocks.append(   MakeCut(hole_solid_3, hole_external))
00106 blocks.append(MakeCommon(hole_solid_3, hole_median  ))
00107 
00108 blocks.append(   MakeCut(hole_solid_4, hole_external))
00109 blocks.append(MakeCommon(hole_solid_4, hole_median  ))
00110 
00111 # The full part
00112 # =============
00113 
00114 # Vertex of the full part
00115 # -----------------------
00116 
00117 full_point_11 = MakeVertex(0     , 0     , cyl_dz)
00118 full_point_21 = MakeVertex(box_dx, 0     , cyl_dz)
00119 full_point_12 = MakeVertex(0     , box_dy, cyl_dz)
00120 full_point_22 = MakeVertex(box_dx, box_dy, cyl_dz)
00121 
00122 full_center = MakeVertex(cyl_x, cyl_y, cyl_dz)
00123 
00124 # Faces of the full part
00125 # ----------------------
00126 
00127 full_face_1 = triangle(full_point_11, full_point_21, full_center)
00128 full_face_2 = triangle(full_point_21, full_point_22, full_center)
00129 full_face_3 = triangle(full_point_12, full_point_22, full_center)
00130 full_face_4 = triangle(full_point_11, full_point_12, full_center)
00131 
00132 # Solids of the full part
00133 # ------------------------
00134 
00135 full_dz = box_dz - cyl_dz
00136 
00137 full_solid_1 = MakePrismVecH(full_face_1, cyl_dir, full_dz)
00138 full_solid_2 = MakePrismVecH(full_face_2, cyl_dir, full_dz)
00139 full_solid_3 = MakePrismVecH(full_face_3, cyl_dir, full_dz)
00140 full_solid_4 = MakePrismVecH(full_face_4, cyl_dir, full_dz)
00141 
00142 full_internal = MakeCylinder(full_center, cyl_dir, cyl_radius          , full_dz)
00143 full_external = MakeCylinder(full_center, cyl_dir, cyl_radius+cyl_thick, full_dz)
00144 full_median   = MakeCut(full_external, full_internal)
00145 
00146 # Boolean operations
00147 # ------------------
00148 
00149 full = []
00150 
00151 full.append(   MakeCut(full_solid_1, full_external))
00152 full.append(MakeCommon(full_solid_1, full_median))
00153 
00154 full.append(   MakeCut(full_solid_2, full_external))
00155 full.append(MakeCommon(full_solid_2, full_median ))
00156 
00157 full.append(   MakeCut(full_solid_3, full_external))
00158 full.append(MakeCommon(full_solid_3, full_median))
00159 
00160 full.append(   MakeCut(full_solid_4, full_external))
00161 full.append(MakeCommon(full_solid_4, full_median))
00162 
00163 # Filling the hole
00164 # ----------------
00165 
00166 box_d = cyl_radius/3
00167 
00168 x = cyl_x-box_d
00169 y = x * cyl_y / cyl_x
00170 box_point_11 = MakeVertex(x, y, cyl_dz)
00171 
00172 x = cyl_x+box_d
00173 y = (box_dx - x) * cyl_y / (box_dx - cyl_x)
00174 box_point_12 = MakeVertex(x, y, cyl_dz)
00175 
00176 x = cyl_x-box_d
00177 y = box_dy - x * (box_dy - cyl_y) / cyl_x
00178 box_point_21 = MakeVertex(x, y, cyl_dz)
00179 
00180 x = cyl_x+box_d
00181 y = box_dy - (box_dx - x) * (box_dy - cyl_y) / (box_dx - cyl_x)
00182 box_point_22 = MakeVertex(x, y, cyl_dz)
00183 
00184 box_face = MakeQuad4Vertices(box_point_11, box_point_12, box_point_21, box_point_22)
00185 
00186 box = MakePrismVecH(box_face, cyl_dir, full_dz)
00187 
00188 full.append(box)
00189 
00190 full.append(MakeCut(MakeCommon(full_solid_1, full_internal), box))
00191 full.append(MakeCut(MakeCommon(full_solid_2, full_internal), box))
00192 full.append(MakeCut(MakeCommon(full_solid_3, full_internal), box))
00193 full.append(MakeCut(MakeCommon(full_solid_4, full_internal), box))
00194 
00195 # Cut the cylinder thikness
00196 # -------------------------
00197 
00198 full_plan = MakePlane(MakeVertex(0, 0, cyl_dz+cyl_thick), cyl_dir, 5000)
00199 
00200 full_parts = MakePartition(full, [full_plan], [], [], ShapeType["SOLID"])
00201 
00202 # Geometry result
00203 # ---------------
00204 
00205 blocks.append(full_parts)
00206 
00207 piece_cpd = MakeCompound(blocks)
00208 
00209 piece_ok = RemoveExtraEdges(piece_cpd, doUnionFaces=True)
00210 
00211 piece = MakeGlueFaces(piece_ok, 1.e-3)
00212 
00213 piece_id = addToStudy(piece, "ex13_hole1partial")
00214 
00215 # Meshing
00216 # =======
00217 
00218 smesh.SetCurrentStudy(salome.myStudy)
00219 
00220 # Create a mesh
00221 # -------------
00222 
00223 hexa = smesh.Mesh(piece, "ex13_hole1partial:hexa")
00224 
00225 algo = hexa.Segment()
00226 algo.NumberOfSegments(2)
00227 
00228 hexa.Quadrangle()
00229 
00230 hexa.Hexahedron()
00231 
00232 # Local hypothesis
00233 # ----------------
00234 
00235 def local(x, y, z, d):
00236     edge = GetEdgeNearPoint(piece, MakeVertex(x, y, z))
00237     algo = hexa.Segment(edge)
00238     algo.NumberOfSegments(d)
00239     algo.Propagation()
00240 
00241 local(0, 0, 100, 40)
00242 local(0, 0, 700, 15)
00243 
00244 local(100, 0, 0, 20)
00245 local(0, 100, 0, 20)
00246 
00247 local(100, 100, 0, 25)
00248 
00249 d = cyl_radius-3*cyl_thick
00250 local(cyl_x+d, cyl_y+d, box_dz, 10)
00251 
00252 # Compute the mesh
00253 # ----------------
00254 
00255 hexa.Compute()