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 respect_geometry parameter
239 # This patch independent option can be deactivated to allow MeshGems-CADSurf
240 # to lower the geometry accuracy in its patch independent process.
242 def SetRespectGeometry( self, toRespect ):
243 self.Parameters().SetRespectGeometry( toRespect )
245 ## Set max_number_of_points_per_patch parameter
247 # This parameter controls the maximum amount of points MeshGems-CADSurf is allowed
248 # to generate on a single CAD patch. For an automatic gestion of the memory, one
249 # can set this parameter to 0
251 def SetMaxNumberOfPointsPerPatch( self, nb ):
252 self.Parameters().SetMaxNumberOfPointsPerPatch( nb )
254 ## Set max_number_of_threads parameter
256 # Set the maximum of threads to use for multithreading mesh computation
258 def SetMaxNumberOfThreads( self, nb ):
259 self.Parameters().SetMaxNumberOfThreads( nb )
261 ## Set respect_geometry parameter
263 # This patch independent option can be deactivated to allow MeshGems-CADSurf
264 # to lower the geometry accuracy in its patch independent process.
266 def SetRespectGeometry( self, toRespect ):
267 self.Parameters().SetRespectGeometry( toRespect )
269 ## Set tiny_edges_avoid_surface_intersections parameter
271 # This option defines the priority between the tiny feature
272 # suppression and the surface intersection prevention.
274 def SetTinyEdgesAvoidSurfaceIntersections( self, toAvoidIntersection ):
275 self.Parameters().SetTinyEdgesAvoidSurfaceIntersections( toAvoidIntersection )
277 ## Set closed_geometry parameter parameter
279 # Describes whether the geometry is expected to be closed or not.
280 # When activated, this option helps MeshGems-PreCAD to treat the dirtiest geometries.
282 def SetClosedGeometry( self, isClosed ):
283 self.Parameters().SetClosedGeometry( isClosed )
285 ## Set debug parameter
287 # Make MeshGems-CADSurf will be very verbose and will output some intermediate
288 # files in the working directory. This option is mainly meant for Distene support issues.
290 def SetDebug( self, isDebug ):
291 self.Parameters().SetDebug( isDebug )
293 ## Set periodic_tolerance parameter
295 # This parameter defines the maximum size difference between two periodic edges
296 # and also the maximum distance error between two periodic entities.
298 def SetPeriodicTolerance( self, tol ):
299 self.Parameters().SetPeriodicTolerance( tol )
301 ## Set required_entities parameter
303 # The required entities control the correction operations.
304 # Accepted values for this parameter are :
305 # - "respect" : MeshGems-CADSurf is not allowed to alter any required entity,
306 # even for correction purposes,
307 # - "ignore" : MeshGems-CADSurf will ignore the required entities in its processing,
308 # - "clear" : MeshGems-CADSurf will clear any required status for the entities.
309 # There will not be any entity marked as required in the generated mesh.
311 def SetRequiredEntities( self, howToTreat ):
312 self.Parameters().SetRequiredEntities( howToTreat )
314 ## Set sewing_tolerance parameter
316 # This parameter is the tolerance of the assembly.
318 def SetSewingTolerance( self, tol ):
319 self.Parameters().SetSewingTolerance( tol )
321 ## Set tags parameter
323 # The tag (attribute) system controls the optimisation process.
324 # Accepted values for this parameter are :
325 # - "respect" : the CAD tags will be preserved and unaltered by the optimisation operations,
326 # - "ignore" : the CAD tags will be ignored by the optimisation operations
327 # but they will still be present in the output mesh,
328 # - "clear" : MeshGems-CADSurf will clear any tag on any entity and optimise accordingly.
329 # There will not be any tag in the generated mesh.
331 def SetTags( self, howToTreat ):
332 self.Parameters().SetTags( howToTreat )
334 ## Activate removal of the tiny edges from the generated
335 # mesh when it improves the local mesh quality, without taking into account the
336 # tags (attributes) specifications.
337 # @param toOptimise "to optimize" flag value
338 # @param length minimal length under which an edge is considered to be a tiny
339 def SetOptimiseTinyEdges(self, toOptimise, length=-1):
340 self.Parameters().SetOptimiseTinyEdges( toOptimise )
342 self.Parameters().SetTinyEdgeOptimisationLength( length )
344 ## Activate correction of all surface intersections
345 # @param toCorrect "to correct" flag value
346 # @param maxCost the time the user is ready to spend in the intersection prevention process
347 # For example, maxCost = 3 means that MeshGems-CADSurf will not spend more time
348 # in the intersection removal process than 3 times the time required to mesh
349 # without processing the intersections.
350 def SetCorrectSurfaceIntersection(self, toCorrect, maxCost ):
351 self.Parameters().SetCorrectSurfaceIntersection( toCorrect )
353 self.Parameters().SetCorrectSurfaceIntersectionMaxCost( maxCost )
355 ## To optimize merges edges.
356 # @param toMergeEdges "merge edges" flag value
357 def SetPreCADMergeEdges(self, toMergeEdges=False):
358 self.Parameters().SetPreCADMergeEdges(toMergeEdges)
361 ## To remove duplicate CAD Faces
362 # @param toRemoveDuplicateCADFaces "remove_duplicate_cad_faces" flag value
363 def SetPreCADRemoveDuplicateCADFaces(self, toRemoveDuplicateCADFaces=False):
364 self.Parameters().SetPreCADRemoveDuplicateCADFaces(toRemoveDuplicateCADFaces)
367 ## To process 3D topology.
368 # @param toProcess "PreCAD process 3D" flag value
369 def SetPreCADProcess3DTopology(self, toProcess=False):
370 self.Parameters().SetPreCADProcess3DTopology(toProcess)
373 ## To remove nano edges.
374 # @param toRemoveNanoEdges "remove nano edges" flag value
375 def SetPreCADRemoveNanoEdges(self, toRemoveNanoEdges=False):
376 if toRemoveNanoEdges:
377 self.SetPreCADOptionValue("remove_tiny_edges","1")
379 self.SetPreCADOptionValue("remove_tiny_edges","0")
382 ## To compute topology from scratch
383 # @param toDiscardInput "discard input" flag value
384 def SetPreCADDiscardInput(self, toDiscardInput=False):
385 self.Parameters().SetPreCADDiscardInput(toDiscardInput)
388 ## Sets the length below which an edge is considered as nano
389 # for the topology processing.
390 # @param epsNano nano edge length threshold value
391 def SetPreCADEpsNano(self, epsNano):
392 self.SetPreCADOptionValue("tiny_edge_length","%f"%epsNano)
395 ## Sets advanced option value.
396 # @param optionName advanced option name
397 # @param level advanced option value
398 def SetOptionValue(self, optionName, level):
399 self.Parameters().SetOptionValue(optionName,level)
402 ## Sets advanced PreCAD option value.
403 # @param optionName name of the option
404 # @param optionValue value of the option
405 def SetPreCADOptionValue(self, optionName, optionValue):
406 self.Parameters().SetPreCADOptionValue(optionName,optionValue)
409 ## Adds custom advanced option values
410 # @param optionsAndValues options and values in a form "option_1 v1 option_2 v2'"
411 def SetAdvancedOption(self, optionsAndValues):
412 self.Parameters().SetAdvancedOption(optionsAndValues)
415 ## Adds custom advanced option value.
416 # @param optionName custom advanced option name
417 # @param level custom advanced option value
418 def AddOption(self, optionName, level):
419 self.Parameters().AddOption(optionName,level)
422 ## Adds custom advanced PreCAD option value.
423 # @param optionName custom name of the option
424 # @param optionValue value of the option
425 def AddPreCADOption(self, optionName, optionValue):
426 self.Parameters().AddPreCADOption(optionName,optionValue)
429 ## Sets GMF file for export at computation
430 # @param fileName GMF file name
431 def SetGMFFile(self, fileName):
432 self.Parameters().SetGMFFile(fileName)
435 #-----------------------------------------
436 # Enforced vertices (BLSURF)
437 #-----------------------------------------
439 ## To get all the enforced vertices
440 def GetAllEnforcedVertices(self):
441 return self.Parameters().GetAllEnforcedVertices()
443 ## To get all the enforced vertices sorted by face (or group, compound)
444 def GetAllEnforcedVerticesByFace(self):
445 return self.Parameters().GetAllEnforcedVerticesByFace()
447 ## To get all the enforced vertices sorted by coords of input vertices
448 def GetAllEnforcedVerticesByCoords(self):
449 return self.Parameters().GetAllEnforcedVerticesByCoords()
451 ## To get all the coords of input vertices sorted by face (or group, compound)
452 def GetAllCoordsByFace(self):
453 return self.Parameters().GetAllCoordsByFace()
455 ## To get all the enforced vertices on a face (or group, compound)
456 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
457 def GetEnforcedVertices(self, theFace):
458 from salome.smesh.smeshBuilder import AssureGeomPublished
459 AssureGeomPublished( self.mesh, theFace )
460 return self.Parameters().GetEnforcedVertices(theFace)
462 ## To clear all the enforced vertices
463 def ClearAllEnforcedVertices(self):
464 return self.Parameters().ClearAllEnforcedVertices()
466 ## 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.
467 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
468 # @param x : x coordinate
469 # @param y : y coordinate
470 # @param z : z coordinate
471 # @param vertexName : name of the enforced vertex
472 # @param groupName : name of the group
473 def SetEnforcedVertex(self, theFace, x, y, z, vertexName = "", groupName = ""):
474 from salome.smesh.smeshBuilder import AssureGeomPublished
475 AssureGeomPublished( self.mesh, theFace )
478 return self.Parameters().SetEnforcedVertex(theFace, x, y, z)
480 return self.Parameters().SetEnforcedVertexWithGroup(theFace, x, y, z, groupName)
484 return self.Parameters().SetEnforcedVertexNamed(theFace, x, y, z, vertexName)
486 return self.Parameters().SetEnforcedVertexNamedWithGroup(theFace, x, y, z, vertexName, groupName)
490 ## To set an enforced vertex on a face (or group, compound) given a GEOM vertex, group or compound.
491 # @param theFace : GEOM face (or group, compound) on which to define an enforced vertex
492 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
493 # @param groupName : name of the group
494 def SetEnforcedVertexGeom(self, theFace, theVertex, groupName = ""):
495 from salome.smesh.smeshBuilder import AssureGeomPublished
496 AssureGeomPublished( self.mesh, theFace )
497 AssureGeomPublished( self.mesh, theVertex )
499 return self.Parameters().SetEnforcedVertexGeom(theFace, theVertex)
501 return self.Parameters().SetEnforcedVertexGeomWithGroup(theFace, theVertex,groupName)
504 ## Set an enforced vertex on a face given the coordinates of a point.
505 # The face if found by the application.
506 # @param x : x coordinate
507 # @param y : y coordinate
508 # @param z : z coordinate
509 # @param vertexName : name of the enforced vertex
510 # @param groupName : name of the group
511 def AddEnforcedVertex(self, x, y, z, vertexName = "", groupName = ""):
512 from salome.smesh.smeshBuilder import AssureGeomPublished
515 return self.Parameters().AddEnforcedVertex(x, y, z)
517 return self.Parameters().AddEnforcedVertexWithGroup(x, y, z, groupName)
521 return self.Parameters().AddEnforcedVertexNamed(x, y, z, vertexName)
523 return self.Parameters().AddEnforcedVertexNamedWithGroup( x, y, z, vertexName, groupName)
527 ## To set an enforced vertex on a face given a GEOM vertex, group or compound.
528 # The face if found by the application.
529 # @param theVertex : GEOM vertex (or group, compound).
530 # @param groupName : name of the group
531 def AddEnforcedVertexGeom(self, theVertex, groupName = ""):
532 from salome.smesh.smeshBuilder import AssureGeomPublished
533 AssureGeomPublished( self.mesh, theVertex )
535 return self.Parameters().AddEnforcedVertexGeom(theVertex)
537 return self.Parameters().AddEnforcedVertexGeomWithGroup(theVertex,groupName)
540 ## To remove an enforced vertex on a given GEOM face (or group, compound) given the coordinates.
541 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
542 # @param x : x coordinate
543 # @param y : y coordinate
544 # @param z : z coordinate
545 def UnsetEnforcedVertex(self, theFace, x, y, z):
546 from salome.smesh.smeshBuilder import AssureGeomPublished
547 AssureGeomPublished( self.mesh, theFace )
548 return self.Parameters().UnsetEnforcedVertex(theFace, x, y, z)
550 ## To remove an enforced vertex on a given GEOM face (or group, compound) given a GEOM vertex, group or compound.
551 # @param theFace : GEOM face (or group, compound) on which to remove the enforced vertex
552 # @param theVertex : GEOM vertex (or group, compound) to remove.
553 def UnsetEnforcedVertexGeom(self, theFace, theVertex):
554 from salome.smesh.smeshBuilder import AssureGeomPublished
555 AssureGeomPublished( self.mesh, theFace )
556 AssureGeomPublished( self.mesh, theVertex )
557 return self.Parameters().UnsetEnforcedVertexGeom(theFace, theVertex)
559 ## To remove all enforced vertices on a given face.
560 # @param theFace : face (or group/compound of faces) on which to remove all enforced vertices
561 def UnsetEnforcedVertices(self, theFace):
562 from salome.smesh.smeshBuilder import AssureGeomPublished
563 AssureGeomPublished( self.mesh, theFace )
564 return self.Parameters().UnsetEnforcedVertices(theFace)
566 ## To tell BLSURF to add a node on internal vertices
567 # @param toEnforceInternalVertices : boolean; if True the internal vertices are added as enforced vertices
568 def SetInternalEnforcedVertexAllFaces(self, toEnforceInternalVertices):
569 return self.Parameters().SetInternalEnforcedVertexAllFaces(toEnforceInternalVertices)
571 ## To know if BLSURF will add a node on internal vertices
572 def GetInternalEnforcedVertexAllFaces(self):
573 return self.Parameters().GetInternalEnforcedVertexAllFaces()
575 ## To define a group for the nodes of internal vertices
576 # @param groupName : string; name of the group
577 def SetInternalEnforcedVertexAllFacesGroup(self, groupName):
578 return self.Parameters().SetInternalEnforcedVertexAllFacesGroup(groupName)
580 ## To get the group name of the nodes of internal vertices
581 def GetInternalEnforcedVertexAllFacesGroup(self):
582 return self.Parameters().GetInternalEnforcedVertexAllFacesGroup()
584 #-----------------------------------------
586 #-----------------------------------------
588 ## 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 ]
589 # @param theFace : face on which the attractor will be defined
590 # @param theAttractor : geometrical object from which the mesh size "h" decreases exponentially
591 # @param theStartSize : mesh size on theAttractor
592 # @param theEndSize : maximum size that will be reached on theFace
593 # @param theInfluenceDistance : influence of the attractor ( the size grow slower on theFace if it's high)
594 # @param theConstantSizeDistance : distance until which the mesh size will be kept constant on theFace
595 def SetAttractorGeom(self, theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance):
596 from salome.smesh.smeshBuilder import AssureGeomPublished
597 AssureGeomPublished( self.mesh, theFace )
598 AssureGeomPublished( self.mesh, theAttractor )
599 self.Parameters().SetAttractorGeom(theFace, theAttractor, theStartSize, theEndSize, theInfluenceDistance, theConstantSizeDistance)
602 ## Unsets an attractor on the chosen face.
603 # @param theFace : face on which the attractor has to be removed
604 def UnsetAttractorGeom(self, theFace):
605 from salome.smesh.smeshBuilder import AssureGeomPublished
606 AssureGeomPublished( self.mesh, theFace )
607 self.Parameters().SetAttractorGeom(theFace)
610 #-----------------------------------------
612 #-----------------------------------------
614 ## To set a size map on a face, edge or vertex (or group, compound) given Python function.
615 # If theObject is a face, the function can be: def f(u,v): return u+v
616 # If theObject is an edge, the function can be: def f(t): return t/2
617 # If theObject is a vertex, the function can be: def f(): return 10
618 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
619 # @param theSizeMap : Size map defined as a string
620 def SetSizeMap(self, theObject, theSizeMap):
621 from salome.smesh.smeshBuilder import AssureGeomPublished
622 AssureGeomPublished( self.mesh, theObject )
623 self.Parameters().SetSizeMap(theObject, theSizeMap)
626 ## To set a constant size map on a face, edge or vertex (or group, compound).
627 # @param theObject : GEOM face, edge or vertex (or group, compound) on which to define a size map
628 # @param theSizeMap : Size map defined as a double
629 def SetConstantSizeMap(self, theObject, theSizeMap):
630 from salome.smesh.smeshBuilder import AssureGeomPublished
631 AssureGeomPublished( self.mesh, theObject )
632 self.Parameters().SetConstantSizeMap(theObject, theSizeMap)
634 ## To remove a size map defined 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 def UnsetSizeMap(self, theObject):
637 from salome.smesh.smeshBuilder import AssureGeomPublished
638 AssureGeomPublished( self.mesh, theObject )
639 self.Parameters().UnsetSizeMap(theObject)
642 ## To remove all the size maps
643 def ClearSizeMaps(self):
644 self.Parameters().ClearSizeMaps()
647 ## Sets QuadAllowed flag.
648 # @param toAllow "allow quadrangles" flag value
649 def SetQuadAllowed(self, toAllow=True):
650 self.Parameters().SetQuadAllowed(toAllow)
653 ## Defines hypothesis having several parameters
654 # @return hypothesis object
655 def Parameters(self):
657 hypType = "MG-CADSurf Parameters"
658 hasGeom = self.mesh.GetMesh().HasShapeToMesh()
660 self.params = self.Hypothesis(hypType, [], LIBRARY, UseExisting=0)
662 self.params = self.Hypothesis(hypType + "_NOGEOM", [], LIBRARY, UseExisting=0)
663 self.mesh.smeshpyD.SetName( self.params, hypType )
667 #-----------------------------------------
668 # Periodicity (BLSURF with PreCAD)
669 #-----------------------------------------
671 ## Defines periodicity between two groups of faces, using PreCAD
672 # @param theFace1 : GEOM face (or group, compound) to associate with theFace2
673 # @param theFace2 : GEOM face (or group, compound) associated with theFace1
674 # @param theSourceVertices (optionnal): list of GEOM vertices on theFace1 defining the transformation from theFace1 to theFace2.
675 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
676 # @param theTargetVertices (optionnal): list of GEOM vertices on theFace2 defining the transformation from theFace1 to theFace2.
677 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
678 def AddPreCadFacesPeriodicity(self, theFace1, theFace2, theSourceVertices=[], theTargetVertices=[]):
679 """calls preCad function:
680 status_t cad_add_face_multiple_periodicity_with_transformation_function(cad t *cad,
681 integer *fid1, integer size1, integer *fid2, integer size2,
682 periodicity_transformation_t transf, void *user data);
684 if theSourceVertices and theTargetVertices:
685 self.Parameters().AddPreCadFacesPeriodicityWithVertices(theFace1, theFace2, theSourceVertices, theTargetVertices)
687 self.Parameters().AddPreCadFacesPeriodicity(theFace1, theFace2)
690 ## Defines periodicity between two groups of edges, using PreCAD
691 # @param theEdge1 : GEOM edge (or group, compound) to associate with theEdge2
692 # @param theEdge2 : GEOM edge (or group, compound) associated with theEdge1
693 # @param theSourceVertices (optionnal): list of GEOM vertices on theEdge1 defining the transformation from theEdge1 to theEdge2.
694 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
695 # @param theTargetVertices (optionnal): list of GEOM vertices on theEdge2 defining the transformation from theEdge1 to theEdge2.
696 # If None, PreCAD tries to find a simple translation. Else, need at least 3 not aligned vertices.
697 def AddPreCadEdgesPeriodicity(self, theEdge1, theEdge2, theSourceVertices=[], theTargetVertices=[]):
698 """calls preCad function:
699 status_t cad_add_edge_multiple_periodicity_with_transformation_function(cad t *cad,
700 integer *eid1, integer size1, integer *eid2, integer size2,
701 periodicity_transformation_t transf, void *user data);
703 if theSourceVertices and theTargetVertices:
704 self.Parameters().AddPreCadEdgesPeriodicityWithVertices(theEdge1, theEdge2, theSourceVertices, theTargetVertices)
706 self.Parameters().AddPreCadEdgesPeriodicity(theEdge1, theEdge2)
709 #-----------------------------------------
711 #-----------------------------------------
713 ## Defines hyper-patches. A hyper-patch is a set of adjacent faces meshed as a whole,
714 # ignoring edges between them
715 # @param hyperPatchList : list of hyper-patches. A hyper-patch is defined as a list of
716 # faces or groups of faces. A face can be identified either as a GEOM object or
717 # a face ID (returned e.g. by geompy.GetSubShapeID( mainShape, subShape )).
719 # Example: cadsurf.SetHyperPatches([[ Face_1, Group_2 ],[ 13, 23 ]])
720 def SetHyperPatches(self, hyperPatchList):
722 for patch in hyperPatchList:
725 if isinstance( face, int ):
727 elif isinstance( face, GEOM._objref_GEOM_Object):
728 faces = self.mesh.geompyD.SubShapeAll( face, self.mesh.geompyD.ShapeType["FACE"] )
730 ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
732 raise TypeError("Face of hyper-patch should be either ID or GEOM_Object, not %s" % type(face))
736 self.Parameters().SetHyperPatches( hpl )
739 #=====================
741 #=====================
746 ## Sets lower boundary of mesh element size (PhySize).
747 def SetPhyMin(self, theVal=-1):
749 Obsolete function. Use SetMinSize.
751 print("Warning: SetPhyMin is obsolete. Please use SetMinSize")
752 self.SetMinSize(theVal)
755 ## Sets upper boundary of mesh element size (PhySize).
756 def SetPhyMax(self, theVal=-1):
758 Obsolete function. Use SetMaxSize.
760 print("Warning: SetPhyMax is obsolete. Please use SetMaxSize")
761 self.SetMaxSize(theVal)
764 ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
765 def SetAngleMeshS(self, theVal=_geometric_approximation):
767 Obsolete function. Use SetAngleMesh.
769 print("Warning: SetAngleMeshS is obsolete. Please use SetAngleMesh")
770 self.SetAngleMesh(theVal)
773 ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
774 def SetAngleMeshC(self, theVal=_geometric_approximation):
776 Obsolete function. Use SetAngleMesh.
778 print("Warning: SetAngleMeshC is obsolete. Please use SetAngleMesh")
779 self.SetAngleMesh(theVal)
782 ## Sets lower boundary of mesh element size computed to respect angular deflection.
783 def SetGeoMin(self, theVal=-1):
785 Obsolete function. Use SetMinSize.
787 print("Warning: SetGeoMin is obsolete. Please use SetMinSize")
788 self.SetMinSize(theVal)
791 ## Sets upper boundary of mesh element size computed to respect angular deflection.
792 def SetGeoMax(self, theVal=-1):
794 Obsolete function. Use SetMaxSize.
796 print("Warning: SetGeoMax is obsolete. Please use SetMaxSize")
797 self.SetMaxSize(theVal)
801 pass # end of BLSURF_Algorithm class