Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[tools/medcoupling.git] / doc / MEDMEM / MESHconnectivities.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 #include "MEDMEM_Mesh.hxx"
5
6 using namespace MEDMEM ;
7 using namespace MED_EN ;
8
9 int main (int argc, char ** argv) {
10
11 //   const string MedFile = "polyedres.med" ;
12 //   const string MeshName = "Erreur orientation" ;
13 //   const string MedFile = "polygones.med" ;
14 //   const string MeshName = "Bord" ;
15   const string MedFile = "pointe.med" ;
16   const string MeshName = "maa1" ;
17   MESH myMesh(MED_DRIVER,MedFile,MeshName) ;
18   myMesh.read() ;
19
20   cout << "Mesh name : " << myMesh.getName()  << endl << endl ; 
21
22   // we get all type for cell entity :
23   int NumberOfTypes = myMesh.getNumberOfTypes(MED_CELL) ;
24   cout << "Show Connectivity (Nodal) :" << endl ;
25   // this example use access with a specified medGeometryElement array
26   const medGeometryElement * Types = myMesh.getTypes(MED_CELL);
27   string * cellTypeNames =  myMesh.getCellTypeNames(MED_CELL);
28   for (int i=0; i<NumberOfTypes; i++) {
29     cout << "For type " << cellTypeNames[i] << " : " << endl ;
30     medGeometryElement myType = Types[i] ;
31     int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,myType);
32     int NomberOfNodesPerCell = Types[i]%100 ;
33     const int * Connectivity = 
34       myMesh.getConnectivity(MED_FULL_INTERLACE,
35                              MED_NODAL,
36                              MED_CELL,
37                              myType);
38     for (int j=0; j<NumberOfElements; j++){
39       cout << "Element "<< j+1 <<" : " ;
40       for (int k=0; k<NomberOfNodesPerCell; k++)
41         cout << Connectivity[j*NomberOfNodesPerCell+k]<<" ";
42       cout << endl ;
43     }
44   }
45   cout << "Show Reverse Nodal Connectivity :" << endl ;
46   // this example use global access with index array
47   int NumberOfNodes = myMesh.getNumberOfNodes() ;
48   const int * ReverseNodalConnectivity = 
49     myMesh.getReverseConnectivity(MED_NODAL) ;
50   const int * ReverseNodalConnectivityIndex = 
51     myMesh.getReverseConnectivityIndex(MED_NODAL) ;
52   for (int i=0; i<NumberOfNodes; i++) {
53     cout << "Node "<<i+1<<" : " ;
54     int IndexBegin = ReverseNodalConnectivityIndex[i] ;
55     int IndexEnd = ReverseNodalConnectivityIndex[i+1] ;
56     for (int j=IndexBegin; j<IndexEnd; j++)
57       // Index value begin at 1 so use j-1
58       cout << ReverseNodalConnectivity[j-1] << " " ; 
59     cout << endl ;
60   }
61
62   cout << "Show Connectivity (Descending) :" << endl ;
63   // this example use global access with index array
64   int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
65   const int * DescendingConnectivity =  
66     myMesh.getConnectivity(MED_FULL_INTERLACE,
67                            MED_DESCENDING,
68                            MED_CELL,
69                            MED_ALL_ELEMENTS);
70   const int * DescendingConnectivityIndex =
71     myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL);
72   for (int i=0; i<NumberOfElements; i++) {
73     cout << "Element "<<i+1<<" : " ;
74     int IndexBegin = DescendingConnectivityIndex[i] ;
75     int IndexEnd = DescendingConnectivityIndex[i+1] ;
76     for (int j=IndexBegin; j<IndexEnd; j++)
77       // Index value begin at 1 so use j-1
78       cout << DescendingConnectivity[j-1] << " " ;
79     cout << endl ;
80   }
81
82   cout << "Show Reverse Descending Connectivity :" << endl ;
83   // this example use global access with Index array
84   const int * ReverseDescendingConnectivity = 
85     myMesh.getReverseConnectivity(MED_DESCENDING) ;
86   const int * ReverseDescendingConnectivityIndex = 
87     myMesh.getReverseConnectivityIndex(MED_DESCENDING) ;
88
89   int MeshDimension = myMesh.getMeshDimension() ;
90   int NumberOfConstituents  = 0;
91   string Constituent ;
92   medEntityMesh ConstituentEntity ;
93   // test if we have face (3D) or edge (2D)
94   if (MeshDimension==3) {
95     Constituent = "Face" ;
96     ConstituentEntity = MED_FACE ;
97   }
98   if (MeshDimension==2) {
99     Constituent = "Edge" ;
100     ConstituentEntity = MED_EDGE ;
101   }
102
103   NumberOfConstituents = 
104     myMesh.getNumberOfElements(ConstituentEntity,MED_ALL_ELEMENTS);
105   
106   if (MeshDimension==1) {
107     MESSAGE("ERROR : MeshDimension = 1 !");
108     MESSAGE("We could not see Reverse Descending Connectivity.") ;
109   } else {
110     for (int i=0; i<NumberOfConstituents; i++) {
111       cout << Constituent << " " << i+1 << " : " ;
112       int IndexBegin = ReverseDescendingConnectivityIndex[i] ;
113       int IndexEnd = ReverseDescendingConnectivityIndex[i+1] ;
114       for (int j=IndexBegin;j<IndexEnd;j++)
115       // Index value begin at 1 so use j-1
116         cout << ReverseDescendingConnectivity[j-1] << " " ;
117       cout << endl ;
118     }
119   }
120   cout << "Show "<< Constituent <<" Connectivity (Nodal) :" << endl ;
121   // this example use global access with index array
122   const int * ConstituentConnectivity =  
123     myMesh.getConnectivity(MED_FULL_INTERLACE,
124                            MED_NODAL,
125                            ConstituentEntity,
126                            MED_ALL_ELEMENTS);
127   const int * ConstituentConnectivityIndex =
128     myMesh.getConnectivityIndex(MED_NODAL,ConstituentEntity);
129   for (int i=0; i<NumberOfConstituents; i++) {
130     cout << Constituent << " " << i+1 << " : " ;
131     int IndexBegin = ConstituentConnectivityIndex[i] ;
132     int IndexEnd = ConstituentConnectivityIndex[i+1] ;
133     for (int j=IndexBegin; j<IndexEnd; j++)
134       // Index value begin at 1 so use j-1
135       cout << ConstituentConnectivity[j-1]<<" ";
136     cout << endl ;
137   }
138
139   int nbPolygons = myMesh.getNumberOfPolygons();
140   if ( nbPolygons > 0 )
141   {
142     cout << "Show Connectivity (Nodal) of POLYGONS:" << endl ;
143     const int* Connectivity = myMesh.getPolygonsConnectivity(MED_NODAL,MED_CELL);
144     const int* ConnectivityIndex = myMesh.getPolygonsConnectivityIndex(MED_NODAL,MED_CELL);
145     for (int j=0; j<nbPolygons; j++){
146       cout << "Polygon "<< j+1 <<" : " ;
147     int IndexBegin = ConnectivityIndex[j];
148     int IndexEnd   = ConnectivityIndex[j+1];
149       for (int k=IndexBegin; k<IndexEnd; k++)
150         cout << Connectivity[k-1]<<" ";
151       cout << endl ;
152     }
153   }
154
155   int nbPolyhedrons = myMesh.getNumberOfPolyhedron();
156   if ( nbPolyhedrons > 0 )
157   {
158     cout << "Show Connectivity (Nodal) of POLYHEDRONS:" << endl ;
159     const int* Connectivity = myMesh.getPolyhedronConnectivity(MED_NODAL);
160     const int* FaceIndex    = myMesh.getPolyhedronFacesIndex();
161     const int* Index        = myMesh.getPolyhedronIndex(MED_NODAL);
162     for (int j=0; j<nbPolyhedrons; j++){
163       cout << "Polyhedron "<< j+1 <<" : " << endl;
164       int FaceIndexBegin = Index[j];
165       int FaceIndexEnd = Index[j+1];
166       for (int k=FaceIndexBegin; k<FaceIndexEnd; k++) {
167         cout << "  Face " << k - FaceIndexBegin + 1 << " : ";
168         int IndexBegin = FaceIndex[k-1];
169         int IndexEnd   = FaceIndex[k];
170         for (int i=IndexBegin; i<IndexEnd; i++)
171           cout << Connectivity[i-1]<<" ";
172         cout << endl ;
173       }
174     }
175   }
176
177   return 0 ;
178 }