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
27 LIBRARY = "libBLSURFEngine.so"
29 # Topology treatment way of MG-CADSurf
30 FromCAD, PreProcess, PreProcessPlus, PreCAD = 0,1,2,3
32 # Element size flag of MG-CADSurf
33 DefaultSize, DefaultGeom, MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize = 0,0,1,2
35 MG_CADSURF_Custom, SizeMap = MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize
36 BLSURF_Custom, BLSURF_GlobalSize, BLSURF_LocalSize = MG_CADSURF_Custom, MG_CADSURF_GlobalSize, MG_CADSURF_LocalSize
38 # import BLSURFPlugin module if possible
46 #----------------------------
47 # Mesh algo type identifiers
48 #----------------------------
50 ## Algorithm type: MG-CADSurf triangle algorithm, see BLSURF_Algorithm
51 MG_CADSurf = "MG-CADSurf"
54 #----------------------
56 #----------------------
58 ## MG-CADSurf 2D algorithm.
60 # It can be created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MG-CADSurf,geom=0)
62 class BLSURF_Algorithm(Mesh_Algorithm):
64 ## name of the dynamic method in smeshBuilder.Mesh class
66 meshMethod = "Triangle"
67 ## type of algorithm used with helper function in smeshBuilder.Mesh class
70 ## doc string of the method
72 docHelper = "Creates triangle algorithm for faces"
74 _anisotropic_ratio = 0
75 _bad_surface_element_aspect_ratio = 1000
76 _geometric_approximation = 22
80 _remove_tiny_edges = 0
82 ## Private constructor.
83 # @param mesh parent mesh object algorithm is assigned to
84 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
85 # if it is @c 0 (default), the algorithm is assigned to the main shape
86 def __init__(self, mesh, geom=0):
87 Mesh_Algorithm.__init__(self)
89 print "Warning: BLSURFPlugin module unavailable"
90 if mesh.GetMesh().HasShapeToMesh():
91 self.Create(mesh, geom, self.algoType, LIBRARY)
93 self.Create(mesh, geom, self.algoType+"_NOGEOM", LIBRARY)
94 mesh.smeshpyD.SetName( self.algo, self.algoType )
96 self.geompyD = mesh.geompyD
97 #self.SetPhysicalMesh() - PAL19680
100 ## Sets a way to define size of mesh elements to generate.
101 # @param thePhysicalMesh is: DefaultSize, MG_CADSURF_Custom or SizeMap.
102 def SetPhysicalMesh(self, thePhysicalMesh=DefaultSize):
103 physical_size_mode = thePhysicalMesh
104 if self.Parameters().GetGeometricMesh() == DefaultGeom:
105 if physical_size_mode == DefaultSize:
106 physical_size_mode = MG_CADSURF_GlobalSize
107 self.Parameters().SetPhysicalMesh(physical_size_mode)
110 ## Sets a way to define maximum angular deflection of mesh from CAD model.
111 # @param theGeometricMesh is: DefaultGeom (0)) or MG_CADSURF_GlobalSize (1))
112 def SetGeometricMesh(self, theGeometricMesh=DefaultGeom):
113 geometric_size_mode = theGeometricMesh
114 if self.Parameters().GetPhysicalMesh() == DefaultSize:
115 if geometric_size_mode == DefaultGeom:
116 geometric_size_mode = MG_CADSURF_GlobalSize
117 self.Parameters().SetGeometricMesh(geometric_size_mode)
120 ## Sets size of mesh elements to generate.
121 # @param theVal : constant global size when using a global physical size.
122 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
123 def SetPhySize(self, theVal, isRelative = False):
124 if self.Parameters().GetPhysicalMesh() == DefaultSize:
125 self.SetPhysicalMesh(MG_CADSURF_GlobalSize)
127 self.Parameters().SetPhySizeRel(theVal)
129 self.Parameters().SetPhySize(theVal)
132 ## Sets lower boundary of mesh element size.
133 # @param theVal : global minimal cell size desired.
134 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
135 def SetMinSize(self, theVal=-1, isRelative = False):
137 self.Parameters().SetMinSizeRel(theVal)
139 self.Parameters().SetMinSize(theVal)
142 ## Sets upper boundary of mesh element size.
143 # @param theVal : global maximal cell size desired.
144 # @param isRelative : if True, the value is relative to the length of the diagonal of the bounding box
145 def SetMaxSize(self, theVal=-1, isRelative = False):
147 self.Parameters().SetMaxSizeRel(theVal)
149 self.Parameters().SetMaxSize(theVal)
152 ## Sets angular deflection (in degrees) from CAD surface.
153 # @param theVal value of angular deflection
154 def SetAngleMesh(self, theVal=_geometric_approximation):
155 if self.Parameters().GetGeometricMesh() == DefaultGeom:
156 self.SetGeometricMesh(MG_CADSURF_GlobalSize)
157 self.Parameters().SetAngleMesh(theVal)
160 ## Sets the maximum desired distance between a triangle and its supporting CAD surface
161 # @param distance the distance between a triangle and a surface
162 def SetChordalError(self, distance):
163 self.Parameters().SetChordalError(distance)
166 ## Sets maximal allowed ratio between the lengths of two adjacent edges.
167 # @param toUseGradation to use gradation
168 # @param theVal value of maximal length ratio
169 def SetGradation(self, toUseGradation=True, theVal=_gradation):
170 if isinstance( toUseGradation, float ): ## backward compatibility
171 toUseGradation, theVal = True, toUseGradation
172 if self.Parameters().GetGeometricMesh() == 0: theVal = self._gradation
173 self.Parameters().SetUseGradation(toUseGradation)
174 self.Parameters().SetGradation(theVal)
177 ## Sets maximal allowed ratio between the lengths of two adjacent edges in 3D mesh.
178 # @param toUseGradation to use gradation
179 # @param theVal value of maximal length ratio
180 def SetVolumeGradation(self, toUseGradation=True, theVal=_gradation):
181 if self.Parameters().GetGeometricMesh() == 0: theVal = self._volume_gradation
182 self.Parameters().SetUseVolumeGradation(toUseGradation)
183 self.Parameters().SetVolumeGradation(theVal)
186 ## Sets topology usage way.
187 # @param way defines how mesh conformity is assured <ul>
188 # <li>FromCAD - mesh conformity is assured by conformity of a shape</li>
189 # <li>PreProcess or PreProcessPlus - by pre-processing a CAD model (OBSOLETE: FromCAD will be used)</li>
190 # <li>PreCAD - by pre-processing with PreCAD a CAD model</li></ul>
191 def SetTopology(self, way):
192 if way != PreCAD and way != FromCAD:
193 print "Warning: topology mode %d is no longer supported. Mode FromCAD is used."%way
195 self.Parameters().SetTopology(way)
198 ## To respect geometrical edges or not.
199 # @param toIgnoreEdges "ignore edges" flag value
200 def SetDecimesh(self, toIgnoreEdges=False):
202 self.SetOptionValue("respect_geometry","0")
204 self.SetOptionValue("respect_geometry","1")
207 ## Sets verbosity level in the range 0 to 100.
208 # @param level verbosity level
209 def SetVerbosity(self, level):
210 self.Parameters().SetVerbosity(level)
213 ## Set enforce_cad_edge_sizes parameter
215 # Relaxes the given sizemap constraint around CAD edges to allow a better
216 # element quality and a better geometric approximation. It is only useful in
217 # combination with the gradation option.
219 def SetEnforceCadEdgesSize( self, toEnforce ):
220 self.Parameters().SetEnforceCadEdgesSize( toEnforce )
222 ## Set jacobian_rectification_respect_geometry parameter
224 # While making the mesh quadratic, allows to lose the CAD-mesh associativity in order
225 # to correct elements with nagative Jacobian
227 def SetJacobianRectificationRespectGeometry( self, allowRectification ):
228 self.Parameters().SetJacobianRectificationRespectGeometry( allowRectification )
230 ## Set rectify_jacobian parameter
232 # While making the mesh quadratic, allow to fix nagative Jacobian surface elements
234 def SetJacobianRectification( self, allowRectification ):
235 self.Parameters().SetJacobianRectification( allowRectification )
237 ## Set use_deprecated_patch_mesher parameter (compatibility with older versions of Meshgems)
239 # the use_deprecated_patch_mesher parameter allows to keep the same behaviour than
240 # in salome < 8.3 (meshgems 2.1.11 instead of meshgems >= 2.4.5)
242 def SetUseDeprecatedPatchMesher( self, useDeprecatedPatchMesher ):
243 self.Parameters().SetUseDeprecatedPatchMesher( useDeprecatedPatchMesher )
245 ## Set respect_geometry parameter
247 # This patch independent option can be deactivated to allow MeshGems-CADSurf
248 # to lower the geometry accuracy in its patch independent process.
250 def SetRespectGeometry( self, toRespect ):
251 self.Parameters().SetRespectGeometry( toRespect )
253 ## Set max_number_of_points_per_patch parameter
255 # This parameter controls the maximum amount of points MeshGems-CADSurf is allowed
256 # to generate on a single CAD patch. For an automatic gestion of the memory, one
257 # can set this parameter to 0
259 def SetMaxNumberOfPointsPerPatch( self, nb ):
260 self.Parameters().SetMaxNumberOfPointsPerPatch( nb )
262 ## Set max_number_of_threads parameter
264 # Set the maximum of threads to use for multithreading mesh computation
266 def SetMaxNumberOfThreads( self, nb ):
267 self.Parameters().SetMaxNumberOfThreads( nb )
269 ## Set respect_geometry parameter
271 # This patch independent option can be deactivated to allow MeshGems-CADSurf
272 # to lower the geometry accuracy in its patch independent process.
274 def SetRespectGeometry( self, toRespect ):
275 self.Parameters().SetRespectGeometry( toRespect )
277 ## Set tiny_edges_avoid_surface_intersections parameter
279 # This option defines the priority between the tiny feature
280 # suppression and the surface intersection prevention.
282 def SetTinyEdgesAvoidSurfaceIntersections( self, toAvoidIntersection ):
283 self.Parameters().SetTinyEdgesAvoidSurfaceIntersections( toAvoidIntersection )
285 ## Set closed_geometry parameter parameter
287 # Describes whether the geometry is expected to be closed or not.
288 # When activated, this option helps MeshGems-PreCAD to treat the dirtiest geometries.
290 def SetClosedGeometry( self, isClosed ):
291 self.Parameters().SetClosedGeometry( isClosed )
293 ## Set debug parameter
295 # Make MeshGems-CADSurf will be very verbose and will output some intermediate
296 # files in the working directory. This option is mainly meant for Distene support issues.
298 def SetDebug( self, isDebug ):
299 self.Parameters().SetDebug( isDebug )
301 ## Set periodic_tolerance parameter
303 # This parameter defines the maximum size difference between two periodic edges
304 # and also the maximum distance error between two periodic entities.
306 def SetPeriodicTolerance( self, tol ):
307 self.Parameters().SetPeriodicTolerance( tol )
309 ## Set required_entities parameter
311 # The required entities control the correction operations.
312 # Accepted values for this parameter are :
313 # - "respect" : MeshGems-CADSurf is not allowed to alter any required entity,
314 # even for correction purposes,
315 # - "ignore" : MeshGems-CADSurf will ignore the required entities in its processing,
316 # - "clear" : MeshGems-CADSurf will clear any required status for the entities.
317 # There will not be any entity marked as required in the generated mesh.
319 def SetRequiredEntities( self, howToTreat ):
320 self.Parameters().SetRequiredEntities( howToTreat )
322 ## Set sewing_tolerance parameter
324 # This parameter is the tolerance of the assembly.
326 def SetSewingTolerance( self, tol ):
327 self.Parameters().SetSewingTolerance( tol )
329 ## Set tags parameter
331 # The tag (attribute) system controls the optimisation process.
332 # Accepted values for this parameter are :
333 # - "respect" : the CAD tags will be preserved and unaltered by the optimisation operations,
334 # - "ignore" : the CAD tags will be ignored by the optimisation operations
335 # but they will still be present in the output mesh,
336 # - "clear" : MeshGems-CADSurf will clear any tag on any entity and optimise accordingly.
337 # There will not be any tag in the generated mesh.
339 def SetTags( self, howToTreat ):
340 self.Parameters().SetTags( howToTreat )
342 ## Activate removal of the tiny edges from the generated
343 # mesh when it improves the local mesh quality, without taking into account the
344 # tags (attributes) specifications.
345 # @param toOptimise "to optimize" flag value
346 # @param length minimal length under which an edge is considered to be a tiny
347 def SetOptimiseTinyEdges(self, toOptimise, length=-1):
348 self.Parameters().SetOptimiseTinyEdges( toOptimise )
350 self.Parameters().SetTinyEdgeOptimisationLength( length )
352 ## Activate correction of all surface intersections
353 # @param toCorrect "to correct" flag value
354 # @param maxCost the time the user is ready to spend in the intersection prevention process
355 # For example, maxCost = 3 means that MeshGems-CADSurf will not spend more time
356 # in the intersection removal process than 3 times the time required to mesh
357 # without processing the intersections.
358 def SetCorrectSurfaceIntersection(self, toCorrect, maxCost ):
359 self.Parameters().SetCorrectSurfaceIntersection( toCorrect )
361 self.Parameters().SetCorrectSurfaceIntersectionMaxCost( maxCost )
363 ## To optimize merges edges.
364 # @param toMergeEdges "merge edges" flag value
365 def SetPreCADMergeEdges(self, toMergeEdges=False):
366 self.Parameters().SetPreCADMergeEdges(toMergeEdges)
369 ## To remove duplicate CAD Faces
370 # @param toRemoveDuplicateCADFaces "remove_duplicate_cad_faces" flag value
371 def SetPreCADRemoveDuplicateCADFaces(self, toRemoveDuplicateCADFaces=False):
372 self.Parameters().SetPreCADRemoveDuplicateCADFaces(toRemoveDuplicateCADFaces)
375 ## To process 3D topology.
376 # @param toProcess "PreCAD process 3D" flag value
377 def SetPreCADProcess3DTopology(self, toProcess=False):
378 self.Parameters().SetPreCADProcess3DTopology(toProcess)
381 ## To remove nano edges.
382 # @param toRemoveNanoEdges "remove nano edges" flag value
383 def SetPreCADRemoveNanoEdges(self, toRemoveNanoEdges=False):
384 if toRemoveNanoEdges:
385 self.SetPreCADOptionValue("remove_tiny_edges","1")
387 self.SetPreCADOptionValue("remove_tiny_edges","0")
390 ## To compute topology from scratch
391 # @param toDiscardInput "discard input" flag value
392 def SetPreCADDiscardInput(self, toDiscardInput=False):
393 self.Parameters().SetPreCADDiscardInput(toDiscardInput)
396 ## Sets the length below which an edge is considered as nano
397 # for the topology processing.
398 # @param epsNano nano edge length threshold value
399 def SetPreCADEpsNano(self, epsNano):
400 self.SetPreCADOptionValue("tiny_edge_length","%f"%epsNano)
403 ## Sets advanced option value.
404 # @param optionName advanced option name
405 # @param level advanced option value
406 def SetOptionValue(self, optionName, level):
407 self.Parameters().SetOptionValue(optionName,level)
410 ## Sets advanced PreCAD option value.
411 # @param optionName name of the option
412 # @param optionValue value of the option
413 def SetPreCADOptionValue(self, optionName, optionValue):
414 self.Parameters().SetPreCADOptionValue(optionName,optionValue)
417 ## Adds custom advanced option values
418 # @param optionsAndValues options and values in a form "option_1 v1 option_2 v2'"
419 def SetAdvancedOption(self, optionsAndValues):
420 self.Parameters().SetAdvancedOption(optionsAndValues)
423 ## Adds custom advanced option value.
424 # @param optionName custom advanced option name
425 # @param level custom advanced option value
426 def AddOption(self, optionName, level):
427 self.Parameters().AddOption(optionName,level)
430 ## Adds custom advanced PreCAD option value.
431 # @param optionName custom name of the option
432 # @param optionValue value of the option
433 def AddPreCADOption(self, optionName, optionValue):
434 self.Parameters().AddPreCADOption(optionName,optionValue)
437 ## Sets GMF file for export at computation
438 # @param fileName GMF file name
439 def SetGMFFile(self, fileName):
440 self.Parameters().SetGMFFile(fileName)
443 #-----------------------------------------
444 # Enforced vertices (BLSURF)
445 #-----------------------------------------
447 ## To get all the enforced vertices
448 def GetAllEnforcedVertices(self):
449 return self.Parameters().GetAllEnforcedVertices()
451 ## To get all the enforced vertices sorted by face (or group, compound)
452 def GetAllEnforcedVerticesByFace(self):
453 return self.Parameters().GetAllEnforcedVerticesByFace()
455 ## To get all the enforced vertices sorted by coords of input vertices
456 def GetAllEnforcedVerticesByCoords(self):
457 return self.Parameters().GetAllEnforcedVerticesByCoords()
459 ## To get all the coords of input vertices sorted by face (or group, compound)
460 def GetAllCoordsByFace(self):
461 return self.Parameters().GetAllCoordsByFace()
463 ## To get all the enforced vertices on a face (or group, compound)
464 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
465 def GetEnforcedVertices(self, theFace):
466 from salome.smesh.smeshBuilder import AssureGeomPublished
467 AssureGeomPublished( self.mesh, theFace )
468 return self.Parameters().GetEnforcedVertices(theFace)
470 ## To clear all the enforced vertices
471 def ClearAllEnforcedVertices(self):
472 return self.Parameters().ClearAllEnforcedVertices()
474 ## 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.
475 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
476 # @param x : x coordinate
477 # @param y : y coordinate
478 # @param z : z coordinate
479 # @param vertexName : name of the enforced vertex
480 # @param groupName : name of the group
481 def SetEnforcedVertex(self, theFace, x, y, z, vertexName = "", groupName = ""):
482 from salome.smesh.smeshBuilder import AssureGeomPublished
483 AssureGeomPublished( self.mesh, theFace )
486 return self.Parameters().SetEnforcedVertex(theFace, x, y, z)
488 return self.Parameters().SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
492 return self.Parameters().SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
494 return self.Parameters().SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
498 ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
499 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
500 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
501 # @param groupName : name of the group
502 def SetEnforcedVertexGeom(self, theFace, theVertex, groupName = ""):
503 from salome.smesh.smeshBuilder import AssureGeomPublished
504 AssureGeomPublished( self.mesh, theFace )
505 AssureGeomPublished( self.mesh, theVertex )
507 return self.Parameters().SetEnforcedVertexGeom(theFace, theVertex)
509 return self.Parameters().SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
512 ## Set an enforced vertex on a face given the coordinates of a point.
513 # The face if found by the application.
514 # @param x : x coordinate
515 # @param y : y coordinate
516 # @param z : z coordinate
517 # @param vertexName : name of the enforced vertex
518 # @param groupName : name of the group
519 def AddEnforcedVertex(self, x, y, z, vertexName = "", groupName = ""):
520 from salome.smesh.smeshBuilder import AssureGeomPublished
523 return self.Parameters().AddEnforcedVertex(x, y, z)
525 return self.Parameters().AddEnforcedVertexWithGroup(x, y, z, groupName)
529 return self.Parameters().AddEnforcedVertexNamed(x, y, z, vertexName)
531 return self.Parameters().AddEnforcedVertexNamedWithGroup( x, y, z, vertexName, groupName)
535 ## To set an enforced vertex on a face given a GEOM vertex, group or compound.
536 # The face if found by the application.
537 # @param theVertex : GEOM vertex (or group, compound).
538 # @param groupName : name of the group
539 def AddEnforcedVertexGeom(self, theVertex, groupName = ""):
540 from salome.smesh.smeshBuilder import AssureGeomPublished
541 AssureGeomPublished( self.mesh, theVertex )
543 return self.Parameters().AddEnforcedVertexGeom(theVertex)
545 return self.Parameters().AddEnforcedVertexGeomWithGroup(theVertex,groupName)
548 ## To remove an enforced vertex on a given GEOM face (or group, compound) given the coordinates.
549 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
550 # @param x : x coordinate
551 # @param y : y coordinate
552 # @param z : z coordinate
553 def UnsetEnforcedVertex(self, theFace, x, y, z):
554 from salome.smesh.smeshBuilder import AssureGeomPublished
555 AssureGeomPublished( self.mesh, theFace )
556 return self.Parameters().UnsetEnforcedVertex(theFace, x, y, z)
558 ## To remove an enforced vertex on a given GEOM face (or group, compound) given a GEOM vertex, group or compound.
559 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
560 # @param theVertex : GEOM vertex (or group, compound) to remove.
561 def UnsetEnforcedVertexGeom(self, theFace, theVertex):
562 from salome.smesh.smeshBuilder import AssureGeomPublished
563 AssureGeomPublished( self.mesh, theFace )
564 AssureGeomPublished( self.mesh, theVertex )
565 return self.Parameters().UnsetEnforcedVertexGeom(theFace, theVertex)
567 ## To remove all enforced vertices on a given face.
568 # @param theFace : face (or group/compound of faces) on which to remove all enforced vertices
569 def UnsetEnforcedVertices(self, theFace):
570 from salome.smesh.smeshBuilder import AssureGeomPublished
571 AssureGeomPublished( self.mesh, theFace )
572 return self.Parameters().UnsetEnforcedVertices(theFace)
574 ## To tell BLSURF to add a node on internal vertices
575 # @param toEnforceInternalVertices : boolean; if True the internal vertices are added as enforced vertices
576 def SetInternalEnforcedVertexAllFaces(self, toEnforceInternalVertices):
577 return self.Parameters().SetInternalEnforcedVertexAllFaces(toEnforceInternalVertices)
579 ## To know if BLSURF will add a node on internal vertices
580 def GetInternalEnforcedVertexAllFaces(self):
581 return self.Parameters().GetInternalEnforcedVertexAllFaces()
583 ## To define a group for the nodes of internal vertices
584 # @param groupName : string; name of the group
585 def SetInternalEnforcedVertexAllFacesGroup(self, groupName):
586 return self.Parameters().SetInternalEnforcedVertexAllFacesGroup(groupName)
588 ## To get the group name of the nodes of internal vertices
589 def GetInternalEnforcedVertexAllFacesGroup(self):
590 return self.Parameters().GetInternalEnforcedVertexAllFacesGroup()
592 #-----------------------------------------
594 #-----------------------------------------
596 ## 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 ]
597 # @param theFace : face on which the attractor will be defined
598 # @param theAttractor : geometrical object from which the mesh size "h" decreases exponentially
599 # @param theStartSize : mesh size on theAttractor
600 # @param theEndSize : maximum size that will be reached on theFace
601 # @param theInfluenceDistance : influence of the attractor ( the size grow slower on theFace if it's high)
602 # @param theConstantSizeDistance : distance until which the mesh size will be kept constant on theFace
603 def SetAttractorGeom(self, theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance):
604 from salome.smesh.smeshBuilder import AssureGeomPublished
605 AssureGeomPublished( self.mesh, theFace )
606 AssureGeomPublished( self.mesh, theAttractor )
607 self.Parameters().SetAttractorGeom(theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance)
610 ## Unsets an attractor on the chosen face.
611 # @param theFace : face on which the attractor has to be removed
612 def UnsetAttractorGeom(self, theFace):
613 from salome.smesh.smeshBuilder import AssureGeomPublished
614 AssureGeomPublished( self.mesh, theFace )
615 self.Parameters().SetAttractorGeom(theFace)
618 #-----------------------------------------
620 #-----------------------------------------
622 ## To set a size map on a face, edge or vertex (or group, compound) given Python function.
623 # If theObject is a face, the function can be: def f(u,v): return u+v
624 # If theObject is an edge, the function can be: def f(t): return t/2
625 # If theObject is a vertex, the function can be: def f(): return 10
626 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
627 # @param theSizeMap : Size map defined as a string
628 def SetSizeMap(self, theObject, theSizeMap):
629 from salome.smesh.smeshBuilder import AssureGeomPublished
630 AssureGeomPublished( self.mesh, theObject )
631 self.Parameters().SetSizeMap(theObject, theSizeMap)
634 ## To set a constant size map on a face, edge or vertex (or group, compound).
635 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
636 # @param theSizeMap : Size map defined as a double
637 def SetConstantSizeMap(self, theObject, theSizeMap):
638 from salome.smesh.smeshBuilder import AssureGeomPublished
639 AssureGeomPublished( self.mesh, theObject )
640 self.Parameters().SetConstantSizeMap(theObject, theSizeMap)
642 ## To remove a size map defined on a face, edge or vertex (or group, compound)
643 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
644 def UnsetSizeMap(self, theObject):
645 from salome.smesh.smeshBuilder import AssureGeomPublished
646 AssureGeomPublished( self.mesh, theObject )
647 self.Parameters().UnsetSizeMap(theObject)
650 ## To remove all the size maps
651 def ClearSizeMaps(self):
652 self.Parameters().ClearSizeMaps()
655 ## Sets QuadAllowed flag.
656 # @param toAllow "allow quadrangles" flag value
657 def SetQuadAllowed(self, toAllow=True):
658 self.Parameters().SetQuadAllowed(toAllow)
661 ## Defines hypothesis having several parameters
662 # @return hypothesis object
663 def Parameters(self):
665 hypType = "MG-CADSurf Parameters"
666 hasGeom = self.mesh.GetMesh().HasShapeToMesh()
668 self.params = self.Hypothesis(hypType, [], LIBRARY, UseExisting=0)
670 self.params = self.Hypothesis(hypType + "_NOGEOM", [], LIBRARY, UseExisting=0)
671 self.mesh.smeshpyD.SetName( self.params, hypType )
675 #-----------------------------------------
676 # Periodicity (BLSURF with PreCAD)
677 #-----------------------------------------
679 ## Defines periodicity between two groups of faces, using PreCAD
680 # @param theFace1 : GEOM face (or group, compound) to associate with theFace2
681 # @param theFace2 : GEOM face (or group, compound) associated with theFace1
682 # @param theSourceVertices (optionnal): list of GEOM vertices on theFace1 defining the transformation from theFace1 to theFace2.
683 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
684 # @param theTargetVertices (optionnal): list of GEOM vertices on theFace2 defining the transformation from theFace1 to theFace2.
685 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
686 def AddPreCadFacesPeriodicity(self, theFace1, theFace2, theSourceVertices=[], theTargetVertices=[]):
687 """calls preCad function:
688 status_t cad_add_face_multiple_periodicity_with_transformation_function(cad t *cad,
689 integer *fid1, integer size1, integer *fid2, integer size2,
690 periodicity_transformation_t transf, void *user data);
692 if theSourceVertices and theTargetVertices:
693 self.Parameters().AddPreCadFacesPeriodicityWithVertices(theFace1, theFace2, theSourceVertices, theTargetVertices)
695 self.Parameters().AddPreCadFacesPeriodicity(theFace1, theFace2)
698 ## Defines periodicity between two groups of edges, using PreCAD
699 # @param theEdge1 : GEOM edge (or group, compound) to associate with theEdge2
700 # @param theEdge2 : GEOM edge (or group, compound) associated with theEdge1
701 # @param theSourceVertices (optionnal): list of GEOM vertices on theEdge1 defining the transformation from theEdge1 to theEdge2.
702 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
703 # @param theTargetVertices (optionnal): list of GEOM vertices on theEdge2 defining the transformation from theEdge1 to theEdge2.
704 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
705 def AddPreCadEdgesPeriodicity(self, theEdge1, theEdge2, theSourceVertices=[], theTargetVertices=[]):
706 """calls preCad function:
707 status_t cad_add_edge_multiple_periodicity_with_transformation_function(cad t *cad,
708 integer *eid1, integer size1, integer *eid2, integer size2,
709 periodicity_transformation_t transf, void *user data);
711 if theSourceVertices and theTargetVertices:
712 self.Parameters().AddPreCadEdgesPeriodicityWithVertices(theEdge1, theEdge2, theSourceVertices, theTargetVertices)
714 self.Parameters().AddPreCadEdgesPeriodicity(theEdge1, theEdge2)
717 #-----------------------------------------
719 #-----------------------------------------
721 ## Defines hyper-patches. A hyper-patch is a set of adjacent faces meshed as a whole,
722 # ignoring edges between them
723 # @param hyperPatchList : list of hyper-patches. A hyper-patch is defined as a list of
724 # faces or groups of faces. A face can be identified either as a GEOM object or
725 # a face ID (returned e.g. by geompy.GetSubShapeID( mainShape, subShape )).
727 # Example: cadsurf.SetHyperPatches([[ Face_1, Group_2 ],[ 13, 23 ]])
728 def SetHyperPatches(self, hyperPatchList):
730 for patch in hyperPatchList:
733 if isinstance( face, int ):
735 elif isinstance( face, GEOM._objref_GEOM_Object):
736 faces = self.mesh.geompyD.SubShapeAll( face, self.mesh.geompyD.ShapeType["FACE"] )
738 ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
741 "Face of hyper-patch should be either ID or GEOM_Object, not %s" % type(face)
745 self.Parameters().SetHyperPatches( hpl )
748 #=====================
750 #=====================
755 ## Sets lower boundary of mesh element size (PhySize).
756 def SetPhyMin(self, theVal=-1):
758 Obsolete function. Use SetMinSize.
760 print "Warning: SetPhyMin is obsolete. Please use SetMinSize"
761 self.SetMinSize(theVal)
764 ## Sets upper boundary of mesh element size (PhySize).
765 def SetPhyMax(self, theVal=-1):
767 Obsolete function. Use SetMaxSize.
769 print "Warning: SetPhyMax is obsolete. Please use SetMaxSize"
770 self.SetMaxSize(theVal)
773 ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
774 def SetAngleMeshS(self, theVal=_geometric_approximation):
776 Obsolete function. Use SetAngleMesh.
778 print "Warning: SetAngleMeshS is obsolete. Please use SetAngleMesh"
779 self.SetAngleMesh(theVal)
782 ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
783 def SetAngleMeshC(self, theVal=_geometric_approximation):
785 Obsolete function. Use SetAngleMesh.
787 print "Warning: SetAngleMeshC is obsolete. Please use SetAngleMesh"
788 self.SetAngleMesh(theVal)
791 ## Sets lower boundary of mesh element size computed to respect angular deflection.
792 def SetGeoMin(self, theVal=-1):
794 Obsolete function. Use SetMinSize.
796 print "Warning: SetGeoMin is obsolete. Please use SetMinSize"
797 self.SetMinSize(theVal)
800 ## Sets upper boundary of mesh element size computed to respect angular deflection.
801 def SetGeoMax(self, theVal=-1):
803 Obsolete function. Use SetMaxSize.
805 print "Warning: SetGeoMax is obsolete. Please use SetMaxSize"
806 self.SetMaxSize(theVal)
810 pass # end of BLSURF_Algorithm class