1 # Copyright (C) 2007-2013 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 BLSURFPluginBuilder
22 # Python API for the BLSURF meshing plug-in module.
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
25 from salome.smesh.smeshBuilder 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_GlobalSize, BLSURF_LocalSize = 0,0,1,2
33 BLSURF_Custom, SizeMap = BLSURF_GlobalSize, BLSURF_LocalSize
36 # import BLSURFPlugin module if possible
44 #----------------------------
45 # Mesh algo type identifiers
46 #----------------------------
48 ## Algorithm type: BLSurf triangle 2D algorithm, see BLSURF_Algorithm
51 #----------------------
53 #----------------------
55 ## BLSurf 2D algorithm.
57 # It can be created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.BLSURF,geom=0)
59 class BLSURF_Algorithm(Mesh_Algorithm):
61 ## name of the dynamic method in smeshBuilder.Mesh class
63 meshMethod = "Triangle"
64 ## type of algorithm used with helper function in smeshBuilder.Mesh class
67 ## doc string of the method
69 docHelper = "Creates triangle 2D algorithm for faces"
71 _anisotropic_ratio = 0
72 _bad_surface_element_aspect_ratio = 1000
73 _geometric_approximation = 22
76 _remove_tiny_edges = 0
78 ## Private constructor.
79 # @param mesh parent mesh object algorithm is assigned to
80 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
81 # if it is @c 0 (default), the algorithm is assigned to the main shape
82 def __init__(self, mesh, geom=0):
83 Mesh_Algorithm.__init__(self)
85 print "Warning: BLSURFPlugin module unavailable"
86 self.Create(mesh, geom, BLSURF, "libBLSURFEngine.so")
88 #self.SetPhysicalMesh() - PAL19680
91 ## Sets a way to define size of mesh elements to generate.
92 # @param thePhysicalMesh is: DefaultSize, BLSURF_Custom or SizeMap.
93 def SetPhysicalMesh(self, thePhysicalMesh=DefaultSize):
94 physical_size_mode = thePhysicalMesh
95 if self.Parameters().GetGeometricMesh() == DefaultGeom:
96 if physical_size_mode == DefaultSize:
97 physical_size_mode = BLSURF_GlobalSize
98 self.Parameters().SetPhysicalMesh(physical_size_mode)
101 ## Sets a way to define maximum angular deflection of mesh from CAD model.
102 # @param theGeometricMesh is: DefaultGeom (0)) or BLSURF_GlobalSize (1))
103 def SetGeometricMesh(self, theGeometricMesh=DefaultGeom):
104 geometric_size_mode = theGeometricMesh
105 if self.Parameters().GetPhysicalMesh() == DefaultSize:
106 if geometric_size_mode == DefaultGeom:
107 geometric_size_mode = BLSURF_GlobalSize
108 self.Parameters().SetGeometricMesh(geometric_size_mode)
111 ## Sets size of mesh elements to generate.
112 # @param theVal : constant global size when using a global physical size.
113 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
114 def SetPhySize(self, theVal, isRelative = False):
115 if self.Parameters().GetPhysicalMesh() == DefaultSize:
116 self.SetPhysicalMesh(BLSURF_GlobalSize)
118 self.Parameters().SetPhySizeRel(theVal)
120 self.Parameters().SetPhySize(theVal)
123 ## Sets lower boundary of mesh element size.
124 # @param theVal : global minimal cell size desired.
125 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
126 def SetMinSize(self, theVal=-1, isRelative = False):
128 self.Parameters().SetMinSizeRel(theVal)
130 self.Parameters().SetMinSize(theVal)
133 ## Sets upper boundary of mesh element size.
134 # @param theVal : global maximal cell size desired.
135 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
136 def SetMaxSize(self, theVal=-1):
138 self.Parameters().SetMaxSizeRel(theVal)
140 self.Parameters().SetMaxSize(theVal)
143 ## Sets angular deflection (in degrees) from CAD surface.
144 # @param theVal value of angular deflection
145 def SetAngleMesh(self, theVal=_geometric_approximation):
146 if self.Parameters().GetGeometricMesh() == DefaultGeom:
147 self.SetGeometricMesh(BLSURF_GlobalSize)
148 self.Parameters().SetAngleMesh(theVal)
151 ## Sets maximal allowed ratio between the lengths of two adjacent edges.
152 # @param theVal value of maximal length ratio
153 def SetGradation(self, theVal=_gradation):
154 if self.Parameters().GetGeometricMesh() == 0: theVal = self._gradation
155 self.Parameters().SetGradation(theVal)
158 ## Sets topology usage way.
159 # @param way defines how mesh conformity is assured <ul>
160 # <li>FromCAD - mesh conformity is assured by conformity of a shape</li>
161 # <li>PreProcess or PreProcessPlus - by pre-processing a CAD model (OBSOLETE: FromCAD will be used)</li>
162 # <li>PreCAD - by pre-processing with PreCAD a CAD model</li></ul>
163 def SetTopology(self, way):
165 print "Warning: topology mode %d is no longer supported. Mode FromCAD is used."%way
167 self.Parameters().SetTopology(way)
170 ## To respect geometrical edges or not.
171 # @param toIgnoreEdges "ignore edges" flag value
172 def SetDecimesh(self, toIgnoreEdges=False):
174 self.SetOptionValue("respect_geometry","0")
176 self.SetOptionValue("respect_geometry","1")
179 ## Sets verbosity level in the range 0 to 100.
180 # @param level verbosity level
181 def SetVerbosity(self, level):
182 self.Parameters().SetVerbosity(level)
185 ## To optimize merges edges.
186 # @param toMergeEdges "merge edges" flag value
187 def SetPreCADMergeEdges(self, toMergeEdges=False):
188 if self.Parameters().GetTopology() != PreCAD:
189 self.SetTopology(PreCAD)
190 self.Parameters().SetPreCADMergeEdges(toMergeEdges)
193 ## To process 3D topology.
194 # @param toProcess "PreCAD process 3D" flag value
195 def SetPreCADProcess3DTopology(self, toProcess=False):
196 if self.Parameters().GetTopology() != PreCAD:
197 self.SetTopology(PreCAD)
198 self.Parameters().SetPreCADProcess3DTopology(toProcess)
201 ## To remove nano edges.
202 # @param toRemoveNanoEdges "remove nano edges" flag value
203 def SetPreCADRemoveNanoEdges(self, toRemoveNanoEdges=False):
204 if toRemoveNanoEdges:
205 self.SetPreCADOptionValue("remove_tiny_edges","1")
207 self.SetPreCADOptionValue("remove_tiny_edges","0")
210 ## To compute topology from scratch
211 # @param toDiscardInput "discard input" flag value
212 def SetPreCADDiscardInput(self, toDiscardInput=False):
213 if self.Parameters().GetTopology() != PreCAD:
214 self.SetTopology(PreCAD)
215 self.Parameters().SetPreCADDiscardInput(toDiscardInput)
218 ## Sets the length below which an edge is considered as nano
219 # for the topology processing.
220 # @param epsNano nano edge length threshold value
221 def SetPreCADEpsNano(self, epsNano):
222 self.SetPreCADOptionValue("tiny_edge_length","%f"%epsNano)
225 ## Sets advanced option value.
226 # @param optionName advanced option name
227 # @param level advanced option value
228 def SetOptionValue(self, optionName, level):
229 self.Parameters().SetOptionValue(optionName,level)
232 ## Sets advanced PreCAD option value.
233 # @param optionName name of the option
234 # @param optionValue value of the option
235 def SetPreCADOptionValue(self, optionName, optionValue):
236 if self.Parameters().GetTopology() != PreCAD:
237 self.SetTopology(PreCAD)
238 self.Parameters().SetPreCADOptionValue(optionName,optionValue)
241 ## Sets GMF file for export at computation
242 # @param fileName GMF file name
243 def SetGMFFile(self, fileName):
244 self.Parameters().SetGMFFile(fileName)
247 #-----------------------------------------
248 # Enforced vertices (BLSURF)
249 #-----------------------------------------
251 ## To get all the enforced vertices
252 def GetAllEnforcedVertices(self):
253 return self.Parameters().GetAllEnforcedVertices()
255 ## To get all the enforced vertices sorted by face (or group, compound)
256 def GetAllEnforcedVerticesByFace(self):
257 return self.Parameters().GetAllEnforcedVerticesByFace()
259 ## To get all the enforced vertices sorted by coords of input vertices
260 def GetAllEnforcedVerticesByCoords(self):
261 return self.Parameters().GetAllEnforcedVerticesByCoords()
263 ## To get all the coords of input vertices sorted by face (or group, compound)
264 def GetAllCoordsByFace(self):
265 return self.Parameters().GetAllCoordsByFace()
267 ## To get all the enforced vertices on a face (or group, compound)
268 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
269 def GetEnforcedVertices(self, theFace):
270 AssureGeomPublished( self.mesh, theFace )
271 return self.Parameters().GetEnforcedVertices(theFace)
273 ## To clear all the enforced vertices
274 def ClearAllEnforcedVertices(self):
275 return self.Parameters().ClearAllEnforcedVertices()
277 ## 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.
278 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
279 # @param x : x coordinate
280 # @param y : y coordinate
281 # @param z : z coordinate
282 # @param vertexName : name of the enforced vertex
283 # @param groupName : name of the group
284 def SetEnforcedVertex(self, theFace, x, y, z, vertexName = "", groupName = ""):
285 AssureGeomPublished( self.mesh, theFace )
288 return self.Parameters().SetEnforcedVertex(theFace, x, y, z)
290 return self.Parameters().SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
294 return self.Parameters().SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
296 return self.Parameters().SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
300 ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
301 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
302 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
303 # @param groupName : name of the group
304 def SetEnforcedVertexGeom(self, theFace, theVertex, groupName = ""):
305 AssureGeomPublished( self.mesh, theFace )
306 AssureGeomPublished( self.mesh, theVertex )
308 return self.Parameters().SetEnforcedVertexGeom(theFace, theVertex)
310 return self.Parameters().SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
313 ## To remove an enforced vertex on a given GEOM face (or group, compound) given the coordinates.
314 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
315 # @param x : x coordinate
316 # @param y : y coordinate
317 # @param z : z coordinate
318 def UnsetEnforcedVertex(self, theFace, x, y, z):
319 AssureGeomPublished( self.mesh, theFace )
320 return self.Parameters().UnsetEnforcedVertex(theFace, x, y, z)
322 ## To remove an enforced vertex on a given GEOM face (or group, compound) given a GEOM vertex, group or compound.
323 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
324 # @param theVertex : GEOM vertex (or group, compound) to remove.
325 def UnsetEnforcedVertexGeom(self, theFace, theVertex):
326 AssureGeomPublished( self.mesh, theFace )
327 AssureGeomPublished( self.mesh, theVertex )
328 return self.Parameters().UnsetEnforcedVertexGeom(theFace, theVertex)
330 ## To remove all enforced vertices on a given face.
331 # @param theFace : face (or group/compound of faces) on which to remove all enforced vertices
332 def UnsetEnforcedVertices(self, theFace):
333 AssureGeomPublished( self.mesh, theFace )
334 return self.Parameters().UnsetEnforcedVertices(theFace)
336 ## To tell BLSURF to add a node on internal vertices
337 # @param toEnforceInternalVertices : boolean; if True the internal vertices are added as enforced vertices
338 def SetInternalEnforcedVertexAllFaces(self, toEnforceInternalVertices):
339 return self.Parameters().SetInternalEnforcedVertexAllFaces(toEnforceInternalVertices)
341 ## To know if BLSURF will add a node on internal vertices
342 def GetInternalEnforcedVertexAllFaces(self):
343 return self.Parameters().GetInternalEnforcedVertexAllFaces()
345 ## To define a group for the nodes of internal vertices
346 # @param groupName : string; name of the group
347 def SetInternalEnforcedVertexAllFacesGroup(self, groupName):
348 return self.Parameters().SetInternalEnforcedVertexAllFacesGroup(groupName)
350 ## To get the group name of the nodes of internal vertices
351 def GetInternalEnforcedVertexAllFacesGroup(self):
352 return self.Parameters().GetInternalEnforcedVertexAllFacesGroup()
354 #-----------------------------------------
356 #-----------------------------------------
358 ## 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 ]
359 # @param theFace : face on which the attractor will be defined
360 # @param theAttractor : geometrical object from which the mesh size "h" decreases exponentially
361 # @param theStartSize : mesh size on theAttractor
362 # @param theEndSize : maximum size that will be reached on theFace
363 # @param theInfluenceDistance : influence of the attractor ( the size grow slower on theFace if it's high)
364 # @param theConstantSizeDistance : distance until which the mesh size will be kept constant on theFace
365 def SetAttractorGeom(self, theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance):
366 AssureGeomPublished( self.mesh, theFace )
367 AssureGeomPublished( self.mesh, theAttractor )
368 self.Parameters().SetAttractorGeom(theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance)
371 ## Unsets an attractor on the chosen face.
372 # @param theFace : face on which the attractor has to be removed
373 def UnsetAttractorGeom(self, theFace):
374 AssureGeomPublished( self.mesh, theFace )
375 self.Parameters().SetAttractorGeom(theFace)
378 #-----------------------------------------
380 #-----------------------------------------
382 ## To set a size map on a face, edge or vertex (or group, compound) given Python function.
383 # If theObject is a face, the function can be: def f(u,v): return u+v
384 # If theObject is an edge, the function can be: def f(t): return t/2
385 # If theObject is a vertex, the function can be: def f(): return 10
386 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
387 # @param theSizeMap : Size map defined as a string
388 def SetSizeMap(self, theObject, theSizeMap):
389 AssureGeomPublished( self.mesh, theObject )
390 self.Parameters().SetSizeMap(theObject, theSizeMap)
393 ## To set a constant size map on a face, edge or vertex (or group, compound).
394 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
395 # @param theSizeMap : Size map defined as a double
396 def SetConstantSizeMap(self, theObject, theSizeMap):
397 AssureGeomPublished( self.mesh, theObject )
398 self.Parameters().SetConstantSizeMap(theObject, theSizeMap)
400 ## To remove a size map defined on a face, edge or vertex (or group, compound)
401 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
402 def UnsetSizeMap(self, theObject):
403 AssureGeomPublished( self.mesh, theObject )
404 self.Parameters().UnsetSizeMap(theObject)
407 ## To remove all the size maps
408 def ClearSizeMaps(self):
409 self.Parameters().ClearSizeMaps()
412 ## Sets QuadAllowed flag.
413 # @param toAllow "allow quadrangles" flag value
414 def SetQuadAllowed(self, toAllow=True):
415 self.Parameters().SetQuadAllowed(toAllow)
418 ## Defines hypothesis having several parameters
419 # @return hypothesis object
420 def Parameters(self):
422 self.params = self.Hypothesis("BLSURF_Parameters", [],
423 "libBLSURFEngine.so", UseExisting=0)
427 #=====================
429 #=====================
434 ## Sets lower boundary of mesh element size (PhySize).
435 def SetPhyMin(self, theVal=-1):
437 Obsolete function. Use SetMinSize.
439 print "Warning: SetPhyMin is obsolete. Please use SetMinSize"
440 self.SetMinSize(theVal)
443 ## Sets upper boundary of mesh element size (PhySize).
444 def SetPhyMax(self, theVal=-1):
446 Obsolete function. Use SetMaxSize.
448 print "Warning: SetPhyMax is obsolete. Please use SetMaxSize"
449 self.SetMaxSize(theVal)
452 ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
453 def SetAngleMeshS(self, theVal=_geometric_approximation):
455 Obsolete function. Use SetAngleMesh.
457 print "Warning: SetAngleMeshS is obsolete. Please use SetAngleMesh"
458 self.SetAngleMesh(theVal)
461 ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
462 def SetAngleMeshC(self, theVal=_geometric_approximation):
464 Obsolete function. Use SetAngleMesh.
466 print "Warning: SetAngleMeshC is obsolete. Please use SetAngleMesh"
467 self.SetAngleMesh(theVal)
470 ## Sets lower boundary of mesh element size computed to respect angular deflection.
471 def SetGeoMin(self, theVal=-1):
473 Obsolete function. Use SetMinSize.
475 print "Warning: SetGeoMin is obsolete. Please use SetMinSize"
476 self.SetMinSize(theVal)
479 ## Sets upper boundary of mesh element size computed to respect angular deflection.
480 def SetGeoMax(self, theVal=-1):
482 Obsolete function. Use SetMaxSize.
484 print "Warning: SetGeoMax is obsolete. Please use SetMaxSize"
485 self.SetMaxSize(theVal)
489 pass # end of BLSURF_Algorithm class