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 #include "LocalTraceCollector.hxx"
22 #endif /* ifdef _DEBUG_*/
25 using namespace MEDMEM;
26 using namespace MED_EN;
28 void affiche_connectivity(const CONNECTIVITY * myConnectivity, MESH * myMesh)
30 int SpaceDimension = myMesh->getSpaceDimension() ;
31 int MeshDimension = myMesh->getMeshDimension() ;
32 int NumberOfNodes = myMesh->getNumberOfNodes() ;
34 int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL) ;
35 const medGeometryElement * Types = myMesh->getTypes(MED_CELL) ;
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]<<" ";
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] << " " ;
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);
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);
71 catch (MEDEXCEPTION m) {
72 cout << m.what() << endl ;
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]<<" ";
82 cout << "Show Reverse Descending Connectivity :" << endl ;
83 const int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ;
84 const int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ;
86 int NumberOfConstituents = 0;
88 medEntityMesh constituentEntity ;
90 if (MeshDimension==3) {
91 constituent = "Face" ;
92 constituentEntity = MED_FACE ;
95 if (MeshDimension==2) {
96 constituent = "Edge" ;
97 constituentEntity = MED_EDGE ;
100 if (MeshDimension==1) {
101 MESSAGE("ERROR : MeshDimension = 1 !");
102 MESSAGE("We could not see Reverse Descending Connectivity.") ;
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] << " " ;
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]<<" ";
124 int main (int argc, char ** argv) {
126 if (argc <3) { // after 3, ignored !
127 cerr << "Usage : " << argv[0]
128 << " filename meshname" << endl << endl;
133 LocalTraceCollector::instance();
134 #endif /* ifdef _DEBUG_*/
136 string filename = argv[1] ;
137 string meshname = argv[2] ;
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() ;
148 const CONNECTIVITY * myConnectivity = myMesh->getConnectivityptr();
149 affiche_connectivity(myConnectivity, myMesh);
151 CONNECTIVITY * myConnectivity2 = new CONNECTIVITY(* myConnectivity);
152 affiche_connectivity(myConnectivity2, myMesh);
154 CONNECTIVITY * myConnectivity3 = new CONNECTIVITY(* myConnectivity2);
155 delete myConnectivity2;
156 affiche_connectivity(myConnectivity3, myMesh);
157 delete myConnectivity3;