Salome HOME
23102: [CEA 1486 ] Add the parameters for defining the boundary layers
[plugins/hexoticplugin.git] / src / HexoticPlugin / HexoticPLUGINBuilder.py
1 # Copyright (C) 2007-2015  CEA/DEN, EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 ##
21 # @package HexoticPLUGINBuilder
22 # Python API for the MG-Hexa meshing plug-in module.
23
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
25 from salome.smesh.smeshBuilder import AssureGeomPublished
26 from salome.geom import geomBuilder
27
28 # import HexoticPlugin module if possible
29 noHexoticPlugin = 0
30 try:
31     import HexoticPlugin
32 except ImportError:
33     noHexoticPlugin = 1
34     pass
35
36 #----------------------------
37 # Mesh algo type identifiers
38 #----------------------------
39
40 ## Algorithm type: MG-Hexa hexahedron 3D algorithm, see Hexotic_Algorithm
41 MG_Hexa = "MG-Hexa"
42 Hexotic = MG_Hexa
43
44 ## Direction of viscous layers for MG_Hexa algorithm
45 Inward = True
46 Outward = False
47
48 #----------------------------
49 # Algorithms
50 #----------------------------
51
52 ## Defines a hexahedron 3D algorithm
53 #
54 #  It is created by calling smeshBuilder.Mesh.Hexahedron( smeshBuilder.MG_Hexa, geom=0 )
55 class Hexotic_Algorithm(Mesh_Algorithm):
56
57     ## name of the dynamic method in smeshBuilder.Mesh class
58     #  @internal
59     meshMethod = "Hexahedron"
60     ## type of algorithm used with helper function in smeshBuilder.Mesh class
61     #  @internal
62     algoType   = MG_Hexa
63     ## doc string of the method in smeshBuilder.Mesh class
64     #  @internal
65     docHelper  = "Creates hexahedron 3D algorithm for volumes"
66
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")
75         self.params = None
76         pass
77
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()
86
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()
95          
96     ## Sets a size map
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 )
102         if theSize <= 0:
103           raise ValueError, "The size must be > 0"
104         self.Parameters().SetSizeMap(theObject, theSize)
105         return self.Parameters()
106       
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()
114
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)
123       
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. 
129     #         Possible values are:
130     #         - \c smeshBuilder.Inward : means the layers grow inwards,
131     #         - \c smeshBuilder.Outward : means the layers grow outwards
132     #  @param facesWithLayers list of surfaces from which the boundary
133     #         layers should be grown
134     #  @param imprintedFaces list of surfaces that can be imprinted by
135     #         boundary layers
136     #  @return hypothesis object
137     def SetViscousLayers(self, numberOfLayers, firstLayerSize, growth, 
138                           facesWithLayers, imprintedFaces=[], direction=Inward): 
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 ):
144           import GEOM
145           facesWithLayersIDs = []
146           for f in facesWithLayers:
147             if self.mesh.geompyD.ShapeIdToType( f.GetType() ) == "GROUP":
148               facesWithLayersIDs += f.GetSubShapeIndices()
149             else:
150               facesWithLayersIDs += [self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f)]
151           facesWithLayers = facesWithLayersIDs
152           
153         if imprintedFaces and isinstance( imprintedFaces[0], geomBuilder.GEOM._objref_GEOM_Object ):
154           import GEOM
155           imprintedFacesIDs = []
156           for f in imprintedFaces:
157             if self.mesh.geompyD.ShapeIdToType( f.GetType() ) == "GROUP":
158               imprintedFacesIDs += f.GetSubShapeIndices()
159             else:
160               imprintedFacesIDs += [self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f)]
161           imprintedFaces = imprintedFacesIDs
162         self.Parameters().SetFacesWithLayers(facesWithLayers)
163         self.Parameters().SetImprintedFaces(imprintedFaces)
164         
165         return self.Parameters()
166
167     ## Defines hypothesis having several parameters
168     #  @return hypothesis object
169     def Parameters(self):
170         if not self.params:
171             self.params = self.Hypothesis("MG-Hexa Parameters", [],
172                                           "libHexoticEngine.so", UseExisting=0)
173             pass
174         return self.params
175
176
177     pass # end of Hexotic_Algorithm class