1 # Copyright (C) 2007-2020 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 ## Set values of advanced options
116 # @param theOptions string in a form "option_1 v1 option_2 v2"
117 def SetAdvancedOption(self, theOptions):
118 self.Parameters().SetAdvancedOption(theOptions)
119 def GetAdvancedOption(self):
120 return self.Parameters().GetAdvancedOption()
122 ## (OBSOLETE) Defines "MinMaxQuad" hypothesis to give three MG-Hexa parameters
123 # @param min minimal level of recursive partitioning on the initial octree cube
124 # @param max maximal level of recursive partitioning on the initial octree cube
125 # @param quad not documented
126 # @return hypothesis object
127 def MinMaxQuad(self, min=3, max=8, quad=True):
128 print("WARNING: Function MinMaxQuad is deprecated, use SetMinMaxHexes instead")
129 return self.SetMinMaxHexes(min, max)
131 ## Set advanced option value
132 # @param optionName option name
133 # @param optionValue option value
134 def SetOptionValue(self, optionName, optionValue):
135 self.Parameters().SetOptionValue( optionName, optionValue )
138 ## Defines "ViscousLayers" hypothesis to give MG-Hexa parameters
139 # @param numberOfLayers number of boundary layers
140 # @param firstLayerSize height of the first layer
141 # @param growth geometric progression for the boundary layer growth
142 # @param direction describes whether the layers grow inwards or outwards.
143 # Possible values are:
144 # - \c smeshBuilder.Inward : means the layers grow inwards,
145 # - \c smeshBuilder.Outward : means the layers grow outwards
146 # @param facesWithLayers list of surfaces from which the boundary
147 # layers should be grown
148 # @param imprintedFaces list of surfaces that can be imprinted by
150 # @return hypothesis object
151 def SetViscousLayers(self, numberOfLayers, firstLayerSize, growth,
152 facesWithLayers, imprintedFaces=[], direction=Inward):
153 self.Parameters().SetNbLayers(numberOfLayers)
154 self.Parameters().SetFirstLayerSize(firstLayerSize)
155 self.Parameters().SetGrowth(growth)
156 self.Parameters().SetDirection(direction)
157 if facesWithLayers and isinstance( facesWithLayers[0], geomBuilder.GEOM._objref_GEOM_Object ):
159 facesWithLayersIDs = []
160 for f in facesWithLayers:
161 if self.mesh.geompyD.ShapeIdToType( f.GetType() ) == "GROUP":
162 facesWithLayersIDs += f.GetSubShapeIndices()
164 facesWithLayersIDs += [self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f)]
165 facesWithLayers = facesWithLayersIDs
167 if imprintedFaces and isinstance( imprintedFaces[0], geomBuilder.GEOM._objref_GEOM_Object ):
169 imprintedFacesIDs = []
170 for f in imprintedFaces:
171 if self.mesh.geompyD.ShapeIdToType( f.GetType() ) == "GROUP":
172 imprintedFacesIDs += f.GetSubShapeIndices()
174 imprintedFacesIDs += [self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f)]
175 imprintedFaces = imprintedFacesIDs
176 self.Parameters().SetFacesWithLayers(facesWithLayers)
177 self.Parameters().SetImprintedFaces(imprintedFaces)
179 return self.Parameters()
181 ## To keep working files or remove them.
182 # @param toKeep "keep working files" flag value
183 def SetKeepFiles(self, toKeep):
184 self.Parameters().SetKeepFiles(toKeep)
187 ## Remove or not the log file (if any) in case of successful computation.
188 # The log file remains in case of errors anyway. If
189 # the "keep working files" flag is set to true, this option
191 # @param toRemove "remove log on success" flag value
192 def SetRemoveLogOnSuccess(self, toRemove):
193 self.Parameters().SetRemoveLogOnSuccess(toRemove)
196 ## Print the the log in a file. If set to false, the
197 # log is printed on the standard output
198 # @param toPrintLogInFile "print log in a file" flag value
199 def SetPrintLogInFile(self, toPrintLogInFile):
200 self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
203 ## Defines hypothesis having several parameters
204 # @return hypothesis object
205 def Parameters(self):
207 self.params = self.Hypothesis("MG-Hexa Parameters", [],
208 "libHexoticEngine.so", UseExisting=0)
213 pass # end of Hexotic_Algorithm class