1 # Copyright (C) 2007-2012 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.
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 BLSURFPluginDC
22 # Python API for the BLSURF meshing plug-in module.
24 from smesh_algorithm import Mesh_Algorithm
25 from smesh import AssureGeomPublished
27 # Topology treatment way of BLSURF
28 FromCAD, PreProcess, PreProcessPlus, PreCAD = 0,1,2,3
30 # Element size flag of BLSURF
31 DefaultSize, DefaultGeom, BLSURF_Custom, SizeMap = 0,0,1,2
34 # import BLSURFPlugin module if possible
42 #----------------------------
43 # Mesh algo type identifiers
44 #----------------------------
46 ## Algorithm type: BLSurf triangle 2D algorithm, see BLSURF_Algorithm
49 #----------------------
51 #----------------------
53 ## BLSurf 2D algorithm.
55 # It can be created by calling smesh.Mesh.Triangle(smesh.BLSURF,geom=0)
57 class BLSURF_Algorithm(Mesh_Algorithm):
59 ## name of the dynamic method in smesh.Mesh class
61 meshMethod = "Triangle"
62 ## type of algorithm used with helper function in smesh.Mesh class
65 ## doc string of the method
67 docHelper = "Creates triangle 2D algorithm for faces"
72 ## Private constructor.
73 # @param mesh parent mesh object algorithm is assigned to
74 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
75 # if it is @c 0 (default), the algorithm is assigned to the main shape
76 def __init__(self, mesh, geom=0):
77 Mesh_Algorithm.__init__(self)
79 print "Warning: BLSURFPlugin module unavailable"
80 self.Create(mesh, geom, BLSURF, "libBLSURFEngine.so")
82 #self.SetPhysicalMesh() - PAL19680
85 ## Sets a way to define size of mesh elements to generate.
86 # @param thePhysicalMesh is: DefaultSize, BLSURF_Custom or SizeMap.
87 def SetPhysicalMesh(self, thePhysicalMesh=DefaultSize):
88 self.Parameters().SetPhysicalMesh(thePhysicalMesh)
91 ## Sets size of mesh elements to generate.
92 # @param theVal value of mesh element size
93 def SetPhySize(self, theVal):
94 self.Parameters().SetPhySize(theVal)
97 ## Sets lower boundary of mesh element size (PhySize).
98 # @param theVal value of mesh element minimal size
99 def SetPhyMin(self, theVal=-1):
100 self.Parameters().SetPhyMin(theVal)
103 ## Sets upper boundary of mesh element size (PhySize).
104 # @param theVal value of mesh element maximal size
105 def SetPhyMax(self, theVal=-1):
106 self.Parameters().SetPhyMax(theVal)
109 ## Sets a way to define maximum angular deflection of mesh from CAD model.
110 # @param theGeometricMesh is: 0 (None) or 1 (Custom)
111 def SetGeometricMesh(self, theGeometricMesh=0):
112 if self.Parameters().GetPhysicalMesh() == 0: theGeometricMesh = 1
113 self.Parameters().SetGeometricMesh(theGeometricMesh)
116 ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
117 # @param theVal value of angular deflection for mesh face
118 def SetAngleMeshS(self, theVal=_angleMeshS):
119 if self.Parameters().GetGeometricMesh() == 0: theVal = self._angleMeshS
120 self.Parameters().SetAngleMeshS(theVal)
123 ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
124 # @param theVal value of angular deflection for mesh edge
125 def SetAngleMeshC(self, theVal=_angleMeshS):
126 if self.Parameters().GetGeometricMesh() == 0: theVal = self._angleMeshS
127 self.Parameters().SetAngleMeshC(theVal)
130 ## Sets lower boundary of mesh element size computed to respect angular deflection.
131 # @param theVal value of mesh element minimal size
132 def SetGeoMin(self, theVal=-1):
133 self.Parameters().SetGeoMin(theVal)
136 ## Sets upper boundary of mesh element size computed to respect angular deflection.
137 # @param theVal value of mesh element maximal size
138 def SetGeoMax(self, theVal=-1):
139 self.Parameters().SetGeoMax(theVal)
142 ## Sets maximal allowed ratio between the lengths of two adjacent edges.
143 # @param theVal value of maximal length ratio
144 def SetGradation(self, theVal=_gradation):
145 if self.Parameters().GetGeometricMesh() == 0: theVal = self._gradation
146 self.Parameters().SetGradation(theVal)
149 ## Sets topology usage way.
150 # @param way defines how mesh conformity is assured
151 # - FromCAD - mesh conformity is assured by conformity of a shape
152 # - PreProcess or PreProcessPlus - by pre-processing a CAD model
153 # - PreCAD - by pre-processing with PreCAD a CAD model
154 def SetTopology(self, way):
155 self.Parameters().SetTopology(way)
158 ## To respect geometrical edges or not.
159 # @param toIgnoreEdges "ignore edges" flag value
160 def SetDecimesh(self, toIgnoreEdges=False):
161 self.Parameters().SetDecimesh(toIgnoreEdges)
164 ## Sets verbosity level in the range 0 to 100.
165 # @param level verbosity level
166 def SetVerbosity(self, level):
167 self.Parameters().SetVerbosity(level)
170 ## To optimize merges edges.
171 # @param toMergeEdges "merge edges" flag value
172 def SetPreCADMergeEdges(self, toMergeEdges=False):
173 self.Parameters().SetPreCADMergeEdges(toMergeEdges)
176 ## To remove nano edges.
177 # @param toRemoveNanoEdges "remove nano edges" flag value
178 def SetPreCADRemoveNanoEdges(self, toRemoveNanoEdges=False):
179 self.Parameters().SetPreCADRemoveNanoEdges(toRemoveNanoEdges)
182 ## To compute topology from scratch
183 # @param toDiscardInput "discard input" flag value
184 def SetPreCADDiscardInput(self, toDiscardInput=False):
185 self.Parameters().SetPreCADDiscardInput(toDiscardInput)
188 ## Sets the length below which an edge is considered as nano
189 # for the topology processing.
190 # @param epsNano nano edge length threshold value
191 def SetPreCADEpsNano(self, epsNano):
192 self.Parameters().SetPreCADEpsNano(epsNano)
195 ## Sets advanced option value.
196 # @param optionName advanced option name
197 # @param level advanced option value
198 def SetOptionValue(self, optionName, level):
199 self.Parameters().SetOptionValue(optionName,level)
202 ## Sets advanced PreCAD option value.
203 # @param optionName name of the option
204 # @param optionValue value of the option
205 def SetPreCADOptionValue(self, optionName, optionValue):
206 self.Parameters().SetPreCADOptionValue(optionName,optionValue)
209 ## Sets GMF file for export at computation
210 # @param fileName GMF file name
211 def SetGMFFile(self, fileName):
212 self.Parameters().SetGMFFile(fileName)
215 #-----------------------------------------
216 # Enforced vertices (BLSURF)
217 #-----------------------------------------
219 ## To get all the enforced vertices
220 def GetAllEnforcedVertices(self):
221 return self.Parameters().GetAllEnforcedVertices()
223 ## To get all the enforced vertices sorted by face (or group, compound)
224 def GetAllEnforcedVerticesByFace(self):
225 return self.Parameters().GetAllEnforcedVerticesByFace()
227 ## To get all the enforced vertices sorted by coords of input vertices
228 def GetAllEnforcedVerticesByCoords(self):
229 return self.Parameters().GetAllEnforcedVerticesByCoords()
231 ## To get all the coords of input vertices sorted by face (or group, compound)
232 def GetAllCoordsByFace(self):
233 return self.Parameters().GetAllCoordsByFace()
235 ## To get all the enforced vertices on a face (or group, compound)
236 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
237 def GetEnforcedVertices(self, theFace):
238 AssureGeomPublished( self.mesh, theFace )
239 return self.Parameters().GetEnforcedVertices(theFace)
241 ## To clear all the enforced vertices
242 def ClearAllEnforcedVertices(self):
243 return self.Parameters().ClearAllEnforcedVertices()
245 ## To set an enforced vertex on a face (or group, compound) given the coordinates of a point. If the point is not on the face, it will projected on it. If there is no projection, no enforced vertex is created.
246 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
247 # @param x : x coordinate
248 # @param y : y coordinate
249 # @param z : z coordinate
250 # @param vertexName : name of the enforced vertex
251 # @param groupName : name of the group
252 def SetEnforcedVertex(self, theFace, x, y, z, vertexName = "", groupName = ""):
253 AssureGeomPublished( self.mesh, theFace )
256 return self.Parameters().SetEnforcedVertex(theFace, x, y, z)
258 return self.Parameters().SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
262 return self.Parameters().SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
264 return self.Parameters().SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
268 ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
269 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
270 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
271 # @param groupName : name of the group
272 def SetEnforcedVertexGeom(self, theFace, theVertex, groupName = ""):
273 AssureGeomPublished( self.mesh, theFace )
274 AssureGeomPublished( self.mesh, theVertex )
276 return self.Parameters().SetEnforcedVertexGeom(theFace, theVertex)
278 return self.Parameters().SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
281 ## To remove an enforced vertex on a given GEOM face (or group, compound) given the coordinates.
282 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
283 # @param x : x coordinate
284 # @param y : y coordinate
285 # @param z : z coordinate
286 def UnsetEnforcedVertex(self, theFace, x, y, z):
287 AssureGeomPublished( self.mesh, theFace )
288 return self.Parameters().UnsetEnforcedVertex(theFace, x, y, z)
290 ## To remove an enforced vertex on a given GEOM face (or group, compound) given a GEOM vertex, group or compound.
291 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
292 # @param theVertex : GEOM vertex (or group, compound) to remove.
293 def UnsetEnforcedVertexGeom(self, theFace, theVertex):
294 AssureGeomPublished( self.mesh, theFace )
295 AssureGeomPublished( self.mesh, theVertex )
296 return self.Parameters().UnsetEnforcedVertexGeom(theFace, theVertex)
298 ## To remove all enforced vertices on a given face.
299 # @param theFace : face (or group/compound of faces) on which to remove all enforced vertices
300 def UnsetEnforcedVertices(self, theFace):
301 AssureGeomPublished( self.mesh, theFace )
302 return self.Parameters().UnsetEnforcedVertices(theFace)
304 ## To tell BLSURF to add a node on internal vertices
305 # @param toEnforceInternalVertices : boolean; if True the internal vertices are added as enforced vertices
306 def SetInternalEnforcedVertexAllFaces(self, toEnforceInternalVertices):
307 return self.Parameters().SetInternalEnforcedVertexAllFaces(toEnforceInternalVertices)
309 ## To know if BLSURF will add a node on internal vertices
310 def GetInternalEnforcedVertexAllFaces(self):
311 return self.Parameters().GetInternalEnforcedVertexAllFaces()
313 ## To define a group for the nodes of internal vertices
314 # @param groupName : string; name of the group
315 def SetInternalEnforcedVertexAllFacesGroup(self, groupName):
316 return self.Parameters().SetInternalEnforcedVertexAllFacesGroup(groupName)
318 ## To get the group name of the nodes of internal vertices
319 def GetInternalEnforcedVertexAllFacesGroup(self):
320 return self.Parameters().GetInternalEnforcedVertexAllFacesGroup()
322 #-----------------------------------------
324 #-----------------------------------------
326 ## Sets an attractor on the chosen face. The mesh size will decrease exponentially with the distance from theAttractor, following the rule h(d) = theEndSize - (theEndSize - theStartSize) * exp [ - ( d / theInfluenceDistance ) ^ 2 ]
327 # @param theFace : face on which the attractor will be defined
328 # @param theAttractor : geometrical object from which the mesh size "h" decreases exponentially
329 # @param theStartSize : mesh size on theAttractor
330 # @param theEndSize : maximum size that will be reached on theFace
331 # @param theInfluenceDistance : influence of the attractor ( the size grow slower on theFace if it's high)
332 # @param theConstantSizeDistance : distance until which the mesh size will be kept constant on theFace
333 def SetAttractorGeom(self, theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance):
334 AssureGeomPublished( self.mesh, theFace )
335 AssureGeomPublished( self.mesh, theAttractor )
336 self.Parameters().SetAttractorGeom(theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance)
339 ## Unsets an attractor on the chosen face.
340 # @param theFace : face on which the attractor has to be removed
341 def UnsetAttractorGeom(self, theFace):
342 AssureGeomPublished( self.mesh, theFace )
343 self.Parameters().SetAttractorGeom(theFace)
346 #-----------------------------------------
348 #-----------------------------------------
350 ## To set a size map on a face, edge or vertex (or group, compound) given Python function.
351 # If theObject is a face, the function can be: def f(u,v): return u+v
352 # If theObject is an edge, the function can be: def f(t): return t/2
353 # If theObject is a vertex, the function can be: def f(): return 10
354 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
355 # @param theSizeMap : Size map defined as a string
356 def SetSizeMap(self, theObject, theSizeMap):
357 AssureGeomPublished( self.mesh, theObject )
358 self.Parameters().SetSizeMap(theObject, theSizeMap)
361 ## To remove a size map defined on a face, edge or vertex (or group, compound)
362 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
363 def UnsetSizeMap(self, theObject):
364 AssureGeomPublished( self.mesh, theObject )
365 self.Parameters().UnsetSizeMap(theObject)
368 ## To remove all the size maps
369 def ClearSizeMaps(self):
370 self.Parameters().ClearSizeMaps()
373 ## Sets QuadAllowed flag.
374 # @param toAllow "allow quadrangles" flag value
375 def SetQuadAllowed(self, toAllow=True):
376 self.Parameters().SetQuadAllowed(toAllow)
379 ## Defines hypothesis having several parameters
380 # @return hypothesis object
381 def Parameters(self):
383 self.params = self.Hypothesis("BLSURF_Parameters", [],
384 "libBLSURFEngine.so", UseExisting=0)
388 pass # end of BLSURF_Algorithm class