1 # Copyright (C) 2007-2015 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 # @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"
45 ## Algorithm type: Quadrangle (Medial Axis Projection) 1D-2D algorithm, see StdMeshersBuilder_QuadMA_1D2D
46 QUAD_MA_PROJ = "QuadFromMedialAxis_1D2D"
48 # import items of enums
49 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
50 for e in StdMeshers.VLExtrusionMethod._items: exec('%s = StdMeshers.%s'%(e,e))
52 #----------------------
54 #----------------------
56 ## Defines segment 1D algorithm for edges discretization.
58 # It can be created by calling smeshBuilder.Mesh.Segment(geom=0)
60 # @ingroup l3_algos_basic
61 class StdMeshersBuilder_Segment(Mesh_Algorithm):
63 ## name of the dynamic method in smeshBuilder.Mesh class
65 meshMethod = "Segment"
66 ## type of algorithm used with helper function in smeshBuilder.Mesh class
69 ## flag pointing either this algorithm should be used by default in dynamic method
70 # of smeshBuilder.Mesh class
73 ## doc string of the method
75 docHelper = "Creates segment 1D algorithm for edges"
77 ## Private constructor.
78 # @param mesh parent mesh object algorithm is assigned to
79 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
80 # if it is @c 0 (default), the algorithm is assigned to the main shape
81 def __init__(self, mesh, geom=0):
82 Mesh_Algorithm.__init__(self)
83 self.Create(mesh, geom, self.algoType)
86 ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
87 # @param l for the length of segments that cut an edge
88 # @param UseExisting if ==true - searches for an existing hypothesis created with
89 # the same parameters, else (default) - creates a new one
90 # @param p precision, used for calculation of the number of segments.
91 # The precision should be a positive, meaningful value within the range [0,1].
92 # In general, the number of segments is calculated with the formula:
93 # nb = ceil((edge_length / l) - p)
94 # Function ceil rounds its argument to the higher integer.
95 # So, p=0 means rounding of (edge_length / l) to the higher integer,
96 # p=0.5 means rounding of (edge_length / l) to the nearest integer,
97 # p=1 means rounding of (edge_length / l) to the lower integer.
98 # Default value is 1e-07.
99 # @return an instance of StdMeshers_LocalLength hypothesis
100 # @ingroup l3_hypos_1dhyps
101 def LocalLength(self, l, UseExisting=0, p=1e-07):
102 from salome.smesh.smeshBuilder import IsEqual
103 comFun=lambda hyp, args: IsEqual(hyp.GetLength(), args[0]) and IsEqual(hyp.GetPrecision(), args[1])
104 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting, CompareMethod=comFun)
109 ## Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
110 # @param length is optional maximal allowed length of segment, if it is omitted
111 # the preestimated length is used that depends on geometry size
112 # @param UseExisting if ==true - searches for an existing hypothesis created with
113 # the same parameters, else (default) - creates a new one
114 # @return an instance of StdMeshers_MaxLength hypothesis
115 # @ingroup l3_hypos_1dhyps
116 def MaxSize(self, length=0.0, UseExisting=0):
117 hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
120 hyp.SetLength(length)
122 # set preestimated length
123 gen = self.mesh.smeshpyD
124 initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
125 self.mesh.GetMesh(), self.mesh.GetShape(),
127 preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
129 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
132 hyp.SetUsePreestimatedLength( length == 0.0 )
135 ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
136 # @param n for the number of segments that cut an edge
137 # @param s for the scale factor (optional)
138 # @param reversedEdges is a list of edges to mesh using reversed orientation.
139 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
140 # @param UseExisting if ==true - searches for an existing hypothesis created with
141 # the same parameters, else (default) - create a new one
142 # @return an instance of StdMeshers_NumberOfSegments hypothesis
143 # @ingroup l3_hypos_1dhyps
144 def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
145 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
146 reversedEdges, UseExisting = [], reversedEdges
147 entry = self.MainShapeEntry()
148 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
150 hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
151 UseExisting=UseExisting,
152 CompareMethod=self._compareNumberOfSegments)
154 hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
155 UseExisting=UseExisting,
156 CompareMethod=self._compareNumberOfSegments)
157 hyp.SetScaleFactor(s)
158 hyp.SetNumberOfSegments(n)
159 hyp.SetReversedEdges( reversedEdgeInd )
160 hyp.SetObjectEntry( entry )
165 # Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
166 def _compareNumberOfSegments(self, hyp, args):
167 if hyp.GetNumberOfSegments() == args[0]:
169 if hyp.GetReversedEdges() == args[1]:
170 if not args[1] or hyp.GetObjectEntry() == args[2]:
173 from salome.smesh.smeshBuilder import IsEqual
174 if hyp.GetReversedEdges() == args[2]:
175 if not args[2] or hyp.GetObjectEntry() == args[3]:
176 if hyp.GetDistrType() == 1:
177 if IsEqual(hyp.GetScaleFactor(), args[1]):
181 ## Defines "Adaptive" hypothesis to cut an edge into segments keeping segment size
182 # within the given range and considering (1) deflection of segments from the edge
183 # and (2) distance from segments to closest edges and faces to have segment length
184 # not longer than two times shortest distances to edges and faces.
185 # @param minSize defines the minimal allowed segment length
186 # @param maxSize defines the maximal allowed segment length
187 # @param deflection defines the maximal allowed distance from a segment to an edge
188 # @param UseExisting if ==true - searches for an existing hypothesis created with
189 # the same parameters, else (default) - creates a new one
190 # @return an instance of StdMeshers_Adaptive1D hypothesis
191 # @ingroup l3_hypos_1dhyps
192 def Adaptive(self, minSize, maxSize, deflection, UseExisting=False):
193 from salome.smesh.smeshBuilder import IsEqual
194 compFun = lambda hyp, args: ( IsEqual(hyp.GetMinSize(), args[0]) and \
195 IsEqual(hyp.GetMaxSize(), args[1]) and \
196 IsEqual(hyp.GetDeflection(), args[2]))
197 hyp = self.Hypothesis("Adaptive1D", [minSize, maxSize, deflection],
198 UseExisting=UseExisting, CompareMethod=compFun)
199 hyp.SetMinSize(minSize)
200 hyp.SetMaxSize(maxSize)
201 hyp.SetDeflection(deflection)
204 ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with a length
205 # that changes in arithmetic progression
206 # @param start defines the length of the first segment
207 # @param end defines the length of the last segment
208 # @param reversedEdges is a list of edges to mesh using reversed orientation.
209 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
210 # @param UseExisting if ==true - searches for an existing hypothesis created with
211 # the same parameters, else (default) - creates a new one
212 # @return an instance of StdMeshers_Arithmetic1D hypothesis
213 # @ingroup l3_hypos_1dhyps
214 def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
215 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
216 reversedEdges, UseExisting = [], reversedEdges
217 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
218 entry = self.MainShapeEntry()
219 from salome.smesh.smeshBuilder import IsEqual
220 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
221 IsEqual(hyp.GetLength(0), args[1]) and \
222 hyp.GetReversedEdges() == args[2] and \
223 (not args[2] or hyp.GetObjectEntry() == args[3]))
224 hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
225 UseExisting=UseExisting, CompareMethod=compFun)
226 hyp.SetStartLength(start)
227 hyp.SetEndLength(end)
228 hyp.SetReversedEdges( reversedEdgeInd )
229 hyp.SetObjectEntry( entry )
232 ## Defines "GeometricProgression" hypothesis to cut an edge in several
233 # segments with a length that changes in Geometric progression
234 # @param start defines the length of the first segment
235 # @param ratio defines the common ratio of the geometric progression
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_Geometric1D hypothesis
241 # @ingroup l3_hypos_1dhyps
242 def GeometricProgression(self, start, ratio, reversedEdges=[], UseExisting=0):
243 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
244 entry = self.MainShapeEntry()
245 from salome.smesh.smeshBuilder import IsEqual
246 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
247 IsEqual(hyp.GetLength(0), args[1]) and \
248 hyp.GetReversedEdges() == args[2] and \
249 (not args[2] or hyp.GetObjectEntry() == args[3]))
250 hyp = self.Hypothesis("GeometricProgression", [start, ratio, reversedEdgeInd, entry],
251 UseExisting=UseExisting, CompareMethod=compFun)
252 hyp.SetStartLength( start )
253 hyp.SetCommonRatio( ratio )
254 hyp.SetReversedEdges( reversedEdgeInd )
255 hyp.SetObjectEntry( entry )
258 ## Defines "FixedPoints1D" hypothesis to cut an edge using parameter
259 # on curve from 0 to 1 (additionally it is neecessary to check
260 # orientation of edges and create list of reversed edges if it is
261 # needed) and sets numbers of segments between given points (default
262 # values are equals 1
263 # @param points defines the list of parameters on curve
264 # @param nbSegs defines the list of numbers of segments
265 # @param reversedEdges is a list of edges to mesh using reversed orientation.
266 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
267 # @param UseExisting if ==true - searches for an existing hypothesis created with
268 # the same parameters, else (default) - creates a new one
269 # @return an instance of StdMeshers_FixedPoints1D hypothesis
270 # @ingroup l3_hypos_1dhyps
271 def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
272 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
273 reversedEdges, UseExisting = [], reversedEdges
274 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
275 entry = self.MainShapeEntry()
276 compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
277 hyp.GetNbSegments() == args[1] and \
278 hyp.GetReversedEdges() == args[2] and \
279 (not args[2] or hyp.GetObjectEntry() == args[3]))
280 hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
281 UseExisting=UseExisting, CompareMethod=compFun)
282 hyp.SetPoints(points)
283 hyp.SetNbSegments(nbSegs)
284 hyp.SetReversedEdges(reversedEdgeInd)
285 hyp.SetObjectEntry(entry)
288 ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
289 # @param start defines the length of the first segment
290 # @param end defines the length of the last segment
291 # @param reversedEdges is a list of edges to mesh using reversed orientation.
292 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
293 # @param UseExisting if ==true - searches for an existing hypothesis created with
294 # the same parameters, else (default) - creates a new one
295 # @return an instance of StdMeshers_StartEndLength hypothesis
296 # @ingroup l3_hypos_1dhyps
297 def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
298 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
299 reversedEdges, UseExisting = [], reversedEdges
300 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
301 entry = self.MainShapeEntry()
302 from salome.smesh.smeshBuilder import IsEqual
303 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
304 IsEqual(hyp.GetLength(0), args[1]) and \
305 hyp.GetReversedEdges() == args[2] and \
306 (not args[2] or hyp.GetObjectEntry() == args[3]))
307 hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
308 UseExisting=UseExisting, CompareMethod=compFun)
309 hyp.SetStartLength(start)
310 hyp.SetEndLength(end)
311 hyp.SetReversedEdges( reversedEdgeInd )
312 hyp.SetObjectEntry( entry )
315 ## Defines "Deflection1D" hypothesis
316 # @param d for the deflection
317 # @param UseExisting if ==true - searches for an existing hypothesis created with
318 # the same parameters, else (default) - create a new one
319 # @ingroup l3_hypos_1dhyps
320 def Deflection1D(self, d, UseExisting=0):
321 from salome.smesh.smeshBuilder import IsEqual
322 compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
323 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
327 ## Defines "Propagation" hypothesis that propagates 1D hypotheses
328 # from an edge where this hypothesis is assigned to
329 # on all other edges that are at the opposite side in case of quadrangular faces
330 # This hypothesis should be assigned to an edge to propagate a hypothesis from.
331 # @ingroup l3_hypos_additi
332 def Propagation(self):
333 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
335 ## Defines "Propagation of Node Distribution" hypothesis that propagates
336 # distribution of nodes from an edge where this hypothesis is assigned to,
337 # to opposite edges of quadrangular faces, so that number of segments on all these
338 # edges will be the same, as well as relations between segment lengths.
339 # @ingroup l3_hypos_additi
340 def PropagationOfDistribution(self):
341 return self.Hypothesis("PropagOfDistribution", UseExisting=1,
342 CompareMethod=self.CompareEqualHyp)
344 ## Defines "AutomaticLength" hypothesis
345 # @param fineness for the fineness [0-1]
346 # @param UseExisting if ==true - searches for an existing hypothesis created with the
347 # same parameters, else (default) - create a new one
348 # @ingroup l3_hypos_1dhyps
349 def AutomaticLength(self, fineness=0, UseExisting=0):
350 from salome.smesh.smeshBuilder import IsEqual
351 compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
352 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
353 CompareMethod=compFun)
354 hyp.SetFineness( fineness )
357 ## Defines "SegmentLengthAroundVertex" hypothesis
358 # @param length for the segment length
359 # @param vertex for the length localization: the vertex index [0,1] | vertex object.
360 # Any other integer value means that the hypothesis will be set on the
361 # whole 1D shape, where Mesh_Segment algorithm is assigned.
362 # @param UseExisting if ==true - searches for an existing hypothesis created with
363 # the same parameters, else (default) - creates a new one
364 # @ingroup l3_algos_segmarv
365 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
367 store_geom = self.geom
368 if type(vertex) is types.IntType:
369 if vertex == 0 or vertex == 1:
370 from salome.geom import geomBuilder
371 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geomBuilder.geomBuilder.ShapeType["VERTEX"],True)[vertex]
379 if self.geom is None:
380 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
381 from salome.smesh.smeshBuilder import AssureGeomPublished, GetName, TreatHypoStatus
382 AssureGeomPublished( self.mesh, self.geom )
383 name = GetName(self.geom)
385 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
387 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
389 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
390 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True, self.mesh)
392 from salome.smesh.smeshBuilder import IsEqual
393 comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
394 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
395 CompareMethod=comFun)
396 self.geom = store_geom
397 hyp.SetLength( length )
400 ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
401 # If the 2D mesher sees that all boundary edges are quadratic,
402 # it generates quadratic faces, else it generates linear faces using
403 # medium nodes as if they are vertices.
404 # The 3D mesher generates quadratic volumes only if all boundary faces
405 # are quadratic, else it fails.
407 # @ingroup l3_hypos_additi
408 def QuadraticMesh(self):
409 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
412 pass # end of StdMeshersBuilder_Segment class
414 ## Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
416 # It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.COMPOSITE,geom=0)
418 # @ingroup l3_algos_basic
419 class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
421 ## name of the dynamic method in smeshBuilder.Mesh class
423 meshMethod = "Segment"
424 ## type of algorithm used with helper function in smeshBuilder.Mesh class
427 ## flag pointing either this algorithm should be used by default in dynamic method
428 # of smeshBuilder.Mesh class
431 ## doc string of the method
433 docHelper = "Creates segment 1D algorithm for edges"
435 ## Private constructor.
436 # @param mesh parent mesh object algorithm is assigned to
437 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
438 # if it is @c 0 (default), the algorithm is assigned to the main shape
439 def __init__(self, mesh, geom=0):
440 self.Create(mesh, geom, self.algoType)
443 pass # end of StdMeshersBuilder_CompositeSegment class
445 ## Defines a segment 1D algorithm for discretization of edges with Python function
447 # It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.PYTHON,geom=0)
449 # @ingroup l3_algos_basic
450 class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
452 ## name of the dynamic method in smeshBuilder.Mesh class
454 meshMethod = "Segment"
455 ## type of algorithm used with helper function in smeshBuilder.Mesh class
458 ## doc string of the method
460 docHelper = "Creates segment 1D algorithm for edges"
462 ## Private constructor.
463 # @param mesh parent mesh object algorithm is assigned to
464 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
465 # if it is @c 0 (default), the algorithm is assigned to the main shape
466 def __init__(self, mesh, geom=0):
467 import Python1dPlugin
468 self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
471 ## Defines "PythonSplit1D" hypothesis
472 # @param n for the number of segments that cut an edge
473 # @param func for the python function that calculates the length of all segments
474 # @param UseExisting if ==true - searches for the existing hypothesis created with
475 # the same parameters, else (default) - creates a new one
476 # @ingroup l3_hypos_1dhyps
477 def PythonSplit1D(self, n, func, UseExisting=0):
478 compFun = lambda hyp, args: False
479 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
480 UseExisting=UseExisting, CompareMethod=compFun)
481 hyp.SetNumberOfSegments(n)
482 hyp.SetPythonLog10RatioFunction(func)
485 pass # end of StdMeshersBuilder_Segment_Python class
487 ## Triangle MEFISTO 2D algorithm
489 # It is created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MEFISTO,geom=0)
491 # @ingroup l3_algos_basic
492 class StdMeshersBuilder_Triangle_MEFISTO(Mesh_Algorithm):
494 ## name of the dynamic method in smeshBuilder.Mesh class
496 meshMethod = "Triangle"
497 ## type of algorithm used with helper function in smeshBuilder.Mesh class
500 ## flag pointing either this algorithm should be used by default in dynamic method
501 # of smeshBuilder.Mesh class
504 ## doc string of the method
506 docHelper = "Creates triangle 2D algorithm for faces"
508 ## Private constructor.
509 # @param mesh parent mesh object algorithm is assigned to
510 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
511 # if it is @c 0 (default), the algorithm is assigned to the main shape
512 def __init__(self, mesh, geom=0):
513 Mesh_Algorithm.__init__(self)
514 self.Create(mesh, geom, self.algoType)
517 ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
518 # @param area for the maximum area of each triangle
519 # @param UseExisting if ==true - searches for an existing hypothesis created with the
520 # same parameters, else (default) - creates a new one
522 # @ingroup l3_hypos_2dhyps
523 def MaxElementArea(self, area, UseExisting=0):
524 from salome.smesh.smeshBuilder import IsEqual
525 comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
526 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
527 CompareMethod=comparator)
528 hyp.SetMaxElementArea(area)
531 ## Defines "LengthFromEdges" hypothesis to build triangles
532 # based on the length of the edges taken from the wire
534 # @ingroup l3_hypos_2dhyps
535 def LengthFromEdges(self):
536 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
539 pass # end of StdMeshersBuilder_Triangle_MEFISTO class
541 ## Defines a quadrangle 2D algorithm
543 # It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
545 # @ingroup l3_algos_basic
546 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
548 ## name of the dynamic method in smeshBuilder.Mesh class
550 meshMethod = "Quadrangle"
551 ## type of algorithm used with helper function in smeshBuilder.Mesh class
553 algoType = QUADRANGLE
554 ## flag pointing either this algorithm should be used by default in dynamic method
555 # of smeshBuilder.Mesh class
558 ## doc string of the method
560 docHelper = "Creates quadrangle 2D algorithm for faces"
561 ## hypothesis associated with algorithm
565 ## Private constructor.
566 # @param mesh parent mesh object algorithm is assigned to
567 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
568 # if it is @c 0 (default), the algorithm is assigned to the main shape
569 def __init__(self, mesh, geom=0):
570 Mesh_Algorithm.__init__(self)
571 self.Create(mesh, geom, self.algoType)
574 ## Defines "QuadrangleParameters" hypothesis
575 # @param quadType defines the algorithm of transition between differently descretized
576 # sides of a geometrical face:
577 # - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
578 # area along the finer meshed sides.
579 # - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
580 # finer meshed sides.
581 # - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
582 # the finer meshed sides, iff the total quantity of segments on
583 # all four sides of the face is even (divisible by 2).
584 # - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
585 # area is located along the coarser meshed sides.
586 # - QUAD_REDUCED - only quadrangles are built and the transition between the sides
587 # is made gradually, layer by layer. This type has a limitation on
588 # the number of segments: one pair of opposite sides must have the
589 # same number of segments, the other pair must have an even difference
590 # between the numbers of segments on the sides.
591 # @param triangleVertex: vertex of a trilateral geometrical face, around which triangles
592 # will be created while other elements will be quadrangles.
593 # Vertex can be either a GEOM_Object or a vertex ID within the
595 # @param enfVertices: list of shapes defining positions where nodes (enforced nodes)
596 # must be created by the mesher. Shapes can be of any type,
597 # vertices of given shapes define positions of enforced nodes.
598 # Only vertices successfully projected to the face are used.
599 # @param enfPoints: list of points giving positions of enforced nodes.
600 # Point can be defined either as SMESH.PointStruct's
601 # ([SMESH.PointStruct(x1,y1,z1), SMESH.PointStruct(x2,y2,z2),...])
602 # or triples of values ([[x1,y1,z1], [x2,y2,z2], ...]).
603 # In the case if the defined QuadrangleParameters() refer to a sole face,
604 # all given points must lie on this face, else the mesher fails.
605 # @param UseExisting: if \c True - searches for the existing hypothesis created with
606 # the same parameters, else (default) - creates a new one
607 # @ingroup l3_hypos_quad
608 def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0,
609 enfVertices=[],enfPoints=[],UseExisting=0):
611 vertexID = triangleVertex
612 if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
613 vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
614 if isinstance( enfVertices, int ) and not enfPoints and not UseExisting:
615 # a call of old syntax, before inserting enfVertices and enfPoints before UseExisting
616 UseExisting, enfVertices = enfVertices, []
617 pStructs, xyz = [], []
619 if isinstance( p, SMESH.PointStruct ):
620 xyz.append(( p.x, p.y, p.z ))
623 xyz.append(( p[0], p[1], p[2] ))
624 pStructs.append( SMESH.PointStruct( p[0], p[1], p[2] ))
626 compFun = lambda hyp,args: \
627 hyp.GetQuadType() == args[0] and \
628 (hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1)) and \
629 ((hyp.GetEnforcedNodes()) == (args[2],args[3])) # True w/o enfVertices only
630 entries = [ shape.GetStudyEntry() for shape in enfVertices ]
631 self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID,entries,xyz],
632 UseExisting = UseExisting, CompareMethod=compFun)
634 if self.params.GetQuadType() != quadType:
635 self.params.SetQuadType(quadType)
637 self.params.SetTriaVertex( vertexID )
638 from salome.smesh.smeshBuilder import AssureGeomPublished
639 for v in enfVertices:
640 AssureGeomPublished( self.mesh, v )
641 self.params.SetEnforcedNodes( enfVertices, pStructs )
644 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
645 # quadrangles are built in the transition area along the finer meshed sides,
646 # iff the total quantity of segments on all four sides of the face is even.
647 # @param reversed if True, transition area is located along the coarser meshed sides.
648 # @param UseExisting: if ==true - searches for the existing hypothesis created with
649 # the same parameters, else (default) - creates a new one
650 # @ingroup l3_hypos_quad
651 def QuadranglePreference(self, reversed=False, UseExisting=0):
653 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
654 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
656 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
657 # triangles are built in the transition area along the finer meshed sides.
658 # @param UseExisting: if ==true - searches for the existing hypothesis created with
659 # the same parameters, else (default) - creates a new one
660 # @ingroup l3_hypos_quad
661 def TrianglePreference(self, UseExisting=0):
662 return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
664 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
665 # quadrangles are built and the transition between the sides is made gradually,
666 # layer by layer. This type has a limitation on the number of segments: one pair
667 # of opposite sides must have the same number of segments, the other pair must
668 # have an even difference between the numbers of segments on the sides.
669 # @param UseExisting: if ==true - searches for the existing hypothesis created with
670 # the same parameters, else (default) - creates a new one
671 # @ingroup l3_hypos_quad
672 def Reduced(self, UseExisting=0):
673 return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
675 ## Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
676 # @param vertex: vertex of a trilateral geometrical face, around which triangles
677 # will be created while other elements will be quadrangles.
678 # Vertex can be either a GEOM_Object or a vertex ID within the
680 # @param UseExisting: if ==true - searches for the existing hypothesis created with
681 # the same parameters, else (default) - creates a new one
682 # @ingroup l3_hypos_quad
683 def TriangleVertex(self, vertex, UseExisting=0):
684 return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
686 pass # end of StdMeshersBuilder_Quadrangle class
688 ## Defines a hexahedron 3D algorithm
690 # It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
692 # @ingroup l3_algos_basic
693 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
695 ## name of the dynamic method in smeshBuilder.Mesh class
697 meshMethod = "Hexahedron"
698 ## type of algorithm used with helper function in smeshBuilder.Mesh class
701 ## flag pointing either this algorithm should be used by default in dynamic method
702 # of smeshBuilder.Mesh class
705 ## doc string of the method
707 docHelper = "Creates hexahedron 3D algorithm for volumes"
709 ## Private constructor.
710 # @param mesh parent mesh object algorithm is assigned to
711 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
712 # if it is @c 0 (default), the algorithm is assigned to the main shape
713 def __init__(self, mesh, geom=0):
714 Mesh_Algorithm.__init__(self)
715 self.Create(mesh, geom, Hexa)
718 pass # end of StdMeshersBuilder_Hexahedron class
720 ## Defines a projection 1D algorithm
722 # It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
724 # @ingroup l3_algos_proj
725 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
727 ## name of the dynamic method in smeshBuilder.Mesh class
729 meshMethod = "Projection1D"
730 ## type of algorithm used with helper function in smeshBuilder.Mesh class
732 algoType = "Projection_1D"
733 ## flag pointing either this algorithm should be used by default in dynamic method
734 # of smeshBuilder.Mesh class
737 ## doc string of the method
739 docHelper = "Creates projection 1D algorithm for edges"
741 ## Private constructor.
742 # @param mesh parent mesh object algorithm is assigned to
743 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
744 # if it is @c 0 (default), the algorithm is assigned to the main shape
745 def __init__(self, mesh, geom=0):
746 Mesh_Algorithm.__init__(self)
747 self.Create(mesh, geom, self.algoType)
750 ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
751 # a mesh pattern is taken, and, optionally, the association of vertices
752 # between the source edge and a target edge (to which a hypothesis is assigned)
753 # @param edge from which nodes distribution is taken
754 # @param mesh from which nodes distribution is taken (optional)
755 # @param srcV a vertex of \a edge to associate with \a tgtV (optional)
756 # @param tgtV a vertex of \a the edge to which the algorithm is assigned,
757 # to associate with \a srcV (optional)
758 # @param UseExisting if ==true - searches for the existing hypothesis created with
759 # the same parameters, else (default) - creates a new one
760 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
761 from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
762 AssureGeomPublished( self.mesh, edge )
763 AssureGeomPublished( self.mesh, srcV )
764 AssureGeomPublished( self.mesh, tgtV )
765 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
767 # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
768 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
769 hyp.SetSourceEdge( edge )
770 if not mesh is None and isinstance(mesh, Mesh):
771 mesh = mesh.GetMesh()
772 hyp.SetSourceMesh( mesh )
773 hyp.SetVertexAssociation( srcV, tgtV )
776 pass # end of StdMeshersBuilder_Projection1D class
778 ## Defines a projection 2D algorithm
780 # It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
782 # @ingroup l3_algos_proj
783 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
785 ## name of the dynamic method in smeshBuilder.Mesh class
787 meshMethod = "Projection2D"
788 ## type of algorithm used with helper function in smeshBuilder.Mesh class
790 algoType = "Projection_2D"
791 ## flag pointing either this algorithm should be used by default in dynamic method
792 # of smeshBuilder.Mesh class
795 ## doc string of the method
797 docHelper = "Creates projection 2D algorithm for faces"
799 ## Private constructor.
800 # @param mesh parent mesh object algorithm is assigned to
801 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
802 # if it is @c 0 (default), the algorithm is assigned to the main shape
803 def __init__(self, mesh, geom=0):
804 Mesh_Algorithm.__init__(self)
805 self.Create(mesh, geom, self.algoType)
808 ## Defines "Source Face" hypothesis, specifying a meshed face, from where
809 # a mesh pattern is taken, and, optionally, the association of vertices
810 # between the source face and the target face (to which a hypothesis is assigned)
811 # @param face from which the mesh pattern is taken
812 # @param mesh from which the mesh pattern is taken (optional)
813 # @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
814 # @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
815 # to associate with \a srcV1 (optional)
816 # @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
817 # @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
818 # to associate with \a srcV2 (optional)
819 # @param UseExisting if ==true - forces the search for the existing hypothesis created with
820 # the same parameters, else (default) - forces the creation a new one
822 # Note: all association vertices must belong to one edge of a face
823 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
824 srcV2=None, tgtV2=None, UseExisting=0):
825 from salome.smesh.smeshBuilder import Mesh
826 if isinstance(mesh, Mesh):
827 mesh = mesh.GetMesh()
828 for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
829 from salome.smesh.smeshBuilder import AssureGeomPublished
830 AssureGeomPublished( self.mesh, geom )
831 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
832 UseExisting=0, toAdd=False)
833 # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
834 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
835 hyp.SetSourceFace( face )
836 hyp.SetSourceMesh( mesh )
837 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
838 self.mesh.AddHypothesis(hyp, self.geom)
841 pass # end of StdMeshersBuilder_Projection2D class
843 ## Defines a projection 1D-2D algorithm
845 # It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
847 # @ingroup l3_algos_proj
848 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
850 ## name of the dynamic method in smeshBuilder.Mesh class
852 meshMethod = "Projection1D2D"
853 ## type of algorithm used with helper function in smeshBuilder.Mesh class
855 algoType = "Projection_1D2D"
856 ## doc string of the method
858 docHelper = "Creates projection 1D-2D algorithm for faces"
860 ## Private constructor.
861 # @param mesh parent mesh object algorithm is assigned to
862 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
863 # if it is @c 0 (default), the algorithm is assigned to the main shape
864 def __init__(self, mesh, geom=0):
865 StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
868 pass # end of StdMeshersBuilder_Projection1D2D class
870 ## Defines a projection 3D algorithm
872 # It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
874 # @ingroup l3_algos_proj
875 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
877 ## name of the dynamic method in smeshBuilder.Mesh class
879 meshMethod = "Projection3D"
880 ## type of algorithm used with helper function in smeshBuilder.Mesh class
882 algoType = "Projection_3D"
883 ## doc string of the method
885 docHelper = "Creates projection 3D algorithm for volumes"
887 ## Private constructor.
888 # @param mesh parent mesh object algorithm is assigned to
889 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
890 # if it is @c 0 (default), the algorithm is assigned to the main shape
891 def __init__(self, mesh, geom=0):
892 Mesh_Algorithm.__init__(self)
893 self.Create(mesh, geom, self.algoType)
896 ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
897 # the mesh pattern is taken, and, optionally, the association of vertices
898 # between the source and the target solid (to which a hipothesis is assigned)
899 # @param solid from where the mesh pattern is taken
900 # @param mesh from where the mesh pattern is taken (optional)
901 # @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
902 # @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
903 # to associate with \a srcV1 (optional)
904 # @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
905 # @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
906 # to associate with \a srcV2 (optional)
907 # @param UseExisting - if ==true - searches for the existing hypothesis created with
908 # the same parameters, else (default) - creates a new one
910 # Note: association vertices must belong to one edge of a solid
911 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
912 srcV2=0, tgtV2=0, UseExisting=0):
913 for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
914 from salome.smesh.smeshBuilder import AssureGeomPublished
915 AssureGeomPublished( self.mesh, geom )
916 hyp = self.Hypothesis("ProjectionSource3D",
917 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
919 # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
920 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
921 hyp.SetSource3DShape( solid )
922 from salome.smesh.smeshBuilder import Mesh
923 if isinstance(mesh, Mesh):
924 mesh = mesh.GetMesh()
926 hyp.SetSourceMesh( mesh )
927 if srcV1 and srcV2 and tgtV1 and tgtV2:
928 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
929 #elif srcV1 or srcV2 or tgtV1 or tgtV2:
932 pass # end of StdMeshersBuilder_Projection3D class
934 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
935 # depending on geometry
937 # It is created by calling smeshBuilder.Mesh.Prism(geom=0)
939 # @ingroup l3_algos_3dextr
940 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
942 ## name of the dynamic method in smeshBuilder.Mesh class
945 ## type of algorithm used with helper function in smeshBuilder.Mesh class
947 algoType = "Prism_3D"
948 ## doc string of the method
950 docHelper = "Creates prism 3D algorithm for volumes"
952 ## Private constructor.
953 # @param mesh parent mesh object algorithm is assigned to
954 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
955 # if it is @c 0 (default), the algorithm is assigned to the main shape
956 def __init__(self, mesh, geom=0):
957 Mesh_Algorithm.__init__(self)
962 from salome.geom import geomBuilder
963 nbSolids = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SOLID"] ))
964 nbShells = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SHELL"] ))
965 if nbSolids == 0 or nbSolids == nbShells:
966 self.Create(mesh, geom, "Prism_3D")
969 self.algoType = "RadialPrism_3D"
970 self.Create(mesh, geom, "RadialPrism_3D")
971 self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
976 ## Return 3D hypothesis holding the 1D one
977 def Get3DHypothesis(self):
978 if self.algoType != "RadialPrism_3D":
979 print "Prism_3D algorith doesn't support any hyposesis"
981 return self.distribHyp
983 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
984 # hypothesis. Returns the created hypothesis
985 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
986 if self.algoType != "RadialPrism_3D":
987 print "Prism_3D algorith doesn't support any hyposesis"
989 if not self.nbLayers is None:
990 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
991 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
992 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
993 self.mesh.smeshpyD.SetCurrentStudy( None )
994 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
995 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
996 if not self.distribHyp:
997 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
998 self.distribHyp.SetLayerDistribution( hyp )
1001 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1002 # prisms to build between the inner and outer shells
1003 # @param n number of layers
1004 # @param UseExisting if ==true - searches for the existing hypothesis created with
1005 # the same parameters, else (default) - creates a new one
1006 def NumberOfLayers(self, n, UseExisting=0):
1007 if self.algoType != "RadialPrism_3D":
1008 print "Prism_3D algorith doesn't support any hyposesis"
1010 self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1011 from salome.smesh.smeshBuilder import IsEqual
1012 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1013 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1014 CompareMethod=compFun)
1015 self.nbLayers.SetNumberOfLayers( n )
1016 return self.nbLayers
1018 ## Defines "LocalLength" hypothesis, specifying the segment length
1019 # to build between the inner and the outer shells
1020 # @param l the length of segments
1021 # @param p the precision of rounding
1022 def LocalLength(self, l, p=1e-07):
1023 if self.algoType != "RadialPrism_3D":
1024 print "Prism_3D algorith doesn't support any hyposesis"
1026 hyp = self.OwnHypothesis("LocalLength", [l,p])
1031 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1032 # prisms to build between the inner and the outer shells.
1033 # @param n the number of layers
1034 # @param s the scale factor (optional)
1035 def NumberOfSegments(self, n, s=[]):
1036 if self.algoType != "RadialPrism_3D":
1037 print "Prism_3D algorith doesn't support any hyposesis"
1040 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1042 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1043 hyp.SetScaleFactor(s)
1044 hyp.SetNumberOfSegments(n)
1047 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1048 # to build between the inner and the outer shells with a length that changes
1049 # in arithmetic progression
1050 # @param start the length of the first segment
1051 # @param end the length of the last segment
1052 def Arithmetic1D(self, start, end ):
1053 if self.algoType != "RadialPrism_3D":
1054 print "Prism_3D algorith doesn't support any hyposesis"
1056 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1057 hyp.SetLength(start, 1)
1058 hyp.SetLength(end , 0)
1061 ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1062 # to build between the inner and the outer shells with a length that changes
1063 # in Geometric progression
1064 # @param start the length of the first segment
1065 # @param ratio the common ratio of the geometric progression
1066 def GeometricProgression(self, start, ratio ):
1067 if self.algoType != "RadialPrism_3D":
1068 print "Prism_3D algorith doesn't support any hyposesis"
1070 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1071 hyp.SetStartLength( start )
1072 hyp.SetCommonRatio( ratio )
1075 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1076 # to build between the inner and the outer shells as geometric length increasing
1077 # @param start for the length of the first segment
1078 # @param end for the length of the last segment
1079 def StartEndLength(self, start, end):
1080 if self.algoType != "RadialPrism_3D":
1081 print "Prism_3D algorith doesn't support any hyposesis"
1083 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1084 hyp.SetLength(start, 1)
1085 hyp.SetLength(end , 0)
1088 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1089 # to build between the inner and outer shells
1090 # @param fineness defines the quality of the mesh within the range [0-1]
1091 def AutomaticLength(self, fineness=0):
1092 if self.algoType != "RadialPrism_3D":
1093 print "Prism_3D algorith doesn't support any hyposesis"
1095 hyp = self.OwnHypothesis("AutomaticLength")
1096 hyp.SetFineness( fineness )
1099 pass # end of StdMeshersBuilder_Prism3D class
1101 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
1102 # depending on geometry
1104 # It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1106 # @ingroup l3_algos_3dextr
1107 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1109 ## name of the dynamic method in smeshBuilder.Mesh class
1111 meshMethod = "Prism"
1112 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1114 algoType = "RadialPrism_3D"
1115 ## doc string of the method
1117 docHelper = "Creates Raial Prism 3D algorithm for volumes"
1119 ## Private constructor.
1120 # @param mesh parent mesh object algorithm is assigned to
1121 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1122 # if it is @c 0 (default), the algorithm is assigned to the main shape
1123 def __init__(self, mesh, geom=0):
1124 Mesh_Algorithm.__init__(self)
1129 self.Create(mesh, geom, "RadialPrism_3D")
1130 self.distribHyp = None
1131 self.nbLayers = None
1134 ## Defines a Radial Quadrangle 1D-2D algorithm
1136 # It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1138 # @ingroup l2_algos_radialq
1139 class StdMeshersBuilder_RadialQuadrangle1D2D(Mesh_Algorithm):
1141 ## name of the dynamic method in smeshBuilder.Mesh class
1143 meshMethod = "Quadrangle"
1144 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1146 algoType = RADIAL_QUAD
1147 ## doc string of the method
1149 docHelper = "Creates quadrangle 1D-2D algorithm for faces having a shape of disk or a disk segment"
1151 ## Private constructor.
1152 # @param mesh parent mesh object algorithm is assigned to
1153 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1154 # if it is @c 0 (default), the algorithm is assigned to the main shape
1155 def __init__(self, mesh, geom=0):
1156 Mesh_Algorithm.__init__(self)
1157 self.Create(mesh, geom, self.algoType)
1159 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1160 self.nbLayers = None
1163 ## Return 2D hypothesis holding the 1D one
1164 def Get2DHypothesis(self):
1165 if not self.distribHyp:
1166 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1167 return self.distribHyp
1169 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
1170 # hypothesis. Returns the created hypothesis
1171 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1173 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1174 if self.distribHyp is None:
1175 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1177 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1178 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
1179 self.mesh.smeshpyD.SetCurrentStudy( None )
1180 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1181 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
1182 self.distribHyp.SetLayerDistribution( hyp )
1185 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
1186 # @param n number of layers
1187 # @param UseExisting if ==true - searches for the existing hypothesis created with
1188 # the same parameters, else (default) - creates a new one
1189 def NumberOfLayers(self, n, UseExisting=0):
1191 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1192 from salome.smesh.smeshBuilder import IsEqual
1193 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1194 self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1195 CompareMethod=compFun)
1196 self.nbLayers.SetNumberOfLayers( n )
1197 return self.nbLayers
1199 ## Defines "LocalLength" hypothesis, specifying the segment length
1200 # @param l the length of segments
1201 # @param p the precision of rounding
1202 def LocalLength(self, l, p=1e-07):
1203 hyp = self.OwnHypothesis("LocalLength", [l,p])
1208 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
1209 # @param n the number of layers
1210 # @param s the scale factor (optional)
1211 def NumberOfSegments(self, n, s=[]):
1213 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1215 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1216 hyp.SetDistrType( 1 )
1217 hyp.SetScaleFactor(s)
1218 hyp.SetNumberOfSegments(n)
1221 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1222 # with a length that changes in arithmetic progression
1223 # @param start the length of the first segment
1224 # @param end the length of the last segment
1225 def Arithmetic1D(self, start, end ):
1226 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1227 hyp.SetLength(start, 1)
1228 hyp.SetLength(end , 0)
1231 ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1232 # with a length that changes in Geometric progression
1233 # @param start the length of the first segment
1234 # @param ratio the common ratio of the geometric progression
1235 def GeometricProgression(self, start, ratio ):
1236 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1237 hyp.SetStartLength( start )
1238 hyp.SetCommonRatio( ratio )
1241 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1242 # as geometric length increasing
1243 # @param start for the length of the first segment
1244 # @param end for the length of the last segment
1245 def StartEndLength(self, start, end):
1246 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1247 hyp.SetLength(start, 1)
1248 hyp.SetLength(end , 0)
1251 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1252 # @param fineness defines the quality of the mesh within the range [0-1]
1253 def AutomaticLength(self, fineness=0):
1254 hyp = self.OwnHypothesis("AutomaticLength")
1255 hyp.SetFineness( fineness )
1258 pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1260 ## Defines a Quadrangle (Medial Axis Projection) 1D-2D algorithm
1262 # It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.QUAD_MA_PROJ,geom=0)
1264 # @ingroup l2_algos_quad_ma
1265 class StdMeshersBuilder_QuadMA_1D2D(Mesh_Algorithm):
1267 ## name of the dynamic method in smeshBuilder.Mesh class
1269 meshMethod = "Quadrangle"
1270 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1272 algoType = QUAD_MA_PROJ
1273 ## doc string of the method
1275 docHelper = "Creates quadrangle 1D-2D algorithm for faces"
1277 ## Private constructor.
1278 # @param mesh parent mesh object algorithm is assigned to
1279 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1280 # if it is @c 0 (default), the algorithm is assigned to the main shape
1281 def __init__(self, mesh, geom=0):
1282 Mesh_Algorithm.__init__(self)
1283 self.Create(mesh, geom, self.algoType)
1289 ## Defines a Use Existing Elements 1D algorithm
1291 # It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1293 # @ingroup l3_algos_basic
1294 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1296 ## name of the dynamic method in smeshBuilder.Mesh class
1298 meshMethod = "UseExisting1DElements"
1299 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1301 algoType = "Import_1D"
1302 ## flag pointing either this algorithm should be used by default in dynamic method
1303 # of smeshBuilder.Mesh class
1306 ## doc string of the method
1308 docHelper = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1310 ## Private constructor.
1311 # @param mesh parent mesh object algorithm is assigned to
1312 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1313 # if it is @c 0 (default), the algorithm is assigned to the main shape
1314 def __init__(self, mesh, geom=0):
1315 Mesh_Algorithm.__init__(self)
1316 self.Create(mesh, geom, self.algoType)
1319 ## Defines "Source edges" hypothesis, specifying groups of edges to import
1320 # @param groups list of groups of edges
1321 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1322 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1323 # @param UseExisting if ==true - searches for the existing hypothesis created with
1324 # the same parameters, else (default) - creates a new one
1325 def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1326 for group in groups:
1327 from salome.smesh.smeshBuilder import AssureGeomPublished
1328 AssureGeomPublished( self.mesh, group )
1329 compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1330 hyp.GetCopySourceMesh() == args[1], args[2] )
1331 hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1332 UseExisting=UseExisting, CompareMethod=compFun)
1333 hyp.SetSourceEdges(groups)
1334 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1337 pass # end of StdMeshersBuilder_UseExistingElements_1D class
1339 ## Defines a Use Existing Elements 1D-2D algorithm
1341 # It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1343 # @ingroup l3_algos_basic
1344 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1346 ## name of the dynamic method in smeshBuilder.Mesh class
1348 meshMethod = "UseExisting2DElements"
1349 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1351 algoType = "Import_1D2D"
1352 ## flag pointing either this algorithm should be used by default in dynamic method
1353 # of smeshBuilder.Mesh class
1356 ## doc string of the method
1358 docHelper = "Creates 1D-2D algorithm for faces with reusing of existing mesh elements"
1360 ## Private constructor.
1361 # @param mesh parent mesh object algorithm is assigned to
1362 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1363 # if it is @c 0 (default), the algorithm is assigned to the main shape
1364 def __init__(self, mesh, geom=0):
1365 Mesh_Algorithm.__init__(self)
1366 self.Create(mesh, geom, self.algoType)
1369 ## Defines "Source faces" hypothesis, specifying groups of faces to import
1370 # @param groups list of groups of faces
1371 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1372 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1373 # @param UseExisting if ==true - searches for the existing hypothesis created with
1374 # the same parameters, else (default) - creates a new one
1375 def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1376 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1377 hyp.GetCopySourceMesh() == args[1], args[2] )
1378 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1379 UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1380 hyp.SetSourceFaces(groups)
1381 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1382 self.mesh.AddHypothesis(hyp, self.geom)
1385 pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1387 ## Defines a Body Fitting 3D algorithm
1389 # It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1391 # @ingroup l3_algos_basic
1392 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1394 ## name of the dynamic method in smeshBuilder.Mesh class
1396 meshMethod = "BodyFitted"
1397 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1399 algoType = "Cartesian_3D"
1400 ## flag pointing either this algorithm should be used by default in dynamic method
1401 # of smeshBuilder.Mesh class
1404 ## doc string of the method
1406 docHelper = "Creates Body Fitting 3D algorithm for volumes"
1408 ## Private constructor.
1409 # @param mesh parent mesh object algorithm is assigned to
1410 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1411 # if it is @c 0 (default), the algorithm is assigned to the main shape
1412 def __init__(self, mesh, geom=0):
1413 self.Create(mesh, geom, self.algoType)
1417 ## Defines "Body Fitting parameters" hypothesis
1418 # @param xGridDef is definition of the grid along the X asix.
1419 # It can be in either of two following forms:
1420 # - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1421 # - Functions f(t) defining grid spacing at each point on grid axis. If there are
1422 # several functions, they must be accompanied by relative coordinates of
1423 # points dividing the whole shape into ranges where the functions apply; points
1424 # coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1425 # function f(t) varies from 0.0 to 1.0 witin a shape range.
1427 # - "10.5" - defines a grid with a constant spacing
1428 # - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1429 # @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does.
1430 # @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does.
1431 # @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1432 # a polyhedron of size less than hexSize/sizeThreshold is not created.
1433 # @param implEdges enables implementation of geometrical edges into the mesh.
1434 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1436 compFun = lambda hyp, args: False
1437 self.hyp = self.Hypothesis("CartesianParameters3D",
1438 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1439 UseExisting=False, CompareMethod=compFun)
1440 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1441 self.mesh.AddHypothesis( self.hyp, self.geom )
1443 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1444 if not gridDef: raise ValueError, "Empty grid definition"
1445 if isinstance( gridDef, str ):
1446 self.hyp.SetGridSpacing( [gridDef], [], axis )
1447 elif isinstance( gridDef[0], str ):
1448 self.hyp.SetGridSpacing( gridDef, [], axis )
1449 elif isinstance( gridDef[0], int ) or \
1450 isinstance( gridDef[0], float ):
1451 self.hyp.SetGrid(gridDef, axis )
1453 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1454 self.hyp.SetSizeThreshold( sizeThreshold )
1455 self.hyp.SetToAddEdges( implEdges )
1458 ## Defines custom directions of axes of the grid
1459 # @param xAxis either SMESH.DirStruct or a vector, or 3 vector components
1460 # @param yAxis either SMESH.DirStruct or a vector, or 3 vector components
1461 # @param zAxis either SMESH.DirStruct or a vector, or 3 vector components
1462 def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1464 if hasattr( xAxis, "__getitem__" ):
1465 xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1466 elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1467 xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1468 if hasattr( yAxis, "__getitem__" ):
1469 yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1470 elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1471 yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1472 if hasattr( zAxis, "__getitem__" ):
1473 zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1474 elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1475 zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1477 self.hyp = self.Hypothesis("CartesianParameters3D")
1478 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1479 self.mesh.AddHypothesis( self.hyp, self.geom )
1480 self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1483 ## Automatically defines directions of axes of the grid at which
1484 # a number of generated hexahedra is maximal
1485 # @param isOrthogonal defines whether the axes mush be orthogonal
1486 def SetOptimalAxesDirs(self, isOrthogonal=True):
1488 self.hyp = self.Hypothesis("CartesianParameters3D")
1489 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1490 self.mesh.AddHypothesis( self.hyp, self.geom )
1491 x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1492 self.hyp.SetAxesDirs( x,y,z )
1495 ## Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1496 # through the fixed point in each direction at which the grid is defined
1498 # @param p coordinates of the fixed point. Either SMESH.PointStruct or
1499 # a vertex or 3 components of coordinates.
1500 # @param toUnset defines whether the fixed point is defined or removed.
1501 def SetFixedPoint( self, p, toUnset=False ):
1504 if not self.hyp: return
1505 p = SMESH.PointStruct(0,0,0)
1506 elif hasattr( p, "__getitem__" ):
1507 p = SMESH.PointStruct( p[0],p[1],p[2] )
1508 elif isinstance( p, GEOM._objref_GEOM_Object ):
1509 p = self.mesh.smeshpyD.GetPointStruct( p )
1511 self.hyp = self.Hypothesis("CartesianParameters3D")
1512 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1513 self.mesh.AddHypothesis( self.hyp, self.geom )
1514 self.hyp.SetFixedPoint( p, toUnset )
1518 pass # end of StdMeshersBuilder_Cartesian_3D class
1520 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1521 # segments usable by 2D algoritms
1523 # It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1525 # @ingroup l3_algos_basic
1526 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1528 ## name of the dynamic method in smeshBuilder.Mesh class
1530 meshMethod = "UseExistingSegments"
1531 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1533 algoType = "UseExisting_1D"
1534 ## doc string of the method
1536 docHelper = "Creates 1D algorithm allowing batch meshing of edges"
1538 ## Private constructor.
1539 # @param mesh parent mesh object algorithm is assigned to
1540 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1541 # if it is @c 0 (default), the algorithm is assigned to the main shape
1542 def __init__(self, mesh, geom=0):
1543 self.Create(mesh, geom, self.algoType)
1546 pass # end of StdMeshersBuilder_UseExisting_1D class
1548 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1549 # faces usable by 3D algoritms
1551 # It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1553 # @ingroup l3_algos_basic
1554 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1556 ## name of the dynamic method in smeshBuilder.Mesh class
1558 meshMethod = "UseExistingFaces"
1559 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1561 algoType = "UseExisting_2D"
1562 ## doc string of the method
1564 docHelper = "Creates 2D algorithm allowing batch meshing of faces"
1566 ## Private constructor.
1567 # @param mesh parent mesh object algorithm is assigned to
1568 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1569 # if it is @c 0 (default), the algorithm is assigned to the main shape
1570 def __init__(self, mesh, geom=0):
1571 self.Create(mesh, geom, self.algoType)
1574 pass # end of StdMeshersBuilder_UseExisting_2D class