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