-## The mother class to define algorithm, it is not recommended to use it directly.
-#
-# More details.
-# @ingroup l2_algorithms
-class Mesh_Algorithm:
- # @class Mesh_Algorithm
- # @brief Class Mesh_Algorithm
-
- #def __init__(self,smesh):
- # self.smesh=smesh
- def __init__(self):
- self.mesh = None
- self.geom = None
- self.subm = None
- self.algo = None
-
- ## Finds a hypothesis in the study by its type name and parameters.
- # Finds only the hypotheses created in smeshpyD engine.
- # @return SMESH.SMESH_Hypothesis
- def FindHypothesis (self, hypname, args, CompareMethod, smeshpyD):
- study = smeshpyD.GetCurrentStudy()
- #to do: find component by smeshpyD object, not by its data type
- scomp = study.FindComponent(smeshpyD.ComponentDataType())
- if scomp is not None:
- res,hypRoot = scomp.FindSubObject(SMESH.Tag_HypothesisRoot)
- # Check if the root label of the hypotheses exists
- if res and hypRoot is not None:
- iter = study.NewChildIterator(hypRoot)
- # Check all published hypotheses
- while iter.More():
- hypo_so_i = iter.Value()
- attr = hypo_so_i.FindAttribute("AttributeIOR")[1]
- if attr is not None:
- anIOR = attr.Value()
- hypo_o_i = salome.orb.string_to_object(anIOR)
- if hypo_o_i is not None:
- # Check if this is a hypothesis
- hypo_i = hypo_o_i._narrow(SMESH.SMESH_Hypothesis)
- if hypo_i is not None:
- # Check if the hypothesis belongs to current engine
- if smeshpyD.GetObjectId(hypo_i) > 0:
- # Check if this is the required hypothesis
- if hypo_i.GetName() == hypname:
- # Check arguments
- if CompareMethod(hypo_i, args):
- # found!!!
- return hypo_i
- pass
- pass
- pass
- pass
- pass
- iter.Next()
- pass
- pass
- pass
- return None
-
- ## Finds the algorithm in the study by its type name.
- # Finds only the algorithms, which have been created in smeshpyD engine.
- # @return SMESH.SMESH_Algo
- def FindAlgorithm (self, algoname, smeshpyD):
- study = smeshpyD.GetCurrentStudy()
- #to do: find component by smeshpyD object, not by its data type
- scomp = study.FindComponent(smeshpyD.ComponentDataType())
- if scomp is not None:
- res,hypRoot = scomp.FindSubObject(SMESH.Tag_AlgorithmsRoot)
- # Check if the root label of the algorithms exists
- if res and hypRoot is not None:
- iter = study.NewChildIterator(hypRoot)
- # Check all published algorithms
- while iter.More():
- algo_so_i = iter.Value()
- attr = algo_so_i.FindAttribute("AttributeIOR")[1]
- if attr is not None:
- anIOR = attr.Value()
- algo_o_i = salome.orb.string_to_object(anIOR)
- if algo_o_i is not None:
- # Check if this is an algorithm
- algo_i = algo_o_i._narrow(SMESH.SMESH_Algo)
- if algo_i is not None:
- # Checks if the algorithm belongs to the current engine
- if smeshpyD.GetObjectId(algo_i) > 0:
- # Check if this is the required algorithm
- if algo_i.GetName() == algoname:
- # found!!!
- return algo_i
- pass
- pass
- pass
- pass
- iter.Next()
- pass
- pass
- pass
- return None
-
- ## If the algorithm is global, returns 0; \n
- # else returns the submesh associated to this algorithm.
- def GetSubMesh(self):
- return self.subm
-
- ## Returns the wrapped mesher.
- def GetAlgorithm(self):
- return self.algo
-
- ## Gets the list of hypothesis that can be used with this algorithm
- def GetCompatibleHypothesis(self):
- mylist = []
- if self.algo:
- mylist = self.algo.GetCompatibleHypothesis()
- return mylist
-
- ## Gets the name of the algorithm
- def GetName(self):
- GetName(self.algo)
-
- ## Sets the name to the algorithm
- def SetName(self, name):
- self.mesh.smeshpyD.SetName(self.algo, name)
-
- ## Gets the id of the algorithm
- def GetId(self):
- return self.algo.GetId()
-
- ## Private method.
- def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
- if geom is None:
- raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
- algo = self.FindAlgorithm(hypo, mesh.smeshpyD)
- if algo is None:
- algo = mesh.smeshpyD.CreateHypothesis(hypo, so)
- pass
- self.Assign(algo, mesh, geom)
- return self.algo
-
- ## Private method
- def Assign(self, algo, mesh, geom):
- if geom is None:
- raise RuntimeError, "Attemp to create " + algo + " algoritm on None shape"
- self.mesh = mesh
- piece = mesh.geom
- if not geom:
- self.geom = piece
- else:
- self.geom = geom
- name = GetName(geom)
- if name==NO_NAME:
- name = mesh.geompyD.SubShapeName(geom, piece)
- mesh.geompyD.addToStudyInFather(piece, geom, name)
- self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
-
- self.algo = algo
- status = mesh.mesh.AddHypothesis(self.geom, self.algo)
- TreatHypoStatus( status, algo.GetName(), GetName(self.geom), True )
-
- def CompareHyp (self, hyp, args):
- print "CompareHyp is not implemented for ", self.__class__.__name__, ":", hyp.GetName()
- return False
-
- def CompareEqualHyp (self, hyp, args):
- return True
-
- ## Private method
- def Hypothesis (self, hyp, args=[], so="libStdMeshersEngine.so",
- UseExisting=0, CompareMethod=""):
- hypo = None
- if UseExisting:
- if CompareMethod == "": CompareMethod = self.CompareHyp
- hypo = self.FindHypothesis(hyp, args, CompareMethod, self.mesh.smeshpyD)
- pass
- if hypo is None:
- hypo = self.mesh.smeshpyD.CreateHypothesis(hyp, so)
- a = ""
- s = "="
- i = 0
- n = len(args)
- while i<n:
- a = a + s + str(args[i])
- s = ","
- i = i + 1
- pass
- self.mesh.smeshpyD.SetName(hypo, hyp + a)
- pass
- status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
- TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
- return hypo
-
-
-# Public class: Mesh_Segment
-# --------------------------
-
-## Class to define a segment 1D algorithm for discretization
-#
-# More details.
-# @ingroup l3_algos_basic
-class Mesh_Segment(Mesh_Algorithm):
-
- ## Private constructor.
- def __init__(self, mesh, geom=0):
- Mesh_Algorithm.__init__(self)
- self.Create(mesh, geom, "Regular_1D")
-
- ## Defines "LocalLength" hypothesis to cut an edge in several segments with the same length
- # @param l for the length of segments that cut an edge
- # @param UseExisting if ==true - searches for an existing hypothesis created with
- # the same parameters, else (default) - creates a new one
- # @param p precision, used for calculation of the number of segments.
- # The precision should be a positive, meaningful value within the range [0,1].
- # In general, the number of segments is calculated with the formula:
- # nb = ceil((edge_length / l) - p)
- # Function ceil rounds its argument to the higher integer.
- # So, p=0 means rounding of (edge_length / l) to the higher integer,
- # p=0.5 means rounding of (edge_length / l) to the nearest integer,
- # p=1 means rounding of (edge_length / l) to the lower integer.
- # Default value is 1e-07.
- # @return an instance of StdMeshers_LocalLength hypothesis
- # @ingroup l3_hypos_1dhyps
- def LocalLength(self, l, UseExisting=0, p=1e-07):
- hyp = self.Hypothesis("LocalLength", [l,p], UseExisting=UseExisting,
- CompareMethod=self.CompareLocalLength)
- hyp.SetLength(l)
- hyp.SetPrecision(p)
- return hyp
-
- ## Private method
- ## Checks if the given "LocalLength" hypothesis has the same parameters as the given arguments
- def CompareLocalLength(self, hyp, args):
- if IsEqual(hyp.GetLength(), args[0]):
- return IsEqual(hyp.GetPrecision(), args[1])
- return False
-
- ## Defines "MaxSize" hypothesis to cut an edge into segments not longer than given value
- # @param length is optional maximal allowed length of segment, if it is omitted
- # the preestimated length is used that depends on geometry size
- # @param UseExisting if ==true - searches for an existing hypothesis created with
- # the same parameters, else (default) - create a new one
- # @return an instance of StdMeshers_MaxLength hypothesis
- # @ingroup l3_hypos_1dhyps
- def MaxSize(self, length=0.0, UseExisting=0):
- hyp = self.Hypothesis("MaxLength", [length], UseExisting=UseExisting)
- if length > 0.0:
- # set given length
- hyp.SetLength(length)
- if not UseExisting:
- # set preestimated length
- gen = self.mesh.smeshpyD
- initHyp = gen.GetHypothesisParameterValues("MaxLength", "libStdMeshersEngine.so",
- self.mesh.GetMesh(), self.mesh.GetShape(),
- False) # <- byMesh
- preHyp = initHyp._narrow(StdMeshers.StdMeshers_MaxLength)
- if preHyp:
- hyp.SetPreestimatedLength( preHyp.GetPreestimatedLength() )
- pass
- pass
- hyp.SetUsePreestimatedLength( length == 0.0 )
- return hyp
-
- ## Defines "NumberOfSegments" hypothesis to cut an edge in a fixed number of segments
- # @param n for the number of segments that cut an edge
- # @param s for the scale factor (optional)
- # @param UseExisting if ==true - searches for an existing hypothesis created with
- # the same parameters, else (default) - create a new one
- # @return an instance of StdMeshers_NumberOfSegments hypothesis
- # @ingroup l3_hypos_1dhyps
- def NumberOfSegments(self, n, s=[], UseExisting=0):
- if s == []:
- hyp = self.Hypothesis("NumberOfSegments", [n], UseExisting=UseExisting,
- CompareMethod=self.CompareNumberOfSegments)
- else:
- hyp = self.Hypothesis("NumberOfSegments", [n,s], UseExisting=UseExisting,
- CompareMethod=self.CompareNumberOfSegments)
- hyp.SetDistrType( 1 )
- hyp.SetScaleFactor(s)
- hyp.SetNumberOfSegments(n)
- return hyp
-
- ## Private method
- ## Checks if the given "NumberOfSegments" hypothesis has the same parameters as the given arguments
- def CompareNumberOfSegments(self, hyp, args):
- if hyp.GetNumberOfSegments() == args[0]:
- if len(args) == 1:
- return True
- else:
- if hyp.GetDistrType() == 1:
- if IsEqual(hyp.GetScaleFactor(), args[1]):
- return True
- return False
-
- ## Defines "Arithmetic1D" hypothesis to cut an edge in several segments with increasing arithmetic length
- # @param start defines the length of the first segment
- # @param end defines the length of the last segment
- # @param UseExisting if ==true - searches for an existing hypothesis created with
- # the same parameters, else (default) - creates a new one
- # @return an instance of StdMeshers_Arithmetic1D hypothesis
- # @ingroup l3_hypos_1dhyps
- def Arithmetic1D(self, start, end, UseExisting=0):
- hyp = self.Hypothesis("Arithmetic1D", [start, end], UseExisting=UseExisting,
- CompareMethod=self.CompareArithmetic1D)
- hyp.SetLength(start, 1)
- hyp.SetLength(end , 0)
- return hyp
-
- ## Private method
- ## Check if the given "Arithmetic1D" hypothesis has the same parameters as the given arguments
- def CompareArithmetic1D(self, hyp, args):
- if IsEqual(hyp.GetLength(1), args[0]):
- if IsEqual(hyp.GetLength(0), args[1]):
- return True
- return False
-
- ## Defines "StartEndLength" hypothesis to cut an edge in several segments with increasing geometric length
- # @param start defines the length of the first segment
- # @param end defines the length of the last segment
- # @param UseExisting if ==true - searches for an existing hypothesis created with
- # the same parameters, else (default) - creates a new one
- # @return an instance of StdMeshers_StartEndLength hypothesis
- # @ingroup l3_hypos_1dhyps
- def StartEndLength(self, start, end, UseExisting=0):
- hyp = self.Hypothesis("StartEndLength", [start, end], UseExisting=UseExisting,
- CompareMethod=self.CompareStartEndLength)
- hyp.SetLength(start, 1)
- hyp.SetLength(end , 0)
- return hyp
-
- ## Check if the given "StartEndLength" hypothesis has the same parameters as the given arguments
- def CompareStartEndLength(self, hyp, args):
- if IsEqual(hyp.GetLength(1), args[0]):
- if IsEqual(hyp.GetLength(0), args[1]):
- return True
- return False
-
- ## Defines "Deflection1D" hypothesis
- # @param d for the deflection
- # @param UseExisting if ==true - searches for an existing hypothesis created with
- # the same parameters, else (default) - create a new one
- # @ingroup l3_hypos_1dhyps
- def Deflection1D(self, d, UseExisting=0):
- hyp = self.Hypothesis("Deflection1D", [d], UseExisting=UseExisting,
- CompareMethod=self.CompareDeflection1D)
- hyp.SetDeflection(d)
- return hyp
-
- ## Check if the given "Deflection1D" hypothesis has the same parameters as the given arguments
- def CompareDeflection1D(self, hyp, args):
- return IsEqual(hyp.GetDeflection(), args[0])
-
- ## Defines "Propagation" hypothesis that propagates all other hypotheses on all other edges that are at
- # the opposite side in case of quadrangular faces
- # @ingroup l3_hypos_additi
- def Propagation(self):
- return self.Hypothesis("Propagation", UseExisting=1, CompareMethod=self.CompareEqualHyp)
-
- ## Defines "AutomaticLength" hypothesis
- # @param fineness for the fineness [0-1]
- # @param UseExisting if ==true - searches for an existing hypothesis created with the
- # same parameters, else (default) - create a new one
- # @ingroup l3_hypos_1dhyps
- def AutomaticLength(self, fineness=0, UseExisting=0):
- hyp = self.Hypothesis("AutomaticLength",[fineness],UseExisting=UseExisting,
- CompareMethod=self.CompareAutomaticLength)
- hyp.SetFineness( fineness )
- return hyp
-
- ## Checks if the given "AutomaticLength" hypothesis has the same parameters as the given arguments
- def CompareAutomaticLength(self, hyp, args):
- return IsEqual(hyp.GetFineness(), args[0])
-
- ## Defines "SegmentLengthAroundVertex" hypothesis
- # @param length for the segment length
- # @param vertex for the length localization: the vertex index [0,1] | vertex object.
- # Any other integer value means that the hypothesis will be set on the
- # whole 1D shape, where Mesh_Segment algorithm is assigned.
- # @param UseExisting if ==true - searches for an existing hypothesis created with
- # the same parameters, else (default) - creates a new one
- # @ingroup l3_algos_segmarv
- def LengthNearVertex(self, length, vertex=0, UseExisting=0):
- import types
- store_geom = self.geom
- if type(vertex) is types.IntType:
- if vertex == 0 or vertex == 1:
- vertex = self.mesh.geompyD.SubShapeAllSorted(self.geom, geompyDC.ShapeType["VERTEX"])[vertex]
- self.geom = vertex
- pass
- pass
- else:
- self.geom = vertex
- pass
- ### 0D algorithm
- if self.geom is None:
- raise RuntimeError, "Attemp to create SegmentAroundVertex_0D algoritm on None shape"
- name = GetName(self.geom)
- if name == NO_NAME:
- piece = self.mesh.geom
- name = self.mesh.geompyD.SubShapeName(self.geom, piece)
- self.mesh.geompyD.addToStudyInFather(piece, self.geom, name)
- algo = self.FindAlgorithm("SegmentAroundVertex_0D", self.mesh.smeshpyD)
- if algo is None:
- algo = self.mesh.smeshpyD.CreateHypothesis("SegmentAroundVertex_0D", "libStdMeshersEngine.so")
- pass
- status = self.mesh.mesh.AddHypothesis(self.geom, algo)
- TreatHypoStatus(status, "SegmentAroundVertex_0D", name, True)
- ###
- hyp = self.Hypothesis("SegmentLengthAroundVertex", [length], UseExisting=UseExisting,
- CompareMethod=self.CompareLengthNearVertex)
- self.geom = store_geom
- hyp.SetLength( length )
- return hyp
-
- ## Checks if the given "LengthNearVertex" hypothesis has the same parameters as the given arguments
- # @ingroup l3_algos_segmarv
- def CompareLengthNearVertex(self, hyp, args):
- return IsEqual(hyp.GetLength(), args[0])
-
- ## Defines "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
- # If the 2D mesher sees that all boundary edges are quadratic,
- # it generates quadratic faces, else it generates linear faces using
- # medium nodes as if they are vertices.
- # The 3D mesher generates quadratic volumes only if all boundary faces
- # are quadratic, else it fails.
- #
- # @ingroup l3_hypos_additi
- def QuadraticMesh(self):
- hyp = self.Hypothesis("QuadraticMesh", UseExisting=1, CompareMethod=self.CompareEqualHyp)
- return hyp
-
-# Public class: Mesh_CompositeSegment
-# --------------------------
-
-## Defines a segment 1D algorithm for discretization
-#
-# @ingroup l3_algos_basic
-class Mesh_CompositeSegment(Mesh_Segment):
-
- ## Private constructor.
- def __init__(self, mesh, geom=0):
- self.Create(mesh, geom, "CompositeSegment_1D")
-
-
-# Public class: Mesh_Segment_Python
-# ---------------------------------
-
-## Defines a segment 1D algorithm for discretization with python function
-#
-# @ingroup l3_algos_basic
-class Mesh_Segment_Python(Mesh_Segment):
-
- ## Private constructor.
- def __init__(self, mesh, geom=0):
- import Python1dPlugin
- self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
-
- ## Defines "PythonSplit1D" hypothesis
- # @param n for the number of segments that cut an edge
- # @param func for the python function that calculates the length of all segments
- # @param UseExisting if ==true - searches for the existing hypothesis created with
- # the same parameters, else (default) - creates a new one
- # @ingroup l3_hypos_1dhyps
- def PythonSplit1D(self, n, func, UseExisting=0):
- hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so",
- UseExisting=UseExisting, CompareMethod=self.ComparePythonSplit1D)
- hyp.SetNumberOfSegments(n)
- hyp.SetPythonLog10RatioFunction(func)
- return hyp
-
- ## Checks if the given "PythonSplit1D" hypothesis has the same parameters as the given arguments
- def ComparePythonSplit1D(self, hyp, args):
- #if hyp.GetNumberOfSegments() == args[0]:
- # if hyp.GetPythonLog10RatioFunction() == args[1]:
- # return True
- return False
-
-# Public class: Mesh_Triangle
-# ---------------------------
-
-## Defines a triangle 2D algorithm
-#
-# @ingroup l3_algos_basic
-class Mesh_Triangle(Mesh_Algorithm):
-
- # default values
- algoType = 0
- params = 0
-
- _angleMeshS = 8
- _gradation = 1.1
-
- ## Private constructor.
- def __init__(self, mesh, algoType, geom=0):
- Mesh_Algorithm.__init__(self)
-
- self.algoType = algoType
- if algoType == MEFISTO:
- self.Create(mesh, geom, "MEFISTO_2D")
- pass
- elif algoType == BLSURF:
- import BLSURFPlugin
- self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
- #self.SetPhysicalMesh() - PAL19680
- elif algoType == NETGEN:
- if noNETGENPlugin:
- print "Warning: NETGENPlugin module unavailable"
- pass
- self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
- pass
- elif algoType == NETGEN_2D:
- if noNETGENPlugin:
- print "Warning: NETGENPlugin module unavailable"
- pass
- self.Create(mesh, geom, "NETGEN_2D_ONLY", "libNETGENEngine.so")
- pass
-
- ## Defines "MaxElementArea" hypothesis basing on the definition of the maximum area of each triangle
- # @param area for the maximum area of each triangle
- # @param UseExisting if ==true - searches for an existing hypothesis created with the
- # same parameters, else (default) - creates a new one
- #
- # Only for algoType == MEFISTO || NETGEN_2D
- # @ingroup l3_hypos_2dhyps
- def MaxElementArea(self, area, UseExisting=0):
- if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
- hyp = self.Hypothesis("MaxElementArea", [area], UseExisting=UseExisting,
- CompareMethod=self.CompareMaxElementArea)
- elif self.algoType == NETGEN:
- hyp = self.Parameters(SIMPLE)
- hyp.SetMaxElementArea(area)
- return hyp
-
- ## Checks if the given "MaxElementArea" hypothesis has the same parameters as the given arguments
- def CompareMaxElementArea(self, hyp, args):
- return IsEqual(hyp.GetMaxElementArea(), args[0])
-
- ## Defines "LengthFromEdges" hypothesis to build triangles
- # based on the length of the edges taken from the wire
- #
- # Only for algoType == MEFISTO || NETGEN_2D
- # @ingroup l3_hypos_2dhyps
- def LengthFromEdges(self):
- if self.algoType == MEFISTO or self.algoType == NETGEN_2D:
- hyp = self.Hypothesis("LengthFromEdges", UseExisting=1, CompareMethod=self.CompareEqualHyp)
- return hyp
- elif self.algoType == NETGEN:
- hyp = self.Parameters(SIMPLE)
- hyp.LengthFromEdges()
- return hyp