Salome HOME
0023102: [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
27 # import HexoticPlugin module if possible
28 noHexoticPlugin = 0
29 try:
30     import HexoticPlugin
31 except ImportError:
32     noHexoticPlugin = 1
33     pass
34
35 #----------------------------
36 # Mesh algo type identifiers
37 #----------------------------
38
39 ## Algorithm type: MG-Hexa hexahedron 3D algorithm, see Hexotic_Algorithm
40 MG_Hexa = "MG-Hexa"
41 Hexotic = MG_Hexa
42
43 #----------------------------
44 # Algorithms
45 #----------------------------
46
47 ## Defines a hexahedron 3D algorithm
48 #
49 #  It is created by calling smeshBuilder.Mesh.Hexahedron( smeshBuilder.MG_Hexa, geom=0 )
50 class Hexotic_Algorithm(Mesh_Algorithm):
51
52     ## name of the dynamic method in smeshBuilder.Mesh class
53     #  @internal
54     meshMethod = "Hexahedron"
55     ## type of algorithm used with helper function in smeshBuilder.Mesh class
56     #  @internal
57     algoType   = MG_Hexa
58     ## doc string of the method in smeshBuilder.Mesh class
59     #  @internal
60     docHelper  = "Creates hexahedron 3D algorithm for volumes"
61
62     ## Private constructor.
63     #  @param mesh parent mesh object algorithm is assigned to
64     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
65     #              if it is @c 0 (default), the algorithm is assigned to the main shape
66     def __init__(self, mesh, geom=0):
67         Mesh_Algorithm.__init__(self)
68         if noHexoticPlugin: print "Warning: HexoticPlugin module unavailable"
69         self.Create(mesh, geom, MG_Hexa, "libHexoticEngine.so")
70         self.params = None
71         pass
72
73     ## Defines "SetMinMaxHexes" hypothesis to give two MG-Hexa parameters
74     #  @param min minimal level of recursive partitioning on the initial octree cube
75     #  @param max maximal level of recursive partitioning on the initial octree cube
76     #  @return hypothesis object
77     def SetMinMaxHexes(self, min=3, max=8):
78         self.Parameters().SetHexesMinLevel(min)
79         self.Parameters().SetHexesMaxLevel(max)
80         return self.Parameters()
81
82     ## Defines "SetMinMaxSize" hypothesis to give two MG-Hexa parameters
83     #  @param min minimal element's size
84     #  @param max maximal element's size
85     #  @return hypothesis object
86     def SetMinMaxSize(self, min, max):
87         self.Parameters().SetMinSize(min)
88         self.Parameters().SetMaxSize(max)
89         return self.Parameters()
90          
91     ## Sets a size map
92     #  @param theObject geometrical object to assign local size to
93     #  @param theSize local size on the given object
94     #  @return hypothesis object
95     def SetSizeMap(self, theObject, theSize):
96         AssureGeomPublished( self.mesh, theObject )
97         if theSize <= 0:
98           raise ValueError, "The size must be > 0"
99         self.Parameters().SetSizeMap(theObject, theSize)
100         return self.Parameters()
101       
102     ## Unsets a size map : this is meant to be used only by the dump
103     #  @param theObject geometrical object to unassign local size
104     #  @return hypothesis object
105     def UnsetSizeMap(self, theObject):
106         AssureGeomPublished( self.mesh, theObject )
107         self.Parameters().UnsetSizeMap(theObject)
108         return self.Parameters()
109
110     ## (OBSOLETE) Defines "MinMaxQuad" hypothesis to give three MG-Hexa parameters
111     #  @param min minimal level of recursive partitioning on the initial octree cube
112     #  @param max maximal level of recursive partitioning on the initial octree cube
113     #  @param quad not documented
114     #  @return hypothesis object
115     def MinMaxQuad(self, min=3, max=8, quad=True):
116         print "WARNING: Function MinMaxQuad is deprecated, use SetMinMaxHexes instead"
117         return self.SetMinMaxHexes(min, max)
118       
119     ## Defines "ViscousLayers" hypothesis to give MG-Hexa parameters
120     #  @param numberOfLayers number of boundary layers
121     #  @param firstLayerSize height of the first layer
122     #  @param growth geometric progression for the boundary layer growth
123     #  @param direction describes whether the layers grow inwards or outwards. 
124     #         if direction is:
125     #         \c Inward : means the layers grow inwards,
126     #         \c Outward : means the layers grow outwards
127     #  @param facesWithLayers list of surface references from which the boundary
128     #         layers should be grown
129     #  @param imprintedFaces list of surface references that can be imprinted by
130     #         boundary layers
131     #  @return hypothesis object
132     def SetViscousLayers(self, numberOfLayers, firstLayerSize, growth, 
133                           direction="Inward", facesWithLayers=[], imprintedFaces=[]): 
134         self.Parameters().SetNbLayers(numberOfLayers)
135         self.Parameters().SetFirstLayerSize(firstLayerSize)
136         self.Parameters().SetGrowth(growth)
137         if direction == "Inward":
138           self.Parameters().SetDirection(True)
139         elif direction == "Outward":
140           self.Parameters().SetDirection(False)
141         self.Parameters().SetFacesWithLayers(facesWithLayers)
142         self.Parameters().SetImprintedFaces(imprintedFaces)
143         
144         return self.Parameters()
145
146     ## Defines hypothesis having several parameters
147     #  @return hypothesis object
148     def Parameters(self):
149         if not self.params:
150             self.params = self.Hypothesis("MG-Hexa Parameters", [],
151                                           "libHexoticEngine.so", UseExisting=0)
152             pass
153         return self.params
154
155
156     pass # end of Hexotic_Algorithm class