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