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