1 # Copyright (C) 2007-2019 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
27 LIBRARY = "libBLSURFEngine.so"
30 Triangles, QuadrangleDominant, Quadrangles = 0, 1, 2
32 # Topology treatment way of MG-CADSurf
33 FromCAD, PreProcess, PreProcessPlus, PreCAD = 0,1,2,3
35 # Element size flag of MG-CADSurf
36 DefaultSize, DefaultGeom, MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize = 0,0,1,2
38 MG_CADSURF_Custom, SizeMap = MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize
39 BLSURF_Custom, BLSURF_GlobalSize, BLSURF_LocalSize = MG_CADSURF_Custom, MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize
41 # import BLSURFPlugin module if possible
49 #----------------------------
50 # Mesh algo type identifiers
51 #----------------------------
53 ## Algorithm type: MG-CADSurf triangle algorithm, see BLSURF_Algorithm
54 MG_CADSurf = "MG-CADSurf"
57 #----------------------
59 #----------------------
61 ## MG-CADSurf 2D algorithm.
63 # It can be created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MG-CADSurf,geom=0)
65 class BLSURF_Algorithm(Mesh_Algorithm):
67 ## name of the dynamic method in smeshBuilder.Mesh class
69 meshMethod = "Triangle"
70 ## type of algorithm used with helper function in smeshBuilder.Mesh class
73 ## doc string of the method
75 docHelper = "Creates triangle algorithm for faces"
77 _anisotropic_ratio = 0
78 _bad_surface_element_aspect_ratio = 1000
79 _geometric_approximation = 22
83 _remove_tiny_edges = 0
85 ## Private constructor.
86 # @param mesh parent mesh object algorithm is assigned to
87 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
88 # if it is @c 0 (default), the algorithm is assigned to the main shape
89 def __init__(self, mesh, geom=0):
90 Mesh_Algorithm.__init__(self)
92 print("Warning: BLSURFPlugin module unavailable")
93 if mesh.GetMesh().HasShapeToMesh():
94 self.Create(mesh, geom, self.algoType, LIBRARY)
96 self.Create(mesh, geom, self.algoType+"_NOGEOM", LIBRARY)
97 mesh.smeshpyD.SetName( self.algo, self.algoType )
99 self.geompyD = mesh.geompyD
100 #self.SetPhysicalMesh() - PAL19680
103 ## Sets a way to define size of mesh elements to generate.
104 # @param thePhysicalMesh is: DefaultSize, MG_CADSURF_Custom or SizeMap.
105 def SetPhysicalMesh(self, thePhysicalMesh=DefaultSize):
106 physical_size_mode = thePhysicalMesh
107 if self.Parameters().GetGeometricMesh() == DefaultGeom:
108 if physical_size_mode == DefaultSize:
109 physical_size_mode = MG_CADSURF_GlobalSize
110 self.Parameters().SetPhysicalMesh(physical_size_mode)
113 ## Sets a way to define maximum angular deflection of mesh from CAD model.
114 # @param theGeometricMesh is: DefaultGeom (0)) or MG_CADSURF_GlobalSize (1))
115 def SetGeometricMesh(self, theGeometricMesh=DefaultGeom):
116 geometric_size_mode = theGeometricMesh
117 if self.Parameters().GetPhysicalMesh() == DefaultSize:
118 if geometric_size_mode == DefaultGeom:
119 geometric_size_mode = MG_CADSURF_GlobalSize
120 self.Parameters().SetGeometricMesh(geometric_size_mode)
123 ## Sets size of mesh elements to generate.
124 # @param theVal : constant global size when using a global physical size.
125 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
126 def SetPhySize(self, theVal, isRelative = False):
127 if self.Parameters().GetPhysicalMesh() == DefaultSize:
128 self.SetPhysicalMesh(MG_CADSURF_GlobalSize)
130 self.Parameters().SetPhySizeRel(theVal)
132 self.Parameters().SetPhySize(theVal)
135 ## Sets lower boundary of mesh element size.
136 # @param theVal : global minimal cell size desired.
137 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
138 def SetMinSize(self, theVal=-1, isRelative = False):
140 self.Parameters().SetMinSizeRel(theVal)
142 self.Parameters().SetMinSize(theVal)
145 ## Sets upper boundary of mesh element size.
146 # @param theVal : global maximal cell size desired.
147 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
148 def SetMaxSize(self, theVal=-1, isRelative = False):
150 self.Parameters().SetMaxSizeRel(theVal)
152 self.Parameters().SetMaxSize(theVal)
155 ## Sets angular deflection (in degrees) from CAD surface.
156 # @param theVal value of angular deflection
157 def SetAngleMesh(self, theVal=_geometric_approximation):
158 if self.Parameters().GetGeometricMesh() == DefaultGeom:
159 self.SetGeometricMesh(MG_CADSURF_GlobalSize)
160 self.Parameters().SetAngleMesh(theVal)
163 ## Sets the maximum desired distance between a triangle and its supporting CAD surface
164 # @param distance the distance between a triangle and a surface
165 def SetChordalError(self, distance):
166 self.Parameters().SetChordalError(distance)
169 ## Sets maximal allowed ratio between the lengths of two adjacent edges.
170 # @param toUseGradation to use gradation
171 # @param theVal value of maximal length ratio
172 def SetGradation(self, toUseGradation=True, theVal=_gradation):
173 if isinstance( toUseGradation, float ): ## backward compatibility
174 toUseGradation, theVal = True, toUseGradation
175 if self.Parameters().GetGeometricMesh() == 0: theVal = self._gradation
176 self.Parameters().SetUseGradation(toUseGradation)
177 self.Parameters().SetGradation(theVal)
180 ## Sets maximal allowed ratio between the lengths of two adjacent edges in 3D mesh.
181 # @param toUseGradation to use gradation
182 # @param theVal value of maximal length ratio
183 def SetVolumeGradation(self, toUseGradation=True, theVal=_gradation):
184 if self.Parameters().GetGeometricMesh() == 0: theVal = self._volume_gradation
185 self.Parameters().SetUseVolumeGradation(toUseGradation)
186 self.Parameters().SetVolumeGradation(theVal)
189 ## Sets topology usage way.
190 # @param way defines how mesh conformity is assured <ul>
191 # <li>FromCAD - mesh conformity is assured by conformity of a shape</li>
192 # <li>PreProcess or PreProcessPlus - by pre-processing a CAD model (OBSOLETE: FromCAD will be used)</li>
193 # <li>PreCAD - by pre-processing with PreCAD a CAD model</li></ul>
194 def SetTopology(self, way):
195 if way != PreCAD and way != FromCAD:
196 print("Warning: topology mode %d is no longer supported. Mode FromCAD is used."%way)
198 self.Parameters().SetTopology(way)
201 ## Activate/deactivate surface proximity computation
202 # @param toUse boolean flag
204 def SetSurfaceProximity(self, toUse ):
205 self.Parameters().SetSurfaceProximity(toUse)
208 ## Set number of surface element layers to be generated due to surface proximity
209 # @param nbLayers number of layers
211 def SetNbSurfaceProximityLayers(self, nbLayers ):
212 self.Parameters().SetNbSurfaceProximityLayers( nbLayers )
215 ## Set coefficient by which size of element refined due to surface proximity is increased
216 # @param ratio proximity coefficient
218 def SetSurfaceProximityRatio(self, ratio ):
219 self.Parameters().SetSurfaceProximityRatio(ratio)
222 ## Activate/deactivate volume proximity computation
223 # @param toUse boolean flag
225 def SetVolumeProximity(self, toUse ):
226 self.Parameters().SetVolumeProximity(toUse)
229 ## Set number of surface element layers to be generated due to volume proximity
230 # @param nbLayers number of layers
232 def SetNbVolumeProximityLayers(self, nbLayers ):
233 self.Parameters().SetNbVolumeProximityLayers(nbLayers)
236 ## Set coefficient by which size of element refined due to volume proximity is increased
237 # @param ratio proximity coefficient
239 def SetVolumeProximityRatio(self, ratio ):
240 self.Parameters().SetVolumeProximityRatio(ratio)
244 ## Sets verbosity level in the range 0 to 100.
245 # @param level verbosity level
246 def SetVerbosity(self, level):
247 self.Parameters().SetVerbosity(level)
250 ## Set enforce_cad_edge_sizes parameter
252 # Relaxes the given sizemap constraint around CAD edges to allow a better
253 # element quality and a better geometric approximation. It is only useful in
254 # combination with the gradation option.
256 def SetEnforceCadEdgesSize( self, toEnforce ):
257 if not version_less(self.Parameters().GetMeshGemsVersion(), '2.10'):
258 print("Warning: method SetEnforceCadEdgesSize() is deprecated")
259 self.Parameters().SetEnforceCadEdgesSize( toEnforce )
261 ## Set jacobian_rectification_respect_geometry parameter
263 # While making the mesh quadratic, allows to lose the CAD-mesh associativity in order
264 # to correct elements with nagative Jacobian
266 def SetJacobianRectificationRespectGeometry( self, allowRectification ):
267 self.Parameters().SetJacobianRectificationRespectGeometry( allowRectification )
269 ## Set rectify_jacobian parameter
271 # While making the mesh quadratic, allow to fix nagative Jacobian surface elements
273 def SetJacobianRectification( self, allowRectification ):
274 self.Parameters().SetJacobianRectification( allowRectification )
276 ## Set use_deprecated_patch_mesher parameter (compatibility with older versions of Meshgems)
278 # the use_deprecated_patch_mesher parameter allows to keep the same behaviour than
279 # in salome < 8.3 (meshgems 2.1.11 instead of meshgems >= 2.4.5)
281 def SetUseDeprecatedPatchMesher( self, useDeprecatedPatchMesher ):
282 self.Parameters().SetUseDeprecatedPatchMesher( useDeprecatedPatchMesher )
284 ## Set respect_geometry parameter
286 # This patch independent option can be deactivated to allow MeshGems-CADSurf
287 # to lower the geometry accuracy in its patch independent process.
289 def SetRespectGeometry( self, toRespect ):
290 self.Parameters().SetRespectGeometry( toRespect )
292 ## Set max_number_of_points_per_patch parameter
294 # This parameter controls the maximum amount of points MeshGems-CADSurf is allowed
295 # to generate on a single CAD patch. For an automatic gestion of the memory, one
296 # can set this parameter to 0
298 def SetMaxNumberOfPointsPerPatch( self, nb ):
299 if not version_less(self.Parameters().GetMeshGemsVersion(), '2.10'):
300 print("Warning: method SetMaxNumberOfPointsPerPatch() is deprecated")
301 self.Parameters().SetMaxNumberOfPointsPerPatch( nb )
303 ## Set max_number_of_threads parameter
305 # Set the maximum of threads to use for multithreading mesh computation
307 def SetMaxNumberOfThreads( self, nb ):
308 self.Parameters().SetMaxNumberOfThreads( nb )
310 ## Set respect_geometry parameter
312 # This patch independent option can be deactivated to allow MeshGems-CADSurf
313 # to lower the geometry accuracy in its patch independent process.
315 def SetRespectGeometry( self, toRespect ):
316 self.Parameters().SetRespectGeometry( toRespect )
318 ## Set tiny_edges_avoid_surface_intersections parameter
320 # This option defines the priority between the tiny feature
321 # suppression and the surface intersection prevention.
323 def SetTinyEdgesAvoidSurfaceIntersections( self, toAvoidIntersection ):
324 self.Parameters().SetTinyEdgesAvoidSurfaceIntersections( toAvoidIntersection )
326 ## Set closed_geometry parameter parameter
328 # Describes whether the geometry is expected to be closed or not.
329 # When activated, this option helps MeshGems-PreCAD to treat the dirtiest geometries.
331 def SetClosedGeometry( self, isClosed ):
332 self.Parameters().SetClosedGeometry( isClosed )
334 ## Set debug parameter
336 # Make MeshGems-CADSurf will be very verbose and will output some intermediate
337 # files in the working directory. This option is mainly meant for Distene support issues.
339 def SetDebug( self, isDebug ):
340 self.Parameters().SetDebug( isDebug )
342 ## Set periodic_tolerance parameter
344 # This parameter defines the maximum size difference between two periodic edges
345 # and also the maximum distance error between two periodic entities.
347 def SetPeriodicTolerance( self, tol ):
348 self.Parameters().SetPeriodicTolerance( tol )
350 ## Set required_entities parameter
352 # The required entities control the correction operations.
353 # Accepted values for this parameter are :
354 # - "respect" : MeshGems-CADSurf is not allowed to alter any required entity,
355 # even for correction purposes,
356 # - "ignore" : MeshGems-CADSurf will ignore the required entities in its processing,
357 # - "clear" : MeshGems-CADSurf will clear any required status for the entities.
358 # There will not be any entity marked as required in the generated mesh.
360 def SetRequiredEntities( self, howToTreat ):
361 self.Parameters().SetRequiredEntities( howToTreat )
363 ## Set sewing_tolerance parameter
365 # This parameter is the tolerance of the assembly.
367 def SetSewingTolerance( self, tol ):
368 self.Parameters().SetSewingTolerance( tol )
370 ## Set tags parameter
372 # The tag (attribute) system controls the optimisation process.
373 # Accepted values for this parameter are :
374 # - "respect" : the CAD tags will be preserved and unaltered by the optimisation operations,
375 # - "ignore" : the CAD tags will be ignored by the optimisation operations
376 # but they will still be present in the output mesh,
377 # - "clear" : MeshGems-CADSurf will clear any tag on any entity and optimise accordingly.
378 # There will not be any tag in the generated mesh.
380 def SetTags( self, howToTreat ):
381 self.Parameters().SetTags( howToTreat )
383 ## Activate/deactivate fully patch independent meshing
384 # @param isIndependent boolean flag
386 # This feature can only be used if the @a tags parameter is set to "respect".
387 # By default this option deactivated.
389 def SetPatchIndependent( self, isIndependent ):
390 self.SetOptionValue( "allow_patch_independent", "yes" if isIndependent else "no" )
392 ## Set to preserve lines defined by a sharp angle in the input discrete geometry
393 # @param toCompute boolean flag
395 # If this option is deactivated, MeshGems-CADSurf will not try to preserve lines
396 # defined by a sharp angle in the input discrete geometry. Only input ridges, free
397 # edges, non manifold edges and separation betwen zones with different attributes
398 # will be respected (if tags is set to respect).
399 # By default this option activated.
401 def SetComputeRidges( self, toCompute ):
402 self.SetOptionValue( "compute_ridges", "yes" if toCompute else "no" )
405 ## Activate removal of the tiny edges from the generated
406 # mesh when it improves the local mesh quality, without taking into account the
407 # tags (attributes) specifications.
408 # @param toOptimise "to optimize" flag value
409 # @param length minimal length under which an edge is considered to be a tiny
410 def SetOptimiseTinyEdges(self, toOptimise, length=-1):
411 self.Parameters().SetOptimiseTinyEdges( toOptimise )
413 self.Parameters().SetTinyEdgeOptimisationLength( length )
415 ## Activate correction of all surface intersections
416 # @param toCorrect "to correct" flag value
417 # @param maxCost the time the user is ready to spend in the intersection prevention process
418 # For example, maxCost = 3 means that MeshGems-CADSurf will not spend more time
419 # in the intersection removal process than 3 times the time required to mesh
420 # without processing the intersections.
421 def SetCorrectSurfaceIntersection(self, toCorrect, maxCost ):
422 self.Parameters().SetCorrectSurfaceIntersection( toCorrect )
424 self.Parameters().SetCorrectSurfaceIntersectionMaxCost( maxCost )
426 ## To optimize merges edges.
427 # @param toMergeEdges "merge edges" flag value
428 def SetPreCADMergeEdges(self, toMergeEdges=False):
429 self.Parameters().SetPreCADMergeEdges(toMergeEdges)
432 ## To remove duplicate CAD Faces
433 # @param toRemoveDuplicateCADFaces "remove_duplicate_cad_faces" flag value
434 def SetPreCADRemoveDuplicateCADFaces(self, toRemoveDuplicateCADFaces=False):
435 self.Parameters().SetPreCADRemoveDuplicateCADFaces(toRemoveDuplicateCADFaces)
438 ## To process 3D topology.
439 # @param toProcess "PreCAD process 3D" flag value
440 def SetPreCADProcess3DTopology(self, toProcess=False):
441 self.Parameters().SetPreCADProcess3DTopology(toProcess)
444 ## To remove nano edges.
445 # @param toRemoveNanoEdges "remove nano edges" flag value
446 def SetPreCADRemoveNanoEdges(self, toRemoveNanoEdges=False):
447 if toRemoveNanoEdges:
448 self.SetPreCADOptionValue("remove_tiny_edges","1")
450 self.SetPreCADOptionValue("remove_tiny_edges","0")
453 ## To compute topology from scratch
454 # @param toDiscardInput "discard input" flag value
455 def SetPreCADDiscardInput(self, toDiscardInput=False):
456 self.Parameters().SetPreCADDiscardInput(toDiscardInput)
459 ## Sets the length below which an edge is considered as nano
460 # for the topology processing.
461 # @param epsNano nano edge length threshold value
462 def SetPreCADEpsNano(self, epsNano):
463 self.SetPreCADOptionValue("tiny_edge_length","%f"%epsNano)
466 ## Sets advanced option value.
467 # @param optionName advanced option name
468 # @param level advanced option value
469 def SetOptionValue(self, optionName, level):
470 self.Parameters().SetOptionValue(optionName,level)
473 ## Sets advanced PreCAD option value.
474 # @param optionName name of the option
475 # @param optionValue value of the option
476 def SetPreCADOptionValue(self, optionName, optionValue):
477 self.Parameters().SetPreCADOptionValue(optionName,optionValue)
480 ## Adds custom advanced option values
481 # @param optionsAndValues options and values in a form "option_1 v1 option_2 v2'"
482 def SetAdvancedOption(self, optionsAndValues):
483 self.Parameters().SetAdvancedOption(optionsAndValues)
486 ## Adds custom advanced option value.
487 # @param optionName custom advanced option name
488 # @param level custom advanced option value
489 def AddOption(self, optionName, level):
490 self.Parameters().AddOption(optionName,level)
493 ## Adds custom advanced PreCAD option value.
494 # @param optionName custom name of the option
495 # @param optionValue value of the option
496 def AddPreCADOption(self, optionName, optionValue):
497 self.Parameters().AddPreCADOption(optionName,optionValue)
500 ## Sets GMF file for export at computation
501 # @param fileName GMF file name
502 def SetGMFFile(self, fileName):
503 self.Parameters().SetGMFFile(fileName)
506 #-----------------------------------------
507 # Enforced vertices (BLSURF)
508 #-----------------------------------------
510 ## To get all the enforced vertices
511 def GetAllEnforcedVertices(self):
512 return self.Parameters().GetAllEnforcedVertices()
514 ## To get all the enforced vertices sorted by face (or group, compound)
515 def GetAllEnforcedVerticesByFace(self):
516 return self.Parameters().GetAllEnforcedVerticesByFace()
518 ## To get all the enforced vertices sorted by coords of input vertices
519 def GetAllEnforcedVerticesByCoords(self):
520 return self.Parameters().GetAllEnforcedVerticesByCoords()
522 ## To get all the coords of input vertices sorted by face (or group, compound)
523 def GetAllCoordsByFace(self):
524 return self.Parameters().GetAllCoordsByFace()
526 ## To get all the enforced vertices on a face (or group, compound)
527 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
528 def GetEnforcedVertices(self, theFace):
529 from salome.smesh.smeshBuilder import AssureGeomPublished
530 AssureGeomPublished( self.mesh, theFace )
531 return self.Parameters().GetEnforcedVertices(theFace)
533 ## To clear all the enforced vertices
534 def ClearAllEnforcedVertices(self):
535 return self.Parameters().ClearAllEnforcedVertices()
537 ## 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.
538 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
539 # @param x : x coordinate
540 # @param y : y coordinate
541 # @param z : z coordinate
542 # @param vertexName : name of the enforced vertex
543 # @param groupName : name of the group
544 def SetEnforcedVertex(self, theFace, x, y, z, vertexName = "", groupName = ""):
545 from salome.smesh.smeshBuilder import AssureGeomPublished
546 AssureGeomPublished( self.mesh, theFace )
549 return self.Parameters().SetEnforcedVertex(theFace, x, y, z)
551 return self.Parameters().SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
555 return self.Parameters().SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
557 return self.Parameters().SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
561 ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
562 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
563 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
564 # @param groupName : name of the group
565 def SetEnforcedVertexGeom(self, theFace, theVertex, groupName = ""):
566 from salome.smesh.smeshBuilder import AssureGeomPublished
567 AssureGeomPublished( self.mesh, theFace )
568 AssureGeomPublished( self.mesh, theVertex )
570 return self.Parameters().SetEnforcedVertexGeom(theFace, theVertex)
572 return self.Parameters().SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
575 ## Set an enforced vertex on a face given the coordinates of a point.
576 # The face if found by the application.
577 # @param x : x coordinate
578 # @param y : y coordinate
579 # @param z : z coordinate
580 # @param vertexName : name of the enforced vertex
581 # @param groupName : name of the group
582 def AddEnforcedVertex(self, x, y, z, vertexName = "", groupName = ""):
583 from salome.smesh.smeshBuilder import AssureGeomPublished
586 return self.Parameters().AddEnforcedVertex(x, y, z)
588 return self.Parameters().AddEnforcedVertexWithGroup(x, y, z, groupName)
592 return self.Parameters().AddEnforcedVertexNamed(x, y, z, vertexName)
594 return self.Parameters().AddEnforcedVertexNamedWithGroup( x, y, z, vertexName, groupName)
598 ## To set an enforced vertex on a face given a GEOM vertex, group or compound.
599 # The face if found by the application.
600 # @param theVertex : GEOM vertex (or group, compound).
601 # @param groupName : name of the group
602 def AddEnforcedVertexGeom(self, theVertex, groupName = ""):
603 from salome.smesh.smeshBuilder import AssureGeomPublished
604 AssureGeomPublished( self.mesh, theVertex )
606 return self.Parameters().AddEnforcedVertexGeom(theVertex)
608 return self.Parameters().AddEnforcedVertexGeomWithGroup(theVertex,groupName)
611 ## To remove an enforced vertex on a given GEOM face (or group, compound) given the coordinates.
612 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
613 # @param x : x coordinate
614 # @param y : y coordinate
615 # @param z : z coordinate
616 def UnsetEnforcedVertex(self, theFace, x, y, z):
617 from salome.smesh.smeshBuilder import AssureGeomPublished
618 AssureGeomPublished( self.mesh, theFace )
619 return self.Parameters().UnsetEnforcedVertex(theFace, x, y, z)
621 ## To remove an enforced vertex on a given GEOM face (or group, compound) given a GEOM vertex, group or compound.
622 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
623 # @param theVertex : GEOM vertex (or group, compound) to remove.
624 def UnsetEnforcedVertexGeom(self, theFace, theVertex):
625 from salome.smesh.smeshBuilder import AssureGeomPublished
626 AssureGeomPublished( self.mesh, theFace )
627 AssureGeomPublished( self.mesh, theVertex )
628 return self.Parameters().UnsetEnforcedVertexGeom(theFace, theVertex)
630 ## To remove all enforced vertices on a given face.
631 # @param theFace : face (or group/compound of faces) on which to remove all enforced vertices
632 def UnsetEnforcedVertices(self, theFace):
633 from salome.smesh.smeshBuilder import AssureGeomPublished
634 AssureGeomPublished( self.mesh, theFace )
635 return self.Parameters().UnsetEnforcedVertices(theFace)
637 ## To tell BLSURF to add a node on internal vertices
638 # @param toEnforceInternalVertices : boolean; if True the internal vertices are added as enforced vertices
639 def SetInternalEnforcedVertexAllFaces(self, toEnforceInternalVertices):
640 return self.Parameters().SetInternalEnforcedVertexAllFaces(toEnforceInternalVertices)
642 ## To know if BLSURF will add a node on internal vertices
643 def GetInternalEnforcedVertexAllFaces(self):
644 return self.Parameters().GetInternalEnforcedVertexAllFaces()
646 ## To define a group for the nodes of internal vertices
647 # @param groupName : string; name of the group
648 def SetInternalEnforcedVertexAllFacesGroup(self, groupName):
649 return self.Parameters().SetInternalEnforcedVertexAllFacesGroup(groupName)
651 ## To get the group name of the nodes of internal vertices
652 def GetInternalEnforcedVertexAllFacesGroup(self):
653 return self.Parameters().GetInternalEnforcedVertexAllFacesGroup()
655 #-----------------------------------------
657 #-----------------------------------------
659 ## 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 ]
660 # @param theFace : face on which the attractor will be defined
661 # @param theAttractor : geometrical object from which the mesh size "h" decreases exponentially
662 # @param theStartSize : mesh size on theAttractor
663 # @param theEndSize : maximum size that will be reached on theFace
664 # @param theInfluenceDistance : influence of the attractor ( the size grow slower on theFace if it's high)
665 # @param theConstantSizeDistance : distance until which the mesh size will be kept constant on theFace
666 def SetAttractorGeom(self, theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance):
667 from salome.smesh.smeshBuilder import AssureGeomPublished
668 AssureGeomPublished( self.mesh, theFace )
669 AssureGeomPublished( self.mesh, theAttractor )
670 self.Parameters().SetAttractorGeom(theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance)
673 ## Unsets an attractor on the chosen face.
674 # @param theFace : face on which the attractor has to be removed
675 def UnsetAttractorGeom(self, theFace):
676 from salome.smesh.smeshBuilder import AssureGeomPublished
677 AssureGeomPublished( self.mesh, theFace )
678 self.Parameters().SetAttractorGeom(theFace)
681 #-----------------------------------------
683 #-----------------------------------------
685 ## To set a size map on a face, edge or vertex (or group, compound) given Python function.
686 # If theObject is a face, the function can be: def f(u,v): return u+v
687 # If theObject is an edge, the function can be: def f(t): return t/2
688 # If theObject is a vertex, the function can be: def f(): return 10
689 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
690 # @param theSizeMap : Size map defined as a string
691 def SetSizeMap(self, theObject, theSizeMap):
692 from salome.smesh.smeshBuilder import AssureGeomPublished
693 AssureGeomPublished( self.mesh, theObject )
694 self.Parameters().SetSizeMap(theObject, theSizeMap)
697 ## To set a constant size map on a face, edge or vertex (or group, compound).
698 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
699 # @param theSizeMap : Size map defined as a double
700 def SetConstantSizeMap(self, theObject, theSizeMap):
701 from salome.smesh.smeshBuilder import AssureGeomPublished
702 AssureGeomPublished( self.mesh, theObject )
703 self.Parameters().SetConstantSizeMap(theObject, theSizeMap)
705 ## To remove a size map defined on a face, edge or vertex (or group, compound)
706 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
707 def UnsetSizeMap(self, theObject):
708 from salome.smesh.smeshBuilder import AssureGeomPublished
709 AssureGeomPublished( self.mesh, theObject )
710 self.Parameters().UnsetSizeMap(theObject)
713 ## To remove all the size maps
714 def ClearSizeMaps(self):
715 self.Parameters().ClearSizeMaps()
718 ## Sets QuadAllowed flag (DEPRECATED: use SetElementType)
719 # @param toAllow "allow quadrangles" flag value
720 # TODO: to remove in Salome 9
721 def SetQuadAllowed(self, toAllow=True):
722 self.Parameters().SetQuadAllowed(toAllow)
725 ## Sets elements type
726 # @param theElementType: 0 (Triangles), 1 (QuadrangleDominant), 2 (Quadrangles)
727 def SetElementType(self, theElementType=Triangles):
728 self.Parameters().SetElementType(theElementType)
731 ## Defines hypothesis having several parameters
732 # @return hypothesis object
733 def Parameters(self):
735 hypType = "MG-CADSurf Parameters"
736 hasGeom = self.mesh.GetMesh().HasShapeToMesh()
738 self.params = self.Hypothesis(hypType, [], LIBRARY, UseExisting=0)
740 self.params = self.Hypothesis(hypType + "_NOGEOM", [], LIBRARY, UseExisting=0)
741 self.mesh.smeshpyD.SetName( self.params, hypType )
745 #-----------------------------------------
746 # Periodicity (BLSURF with PreCAD)
747 #-----------------------------------------
749 ## Defines periodicity between two groups of faces, using PreCAD
750 # @param theFace1 : GEOM face (or group, compound) to associate with theFace2
751 # @param theFace2 : GEOM face (or group, compound) associated with theFace1
752 # @param theSourceVertices (optionnal): list of GEOM vertices on theFace1 defining the transformation from theFace1 to theFace2.
753 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
754 # @param theTargetVertices (optionnal): list of GEOM vertices on theFace2 defining the transformation from theFace1 to theFace2.
755 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
756 def AddPreCadFacesPeriodicity(self, theFace1, theFace2, theSourceVertices=[], theTargetVertices=[]):
757 """calls preCad function:
758 status_t cad_add_face_multiple_periodicity_with_transformation_function(cad t *cad,
759 integer *fid1, integer size1, integer *fid2, integer size2,
760 periodicity_transformation_t transf, void *user data);
762 if theSourceVertices and theTargetVertices:
763 self.Parameters().AddPreCadFacesPeriodicityWithVertices(theFace1, theFace2, theSourceVertices, theTargetVertices)
765 self.Parameters().AddPreCadFacesPeriodicity(theFace1, theFace2)
768 ## Defines periodicity between two groups of edges, using PreCAD
769 # @param theEdge1 : GEOM edge (or group, compound) to associate with theEdge2
770 # @param theEdge2 : GEOM edge (or group, compound) associated with theEdge1
771 # @param theSourceVertices (optionnal): list of GEOM vertices on theEdge1 defining the transformation from theEdge1 to theEdge2.
772 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
773 # @param theTargetVertices (optionnal): list of GEOM vertices on theEdge2 defining the transformation from theEdge1 to theEdge2.
774 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
775 def AddPreCadEdgesPeriodicity(self, theEdge1, theEdge2, theSourceVertices=[], theTargetVertices=[]):
776 """calls preCad function:
777 status_t cad_add_edge_multiple_periodicity_with_transformation_function(cad t *cad,
778 integer *eid1, integer size1, integer *eid2, integer size2,
779 periodicity_transformation_t transf, void *user data);
781 if theSourceVertices and theTargetVertices:
782 self.Parameters().AddPreCadEdgesPeriodicityWithVertices(theEdge1, theEdge2, theSourceVertices, theTargetVertices)
784 self.Parameters().AddPreCadEdgesPeriodicity(theEdge1, theEdge2)
787 #-----------------------------------------
789 #-----------------------------------------
791 ## Defines hyper-patches. A hyper-patch is a set of adjacent faces meshed as a whole,
792 # ignoring edges between them
793 # @param hyperPatchList : list of hyper-patches. A hyper-patch is defined as a list of
794 # faces or groups of faces. A face can be identified either as a GEOM object or
795 # a face ID (returned e.g. by geompy.GetSubShapeID( mainShape, subShape )).
797 # Example: cadsurf.SetHyperPatches([[ Face_1, Group_2 ],[ 13, 23 ]])
798 def SetHyperPatches(self, hyperPatchList):
800 for patch in hyperPatchList:
803 if isinstance( face, int ):
805 elif isinstance( face, GEOM._objref_GEOM_Object):
806 faces = self.mesh.geompyD.SubShapeAll( face, self.mesh.geompyD.ShapeType["FACE"] )
808 ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
810 raise TypeError("Face of hyper-patch should be either ID or GEOM_Object, not %s" % type(face))
814 self.Parameters().SetHyperPatches( hpl )
817 pass # end of BLSURF_Algorithm class
819 def version_less(version: str, ref_version: str):
821 return [int(i) for i in split('[.-]', version)] < [int(i) for i in re.split('[.-]', ref_version)]