1 # Copyright (C) 2007-2016 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 BLSURFPluginBuilder
22 # Python API for the MG-CADSurf meshing plug-in module.
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
26 LIBRARY = "libBLSURFEngine.so"
28 # Topology treatment way of MG-CADSurf
29 FromCAD, PreProcess, PreProcessPlus, PreCAD = 0,1,2,3
31 # Element size flag of MG-CADSurf
32 DefaultSize, DefaultGeom, MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize = 0,0,1,2
34 MG_CADSURF_Custom, SizeMap = MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize
35 BLSURF_Custom, BLSURF_GlobalSize, BLSURF_LocalSize = MG_CADSURF_Custom, MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize
37 # import BLSURFPlugin module if possible
45 #----------------------------
46 # Mesh algo type identifiers
47 #----------------------------
49 ## Algorithm type: MG-CADSurf triangle algorithm, see BLSURF_Algorithm
50 MG_CADSurf = "MG-CADSurf"
53 #----------------------
55 #----------------------
57 ## MG-CADSurf 2D algorithm.
59 # It can be created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MG-CADSurf,geom=0)
61 class BLSURF_Algorithm(Mesh_Algorithm):
63 ## name of the dynamic method in smeshBuilder.Mesh class
65 meshMethod = "Triangle"
66 ## type of algorithm used with helper function in smeshBuilder.Mesh class
69 ## doc string of the method
71 docHelper = "Creates triangle algorithm for faces"
73 _anisotropic_ratio = 0
74 _bad_surface_element_aspect_ratio = 1000
75 _geometric_approximation = 22
78 _remove_tiny_edges = 0
80 ## Private constructor.
81 # @param mesh parent mesh object algorithm is assigned to
82 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
83 # if it is @c 0 (default), the algorithm is assigned to the main shape
84 def __init__(self, mesh, geom=0):
85 Mesh_Algorithm.__init__(self)
87 print "Warning: BLSURFPlugin module unavailable"
88 self.Create(mesh, geom, BLSURF, LIBRARY)
90 self.geompyD = mesh.geompyD
91 #self.SetPhysicalMesh() - PAL19680
94 ## Sets a way to define size of mesh elements to generate.
95 # @param thePhysicalMesh is: DefaultSize, MG_CADSURF_Custom or SizeMap.
96 def SetPhysicalMesh(self, thePhysicalMesh=DefaultSize):
97 physical_size_mode = thePhysicalMesh
98 if self.Parameters().GetGeometricMesh() == DefaultGeom:
99 if physical_size_mode == DefaultSize:
100 physical_size_mode = MG_CADSURF_GlobalSize
101 self.Parameters().SetPhysicalMesh(physical_size_mode)
104 ## Sets a way to define maximum angular deflection of mesh from CAD model.
105 # @param theGeometricMesh is: DefaultGeom (0)) or MG_CADSURF_GlobalSize (1))
106 def SetGeometricMesh(self, theGeometricMesh=DefaultGeom):
107 geometric_size_mode = theGeometricMesh
108 if self.Parameters().GetPhysicalMesh() == DefaultSize:
109 if geometric_size_mode == DefaultGeom:
110 geometric_size_mode = MG_CADSURF_GlobalSize
111 self.Parameters().SetGeometricMesh(geometric_size_mode)
114 ## Sets size of mesh elements to generate.
115 # @param theVal : constant global size when using a global physical size.
116 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
117 def SetPhySize(self, theVal, isRelative = False):
118 if self.Parameters().GetPhysicalMesh() == DefaultSize:
119 self.SetPhysicalMesh(MG_CADSURF_GlobalSize)
121 self.Parameters().SetPhySizeRel(theVal)
123 self.Parameters().SetPhySize(theVal)
126 ## Sets lower boundary of mesh element size.
127 # @param theVal : global minimal cell size desired.
128 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
129 def SetMinSize(self, theVal=-1, isRelative = False):
131 self.Parameters().SetMinSizeRel(theVal)
133 self.Parameters().SetMinSize(theVal)
136 ## Sets upper boundary of mesh element size.
137 # @param theVal : global maximal cell size desired.
138 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
139 def SetMaxSize(self, theVal=-1, isRelative = False):
141 self.Parameters().SetMaxSizeRel(theVal)
143 self.Parameters().SetMaxSize(theVal)
146 ## Sets angular deflection (in degrees) from CAD surface.
147 # @param theVal value of angular deflection
148 def SetAngleMesh(self, theVal=_geometric_approximation):
149 if self.Parameters().GetGeometricMesh() == DefaultGeom:
150 self.SetGeometricMesh(MG_CADSURF_GlobalSize)
151 self.Parameters().SetAngleMesh(theVal)
154 ## Sets the maximum desired distance between a triangle and its supporting CAD surface
155 # @param distance the distance between a triangle and a surface
156 def SetChordalError(self, distance):
157 self.Parameters().SetChordalError(distance)
160 ## Sets maximal allowed ratio between the lengths of two adjacent edges.
161 # @param theVal value of maximal length ratio
162 def SetGradation(self, theVal=_gradation):
163 if self.Parameters().GetGeometricMesh() == 0: theVal = self._gradation
164 self.Parameters().SetGradation(theVal)
167 ## Sets topology usage way.
168 # @param way defines how mesh conformity is assured <ul>
169 # <li>FromCAD - mesh conformity is assured by conformity of a shape</li>
170 # <li>PreProcess or PreProcessPlus - by pre-processing a CAD model (OBSOLETE: FromCAD will be used)</li>
171 # <li>PreCAD - by pre-processing with PreCAD a CAD model</li></ul>
172 def SetTopology(self, way):
173 if way != PreCAD and way != FromCAD:
174 print "Warning: topology mode %d is no longer supported. Mode FromCAD is used."%way
176 self.Parameters().SetTopology(way)
179 ## To respect geometrical edges or not.
180 # @param toIgnoreEdges "ignore edges" flag value
181 def SetDecimesh(self, toIgnoreEdges=False):
183 self.SetOptionValue("respect_geometry","0")
185 self.SetOptionValue("respect_geometry","1")
188 ## Sets verbosity level in the range 0 to 100.
189 # @param level verbosity level
190 def SetVerbosity(self, level):
191 self.Parameters().SetVerbosity(level)
194 ## To optimize merges edges.
195 # @param toMergeEdges "merge edges" flag value
196 def SetPreCADMergeEdges(self, toMergeEdges=False):
197 self.Parameters().SetPreCADMergeEdges(toMergeEdges)
200 ## To remove tiny UV edges.
201 # @param toRemoveTinyUVEdges "remove_tiny_uv_edges" flag value
202 def SetPreCADRemoveTinyUVEdges(self, toRemoveTinyUVEdges=False):
203 self.Parameters().SetPreCADRemoveTinyUVEdges(toRemoveTinyUVEdges)
206 ## To remove duplicate CAD Faces
207 # @param toRemoveDuplicateCADFaces "remove_duplicate_cad_faces" flag value
208 def SetPreCADRemoveDuplicateCADFaces(self, toRemoveDuplicateCADFaces=False):
209 self.Parameters().SetPreCADRemoveDuplicateCADFaces(toRemoveDuplicateCADFaces)
212 ## To process 3D topology.
213 # @param toProcess "PreCAD process 3D" flag value
214 def SetPreCADProcess3DTopology(self, toProcess=False):
215 self.Parameters().SetPreCADProcess3DTopology(toProcess)
218 ## To remove nano edges.
219 # @param toRemoveNanoEdges "remove nano edges" flag value
220 def SetPreCADRemoveNanoEdges(self, toRemoveNanoEdges=False):
221 if toRemoveNanoEdges:
222 self.SetPreCADOptionValue("remove_tiny_edges","1")
224 self.SetPreCADOptionValue("remove_tiny_edges","0")
227 ## To compute topology from scratch
228 # @param toDiscardInput "discard input" flag value
229 def SetPreCADDiscardInput(self, toDiscardInput=False):
230 self.Parameters().SetPreCADDiscardInput(toDiscardInput)
233 ## Sets the length below which an edge is considered as nano
234 # for the topology processing.
235 # @param epsNano nano edge length threshold value
236 def SetPreCADEpsNano(self, epsNano):
237 self.SetPreCADOptionValue("tiny_edge_length","%f"%epsNano)
240 ## Sets advanced option value.
241 # @param optionName advanced option name
242 # @param level advanced option value
243 def SetOptionValue(self, optionName, level):
244 self.Parameters().SetOptionValue(optionName,level)
247 ## Sets advanced PreCAD option value.
248 # @param optionName name of the option
249 # @param optionValue value of the option
250 def SetPreCADOptionValue(self, optionName, optionValue):
251 self.Parameters().SetPreCADOptionValue(optionName,optionValue)
254 ## Adds custom advanced option value.
255 # @param optionName custom advanced option name
256 # @param level custom advanced option value
257 def AddOption(self, optionName, level):
258 self.Parameters().AddOption(optionName,level)
261 ## Adds custom advanced PreCAD option value.
262 # @param optionName custom name of the option
263 # @param optionValue value of the option
264 def AddPreCADOption(self, optionName, optionValue):
265 self.Parameters().AddPreCADOption(optionName,optionValue)
268 ## Sets GMF file for export at computation
269 # @param fileName GMF file name
270 def SetGMFFile(self, fileName):
271 self.Parameters().SetGMFFile(fileName)
274 #-----------------------------------------
275 # Enforced vertices (BLSURF)
276 #-----------------------------------------
278 ## To get all the enforced vertices
279 def GetAllEnforcedVertices(self):
280 return self.Parameters().GetAllEnforcedVertices()
282 ## To get all the enforced vertices sorted by face (or group, compound)
283 def GetAllEnforcedVerticesByFace(self):
284 return self.Parameters().GetAllEnforcedVerticesByFace()
286 ## To get all the enforced vertices sorted by coords of input vertices
287 def GetAllEnforcedVerticesByCoords(self):
288 return self.Parameters().GetAllEnforcedVerticesByCoords()
290 ## To get all the coords of input vertices sorted by face (or group, compound)
291 def GetAllCoordsByFace(self):
292 return self.Parameters().GetAllCoordsByFace()
294 ## To get all the enforced vertices on a face (or group, compound)
295 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
296 def GetEnforcedVertices(self, theFace):
297 from salome.smesh.smeshBuilder import AssureGeomPublished
298 AssureGeomPublished( self.mesh, theFace )
299 return self.Parameters().GetEnforcedVertices(theFace)
301 ## To clear all the enforced vertices
302 def ClearAllEnforcedVertices(self):
303 return self.Parameters().ClearAllEnforcedVertices()
305 ## 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.
306 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
307 # @param x : x coordinate
308 # @param y : y coordinate
309 # @param z : z coordinate
310 # @param vertexName : name of the enforced vertex
311 # @param groupName : name of the group
312 def SetEnforcedVertex(self, theFace, x, y, z, vertexName = "", groupName = ""):
313 from salome.smesh.smeshBuilder import AssureGeomPublished
314 AssureGeomPublished( self.mesh, theFace )
317 return self.Parameters().SetEnforcedVertex(theFace, x, y, z)
319 return self.Parameters().SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
323 return self.Parameters().SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
325 return self.Parameters().SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
329 ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
330 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
331 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
332 # @param groupName : name of the group
333 def SetEnforcedVertexGeom(self, theFace, theVertex, groupName = ""):
334 from salome.smesh.smeshBuilder import AssureGeomPublished
335 AssureGeomPublished( self.mesh, theFace )
336 AssureGeomPublished( self.mesh, theVertex )
338 return self.Parameters().SetEnforcedVertexGeom(theFace, theVertex)
340 return self.Parameters().SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
343 ## To remove an enforced vertex on a given GEOM face (or group, compound) given the coordinates.
344 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
345 # @param x : x coordinate
346 # @param y : y coordinate
347 # @param z : z coordinate
348 def UnsetEnforcedVertex(self, theFace, x, y, z):
349 from salome.smesh.smeshBuilder import AssureGeomPublished
350 AssureGeomPublished( self.mesh, theFace )
351 return self.Parameters().UnsetEnforcedVertex(theFace, x, y, z)
353 ## To remove an enforced vertex on a given GEOM face (or group, compound) given a GEOM vertex, group or compound.
354 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
355 # @param theVertex : GEOM vertex (or group, compound) to remove.
356 def UnsetEnforcedVertexGeom(self, theFace, theVertex):
357 from salome.smesh.smeshBuilder import AssureGeomPublished
358 AssureGeomPublished( self.mesh, theFace )
359 AssureGeomPublished( self.mesh, theVertex )
360 return self.Parameters().UnsetEnforcedVertexGeom(theFace, theVertex)
362 ## To remove all enforced vertices on a given face.
363 # @param theFace : face (or group/compound of faces) on which to remove all enforced vertices
364 def UnsetEnforcedVertices(self, theFace):
365 from salome.smesh.smeshBuilder import AssureGeomPublished
366 AssureGeomPublished( self.mesh, theFace )
367 return self.Parameters().UnsetEnforcedVertices(theFace)
369 ## To tell BLSURF to add a node on internal vertices
370 # @param toEnforceInternalVertices : boolean; if True the internal vertices are added as enforced vertices
371 def SetInternalEnforcedVertexAllFaces(self, toEnforceInternalVertices):
372 return self.Parameters().SetInternalEnforcedVertexAllFaces(toEnforceInternalVertices)
374 ## To know if BLSURF will add a node on internal vertices
375 def GetInternalEnforcedVertexAllFaces(self):
376 return self.Parameters().GetInternalEnforcedVertexAllFaces()
378 ## To define a group for the nodes of internal vertices
379 # @param groupName : string; name of the group
380 def SetInternalEnforcedVertexAllFacesGroup(self, groupName):
381 return self.Parameters().SetInternalEnforcedVertexAllFacesGroup(groupName)
383 ## To get the group name of the nodes of internal vertices
384 def GetInternalEnforcedVertexAllFacesGroup(self):
385 return self.Parameters().GetInternalEnforcedVertexAllFacesGroup()
387 #-----------------------------------------
389 #-----------------------------------------
391 ## 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 ]
392 # @param theFace : face on which the attractor will be defined
393 # @param theAttractor : geometrical object from which the mesh size "h" decreases exponentially
394 # @param theStartSize : mesh size on theAttractor
395 # @param theEndSize : maximum size that will be reached on theFace
396 # @param theInfluenceDistance : influence of the attractor ( the size grow slower on theFace if it's high)
397 # @param theConstantSizeDistance : distance until which the mesh size will be kept constant on theFace
398 def SetAttractorGeom(self, theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance):
399 from salome.smesh.smeshBuilder import AssureGeomPublished
400 AssureGeomPublished( self.mesh, theFace )
401 AssureGeomPublished( self.mesh, theAttractor )
402 self.Parameters().SetAttractorGeom(theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance)
405 ## Unsets an attractor on the chosen face.
406 # @param theFace : face on which the attractor has to be removed
407 def UnsetAttractorGeom(self, theFace):
408 from salome.smesh.smeshBuilder import AssureGeomPublished
409 AssureGeomPublished( self.mesh, theFace )
410 self.Parameters().SetAttractorGeom(theFace)
413 #-----------------------------------------
415 #-----------------------------------------
417 ## To set a size map on a face, edge or vertex (or group, compound) given Python function.
418 # If theObject is a face, the function can be: def f(u,v): return u+v
419 # If theObject is an edge, the function can be: def f(t): return t/2
420 # If theObject is a vertex, the function can be: def f(): return 10
421 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
422 # @param theSizeMap : Size map defined as a string
423 def SetSizeMap(self, theObject, theSizeMap):
424 from salome.smesh.smeshBuilder import AssureGeomPublished
425 AssureGeomPublished( self.mesh, theObject )
426 self.Parameters().SetSizeMap(theObject, theSizeMap)
429 ## To set a constant size map on a face, edge or vertex (or group, compound).
430 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
431 # @param theSizeMap : Size map defined as a double
432 def SetConstantSizeMap(self, theObject, theSizeMap):
433 from salome.smesh.smeshBuilder import AssureGeomPublished
434 AssureGeomPublished( self.mesh, theObject )
435 self.Parameters().SetConstantSizeMap(theObject, theSizeMap)
437 ## To remove a size map defined on a face, edge or vertex (or group, compound)
438 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
439 def UnsetSizeMap(self, theObject):
440 from salome.smesh.smeshBuilder import AssureGeomPublished
441 AssureGeomPublished( self.mesh, theObject )
442 self.Parameters().UnsetSizeMap(theObject)
445 ## To remove all the size maps
446 def ClearSizeMaps(self):
447 self.Parameters().ClearSizeMaps()
450 ## Sets QuadAllowed flag.
451 # @param toAllow "allow quadrangles" flag value
452 def SetQuadAllowed(self, toAllow=True):
453 self.Parameters().SetQuadAllowed(toAllow)
456 ## Defines hypothesis having several parameters
457 # @return hypothesis object
458 def Parameters(self):
460 self.params = self.Hypothesis("MG-CADSurf Parameters", [],
461 LIBRARY, UseExisting=0)
465 #-----------------------------------------
466 # Periodicity (BLSURF with PreCAD)
467 #-----------------------------------------
469 ## Defines periodicity between two groups of faces, using PreCAD
470 # @param theFace1 : GEOM face (or group, compound) to associate with theFace2
471 # @param theFace2 : GEOM face (or group, compound) associated with theFace1
472 # @param theSourceVertices (optionnal): list of GEOM vertices on theFace1 defining the transformation from theFace1 to theFace2.
473 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
474 # @param theTargetVertices (optionnal): list of GEOM vertices on theFace2 defining the transformation from theFace1 to theFace2.
475 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
476 def AddPreCadFacesPeriodicity(self, theFace1, theFace2, theSourceVertices=[], theTargetVertices=[]):
477 """calls preCad function:
478 status_t cad_add_face_multiple_periodicity_with_transformation_function(cad t *cad,
479 integer *fid1, integer size1, integer *fid2, integer size2,
480 periodicity_transformation_t transf, void *user data);
482 if theSourceVertices and theTargetVertices:
483 self.Parameters().AddPreCadFacesPeriodicityWithVertices(theFace1, theFace2, theSourceVertices, theTargetVertices)
485 self.Parameters().AddPreCadFacesPeriodicity(theFace1, theFace2)
488 ## Defines periodicity between two groups of edges, using PreCAD
489 # @param theEdge1 : GEOM edge (or group, compound) to associate with theEdge2
490 # @param theEdge2 : GEOM edge (or group, compound) associated with theEdge1
491 # @param theSourceVertices (optionnal): list of GEOM vertices on theEdge1 defining the transformation from theEdge1 to theEdge2.
492 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
493 # @param theTargetVertices (optionnal): list of GEOM vertices on theEdge2 defining the transformation from theEdge1 to theEdge2.
494 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
495 def AddPreCadEdgesPeriodicity(self, theEdge1, theEdge2, theSourceVertices=[], theTargetVertices=[]):
496 """calls preCad function:
497 status_t cad_add_edge_multiple_periodicity_with_transformation_function(cad t *cad,
498 integer *eid1, integer size1, integer *eid2, integer size2,
499 periodicity_transformation_t transf, void *user data);
501 if theSourceVertices and theTargetVertices:
502 self.Parameters().AddPreCadEdgesPeriodicityWithVertices(theEdge1, theEdge2, theSourceVertices, theTargetVertices)
504 self.Parameters().AddPreCadEdgesPeriodicity(theEdge1, theEdge2)
507 #=====================
509 #=====================
514 ## Sets lower boundary of mesh element size (PhySize).
515 def SetPhyMin(self, theVal=-1):
517 Obsolete function. Use SetMinSize.
519 print "Warning: SetPhyMin is obsolete. Please use SetMinSize"
520 self.SetMinSize(theVal)
523 ## Sets upper boundary of mesh element size (PhySize).
524 def SetPhyMax(self, theVal=-1):
526 Obsolete function. Use SetMaxSize.
528 print "Warning: SetPhyMax is obsolete. Please use SetMaxSize"
529 self.SetMaxSize(theVal)
532 ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
533 def SetAngleMeshS(self, theVal=_geometric_approximation):
535 Obsolete function. Use SetAngleMesh.
537 print "Warning: SetAngleMeshS is obsolete. Please use SetAngleMesh"
538 self.SetAngleMesh(theVal)
541 ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
542 def SetAngleMeshC(self, theVal=_geometric_approximation):
544 Obsolete function. Use SetAngleMesh.
546 print "Warning: SetAngleMeshC is obsolete. Please use SetAngleMesh"
547 self.SetAngleMesh(theVal)
550 ## Sets lower boundary of mesh element size computed to respect angular deflection.
551 def SetGeoMin(self, theVal=-1):
553 Obsolete function. Use SetMinSize.
555 print "Warning: SetGeoMin is obsolete. Please use SetMinSize"
556 self.SetMinSize(theVal)
559 ## Sets upper boundary of mesh element size computed to respect angular deflection.
560 def SetGeoMax(self, theVal=-1):
562 Obsolete function. Use SetMaxSize.
564 print "Warning: SetGeoMax is obsolete. Please use SetMaxSize"
565 self.SetMaxSize(theVal)
569 pass # end of BLSURF_Algorithm class