Salome HOME
This commit was generated by cvs2git to create branch 'IMPORT'.
[modules/med.git] / src / MEDMEM / test_copie_connectivity.cxx
1 using namespace std;
2 /* Programme de test du constructeur de copies de la classe CONNECTIVITY de MEDMEM
3    jroy - 19/12/2002 */
4
5 #include <string>
6
7 #include <math.h>
8 #include <stdlib.h>
9
10 #include "MEDMEM_Exception.hxx"
11 #include "MEDMEM_Mesh.hxx"
12 #include "MEDMEM_Family.hxx"
13 #include "MEDMEM_Group.hxx"
14
15 #include "MEDMEM_MedMeshDriver.hxx"
16 #include "MEDMEM_MedFieldDriver.hxx"
17 #include "MEDMEM_Support.hxx"
18 #include "MEDMEM_Field.hxx"
19 #include "MEDMEM_define.hxx"
20
21 void affiche_connectivity(CONNECTIVITY * myConnectivity, MESH * myMesh)
22 {
23   int SpaceDimension = myMesh->getSpaceDimension() ;
24   int MeshDimension  = myMesh->getMeshDimension() ;
25   int NumberOfNodes  = myMesh->getNumberOfNodes() ;
26
27   int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL) ;
28   medGeometryElement  * Types = myMesh->getTypes(MED_CELL) ;
29
30   cout << "Show Connectivity (Nodal) :" << endl ;
31   for (int i=0; i<NumberOfTypes; i++) {
32     cout << "For type " << Types[i] << " : " << endl ;
33     int NumberOfElements = myMesh->getNumberOfElements(MED_CELL,Types[i]);
34     int * connectivity =  myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,Types[i]);
35     int NomberOfNodesPerCell = Types[i]%100 ;
36     for (int j=0;j<NumberOfElements;j++){
37       cout << "Element "<< j+1 <<" : " ;
38       for (int k=0;k<NomberOfNodesPerCell;k++)
39         cout << connectivity[j*NomberOfNodesPerCell+k]<<" ";
40       cout << endl ;
41     }
42   }
43
44   cout << "Show Reverse Nodal Connectivity :" << endl ;
45   int * ReverseNodalConnectivity = myMesh->getReverseConnectivity(MED_NODAL) ;
46   int * ReverseNodalConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_NODAL) ;
47   for (int i=0; i<NumberOfNodes; i++) {
48     cout << "Node "<<i+1<<" : " ;
49     for (int j=ReverseNodalConnectivityIndex[i];j<ReverseNodalConnectivityIndex[i+1];j++)
50       cout << ReverseNodalConnectivity[j-1] << " " ;
51     cout << endl ;
52   }
53
54   cout << "Show Connectivity (Descending) :" << endl ;
55   int NumberOfElements ;
56   int * connectivity ;
57   int * connectivity_index ;
58   myMesh->calculateConnectivity(MED_FULL_INTERLACE,MED_DESCENDING,MED_CELL);
59   try {
60     NumberOfElements = myMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
61     connectivity =  myMesh->getConnectivity(MED_FULL_INTERLACE,MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
62     connectivity_index =  myMesh->getConnectivityIndex(MED_DESCENDING,MED_CELL);
63   }
64   catch (MEDEXCEPTION m) {
65     cout << m.what() << endl ;
66     exit (-1) ;
67   }
68   for (int j=0;j<NumberOfElements;j++) {
69     cout << "Element "<<j+1<<" : " ;
70     for (int k=connectivity_index[j];k<connectivity_index[j+1];k++)
71       cout << connectivity[k-1]<<" ";
72     cout << endl ;
73   }
74
75   cout << "Show Reverse Descending Connectivity :" << endl ;
76   int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ;
77   int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ;
78
79   int NumberOfConstituents  = 0;
80   string constituent ;
81   medEntityMesh constituentEntity ;
82
83   if (MeshDimension==3) {
84     constituent = "Face" ;
85     constituentEntity = MED_FACE ;
86   }
87
88   if (MeshDimension==2) {
89     constituent = "Edge" ;
90     constituentEntity = MED_EDGE ;
91   }
92
93   if (MeshDimension==1) {
94     MESSAGE("ERROR : MeshDimension = 1 !");
95     MESSAGE("We could not see Reverse Descending Connectivity.") ;
96   } else {
97     NumberOfConstituents = myMesh->getNumberOfElements (constituentEntity,MED_ALL_ELEMENTS);
98     for (int i=0; i<NumberOfConstituents; i++) {
99       cout << constituent <<i+1<<" : " ;
100       for (int j=ReverseDescendingConnectivityIndex[i];j<ReverseDescendingConnectivityIndex[i+1];j++)
101         cout << ReverseDescendingConnectivity[j-1] << " " ;
102       cout << endl ;
103     }
104   }
105   cout << "Show "<<constituent<<" Connectivity (Nodal) :" << endl ;
106   int * face_connectivity =  myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,constituentEntity,MED_ALL_ELEMENTS);
107   int * face_connectivity_index =  myMesh->getConnectivityIndex(MED_NODAL,constituentEntity);
108   for (int i=0; i<NumberOfConstituents; i++) {
109     cout << constituent <<i+1<<" : " ;
110     for (int j=face_connectivity_index[i];j<face_connectivity_index[i+1];j++)
111       cout << face_connectivity[j-1]<<" ";
112     cout << endl ;
113   }
114 }
115
116
117 int main (int argc, char ** argv) {
118
119
120   if (argc !=3) {
121     cerr << "Usage : " << argv[0] 
122          << " filename meshname" << endl << endl;
123     exit(-1);
124   }
125   string filename = argv[1] ;
126   string meshname = argv[2] ;
127
128   //Construction d'un maillage
129   MESH * myMesh= new MESH() ;
130   myMesh->setName(meshname);
131   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
132   myMeshDriver.setMeshName(meshname);
133   myMeshDriver.open() ;
134   myMeshDriver.read() ; //A partir d'ici la connectivité est construite
135   myMeshDriver.close() ;
136
137   CONNECTIVITY * myConnectivity = myMesh->getConnectivityptr();
138   affiche_connectivity(myConnectivity, myMesh);
139   CONNECTIVITY * myConnectivity2 = new CONNECTIVITY(* myConnectivity);
140   affiche_connectivity(myConnectivity2, myMesh);
141   delete myConnectivity;//myConnectivity utile pour afficher myConnectivity2 via myMesh!
142
143   return 0;
144 }