-# 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
- name = ""
- if not geom:
- self.geom = piece
- else:
- self.geom = geom
- try:
- name = GetName(geom)
- pass
- except:
- pass
- if not name and geom.GetShapeType() != geompyDC.GEOM.COMPOUND:
- # for all groups SubShapeName() returns "Compound_-1"
- name = mesh.geompyD.SubShapeName(geom, piece)
- if not name:
- name = "%s_%s"%(geom.GetShapeType(), id(geom)%10000)
- # publish geom of sub-mesh (issue 0021122)
- if not self.geom.IsSame( self.mesh.geom ) and not self.geom.GetStudyEntry():
- studyID = self.mesh.smeshpyD.GetCurrentStudy()._get_StudyId()
- if studyID != self.mesh.geompyD.myStudyId:
- self.mesh.geompyD.init_geom( self.mesh.smeshpyD.GetCurrentStudy())
- self.mesh.geompyD.addToStudyInFather( self.mesh.geom, self.geom, name )
- pass
- self.subm = mesh.mesh.GetSubMesh(geom, algo.GetName())
- self.algo = algo
- status = mesh.mesh.AddHypothesis(self.geom, self.algo)
- TreatHypoStatus( status, algo.GetName(), name, 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
- geomName=""
- if self.geom:
- geomName = GetName(self.geom)
- status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
- TreatHypoStatus( status, GetName(hypo), geomName, 0 )
- return hypo
-
- ## Returns entry of the shape to mesh in the study
- def MainShapeEntry(self):
- entry = ""
- if not self.mesh or not self.mesh.GetMesh(): return entry
- if not self.mesh.GetMesh().HasShapeToMesh(): return entry
- study = self.mesh.smeshpyD.GetCurrentStudy()
- ior = salome.orb.object_to_string( self.mesh.GetShape() )
- sobj = study.FindObjectIOR(ior)
- if sobj: entry = sobj.GetID()
- if not entry: return ""
- return entry
-
- ## Defines "ViscousLayers" hypothesis to give parameters of layers of prisms to build
- # near mesh boundary. This hypothesis can be used by several 3D algorithms:
- # NETGEN 3D, GHS3D, Hexahedron(i,j,k)
- # @param thickness total thickness of layers of prisms
- # @param numberOfLayers number of layers of prisms
- # @param stretchFactor factor (>1.0) of growth of layer thickness towards inside of mesh
- # @param ignoreFaces geometrical face (or their ids) not to generate layers on
- # @ingroup l3_hypos_additi
- def ViscousLayers(self, thickness, numberOfLayers, stretchFactor, ignoreFaces=[]):
- if not isinstance(self.algo, SMESH._objref_SMESH_3D_Algo):
- raise TypeError, "ViscousLayers are supported by 3D algorithms only"
- if not "ViscousLayers" in self.GetCompatibleHypothesis():
- raise TypeError, "ViscousLayers are not supported by %s"%self.algo.GetName()
- if ignoreFaces and isinstance( ignoreFaces[0], geompyDC.GEOM._objref_GEOM_Object ):
- ignoreFaces = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, f) for f in ignoreFaces ]
- hyp = self.Hypothesis("ViscousLayers",
- [thickness, numberOfLayers, stretchFactor, ignoreFaces])
- hyp.SetTotalThickness(thickness)
- hyp.SetNumberLayers(numberOfLayers)
- hyp.SetStretchFactor(stretchFactor)
- hyp.SetIgnoreFaces(ignoreFaces)
- return hyp
-
-# 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 reversedEdges is a list of edges to mesh using reversed orientation
- # @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=[], reversedEdges=[], UseExisting=0):
- if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
- reversedEdges, UseExisting = [], reversedEdges
- entry = self.MainShapeEntry()
- if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
- reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
- if s == []:
- hyp = self.Hypothesis("NumberOfSegments", [n, reversedEdges, entry],
- UseExisting=UseExisting,
- CompareMethod=self.CompareNumberOfSegments)
- else:
- hyp = self.Hypothesis("NumberOfSegments", [n,s, reversedEdges, entry],
- UseExisting=UseExisting,
- CompareMethod=self.CompareNumberOfSegments)
- hyp.SetDistrType( 1 )
- hyp.SetScaleFactor(s)
- hyp.SetNumberOfSegments(n)
- hyp.SetReversedEdges( reversedEdges )
- hyp.SetObjectEntry( entry )
- 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) == 3:
- if hyp.GetReversedEdges() == args[1]:
- if not args[1] or hyp.GetObjectEntry() == args[2]:
- return True
- else:
- if hyp.GetReversedEdges() == args[2]:
- if not args[2] or hyp.GetObjectEntry() == args[3]:
- 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 reversedEdges is a list of edges to mesh using reversed orientation
- # @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, reversedEdges=[], UseExisting=0):
- if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
- reversedEdges, UseExisting = [], reversedEdges
- if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
- reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
- entry = self.MainShapeEntry()
- hyp = self.Hypothesis("Arithmetic1D", [start, end, reversedEdges, entry],
- UseExisting=UseExisting,
- CompareMethod=self.CompareArithmetic1D)
- hyp.SetStartLength(start)
- hyp.SetEndLength(end)
- hyp.SetReversedEdges( reversedEdges )
- hyp.SetObjectEntry( entry )
- 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]):
- if hyp.GetReversedEdges() == args[2]:
- if not args[2] or hyp.GetObjectEntry() == args[3]:
- return True
- return False
-
-
- ## Defines "FixedPoints1D" hypothesis to cut an edge using parameter
- # on curve from 0 to 1 (additionally it is neecessary to check
- # orientation of edges and create list of reversed edges if it is
- # needed) and sets numbers of segments between given points (default
- # values are equals 1
- # @param points defines the list of parameters on curve
- # @param nbSegs defines the list of numbers of segments
- # @param reversedEdges is a list of edges to mesh using reversed orientation
- # @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 FixedPoints1D(self, points, nbSegs=[1], reversedEdges=[], UseExisting=0):
- if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
- reversedEdges, UseExisting = [], reversedEdges
- if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
- reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
- entry = self.MainShapeEntry()
- hyp = self.Hypothesis("FixedPoints1D", [points, nbSegs, reversedEdges, entry],
- UseExisting=UseExisting,
- CompareMethod=self.CompareFixedPoints1D)
- hyp.SetPoints(points)
- hyp.SetNbSegments(nbSegs)
- hyp.SetReversedEdges(reversedEdges)
- hyp.SetObjectEntry(entry)
- return hyp
-
- ## Private method
- ## Check if the given "FixedPoints1D" hypothesis has the same parameters
- ## as the given arguments
- def CompareFixedPoints1D(self, hyp, args):
- if hyp.GetPoints() == args[0]:
- if hyp.GetNbSegments() == args[1]:
- if hyp.GetReversedEdges() == args[2]:
- if not args[2] or hyp.GetObjectEntry() == args[3]:
- 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 reversedEdges is a list of edges to mesh using reversed orientation
- # @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, reversedEdges=[], UseExisting=0):
- if not isinstance(reversedEdges,list): #old version script, before adding reversedEdges
- reversedEdges, UseExisting = [], reversedEdges
- if reversedEdges and isinstance(reversedEdges[0],geompyDC.GEOM._objref_GEOM_Object):
- reversedEdges = [ self.mesh.geompyD.GetSubShapeID(self.mesh.geom, e) for e in reversedEdges ]
- entry = self.MainShapeEntry()
- hyp = self.Hypothesis("StartEndLength", [start, end, reversedEdges, entry],
- UseExisting=UseExisting,
- CompareMethod=self.CompareStartEndLength)
- hyp.SetStartLength(start)
- hyp.SetEndLength(end)
- hyp.SetReversedEdges( reversedEdges )
- hyp.SetObjectEntry( entry )
- 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]):
- if hyp.GetReversedEdges() == args[2]:
- if not args[2] or hyp.GetObjectEntry() == args[3]:
- 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.ExtractShapes(self.geom, geompyDC.ShapeType["VERTEX"],True)[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"
- try:
- name = GetName(self.geom)
- pass
- except:
- piece = self.mesh.geom
- name = self.mesh.geompyD.SubShapeName(self.geom, piece)
- self.mesh.geompyD.addToStudyInFather(piece, self.geom, name)
- pass
- 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:
- CheckPlugin(BLSURF)
- self.Create(mesh, geom, "BLSURF", "libBLSURFEngine.so")
- #self.SetPhysicalMesh() - PAL19680
- elif algoType == NETGEN:
- CheckPlugin(NETGEN)
- self.Create(mesh, geom, "NETGEN_2D", "libNETGENEngine.so")
- pass
- elif algoType == NETGEN_2D:
- CheckPlugin(NETGEN)
- 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
-
- ## Sets a way to define size of mesh elements to generate.
- # @param thePhysicalMesh is: DefaultSize or Custom.
- # @ingroup l3_hypos_blsurf
- def SetPhysicalMesh(self, thePhysicalMesh=DefaultSize):
- # Parameter of BLSURF algo
- self.Parameters().SetPhysicalMesh(thePhysicalMesh)
-
- ## Sets size of mesh elements to generate.
- # @ingroup l3_hypos_blsurf
- def SetPhySize(self, theVal):
- # Parameter of BLSURF algo
- self.SetPhysicalMesh(1) #Custom - else why to set the size?
- self.Parameters().SetPhySize(theVal)
-
- ## Sets lower boundary of mesh element size (PhySize).
- # @ingroup l3_hypos_blsurf
- def SetPhyMin(self, theVal=-1):
- # Parameter of BLSURF algo
- self.Parameters().SetPhyMin(theVal)
-
- ## Sets upper boundary of mesh element size (PhySize).
- # @ingroup l3_hypos_blsurf
- def SetPhyMax(self, theVal=-1):
- # Parameter of BLSURF algo
- self.Parameters().SetPhyMax(theVal)
-
- ## Sets a way to define maximum angular deflection of mesh from CAD model.
- # @param theGeometricMesh is: 0 (None) or 1 (Custom)
- # @ingroup l3_hypos_blsurf
- def SetGeometricMesh(self, theGeometricMesh=0):
- # Parameter of BLSURF algo
- if self.Parameters().GetPhysicalMesh() == 0: theGeometricMesh = 1
- self.params.SetGeometricMesh(theGeometricMesh)
-
- ## Sets angular deflection (in degrees) of a mesh face from CAD surface.
- # @ingroup l3_hypos_blsurf
- def SetAngleMeshS(self, theVal=_angleMeshS):
- # Parameter of BLSURF algo
- if self.Parameters().GetGeometricMesh() == 0: theVal = self._angleMeshS
- self.params.SetAngleMeshS(theVal)
-
- ## Sets angular deflection (in degrees) of a mesh edge from CAD curve.
- # @ingroup l3_hypos_blsurf
- def SetAngleMeshC(self, theVal=_angleMeshS):
- # Parameter of BLSURF algo
- if self.Parameters().GetGeometricMesh() == 0: theVal = self._angleMeshS
- self.params.SetAngleMeshC(theVal)
-
- ## Sets lower boundary of mesh element size computed to respect angular deflection.
- # @ingroup l3_hypos_blsurf
- def SetGeoMin(self, theVal=-1):
- # Parameter of BLSURF algo
- self.Parameters().SetGeoMin(theVal)
-
- ## Sets upper boundary of mesh element size computed to respect angular deflection.
- # @ingroup l3_hypos_blsurf
- def SetGeoMax(self, theVal=-1):
- # Parameter of BLSURF algo
- self.Parameters().SetGeoMax(theVal)
-
- ## Sets maximal allowed ratio between the lengths of two adjacent edges.
- # @ingroup l3_hypos_blsurf
- def SetGradation(self, theVal=_gradation):
- # Parameter of BLSURF algo
- if self.Parameters().GetGeometricMesh() == 0: theVal = self._gradation
- self.params.SetGradation(theVal)
-
- ## Sets topology usage way.
- # @param way defines how mesh conformity is assured <ul>
- # <li>FromCAD - mesh conformity is assured by conformity of a shape</li>
- # <li>PreProcess or PreProcessPlus - by pre-processing a CAD model</li></ul>
- # @ingroup l3_hypos_blsurf
- def SetTopology(self, way):
- # Parameter of BLSURF algo
- self.Parameters().SetTopology(way)
-
- ## To respect geometrical edges or not.
- # @ingroup l3_hypos_blsurf
- def SetDecimesh(self, toIgnoreEdges=False):
- # Parameter of BLSURF algo
- self.Parameters().SetDecimesh(toIgnoreEdges)
-
- ## Sets verbosity level in the range 0 to 100.
- # @ingroup l3_hypos_blsurf
- def SetVerbosity(self, level):
- # Parameter of BLSURF algo
- self.Parameters().SetVerbosity(level)
-
- ## Sets advanced option value.
- # @ingroup l3_hypos_blsurf
- def SetOptionValue(self, optionName, level):
- # Parameter of BLSURF algo
- self.Parameters().SetOptionValue(optionName,level)
-
- ## Sets QuadAllowed flag.
- # Only for algoType == NETGEN(NETGEN_1D2D) || NETGEN_2D || BLSURF
- # @ingroup l3_hypos_netgen l3_hypos_blsurf
- def SetQuadAllowed(self, toAllow=True):
- if self.algoType == NETGEN_2D:
- if not self.params:
- # use simple hyps
- hasSimpleHyps = False
- simpleHyps = ["QuadranglePreference","LengthFromEdges","MaxElementArea"]
- for hyp in self.mesh.GetHypothesisList( self.geom ):
- if hyp.GetName() in simpleHyps:
- hasSimpleHyps = True
- if hyp.GetName() == "QuadranglePreference":
- if not toAllow: # remove QuadranglePreference
- self.mesh.RemoveHypothesis( self.geom, hyp )
- pass
- return
- pass
- pass
- if hasSimpleHyps:
- if toAllow: # add QuadranglePreference
- self.Hypothesis("QuadranglePreference", UseExisting=1, CompareMethod=self.CompareEqualHyp)
- pass
- return
- pass
- pass
- if self.Parameters():
- self.params.SetQuadAllowed(toAllow)
- return
-
- ## Defines hypothesis having several parameters
- #
- # @ingroup l3_hypos_netgen
- def Parameters(self, which=SOLE):
- if not self.params:
- if self.algoType == NETGEN:
- if which == SIMPLE:
- self.params = self.Hypothesis("NETGEN_SimpleParameters_2D", [],
- "libNETGENEngine.so", UseExisting=0)
- else:
- self.params = self.Hypothesis("NETGEN_Parameters_2D", [],
- "libNETGENEngine.so", UseExisting=0)
- elif self.algoType == MEFISTO:
- print "Mefisto algo support no multi-parameter hypothesis"
- elif self.algoType == NETGEN_2D:
- self.params = self.Hypothesis("NETGEN_Parameters_2D_ONLY", [],
- "libNETGENEngine.so", UseExisting=0)
- elif self.algoType == BLSURF:
- self.params = self.Hypothesis("BLSURF_Parameters", [],
- "libBLSURFEngine.so", UseExisting=0)
- else:
- print "Mesh_Triangle with algo type %s does not have such a parameter, check algo type"%self.algoType
- return self.params
-
- ## Sets MaxSize
- #
- # Only for algoType == NETGEN
- # @ingroup l3_hypos_netgen
- def SetMaxSize(self, theSize):
- if self.Parameters():
- self.params.SetMaxSize(theSize)
-
- ## Sets SecondOrder flag
- #
- # Only for algoType == NETGEN
- # @ingroup l3_hypos_netgen
- def SetSecondOrder(self, theVal):
- if self.Parameters():
- self.params.SetSecondOrder(theVal)
-
- ## Sets Optimize flag
- #
- # Only for algoType == NETGEN
- # @ingroup l3_hypos_netgen
- def SetOptimize(self, theVal):
- if self.Parameters():
- self.params.SetOptimize(theVal)
-
- ## Sets Fineness
- # @param theFineness is:
- # VeryCoarse, Coarse, Moderate, Fine, VeryFine or Custom
- #
- # Only for algoType == NETGEN
- # @ingroup l3_hypos_netgen
- def SetFineness(self, theFineness):
- if self.Parameters():
- self.params.SetFineness(theFineness)
-
- ## Sets GrowthRate
- #
- # Only for algoType == NETGEN
- # @ingroup l3_hypos_netgen
- def SetGrowthRate(self, theRate):
- if self.Parameters():
- self.params.SetGrowthRate(theRate)
-
- ## Sets NbSegPerEdge
- #
- # Only for algoType == NETGEN
- # @ingroup l3_hypos_netgen
- def SetNbSegPerEdge(self, theVal):
- if self.Parameters():
- self.params.SetNbSegPerEdge(theVal)
-
- ## Sets NbSegPerRadius
- #
- # Only for algoType == NETGEN
- # @ingroup l3_hypos_netgen
- def SetNbSegPerRadius(self, theVal):
- if self.Parameters():
- self.params.SetNbSegPerRadius(theVal)
-
- ## Sets number of segments overriding value set by SetLocalLength()
- #
- # Only for algoType == NETGEN
- # @ingroup l3_hypos_netgen
- def SetNumberOfSegments(self, theVal):
- self.Parameters(SIMPLE).SetNumberOfSegments(theVal)
-
- ## Sets number of segments overriding value set by SetNumberOfSegments()
- #
- # Only for algoType == NETGEN
- # @ingroup l3_hypos_netgen
- def SetLocalLength(self, theVal):
- self.Parameters(SIMPLE).SetLocalLength(theVal)
-
- pass
-
-
-# Public class: Mesh_Quadrangle
-# -----------------------------