Back to index

salome-smesh  6.5.0
ex12_grid17partition.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 # grid compound of 17 x 17 elements
00034 # an element is compound of 3 concentric cylinders
00035 # an element is centered in a square of the grid
00036 
00037 # prism the grid, and mesh it in hexahedral way
00038 
00039 # Values
00040 # ------
00041 
00042 g_x = 0
00043 g_y = 0
00044 g_z = 0
00045 
00046 g_arete   = 50
00047 g_hauteur = 30
00048 
00049 g_rayon1 = 20
00050 g_rayon2 = 30
00051 g_rayon3 = 40
00052 
00053 g_grid = 17
00054 
00055 g_trim = 1000
00056 
00057 # Solids and rotation to prevent repair
00058 # -------------------------------------
00059 
00060 s_boite = MakeBox(g_x-g_arete, g_y-g_hauteur, g_z-g_arete,  g_x+g_arete, g_y+g_hauteur, g_z+g_arete)
00061 
00062 s_pi4     = 3.141592653/4
00063 s_hauteur = 2*g_hauteur
00064 s_centre  = MakeVertex(g_x, g_y-g_hauteur, g_z)
00065 s_dir     = MakeVectorDXDYDZ(0, 1, 0)
00066 
00067 s_cyl0 = MakeCylinder(s_centre, s_dir, g_rayon3, s_hauteur)
00068 s_cyl1 = MakeRotation(s_cyl0, s_dir, s_pi4)
00069 
00070 s_blo1 = MakeCut(s_boite, s_cyl1)
00071 
00072 s_cyl0 = MakeCylinder(s_centre, s_dir, g_rayon2, s_hauteur)
00073 s_cyl2 = MakeRotation(s_cyl0, s_dir, s_pi4)
00074 
00075 s_blo2 = MakeCut(s_cyl1, s_cyl2)
00076 
00077 s_cyl0 = MakeCylinder(s_centre, s_dir, g_rayon1, s_hauteur)
00078 s_cyl3 = MakeRotation(s_cyl0, s_dir, s_pi4)
00079 
00080 s_blo3 = MakeCut(s_cyl2, s_cyl3)
00081 
00082 s_arete = g_rayon1/2
00083 
00084 s_blo4 = MakeBox(g_x-s_arete, g_y-g_hauteur, g_z-s_arete,  g_x+s_arete, g_y+g_hauteur, g_z+s_arete)
00085 
00086 s_blo5 = MakeCut(s_cyl3, s_blo4)
00087 
00088 # Partition
00089 # ---------
00090 
00091 p_tools = []
00092 p_tools.append(MakePlane(s_centre, MakeVectorDXDYDZ( 1, 0, 1), g_trim))
00093 p_tools.append(MakePlane(s_centre, MakeVectorDXDYDZ(-1, 0, 1), g_trim))
00094 
00095 p_partie = MakePartition([s_blo1, s_blo2, s_blo3, s_blo5], p_tools, [], [], ShapeType["SOLID"])
00096 
00097 # Compound and glue
00098 # -----------------
00099 
00100 c_blocs = SubShapeAll(p_partie, ShapeType["SOLID"])
00101 c_blocs.append(s_blo4)
00102 
00103 c_cpd = MakeCompound(c_blocs)
00104 
00105 c_element = MakeGlueFaces(c_cpd, 1e-4)
00106 
00107 # Grid
00108 # ----
00109 
00110 piece = MakeMultiTranslation2D(c_element, MakeVectorDXDYDZ(1, 0, 0), 2*g_arete, g_grid, MakeVectorDXDYDZ(0, 0, 1), 2*g_arete, g_grid)
00111 
00112 # Add in study
00113 # ------------
00114 
00115 piece_id = addToStudy(piece, "ex12_grid17partition")
00116 
00117 # Meshing
00118 # =======
00119 
00120 smesh.SetCurrentStudy(salome.myStudy)
00121 
00122 # Create a hexahedral mesh
00123 # ------------------------
00124 
00125 hexa = smesh.Mesh(piece, "ex12_grid17partition:hexa")
00126 
00127 algo = hexa.Segment()
00128 algo.NumberOfSegments(2)
00129 
00130 hexa.Quadrangle()
00131 
00132 hexa.Hexahedron()
00133 
00134 # Mesh calculus
00135 # -------------
00136 
00137 hexa.Compute()