Salome HOME
Building a version which will be tagged PreV2_0_0 working with KERNEL V1_4_0.
[modules/med.git] / doc / MEDMEM / MESHconnectivities.cxx
1 #include "MEDMEM_Mesh.hxx"
2 #include "MEDMEM_CellModel.hxx"
3
4 int main (int argc, char ** argv) {
5
6   const string MedFile = "pointe.med" ;
7   const string MeshName = "maa1" ;
8   MESH myMesh(MED_DRIVER,MedFile,MeshName) ;
9   myMesh.read() ;
10
11   cout << "Mesh name : " << myMesh.getName()  << endl << endl ; 
12
13   // we get all type for cell entity :
14   int NumberOfTypes = myMesh.getNumberOfTypes(MED_CELL) ;
15   const CELLMODEL * Types = myMesh.getCellsTypes(MED_CELL) ;
16
17   cout << "Show Connectivity (Nodal) :" << endl ;
18   // this example use access with a specified medGeometryElement through
19   // CELLMODEL class
20   for (int i=0; i<NumberOfTypes; i++) {
21     cout << "For type " << Types[i].getName() << " : " << endl ;
22     medGeometryElement myType = Types[i].getType() ;
23     int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,myType);
24     int NomberOfNodesPerCell = Types[i].getNumberOfNodes() ;
25     const int * Connectivity = 
26       myMesh.getConnectivity(MED_FULL_INTERLACE,
27                              MED_NODAL,
28                              MED_CELL,
29                              myType);
30     for (int j=0; j<NumberOfElements; j++){
31       cout << "Element "<< j+1 <<" : " ;
32       for (int k=0; k<NomberOfNodesPerCell; k++)
33         cout << Connectivity[j*NomberOfNodesPerCell+k]<<" ";
34       cout << endl ;
35     }
36   }
37   cout << "Show Reverse Nodal Connectivity :" << endl ;
38   // this example use global access with index array
39   int NumberOfNodes = myMesh.getNumberOfNodes() ;
40   const int * ReverseNodalConnectivity = 
41     myMesh.getReverseConnectivity(MED_NODAL) ;
42   const int * ReverseNodalConnectivityIndex = 
43     myMesh.getReverseConnectivityIndex(MED_NODAL) ;
44   for (int i=0; i<NumberOfNodes; i++) {
45     cout << "Node "<<i+1<<" : " ;
46     int IndexBegin = ReverseNodalConnectivityIndex[i] ;
47     int IndexEnd = ReverseNodalConnectivityIndex[i+1] ;
48     for (int j=IndexBegin; j<IndexEnd; j++)
49       // Index value begin at 1 so use j-1
50       cout << ReverseNodalConnectivity[j-1] << " " ; 
51     cout << endl ;
52   }
53
54   cout << "Show Connectivity (Descending) :" << endl ;
55   // this example use global access with index array
56   int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
57   const int * DescendingConnectivity =  
58     myMesh.getConnectivity(MED_FULL_INTERLACE,
59                            MED_DESCENDING,
60                            MED_CELL,
61                            MED_ALL_ELEMENTS);
62   const int * DescendingConnectivityIndex =
63     myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL);
64   for (int i=0; i<NumberOfElements; i++) {
65     cout << "Element "<<i+1<<" : " ;
66     int IndexBegin = DescendingConnectivityIndex[i] ;
67     int IndexEnd = DescendingConnectivityIndex[i+1] ;
68     for (int j=IndexBegin; j<IndexEnd; j++)
69       // Index value begin at 1 so use j-1
70       cout << DescendingConnectivity[j-1] << " " ;
71     cout << endl ;
72   }
73
74   cout << "Show Reverse Descending Connectivity :" << endl ;
75   // this example use global access with Index array
76   const int * ReverseDescendingConnectivity = 
77     myMesh.getReverseConnectivity(MED_DESCENDING) ;
78   const int * ReverseDescendingConnectivityIndex = 
79     myMesh.getReverseConnectivityIndex(MED_DESCENDING) ;
80
81   int MeshDimension = myMesh.getMeshDimension() ;
82   int NumberOfConstituents  = 0;
83   string Constituent ;
84   medEntityMesh ConstituentEntity ;
85   // test if we have face (3D) or edge (2D)
86   if (MeshDimension==3) {
87     Constituent = "Face" ;
88     ConstituentEntity = MED_FACE ;
89   }
90   if (MeshDimension==2) {
91     Constituent = "Edge" ;
92     ConstituentEntity = MED_EDGE ;
93   }
94
95   NumberOfConstituents = 
96     myMesh.getNumberOfElements(ConstituentEntity,MED_ALL_ELEMENTS);
97   
98   if (MeshDimension==1) {
99     MESSAGE("ERROR : MeshDimension = 1 !");
100     MESSAGE("We could not see Reverse Descending Connectivity.") ;
101   } else {
102     for (int i=0; i<NumberOfConstituents; i++) {
103       cout << Constituent << " " << i+1 << " : " ;
104       int IndexBegin = ReverseDescendingConnectivityIndex[i] ;
105       int IndexEnd = ReverseDescendingConnectivityIndex[i+1] ;
106       for (int j=IndexBegin;j<IndexEnd;j++)
107       // Index value begin at 1 so use j-1
108         cout << ReverseDescendingConnectivity[j-1] << " " ;
109       cout << endl ;
110     }
111   }
112   cout << "Show "<< Constituent <<" Connectivity (Nodal) :" << endl ;
113   // this example use global access with index array
114   const int * ConstituentConnectivity =  
115     myMesh.getConnectivity(MED_FULL_INTERLACE,
116                            MED_NODAL,
117                            ConstituentEntity,
118                            MED_ALL_ELEMENTS);
119   const int * ConstituentConnectivityIndex =
120     myMesh.getConnectivityIndex(MED_NODAL,ConstituentEntity);
121   for (int i=0; i<NumberOfConstituents; i++) {
122     cout << Constituent << " " << i+1 << " : " ;
123     int IndexBegin = ConstituentConnectivityIndex[i] ;
124     int IndexEnd = ConstituentConnectivityIndex[i+1] ;
125     for (int j=IndexBegin; j<IndexEnd; j++)
126       // Index value begin at 1 so use j-1
127       cout << ConstituentConnectivity[j-1]<<" ";
128     cout << endl ;
129   }
130
131   return 0 ;
132 }