1 # Copyright (C) 2007-2015 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # @package HexoticPLUGINBuilder
22 # Python API for the MG-Hexa meshing plug-in module.
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
25 from salome.smesh.smeshBuilder import AssureGeomPublished
26 from salome.geom import geomBuilder
28 # import HexoticPlugin module if possible
36 #----------------------------
37 # Mesh algo type identifiers
38 #----------------------------
40 ## Algorithm type: MG-Hexa hexahedron 3D algorithm, see Hexotic_Algorithm
44 ## Direction of viscous layers for MG_Hexa algorithm
48 #----------------------------
50 #----------------------------
52 ## Defines a hexahedron 3D algorithm
54 # It is created by calling smeshBuilder.Mesh.Hexahedron( smeshBuilder.MG_Hexa, geom=0 )
55 class Hexotic_Algorithm(Mesh_Algorithm):
57 ## name of the dynamic method in smeshBuilder.Mesh class
59 meshMethod = "Hexahedron"
60 ## type of algorithm used with helper function in smeshBuilder.Mesh class
63 ## doc string of the method in smeshBuilder.Mesh class
65 docHelper = "Creates hexahedron 3D algorithm for volumes"
67 ## Private constructor.
68 # @param mesh parent mesh object algorithm is assigned to
69 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
70 # if it is @c 0 (default), the algorithm is assigned to the main shape
71 def __init__(self, mesh, geom=0):
72 Mesh_Algorithm.__init__(self)
73 if noHexoticPlugin: print "Warning: HexoticPlugin module unavailable"
74 self.Create(mesh, geom, MG_Hexa, "libHexoticEngine.so")
78 ## Defines "SetMinMaxHexes" hypothesis to give two MG-Hexa parameters
79 # @param min minimal level of recursive partitioning on the initial octree cube
80 # @param max maximal level of recursive partitioning on the initial octree cube
81 # @return hypothesis object
82 def SetMinMaxHexes(self, min=3, max=8):
83 self.Parameters().SetHexesMinLevel(min)
84 self.Parameters().SetHexesMaxLevel(max)
85 return self.Parameters()
87 ## Defines "SetMinMaxSize" hypothesis to give two MG-Hexa parameters
88 # @param min minimal element's size
89 # @param max maximal element's size
90 # @return hypothesis object
91 def SetMinMaxSize(self, min, max):
92 self.Parameters().SetMinSize(min)
93 self.Parameters().SetMaxSize(max)
94 return self.Parameters()
97 # @param theObject geometrical object to assign local size to
98 # @param theSize local size on the given object
99 # @return hypothesis object
100 def SetSizeMap(self, theObject, theSize):
101 AssureGeomPublished( self.mesh, theObject )
103 raise ValueError, "The size must be > 0"
104 self.Parameters().SetSizeMap(theObject, theSize)
105 return self.Parameters()
107 ## Unsets a size map : this is meant to be used only by the dump
108 # @param theObject geometrical object to unassign local size
109 # @return hypothesis object
110 def UnsetSizeMap(self, theObject):
111 AssureGeomPublished( self.mesh, theObject )
112 self.Parameters().UnsetSizeMap(theObject)
113 return self.Parameters()
115 ## (OBSOLETE) Defines "MinMaxQuad" hypothesis to give three MG-Hexa parameters
116 # @param min minimal level of recursive partitioning on the initial octree cube
117 # @param max maximal level of recursive partitioning on the initial octree cube
118 # @param quad not documented
119 # @return hypothesis object
120 def MinMaxQuad(self, min=3, max=8, quad=True):
121 print "WARNING: Function MinMaxQuad is deprecated, use SetMinMaxHexes instead"
122 return self.SetMinMaxHexes(min, max)
124 ## Defines "ViscousLayers" hypothesis to give MG-Hexa parameters
125 # @param numberOfLayers number of boundary layers
126 # @param firstLayerSize height of the first layer
127 # @param growth geometric progression for the boundary layer growth
128 # @param direction describes whether the layers grow inwards or outwards.
130 # \c Inward : means the layers grow inwards,
131 # \c Outward : means the layers grow outwards
132 # @param facesWithLayers list of surface references from which the boundary
133 # layers should be grown
134 # @param imprintedFaces list of surface references that can be imprinted by
136 # @return hypothesis object
137 def SetViscousLayers(self, numberOfLayers, firstLayerSize, growth,
138 direction=Inward, facesWithLayers=[], imprintedFaces=[]):
139 self.Parameters().SetNbLayers(numberOfLayers)
140 self.Parameters().SetFirstLayerSize(firstLayerSize)
141 self.Parameters().SetGrowth(growth)
142 self.Parameters().SetDirection(direction)
143 if facesWithLayers and isinstance( facesWithLayers[0], geomBuilder.GEOM._objref_GEOM_Object ):
145 facesWithLayersIDs = []
146 for f in facesWithLayers:
147 if self.mesh.geompyD.ShapeIdToType( f.GetType() ) == "GROUP":
148 facesWithLayersIDs += f.GetSubShapeIndices()
150 facesWithLayersIDs += [self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f)]
151 facesWithLayers = facesWithLayersIDs
153 if imprintedFaces and isinstance( imprintedFaces[0], geomBuilder.GEOM._objref_GEOM_Object ):
155 imprintedFacesIDs = []
156 for f in imprintedFaces:
157 if self.mesh.geompyD.ShapeIdToType( f.GetType() ) == "GROUP":
158 imprintedFacesIDs += f.GetSubShapeIndices()
160 imprintedFacesIDs += [self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f)]
161 imprintedFaces = imprintedFacesIDs
162 self.Parameters().SetFacesWithLayers(facesWithLayers)
163 self.Parameters().SetImprintedFaces(imprintedFaces)
165 return self.Parameters()
167 ## Defines hypothesis having several parameters
168 # @return hypothesis object
169 def Parameters(self):
171 self.params = self.Hypothesis("MG-Hexa Parameters", [],
172 "libHexoticEngine.so", UseExisting=0)
177 pass # end of Hexotic_Algorithm class