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 UseExisting if ==true - searches for an existing hypothesis created with
187 # the same parameters, else (default) - creates a new one
188 # @return an instance of StdMeshers_Adaptive1D hypothesis
189 # @ingroup l3_hypos_1dhyps
190 def Adaptive(self, minSize, maxSize, deflection, UseExisting=False):
191 from salome.smesh.smeshBuilder import IsEqual
192 compFun = lambda hyp, args: ( IsEqual(hyp.GetMinSize(), args[0]) and \
193 IsEqual(hyp.GetMaxSize(), args[1]) and \
194 IsEqual(hyp.GetDeflection(), args[2]))
195 hyp = self.Hypothesis("Adaptive1D", [minSize, maxSize, deflection],
196 UseExisting=UseExisting, CompareMethod=compFun)
197 hyp.SetMinSize(minSize)
198 hyp.SetMaxSize(maxSize)
199 hyp.SetDeflection(deflection)
202 ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with a length
203 # that changes in arithmetic progression
204 # @param start defines the length of the first segment
205 # @param end defines the length of the last segment
206 # @param reversedEdges is a list of edges to mesh using reversed orientation.
207 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
208 # @param UseExisting if ==true - searches for an existing hypothesis created with
209 # the same parameters, else (default) - creates a new one
210 # @return an instance of StdMeshers_Arithmetic1D hypothesis
211 # @ingroup l3_hypos_1dhyps
212 def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
213 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
214 reversedEdges, UseExisting = [], reversedEdges
215 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
216 entry = self.MainShapeEntry()
217 from salome.smesh.smeshBuilder import IsEqual
218 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
219 IsEqual(hyp.GetLength(0), args[1]) and \
220 hyp.GetReversedEdges() == args[2] and \
221 (not args[2] or hyp.GetObjectEntry() == args[3]))
222 hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
223 UseExisting=UseExisting, CompareMethod=compFun)
224 hyp.SetStartLength(start)
225 hyp.SetEndLength(end)
226 hyp.SetReversedEdges( reversedEdgeInd )
227 hyp.SetObjectEntry( entry )
230 ## Defines "GeometricProgression" hypothesis to cut an edge in several
231 # segments with a length that changes in Geometric progression
232 # @param start defines the length of the first segment
233 # @param ratio defines the common ratio of the geometric progression
234 # @param reversedEdges is a list of edges to mesh using reversed orientation.
235 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
236 # @param UseExisting if ==true - searches for an existing hypothesis created with
237 # the same parameters, else (default) - creates a new one
238 # @return an instance of StdMeshers_Geometric1D hypothesis
239 # @ingroup l3_hypos_1dhyps
240 def GeometricProgression(self, start, ratio, reversedEdges=[], UseExisting=0):
241 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
242 entry = self.MainShapeEntry()
243 from salome.smesh.smeshBuilder import IsEqual
244 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
245 IsEqual(hyp.GetLength(0), args[1]) and \
246 hyp.GetReversedEdges() == args[2] and \
247 (not args[2] or hyp.GetObjectEntry() == args[3]))
248 hyp = self.Hypothesis("GeometricProgression", [start, ratio, reversedEdgeInd, entry],
249 UseExisting=UseExisting, CompareMethod=compFun)
250 hyp.SetStartLength( start )
251 hyp.SetCommonRatio( ratio )
252 hyp.SetReversedEdges( reversedEdgeInd )
253 hyp.SetObjectEntry( entry )
256 ## Defines "FixedPoints1D" hypothesis to cut an edge using parameter
257 # on curve from 0 to 1 (additionally it is neecessary to check
258 # orientation of edges and create list of reversed edges if it is
259 # needed) and sets numbers of segments between given points (default
260 # values are equals 1
261 # @param points defines the list of parameters on curve
262 # @param nbSegs defines the list of numbers of segments
263 # @param reversedEdges is a list of edges to mesh using reversed orientation.
264 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
265 # @param UseExisting if ==true - searches for an existing hypothesis created with
266 # the same parameters, else (default) - creates a new one
267 # @return an instance of StdMeshers_FixedPoints1D hypothesis
268 # @ingroup l3_hypos_1dhyps
269 def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
270 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
271 reversedEdges, UseExisting = [], reversedEdges
272 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
273 entry = self.MainShapeEntry()
274 compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
275 hyp.GetNbSegments() == args[1] and \
276 hyp.GetReversedEdges() == args[2] and \
277 (not args[2] or hyp.GetObjectEntry() == args[3]))
278 hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
279 UseExisting=UseExisting, CompareMethod=compFun)
280 hyp.SetPoints(points)
281 hyp.SetNbSegments(nbSegs)
282 hyp.SetReversedEdges(reversedEdgeInd)
283 hyp.SetObjectEntry(entry)
286 ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
287 # @param start defines the length of the first segment
288 # @param end defines the length of the last segment
289 # @param reversedEdges is a list of edges to mesh using reversed orientation.
290 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
291 # @param UseExisting if ==true - searches for an existing hypothesis created with
292 # the same parameters, else (default) - creates a new one
293 # @return an instance of StdMeshers_StartEndLength hypothesis
294 # @ingroup l3_hypos_1dhyps
295 def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
296 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
297 reversedEdges, UseExisting = [], reversedEdges
298 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
299 entry = self.MainShapeEntry()
300 from salome.smesh.smeshBuilder import IsEqual
301 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
302 IsEqual(hyp.GetLength(0), args[1]) and \
303 hyp.GetReversedEdges() == args[2] and \
304 (not args[2] or hyp.GetObjectEntry() == args[3]))
305 hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
306 UseExisting=UseExisting, CompareMethod=compFun)
307 hyp.SetStartLength(start)
308 hyp.SetEndLength(end)
309 hyp.SetReversedEdges( reversedEdgeInd )
310 hyp.SetObjectEntry( entry )
313 ## Defines "Deflection1D" hypothesis
314 # @param d for the deflection
315 # @param UseExisting if ==true - searches for an existing hypothesis created with
316 # the same parameters, else (default) - create a new one
317 # @ingroup l3_hypos_1dhyps
318 def Deflection1D(self, d, UseExisting=0):
319 from salome.smesh.smeshBuilder import IsEqual
320 compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
321 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
325 ## Defines "Propagation" hypothesis that propagates 1D hypotheses
326 # from an edge where this hypothesis is assigned to
327 # on all other edges that are at the opposite side in case of quadrangular faces
328 # This hypothesis should be assigned to an edge to propagate a hypothesis from.
329 # @ingroup l3_hypos_additi
330 def Propagation(self):
331 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
333 ## Defines "Propagation of Node Distribution" hypothesis that propagates
334 # distribution of nodes from an edge where this hypothesis is assigned to,
335 # to opposite edges of quadrangular faces, so that number of segments on all these
336 # edges will be the same, as well as relations between segment lengths.
337 # @ingroup l3_hypos_additi
338 def PropagationOfDistribution(self):
339 return self.Hypothesis("PropagOfDistribution", UseExisting=1,
340 CompareMethod=self.CompareEqualHyp)
342 ## Defines "AutomaticLength" hypothesis
343 # @param fineness for the fineness [0-1]
344 # @param UseExisting if ==true - searches for an existing hypothesis created with the
345 # same parameters, else (default) - create a new one
346 # @ingroup l3_hypos_1dhyps
347 def AutomaticLength(self, fineness=0, UseExisting=0):
348 from salome.smesh.smeshBuilder import IsEqual
349 compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
350 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
351 CompareMethod=compFun)
352 hyp.SetFineness( fineness )
355 ## Defines "SegmentLengthAroundVertex" hypothesis
356 # @param length for the segment length
357 # @param vertex for the length localization: the vertex index [0,1] | vertex object.
358 # Any other integer value means that the hypothesis will be set on the
359 # whole 1D shape, where Mesh_Segment algorithm is assigned.
360 # @param UseExisting if ==true - searches for an existing hypothesis created with
361 # the same parameters, else (default) - creates a new one
362 # @ingroup l3_algos_segmarv
363 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
365 store_geom = self.geom
366 if type(vertex) is types.IntType:
367 if vertex == 0 or vertex == 1:
368 from salome.geom import geomBuilder
369 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geomBuilder.geomBuilder.ShapeType["VERTEX"],True)[vertex]
377 if self.geom is None:
378 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
379 from salome.smesh.smeshBuilder import AssureGeomPublished, GetName, TreatHypoStatus
380 AssureGeomPublished( self.mesh, self.geom )
381 name = GetName(self.geom)
383 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
385 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
387 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
388 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True, self.mesh)
390 from salome.smesh.smeshBuilder import IsEqual
391 comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
392 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
393 CompareMethod=comFun)
394 self.geom = store_geom
395 hyp.SetLength( length )
398 ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
399 # If the 2D mesher sees that all boundary edges are quadratic,
400 # it generates quadratic faces, else it generates linear faces using
401 # medium nodes as if they are vertices.
402 # The 3D mesher generates quadratic volumes only if all boundary faces
403 # are quadratic, else it fails.
405 # @ingroup l3_hypos_additi
406 def QuadraticMesh(self):
407 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
410 pass # end of StdMeshersBuilder_Segment class
412 ## Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
414 # It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.COMPOSITE,geom=0)
416 # @ingroup l3_algos_basic
417 class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
419 ## name of the dynamic method in smeshBuilder.Mesh class
421 meshMethod = "Segment"
422 ## type of algorithm used with helper function in smeshBuilder.Mesh class
425 ## flag pointing either this algorithm should be used by default in dynamic method
426 # of smeshBuilder.Mesh class
429 ## doc string of the method
431 docHelper = "Creates segment 1D algorithm for edges"
433 ## Private constructor.
434 # @param mesh parent mesh object algorithm is assigned to
435 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
436 # if it is @c 0 (default), the algorithm is assigned to the main shape
437 def __init__(self, mesh, geom=0):
438 self.Create(mesh, geom, self.algoType)
441 pass # end of StdMeshersBuilder_CompositeSegment class
443 ## Defines a segment 1D algorithm for discretization of edges with Python function
445 # It is created by calling smeshBuilder.Mesh.Segment(smeshBuilder.PYTHON,geom=0)
447 # @ingroup l3_algos_basic
448 class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
450 ## name of the dynamic method in smeshBuilder.Mesh class
452 meshMethod = "Segment"
453 ## type of algorithm used with helper function in smeshBuilder.Mesh class
456 ## doc string of the method
458 docHelper = "Creates tetrahedron 3D algorithm for solids"
459 ## doc string of the method
461 docHelper = "Creates segment 1D algorithm for edges"
463 ## Private constructor.
464 # @param mesh parent mesh object algorithm is assigned to
465 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
466 # if it is @c 0 (default), the algorithm is assigned to the main shape
467 def __init__(self, mesh, geom=0):
468 import Python1dPlugin
469 self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
472 ## Defines "PythonSplit1D" hypothesis
473 # @param n for the number of segments that cut an edge
474 # @param func for the python function that calculates the length of all segments
475 # @param UseExisting if ==true - searches for the existing hypothesis created with
476 # the same parameters, else (default) - creates a new one
477 # @ingroup l3_hypos_1dhyps
478 def PythonSplit1D(self, n, func, UseExisting=0):
479 compFun = lambda hyp, args: False
480 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
481 UseExisting=UseExisting, CompareMethod=compFun)
482 hyp.SetNumberOfSegments(n)
483 hyp.SetPythonLog10RatioFunction(func)
486 pass # end of StdMeshersBuilder_Segment_Python class
488 ## Triangle MEFISTO 2D algorithm
490 # It is created by calling smeshBuilder.Mesh.Triangle(smeshBuilder.MEFISTO,geom=0)
492 # @ingroup l3_algos_basic
493 class StdMeshersBuilder_Triangle_MEFISTO(Mesh_Algorithm):
495 ## name of the dynamic method in smeshBuilder.Mesh class
497 meshMethod = "Triangle"
498 ## type of algorithm used with helper function in smeshBuilder.Mesh class
501 ## flag pointing either this algorithm should be used by default in dynamic method
502 # of smeshBuilder.Mesh class
505 ## doc string of the method
507 docHelper = "Creates triangle 2D algorithm for faces"
509 ## Private constructor.
510 # @param mesh parent mesh object algorithm is assigned to
511 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
512 # if it is @c 0 (default), the algorithm is assigned to the main shape
513 def __init__(self, mesh, geom=0):
514 Mesh_Algorithm.__init__(self)
515 self.Create(mesh, geom, self.algoType)
518 ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
519 # @param area for the maximum area of each triangle
520 # @param UseExisting if ==true - searches for an existing hypothesis created with the
521 # same parameters, else (default) - creates a new one
523 # @ingroup l3_hypos_2dhyps
524 def MaxElementArea(self, area, UseExisting=0):
525 from salome.smesh.smeshBuilder import IsEqual
526 comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
527 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
528 CompareMethod=comparator)
529 hyp.SetMaxElementArea(area)
532 ## Defines "LengthFromEdges" hypothesis to build triangles
533 # based on the length of the edges taken from the wire
535 # @ingroup l3_hypos_2dhyps
536 def LengthFromEdges(self):
537 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
540 pass # end of StdMeshersBuilder_Triangle_MEFISTO class
542 ## Defines a quadrangle 2D algorithm
544 # It is created by calling smeshBuilder.Mesh.Quadrangle(geom=0)
546 # @ingroup l3_algos_basic
547 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
549 ## name of the dynamic method in smeshBuilder.Mesh class
551 meshMethod = "Quadrangle"
552 ## type of algorithm used with helper function in smeshBuilder.Mesh class
554 algoType = QUADRANGLE
555 ## flag pointing either this algorithm should be used by default in dynamic method
556 # of smeshBuilder.Mesh class
559 ## doc string of the method
561 docHelper = "Creates quadrangle 2D algorithm for faces"
562 ## hypothesis associated with algorithm
566 ## Private constructor.
567 # @param mesh parent mesh object algorithm is assigned to
568 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
569 # if it is @c 0 (default), the algorithm is assigned to the main shape
570 def __init__(self, mesh, geom=0):
571 Mesh_Algorithm.__init__(self)
572 self.Create(mesh, geom, self.algoType)
575 ## Defines "QuadrangleParameters" hypothesis
576 # @param quadType defines the algorithm of transition between differently descretized
577 # sides of a geometrical face:
578 # - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
579 # area along the finer meshed sides.
580 # - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
581 # finer meshed sides.
582 # - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
583 # the finer meshed sides, iff the total quantity of segments on
584 # all four sides of the face is even (divisible by 2).
585 # - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
586 # area is located along the coarser meshed sides.
587 # - QUAD_REDUCED - only quadrangles are built and the transition between the sides
588 # is made gradually, layer by layer. This type has a limitation on
589 # the number of segments: one pair of opposite sides must have the
590 # same number of segments, the other pair must have an even difference
591 # between the numbers of segments on the sides.
592 # @param triangleVertex: vertex of a trilateral geometrical face, around which triangles
593 # will be created while other elements will be quadrangles.
594 # Vertex can be either a GEOM_Object or a vertex ID within the
596 # @param enfVertices: list of shapes defining positions where nodes (enforced nodes)
597 # must be created by the mesher. Shapes can be of any type,
598 # vertices of given shapes define positions of enforced nodes.
599 # Only vertices successfully projected to the face are used.
600 # @param enfPoints: list of points giving positions of enforced nodes.
601 # Point can be defined either as SMESH.PointStruct's
602 # ([SMESH.PointStruct(x1,y1,z1), SMESH.PointStruct(x2,y2,z2),...])
603 # or triples of values ([[x1,y1,z1], [x2,y2,z2], ...]).
604 # In the case if the defined QuadrangleParameters() refer to a sole face,
605 # all given points must lie on this face, else the mesher fails.
606 # @param UseExisting: if \c True - searches for the existing hypothesis created with
607 # the same parameters, else (default) - creates a new one
608 # @ingroup l3_hypos_quad
609 def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0,
610 enfVertices=[],enfPoints=[],UseExisting=0):
612 vertexID = triangleVertex
613 if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
614 vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
615 if isinstance( enfVertices, int ) and not enfPoints and not UseExisting:
616 # a call of old syntax, before inserting enfVertices and enfPoints before UseExisting
617 UseExisting, enfVertices = enfVertices, []
618 pStructs, xyz = [], []
620 if isinstance( p, SMESH.PointStruct ):
621 xyz.append(( p.x, p.y, p.z ))
624 xyz.append(( p[0], p[1], p[2] ))
625 pStructs.append( SMESH.PointStruct( p[0], p[1], p[2] ))
627 compFun = lambda hyp,args: \
628 hyp.GetQuadType() == args[0] and \
629 (hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1)) and \
630 ((hyp.GetEnforcedNodes()) == (args[2],args[3])) # True w/o enfVertices only
631 entries = [ shape.GetStudyEntry() for shape in enfVertices ]
632 self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID,entries,xyz],
633 UseExisting = UseExisting, CompareMethod=compFun)
635 if self.params.GetQuadType() != quadType:
636 self.params.SetQuadType(quadType)
638 self.params.SetTriaVertex( vertexID )
639 from salome.smesh.smeshBuilder import AssureGeomPublished
640 for v in enfVertices:
641 AssureGeomPublished( self.mesh, v )
642 self.params.SetEnforcedNodes( enfVertices, pStructs )
645 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
646 # quadrangles are built in the transition area along the finer meshed sides,
647 # iff the total quantity of segments on all four sides of the face is even.
648 # @param reversed if True, transition area is located along the coarser meshed sides.
649 # @param UseExisting: if ==true - searches for the existing hypothesis created with
650 # the same parameters, else (default) - creates a new one
651 # @ingroup l3_hypos_quad
652 def QuadranglePreference(self, reversed=False, UseExisting=0):
654 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
655 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
657 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
658 # triangles are built in the transition area along the finer meshed sides.
659 # @param UseExisting: if ==true - searches for the existing hypothesis created with
660 # the same parameters, else (default) - creates a new one
661 # @ingroup l3_hypos_quad
662 def TrianglePreference(self, UseExisting=0):
663 return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
665 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
666 # quadrangles are built and the transition between the sides is made gradually,
667 # layer by layer. This type has a limitation on the number of segments: one pair
668 # of opposite sides must have the same number of segments, the other pair must
669 # have an even difference between the numbers of segments on the sides.
670 # @param UseExisting: if ==true - searches for the existing hypothesis created with
671 # the same parameters, else (default) - creates a new one
672 # @ingroup l3_hypos_quad
673 def Reduced(self, UseExisting=0):
674 return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
676 ## Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
677 # @param vertex: vertex of a trilateral geometrical face, around which triangles
678 # will be created while other elements will be quadrangles.
679 # Vertex can be either a GEOM_Object or a vertex ID within the
681 # @param UseExisting: if ==true - searches for the existing hypothesis created with
682 # the same parameters, else (default) - creates a new one
683 # @ingroup l3_hypos_quad
684 def TriangleVertex(self, vertex, UseExisting=0):
685 return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
687 pass # end of StdMeshersBuilder_Quadrangle class
689 ## Defines a hexahedron 3D algorithm
691 # It is created by calling smeshBuilder.Mesh.Hexahedron(geom=0)
693 # @ingroup l3_algos_basic
694 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
696 ## name of the dynamic method in smeshBuilder.Mesh class
698 meshMethod = "Hexahedron"
699 ## type of algorithm used with helper function in smeshBuilder.Mesh class
702 ## flag pointing either this algorithm should be used by default in dynamic method
703 # of smeshBuilder.Mesh class
706 ## doc string of the method
708 docHelper = "Creates hexahedron 3D algorithm for volumes"
710 ## Private constructor.
711 # @param mesh parent mesh object algorithm is assigned to
712 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
713 # if it is @c 0 (default), the algorithm is assigned to the main shape
714 def __init__(self, mesh, geom=0):
715 Mesh_Algorithm.__init__(self)
716 self.Create(mesh, geom, Hexa)
719 pass # end of StdMeshersBuilder_Hexahedron class
721 ## Defines a projection 1D algorithm
723 # It is created by calling smeshBuilder.Mesh.Projection1D(geom=0)
725 # @ingroup l3_algos_proj
726 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
728 ## name of the dynamic method in smeshBuilder.Mesh class
730 meshMethod = "Projection1D"
731 ## type of algorithm used with helper function in smeshBuilder.Mesh class
733 algoType = "Projection_1D"
734 ## flag pointing either this algorithm should be used by default in dynamic method
735 # of smeshBuilder.Mesh class
738 ## doc string of the method
740 docHelper = "Creates projection 1D algorithm for edges"
742 ## Private constructor.
743 # @param mesh parent mesh object algorithm is assigned to
744 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
745 # if it is @c 0 (default), the algorithm is assigned to the main shape
746 def __init__(self, mesh, geom=0):
747 Mesh_Algorithm.__init__(self)
748 self.Create(mesh, geom, self.algoType)
751 ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
752 # a mesh pattern is taken, and, optionally, the association of vertices
753 # between the source edge and a target edge (to which a hypothesis is assigned)
754 # @param edge from which nodes distribution is taken
755 # @param mesh from which nodes distribution is taken (optional)
756 # @param srcV a vertex of \a edge to associate with \a tgtV (optional)
757 # @param tgtV a vertex of \a the edge to which the algorithm is assigned,
758 # to associate with \a srcV (optional)
759 # @param UseExisting if ==true - searches for the existing hypothesis created with
760 # the same parameters, else (default) - creates a new one
761 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
762 from salome.smesh.smeshBuilder import AssureGeomPublished, Mesh
763 AssureGeomPublished( self.mesh, edge )
764 AssureGeomPublished( self.mesh, srcV )
765 AssureGeomPublished( self.mesh, tgtV )
766 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
768 # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
769 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
770 hyp.SetSourceEdge( edge )
771 if not mesh is None and isinstance(mesh, Mesh):
772 mesh = mesh.GetMesh()
773 hyp.SetSourceMesh( mesh )
774 hyp.SetVertexAssociation( srcV, tgtV )
777 pass # end of StdMeshersBuilder_Projection1D class
779 ## Defines a projection 2D algorithm
781 # It is created by calling smeshBuilder.Mesh.Projection2D(geom=0)
783 # @ingroup l3_algos_proj
784 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
786 ## name of the dynamic method in smeshBuilder.Mesh class
788 meshMethod = "Projection2D"
789 ## type of algorithm used with helper function in smeshBuilder.Mesh class
791 algoType = "Projection_2D"
792 ## flag pointing either this algorithm should be used by default in dynamic method
793 # of smeshBuilder.Mesh class
796 ## doc string of the method
798 docHelper = "Creates projection 2D algorithm for faces"
800 ## Private constructor.
801 # @param mesh parent mesh object algorithm is assigned to
802 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
803 # if it is @c 0 (default), the algorithm is assigned to the main shape
804 def __init__(self, mesh, geom=0):
805 Mesh_Algorithm.__init__(self)
806 self.Create(mesh, geom, self.algoType)
809 ## Defines "Source Face" hypothesis, specifying a meshed face, from where
810 # a mesh pattern is taken, and, optionally, the association of vertices
811 # between the source face and the target face (to which a hypothesis is assigned)
812 # @param face from which the mesh pattern is taken
813 # @param mesh from which the mesh pattern is taken (optional)
814 # @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
815 # @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
816 # to associate with \a srcV1 (optional)
817 # @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
818 # @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
819 # to associate with \a srcV2 (optional)
820 # @param UseExisting if ==true - forces the search for the existing hypothesis created with
821 # the same parameters, else (default) - forces the creation a new one
823 # Note: all association vertices must belong to one edge of a face
824 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
825 srcV2=None, tgtV2=None, UseExisting=0):
826 from salome.smesh.smeshBuilder import Mesh
827 if isinstance(mesh, Mesh):
828 mesh = mesh.GetMesh()
829 for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
830 from salome.smesh.smeshBuilder import AssureGeomPublished
831 AssureGeomPublished( self.mesh, geom )
832 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
833 UseExisting=0, toAdd=False)
834 # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
835 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
836 hyp.SetSourceFace( face )
837 hyp.SetSourceMesh( mesh )
838 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
839 self.mesh.AddHypothesis(hyp, self.geom)
842 pass # end of StdMeshersBuilder_Projection2D class
844 ## Defines a projection 1D-2D algorithm
846 # It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
848 # @ingroup l3_algos_proj
849 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
851 ## name of the dynamic method in smeshBuilder.Mesh class
853 meshMethod = "Projection1D2D"
854 ## type of algorithm used with helper function in smeshBuilder.Mesh class
856 algoType = "Projection_1D2D"
857 ## doc string of the method
859 docHelper = "Creates projection 1D-2D algorithm for edges and faces"
861 ## Private constructor.
862 # @param mesh parent mesh object algorithm is assigned to
863 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
864 # if it is @c 0 (default), the algorithm is assigned to the main shape
865 def __init__(self, mesh, geom=0):
866 StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
869 pass # end of StdMeshersBuilder_Projection1D2D class
871 ## Defines a projection 3D algorithm
873 # It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
875 # @ingroup l3_algos_proj
876 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
878 ## name of the dynamic method in smeshBuilder.Mesh class
880 meshMethod = "Projection3D"
881 ## type of algorithm used with helper function in smeshBuilder.Mesh class
883 algoType = "Projection_3D"
884 ## doc string of the method
886 docHelper = "Creates projection 3D algorithm for volumes"
888 ## Private constructor.
889 # @param mesh parent mesh object algorithm is assigned to
890 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
891 # if it is @c 0 (default), the algorithm is assigned to the main shape
892 def __init__(self, mesh, geom=0):
893 Mesh_Algorithm.__init__(self)
894 self.Create(mesh, geom, self.algoType)
897 ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
898 # the mesh pattern is taken, and, optionally, the association of vertices
899 # between the source and the target solid (to which a hipothesis is assigned)
900 # @param solid from where the mesh pattern is taken
901 # @param mesh from where the mesh pattern is taken (optional)
902 # @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
903 # @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
904 # to associate with \a srcV1 (optional)
905 # @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
906 # @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
907 # to associate with \a srcV2 (optional)
908 # @param UseExisting - if ==true - searches for the existing hypothesis created with
909 # the same parameters, else (default) - creates a new one
911 # Note: association vertices must belong to one edge of a solid
912 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
913 srcV2=0, tgtV2=0, UseExisting=0):
914 for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
915 from salome.smesh.smeshBuilder import AssureGeomPublished
916 AssureGeomPublished( self.mesh, geom )
917 hyp = self.Hypothesis("ProjectionSource3D",
918 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
920 # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
921 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
922 hyp.SetSource3DShape( solid )
923 from salome.smesh.smeshBuilder import Mesh
924 if isinstance(mesh, Mesh):
925 mesh = mesh.GetMesh()
927 hyp.SetSourceMesh( mesh )
928 if srcV1 and srcV2 and tgtV1 and tgtV2:
929 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
930 #elif srcV1 or srcV2 or tgtV1 or tgtV2:
933 pass # end of StdMeshersBuilder_Projection3D class
935 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
936 # depending on geometry
938 # It is created by calling smeshBuilder.Mesh.Prism(geom=0)
940 # @ingroup l3_algos_3dextr
941 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
943 ## name of the dynamic method in smeshBuilder.Mesh class
946 ## type of algorithm used with helper function in smeshBuilder.Mesh class
948 algoType = "Prism_3D"
949 ## doc string of the method
951 docHelper = "Creates prism 3D algorithm for volumes"
953 ## Private constructor.
954 # @param mesh parent mesh object algorithm is assigned to
955 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
956 # if it is @c 0 (default), the algorithm is assigned to the main shape
957 def __init__(self, mesh, geom=0):
958 Mesh_Algorithm.__init__(self)
963 from salome.geom import geomBuilder
964 nbSolids = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SOLID"] ))
965 nbShells = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SHELL"] ))
966 if nbSolids == 0 or nbSolids == nbShells:
967 self.Create(mesh, geom, "Prism_3D")
970 self.algoType = "RadialPrism_3D"
971 self.Create(mesh, geom, "RadialPrism_3D")
972 self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
977 ## Return 3D hypothesis holding the 1D one
978 def Get3DHypothesis(self):
979 if self.algoType != "RadialPrism_3D":
980 print "Prism_3D algorith doesn't support any hyposesis"
982 return self.distribHyp
984 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
985 # hypothesis. Returns the created hypothesis
986 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
987 if self.algoType != "RadialPrism_3D":
988 print "Prism_3D algorith doesn't support any hyposesis"
990 if not self.nbLayers is None:
991 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
992 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
993 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
994 self.mesh.smeshpyD.SetCurrentStudy( None )
995 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
996 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
997 if not self.distribHyp:
998 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
999 self.distribHyp.SetLayerDistribution( hyp )
1002 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1003 # prisms to build between the inner and outer shells
1004 # @param n number of layers
1005 # @param UseExisting if ==true - searches for the existing hypothesis created with
1006 # the same parameters, else (default) - creates a new one
1007 def NumberOfLayers(self, n, UseExisting=0):
1008 if self.algoType != "RadialPrism_3D":
1009 print "Prism_3D algorith doesn't support any hyposesis"
1011 self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1012 from salome.smesh.smeshBuilder import IsEqual
1013 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1014 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1015 CompareMethod=compFun)
1016 self.nbLayers.SetNumberOfLayers( n )
1017 return self.nbLayers
1019 ## Defines "LocalLength" hypothesis, specifying the segment length
1020 # to build between the inner and the outer shells
1021 # @param l the length of segments
1022 # @param p the precision of rounding
1023 def LocalLength(self, l, p=1e-07):
1024 if self.algoType != "RadialPrism_3D":
1025 print "Prism_3D algorith doesn't support any hyposesis"
1027 hyp = self.OwnHypothesis("LocalLength", [l,p])
1032 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1033 # prisms to build between the inner and the outer shells.
1034 # @param n the number of layers
1035 # @param s the scale factor (optional)
1036 def NumberOfSegments(self, n, s=[]):
1037 if self.algoType != "RadialPrism_3D":
1038 print "Prism_3D algorith doesn't support any hyposesis"
1041 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1043 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1044 hyp.SetDistrType( 1 )
1045 hyp.SetScaleFactor(s)
1046 hyp.SetNumberOfSegments(n)
1049 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1050 # to build between the inner and the outer shells with a length that changes
1051 # in arithmetic progression
1052 # @param start the length of the first segment
1053 # @param end the length of the last segment
1054 def Arithmetic1D(self, start, end ):
1055 if self.algoType != "RadialPrism_3D":
1056 print "Prism_3D algorith doesn't support any hyposesis"
1058 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1059 hyp.SetLength(start, 1)
1060 hyp.SetLength(end , 0)
1063 ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1064 # to build between the inner and the outer shells with a length that changes
1065 # in Geometric progression
1066 # @param start the length of the first segment
1067 # @param ratio the common ratio of the geometric progression
1068 def GeometricProgression(self, start, ratio ):
1069 if self.algoType != "RadialPrism_3D":
1070 print "Prism_3D algorith doesn't support any hyposesis"
1072 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1073 hyp.SetStartLength( start )
1074 hyp.SetCommonRatio( ratio )
1077 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1078 # to build between the inner and the outer shells as geometric length increasing
1079 # @param start for the length of the first segment
1080 # @param end for the length of the last segment
1081 def StartEndLength(self, start, end):
1082 if self.algoType != "RadialPrism_3D":
1083 print "Prism_3D algorith doesn't support any hyposesis"
1085 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1086 hyp.SetLength(start, 1)
1087 hyp.SetLength(end , 0)
1090 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1091 # to build between the inner and outer shells
1092 # @param fineness defines the quality of the mesh within the range [0-1]
1093 def AutomaticLength(self, fineness=0):
1094 if self.algoType != "RadialPrism_3D":
1095 print "Prism_3D algorith doesn't support any hyposesis"
1097 hyp = self.OwnHypothesis("AutomaticLength")
1098 hyp.SetFineness( fineness )
1101 pass # end of StdMeshersBuilder_Prism3D class
1103 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
1104 # depending on geometry
1106 # It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1108 # @ingroup l3_algos_3dextr
1109 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1111 ## name of the dynamic method in smeshBuilder.Mesh class
1113 meshMethod = "Prism"
1114 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1116 algoType = "RadialPrism_3D"
1117 ## doc string of the method
1119 docHelper = "Creates prism 3D algorithm for volumes"
1121 ## Private constructor.
1122 # @param mesh parent mesh object algorithm is assigned to
1123 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1124 # if it is @c 0 (default), the algorithm is assigned to the main shape
1125 def __init__(self, mesh, geom=0):
1126 Mesh_Algorithm.__init__(self)
1131 self.Create(mesh, geom, "RadialPrism_3D")
1132 self.distribHyp = None
1133 self.nbLayers = None
1136 ## Defines a Radial Quadrangle 1D-2D algorithm
1138 # It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1140 # @ingroup l2_algos_radialq
1141 class StdMeshersBuilder_RadialQuadrangle1D2D(Mesh_Algorithm):
1143 ## name of the dynamic method in smeshBuilder.Mesh class
1145 meshMethod = "Quadrangle"
1146 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1148 algoType = RADIAL_QUAD
1149 ## doc string of the method
1151 docHelper = "Creates quadrangle 1D-2D algorithm for triangular faces"
1153 ## Private constructor.
1154 # @param mesh parent mesh object algorithm is assigned to
1155 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1156 # if it is @c 0 (default), the algorithm is assigned to the main shape
1157 def __init__(self, mesh, geom=0):
1158 Mesh_Algorithm.__init__(self)
1159 self.Create(mesh, geom, self.algoType)
1161 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1162 self.nbLayers = None
1165 ## Return 2D hypothesis holding the 1D one
1166 def Get2DHypothesis(self):
1167 if not self.distribHyp:
1168 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1169 return self.distribHyp
1171 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
1172 # hypothesis. Returns the created hypothesis
1173 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1175 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1176 if self.distribHyp is None:
1177 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1179 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1180 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
1181 self.mesh.smeshpyD.SetCurrentStudy( None )
1182 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1183 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
1184 self.distribHyp.SetLayerDistribution( hyp )
1187 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
1188 # @param n number of layers
1189 # @param UseExisting if ==true - searches for the existing hypothesis created with
1190 # the same parameters, else (default) - creates a new one
1191 def NumberOfLayers(self, n, UseExisting=0):
1193 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1194 from salome.smesh.smeshBuilder import IsEqual
1195 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1196 self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1197 CompareMethod=compFun)
1198 self.nbLayers.SetNumberOfLayers( n )
1199 return self.nbLayers
1201 ## Defines "LocalLength" hypothesis, specifying the segment length
1202 # @param l the length of segments
1203 # @param p the precision of rounding
1204 def LocalLength(self, l, p=1e-07):
1205 hyp = self.OwnHypothesis("LocalLength", [l,p])
1210 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
1211 # @param n the number of layers
1212 # @param s the scale factor (optional)
1213 def NumberOfSegments(self, n, s=[]):
1215 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1217 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1218 hyp.SetDistrType( 1 )
1219 hyp.SetScaleFactor(s)
1220 hyp.SetNumberOfSegments(n)
1223 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1224 # with a length that changes in arithmetic progression
1225 # @param start the length of the first segment
1226 # @param end the length of the last segment
1227 def Arithmetic1D(self, start, end ):
1228 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1229 hyp.SetLength(start, 1)
1230 hyp.SetLength(end , 0)
1233 ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1234 # with a length that changes in Geometric progression
1235 # @param start the length of the first segment
1236 # @param ratio the common ratio of the geometric progression
1237 def GeometricProgression(self, start, ratio ):
1238 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1239 hyp.SetStartLength( start )
1240 hyp.SetCommonRatio( ratio )
1243 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1244 # as geometric length increasing
1245 # @param start for the length of the first segment
1246 # @param end for the length of the last segment
1247 def StartEndLength(self, start, end):
1248 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1249 hyp.SetLength(start, 1)
1250 hyp.SetLength(end , 0)
1253 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1254 # @param fineness defines the quality of the mesh within the range [0-1]
1255 def AutomaticLength(self, fineness=0):
1256 hyp = self.OwnHypothesis("AutomaticLength")
1257 hyp.SetFineness( fineness )
1260 pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1262 ## Defines a Use Existing Elements 1D algorithm
1264 # It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1266 # @ingroup l3_algos_basic
1267 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1269 ## name of the dynamic method in smeshBuilder.Mesh class
1271 meshMethod = "UseExisting1DElements"
1272 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1274 algoType = "Import_1D"
1275 ## flag pointing either this algorithm should be used by default in dynamic method
1276 # of smeshBuilder.Mesh class
1279 ## doc string of the method
1281 docHelper = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1283 ## Private constructor.
1284 # @param mesh parent mesh object algorithm is assigned to
1285 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1286 # if it is @c 0 (default), the algorithm is assigned to the main shape
1287 def __init__(self, mesh, geom=0):
1288 Mesh_Algorithm.__init__(self)
1289 self.Create(mesh, geom, self.algoType)
1292 ## Defines "Source edges" hypothesis, specifying groups of edges to import
1293 # @param groups list of groups of edges
1294 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1295 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1296 # @param UseExisting if ==true - searches for the existing hypothesis created with
1297 # the same parameters, else (default) - creates a new one
1298 def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1299 for group in groups:
1300 from salome.smesh.smeshBuilder import AssureGeomPublished
1301 AssureGeomPublished( self.mesh, group )
1302 compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1303 hyp.GetCopySourceMesh() == args[1], args[2] )
1304 hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1305 UseExisting=UseExisting, CompareMethod=compFun)
1306 hyp.SetSourceEdges(groups)
1307 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1310 pass # end of StdMeshersBuilder_UseExistingElements_1D class
1312 ## Defines a Use Existing Elements 1D-2D algorithm
1314 # It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1316 # @ingroup l3_algos_basic
1317 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1319 ## name of the dynamic method in smeshBuilder.Mesh class
1321 meshMethod = "UseExisting2DElements"
1322 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1324 algoType = "Import_1D2D"
1325 ## flag pointing either this algorithm should be used by default in dynamic method
1326 # of smeshBuilder.Mesh class
1329 ## doc string of the method
1331 docHelper = "Creates 1D-2D algorithm for edges/faces with reusing of existing mesh elements"
1333 ## Private constructor.
1334 # @param mesh parent mesh object algorithm is assigned to
1335 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1336 # if it is @c 0 (default), the algorithm is assigned to the main shape
1337 def __init__(self, mesh, geom=0):
1338 Mesh_Algorithm.__init__(self)
1339 self.Create(mesh, geom, self.algoType)
1342 ## Defines "Source faces" hypothesis, specifying groups of faces to import
1343 # @param groups list of groups of faces
1344 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1345 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1346 # @param UseExisting if ==true - searches for the existing hypothesis created with
1347 # the same parameters, else (default) - creates a new one
1348 def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1349 for group in groups:
1350 from salome.smesh.smeshBuilder import AssureGeomPublished
1351 AssureGeomPublished( self.mesh, group )
1352 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1353 hyp.GetCopySourceMesh() == args[1], args[2] )
1354 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1355 UseExisting=UseExisting, CompareMethod=compFun)
1356 hyp.SetSourceFaces(groups)
1357 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1360 pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1362 ## Defines a Body Fitting 3D algorithm
1364 # It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1366 # @ingroup l3_algos_basic
1367 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1369 ## name of the dynamic method in smeshBuilder.Mesh class
1371 meshMethod = "BodyFitted"
1372 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1374 algoType = "Cartesian_3D"
1375 ## flag pointing either this algorithm should be used by default in dynamic method
1376 # of smeshBuilder.Mesh class
1379 ## doc string of the method
1381 docHelper = "Creates body fitting 3D algorithm for volumes"
1383 ## Private constructor.
1384 # @param mesh parent mesh object algorithm is assigned to
1385 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1386 # if it is @c 0 (default), the algorithm is assigned to the main shape
1387 def __init__(self, mesh, geom=0):
1388 self.Create(mesh, geom, self.algoType)
1392 ## Defines "Body Fitting parameters" hypothesis
1393 # @param xGridDef is definition of the grid along the X asix.
1394 # It can be in either of two following forms:
1395 # - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1396 # - Functions f(t) defining grid spacing at each point on grid axis. If there are
1397 # several functions, they must be accompanied by relative coordinates of
1398 # points dividing the whole shape into ranges where the functions apply; points
1399 # coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1400 # function f(t) varies from 0.0 to 1.0 witin a shape range.
1402 # - "10.5" - defines a grid with a constant spacing
1403 # - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1404 # @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does.
1405 # @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does.
1406 # @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1407 # a polyhedron of size less than hexSize/sizeThreshold is not created.
1408 # @param implEdges enables implementation of geometrical edges into the mesh.
1409 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1411 compFun = lambda hyp, args: False
1412 self.hyp = self.Hypothesis("CartesianParameters3D",
1413 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1414 UseExisting=False, CompareMethod=compFun)
1415 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1416 self.mesh.AddHypothesis( self.hyp, self.geom )
1418 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1419 if not gridDef: raise ValueError, "Empty grid definition"
1420 if isinstance( gridDef, str ):
1421 self.hyp.SetGridSpacing( [gridDef], [], axis )
1422 elif isinstance( gridDef[0], str ):
1423 self.hyp.SetGridSpacing( gridDef, [], axis )
1424 elif isinstance( gridDef[0], int ) or \
1425 isinstance( gridDef[0], float ):
1426 self.hyp.SetGrid(gridDef, axis )
1428 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1429 self.hyp.SetSizeThreshold( sizeThreshold )
1430 self.hyp.SetToAddEdges( implEdges )
1433 ## Defines custom directions of axes of the grid
1434 # @param xAxis either SMESH.DirStruct or a vector, or 3 vector components
1435 # @param yAxis either SMESH.DirStruct or a vector, or 3 vector components
1436 # @param zAxis either SMESH.DirStruct or a vector, or 3 vector components
1437 def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1439 if hasattr( xAxis, "__getitem__" ):
1440 xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1441 elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1442 xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1443 if hasattr( yAxis, "__getitem__" ):
1444 yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1445 elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1446 yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1447 if hasattr( zAxis, "__getitem__" ):
1448 zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1449 elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1450 zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1452 self.hyp = self.Hypothesis("CartesianParameters3D")
1453 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1454 self.mesh.AddHypothesis( self.hyp, self.geom )
1455 self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1458 ## Automatically defines directions of axes of the grid at which
1459 # a number of generated hexahedra is maximal
1460 # @param isOrthogonal defines whether the axes mush be orthogonal
1461 def SetOptimalAxesDirs(self, isOrthogonal=True):
1463 self.hyp = self.Hypothesis("CartesianParameters3D")
1464 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1465 self.mesh.AddHypothesis( self.hyp, self.geom )
1466 x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1467 self.hyp.SetAxesDirs( x,y,z )
1470 ## Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1471 # through the fixed point in each direction at which the grid is defined
1473 # @param p coordinates of the fixed point. Either SMESH.PointStruct or
1474 # a vertex or 3 components of coordinates.
1475 # @param toUnset defines whether the fixed point is defined or removed.
1476 def SetFixedPoint( self, p, toUnset=False ):
1479 if not self.hyp: return
1480 p = SMESH.PointStruct(0,0,0)
1481 elif hasattr( p, "__getitem__" ):
1482 p = SMESH.PointStruct( p[0],p[1],p[2] )
1483 elif isinstance( p, GEOM._objref_GEOM_Object ):
1484 p = self.mesh.smeshpyD.GetPointStruct( p )
1486 self.hyp = self.Hypothesis("CartesianParameters3D")
1487 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1488 self.mesh.AddHypothesis( self.hyp, self.geom )
1489 self.hyp.SetFixedPoint( p, toUnset )
1493 pass # end of StdMeshersBuilder_Cartesian_3D class
1495 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1496 # segments usable by 2D algoritms
1498 # It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1500 # @ingroup l3_algos_basic
1501 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1503 ## name of the dynamic method in smeshBuilder.Mesh class
1505 meshMethod = "UseExistingSegments"
1506 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1508 algoType = "UseExisting_1D"
1509 ## doc string of the method
1511 docHelper = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1513 ## Private constructor.
1514 # @param mesh parent mesh object algorithm is assigned to
1515 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1516 # if it is @c 0 (default), the algorithm is assigned to the main shape
1517 def __init__(self, mesh, geom=0):
1518 self.Create(mesh, geom, self.algoType)
1521 pass # end of StdMeshersBuilder_UseExisting_1D class
1523 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1524 # faces usable by 3D algoritms
1526 # It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1528 # @ingroup l3_algos_basic
1529 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1531 ## name of the dynamic method in smeshBuilder.Mesh class
1533 meshMethod = "UseExistingFaces"
1534 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1536 algoType = "UseExisting_2D"
1537 ## doc string of the method
1539 docHelper = "Creates 2D algorithm for faces with reusing of existing mesh elements"
1541 ## Private constructor.
1542 # @param mesh parent mesh object algorithm is assigned to
1543 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1544 # if it is @c 0 (default), the algorithm is assigned to the main shape
1545 def __init__(self, mesh, geom=0):
1546 self.Create(mesh, geom, self.algoType)
1549 pass # end of StdMeshersBuilder_UseExisting_2D class