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"
20 using namespace MEDMEM;
22 void affiche_connectivity(const CONNECTIVITY * myConnectivity, MESH * myMesh)
24 int SpaceDimension = myMesh->getSpaceDimension() ;
25 int MeshDimension = myMesh->getMeshDimension() ;
26 int NumberOfNodes = myMesh->getNumberOfNodes() ;
28 int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL) ;
29 const medGeometryElement * Types = myMesh->getTypes(MED_CELL) ;
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]<<" ";
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] << " " ;
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);
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);
65 catch (MEDEXCEPTION m) {
66 cout << m.what() << endl ;
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]<<" ";
76 cout << "Show Reverse Descending Connectivity :" << endl ;
77 const int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ;
78 const int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ;
80 int NumberOfConstituents = 0;
82 medEntityMesh constituentEntity ;
84 if (MeshDimension==3) {
85 constituent = "Face" ;
86 constituentEntity = MED_FACE ;
89 if (MeshDimension==2) {
90 constituent = "Edge" ;
91 constituentEntity = MED_EDGE ;
94 if (MeshDimension==1) {
95 MESSAGE("ERROR : MeshDimension = 1 !");
96 MESSAGE("We could not see Reverse Descending Connectivity.") ;
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] << " " ;
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]<<" ";
118 int main (int argc, char ** argv) {
121 if (argc <3) { // after 3, ignored !
122 cerr << "Usage : " << argv[0]
123 << " filename meshname" << endl << endl;
126 string filename = argv[1] ;
127 string meshname = argv[2] ;
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() ;
138 const CONNECTIVITY * myConnectivity = myMesh->getConnectivityptr();
139 affiche_connectivity(myConnectivity, myMesh);
141 CONNECTIVITY * myConnectivity2 = new CONNECTIVITY(* myConnectivity);
142 affiche_connectivity(myConnectivity2, myMesh);
144 CONNECTIVITY * myConnectivity3 = new CONNECTIVITY(* myConnectivity2);
145 delete myConnectivity2;
146 affiche_connectivity(myConnectivity3, myMesh);
147 delete myConnectivity3;