Salome HOME
Join modifications from branch CEAFor_V3_2_0
[tools/medcoupling.git] / doc / MEDMEM / MESHconnectivities.py
1 from libMEDMEM_Swig import *
2
3 MedFile = "pointe.med"
4 #MedFile = "carre_quad4_3.med"
5 #MedFile = "polyedres.med"
6 #MedFile = "polygones.med"
7 meshName = "maa1"
8 #meshName = "CARRE_EN_QUAD4"
9 #meshName = "Erreur orientation"
10 #meshName = "Bord"
11
12 myMesh = MESH(MED_DRIVER,MedFile,meshName)
13 myMesh.read()
14
15 nameMesh = myMesh.getName()
16
17 print "Mesh name : ",nameMesh
18
19 numberOfTypes = myMesh.getNumberOfTypes(MED_CELL)
20 print "Show Connectivity (Nodal) : "
21
22 # This example use access with a specified medGeometryElement through
23 # CELLMODEL class
24
25 for i in range(numberOfTypes):
26     cellType = myMesh.getCellType(MED_CELL,i)
27     nameType = cellType.getName()
28     type = cellType.getType()
29     numberOfElements = myMesh.getNumberOfElements(MED_CELL,type)
30     numberOfNodesPerCell = cellType.getNumberOfNodes()
31     connectivity = myMesh.getConnectivity(MED_FULL_INTERLACE,
32                                           MED_NODAL,MED_CELL,type)
33     print "For Type ",nameType," : "
34     for j in range(numberOfElements):
35         print "Element ",(j+1)," : ",connectivity[j*numberOfNodesPerCell:
36                                                   (j+1)*numberOfNodesPerCell]
37
38 print "Show Reverse Nodal Connectivity :"
39
40 # This example use global access with index array
41
42 numberOfNodes = myMesh.getNumberOfNodes()
43
44 reverseNodalConnectivity = myMesh.getReverseConnectivity(MED_NODAL)
45 reverseNodalConnectivityIndex = myMesh.getReverseConnectivityIndex(MED_NODAL)
46
47 for i in range(numberOfNodes):
48     indexBegin = reverseNodalConnectivityIndex[i]
49     indexEnd = reverseNodalConnectivityIndex[i+1]
50
51     # Index value begin at 1 so (index-1) is in fact used here
52
53     print "Node ",(i+1)," : ",reverseNodalConnectivity[(indexBegin-1):
54                                                        (indexEnd-1)]
55
56 print "Show Connectivity (Descending) :"
57
58 # This example use global access with index array
59
60 numberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
61 descendingConnectivity = myMesh.getConnectivity(MED_FULL_INTERLACE,
62                                                 MED_DESCENDING,MED_CELL,
63                                                 MED_ALL_ELEMENTS)
64 descendingConnectivityIndex = myMesh.getConnectivityIndex(MED_DESCENDING,
65                                                           MED_CELL)
66
67 for i in range(numberOfElements):
68     indexBegin = descendingConnectivityIndex[i]
69     indexEnd = descendingConnectivityIndex[i+1]
70
71     # Index value begin at 1 so (index-1) is in fact used here
72
73     print "Element ",(i+1)," : ",descendingConnectivity[(indexBegin-1):
74                                                         (indexEnd-1)]
75
76 print "Show Reverse Descending Connectivity :"
77
78 # This example use global access with index array
79
80 meshDimension = myMesh.getMeshDimension()
81
82 if (meshDimension == 1):
83     print "ERROR : Mesh Dimension = 1"
84     print "Then the Reverse Descending Connectivity could not be seen"
85 else:
86     if (meshDimension == 2):
87         constituent = "Edge"
88         constituentEntity = MED_EDGE
89
90     if (meshDimension == 3):
91         constituent = "Face"
92         constituentEntity = MED_FACE
93
94     numberOfConstituents = myMesh.getNumberOfElements(constituentEntity,
95                                                       MED_ALL_ELEMENTS)
96     reverseDescendingConnectivity = myMesh.getReverseConnectivity(
97         MED_DESCENDING)
98     reverseDescendingConnectivityIndex = myMesh.getReverseConnectivityIndex(
99         MED_DESCENDING)
100
101     for i in range(numberOfConstituents):
102         indexBegin = reverseDescendingConnectivityIndex[i]
103         indexEnd = reverseDescendingConnectivityIndex[i+1]
104
105         # Index value begin at 1 so (index-1) is in fact used here
106
107         print constituent," : ",(i+1)," : ",reverseDescendingConnectivity[
108             (indexBegin-1):(indexEnd-1)]
109
110     print "Show ",constituent," Connectivity (Nodal) :"
111
112     constituentConnectivity = myMesh.getConnectivity(MED_FULL_INTERLACE,
113                                                      MED_NODAL,
114                                                      constituentEntity,
115                                                      MED_ALL_ELEMENTS)
116     constituentConnectivityIndex = myMesh.getConnectivityIndex(MED_NODAL,
117                                                                constituentEntity)
118
119     for i in range(numberOfConstituents):
120         indexBegin = constituentConnectivityIndex[i]
121         indexEnd = constituentConnectivityIndex[i+1]
122
123         # Index value begin at 1 so (index-1) is in fact used here
124
125         print constituent," : ",(i+1)," : ",constituentConnectivity[
126             (indexBegin-1):(indexEnd-1)]
127         pass
128     pass
129
130 nbPolygons = myMesh.getNumberOfPolygons()
131 if nbPolygons > 0 :
132     print ""
133     print "     Show Connectivity (Nodal) of POLYGONS:"
134     print ""
135     connectivity = myMesh.getPolygonsConnectivity(MED_NODAL,MED_CELL)
136     index = myMesh.getPolygonsConnectivityIndex(MED_NODAL,MED_CELL)
137     for j in range(nbPolygons):
138         print "       Polygon",(j+1)," ",connectivity[ index[j]-1 : index[j+1]-1 ]
139         pass
140     pass
141
142 nbPolyhedrons = myMesh.getNumberOfPolyhedron()
143 if nbPolyhedrons > 0 :
144     print ""
145     print "     Show Connectivity (Nodal) of POLYHEDRONS:"
146     print ""
147     connectivity = myMesh.getPolyhedronConnectivity(MED_NODAL)
148     fIndex = myMesh.getPolyhedronFacesIndex()
149     index = myMesh.getPolyhedronIndex(MED_NODAL)
150     for j in range(nbPolyhedrons):
151         print     "       Polyhedra",(j+1)
152         iF1, iF2 = index[ j ]-1, index[ j+1 ]-1
153         for f in range( iF2 - iF1 ):
154             iN1, iN2 = fIndex[ iF1+f ]-1, fIndex[ iF1+f+1 ]-1
155             print "         Face",f+1," ",connectivity[ iN1 : iN2 ]
156             pass
157         pass
158     pass