-import geompy
-import StdMeshers
-import SMESH
-
-# Public variables
-# ----------------
-
-REGULAR = 1
-PYTHON = 2
-
-NETGEN = 3
-GHS3D = 4
-
-smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
-smesh.SetCurrentStudy(salome.myStudy)
-
-# Private functions
-# -----------------
-
-NO_NAME = "NoName"
-
-def GetName(obj):
- ior = salome.orb.object_to_string(obj)
- sobj = salome.myStudy.FindObjectIOR(ior)
- if sobj is None:
- return NO_NAME
- else:
- attr = sobj.FindAttribute("AttributeName")[1]
- return attr.Value()
-
-def SetName(obj, name):
- ior = salome.orb.object_to_string(obj)
- sobj = salome.myStudy.FindObjectIOR(ior)
- if not sobj is None:
- attr = sobj.FindAttribute("AttributeName")[1]
- attr.SetValue(name)
-
-# Algorithms and hypothesis
-# =========================
-
-# Private class: Mesh_Algorithm
-# -----------------------------
-
-class Mesh_Algorithm:
- """
- Mother class to define algorithm, recommended to don't use directly
- """
-
- mesh = 0
- geom = 0
- subm = 0
- algo = 0
-
- def GetSubMesh(self):
- """
- If the algorithm is global, return 0
- else return the submesh associated to this algorithm
- """
- return self.subm
-
- def GetAlgorithm(self):
- """
- Return the wrapped mesher
- """
- return self.algo
-
- def TreatHypoStatus(self, status, hypName, geomName, isAlgo):
- """
- Private method. Print error message if a hypothesis was not assigned
- """
- if isAlgo:
- hypType = "algorithm"
- else:
- hypType = "hypothesis"
- if status == SMESH.HYP_UNKNOWN_FATAL :
- reason = "for unknown reason"
- elif status == SMESH.HYP_INCOMPATIBLE :
- reason = "this hypothesis mismatches algorithm"
- elif status == SMESH.HYP_NOTCONFORM :
- reason = "not conform mesh would be built"
- elif status == SMESH.HYP_ALREADY_EXIST :
- reason = hypType + " of the same dimension already assigned to this shape"
- elif status == SMESH.HYP_BAD_DIM :
- reason = hypType + " mismatches shape"
- elif status == SMESH.HYP_CONCURENT :
- reason = "there are concurrent hypotheses on sub-shapes"
- elif status == SMESH.HYP_BAD_SUBSHAPE :
- reason = "shape is neither the main one, nor its subshape, nor a valid group"
- else:
- return
- hypName = '"' + hypName + '"'
- geomName= '"' + geomName+ '"'
- if status < SMESH.HYP_UNKNOWN_FATAL:
- print hypName, "was assigned to", geomName,"but", reason
- else:
- print hypName, "was not assigned to",geomName,":", reason
- pass
-
- def Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
- """
- Private method
- """
- if geom is None:
- raise RuntimeError, "Attemp to create " + hypo + " algoritm on None shape"
- self.mesh = mesh
- piece = mesh.geom
- if geom==0:
- self.geom = piece
- name = GetName(piece)
- else:
- self.geom = geom
- name = GetName(geom)
- if name==NO_NAME:
- name = geompy.SubShapeName(geom, piece)
- geompy.addToStudyInFather(piece, geom, name)
- self.subm = mesh.mesh.GetSubMesh(geom, hypo)
-
- self.algo = smesh.CreateHypothesis(hypo, so)
- SetName(self.algo, name + "/" + hypo)
- status = mesh.mesh.AddHypothesis(self.geom, self.algo)
- self.TreatHypoStatus( status, hypo, name, 1 )
-
- def Hypothesis(self, hyp, args=[], so="libStdMeshersEngine.so"):
- """
- Private method
- """
- hypo = smesh.CreateHypothesis(hyp, so)
- a = ""
- s = "="
- i = 0
- n = len(args)
- while i<n:
- a = a + s + str(args[i])
- s = ","
- i = i + 1
- name = GetName(self.geom)
- SetName(hypo, name + "/" + hyp + a)
- status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
- self.TreatHypoStatus( status, hyp, name, 0 )
- return hypo
-
-# Public class: Mesh_Segment
-# --------------------------
-
-class Mesh_Segment(Mesh_Algorithm):
- """
- Class to define a segment 1D algorithm for discretization
- """
-
- def __init__(self, mesh, geom=0):
- """
- Private constructor
- """
- self.Create(mesh, geom, "Regular_1D")
-
- def LocalLength(self, l):
- """
- Define "LocalLength" hypothesis to cut an edge in several segments with the same length
- \param l for the length of segments that cut an edge
- """
- hyp = self.Hypothesis("LocalLength", [l])
- hyp.SetLength(l)
- return hyp
-
- def NumberOfSegments(self, n, s=[]):
- """
- Define "NumberOfSegments" hypothesis to cut an edge in several fixed number of segments
- \param n for the number of segments that cut an edge
- \param s for the scale factor (optional)
- """
- if s == []:
- hyp = self.Hypothesis("NumberOfSegments", [n])
- else:
- hyp = self.Hypothesis("NumberOfSegments", [n,s])
- hyp.SetDistrType( 1 )
- hyp.SetScaleFactor(s)
- hyp.SetNumberOfSegments(n)
- return hyp
-
- def Arithmetic1D(self, start, end):
- """
- Define "Arithmetic1D" hypothesis to cut an edge in several segments with arithmetic length increasing
- \param start for the length of the first segment
- \param end for the length of the last segment
- """
- hyp = self.Hypothesis("Arithmetic1D", [start, end])
- hyp.SetLength(start, 1)
- hyp.SetLength(end , 0)
- return hyp
-
- def StartEndLength(self, start, end):
- """
- Define "StartEndLength" hypothesis to cut an edge in several segments with geometric length increasing
- \param start for the length of the first segment
- \param end for the length of the last segment
- """
- hyp = self.Hypothesis("StartEndLength", [start, end])
- hyp.SetLength(start, 1)
- hyp.SetLength(end , 0)
- return hyp
-
- def Deflection1D(self, d):
- """
- Define "Deflection1D" hypothesis
- \param d for the deflection
- """
- hyp = self.Hypothesis("Deflection1D", [d])
- hyp.SetDeflection(d)
- return hyp
-
- def Propagation(self):
- """
- Define "Propagation" hypothesis that propagate all other hypothesis on all others edges that are in
- the opposite side in the case of quadrangular faces
- """
- return self.Hypothesis("Propagation")
-
- def AutomaticLength(self, fineness=0):
- """
- Define "AutomaticLength" hypothesis
- \param fineness for the fineness [0-1]
- """
- hyp = self.Hypothesis("AutomaticLength")
- hyp.SetFineness( fineness )
- return hyp
-
- def QuadraticMesh(self):
- """
- Define "QuadraticMesh" hypothesis, forcing construction of quadratic edges.
- If the 2D mesher sees that all boundary edges are quadratic ones,
- it generates quadratic faces, else it generates linear faces using
- medium nodes as if they were vertex ones.
- The 3D mesher generates quadratic volumes only if all boundary faces
- are quadratic ones, else it fails.
- """
- hyp = self.Hypothesis("QuadraticMesh")
- return hyp
-
-# Public class: Mesh_Segment_Python
-# ---------------------------------
-
-class Mesh_Segment_Python(Mesh_Segment):
- """
- Class to define a segment 1D algorithm for discretization with python function
- """
-
- def __init__(self, mesh, geom=0):
- """
- Private constructor
- """
- import Python1dPlugin
- self.Create(mesh, geom, "Python_1D", "libPython1dEngine.so")
-
- def PythonSplit1D(self, n, func):
- """
- Define "PythonSplit1D" hypothesis based on the Erwan Adam patch, awaiting equivalent SALOME functionality
- \param n for the number of segments that cut an edge
- \param func for the python function that calculate the length of all segments
- """
- hyp = self.Hypothesis("PythonSplit1D", [n], "libPython1dEngine.so")
- hyp.SetNumberOfSegments(n)
- hyp.SetPythonLog10RatioFunction(func)
- return hyp
-
-# Public class: Mesh_Triangle
-# ---------------------------
-
-class Mesh_Triangle(Mesh_Algorithm):
- """
- Class to define a triangle 2D algorithm
- """
-
- def __init__(self, mesh, geom=0):
- """
- Private constructor
- """
- self.Create(mesh, geom, "MEFISTO_2D")
-
- def MaxElementArea(self, area):
- """
- Define "MaxElementArea" hypothesis to give the maximun area of each triangles
- \param area for the maximum area of each triangles
- """
- hyp = self.Hypothesis("MaxElementArea", [area])
- hyp.SetMaxElementArea(area)
- return hyp
-
- def LengthFromEdges(self):
- """
- Define "LengthFromEdges" hypothesis to build triangles based on the length of the edges taken from the wire
- """
- return self.Hypothesis("LengthFromEdges")
-
-# Public class: Mesh_Quadrangle
-# -----------------------------