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