1 # Copyright (C) 2007-2023 CEA/DEN, EDF R&D, OPEN CASCADE
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 Python API for the standard meshing plug-in module.
24 LIBRARY = "libStdMeshersEngine.so"
26 from salome.smesh.smesh_algorithm import Mesh_Algorithm
29 #----------------------------
30 # Mesh algo type identifiers
31 #----------------------------
33 REGULAR = "Regular_1D"
35 Algorithm type: Regular 1D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Segment`
40 Algorithm type: Python 1D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Segment_Python`
43 COMPOSITE = "CompositeSegment_1D"
45 Algorithm type: Composite segment 1D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_CompositeSegment`
50 Algorithm type: Hexahedron 3D (i-j-k) algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Hexahedron`
53 QUADRANGLE = "Quadrangle_2D"
55 Algorithm type: Quadrangle 2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Quadrangle`
58 RADIAL_QUAD = "RadialQuadrangle_1D2D"
60 Algorithm type: Radial Quadrangle 1D-2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_RadialQuadrangle1D2D`
63 QUAD_MA_PROJ = "QuadFromMedialAxis_1D2D"
65 Algorithm type: Quadrangle (Medial Axis Projection) 1D-2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_QuadMA_1D2D`
68 POLYGON = "PolygonPerFace_2D"
70 Algorithm type: Polygon Per Face 2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_PolygonPerFace`
73 POLYHEDRON = "PolyhedronPerSolid_3D"
75 Algorithm type: Polyhedron Per Solid 3D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_PolyhedronPerSolid`
78 # import items of enums
79 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
80 for e in StdMeshers.VLExtrusionMethod._items: exec('%s = StdMeshers.%s'%(e,e))
82 #----------------------
84 #----------------------
86 class StdMeshersBuilder_Segment(Mesh_Algorithm):
88 Defines segment 1D algorithm for edges discretization.
90 It can be created by calling smeshBuilder.Mesh.Segment(geom=0)
94 meshMethod = "Segment"
96 name of the dynamic method in smeshBuilder.Mesh class
101 type of algorithm used with helper function in smeshBuilder.Mesh class
106 flag pointing whether this algorithm should be used by default in dynamic method
107 of smeshBuilder.Mesh class
110 docHelper = "Create segment 1D algorithm for edges"
112 doc string of the method
115 def __init__(self, mesh, geom=0):
119 mesh: parent mesh object algorithm is assigned to
120 geom: geometry (shape/sub-shape) algorithm is assigned to;
121 if it is :code:`0` (default), the algorithm is assigned to the main shape
123 Mesh_Algorithm.__init__(self)
124 self.Create(mesh, geom, self.algoType)
127 def LocalLength(self, l, UseExisting=0, p=1e-07):
129 Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
132 l : for the length of segments that cut an edge
133 UseExisting : if == true - searches for an existing hypothesis created with
134 the same parameters, else (default) - Create a new one
135 p : precision, used for calculation of the number of segments.
136 The precision should be a positive, meaningful value within the range [0,1].
137 In general, the number of segments is calculated with the formula:
138 nb = ceil((edge_length / l) - p)
139 Function ceil rounds its argument to the higher integer.
140 So, p=0 means rounding of (edge_length / l) to the higher integer,
141 p=0.5 means rounding of (edge_length / l) to the nearest integer,
142 p=1 means rounding of (edge_length / l) to the lower integer.
143 Default value is 1e-07.
146 an instance of StdMeshers_LocalLength hypothesis
149 from salome.smesh.smeshBuilder import IsEqual
150 comFun=lambda hyp, args: IsEqual(hyp.GetLength(), args[0]) and IsEqual(hyp.GetPrecision(), args[1])
151 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting, CompareMethod=comFun)
156 def MaxSize(self, length=0.0, UseExisting=0):
158 Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
161 length : is optional maximal allowed length of segment, if it is omitted
162 the preestimated length is used that depends on geometry size
163 UseExisting : if ==true - searches for an existing hypothesis created with
164 the same parameters, else (default) - Create a new one
167 an instance of StdMeshers_MaxLength hypothesis
171 hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
172 if isinstance(length,str) or length > 0:
174 hyp.SetLength(length)
176 # set preestimated length
178 gen = self.mesh.smeshpyD
179 initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
180 self.mesh.GetMesh(), self.mesh.GetShape(),
181 SMESH.HypInitParams( 1, 1.0, False ))
182 preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
184 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
187 hyp.SetUsePreestimatedLength( length == 0.0 )
190 def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
192 Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
195 n: for the number of segments that cut an edge
196 s: for the scale factor (optional)
197 reversedEdges: is a list of edges to mesh using reversed orientation.
198 A list item can also be a tuple (edge, 1st_vertex_of_edge)
199 UseExisting: if ==true - searches for an existing hypothesis created with
200 the same parameters, else (default) - create a new one
203 an instance of StdMeshers_NumberOfSegments hypothesis
207 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
208 reversedEdges, UseExisting = [], reversedEdges
209 entry = self.MainShapeEntry()
210 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
212 hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
213 UseExisting=UseExisting,
214 CompareMethod=self._compareNumberOfSegments)
216 hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
217 UseExisting=UseExisting,
218 CompareMethod=self._compareNumberOfSegments)
219 hyp.SetScaleFactor(s)
220 hyp.SetNumberOfSegments(n)
221 hyp.SetReversedEdges( reversedEdgeInd )
222 hyp.SetObjectEntry( entry )
225 def _compareNumberOfSegments(self, hyp, args):
228 Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
230 if hyp.GetNumberOfSegments() == args[0]:
232 if hyp.GetReversedEdges() == args[1]:
233 if not args[1] or hyp.GetObjectEntry() == args[2]:
236 from salome.smesh.smeshBuilder import IsEqual
237 if hyp.GetReversedEdges() == args[2]:
238 if not args[2] or hyp.GetObjectEntry() == args[3]:
239 if hyp.GetDistrType() == 1:
240 if IsEqual(hyp.GetScaleFactor(), args[1]):
244 def Adaptive(self, minSize, maxSize, deflection, UseExisting=False):
246 Defines "Adaptive" hypothesis to cut an edge into segments keeping segment size
247 within the given range and considering (1) deflection of segments from the edge
248 and (2) distance from segments to closest edges and faces to have segment length
249 not longer than two times shortest distances to edges and faces.
252 minSize: defines the minimal allowed segment length
253 maxSize: defines the maximal allowed segment length
254 deflection: defines the maximal allowed distance from a segment to an edge
255 UseExisting: if ==true - searches for an existing hypothesis created with
256 the same parameters, else (default) - Create a new one
259 an instance of StdMeshers_Adaptive1D hypothesis
262 from salome.smesh.smeshBuilder import IsEqual
263 compFun = lambda hyp, args: ( IsEqual(hyp.GetMinSize(), args[0]) and \
264 IsEqual(hyp.GetMaxSize(), args[1]) and \
265 IsEqual(hyp.GetDeflection(), args[2]))
266 hyp = self.Hypothesis("Adaptive1D", [minSize, maxSize, deflection],
267 UseExisting=UseExisting, CompareMethod=compFun)
268 hyp.SetMinSize(minSize)
269 hyp.SetMaxSize(maxSize)
270 hyp.SetDeflection(deflection)
273 def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
275 Defines "Arithmetic1D" hypothesis to cut an edge in several segments with a length
276 that changes in arithmetic progression
279 start: defines the length of the first segment
280 end: defines the length of the last segment
281 reversedEdges: is a list of edges to mesh using reversed orientation.
282 A list item can also be a tuple (edge, 1st_vertex_of_edge)
283 UseExisting: if ==true - searches for an existing hypothesis created with
284 the same parameters, else (default) - Create a new one
287 an instance of StdMeshers_Arithmetic1D hypothesis
290 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
291 reversedEdges, UseExisting = [], reversedEdges
292 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
293 entry = self.MainShapeEntry()
294 from salome.smesh.smeshBuilder import IsEqual
295 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
296 IsEqual(hyp.GetLength(0), args[1]) and \
297 hyp.GetReversedEdges() == args[2] and \
298 (not args[2] or hyp.GetObjectEntry() == args[3]))
299 hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
300 UseExisting=UseExisting, CompareMethod=compFun)
301 hyp.SetStartLength(start)
302 hyp.SetEndLength(end)
303 hyp.SetReversedEdges( reversedEdgeInd )
304 hyp.SetObjectEntry( entry )
307 def GeometricProgression(self, start, ratio, reversedEdges=[], UseExisting=0):
309 Defines "GeometricProgression" hypothesis to cut an edge in several
310 segments with a length that changes in Geometric progression
313 start: defines the length of the first segment
314 ratio: defines the common ratio of the geometric progression
315 reversedEdges: is a list of edges to mesh using reversed orientation.
316 A list item can also be a tuple (edge, 1st_vertex_of_edge)
317 UseExisting: if ==true - searches for an existing hypothesis created with
318 the same parameters, else (default) - Create a new one
321 an instance of StdMeshers_Geometric1D hypothesis
324 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
325 entry = self.MainShapeEntry()
326 from salome.smesh.smeshBuilder import IsEqual
327 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
328 IsEqual(hyp.GetLength(0), args[1]) and \
329 hyp.GetReversedEdges() == args[2] and \
330 (not args[2] or hyp.GetObjectEntry() == args[3]))
331 hyp = self.Hypothesis("GeometricProgression", [start, ratio, reversedEdgeInd, entry],
332 UseExisting=UseExisting, CompareMethod=compFun)
333 hyp.SetStartLength( start )
334 hyp.SetCommonRatio( ratio )
335 hyp.SetReversedEdges( reversedEdgeInd )
336 hyp.SetObjectEntry( entry )
339 def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
341 Defines "FixedPoints1D" hypothesis to cut an edge using parameter
342 on curve from 0 to 1 (additionally it is neecessary to check
343 orientation of edges and create list of reversed edges if it is
344 needed) and sets numbers of segments between given points (default
348 points: defines the list of parameters on curve
349 nbSegs: defines the list of numbers of segments
350 reversedEdges: is a list of edges to mesh using reversed orientation.
351 A list item can also be a tuple (edge, 1st_vertex_of_edge)
352 UseExisting: if ==true - searches for an existing hypothesis created with
353 the same parameters, else (default) - Create a new one
356 an instance of StdMeshers_FixedPoints1D hypothesis
359 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
360 reversedEdges, UseExisting = [], reversedEdges
361 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
362 entry = self.MainShapeEntry()
363 compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
364 hyp.GetNbSegments() == args[1] and \
365 hyp.GetReversedEdges() == args[2] and \
366 (not args[2] or hyp.GetObjectEntry() == args[3]))
367 hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
368 UseExisting=UseExisting, CompareMethod=compFun)
369 hyp.SetPoints(points)
370 hyp.SetNbSegments(nbSegs)
371 hyp.SetReversedEdges(reversedEdgeInd)
372 hyp.SetObjectEntry(entry)
375 def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
377 Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
380 start: defines the length of the first segment
381 end: defines the length of the last segment
382 reversedEdges: is a list of edges to mesh using reversed orientation.
383 A list item can also be a tuple (edge, 1st_vertex_of_edge)
384 UseExisting: if ==true - searches for an existing hypothesis created with
385 the same parameters, else (default) - Create a new one
388 an instance of StdMeshers_StartEndLength hypothesis
391 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
392 reversedEdges, UseExisting = [], reversedEdges
393 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
394 entry = self.MainShapeEntry()
395 from salome.smesh.smeshBuilder import IsEqual
396 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
397 IsEqual(hyp.GetLength(0), args[1]) and \
398 hyp.GetReversedEdges() == args[2] and \
399 (not args[2] or hyp.GetObjectEntry() == args[3]))
400 hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
401 UseExisting=UseExisting, CompareMethod=compFun)
402 hyp.SetStartLength(start)
403 hyp.SetEndLength(end)
404 hyp.SetReversedEdges( reversedEdgeInd )
405 hyp.SetObjectEntry( entry )
408 def Deflection1D(self, d, UseExisting=0):
410 Defines "Deflection1D" hypothesis
413 d: for the deflection
414 UseExisting: if ==true - searches for an existing hypothesis created with
415 the same parameters, else (default) - create a new one
418 from salome.smesh.smeshBuilder import IsEqual
419 compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
420 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
424 def Propagation(self):
426 Defines "Propagation" hypothesis that propagates 1D hypotheses
427 from an edge where this hypothesis is assigned to
428 on all other edges that are at the opposite side in case of quadrangular faces
429 This hypothesis should be assigned to an edge to propagate a hypothesis from.
432 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
434 def PropagationOfDistribution(self):
436 Defines "Propagation of Node Distribution" hypothesis that propagates
437 distribution of nodes from an edge where this hypothesis is assigned to,
438 to opposite edges of quadrangular faces, so that number of segments on all these
439 edges will be the same, as well as relations between segment lengths.
442 return self.Hypothesis("PropagOfDistribution", UseExisting=1,
443 CompareMethod=self.CompareEqualHyp)
445 def AutomaticLength(self, fineness=0, UseExisting=0):
447 Defines "AutomaticLength" hypothesis
450 fineness: for the fineness [0-1]
451 UseExisting: if ==true - searches for an existing hypothesis created with the
452 same parameters, else (default) - create a new one
455 from salome.smesh.smeshBuilder import IsEqual
456 compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
457 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
458 CompareMethod=compFun)
459 hyp.SetFineness( fineness )
462 def LengthNearVertex(self, length, vertex=-1, UseExisting=0):
464 Defines "SegmentLengthAroundVertex" hypothesis
467 length: for the segment length
468 vertex: for the length localization: the vertex index [0,1] | vertex object.
469 Any other integer value means that the hypothesis will be set on the
470 whole 1D shape, where Mesh_Segment algorithm is assigned.
471 UseExisting: if ==true - searches for an existing hypothesis created with
472 the same parameters, else (default) - Create a new one
476 store_geom = self.geom
477 if isinstance(vertex, int):
478 if vertex == 0 or vertex == 1:
479 from salome.geom import geomBuilder
480 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geomBuilder.geomBuilder.ShapeType["VERTEX"],True)[vertex]
488 if self.geom is None:
489 self.geom = store_geom
490 raise RuntimeError("Attempt to create SegmentAroundVertex_0D algorithm on None shape")
491 from salome.smesh.smeshBuilder import AssureGeomPublished, GetName, TreatHypoStatus
492 AssureGeomPublished( self.mesh, self.geom )
493 name = GetName(self.geom)
495 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
497 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
499 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
500 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True, self.mesh)
502 from salome.smesh.smeshBuilder import IsEqual
503 comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
504 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
505 CompareMethod=comFun)
506 self.geom = store_geom
507 hyp.SetLength( length )
510 def QuadraticMesh(self):
512 Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
513 If the 2D mesher sees that all boundary edges are quadratic,
514 it generates quadratic faces, else it generates linear faces using
515 medium nodes as if they are vertices.
516 The 3D mesher generates quadratic volumes only if all boundary faces
517 are quadratic, else it fails.
520 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
523 pass # end of StdMeshersBuilder_Segment class
525 class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
527 Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
529 It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.COMPOSITE,geom=0)
533 meshMethod = "Segment"
535 name of the dynamic method in smeshBuilder.Mesh class
540 type of algorithm used with helper function in smeshBuilder.Mesh class
545 flag pointing whether this algorithm should be used by default in dynamic method
546 of smeshBuilder.Mesh class
549 docHelper = "Create segment 1D algorithm for edges"
551 doc string of the method
554 def __init__(self, mesh, geom=0):
559 mesh: parent mesh object algorithm is assigned to
560 geom: geometry (shape/sub-shape) algorithm is assigned to;
561 if it is :code:`0` (default), the algorithm is assigned to the main shape
563 self.Create(mesh, geom, self.algoType)
566 pass # end of StdMeshersBuilder_CompositeSegment class
568 class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
570 Defines a segment 1D algorithm for discretization of edges with Python function.
571 It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.PYTHON,geom=0)
575 meshMethod = "Segment"
577 name of the dynamic method in smeshBuilder.Mesh class
581 type of algorithm used with helper function in smeshBuilder.Mesh class
583 docHelper = "Create segment 1D algorithm for edges"
585 doc string of the method
588 def __init__(self, mesh, geom=0):
593 mesh: parent mesh object algorithm is assigned to
594 geom: geometry (shape/sub-shape) algorithm is assigned to;
595 if it is :code:`0` (default), the algorithm is assigned to the main shape
597 import Python1dPlugin
598 self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
601 def PythonSplit1D(self, n, func, UseExisting=0):
603 Defines "PythonSplit1D" hypothesis
606 n: for the number of segments that cut an edge
607 func: for the python function that calculates the length of all segments
608 UseExisting: if ==true - searches for the existing hypothesis created with
609 the same parameters, else (default) - Create a new one
612 compFun = lambda hyp, args: False
613 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
614 UseExisting=UseExisting, CompareMethod=compFun)
615 hyp.SetNumberOfSegments(n)
616 hyp.SetPythonLog10RatioFunction(func)
619 pass # end of StdMeshersBuilder_Segment_Python class
621 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
623 Defines a quadrangle 2D algorithm.
624 It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
628 meshMethod = "Quadrangle"
630 name of the dynamic method in smeshBuilder.Mesh class
632 algoType = QUADRANGLE
634 type of algorithm used with helper function in smeshBuilder.Mesh class
638 flag pointing whether this algorithm should be used by default in dynamic method
639 of smeshBuilder.Mesh class
641 docHelper = "Create quadrangle 2D algorithm for faces"
643 doc string of the method
647 hypothesis associated with algorithm
650 def __init__(self, mesh, geom=0):
655 mesh: parent mesh object algorithm is assigned to
656 geom: geometry (shape/sub-shape) algorithm is assigned to;
657 if it is :code:`0` (default), the algorithm is assigned to the main shape
659 Mesh_Algorithm.__init__(self)
660 self.Create(mesh, geom, self.algoType)
663 def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0,
664 enfVertices=[],enfPoints=[],corners=[],UseExisting=0):
666 Defines "QuadrangleParameters" hypothesis
667 quadType defines the algorithm of transition between differently descretized
668 sides of a geometrical face:
670 - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
671 area along the finer meshed sides.
672 - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
674 - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
675 the finer meshed sides, iff the total quantity of segments on
676 all four sides of the face is even (divisible by 2).
677 - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
678 area is located along the coarser meshed sides.
679 - QUAD_REDUCED - only quadrangles are built and the transition between the sides
680 is made gradually, layer by layer. This type has a limitation on
681 the number of segments: one pair of opposite sides must have the
682 same number of segments, the other pair must have an even difference
683 between the numbers of segments on the sides.
686 triangleVertex: vertex of a trilateral geometrical face, around which triangles
687 will be created while other elements will be quadrangles.
688 Vertex can be either a GEOM_Object or a vertex ID within the
690 enfVertices: list of shapes defining positions where nodes (enforced nodes)
691 must be created by the mesher. Shapes can be of any type,
692 vertices of given shapes define positions of enforced nodes.
693 Only vertices successfully projected to the face are used.
694 enfPoints: list of points giving positions of enforced nodes.
695 Point can be defined either as SMESH.PointStruct's
696 ([SMESH.PointStruct(x1,y1,z1), SMESH.PointStruct(x2,y2,z2),...])
697 or triples of values ([[x1,y1,z1], [x2,y2,z2], ...]).
698 In the case if the defined QuadrangleParameters() refer to a sole face,
699 all given points must lie on this face, else the mesher fails.
700 corners: list of vertices that should be used as quadrangle corners.
701 The parameter can be useful for faces with more than four vertices,
702 since in some cases Quadrangle Mapping algorithm chooses corner vertices
703 differently than it is desired.
704 A hypothesis can be global and define corners for all CAD faces that
705 require it, but be sure that each specified vertex is a corner in all
706 faces the hypothesis will be applied to.
707 UseExisting: if *True* - searches for the existing hypothesis created with
708 the same parameters, else (default) - Create a new one
713 vertexID = triangleVertex
714 if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
715 vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
716 if isinstance( enfVertices, int ) and not enfPoints and not UseExisting:
717 # a call of old syntax, before inserting enfVertices and enfPoints before UseExisting
718 UseExisting, enfVertices = enfVertices, []
720 pStructs, xyz = [], []
722 if isinstance( p, SMESH.PointStruct ):
723 xyz.append(( p.x, p.y, p.z ))
726 xyz.append(( p[0], p[1], p[2] ))
727 pStructs.append( SMESH.PointStruct( p[0], p[1], p[2] ))
729 compFun = lambda hyp,args: \
730 hyp.GetQuadType() == args[0] and \
731 (hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1)) and \
732 ((hyp.GetEnforcedNodes()) == (args[2],args[3])) # True w/o enfVertices only
733 entries = [ shape.GetStudyEntry() for shape in enfVertices ]
734 self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID,entries,xyz],
735 UseExisting = UseExisting, CompareMethod=compFun)
738 if corners and isinstance( corners[0], GEOM._objref_GEOM_Object ):
739 corners = [ self.mesh.geompyD.GetSubShapeID( self.mesh.geom, v ) for v in corners ]
741 if self.params.GetQuadType() != quadType:
742 self.params.SetQuadType(quadType)
744 self.params.SetTriaVertex( vertexID )
745 from salome.smesh.smeshBuilder import AssureGeomPublished
746 for v in enfVertices:
747 AssureGeomPublished( self.mesh, v )
748 self.params.SetEnforcedNodes( enfVertices, pStructs )
749 self.params.SetCorners( corners )
752 def QuadranglePreference(self, reversed=False, UseExisting=0):
754 Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
755 quadrangles are built in the transition area along the finer meshed sides,
756 if the total quantity of segments on all four sides of the face is even.
759 reversed: if True, transition area is located along the coarser meshed sides.
760 UseExisting: if ==true - searches for the existing hypothesis created with
761 the same parameters, else (default) - Create a new one
765 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
766 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
768 def TrianglePreference(self, UseExisting=0):
770 Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
771 triangles are built in the transition area along the finer meshed sides.
774 UseExisting: if ==true - searches for the existing hypothesis created with
775 the same parameters, else (default) - Create a new one
778 return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
780 def Reduced(self, UseExisting=0):
782 Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
783 quadrangles are built and the transition between the sides is made gradually,
784 layer by layer. This type has a limitation on the number of segments: one pair
785 of opposite sides must have the same number of segments, the other pair must
786 have an even difference between the numbers of segments on the sides.
789 UseExisting: if ==true - searches for the existing hypothesis created with
790 the same parameters, else (default) - Create a new one
793 return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
795 def TriangleVertex(self, vertex, UseExisting=0):
797 Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
800 vertex: vertex of a trilateral geometrical face, around which triangles
801 will be created while other elements will be quadrangles.
802 Vertex can be either a GEOM_Object or a vertex ID within the
804 UseExisting: if ==true - searches for the existing hypothesis created with
805 the same parameters, else (default) - Create a new one
808 return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
810 pass # end of StdMeshersBuilder_Quadrangle class
812 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
814 Defines a hexahedron 3D algorithm.
815 It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
819 meshMethod = "Hexahedron"
821 name of the dynamic method in smeshBuilder.Mesh class
825 type of algorithm used with helper function in smeshBuilder.Mesh class
829 flag pointing whether this algorithm should be used by default in dynamic method
830 of smeshBuilder.Mesh class
832 docHelper = "Create hexahedron 3D algorithm for volumes"
834 doc string of the method
837 def __init__(self, mesh, geom=0):
842 mesh: parent mesh object algorithm is assigned to
843 geom: geometry (shape/sub-shape) algorithm is assigned to;
844 if it is :code:`0` (default), the algorithm is assigned to the main shape
846 Mesh_Algorithm.__init__(self)
847 self.Create(mesh, geom, Hexa)
848 self.renumHypothesis = 0
851 def Renumber(self, blockCSList=[] ):
852 if isinstance( blockCSList, StdMeshers.BlockCS ):
853 blockCSList = [blockCSList]
854 if not self.renumHypothesis:
855 self.renumHypothesis = self.Hypothesis("BlockRenumber", blockCSList, UseExisting=0)
856 self.renumHypothesis.SetBlocksOrientation( blockCSList )
857 return self.renumHypothesis
859 pass # end of StdMeshersBuilder_Hexahedron class
861 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
863 Defines a projection 1D algorithm.
864 It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
868 meshMethod = "Projection1D"
870 name of the dynamic method in smeshBuilder.Mesh class
872 algoType = "Projection_1D"
874 type of algorithm used with helper function in smeshBuilder.Mesh class
878 flag pointing whether this algorithm should be used by default in dynamic method
879 of smeshBuilder.Mesh class
881 docHelper = "Create projection 1D algorithm for edges"
883 doc string of the method
885 def __init__(self, mesh, geom=0):
890 mesh: parent mesh object algorithm is assigned to
891 geom: geometry (shape/sub-shape) algorithm is assigned to;
892 if it is :code:`0` (default), the algorithm is assigned to the main shape
894 Mesh_Algorithm.__init__(self)
895 self.Create(mesh, geom, self.algoType)
898 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
900 Defines "Source Edge" hypothesis, specifying a meshed edge, from where
901 a mesh pattern is taken, and, optionally, the association of vertices
902 between the source edge and a target edge (to which a hypothesis is assigned)
905 edge: from which nodes distribution is taken
906 mesh: from which nodes distribution is taken (optional)
907 srcV: a vertex of *edge* to associate with *tgtV* (optional)
908 tgtV: a vertex of *the edge* to which the algorithm is assigned, to associate with *srcV* (optional)
909 UseExisting: if ==true - searches for the existing hypothesis created with
910 the same parameters, else (default) - Create a new one
912 from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
913 AssureGeomPublished( self.mesh, edge )
914 AssureGeomPublished( self.mesh, srcV )
915 AssureGeomPublished( self.mesh, tgtV )
916 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
918 # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
919 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
920 hyp.SetSourceEdge( edge )
921 if not mesh is None and isinstance(mesh, Mesh):
922 mesh = mesh.GetMesh()
923 hyp.SetSourceMesh( mesh )
924 hyp.SetVertexAssociation( srcV, tgtV )
927 pass # end of StdMeshersBuilder_Projection1D class
929 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
931 Defines a projection 2D algorithm.
932 It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
936 meshMethod = "Projection2D"
938 name of the dynamic method in smeshBuilder.Mesh class
940 algoType = "Projection_2D"
942 type of algorithm used with helper function in smeshBuilder.Mesh class
946 flag pointing whether this algorithm should be used by default in dynamic method
947 of smeshBuilder.Mesh class
949 docHelper = "Create projection 2D algorithm for faces"
951 doc string of the method
954 def __init__(self, mesh, geom=0):
959 mesh: parent mesh object algorithm is assigned to
960 geom: geometry (shape/sub-shape) algorithm is assigned to;
961 if it is :code:`0` (default), the algorithm is assigned to the main shape
963 Mesh_Algorithm.__init__(self)
964 self.Create(mesh, geom, self.algoType)
968 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
969 srcV2=None, tgtV2=None, UseExisting=0):
971 Defines "Source Face" hypothesis, specifying a meshed face, from where
972 a mesh pattern is taken, and, optionally, the association of vertices
973 between the source face and the target face (to which a hypothesis is assigned)
976 face: from which the mesh pattern is taken
977 mesh: from which the mesh pattern is taken (optional)
978 srcV1: a vertex of *face* to associate with *tgtV1* (optional)
979 tgtV1: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV1* (optional)
980 srcV2: a vertex of *face* to associate with *tgtV1* (optional)
981 tgtV2: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV2* (optional)
982 UseExisting: if ==true - forces the search for the existing hypothesis created with
983 he same parameters, else (default) - forces the creation a new one
986 all association vertices must belong to one edge of a face
988 from salome.smesh.smeshBuilder import Mesh
989 if isinstance(mesh, Mesh):
990 mesh = mesh.GetMesh()
991 for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
992 from salome.smesh.smeshBuilder import AssureGeomPublished
993 AssureGeomPublished( self.mesh, geom )
994 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
995 UseExisting=0, toAdd=False)
996 # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
997 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
998 hyp.SetSourceFace( face )
999 hyp.SetSourceMesh( mesh )
1000 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1001 self.mesh.AddHypothesis(hyp, self.geom)
1004 pass # end of StdMeshersBuilder_Projection2D class
1006 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
1008 Defines a projection 1D-2D algorithm.
1009 It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
1013 meshMethod = "Projection1D2D"
1015 name of the dynamic method in smeshBuilder.Mesh class
1017 algoType = "Projection_1D2D"
1019 type of algorithm used with helper function in smeshBuilder.Mesh class
1021 docHelper = "Create projection 1D-2D algorithm for faces"
1023 doc string of the method
1026 def __init__(self, mesh, geom=0):
1028 Private constructor.
1031 mesh: parent mesh object algorithm is assigned to
1032 geom: geometry (shape/sub-shape) algorithm is assigned to;
1033 if it is :code:`0` (default), the algorithm is assigned to the main shape
1035 StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
1038 pass # end of StdMeshersBuilder_Projection1D2D class
1040 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
1042 Defines a projection 3D algorithm.
1043 It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
1047 meshMethod = "Projection3D"
1049 name of the dynamic method in smeshBuilder.Mesh class
1051 algoType = "Projection_3D"
1053 type of algorithm used with helper function in smeshBuilder.Mesh class
1055 docHelper = "Create projection 3D algorithm for volumes"
1057 doc string of the method
1060 def __init__(self, mesh, geom=0):
1062 Private constructor.
1065 mesh: parent mesh object algorithm is assigned to
1066 geom" geometry (shape/sub-shape) algorithm is assigned to;
1067 if it is :code:`0` (default), the algorithm is assigned to the main shape
1069 Mesh_Algorithm.__init__(self)
1070 self.Create(mesh, geom, self.algoType)
1073 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1074 srcV2=0, tgtV2=0, UseExisting=0):
1076 Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
1077 the mesh pattern is taken, and, optionally, the association of vertices
1078 between the source and the target solid (to which a hipothesis is assigned)
1081 solid: from where the mesh pattern is taken
1082 mesh: from where the mesh pattern is taken (optional)
1083 srcV1: a vertex of *solid* to associate with *tgtV1* (optional)
1084 tgtV1: a vertex of *the solid* where the algorithm is assigned, to associate with *srcV1* (optional)
1085 srcV2: a vertex of *solid* to associate with *tgtV1* (optional)
1086 tgtV2: a vertex of *the solid* to which the algorithm is assigned,to associate with *srcV2* (optional)
1087 UseExisting: if ==true - searches for the existing hypothesis created with
1088 the same parameters, else (default) - Create a new one
1091 association vertices must belong to one edge of a solid
1093 for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
1094 from salome.smesh.smeshBuilder import AssureGeomPublished
1095 AssureGeomPublished( self.mesh, geom )
1096 hyp = self.Hypothesis("ProjectionSource3D",
1097 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1099 # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
1100 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
1101 hyp.SetSource3DShape( solid )
1102 from salome.smesh.smeshBuilder import Mesh
1103 if isinstance(mesh, Mesh):
1104 mesh = mesh.GetMesh()
1106 hyp.SetSourceMesh( mesh )
1107 if srcV1 and srcV2 and tgtV1 and tgtV2:
1108 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1109 #elif srcV1 or srcV2 or tgtV1 or tgtV2:
1112 pass # end of StdMeshersBuilder_Projection3D class
1114 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
1116 Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism" depending on geometry.
1117 It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1121 meshMethod = "Prism"
1123 name of the dynamic method in smeshBuilder.Mesh class
1125 algoType = "Prism_3D"
1127 type of algorithm used with helper function in smeshBuilder.Mesh class
1129 docHelper = "Create prism 3D algorithm for volumes"
1131 doc string of the method
1135 flag pointing whether this algorithm should be used by default in dynamic method
1136 of smeshBuilder.Mesh class
1139 def __init__(self, mesh, geom=0):
1141 Private constructor.
1144 mesh: parent mesh object algorithm is assigned to
1145 geom: geometry (shape/sub-shape) algorithm is assigned to;
1146 if it is :code:`0` (default), the algorithm is assigned to the main shape
1148 Mesh_Algorithm.__init__(self)
1153 isRadial = mesh.smeshpyD.IsApplicable("RadialPrism_3D", LIBRARY, shape, False )
1155 self.Create(mesh, geom, "Prism_3D")
1158 self.algoType = "RadialPrism_3D"
1159 self.Create(mesh, geom, "RadialPrism_3D")
1160 self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
1161 self.nbLayers = None
1165 def Get3DHypothesis(self):
1168 3D hypothesis holding the 1D one
1170 if self.algoType != "RadialPrism_3D":
1171 print("Prism_3D algorithm doesn't support any hypothesis")
1173 return self.distribHyp
1175 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1177 Private method creating a 1D hypothesis and storing it in the LayerDistribution
1181 the created hypothesis
1183 if self.algoType != "RadialPrism_3D":
1184 print("Prism_3D algorithm doesn't support any hypothesis")
1186 if not self.nbLayers is None:
1187 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1188 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1189 self.mesh.smeshpyD.SetEnablePublish( False ) # prevents publishing own 1D hypothesis
1190 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1191 self.mesh.smeshpyD.SetEnablePublish( True ) # enables publishing
1192 if not self.distribHyp:
1193 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1194 self.distribHyp.SetLayerDistribution( hyp )
1197 def NumberOfLayers(self, n, UseExisting=0):
1199 Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1200 prisms to build between the inner and outer shells
1204 UseExisting: if ==true - searches for the existing hypothesis created with
1205 the same parameters, else (default) - Create a new one
1207 if self.algoType != "RadialPrism_3D":
1208 print("Prism_3D algorithm doesn't support any hypothesis")
1210 self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1211 from salome.smesh.smeshBuilder import IsEqual
1212 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1213 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1214 CompareMethod=compFun)
1215 self.nbLayers.SetNumberOfLayers( n )
1216 return self.nbLayers
1218 def LocalLength(self, l, p=1e-07):
1220 Defines "LocalLength" hypothesis, specifying the segment length
1221 to build between the inner and the outer shells
1224 l: the length of segments
1225 p: the precision of rounding
1227 if self.algoType != "RadialPrism_3D":
1228 print("Prism_3D algorithm doesn't support any hypothesis")
1230 hyp = self.OwnHypothesis("LocalLength", [l,p])
1235 def NumberOfSegments(self, n, s=[]):
1237 Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1238 prisms to build between the inner and the outer shells.
1241 n: the number of layers
1242 s: the scale factor (optional)
1244 if self.algoType != "RadialPrism_3D":
1245 print("Prism_3D algorithm doesn't support any hypothesis")
1248 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1250 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1251 hyp.SetScaleFactor(s)
1252 hyp.SetNumberOfSegments(n)
1255 def Arithmetic1D(self, start, end ):
1257 Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1258 to build between the inner and the outer shells with a length that changes
1259 in arithmetic progression
1262 start: the length of the first segment
1263 end: the length of the last segment
1265 if self.algoType != "RadialPrism_3D":
1266 print("Prism_3D algorithm doesn't support any hypothesis")
1268 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1269 hyp.SetLength(start, 1)
1270 hyp.SetLength(end , 0)
1273 def GeometricProgression(self, start, ratio ):
1275 Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1276 to build between the inner and the outer shells with a length that changes
1277 in Geometric progression
1280 start: the length of the first segment
1281 ratio: the common ratio of the geometric progression
1283 if self.algoType != "RadialPrism_3D":
1284 print("Prism_3D algorithm doesn't support any hypothesis")
1286 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1287 hyp.SetStartLength( start )
1288 hyp.SetCommonRatio( ratio )
1291 def StartEndLength(self, start, end):
1293 Defines "StartEndLength" hypothesis, specifying distribution of segments
1294 to build between the inner and the outer shells as geometric length increasing
1297 start: for the length of the first segment
1298 end: for the length of the last segment
1300 if self.algoType != "RadialPrism_3D":
1301 print("Prism_3D algorithm doesn't support any hypothesis")
1303 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1304 hyp.SetLength(start, 1)
1305 hyp.SetLength(end , 0)
1308 def AutomaticLength(self, fineness=0):
1310 Defines "AutomaticLength" hypothesis, specifying the number of segments
1311 to build between the inner and outer shells
1314 fineness: defines the quality of the mesh within the range [0-1]
1316 if self.algoType != "RadialPrism_3D":
1317 print("Prism_3D algorithm doesn't support any hypothesis")
1319 hyp = self.OwnHypothesis("AutomaticLength")
1320 hyp.SetFineness( fineness )
1323 pass # end of StdMeshersBuilder_Prism3D class
1325 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1327 Defines Radial Prism 3D algorithm.
1328 It is created by calling smeshBuilder.Mesh.Prism(geom=0).
1329 See :class:`StdMeshersBuilder_Prism3D` for methods defining distribution of mesh layers
1330 build between the inner and outer shells.
1333 meshMethod = "Prism"
1335 name of the dynamic method in smeshBuilder.Mesh class
1337 algoType = "RadialPrism_3D"
1339 type of algorithm used with helper function in smeshBuilder.Mesh class
1341 docHelper = "Create Raial Prism 3D algorithm for volumes"
1343 doc string of the method
1346 def __init__(self, mesh, geom=0):
1348 Private constructor.
1351 mesh: parent mesh object algorithm is assigned to
1352 geom: geometry (shape/sub-shape) algorithm is assigned to;
1353 if it is :code:`0` (default), the algorithm is assigned to the main shape
1355 Mesh_Algorithm.__init__(self)
1360 self.Create(mesh, geom, "RadialPrism_3D")
1361 self.distribHyp = None
1362 self.nbLayers = None
1365 class StdMeshersBuilder_RadialAlgorithm(Mesh_Algorithm):
1367 Base class for algorithms supporting radial distribution hypotheses
1371 Mesh_Algorithm.__init__(self)
1373 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1374 self.nbLayers = None
1377 def Get2DHypothesis(self):
1380 2D hypothesis holding the 1D one
1382 if not self.distribHyp:
1383 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1384 return self.distribHyp
1386 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1388 Private method creating a 1D hypothesis and storing it in the LayerDistribution
1392 the created hypothesis
1395 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1396 if self.distribHyp is None:
1397 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1399 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1400 self.mesh.smeshpyD.SetEnablePublish( False )
1401 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1402 self.mesh.smeshpyD.SetEnablePublish( True )
1403 self.distribHyp.SetLayerDistribution( hyp )
1406 def NumberOfLayers(self, n, UseExisting=0):
1408 Defines "NumberOfLayers" hypothesis, specifying the number of layers
1412 UseExisting: if ==true - searches for the existing hypothesis created with
1413 the same parameters, else (default) - Create a new one
1416 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1417 from salome.smesh.smeshBuilder import IsEqual
1418 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1419 self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1420 CompareMethod=compFun)
1421 self.nbLayers.SetNumberOfLayers( n )
1422 return self.nbLayers
1424 def LocalLength(self, l, p=1e-07):
1426 Defines "LocalLength" hypothesis, specifying the segment length
1429 l: the length of segments
1430 p: the precision of rounding
1432 hyp = self.OwnHypothesis("LocalLength", [l,p])
1437 def NumberOfSegments(self, n, s=[]):
1439 Defines "NumberOfSegments" hypothesis, specifying the number of layers
1442 n: the number of layers
1443 s: the scale factor (optional)
1446 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1448 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1449 hyp.SetDistrType( 1 )
1450 hyp.SetScaleFactor(s)
1451 hyp.SetNumberOfSegments(n)
1454 def Arithmetic1D(self, start, end ):
1456 Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1457 with a length that changes in arithmetic progression
1460 start: the length of the first segment
1461 end: the length of the last segment
1463 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1464 hyp.SetLength(start, 1)
1465 hyp.SetLength(end , 0)
1468 def GeometricProgression(self, start, ratio ):
1470 Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1471 with a length that changes in Geometric progression
1474 start: the length of the first segment
1475 ratio: the common ratio of the geometric progression
1477 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1478 hyp.SetStartLength( start )
1479 hyp.SetCommonRatio( ratio )
1482 def StartEndLength(self, start, end):
1484 Defines "StartEndLength" hypothesis, specifying distribution of segments
1485 as geometric length increasing
1488 start: for the length of the first segment
1489 end: for the length of the last segment
1491 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1492 hyp.SetLength(start, 1)
1493 hyp.SetLength(end , 0)
1496 def AutomaticLength(self, fineness=0):
1498 Defines "AutomaticLength" hypothesis, specifying the number of segments
1501 fineness: defines the quality of the mesh within the range [0-1]
1503 hyp = self.OwnHypothesis("AutomaticLength")
1504 hyp.SetFineness( fineness )
1507 pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1509 class StdMeshersBuilder_RadialQuadrangle1D2D(StdMeshersBuilder_RadialAlgorithm):
1511 Defines a Radial Quadrangle 1D-2D algorithm.
1512 It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1515 meshMethod = "Quadrangle"
1517 name of the dynamic method in smeshBuilder.Mesh class
1519 algoType = RADIAL_QUAD
1521 type of algorithm used with helper function in smeshBuilder.Mesh class
1523 docHelper = "Create quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
1525 doc string of the method
1528 def __init__(self, mesh, geom=0):
1530 Private constructor.
1533 mesh: parent mesh object algorithm is assigned to
1534 geom: geometry (shape/sub-shape) algorithm is assigned to;
1535 if it is :code:`0` (default), the algorithm is assigned to the main shape
1537 StdMeshersBuilder_RadialAlgorithm.__init__(self)
1538 self.Create(mesh, geom, self.algoType)
1540 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1541 self.nbLayers = None
1545 class StdMeshersBuilder_QuadMA_1D2D(StdMeshersBuilder_RadialAlgorithm):
1547 Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm .
1548 It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
1551 meshMethod = "Quadrangle"
1553 name of the dynamic method in smeshBuilder.Mesh class
1555 algoType = QUAD_MA_PROJ
1557 type of algorithm used with helper function in smeshBuilder.Mesh class
1559 docHelper = "Create quadrangle 1D-2D algorithm for faces"
1561 doc string of the method
1564 def __init__(self, mesh, geom=0):
1566 Private constructor.
1569 mesh: parent mesh object algorithm is assigned to
1570 geom: geometry (shape/sub-shape) algorithm is assigned to;
1571 if it is :code:`0` (default), the algorithm is assigned to the main shape
1573 StdMeshersBuilder_RadialAlgorithm.__init__(self)
1574 self.Create(mesh, geom, self.algoType)
1579 class StdMeshersBuilder_PolygonPerFace(Mesh_Algorithm):
1580 """ Defines a Polygon Per Face 2D algorithm.
1581 It is created by calling smeshBuilder.Mesh.Polygon(geom=0)
1584 meshMethod = "Polygon"
1586 name of the dynamic method in smeshBuilder.Mesh class
1590 type of algorithm used with helper function in smeshBuilder.Mesh class
1594 flag pointing whether this algorithm should be used by default in dynamic method
1595 of smeshBuilder.Mesh class
1597 docHelper = "Create polygon 2D algorithm for faces"
1599 doc string of the method
1602 def __init__(self, mesh, geom=0):
1604 Private constructor.
1607 mesh: parent mesh object algorithm is assigned to
1608 geom: geometry (shape/sub-shape) algorithm is assigned to;
1609 if it is :code:`0` (default), the algorithm is assigned to the main shape
1611 Mesh_Algorithm.__init__(self)
1612 self.Create(mesh, geom, self.algoType)
1617 class StdMeshersBuilder_PolyhedronPerSolid(Mesh_Algorithm):
1618 """ Defines a Polyhedron Per Solid 3D algorithm.
1619 It is created by calling smeshBuilder.Mesh.Polyhedron(geom=0)
1622 meshMethod = "Polyhedron"
1624 name of the dynamic method in smeshBuilder.Mesh class
1626 algoType = POLYHEDRON
1628 type of algorithm used with helper function in smeshBuilder.Mesh class
1632 flag pointing whether this algorithm should be used by default in dynamic method
1633 of smeshBuilder.Mesh class
1635 docHelper = "Create polyhedron 3D algorithm for solids"
1637 doc string of the method
1640 def __init__(self, mesh, geom=0):
1642 Private constructor.
1645 mesh: parent mesh object algorithm is assigned to
1646 geom: geometry (shape/sub-shape) algorithm is assigned to;
1647 if it is :code:`0` (default), the algorithm is assigned to the main shape
1649 Mesh_Algorithm.__init__(self)
1650 self.Create(mesh, geom, self.algoType)
1655 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1656 """ Defines a Use Existing Elements 1D algorithm.
1658 It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1662 meshMethod = "UseExisting1DElements"
1664 name of the dynamic method in smeshBuilder.Mesh class
1666 algoType = "Import_1D"
1668 type of algorithm used with helper function in smeshBuilder.Mesh class
1672 flag pointing whether this algorithm should be used by default in dynamic method
1673 of smeshBuilder.Mesh class
1675 docHelper = "Create 1D algorithm for edges with reusing of existing mesh elements"
1677 doc string of the method
1680 def __init__(self, mesh, geom=0):
1682 Private constructor.
1685 mesh: parent mesh object algorithm is assigned to
1686 geom: geometry (shape/sub-shape) algorithm is assigned to;
1687 if it is :code:`0` (default), the algorithm is assigned to the main shape
1689 Mesh_Algorithm.__init__(self)
1690 self.Create(mesh, geom, self.algoType)
1693 def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1695 Defines "Source edges" hypothesis, specifying groups of edges to import
1698 groups: list of groups of edges
1699 toCopyMesh: if True, the whole mesh *groups* belong to is imported
1700 toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1701 UseExisting: if ==true - searches for the existing hypothesis created with
1702 the same parameters, else (default) - Create a new one
1704 for group in groups:
1705 from salome.smesh.smeshBuilder import AssureGeomPublished
1706 AssureGeomPublished( self.mesh, group )
1707 compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1708 hyp.GetCopySourceMesh() == args[1], args[2] )
1709 hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1710 UseExisting=UseExisting, CompareMethod=compFun)
1711 hyp.SetSourceEdges(groups)
1712 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1715 pass # end of StdMeshersBuilder_UseExistingElements_1D class
1717 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1718 """ Defines a Use Existing Elements 1D-2D algorithm.
1720 It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1724 meshMethod = "UseExisting2DElements"
1726 name of the dynamic method in smeshBuilder.Mesh class
1728 algoType = "Import_1D2D"
1730 type of algorithm used with helper function in smeshBuilder.Mesh class
1734 flag pointing whether this algorithm should be used by default in dynamic method
1735 of smeshBuilder.Mesh class
1737 docHelper = "Create 1D-2D algorithm for faces with reusing of existing mesh elements"
1739 doc string of the method
1742 def __init__(self, mesh, geom=0):
1744 Private constructor.
1747 mesh: parent mesh object algorithm is assigned to
1748 geom: geometry (shape/sub-shape) algorithm is assigned to;
1749 if it is :code:`0` (default), the algorithm is assigned to the main shape
1751 Mesh_Algorithm.__init__(self)
1752 self.Create(mesh, geom, self.algoType)
1755 def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1757 Defines "Source faces" hypothesis, specifying groups of faces to import
1760 groups: list of groups of faces
1761 toCopyMesh: if True, the whole mesh *groups* belong to is imported
1762 toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1763 UseExisting: if ==true - searches for the existing hypothesis created with
1764 the same parameters, else (default) - Create a new one
1767 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1768 hyp.GetCopySourceMesh() == args[1], args[2] )
1769 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1770 UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1771 if groups and isinstance( groups, SMESH._objref_SMESH_GroupBase ):
1773 hyp.SetSourceFaces(groups)
1774 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1775 self.mesh.AddHypothesis(hyp, self.geom)
1778 pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1780 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1781 """ Defines a Body Fitting 3D algorithm.
1783 It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1787 meshMethod = "BodyFitted"
1789 name of the dynamic method in smeshBuilder.Mesh class
1791 algoType = "Cartesian_3D"
1793 type of algorithm used with helper function in smeshBuilder.Mesh class
1797 flag pointing whether this algorithm should be used by default in dynamic method
1798 of smeshBuilder.Mesh class
1800 docHelper = "Create Body Fitting 3D algorithm for volumes"
1802 doc string of the method
1805 def __init__(self, mesh, geom=0):
1807 Private constructor.
1810 mesh: parent mesh object algorithm is assigned to
1811 geom: geometry (shape/sub-shape) algorithm is assigned to;
1812 if it is :code:`0` (default), the algorithm is assigned to the main shape
1814 self.Create(mesh, geom, self.algoType)
1818 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1820 Defines "Body Fitting parameters" hypothesis
1823 xGridDef: is definition of the grid along the X asix.
1824 It can be in either of two following forms:
1826 - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1827 - Functions f(t) defining grid spacing at each point on grid axis. If there are
1828 several functions, they must be accompanied by relative coordinates of
1829 points dividing the whole shape into ranges where the functions apply; points
1830 coordinates should vary within (0.0, 1.0) range. Parameter *t* of the spacing
1831 function f(t) varies from 0.0 to 1.0 within a shape range.
1833 The actual grid spacing can slightly differ from the defined one. This is done for the
1834 best fitting of polyhedrons and for a better mesh quality on the interval boundaries.
1835 For example, if a constant **Spacing** is defined along an axis, the actual grid will
1836 fill the shape's dimension L along this axis with round number of equal cells:
1837 Spacing_actual = L / round( L / Spacing_defined ).
1840 "10.5" - defines a grid with a constant spacing
1841 [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1844 yGridDef: defines the grid along the Y asix the same way as *xGridDef* does.
1845 zGridDef: defines the grid along the Z asix the same way as *xGridDef* does.
1846 sizeThreshold: (> 1.0) defines a minimal size of a polyhedron so that
1847 a polyhedron of size less than hexSize/sizeThreshold is not created.
1848 implEdges: enables implementation of geometrical edges into the mesh.
1851 compFun = lambda hyp, args: False
1852 self.hyp = self.Hypothesis("CartesianParameters3D",
1853 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1854 UseExisting=False, CompareMethod=compFun)
1855 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1856 self.mesh.AddHypothesis( self.hyp, self.geom )
1858 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1859 if not gridDef: raise ValueError("Empty grid definition")
1860 if isinstance( gridDef, str ):
1861 self.hyp.SetGridSpacing( [gridDef], [], axis )
1862 elif isinstance( gridDef[0], str ):
1863 self.hyp.SetGridSpacing( gridDef, [], axis )
1864 elif isinstance( gridDef[0], int ) or \
1865 isinstance( gridDef[0], float ):
1866 self.hyp.SetGrid(gridDef, axis )
1868 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1869 self.hyp.SetSizeThreshold( sizeThreshold )
1870 self.hyp.SetToAddEdges( implEdges )
1873 def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1875 Defines custom directions of axes of the grid
1878 xAxis: either SMESH.DirStruct or a vector, or 3 vector components
1879 yAxis: either SMESH.DirStruct or a vector, or 3 vector components
1880 zAxis: either SMESH.DirStruct or a vector, or 3 vector components
1883 if hasattr( xAxis, "__getitem__" ):
1884 xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1885 elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1886 xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1887 if hasattr( yAxis, "__getitem__" ):
1888 yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1889 elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1890 yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1891 if hasattr( zAxis, "__getitem__" ):
1892 zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1893 elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1894 zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1896 self.hyp = self.Hypothesis("CartesianParameters3D")
1897 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1898 self.mesh.AddHypothesis( self.hyp, self.geom )
1899 self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1902 def SetOptimalAxesDirs(self, isOrthogonal=True):
1904 Automatically defines directions of axes of the grid at which
1905 a number of generated hexahedra is maximal
1908 isOrthogonal: defines whether the axes mush be orthogonal
1911 self.hyp = self.Hypothesis("CartesianParameters3D")
1912 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1913 self.mesh.AddHypothesis( self.hyp, self.geom )
1914 x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1915 self.hyp.SetAxesDirs( x,y,z )
1918 def SetFixedPoint( self, p, toUnset=False ):
1920 Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1921 through the fixed point in each direction at which the grid is defined
1925 p: coordinates of the fixed point. Either SMESH.PointStruct or
1926 a vertex or 3 components of coordinates.
1927 toUnset: defines whether the fixed point is defined or removed.
1931 if not self.hyp: return
1932 p = SMESH.PointStruct(0,0,0)
1933 elif hasattr( p, "__getitem__" ):
1934 p = SMESH.PointStruct( p[0],p[1],p[2] )
1935 elif isinstance( p, GEOM._objref_GEOM_Object ):
1936 p = self.mesh.smeshpyD.GetPointStruct( p )
1938 self.hyp = self.Hypothesis("CartesianParameters3D")
1939 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1940 self.mesh.AddHypothesis( self.hyp, self.geom )
1941 self.hyp.SetFixedPoint( p, toUnset )
1945 pass # end of StdMeshersBuilder_Cartesian_3D class
1947 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1948 """ Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1949 segments usable by 2D algorithms.
1951 It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1955 meshMethod = "UseExistingSegments"
1957 name of the dynamic method in smeshBuilder.Mesh class
1959 algoType = "UseExisting_1D"
1961 type of algorithm used with helper function in smeshBuilder.Mesh class
1963 docHelper = "Create 1D algorithm allowing batch meshing of edges"
1965 doc string of the method
1968 def __init__(self, mesh, geom=0):
1970 Private constructor.
1973 mesh: parent mesh object algorithm is assigned to
1974 geom: geometry (shape/sub-shape) algorithm is assigned to;
1975 if it is :code:`0` (default), the algorithm is assigned to the main shape
1977 self.Create(mesh, geom, self.algoType)
1980 pass # end of StdMeshersBuilder_UseExisting_1D class
1982 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1983 """ Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1984 faces usable by 3D algorithms.
1986 It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1990 meshMethod = "UseExistingFaces"
1992 name of the dynamic method in smeshBuilder.Mesh class
1994 algoType = "UseExisting_2D"
1996 type of algorithm used with helper function in smeshBuilder.Mesh class
1998 docHelper = "Create 2D algorithm allowing batch meshing of faces"
2000 doc string of the method
2003 def __init__(self, mesh, geom=0):
2005 Private constructor.
2008 mesh: parent mesh object algorithm is assigned to
2009 geom: geometry (shape/sub-shape) algorithm is assigned to;
2010 if it is :code:`0` (default), the algorithm is assigned to the main shape
2012 self.Create(mesh, geom, self.algoType)
2015 pass # end of StdMeshersBuilder_UseExisting_2D class