Salome HOME
bf79aeb0372cc69fd6cc5891678f3db6867a97d3
[modules/smesh.git] / src / SMESH_SWIG / StdMeshersBuilder.py
1 # Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 ##
21 # @package StdMeshersBuilder
22 # Python API for the standard meshing plug-in module.
23
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
25 from salome.smesh.smeshBuilder import AssureGeomPublished, IsEqual, ParseParameters
26 from salome.smesh.smeshBuilder import GetName, TreatHypoStatus
27 from salome.smesh.smeshBuilder import Mesh
28
29 import StdMeshers
30
31 #----------------------------
32 # Mesh algo type identifiers
33 #----------------------------
34
35 ## Algorithm type: Regular 1D algorithm, see StdMeshersBuilder_Segment
36 REGULAR     = "Regular_1D"
37 ## Algorithm type: Python 1D algorithm, see StdMeshersBuilder_Segment_Python
38 PYTHON      = "Python_1D"
39 ## Algorithm type: Composite segment 1D algorithm, see StdMeshersBuilder_CompositeSegment
40 COMPOSITE   = "CompositeSegment_1D"
41 ## Algorithm type: Triangle MEFISTO 2D algorithm, see StdMeshersBuilder_Triangle_MEFISTO
42 MEFISTO     = "MEFISTO_2D"
43 ## Algorithm type: Hexahedron 3D (i-j-k) algorithm, see StdMeshersBuilder_Hexahedron
44 Hexa        = "Hexa_3D"
45 ## Algorithm type: Quadrangle 2D algorithm, see StdMeshersBuilder_Quadrangle
46 QUADRANGLE  = "Quadrangle_2D"
47 ## Algorithm type: Radial Quadrangle 1D-2D algorithm, see StdMeshersBuilder_RadialQuadrangle1D2D
48 RADIAL_QUAD = "RadialQuadrangle_1D2D"
49
50 # import items of enum QuadType
51 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
52
53 #----------------------
54 # Algorithms
55 #----------------------
56
57 ## Defines segment 1D algorithm for edges discretization.
58 #
59 #  It can be created by calling smesh.Mesh.Segment(geom=0)
60 #
61 #  @ingroup l3_algos_basic
62 class StdMeshersBuilder_Segment(Mesh_Algorithm):
63
64     ## name of the dynamic method in smesh.Mesh class
65     #  @internal
66     meshMethod = "Segment"
67     ## type of algorithm used with helper function in smesh.Mesh class
68     #  @internal
69     algoType   = REGULAR
70     ## flag pointing either this algorithm should be used by default in dynamic method
71     #  of smesh.Mesh class
72     #  @internal
73     isDefault  = True
74     ## doc string of the method
75     #  @internal
76     docHelper  = "Creates segment 1D algorithm for edges"
77
78     ## Private constructor.
79     #  @param mesh parent mesh object algorithm is assigned to
80     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
81     #              if it is @c 0 (default), the algorithm is assigned to the main shape
82     def __init__(self, mesh, geom=0):
83         Mesh_Algorithm.__init__(self)
84         self.Create(mesh, geom, self.algoType)
85         pass
86
87     ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
88     #  @param l for the length of segments that cut an edge
89     #  @param UseExisting if ==true - searches for an  existing hypothesis created with
90     #                    the same parameters, else (default) - creates a new one
91     #  @param p precision, used for calculation of the number of segments.
92     #           The precision should be a positive, meaningful value within the range [0,1].
93     #           In general, the number of segments is calculated with the formula:
94     #           nb = ceil((edge_length / l) - p)
95     #           Function ceil rounds its argument to the higher integer.
96     #           So, p=0 means rounding of (edge_length / l) to the higher integer,
97     #               p=0.5 means rounding of (edge_length / l) to the nearest integer,
98     #               p=1 means rounding of (edge_length / l) to the lower integer.
99     #           Default value is 1e-07.
100     #  @return an instance of StdMeshers_LocalLength hypothesis
101     #  @ingroup l3_hypos_1dhyps
102     def LocalLength(self, l, UseExisting=0, p=1e-07):
103         comFun=lambda hyp, args: IsEqual(hyp.GetLength(), args[0]) and IsEqual(hyp.GetPrecision(), args[1])
104         hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting, CompareMethod=comFun)
105         hyp.SetLength(l)
106         hyp.SetPrecision(p)
107         return hyp
108
109     ## Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
110     #  @param length is optional maximal allowed length of segment, if it is omitted
111     #                the preestimated length is used that depends on geometry size
112     #  @param UseExisting if ==true - searches for an existing hypothesis created with
113     #                     the same parameters, else (default) - creates a new one
114     #  @return an instance of StdMeshers_MaxLength hypothesis
115     #  @ingroup l3_hypos_1dhyps
116     def MaxSize(self, length=0.0, UseExisting=0):
117         hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
118         if length > 0.0:
119             # set given length
120             hyp.SetLength(length)
121         if not UseExisting:
122             # set preestimated length
123             gen = self.mesh.smeshpyD
124             initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
125                                                        self.mesh.GetMesh(), self.mesh.GetShape(),
126                                                        False) # <- byMesh
127             preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
128             if preHyp:
129                 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
130                 pass
131             pass
132         hyp.SetUsePreestimatedLength( length == 0.0 )
133         return hyp
134
135     ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
136     #  @param n for the number of segments that cut an edge
137     #  @param s for the scale factor (optional)
138     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
139     #                       A list item can also be a tuple (edge, 1st_vertex_of_edge)
140     #  @param UseExisting if ==true - searches for an existing hypothesis created with
141     #                     the same parameters, else (default) - create a new one
142     #  @return an instance of StdMeshers_NumberOfSegments hypothesis
143     #  @ingroup l3_hypos_1dhyps
144     def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
145         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
146             reversedEdges, UseExisting = [], reversedEdges
147         entry = self.MainShapeEntry()
148         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
149         if s == []:
150             hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
151                                   UseExisting=UseExisting,
152                                   CompareMethod=self._compareNumberOfSegments)
153         else:
154             hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
155                                   UseExisting=UseExisting,
156                                   CompareMethod=self._compareNumberOfSegments)
157             hyp.SetDistrType( 1 )
158             hyp.SetScaleFactor(s)
159         hyp.SetNumberOfSegments(n)
160         hyp.SetReversedEdges( reversedEdgeInd )
161         hyp.SetObjectEntry( entry )
162         return hyp
163
164     ## Private method
165     #  
166     #  Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
167     def _compareNumberOfSegments(self, hyp, args):
168         if hyp.GetNumberOfSegments() == args[0]:
169             if len(args) == 3:
170                 if hyp.GetReversedEdges() == args[1]:
171                     if not args[1] or hyp.GetObjectEntry() == args[2]:
172                         return True
173             else:
174                 if hyp.GetReversedEdges() == args[2]:
175                     if not args[2] or hyp.GetObjectEntry() == args[3]:
176                         if hyp.GetDistrType() == 1:
177                             if IsEqual(hyp.GetScaleFactor(), args[1]):
178                                 return True
179         return False
180
181     ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with increasing arithmetic length
182     #  @param start defines the length of the first segment
183     #  @param end   defines the length of the last  segment
184     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
185     #                       A list item can also be a tuple (edge, 1st_vertex_of_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_Arithmetic1D hypothesis
189     #  @ingroup l3_hypos_1dhyps
190     def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
191         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
192             reversedEdges, UseExisting = [], reversedEdges
193         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
194         entry = self.MainShapeEntry()
195         compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
196                                       IsEqual(hyp.GetLength(0), args[1]) and \
197                                       hyp.GetReversedEdges() == args[2]  and \
198                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
199         hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
200                               UseExisting=UseExisting, CompareMethod=compFun)
201         hyp.SetStartLength(start)
202         hyp.SetEndLength(end)
203         hyp.SetReversedEdges( reversedEdgeInd )
204         hyp.SetObjectEntry( entry )
205         return hyp
206
207     ## Defines "FixedPoints1D" hypothesis to cut an edge using parameter
208     # on curve from 0 to 1 (additionally it is neecessary to check
209     # orientation of edges and create list of reversed edges if it is
210     # needed) and sets numbers of segments between given points (default
211     # values are equals 1
212     #  @param points defines the list of parameters on curve
213     #  @param nbSegs defines the list of numbers of segments
214     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
215     #                       A list item can also be a tuple (edge, 1st_vertex_of_edge)
216     #  @param UseExisting if ==true - searches for an existing hypothesis created with
217     #                     the same parameters, else (default) - creates a new one
218     #  @return an instance of StdMeshers_Arithmetic1D hypothesis
219     #  @ingroup l3_hypos_1dhyps
220     def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
221         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
222             reversedEdges, UseExisting = [], reversedEdges
223         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
224         entry = self.MainShapeEntry()
225         compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
226                                       hyp.GetNbSegments() == args[1] and \
227                                       hyp.GetReversedEdges() == args[2] and \
228                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
229         hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
230                               UseExisting=UseExisting, CompareMethod=compFun)
231         hyp.SetPoints(points)
232         hyp.SetNbSegments(nbSegs)
233         hyp.SetReversedEdges(reversedEdgeInd)
234         hyp.SetObjectEntry(entry)
235         return hyp
236
237     ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
238     #  @param start defines the length of the first segment
239     #  @param end   defines the length of the last  segment
240     #  @param reversedEdges is a list of edges to mesh using reversed orientation.
241     #                       A list item can also be a tuple (edge, 1st_vertex_of_edge)
242     #  @param UseExisting if ==true - searches for an existing hypothesis created with
243     #                     the same parameters, else (default) - creates a new one
244     #  @return an instance of StdMeshers_StartEndLength hypothesis
245     #  @ingroup l3_hypos_1dhyps
246     def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
247         if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
248             reversedEdges, UseExisting = [], reversedEdges
249         reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
250         entry = self.MainShapeEntry()
251         compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
252                                       IsEqual(hyp.GetLength(0), args[1]) and \
253                                       hyp.GetReversedEdges() == args[2]  and \
254                                       (not args[2] or hyp.GetObjectEntry() == args[3]))
255         hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
256                               UseExisting=UseExisting, CompareMethod=compFun)
257         hyp.SetStartLength(start)
258         hyp.SetEndLength(end)
259         hyp.SetReversedEdges( reversedEdgeInd )
260         hyp.SetObjectEntry( entry )
261         return hyp
262
263     ## Defines "Deflection1D" hypothesis
264     #  @param d for the deflection
265     #  @param UseExisting if ==true - searches for an existing hypothesis created with
266     #                     the same parameters, else (default) - create a new one
267     #  @ingroup l3_hypos_1dhyps
268     def Deflection1D(self, d, UseExisting=0):
269         compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
270         hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
271         hyp.SetDeflection(d)
272         return hyp
273
274     ## Defines "Propagation" hypothesis that propagates all other hypotheses on all other edges that are at
275     #  the opposite side in case of quadrangular faces
276     #  @ingroup l3_hypos_additi
277     def Propagation(self):
278         return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
279
280     ## Defines "AutomaticLength" hypothesis
281     #  @param fineness for the fineness [0-1]
282     #  @param UseExisting if ==true - searches for an existing hypothesis created with the
283     #                     same parameters, else (default) - create a new one
284     #  @ingroup l3_hypos_1dhyps
285     def AutomaticLength(self, fineness=0, UseExisting=0):
286         compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
287         hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
288                               CompareMethod=compFun)
289         hyp.SetFineness( fineness )
290         return hyp
291
292     ## Defines "SegmentLengthAroundVertex" hypothesis
293     #  @param length for the segment length
294     #  @param vertex for the length localization: the vertex index [0,1] | vertex object.
295     #         Any other integer value means that the hypothesis will be set on the
296     #         whole 1D shape, where Mesh_Segment algorithm is assigned.
297     #  @param UseExisting if ==true - searches for an  existing hypothesis created with
298     #                   the same parameters, else (default) - creates a new one
299     #  @ingroup l3_algos_segmarv
300     def LengthNearVertex(self, length, vertex=0, UseExisting=0):
301         import types
302         store_geom = self.geom
303         if type(vertex) is types.IntType:
304             if vertex == 0 or vertex == 1:
305                 from salome.geom import geomBuilder
306                 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geomBuilder.ShapeType["VERTEX"],True)[vertex]
307                 self.geom = vertex
308                 pass
309             pass
310         else:
311             self.geom = vertex
312             pass
313         # 0D algorithm
314         if self.geom is None:
315             raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
316         AssureGeomPublished( self.mesh, self.geom )
317         name = GetName(self.geom)
318
319         algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
320         if algo is None:
321             algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
322             pass
323         status = self.mesh.mesh.AddHypothesis(self.geom, algo)
324         TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
325         #
326         comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
327         hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
328                               CompareMethod=comFun)
329         self.geom = store_geom
330         hyp.SetLength( length )
331         return hyp
332
333     ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
334     #  If the 2D mesher sees that all boundary edges are quadratic,
335     #  it generates quadratic faces, else it generates linear faces using
336     #  medium nodes as if they are vertices.
337     #  The 3D mesher generates quadratic volumes only if all boundary faces
338     #  are quadratic, else it fails.
339     #
340     #  @ingroup l3_hypos_additi
341     def QuadraticMesh(self):
342         hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
343         return hyp
344
345     pass # end of StdMeshersBuilder_Segment class
346
347 ## Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
348 #
349 #  It is created by calling smesh.Mesh.Segment(smesh.COMPOSITE,geom=0)
350 #
351 #  @ingroup l3_algos_basic
352 class StdMeshersBuilder_CompositeSegment(StdMeshersBuilder_Segment):
353
354     ## name of the dynamic method in smesh.Mesh class
355     #  @internal
356     meshMethod = "Segment"
357     ## type of algorithm used with helper function in smesh.Mesh class
358     #  @internal
359     algoType   = COMPOSITE
360     ## flag pointing either this algorithm should be used by default in dynamic method
361     #  of smesh.Mesh class
362     #  @internal
363     isDefault  = False
364     ## doc string of the method
365     #  @internal
366     docHelper  = "Creates segment 1D algorithm for edges"
367
368     ## Private constructor.
369     #  @param mesh parent mesh object algorithm is assigned to
370     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
371     #              if it is @c 0 (default), the algorithm is assigned to the main shape
372     def __init__(self, mesh, geom=0):
373         self.Create(mesh, geom, self.algoType)
374         pass
375
376     pass # end of StdMeshersBuilder_CompositeSegment class
377
378 ## Defines a segment 1D algorithm for discretization of edges with Python function
379 #
380 #  It is created by calling smesh.Mesh.Segment(smesh.PYTHON,geom=0)
381 #
382 #  @ingroup l3_algos_basic
383 class StdMeshersBuilder_Segment_Python(Mesh_Algorithm):
384
385     ## name of the dynamic method in smesh.Mesh class
386     #  @internal
387     meshMethod = "Segment"
388     ## type of algorithm used with helper function in smesh.Mesh class
389     #  @internal
390     algoType   = PYTHON
391     ## doc string of the method
392     #  @internal
393     docHelper  = "Creates tetrahedron 3D algorithm for solids"
394     ## doc string of the method
395     #  @internal
396     docHelper  = "Creates segment 1D algorithm for edges"
397
398     ## Private constructor.
399     #  @param mesh parent mesh object algorithm is assigned to
400     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
401     #              if it is @c 0 (default), the algorithm is assigned to the main shape
402     def __init__(self, mesh, geom=0):
403         import Python1dPlugin
404         self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
405         pass
406
407     ## Defines "PythonSplit1D" hypothesis
408     #  @param n for the number of segments that cut an edge
409     #  @param func for the python function that calculates the length of all segments
410     #  @param UseExisting if ==true - searches for the existing hypothesis created with
411     #                     the same parameters, else (default) - creates a new one
412     #  @ingroup l3_hypos_1dhyps
413     def PythonSplit1D(self, n, func, UseExisting=0):
414         compFun = lambda hyp, args: False
415         hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
416                               UseExisting=UseExisting, CompareMethod=compFun)
417         hyp.SetNumberOfSegments(n)
418         hyp.SetPythonLog10RatioFunction(func)
419         return hyp
420
421     pass # end of StdMeshersBuilder_Segment_Python class
422
423 ## Triangle MEFISTO 2D algorithm
424 #
425 #  It is created by calling smesh.Mesh.Triangle(smesh.MEFISTO,geom=0)
426 #
427 #  @ingroup l3_algos_basic
428 class StdMeshersBuilder_Triangle_MEFISTO(Mesh_Algorithm):
429
430     ## name of the dynamic method in smesh.Mesh class
431     #  @internal
432     meshMethod = "Triangle"
433     ## type of algorithm used with helper function in smesh.Mesh class
434     #  @internal
435     algoType   = MEFISTO
436     ## flag pointing either this algorithm should be used by default in dynamic method
437     #  of smesh.Mesh class
438     #  @internal
439     isDefault  = True
440     ## doc string of the method
441     #  @internal
442     docHelper  = "Creates triangle 2D algorithm for faces"
443
444     ## Private constructor.
445     #  @param mesh parent mesh object algorithm is assigned to
446     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
447     #              if it is @c 0 (default), the algorithm is assigned to the main shape
448     def __init__(self, mesh, geom=0):
449         Mesh_Algorithm.__init__(self)
450         self.Create(mesh, geom, self.algoType)
451         pass
452
453     ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
454     #  @param area for the maximum area of each triangle
455     #  @param UseExisting if ==true - searches for an  existing hypothesis created with the
456     #                     same parameters, else (default) - creates a new one
457     #
458     #  @ingroup l3_hypos_2dhyps
459     def MaxElementArea(self, area, UseExisting=0):
460         comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
461         hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
462                               CompareMethod=comparator)
463         hyp.SetMaxElementArea(area)
464         return hyp
465
466     ## Defines "LengthFromEdges" hypothesis to build triangles
467     #  based on the length of the edges taken from the wire
468     #
469     #  @ingroup l3_hypos_2dhyps
470     def LengthFromEdges(self):
471         hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
472         return hyp
473
474     pass # end of StdMeshersBuilder_Triangle_MEFISTO class
475
476 ## Defines a quadrangle 2D algorithm
477
478 #  It is created by calling smesh.Mesh.Quadrangle(geom=0)
479 #
480 #  @ingroup l3_algos_basic
481 class StdMeshersBuilder_Quadrangle(Mesh_Algorithm):
482
483     ## name of the dynamic method in smesh.Mesh class
484     #  @internal
485     meshMethod = "Quadrangle"
486     ## type of algorithm used with helper function in smesh.Mesh class
487     #  @internal
488     algoType   = QUADRANGLE
489     ## flag pointing either this algorithm should be used by default in dynamic method
490     #  of smesh.Mesh class
491     #  @internal
492     isDefault  = True
493     ## doc string of the method
494     #  @internal
495     docHelper  = "Creates quadrangle 2D algorithm for faces"
496     ## hypothesis associated with algorithm
497     #  @internal
498     params     = 0
499
500     ## Private constructor.
501     #  @param mesh parent mesh object algorithm is assigned to
502     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
503     #              if it is @c 0 (default), the algorithm is assigned to the main shape
504     def __init__(self, mesh, geom=0):
505         Mesh_Algorithm.__init__(self)
506         self.Create(mesh, geom, self.algoType)
507         pass
508
509     ## Defines "QuadrangleParameters" hypothesis
510     #  @param quadType defines the algorithm of transition between differently descretized
511     #                  sides of a geometrical face:
512     #  - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
513     #                    area along the finer meshed sides.
514     #  - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
515     #                    finer meshed sides.
516     #  - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
517     #                    the finer meshed sides, iff the total quantity of segments on
518     #                    all four sides of the face is even (divisible by 2).
519     #  - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
520     #                    area is located along the coarser meshed sides.
521     #  - QUAD_REDUCED - only quadrangles are built and the transition between the sides
522     #                    is made gradually, layer by layer. This type has a limitation on
523     #                    the number of segments: one pair of opposite sides must have the
524     #                    same number of segments, the other pair must have an even difference
525     #                    between the numbers of segments on the sides.
526     #  @param triangleVertex: vertex of a trilateral geometrical face, around which triangles
527     #                  will be created while other elements will be quadrangles.
528     #                  Vertex can be either a GEOM_Object or a vertex ID within the
529     #                  shape to mesh
530     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
531     #                  the same parameters, else (default) - creates a new one
532     #  @ingroup l3_hypos_quad
533     def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0, UseExisting=0):
534         import GEOM
535         vertexID = triangleVertex
536         if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
537             vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
538         if not self.params:
539             compFun = lambda hyp,args: \
540                       hyp.GetQuadType() == args[0] and \
541                       ( hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1))
542             self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID],
543                                           UseExisting = UseExisting, CompareMethod=compFun)
544             pass
545         if self.params.GetQuadType() != quadType:
546             self.params.SetQuadType(quadType)
547         if vertexID > 0:
548             self.params.SetTriaVertex( vertexID )
549         return self.params
550
551     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
552     #   quadrangles are built in the transition area along the finer meshed sides,
553     #   iff the total quantity of segments on all four sides of the face is even.
554     #  @param reversed if True, transition area is located along the coarser meshed sides.
555     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
556     #                  the same parameters, else (default) - creates a new one
557     #  @ingroup l3_hypos_quad
558     def QuadranglePreference(self, reversed=False, UseExisting=0):
559         if reversed:
560             return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
561         return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
562
563     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
564     #   triangles are built in the transition area along the finer meshed sides.
565     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
566     #                  the same parameters, else (default) - creates a new one
567     #  @ingroup l3_hypos_quad
568     def TrianglePreference(self, UseExisting=0):
569         return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
570
571     ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
572     #   quadrangles are built and the transition between the sides is made gradually,
573     #   layer by layer. This type has a limitation on the number of segments: one pair
574     #   of opposite sides must have the same number of segments, the other pair must
575     #   have an even difference between the numbers of segments on the sides.
576     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
577     #                  the same parameters, else (default) - creates a new one
578     #  @ingroup l3_hypos_quad
579     def Reduced(self, UseExisting=0):
580         return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
581
582     ## Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
583     #  @param vertex: vertex of a trilateral geometrical face, around which triangles
584     #                 will be created while other elements will be quadrangles.
585     #                 Vertex can be either a GEOM_Object or a vertex ID within the
586     #                 shape to mesh
587     #  @param UseExisting: if ==true - searches for the existing hypothesis created with
588     #                   the same parameters, else (default) - creates a new one
589     #  @ingroup l3_hypos_quad
590     def TriangleVertex(self, vertex, UseExisting=0):
591         return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
592
593     pass # end of StdMeshersBuilder_Quadrangle class
594
595 ## Defines a hexahedron 3D algorithm
596
597 #  It is created by calling smesh.Mesh.Hexahedron(geom=0)
598 #
599 #  @ingroup l3_algos_basic
600 class StdMeshersBuilder_Hexahedron(Mesh_Algorithm):
601
602     ## name of the dynamic method in smesh.Mesh class
603     #  @internal
604     meshMethod = "Hexahedron"
605     ## type of algorithm used with helper function in smesh.Mesh class
606     #  @internal
607     algoType   = Hexa
608     ## flag pointing either this algorithm should be used by default in dynamic method
609     #  of smesh.Mesh class
610     #  @internal
611     isDefault  = True
612     ## doc string of the method
613     #  @internal
614     docHelper  = "Creates hexahedron 3D algorithm for volumes"
615
616     ## Private constructor.
617     #  @param mesh parent mesh object algorithm is assigned to
618     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
619     #              if it is @c 0 (default), the algorithm is assigned to the main shape
620     def __init__(self, mesh, geom=0):
621         Mesh_Algorithm.__init__(self)
622         self.Create(mesh, geom, Hexa)
623         pass
624
625     pass # end of StdMeshersBuilder_Hexahedron class
626
627 ## Defines a projection 1D algorithm
628 #  
629 #  It is created by calling smesh.Mesh.Projection1D(geom=0)
630 #
631 #  @ingroup l3_algos_proj
632 class StdMeshersBuilder_Projection1D(Mesh_Algorithm):
633
634     ## name of the dynamic method in smesh.Mesh class
635     #  @internal
636     meshMethod = "Projection1D"
637     ## type of algorithm used with helper function in smesh.Mesh class
638     #  @internal
639     algoType   = "Projection_1D"
640     ## flag pointing either this algorithm should be used by default in dynamic method
641     #  of smesh.Mesh class
642     #  @internal
643     isDefault  = True
644     ## doc string of the method
645     #  @internal
646     docHelper  = "Creates projection 1D algorithm for edges"
647
648     ## Private constructor.
649     #  @param mesh parent mesh object algorithm is assigned to
650     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
651     #              if it is @c 0 (default), the algorithm is assigned to the main shape
652     def __init__(self, mesh, geom=0):
653         Mesh_Algorithm.__init__(self)
654         self.Create(mesh, geom, self.algoType)
655         pass
656
657     ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
658     #  a mesh pattern is taken, and, optionally, the association of vertices
659     #  between the source edge and a target edge (to which a hypothesis is assigned)
660     #  @param edge from which nodes distribution is taken
661     #  @param mesh from which nodes distribution is taken (optional)
662     #  @param srcV a vertex of \a edge to associate with \a tgtV (optional)
663     #  @param tgtV a vertex of \a the edge to which the algorithm is assigned,
664     #  to associate with \a srcV (optional)
665     #  @param UseExisting if ==true - searches for the existing hypothesis created with
666     #                     the same parameters, else (default) - creates a new one
667     def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
668         AssureGeomPublished( self.mesh, edge )
669         AssureGeomPublished( self.mesh, srcV )
670         AssureGeomPublished( self.mesh, tgtV )
671         hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
672                               UseExisting=0)
673         # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
674                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
675         hyp.SetSourceEdge( edge )
676         if not mesh is None and isinstance(mesh, Mesh):
677             mesh = mesh.GetMesh()
678         hyp.SetSourceMesh( mesh )
679         hyp.SetVertexAssociation( srcV, tgtV )
680         return hyp
681
682     pass # end of StdMeshersBuilder_Projection1D class
683
684 ## Defines a projection 2D algorithm
685 #  
686 #  It is created by calling smesh.Mesh.Projection2D(geom=0)
687 #
688 #  @ingroup l3_algos_proj
689 class StdMeshersBuilder_Projection2D(Mesh_Algorithm):
690
691     ## name of the dynamic method in smesh.Mesh class
692     #  @internal
693     meshMethod = "Projection2D"
694     ## type of algorithm used with helper function in smesh.Mesh class
695     #  @internal
696     algoType   = "Projection_2D"
697     ## flag pointing either this algorithm should be used by default in dynamic method
698     #  of smesh.Mesh class
699     #  @internal
700     isDefault  = True
701     ## doc string of the method
702     #  @internal
703     docHelper  = "Creates projection 2D algorithm for faces"
704
705     ## Private constructor.
706     #  @param mesh parent mesh object algorithm is assigned to
707     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
708     #              if it is @c 0 (default), the algorithm is assigned to the main shape
709     def __init__(self, mesh, geom=0):
710         Mesh_Algorithm.__init__(self)
711         self.Create(mesh, geom, self.algoType)
712         pass
713
714     ## Defines "Source Face" hypothesis, specifying a meshed face, from where
715     #  a mesh pattern is taken, and, optionally, the association of vertices
716     #  between the source face and the target face (to which a hypothesis is assigned)
717     #  @param face from which the mesh pattern is taken
718     #  @param mesh from which the mesh pattern is taken (optional)
719     #  @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
720     #  @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
721     #               to associate with \a srcV1 (optional)
722     #  @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
723     #  @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
724     #               to associate with \a srcV2 (optional)
725     #  @param UseExisting if ==true - forces the search for the existing hypothesis created with
726     #                     the same parameters, else (default) - forces the creation a new one
727     #
728     #  Note: all association vertices must belong to one edge of a face
729     def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
730                    srcV2=None, tgtV2=None, UseExisting=0):
731         from salome.smesh.smeshBuilder import Mesh
732         if isinstance(mesh, Mesh):
733             mesh = mesh.GetMesh()
734         for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
735             AssureGeomPublished( self.mesh, geom )
736         hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
737                               UseExisting=0)
738         # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
739                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
740         hyp.SetSourceFace( face )
741         hyp.SetSourceMesh( mesh )
742         hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
743         return hyp
744
745     pass # end of StdMeshersBuilder_Projection2D class
746
747 ## Defines a projection 1D-2D algorithm
748 #  
749 #  It is created by calling smesh.Mesh.Projection1D2D(geom=0)
750 #
751 #  @ingroup l3_algos_proj
752 class StdMeshersBuilder_Projection1D2D(StdMeshersBuilder_Projection2D):
753
754     ## name of the dynamic method in smesh.Mesh class
755     #  @internal
756     meshMethod = "Projection1D2D"
757     ## type of algorithm used with helper function in smesh.Mesh class
758     #  @internal
759     algoType   = "Projection_1D2D"
760     ## doc string of the method
761     #  @internal
762     docHelper  = "Creates projection 1D-2D algorithm for edges and faces"
763
764     ## Private constructor.
765     #  @param mesh parent mesh object algorithm is assigned to
766     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
767     #              if it is @c 0 (default), the algorithm is assigned to the main shape
768     def __init__(self, mesh, geom=0):
769         StdMeshersBuilder_Projection2D.__init__(self, mesh, geom)
770         pass
771
772     pass # end of StdMeshersBuilder_Projection1D2D class
773
774 ## Defines a projection 3D algorithm
775
776 #  It is created by calling smesh.Mesh.Projection3D(geom=0)
777 #
778 #  @ingroup l3_algos_proj
779 class StdMeshersBuilder_Projection3D(Mesh_Algorithm):
780
781     ## name of the dynamic method in smesh.Mesh class
782     #  @internal
783     meshMethod = "Projection3D"
784     ## type of algorithm used with helper function in smesh.Mesh class
785     #  @internal
786     algoType   = "Projection_3D"
787     ## doc string of the method
788     #  @internal
789     docHelper  = "Creates projection 3D algorithm for volumes"
790
791     ## Private constructor.
792     #  @param mesh parent mesh object algorithm is assigned to
793     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
794     #              if it is @c 0 (default), the algorithm is assigned to the main shape
795     def __init__(self, mesh, geom=0):
796         Mesh_Algorithm.__init__(self)
797         self.Create(mesh, geom, self.algoType)
798         pass
799
800     ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
801     #  the mesh pattern is taken, and, optionally, the  association of vertices
802     #  between the source and the target solid  (to which a hipothesis is assigned)
803     #  @param solid from where the mesh pattern is taken
804     #  @param mesh from where the mesh pattern is taken (optional)
805     #  @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
806     #  @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
807     #  to associate with \a srcV1 (optional)
808     #  @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
809     #  @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
810     #  to associate with \a srcV2 (optional)
811     #  @param UseExisting - if ==true - searches for the existing hypothesis created with
812     #                     the same parameters, else (default) - creates a new one
813     #
814     #  Note: association vertices must belong to one edge of a solid
815     def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
816                       srcV2=0, tgtV2=0, UseExisting=0):
817         for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
818             AssureGeomPublished( self.mesh, geom )
819         hyp = self.Hypothesis("ProjectionSource3D",
820                               [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
821                               UseExisting=0)
822         # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
823                               #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
824         hyp.SetSource3DShape( solid )
825         if isinstance(mesh, Mesh):
826             mesh = mesh.GetMesh()
827         if mesh:
828             hyp.SetSourceMesh( mesh )
829         if srcV1 and srcV2 and tgtV1 and tgtV2:
830             hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
831         #elif srcV1 or srcV2 or tgtV1 or tgtV2:
832         return hyp
833
834     pass # end of StdMeshersBuilder_Projection3D class
835
836 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
837 #  depending on geometry
838
839 #  It is created by calling smesh.Mesh.Prism(geom=0)
840 #
841 #  @ingroup l3_algos_3dextr
842 class StdMeshersBuilder_Prism3D(Mesh_Algorithm):
843
844     ## name of the dynamic method in smesh.Mesh class
845     #  @internal
846     meshMethod = "Prism"
847     ## type of algorithm used with helper function in smesh.Mesh class
848     #  @internal
849     algoType   = "Prism_3D"
850     ## doc string of the method
851     #  @internal
852     docHelper  = "Creates prism 3D algorithm for volumes"
853
854     ## Private constructor.
855     #  @param mesh parent mesh object algorithm is assigned to
856     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
857     #              if it is @c 0 (default), the algorithm is assigned to the main shape
858     def __init__(self, mesh, geom=0):
859         Mesh_Algorithm.__init__(self)
860         
861         shape = geom
862         if not shape:
863             shape = mesh.geom
864         from geompy import SubShapeAll, ShapeType
865         nbSolids = len( SubShapeAll( shape, ShapeType["SOLID"] ))
866         nbShells = len( SubShapeAll( shape, ShapeType["SHELL"] ))
867         if nbSolids == 0 or nbSolids == nbShells:
868             self.Create(mesh, geom, "Prism_3D")
869             pass
870         else:
871             self.algoType = "RadialPrism_3D"
872             self.Create(mesh, geom, "RadialPrism_3D")
873             self.distribHyp = None #self.Hypothesis("LayerDistribution", UseExisting=0)
874             self.nbLayers = None
875             pass
876         pass
877
878     ## Return 3D hypothesis holding the 1D one
879     def Get3DHypothesis(self):
880         if self.algoType != "RadialPrism_3D":
881             print "Prism_3D algorith doesn't support any hyposesis"
882             return None
883         return self.distribHyp
884
885     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
886     #  hypothesis. Returns the created hypothesis
887     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
888         if self.algoType != "RadialPrism_3D":
889             print "Prism_3D algorith doesn't support any hyposesis"
890             return None
891         if not self.nbLayers is None:
892             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
893             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
894         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
895         self.mesh.smeshpyD.SetCurrentStudy( None )
896         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
897         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
898         if not self.distribHyp:
899             self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
900         self.distribHyp.SetLayerDistribution( hyp )
901         return hyp
902
903     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
904     #  prisms to build between the inner and outer shells
905     #  @param n number of layers
906     #  @param UseExisting if ==true - searches for the existing hypothesis created with
907     #                     the same parameters, else (default) - creates a new one
908     def NumberOfLayers(self, n, UseExisting=0):
909         if self.algoType != "RadialPrism_3D":
910             print "Prism_3D algorith doesn't support any hyposesis"
911             return None
912         self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
913         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
914         self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
915                                         CompareMethod=compFun)
916         self.nbLayers.SetNumberOfLayers( n )
917         return self.nbLayers
918
919     ## Defines "LocalLength" hypothesis, specifying the segment length
920     #  to build between the inner and the outer shells
921     #  @param l the length of segments
922     #  @param p the precision of rounding
923     def LocalLength(self, l, p=1e-07):
924         if self.algoType != "RadialPrism_3D":
925             print "Prism_3D algorith doesn't support any hyposesis"
926             return None
927         hyp = self.OwnHypothesis("LocalLength", [l,p])
928         hyp.SetLength(l)
929         hyp.SetPrecision(p)
930         return hyp
931
932     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
933     #  prisms to build between the inner and the outer shells.
934     #  @param n the number of layers
935     #  @param s the scale factor (optional)
936     def NumberOfSegments(self, n, s=[]):
937         if self.algoType != "RadialPrism_3D":
938             print "Prism_3D algorith doesn't support any hyposesis"
939             return None
940         if s == []:
941             hyp = self.OwnHypothesis("NumberOfSegments", [n])
942         else:
943             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
944             hyp.SetDistrType( 1 )
945             hyp.SetScaleFactor(s)
946         hyp.SetNumberOfSegments(n)
947         return hyp
948
949     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
950     #  to build between the inner and the outer shells with a length that changes in arithmetic progression
951     #  @param start  the length of the first segment
952     #  @param end    the length of the last  segment
953     def Arithmetic1D(self, start, end ):
954         if self.algoType != "RadialPrism_3D":
955             print "Prism_3D algorith doesn't support any hyposesis"
956             return None
957         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
958         hyp.SetLength(start, 1)
959         hyp.SetLength(end  , 0)
960         return hyp
961
962     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
963     #  to build between the inner and the outer shells as geometric length increasing
964     #  @param start for the length of the first segment
965     #  @param end   for the length of the last  segment
966     def StartEndLength(self, start, end):
967         if self.algoType != "RadialPrism_3D":
968             print "Prism_3D algorith doesn't support any hyposesis"
969             return None
970         hyp = self.OwnHypothesis("StartEndLength", [start, end])
971         hyp.SetLength(start, 1)
972         hyp.SetLength(end  , 0)
973         return hyp
974
975     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
976     #  to build between the inner and outer shells
977     #  @param fineness defines the quality of the mesh within the range [0-1]
978     def AutomaticLength(self, fineness=0):
979         if self.algoType != "RadialPrism_3D":
980             print "Prism_3D algorith doesn't support any hyposesis"
981             return None
982         hyp = self.OwnHypothesis("AutomaticLength")
983         hyp.SetFineness( fineness )
984         return hyp
985
986     pass # end of StdMeshersBuilder_Prism3D class
987
988 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
989 #  depending on geometry
990
991 #  It is created by calling smesh.Mesh.Prism(geom=0)
992 #
993 #  @ingroup l3_algos_3dextr
994 class StdMeshersBuilder_RadialPrism3D(StdMeshersBuilder_Prism3D):
995
996     ## name of the dynamic method in smesh.Mesh class
997     #  @internal
998     meshMethod = "Prism"
999     ## type of algorithm used with helper function in smesh.Mesh class
1000     #  @internal
1001     algoType   = "RadialPrism_3D"
1002     ## doc string of the method
1003     #  @internal
1004     docHelper  = "Creates prism 3D algorithm for volumes"
1005
1006     ## Private constructor.
1007     #  @param mesh parent mesh object algorithm is assigned to
1008     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1009     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1010     def __init__(self, mesh, geom=0):
1011         Mesh_Algorithm.__init__(self)
1012         
1013         shape = geom
1014         if not shape:
1015             shape = mesh.geom
1016         self.Create(mesh, geom, "RadialPrism_3D")
1017         self.distribHyp = None
1018         self.nbLayers = None
1019         return
1020
1021 ## Defines a Radial Quadrangle 1D-2D algorithm
1022
1023 #  It is created by calling smesh.Mesh.Quadrangle(smesh.RADIAL_QUAD,geom=0)
1024 #
1025 #  @ingroup l2_algos_radialq
1026 class StdMeshersBuilder_RadialQuadrangle1D2D(Mesh_Algorithm):
1027
1028     ## name of the dynamic method in smesh.Mesh class
1029     #  @internal
1030     meshMethod = "Quadrangle"
1031     ## type of algorithm used with helper function in smesh.Mesh class
1032     #  @internal
1033     algoType   = RADIAL_QUAD
1034     ## doc string of the method
1035     #  @internal
1036     docHelper  = "Creates quadrangle 1D-2D algorithm for triangular faces"
1037
1038     ## Private constructor.
1039     #  @param mesh parent mesh object algorithm is assigned to
1040     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1041     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1042     def __init__(self, mesh, geom=0):
1043         Mesh_Algorithm.__init__(self)
1044         self.Create(mesh, geom, self.algoType)
1045
1046         self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
1047         self.nbLayers = None
1048         pass
1049
1050     ## Return 2D hypothesis holding the 1D one
1051     def Get2DHypothesis(self):
1052         if not self.distribHyp:
1053             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1054         return self.distribHyp
1055
1056     ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
1057     #  hypothesis. Returns the created hypothesis
1058     def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
1059         if self.nbLayers:
1060             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
1061         if self.distribHyp is None:
1062             self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
1063         else:
1064             self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
1065         study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
1066         self.mesh.smeshpyD.SetCurrentStudy( None )
1067         hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
1068         self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
1069         self.distribHyp.SetLayerDistribution( hyp )
1070         return hyp
1071
1072     ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
1073     #  @param n number of layers
1074     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1075     #                     the same parameters, else (default) - creates a new one
1076     def NumberOfLayers(self, n, UseExisting=0):
1077         if self.distribHyp:
1078             self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1079         compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1080         self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1081                                         CompareMethod=compFun)
1082         self.nbLayers.SetNumberOfLayers( n )
1083         return self.nbLayers
1084
1085     ## Defines "LocalLength" hypothesis, specifying the segment length
1086     #  @param l the length of segments
1087     #  @param p the precision of rounding
1088     def LocalLength(self, l, p=1e-07):
1089         hyp = self.OwnHypothesis("LocalLength", [l,p])
1090         hyp.SetLength(l)
1091         hyp.SetPrecision(p)
1092         return hyp
1093
1094     ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
1095     #  @param n the number of layers
1096     #  @param s the scale factor (optional)
1097     def NumberOfSegments(self, n, s=[]):
1098         if s == []:
1099             hyp = self.OwnHypothesis("NumberOfSegments", [n])
1100         else:
1101             hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1102             hyp.SetDistrType( 1 )
1103             hyp.SetScaleFactor(s)
1104         hyp.SetNumberOfSegments(n)
1105         return hyp
1106
1107     ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1108     #  with a length that changes in arithmetic progression
1109     #  @param start  the length of the first segment
1110     #  @param end    the length of the last  segment
1111     def Arithmetic1D(self, start, end ):
1112         hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1113         hyp.SetLength(start, 1)
1114         hyp.SetLength(end  , 0)
1115         return hyp
1116
1117     ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1118     #  as geometric length increasing
1119     #  @param start for the length of the first segment
1120     #  @param end   for the length of the last  segment
1121     def StartEndLength(self, start, end):
1122         hyp = self.OwnHypothesis("StartEndLength", [start, end])
1123         hyp.SetLength(start, 1)
1124         hyp.SetLength(end  , 0)
1125         return hyp
1126
1127     ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1128     #  @param fineness defines the quality of the mesh within the range [0-1]
1129     def AutomaticLength(self, fineness=0):
1130         hyp = self.OwnHypothesis("AutomaticLength")
1131         hyp.SetFineness( fineness )
1132         return hyp
1133
1134     pass # end of StdMeshersBuilder_RadialQuadrangle1D2D class
1135
1136 ## Defines a Use Existing Elements 1D algorithm
1137 #
1138 #  It is created by calling smesh.Mesh.UseExisting1DElements(geom=0)
1139 #
1140 #  @ingroup l3_algos_basic
1141 class StdMeshersBuilder_UseExistingElements_1D(Mesh_Algorithm):
1142
1143     ## name of the dynamic method in smesh.Mesh class
1144     #  @internal
1145     meshMethod = "UseExisting1DElements"
1146     ## type of algorithm used with helper function in smesh.Mesh class
1147     #  @internal
1148     algoType   = "Import_1D"
1149     ## flag pointing either this algorithm should be used by default in dynamic method
1150     #  of smesh.Mesh class
1151     #  @internal
1152     isDefault  = True
1153     ## doc string of the method
1154     #  @internal
1155     docHelper  = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1156
1157     ## Private constructor.
1158     #  @param mesh parent mesh object algorithm is assigned to
1159     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1160     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1161     def __init__(self, mesh, geom=0):
1162         Mesh_Algorithm.__init__(self)
1163         self.Create(mesh, geom, self.algoType)
1164         pass
1165
1166     ## Defines "Source edges" hypothesis, specifying groups of edges to import
1167     #  @param groups list of groups of edges
1168     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1169     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1170     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1171     #                     the same parameters, else (default) - creates a new one
1172     def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1173         for group in groups:
1174             AssureGeomPublished( self.mesh, group )
1175         compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1176                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1177         hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1178                               UseExisting=UseExisting, CompareMethod=compFun)
1179         hyp.SetSourceEdges(groups)
1180         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1181         return hyp
1182
1183     pass # end of StdMeshersBuilder_UseExistingElements_1D class
1184
1185 ## Defines a Use Existing Elements 1D-2D algorithm
1186 #
1187 #  It is created by calling smesh.Mesh.UseExisting2DElements(geom=0)
1188 #
1189 #  @ingroup l3_algos_basic
1190 class StdMeshersBuilder_UseExistingElements_1D2D(Mesh_Algorithm):
1191
1192     ## name of the dynamic method in smesh.Mesh class
1193     #  @internal
1194     meshMethod = "UseExisting2DElements"
1195     ## type of algorithm used with helper function in smesh.Mesh class
1196     #  @internal
1197     algoType   = "Import_1D2D"
1198     ## flag pointing either this algorithm should be used by default in dynamic method
1199     #  of smesh.Mesh class
1200     #  @internal
1201     isDefault  = True
1202     ## doc string of the method
1203     #  @internal
1204     docHelper  = "Creates 1D-2D algorithm for edges/faces with reusing of existing mesh elements"
1205
1206     ## Private constructor.
1207     #  @param mesh parent mesh object algorithm is assigned to
1208     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1209     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1210     def __init__(self, mesh, geom=0):
1211         Mesh_Algorithm.__init__(self)
1212         self.Create(mesh, geom, self.algoType)
1213         pass
1214
1215     ## Defines "Source faces" hypothesis, specifying groups of faces to import
1216     #  @param groups list of groups of faces
1217     #  @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1218     #  @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1219     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1220     #                     the same parameters, else (default) - creates a new one
1221     def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1222         for group in groups:
1223             AssureGeomPublished( self.mesh, group )
1224         compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1225                                       hyp.GetCopySourceMesh() == args[1], args[2] )
1226         hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1227                               UseExisting=UseExisting, CompareMethod=compFun)
1228         hyp.SetSourceFaces(groups)
1229         hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1230         return hyp
1231
1232     pass # end of StdMeshersBuilder_UseExistingElements_1D2D class
1233
1234 ## Defines a Body Fitting 3D algorithm
1235 #
1236 #  It is created by calling smesh.Mesh.BodyFitted(geom=0)
1237 #
1238 #  @ingroup l3_algos_basic
1239 class StdMeshersBuilder_Cartesian_3D(Mesh_Algorithm):
1240
1241     ## name of the dynamic method in smesh.Mesh class
1242     #  @internal
1243     meshMethod = "BodyFitted"
1244     ## type of algorithm used with helper function in smesh.Mesh class
1245     #  @internal
1246     algoType   = "Cartesian_3D"
1247     ## flag pointing either this algorithm should be used by default in dynamic method
1248     #  of smesh.Mesh class
1249     #  @internal
1250     isDefault  = True
1251     ## doc string of the method
1252     #  @internal
1253     docHelper  = "Creates body fitting 3D algorithm for volumes"
1254
1255     ## Private constructor.
1256     #  @param mesh parent mesh object algorithm is assigned to
1257     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1258     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1259     def __init__(self, mesh, geom=0):
1260         self.Create(mesh, geom, self.algoType)
1261         self.hyp = None
1262         pass
1263
1264     ## Defines "Body Fitting parameters" hypothesis
1265     #  @param xGridDef is definition of the grid along the X asix.
1266     #  It can be in either of two following forms:
1267     #  - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1268     #  - Functions f(t) defining grid spacing at each point on grid axis. If there are
1269     #    several functions, they must be accompanied by relative coordinates of
1270     #    points dividing the whole shape into ranges where the functions apply; points
1271     #    coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1272     #    function f(t) varies from 0.0 to 1.0 witin a shape range. 
1273     #    Examples:
1274     #    - "10.5" - defines a grid with a constant spacing
1275     #    - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1276     #  @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does
1277     #  @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does
1278     #  @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1279     #         a polyhedron of size less than hexSize/sizeThreshold is not created
1280     #  @param UseExisting if ==true - searches for the existing hypothesis created with
1281     #                     the same parameters, else (default) - creates a new one
1282     def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, UseExisting=False):
1283         if not self.hyp:
1284             compFun = lambda hyp, args: False
1285             self.hyp = self.Hypothesis("CartesianParameters3D",
1286                                        [xGridDef, yGridDef, zGridDef, sizeThreshold],
1287                                        UseExisting=UseExisting, CompareMethod=compFun)
1288         if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1289             self.mesh.AddHypothesis( self.hyp, self.geom )
1290
1291         for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef]):
1292             if not gridDef: raise ValueError, "Empty grid definition"
1293             if isinstance( gridDef, str ):
1294                 self.hyp.SetGridSpacing( [gridDef], [], axis )
1295             elif isinstance( gridDef[0], str ):
1296                 self.hyp.SetGridSpacing( gridDef, [], axis )
1297             elif isinstance( gridDef[0], int ) or \
1298                  isinstance( gridDef[0], float ):
1299                 self.hyp.SetGrid(gridDef, axis )
1300             else:
1301                 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1302         self.hyp.SetSizeThreshold( sizeThreshold )
1303         return self.hyp
1304
1305     pass # end of StdMeshersBuilder_Cartesian_3D class
1306
1307 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1308 #  segments usable by 2D algoritms
1309 #
1310 #  It is created by calling smesh.Mesh.UseExistingSegments(geom=0)
1311 #
1312 #  @ingroup l3_algos_basic
1313 class StdMeshersBuilder_UseExisting_1D(Mesh_Algorithm):
1314
1315     ## name of the dynamic method in smesh.Mesh class
1316     #  @internal
1317     meshMethod = "UseExistingSegments"
1318     ## type of algorithm used with helper function in smesh.Mesh class
1319     #  @internal
1320     algoType   = "UseExisting_1D"
1321     ## doc string of the method
1322     #  @internal
1323     docHelper  = "Creates 1D algorithm for edges with reusing of existing mesh elements"
1324
1325     ## Private constructor.
1326     #  @param mesh parent mesh object algorithm is assigned to
1327     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1328     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1329     def __init__(self, mesh, geom=0):
1330         self.Create(mesh, geom, self.algoType)
1331         pass
1332
1333     pass # end of StdMeshersBuilder_UseExisting_1D class
1334
1335 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1336 #  faces usable by 3D algoritms
1337 #
1338 #  It is created by calling smesh.Mesh.UseExistingFaces(geom=0)
1339 #
1340 #  @ingroup l3_algos_basic
1341 class StdMeshersBuilder_UseExisting_2D(Mesh_Algorithm):
1342
1343     ## name of the dynamic method in smesh.Mesh class
1344     #  @internal
1345     meshMethod = "UseExistingFaces"
1346     ## type of algorithm used with helper function in smesh.Mesh class
1347     #  @internal
1348     algoType   = "UseExisting_2D"
1349     ## doc string of the method
1350     #  @internal
1351     docHelper  = "Creates 2D algorithm for faces with reusing of existing mesh elements"
1352
1353     ## Private constructor.
1354     #  @param mesh parent mesh object algorithm is assigned to
1355     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
1356     #              if it is @c 0 (default), the algorithm is assigned to the main shape
1357     def __init__(self, mesh, geom=0):
1358         self.Create(mesh, geom, self.algoType)
1359         pass
1360
1361     pass # end of StdMeshersBuilder_UseExisting_2D class