Salome HOME
Merge with OCC-V2_1_0_deb
[modules/smesh.git] / src / SMESH_SWIG / meshpy.py
1 # CEA/LGLS 2004, Francis KLOSS (OCC)
2 # ==================================
3
4 # Import
5 # ------
6
7 import geompy
8
9 import salome
10
11 import StdMeshers
12
13 import SMESH
14
15 # Variables
16 # ---------
17
18 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
19 smesh.SetCurrentStudy(salome.myStudy)
20 smeshgui = salome.ImportComponentGUI("SMESH")
21 smeshgui.Init(salome.myStudyId)
22
23 # Hexahedrical meshing
24 #
25 # Examples: cube2pyGibi.py, lines 270-295
26 #           cube2partition.py, lines 72-83
27 # --------------------
28
29 class MeshHexaImpl:
30     piece = 0
31     name  = 0
32     mesh  = 0
33     cpt   = 0
34
35     # Sets algorithm and hypothesis for 1D discretization of the <shape>:
36     #   - algorithm  "Regular_1D"
37     #   - hypothesis "NumberOfSegments" with number of segments <n>
38     # --------------------
39
40     def Mesh1D(self, shape, n):
41         hyp1D=smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
42         smeshgui.SetName(salome.ObjectToID(hyp1D), self.name+"/WireDiscretisation/"+str(self.cpt))
43         self.mesh.AddHypothesis(shape, hyp1D)
44
45         hyp=smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
46         hyp.SetNumberOfSegments(n)
47         smeshgui.SetName(salome.ObjectToID(hyp), self.name+"/Segments_"+str(n)+"/"+str(self.cpt))
48         self.mesh.AddHypothesis(shape, hyp)
49
50         self.cpt=self.cpt+1
51
52     # Constructor
53     #
54     # Creates mesh on the shape <piece>,
55     # sets GUI name of this mesh to <name>.
56     # Sets the following global algorithms and hypotheses:
57     #   - for 1D discretization:
58     #       - algorithm  "Regular_1D"
59     #       - hypothesis "NumberOfSegments" with number of segments <n>,
60     #   - for 2D discretization:
61     #       - algorithm  "Quadrangle_2D"
62     #   - for 3D discretization:
63     #       - algorithm  "Hexa_3D"
64     # --------------------
65
66     def __init__(self, piece, n, name):
67         self.piece = piece
68         self.name  = name
69
70         self.mesh  = smesh.CreateMesh(piece)
71         smeshgui.SetName(salome.ObjectToID(self.mesh), name)
72
73         self.Mesh1D(piece, n)
74
75         hyp2D=smesh.CreateHypothesis("Quadrangle_2D", "libStdMeshersEngine.so")
76         smeshgui.SetName(salome.ObjectToID(hyp2D), name+"/Quadrangle")
77         self.mesh.AddHypothesis(piece, hyp2D)
78
79         hyp3D=smesh.CreateHypothesis("Hexa_3D", "libStdMeshersEngine.so")
80         smeshgui.SetName(salome.ObjectToID(hyp3D), name+"/ijk")
81         self.mesh.AddHypothesis(piece, hyp3D)
82
83     # Creates sub-mesh of the mesh, created by constructor.
84     # This sub-mesh will be created on edge <edge>.
85     # Set algorithm and hypothesis for 1D discretization of the <edge>:
86     #   - algorithm  "Regular_1D"
87     #   - hypothesis "NumberOfSegments" with number of segments <n>
88     # Note: the <edge> will be automatically published in study under the shape, given in constructor.
89     # --------------------
90
91     def local(self, edge, n):
92         geompy.addToStudyInFather(self.piece, edge, geompy.SubShapeName(edge, self.piece))
93         submesh = self.mesh.GetSubMesh(edge, self.name+"/SubMeshEdge/"+str(self.cpt))
94         self.Mesh1D(edge, n)
95
96     # Computes mesh, created by constructor.
97     # --------------------
98
99     def Compute(self):
100         smesh.Compute(self.mesh, self.piece)
101         salome.sg.updateObjBrowser(1)
102
103     # Creates mesh group based on a geometric group
104     # --------------------
105
106     def Group(self, grp, name=""):
107         if name == "":
108             name = grp.GetName()
109         tgeo = geompy.GroupOp.GetType(grp)
110         if tgeo == geompy.ShapeType["VERTEX"]:
111             type = SMESH.NODE
112         elif tgeo == geompy.ShapeType["EDGE"]:
113             type = SMESH.EDGE
114         elif tgeo == geompy.ShapeType["FACE"]:
115             type = SMESH.FACE
116         elif tgeo == geompy.ShapeType["SOLID"]:
117             type = SMESH.VOLUME
118         return self.mesh.CreateGroupFromGEOM(type, name, grp)
119
120     # Export mesh in a MED file
121     # --------------------
122
123     def ExportMED(self, filename, groups=1):
124         self.mesh.ExportMED(filename, groups)
125
126 MeshHexa = MeshHexaImpl