1 # Copyright (C) 2007-2020 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 POLYHEDRON = "PolyhedronPerSolid_3D"
80 Algorithm type: Polyhedron Per Solid 3D algorithm, see :class:`~StdMeshersBuilder.StdMeshersBuilder_PolyhedronPerSolid`
83 # import items of enums
84 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
85 for e in StdMeshers.VLExtrusionMethod._items: exec('%s = StdMeshers.%s'%(e,e))
87 #----------------------
89 #----------------------
91 class StdMeshersBuilder_Segment(Mesh_Algorithm):
93 Defines segment 1D algorithm for edges discretization.
95 It can be created by calling smeshBuilder.Mesh.Segment(geom=0)
99 meshMethod = "Segment"
101 name of the dynamic method in smeshBuilder.Mesh class
106 type of algorithm used with helper function in smeshBuilder.Mesh class
111 flag pointing whether this algorithm should be used by default in dynamic method
112 of smeshBuilder.Mesh class
115 docHelper = "Create segment 1D algorithm for edges"
117 doc string of the method
120 def __init__(self, mesh, geom=0):
124 mesh: parent mesh object algorithm is assigned to
125 geom: geometry (shape/sub-shape) algorithm is assigned to;
126 if it is :code:`0` (default), the algorithm is assigned to the main shape
128 Mesh_Algorithm.__init__(self)
129 self.Create(mesh, geom, self.algoType)
132 def LocalLength(self, l, UseExisting=0, p=1e-07):
134 Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
137 l : for the length of segments that cut an edge
138 UseExisting : if == true - searches for an existing hypothesis created with
139 the same parameters, else (default) - Create a new one
140 p : precision, used for calculation of the number of segments.
141 The precision should be a positive, meaningful value within the range [0,1].
142 In general, the number of segments is calculated with the formula:
143 nb = ceil((edge_length / l) - p)
144 Function ceil rounds its argument to the higher integer.
145 So, p=0 means rounding of (edge_length / l) to the higher integer,
146 p=0.5 means rounding of (edge_length / l) to the nearest integer,
147 p=1 means rounding of (edge_length / l) to the lower integer.
148 Default value is 1e-07.
151 an instance of StdMeshers_LocalLength hypothesis
154 from salome.smesh.smeshBuilder import IsEqual
155 comFun=lambda hyp, args: IsEqual(hyp.GetLength(), args[0]) and IsEqual(hyp.GetPrecision(), args[1])
156 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting, CompareMethod=comFun)
161 def MaxSize(self, length=0.0, UseExisting=0):
163 Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
166 length : is optional maximal allowed length of segment, if it is omitted
167 the preestimated length is used that depends on geometry size
168 UseExisting : if ==true - searches for an existing hypothesis created with
169 the same parameters, else (default) - Create a new one
172 an instance of StdMeshers_MaxLength hypothesis
176 hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
177 if isinstance(length,str) or length > 0:
179 hyp.SetLength(length)
181 # set preestimated length
183 gen = self.mesh.smeshpyD
184 initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
185 self.mesh.GetMesh(), self.mesh.GetShape(),
186 SMESH.HypInitParams( 1, 1.0, False ))
187 preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
189 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
192 hyp.SetUsePreestimatedLength( length == 0.0 )
195 def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
197 Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
200 n: for the number of segments that cut an edge
201 s: for the scale factor (optional)
202 reversedEdges: is a list of edges to mesh using reversed orientation.
203 A list item can also be a tuple (edge, 1st_vertex_of_edge)
204 UseExisting: if ==true - searches for an existing hypothesis created with
205 the same parameters, else (default) - create a new one
208 an instance of StdMeshers_NumberOfSegments hypothesis
212 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
213 reversedEdges, UseExisting = [], reversedEdges
214 entry = self.MainShapeEntry()
215 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
217 hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
218 UseExisting=UseExisting,
219 CompareMethod=self._compareNumberOfSegments)
221 hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
222 UseExisting=UseExisting,
223 CompareMethod=self._compareNumberOfSegments)
224 hyp.SetScaleFactor(s)
225 hyp.SetNumberOfSegments(n)
226 hyp.SetReversedEdges( reversedEdgeInd )
227 hyp.SetObjectEntry( entry )
230 def _compareNumberOfSegments(self, hyp, args):
233 Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
235 if hyp.GetNumberOfSegments() == args[0]:
237 if hyp.GetReversedEdges() == args[1]:
238 if not args[1] or hyp.GetObjectEntry() == args[2]:
241 from salome.smesh.smeshBuilder import IsEqual
242 if hyp.GetReversedEdges() == args[2]:
243 if not args[2] or hyp.GetObjectEntry() == args[3]:
244 if hyp.GetDistrType() == 1:
245 if IsEqual(hyp.GetScaleFactor(), args[1]):
249 def Adaptive(self, minSize, maxSize, deflection, UseExisting=False):
251 Defines "Adaptive" hypothesis to cut an edge into segments keeping segment size
252 within the given range and considering (1) deflection of segments from the edge
253 and (2) distance from segments to closest edges and faces to have segment length
254 not longer than two times shortest distances to edges and faces.
257 minSize: defines the minimal allowed segment length
258 maxSize: defines the maximal allowed segment length
259 deflection: defines the maximal allowed distance from a segment to an edge
260 UseExisting: if ==true - searches for an existing hypothesis created with
261 the same parameters, else (default) - Create a new one
264 an instance of StdMeshers_Adaptive1D hypothesis
267 from salome.smesh.smeshBuilder import IsEqual
268 compFun = lambda hyp, args: ( IsEqual(hyp.GetMinSize(), args[0]) and \
269 IsEqual(hyp.GetMaxSize(), args[1]) and \
270 IsEqual(hyp.GetDeflection(), args[2]))
271 hyp = self.Hypothesis("Adaptive1D", [minSize, maxSize, deflection],
272 UseExisting=UseExisting, CompareMethod=compFun)
273 hyp.SetMinSize(minSize)
274 hyp.SetMaxSize(maxSize)
275 hyp.SetDeflection(deflection)
278 def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
280 Defines "Arithmetic1D" hypothesis to cut an edge in several segments with a length
281 that changes in arithmetic progression
284 start: defines the length of the first segment
285 end: defines the length of the last segment
286 reversedEdges: is a list of edges to mesh using reversed orientation.
287 A list item can also be a tuple (edge, 1st_vertex_of_edge)
288 UseExisting: if ==true - searches for an existing hypothesis created with
289 the same parameters, else (default) - Create a new one
292 an instance of StdMeshers_Arithmetic1D hypothesis
295 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
296 reversedEdges, UseExisting = [], reversedEdges
297 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
298 entry = self.MainShapeEntry()
299 from salome.smesh.smeshBuilder import IsEqual
300 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
301 IsEqual(hyp.GetLength(0), args[1]) and \
302 hyp.GetReversedEdges() == args[2] and \
303 (not args[2] or hyp.GetObjectEntry() == args[3]))
304 hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
305 UseExisting=UseExisting, CompareMethod=compFun)
306 hyp.SetStartLength(start)
307 hyp.SetEndLength(end)
308 hyp.SetReversedEdges( reversedEdgeInd )
309 hyp.SetObjectEntry( entry )
312 def GeometricProgression(self, start, ratio, reversedEdges=[], UseExisting=0):
314 Defines "GeometricProgression" hypothesis to cut an edge in several
315 segments with a length that changes in Geometric progression
318 start: defines the length of the first segment
319 ratio: defines the common ratio of the geometric progression
320 reversedEdges: is a list of edges to mesh using reversed orientation.
321 A list item can also be a tuple (edge, 1st_vertex_of_edge)
322 UseExisting: if ==true - searches for an existing hypothesis created with
323 the same parameters, else (default) - Create a new one
326 an instance of StdMeshers_Geometric1D hypothesis
329 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
330 entry = self.MainShapeEntry()
331 from salome.smesh.smeshBuilder import IsEqual
332 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
333 IsEqual(hyp.GetLength(0), args[1]) and \
334 hyp.GetReversedEdges() == args[2] and \
335 (not args[2] or hyp.GetObjectEntry() == args[3]))
336 hyp = self.Hypothesis("GeometricProgression", [start, ratio, reversedEdgeInd, entry],
337 UseExisting=UseExisting, CompareMethod=compFun)
338 hyp.SetStartLength( start )
339 hyp.SetCommonRatio( ratio )
340 hyp.SetReversedEdges( reversedEdgeInd )
341 hyp.SetObjectEntry( entry )
344 def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
346 Defines "FixedPoints1D" hypothesis to cut an edge using parameter
347 on curve from 0 to 1 (additionally it is neecessary to check
348 orientation of edges and create list of reversed edges if it is
349 needed) and sets numbers of segments between given points (default
353 points: defines the list of parameters on curve
354 nbSegs: defines the list of numbers of segments
355 reversedEdges: is a list of edges to mesh using reversed orientation.
356 A list item can also be a tuple (edge, 1st_vertex_of_edge)
357 UseExisting: if ==true - searches for an existing hypothesis created with
358 the same parameters, else (default) - Create a new one
361 an instance of StdMeshers_FixedPoints1D hypothesis
364 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
365 reversedEdges, UseExisting = [], reversedEdges
366 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
367 entry = self.MainShapeEntry()
368 compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
369 hyp.GetNbSegments() == args[1] and \
370 hyp.GetReversedEdges() == args[2] and \
371 (not args[2] or hyp.GetObjectEntry() == args[3]))
372 hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
373 UseExisting=UseExisting, CompareMethod=compFun)
374 hyp.SetPoints(points)
375 hyp.SetNbSegments(nbSegs)
376 hyp.SetReversedEdges(reversedEdgeInd)
377 hyp.SetObjectEntry(entry)
380 def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
382 Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
385 start: defines the length of the first segment
386 end: defines the length of the last segment
387 reversedEdges: is a list of edges to mesh using reversed orientation.
388 A list item can also be a tuple (edge, 1st_vertex_of_edge)
389 UseExisting: if ==true - searches for an existing hypothesis created with
390 the same parameters, else (default) - Create a new one
393 an instance of StdMeshers_StartEndLength hypothesis
396 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
397 reversedEdges, UseExisting = [], reversedEdges
398 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
399 entry = self.MainShapeEntry()
400 from salome.smesh.smeshBuilder import IsEqual
401 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
402 IsEqual(hyp.GetLength(0), args[1]) and \
403 hyp.GetReversedEdges() == args[2] and \
404 (not args[2] or hyp.GetObjectEntry() == args[3]))
405 hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
406 UseExisting=UseExisting, CompareMethod=compFun)
407 hyp.SetStartLength(start)
408 hyp.SetEndLength(end)
409 hyp.SetReversedEdges( reversedEdgeInd )
410 hyp.SetObjectEntry( entry )
413 def Deflection1D(self, d, UseExisting=0):
415 Defines "Deflection1D" hypothesis
418 d: for the deflection
419 UseExisting: if ==true - searches for an existing hypothesis created with
420 the same parameters, else (default) - create a new one
423 from salome.smesh.smeshBuilder import IsEqual
424 compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
425 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
429 def Propagation(self):
431 Defines "Propagation" hypothesis that propagates 1D hypotheses
432 from an edge where this hypothesis is assigned to
433 on all other edges that are at the opposite side in case of quadrangular faces
434 This hypothesis should be assigned to an edge to propagate a hypothesis from.
437 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
439 def PropagationOfDistribution(self):
441 Defines "Propagation of Node Distribution" hypothesis that propagates
442 distribution of nodes from an edge where this hypothesis is assigned to,
443 to opposite edges of quadrangular faces, so that number of segments on all these
444 edges will be the same, as well as relations between segment lengths.
447 return self.Hypothesis("PropagOfDistribution", UseExisting=1,
448 CompareMethod=self.CompareEqualHyp)
450 def AutomaticLength(self, fineness=0, UseExisting=0):
452 Defines "AutomaticLength" hypothesis
455 fineness: for the fineness [0-1]
456 UseExisting: if ==true - searches for an existing hypothesis created with the
457 same parameters, else (default) - create a new one
460 from salome.smesh.smeshBuilder import IsEqual
461 compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
462 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
463 CompareMethod=compFun)
464 hyp.SetFineness( fineness )
467 def LengthNearVertex(self, length, vertex=-1, UseExisting=0):
469 Defines "SegmentLengthAroundVertex" hypothesis
472 length: for the segment length
473 vertex: for the length localization: the vertex index [0,1] | vertex object.
474 Any other integer value means that the hypothesis will be set on the
475 whole 1D shape, where Mesh_Segment algorithm is assigned.
476 UseExisting: if ==true - searches for an existing hypothesis created with
477 the same parameters, else (default) - Create a new one
481 store_geom = self.geom
482 if isinstance(vertex, int):
483 if vertex == 0 or vertex == 1:
484 from salome.geom import geomBuilder
485 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geomBuilder.geomBuilder.ShapeType["VERTEX"],True)[vertex]
493 if self.geom is None:
494 self.geom = store_geom
495 raise RuntimeError("Attempt to create SegmentAroundVertex_0D algorithm on None shape")
496 from salome.smesh.smeshBuilder import AssureGeomPublished, GetName, TreatHypoStatus
497 AssureGeomPublished( self.mesh, self.geom )
498 name = GetName(self.geom)
500 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
502 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
504 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
505 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True, self.mesh)
507 from salome.smesh.smeshBuilder import IsEqual
508 comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
509 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
510 CompareMethod=comFun)
511 self.geom = store_geom
512 hyp.SetLength( length )
515 def QuadraticMesh(self):
517 Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
518 If the 2D mesher sees that all boundary edges are quadratic,
519 it generates quadratic faces, else it generates linear faces using
520 medium nodes as if they are vertices.
521 The 3D mesher generates quadratic volumes only if all boundary faces
522 are quadratic, else it fails.
525 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
528 pass # end of StdMeshersBuilder_Segment class
530 class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
532 Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
534 It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.COMPOSITE,geom=0)
538 meshMethod = "Segment"
540 name of the dynamic method in smeshBuilder.Mesh class
545 type of algorithm used with helper function in smeshBuilder.Mesh class
550 flag pointing whether this algorithm should be used by default in dynamic method
551 of smeshBuilder.Mesh class
554 docHelper = "Create segment 1D algorithm for edges"
556 doc string of the method
559 def __init__(self, mesh, geom=0):
564 mesh: parent mesh object algorithm is assigned to
565 geom: geometry (shape/sub-shape) algorithm is assigned to;
566 if it is :code:`0` (default), the algorithm is assigned to the main shape
568 self.Create(mesh, geom, self.algoType)
571 pass # end of StdMeshersBuilder_CompositeSegment class
573 class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
575 Defines a segment 1D algorithm for discretization of edges with Python function.
576 It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.PYTHON,geom=0)
580 meshMethod = "Segment"
582 name of the dynamic method in smeshBuilder.Mesh class
586 type of algorithm used with helper function in smeshBuilder.Mesh class
588 docHelper = "Create segment 1D algorithm for edges"
590 doc string of the method
593 def __init__(self, mesh, geom=0):
598 mesh: parent mesh object algorithm is assigned to
599 geom: geometry (shape/sub-shape) algorithm is assigned to;
600 if it is :code:`0` (default), the algorithm is assigned to the main shape
602 import Python1dPlugin
603 self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
606 def PythonSplit1D(self, n, func, UseExisting=0):
608 Defines "PythonSplit1D" hypothesis
611 n: for the number of segments that cut an edge
612 func: for the python function that calculates the length of all segments
613 UseExisting: if ==true - searches for the existing hypothesis created with
614 the same parameters, else (default) - Create a new one
617 compFun = lambda hyp, args: False
618 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
619 UseExisting=UseExisting, CompareMethod=compFun)
620 hyp.SetNumberOfSegments(n)
621 hyp.SetPythonLog10RatioFunction(func)
624 pass # end of StdMeshersBuilder_Segment_Python class
626 class StdMeshersBuilder_Triangle_MEFISTO(Mesh_Algorithm):
628 Triangle MEFISTO 2D algorithm.
629 It is created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MEFISTO,geom=0)
633 meshMethod = "Triangle"
635 name of the dynamic method in smeshBuilder.Mesh class
639 type of algorithm used with helper function in smeshBuilder.Mesh class
643 flag pointing whether this algorithm should be used by default in dynamic method
644 of smeshBuilder.Mesh class
646 docHelper = "Create triangle 2D algorithm for faces"
648 doc string of the method
651 def __init__(self, mesh, geom=0):
656 mesh: parent mesh object algorithm is assigned to
657 geom: geometry (shape/sub-shape) algorithm is assigned to;
658 if it is :code:`0` (default), the algorithm is assigned to the main shape
660 Mesh_Algorithm.__init__(self)
661 self.Create(mesh, geom, self.algoType)
664 def MaxElementArea(self, area, UseExisting=0):
666 Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
669 area: for the maximum area of each triangle
670 UseExisting: if ==true - searches for an existing hypothesis created with the
671 same parameters, else (default) - Create a new one
674 from salome.smesh.smeshBuilder import IsEqual
675 comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
676 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
677 CompareMethod=comparator)
678 hyp.SetMaxElementArea(area)
681 def LengthFromEdges(self):
683 Defines "LengthFromEdges" hypothesis to build triangles
684 based on the length of the edges taken from the wire
687 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
690 pass # end of StdMeshersBuilder_Triangle_MEFISTO class
692 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
694 Defines a quadrangle 2D algorithm.
695 It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
699 meshMethod = "Quadrangle"
701 name of the dynamic method in smeshBuilder.Mesh class
703 algoType = QUADRANGLE
705 type of algorithm used with helper function in smeshBuilder.Mesh class
709 flag pointing whether this algorithm should be used by default in dynamic method
710 of smeshBuilder.Mesh class
712 docHelper = "Create quadrangle 2D algorithm for faces"
714 doc string of the method
718 hypothesis associated with algorithm
721 def __init__(self, mesh, geom=0):
726 mesh: parent mesh object algorithm is assigned to
727 geom: geometry (shape/sub-shape) algorithm is assigned to;
728 if it is :code:`0` (default), the algorithm is assigned to the main shape
730 Mesh_Algorithm.__init__(self)
731 self.Create(mesh, geom, self.algoType)
734 def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0,
735 enfVertices=[],enfPoints=[],corners=[],UseExisting=0):
737 Defines "QuadrangleParameters" hypothesis
738 quadType defines the algorithm of transition between differently descretized
739 sides of a geometrical face:
741 - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
742 area along the finer meshed sides.
743 - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
745 - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
746 the finer meshed sides, iff the total quantity of segments on
747 all four sides of the face is even (divisible by 2).
748 - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
749 area is located along the coarser meshed sides.
750 - QUAD_REDUCED - only quadrangles are built and the transition between the sides
751 is made gradually, layer by layer. This type has a limitation on
752 the number of segments: one pair of opposite sides must have the
753 same number of segments, the other pair must have an even difference
754 between the numbers of segments on the sides.
757 triangleVertex: vertex of a trilateral geometrical face, around which triangles
758 will be created while other elements will be quadrangles.
759 Vertex can be either a GEOM_Object or a vertex ID within the
761 enfVertices: list of shapes defining positions where nodes (enforced nodes)
762 must be created by the mesher. Shapes can be of any type,
763 vertices of given shapes define positions of enforced nodes.
764 Only vertices successfully projected to the face are used.
765 enfPoints: list of points giving positions of enforced nodes.
766 Point can be defined either as SMESH.PointStruct's
767 ([SMESH.PointStruct(x1,y1,z1), SMESH.PointStruct(x2,y2,z2),...])
768 or triples of values ([[x1,y1,z1], [x2,y2,z2], ...]).
769 In the case if the defined QuadrangleParameters() refer to a sole face,
770 all given points must lie on this face, else the mesher fails.
771 corners: list of vertices that should be used as quadrangle corners.
772 The parameter can be useful for faces with more than four vertices,
773 since in some cases Quadrangle Mapping algorithm chooses corner vertices
774 differently than it is desired.
775 A hypothesis can be global and define corners for all CAD faces that
776 require it, but be sure that each specified vertex is a corner in all
777 faces the hypothesis will be applied to.
778 UseExisting: if *True* - searches for the existing hypothesis created with
779 the same parameters, else (default) - Create a new one
784 vertexID = triangleVertex
785 if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
786 vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
787 if isinstance( enfVertices, int ) and not enfPoints and not UseExisting:
788 # a call of old syntax, before inserting enfVertices and enfPoints before UseExisting
789 UseExisting, enfVertices = enfVertices, []
791 pStructs, xyz = [], []
793 if isinstance( p, SMESH.PointStruct ):
794 xyz.append(( p.x, p.y, p.z ))
797 xyz.append(( p[0], p[1], p[2] ))
798 pStructs.append( SMESH.PointStruct( p[0], p[1], p[2] ))
800 compFun = lambda hyp,args: \
801 hyp.GetQuadType() == args[0] and \
802 (hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1)) and \
803 ((hyp.GetEnforcedNodes()) == (args[2],args[3])) # True w/o enfVertices only
804 entries = [ shape.GetStudyEntry() for shape in enfVertices ]
805 self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID,entries,xyz],
806 UseExisting = UseExisting, CompareMethod=compFun)
809 if corners and isinstance( corners[0], GEOM._objref_GEOM_Object ):
810 corners = [ self.mesh.geompyD.GetSubShapeID( self.mesh.geom, v ) for v in corners ]
812 if self.params.GetQuadType() != quadType:
813 self.params.SetQuadType(quadType)
815 self.params.SetTriaVertex( vertexID )
816 from salome.smesh.smeshBuilder import AssureGeomPublished
817 for v in enfVertices:
818 AssureGeomPublished( self.mesh, v )
819 self.params.SetEnforcedNodes( enfVertices, pStructs )
820 self.params.SetCorners( corners )
823 def QuadranglePreference(self, reversed=False, UseExisting=0):
825 Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
826 quadrangles are built in the transition area along the finer meshed sides,
827 if the total quantity of segments on all four sides of the face is even.
830 reversed: if True, transition area is located along the coarser meshed sides.
831 UseExisting: if ==true - searches for the existing hypothesis created with
832 the same parameters, else (default) - Create a new one
836 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
837 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
839 def TrianglePreference(self, UseExisting=0):
841 Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
842 triangles are built in the transition area along the finer meshed sides.
845 UseExisting: if ==true - searches for the existing hypothesis created with
846 the same parameters, else (default) - Create a new one
849 return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
851 def Reduced(self, UseExisting=0):
853 Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
854 quadrangles are built and the transition between the sides is made gradually,
855 layer by layer. This type has a limitation on the number of segments: one pair
856 of opposite sides must have the same number of segments, the other pair must
857 have an even difference between the numbers of segments on the sides.
860 UseExisting: if ==true - searches for the existing hypothesis created with
861 the same parameters, else (default) - Create a new one
864 return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
866 def TriangleVertex(self, vertex, UseExisting=0):
868 Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
871 vertex: vertex of a trilateral geometrical face, around which triangles
872 will be created while other elements will be quadrangles.
873 Vertex can be either a GEOM_Object or a vertex ID within the
875 UseExisting: if ==true - searches for the existing hypothesis created with
876 the same parameters, else (default) - Create a new one
879 return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
881 pass # end of StdMeshersBuilder_Quadrangle class
883 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
885 Defines a hexahedron 3D algorithm.
886 It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
890 meshMethod = "Hexahedron"
892 name of the dynamic method in smeshBuilder.Mesh class
896 type of algorithm used with helper function in smeshBuilder.Mesh class
900 flag pointing whether this algorithm should be used by default in dynamic method
901 of smeshBuilder.Mesh class
903 docHelper = "Create hexahedron 3D algorithm for volumes"
905 doc string of the method
908 def __init__(self, mesh, geom=0):
913 mesh: parent mesh object algorithm is assigned to
914 geom: geometry (shape/sub-shape) algorithm is assigned to;
915 if it is :code:`0` (default), the algorithm is assigned to the main shape
917 Mesh_Algorithm.__init__(self)
918 self.Create(mesh, geom, Hexa)
919 self.renumHypothesis = 0
922 def Renumber(self, blockCSList=[] ):
923 if isinstance( blockCSList, StdMeshers.BlockCS ):
924 blockCSList = [blockCSList]
925 if not self.renumHypothesis:
926 self.renumHypothesis = self.Hypothesis("BlockRenumber", blockCSList, UseExisting=0)
927 self.renumHypothesis.SetBlocksOrientation( blockCSList )
928 return self.renumHypothesis
930 pass # end of StdMeshersBuilder_Hexahedron class
932 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
934 Defines a projection 1D algorithm.
935 It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
939 meshMethod = "Projection1D"
941 name of the dynamic method in smeshBuilder.Mesh class
943 algoType = "Projection_1D"
945 type of algorithm used with helper function in smeshBuilder.Mesh class
949 flag pointing whether this algorithm should be used by default in dynamic method
950 of smeshBuilder.Mesh class
952 docHelper = "Create projection 1D algorithm for edges"
954 doc string of the method
956 def __init__(self, mesh, geom=0):
961 mesh: parent mesh object algorithm is assigned to
962 geom: geometry (shape/sub-shape) algorithm is assigned to;
963 if it is :code:`0` (default), the algorithm is assigned to the main shape
965 Mesh_Algorithm.__init__(self)
966 self.Create(mesh, geom, self.algoType)
969 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
971 Defines "Source Edge" hypothesis, specifying a meshed edge, from where
972 a mesh pattern is taken, and, optionally, the association of vertices
973 between the source edge and a target edge (to which a hypothesis is assigned)
976 edge: from which nodes distribution is taken
977 mesh: from which nodes distribution is taken (optional)
978 srcV: a vertex of *edge* to associate with *tgtV* (optional)
979 tgtV: a vertex of *the edge* to which the algorithm is assigned, to associate with *srcV* (optional)
980 UseExisting: if ==true - searches for the existing hypothesis created with
981 the same parameters, else (default) - Create a new one
983 from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
984 AssureGeomPublished( self.mesh, edge )
985 AssureGeomPublished( self.mesh, srcV )
986 AssureGeomPublished( self.mesh, tgtV )
987 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
989 # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
990 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
991 hyp.SetSourceEdge( edge )
992 if not mesh is None and isinstance(mesh, Mesh):
993 mesh = mesh.GetMesh()
994 hyp.SetSourceMesh( mesh )
995 hyp.SetVertexAssociation( srcV, tgtV )
998 pass # end of StdMeshersBuilder_Projection1D class
1000 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
1002 Defines a projection 2D algorithm.
1003 It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
1007 meshMethod = "Projection2D"
1009 name of the dynamic method in smeshBuilder.Mesh class
1011 algoType = "Projection_2D"
1013 type of algorithm used with helper function in smeshBuilder.Mesh class
1017 flag pointing whether this algorithm should be used by default in dynamic method
1018 of smeshBuilder.Mesh class
1020 docHelper = "Create projection 2D algorithm for faces"
1022 doc string of the method
1025 def __init__(self, mesh, geom=0):
1027 Private constructor.
1030 mesh: parent mesh object algorithm is assigned to
1031 geom: geometry (shape/sub-shape) algorithm is assigned to;
1032 if it is :code:`0` (default), the algorithm is assigned to the main shape
1034 Mesh_Algorithm.__init__(self)
1035 self.Create(mesh, geom, self.algoType)
1039 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1040 srcV2=None, tgtV2=None, UseExisting=0):
1042 Defines "Source Face" hypothesis, specifying a meshed face, from where
1043 a mesh pattern is taken, and, optionally, the association of vertices
1044 between the source face and the target face (to which a hypothesis is assigned)
1047 face: from which the mesh pattern is taken
1048 mesh: from which the mesh pattern is taken (optional)
1049 srcV1: a vertex of *face* to associate with *tgtV1* (optional)
1050 tgtV1: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV1* (optional)
1051 srcV2: a vertex of *face* to associate with *tgtV1* (optional)
1052 tgtV2: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV2* (optional)
1053 UseExisting: if ==true - forces the search for the existing hypothesis created with
1054 he same parameters, else (default) - forces the creation a new one
1057 all association vertices must belong to one edge of a face
1059 from salome.smesh.smeshBuilder import Mesh
1060 if isinstance(mesh, Mesh):
1061 mesh = mesh.GetMesh()
1062 for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
1063 from salome.smesh.smeshBuilder import AssureGeomPublished
1064 AssureGeomPublished( self.mesh, geom )
1065 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1066 UseExisting=0, toAdd=False)
1067 # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
1068 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
1069 hyp.SetSourceFace( face )
1070 hyp.SetSourceMesh( mesh )
1071 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1072 self.mesh.AddHypothesis(hyp, self.geom)
1075 pass # end of StdMeshersBuilder_Projection2D class
1077 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
1079 Defines a projection 1D-2D algorithm.
1080 It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
1084 meshMethod = "Projection1D2D"
1086 name of the dynamic method in smeshBuilder.Mesh class
1088 algoType = "Projection_1D2D"
1090 type of algorithm used with helper function in smeshBuilder.Mesh class
1092 docHelper = "Create projection 1D-2D algorithm for faces"
1094 doc string of the method
1097 def __init__(self, mesh, geom=0):
1099 Private constructor.
1102 mesh: parent mesh object algorithm is assigned to
1103 geom: geometry (shape/sub-shape) algorithm is assigned to;
1104 if it is :code:`0` (default), the algorithm is assigned to the main shape
1106 StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
1109 pass # end of StdMeshersBuilder_Projection1D2D class
1111 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
1113 Defines a projection 3D algorithm.
1114 It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
1118 meshMethod = "Projection3D"
1120 name of the dynamic method in smeshBuilder.Mesh class
1122 algoType = "Projection_3D"
1124 type of algorithm used with helper function in smeshBuilder.Mesh class
1126 docHelper = "Create projection 3D algorithm for volumes"
1128 doc string of the method
1131 def __init__(self, mesh, geom=0):
1133 Private constructor.
1136 mesh: parent mesh object algorithm is assigned to
1137 geom" geometry (shape/sub-shape) algorithm is assigned to;
1138 if it is :code:`0` (default), the algorithm is assigned to the main shape
1140 Mesh_Algorithm.__init__(self)
1141 self.Create(mesh, geom, self.algoType)
1144 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1145 srcV2=0, tgtV2=0, UseExisting=0):
1147 Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
1148 the mesh pattern is taken, and, optionally, the association of vertices
1149 between the source and the target solid (to which a hipothesis is assigned)
1152 solid: from where the mesh pattern is taken
1153 mesh: from where the mesh pattern is taken (optional)
1154 srcV1: a vertex of *solid* to associate with *tgtV1* (optional)
1155 tgtV1: a vertex of *the solid* where the algorithm is assigned, to associate with *srcV1* (optional)
1156 srcV2: a vertex of *solid* to associate with *tgtV1* (optional)
1157 tgtV2: a vertex of *the solid* to which the algorithm is assigned,to associate with *srcV2* (optional)
1158 UseExisting: if ==true - searches for the existing hypothesis created with
1159 the same parameters, else (default) - Create a new one
1162 association vertices must belong to one edge of a solid
1164 for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
1165 from salome.smesh.smeshBuilder import AssureGeomPublished
1166 AssureGeomPublished( self.mesh, geom )
1167 hyp = self.Hypothesis("ProjectionSource3D",
1168 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1170 # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
1171 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
1172 hyp.SetSource3DShape( solid )
1173 from salome.smesh.smeshBuilder import Mesh
1174 if isinstance(mesh, Mesh):
1175 mesh = mesh.GetMesh()
1177 hyp.SetSourceMesh( mesh )
1178 if srcV1 and srcV2 and tgtV1 and tgtV2:
1179 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1180 #elif srcV1 or srcV2 or tgtV1 or tgtV2:
1183 pass # end of StdMeshersBuilder_Projection3D class
1185 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
1187 Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism" depending on geometry.
1188 It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1192 meshMethod = "Prism"
1194 name of the dynamic method in smeshBuilder.Mesh class
1196 algoType = "Prism_3D"
1198 type of algorithm used with helper function in smeshBuilder.Mesh class
1200 docHelper = "Create prism 3D algorithm for volumes"
1202 doc string of the method
1206 flag pointing whether this algorithm should be used by default in dynamic method
1207 of smeshBuilder.Mesh class
1210 def __init__(self, mesh, geom=0):
1212 Private constructor.
1215 mesh: parent mesh object algorithm is assigned to
1216 geom: geometry (shape/sub-shape) algorithm is assigned to;
1217 if it is :code:`0` (default), the algorithm is assigned to the main shape
1219 Mesh_Algorithm.__init__(self)
1224 isRadial = mesh.smeshpyD.IsApplicable("RadialPrism_3D", LIBRARY, shape, False )
1226 self.Create(mesh, geom, "Prism_3D")
1229 self.algoType = "RadialPrism_3D"
1230 self.Create(mesh, geom, "RadialPrism_3D")
1231 self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
1232 self.nbLayers = None
1236 def Get3DHypothesis(self):
1239 3D hypothesis holding the 1D one
1241 if self.algoType != "RadialPrism_3D":
1242 print("Prism_3D algorithm doesn't support any hypothesis")
1244 return self.distribHyp
1246 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1248 Private method creating a 1D hypothesis and storing it in the LayerDistribution
1252 the created hypothesis
1254 if self.algoType != "RadialPrism_3D":
1255 print("Prism_3D algorithm doesn't support any hypothesis")
1257 if not self.nbLayers is None:
1258 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1259 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1260 self.mesh.smeshpyD.SetEnablePublish( False ) # prevents publishing own 1D hypothesis
1261 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1262 self.mesh.smeshpyD.SetEnablePublish( True ) # enables publishing
1263 if not self.distribHyp:
1264 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1265 self.distribHyp.SetLayerDistribution( hyp )
1268 def NumberOfLayers(self, n, UseExisting=0):
1270 Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1271 prisms to build between the inner and outer shells
1275 UseExisting: if ==true - searches for the existing hypothesis created with
1276 the same parameters, else (default) - Create a new one
1278 if self.algoType != "RadialPrism_3D":
1279 print("Prism_3D algorithm doesn't support any hypothesis")
1281 self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1282 from salome.smesh.smeshBuilder import IsEqual
1283 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1284 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1285 CompareMethod=compFun)
1286 self.nbLayers.SetNumberOfLayers( n )
1287 return self.nbLayers
1289 def LocalLength(self, l, p=1e-07):
1291 Defines "LocalLength" hypothesis, specifying the segment length
1292 to build between the inner and the outer shells
1295 l: the length of segments
1296 p: the precision of rounding
1298 if self.algoType != "RadialPrism_3D":
1299 print("Prism_3D algorithm doesn't support any hypothesis")
1301 hyp = self.OwnHypothesis("LocalLength", [l,p])
1306 def NumberOfSegments(self, n, s=[]):
1308 Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1309 prisms to build between the inner and the outer shells.
1312 n: the number of layers
1313 s: the scale factor (optional)
1315 if self.algoType != "RadialPrism_3D":
1316 print("Prism_3D algorithm doesn't support any hypothesis")
1319 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1321 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1322 hyp.SetScaleFactor(s)
1323 hyp.SetNumberOfSegments(n)
1326 def Arithmetic1D(self, start, end ):
1328 Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1329 to build between the inner and the outer shells with a length that changes
1330 in arithmetic progression
1333 start: the length of the first segment
1334 end: the length of the last segment
1336 if self.algoType != "RadialPrism_3D":
1337 print("Prism_3D algorithm doesn't support any hypothesis")
1339 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1340 hyp.SetLength(start, 1)
1341 hyp.SetLength(end , 0)
1344 def GeometricProgression(self, start, ratio ):
1346 Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1347 to build between the inner and the outer shells with a length that changes
1348 in Geometric progression
1351 start: the length of the first segment
1352 ratio: the common ratio of the geometric progression
1354 if self.algoType != "RadialPrism_3D":
1355 print("Prism_3D algorithm doesn't support any hypothesis")
1357 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1358 hyp.SetStartLength( start )
1359 hyp.SetCommonRatio( ratio )
1362 def StartEndLength(self, start, end):
1364 Defines "StartEndLength" hypothesis, specifying distribution of segments
1365 to build between the inner and the outer shells as geometric length increasing
1368 start: for the length of the first segment
1369 end: for the length of the last segment
1371 if self.algoType != "RadialPrism_3D":
1372 print("Prism_3D algorithm doesn't support any hypothesis")
1374 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1375 hyp.SetLength(start, 1)
1376 hyp.SetLength(end , 0)
1379 def AutomaticLength(self, fineness=0):
1381 Defines "AutomaticLength" hypothesis, specifying the number of segments
1382 to build between the inner and outer shells
1385 fineness: defines the quality of the mesh within the range [0-1]
1387 if self.algoType != "RadialPrism_3D":
1388 print("Prism_3D algorithm doesn't support any hypothesis")
1390 hyp = self.OwnHypothesis("AutomaticLength")
1391 hyp.SetFineness( fineness )
1394 pass # end of StdMeshersBuilder_Prism3D class
1396 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1398 Defines Radial Prism 3D algorithm.
1399 It is created by calling smeshBuilder.Mesh.Prism(geom=0).
1400 See :class:`StdMeshersBuilder_Prism3D` for methods defining distribution of mesh layers
1401 build between the inner and outer shells.
1404 meshMethod = "Prism"
1406 name of the dynamic method in smeshBuilder.Mesh class
1408 algoType = "RadialPrism_3D"
1410 type of algorithm used with helper function in smeshBuilder.Mesh class
1412 docHelper = "Create Raial Prism 3D algorithm for volumes"
1414 doc string of the method
1417 def __init__(self, mesh, geom=0):
1419 Private constructor.
1422 mesh: parent mesh object algorithm is assigned to
1423 geom: geometry (shape/sub-shape) algorithm is assigned to;
1424 if it is :code:`0` (default), the algorithm is assigned to the main shape
1426 Mesh_Algorithm.__init__(self)
1431 self.Create(mesh, geom, "RadialPrism_3D")
1432 self.distribHyp = None
1433 self.nbLayers = None
1436 class StdMeshersBuilder_RadialAlgorithm(Mesh_Algorithm):
1438 Base class for algorithms supporting radial distribution hypotheses
1442 Mesh_Algorithm.__init__(self)
1444 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1445 self.nbLayers = None
1448 def Get2DHypothesis(self):
1451 2D hypothesis holding the 1D one
1453 if not self.distribHyp:
1454 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1455 return self.distribHyp
1457 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1459 Private method creating a 1D hypothesis and storing it in the LayerDistribution
1463 the created hypothesis
1466 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1467 if self.distribHyp is None:
1468 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1470 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1471 self.mesh.smeshpyD.SetEnablePublish( False )
1472 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1473 self.mesh.smeshpyD.SetEnablePublish( True )
1474 self.distribHyp.SetLayerDistribution( hyp )
1477 def NumberOfLayers(self, n, UseExisting=0):
1479 Defines "NumberOfLayers" hypothesis, specifying the number of layers
1483 UseExisting: if ==true - searches for the existing hypothesis created with
1484 the same parameters, else (default) - Create a new one
1487 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1488 from salome.smesh.smeshBuilder import IsEqual
1489 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1490 self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1491 CompareMethod=compFun)
1492 self.nbLayers.SetNumberOfLayers( n )
1493 return self.nbLayers
1495 def LocalLength(self, l, p=1e-07):
1497 Defines "LocalLength" hypothesis, specifying the segment length
1500 l: the length of segments
1501 p: the precision of rounding
1503 hyp = self.OwnHypothesis("LocalLength", [l,p])
1508 def NumberOfSegments(self, n, s=[]):
1510 Defines "NumberOfSegments" hypothesis, specifying the number of layers
1513 n: the number of layers
1514 s: the scale factor (optional)
1517 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1519 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1520 hyp.SetDistrType( 1 )
1521 hyp.SetScaleFactor(s)
1522 hyp.SetNumberOfSegments(n)
1525 def Arithmetic1D(self, start, end ):
1527 Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1528 with a length that changes in arithmetic progression
1531 start: the length of the first segment
1532 end: the length of the last segment
1534 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1535 hyp.SetLength(start, 1)
1536 hyp.SetLength(end , 0)
1539 def GeometricProgression(self, start, ratio ):
1541 Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1542 with a length that changes in Geometric progression
1545 start: the length of the first segment
1546 ratio: the common ratio of the geometric progression
1548 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1549 hyp.SetStartLength( start )
1550 hyp.SetCommonRatio( ratio )
1553 def StartEndLength(self, start, end):
1555 Defines "StartEndLength" hypothesis, specifying distribution of segments
1556 as geometric length increasing
1559 start: for the length of the first segment
1560 end: for the length of the last segment
1562 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1563 hyp.SetLength(start, 1)
1564 hyp.SetLength(end , 0)
1567 def AutomaticLength(self, fineness=0):
1569 Defines "AutomaticLength" hypothesis, specifying the number of segments
1572 fineness: defines the quality of the mesh within the range [0-1]
1574 hyp = self.OwnHypothesis("AutomaticLength")
1575 hyp.SetFineness( fineness )
1578 pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1580 class StdMeshersBuilder_RadialQuadrangle1D2D(StdMeshersBuilder_RadialAlgorithm):
1582 Defines a Radial Quadrangle 1D-2D algorithm.
1583 It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1586 meshMethod = "Quadrangle"
1588 name of the dynamic method in smeshBuilder.Mesh class
1590 algoType = RADIAL_QUAD
1592 type of algorithm used with helper function in smeshBuilder.Mesh class
1594 docHelper = "Create quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
1596 doc string of the method
1599 def __init__(self, mesh, geom=0):
1601 Private constructor.
1604 mesh: parent mesh object algorithm is assigned to
1605 geom: geometry (shape/sub-shape) algorithm is assigned to;
1606 if it is :code:`0` (default), the algorithm is assigned to the main shape
1608 StdMeshersBuilder_RadialAlgorithm.__init__(self)
1609 self.Create(mesh, geom, self.algoType)
1611 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1612 self.nbLayers = None
1616 class StdMeshersBuilder_QuadMA_1D2D(StdMeshersBuilder_RadialAlgorithm):
1618 Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm .
1619 It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
1622 meshMethod = "Quadrangle"
1624 name of the dynamic method in smeshBuilder.Mesh class
1626 algoType = QUAD_MA_PROJ
1628 type of algorithm used with helper function in smeshBuilder.Mesh class
1630 docHelper = "Create quadrangle 1D-2D algorithm for faces"
1632 doc string of the method
1635 def __init__(self, mesh, geom=0):
1637 Private constructor.
1640 mesh: parent mesh object algorithm is assigned to
1641 geom: geometry (shape/sub-shape) algorithm is assigned to;
1642 if it is :code:`0` (default), the algorithm is assigned to the main shape
1644 StdMeshersBuilder_RadialAlgorithm.__init__(self)
1645 self.Create(mesh, geom, self.algoType)
1650 class StdMeshersBuilder_PolygonPerFace(Mesh_Algorithm):
1651 """ Defines a Polygon Per Face 2D algorithm.
1652 It is created by calling smeshBuilder.Mesh.Polygon(geom=0)
1655 meshMethod = "Polygon"
1657 name of the dynamic method in smeshBuilder.Mesh class
1661 type of algorithm used with helper function in smeshBuilder.Mesh class
1665 flag pointing whether this algorithm should be used by default in dynamic method
1666 of smeshBuilder.Mesh class
1668 docHelper = "Create polygon 2D algorithm for faces"
1670 doc string of the method
1673 def __init__(self, mesh, geom=0):
1675 Private constructor.
1678 mesh: parent mesh object algorithm is assigned to
1679 geom: geometry (shape/sub-shape) algorithm is assigned to;
1680 if it is :code:`0` (default), the algorithm is assigned to the main shape
1682 Mesh_Algorithm.__init__(self)
1683 self.Create(mesh, geom, self.algoType)
1688 class StdMeshersBuilder_PolyhedronPerSolid(Mesh_Algorithm):
1689 """ Defines a Polyhedron Per Solid 3D algorithm.
1690 It is created by calling smeshBuilder.Mesh.Polyhedron(geom=0)
1693 meshMethod = "Polyhedron"
1695 name of the dynamic method in smeshBuilder.Mesh class
1697 algoType = POLYHEDRON
1699 type of algorithm used with helper function in smeshBuilder.Mesh class
1703 flag pointing whether this algorithm should be used by default in dynamic method
1704 of smeshBuilder.Mesh class
1706 docHelper = "Create polyhedron 3D algorithm for solids"
1708 doc string of the method
1711 def __init__(self, mesh, geom=0):
1713 Private constructor.
1716 mesh: parent mesh object algorithm is assigned to
1717 geom: geometry (shape/sub-shape) algorithm is assigned to;
1718 if it is :code:`0` (default), the algorithm is assigned to the main shape
1720 Mesh_Algorithm.__init__(self)
1721 self.Create(mesh, geom, self.algoType)
1726 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1727 """ Defines a Use Existing Elements 1D algorithm.
1729 It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1733 meshMethod = "UseExisting1DElements"
1735 name of the dynamic method in smeshBuilder.Mesh class
1737 algoType = "Import_1D"
1739 type of algorithm used with helper function in smeshBuilder.Mesh class
1743 flag pointing whether this algorithm should be used by default in dynamic method
1744 of smeshBuilder.Mesh class
1746 docHelper = "Create 1D algorithm for edges with reusing of existing mesh elements"
1748 doc string of the method
1751 def __init__(self, mesh, geom=0):
1753 Private constructor.
1756 mesh: parent mesh object algorithm is assigned to
1757 geom: geometry (shape/sub-shape) algorithm is assigned to;
1758 if it is :code:`0` (default), the algorithm is assigned to the main shape
1760 Mesh_Algorithm.__init__(self)
1761 self.Create(mesh, geom, self.algoType)
1764 def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1766 Defines "Source edges" hypothesis, specifying groups of edges to import
1769 groups: list of groups of edges
1770 toCopyMesh: if True, the whole mesh *groups* belong to is imported
1771 toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1772 UseExisting: if ==true - searches for the existing hypothesis created with
1773 the same parameters, else (default) - Create a new one
1775 for group in groups:
1776 from salome.smesh.smeshBuilder import AssureGeomPublished
1777 AssureGeomPublished( self.mesh, group )
1778 compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1779 hyp.GetCopySourceMesh() == args[1], args[2] )
1780 hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1781 UseExisting=UseExisting, CompareMethod=compFun)
1782 hyp.SetSourceEdges(groups)
1783 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1786 pass # end of StdMeshersBuilder_UseExistingElements_1D class
1788 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1789 """ Defines a Use Existing Elements 1D-2D algorithm.
1791 It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1795 meshMethod = "UseExisting2DElements"
1797 name of the dynamic method in smeshBuilder.Mesh class
1799 algoType = "Import_1D2D"
1801 type of algorithm used with helper function in smeshBuilder.Mesh class
1805 flag pointing whether this algorithm should be used by default in dynamic method
1806 of smeshBuilder.Mesh class
1808 docHelper = "Create 1D-2D algorithm for faces with reusing of existing mesh elements"
1810 doc string of the method
1813 def __init__(self, mesh, geom=0):
1815 Private constructor.
1818 mesh: parent mesh object algorithm is assigned to
1819 geom: geometry (shape/sub-shape) algorithm is assigned to;
1820 if it is :code:`0` (default), the algorithm is assigned to the main shape
1822 Mesh_Algorithm.__init__(self)
1823 self.Create(mesh, geom, self.algoType)
1826 def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1828 Defines "Source faces" hypothesis, specifying groups of faces to import
1831 groups: list of groups of faces
1832 toCopyMesh: if True, the whole mesh *groups* belong to is imported
1833 toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1834 UseExisting: if ==true - searches for the existing hypothesis created with
1835 the same parameters, else (default) - Create a new one
1838 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1839 hyp.GetCopySourceMesh() == args[1], args[2] )
1840 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1841 UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1842 if groups and isinstance( groups, SMESH._objref_SMESH_GroupBase ):
1844 hyp.SetSourceFaces(groups)
1845 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1846 self.mesh.AddHypothesis(hyp, self.geom)
1849 pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1851 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1852 """ Defines a Body Fitting 3D algorithm.
1854 It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1858 meshMethod = "BodyFitted"
1860 name of the dynamic method in smeshBuilder.Mesh class
1862 algoType = "Cartesian_3D"
1864 type of algorithm used with helper function in smeshBuilder.Mesh class
1868 flag pointing whether this algorithm should be used by default in dynamic method
1869 of smeshBuilder.Mesh class
1871 docHelper = "Create Body Fitting 3D algorithm for volumes"
1873 doc string of the method
1876 def __init__(self, mesh, geom=0):
1878 Private constructor.
1881 mesh: parent mesh object algorithm is assigned to
1882 geom: geometry (shape/sub-shape) algorithm is assigned to;
1883 if it is :code:`0` (default), the algorithm is assigned to the main shape
1885 self.Create(mesh, geom, self.algoType)
1889 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1891 Defines "Body Fitting parameters" hypothesis
1894 xGridDef: is definition of the grid along the X asix.
1895 It can be in either of two following forms:
1897 - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1898 - Functions f(t) defining grid spacing at each point on grid axis. If there are
1899 several functions, they must be accompanied by relative coordinates of
1900 points dividing the whole shape into ranges where the functions apply; points
1901 coordinates should vary within (0.0, 1.0) range. Parameter *t* of the spacing
1902 function f(t) varies from 0.0 to 1.0 within a shape range.
1904 The actual grid spacing can slightly differ from the defined one. This is done for the
1905 best fitting of polyhedrons and for a better mesh quality on the interval boundaries.
1906 For example, if a constant **Spacing** is defined along an axis, the actual grid will
1907 fill the shape's dimension L along this axis with round number of equal cells:
1908 Spacing_actual = L / round( L / Spacing_defined ).
1911 "10.5" - defines a grid with a constant spacing
1912 [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1915 yGridDef: defines the grid along the Y asix the same way as *xGridDef* does.
1916 zGridDef: defines the grid along the Z asix the same way as *xGridDef* does.
1917 sizeThreshold: (> 1.0) defines a minimal size of a polyhedron so that
1918 a polyhedron of size less than hexSize/sizeThreshold is not created.
1919 implEdges: enables implementation of geometrical edges into the mesh.
1922 compFun = lambda hyp, args: False
1923 self.hyp = self.Hypothesis("CartesianParameters3D",
1924 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1925 UseExisting=False, CompareMethod=compFun)
1926 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1927 self.mesh.AddHypothesis( self.hyp, self.geom )
1929 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1930 if not gridDef: raise ValueError("Empty grid definition")
1931 if isinstance( gridDef, str ):
1932 self.hyp.SetGridSpacing( [gridDef], [], axis )
1933 elif isinstance( gridDef[0], str ):
1934 self.hyp.SetGridSpacing( gridDef, [], axis )
1935 elif isinstance( gridDef[0], int ) or \
1936 isinstance( gridDef[0], float ):
1937 self.hyp.SetGrid(gridDef, axis )
1939 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1940 self.hyp.SetSizeThreshold( sizeThreshold )
1941 self.hyp.SetToAddEdges( implEdges )
1944 def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1946 Defines custom directions of axes of the grid
1949 xAxis: either SMESH.DirStruct or a vector, or 3 vector components
1950 yAxis: either SMESH.DirStruct or a vector, or 3 vector components
1951 zAxis: either SMESH.DirStruct or a vector, or 3 vector components
1954 if hasattr( xAxis, "__getitem__" ):
1955 xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1956 elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1957 xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1958 if hasattr( yAxis, "__getitem__" ):
1959 yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1960 elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1961 yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1962 if hasattr( zAxis, "__getitem__" ):
1963 zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1964 elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1965 zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1967 self.hyp = self.Hypothesis("CartesianParameters3D")
1968 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1969 self.mesh.AddHypothesis( self.hyp, self.geom )
1970 self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1973 def SetOptimalAxesDirs(self, isOrthogonal=True):
1975 Automatically defines directions of axes of the grid at which
1976 a number of generated hexahedra is maximal
1979 isOrthogonal: defines whether the axes mush be orthogonal
1982 self.hyp = self.Hypothesis("CartesianParameters3D")
1983 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1984 self.mesh.AddHypothesis( self.hyp, self.geom )
1985 x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1986 self.hyp.SetAxesDirs( x,y,z )
1989 def SetFixedPoint( self, p, toUnset=False ):
1991 Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1992 through the fixed point in each direction at which the grid is defined
1996 p: coordinates of the fixed point. Either SMESH.PointStruct or
1997 a vertex or 3 components of coordinates.
1998 toUnset: defines whether the fixed point is defined or removed.
2002 if not self.hyp: return
2003 p = SMESH.PointStruct(0,0,0)
2004 elif hasattr( p, "__getitem__" ):
2005 p = SMESH.PointStruct( p[0],p[1],p[2] )
2006 elif isinstance( p, GEOM._objref_GEOM_Object ):
2007 p = self.mesh.smeshpyD.GetPointStruct( p )
2009 self.hyp = self.Hypothesis("CartesianParameters3D")
2010 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
2011 self.mesh.AddHypothesis( self.hyp, self.geom )
2012 self.hyp.SetFixedPoint( p, toUnset )
2016 pass # end of StdMeshersBuilder_Cartesian_3D class
2018 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
2019 """ Defines a stub 1D algorithm, which enables "manual" creation of nodes and
2020 segments usable by 2D algorithms.
2022 It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
2026 meshMethod = "UseExistingSegments"
2028 name of the dynamic method in smeshBuilder.Mesh class
2030 algoType = "UseExisting_1D"
2032 type of algorithm used with helper function in smeshBuilder.Mesh class
2034 docHelper = "Create 1D algorithm allowing batch meshing of edges"
2036 doc string of the method
2039 def __init__(self, mesh, geom=0):
2041 Private constructor.
2044 mesh: parent mesh object algorithm is assigned to
2045 geom: geometry (shape/sub-shape) algorithm is assigned to;
2046 if it is :code:`0` (default), the algorithm is assigned to the main shape
2048 self.Create(mesh, geom, self.algoType)
2051 pass # end of StdMeshersBuilder_UseExisting_1D class
2053 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
2054 """ Defines a stub 2D algorithm, which enables "manual" creation of nodes and
2055 faces usable by 3D algorithms.
2057 It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
2061 meshMethod = "UseExistingFaces"
2063 name of the dynamic method in smeshBuilder.Mesh class
2065 algoType = "UseExisting_2D"
2067 type of algorithm used with helper function in smeshBuilder.Mesh class
2069 docHelper = "Create 2D algorithm allowing batch meshing of faces"
2071 doc string of the method
2074 def __init__(self, mesh, geom=0):
2076 Private constructor.
2079 mesh: parent mesh object algorithm is assigned to
2080 geom: geometry (shape/sub-shape) algorithm is assigned to;
2081 if it is :code:`0` (default), the algorithm is assigned to the main shape
2083 self.Create(mesh, geom, self.algoType)
2086 pass # end of StdMeshersBuilder_UseExisting_2D class