Salome HOME
Nerge with PAL/SALOME 2.1.0d
[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 # Variables
14 # ---------
15
16 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
17 smesh.SetCurrentStudy(salome.myStudy)
18 smeshgui = salome.ImportComponentGUI("SMESH")
19 smeshgui.Init(salome.myStudyId)
20
21 # Hexahedrical meshing
22 #
23 # Examples: cube2pyGibi.py, lines 270-295
24 #           cube2partition.py, lines 72-83
25 # --------------------
26
27 class MeshHexaImpl:
28     piece = 0
29     name  = 0
30     mesh  = 0
31     cpt   = 0
32
33     # Sets algorithm and hypothesis for 1D discretization of the <shape>:
34     #   - algorithm  "Regular_1D"
35     #   - hypothesis "NumberOfSegments" with number of segments <n>
36     # --------------------
37
38     def Mesh1D(self, shape, n):
39         hyp1D=smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
40         smeshgui.SetName(salome.ObjectToID(hyp1D), self.name+"/WireDiscretisation/"+str(self.cpt))
41         self.mesh.AddHypothesis(shape, hyp1D)
42
43         hyp=smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
44         hyp.SetNumberOfSegments(n)
45         smeshgui.SetName(salome.ObjectToID(hyp), self.name+"/Segments_"+str(n)+"/"+str(self.cpt))
46         self.mesh.AddHypothesis(shape, hyp)
47
48         self.cpt=self.cpt+1
49
50     # Constructor
51     #
52     # Creates mesh on the shape <piece>,
53     # sets GUI name of this mesh to <name>.
54     # Sets the following global algorithms and hypotheses:
55     #   - for 1D discretization:
56     #       - algorithm  "Regular_1D"
57     #       - hypothesis "NumberOfSegments" with number of segments <n>,
58     #   - for 2D discretization:
59     #       - algorithm  "Quadrangle_2D"
60     #   - for 3D discretization:
61     #       - algorithm  "Hexa_3D"
62     # --------------------
63
64     def __init__(self, piece, n, name):
65         self.piece = piece
66         self.name  = name
67
68         self.mesh  = smesh.CreateMesh(piece)
69         smeshgui.SetName(salome.ObjectToID(self.mesh), name)
70
71         self.Mesh1D(piece, n)
72
73         hyp2D=smesh.CreateHypothesis("Quadrangle_2D", "libStdMeshersEngine.so")
74         smeshgui.SetName(salome.ObjectToID(hyp2D), name+"/Quadrangle")
75         self.mesh.AddHypothesis(piece, hyp2D)
76
77         hyp3D=smesh.CreateHypothesis("Hexa_3D", "libStdMeshersEngine.so")
78         smeshgui.SetName(salome.ObjectToID(hyp3D), name+"/ijk")
79         self.mesh.AddHypothesis(piece, hyp3D)
80
81     # Creates sub-mesh of the mesh, created by constructor.
82     # This sub-mesh will be created on edge <edge>.
83     # Set algorithm and hypothesis for 1D discretization of the <edge>:
84     #   - algorithm  "Regular_1D"
85     #   - hypothesis "NumberOfSegments" with number of segments <n>
86     # Note: the <edge> will be automatically published in study under the shape, given in constructor.
87     # --------------------
88
89     def local(self, edge, n):
90         geompy.addToStudyInFather(self.piece, edge, geompy.SubShapeName(edge, self.piece))
91         submesh = self.mesh.GetSubMesh(edge, self.name+"/SubMeshEdge/"+str(self.cpt))
92         self.Mesh1D(edge, n)
93
94     # Computes mesh, created by constructor.
95     # --------------------
96
97     def Compute(self):
98         smesh.Compute(self.mesh, self.piece)
99         salome.sg.updateObjBrowser(1)
100
101 MeshHexa = MeshHexaImpl