1 # Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # @package StdMeshersBuilder
22 # Python API for the standard meshing plug-in module.
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
27 #----------------------------
28 # Mesh algo type identifiers
29 #----------------------------
31 ## Algorithm type: Regular 1D algorithm, see StdMeshersBuilder_Segment
32 REGULAR = "Regular_1D"
33 ## Algorithm type: Python 1D algorithm, see StdMeshersBuilder_Segment_Python
35 ## Algorithm type: Composite segment 1D algorithm, see StdMeshersBuilder_CompositeSegment
36 COMPOSITE = "CompositeSegment_1D"
37 ## Algorithm type: Triangle MEFISTO 2D algorithm, see StdMeshersBuilder_Triangle_MEFISTO
38 MEFISTO = "MEFISTO_2D"
39 ## Algorithm type: Hexahedron 3D (i-j-k) algorithm, see StdMeshersBuilder_Hexahedron
41 ## Algorithm type: Quadrangle 2D algorithm, see StdMeshersBuilder_Quadrangle
42 QUADRANGLE = "Quadrangle_2D"
43 ## Algorithm type: Radial Quadrangle 1D-2D algorithm, see StdMeshersBuilder_RadialQuadrangle1D2D
44 RADIAL_QUAD = "RadialQuadrangle_1D2D"
46 # import items of enums
47 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
48 for e in StdMeshers.VLExtrusionMethod._items: exec('%s = StdMeshers.%s'%(e,e))
50 #----------------------
52 #----------------------
54 ## Defines segment 1D algorithm for edges discretization.
56 # It can be created by calling smeshBuilder.Mesh.Segment(geom=0)
58 # @ingroup l3_algos_basic
59 class StdMeshersBuilder_Segment(Mesh_Algorithm):
61 ## name of the dynamic method in smeshBuilder.Mesh class
63 meshMethod = "Segment"
64 ## type of algorithm used with helper function in smeshBuilder.Mesh class
67 ## flag pointing either this algorithm should be used by default in dynamic method
68 # of smeshBuilder.Mesh class
71 ## doc string of the method
73 docHelper = "Creates segment 1D algorithm for edges"
75 ## Private constructor.
76 # @param mesh parent mesh object algorithm is assigned to
77 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
78 # if it is @c 0 (default), the algorithm is assigned to the main shape
79 def __init__(self, mesh, geom=0):
80 Mesh_Algorithm.__init__(self)
81 self.Create(mesh, geom, self.algoType)
84 ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
85 # @param l for the length of segments that cut an edge
86 # @param UseExisting if ==true - searches for an existing hypothesis created with
87 # the same parameters, else (default) - creates a new one
88 # @param p precision, used for calculation of the number of segments.
89 # The precision should be a positive, meaningful value within the range [0,1].
90 # In general, the number of segments is calculated with the formula:
91 # nb = ceil((edge_length / l) - p)
92 # Function ceil rounds its argument to the higher integer.
93 # So, p=0 means rounding of (edge_length / l) to the higher integer,
94 # p=0.5 means rounding of (edge_length / l) to the nearest integer,
95 # p=1 means rounding of (edge_length / l) to the lower integer.
96 # Default value is 1e-07.
97 # @return an instance of StdMeshers_LocalLength hypothesis
98 # @ingroup l3_hypos_1dhyps
99 def LocalLength(self, l, UseExisting=0, p=1e-07):
100 from salome.smesh.smeshBuilder import IsEqual
101 comFun=lambda hyp, args: IsEqual(hyp.GetLength(), args[0]) and IsEqual(hyp.GetPrecision(), args[1])
102 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting, CompareMethod=comFun)
107 ## Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
108 # @param length is optional maximal allowed length of segment, if it is omitted
109 # the preestimated length is used that depends on geometry size
110 # @param UseExisting if ==true - searches for an existing hypothesis created with
111 # the same parameters, else (default) - creates a new one
112 # @return an instance of StdMeshers_MaxLength hypothesis
113 # @ingroup l3_hypos_1dhyps
114 def MaxSize(self, length=0.0, UseExisting=0):
115 hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
118 hyp.SetLength(length)
120 # set preestimated length
121 gen = self.mesh.smeshpyD
122 initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
123 self.mesh.GetMesh(), self.mesh.GetShape(),
125 preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
127 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
130 hyp.SetUsePreestimatedLength( length == 0.0 )
133 ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
134 # @param n for the number of segments that cut an edge
135 # @param s for the scale factor (optional)
136 # @param reversedEdges is a list of edges to mesh using reversed orientation.
137 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
138 # @param UseExisting if ==true - searches for an existing hypothesis created with
139 # the same parameters, else (default) - create a new one
140 # @return an instance of StdMeshers_NumberOfSegments hypothesis
141 # @ingroup l3_hypos_1dhyps
142 def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
143 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
144 reversedEdges, UseExisting = [], reversedEdges
145 entry = self.MainShapeEntry()
146 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
148 hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
149 UseExisting=UseExisting,
150 CompareMethod=self._compareNumberOfSegments)
152 hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
153 UseExisting=UseExisting,
154 CompareMethod=self._compareNumberOfSegments)
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.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 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1349 hyp.GetCopySourceMesh() == args[1], args[2] )
1350 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1351 UseExisting=UseExisting, CompareMethod=compFun, toAdd=False)
1352 hyp.SetSourceFaces(groups)
1353 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1354 self.mesh.AddHypothesis(hyp, self.geom)
1357 pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1359 ## Defines a Body Fitting 3D algorithm
1361 # It is created by calling smeshBuilder.Mesh.BodyFitted(geom=0)
1363 # @ingroup l3_algos_basic
1364 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1366 ## name of the dynamic method in smeshBuilder.Mesh class
1368 meshMethod = "BodyFitted"
1369 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1371 algoType = "Cartesian_3D"
1372 ## flag pointing either this algorithm should be used by default in dynamic method
1373 # of smeshBuilder.Mesh class
1376 ## doc string of the method
1378 docHelper = "Creates body fitting 3D algorithm for volumes"
1380 ## Private constructor.
1381 # @param mesh parent mesh object algorithm is assigned to
1382 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1383 # if it is @c 0 (default), the algorithm is assigned to the main shape
1384 def __init__(self, mesh, geom=0):
1385 self.Create(mesh, geom, self.algoType)
1389 ## Defines "Body Fitting parameters" hypothesis
1390 # @param xGridDef is definition of the grid along the X asix.
1391 # It can be in either of two following forms:
1392 # - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1393 # - Functions f(t) defining grid spacing at each point on grid axis. If there are
1394 # several functions, they must be accompanied by relative coordinates of
1395 # points dividing the whole shape into ranges where the functions apply; points
1396 # coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1397 # function f(t) varies from 0.0 to 1.0 witin a shape range.
1399 # - "10.5" - defines a grid with a constant spacing
1400 # - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1401 # @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does.
1402 # @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does.
1403 # @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1404 # a polyhedron of size less than hexSize/sizeThreshold is not created.
1405 # @param implEdges enables implementation of geometrical edges into the mesh.
1406 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, implEdges=False):
1408 compFun = lambda hyp, args: False
1409 self.hyp = self.Hypothesis("CartesianParameters3D",
1410 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1411 UseExisting=False, CompareMethod=compFun)
1412 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1413 self.mesh.AddHypothesis( self.hyp, self.geom )
1415 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef] ):
1416 if not gridDef: raise ValueError, "Empty grid definition"
1417 if isinstance( gridDef, str ):
1418 self.hyp.SetGridSpacing( [gridDef], [], axis )
1419 elif isinstance( gridDef[0], str ):
1420 self.hyp.SetGridSpacing( gridDef, [], axis )
1421 elif isinstance( gridDef[0], int ) or \
1422 isinstance( gridDef[0], float ):
1423 self.hyp.SetGrid(gridDef, axis )
1425 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1426 self.hyp.SetSizeThreshold( sizeThreshold )
1427 self.hyp.SetToAddEdges( implEdges )
1430 ## Defines custom directions of axes of the grid
1431 # @param xAxis either SMESH.DirStruct or a vector, or 3 vector components
1432 # @param yAxis either SMESH.DirStruct or a vector, or 3 vector components
1433 # @param zAxis either SMESH.DirStruct or a vector, or 3 vector components
1434 def SetAxesDirs( self, xAxis, yAxis, zAxis ):
1436 if hasattr( xAxis, "__getitem__" ):
1437 xAxis = self.mesh.smeshpyD.MakeDirStruct( xAxis[0],xAxis[1],xAxis[2] )
1438 elif isinstance( xAxis, GEOM._objref_GEOM_Object ):
1439 xAxis = self.mesh.smeshpyD.GetDirStruct( xAxis )
1440 if hasattr( yAxis, "__getitem__" ):
1441 yAxis = self.mesh.smeshpyD.MakeDirStruct( yAxis[0],yAxis[1],yAxis[2] )
1442 elif isinstance( yAxis, GEOM._objref_GEOM_Object ):
1443 yAxis = self.mesh.smeshpyD.GetDirStruct( yAxis )
1444 if hasattr( zAxis, "__getitem__" ):
1445 zAxis = self.mesh.smeshpyD.MakeDirStruct( zAxis[0],zAxis[1],zAxis[2] )
1446 elif isinstance( zAxis, GEOM._objref_GEOM_Object ):
1447 zAxis = self.mesh.smeshpyD.GetDirStruct( zAxis )
1449 self.hyp = self.Hypothesis("CartesianParameters3D")
1450 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1451 self.mesh.AddHypothesis( self.hyp, self.geom )
1452 self.hyp.SetAxesDirs( xAxis, yAxis, zAxis )
1455 ## Automatically defines directions of axes of the grid at which
1456 # a number of generated hexahedra is maximal
1457 # @param isOrthogonal defines whether the axes mush be orthogonal
1458 def SetOptimalAxesDirs(self, isOrthogonal=True):
1460 self.hyp = self.Hypothesis("CartesianParameters3D")
1461 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1462 self.mesh.AddHypothesis( self.hyp, self.geom )
1463 x,y,z = self.hyp.ComputeOptimalAxesDirs( self.geom, isOrthogonal )
1464 self.hyp.SetAxesDirs( x,y,z )
1467 ## Sets/unsets a fixed point. The algorithm makes a plane of the grid pass
1468 # through the fixed point in each direction at which the grid is defined
1470 # @param p coordinates of the fixed point. Either SMESH.PointStruct or
1471 # a vertex or 3 components of coordinates.
1472 # @param toUnset defines whether the fixed point is defined or removed.
1473 def SetFixedPoint( self, p, toUnset=False ):
1476 if not self.hyp: return
1477 p = SMESH.PointStruct(0,0,0)
1478 elif hasattr( p, "__getitem__" ):
1479 p = SMESH.PointStruct( p[0],p[1],p[2] )
1480 elif isinstance( p, GEOM._objref_GEOM_Object ):
1481 p = self.mesh.smeshpyD.GetPointStruct( p )
1483 self.hyp = self.Hypothesis("CartesianParameters3D")
1484 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1485 self.mesh.AddHypothesis( self.hyp, self.geom )
1486 self.hyp.SetFixedPoint( p, toUnset )
1490 pass # end of StdMeshersBuilder_Cartesian_3D class
1492 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1493 # segments usable by 2D algoritms
1495 # It is created by calling smeshBuilder.Mesh.UseExistingSegments(geom=0)
1497 # @ingroup l3_algos_basic
1498 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1500 ## name of the dynamic method in smeshBuilder.Mesh class
1502 meshMethod = "UseExistingSegments"
1503 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1505 algoType = "UseExisting_1D"
1506 ## doc string of the method
1508 docHelper = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1510 ## Private constructor.
1511 # @param mesh parent mesh object algorithm is assigned to
1512 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1513 # if it is @c 0 (default), the algorithm is assigned to the main shape
1514 def __init__(self, mesh, geom=0):
1515 self.Create(mesh, geom, self.algoType)
1518 pass # end of StdMeshersBuilder_UseExisting_1D class
1520 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1521 # faces usable by 3D algoritms
1523 # It is created by calling smeshBuilder.Mesh.UseExistingFaces(geom=0)
1525 # @ingroup l3_algos_basic
1526 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1528 ## name of the dynamic method in smeshBuilder.Mesh class
1530 meshMethod = "UseExistingFaces"
1531 ## type of algorithm used with helper function in smeshBuilder.Mesh class
1533 algoType = "UseExisting_2D"
1534 ## doc string of the method
1536 docHelper = "Creates 2D algorithm for faces with reusing of existing mesh elements"
1538 ## Private constructor.
1539 # @param mesh parent mesh object algorithm is assigned to
1540 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1541 # if it is @c 0 (default), the algorithm is assigned to the main shape
1542 def __init__(self, mesh, geom=0):
1543 self.Create(mesh, geom, self.algoType)
1546 pass # end of StdMeshersBuilder_UseExisting_2D class