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 if self.Parameters().GetTopology() != PreCAD:
198 self.SetTopology(PreCAD)
199 self.Parameters().SetPreCADMergeEdges(toMergeEdges)
202 ## To remove duplicate CAD Faces
203 # @param toRemoveDuplicateCADFaces "merge edges" flag value
204 def SetPreCADRemoveDuplicateCADFaces(self, toRemoveDuplicateCADFaces=False):
205 if self.Parameters().GetTopology() != PreCAD:
206 self.SetTopology(PreCAD)
207 self.Parameters().SetPreCADRemoveDuplicateCADFaces(toRemoveDuplicateCADFaces)
210 ## To process 3D topology.
211 # @param toProcess "PreCAD process 3D" flag value
212 def SetPreCADProcess3DTopology(self, toProcess=False):
213 if self.Parameters().GetTopology() != PreCAD:
214 self.SetTopology(PreCAD)
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 if self.Parameters().GetTopology() != PreCAD:
231 self.SetTopology(PreCAD)
232 self.Parameters().SetPreCADDiscardInput(toDiscardInput)
235 ## Sets the length below which an edge is considered as nano
236 # for the topology processing.
237 # @param epsNano nano edge length threshold value
238 def SetPreCADEpsNano(self, epsNano):
239 self.SetPreCADOptionValue("tiny_edge_length","%f"%epsNano)
242 ## Sets advanced option value.
243 # @param optionName advanced option name
244 # @param level advanced option value
245 def SetOptionValue(self, optionName, level):
246 self.Parameters().SetOptionValue(optionName,level)
249 ## Sets advanced PreCAD option value.
250 # @param optionName name of the option
251 # @param optionValue value of the option
252 def SetPreCADOptionValue(self, optionName, optionValue):
253 if self.Parameters().GetTopology() != PreCAD:
254 self.SetTopology(PreCAD)
255 self.Parameters().SetPreCADOptionValue(optionName,optionValue)
258 ## Adds custom advanced option value.
259 # @param optionName custom advanced option name
260 # @param level custom advanced option value
261 def AddOption(self, optionName, level):
262 self.Parameters().AddOption(optionName,level)
265 ## Adds custom advanced PreCAD option value.
266 # @param optionName custom name of the option
267 # @param optionValue value of the option
268 def AddPreCADOption(self, optionName, optionValue):
269 if self.Parameters().GetTopology() != PreCAD:
270 self.SetTopology(PreCAD)
271 self.Parameters().AddPreCADOption(optionName,optionValue)
274 ## Sets GMF file for export at computation
275 # @param fileName GMF file name
276 def SetGMFFile(self, fileName):
277 self.Parameters().SetGMFFile(fileName)
280 #-----------------------------------------
281 # Enforced vertices (BLSURF)
282 #-----------------------------------------
284 ## To get all the enforced vertices
285 def GetAllEnforcedVertices(self):
286 return self.Parameters().GetAllEnforcedVertices()
288 ## To get all the enforced vertices sorted by face (or group, compound)
289 def GetAllEnforcedVerticesByFace(self):
290 return self.Parameters().GetAllEnforcedVerticesByFace()
292 ## To get all the enforced vertices sorted by coords of input vertices
293 def GetAllEnforcedVerticesByCoords(self):
294 return self.Parameters().GetAllEnforcedVerticesByCoords()
296 ## To get all the coords of input vertices sorted by face (or group, compound)
297 def GetAllCoordsByFace(self):
298 return self.Parameters().GetAllCoordsByFace()
300 ## To get all the enforced vertices on a face (or group, compound)
301 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
302 def GetEnforcedVertices(self, theFace):
303 from salome.smesh.smeshBuilder import AssureGeomPublished
304 AssureGeomPublished( self.mesh, theFace )
305 return self.Parameters().GetEnforcedVertices(theFace)
307 ## To clear all the enforced vertices
308 def ClearAllEnforcedVertices(self):
309 return self.Parameters().ClearAllEnforcedVertices()
311 ## 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.
312 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
313 # @param x : x coordinate
314 # @param y : y coordinate
315 # @param z : z coordinate
316 # @param vertexName : name of the enforced vertex
317 # @param groupName : name of the group
318 def SetEnforcedVertex(self, theFace, x, y, z, vertexName = "", groupName = ""):
319 from salome.smesh.smeshBuilder import AssureGeomPublished
320 AssureGeomPublished( self.mesh, theFace )
323 return self.Parameters().SetEnforcedVertex(theFace, x, y, z)
325 return self.Parameters().SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
329 return self.Parameters().SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
331 return self.Parameters().SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
335 ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
336 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
337 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
338 # @param groupName : name of the group
339 def SetEnforcedVertexGeom(self, theFace, theVertex, groupName = ""):
340 from salome.smesh.smeshBuilder import AssureGeomPublished
341 AssureGeomPublished( self.mesh, theFace )
342 AssureGeomPublished( self.mesh, theVertex )
344 return self.Parameters().SetEnforcedVertexGeom(theFace, theVertex)
346 return self.Parameters().SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
349 ## To remove an enforced vertex on a given GEOM face (or group, compound) given the coordinates.
350 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
351 # @param x : x coordinate
352 # @param y : y coordinate
353 # @param z : z coordinate
354 def UnsetEnforcedVertex(self, theFace, x, y, z):
355 from salome.smesh.smeshBuilder import AssureGeomPublished
356 AssureGeomPublished( self.mesh, theFace )
357 return self.Parameters().UnsetEnforcedVertex(theFace, x, y, z)
359 ## To remove an enforced vertex on a given GEOM face (or group, compound) given a GEOM vertex, group or compound.
360 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
361 # @param theVertex : GEOM vertex (or group, compound) to remove.
362 def UnsetEnforcedVertexGeom(self, theFace, theVertex):
363 from salome.smesh.smeshBuilder import AssureGeomPublished
364 AssureGeomPublished( self.mesh, theFace )
365 AssureGeomPublished( self.mesh, theVertex )
366 return self.Parameters().UnsetEnforcedVertexGeom(theFace, theVertex)
368 ## To remove all enforced vertices on a given face.
369 # @param theFace : face (or group/compound of faces) on which to remove all enforced vertices
370 def UnsetEnforcedVertices(self, theFace):
371 from salome.smesh.smeshBuilder import AssureGeomPublished
372 AssureGeomPublished( self.mesh, theFace )
373 return self.Parameters().UnsetEnforcedVertices(theFace)
375 ## To tell BLSURF to add a node on internal vertices
376 # @param toEnforceInternalVertices : boolean; if True the internal vertices are added as enforced vertices
377 def SetInternalEnforcedVertexAllFaces(self, toEnforceInternalVertices):
378 return self.Parameters().SetInternalEnforcedVertexAllFaces(toEnforceInternalVertices)
380 ## To know if BLSURF will add a node on internal vertices
381 def GetInternalEnforcedVertexAllFaces(self):
382 return self.Parameters().GetInternalEnforcedVertexAllFaces()
384 ## To define a group for the nodes of internal vertices
385 # @param groupName : string; name of the group
386 def SetInternalEnforcedVertexAllFacesGroup(self, groupName):
387 return self.Parameters().SetInternalEnforcedVertexAllFacesGroup(groupName)
389 ## To get the group name of the nodes of internal vertices
390 def GetInternalEnforcedVertexAllFacesGroup(self):
391 return self.Parameters().GetInternalEnforcedVertexAllFacesGroup()
393 #-----------------------------------------
395 #-----------------------------------------
397 ## 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 ]
398 # @param theFace : face on which the attractor will be defined
399 # @param theAttractor : geometrical object from which the mesh size "h" decreases exponentially
400 # @param theStartSize : mesh size on theAttractor
401 # @param theEndSize : maximum size that will be reached on theFace
402 # @param theInfluenceDistance : influence of the attractor ( the size grow slower on theFace if it's high)
403 # @param theConstantSizeDistance : distance until which the mesh size will be kept constant on theFace
404 def SetAttractorGeom(self, theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance):
405 from salome.smesh.smeshBuilder import AssureGeomPublished
406 AssureGeomPublished( self.mesh, theFace )
407 AssureGeomPublished( self.mesh, theAttractor )
408 self.Parameters().SetAttractorGeom(theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance)
411 ## Unsets an attractor on the chosen face.
412 # @param theFace : face on which the attractor has to be removed
413 def UnsetAttractorGeom(self, theFace):
414 from salome.smesh.smeshBuilder import AssureGeomPublished
415 AssureGeomPublished( self.mesh, theFace )
416 self.Parameters().SetAttractorGeom(theFace)
419 #-----------------------------------------
421 #-----------------------------------------
423 ## To set a size map on a face, edge or vertex (or group, compound) given Python function.
424 # If theObject is a face, the function can be: def f(u,v): return u+v
425 # If theObject is an edge, the function can be: def f(t): return t/2
426 # If theObject is a vertex, the function can be: def f(): return 10
427 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
428 # @param theSizeMap : Size map defined as a string
429 def SetSizeMap(self, theObject, theSizeMap):
430 from salome.smesh.smeshBuilder import AssureGeomPublished
431 AssureGeomPublished( self.mesh, theObject )
432 self.Parameters().SetSizeMap(theObject, theSizeMap)
435 ## To set a constant size map on a face, edge or vertex (or group, compound).
436 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
437 # @param theSizeMap : Size map defined as a double
438 def SetConstantSizeMap(self, theObject, theSizeMap):
439 from salome.smesh.smeshBuilder import AssureGeomPublished
440 AssureGeomPublished( self.mesh, theObject )
441 self.Parameters().SetConstantSizeMap(theObject, theSizeMap)
443 ## To remove a size map defined on a face, edge or vertex (or group, compound)
444 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
445 def UnsetSizeMap(self, theObject):
446 from salome.smesh.smeshBuilder import AssureGeomPublished
447 AssureGeomPublished( self.mesh, theObject )
448 self.Parameters().UnsetSizeMap(theObject)
451 ## To remove all the size maps
452 def ClearSizeMaps(self):
453 self.Parameters().ClearSizeMaps()
456 ## Sets QuadAllowed flag.
457 # @param toAllow "allow quadrangles" flag value
458 def SetQuadAllowed(self, toAllow=True):
459 self.Parameters().SetQuadAllowed(toAllow)
462 ## Defines hypothesis having several parameters
463 # @return hypothesis object
464 def Parameters(self):
466 self.params = self.Hypothesis("MG-CADSurf Parameters", [],
467 LIBRARY, UseExisting=0)
471 #-----------------------------------------
472 # Periodicity (BLSURF with PreCAD)
473 #-----------------------------------------
475 ## Defines periodicity between two groups of faces, using PreCAD
476 # @param theFace1 : GEOM face (or group, compound) to associate with theFace2
477 # @param theFace2 : GEOM face (or group, compound) associated with theFace1
478 # @param theSourceVertices (optionnal): list of GEOM vertices on theFace1 defining the transformation from theFace1 to theFace2.
479 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
480 # @param theTargetVertices (optionnal): list of GEOM vertices on theFace2 defining the transformation from theFace1 to theFace2.
481 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
482 def AddPreCadFacesPeriodicity(self, theFace1, theFace2, theSourceVertices=[], theTargetVertices=[]):
483 """calls preCad function:
484 status_t cad_add_face_multiple_periodicity_with_transformation_function(cad t *cad,
485 integer *fid1, integer size1, integer *fid2, integer size2,
486 periodicity_transformation_t transf, void *user data);
488 if theSourceVertices and theTargetVertices:
489 self.Parameters().AddPreCadFacesPeriodicityWithVertices(theFace1, theFace2, theSourceVertices, theTargetVertices)
491 self.Parameters().AddPreCadFacesPeriodicity(theFace1, theFace2)
494 ## Defines periodicity between two groups of edges, using PreCAD
495 # @param theEdge1 : GEOM edge (or group, compound) to associate with theEdge2
496 # @param theEdge2 : GEOM edge (or group, compound) associated with theEdge1
497 # @param theSourceVertices (optionnal): list of GEOM vertices on theEdge1 defining the transformation from theEdge1 to theEdge2.
498 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
499 # @param theTargetVertices (optionnal): list of GEOM vertices on theEdge2 defining the transformation from theEdge1 to theEdge2.
500 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
501 def AddPreCadEdgesPeriodicity(self, theEdge1, theEdge2, theSourceVertices=[], theTargetVertices=[]):
502 """calls preCad function:
503 status_t cad_add_edge_multiple_periodicity_with_transformation_function(cad t *cad,
504 integer *eid1, integer size1, integer *eid2, integer size2,
505 periodicity_transformation_t transf, void *user data);
507 if theSourceVertices and theTargetVertices:
508 self.Parameters().AddPreCadEdgesPeriodicityWithVertices(theEdge1, theEdge2, theSourceVertices, theTargetVertices)
510 self.Parameters().AddPreCadEdgesPeriodicity(theEdge1, theEdge2)
513 #=====================
515 #=====================
520 ## Sets lower boundary of mesh element size (PhySize).
521 def SetPhyMin(self, theVal=-1):
523 Obsolete function. Use SetMinSize.
525 print "Warning: SetPhyMin is obsolete. Please use SetMinSize"
526 self.SetMinSize(theVal)
529 ## Sets upper boundary of mesh element size (PhySize).
530 def SetPhyMax(self, theVal=-1):
532 Obsolete function. Use SetMaxSize.
534 print "Warning: SetPhyMax is obsolete. Please use SetMaxSize"
535 self.SetMaxSize(theVal)
538 ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
539 def SetAngleMeshS(self, theVal=_geometric_approximation):
541 Obsolete function. Use SetAngleMesh.
543 print "Warning: SetAngleMeshS is obsolete. Please use SetAngleMesh"
544 self.SetAngleMesh(theVal)
547 ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
548 def SetAngleMeshC(self, theVal=_geometric_approximation):
550 Obsolete function. Use SetAngleMesh.
552 print "Warning: SetAngleMeshC is obsolete. Please use SetAngleMesh"
553 self.SetAngleMesh(theVal)
556 ## Sets lower boundary of mesh element size computed to respect angular deflection.
557 def SetGeoMin(self, theVal=-1):
559 Obsolete function. Use SetMinSize.
561 print "Warning: SetGeoMin is obsolete. Please use SetMinSize"
562 self.SetMinSize(theVal)
565 ## Sets upper boundary of mesh element size computed to respect angular deflection.
566 def SetGeoMax(self, theVal=-1):
568 Obsolete function. Use SetMaxSize.
570 print "Warning: SetGeoMax is obsolete. Please use SetMaxSize"
571 self.SetMaxSize(theVal)
575 pass # end of BLSURF_Algorithm class