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 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)
921 pass # end of StdMeshersBuilder_Hexahedron class
923 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
925 Defines a projection 1D algorithm.
926 It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
930 meshMethod = "Projection1D"
932 name of the dynamic method in smeshBuilder.Mesh class
934 algoType = "Projection_1D"
936 type of algorithm used with helper function in smeshBuilder.Mesh class
940 flag pointing whether this algorithm should be used by default in dynamic method
941 of smeshBuilder.Mesh class
943 docHelper = "Create projection 1D algorithm for edges"
945 doc string of the method
947 def __init__(self, mesh, geom=0):
952 mesh: parent mesh object algorithm is assigned to
953 geom: geometry (shape/sub-shape) algorithm is assigned to;
954 if it is :code:`0` (default), the algorithm is assigned to the main shape
956 Mesh_Algorithm.__init__(self)
957 self.Create(mesh, geom, self.algoType)
960 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
962 Defines "Source Edge" hypothesis, specifying a meshed edge, from where
963 a mesh pattern is taken, and, optionally, the association of vertices
964 between the source edge and a target edge (to which a hypothesis is assigned)
967 edge: from which nodes distribution is taken
968 mesh: from which nodes distribution is taken (optional)
969 srcV: a vertex of *edge* to associate with *tgtV* (optional)
970 tgtV: a vertex of *the edge* to which the algorithm is assigned, to associate with *srcV* (optional)
971 UseExisting: if ==true - searches for the existing hypothesis created with
972 the same parameters, else (default) - Create a new one
974 from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
975 AssureGeomPublished( self.mesh, edge )
976 AssureGeomPublished( self.mesh, srcV )
977 AssureGeomPublished( self.mesh, tgtV )
978 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
980 # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
981 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
982 hyp.SetSourceEdge( edge )
983 if not mesh is None and isinstance(mesh, Mesh):
984 mesh = mesh.GetMesh()
985 hyp.SetSourceMesh( mesh )
986 hyp.SetVertexAssociation( srcV, tgtV )
989 pass # end of StdMeshersBuilder_Projection1D class
991 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
993 Defines a projection 2D algorithm.
994 It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
998 meshMethod = "Projection2D"
1000 name of the dynamic method in smeshBuilder.Mesh class
1002 algoType = "Projection_2D"
1004 type of algorithm used with helper function in smeshBuilder.Mesh class
1008 flag pointing whether this algorithm should be used by default in dynamic method
1009 of smeshBuilder.Mesh class
1011 docHelper = "Create projection 2D algorithm for faces"
1013 doc string of the method
1016 def __init__(self, mesh, geom=0):
1018 Private constructor.
1021 mesh: parent mesh object algorithm is assigned to
1022 geom: geometry (shape/sub-shape) algorithm is assigned to;
1023 if it is :code:`0` (default), the algorithm is assigned to the main shape
1025 Mesh_Algorithm.__init__(self)
1026 self.Create(mesh, geom, self.algoType)
1030 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
1031 srcV2=None, tgtV2=None, UseExisting=0):
1033 Defines "Source Face" hypothesis, specifying a meshed face, from where
1034 a mesh pattern is taken, and, optionally, the association of vertices
1035 between the source face and the target face (to which a hypothesis is assigned)
1038 face: from which the mesh pattern is taken
1039 mesh: from which the mesh pattern is taken (optional)
1040 srcV1: a vertex of *face* to associate with *tgtV1* (optional)
1041 tgtV1: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV1* (optional)
1042 srcV2: a vertex of *face* to associate with *tgtV1* (optional)
1043 tgtV2: a vertex of *the face* to which the algorithm is assigned, to associate with *srcV2* (optional)
1044 UseExisting: if ==true - forces the search for the existing hypothesis created with
1045 he same parameters, else (default) - forces the creation a new one
1048 all association vertices must belong to one edge of a face
1050 from salome.smesh.smeshBuilder import Mesh
1051 if isinstance(mesh, Mesh):
1052 mesh = mesh.GetMesh()
1053 for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
1054 from salome.smesh.smeshBuilder import AssureGeomPublished
1055 AssureGeomPublished( self.mesh, geom )
1056 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
1057 UseExisting=0, toAdd=False)
1058 # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
1059 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
1060 hyp.SetSourceFace( face )
1061 hyp.SetSourceMesh( mesh )
1062 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1063 self.mesh.AddHypothesis(hyp, self.geom)
1066 pass # end of StdMeshersBuilder_Projection2D class
1068 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
1070 Defines a projection 1D-2D algorithm.
1071 It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
1075 meshMethod = "Projection1D2D"
1077 name of the dynamic method in smeshBuilder.Mesh class
1079 algoType = "Projection_1D2D"
1081 type of algorithm used with helper function in smeshBuilder.Mesh class
1083 docHelper = "Create projection 1D-2D algorithm for faces"
1085 doc string of the method
1088 def __init__(self, mesh, geom=0):
1090 Private constructor.
1093 mesh: parent mesh object algorithm is assigned to
1094 geom: geometry (shape/sub-shape) algorithm is assigned to;
1095 if it is :code:`0` (default), the algorithm is assigned to the main shape
1097 StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
1100 pass # end of StdMeshersBuilder_Projection1D2D class
1102 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
1104 Defines a projection 3D algorithm.
1105 It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
1109 meshMethod = "Projection3D"
1111 name of the dynamic method in smeshBuilder.Mesh class
1113 algoType = "Projection_3D"
1115 type of algorithm used with helper function in smeshBuilder.Mesh class
1117 docHelper = "Create projection 3D algorithm for volumes"
1119 doc string of the method
1122 def __init__(self, mesh, geom=0):
1124 Private constructor.
1127 mesh: parent mesh object algorithm is assigned to
1128 geom" geometry (shape/sub-shape) algorithm is assigned to;
1129 if it is :code:`0` (default), the algorithm is assigned to the main shape
1131 Mesh_Algorithm.__init__(self)
1132 self.Create(mesh, geom, self.algoType)
1135 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
1136 srcV2=0, tgtV2=0, UseExisting=0):
1138 Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
1139 the mesh pattern is taken, and, optionally, the association of vertices
1140 between the source and the target solid (to which a hipothesis is assigned)
1143 solid: from where the mesh pattern is taken
1144 mesh: from where the mesh pattern is taken (optional)
1145 srcV1: a vertex of *solid* to associate with *tgtV1* (optional)
1146 tgtV1: a vertex of *the solid* where the algorithm is assigned, to associate with *srcV1* (optional)
1147 srcV2: a vertex of *solid* to associate with *tgtV1* (optional)
1148 tgtV2: a vertex of *the solid* to which the algorithm is assigned,to associate with *srcV2* (optional)
1149 UseExisting: if ==true - searches for the existing hypothesis created with
1150 the same parameters, else (default) - Create a new one
1153 association vertices must belong to one edge of a solid
1155 for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
1156 from salome.smesh.smeshBuilder import AssureGeomPublished
1157 AssureGeomPublished( self.mesh, geom )
1158 hyp = self.Hypothesis("ProjectionSource3D",
1159 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
1161 # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
1162 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
1163 hyp.SetSource3DShape( solid )
1164 from salome.smesh.smeshBuilder import Mesh
1165 if isinstance(mesh, Mesh):
1166 mesh = mesh.GetMesh()
1168 hyp.SetSourceMesh( mesh )
1169 if srcV1 and srcV2 and tgtV1 and tgtV2:
1170 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
1171 #elif srcV1 or srcV2 or tgtV1 or tgtV2:
1174 pass # end of StdMeshersBuilder_Projection3D class
1176 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
1178 Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism" depending on geometry.
1179 It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1183 meshMethod = "Prism"
1185 name of the dynamic method in smeshBuilder.Mesh class
1187 algoType = "Prism_3D"
1189 type of algorithm used with helper function in smeshBuilder.Mesh class
1191 docHelper = "Create prism 3D algorithm for volumes"
1193 doc string of the method
1197 flag pointing whether this algorithm should be used by default in dynamic method
1198 of smeshBuilder.Mesh class
1201 def __init__(self, mesh, geom=0):
1203 Private constructor.
1206 mesh: parent mesh object algorithm is assigned to
1207 geom: geometry (shape/sub-shape) algorithm is assigned to;
1208 if it is :code:`0` (default), the algorithm is assigned to the main shape
1210 Mesh_Algorithm.__init__(self)
1215 isRadial = mesh.smeshpyD.IsApplicable("RadialPrism_3D", LIBRARY, shape, False )
1217 self.Create(mesh, geom, "Prism_3D")
1220 self.algoType = "RadialPrism_3D"
1221 self.Create(mesh, geom, "RadialPrism_3D")
1222 self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
1223 self.nbLayers = None
1227 def Get3DHypothesis(self):
1230 3D hypothesis holding the 1D one
1232 if self.algoType != "RadialPrism_3D":
1233 print("Prism_3D algorithm doesn't support any hypothesis")
1235 return self.distribHyp
1237 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1239 Private method creating a 1D hypothesis and storing it in the LayerDistribution
1243 the created hypothesis
1245 if self.algoType != "RadialPrism_3D":
1246 print("Prism_3D algorithm doesn't support any hypothesis")
1248 if not self.nbLayers is None:
1249 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1250 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1251 self.mesh.smeshpyD.SetEnablePublish( False ) # prevents publishing own 1D hypothesis
1252 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1253 self.mesh.smeshpyD.SetEnablePublish( True ) # enables publishing
1254 if not self.distribHyp:
1255 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1256 self.distribHyp.SetLayerDistribution( hyp )
1259 def NumberOfLayers(self, n, UseExisting=0):
1261 Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1262 prisms to build between the inner and outer shells
1266 UseExisting: if ==true - searches for the existing hypothesis created with
1267 the same parameters, else (default) - Create a new one
1269 if self.algoType != "RadialPrism_3D":
1270 print("Prism_3D algorithm doesn't support any hypothesis")
1272 self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1273 from salome.smesh.smeshBuilder import IsEqual
1274 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1275 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1276 CompareMethod=compFun)
1277 self.nbLayers.SetNumberOfLayers( n )
1278 return self.nbLayers
1280 def LocalLength(self, l, p=1e-07):
1282 Defines "LocalLength" hypothesis, specifying the segment length
1283 to build between the inner and the outer shells
1286 l: the length of segments
1287 p: the precision of rounding
1289 if self.algoType != "RadialPrism_3D":
1290 print("Prism_3D algorithm doesn't support any hypothesis")
1292 hyp = self.OwnHypothesis("LocalLength", [l,p])
1297 def NumberOfSegments(self, n, s=[]):
1299 Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1300 prisms to build between the inner and the outer shells.
1303 n: the number of layers
1304 s: the scale factor (optional)
1306 if self.algoType != "RadialPrism_3D":
1307 print("Prism_3D algorithm doesn't support any hypothesis")
1310 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1312 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1313 hyp.SetScaleFactor(s)
1314 hyp.SetNumberOfSegments(n)
1317 def Arithmetic1D(self, start, end ):
1319 Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1320 to build between the inner and the outer shells with a length that changes
1321 in arithmetic progression
1324 start: the length of the first segment
1325 end: the length of the last segment
1327 if self.algoType != "RadialPrism_3D":
1328 print("Prism_3D algorithm doesn't support any hypothesis")
1330 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1331 hyp.SetLength(start, 1)
1332 hyp.SetLength(end , 0)
1335 def GeometricProgression(self, start, ratio ):
1337 Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1338 to build between the inner and the outer shells with a length that changes
1339 in Geometric progression
1342 start: the length of the first segment
1343 ratio: the common ratio of the geometric progression
1345 if self.algoType != "RadialPrism_3D":
1346 print("Prism_3D algorithm doesn't support any hypothesis")
1348 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1349 hyp.SetStartLength( start )
1350 hyp.SetCommonRatio( ratio )
1353 def StartEndLength(self, start, end):
1355 Defines "StartEndLength" hypothesis, specifying distribution of segments
1356 to build between the inner and the outer shells as geometric length increasing
1359 start: for the length of the first segment
1360 end: for the length of the last segment
1362 if self.algoType != "RadialPrism_3D":
1363 print("Prism_3D algorithm doesn't support any hypothesis")
1365 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1366 hyp.SetLength(start, 1)
1367 hyp.SetLength(end , 0)
1370 def AutomaticLength(self, fineness=0):
1372 Defines "AutomaticLength" hypothesis, specifying the number of segments
1373 to build between the inner and outer shells
1376 fineness: defines the quality of the mesh within the range [0-1]
1378 if self.algoType != "RadialPrism_3D":
1379 print("Prism_3D algorithm doesn't support any hypothesis")
1381 hyp = self.OwnHypothesis("AutomaticLength")
1382 hyp.SetFineness( fineness )
1385 pass # end of StdMeshersBuilder_Prism3D class
1387 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1389 Defines Radial Prism 3D algorithm.
1390 It is created by calling smeshBuilder.Mesh.Prism(geom=0).
1391 See :class:`StdMeshersBuilder_Prism3D` for methods defining distribution of mesh layers
1392 build between the inner and outer shells.
1395 meshMethod = "Prism"
1397 name of the dynamic method in smeshBuilder.Mesh class
1399 algoType = "RadialPrism_3D"
1401 type of algorithm used with helper function in smeshBuilder.Mesh class
1403 docHelper = "Create Raial Prism 3D algorithm for volumes"
1405 doc string of the method
1408 def __init__(self, mesh, geom=0):
1410 Private constructor.
1413 mesh: parent mesh object algorithm is assigned to
1414 geom: geometry (shape/sub-shape) algorithm is assigned to;
1415 if it is :code:`0` (default), the algorithm is assigned to the main shape
1417 Mesh_Algorithm.__init__(self)
1422 self.Create(mesh, geom, "RadialPrism_3D")
1423 self.distribHyp = None
1424 self.nbLayers = None
1427 class StdMeshersBuilder_RadialAlgorithm(Mesh_Algorithm):
1429 Base class for algorithms supporting radial distribution hypotheses
1433 Mesh_Algorithm.__init__(self)
1435 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1436 self.nbLayers = None
1439 def Get2DHypothesis(self):
1442 2D hypothesis holding the 1D one
1444 if not self.distribHyp:
1445 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1446 return self.distribHyp
1448 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1450 Private method creating a 1D hypothesis and storing it in the LayerDistribution
1454 the created hypothesis
1457 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1458 if self.distribHyp is None:
1459 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1461 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1462 self.mesh.smeshpyD.SetEnablePublish( False )
1463 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1464 self.mesh.smeshpyD.SetEnablePublish( True )
1465 self.distribHyp.SetLayerDistribution( hyp )
1468 def NumberOfLayers(self, n, UseExisting=0):
1470 Defines "NumberOfLayers" hypothesis, specifying the number of layers
1474 UseExisting: if ==true - searches for the existing hypothesis created with
1475 the same parameters, else (default) - Create a new one
1478 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1479 from salome.smesh.smeshBuilder import IsEqual
1480 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1481 self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1482 CompareMethod=compFun)
1483 self.nbLayers.SetNumberOfLayers( n )
1484 return self.nbLayers
1486 def LocalLength(self, l, p=1e-07):
1488 Defines "LocalLength" hypothesis, specifying the segment length
1491 l: the length of segments
1492 p: the precision of rounding
1494 hyp = self.OwnHypothesis("LocalLength", [l,p])
1499 def NumberOfSegments(self, n, s=[]):
1501 Defines "NumberOfSegments" hypothesis, specifying the number of layers
1504 n: the number of layers
1505 s: the scale factor (optional)
1508 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1510 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1511 hyp.SetDistrType( 1 )
1512 hyp.SetScaleFactor(s)
1513 hyp.SetNumberOfSegments(n)
1516 def Arithmetic1D(self, start, end ):
1518 Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1519 with a length that changes in arithmetic progression
1522 start: the length of the first segment
1523 end: the length of the last segment
1525 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1526 hyp.SetLength(start, 1)
1527 hyp.SetLength(end , 0)
1530 def GeometricProgression(self, start, ratio ):
1532 Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1533 with a length that changes in Geometric progression
1536 start: the length of the first segment
1537 ratio: the common ratio of the geometric progression
1539 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1540 hyp.SetStartLength( start )
1541 hyp.SetCommonRatio( ratio )
1544 def StartEndLength(self, start, end):
1546 Defines "StartEndLength" hypothesis, specifying distribution of segments
1547 as geometric length increasing
1550 start: for the length of the first segment
1551 end: for the length of the last segment
1553 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1554 hyp.SetLength(start, 1)
1555 hyp.SetLength(end , 0)
1558 def AutomaticLength(self, fineness=0):
1560 Defines "AutomaticLength" hypothesis, specifying the number of segments
1563 fineness: defines the quality of the mesh within the range [0-1]
1565 hyp = self.OwnHypothesis("AutomaticLength")
1566 hyp.SetFineness( fineness )
1569 pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1571 class StdMeshersBuilder_RadialQuadrangle1D2D(StdMeshersBuilder_RadialAlgorithm):
1573 Defines a Radial Quadrangle 1D-2D algorithm.
1574 It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1577 meshMethod = "Quadrangle"
1579 name of the dynamic method in smeshBuilder.Mesh class
1581 algoType = RADIAL_QUAD
1583 type of algorithm used with helper function in smeshBuilder.Mesh class
1585 docHelper = "Create quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
1587 doc string of the method
1590 def __init__(self, mesh, geom=0):
1592 Private constructor.
1595 mesh: parent mesh object algorithm is assigned to
1596 geom: geometry (shape/sub-shape) algorithm is assigned to;
1597 if it is :code:`0` (default), the algorithm is assigned to the main shape
1599 StdMeshersBuilder_RadialAlgorithm.__init__(self)
1600 self.Create(mesh, geom, self.algoType)
1602 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1603 self.nbLayers = None
1607 class StdMeshersBuilder_QuadMA_1D2D(StdMeshersBuilder_RadialAlgorithm):
1609 Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm .
1610 It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
1613 meshMethod = "Quadrangle"
1615 name of the dynamic method in smeshBuilder.Mesh class
1617 algoType = QUAD_MA_PROJ
1619 type of algorithm used with helper function in smeshBuilder.Mesh class
1621 docHelper = "Create quadrangle 1D-2D algorithm for faces"
1623 doc string of the method
1626 def __init__(self, mesh, geom=0):
1628 Private constructor.
1631 mesh: parent mesh object algorithm is assigned to
1632 geom: geometry (shape/sub-shape) algorithm is assigned to;
1633 if it is :code:`0` (default), the algorithm is assigned to the main shape
1635 StdMeshersBuilder_RadialAlgorithm.__init__(self)
1636 self.Create(mesh, geom, self.algoType)
1641 class StdMeshersBuilder_PolygonPerFace(Mesh_Algorithm):
1642 """ Defines a Polygon Per Face 2D algorithm.
1643 It is created by calling smeshBuilder.Mesh.Polygon(geom=0)
1646 meshMethod = "Polygon"
1648 name of the dynamic method in smeshBuilder.Mesh class
1652 type of algorithm used with helper function in smeshBuilder.Mesh class
1656 flag pointing whether this algorithm should be used by default in dynamic method
1657 of smeshBuilder.Mesh class
1659 docHelper = "Create polygon 2D algorithm for faces"
1661 doc string of the method
1664 def __init__(self, mesh, geom=0):
1666 Private constructor.
1669 mesh: parent mesh object algorithm is assigned to
1670 geom: geometry (shape/sub-shape) algorithm is assigned to;
1671 if it is :code:`0` (default), the algorithm is assigned to the main shape
1673 Mesh_Algorithm.__init__(self)
1674 self.Create(mesh, geom, self.algoType)
1679 class StdMeshersBuilder_PolyhedronPerSolid(Mesh_Algorithm):
1680 """ Defines a Polyhedron Per Solid 3D algorithm.
1681 It is created by calling smeshBuilder.Mesh.Polyhedron(geom=0)
1684 meshMethod = "Polyhedron"
1686 name of the dynamic method in smeshBuilder.Mesh class
1688 algoType = POLYHEDRON
1690 type of algorithm used with helper function in smeshBuilder.Mesh class
1694 flag pointing whether this algorithm should be used by default in dynamic method
1695 of smeshBuilder.Mesh class
1697 docHelper = "Create polyhedron 3D algorithm for solids"
1699 doc string of the method
1702 def __init__(self, mesh, geom=0):
1704 Private constructor.
1707 mesh: parent mesh object algorithm is assigned to
1708 geom: geometry (shape/sub-shape) algorithm is assigned to;
1709 if it is :code:`0` (default), the algorithm is assigned to the main shape
1711 Mesh_Algorithm.__init__(self)
1712 self.Create(mesh, geom, self.algoType)
1717 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1718 """ Defines a Use Existing Elements 1D algorithm.
1720 It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1724 meshMethod = "UseExisting1DElements"
1726 name of the dynamic method in smeshBuilder.Mesh class
1728 algoType = "Import_1D"
1730 type of algorithm used with helper function in smeshBuilder.Mesh class
1734 flag pointing whether this algorithm should be used by default in dynamic method
1735 of smeshBuilder.Mesh class
1737 docHelper = "Create 1D algorithm for edges with reusing of existing mesh elements"
1739 doc string of the method
1742 def __init__(self, mesh, geom=0):
1744 Private constructor.
1747 mesh: parent mesh object algorithm is assigned to
1748 geom: geometry (shape/sub-shape) algorithm is assigned to;
1749 if it is :code:`0` (default), the algorithm is assigned to the main shape
1751 Mesh_Algorithm.__init__(self)
1752 self.Create(mesh, geom, self.algoType)
1755 def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1757 Defines "Source edges" hypothesis, specifying groups of edges to import
1760 groups: list of groups of edges
1761 toCopyMesh: if True, the whole mesh *groups* belong to is imported
1762 toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1763 UseExisting: if ==true - searches for the existing hypothesis created with
1764 the same parameters, else (default) - Create a new one
1766 for group in groups:
1767 from salome.smesh.smeshBuilder import AssureGeomPublished
1768 AssureGeomPublished( self.mesh, group )
1769 compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1770 hyp.GetCopySourceMesh() == args[1], args[2] )
1771 hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1772 UseExisting=UseExisting, CompareMethod=compFun)
1773 hyp.SetSourceEdges(groups)
1774 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1777 pass # end of StdMeshersBuilder_UseExistingElements_1D class
1779 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1780 """ Defines a Use Existing Elements 1D-2D algorithm.
1782 It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1786 meshMethod = "UseExisting2DElements"
1788 name of the dynamic method in smeshBuilder.Mesh class
1790 algoType = "Import_1D2D"
1792 type of algorithm used with helper function in smeshBuilder.Mesh class
1796 flag pointing whether this algorithm should be used by default in dynamic method
1797 of smeshBuilder.Mesh class
1799 docHelper = "Create 1D-2D algorithm for faces with reusing of existing mesh elements"
1801 doc string of the method
1804 def __init__(self, mesh, geom=0):
1806 Private constructor.
1809 mesh: parent mesh object algorithm is assigned to
1810 geom: geometry (shape/sub-shape) algorithm is assigned to;
1811 if it is :code:`0` (default), the algorithm is assigned to the main shape
1813 Mesh_Algorithm.__init__(self)
1814 self.Create(mesh, geom, self.algoType)
1817 def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1819 Defines "Source faces" hypothesis, specifying groups of faces to import
1822 groups: list of groups of faces
1823 toCopyMesh: if True, the whole mesh *groups* belong to is imported
1824 toCopyGroups: if True, all groups of the mesh *groups* belong to are imported
1825 UseExisting: if ==true - searches for the existing hypothesis created with
1826 the same parameters, else (default) - Create a new one
1829 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1830 hyp.GetCopySourceMesh() == args[1], args[2] )
1831 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1832 UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1833 if groups and isinstance( groups, SMESH._objref_SMESH_GroupBase ):
1835 hyp.SetSourceFaces(groups)
1836 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1837 self.mesh.AddHypothesis(hyp, self.geom)
1840 pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1842 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1843 """ Defines a Body Fitting 3D algorithm.
1845 It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1849 meshMethod = "BodyFitted"
1851 name of the dynamic method in smeshBuilder.Mesh class
1853 algoType = "Cartesian_3D"
1855 type of algorithm used with helper function in smeshBuilder.Mesh class
1859 flag pointing whether this algorithm should be used by default in dynamic method
1860 of smeshBuilder.Mesh class
1862 docHelper = "Create Body Fitting 3D algorithm for volumes"
1864 doc string of the method
1867 def __init__(self, mesh, geom=0):
1869 Private constructor.
1872 mesh: parent mesh object algorithm is assigned to
1873 geom: geometry (shape/sub-shape) algorithm is assigned to;
1874 if it is :code:`0` (default), the algorithm is assigned to the main shape
1876 self.Create(mesh, geom, self.algoType)
1880 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1882 Defines "Body Fitting parameters" hypothesis
1885 xGridDef: is definition of the grid along the X asix.
1886 It can be in either of two following forms:
1888 - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1889 - Functions f(t) defining grid spacing at each point on grid axis. If there are
1890 several functions, they must be accompanied by relative coordinates of
1891 points dividing the whole shape into ranges where the functions apply; points
1892 coordinates should vary within (0.0, 1.0) range. Parameter *t* of the spacing
1893 function f(t) varies from 0.0 to 1.0 within a shape range.
1896 "10.5" - defines a grid with a constant spacing
1897 [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1900 yGridDef: defines the grid along the Y asix the same way as *xGridDef* does.
1901 zGridDef: defines the grid along the Z asix the same way as *xGridDef* does.
1902 sizeThreshold: (> 1.0) defines a minimal size of a polyhedron so that
1903 a polyhedron of size less than hexSize/sizeThreshold is not created.
1904 implEdges: enables implementation of geometrical edges into the mesh.
1907 compFun = lambda hyp, args: False
1908 self.hyp = self.Hypothesis("CartesianParameters3D",
1909 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1910 UseExisting=False, CompareMethod=compFun)
1911 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1912 self.mesh.AddHypothesis( self.hyp, self.geom )
1914 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1915 if not gridDef: raise ValueError("Empty grid definition")
1916 if isinstance( gridDef, str ):
1917 self.hyp.SetGridSpacing( [gridDef], [], axis )
1918 elif isinstance( gridDef[0], str ):
1919 self.hyp.SetGridSpacing( gridDef, [], axis )
1920 elif isinstance( gridDef[0], int ) or \
1921 isinstance( gridDef[0], float ):
1922 self.hyp.SetGrid(gridDef, axis )
1924 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1925 self.hyp.SetSizeThreshold( sizeThreshold )
1926 self.hyp.SetToAddEdges( implEdges )
1929 def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1931 Defines custom directions of axes of the grid
1934 xAxis: either SMESH.DirStruct or a vector, or 3 vector components
1935 yAxis: either SMESH.DirStruct or a vector, or 3 vector components
1936 zAxis: either SMESH.DirStruct or a vector, or 3 vector components
1939 if hasattr( xAxis, "__getitem__" ):
1940 xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1941 elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1942 xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1943 if hasattr( yAxis, "__getitem__" ):
1944 yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1945 elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1946 yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1947 if hasattr( zAxis, "__getitem__" ):
1948 zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1949 elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1950 zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1952 self.hyp = self.Hypothesis("CartesianParameters3D")
1953 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1954 self.mesh.AddHypothesis( self.hyp, self.geom )
1955 self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1958 def SetOptimalAxesDirs(self, isOrthogonal=True):
1960 Automatically defines directions of axes of the grid at which
1961 a number of generated hexahedra is maximal
1964 isOrthogonal: defines whether the axes mush be orthogonal
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 x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1971 self.hyp.SetAxesDirs( x,y,z )
1974 def SetFixedPoint( self, p, toUnset=False ):
1976 Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1977 through the fixed point in each direction at which the grid is defined
1981 p: coordinates of the fixed point. Either SMESH.PointStruct or
1982 a vertex or 3 components of coordinates.
1983 toUnset: defines whether the fixed point is defined or removed.
1987 if not self.hyp: return
1988 p = SMESH.PointStruct(0,0,0)
1989 elif hasattr( p, "__getitem__" ):
1990 p = SMESH.PointStruct( p[0],p[1],p[2] )
1991 elif isinstance( p, GEOM._objref_GEOM_Object ):
1992 p = self.mesh.smeshpyD.GetPointStruct( p )
1994 self.hyp = self.Hypothesis("CartesianParameters3D")
1995 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1996 self.mesh.AddHypothesis( self.hyp, self.geom )
1997 self.hyp.SetFixedPoint( p, toUnset )
2001 pass # end of StdMeshersBuilder_Cartesian_3D class
2003 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
2004 """ Defines a stub 1D algorithm, which enables "manual" creation of nodes and
2005 segments usable by 2D algorithms.
2007 It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
2011 meshMethod = "UseExistingSegments"
2013 name of the dynamic method in smeshBuilder.Mesh class
2015 algoType = "UseExisting_1D"
2017 type of algorithm used with helper function in smeshBuilder.Mesh class
2019 docHelper = "Create 1D algorithm allowing batch meshing of edges"
2021 doc string of the method
2024 def __init__(self, mesh, geom=0):
2026 Private constructor.
2029 mesh: parent mesh object algorithm is assigned to
2030 geom: geometry (shape/sub-shape) algorithm is assigned to;
2031 if it is :code:`0` (default), the algorithm is assigned to the main shape
2033 self.Create(mesh, geom, self.algoType)
2036 pass # end of StdMeshersBuilder_UseExisting_1D class
2038 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
2039 """ Defines a stub 2D algorithm, which enables "manual" creation of nodes and
2040 faces usable by 3D algorithms.
2042 It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
2046 meshMethod = "UseExistingFaces"
2048 name of the dynamic method in smeshBuilder.Mesh class
2050 algoType = "UseExisting_2D"
2052 type of algorithm used with helper function in smeshBuilder.Mesh class
2054 docHelper = "Create 2D algorithm allowing batch meshing of faces"
2056 doc string of the method
2059 def __init__(self, mesh, geom=0):
2061 Private constructor.
2064 mesh: parent mesh object algorithm is assigned to
2065 geom: geometry (shape/sub-shape) algorithm is assigned to;
2066 if it is :code:`0` (default), the algorithm is assigned to the main shape
2068 self.Create(mesh, geom, self.algoType)
2071 pass # end of StdMeshersBuilder_UseExisting_2D class