1 /* Programme de test du constructeur de copies de la classe CONNECTIVITY de MEDMEM
9 #include "MEDMEM_Exception.hxx"
10 #include "MEDMEM_Mesh.hxx"
11 #include "MEDMEM_Family.hxx"
12 #include "MEDMEM_Group.hxx"
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"
21 using namespace MEDMEM;
22 using namespace MED_EN;
24 void affiche_connectivity(const CONNECTIVITY * myConnectivity, MESH * myMesh)
26 int SpaceDimension = myMesh->getSpaceDimension() ;
27 int MeshDimension = myMesh->getMeshDimension() ;
28 int NumberOfNodes = myMesh->getNumberOfNodes() ;
30 int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL) ;
31 const medGeometryElement * Types = myMesh->getTypes(MED_CELL) ;
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]<<" ";
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] << " " ;
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);
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);
67 catch (MEDEXCEPTION m) {
68 cout << m.what() << endl ;
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]<<" ";
78 cout << "Show Reverse Descending Connectivity :" << endl ;
79 const int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ;
80 const int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ;
82 int NumberOfConstituents = 0;
84 medEntityMesh constituentEntity ;
86 if (MeshDimension==3) {
87 constituent = "Face" ;
88 constituentEntity = MED_FACE ;
91 if (MeshDimension==2) {
92 constituent = "Edge" ;
93 constituentEntity = MED_EDGE ;
96 if (MeshDimension==1) {
97 MESSAGE("ERROR : MeshDimension = 1 !");
98 MESSAGE("We could not see Reverse Descending Connectivity.") ;
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] << " " ;
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]<<" ";
120 int main (int argc, char ** argv) {
123 if (argc <3) { // after 3, ignored !
124 cerr << "Usage : " << argv[0]
125 << " filename meshname" << endl << endl;
128 string filename = argv[1] ;
129 string meshname = argv[2] ;
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() ;
140 const CONNECTIVITY * myConnectivity = myMesh->getConnectivityptr();
141 affiche_connectivity(myConnectivity, myMesh);
143 CONNECTIVITY * myConnectivity2 = new CONNECTIVITY(* myConnectivity);
144 affiche_connectivity(myConnectivity2, myMesh);
146 CONNECTIVITY * myConnectivity3 = new CONNECTIVITY(* myConnectivity2);
147 delete myConnectivity2;
148 affiche_connectivity(myConnectivity3, myMesh);
149 delete myConnectivity3;