2 /* Programme de test du constructeur de copies de la classe CONNECTIVITY de MEDMEM
10 #include "MEDMEM_Exception.hxx"
11 #include "MEDMEM_Mesh.hxx"
12 #include "MEDMEM_Family.hxx"
13 #include "MEDMEM_Group.hxx"
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"
21 void affiche_connectivity(const CONNECTIVITY * myConnectivity, MESH * myMesh)
23 int SpaceDimension = myMesh->getSpaceDimension() ;
24 int MeshDimension = myMesh->getMeshDimension() ;
25 int NumberOfNodes = myMesh->getNumberOfNodes() ;
27 int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL) ;
28 const medGeometryElement * Types = myMesh->getTypes(MED_CELL) ;
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 const 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]<<" ";
44 cout << "Show Reverse Nodal Connectivity :" << endl ;
45 const int * ReverseNodalConnectivity = myMesh->getReverseConnectivity(MED_NODAL) ;
46 const 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] << " " ;
54 cout << "Show Connectivity (Descending) :" << endl ;
55 int NumberOfElements ;
56 const int * connectivity ;
57 const int * connectivity_index ;
58 myMesh->calculateConnectivity(MED_FULL_INTERLACE,MED_DESCENDING,MED_CELL);
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);
64 catch (MEDEXCEPTION m) {
65 cout << m.what() << endl ;
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]<<" ";
75 cout << "Show Reverse Descending Connectivity :" << endl ;
76 const int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ;
77 const int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ;
79 int NumberOfConstituents = 0;
81 medEntityMesh constituentEntity ;
83 if (MeshDimension==3) {
84 constituent = "Face" ;
85 constituentEntity = MED_FACE ;
88 if (MeshDimension==2) {
89 constituent = "Edge" ;
90 constituentEntity = MED_EDGE ;
93 if (MeshDimension==1) {
94 MESSAGE("ERROR : MeshDimension = 1 !");
95 MESSAGE("We could not see Reverse Descending Connectivity.") ;
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] << " " ;
105 cout << "Show "<<constituent<<" Connectivity (Nodal) :" << endl ;
106 const int * face_connectivity = myMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,constituentEntity,MED_ALL_ELEMENTS);
107 const 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]<<" ";
117 int main (int argc, char ** argv) {
120 if (argc <3) { // after 3, ignored !
121 cerr << "Usage : " << argv[0]
122 << " filename meshname" << endl << endl;
125 string filename = argv[1] ;
126 string meshname = argv[2] ;
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() ;
137 const CONNECTIVITY * myConnectivity = myMesh->getConnectivityptr();
138 affiche_connectivity(myConnectivity, myMesh);
140 CONNECTIVITY * myConnectivity2 = new CONNECTIVITY(* myConnectivity);
141 affiche_connectivity(myConnectivity2, myMesh);
143 CONNECTIVITY * myConnectivity3 = new CONNECTIVITY(* myConnectivity2);
144 delete myConnectivity2;
145 affiche_connectivity(myConnectivity3, myMesh);
146 delete myConnectivity3;