Salome HOME
removing this useless file.
[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 using namespace MEDMEM;
21
22 void affiche_connectivity(const CONNECTIVITY * myConnectivity, MESH * myMesh)
23 {
24   int SpaceDimension = myMesh->getSpaceDimension() ;
25   int MeshDimension  = myMesh->getMeshDimension() ;
26   int NumberOfNodes  = myMesh->getNumberOfNodes() ;
27
28   int NumberOfTypes                 = myMesh->getNumberOfTypes(MED_CELL) ;
29   const medGeometryElement  * Types = myMesh->getTypes(MED_CELL) ;
30
31   cout << "Show Connectivity (Nodal) :" << endl ;
32   for (int i=0; i<NumberOfTypes; i++) {
33     cout << "For type " << Types[i] << " : " << endl ;
34     int NumberOfElements = myMesh->getNumberOfElements(MED_CELL,Types[i]);
35     const int * connectivity =  myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,Types[i]);
36     int NomberOfNodesPerCell = Types[i]%100 ;
37     for (int j=0;j<NumberOfElements;j++){
38       cout << "Element "<< j+1 <<" : " ;
39       for (int k=0;k<NomberOfNodesPerCell;k++)
40         cout << connectivity[j*NomberOfNodesPerCell+k]<<" ";
41       cout << endl ;
42     }
43   }
44
45   cout << "Show Reverse Nodal Connectivity :" << endl ;
46   const int * ReverseNodalConnectivity = myMesh->getReverseConnectivity(MED_NODAL) ;
47   const int * ReverseNodalConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_NODAL) ;
48   for (int i=0; i<NumberOfNodes; i++) {
49     cout << "Node "<<i+1<<" : " ;
50     for (int j=ReverseNodalConnectivityIndex[i];j<ReverseNodalConnectivityIndex[i+1];j++)
51       cout << ReverseNodalConnectivity[j-1] << " " ;
52     cout << endl ;
53   }
54
55   cout << "Show Connectivity (Descending) :" << endl ;
56   int NumberOfElements ;
57   const int * connectivity ;
58   const int * connectivity_index ;
59   myMesh->calculateConnectivity(MED_FULL_INTERLACE,MED_DESCENDING,MED_CELL);
60   try {
61     NumberOfElements = myMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
62     connectivity =  myMesh->getConnectivity(MED_FULL_INTERLACE,MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
63     connectivity_index =  myMesh->getConnectivityIndex(MED_DESCENDING,MED_CELL);
64   }
65   catch (MEDEXCEPTION m) {
66     cout << m.what() << endl ;
67     exit (-1) ;
68   }
69   for (int j=0;j<NumberOfElements;j++) {
70     cout << "Element "<<j+1<<" : " ;
71     for (int k=connectivity_index[j];k<connectivity_index[j+1];k++)
72       cout << connectivity[k-1]<<" ";
73     cout << endl ;
74   }
75
76   cout << "Show Reverse Descending Connectivity :" << endl ;
77   const int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ;
78   const int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ;
79
80   int NumberOfConstituents  = 0;
81   string constituent ;
82   medEntityMesh constituentEntity ;
83
84   if (MeshDimension==3) {
85     constituent = "Face" ;
86     constituentEntity = MED_FACE ;
87   }
88
89   if (MeshDimension==2) {
90     constituent = "Edge" ;
91     constituentEntity = MED_EDGE ;
92   }
93
94   if (MeshDimension==1) {
95     MESSAGE("ERROR : MeshDimension = 1 !");
96     MESSAGE("We could not see Reverse Descending Connectivity.") ;
97   } else {
98     NumberOfConstituents = myMesh->getNumberOfElements (constituentEntity,MED_ALL_ELEMENTS);
99     for (int i=0; i<NumberOfConstituents; i++) {
100       cout << constituent <<i+1<<" : " ;
101       for (int j=ReverseDescendingConnectivityIndex[i];j<ReverseDescendingConnectivityIndex[i+1];j++)
102         cout << ReverseDescendingConnectivity[j-1] << " " ;
103       cout << endl ;
104     }
105   }
106   cout << "Show "<<constituent<<" Connectivity (Nodal) :" << endl ;
107   const int * face_connectivity =  myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,constituentEntity,MED_ALL_ELEMENTS);
108   const int * face_connectivity_index =  myMesh->getConnectivityIndex(MED_NODAL,constituentEntity);
109   for (int i=0; i<NumberOfConstituents; i++) {
110     cout << constituent <<i+1<<" : " ;
111     for (int j=face_connectivity_index[i];j<face_connectivity_index[i+1];j++)
112       cout << face_connectivity[j-1]<<" ";
113     cout << endl ;
114   }
115 }
116
117
118 int main (int argc, char ** argv) {
119
120
121   if (argc <3) { // after 3, ignored !
122     cerr << "Usage : " << argv[0] 
123          << " filename meshname" << endl << endl;
124     exit(-1);
125   }
126   string filename = argv[1] ;
127   string meshname = argv[2] ;
128
129   //Construction d'un maillage
130   MESH * myMesh= new MESH() ;
131   myMesh->setName(meshname);
132   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
133   myMeshDriver.setMeshName(meshname);
134   myMeshDriver.open() ;
135   myMeshDriver.read() ; //A partir d'ici la connectivité est construite
136   myMeshDriver.close() ;
137
138   const CONNECTIVITY * myConnectivity = myMesh->getConnectivityptr();
139   affiche_connectivity(myConnectivity, myMesh);
140
141   CONNECTIVITY * myConnectivity2 = new CONNECTIVITY(* myConnectivity);
142   affiche_connectivity(myConnectivity2, myMesh);
143
144   CONNECTIVITY * myConnectivity3 = new CONNECTIVITY(* myConnectivity2);
145   delete myConnectivity2;
146   affiche_connectivity(myConnectivity3, myMesh);
147   delete myConnectivity3;
148
149   delete myMesh ;
150
151   return 0;
152 }