Salome HOME
MEDMEM suppression
[modules/med.git] / doc / MEDMEM / MESHconnectivities.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 from libMEDMEM_Swig import *
25
26 MedFile = "pointe.med"
27 #MedFile = "carre_quad4_3.med"
28 #MedFile = "polyedres.med"
29 #MedFile = "polygones.med"
30 meshName = "maa1"
31 #meshName = "CARRE_EN_QUAD4"
32 #meshName = "Erreur orientation"
33 #meshName = "Bord"
34
35 myMesh = MESH(MED_DRIVER,MedFile,meshName)
36 myMesh.read()
37
38 nameMesh = myMesh.getName()
39
40 print "Mesh name : ",nameMesh
41
42 numberOfTypes = myMesh.getNumberOfTypes(MED_CELL)
43 print "Show Connectivity (Nodal) : "
44
45 # This example use access with a specified medGeometryElement through
46 # CELLMODEL class
47
48 for i in range(numberOfTypes):
49     cellType = myMesh.getCellType(MED_CELL,i)
50     nameType = cellType.getName()
51     type = cellType.getType()
52     numberOfElements = myMesh.getNumberOfElements(MED_CELL,type)
53     numberOfNodesPerCell = cellType.getNumberOfNodes()
54     connectivity = myMesh.getConnectivity(MED_NODAL,MED_CELL,type)
55     print "For Type ",nameType," : "
56     for j in range(numberOfElements):
57         print "Element ",(j+1)," : ",connectivity[j*numberOfNodesPerCell:
58                                                   (j+1)*numberOfNodesPerCell]
59
60 print "Show Reverse Nodal Connectivity :"
61
62 # This example use global access with index array
63
64 numberOfNodes = myMesh.getNumberOfNodes()
65
66 reverseNodalConnectivity = myMesh.getReverseConnectivity(MED_NODAL)
67 reverseNodalConnectivityIndex = myMesh.getReverseConnectivityIndex(MED_NODAL)
68
69 for i in range(numberOfNodes):
70     indexBegin = reverseNodalConnectivityIndex[i]
71     indexEnd = reverseNodalConnectivityIndex[i+1]
72
73     # Index value begin at 1 so (index-1) is in fact used here
74
75     print "Node ",(i+1)," : ",reverseNodalConnectivity[(indexBegin-1):
76                                                        (indexEnd-1)]
77
78 print "Show Connectivity (Descending) :"
79
80 # This example use global access with index array
81
82 numberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
83 descendingConnectivity = myMesh.getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS)
84 descendingConnectivityIndex = myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL)
85
86 for i in range(numberOfElements):
87     indexBegin = descendingConnectivityIndex[i]
88     indexEnd = descendingConnectivityIndex[i+1]
89
90     # Index value begin at 1 so (index-1) is in fact used here
91
92     print "Element ",(i+1)," : ",descendingConnectivity[(indexBegin-1):
93                                                         (indexEnd-1)]
94
95 print "Show Reverse Descending Connectivity :"
96
97 # This example use global access with index array
98
99 meshDimension = myMesh.getMeshDimension()
100
101 if (meshDimension == 1):
102     print "ERROR : Mesh Dimension = 1"
103     print "Then the Reverse Descending Connectivity could not be seen"
104 else:
105     if (meshDimension == 2):
106         constituent = "Edge"
107         constituentEntity = MED_EDGE
108
109     if (meshDimension == 3):
110         constituent = "Face"
111         constituentEntity = MED_FACE
112
113     numberOfConstituents = myMesh.getNumberOfElements(constituentEntity,
114                                                       MED_ALL_ELEMENTS)
115     reverseDescendingConnectivity = myMesh.getReverseConnectivity(
116         MED_DESCENDING)
117     reverseDescendingConnectivityIndex = myMesh.getReverseConnectivityIndex(
118         MED_DESCENDING)
119
120     for i in range(numberOfConstituents):
121         indexBegin = reverseDescendingConnectivityIndex[i]
122         indexEnd = reverseDescendingConnectivityIndex[i+1]
123
124         # Index value begin at 1 so (index-1) is in fact used here
125
126         print constituent," : ",(i+1)," : ",reverseDescendingConnectivity[
127             (indexBegin-1):(indexEnd-1)]
128
129     print "Show ",constituent," Connectivity (Nodal) :"
130
131     constituentConnectivity = myMesh.getConnectivity(MED_NODAL,constituentEntity,MED_ALL_ELEMENTS)
132     constituentConnectivityIndex = myMesh.getConnectivityIndex(MED_NODAL,constituentEntity)
133
134     for i in range(numberOfConstituents):
135         indexBegin = constituentConnectivityIndex[i]
136         indexEnd = constituentConnectivityIndex[i+1]
137
138         # Index value begin at 1 so (index-1) is in fact used here
139
140         print constituent," : ",(i+1)," : ",constituentConnectivity[
141             (indexBegin-1):(indexEnd-1)]
142         pass
143     pass
144