1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 /* Programme de test du constructeur de copies de la classe CONNECTIVITY de MEDMEM
30 #include "MEDMEM_Exception.hxx"
31 #include "MEDMEM_Mesh.hxx"
32 #include "MEDMEM_Family.hxx"
33 #include "MEDMEM_Group.hxx"
35 #include "MEDMEM_MedMeshDriver.hxx"
36 #include "MEDMEM_MedFieldDriver.hxx"
37 #include "MEDMEM_Support.hxx"
38 #include "MEDMEM_Field.hxx"
39 #include "MEDMEM_define.hxx"
42 using namespace MEDMEM;
43 using namespace MED_EN;
45 static void affiche_connectivity(const CONNECTIVITY * myConnectivity, MESH * myMesh)
47 int MeshDimension = myMesh->getMeshDimension() ;
48 int NumberOfNodes = myMesh->getNumberOfNodes() ;
50 int NumberOfTypes = myMesh->getNumberOfTypes(MED_CELL) ;
51 const medGeometryElement * Types = myMesh->getTypes(MED_CELL) ;
53 cout << "Show Connectivity (Nodal) :" << endl ;
54 for (int i=0; i<NumberOfTypes; i++) {
55 cout << "For type " << Types[i] << " : " << endl ;
56 int NumberOfElements = myMesh->getNumberOfElements(MED_CELL,Types[i]);
57 const int * connectivity = myMesh->getConnectivity(MED_NODAL,MED_CELL,Types[i]);
58 int NomberOfNodesPerCell = Types[i]%100 ;
59 for (int j=0;j<NumberOfElements;j++){
60 cout << "Element "<< j+1 <<" : " ;
61 for (int k=0;k<NomberOfNodesPerCell;k++)
62 cout << connectivity[j*NomberOfNodesPerCell+k]<<" ";
67 cout << "Show Reverse Nodal Connectivity :" << endl ;
68 const int * ReverseNodalConnectivity = myMesh->getReverseConnectivity(MED_NODAL) ;
69 const int * ReverseNodalConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_NODAL) ;
70 for (int i=0; i<NumberOfNodes; i++) {
71 cout << "Node "<<i+1<<" : " ;
72 for (int j=ReverseNodalConnectivityIndex[i];j<ReverseNodalConnectivityIndex[i+1];j++)
73 cout << ReverseNodalConnectivity[j-1] << " " ;
77 cout << "Show Connectivity (Descending) :" << endl ;
78 int NumberOfElements ;
79 const int * connectivity ;
80 const int * connectivity_index ;
81 myMesh->calculateConnectivity(MED_DESCENDING,MED_CELL);
83 NumberOfElements = myMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
84 connectivity = myMesh->getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
85 connectivity_index = myMesh->getConnectivityIndex(MED_DESCENDING,MED_CELL);
87 catch (MEDEXCEPTION& m) {
88 cout << m.what() << endl ;
91 for (int j=0;j<NumberOfElements;j++) {
92 cout << "Element "<<j+1<<" : " ;
93 for (int k=connectivity_index[j];k<connectivity_index[j+1];k++)
94 cout << connectivity[k-1]<<" ";
98 cout << "Show Reverse Descending Connectivity :" << endl ;
99 const int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ;
100 const int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ;
102 int NumberOfConstituents = 0;
104 medEntityMesh constituentEntity ;
106 if (MeshDimension==3) {
107 constituent = "Face" ;
108 constituentEntity = MED_FACE ;
111 if (MeshDimension==2) {
112 constituent = "Edge" ;
113 constituentEntity = MED_EDGE ;
116 if (MeshDimension==1) {
117 MESSAGE_MED("ERROR : MeshDimension = 1 !");
118 MESSAGE_MED("We could not see Reverse Descending Connectivity.") ;
120 NumberOfConstituents = myMesh->getNumberOfElements (constituentEntity,MED_ALL_ELEMENTS);
121 for (int i=0; i<NumberOfConstituents; i++) {
122 cout << constituent <<i+1<<" : " ;
123 for (int j=ReverseDescendingConnectivityIndex[i];j<ReverseDescendingConnectivityIndex[i+1];j++)
124 cout << ReverseDescendingConnectivity[j-1] << " " ;
128 cout << "Show "<<constituent<<" Connectivity (Nodal) :" << endl ;
129 const int * face_connectivity = myMesh->getConnectivity(MED_NODAL,constituentEntity,MED_ALL_ELEMENTS);
130 const int * face_connectivity_index = myMesh->getConnectivityIndex(MED_NODAL,constituentEntity);
131 for (int i=0; i<NumberOfConstituents; i++) {
132 cout << constituent <<i+1<<" : " ;
133 for (int j=face_connectivity_index[i];j<face_connectivity_index[i+1];j++)
134 cout << face_connectivity[j-1]<<" ";
140 int main (int argc, char ** argv) {
142 if (argc <3) { // after 3, ignored !
143 cerr << "Usage : " << argv[0]
144 << " filename meshname" << endl << endl;
148 string filename = argv[1] ;
149 string meshname = argv[2] ;
151 //Construction d'un maillage
152 MESH * myMesh= new MESH;
153 myMesh->setName(meshname);
154 MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
155 myMeshDriver.setMeshName(meshname);
156 myMeshDriver.open() ;
157 myMeshDriver.read() ; //A partir d'ici la connectivité est construite
158 myMeshDriver.close() ;
160 const CONNECTIVITY * myConnectivity = myMesh->getConnectivityptr();
161 affiche_connectivity(myConnectivity, myMesh);
163 CONNECTIVITY * myConnectivity2 = new CONNECTIVITY(* myConnectivity);
164 affiche_connectivity(myConnectivity2, myMesh);
166 CONNECTIVITY * myConnectivity3 = new CONNECTIVITY(* myConnectivity2);
167 delete myConnectivity2;
168 affiche_connectivity(myConnectivity3, myMesh);
169 delete myConnectivity3;
171 myMesh->removeReference();