1 # Copyright (C) 2007-2019 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"
46 Algorithm type: Composite segment 1D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_CompositeSegment`
48 MEFISTO = "MEFISTO_2D"
50 Algorithm type: Triangle MEFISTO 2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Triangle_MEFISTO`
55 Algorithm type: Hexahedron 3D (i-j-k) algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Hexahedron`
58 QUADRANGLE = "Quadrangle_2D"
60 Algorithm type: Quadrangle 2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_Quadrangle`
63 RADIAL_QUAD = "RadialQuadrangle_1D2D"
65 Algorithm type: Radial Quadrangle 1D-2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_RadialQuadrangle1D2D`
68 QUAD_MA_PROJ = "QuadFromMedialAxis_1D2D"
70 Algorithm type: Quadrangle (Medial Axis Projection) 1D-2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_QuadMA_1D2D`
73 POLYGON = "PolygonPerFace_2D"
75 Algorithm type: Polygon Per Face 2D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_PolygonPerFace`
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_Triangle_MEFISTO(Mesh_Algorithm):
623 Triangle MEFISTO 2D algorithm.
624 It is created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MEFISTO,geom=0)
628 meshMethod = "Triangle"
630 name of the dynamic method in smeshBuilder.Mesh class
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 triangle 2D algorithm for faces"
643 doc string of the method
646 def __init__(self, mesh, geom=0):
651 mesh: parent mesh object algorithm is assigned to
652 geom: geometry (shape/sub-shape) algorithm is assigned to;
653 if it is :code:`0` (default), the algorithm is assigned to the main shape
655 Mesh_Algorithm.__init__(self)
656 self.Create(mesh, geom, self.algoType)
659 def MaxElementArea(self, area, UseExisting=0):
661 Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
664 area: for the maximum area of each triangle
665 UseExisting: if ==true - searches for an existing hypothesis created with the
666 same parameters, else (default) - Create a new one
669 from salome.smesh.smeshBuilder import IsEqual
670 comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
671 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
672 CompareMethod=comparator)
673 hyp.SetMaxElementArea(area)
676 def LengthFromEdges(self):
678 Defines "LengthFromEdges" hypothesis to build triangles
679 based on the length of the edges taken from the wire
682 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
685 pass # end of StdMeshersBuilder_Triangle_MEFISTO class
687 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
689 Defines a quadrangle 2D algorithm.
690 It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
694 meshMethod = "Quadrangle"
696 name of the dynamic method in smeshBuilder.Mesh class
698 algoType = QUADRANGLE
700 type of algorithm used with helper function in smeshBuilder.Mesh class
704 flag pointing whether this algorithm should be used by default in dynamic method
705 of smeshBuilder.Mesh class
707 docHelper = "Create quadrangle 2D algorithm for faces"
709 doc string of the method
713 hypothesis associated with algorithm
716 def __init__(self, mesh, geom=0):
721 mesh: parent mesh object algorithm is assigned to
722 geom: geometry (shape/sub-shape) algorithm is assigned to;
723 if it is :code:`0` (default), the algorithm is assigned to the main shape
725 Mesh_Algorithm.__init__(self)
726 self.Create(mesh, geom, self.algoType)
729 def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0,
730 enfVertices=[],enfPoints=[],corners=[],UseExisting=0):
732 Defines "QuadrangleParameters" hypothesis
733 quadType defines the algorithm of transition between differently descretized
734 sides of a geometrical face:
736 - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
737 area along the finer meshed sides.
738 - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
740 - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
741 the finer meshed sides, iff the total quantity of segments on
742 all four sides of the face is even (divisible by 2).
743 - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
744 area is located along the coarser meshed sides.
745 - QUAD_REDUCED - only quadrangles are built and the transition between the sides
746 is made gradually, layer by layer. This type has a limitation on
747 the number of segments: one pair of opposite sides must have the
748 same number of segments, the other pair must have an even difference
749 between the numbers of segments on the sides.
752 triangleVertex: vertex of a trilateral geometrical face, around which triangles
753 will be created while other elements will be quadrangles.
754 Vertex can be either a GEOM_Object or a vertex ID within the
756 enfVertices: list of shapes defining positions where nodes (enforced nodes)
757 must be created by the mesher. Shapes can be of any type,
758 vertices of given shapes define positions of enforced nodes.
759 Only vertices successfully projected to the face are used.
760 enfPoints: list of points giving positions of enforced nodes.
761 Point can be defined either as SMESH.PointStruct's
762 ([SMESH.PointStruct(x1,y1,z1), SMESH.PointStruct(x2,y2,z2),...])
763 or triples of values ([[x1,y1,z1], [x2,y2,z2], ...]).
764 In the case if the defined QuadrangleParameters() refer to a sole face,
765 all given points must lie on this face, else the mesher fails.
766 corners: list of vertices that should be used as quadrangle corners.
767 The parameter can be useful for faces with more than four vertices,
768 since in some cases Quadrangle Mapping algorithm chooses corner vertices
769 differently than it is desired.
770 A hypothesis can be global and define corners for all CAD faces that
771 require it, but be sure that each specified vertex is a corner in all
772 faces the hypothesis will be applied to.
773 UseExisting: if *True* - searches for the existing hypothesis created with
774 the same parameters, else (default) - Create a new one
779 vertexID = triangleVertex
780 if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
781 vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
782 if isinstance( enfVertices, int ) and not enfPoints and not UseExisting:
783 # a call of old syntax, before inserting enfVertices and enfPoints before UseExisting
784 UseExisting, enfVertices = enfVertices, []
786 pStructs, xyz = [], []
788 if isinstance( p, SMESH.PointStruct ):
789 xyz.append(( p.x, p.y, p.z ))
792 xyz.append(( p[0], p[1], p[2] ))
793 pStructs.append( SMESH.PointStruct( p[0], p[1], p[2] ))
795 compFun = lambda hyp,args: \
796 hyp.GetQuadType() == args[0] and \
797 (hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1)) and \
798 ((hyp.GetEnforcedNodes()) == (args[2],args[3])) # True w/o enfVertices only
799 entries = [ shape.GetStudyEntry() for shape in enfVertices ]
800 self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID,entries,xyz],
801 UseExisting = UseExisting, CompareMethod=compFun)
804 if corners and isinstance( corners[0], GEOM._objref_GEOM_Object ):
805 corners = [ self.mesh.geompyD.GetSubShapeID( self.mesh.geom, v ) for v in corners ]
807 if self.params.GetQuadType() != quadType:
808 self.params.SetQuadType(quadType)
810 self.params.SetTriaVertex( vertexID )
811 from salome.smesh.smeshBuilder import AssureGeomPublished
812 for v in enfVertices:
813 AssureGeomPublished( self.mesh, v )
814 self.params.SetEnforcedNodes( enfVertices, pStructs )
815 self.params.SetCorners( corners )
818 def QuadranglePreference(self, reversed=False, UseExisting=0):
820 Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
821 quadrangles are built in the transition area along the finer meshed sides,
822 if the total quantity of segments on all four sides of the face is even.
825 reversed: if True, transition area is located along the coarser meshed sides.
826 UseExisting: if ==true - searches for the existing hypothesis created with
827 the same parameters, else (default) - Create a new one
831 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
832 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
834 def TrianglePreference(self, UseExisting=0):
836 Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
837 triangles are built in the transition area along the finer meshed sides.
840 UseExisting: if ==true - searches for the existing hypothesis created with
841 the same parameters, else (default) - Create a new one
844 return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
846 def Reduced(self, UseExisting=0):
848 Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
849 quadrangles are built and the transition between the sides is made gradually,
850 layer by layer. This type has a limitation on the number of segments: one pair
851 of opposite sides must have the same number of segments, the other pair must
852 have an even difference between the numbers of segments on the sides.
855 UseExisting: if ==true - searches for the existing hypothesis created with
856 the same parameters, else (default) - Create a new one
859 return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
861 def TriangleVertex(self, vertex, UseExisting=0):
863 Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
866 vertex: vertex of a trilateral geometrical face, around which triangles
867 will be created while other elements will be quadrangles.
868 Vertex can be either a GEOM_Object or a vertex ID within the
870 UseExisting: if ==true - searches for the existing hypothesis created with
871 the same parameters, else (default) - Create a new one
874 return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
876 pass # end of StdMeshersBuilder_Quadrangle class
878 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
880 Defines a hexahedron 3D algorithm.
881 It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
885 meshMethod = "Hexahedron"
887 name of the dynamic method in smeshBuilder.Mesh class
891 type of algorithm used with helper function in smeshBuilder.Mesh class
895 flag pointing whether this algorithm should be used by default in dynamic method
896 of smeshBuilder.Mesh class
898 docHelper = "Create hexahedron 3D algorithm for volumes"
900 doc string of the method
903 def __init__(self, mesh, geom=0):
908 mesh: parent mesh object algorithm is assigned to
909 geom: geometry (shape/sub-shape) algorithm is assigned to;
910 if it is :code:`0` (default), the algorithm is assigned to the main shape
912 Mesh_Algorithm.__init__(self)
913 self.Create(mesh, geom, Hexa)
916 pass # end of StdMeshersBuilder_Hexahedron class
918 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
920 Defines a projection 1D algorithm.
921 It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
925 meshMethod = "Projection1D"
927 name of the dynamic method in smeshBuilder.Mesh class
929 algoType = "Projection_1D"
931 type of algorithm used with helper function in smeshBuilder.Mesh class
935 flag pointing whether this algorithm should be used by default in dynamic method
936 of smeshBuilder.Mesh class
938 docHelper = "Create projection 1D algorithm for edges"
940 doc string of the method
942 def __init__(self, mesh, geom=0):
947 mesh: parent mesh object algorithm is assigned to
948 geom: geometry (shape/sub-shape) algorithm is assigned to;
949 if it is :code:`0` (default), the algorithm is assigned to the main shape
951 Mesh_Algorithm.__init__(self)
952 self.Create(mesh, geom, self.algoType)
955 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
957 Defines "Source Edge" hypothesis, specifying a meshed edge, from where
958 a mesh pattern is taken, and, optionally, the association of vertices
959 between the source edge and a target edge (to which a hypothesis is assigned)
962 edge: from which nodes distribution is taken
963 mesh: from which nodes distribution is taken (optional)
964 srcV: a vertex of *edge* to associate with *tgtV* (optional)
965 tgtV: a vertex of *the edge* to which the algorithm is assigned, to associate with *srcV* (optional)
966 UseExisting: if ==true - searches for the existing hypothesis created with
967 the same parameters, else (default) - Create a new one
969 from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
970 AssureGeomPublished( self.mesh, edge )
971 AssureGeomPublished( self.mesh, srcV )
972 AssureGeomPublished( self.mesh, tgtV )
973 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
975 # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
976 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
977 hyp.SetSourceEdge( edge )
978 if not mesh is None and isinstance(mesh, Mesh):
979 mesh = mesh.GetMesh()
980 hyp.SetSourceMesh( mesh )
981 hyp.SetVertexAssociation( srcV, tgtV )
984 pass # end of StdMeshersBuilder_Projection1D class
986 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
988 Defines a projection 2D algorithm.
989 It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
993 meshMethod = "Projection2D"
995 name of the dynamic method in smeshBuilder.Mesh class
997 algoType = "Projection_2D"
999 type of algorithm used with helper function in smeshBuilder.Mesh class
1003 flag pointing whether this algorithm should be used by default in dynamic method
1004 of smeshBuilder.Mesh class
1006 docHelper = "Create projection 2D algorithm for faces"
1008 doc string of the method
1011 def __init__(self, mesh, geom=0):
1013 Private constructor.
1016 mesh: parent mesh object algorithm is assigned to
1017 geom: geometry (shape/sub-shape) algorithm is assigned to;
1018 if it is :code:`0` (default), the algorithm is assigned to the main shape
1020 Mesh_Algorithm.__init__(self)
1021 self.Create(mesh, geom, self.algoType)
1025 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1026 srcV2=None, tgtV2=None, UseExisting=0):
1028 Defines "Source Face" hypothesis, specifying a meshed face, from where
1029 a mesh pattern is taken, and, optionally, the association of vertices
1030 between the source face and the target face (to which a hypothesis is assigned)
1033 face: from which the mesh pattern is taken
1034 mesh: from which the mesh pattern is taken (optional)
1035 srcV1: a vertex of *face* to associate with *tgtV1* (optional)
1036 tgtV1: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV1* (optional)
1037 srcV2: a vertex of *face* to associate with *tgtV1* (optional)
1038 tgtV2: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV2* (optional)
1039 UseExisting: if ==true - forces the search for the existing hypothesis created with
1040 he same parameters, else (default) - forces the creation a new one
1043 all association vertices must belong to one edge of a face
1045 from salome.smesh.smeshBuilder import Mesh
1046 if isinstance(mesh, Mesh):
1047 mesh = mesh.GetMesh()
1048 for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
1049 from salome.smesh.smeshBuilder import AssureGeomPublished
1050 AssureGeomPublished( self.mesh, geom )
1051 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1052 UseExisting=0, toAdd=False)
1053 # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
1054 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
1055 hyp.SetSourceFace( face )
1056 hyp.SetSourceMesh( mesh )
1057 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1058 self.mesh.AddHypothesis(hyp, self.geom)
1061 pass # end of StdMeshersBuilder_Projection2D class
1063 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
1065 Defines a projection 1D-2D algorithm.
1066 It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
1070 meshMethod = "Projection1D2D"
1072 name of the dynamic method in smeshBuilder.Mesh class
1074 algoType = "Projection_1D2D"
1076 type of algorithm used with helper function in smeshBuilder.Mesh class
1078 docHelper = "Create projection 1D-2D algorithm for faces"
1080 doc string of the method
1083 def __init__(self, mesh, geom=0):
1085 Private constructor.
1088 mesh: parent mesh object algorithm is assigned to
1089 geom: geometry (shape/sub-shape) algorithm is assigned to;
1090 if it is :code:`0` (default), the algorithm is assigned to the main shape
1092 StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
1095 pass # end of StdMeshersBuilder_Projection1D2D class
1097 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
1099 Defines a projection 3D algorithm.
1100 It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
1104 meshMethod = "Projection3D"
1106 name of the dynamic method in smeshBuilder.Mesh class
1108 algoType = "Projection_3D"
1110 type of algorithm used with helper function in smeshBuilder.Mesh class
1112 docHelper = "Create projection 3D algorithm for volumes"
1114 doc string of the method
1117 def __init__(self, mesh, geom=0):
1119 Private constructor.
1122 mesh: parent mesh object algorithm is assigned to
1123 geom" geometry (shape/sub-shape) algorithm is assigned to;
1124 if it is :code:`0` (default), the algorithm is assigned to the main shape
1126 Mesh_Algorithm.__init__(self)
1127 self.Create(mesh, geom, self.algoType)
1130 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1131 srcV2=0, tgtV2=0, UseExisting=0):
1133 Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
1134 the mesh pattern is taken, and, optionally, the association of vertices
1135 between the source and the target solid (to which a hipothesis is assigned)
1138 solid: from where the mesh pattern is taken
1139 mesh: from where the mesh pattern is taken (optional)
1140 srcV1: a vertex of *solid* to associate with *tgtV1* (optional)
1141 tgtV1: a vertex of *the solid* where the algorithm is assigned, to associate with *srcV1* (optional)
1142 srcV2: a vertex of *solid* to associate with *tgtV1* (optional)
1143 tgtV2: a vertex of *the solid* to which the algorithm is assigned,to associate with *srcV2* (optional)
1144 UseExisting: if ==true - searches for the existing hypothesis created with
1145 the same parameters, else (default) - Create a new one
1148 association vertices must belong to one edge of a solid
1150 for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
1151 from salome.smesh.smeshBuilder import AssureGeomPublished
1152 AssureGeomPublished( self.mesh, geom )
1153 hyp = self.Hypothesis("ProjectionSource3D",
1154 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1156 # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
1157 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
1158 hyp.SetSource3DShape( solid )
1159 from salome.smesh.smeshBuilder import Mesh
1160 if isinstance(mesh, Mesh):
1161 mesh = mesh.GetMesh()
1163 hyp.SetSourceMesh( mesh )
1164 if srcV1 and srcV2 and tgtV1 and tgtV2:
1165 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1166 #elif srcV1 or srcV2 or tgtV1 or tgtV2:
1169 pass # end of StdMeshersBuilder_Projection3D class
1171 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
1173 Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism" depending on geometry.
1174 It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1178 meshMethod = "Prism"
1180 name of the dynamic method in smeshBuilder.Mesh class
1182 algoType = "Prism_3D"
1184 type of algorithm used with helper function in smeshBuilder.Mesh class
1186 docHelper = "Create prism 3D algorithm for volumes"
1188 doc string of the method
1192 flag pointing whether this algorithm should be used by default in dynamic method
1193 of smeshBuilder.Mesh class
1196 def __init__(self, mesh, geom=0):
1198 Private constructor.
1201 mesh: parent mesh object algorithm is assigned to
1202 geom: geometry (shape/sub-shape) algorithm is assigned to;
1203 if it is :code:`0` (default), the algorithm is assigned to the main shape
1205 Mesh_Algorithm.__init__(self)
1210 isRadial = mesh.smeshpyD.IsApplicable("RadialPrism_3D", LIBRARY, shape, False )
1212 self.Create(mesh, geom, "Prism_3D")
1215 self.algoType = "RadialPrism_3D"
1216 self.Create(mesh, geom, "RadialPrism_3D")
1217 self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
1218 self.nbLayers = None
1222 def Get3DHypothesis(self):
1225 3D hypothesis holding the 1D one
1227 if self.algoType != "RadialPrism_3D":
1228 print("Prism_3D algorithm doesn't support any hypothesis")
1230 return self.distribHyp
1232 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1234 Private method creating a 1D hypothesis and storing it in the LayerDistribution
1238 the created hypothesis
1240 if self.algoType != "RadialPrism_3D":
1241 print("Prism_3D algorithm doesn't support any hypothesis")
1243 if not self.nbLayers is None:
1244 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1245 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1246 self.mesh.smeshpyD.SetEnablePublish( False ) # prevents publishing own 1D hypothesis
1247 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1248 self.mesh.smeshpyD.SetEnablePublish( True ) # enables publishing
1249 if not self.distribHyp:
1250 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1251 self.distribHyp.SetLayerDistribution( hyp )
1254 def NumberOfLayers(self, n, UseExisting=0):
1256 Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1257 prisms to build between the inner and outer shells
1261 UseExisting: if ==true - searches for the existing hypothesis created with
1262 the same parameters, else (default) - Create a new one
1264 if self.algoType != "RadialPrism_3D":
1265 print("Prism_3D algorithm doesn't support any hypothesis")
1267 self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1268 from salome.smesh.smeshBuilder import IsEqual
1269 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1270 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1271 CompareMethod=compFun)
1272 self.nbLayers.SetNumberOfLayers( n )
1273 return self.nbLayers
1275 def LocalLength(self, l, p=1e-07):
1277 Defines "LocalLength" hypothesis, specifying the segment length
1278 to build between the inner and the outer shells
1281 l: the length of segments
1282 p: the precision of rounding
1284 if self.algoType != "RadialPrism_3D":
1285 print("Prism_3D algorithm doesn't support any hypothesis")
1287 hyp = self.OwnHypothesis("LocalLength", [l,p])
1292 def NumberOfSegments(self, n, s=[]):
1294 Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1295 prisms to build between the inner and the outer shells.
1298 n: the number of layers
1299 s: the scale factor (optional)
1301 if self.algoType != "RadialPrism_3D":
1302 print("Prism_3D algorithm doesn't support any hypothesis")
1305 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1307 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1308 hyp.SetScaleFactor(s)
1309 hyp.SetNumberOfSegments(n)
1312 def Arithmetic1D(self, start, end ):
1314 Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1315 to build between the inner and the outer shells with a length that changes
1316 in arithmetic progression
1319 start: the length of the first segment
1320 end: the length of the last segment
1322 if self.algoType != "RadialPrism_3D":
1323 print("Prism_3D algorithm doesn't support any hypothesis")
1325 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1326 hyp.SetLength(start, 1)
1327 hyp.SetLength(end , 0)
1330 def GeometricProgression(self, start, ratio ):
1332 Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1333 to build between the inner and the outer shells with a length that changes
1334 in Geometric progression
1337 start: the length of the first segment
1338 ratio: the common ratio of the geometric progression
1340 if self.algoType != "RadialPrism_3D":
1341 print("Prism_3D algorithm doesn't support any hypothesis")
1343 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1344 hyp.SetStartLength( start )
1345 hyp.SetCommonRatio( ratio )
1348 def StartEndLength(self, start, end):
1350 Defines "StartEndLength" hypothesis, specifying distribution of segments
1351 to build between the inner and the outer shells as geometric length increasing
1354 start: for the length of the first segment
1355 end: for the length of the last segment
1357 if self.algoType != "RadialPrism_3D":
1358 print("Prism_3D algorithm doesn't support any hypothesis")
1360 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1361 hyp.SetLength(start, 1)
1362 hyp.SetLength(end , 0)
1365 def AutomaticLength(self, fineness=0):
1367 Defines "AutomaticLength" hypothesis, specifying the number of segments
1368 to build between the inner and outer shells
1371 fineness: defines the quality of the mesh within the range [0-1]
1373 if self.algoType != "RadialPrism_3D":
1374 print("Prism_3D algorithm doesn't support any hypothesis")
1376 hyp = self.OwnHypothesis("AutomaticLength")
1377 hyp.SetFineness( fineness )
1380 pass # end of StdMeshersBuilder_Prism3D class
1382 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1384 Defines Radial Prism 3D algorithm.
1385 It is created by calling smeshBuilder.Mesh.Prism(geom=0).
1386 See :class:`StdMeshersBuilder_Prism3D` for methods defining distribution of mesh layers
1387 build between the inner and outer shells.
1390 meshMethod = "Prism"
1392 name of the dynamic method in smeshBuilder.Mesh class
1394 algoType = "RadialPrism_3D"
1396 type of algorithm used with helper function in smeshBuilder.Mesh class
1398 docHelper = "Create Raial Prism 3D algorithm for volumes"
1400 doc string of the method
1403 def __init__(self, mesh, geom=0):
1405 Private constructor.
1408 mesh: parent mesh object algorithm is assigned to
1409 geom: geometry (shape/sub-shape) algorithm is assigned to;
1410 if it is :code:`0` (default), the algorithm is assigned to the main shape
1412 Mesh_Algorithm.__init__(self)
1417 self.Create(mesh, geom, "RadialPrism_3D")
1418 self.distribHyp = None
1419 self.nbLayers = None
1422 class StdMeshersBuilder_RadialAlgorithm(Mesh_Algorithm):
1424 Base class for algorithms supporting radial distribution hypotheses
1428 Mesh_Algorithm.__init__(self)
1430 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1431 self.nbLayers = None
1434 def Get2DHypothesis(self):
1437 2D hypothesis holding the 1D one
1439 if not self.distribHyp:
1440 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1441 return self.distribHyp
1443 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1445 Private method creating a 1D hypothesis and storing it in the LayerDistribution
1449 the created hypothesis
1452 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1453 if self.distribHyp is None:
1454 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1456 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1457 self.mesh.smeshpyD.SetEnablePublish( False )
1458 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1459 self.mesh.smeshpyD.SetEnablePublish( True )
1460 self.distribHyp.SetLayerDistribution( hyp )
1463 def NumberOfLayers(self, n, UseExisting=0):
1465 Defines "NumberOfLayers" hypothesis, specifying the number of layers
1469 UseExisting: if ==true - searches for the existing hypothesis created with
1470 the same parameters, else (default) - Create a new one
1473 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1474 from salome.smesh.smeshBuilder import IsEqual
1475 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1476 self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1477 CompareMethod=compFun)
1478 self.nbLayers.SetNumberOfLayers( n )
1479 return self.nbLayers
1481 def LocalLength(self, l, p=1e-07):
1483 Defines "LocalLength" hypothesis, specifying the segment length
1486 l: the length of segments
1487 p: the precision of rounding
1489 hyp = self.OwnHypothesis("LocalLength", [l,p])
1494 def NumberOfSegments(self, n, s=[]):
1496 Defines "NumberOfSegments" hypothesis, specifying the number of layers
1499 n: the number of layers
1500 s: the scale factor (optional)
1503 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1505 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1506 hyp.SetDistrType( 1 )
1507 hyp.SetScaleFactor(s)
1508 hyp.SetNumberOfSegments(n)
1511 def Arithmetic1D(self, start, end ):
1513 Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1514 with a length that changes in arithmetic progression
1517 start: the length of the first segment
1518 end: the length of the last segment
1520 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1521 hyp.SetLength(start, 1)
1522 hyp.SetLength(end , 0)
1525 def GeometricProgression(self, start, ratio ):
1527 Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1528 with a length that changes in Geometric progression
1531 start: the length of the first segment
1532 ratio: the common ratio of the geometric progression
1534 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1535 hyp.SetStartLength( start )
1536 hyp.SetCommonRatio( ratio )
1539 def StartEndLength(self, start, end):
1541 Defines "StartEndLength" hypothesis, specifying distribution of segments
1542 as geometric length increasing
1545 start: for the length of the first segment
1546 end: for the length of the last segment
1548 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1549 hyp.SetLength(start, 1)
1550 hyp.SetLength(end , 0)
1553 def AutomaticLength(self, fineness=0):
1555 Defines "AutomaticLength" hypothesis, specifying the number of segments
1558 fineness: defines the quality of the mesh within the range [0-1]
1560 hyp = self.OwnHypothesis("AutomaticLength")
1561 hyp.SetFineness( fineness )
1564 pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1566 class StdMeshersBuilder_RadialQuadrangle1D2D(StdMeshersBuilder_RadialAlgorithm):
1568 Defines a Radial Quadrangle 1D-2D algorithm.
1569 It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1572 meshMethod = "Quadrangle"
1574 name of the dynamic method in smeshBuilder.Mesh class
1576 algoType = RADIAL_QUAD
1578 type of algorithm used with helper function in smeshBuilder.Mesh class
1580 docHelper = "Create quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
1582 doc string of the method
1585 def __init__(self, mesh, geom=0):
1587 Private constructor.
1590 mesh: parent mesh object algorithm is assigned to
1591 geom: geometry (shape/sub-shape) algorithm is assigned to;
1592 if it is :code:`0` (default), the algorithm is assigned to the main shape
1594 StdMeshersBuilder_RadialAlgorithm.__init__(self)
1595 self.Create(mesh, geom, self.algoType)
1597 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1598 self.nbLayers = None
1602 class StdMeshersBuilder_QuadMA_1D2D(StdMeshersBuilder_RadialAlgorithm):
1604 Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm .
1605 It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
1608 meshMethod = "Quadrangle"
1610 name of the dynamic method in smeshBuilder.Mesh class
1612 algoType = QUAD_MA_PROJ
1614 type of algorithm used with helper function in smeshBuilder.Mesh class
1616 docHelper = "Create quadrangle 1D-2D algorithm for faces"
1618 doc string of the method
1621 def __init__(self, mesh, geom=0):
1623 Private constructor.
1626 mesh: parent mesh object algorithm is assigned to
1627 geom: geometry (shape/sub-shape) algorithm is assigned to;
1628 if it is :code:`0` (default), the algorithm is assigned to the main shape
1630 StdMeshersBuilder_RadialAlgorithm.__init__(self)
1631 self.Create(mesh, geom, self.algoType)
1636 class StdMeshersBuilder_PolygonPerFace(Mesh_Algorithm):
1637 """ Defines a Polygon Per Face 2D algorithm.
1638 It is created by calling smeshBuilder.Mesh.Polygon(geom=0)
1641 meshMethod = "Polygon"
1643 name of the dynamic method in smeshBuilder.Mesh class
1647 type of algorithm used with helper function in smeshBuilder.Mesh class
1651 flag pointing whether this algorithm should be used by default in dynamic method
1652 of smeshBuilder.Mesh class
1654 docHelper = "Create polygon 2D algorithm for faces"
1656 doc string of the method
1659 def __init__(self, mesh, geom=0):
1661 Private constructor.
1664 mesh: parent mesh object algorithm is assigned to
1665 geom: geometry (shape/sub-shape) algorithm is assigned to;
1666 if it is :code:`0` (default), the algorithm is assigned to the main shape
1668 Mesh_Algorithm.__init__(self)
1669 self.Create(mesh, geom, self.algoType)
1674 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1675 """ Defines a Use Existing Elements 1D algorithm.
1677 It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1681 meshMethod = "UseExisting1DElements"
1683 name of the dynamic method in smeshBuilder.Mesh class
1685 algoType = "Import_1D"
1687 type of algorithm used with helper function in smeshBuilder.Mesh class
1691 flag pointing whether this algorithm should be used by default in dynamic method
1692 of smeshBuilder.Mesh class
1694 docHelper = "Create 1D algorithm for edges with reusing of existing mesh elements"
1696 doc string of the method
1699 def __init__(self, mesh, geom=0):
1701 Private constructor.
1704 mesh: parent mesh object algorithm is assigned to
1705 geom: geometry (shape/sub-shape) algorithm is assigned to;
1706 if it is :code:`0` (default), the algorithm is assigned to the main shape
1708 Mesh_Algorithm.__init__(self)
1709 self.Create(mesh, geom, self.algoType)
1712 def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1714 Defines "Source edges" hypothesis, specifying groups of edges to import
1717 groups: list of groups of edges
1718 toCopyMesh: if True, the whole mesh *groups* belong to is imported
1719 toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1720 UseExisting: if ==true - searches for the existing hypothesis created with
1721 the same parameters, else (default) - Create a new one
1723 for group in groups:
1724 from salome.smesh.smeshBuilder import AssureGeomPublished
1725 AssureGeomPublished( self.mesh, group )
1726 compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1727 hyp.GetCopySourceMesh() == args[1], args[2] )
1728 hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1729 UseExisting=UseExisting, CompareMethod=compFun)
1730 hyp.SetSourceEdges(groups)
1731 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1734 pass # end of StdMeshersBuilder_UseExistingElements_1D class
1736 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1737 """ Defines a Use Existing Elements 1D-2D algorithm.
1739 It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1743 meshMethod = "UseExisting2DElements"
1745 name of the dynamic method in smeshBuilder.Mesh class
1747 algoType = "Import_1D2D"
1749 type of algorithm used with helper function in smeshBuilder.Mesh class
1753 flag pointing whether this algorithm should be used by default in dynamic method
1754 of smeshBuilder.Mesh class
1756 docHelper = "Create 1D-2D algorithm for faces with reusing of existing mesh elements"
1758 doc string of the method
1761 def __init__(self, mesh, geom=0):
1763 Private constructor.
1766 mesh: parent mesh object algorithm is assigned to
1767 geom: geometry (shape/sub-shape) algorithm is assigned to;
1768 if it is :code:`0` (default), the algorithm is assigned to the main shape
1770 Mesh_Algorithm.__init__(self)
1771 self.Create(mesh, geom, self.algoType)
1774 def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1776 Defines "Source faces" hypothesis, specifying groups of faces to import
1779 groups: list of groups of faces
1780 toCopyMesh: if True, the whole mesh *groups* belong to is imported
1781 toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1782 UseExisting: if ==true - searches for the existing hypothesis created with
1783 the same parameters, else (default) - Create a new one
1786 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1787 hyp.GetCopySourceMesh() == args[1], args[2] )
1788 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1789 UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1790 if groups and isinstance( groups, SMESH._objref_SMESH_GroupBase ):
1792 hyp.SetSourceFaces(groups)
1793 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1794 self.mesh.AddHypothesis(hyp, self.geom)
1797 pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1799 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1800 """ Defines a Body Fitting 3D algorithm.
1802 It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1806 meshMethod = "BodyFitted"
1808 name of the dynamic method in smeshBuilder.Mesh class
1810 algoType = "Cartesian_3D"
1812 type of algorithm used with helper function in smeshBuilder.Mesh class
1816 flag pointing whether this algorithm should be used by default in dynamic method
1817 of smeshBuilder.Mesh class
1819 docHelper = "Create Body Fitting 3D algorithm for volumes"
1821 doc string of the method
1824 def __init__(self, mesh, geom=0):
1826 Private constructor.
1829 mesh: parent mesh object algorithm is assigned to
1830 geom: geometry (shape/sub-shape) algorithm is assigned to;
1831 if it is :code:`0` (default), the algorithm is assigned to the main shape
1833 self.Create(mesh, geom, self.algoType)
1837 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1839 Defines "Body Fitting parameters" hypothesis
1842 xGridDef: is definition of the grid along the X asix.
1843 It can be in either of two following forms:
1845 - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1846 - Functions f(t) defining grid spacing at each point on grid axis. If there are
1847 several functions, they must be accompanied by relative coordinates of
1848 points dividing the whole shape into ranges where the functions apply; points
1849 coordinates should vary within (0.0, 1.0) range. Parameter *t* of the spacing
1850 function f(t) varies from 0.0 to 1.0 within a shape range.
1853 "10.5" - defines a grid with a constant spacing
1854 [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1857 yGridDef: defines the grid along the Y asix the same way as *xGridDef* does.
1858 zGridDef: defines the grid along the Z asix the same way as *xGridDef* does.
1859 sizeThreshold: (> 1.0) defines a minimal size of a polyhedron so that
1860 a polyhedron of size less than hexSize/sizeThreshold is not created.
1861 implEdges: enables implementation of geometrical edges into the mesh.
1864 compFun = lambda hyp, args: False
1865 self.hyp = self.Hypothesis("CartesianParameters3D",
1866 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1867 UseExisting=False, CompareMethod=compFun)
1868 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1869 self.mesh.AddHypothesis( self.hyp, self.geom )
1871 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1872 if not gridDef: raise ValueError("Empty grid definition")
1873 if isinstance( gridDef, str ):
1874 self.hyp.SetGridSpacing( [gridDef], [], axis )
1875 elif isinstance( gridDef[0], str ):
1876 self.hyp.SetGridSpacing( gridDef, [], axis )
1877 elif isinstance( gridDef[0], int ) or \
1878 isinstance( gridDef[0], float ):
1879 self.hyp.SetGrid(gridDef, axis )
1881 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1882 self.hyp.SetSizeThreshold( sizeThreshold )
1883 self.hyp.SetToAddEdges( implEdges )
1886 def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1888 Defines custom directions of axes of the grid
1891 xAxis: either SMESH.DirStruct or a vector, or 3 vector components
1892 yAxis: either SMESH.DirStruct or a vector, or 3 vector components
1893 zAxis: either SMESH.DirStruct or a vector, or 3 vector components
1896 if hasattr( xAxis, "__getitem__" ):
1897 xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1898 elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1899 xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1900 if hasattr( yAxis, "__getitem__" ):
1901 yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1902 elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1903 yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1904 if hasattr( zAxis, "__getitem__" ):
1905 zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1906 elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1907 zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1909 self.hyp = self.Hypothesis("CartesianParameters3D")
1910 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1911 self.mesh.AddHypothesis( self.hyp, self.geom )
1912 self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1915 def SetOptimalAxesDirs(self, isOrthogonal=True):
1917 Automatically defines directions of axes of the grid at which
1918 a number of generated hexahedra is maximal
1921 isOrthogonal: defines whether the axes mush be orthogonal
1924 self.hyp = self.Hypothesis("CartesianParameters3D")
1925 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1926 self.mesh.AddHypothesis( self.hyp, self.geom )
1927 x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1928 self.hyp.SetAxesDirs( x,y,z )
1931 def SetFixedPoint( self, p, toUnset=False ):
1933 Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1934 through the fixed point in each direction at which the grid is defined
1938 p: coordinates of the fixed point. Either SMESH.PointStruct or
1939 a vertex or 3 components of coordinates.
1940 toUnset: defines whether the fixed point is defined or removed.
1944 if not self.hyp: return
1945 p = SMESH.PointStruct(0,0,0)
1946 elif hasattr( p, "__getitem__" ):
1947 p = SMESH.PointStruct( p[0],p[1],p[2] )
1948 elif isinstance( p, GEOM._objref_GEOM_Object ):
1949 p = self.mesh.smeshpyD.GetPointStruct( p )
1951 self.hyp = self.Hypothesis("CartesianParameters3D")
1952 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1953 self.mesh.AddHypothesis( self.hyp, self.geom )
1954 self.hyp.SetFixedPoint( p, toUnset )
1958 pass # end of StdMeshersBuilder_Cartesian_3D class
1960 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1961 """ Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1962 segments usable by 2D algorithms.
1964 It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1968 meshMethod = "UseExistingSegments"
1970 name of the dynamic method in smeshBuilder.Mesh class
1972 algoType = "UseExisting_1D"
1974 type of algorithm used with helper function in smeshBuilder.Mesh class
1976 docHelper = "Create 1D algorithm allowing batch meshing of edges"
1978 doc string of the method
1981 def __init__(self, mesh, geom=0):
1983 Private constructor.
1986 mesh: parent mesh object algorithm is assigned to
1987 geom: geometry (shape/sub-shape) algorithm is assigned to;
1988 if it is :code:`0` (default), the algorithm is assigned to the main shape
1990 self.Create(mesh, geom, self.algoType)
1993 pass # end of StdMeshersBuilder_UseExisting_1D class
1995 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1996 """ Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1997 faces usable by 3D algorithms.
1999 It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
2003 meshMethod = "UseExistingFaces"
2005 name of the dynamic method in smeshBuilder.Mesh class
2007 algoType = "UseExisting_2D"
2009 type of algorithm used with helper function in smeshBuilder.Mesh class
2011 docHelper = "Create 2D algorithm allowing batch meshing of faces"
2013 doc string of the method
2016 def __init__(self, mesh, geom=0):
2018 Private constructor.
2021 mesh: parent mesh object algorithm is assigned to
2022 geom: geometry (shape/sub-shape) algorithm is assigned to;
2023 if it is :code:`0` (default), the algorithm is assigned to the main shape
2025 self.Create(mesh, geom, self.algoType)
2028 pass # end of StdMeshersBuilder_UseExisting_2D class