1 # Copyright (C) 2007-2014 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"
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 grading defines how much size of adjacent elements can differ
187 # @param UseExisting if ==true - searches for an existing hypothesis created with
188 # the same parameters, else (default) - creates a new one
189 # @return an instance of StdMeshers_Adaptive1D hypothesis
190 # @ingroup l3_hypos_1dhyps
191 def Adaptive(self, minSize, maxSize, deflection, grading, UseExisting=False):
192 from salome.smesh.smeshBuilder import IsEqual
193 compFun = lambda hyp, args: ( IsEqual(hyp.GetMinSize(), args[0]) and \
194 IsEqual(hyp.GetMaxSize(), args[1]) and \
195 IsEqual(hyp.GetDeflection(), args[2]) and \
196 IsEqual(hyp.GetGrading(), args[3]))
197 hyp = self.Hypothesis("Adaptive1D", [minSize, maxSize, deflection, grading],
198 UseExisting=UseExisting, CompareMethod=compFun)
199 hyp.SetMinSize(minSize)
200 hyp.SetMaxSize(maxSize)
201 hyp.SetDeflection(deflection)
202 hyp.SetGrading(grading)
205 ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with a length
206 # that changes in arithmetic progression
207 # @param start defines the length of the first segment
208 # @param end defines the length of the last segment
209 # @param reversedEdges is a list of edges to mesh using reversed orientation.
210 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
211 # @param UseExisting if ==true - searches for an existing hypothesis created with
212 # the same parameters, else (default) - creates a new one
213 # @return an instance of StdMeshers_Arithmetic1D hypothesis
214 # @ingroup l3_hypos_1dhyps
215 def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
216 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
217 reversedEdges, UseExisting = [], reversedEdges
218 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
219 entry = self.MainShapeEntry()
220 from salome.smesh.smeshBuilder import IsEqual
221 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
222 IsEqual(hyp.GetLength(0), args[1]) and \
223 hyp.GetReversedEdges() == args[2] and \
224 (not args[2] or hyp.GetObjectEntry() == args[3]))
225 hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
226 UseExisting=UseExisting, CompareMethod=compFun)
227 hyp.SetStartLength(start)
228 hyp.SetEndLength(end)
229 hyp.SetReversedEdges( reversedEdgeInd )
230 hyp.SetObjectEntry( entry )
233 ## Defines "GeometricProgression" hypothesis to cut an edge in several
234 # segments with a length that changes in Geometric progression
235 # @param start defines the length of the first segment
236 # @param ratio defines the common ratio of the geometric progression
237 # @param reversedEdges is a list of edges to mesh using reversed orientation.
238 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
239 # @param UseExisting if ==true - searches for an existing hypothesis created with
240 # the same parameters, else (default) - creates a new one
241 # @return an instance of StdMeshers_Geometric1D hypothesis
242 # @ingroup l3_hypos_1dhyps
243 def GeometricProgression(self, start, ratio, reversedEdges=[], UseExisting=0):
244 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
245 entry = self.MainShapeEntry()
246 from salome.smesh.smeshBuilder import IsEqual
247 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
248 IsEqual(hyp.GetLength(0), args[1]) and \
249 hyp.GetReversedEdges() == args[2] and \
250 (not args[2] or hyp.GetObjectEntry() == args[3]))
251 hyp = self.Hypothesis("GeometricProgression", [start, ratio, reversedEdgeInd, entry],
252 UseExisting=UseExisting, CompareMethod=compFun)
253 hyp.SetStartLength( start )
254 hyp.SetCommonRatio( ratio )
255 hyp.SetReversedEdges( reversedEdgeInd )
256 hyp.SetObjectEntry( entry )
259 ## Defines "FixedPoints1D" hypothesis to cut an edge using parameter
260 # on curve from 0 to 1 (additionally it is neecessary to check
261 # orientation of edges and create list of reversed edges if it is
262 # needed) and sets numbers of segments between given points (default
263 # values are equals 1
264 # @param points defines the list of parameters on curve
265 # @param nbSegs defines the list of numbers of segments
266 # @param reversedEdges is a list of edges to mesh using reversed orientation.
267 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
268 # @param UseExisting if ==true - searches for an existing hypothesis created with
269 # the same parameters, else (default) - creates a new one
270 # @return an instance of StdMeshers_FixedPoints1D hypothesis
271 # @ingroup l3_hypos_1dhyps
272 def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
273 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
274 reversedEdges, UseExisting = [], reversedEdges
275 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
276 entry = self.MainShapeEntry()
277 compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
278 hyp.GetNbSegments() == args[1] and \
279 hyp.GetReversedEdges() == args[2] and \
280 (not args[2] or hyp.GetObjectEntry() == args[3]))
281 hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
282 UseExisting=UseExisting, CompareMethod=compFun)
283 hyp.SetPoints(points)
284 hyp.SetNbSegments(nbSegs)
285 hyp.SetReversedEdges(reversedEdgeInd)
286 hyp.SetObjectEntry(entry)
289 ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
290 # @param start defines the length of the first segment
291 # @param end defines the length of the last segment
292 # @param reversedEdges is a list of edges to mesh using reversed orientation.
293 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
294 # @param UseExisting if ==true - searches for an existing hypothesis created with
295 # the same parameters, else (default) - creates a new one
296 # @return an instance of StdMeshers_StartEndLength hypothesis
297 # @ingroup l3_hypos_1dhyps
298 def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
299 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
300 reversedEdges, UseExisting = [], reversedEdges
301 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
302 entry = self.MainShapeEntry()
303 from salome.smesh.smeshBuilder import IsEqual
304 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
305 IsEqual(hyp.GetLength(0), args[1]) and \
306 hyp.GetReversedEdges() == args[2] and \
307 (not args[2] or hyp.GetObjectEntry() == args[3]))
308 hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
309 UseExisting=UseExisting, CompareMethod=compFun)
310 hyp.SetStartLength(start)
311 hyp.SetEndLength(end)
312 hyp.SetReversedEdges( reversedEdgeInd )
313 hyp.SetObjectEntry( entry )
316 ## Defines "Deflection1D" hypothesis
317 # @param d for the deflection
318 # @param UseExisting if ==true - searches for an existing hypothesis created with
319 # the same parameters, else (default) - create a new one
320 # @ingroup l3_hypos_1dhyps
321 def Deflection1D(self, d, UseExisting=0):
322 from salome.smesh.smeshBuilder import IsEqual
323 compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
324 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
328 ## Defines "Propagation" hypothesis that propagates 1D hypotheses
329 # from an edge where this hypothesis is assigned to
330 # on all other edges that are at the opposite side in case of quadrangular faces
331 # This hypothesis should be assigned to an edge to propagate a hypothesis from.
332 # @ingroup l3_hypos_additi
333 def Propagation(self):
334 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
336 ## Defines "Propagation of Node Distribution" hypothesis that propagates
337 # distribution of nodes from an edge where this hypothesis is assigned to,
338 # to opposite edges of quadrangular faces, so that number of segments on all these
339 # edges will be the same, as well as relations between segment lengths.
340 # @ingroup l3_hypos_additi
341 def PropagationOfDistribution(self):
342 return self.Hypothesis("PropagOfDistribution", UseExisting=1,
343 CompareMethod=self.CompareEqualHyp)
345 ## Defines "AutomaticLength" hypothesis
346 # @param fineness for the fineness [0-1]
347 # @param UseExisting if ==true - searches for an existing hypothesis created with the
348 # same parameters, else (default) - create a new one
349 # @ingroup l3_hypos_1dhyps
350 def AutomaticLength(self, fineness=0, UseExisting=0):
351 from salome.smesh.smeshBuilder import IsEqual
352 compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
353 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
354 CompareMethod=compFun)
355 hyp.SetFineness( fineness )
358 ## Defines "SegmentLengthAroundVertex" hypothesis
359 # @param length for the segment length
360 # @param vertex for the length localization: the vertex index [0,1] | vertex object.
361 # Any other integer value means that the hypothesis will be set on the
362 # whole 1D shape, where Mesh_Segment algorithm is assigned.
363 # @param UseExisting if ==true - searches for an existing hypothesis created with
364 # the same parameters, else (default) - creates a new one
365 # @ingroup l3_algos_segmarv
366 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
368 store_geom = self.geom
369 if type(vertex) is types.IntType:
370 if vertex == 0 or vertex == 1:
371 from salome.geom import geomBuilder
372 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geomBuilder.geomBuilder.ShapeType["VERTEX"],True)[vertex]
380 if self.geom is None:
381 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
382 from salome.smesh.smeshBuilder import AssureGeomPublished, GetName, TreatHypoStatus
383 AssureGeomPublished( self.mesh, self.geom )
384 name = GetName(self.geom)
386 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
388 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
390 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
391 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
393 from salome.smesh.smeshBuilder import IsEqual
394 comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
395 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
396 CompareMethod=comFun)
397 self.geom = store_geom
398 hyp.SetLength( length )
401 ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
402 # If the 2D mesher sees that all boundary edges are quadratic,
403 # it generates quadratic faces, else it generates linear faces using
404 # medium nodes as if they are vertices.
405 # The 3D mesher generates quadratic volumes only if all boundary faces
406 # are quadratic, else it fails.
408 # @ingroup l3_hypos_additi
409 def QuadraticMesh(self):
410 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
413 pass # end of StdMeshersBuilder_Segment class
415 ## Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
417 # It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.COMPOSITE,geom=0)
419 # @ingroup l3_algos_basic
420 class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
422 ## name of the dynamic method in smeshBuilder.Mesh class
424 meshMethod = "Segment"
425 ## type of algorithm used with helper function in smeshBuilder.Mesh class
428 ## flag pointing either this algorithm should be used by default in dynamic method
429 # of smeshBuilder.Mesh class
432 ## doc string of the method
434 docHelper = "Creates segment 1D algorithm for edges"
436 ## Private constructor.
437 # @param mesh parent mesh object algorithm is assigned to
438 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
439 # if it is @c 0 (default), the algorithm is assigned to the main shape
440 def __init__(self, mesh, geom=0):
441 self.Create(mesh, geom, self.algoType)
444 pass # end of StdMeshersBuilder_CompositeSegment class
446 ## Defines a segment 1D algorithm for discretization of edges with Python function
448 # It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.PYTHON,geom=0)
450 # @ingroup l3_algos_basic
451 class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
453 ## name of the dynamic method in smeshBuilder.Mesh class
455 meshMethod = "Segment"
456 ## type of algorithm used with helper function in smeshBuilder.Mesh class
459 ## doc string of the method
461 docHelper = "Creates tetrahedron 3D algorithm for solids"
462 ## doc string of the method
464 docHelper = "Creates segment 1D algorithm for edges"
466 ## Private constructor.
467 # @param mesh parent mesh object algorithm is assigned to
468 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
469 # if it is @c 0 (default), the algorithm is assigned to the main shape
470 def __init__(self, mesh, geom=0):
471 import Python1dPlugin
472 self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
475 ## Defines "PythonSplit1D" hypothesis
476 # @param n for the number of segments that cut an edge
477 # @param func for the python function that calculates the length of all segments
478 # @param UseExisting if ==true - searches for the existing hypothesis created with
479 # the same parameters, else (default) - creates a new one
480 # @ingroup l3_hypos_1dhyps
481 def PythonSplit1D(self, n, func, UseExisting=0):
482 compFun = lambda hyp, args: False
483 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
484 UseExisting=UseExisting, CompareMethod=compFun)
485 hyp.SetNumberOfSegments(n)
486 hyp.SetPythonLog10RatioFunction(func)
489 pass # end of StdMeshersBuilder_Segment_Python class
491 ## Triangle MEFISTO 2D algorithm
493 # It is created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MEFISTO,geom=0)
495 # @ingroup l3_algos_basic
496 class StdMeshersBuilder_Triangle_MEFISTO(Mesh_Algorithm):
498 ## name of the dynamic method in smeshBuilder.Mesh class
500 meshMethod = "Triangle"
501 ## type of algorithm used with helper function in smeshBuilder.Mesh class
504 ## flag pointing either this algorithm should be used by default in dynamic method
505 # of smeshBuilder.Mesh class
508 ## doc string of the method
510 docHelper = "Creates triangle 2D algorithm for faces"
512 ## Private constructor.
513 # @param mesh parent mesh object algorithm is assigned to
514 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
515 # if it is @c 0 (default), the algorithm is assigned to the main shape
516 def __init__(self, mesh, geom=0):
517 Mesh_Algorithm.__init__(self)
518 self.Create(mesh, geom, self.algoType)
521 ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
522 # @param area for the maximum area of each triangle
523 # @param UseExisting if ==true - searches for an existing hypothesis created with the
524 # same parameters, else (default) - creates a new one
526 # @ingroup l3_hypos_2dhyps
527 def MaxElementArea(self, area, UseExisting=0):
528 from salome.smesh.smeshBuilder import IsEqual
529 comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
530 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
531 CompareMethod=comparator)
532 hyp.SetMaxElementArea(area)
535 ## Defines "LengthFromEdges" hypothesis to build triangles
536 # based on the length of the edges taken from the wire
538 # @ingroup l3_hypos_2dhyps
539 def LengthFromEdges(self):
540 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
543 pass # end of StdMeshersBuilder_Triangle_MEFISTO class
545 ## Defines a quadrangle 2D algorithm
547 # It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
549 # @ingroup l3_algos_basic
550 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
552 ## name of the dynamic method in smeshBuilder.Mesh class
554 meshMethod = "Quadrangle"
555 ## type of algorithm used with helper function in smeshBuilder.Mesh class
557 algoType = QUADRANGLE
558 ## flag pointing either this algorithm should be used by default in dynamic method
559 # of smeshBuilder.Mesh class
562 ## doc string of the method
564 docHelper = "Creates quadrangle 2D algorithm for faces"
565 ## hypothesis associated with algorithm
569 ## Private constructor.
570 # @param mesh parent mesh object algorithm is assigned to
571 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
572 # if it is @c 0 (default), the algorithm is assigned to the main shape
573 def __init__(self, mesh, geom=0):
574 Mesh_Algorithm.__init__(self)
575 self.Create(mesh, geom, self.algoType)
578 ## Defines "QuadrangleParameters" hypothesis
579 # @param quadType defines the algorithm of transition between differently descretized
580 # sides of a geometrical face:
581 # - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
582 # area along the finer meshed sides.
583 # - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
584 # finer meshed sides.
585 # - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
586 # the finer meshed sides, iff the total quantity of segments on
587 # all four sides of the face is even (divisible by 2).
588 # - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
589 # area is located along the coarser meshed sides.
590 # - QUAD_REDUCED - only quadrangles are built and the transition between the sides
591 # is made gradually, layer by layer. This type has a limitation on
592 # the number of segments: one pair of opposite sides must have the
593 # same number of segments, the other pair must have an even difference
594 # between the numbers of segments on the sides.
595 # @param triangleVertex: vertex of a trilateral geometrical face, around which triangles
596 # will be created while other elements will be quadrangles.
597 # Vertex can be either a GEOM_Object or a vertex ID within the
599 # @param enfVertices: list of shapes defining positions where nodes (enforced nodes)
600 # must be created by the mesher. Shapes can be of any type,
601 # vertices of given shapes define positions of enforced nodes.
602 # Only vertices successfully projected to the face are used.
603 # @param enfPoints: list of points giving positions of enforced nodes.
604 # Point can be defined either as SMESH.PointStruct's
605 # ([SMESH.PointStruct(x1,y1,z1), SMESH.PointStruct(x2,y2,z2),...])
606 # or triples of values ([[x1,y1,z1], [x2,y2,z2], ...]).
607 # In the case if the defined QuadrangleParameters() refer to a sole face,
608 # all given points must lie on this face, else the mesher fails.
609 # @param UseExisting: if \c True - searches for the existing hypothesis created with
610 # the same parameters, else (default) - creates a new one
611 # @ingroup l3_hypos_quad
612 def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0,
613 enfVertices=[],enfPoints=[],UseExisting=0):
615 vertexID = triangleVertex
616 if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
617 vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
618 if isinstance( enfVertices, int ) and not enfPoints and not UseExisting:
619 # a call of old syntax, before inserting enfVertices and enfPoints before UseExisting
620 UseExisting, enfVertices = enfVertices, []
621 pStructs, xyz = [], []
623 if isinstance( p, SMESH.PointStruct ):
624 xyz.append(( p.x, p.y, p.z ))
627 xyz.append(( p[0], p[1], p[2] ))
628 pStructs.append( SMESH.PointStruct( p[0], p[1], p[2] ))
630 compFun = lambda hyp,args: \
631 hyp.GetQuadType() == args[0] and \
632 (hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1)) and \
633 ((hyp.GetEnforcedNodes()) == (args[2],args[3])) # True w/o enfVertices only
634 entries = [ shape.GetStudyEntry() for shape in enfVertices ]
635 self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID,entries,xyz],
636 UseExisting = UseExisting, CompareMethod=compFun)
638 if self.params.GetQuadType() != quadType:
639 self.params.SetQuadType(quadType)
641 self.params.SetTriaVertex( vertexID )
642 from salome.smesh.smeshBuilder import AssureGeomPublished
643 for v in enfVertices:
644 AssureGeomPublished( self.mesh, v )
645 self.params.SetEnforcedNodes( enfVertices, pStructs )
648 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
649 # quadrangles are built in the transition area along the finer meshed sides,
650 # iff the total quantity of segments on all four sides of the face is even.
651 # @param reversed if True, transition area is located along the coarser meshed sides.
652 # @param UseExisting: if ==true - searches for the existing hypothesis created with
653 # the same parameters, else (default) - creates a new one
654 # @ingroup l3_hypos_quad
655 def QuadranglePreference(self, reversed=False, UseExisting=0):
657 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
658 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
660 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
661 # triangles are built in the transition area along the finer meshed sides.
662 # @param UseExisting: if ==true - searches for the existing hypothesis created with
663 # the same parameters, else (default) - creates a new one
664 # @ingroup l3_hypos_quad
665 def TrianglePreference(self, UseExisting=0):
666 return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
668 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
669 # quadrangles are built and the transition between the sides is made gradually,
670 # layer by layer. This type has a limitation on the number of segments: one pair
671 # of opposite sides must have the same number of segments, the other pair must
672 # have an even difference between the numbers of segments on the sides.
673 # @param UseExisting: if ==true - searches for the existing hypothesis created with
674 # the same parameters, else (default) - creates a new one
675 # @ingroup l3_hypos_quad
676 def Reduced(self, UseExisting=0):
677 return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
679 ## Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
680 # @param vertex: vertex of a trilateral geometrical face, around which triangles
681 # will be created while other elements will be quadrangles.
682 # Vertex can be either a GEOM_Object or a vertex ID within the
684 # @param UseExisting: if ==true - searches for the existing hypothesis created with
685 # the same parameters, else (default) - creates a new one
686 # @ingroup l3_hypos_quad
687 def TriangleVertex(self, vertex, UseExisting=0):
688 return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
690 pass # end of StdMeshersBuilder_Quadrangle class
692 ## Defines a hexahedron 3D algorithm
694 # It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
696 # @ingroup l3_algos_basic
697 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
699 ## name of the dynamic method in smeshBuilder.Mesh class
701 meshMethod = "Hexahedron"
702 ## type of algorithm used with helper function in smeshBuilder.Mesh class
705 ## flag pointing either this algorithm should be used by default in dynamic method
706 # of smeshBuilder.Mesh class
709 ## doc string of the method
711 docHelper = "Creates hexahedron 3D algorithm for volumes"
713 ## Private constructor.
714 # @param mesh parent mesh object algorithm is assigned to
715 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
716 # if it is @c 0 (default), the algorithm is assigned to the main shape
717 def __init__(self, mesh, geom=0):
718 Mesh_Algorithm.__init__(self)
719 self.Create(mesh, geom, Hexa)
722 pass # end of StdMeshersBuilder_Hexahedron class
724 ## Defines a projection 1D algorithm
726 # It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
728 # @ingroup l3_algos_proj
729 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
731 ## name of the dynamic method in smeshBuilder.Mesh class
733 meshMethod = "Projection1D"
734 ## type of algorithm used with helper function in smeshBuilder.Mesh class
736 algoType = "Projection_1D"
737 ## flag pointing either this algorithm should be used by default in dynamic method
738 # of smeshBuilder.Mesh class
741 ## doc string of the method
743 docHelper = "Creates projection 1D algorithm for edges"
745 ## Private constructor.
746 # @param mesh parent mesh object algorithm is assigned to
747 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
748 # if it is @c 0 (default), the algorithm is assigned to the main shape
749 def __init__(self, mesh, geom=0):
750 Mesh_Algorithm.__init__(self)
751 self.Create(mesh, geom, self.algoType)
754 ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
755 # a mesh pattern is taken, and, optionally, the association of vertices
756 # between the source edge and a target edge (to which a hypothesis is assigned)
757 # @param edge from which nodes distribution is taken
758 # @param mesh from which nodes distribution is taken (optional)
759 # @param srcV a vertex of \a edge to associate with \a tgtV (optional)
760 # @param tgtV a vertex of \a the edge to which the algorithm is assigned,
761 # to associate with \a srcV (optional)
762 # @param UseExisting if ==true - searches for the existing hypothesis created with
763 # the same parameters, else (default) - creates a new one
764 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
765 from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
766 AssureGeomPublished( self.mesh, edge )
767 AssureGeomPublished( self.mesh, srcV )
768 AssureGeomPublished( self.mesh, tgtV )
769 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
771 # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
772 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
773 hyp.SetSourceEdge( edge )
774 if not mesh is None and isinstance(mesh, Mesh):
775 mesh = mesh.GetMesh()
776 hyp.SetSourceMesh( mesh )
777 hyp.SetVertexAssociation( srcV, tgtV )
780 pass # end of StdMeshersBuilder_Projection1D class
782 ## Defines a projection 2D algorithm
784 # It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
786 # @ingroup l3_algos_proj
787 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
789 ## name of the dynamic method in smeshBuilder.Mesh class
791 meshMethod = "Projection2D"
792 ## type of algorithm used with helper function in smeshBuilder.Mesh class
794 algoType = "Projection_2D"
795 ## flag pointing either this algorithm should be used by default in dynamic method
796 # of smeshBuilder.Mesh class
799 ## doc string of the method
801 docHelper = "Creates projection 2D algorithm for faces"
803 ## Private constructor.
804 # @param mesh parent mesh object algorithm is assigned to
805 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
806 # if it is @c 0 (default), the algorithm is assigned to the main shape
807 def __init__(self, mesh, geom=0):
808 Mesh_Algorithm.__init__(self)
809 self.Create(mesh, geom, self.algoType)
812 ## Defines "Source Face" hypothesis, specifying a meshed face, from where
813 # a mesh pattern is taken, and, optionally, the association of vertices
814 # between the source face and the target face (to which a hypothesis is assigned)
815 # @param face from which the mesh pattern is taken
816 # @param mesh from which the mesh pattern is taken (optional)
817 # @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
818 # @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
819 # to associate with \a srcV1 (optional)
820 # @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
821 # @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
822 # to associate with \a srcV2 (optional)
823 # @param UseExisting if ==true - forces the search for the existing hypothesis created with
824 # the same parameters, else (default) - forces the creation a new one
826 # Note: all association vertices must belong to one edge of a face
827 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
828 srcV2=None, tgtV2=None, UseExisting=0):
829 from salome.smesh.smeshBuilder import Mesh
830 if isinstance(mesh, Mesh):
831 mesh = mesh.GetMesh()
832 for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
833 from salome.smesh.smeshBuilder import AssureGeomPublished
834 AssureGeomPublished( self.mesh, geom )
835 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
837 # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
838 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
839 hyp.SetSourceFace( face )
840 hyp.SetSourceMesh( mesh )
841 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
844 pass # end of StdMeshersBuilder_Projection2D class
846 ## Defines a projection 1D-2D algorithm
848 # It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
850 # @ingroup l3_algos_proj
851 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
853 ## name of the dynamic method in smeshBuilder.Mesh class
855 meshMethod = "Projection1D2D"
856 ## type of algorithm used with helper function in smeshBuilder.Mesh class
858 algoType = "Projection_1D2D"
859 ## doc string of the method
861 docHelper = "Creates projection 1D-2D algorithm for edges and faces"
863 ## Private constructor.
864 # @param mesh parent mesh object algorithm is assigned to
865 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
866 # if it is @c 0 (default), the algorithm is assigned to the main shape
867 def __init__(self, mesh, geom=0):
868 StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
871 pass # end of StdMeshersBuilder_Projection1D2D class
873 ## Defines a projection 3D algorithm
875 # It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
877 # @ingroup l3_algos_proj
878 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
880 ## name of the dynamic method in smeshBuilder.Mesh class
882 meshMethod = "Projection3D"
883 ## type of algorithm used with helper function in smeshBuilder.Mesh class
885 algoType = "Projection_3D"
886 ## doc string of the method
888 docHelper = "Creates projection 3D algorithm for volumes"
890 ## Private constructor.
891 # @param mesh parent mesh object algorithm is assigned to
892 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
893 # if it is @c 0 (default), the algorithm is assigned to the main shape
894 def __init__(self, mesh, geom=0):
895 Mesh_Algorithm.__init__(self)
896 self.Create(mesh, geom, self.algoType)
899 ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
900 # the mesh pattern is taken, and, optionally, the association of vertices
901 # between the source and the target solid (to which a hipothesis is assigned)
902 # @param solid from where the mesh pattern is taken
903 # @param mesh from where the mesh pattern is taken (optional)
904 # @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
905 # @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
906 # to associate with \a srcV1 (optional)
907 # @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
908 # @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
909 # to associate with \a srcV2 (optional)
910 # @param UseExisting - if ==true - searches for the existing hypothesis created with
911 # the same parameters, else (default) - creates a new one
913 # Note: association vertices must belong to one edge of a solid
914 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
915 srcV2=0, tgtV2=0, UseExisting=0):
916 for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
917 from salome.smesh.smeshBuilder import AssureGeomPublished
918 AssureGeomPublished( self.mesh, geom )
919 hyp = self.Hypothesis("ProjectionSource3D",
920 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
922 # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
923 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
924 hyp.SetSource3DShape( solid )
925 from salome.smesh.smeshBuilder import Mesh
926 if isinstance(mesh, Mesh):
927 mesh = mesh.GetMesh()
929 hyp.SetSourceMesh( mesh )
930 if srcV1 and srcV2 and tgtV1 and tgtV2:
931 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
932 #elif srcV1 or srcV2 or tgtV1 or tgtV2:
935 pass # end of StdMeshersBuilder_Projection3D class
937 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
938 # depending on geometry
940 # It is created by calling smeshBuilder.Mesh.Prism(geom=0)
942 # @ingroup l3_algos_3dextr
943 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
945 ## name of the dynamic method in smeshBuilder.Mesh class
948 ## type of algorithm used with helper function in smeshBuilder.Mesh class
950 algoType = "Prism_3D"
951 ## doc string of the method
953 docHelper = "Creates prism 3D algorithm for volumes"
955 ## Private constructor.
956 # @param mesh parent mesh object algorithm is assigned to
957 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
958 # if it is @c 0 (default), the algorithm is assigned to the main shape
959 def __init__(self, mesh, geom=0):
960 Mesh_Algorithm.__init__(self)
965 from salome.geom import geomBuilder
966 nbSolids = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SOLID"] ))
967 nbShells = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SHELL"] ))
968 if nbSolids == 0 or nbSolids == nbShells:
969 self.Create(mesh, geom, "Prism_3D")
972 self.algoType = "RadialPrism_3D"
973 self.Create(mesh, geom, "RadialPrism_3D")
974 self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
979 ## Return 3D hypothesis holding the 1D one
980 def Get3DHypothesis(self):
981 if self.algoType != "RadialPrism_3D":
982 print "Prism_3D algorith doesn't support any hyposesis"
984 return self.distribHyp
986 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
987 # hypothesis. Returns the created hypothesis
988 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
989 if self.algoType != "RadialPrism_3D":
990 print "Prism_3D algorith doesn't support any hyposesis"
992 if not self.nbLayers is None:
993 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
994 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
995 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
996 self.mesh.smeshpyD.SetCurrentStudy( None )
997 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
998 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
999 if not self.distribHyp:
1000 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
1001 self.distribHyp.SetLayerDistribution( hyp )
1004 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1005 # prisms to build between the inner and outer shells
1006 # @param n number of layers
1007 # @param UseExisting if ==true - searches for the existing hypothesis created with
1008 # the same parameters, else (default) - creates a new one
1009 def NumberOfLayers(self, n, UseExisting=0):
1010 if self.algoType != "RadialPrism_3D":
1011 print "Prism_3D algorith doesn't support any hyposesis"
1013 self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1014 from salome.smesh.smeshBuilder import IsEqual
1015 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1016 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1017 CompareMethod=compFun)
1018 self.nbLayers.SetNumberOfLayers( n )
1019 return self.nbLayers
1021 ## Defines "LocalLength" hypothesis, specifying the segment length
1022 # to build between the inner and the outer shells
1023 # @param l the length of segments
1024 # @param p the precision of rounding
1025 def LocalLength(self, l, p=1e-07):
1026 if self.algoType != "RadialPrism_3D":
1027 print "Prism_3D algorith doesn't support any hyposesis"
1029 hyp = self.OwnHypothesis("LocalLength", [l,p])
1034 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1035 # prisms to build between the inner and the outer shells.
1036 # @param n the number of layers
1037 # @param s the scale factor (optional)
1038 def NumberOfSegments(self, n, s=[]):
1039 if self.algoType != "RadialPrism_3D":
1040 print "Prism_3D algorith doesn't support any hyposesis"
1043 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1045 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1046 hyp.SetDistrType( 1 )
1047 hyp.SetScaleFactor(s)
1048 hyp.SetNumberOfSegments(n)
1051 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1052 # to build between the inner and the outer shells with a length that changes
1053 # in arithmetic progression
1054 # @param start the length of the first segment
1055 # @param end the length of the last segment
1056 def Arithmetic1D(self, start, end ):
1057 if self.algoType != "RadialPrism_3D":
1058 print "Prism_3D algorith doesn't support any hyposesis"
1060 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1061 hyp.SetLength(start, 1)
1062 hyp.SetLength(end , 0)
1065 ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1066 # to build between the inner and the outer shells with a length that changes
1067 # in Geometric progression
1068 # @param start the length of the first segment
1069 # @param ratio the common ratio of the geometric progression
1070 def GeometricProgression(self, start, ratio ):
1071 if self.algoType != "RadialPrism_3D":
1072 print "Prism_3D algorith doesn't support any hyposesis"
1074 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1075 hyp.SetStartLength( start )
1076 hyp.SetCommonRatio( ratio )
1079 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1080 # to build between the inner and the outer shells as geometric length increasing
1081 # @param start for the length of the first segment
1082 # @param end for the length of the last segment
1083 def StartEndLength(self, start, end):
1084 if self.algoType != "RadialPrism_3D":
1085 print "Prism_3D algorith doesn't support any hyposesis"
1087 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1088 hyp.SetLength(start, 1)
1089 hyp.SetLength(end , 0)
1092 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1093 # to build between the inner and outer shells
1094 # @param fineness defines the quality of the mesh within the range [0-1]
1095 def AutomaticLength(self, fineness=0):
1096 if self.algoType != "RadialPrism_3D":
1097 print "Prism_3D algorith doesn't support any hyposesis"
1099 hyp = self.OwnHypothesis("AutomaticLength")
1100 hyp.SetFineness( fineness )
1103 pass # end of StdMeshersBuilder_Prism3D class
1105 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
1106 # depending on geometry
1108 # It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1110 # @ingroup l3_algos_3dextr
1111 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1113 ## name of the dynamic method in smeshBuilder.Mesh class
1115 meshMethod = "Prism"
1116 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1118 algoType = "RadialPrism_3D"
1119 ## doc string of the method
1121 docHelper = "Creates prism 3D algorithm for volumes"
1123 ## Private constructor.
1124 # @param mesh parent mesh object algorithm is assigned to
1125 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1126 # if it is @c 0 (default), the algorithm is assigned to the main shape
1127 def __init__(self, mesh, geom=0):
1128 Mesh_Algorithm.__init__(self)
1133 self.Create(mesh, geom, "RadialPrism_3D")
1134 self.distribHyp = None
1135 self.nbLayers = None
1138 ## Defines a Radial Quadrangle 1D-2D algorithm
1140 # It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1142 # @ingroup l2_algos_radialq
1143 class StdMeshersBuilder_RadialQuadrangle1D2D(Mesh_Algorithm):
1145 ## name of the dynamic method in smeshBuilder.Mesh class
1147 meshMethod = "Quadrangle"
1148 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1150 algoType = RADIAL_QUAD
1151 ## doc string of the method
1153 docHelper = "Creates quadrangle 1D-2D algorithm for triangular faces"
1155 ## Private constructor.
1156 # @param mesh parent mesh object algorithm is assigned to
1157 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1158 # if it is @c 0 (default), the algorithm is assigned to the main shape
1159 def __init__(self, mesh, geom=0):
1160 Mesh_Algorithm.__init__(self)
1161 self.Create(mesh, geom, self.algoType)
1163 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1164 self.nbLayers = None
1167 ## Return 2D hypothesis holding the 1D one
1168 def Get2DHypothesis(self):
1169 if not self.distribHyp:
1170 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1171 return self.distribHyp
1173 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
1174 # hypothesis. Returns the created hypothesis
1175 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1177 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1178 if self.distribHyp is None:
1179 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1181 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1182 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
1183 self.mesh.smeshpyD.SetCurrentStudy( None )
1184 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1185 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
1186 self.distribHyp.SetLayerDistribution( hyp )
1189 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
1190 # @param n number of layers
1191 # @param UseExisting if ==true - searches for the existing hypothesis created with
1192 # the same parameters, else (default) - creates a new one
1193 def NumberOfLayers(self, n, UseExisting=0):
1195 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1196 from salome.smesh.smeshBuilder import IsEqual
1197 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1198 self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1199 CompareMethod=compFun)
1200 self.nbLayers.SetNumberOfLayers( n )
1201 return self.nbLayers
1203 ## Defines "LocalLength" hypothesis, specifying the segment length
1204 # @param l the length of segments
1205 # @param p the precision of rounding
1206 def LocalLength(self, l, p=1e-07):
1207 hyp = self.OwnHypothesis("LocalLength", [l,p])
1212 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
1213 # @param n the number of layers
1214 # @param s the scale factor (optional)
1215 def NumberOfSegments(self, n, s=[]):
1217 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1219 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1220 hyp.SetDistrType( 1 )
1221 hyp.SetScaleFactor(s)
1222 hyp.SetNumberOfSegments(n)
1225 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1226 # with a length that changes in arithmetic progression
1227 # @param start the length of the first segment
1228 # @param end the length of the last segment
1229 def Arithmetic1D(self, start, end ):
1230 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1231 hyp.SetLength(start, 1)
1232 hyp.SetLength(end , 0)
1235 ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1236 # with a length that changes in Geometric progression
1237 # @param start the length of the first segment
1238 # @param ratio the common ratio of the geometric progression
1239 def GeometricProgression(self, start, ratio ):
1240 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1241 hyp.SetStartLength( start )
1242 hyp.SetCommonRatio( ratio )
1245 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1246 # as geometric length increasing
1247 # @param start for the length of the first segment
1248 # @param end for the length of the last segment
1249 def StartEndLength(self, start, end):
1250 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1251 hyp.SetLength(start, 1)
1252 hyp.SetLength(end , 0)
1255 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1256 # @param fineness defines the quality of the mesh within the range [0-1]
1257 def AutomaticLength(self, fineness=0):
1258 hyp = self.OwnHypothesis("AutomaticLength")
1259 hyp.SetFineness( fineness )
1262 pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1264 ## Defines a Use Existing Elements 1D algorithm
1266 # It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1268 # @ingroup l3_algos_basic
1269 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1271 ## name of the dynamic method in smeshBuilder.Mesh class
1273 meshMethod = "UseExisting1DElements"
1274 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1276 algoType = "Import_1D"
1277 ## flag pointing either this algorithm should be used by default in dynamic method
1278 # of smeshBuilder.Mesh class
1281 ## doc string of the method
1283 docHelper = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1285 ## Private constructor.
1286 # @param mesh parent mesh object algorithm is assigned to
1287 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1288 # if it is @c 0 (default), the algorithm is assigned to the main shape
1289 def __init__(self, mesh, geom=0):
1290 Mesh_Algorithm.__init__(self)
1291 self.Create(mesh, geom, self.algoType)
1294 ## Defines "Source edges" hypothesis, specifying groups of edges to import
1295 # @param groups list of groups of edges
1296 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1297 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1298 # @param UseExisting if ==true - searches for the existing hypothesis created with
1299 # the same parameters, else (default) - creates a new one
1300 def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1301 for group in groups:
1302 from salome.smesh.smeshBuilder import AssureGeomPublished
1303 AssureGeomPublished( self.mesh, group )
1304 compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1305 hyp.GetCopySourceMesh() == args[1], args[2] )
1306 hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1307 UseExisting=UseExisting, CompareMethod=compFun)
1308 hyp.SetSourceEdges(groups)
1309 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1312 pass # end of StdMeshersBuilder_UseExistingElements_1D class
1314 ## Defines a Use Existing Elements 1D-2D algorithm
1316 # It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1318 # @ingroup l3_algos_basic
1319 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1321 ## name of the dynamic method in smeshBuilder.Mesh class
1323 meshMethod = "UseExisting2DElements"
1324 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1326 algoType = "Import_1D2D"
1327 ## flag pointing either this algorithm should be used by default in dynamic method
1328 # of smeshBuilder.Mesh class
1331 ## doc string of the method
1333 docHelper = "Creates 1D-2D algorithm for edges/faces with reusing of existing mesh elements"
1335 ## Private constructor.
1336 # @param mesh parent mesh object algorithm is assigned to
1337 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1338 # if it is @c 0 (default), the algorithm is assigned to the main shape
1339 def __init__(self, mesh, geom=0):
1340 Mesh_Algorithm.__init__(self)
1341 self.Create(mesh, geom, self.algoType)
1344 ## Defines "Source faces" hypothesis, specifying groups of faces to import
1345 # @param groups list of groups of faces
1346 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1347 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1348 # @param UseExisting if ==true - searches for the existing hypothesis created with
1349 # the same parameters, else (default) - creates a new one
1350 def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1351 for group in groups:
1352 from salome.smesh.smeshBuilder import AssureGeomPublished
1353 AssureGeomPublished( self.mesh, group )
1354 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1355 hyp.GetCopySourceMesh() == args[1], args[2] )
1356 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1357 UseExisting=UseExisting, CompareMethod=compFun)
1358 hyp.SetSourceFaces(groups)
1359 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1362 pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1364 ## Defines a Body Fitting 3D algorithm
1366 # It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1368 # @ingroup l3_algos_basic
1369 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1371 ## name of the dynamic method in smeshBuilder.Mesh class
1373 meshMethod = "BodyFitted"
1374 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1376 algoType = "Cartesian_3D"
1377 ## flag pointing either this algorithm should be used by default in dynamic method
1378 # of smeshBuilder.Mesh class
1381 ## doc string of the method
1383 docHelper = "Creates body fitting 3D algorithm for volumes"
1385 ## Private constructor.
1386 # @param mesh parent mesh object algorithm is assigned to
1387 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1388 # if it is @c 0 (default), the algorithm is assigned to the main shape
1389 def __init__(self, mesh, geom=0):
1390 self.Create(mesh, geom, self.algoType)
1394 ## Defines "Body Fitting parameters" hypothesis
1395 # @param xGridDef is definition of the grid along the X asix.
1396 # It can be in either of two following forms:
1397 # - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1398 # - Functions f(t) defining grid spacing at each point on grid axis. If there are
1399 # several functions, they must be accompanied by relative coordinates of
1400 # points dividing the whole shape into ranges where the functions apply; points
1401 # coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1402 # function f(t) varies from 0.0 to 1.0 witin a shape range.
1404 # - "10.5" - defines a grid with a constant spacing
1405 # - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1406 # @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does.
1407 # @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does.
1408 # @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1409 # a polyhedron of size less than hexSize/sizeThreshold is not created.
1410 # @param implEdges enables implementation of geometrical edges into the mesh.
1411 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1413 compFun = lambda hyp, args: False
1414 self.hyp = self.Hypothesis("CartesianParameters3D",
1415 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1416 UseExisting=False, CompareMethod=compFun)
1417 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1418 self.mesh.AddHypothesis( self.hyp, self.geom )
1420 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1421 if not gridDef: raise ValueError, "Empty grid definition"
1422 if isinstance( gridDef, str ):
1423 self.hyp.SetGridSpacing( [gridDef], [], axis )
1424 elif isinstance( gridDef[0], str ):
1425 self.hyp.SetGridSpacing( gridDef, [], axis )
1426 elif isinstance( gridDef[0], int ) or \
1427 isinstance( gridDef[0], float ):
1428 self.hyp.SetGrid(gridDef, axis )
1430 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1431 self.hyp.SetSizeThreshold( sizeThreshold )
1432 self.hyp.SetToAddEdges( implEdges )
1435 ## Defines custom directions of axes of the grid
1436 # @param xAxis either SMESH.DirStruct or a vector, or 3 vector components
1437 # @param yAxis either SMESH.DirStruct or a vector, or 3 vector components
1438 # @param zAxis either SMESH.DirStruct or a vector, or 3 vector components
1439 def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1441 if hasattr( xAxis, "__getitem__" ):
1442 xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1443 elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1444 xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1445 if hasattr( yAxis, "__getitem__" ):
1446 yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1447 elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1448 yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1449 if hasattr( zAxis, "__getitem__" ):
1450 zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1451 elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1452 zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1454 self.hyp = self.Hypothesis("CartesianParameters3D")
1455 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1456 self.mesh.AddHypothesis( self.hyp, self.geom )
1457 self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1460 ## Automatically defines directions of axes of the grid at which
1461 # a number of generated hexahedra is maximal
1462 # @param isOrthogonal defines whether the axes mush be orthogonal
1463 def SetOptimalAxesDirs(self, isOrthogonal=True):
1465 self.hyp = self.Hypothesis("CartesianParameters3D")
1466 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1467 self.mesh.AddHypothesis( self.hyp, self.geom )
1468 x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1469 self.hyp.SetAxesDirs( x,y,z )
1472 ## Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1473 # through the fixed point in each direction at which the grid is defined
1475 # @param p coordinates of the fixed point. Either SMESH.PointStruct or
1476 # a vertex or 3 components of coordinates.
1477 # @param toUnset defines whether the fixed point is defined or removed.
1478 def SetFixedPoint( self, p, toUnset=False ):
1481 if not self.hyp: return
1482 p = SMESH.PointStruct(0,0,0)
1483 elif hasattr( p, "__getitem__" ):
1484 p = SMESH.PointStruct( p[0],p[1],p[2] )
1485 elif isinstance( p, GEOM._objref_GEOM_Object ):
1486 p = self.mesh.smeshpyD.GetPointStruct( p )
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 self.hyp.SetFixedPoint( p, toUnset )
1495 pass # end of StdMeshersBuilder_Cartesian_3D class
1497 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1498 # segments usable by 2D algoritms
1500 # It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1502 # @ingroup l3_algos_basic
1503 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1505 ## name of the dynamic method in smeshBuilder.Mesh class
1507 meshMethod = "UseExistingSegments"
1508 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1510 algoType = "UseExisting_1D"
1511 ## doc string of the method
1513 docHelper = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1515 ## Private constructor.
1516 # @param mesh parent mesh object algorithm is assigned to
1517 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1518 # if it is @c 0 (default), the algorithm is assigned to the main shape
1519 def __init__(self, mesh, geom=0):
1520 self.Create(mesh, geom, self.algoType)
1523 pass # end of StdMeshersBuilder_UseExisting_1D class
1525 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1526 # faces usable by 3D algoritms
1528 # It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1530 # @ingroup l3_algos_basic
1531 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1533 ## name of the dynamic method in smeshBuilder.Mesh class
1535 meshMethod = "UseExistingFaces"
1536 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1538 algoType = "UseExisting_2D"
1539 ## doc string of the method
1541 docHelper = "Creates 2D algorithm for faces with reusing of existing mesh elements"
1543 ## Private constructor.
1544 # @param mesh parent mesh object algorithm is assigned to
1545 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1546 # if it is @c 0 (default), the algorithm is assigned to the main shape
1547 def __init__(self, mesh, geom=0):
1548 self.Create(mesh, geom, self.algoType)
1551 pass # end of StdMeshersBuilder_UseExisting_2D class