-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)
- 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 Create(self, mesh, geom, hypo, so="libStdMeshersEngine.so"):
- """
- Private method
- """
- 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)
- mesh.mesh.AddHypothesis(self.geom, self.algo)
-
- 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
- SetName(hypo, GetName(self.geom) + "/" + hyp + a)
- self.mesh.mesh.AddHypothesis(self.geom, hypo)
- 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):
- """
- Define "AutomaticLength" hypothesis
- """
- return self.Hypothesis("AutomaticLength")
-
-# 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
-# ---------------------------