1 # Copyright (C) 2007-2013 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.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # @package StdMeshersBuilder
22 # Python API for the standard meshing plug-in module.
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
27 #----------------------------
28 # Mesh algo type identifiers
29 #----------------------------
31 ## Algorithm type: Regular 1D algorithm, see StdMeshersBuilder_Segment
32 REGULAR = "Regular_1D"
33 ## Algorithm type: Python 1D algorithm, see StdMeshersBuilder_Segment_Python
35 ## Algorithm type: Composite segment 1D algorithm, see StdMeshersBuilder_CompositeSegment
36 COMPOSITE = "CompositeSegment_1D"
37 ## Algorithm type: Triangle MEFISTO 2D algorithm, see StdMeshersBuilder_Triangle_MEFISTO
38 MEFISTO = "MEFISTO_2D"
39 ## Algorithm type: Hexahedron 3D (i-j-k) algorithm, see StdMeshersBuilder_Hexahedron
41 ## Algorithm type: Quadrangle 2D algorithm, see StdMeshersBuilder_Quadrangle
42 QUADRANGLE = "Quadrangle_2D"
43 ## Algorithm type: Radial Quadrangle 1D-2D algorithm, see StdMeshersBuilder_RadialQuadrangle1D2D
44 RADIAL_QUAD = "RadialQuadrangle_1D2D"
46 # import items of enum QuadType
47 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
49 #----------------------
51 #----------------------
53 ## Defines segment 1D algorithm for edges discretization.
55 # It can be created by calling smeshBuilder.Mesh.Segment(geom=0)
57 # @ingroup l3_algos_basic
58 class StdMeshersBuilder_Segment(Mesh_Algorithm):
60 ## name of the dynamic method in smeshBuilder.Mesh class
62 meshMethod = "Segment"
63 ## type of algorithm used with helper function in smeshBuilder.Mesh class
66 ## flag pointing either this algorithm should be used by default in dynamic method
67 # of smeshBuilder.Mesh class
70 ## doc string of the method
72 docHelper = "Creates segment 1D algorithm for edges"
74 ## Private constructor.
75 # @param mesh parent mesh object algorithm is assigned to
76 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
77 # if it is @c 0 (default), the algorithm is assigned to the main shape
78 def __init__(self, mesh, geom=0):
79 Mesh_Algorithm.__init__(self)
80 self.Create(mesh, geom, self.algoType)
83 ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
84 # @param l for the length of segments that cut an edge
85 # @param UseExisting if ==true - searches for an existing hypothesis created with
86 # the same parameters, else (default) - creates a new one
87 # @param p precision, used for calculation of the number of segments.
88 # The precision should be a positive, meaningful value within the range [0,1].
89 # In general, the number of segments is calculated with the formula:
90 # nb = ceil((edge_length / l) - p)
91 # Function ceil rounds its argument to the higher integer.
92 # So, p=0 means rounding of (edge_length / l) to the higher integer,
93 # p=0.5 means rounding of (edge_length / l) to the nearest integer,
94 # p=1 means rounding of (edge_length / l) to the lower integer.
95 # Default value is 1e-07.
96 # @return an instance of StdMeshers_LocalLength hypothesis
97 # @ingroup l3_hypos_1dhyps
98 def LocalLength(self, l, UseExisting=0, p=1e-07):
99 from salome.smesh.smeshBuilder import IsEqual
100 comFun=lambda hyp, args: IsEqual(hyp.GetLength(), args[0]) and IsEqual(hyp.GetPrecision(), args[1])
101 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting, CompareMethod=comFun)
106 ## Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
107 # @param length is optional maximal allowed length of segment, if it is omitted
108 # the preestimated length is used that depends on geometry size
109 # @param UseExisting if ==true - searches for an existing hypothesis created with
110 # the same parameters, else (default) - creates a new one
111 # @return an instance of StdMeshers_MaxLength hypothesis
112 # @ingroup l3_hypos_1dhyps
113 def MaxSize(self, length=0.0, UseExisting=0):
114 hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
117 hyp.SetLength(length)
119 # set preestimated length
120 gen = self.mesh.smeshpyD
121 initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
122 self.mesh.GetMesh(), self.mesh.GetShape(),
124 preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
126 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
129 hyp.SetUsePreestimatedLength( length == 0.0 )
132 ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
133 # @param n for the number of segments that cut an edge
134 # @param s for the scale factor (optional)
135 # @param reversedEdges is a list of edges to mesh using reversed orientation.
136 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
137 # @param UseExisting if ==true - searches for an existing hypothesis created with
138 # the same parameters, else (default) - create a new one
139 # @return an instance of StdMeshers_NumberOfSegments hypothesis
140 # @ingroup l3_hypos_1dhyps
141 def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
142 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
143 reversedEdges, UseExisting = [], reversedEdges
144 entry = self.MainShapeEntry()
145 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
147 hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
148 UseExisting=UseExisting,
149 CompareMethod=self._compareNumberOfSegments)
151 hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
152 UseExisting=UseExisting,
153 CompareMethod=self._compareNumberOfSegments)
154 hyp.SetDistrType( 1 )
155 hyp.SetScaleFactor(s)
156 hyp.SetNumberOfSegments(n)
157 hyp.SetReversedEdges( reversedEdgeInd )
158 hyp.SetObjectEntry( entry )
163 # Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
164 def _compareNumberOfSegments(self, hyp, args):
165 if hyp.GetNumberOfSegments() == args[0]:
167 if hyp.GetReversedEdges() == args[1]:
168 if not args[1] or hyp.GetObjectEntry() == args[2]:
171 from salome.smesh.smeshBuilder import IsEqual
172 if hyp.GetReversedEdges() == args[2]:
173 if not args[2] or hyp.GetObjectEntry() == args[3]:
174 if hyp.GetDistrType() == 1:
175 if IsEqual(hyp.GetScaleFactor(), args[1]):
179 ## Defines "Adaptive" hypothesis to cut an edge into segments keeping segment size
180 # within the given range and considering (1) deflection of segments from the edge
181 # and (2) distance from segments to closest edges and faces to have segment length
182 # not longer than two times shortest distances to edges and faces.
183 # @param minSize defines the minimal allowed segment length
184 # @param maxSize defines the maximal allowed segment length
185 # @param deflection defines the maximal allowed distance from a segment to an edge
186 # @param UseExisting if ==true - searches for an existing hypothesis created with
187 # the same parameters, else (default) - creates a new one
188 # @return an instance of StdMeshers_Adaptive1D hypothesis
189 # @ingroup l3_hypos_1dhyps
190 def Adaptive(self, minSize, maxSize, deflection, UseExisting=False):
191 from salome.smesh.smeshBuilder import IsEqual
192 compFun = lambda hyp, args: ( IsEqual(hyp.GetMinSize(), args[0]) and \
193 IsEqual(hyp.GetMaxSize(), args[1]) and \
194 IsEqual(hyp.GetDeflection(), args[2]))
195 hyp = self.Hypothesis("Adaptive1D", [minSize, maxSize, deflection],
196 UseExisting=UseExisting, CompareMethod=compFun)
197 hyp.SetMinSize(minSize)
198 hyp.SetMaxSize(maxSize)
199 hyp.SetDeflection(deflection)
202 ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with increasing arithmetic length
203 # @param start defines the length of the first segment
204 # @param end defines the length of the last segment
205 # @param reversedEdges is a list of edges to mesh using reversed orientation.
206 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
207 # @param UseExisting if ==true - searches for an existing hypothesis created with
208 # the same parameters, else (default) - creates a new one
209 # @return an instance of StdMeshers_Arithmetic1D hypothesis
210 # @ingroup l3_hypos_1dhyps
211 def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
212 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
213 reversedEdges, UseExisting = [], reversedEdges
214 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
215 entry = self.MainShapeEntry()
216 from salome.smesh.smeshBuilder import IsEqual
217 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
218 IsEqual(hyp.GetLength(0), args[1]) and \
219 hyp.GetReversedEdges() == args[2] and \
220 (not args[2] or hyp.GetObjectEntry() == args[3]))
221 hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
222 UseExisting=UseExisting, CompareMethod=compFun)
223 hyp.SetStartLength(start)
224 hyp.SetEndLength(end)
225 hyp.SetReversedEdges( reversedEdgeInd )
226 hyp.SetObjectEntry( entry )
229 ## Defines "FixedPoints1D" hypothesis to cut an edge using parameter
230 # on curve from 0 to 1 (additionally it is neecessary to check
231 # orientation of edges and create list of reversed edges if it is
232 # needed) and sets numbers of segments between given points (default
233 # values are equals 1
234 # @param points defines the list of parameters on curve
235 # @param nbSegs defines the list of numbers of segments
236 # @param reversedEdges is a list of edges to mesh using reversed orientation.
237 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
238 # @param UseExisting if ==true - searches for an existing hypothesis created with
239 # the same parameters, else (default) - creates a new one
240 # @return an instance of StdMeshers_Arithmetic1D hypothesis
241 # @ingroup l3_hypos_1dhyps
242 def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
243 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
244 reversedEdges, UseExisting = [], reversedEdges
245 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
246 entry = self.MainShapeEntry()
247 compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
248 hyp.GetNbSegments() == args[1] and \
249 hyp.GetReversedEdges() == args[2] and \
250 (not args[2] or hyp.GetObjectEntry() == args[3]))
251 hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
252 UseExisting=UseExisting, CompareMethod=compFun)
253 hyp.SetPoints(points)
254 hyp.SetNbSegments(nbSegs)
255 hyp.SetReversedEdges(reversedEdgeInd)
256 hyp.SetObjectEntry(entry)
259 ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
260 # @param start defines the length of the first segment
261 # @param end defines the length of the last segment
262 # @param reversedEdges is a list of edges to mesh using reversed orientation.
263 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
264 # @param UseExisting if ==true - searches for an existing hypothesis created with
265 # the same parameters, else (default) - creates a new one
266 # @return an instance of StdMeshers_StartEndLength hypothesis
267 # @ingroup l3_hypos_1dhyps
268 def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
269 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
270 reversedEdges, UseExisting = [], reversedEdges
271 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
272 entry = self.MainShapeEntry()
273 from salome.smesh.smeshBuilder import IsEqual
274 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
275 IsEqual(hyp.GetLength(0), args[1]) and \
276 hyp.GetReversedEdges() == args[2] and \
277 (not args[2] or hyp.GetObjectEntry() == args[3]))
278 hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
279 UseExisting=UseExisting, CompareMethod=compFun)
280 hyp.SetStartLength(start)
281 hyp.SetEndLength(end)
282 hyp.SetReversedEdges( reversedEdgeInd )
283 hyp.SetObjectEntry( entry )
286 ## Defines "Deflection1D" hypothesis
287 # @param d for the deflection
288 # @param UseExisting if ==true - searches for an existing hypothesis created with
289 # the same parameters, else (default) - create a new one
290 # @ingroup l3_hypos_1dhyps
291 def Deflection1D(self, d, UseExisting=0):
292 from salome.smesh.smeshBuilder import IsEqual
293 compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
294 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
298 ## Defines "Propagation" hypothesis that propagates all other hypotheses on all other edges that are at
299 # the opposite side in case of quadrangular faces
300 # @ingroup l3_hypos_additi
301 def Propagation(self):
302 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
304 ## Defines "AutomaticLength" hypothesis
305 # @param fineness for the fineness [0-1]
306 # @param UseExisting if ==true - searches for an existing hypothesis created with the
307 # same parameters, else (default) - create a new one
308 # @ingroup l3_hypos_1dhyps
309 def AutomaticLength(self, fineness=0, UseExisting=0):
310 from salome.smesh.smeshBuilder import IsEqual
311 compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
312 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
313 CompareMethod=compFun)
314 hyp.SetFineness( fineness )
317 ## Defines "SegmentLengthAroundVertex" hypothesis
318 # @param length for the segment length
319 # @param vertex for the length localization: the vertex index [0,1] | vertex object.
320 # Any other integer value means that the hypothesis will be set on the
321 # whole 1D shape, where Mesh_Segment algorithm is assigned.
322 # @param UseExisting if ==true - searches for an existing hypothesis created with
323 # the same parameters, else (default) - creates a new one
324 # @ingroup l3_algos_segmarv
325 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
327 store_geom = self.geom
328 if type(vertex) is types.IntType:
329 if vertex == 0 or vertex == 1:
330 from salome.geom import geomBuilder
331 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geomBuilder.geomBuilder.ShapeType["VERTEX"],True)[vertex]
339 if self.geom is None:
340 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
341 from salome.smesh.smeshBuilder import AssureGeomPublished, GetName, TreatHypoStatus
342 AssureGeomPublished( self.mesh, self.geom )
343 name = GetName(self.geom)
345 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
347 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
349 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
350 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
352 from salome.smesh.smeshBuilder import IsEqual
353 comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
354 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
355 CompareMethod=comFun)
356 self.geom = store_geom
357 hyp.SetLength( length )
360 ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
361 # If the 2D mesher sees that all boundary edges are quadratic,
362 # it generates quadratic faces, else it generates linear faces using
363 # medium nodes as if they are vertices.
364 # The 3D mesher generates quadratic volumes only if all boundary faces
365 # are quadratic, else it fails.
367 # @ingroup l3_hypos_additi
368 def QuadraticMesh(self):
369 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
372 pass # end of StdMeshersBuilder_Segment class
374 ## Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
376 # It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.COMPOSITE,geom=0)
378 # @ingroup l3_algos_basic
379 class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
381 ## name of the dynamic method in smeshBuilder.Mesh class
383 meshMethod = "Segment"
384 ## type of algorithm used with helper function in smeshBuilder.Mesh class
387 ## flag pointing either this algorithm should be used by default in dynamic method
388 # of smeshBuilder.Mesh class
391 ## doc string of the method
393 docHelper = "Creates segment 1D algorithm for edges"
395 ## Private constructor.
396 # @param mesh parent mesh object algorithm is assigned to
397 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
398 # if it is @c 0 (default), the algorithm is assigned to the main shape
399 def __init__(self, mesh, geom=0):
400 self.Create(mesh, geom, self.algoType)
403 pass # end of StdMeshersBuilder_CompositeSegment class
405 ## Defines a segment 1D algorithm for discretization of edges with Python function
407 # It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.PYTHON,geom=0)
409 # @ingroup l3_algos_basic
410 class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
412 ## name of the dynamic method in smeshBuilder.Mesh class
414 meshMethod = "Segment"
415 ## type of algorithm used with helper function in smeshBuilder.Mesh class
418 ## doc string of the method
420 docHelper = "Creates tetrahedron 3D algorithm for solids"
421 ## doc string of the method
423 docHelper = "Creates segment 1D algorithm for edges"
425 ## Private constructor.
426 # @param mesh parent mesh object algorithm is assigned to
427 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
428 # if it is @c 0 (default), the algorithm is assigned to the main shape
429 def __init__(self, mesh, geom=0):
430 import Python1dPlugin
431 self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
434 ## Defines "PythonSplit1D" hypothesis
435 # @param n for the number of segments that cut an edge
436 # @param func for the python function that calculates the length of all segments
437 # @param UseExisting if ==true - searches for the existing hypothesis created with
438 # the same parameters, else (default) - creates a new one
439 # @ingroup l3_hypos_1dhyps
440 def PythonSplit1D(self, n, func, UseExisting=0):
441 compFun = lambda hyp, args: False
442 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
443 UseExisting=UseExisting, CompareMethod=compFun)
444 hyp.SetNumberOfSegments(n)
445 hyp.SetPythonLog10RatioFunction(func)
448 pass # end of StdMeshersBuilder_Segment_Python class
450 ## Triangle MEFISTO 2D algorithm
452 # It is created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MEFISTO,geom=0)
454 # @ingroup l3_algos_basic
455 class StdMeshersBuilder_Triangle_MEFISTO(Mesh_Algorithm):
457 ## name of the dynamic method in smeshBuilder.Mesh class
459 meshMethod = "Triangle"
460 ## type of algorithm used with helper function in smeshBuilder.Mesh class
463 ## flag pointing either this algorithm should be used by default in dynamic method
464 # of smeshBuilder.Mesh class
467 ## doc string of the method
469 docHelper = "Creates triangle 2D algorithm for faces"
471 ## Private constructor.
472 # @param mesh parent mesh object algorithm is assigned to
473 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
474 # if it is @c 0 (default), the algorithm is assigned to the main shape
475 def __init__(self, mesh, geom=0):
476 Mesh_Algorithm.__init__(self)
477 self.Create(mesh, geom, self.algoType)
480 ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
481 # @param area for the maximum area of each triangle
482 # @param UseExisting if ==true - searches for an existing hypothesis created with the
483 # same parameters, else (default) - creates a new one
485 # @ingroup l3_hypos_2dhyps
486 def MaxElementArea(self, area, UseExisting=0):
487 from salome.smesh.smeshBuilder import IsEqual
488 comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
489 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
490 CompareMethod=comparator)
491 hyp.SetMaxElementArea(area)
494 ## Defines "LengthFromEdges" hypothesis to build triangles
495 # based on the length of the edges taken from the wire
497 # @ingroup l3_hypos_2dhyps
498 def LengthFromEdges(self):
499 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
502 pass # end of StdMeshersBuilder_Triangle_MEFISTO class
504 ## Defines a quadrangle 2D algorithm
506 # It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
508 # @ingroup l3_algos_basic
509 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
511 ## name of the dynamic method in smeshBuilder.Mesh class
513 meshMethod = "Quadrangle"
514 ## type of algorithm used with helper function in smeshBuilder.Mesh class
516 algoType = QUADRANGLE
517 ## flag pointing either this algorithm should be used by default in dynamic method
518 # of smeshBuilder.Mesh class
521 ## doc string of the method
523 docHelper = "Creates quadrangle 2D algorithm for faces"
524 ## hypothesis associated with algorithm
528 ## Private constructor.
529 # @param mesh parent mesh object algorithm is assigned to
530 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
531 # if it is @c 0 (default), the algorithm is assigned to the main shape
532 def __init__(self, mesh, geom=0):
533 Mesh_Algorithm.__init__(self)
534 self.Create(mesh, geom, self.algoType)
537 ## Defines "QuadrangleParameters" hypothesis
538 # @param quadType defines the algorithm of transition between differently descretized
539 # sides of a geometrical face:
540 # - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
541 # area along the finer meshed sides.
542 # - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
543 # finer meshed sides.
544 # - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
545 # the finer meshed sides, iff the total quantity of segments on
546 # all four sides of the face is even (divisible by 2).
547 # - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
548 # area is located along the coarser meshed sides.
549 # - QUAD_REDUCED - only quadrangles are built and the transition between the sides
550 # is made gradually, layer by layer. This type has a limitation on
551 # the number of segments: one pair of opposite sides must have the
552 # same number of segments, the other pair must have an even difference
553 # between the numbers of segments on the sides.
554 # @param triangleVertex: vertex of a trilateral geometrical face, around which triangles
555 # will be created while other elements will be quadrangles.
556 # Vertex can be either a GEOM_Object or a vertex ID within the
558 # @param UseExisting: if ==true - searches for the existing hypothesis created with
559 # the same parameters, else (default) - creates a new one
560 # @ingroup l3_hypos_quad
561 def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0, UseExisting=0):
563 vertexID = triangleVertex
564 if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
565 vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
567 compFun = lambda hyp,args: \
568 hyp.GetQuadType() == args[0] and \
569 ( hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1))
570 self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID],
571 UseExisting = UseExisting, CompareMethod=compFun)
573 if self.params.GetQuadType() != quadType:
574 self.params.SetQuadType(quadType)
576 self.params.SetTriaVertex( vertexID )
579 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
580 # quadrangles are built in the transition area along the finer meshed sides,
581 # iff the total quantity of segments on all four sides of the face is even.
582 # @param reversed if True, transition area is located along the coarser meshed sides.
583 # @param UseExisting: if ==true - searches for the existing hypothesis created with
584 # the same parameters, else (default) - creates a new one
585 # @ingroup l3_hypos_quad
586 def QuadranglePreference(self, reversed=False, UseExisting=0):
588 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
589 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
591 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
592 # triangles are built in the transition area along the finer meshed sides.
593 # @param UseExisting: if ==true - searches for the existing hypothesis created with
594 # the same parameters, else (default) - creates a new one
595 # @ingroup l3_hypos_quad
596 def TrianglePreference(self, UseExisting=0):
597 return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
599 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
600 # quadrangles are built and the transition between the sides is made gradually,
601 # layer by layer. This type has a limitation on the number of segments: one pair
602 # of opposite sides must have the same number of segments, the other pair must
603 # have an even difference between the numbers of segments on the sides.
604 # @param UseExisting: if ==true - searches for the existing hypothesis created with
605 # the same parameters, else (default) - creates a new one
606 # @ingroup l3_hypos_quad
607 def Reduced(self, UseExisting=0):
608 return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
610 ## Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
611 # @param vertex: vertex of a trilateral geometrical face, around which triangles
612 # will be created while other elements will be quadrangles.
613 # Vertex can be either a GEOM_Object or a vertex ID within the
615 # @param UseExisting: if ==true - searches for the existing hypothesis created with
616 # the same parameters, else (default) - creates a new one
617 # @ingroup l3_hypos_quad
618 def TriangleVertex(self, vertex, UseExisting=0):
619 return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
621 pass # end of StdMeshersBuilder_Quadrangle class
623 ## Defines a hexahedron 3D algorithm
625 # It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
627 # @ingroup l3_algos_basic
628 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
630 ## name of the dynamic method in smeshBuilder.Mesh class
632 meshMethod = "Hexahedron"
633 ## type of algorithm used with helper function in smeshBuilder.Mesh class
636 ## flag pointing either this algorithm should be used by default in dynamic method
637 # of smeshBuilder.Mesh class
640 ## doc string of the method
642 docHelper = "Creates hexahedron 3D algorithm for volumes"
644 ## Private constructor.
645 # @param mesh parent mesh object algorithm is assigned to
646 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
647 # if it is @c 0 (default), the algorithm is assigned to the main shape
648 def __init__(self, mesh, geom=0):
649 Mesh_Algorithm.__init__(self)
650 self.Create(mesh, geom, Hexa)
653 pass # end of StdMeshersBuilder_Hexahedron class
655 ## Defines a projection 1D algorithm
657 # It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
659 # @ingroup l3_algos_proj
660 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
662 ## name of the dynamic method in smeshBuilder.Mesh class
664 meshMethod = "Projection1D"
665 ## type of algorithm used with helper function in smeshBuilder.Mesh class
667 algoType = "Projection_1D"
668 ## flag pointing either this algorithm should be used by default in dynamic method
669 # of smeshBuilder.Mesh class
672 ## doc string of the method
674 docHelper = "Creates projection 1D algorithm for edges"
676 ## Private constructor.
677 # @param mesh parent mesh object algorithm is assigned to
678 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
679 # if it is @c 0 (default), the algorithm is assigned to the main shape
680 def __init__(self, mesh, geom=0):
681 Mesh_Algorithm.__init__(self)
682 self.Create(mesh, geom, self.algoType)
685 ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
686 # a mesh pattern is taken, and, optionally, the association of vertices
687 # between the source edge and a target edge (to which a hypothesis is assigned)
688 # @param edge from which nodes distribution is taken
689 # @param mesh from which nodes distribution is taken (optional)
690 # @param srcV a vertex of \a edge to associate with \a tgtV (optional)
691 # @param tgtV a vertex of \a the edge to which the algorithm is assigned,
692 # to associate with \a srcV (optional)
693 # @param UseExisting if ==true - searches for the existing hypothesis created with
694 # the same parameters, else (default) - creates a new one
695 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
696 from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
697 AssureGeomPublished( self.mesh, edge )
698 AssureGeomPublished( self.mesh, srcV )
699 AssureGeomPublished( self.mesh, tgtV )
700 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
702 # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
703 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
704 hyp.SetSourceEdge( edge )
705 if not mesh is None and isinstance(mesh, Mesh):
706 mesh = mesh.GetMesh()
707 hyp.SetSourceMesh( mesh )
708 hyp.SetVertexAssociation( srcV, tgtV )
711 pass # end of StdMeshersBuilder_Projection1D class
713 ## Defines a projection 2D algorithm
715 # It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
717 # @ingroup l3_algos_proj
718 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
720 ## name of the dynamic method in smeshBuilder.Mesh class
722 meshMethod = "Projection2D"
723 ## type of algorithm used with helper function in smeshBuilder.Mesh class
725 algoType = "Projection_2D"
726 ## flag pointing either this algorithm should be used by default in dynamic method
727 # of smeshBuilder.Mesh class
730 ## doc string of the method
732 docHelper = "Creates projection 2D algorithm for faces"
734 ## Private constructor.
735 # @param mesh parent mesh object algorithm is assigned to
736 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
737 # if it is @c 0 (default), the algorithm is assigned to the main shape
738 def __init__(self, mesh, geom=0):
739 Mesh_Algorithm.__init__(self)
740 self.Create(mesh, geom, self.algoType)
743 ## Defines "Source Face" hypothesis, specifying a meshed face, from where
744 # a mesh pattern is taken, and, optionally, the association of vertices
745 # between the source face and the target face (to which a hypothesis is assigned)
746 # @param face from which the mesh pattern is taken
747 # @param mesh from which the mesh pattern is taken (optional)
748 # @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
749 # @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
750 # to associate with \a srcV1 (optional)
751 # @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
752 # @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
753 # to associate with \a srcV2 (optional)
754 # @param UseExisting if ==true - forces the search for the existing hypothesis created with
755 # the same parameters, else (default) - forces the creation a new one
757 # Note: all association vertices must belong to one edge of a face
758 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
759 srcV2=None, tgtV2=None, UseExisting=0):
760 from salome.smesh.smeshBuilder import Mesh
761 if isinstance(mesh, Mesh):
762 mesh = mesh.GetMesh()
763 for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
764 from salome.smesh.smeshBuilder import AssureGeomPublished
765 AssureGeomPublished( self.mesh, geom )
766 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
768 # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
769 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
770 hyp.SetSourceFace( face )
771 hyp.SetSourceMesh( mesh )
772 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
775 pass # end of StdMeshersBuilder_Projection2D class
777 ## Defines a projection 1D-2D algorithm
779 # It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
781 # @ingroup l3_algos_proj
782 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
784 ## name of the dynamic method in smeshBuilder.Mesh class
786 meshMethod = "Projection1D2D"
787 ## type of algorithm used with helper function in smeshBuilder.Mesh class
789 algoType = "Projection_1D2D"
790 ## doc string of the method
792 docHelper = "Creates projection 1D-2D algorithm for edges and faces"
794 ## Private constructor.
795 # @param mesh parent mesh object algorithm is assigned to
796 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
797 # if it is @c 0 (default), the algorithm is assigned to the main shape
798 def __init__(self, mesh, geom=0):
799 StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
802 pass # end of StdMeshersBuilder_Projection1D2D class
804 ## Defines a projection 3D algorithm
806 # It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
808 # @ingroup l3_algos_proj
809 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
811 ## name of the dynamic method in smeshBuilder.Mesh class
813 meshMethod = "Projection3D"
814 ## type of algorithm used with helper function in smeshBuilder.Mesh class
816 algoType = "Projection_3D"
817 ## doc string of the method
819 docHelper = "Creates projection 3D algorithm for volumes"
821 ## Private constructor.
822 # @param mesh parent mesh object algorithm is assigned to
823 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
824 # if it is @c 0 (default), the algorithm is assigned to the main shape
825 def __init__(self, mesh, geom=0):
826 Mesh_Algorithm.__init__(self)
827 self.Create(mesh, geom, self.algoType)
830 ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
831 # the mesh pattern is taken, and, optionally, the association of vertices
832 # between the source and the target solid (to which a hipothesis is assigned)
833 # @param solid from where the mesh pattern is taken
834 # @param mesh from where the mesh pattern is taken (optional)
835 # @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
836 # @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
837 # to associate with \a srcV1 (optional)
838 # @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
839 # @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
840 # to associate with \a srcV2 (optional)
841 # @param UseExisting - if ==true - searches for the existing hypothesis created with
842 # the same parameters, else (default) - creates a new one
844 # Note: association vertices must belong to one edge of a solid
845 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
846 srcV2=0, tgtV2=0, UseExisting=0):
847 for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
848 from salome.smesh.smeshBuilder import AssureGeomPublished
849 AssureGeomPublished( self.mesh, geom )
850 hyp = self.Hypothesis("ProjectionSource3D",
851 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
853 # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
854 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
855 hyp.SetSource3DShape( solid )
856 from salome.smesh.smeshBuilder import Mesh
857 if isinstance(mesh, Mesh):
858 mesh = mesh.GetMesh()
860 hyp.SetSourceMesh( mesh )
861 if srcV1 and srcV2 and tgtV1 and tgtV2:
862 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
863 #elif srcV1 or srcV2 or tgtV1 or tgtV2:
866 pass # end of StdMeshersBuilder_Projection3D class
868 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
869 # depending on geometry
871 # It is created by calling smeshBuilder.Mesh.Prism(geom=0)
873 # @ingroup l3_algos_3dextr
874 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
876 ## name of the dynamic method in smeshBuilder.Mesh class
879 ## type of algorithm used with helper function in smeshBuilder.Mesh class
881 algoType = "Prism_3D"
882 ## doc string of the method
884 docHelper = "Creates prism 3D algorithm for volumes"
886 ## Private constructor.
887 # @param mesh parent mesh object algorithm is assigned to
888 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
889 # if it is @c 0 (default), the algorithm is assigned to the main shape
890 def __init__(self, mesh, geom=0):
891 Mesh_Algorithm.__init__(self)
896 from salome.geom import geomBuilder
897 nbSolids = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SOLID"] ))
898 nbShells = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SHELL"] ))
899 if nbSolids == 0 or nbSolids == nbShells:
900 self.Create(mesh, geom, "Prism_3D")
903 self.algoType = "RadialPrism_3D"
904 self.Create(mesh, geom, "RadialPrism_3D")
905 self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
910 ## Return 3D hypothesis holding the 1D one
911 def Get3DHypothesis(self):
912 if self.algoType != "RadialPrism_3D":
913 print "Prism_3D algorith doesn't support any hyposesis"
915 return self.distribHyp
917 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
918 # hypothesis. Returns the created hypothesis
919 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
920 if self.algoType != "RadialPrism_3D":
921 print "Prism_3D algorith doesn't support any hyposesis"
923 if not self.nbLayers is None:
924 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
925 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
926 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
927 self.mesh.smeshpyD.SetCurrentStudy( None )
928 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
929 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
930 if not self.distribHyp:
931 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
932 self.distribHyp.SetLayerDistribution( hyp )
935 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
936 # prisms to build between the inner and outer shells
937 # @param n number of layers
938 # @param UseExisting if ==true - searches for the existing hypothesis created with
939 # the same parameters, else (default) - creates a new one
940 def NumberOfLayers(self, n, UseExisting=0):
941 if self.algoType != "RadialPrism_3D":
942 print "Prism_3D algorith doesn't support any hyposesis"
944 self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
945 from salome.smesh.smeshBuilder import IsEqual
946 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
947 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
948 CompareMethod=compFun)
949 self.nbLayers.SetNumberOfLayers( n )
952 ## Defines "LocalLength" hypothesis, specifying the segment length
953 # to build between the inner and the outer shells
954 # @param l the length of segments
955 # @param p the precision of rounding
956 def LocalLength(self, l, p=1e-07):
957 if self.algoType != "RadialPrism_3D":
958 print "Prism_3D algorith doesn't support any hyposesis"
960 hyp = self.OwnHypothesis("LocalLength", [l,p])
965 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
966 # prisms to build between the inner and the outer shells.
967 # @param n the number of layers
968 # @param s the scale factor (optional)
969 def NumberOfSegments(self, n, s=[]):
970 if self.algoType != "RadialPrism_3D":
971 print "Prism_3D algorith doesn't support any hyposesis"
974 hyp = self.OwnHypothesis("NumberOfSegments", [n])
976 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
977 hyp.SetDistrType( 1 )
978 hyp.SetScaleFactor(s)
979 hyp.SetNumberOfSegments(n)
982 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
983 # to build between the inner and the outer shells with a length that changes in arithmetic progression
984 # @param start the length of the first segment
985 # @param end the length of the last segment
986 def Arithmetic1D(self, start, end ):
987 if self.algoType != "RadialPrism_3D":
988 print "Prism_3D algorith doesn't support any hyposesis"
990 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
991 hyp.SetLength(start, 1)
992 hyp.SetLength(end , 0)
995 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
996 # to build between the inner and the outer shells as geometric length increasing
997 # @param start for the length of the first segment
998 # @param end for the length of the last segment
999 def StartEndLength(self, start, end):
1000 if self.algoType != "RadialPrism_3D":
1001 print "Prism_3D algorith doesn't support any hyposesis"
1003 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1004 hyp.SetLength(start, 1)
1005 hyp.SetLength(end , 0)
1008 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1009 # to build between the inner and outer shells
1010 # @param fineness defines the quality of the mesh within the range [0-1]
1011 def AutomaticLength(self, fineness=0):
1012 if self.algoType != "RadialPrism_3D":
1013 print "Prism_3D algorith doesn't support any hyposesis"
1015 hyp = self.OwnHypothesis("AutomaticLength")
1016 hyp.SetFineness( fineness )
1019 pass # end of StdMeshersBuilder_Prism3D class
1021 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
1022 # depending on geometry
1024 # It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1026 # @ingroup l3_algos_3dextr
1027 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1029 ## name of the dynamic method in smeshBuilder.Mesh class
1031 meshMethod = "Prism"
1032 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1034 algoType = "RadialPrism_3D"
1035 ## doc string of the method
1037 docHelper = "Creates prism 3D algorithm for volumes"
1039 ## Private constructor.
1040 # @param mesh parent mesh object algorithm is assigned to
1041 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1042 # if it is @c 0 (default), the algorithm is assigned to the main shape
1043 def __init__(self, mesh, geom=0):
1044 Mesh_Algorithm.__init__(self)
1049 self.Create(mesh, geom, "RadialPrism_3D")
1050 self.distribHyp = None
1051 self.nbLayers = None
1054 ## Defines a Radial Quadrangle 1D-2D algorithm
1056 # It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1058 # @ingroup l2_algos_radialq
1059 class StdMeshersBuilder_RadialQuadrangle1D2D(Mesh_Algorithm):
1061 ## name of the dynamic method in smeshBuilder.Mesh class
1063 meshMethod = "Quadrangle"
1064 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1066 algoType = RADIAL_QUAD
1067 ## doc string of the method
1069 docHelper = "Creates quadrangle 1D-2D algorithm for triangular faces"
1071 ## Private constructor.
1072 # @param mesh parent mesh object algorithm is assigned to
1073 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1074 # if it is @c 0 (default), the algorithm is assigned to the main shape
1075 def __init__(self, mesh, geom=0):
1076 Mesh_Algorithm.__init__(self)
1077 self.Create(mesh, geom, self.algoType)
1079 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1080 self.nbLayers = None
1083 ## Return 2D hypothesis holding the 1D one
1084 def Get2DHypothesis(self):
1085 if not self.distribHyp:
1086 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1087 return self.distribHyp
1089 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
1090 # hypothesis. Returns the created hypothesis
1091 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1093 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1094 if self.distribHyp is None:
1095 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1097 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1098 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
1099 self.mesh.smeshpyD.SetCurrentStudy( None )
1100 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1101 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
1102 self.distribHyp.SetLayerDistribution( hyp )
1105 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
1106 # @param n number of layers
1107 # @param UseExisting if ==true - searches for the existing hypothesis created with
1108 # the same parameters, else (default) - creates a new one
1109 def NumberOfLayers(self, n, UseExisting=0):
1111 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1112 from salome.smesh.smeshBuilder import IsEqual
1113 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1114 self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1115 CompareMethod=compFun)
1116 self.nbLayers.SetNumberOfLayers( n )
1117 return self.nbLayers
1119 ## Defines "LocalLength" hypothesis, specifying the segment length
1120 # @param l the length of segments
1121 # @param p the precision of rounding
1122 def LocalLength(self, l, p=1e-07):
1123 hyp = self.OwnHypothesis("LocalLength", [l,p])
1128 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
1129 # @param n the number of layers
1130 # @param s the scale factor (optional)
1131 def NumberOfSegments(self, n, s=[]):
1133 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1135 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1136 hyp.SetDistrType( 1 )
1137 hyp.SetScaleFactor(s)
1138 hyp.SetNumberOfSegments(n)
1141 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1142 # with a length that changes in arithmetic progression
1143 # @param start the length of the first segment
1144 # @param end the length of the last segment
1145 def Arithmetic1D(self, start, end ):
1146 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1147 hyp.SetLength(start, 1)
1148 hyp.SetLength(end , 0)
1151 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1152 # as geometric length increasing
1153 # @param start for the length of the first segment
1154 # @param end for the length of the last segment
1155 def StartEndLength(self, start, end):
1156 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1157 hyp.SetLength(start, 1)
1158 hyp.SetLength(end , 0)
1161 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1162 # @param fineness defines the quality of the mesh within the range [0-1]
1163 def AutomaticLength(self, fineness=0):
1164 hyp = self.OwnHypothesis("AutomaticLength")
1165 hyp.SetFineness( fineness )
1168 pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1170 ## Defines a Use Existing Elements 1D algorithm
1172 # It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1174 # @ingroup l3_algos_basic
1175 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1177 ## name of the dynamic method in smeshBuilder.Mesh class
1179 meshMethod = "UseExisting1DElements"
1180 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1182 algoType = "Import_1D"
1183 ## flag pointing either this algorithm should be used by default in dynamic method
1184 # of smeshBuilder.Mesh class
1187 ## doc string of the method
1189 docHelper = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1191 ## Private constructor.
1192 # @param mesh parent mesh object algorithm is assigned to
1193 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1194 # if it is @c 0 (default), the algorithm is assigned to the main shape
1195 def __init__(self, mesh, geom=0):
1196 Mesh_Algorithm.__init__(self)
1197 self.Create(mesh, geom, self.algoType)
1200 ## Defines "Source edges" hypothesis, specifying groups of edges to import
1201 # @param groups list of groups of edges
1202 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1203 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1204 # @param UseExisting if ==true - searches for the existing hypothesis created with
1205 # the same parameters, else (default) - creates a new one
1206 def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1207 for group in groups:
1208 from salome.smesh.smeshBuilder import AssureGeomPublished
1209 AssureGeomPublished( self.mesh, group )
1210 compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1211 hyp.GetCopySourceMesh() == args[1], args[2] )
1212 hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1213 UseExisting=UseExisting, CompareMethod=compFun)
1214 hyp.SetSourceEdges(groups)
1215 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1218 pass # end of StdMeshersBuilder_UseExistingElements_1D class
1220 ## Defines a Use Existing Elements 1D-2D algorithm
1222 # It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1224 # @ingroup l3_algos_basic
1225 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1227 ## name of the dynamic method in smeshBuilder.Mesh class
1229 meshMethod = "UseExisting2DElements"
1230 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1232 algoType = "Import_1D2D"
1233 ## flag pointing either this algorithm should be used by default in dynamic method
1234 # of smeshBuilder.Mesh class
1237 ## doc string of the method
1239 docHelper = "Creates 1D-2D algorithm for edges/faces with reusing of existing mesh elements"
1241 ## Private constructor.
1242 # @param mesh parent mesh object algorithm is assigned to
1243 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1244 # if it is @c 0 (default), the algorithm is assigned to the main shape
1245 def __init__(self, mesh, geom=0):
1246 Mesh_Algorithm.__init__(self)
1247 self.Create(mesh, geom, self.algoType)
1250 ## Defines "Source faces" hypothesis, specifying groups of faces to import
1251 # @param groups list of groups of faces
1252 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1253 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1254 # @param UseExisting if ==true - searches for the existing hypothesis created with
1255 # the same parameters, else (default) - creates a new one
1256 def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1257 for group in groups:
1258 from salome.smesh.smeshBuilder import AssureGeomPublished
1259 AssureGeomPublished( self.mesh, group )
1260 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1261 hyp.GetCopySourceMesh() == args[1], args[2] )
1262 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1263 UseExisting=UseExisting, CompareMethod=compFun)
1264 hyp.SetSourceFaces(groups)
1265 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1268 pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1270 ## Defines a Body Fitting 3D algorithm
1272 # It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1274 # @ingroup l3_algos_basic
1275 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1277 ## name of the dynamic method in smeshBuilder.Mesh class
1279 meshMethod = "BodyFitted"
1280 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1282 algoType = "Cartesian_3D"
1283 ## flag pointing either this algorithm should be used by default in dynamic method
1284 # of smeshBuilder.Mesh class
1287 ## doc string of the method
1289 docHelper = "Creates body fitting 3D algorithm for volumes"
1291 ## Private constructor.
1292 # @param mesh parent mesh object algorithm is assigned to
1293 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1294 # if it is @c 0 (default), the algorithm is assigned to the main shape
1295 def __init__(self, mesh, geom=0):
1296 self.Create(mesh, geom, self.algoType)
1300 ## Defines "Body Fitting parameters" hypothesis
1301 # @param xGridDef is definition of the grid along the X asix.
1302 # It can be in either of two following forms:
1303 # - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1304 # - Functions f(t) defining grid spacing at each point on grid axis. If there are
1305 # several functions, they must be accompanied by relative coordinates of
1306 # points dividing the whole shape into ranges where the functions apply; points
1307 # coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1308 # function f(t) varies from 0.0 to 1.0 witin a shape range.
1310 # - "10.5" - defines a grid with a constant spacing
1311 # - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1312 # @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does
1313 # @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does
1314 # @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1315 # a polyhedron of size less than hexSize/sizeThreshold is not created
1316 # @param UseExisting if ==true - searches for the existing hypothesis created with
1317 # the same parameters, else (default) - creates a new one
1318 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, UseExisting=False):
1320 compFun = lambda hyp, args: False
1321 self.hyp = self.Hypothesis("CartesianParameters3D",
1322 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1323 UseExisting=UseExisting, CompareMethod=compFun)
1324 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1325 self.mesh.AddHypothesis( self.hyp, self.geom )
1327 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef]):
1328 if not gridDef: raise ValueError, "Empty grid definition"
1329 if isinstance( gridDef, str ):
1330 self.hyp.SetGridSpacing( [gridDef], [], axis )
1331 elif isinstance( gridDef[0], str ):
1332 self.hyp.SetGridSpacing( gridDef, [], axis )
1333 elif isinstance( gridDef[0], int ) or \
1334 isinstance( gridDef[0], float ):
1335 self.hyp.SetGrid(gridDef, axis )
1337 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1338 self.hyp.SetSizeThreshold( sizeThreshold )
1341 pass # end of StdMeshersBuilder_Cartesian_3D class
1343 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1344 # segments usable by 2D algoritms
1346 # It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1348 # @ingroup l3_algos_basic
1349 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1351 ## name of the dynamic method in smeshBuilder.Mesh class
1353 meshMethod = "UseExistingSegments"
1354 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1356 algoType = "UseExisting_1D"
1357 ## doc string of the method
1359 docHelper = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1361 ## Private constructor.
1362 # @param mesh parent mesh object algorithm is assigned to
1363 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1364 # if it is @c 0 (default), the algorithm is assigned to the main shape
1365 def __init__(self, mesh, geom=0):
1366 self.Create(mesh, geom, self.algoType)
1369 pass # end of StdMeshersBuilder_UseExisting_1D class
1371 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1372 # faces usable by 3D algoritms
1374 # It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1376 # @ingroup l3_algos_basic
1377 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1379 ## name of the dynamic method in smeshBuilder.Mesh class
1381 meshMethod = "UseExistingFaces"
1382 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1384 algoType = "UseExisting_2D"
1385 ## doc string of the method
1387 docHelper = "Creates 2D algorithm for faces with reusing of existing mesh elements"
1389 ## Private constructor.
1390 # @param mesh parent mesh object algorithm is assigned to
1391 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1392 # if it is @c 0 (default), the algorithm is assigned to the main shape
1393 def __init__(self, mesh, geom=0):
1394 self.Create(mesh, geom, self.algoType)
1397 pass # end of StdMeshersBuilder_UseExisting_2D class