1 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # @package StdMeshersDC
22 # Python API for the standard meshing plug-in module.
24 from smesh import Mesh_Algorithm, AssureGeomPublished, IsEqual, ParseParameters
25 from smesh import GetName, TreatHypoStatus
26 from smeshDC import Mesh
30 #----------------------------
31 # Mesh algo type identifiers
32 #----------------------------
34 ## Algorithm type: Regular 1D algorithm, see StdMeshersDC_Segment
35 REGULAR = "Regular_1D"
36 ## Algorithm type: Python 1D algorithm, see StdMeshersDC_Segment_Python
38 ## Algorithm type: Composite segment 1D algorithm, see StdMeshersDC_CompositeSegment
39 COMPOSITE = "CompositeSegment_1D"
40 ## Algorithm type: Triangle MEFISTO 2D algorithm, see StdMeshersDC_Triangle_MEFISTO
41 MEFISTO = "MEFISTO_2D"
42 ## Algorithm type: Hexahedron 3D (i-j-k) algorithm, see StdMeshersDC_Hexahedron
44 ## Algorithm type: Quadrangle 2D algorithm, see StdMeshersDC_Quadrangle
45 QUADRANGLE = "Quadrangle_2D"
46 ## Algorithm type: Radial Quadrangle 1D-2D algorithm, see StdMeshersDC_RadialQuadrangle1D2D
47 RADIAL_QUAD = "RadialQuadrangle_1D2D"
49 # import items of enum QuadType
50 for e in StdMeshers.QuadType._items: exec('%s = StdMeshers.%s'%(e,e))
52 #----------------------
54 #----------------------
56 ## Defines segment 1D algorithm for edges discretization.
58 # It can be created by calling smesh.Mesh.Segment(geom=0)
60 # @ingroup l3_algos_basic
61 class StdMeshersDC_Segment(Mesh_Algorithm):
63 ## name of the dynamic method in smesh.Mesh class
65 meshMethod = "Segment"
66 ## type of algorithm used with helper function in smesh.Mesh class
69 ## flag pointing either this algorithm should be used by default in dynamic method
73 ## doc string of the method
75 docHelper = "Creates segment 1D algorithm for edges"
77 ## Private constructor.
78 # @param mesh parent mesh object algorithm is assigned to
79 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
80 # if it is @c 0 (default), the algorithm is assigned to the main shape
81 def __init__(self, mesh, geom=0):
82 Mesh_Algorithm.__init__(self)
83 self.Create(mesh, geom, self.algoType)
86 ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
87 # @param l for the length of segments that cut an edge
88 # @param UseExisting if ==true - searches for an existing hypothesis created with
89 # the same parameters, else (default) - creates a new one
90 # @param p precision, used for calculation of the number of segments.
91 # The precision should be a positive, meaningful value within the range [0,1].
92 # In general, the number of segments is calculated with the formula:
93 # nb = ceil((edge_length / l) - p)
94 # Function ceil rounds its argument to the higher integer.
95 # So, p=0 means rounding of (edge_length / l) to the higher integer,
96 # p=0.5 means rounding of (edge_length / l) to the nearest integer,
97 # p=1 means rounding of (edge_length / l) to the lower integer.
98 # Default value is 1e-07.
99 # @return an instance of StdMeshers_LocalLength hypothesis
100 # @ingroup l3_hypos_1dhyps
101 def LocalLength(self, l, UseExisting=0, p=1e-07):
102 comFun=lambda hyp, args: IsEqual(hyp.GetLength(), args[0]) and IsEqual(hyp.GetPrecision(), args[1])
103 hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting, CompareMethod=comFun)
108 ## Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
109 # @param length is optional maximal allowed length of segment, if it is omitted
110 # the preestimated length is used that depends on geometry size
111 # @param UseExisting if ==true - searches for an existing hypothesis created with
112 # the same parameters, else (default) - creates a new one
113 # @return an instance of StdMeshers_MaxLength hypothesis
114 # @ingroup l3_hypos_1dhyps
115 def MaxSize(self, length=0.0, UseExisting=0):
116 hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
119 hyp.SetLength(length)
121 # set preestimated length
122 gen = self.mesh.smeshpyD
123 initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
124 self.mesh.GetMesh(), self.mesh.GetShape(),
126 preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
128 hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
131 hyp.SetUsePreestimatedLength( length == 0.0 )
134 ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
135 # @param n for the number of segments that cut an edge
136 # @param s for the scale factor (optional)
137 # @param reversedEdges is a list of edges to mesh using reversed orientation.
138 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
139 # @param UseExisting if ==true - searches for an existing hypothesis created with
140 # the same parameters, else (default) - create a new one
141 # @return an instance of StdMeshers_NumberOfSegments hypothesis
142 # @ingroup l3_hypos_1dhyps
143 def NumberOfSegments(self, n, s=[], reversedEdges=[], UseExisting=0):
144 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
145 reversedEdges, UseExisting = [], reversedEdges
146 entry = self.MainShapeEntry()
147 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
149 hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdgeInd, entry],
150 UseExisting=UseExisting,
151 CompareMethod=self._compareNumberOfSegments)
153 hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdgeInd, entry],
154 UseExisting=UseExisting,
155 CompareMethod=self._compareNumberOfSegments)
156 hyp.SetDistrType( 1 )
157 hyp.SetScaleFactor(s)
158 hyp.SetNumberOfSegments(n)
159 hyp.SetReversedEdges( reversedEdgeInd )
160 hyp.SetObjectEntry( entry )
165 # Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
166 def _compareNumberOfSegments(self, hyp, args):
167 if hyp.GetNumberOfSegments() == args[0]:
169 if hyp.GetReversedEdges() == args[1]:
170 if not args[1] or hyp.GetObjectEntry() == args[2]:
173 if hyp.GetReversedEdges() == args[2]:
174 if not args[2] or hyp.GetObjectEntry() == args[3]:
175 if hyp.GetDistrType() == 1:
176 if IsEqual(hyp.GetScaleFactor(), args[1]):
180 ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with increasing arithmetic length
181 # @param start defines the length of the first segment
182 # @param end defines the length of the last segment
183 # @param reversedEdges is a list of edges to mesh using reversed orientation.
184 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
185 # @param UseExisting if ==true - searches for an existing hypothesis created with
186 # the same parameters, else (default) - creates a new one
187 # @return an instance of StdMeshers_Arithmetic1D hypothesis
188 # @ingroup l3_hypos_1dhyps
189 def Arithmetic1D(self, start, end, reversedEdges=[], UseExisting=0):
190 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
191 reversedEdges, UseExisting = [], reversedEdges
192 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
193 entry = self.MainShapeEntry()
194 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
195 IsEqual(hyp.GetLength(0), args[1]) and \
196 hyp.GetReversedEdges() == args[2] and \
197 (not args[2] or hyp.GetObjectEntry() == args[3]))
198 hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdgeInd, entry],
199 UseExisting=UseExisting, CompareMethod=compFun)
200 hyp.SetStartLength(start)
201 hyp.SetEndLength(end)
202 hyp.SetReversedEdges( reversedEdgeInd )
203 hyp.SetObjectEntry( entry )
206 ## Defines "FixedPoints1D" hypothesis to cut an edge using parameter
207 # on curve from 0 to 1 (additionally it is neecessary to check
208 # orientation of edges and create list of reversed edges if it is
209 # needed) and sets numbers of segments between given points (default
210 # values are equals 1
211 # @param points defines the list of parameters on curve
212 # @param nbSegs defines the list of numbers of segments
213 # @param reversedEdges is a list of edges to mesh using reversed orientation.
214 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
215 # @param UseExisting if ==true - searches for an existing hypothesis created with
216 # the same parameters, else (default) - creates a new one
217 # @return an instance of StdMeshers_Arithmetic1D hypothesis
218 # @ingroup l3_hypos_1dhyps
219 def FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
220 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
221 reversedEdges, UseExisting = [], reversedEdges
222 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
223 entry = self.MainShapeEntry()
224 compFun = lambda hyp, args: ( hyp.GetPoints() == args[0] and \
225 hyp.GetNbSegments() == args[1] and \
226 hyp.GetReversedEdges() == args[2] and \
227 (not args[2] or hyp.GetObjectEntry() == args[3]))
228 hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdgeInd, entry],
229 UseExisting=UseExisting, CompareMethod=compFun)
230 hyp.SetPoints(points)
231 hyp.SetNbSegments(nbSegs)
232 hyp.SetReversedEdges(reversedEdgeInd)
233 hyp.SetObjectEntry(entry)
236 ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
237 # @param start defines the length of the first segment
238 # @param end defines the length of the last segment
239 # @param reversedEdges is a list of edges to mesh using reversed orientation.
240 # A list item can also be a tuple (edge, 1st_vertex_of_edge)
241 # @param UseExisting if ==true - searches for an existing hypothesis created with
242 # the same parameters, else (default) - creates a new one
243 # @return an instance of StdMeshers_StartEndLength hypothesis
244 # @ingroup l3_hypos_1dhyps
245 def StartEndLength(self, start, end, reversedEdges=[], UseExisting=0):
246 if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
247 reversedEdges, UseExisting = [], reversedEdges
248 reversedEdgeInd = self.ReversedEdgeIndices(reversedEdges)
249 entry = self.MainShapeEntry()
250 compFun = lambda hyp, args: ( IsEqual(hyp.GetLength(1), args[0]) and \
251 IsEqual(hyp.GetLength(0), args[1]) and \
252 hyp.GetReversedEdges() == args[2] and \
253 (not args[2] or hyp.GetObjectEntry() == args[3]))
254 hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdgeInd, entry],
255 UseExisting=UseExisting, CompareMethod=compFun)
256 hyp.SetStartLength(start)
257 hyp.SetEndLength(end)
258 hyp.SetReversedEdges( reversedEdgeInd )
259 hyp.SetObjectEntry( entry )
262 ## Defines "Deflection1D" hypothesis
263 # @param d for the deflection
264 # @param UseExisting if ==true - searches for an existing hypothesis created with
265 # the same parameters, else (default) - create a new one
266 # @ingroup l3_hypos_1dhyps
267 def Deflection1D(self, d, UseExisting=0):
268 compFun = lambda hyp, args: IsEqual(hyp.GetDeflection(), args[0])
269 hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting, CompareMethod=compFun)
273 ## Defines "Propagation" hypothesis that propagates all other hypotheses on all other edges that are at
274 # the opposite side in case of quadrangular faces
275 # @ingroup l3_hypos_additi
276 def Propagation(self):
277 return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
279 ## Defines "AutomaticLength" hypothesis
280 # @param fineness for the fineness [0-1]
281 # @param UseExisting if ==true - searches for an existing hypothesis created with the
282 # same parameters, else (default) - create a new one
283 # @ingroup l3_hypos_1dhyps
284 def AutomaticLength(self, fineness=0, UseExisting=0):
285 compFun = lambda hyp, args: IsEqual(hyp.GetFineness(), args[0])
286 hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
287 CompareMethod=compFun)
288 hyp.SetFineness( fineness )
291 ## Defines "SegmentLengthAroundVertex" hypothesis
292 # @param length for the segment length
293 # @param vertex for the length localization: the vertex index [0,1] | vertex object.
294 # Any other integer value means that the hypothesis will be set on the
295 # whole 1D shape, where Mesh_Segment algorithm is assigned.
296 # @param UseExisting if ==true - searches for an existing hypothesis created with
297 # the same parameters, else (default) - creates a new one
298 # @ingroup l3_algos_segmarv
299 def LengthNearVertex(self, length, vertex=0, UseExisting=0):
301 store_geom = self.geom
302 if type(vertex) is types.IntType:
303 if vertex == 0 or vertex == 1:
305 vertex = self.mesh.geompyD.ExtractShapes(self.geom, geompyDC.ShapeType["VERTEX"],True)[vertex]
313 if self.geom is None:
314 raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
315 AssureGeomPublished( self.mesh, self.geom )
316 name = GetName(self.geom)
318 algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
320 algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
322 status = self.mesh.mesh.AddHypothesis(self.geom, algo)
323 TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
325 comFun = lambda hyp, args: IsEqual(hyp.GetLength(), args[0])
326 hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
327 CompareMethod=comFun)
328 self.geom = store_geom
329 hyp.SetLength( length )
332 ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
333 # If the 2D mesher sees that all boundary edges are quadratic,
334 # it generates quadratic faces, else it generates linear faces using
335 # medium nodes as if they are vertices.
336 # The 3D mesher generates quadratic volumes only if all boundary faces
337 # are quadratic, else it fails.
339 # @ingroup l3_hypos_additi
340 def QuadraticMesh(self):
341 hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
344 pass # end of StdMeshersDC_Segment class
346 ## Segment 1D algorithm for discretization of a set of adjacent edges as one edge.
348 # It is created by calling smesh.Mesh.Segment(smesh.COMPOSITE,geom=0)
350 # @ingroup l3_algos_basic
351 class StdMeshersDC_CompositeSegment(StdMeshersDC_Segment):
353 ## name of the dynamic method in smesh.Mesh class
355 meshMethod = "Segment"
356 ## type of algorithm used with helper function in smesh.Mesh class
359 ## flag pointing either this algorithm should be used by default in dynamic method
360 # of smesh.Mesh class
364 ## Private constructor.
365 # @param mesh parent mesh object algorithm is assigned to
366 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
367 # if it is @c 0 (default), the algorithm is assigned to the main shape
368 def __init__(self, mesh, geom=0):
369 self.Create(mesh, geom, self.algoType)
372 pass # end of StdMeshersDC_CompositeSegment class
374 ## Defines a segment 1D algorithm for discretization of edges with Python function
376 # It is created by calling smesh.Mesh.Segment(smesh.PYTHON,geom=0)
378 # @ingroup l3_algos_basic
379 class StdMeshersDC_Segment_Python(Mesh_Algorithm):
381 ## name of the dynamic method in smesh.Mesh class
383 meshMethod = "Segment"
384 ## type of algorithm used with helper function in smesh.Mesh class
387 ## doc string of the method
389 docHelper = "Creates tetrahedron 3D algorithm for solids"
391 ## Private constructor.
392 # @param mesh parent mesh object algorithm is assigned to
393 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
394 # if it is @c 0 (default), the algorithm is assigned to the main shape
395 def __init__(self, mesh, geom=0):
396 import Python1dPlugin
397 self.Create(mesh, geom, self.algoType, "libPython1dEngine.so")
400 ## Defines "PythonSplit1D" hypothesis
401 # @param n for the number of segments that cut an edge
402 # @param func for the python function that calculates the length of all segments
403 # @param UseExisting if ==true - searches for the existing hypothesis created with
404 # the same parameters, else (default) - creates a new one
405 # @ingroup l3_hypos_1dhyps
406 def PythonSplit1D(self, n, func, UseExisting=0):
407 compFun = lambda hyp, args: False
408 hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
409 UseExisting=UseExisting, CompareMethod=compFun)
410 hyp.SetNumberOfSegments(n)
411 hyp.SetPythonLog10RatioFunction(func)
414 pass # end of StdMeshersDC_Segment_Python class
416 ## Triangle MEFISTO 2D algorithm
418 # It is created by calling smesh.Mesh.Triangle(smesh.MEFISTO,geom=0)
420 # @ingroup l3_algos_basic
421 class StdMeshersDC_Triangle_MEFISTO(Mesh_Algorithm):
423 ## name of the dynamic method in smesh.Mesh class
425 meshMethod = "Triangle"
426 ## type of algorithm used with helper function in smesh.Mesh class
429 ## flag pointing either this algorithm should be used by default in dynamic method
430 # of smesh.Mesh class
434 ## Private constructor.
435 # @param mesh parent mesh object algorithm is assigned to
436 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
437 # if it is @c 0 (default), the algorithm is assigned to the main shape
438 def __init__(self, mesh, geom=0):
439 Mesh_Algorithm.__init__(self)
440 self.Create(mesh, geom, self.algoType)
443 ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
444 # @param area for the maximum area of each triangle
445 # @param UseExisting if ==true - searches for an existing hypothesis created with the
446 # same parameters, else (default) - creates a new one
448 # @ingroup l3_hypos_2dhyps
449 def MaxElementArea(self, area, UseExisting=0):
450 comparator = lambda hyp, args: IsEqual(hyp.GetMaxElementArea(), args[0])
451 hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
452 CompareMethod=comparator)
453 hyp.SetMaxElementArea(area)
456 ## Defines "LengthFromEdges" hypothesis to build triangles
457 # based on the length of the edges taken from the wire
459 # @ingroup l3_hypos_2dhyps
460 def LengthFromEdges(self):
461 hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
464 pass # end of StdMeshersDC_Triangle_MEFISTO class
466 ## Defines a quadrangle 2D algorithm
468 # It is created by calling smesh.Mesh.Quadrangle(geom=0)
470 # @ingroup l3_algos_basic
471 class StdMeshersDC_Quadrangle(Mesh_Algorithm):
473 ## name of the dynamic method in smesh.Mesh class
475 meshMethod = "Quadrangle"
476 ## type of algorithm used with helper function in smesh.Mesh class
478 algoType = QUADRANGLE
479 ## flag pointing either this algorithm should be used by default in dynamic method
480 # of smesh.Mesh class
483 ## hypothesis associated with algorithm
487 ## Private constructor.
488 # @param mesh parent mesh object algorithm is assigned to
489 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
490 # if it is @c 0 (default), the algorithm is assigned to the main shape
491 def __init__(self, mesh, geom=0):
492 Mesh_Algorithm.__init__(self)
493 self.Create(mesh, geom, self.algoType)
496 ## Defines "QuadrangleParameters" hypothesis
497 # @param quadType defines the algorithm of transition between differently descretized
498 # sides of a geometrical face:
499 # - QUAD_STANDARD - both triangles and quadrangles are possible in the transition
500 # area along the finer meshed sides.
501 # - QUAD_TRIANGLE_PREF - only triangles are built in the transition area along the
502 # finer meshed sides.
503 # - QUAD_QUADRANGLE_PREF - only quadrangles are built in the transition area along
504 # the finer meshed sides, iff the total quantity of segments on
505 # all four sides of the face is even (divisible by 2).
506 # - QUAD_QUADRANGLE_PREF_REVERSED - same as QUAD_QUADRANGLE_PREF but the transition
507 # area is located along the coarser meshed sides.
508 # - QUAD_REDUCED - only quadrangles are built and the transition between the sides
509 # is made gradually, layer by layer. This type has a limitation on
510 # the number of segments: one pair of opposite sides must have the
511 # same number of segments, the other pair must have an even difference
512 # between the numbers of segments on the sides.
513 # @param triangleVertex: vertex of a trilateral geometrical face, around which triangles
514 # will be created while other elements will be quadrangles.
515 # Vertex can be either a GEOM_Object or a vertex ID within the
517 # @param UseExisting: if ==true - searches for the existing hypothesis created with
518 # the same parameters, else (default) - creates a new one
519 # @ingroup l3_hypos_quad
520 def QuadrangleParameters(self, quadType=StdMeshers.QUAD_STANDARD, triangleVertex=0, UseExisting=0):
522 vertexID = triangleVertex
523 if isinstance( triangleVertex, GEOM._objref_GEOM_Object ):
524 vertexID = self.mesh.geompyD.GetSubShapeID( self.mesh.geom, triangleVertex )
526 compFun = lambda hyp,args: \
527 hyp.GetQuadType() == args[0] and \
528 ( hyp.GetTriaVertex()==args[1] or ( hyp.GetTriaVertex()<1 and args[1]<1))
529 self.params = self.Hypothesis("QuadrangleParams", [quadType,vertexID],
530 UseExisting = UseExisting, CompareMethod=compFun)
532 if self.params.GetQuadType() != quadType:
533 self.params.SetQuadType(quadType)
535 self.params.SetTriaVertex( vertexID )
538 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
539 # quadrangles are built in the transition area along the finer meshed sides,
540 # iff the total quantity of segments on all four sides of the face is even.
541 # @param reversed if True, transition area is located along the coarser meshed sides.
542 # @param UseExisting: if ==true - searches for the existing hypothesis created with
543 # the same parameters, else (default) - creates a new one
544 # @ingroup l3_hypos_quad
545 def QuadranglePreference(self, reversed=False, UseExisting=0):
547 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF_REVERSED,UseExisting=UseExisting)
548 return self.QuadrangleParameters(QUAD_QUADRANGLE_PREF,UseExisting=UseExisting)
550 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
551 # triangles are built in the transition area along the finer meshed sides.
552 # @param UseExisting: if ==true - searches for the existing hypothesis created with
553 # the same parameters, else (default) - creates a new one
554 # @ingroup l3_hypos_quad
555 def TrianglePreference(self, UseExisting=0):
556 return self.QuadrangleParameters(QUAD_TRIANGLE_PREF,UseExisting=UseExisting)
558 ## Defines "QuadrangleParams" hypothesis with a type of quadrangulation that only
559 # quadrangles are built and the transition between the sides is made gradually,
560 # layer by layer. This type has a limitation on the number of segments: one pair
561 # of opposite sides must have the same number of segments, the other pair must
562 # have an even difference between the numbers of segments on the sides.
563 # @param UseExisting: if ==true - searches for the existing hypothesis created with
564 # the same parameters, else (default) - creates a new one
565 # @ingroup l3_hypos_quad
566 def Reduced(self, UseExisting=0):
567 return self.QuadrangleParameters(QUAD_REDUCED,UseExisting=UseExisting)
569 ## Defines "QuadrangleParams" hypothesis with QUAD_STANDARD type of quadrangulation
570 # @param vertex: vertex of a trilateral geometrical face, around which triangles
571 # will be created while other elements will be quadrangles.
572 # Vertex can be either a GEOM_Object or a vertex ID within the
574 # @param UseExisting: if ==true - searches for the existing hypothesis created with
575 # the same parameters, else (default) - creates a new one
576 # @ingroup l3_hypos_quad
577 def TriangleVertex(self, vertex, UseExisting=0):
578 return self.QuadrangleParameters(QUAD_STANDARD,vertex,UseExisting)
580 pass # end of StdMeshersDC_Quadrangle class
582 ## Defines a hexahedron 3D algorithm
584 # It is created by calling smesh.Mesh.Hexahedron(geom=0)
586 # @ingroup l3_algos_basic
587 class StdMeshersDC_Hexahedron(Mesh_Algorithm):
589 ## name of the dynamic method in smesh.Mesh class
591 meshMethod = "Hexahedron"
592 ## type of algorithm used with helper function in smesh.Mesh class
595 ## flag pointing either this algorithm should be used by default in dynamic method
596 # of smesh.Mesh class
600 ## Private constructor.
601 # @param mesh parent mesh object algorithm is assigned to
602 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
603 # if it is @c 0 (default), the algorithm is assigned to the main shape
604 def __init__(self, mesh, geom=0):
605 Mesh_Algorithm.__init__(self)
606 self.Create(mesh, geom, Hexa)
609 pass # end of StdMeshersDC_Hexahedron class
611 ## Defines a projection 1D algorithm
613 # It is created by calling smesh.Mesh.Projection1D(geom=0)
615 # @ingroup l3_algos_proj
616 class StdMeshersDC_Projection1D(Mesh_Algorithm):
618 ## name of the dynamic method in smesh.Mesh class
620 meshMethod = "Projection1D"
621 ## type of algorithm used with helper function in smesh.Mesh class
623 algoType = "Projection_1D"
624 ## flag pointing either this algorithm should be used by default in dynamic method
625 # of smesh.Mesh class
629 ## Private constructor.
630 # @param mesh parent mesh object algorithm is assigned to
631 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
632 # if it is @c 0 (default), the algorithm is assigned to the main shape
633 def __init__(self, mesh, geom=0):
634 Mesh_Algorithm.__init__(self)
635 self.Create(mesh, geom, self.algoType)
638 ## Defines "Source Edge" hypothesis, specifying a meshed edge, from where
639 # a mesh pattern is taken, and, optionally, the association of vertices
640 # between the source edge and a target edge (to which a hypothesis is assigned)
641 # @param edge from which nodes distribution is taken
642 # @param mesh from which nodes distribution is taken (optional)
643 # @param srcV a vertex of \a edge to associate with \a tgtV (optional)
644 # @param tgtV a vertex of \a the edge to which the algorithm is assigned,
645 # to associate with \a srcV (optional)
646 # @param UseExisting if ==true - searches for the existing hypothesis created with
647 # the same parameters, else (default) - creates a new one
648 def SourceEdge(self, edge, mesh=None, srcV=None, tgtV=None, UseExisting=0):
649 AssureGeomPublished( self.mesh, edge )
650 AssureGeomPublished( self.mesh, srcV )
651 AssureGeomPublished( self.mesh, tgtV )
652 hyp = self.Hypothesis("ProjectionSource1D", [edge,mesh,srcV,tgtV],
654 # it does not seem to be useful to reuse the existing "SourceEdge" hypothesis
655 #UseExisting=UseExisting, CompareMethod=self.CompareSourceEdge)
656 hyp.SetSourceEdge( edge )
657 if not mesh is None and isinstance(mesh, Mesh):
658 mesh = mesh.GetMesh()
659 hyp.SetSourceMesh( mesh )
660 hyp.SetVertexAssociation( srcV, tgtV )
663 pass # end of StdMeshersDC_Projection1D class
665 ## Defines a projection 2D algorithm
667 # It is created by calling smesh.Mesh.Projection2D(geom=0)
669 # @ingroup l3_algos_proj
670 class StdMeshersDC_Projection2D(Mesh_Algorithm):
672 ## name of the dynamic method in smesh.Mesh class
674 meshMethod = "Projection2D"
675 ## type of algorithm used with helper function in smesh.Mesh class
677 algoType = "Projection_2D"
678 ## flag pointing either this algorithm should be used by default in dynamic method
679 # of smesh.Mesh class
683 ## Private constructor.
684 # @param mesh parent mesh object algorithm is assigned to
685 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
686 # if it is @c 0 (default), the algorithm is assigned to the main shape
687 def __init__(self, mesh, geom=0):
688 Mesh_Algorithm.__init__(self)
689 self.Create(mesh, geom, self.algoType)
692 ## Defines "Source Face" hypothesis, specifying a meshed face, from where
693 # a mesh pattern is taken, and, optionally, the association of vertices
694 # between the source face and the target face (to which a hypothesis is assigned)
695 # @param face from which the mesh pattern is taken
696 # @param mesh from which the mesh pattern is taken (optional)
697 # @param srcV1 a vertex of \a face to associate with \a tgtV1 (optional)
698 # @param tgtV1 a vertex of \a the face to which the algorithm is assigned,
699 # to associate with \a srcV1 (optional)
700 # @param srcV2 a vertex of \a face to associate with \a tgtV1 (optional)
701 # @param tgtV2 a vertex of \a the face to which the algorithm is assigned,
702 # to associate with \a srcV2 (optional)
703 # @param UseExisting if ==true - forces the search for the existing hypothesis created with
704 # the same parameters, else (default) - forces the creation a new one
706 # Note: all association vertices must belong to one edge of a face
707 def SourceFace(self, face, mesh=None, srcV1=None, tgtV1=None,
708 srcV2=None, tgtV2=None, UseExisting=0):
709 from smeshDC import Mesh
710 if isinstance(mesh, Mesh):
711 mesh = mesh.GetMesh()
712 for geom in [ face, srcV1, tgtV1, srcV2, tgtV2 ]:
713 AssureGeomPublished( self.mesh, geom )
714 hyp = self.Hypothesis("ProjectionSource2D", [face,mesh,srcV1,tgtV1,srcV2,tgtV2],
716 # it does not seem to be useful to reuse the existing "SourceFace" hypothesis
717 #UseExisting=UseExisting, CompareMethod=self.CompareSourceFace)
718 hyp.SetSourceFace( face )
719 hyp.SetSourceMesh( mesh )
720 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
723 pass # end of StdMeshersDC_Projection2D class
725 ## Defines a projection 1D-2D algorithm
727 # It is created by calling smesh.Mesh.Projection1D2D(geom=0)
729 # @ingroup l3_algos_proj
730 class StdMeshersDC_Projection1D2D(StdMeshersDC_Projection2D):
732 ## name of the dynamic method in smesh.Mesh class
734 meshMethod = "Projection1D2D"
735 ## type of algorithm used with helper function in smesh.Mesh class
737 algoType = "Projection_1D2D"
739 ## Private constructor.
740 # @param mesh parent mesh object algorithm is assigned to
741 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
742 # if it is @c 0 (default), the algorithm is assigned to the main shape
743 def __init__(self, mesh, geom=0):
744 StdMeshersDC_Projection2D.__init__(self, mesh, geom)
747 pass # end of StdMeshersDC_Projection1D2D class
749 ## Defines a projection 3D algorithm
751 # It is created by calling smesh.Mesh.Projection3D(geom=0)
753 # @ingroup l3_algos_proj
754 class StdMeshersDC_Projection3D(Mesh_Algorithm):
756 ## name of the dynamic method in smesh.Mesh class
758 meshMethod = "Projection3D"
759 ## type of algorithm used with helper function in smesh.Mesh class
761 algoType = "Projection_3D"
763 ## Private constructor.
764 # @param mesh parent mesh object algorithm is assigned to
765 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
766 # if it is @c 0 (default), the algorithm is assigned to the main shape
767 def __init__(self, mesh, geom=0):
768 Mesh_Algorithm.__init__(self)
769 self.Create(mesh, geom, self.algoType)
772 ## Defines the "Source Shape 3D" hypothesis, specifying a meshed solid, from where
773 # the mesh pattern is taken, and, optionally, the association of vertices
774 # between the source and the target solid (to which a hipothesis is assigned)
775 # @param solid from where the mesh pattern is taken
776 # @param mesh from where the mesh pattern is taken (optional)
777 # @param srcV1 a vertex of \a solid to associate with \a tgtV1 (optional)
778 # @param tgtV1 a vertex of \a the solid where the algorithm is assigned,
779 # to associate with \a srcV1 (optional)
780 # @param srcV2 a vertex of \a solid to associate with \a tgtV1 (optional)
781 # @param tgtV2 a vertex of \a the solid to which the algorithm is assigned,
782 # to associate with \a srcV2 (optional)
783 # @param UseExisting - if ==true - searches for the existing hypothesis created with
784 # the same parameters, else (default) - creates a new one
786 # Note: association vertices must belong to one edge of a solid
787 def SourceShape3D(self, solid, mesh=0, srcV1=0, tgtV1=0,
788 srcV2=0, tgtV2=0, UseExisting=0):
789 for geom in [ solid, srcV1, tgtV1, srcV2, tgtV2 ]:
790 AssureGeomPublished( self.mesh, geom )
791 hyp = self.Hypothesis("ProjectionSource3D",
792 [solid,mesh,srcV1,tgtV1,srcV2,tgtV2],
794 # seems to be not really useful to reuse existing "SourceShape3D" hypothesis
795 #UseExisting=UseExisting, CompareMethod=self.CompareSourceShape3D)
796 hyp.SetSource3DShape( solid )
797 if isinstance(mesh, Mesh):
798 mesh = mesh.GetMesh()
800 hyp.SetSourceMesh( mesh )
801 if srcV1 and srcV2 and tgtV1 and tgtV2:
802 hyp.SetVertexAssociation( srcV1, srcV2, tgtV1, tgtV2 )
803 #elif srcV1 or srcV2 or tgtV1 or tgtV2:
806 pass # end of StdMeshersDC_Projection3D class
808 ## Defines a Prism 3D algorithm, which is either "Extrusion 3D" or "Radial Prism"
809 # depending on geometry
811 # It is created by calling smesh.Mesh.Prism(geom=0)
813 # @ingroup l3_algos_3dextr
814 class StdMeshersDC_Prism3D(Mesh_Algorithm):
816 ## name of the dynamic method in smesh.Mesh class
819 ## type of algorithm used with helper function in smesh.Mesh class
821 algoType = "Prism_3D"
823 ## Private constructor.
824 # @param mesh parent mesh object algorithm is assigned to
825 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
826 # if it is @c 0 (default), the algorithm is assigned to the main shape
827 def __init__(self, mesh, geom=0):
828 Mesh_Algorithm.__init__(self)
833 from geompy import SubShapeAll, ShapeType
834 nbSolids = len( SubShapeAll( shape, ShapeType["SOLID"] ))
835 nbShells = len( SubShapeAll( shape, ShapeType["SHELL"] ))
836 if nbSolids == 0 or nbSolids == nbShells:
837 self.Create(mesh, geom, "Prism_3D")
840 self.algoType = "RadialPrism_3D"
841 self.Create(mesh, geom, "RadialPrism_3D")
842 self.distribHyp = self.Hypothesis("LayerDistribution", UseExisting=0)
847 ## Return 3D hypothesis holding the 1D one
848 def Get3DHypothesis(self):
849 if self.algoType != "RadialPrism_3D":
850 print "Prism_3D algorith doesn't support any hyposesis"
852 return self.distribHyp
854 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
855 # hypothesis. Returns the created hypothesis
856 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
857 if self.algoType != "RadialPrism_3D":
858 print "Prism_3D algorith doesn't support any hyposesis"
860 if not self.nbLayers is None:
861 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
862 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
863 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
864 self.mesh.smeshpyD.SetCurrentStudy( None )
865 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
866 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
867 self.distribHyp.SetLayerDistribution( hyp )
870 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers of
871 # prisms to build between the inner and outer shells
872 # @param n number of layers
873 # @param UseExisting if ==true - searches for the existing hypothesis created with
874 # the same parameters, else (default) - creates a new one
875 def NumberOfLayers(self, n, UseExisting=0):
876 if self.algoType != "RadialPrism_3D":
877 print "Prism_3D algorith doesn't support any hyposesis"
879 self.mesh.RemoveHypothesis( self.distribHyp, self.geom )
880 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
881 self.nbLayers = self.Hypothesis("NumberOfLayers", [n], UseExisting=UseExisting,
882 CompareMethod=compFun)
883 self.nbLayers.SetNumberOfLayers( n )
886 ## Defines "LocalLength" hypothesis, specifying the segment length
887 # to build between the inner and the outer shells
888 # @param l the length of segments
889 # @param p the precision of rounding
890 def LocalLength(self, l, p=1e-07):
891 if self.algoType != "RadialPrism_3D":
892 print "Prism_3D algorith doesn't support any hyposesis"
894 hyp = self.OwnHypothesis("LocalLength", [l,p])
899 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers of
900 # prisms to build between the inner and the outer shells.
901 # @param n the number of layers
902 # @param s the scale factor (optional)
903 def NumberOfSegments(self, n, s=[]):
904 if self.algoType != "RadialPrism_3D":
905 print "Prism_3D algorith doesn't support any hyposesis"
908 hyp = self.OwnHypothesis("NumberOfSegments", [n])
910 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
911 hyp.SetDistrType( 1 )
912 hyp.SetScaleFactor(s)
913 hyp.SetNumberOfSegments(n)
916 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
917 # to build between the inner and the outer shells with a length that changes in arithmetic progression
918 # @param start the length of the first segment
919 # @param end the length of the last segment
920 def Arithmetic1D(self, start, end ):
921 if self.algoType != "RadialPrism_3D":
922 print "Prism_3D algorith doesn't support any hyposesis"
924 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
925 hyp.SetLength(start, 1)
926 hyp.SetLength(end , 0)
929 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
930 # to build between the inner and the outer shells as geometric length increasing
931 # @param start for the length of the first segment
932 # @param end for the length of the last segment
933 def StartEndLength(self, start, end):
934 if self.algoType != "RadialPrism_3D":
935 print "Prism_3D algorith doesn't support any hyposesis"
937 hyp = self.OwnHypothesis("StartEndLength", [start, end])
938 hyp.SetLength(start, 1)
939 hyp.SetLength(end , 0)
942 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
943 # to build between the inner and outer shells
944 # @param fineness defines the quality of the mesh within the range [0-1]
945 def AutomaticLength(self, fineness=0):
946 if self.algoType != "RadialPrism_3D":
947 print "Prism_3D algorith doesn't support any hyposesis"
949 hyp = self.OwnHypothesis("AutomaticLength")
950 hyp.SetFineness( fineness )
953 pass # end of StdMeshersDC_Prism3D class
955 ## Defines a Radial Quadrangle 1D2D algorithm
957 # It is created by calling smesh.Mesh.Quadrangle(smesh.RADIAL_QUAD,geom=0)
959 # @ingroup l2_algos_radialq
960 class StdMeshersDC_RadialQuadrangle1D2D(Mesh_Algorithm):
962 ## name of the dynamic method in smesh.Mesh class
964 meshMethod = "Quadrangle"
965 ## type of algorithm used with helper function in smesh.Mesh class
967 algoType = RADIAL_QUAD
969 ## Private constructor.
970 # @param mesh parent mesh object algorithm is assigned to
971 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
972 # if it is @c 0 (default), the algorithm is assigned to the main shape
973 def __init__(self, mesh, geom=0):
974 Mesh_Algorithm.__init__(self)
975 self.Create(mesh, geom, self.algoType)
977 self.distribHyp = None #self.Hypothesis("LayerDistribution2D", UseExisting=0)
981 ## Return 2D hypothesis holding the 1D one
982 def Get2DHypothesis(self):
983 if not self.distribHyp:
984 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
985 return self.distribHyp
987 ## Private method creating a 1D hypothesis and storing it in the LayerDistribution
988 # hypothesis. Returns the created hypothesis
989 def OwnHypothesis(self, hypType, args=[], so="libStdMeshersEngine.so"):
991 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.nbLayers )
992 if self.distribHyp is None:
993 self.distribHyp = self.Hypothesis("LayerDistribution2D", UseExisting=0)
995 self.mesh.GetMesh().AddHypothesis( self.geom, self.distribHyp )
996 study = self.mesh.smeshpyD.GetCurrentStudy() # prevents publishing own 1D hypothesis
997 self.mesh.smeshpyD.SetCurrentStudy( None )
998 hyp = self.mesh.smeshpyD.CreateHypothesis(hypType, so)
999 self.mesh.smeshpyD.SetCurrentStudy( study ) # enables publishing
1000 self.distribHyp.SetLayerDistribution( hyp )
1003 ## Defines "NumberOfLayers" hypothesis, specifying the number of layers
1004 # @param n number of layers
1005 # @param UseExisting if ==true - searches for the existing hypothesis created with
1006 # the same parameters, else (default) - creates a new one
1007 def NumberOfLayers(self, n, UseExisting=0):
1009 self.mesh.GetMesh().RemoveHypothesis( self.geom, self.distribHyp )
1010 compFun = lambda hyp, args: IsEqual(hyp.GetNumberOfLayers(), args[0])
1011 self.nbLayers = self.Hypothesis("NumberOfLayers2D", [n], UseExisting=UseExisting,
1012 CompareMethod=compFun)
1013 self.nbLayers.SetNumberOfLayers( n )
1014 return self.nbLayers
1016 ## Defines "LocalLength" hypothesis, specifying the segment length
1017 # @param l the length of segments
1018 # @param p the precision of rounding
1019 def LocalLength(self, l, p=1e-07):
1020 hyp = self.OwnHypothesis("LocalLength", [l,p])
1025 ## Defines "NumberOfSegments" hypothesis, specifying the number of layers
1026 # @param n the number of layers
1027 # @param s the scale factor (optional)
1028 def NumberOfSegments(self, n, s=[]):
1030 hyp = self.OwnHypothesis("NumberOfSegments", [n])
1032 hyp = self.OwnHypothesis("NumberOfSegments", [n,s])
1033 hyp.SetDistrType( 1 )
1034 hyp.SetScaleFactor(s)
1035 hyp.SetNumberOfSegments(n)
1038 ## Defines "Arithmetic1D" hypothesis, specifying the distribution of segments
1039 # with a length that changes in arithmetic progression
1040 # @param start the length of the first segment
1041 # @param end the length of the last segment
1042 def Arithmetic1D(self, start, end ):
1043 hyp = self.OwnHypothesis("Arithmetic1D", [start, end])
1044 hyp.SetLength(start, 1)
1045 hyp.SetLength(end , 0)
1048 ## Defines "StartEndLength" hypothesis, specifying distribution of segments
1049 # as geometric length increasing
1050 # @param start for the length of the first segment
1051 # @param end for the length of the last segment
1052 def StartEndLength(self, start, end):
1053 hyp = self.OwnHypothesis("StartEndLength", [start, end])
1054 hyp.SetLength(start, 1)
1055 hyp.SetLength(end , 0)
1058 ## Defines "AutomaticLength" hypothesis, specifying the number of segments
1059 # @param fineness defines the quality of the mesh within the range [0-1]
1060 def AutomaticLength(self, fineness=0):
1061 hyp = self.OwnHypothesis("AutomaticLength")
1062 hyp.SetFineness( fineness )
1065 pass # end of StdMeshersDC_RadialQuadrangle1D2D class
1067 ## Defines a Use Existing Elements 1D algorithm
1069 # It is created by calling smesh.Mesh.UseExisting1DElements(geom=0)
1071 # @ingroup l3_algos_basic
1072 class StdMeshersDC_UseExistingElements_1D(Mesh_Algorithm):
1074 ## name of the dynamic method in smesh.Mesh class
1076 meshMethod = "UseExisting1DElements"
1077 ## type of algorithm used with helper function in smesh.Mesh class
1079 algoType = "Import_1D"
1080 ## flag pointing either this algorithm should be used by default in dynamic method
1081 # of smesh.Mesh class
1085 ## Private constructor.
1086 # @param mesh parent mesh object algorithm is assigned to
1087 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1088 # if it is @c 0 (default), the algorithm is assigned to the main shape
1089 def __init__(self, mesh, geom=0):
1090 Mesh_Algorithm.__init__(self)
1091 self.Create(mesh, geom, self.algoType)
1094 ## Defines "Source edges" hypothesis, specifying groups of edges to import
1095 # @param groups list of groups of edges
1096 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1097 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1098 # @param UseExisting if ==true - searches for the existing hypothesis created with
1099 # the same parameters, else (default) - creates a new one
1100 def SourceEdges(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1101 for group in groups:
1102 AssureGeomPublished( self.mesh, group )
1103 compFun = lambda hyp, args: ( hyp.GetSourceEdges() == args[0] and \
1104 hyp.GetCopySourceMesh() == args[1], args[2] )
1105 hyp = self.Hypothesis("ImportSource1D", [groups, toCopyMesh, toCopyGroups],
1106 UseExisting=UseExisting, CompareMethod=compFun)
1107 hyp.SetSourceEdges(groups)
1108 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1111 pass # end of StdMeshersDC_UseExistingElements_1D class
1113 ## Defines a Use Existing Elements 1D-2D algorithm
1115 # It is created by calling smesh.Mesh.UseExisting2DElements(geom=0)
1117 # @ingroup l3_algos_basic
1118 class StdMeshersDC_UseExistingElements_1D2D(Mesh_Algorithm):
1120 ## name of the dynamic method in smesh.Mesh class
1122 meshMethod = "UseExisting2DElements"
1123 ## type of algorithm used with helper function in smesh.Mesh class
1125 algoType = "Import_1D2D"
1126 ## flag pointing either this algorithm should be used by default in dynamic method
1127 # of smesh.Mesh class
1131 ## Private constructor.
1132 # @param mesh parent mesh object algorithm is assigned to
1133 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1134 # if it is @c 0 (default), the algorithm is assigned to the main shape
1135 def __init__(self, mesh, geom=0):
1136 Mesh_Algorithm.__init__(self)
1137 self.Create(mesh, geom, self.algoType)
1140 ## Defines "Source faces" hypothesis, specifying groups of faces to import
1141 # @param groups list of groups of faces
1142 # @param toCopyMesh if True, the whole mesh \a groups belong to is imported
1143 # @param toCopyGroups if True, all groups of the mesh \a groups belong to are imported
1144 # @param UseExisting if ==true - searches for the existing hypothesis created with
1145 # the same parameters, else (default) - creates a new one
1146 def SourceFaces(self, groups, toCopyMesh=False, toCopyGroups=False, UseExisting=False):
1147 for group in groups:
1148 AssureGeomPublished( self.mesh, group )
1149 compFun = lambda hyp, args: ( hyp.GetSourceFaces() == args[0] and \
1150 hyp.GetCopySourceMesh() == args[1], args[2] )
1151 hyp = self.Hypothesis("ImportSource2D", [groups, toCopyMesh, toCopyGroups],
1152 UseExisting=UseExisting, CompareMethod=compFun)
1153 hyp.SetSourceFaces(groups)
1154 hyp.SetCopySourceMesh(toCopyMesh, toCopyGroups)
1157 pass # end of StdMeshersDC_UseExistingElements_1D2D class
1159 ## Defines a Body Fitting 3D algorithm
1161 # It is created by calling smesh.Mesh.BodyFitted(geom=0)
1163 # @ingroup l3_algos_basic
1164 class StdMeshersDC_Cartesian_3D(Mesh_Algorithm):
1166 ## name of the dynamic method in smesh.Mesh class
1168 meshMethod = "BodyFitted"
1169 ## type of algorithm used with helper function in smesh.Mesh class
1171 algoType = "Cartesian_3D"
1172 ## flag pointing either this algorithm should be used by default in dynamic method
1173 # of smesh.Mesh class
1177 ## Private constructor.
1178 # @param mesh parent mesh object algorithm is assigned to
1179 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1180 # if it is @c 0 (default), the algorithm is assigned to the main shape
1181 def __init__(self, mesh, geom=0):
1182 self.Create(mesh, geom, self.algoType)
1186 ## Defines "Body Fitting parameters" hypothesis
1187 # @param xGridDef is definition of the grid along the X asix.
1188 # It can be in either of two following forms:
1189 # - Explicit coordinates of nodes, e.g. [-1.5, 0.0, 3.1] or range( -100,200,10)
1190 # - Functions f(t) defining grid spacing at each point on grid axis. If there are
1191 # several functions, they must be accompanied by relative coordinates of
1192 # points dividing the whole shape into ranges where the functions apply; points
1193 # coodrinates should vary within (0.0, 1.0) range. Parameter \a t of the spacing
1194 # function f(t) varies from 0.0 to 1.0 witin a shape range.
1196 # - "10.5" - defines a grid with a constant spacing
1197 # - [["1", "1+10*t", "11"] [0.1, 0.6]] - defines different spacing in 3 ranges.
1198 # @param yGridDef defines the grid along the Y asix the same way as \a xGridDef does
1199 # @param zGridDef defines the grid along the Z asix the same way as \a xGridDef does
1200 # @param sizeThreshold (> 1.0) defines a minimal size of a polyhedron so that
1201 # a polyhedron of size less than hexSize/sizeThreshold is not created
1202 # @param UseExisting if ==true - searches for the existing hypothesis created with
1203 # the same parameters, else (default) - creates a new one
1204 def SetGrid(self, xGridDef, yGridDef, zGridDef, sizeThreshold=4.0, UseExisting=False):
1206 compFun = lambda hyp, args: False
1207 self.hyp = self.Hypothesis("CartesianParameters3D",
1208 [xGridDef, yGridDef, zGridDef, sizeThreshold],
1209 UseExisting=UseExisting, CompareMethod=compFun)
1210 if not self.mesh.IsUsedHypothesis( self.hyp, self.geom ):
1211 self.mesh.AddHypothesis( self.hyp, self.geom )
1213 for axis, gridDef in enumerate( [xGridDef, yGridDef, zGridDef]):
1214 if not gridDef: raise ValueError, "Empty grid definition"
1215 if isinstance( gridDef, str ):
1216 self.hyp.SetGridSpacing( [gridDef], [], axis )
1217 elif isinstance( gridDef[0], str ):
1218 self.hyp.SetGridSpacing( gridDef, [], axis )
1219 elif isinstance( gridDef[0], int ) or \
1220 isinstance( gridDef[0], float ):
1221 self.hyp.SetGrid(gridDef, axis )
1223 self.hyp.SetGridSpacing( gridDef[0], gridDef[1], axis )
1224 self.hyp.SetSizeThreshold( sizeThreshold )
1227 pass # end of StdMeshersDC_Cartesian_3D class
1229 ## Defines a stub 1D algorithm, which enables "manual" creation of nodes and
1230 # segments usable by 2D algoritms
1232 # It is created by calling smesh.Mesh.UseExistingSegments(geom=0)
1234 # @ingroup l3_algos_basic
1235 class StdMeshersDC_UseExisting_1D(Mesh_Algorithm):
1237 ## name of the dynamic method in smesh.Mesh class
1239 meshMethod = "UseExistingSegments"
1240 ## type of algorithm used with helper function in smesh.Mesh class
1242 algoType = "UseExisting_1D"
1244 ## Private constructor.
1245 # @param mesh parent mesh object algorithm is assigned to
1246 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1247 # if it is @c 0 (default), the algorithm is assigned to the main shape
1248 def __init__(self, mesh, geom=0):
1249 self.Create(mesh, geom, self.algoType)
1252 pass # end of StdMeshersDC_UseExisting_1D class
1254 ## Defines a stub 2D algorithm, which enables "manual" creation of nodes and
1255 # faces usable by 3D algoritms
1257 # It is created by calling smesh.Mesh.UseExistingFaces(geom=0)
1259 # @ingroup l3_algos_basic
1260 class StdMeshersDC_UseExisting_2D(Mesh_Algorithm):
1262 ## name of the dynamic method in smesh.Mesh class
1264 meshMethod = "UseExistingFaces"
1265 ## type of algorithm used with helper function in smesh.Mesh class
1267 algoType = "UseExisting_2D"
1269 ## Private constructor.
1270 # @param mesh parent mesh object algorithm is assigned to
1271 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
1272 # if it is @c 0 (default), the algorithm is assigned to the main shape
1273 def __init__(self, mesh, geom=0):
1274 self.Create(mesh, geom, self.algoType)
1277 pass # end of StdMeshersDC_UseExisting_2D class