Salome HOME
Comment out the example.
[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 import salome
9
10 import StdMeshers
11 import SMESH
12
13 """
14  \namespace meshpy
15  \brief Module meshpy
16 """
17
18 # Variables
19 # ---------
20
21 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
22 smesh.SetCurrentStudy(salome.myStudy)
23 smeshgui = salome.ImportComponentGUI("SMESH")
24 smeshgui.Init(salome.myStudyId)
25
26 class MeshHexaImpl:
27     """
28      Class MeshHexaImpl for Hexahedrical meshing
29
30      Examples: cube2pyGibi.py, lines 270-295
31                cube2partition.py, lines 72-83
32     """
33     piece = 0
34     name  = 0
35     mesh  = 0
36     cpt   = 0
37
38     def Mesh1D(self, shape, n, propagate=0):
39         """
40          Define Wires discretization.
41          Sets algorithm and hypothesis for 1D discretization of \a shape:
42            - algorithm  "Regular_1D"
43            - hypothesis "NumberOfSegments" with number of segments \a n
44          \param shape Main shape or sub-shape to define wire discretization of
45          \param n Number of segments to split eash wire of the \a shape on
46          \param propagate Boolean flag. If propagate = 1,
47                 "Propagation" hypothesis will be applied also to the \a shape
48         """
49         hyp1D=smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
50         smeshgui.SetName(salome.ObjectToID(hyp1D), self.name+"/WireDiscretisation/"+str(self.cpt))
51         self.mesh.AddHypothesis(shape, hyp1D)
52
53         hyp=smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
54         hyp.SetNumberOfSegments(n)
55         smeshgui.SetName(salome.ObjectToID(hyp), self.name+"/Segments_"+str(n)+"/"+str(self.cpt))
56         self.mesh.AddHypothesis(shape, hyp)
57
58         if propagate:
59             hypPro=smesh.CreateHypothesis("Propagation", "libStdMeshersEngine.so")
60             smeshgui.SetName(salome.ObjectToID(hypPro), self.name+"/Propagation/"+str(self.cpt))
61             self.mesh.AddHypothesis(shape, hypPro)
62
63         self.cpt=self.cpt+1
64
65     def __init__(self, piece, n, name):
66         """
67          Constructor
68
69          Creates mesh on the shape \a piece,
70          sets GUI name of this mesh to \a name. \n
71          Sets the following global algorithms and hypotheses:
72            - for 1D discretization:
73                - algorithm  "Regular_1D"
74                - hypothesis "NumberOfSegments" with number of segments \a n
75            - for 2D discretization:
76                - algorithm  "Quadrangle_2D"
77            - for 3D discretization:
78                - algorithm  "Hexa_3D"
79          \param piece Shape to be meshed
80          \param n Global number of segments for wires discretization
81          \param name Name for mesh to be created
82         """
83         self.piece = piece
84         self.name  = name
85
86         self.mesh  = smesh.CreateMesh(piece)
87         smeshgui.SetName(salome.ObjectToID(self.mesh), name)
88
89         self.Mesh1D(piece, n)
90
91         hyp2D=smesh.CreateHypothesis("Quadrangle_2D", "libStdMeshersEngine.so")
92         smeshgui.SetName(salome.ObjectToID(hyp2D), name+"/Quadrangle")
93         self.mesh.AddHypothesis(piece, hyp2D)
94
95         hyp3D=smesh.CreateHypothesis("Hexa_3D", "libStdMeshersEngine.so")
96         smeshgui.SetName(salome.ObjectToID(hyp3D), name+"/ijk")
97         self.mesh.AddHypothesis(piece, hyp3D)
98
99     def local(self, edge, n):
100         """
101          Creates sub-mesh of the mesh, created by constructor.
102          This sub-mesh will be created on edge \a edge.
103          Set algorithm and hypothesis for 1D discretization of the \a edge:
104            - algorithm  "Regular_1D"
105            - hypothesis "NumberOfSegments" with number of segments \a n
106          \param edge Sub-edge of the main shape
107          \param n Number of segments to split the \a edge on
108          \note: \a edge will be automatically published in study under the shape, given in constructor.
109         """
110         geompy.addToStudyInFather(self.piece, edge, geompy.SubShapeName(edge, self.piece))
111         submesh = self.mesh.GetSubMesh(edge, self.name+"/SubMeshEdge/"+str(self.cpt))
112         self.Mesh1D(edge, n)
113
114     def Propagate(self, edge, n):
115         """
116          Creates sub-mesh of the mesh, created by constructor.
117          This sub-mesh will be created on edge \a edge and
118          propagate the hypothesis on all correspondant edges.
119          Set algorithm and hypothesis for 1D discretization of the \a edge and all other propagate edges:
120            - algorithm  "Regular_1D"
121            - hypothesis "NumberOfSegments" with number of segments \a n
122            - hypothesis "Propagation"
123          \param edge Sub-edge of the main shape
124          \param n Number of segments to split the \a edge and all other propagate edges on
125          \note: \a edge will be automatically published in study under the shape, given in constructor.
126         """
127         geompy.addToStudyInFather(self.piece, edge, geompy.SubShapeName(edge, self.piece))
128         submesh = self.mesh.GetSubMesh(edge, self.name+"/SubMeshEdge/"+str(self.cpt))
129         self.Mesh1D(edge, n, 1)
130
131     def Compute(self):
132         """
133          Computes mesh, created by constructor.
134         """
135         smesh.Compute(self.mesh, self.piece)
136         salome.sg.updateObjBrowser(1)
137
138     def Group(self, grp, name=""):
139         """
140          Creates mesh group based on a geometric group
141          \param grp Geometric group
142          \param name Name for mesh group to be created
143         """
144         if name == "":
145             name = grp.GetName()
146         tgeo = geompy.GroupOp.GetType(grp)
147         if tgeo == geompy.ShapeType["VERTEX"]:
148             type = SMESH.NODE
149         elif tgeo == geompy.ShapeType["EDGE"]:
150             type = SMESH.EDGE
151         elif tgeo == geompy.ShapeType["FACE"]:
152             type = SMESH.FACE
153         elif tgeo == geompy.ShapeType["SOLID"]:
154             type = SMESH.VOLUME
155         return self.mesh.CreateGroupFromGEOM(type, name, grp)
156
157     def ExportMED(self, filename, groups=1):
158         """
159          Export mesh in a MED file
160          \param filename Name for MED file to be created
161          \param groups Boolean flag. If groups = 1, mesh groups will be also stored in file
162         """
163         self.mesh.ExportMED(filename, groups)
164
165 MeshHexa = MeshHexaImpl