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)
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],
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 )
841 pass # end of StdMeshersBuilder_Projection2D class
843 ## Defines a projection 1D-2D algorithm
845 # It is created by calling smeshBuilder.Mesh.Projection1D2D(geom=0)
847 # @ingroup l3_algos_proj
848 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
850 ## name of the dynamic method in smeshBuilder.Mesh class
852 meshMethod = "Projection1D2D"
853 ## type of algorithm used with helper function in smeshBuilder.Mesh class
855 algoType = "Projection_1D2D"
856 ## doc string of the method
858 docHelper = "Creates projection 1D-2D algorithm for edges and faces"
860 ## Private constructor.
861 # @param mesh parent mesh object algorithm is assigned to
862 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
863 # if it is @c 0 (default), the algorithm is assigned to the main shape
864 def __init__(self, mesh, geom=0):
865 StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
868 pass # end of StdMeshersBuilder_Projection1D2D class
870 ## Defines a projection 3D algorithm
872 # It is created by calling smeshBuilder.Mesh.Projection3D(geom=0)
874 # @ingroup l3_algos_proj
875 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
877 ## name of the dynamic method in smeshBuilder.Mesh class
879 meshMethod = "Projection3D"
880 ## type of algorithm used with helper function in smeshBuilder.Mesh class
882 algoType = "Projection_3D"
883 ## doc string of the method
885 docHelper = "Creates projection 3D algorithm for volumes"
887 ## Private constructor.
888 # @param mesh parent mesh object algorithm is assigned to
889 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
890 # if it is @c 0 (default), the algorithm is assigned to the main shape
891 def __init__(self, mesh, geom=0):
892 Mesh_Algorithm.__init__(self)
893 self.Create(mesh, geom, self.algoType)
896 ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
897 # the mesh pattern is taken, and, optionally, the association of vertices
898 # between the source and the target solid (to which a hipothesis is assigned)
899 # @param solid from where the mesh pattern is taken
900 # @param mesh from where the mesh pattern is taken (optional)
901 # @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
902 # @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
903 # to associate with \a srcV1 (optional)
904 # @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
905 # @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
906 # to associate with \a srcV2 (optional)
907 # @param UseExisting - if ==true - searches for the existing hypothesis created with
908 # the same parameters, else (default) - creates a new one
910 # Note: association vertices must belong to one edge of a solid
911 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
912 srcV2=0, tgtV2=0, UseExisting=0):
913 for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
914 from salome.smesh.smeshBuilder import AssureGeomPublished
915 AssureGeomPublished( self.mesh, geom )
916 hyp = self.Hypothesis("ProjectionSource3D",
917 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
919 # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
920 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
921 hyp.SetSource3DShape( solid )
922 from salome.smesh.smeshBuilder import Mesh
923 if isinstance(mesh, Mesh):
924 mesh = mesh.GetMesh()
926 hyp.SetSourceMesh( mesh )
927 if srcV1 and srcV2 and tgtV1 and tgtV2:
928 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
929 #elif srcV1 or srcV2 or tgtV1 or tgtV2:
932 pass # end of StdMeshersBuilder_Projection3D class
934 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
935 # depending on geometry
937 # It is created by calling smeshBuilder.Mesh.Prism(geom=0)
939 # @ingroup l3_algos_3dextr
940 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
942 ## name of the dynamic method in smeshBuilder.Mesh class
945 ## type of algorithm used with helper function in smeshBuilder.Mesh class
947 algoType = "Prism_3D"
948 ## doc string of the method
950 docHelper = "Creates prism 3D algorithm for volumes"
952 ## Private constructor.
953 # @param mesh parent mesh object algorithm is assigned to
954 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
955 # if it is @c 0 (default), the algorithm is assigned to the main shape
956 def __init__(self, mesh, geom=0):
957 Mesh_Algorithm.__init__(self)
962 from salome.geom import geomBuilder
963 nbSolids = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SOLID"] ))
964 nbShells = len( geomBuilder.geom.SubShapeAll( shape, geomBuilder.geomBuilder.ShapeType["SHELL"] ))
965 if nbSolids == 0 or nbSolids == nbShells:
966 self.Create(mesh, geom, "Prism_3D")
969 self.algoType = "RadialPrism_3D"
970 self.Create(mesh, geom, "RadialPrism_3D")
971 self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
976 ## Return 3D hypothesis holding the 1D one
977 def Get3DHypothesis(self):
978 if self.algoType != "RadialPrism_3D":
979 print "Prism_3D algorith doesn't support any hyposesis"
981 return self.distribHyp
983 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
984 # hypothesis. Returns the created hypothesis
985 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
986 if self.algoType != "RadialPrism_3D":
987 print "Prism_3D algorith doesn't support any hyposesis"
989 if not self.nbLayers is None:
990 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
991 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
992 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
993 self.mesh.smeshpyD.SetCurrentStudy( None )
994 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
995 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
996 if not self.distribHyp:
997 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
998 self.distribHyp.SetLayerDistribution( hyp )
1001 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
1002 # prisms to build between the inner and outer shells
1003 # @param n number of layers
1004 # @param UseExisting if ==true - searches for the existing hypothesis created with
1005 # the same parameters, else (default) - creates a new one
1006 def NumberOfLayers(self, n, UseExisting=0):
1007 if self.algoType != "RadialPrism_3D":
1008 print "Prism_3D algorith doesn't support any hyposesis"
1010 self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
1011 from salome.smesh.smeshBuilder import IsEqual
1012 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1013 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
1014 CompareMethod=compFun)
1015 self.nbLayers.SetNumberOfLayers( n )
1016 return self.nbLayers
1018 ## Defines "LocalLength" hypothesis, specifying the segment length
1019 # to build between the inner and the outer shells
1020 # @param l the length of segments
1021 # @param p the precision of rounding
1022 def LocalLength(self, l, p=1e-07):
1023 if self.algoType != "RadialPrism_3D":
1024 print "Prism_3D algorith doesn't support any hyposesis"
1026 hyp = self.OwnHypothesis("LocalLength", [l,p])
1031 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
1032 # prisms to build between the inner and the outer shells.
1033 # @param n the number of layers
1034 # @param s the scale factor (optional)
1035 def NumberOfSegments(self, n, s=[]):
1036 if self.algoType != "RadialPrism_3D":
1037 print "Prism_3D algorith doesn't support any hyposesis"
1040 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1042 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1043 hyp.SetDistrType( 1 )
1044 hyp.SetScaleFactor(s)
1045 hyp.SetNumberOfSegments(n)
1048 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1049 # to build between the inner and the outer shells with a length that changes
1050 # in arithmetic progression
1051 # @param start the length of the first segment
1052 # @param end the length of the last segment
1053 def Arithmetic1D(self, start, end ):
1054 if self.algoType != "RadialPrism_3D":
1055 print "Prism_3D algorith doesn't support any hyposesis"
1057 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1058 hyp.SetLength(start, 1)
1059 hyp.SetLength(end , 0)
1062 ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1063 # to build between the inner and the outer shells with a length that changes
1064 # in Geometric progression
1065 # @param start the length of the first segment
1066 # @param ratio the common ratio of the geometric progression
1067 def GeometricProgression(self, start, ratio ):
1068 if self.algoType != "RadialPrism_3D":
1069 print "Prism_3D algorith doesn't support any hyposesis"
1071 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1072 hyp.SetStartLength( start )
1073 hyp.SetCommonRatio( ratio )
1076 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1077 # to build between the inner and the outer shells as geometric length increasing
1078 # @param start for the length of the first segment
1079 # @param end for the length of the last segment
1080 def StartEndLength(self, start, end):
1081 if self.algoType != "RadialPrism_3D":
1082 print "Prism_3D algorith doesn't support any hyposesis"
1084 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1085 hyp.SetLength(start, 1)
1086 hyp.SetLength(end , 0)
1089 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1090 # to build between the inner and outer shells
1091 # @param fineness defines the quality of the mesh within the range [0-1]
1092 def AutomaticLength(self, fineness=0):
1093 if self.algoType != "RadialPrism_3D":
1094 print "Prism_3D algorith doesn't support any hyposesis"
1096 hyp = self.OwnHypothesis("AutomaticLength")
1097 hyp.SetFineness( fineness )
1100 pass # end of StdMeshersBuilder_Prism3D class
1102 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
1103 # depending on geometry
1105 # It is created by calling smeshBuilder.Mesh.Prism(geom=0)
1107 # @ingroup l3_algos_3dextr
1108 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
1110 ## name of the dynamic method in smeshBuilder.Mesh class
1112 meshMethod = "Prism"
1113 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1115 algoType = "RadialPrism_3D"
1116 ## doc string of the method
1118 docHelper = "Creates prism 3D algorithm for volumes"
1120 ## Private constructor.
1121 # @param mesh parent mesh object algorithm is assigned to
1122 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1123 # if it is @c 0 (default), the algorithm is assigned to the main shape
1124 def __init__(self, mesh, geom=0):
1125 Mesh_Algorithm.__init__(self)
1130 self.Create(mesh, geom, "RadialPrism_3D")
1131 self.distribHyp = None
1132 self.nbLayers = None
1135 ## Defines a Radial Quadrangle 1D-2D algorithm
1137 # It is created by calling smeshBuilder.Mesh.Quadrangle(smeshBuilder.RADIAL_QUAD,geom=0)
1139 # @ingroup l2_algos_radialq
1140 class StdMeshersBuilder_RadialQuadrangle1D2D(Mesh_Algorithm):
1142 ## name of the dynamic method in smeshBuilder.Mesh class
1144 meshMethod = "Quadrangle"
1145 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1147 algoType = RADIAL_QUAD
1148 ## doc string of the method
1150 docHelper = "Creates quadrangle 1D-2D algorithm for triangular faces"
1152 ## Private constructor.
1153 # @param mesh parent mesh object algorithm is assigned to
1154 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1155 # if it is @c 0 (default), the algorithm is assigned to the main shape
1156 def __init__(self, mesh, geom=0):
1157 Mesh_Algorithm.__init__(self)
1158 self.Create(mesh, geom, self.algoType)
1160 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1161 self.nbLayers = None
1164 ## Return 2D hypothesis holding the 1D one
1165 def Get2DHypothesis(self):
1166 if not self.distribHyp:
1167 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1168 return self.distribHyp
1170 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
1171 # hypothesis. Returns the created hypothesis
1172 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1174 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1175 if self.distribHyp is None:
1176 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1178 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1179 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
1180 self.mesh.smeshpyD.SetCurrentStudy( None )
1181 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1182 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
1183 self.distribHyp.SetLayerDistribution( hyp )
1186 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
1187 # @param n number of layers
1188 # @param UseExisting if ==true - searches for the existing hypothesis created with
1189 # the same parameters, else (default) - creates a new one
1190 def NumberOfLayers(self, n, UseExisting=0):
1192 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1193 from salome.smesh.smeshBuilder import IsEqual
1194 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1195 self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1196 CompareMethod=compFun)
1197 self.nbLayers.SetNumberOfLayers( n )
1198 return self.nbLayers
1200 ## Defines "LocalLength" hypothesis, specifying the segment length
1201 # @param l the length of segments
1202 # @param p the precision of rounding
1203 def LocalLength(self, l, p=1e-07):
1204 hyp = self.OwnHypothesis("LocalLength", [l,p])
1209 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
1210 # @param n the number of layers
1211 # @param s the scale factor (optional)
1212 def NumberOfSegments(self, n, s=[]):
1214 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1216 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1217 hyp.SetDistrType( 1 )
1218 hyp.SetScaleFactor(s)
1219 hyp.SetNumberOfSegments(n)
1222 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1223 # with a length that changes in arithmetic progression
1224 # @param start the length of the first segment
1225 # @param end the length of the last segment
1226 def Arithmetic1D(self, start, end ):
1227 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1228 hyp.SetLength(start, 1)
1229 hyp.SetLength(end , 0)
1232 ## Defines "GeometricProgression" hypothesis, specifying the distribution of segments
1233 # with a length that changes in Geometric progression
1234 # @param start the length of the first segment
1235 # @param ratio the common ratio of the geometric progression
1236 def GeometricProgression(self, start, ratio ):
1237 hyp = self.OwnHypothesis("GeometricProgression", [start, ratio])
1238 hyp.SetStartLength( start )
1239 hyp.SetCommonRatio( ratio )
1242 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1243 # as geometric length increasing
1244 # @param start for the length of the first segment
1245 # @param end for the length of the last segment
1246 def StartEndLength(self, start, end):
1247 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1248 hyp.SetLength(start, 1)
1249 hyp.SetLength(end , 0)
1252 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1253 # @param fineness defines the quality of the mesh within the range [0-1]
1254 def AutomaticLength(self, fineness=0):
1255 hyp = self.OwnHypothesis("AutomaticLength")
1256 hyp.SetFineness( fineness )
1259 pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1261 ## Defines a Use Existing Elements 1D algorithm
1263 # It is created by calling smeshBuilder.Mesh.UseExisting1DElements(geom=0)
1265 # @ingroup l3_algos_basic
1266 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1268 ## name of the dynamic method in smeshBuilder.Mesh class
1270 meshMethod = "UseExisting1DElements"
1271 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1273 algoType = "Import_1D"
1274 ## flag pointing either this algorithm should be used by default in dynamic method
1275 # of smeshBuilder.Mesh class
1278 ## doc string of the method
1280 docHelper = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1282 ## Private constructor.
1283 # @param mesh parent mesh object algorithm is assigned to
1284 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1285 # if it is @c 0 (default), the algorithm is assigned to the main shape
1286 def __init__(self, mesh, geom=0):
1287 Mesh_Algorithm.__init__(self)
1288 self.Create(mesh, geom, self.algoType)
1291 ## Defines "Source edges" hypothesis, specifying groups of edges to import
1292 # @param groups list of groups of edges
1293 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1294 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1295 # @param UseExisting if ==true - searches for the existing hypothesis created with
1296 # the same parameters, else (default) - creates a new one
1297 def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1298 for group in groups:
1299 from salome.smesh.smeshBuilder import AssureGeomPublished
1300 AssureGeomPublished( self.mesh, group )
1301 compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1302 hyp.GetCopySourceMesh() == args[1], args[2] )
1303 hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1304 UseExisting=UseExisting, CompareMethod=compFun)
1305 hyp.SetSourceEdges(groups)
1306 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1309 pass # end of StdMeshersBuilder_UseExistingElements_1D class
1311 ## Defines a Use Existing Elements 1D-2D algorithm
1313 # It is created by calling smeshBuilder.Mesh.UseExisting2DElements(geom=0)
1315 # @ingroup l3_algos_basic
1316 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1318 ## name of the dynamic method in smeshBuilder.Mesh class
1320 meshMethod = "UseExisting2DElements"
1321 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1323 algoType = "Import_1D2D"
1324 ## flag pointing either this algorithm should be used by default in dynamic method
1325 # of smeshBuilder.Mesh class
1328 ## doc string of the method
1330 docHelper = "Creates 1D-2D algorithm for edges/faces with reusing of existing mesh elements"
1332 ## Private constructor.
1333 # @param mesh parent mesh object algorithm is assigned to
1334 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1335 # if it is @c 0 (default), the algorithm is assigned to the main shape
1336 def __init__(self, mesh, geom=0):
1337 Mesh_Algorithm.__init__(self)
1338 self.Create(mesh, geom, self.algoType)
1341 ## Defines "Source faces" hypothesis, specifying groups of faces to import
1342 # @param groups list of groups of faces
1343 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1344 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1345 # @param UseExisting if ==true - searches for the existing hypothesis created with
1346 # the same parameters, else (default) - creates a new one
1347 def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1348 for group in groups:
1349 from salome.smesh.smeshBuilder import AssureGeomPublished
1350 AssureGeomPublished( self.mesh, group )
1351 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1352 hyp.GetCopySourceMesh() == args[1], args[2] )
1353 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1354 UseExisting=UseExisting, CompareMethod=compFun)
1355 hyp.SetSourceFaces(groups)
1356 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1359 pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1361 ## Defines a Body Fitting 3D algorithm
1363 # It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1365 # @ingroup l3_algos_basic
1366 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1368 ## name of the dynamic method in smeshBuilder.Mesh class
1370 meshMethod = "BodyFitted"
1371 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1373 algoType = "Cartesian_3D"
1374 ## flag pointing either this algorithm should be used by default in dynamic method
1375 # of smeshBuilder.Mesh class
1378 ## doc string of the method
1380 docHelper = "Creates body fitting 3D algorithm for volumes"
1382 ## Private constructor.
1383 # @param mesh parent mesh object algorithm is assigned to
1384 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1385 # if it is @c 0 (default), the algorithm is assigned to the main shape
1386 def __init__(self, mesh, geom=0):
1387 self.Create(mesh, geom, self.algoType)
1391 ## Defines "Body Fitting parameters" hypothesis
1392 # @param xGridDef is definition of the grid along the X asix.
1393 # It can be in either of two following forms:
1394 # - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1395 # - Functions f(t) defining grid spacing at each point on grid axis. If there are
1396 # several functions, they must be accompanied by relative coordinates of
1397 # points dividing the whole shape into ranges where the functions apply; points
1398 # coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1399 # function f(t) varies from 0.0 to 1.0 witin a shape range.
1401 # - "10.5" - defines a grid with a constant spacing
1402 # - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1403 # @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does.
1404 # @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does.
1405 # @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1406 # a polyhedron of size less than hexSize/sizeThreshold is not created.
1407 # @param implEdges enables implementation of geometrical edges into the mesh.
1408 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1410 compFun = lambda hyp, args: False
1411 self.hyp = self.Hypothesis("CartesianParameters3D",
1412 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1413 UseExisting=False, CompareMethod=compFun)
1414 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1415 self.mesh.AddHypothesis( self.hyp, self.geom )
1417 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1418 if not gridDef: raise ValueError, "Empty grid definition"
1419 if isinstance( gridDef, str ):
1420 self.hyp.SetGridSpacing( [gridDef], [], axis )
1421 elif isinstance( gridDef[0], str ):
1422 self.hyp.SetGridSpacing( gridDef, [], axis )
1423 elif isinstance( gridDef[0], int ) or \
1424 isinstance( gridDef[0], float ):
1425 self.hyp.SetGrid(gridDef, axis )
1427 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1428 self.hyp.SetSizeThreshold( sizeThreshold )
1429 self.hyp.SetToAddEdges( implEdges )
1432 ## Defines custom directions of axes of the grid
1433 # @param xAxis either SMESH.DirStruct or a vector, or 3 vector components
1434 # @param yAxis either SMESH.DirStruct or a vector, or 3 vector components
1435 # @param zAxis either SMESH.DirStruct or a vector, or 3 vector components
1436 def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1438 if hasattr( xAxis, "__getitem__" ):
1439 xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1440 elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1441 xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1442 if hasattr( yAxis, "__getitem__" ):
1443 yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1444 elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1445 yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1446 if hasattr( zAxis, "__getitem__" ):
1447 zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1448 elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1449 zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1451 self.hyp = self.Hypothesis("CartesianParameters3D")
1452 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1453 self.mesh.AddHypothesis( self.hyp, self.geom )
1454 self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1457 ## Automatically defines directions of axes of the grid at which
1458 # a number of generated hexahedra is maximal
1459 # @param isOrthogonal defines whether the axes mush be orthogonal
1460 def SetOptimalAxesDirs(self, isOrthogonal=True):
1462 self.hyp = self.Hypothesis("CartesianParameters3D")
1463 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1464 self.mesh.AddHypothesis( self.hyp, self.geom )
1465 x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1466 self.hyp.SetAxesDirs( x,y,z )
1469 ## Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1470 # through the fixed point in each direction at which the grid is defined
1472 # @param p coordinates of the fixed point. Either SMESH.PointStruct or
1473 # a vertex or 3 components of coordinates.
1474 # @param toUnset defines whether the fixed point is defined or removed.
1475 def SetFixedPoint( self, p, toUnset=False ):
1478 if not self.hyp: return
1479 p = SMESH.PointStruct(0,0,0)
1480 elif hasattr( p, "__getitem__" ):
1481 p = SMESH.PointStruct( p[0],p[1],p[2] )
1482 elif isinstance( p, GEOM._objref_GEOM_Object ):
1483 p = self.mesh.smeshpyD.GetPointStruct( p )
1485 self.hyp = self.Hypothesis("CartesianParameters3D")
1486 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1487 self.mesh.AddHypothesis( self.hyp, self.geom )
1488 self.hyp.SetFixedPoint( p, toUnset )
1492 pass # end of StdMeshersBuilder_Cartesian_3D class
1494 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1495 # segments usable by 2D algoritms
1497 # It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1499 # @ingroup l3_algos_basic
1500 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1502 ## name of the dynamic method in smeshBuilder.Mesh class
1504 meshMethod = "UseExistingSegments"
1505 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1507 algoType = "UseExisting_1D"
1508 ## doc string of the method
1510 docHelper = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1512 ## Private constructor.
1513 # @param mesh parent mesh object algorithm is assigned to
1514 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1515 # if it is @c 0 (default), the algorithm is assigned to the main shape
1516 def __init__(self, mesh, geom=0):
1517 self.Create(mesh, geom, self.algoType)
1520 pass # end of StdMeshersBuilder_UseExisting_1D class
1522 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1523 # faces usable by 3D algoritms
1525 # It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1527 # @ingroup l3_algos_basic
1528 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1530 ## name of the dynamic method in smeshBuilder.Mesh class
1532 meshMethod = "UseExistingFaces"
1533 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1535 algoType = "UseExisting_2D"
1536 ## doc string of the method
1538 docHelper = "Creates 2D algorithm for faces with reusing of existing mesh elements"
1540 ## Private constructor.
1541 # @param mesh parent mesh object algorithm is assigned to
1542 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1543 # if it is @c 0 (default), the algorithm is assigned to the main shape
1544 def __init__(self, mesh, geom=0):
1545 self.Create(mesh, geom, self.algoType)
1548 pass # end of StdMeshersBuilder_UseExisting_2D class