# 3d mesh generation
-from geompy import *
-import smesh
+import salome
+salome.salome_init()
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
###
# Geometry: an assembly of a box, a cylinder and a truncated cone
height = 100
# Build a box
-box = MakeBox(-cote, -cote, -cote, +cote, +cote, +cote)
+box = geompy.MakeBox(-cote, -cote, -cote, +cote, +cote, +cote)
# Build a cylinder
-pt1 = MakeVertex(0, 0, cote/3)
-di1 = MakeVectorDXDYDZ(0, 0, 1)
-cyl = MakeCylinder(pt1, di1, section, size)
+pt1 = geompy.MakeVertex(0, 0, cote/3)
+di1 = geompy.MakeVectorDXDYDZ(0, 0, 1)
+cyl = geompy.MakeCylinder(pt1, di1, section, size)
# Build a truncated cone
-pt2 = MakeVertex(0, 0, size)
-cone = MakeCone(pt2, di1, radius_1, radius_2, height)
+pt2 = geompy.MakeVertex(0, 0, size)
+cone = geompy.MakeCone(pt2, di1, radius_1, radius_2, height)
# Fuse
-box_cyl = MakeFuse(box, cyl)
-piece = MakeFuse(box_cyl, cone)
+box_cyl = geompy.MakeFuse(box, cyl)
+piece = geompy.MakeFuse(box_cyl, cone)
# Add to the study
-addToStudy(piece, name)
+geompy.addToStudy(piece, name)
# Create a group of faces
-group = CreateGroup(piece, ShapeType["FACE"])
+group = geompy.CreateGroup(piece, geompy.ShapeType["FACE"])
group_name = name + "_grp"
-addToStudy(group, group_name)
+geompy.addToStudy(group, group_name)
group.SetName(group_name)
# Add faces to the group
-faces = SubShapeAllIDs(piece, ShapeType["FACE"])
-UnionIDs(group, faces)
+faces = geompy.SubShapeAllIDs(piece, geompy.ShapeType["FACE"])
+geompy.UnionIDs(group, faces)
###
# Create a mesh
# Construction of a Mesh
-import geompy
-import smesh
+import salome
+salome.salome_init()
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
# create a box
box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
# Construction of a Submesh
-from geompy import *
-import smesh
+import salome
+salome.salome_init()
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
# create a box
-box = MakeBoxDXDYDZ(10., 10., 10.)
-addToStudy(box, "Box")
+box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
+geompy.addToStudy(box, "Box")
# select one edge of the box for definition of a local hypothesis
-p5 = MakeVertex(5., 0., 0.)
-EdgeX = GetEdgeNearPoint(box, p5)
-addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
+p5 = geompy.MakeVertex(5., 0., 0.)
+EdgeX = geompy.GetEdgeNearPoint(box, p5)
+geompy.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
# create a hexahedral mesh on the box
quadra = smesh.Mesh(box, "Box : quadrangle 2D mesh")
# Change priority of submeshes in Mesh
import salome
-import geompy
-import smesh
-import SMESH
+salome.salome_init()
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
Box_1 = geompy.MakeBoxDXDYDZ(200, 200, 200)
[Face_1,Face_2,Face_3,Face_4,Face_5,Face_6] = geompy.SubShapeAllSorted(Box_1, geompy.ShapeType["FACE"])
Regular_1D_1 = Mesh_1.Segment(geom=Face_1)
Nb_Segments_2 = Regular_1D_1.NumberOfSegments(4)
Nb_Segments_2.SetDistrType( 0 )
-MEFISTO_2D_1 = Mesh_1.Triangle(algo=smesh.MEFISTO,geom=Face_1)
+MEFISTO_2D_1 = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO,geom=Face_1)
Length_From_Edges_2D = MEFISTO_2D_1.LengthFromEdges()
SubMesh_1 = MEFISTO_2D_1.GetSubMesh()
Regular_1D_2 = Mesh_1.Segment(geom=Face_2)
Nb_Segments_3 = Regular_1D_2.NumberOfSegments(8)
Nb_Segments_3.SetDistrType( 0 )
-MEFISTO_2D_2 = Mesh_1.Triangle(algo=smesh.MEFISTO,geom=Face_2)
+MEFISTO_2D_2 = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO,geom=Face_2)
Length_From_Edges_2D_1 = MEFISTO_2D_2.LengthFromEdges()
SubMesh_2 = MEFISTO_2D_2.GetSubMesh()
Regular_1D_3 = Mesh_1.Segment(geom=Face_3)
Nb_Segments_4 = Regular_1D_3.NumberOfSegments(12)
Nb_Segments_4.SetDistrType( 0 )
-MEFISTO_2D_3 = Mesh_1.Triangle(algo=smesh.MEFISTO,geom=Face_3)
+MEFISTO_2D_3 = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO,geom=Face_3)
Length_From_Edges_2D_2 = MEFISTO_2D_3.LengthFromEdges()
SubMesh_3 = MEFISTO_2D_3.GetSubMesh()
# Editing of a mesh
-import geompy
-import smesh
+import salome
+salome.salome_init()
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
def PrintMeshInfo(theMesh):
aMesh = theMesh.GetMesh()
# Export of a Mesh
-import geompy
-import smesh
+import salome
+salome.salome_init()
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
# create a box
box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
# Creating a hexahedral mesh on a cylinder.
# Note: it is a copy of 'ex24_cylinder.py' from SMESH_SWIG
-import math
-
-import geompy
-import smesh
import salome
-geo = geompy
+salome.salome_init()
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
+
+import math
# Parameters
# ----------
# Build a cylinder
# ----------------
-base = geo.MakeVertex(0, 0, 0)
-direction = geo.MakeVectorDXDYDZ(0, 0, 1)
+base = geompy.MakeVertex(0, 0, 0)
+direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
-cylinder = geo.MakeCylinder(base, direction, radius, height)
+cylinder = geompy.MakeCylinder(base, direction, radius, height)
-geo.addToStudy(cylinder, "cylinder")
+geompy.addToStudy(cylinder, "cylinder")
# Build blocks
# ------------
size = radius/2.0
-box_rot = geo.MakeBox(-size, -size, 0, +size, +size, height)
-box_axis = geo.MakeLine(base, direction)
-box = geo.MakeRotation(box_rot, box_axis, math.pi/4)
+box_rot = geompy.MakeBox(-size, -size, 0, +size, +size, height)
+box_axis = geompy.MakeLine(base, direction)
+box = geompy.MakeRotation(box_rot, box_axis, math.pi/4)
-hole = geo.MakeCut(cylinder, box)
+hole = geompy.MakeCut(cylinder, box)
plane_trim = 2000
-plane_a = geo.MakePlane(base, geo.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
-plane_b = geo.MakePlane(base, geo.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
+plane_a = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
+plane_b = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
-blocks_part = geo.MakePartition([hole], [plane_a, plane_b], [], [], geo.ShapeType["SOLID"])
-blocks_list = [box] + geo.SubShapeAll(blocks_part, geo.ShapeType["SOLID"])
-blocks_all = geo.MakeCompound(blocks_list)
-blocks = geo.MakeGlueFaces(blocks_all, 0.0001)
+blocks_part = geompy.MakePartition([hole], [plane_a, plane_b], [], [], geompy.ShapeType["SOLID"])
+blocks_list = [box] + geompy.SubShapeAll(blocks_part, geompy.ShapeType["SOLID"])
+blocks_all = geompy.MakeCompound(blocks_list)
+blocks = geompy.MakeGlueFaces(blocks_all, 0.0001)
-geo.addToStudy(blocks, "cylinder:blocks")
+geompy.addToStudy(blocks, "cylinder:blocks")
# Build geometric groups
# ----------------------
def group(name, shape, type, base=None, direction=None):
- t = geo.ShapeType[type]
- g = geo.CreateGroup(shape, t)
+ t = geompy.ShapeType[type]
+ g = geompy.CreateGroup(shape, t)
- geo.addToStudy(g, name)
+ geompy.addToStudy(g, name)
g.SetName(name)
if base!=None:
- l = geo.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, geo.GEOM.ST_ON)
- geo.UnionIDs(g, l)
+ l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
+ geompy.UnionIDs(g, l)
return g
group_a = group("baseA", blocks, "FACE", base, direction)
-base_b = geo.MakeVertex(0, 0, height)
+base_b = geompy.MakeVertex(0, 0, height)
group_b = group("baseB", blocks, "FACE", base_b, direction)
group_1 = group("limit", blocks, "SOLID")
-group_1_all = geo.SubShapeAllIDs(blocks, geo.ShapeType["SOLID"])
-geo.UnionIDs(group_1, group_1_all)
-group_1_box = geo.GetBlockNearPoint(blocks, base)
-geo.DifferenceList(group_1, [group_1_box])
+group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType["SOLID"])
+geompy.UnionIDs(group_1, group_1_all)
+group_1_box = geompy.GetBlockNearPoint(blocks, base)
+geompy.DifferenceList(group_1, [group_1_box])
# Mesh the blocks with hexahedral
# -------------------------------
smesh.SetCurrentStudy(salome.myStudy)
def discretize(x, y, z, n, s=blocks):
- p = geo.MakeVertex(x, y, z)
- e = geo.GetEdgeNearPoint(s, p)
+ p = geompy.MakeVertex(x, y, z)
+ e = geompy.GetEdgeNearPoint(s, p)
a = hexa.Segment(e)
a.NumberOfSegments(n)
a.Propagation()
# Note: it is a copy of 'SMESH_BuildCompound.py' from SMESH_SWIG
import salome
-import geompy
-import smesh
+salome.salome_init()
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
## create a bottom box
Box_inf = geompy.MakeBox(0., 0., 0., 200., 200., 50.)
## create compounds
# create a compound of two meshes with renaming groups with the same names and
# merging of elements with the given tolerance
-Compound1 = smesh.smesh.Concatenate([Mesh_inf.GetMesh(), Mesh_sup.GetMesh()], 0, 1, 1e-05)
+Compound1 = smesh.Concatenate([Mesh_inf.GetMesh(), Mesh_sup.GetMesh()], 0, 1, 1e-05)
smesh.SetName(Compound1, 'Compound_with_RenamedGrps_and_MergeElems')
# create a compound of two meshes with uniting groups with the same names and
# creating groups of all elements
-Compound2 = smesh.smesh.Concatenate([Mesh_inf.GetMesh(), Mesh_sup.GetMesh()], 1, 0, 1e-05, True)
+Compound2 = smesh.Concatenate([Mesh_inf.GetMesh(), Mesh_sup.GetMesh()], 1, 0, 1e-05, True)
smesh.SetName(Compound2, 'Compound_with_UniteGrps_and_GrpsOfAllElems')
# Mesh Copying
-from smesh import *
-SetCurrentStudy(salome.myStudy)
+import salome
+salome.salome_init()
+import GEOM
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+import SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+smesh = smeshBuilder.New(salome.myStudy)
# make geometry of a box
box = geompy.MakeBoxDXDYDZ(100,100,100)
face = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])[0]
# generate 3D mesh
-mesh = Mesh(box)
+mesh = smesh.Mesh(box)
localAlgo = mesh.Triangle(face)
mesh.AutomaticHexahedralization()
# objects to copy
fGroup = mesh.GroupOnGeom( face, "2D on face")
-nGroup = mesh.GroupOnGeom( face, "nodes on face", NODE)
+nGroup = mesh.GroupOnGeom( face, "nodes on face", SMESH.NODE)
subMesh = localAlgo.GetSubMesh()
# make a new mesh by copying different parts of the mesh
# 1. copy the whole mesh
-newMesh = CopyMesh( mesh, "whole mesh copy")
+newMesh = smesh.CopyMesh( mesh, "whole mesh copy")
# 2. copy a group of 2D elements along with groups
-newMesh = CopyMesh( fGroup, "face group copy with groups",toCopyGroups=True)
+newMesh = smesh.CopyMesh( fGroup, "face group copy with groups",toCopyGroups=True)
# 3. copy a group of nodes with preseving their ids
-newMesh = CopyMesh( nGroup, "node group copy", toKeepIDs=True)
+newMesh = smesh.CopyMesh( nGroup, "node group copy", toKeepIDs=True)
# 4. copy some faces
faceIds = fGroup.GetIDs()[-10:]
-newMesh = CopyMesh( mesh.GetIDSource( faceIds, FACE ), "some faces copy")
+newMesh = smesh.CopyMesh( mesh.GetIDSource( faceIds, SMESH.FACE ), "some faces copy")
# 5. copy some nodes
nodeIds = nGroup.GetIDs()[-10:]
-newMesh = CopyMesh( mesh.GetIDSource( nodeIds, NODE), "some nodes copy")
+newMesh = smesh.CopyMesh( mesh.GetIDSource( nodeIds, SMESH.NODE), "some nodes copy")
# 6. copy a sub-mesh
-newMesh = CopyMesh( subMesh, "submesh copy" )
+newMesh = smesh.CopyMesh( subMesh, "submesh copy" )
::Initialize()
{
Superclass::Initialize();
- my0DActor->SetInput(my0DGrid);
- myBallActor->SetInput(myBallGrid);
+ my0DActor->SetInputData(my0DGrid);
+ myBallActor->SetInputData(myBallGrid);
}
## Return the first vertex of a geometrical edge by ignoring orientation
def FirstVertexOnCurve(edge):
- vv = geomBuilder.SubShapeAll( edge, geomBuilder.ShapeType["VERTEX"])
+ vv = geomBuilder.SubShapeAll( edge, geomBuilder.geomBuilder.ShapeType["VERTEX"])
if not vv:
raise TypeError, "Given object has no vertices"
if len( vv ) == 1: return vv[0]
engine = None
doLcc = False
+## This class allows to create, load or manipulate meshes
+# It has a set of methods to create load or copy meshes, to combine several meshes.
+# It also has methods to get infos on meshes.
class smeshBuilder(object, SMESH._objref_SMESH_Gen):
def __new__(cls):
# @return SMESH.DirStruct
# @ingroup l1_auxiliary
def GetDirStruct(self,theVector):
- vertices = self.geompyD.SubShapeAll( theVector, geomBuilder.ShapeType["VERTEX"] )
+ vertices = self.geompyD.SubShapeAll( theVector, geomBuilder.geomBuilder.ShapeType["VERTEX"] )
if(len(vertices) != 2):
print "Error: vector object is incorrect."
return None
# @return SMESH.AxisStruct
# @ingroup l1_auxiliary
def GetAxisStruct(self,theObj):
- edges = self.geompyD.SubShapeAll( theObj, geomBuilder.ShapeType["EDGE"] )
+ edges = self.geompyD.SubShapeAll( theObj, geomBuilder.geomBuilder.ShapeType["EDGE"] )
if len(edges) > 1:
- vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.ShapeType["VERTEX"] )
- vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geomBuilder.ShapeType["VERTEX"] )
+ vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
+ vertex3, vertex4 = self.geompyD.SubShapeAll( edges[1], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
vertex1 = self.geompyD.PointCoordinates(vertex1)
vertex2 = self.geompyD.PointCoordinates(vertex2)
vertex3 = self.geompyD.PointCoordinates(vertex3)
axis = AxisStruct(vertex1[0], vertex1[1], vertex1[2], normal[0], normal[1], normal[2])
return axis
elif len(edges) == 1:
- vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.ShapeType["VERTEX"] )
+ vertex1, vertex2 = self.geompyD.SubShapeAll( edges[0], geomBuilder.geomBuilder.ShapeType["VERTEX"] )
p1 = self.geompyD.PointCoordinates( vertex1 )
p2 = self.geompyD.PointCoordinates( vertex2 )
axis = AxisStruct(p1[0], p1[1], p1[2], p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2])
#Registering the new proxy for SMESH_Gen
omniORB.registerObjref(SMESH._objref_SMESH_Gen._NP_RepositoryId, smeshBuilder)
+## Create a new smeshBuilder instance.The smeshBuilder class provides the Python
+# interface to create or load meshes.
+#
+# Typical use is:
+# \code
+# import salome
+# salome.salome_init()
+# from salome.smesh import smeshBuilder
+# smesh = smeshBuilder.New(theStudy)
+# \endcode
+# @param study SALOME study, generally obtained by salome.myStudy.
+# @param instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
+# @return smeshBuilder instance
def New( study, instance=None):
+ """
+ Create a new smeshBuilder instance.The smeshBuilder class provides the Python
+ interface to create or load meshes.
+
+ Typical use is:
+ import salome
+ salome.salome_init()
+ from salome.smesh import smeshBuilder
+ smesh = smeshBuilder.New(theStudy)
+
+ Parameters:
+ study SALOME study, generally obtained by salome.myStudy.
+ instance CORBA proxy of SMESH Engine. If None, the default Engine is used.
+ Returns:
+ smeshBuilder instance
+ """
global engine
global smeshInst
global doLcc
# @ingroup l1_auxiliary
def MeshDimension(self):
if self.mesh.HasShapeToMesh():
- shells = self.geompyD.SubShapeAllIDs( self.geom, geomBuilder.ShapeType["SOLID"] )
+ shells = self.geompyD.SubShapeAllIDs( self.geom, self.geompyD.ShapeType["SOLID"] )
if len( shells ) > 0 :
return 3
elif self.geompyD.NumberOfFaces( self.geom ) > 0 :
elif tgeo == "SOLID" or tgeo == "COMPSOLID":
typ = VOLUME
elif tgeo == "COMPOUND":
- sub = self.geompyD.SubShapeAll( shape, geomBuilder.ShapeType["SHAPE"])
+ sub = self.geompyD.SubShapeAll( shape, self.geompyD.ShapeType["SHAPE"])
if not sub:
raise ValueError,"_groupTypeFromShape(): empty geometric group or compound '%s'" % GetName(shape)
return self._groupTypeFromShape( sub[0] )