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