1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 #include "MEDMEM_Mesh.hxx"
21 #include "MEDMEM_CellModel.hxx"
23 using namespace MEDMEM ;
24 using namespace MED_EN ;
26 int main (int argc, char ** argv) {
28 const string MedFile = "pointe.med" ;
29 const string MeshName = "maa1" ;
30 MESH myMesh(MED_DRIVER,MedFile,MeshName) ;
33 cout << "Mesh name : " << myMesh.getName() << endl << endl ;
35 // we get all type for cell entity :
36 int NumberOfTypes = myMesh.getNumberOfTypes(MED_CELL) ;
37 const CELLMODEL * Types = myMesh.getCellsTypes(MED_CELL) ;
39 cout << "Show Connectivity (Nodal) :" << endl ;
40 // this example use access with a specified medGeometryElement through
42 for (int i=0; i<NumberOfTypes; i++) {
43 cout << "For type " << Types[i].getName() << " : " << endl ;
44 medGeometryElement myType = Types[i].getType() ;
45 int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,myType);
46 int NomberOfNodesPerCell = Types[i].getNumberOfNodes() ;
47 const int * Connectivity =
48 myMesh.getConnectivity(MED_FULL_INTERLACE,
52 for (int j=0; j<NumberOfElements; j++){
53 cout << "Element "<< j+1 <<" : " ;
54 for (int k=0; k<NomberOfNodesPerCell; k++)
55 cout << Connectivity[j*NomberOfNodesPerCell+k]<<" ";
59 cout << "Show Reverse Nodal Connectivity :" << endl ;
60 // this example use global access with index array
61 int NumberOfNodes = myMesh.getNumberOfNodes() ;
62 const int * ReverseNodalConnectivity =
63 myMesh.getReverseConnectivity(MED_NODAL) ;
64 const int * ReverseNodalConnectivityIndex =
65 myMesh.getReverseConnectivityIndex(MED_NODAL) ;
66 for (int i=0; i<NumberOfNodes; i++) {
67 cout << "Node "<<i+1<<" : " ;
68 int IndexBegin = ReverseNodalConnectivityIndex[i] ;
69 int IndexEnd = ReverseNodalConnectivityIndex[i+1] ;
70 for (int j=IndexBegin; j<IndexEnd; j++)
71 // Index value begin at 1 so use j-1
72 cout << ReverseNodalConnectivity[j-1] << " " ;
76 cout << "Show Connectivity (Descending) :" << endl ;
77 // this example use global access with index array
78 int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
79 const int * DescendingConnectivity =
80 myMesh.getConnectivity(MED_FULL_INTERLACE,
84 const int * DescendingConnectivityIndex =
85 myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL);
86 for (int i=0; i<NumberOfElements; i++) {
87 cout << "Element "<<i+1<<" : " ;
88 int IndexBegin = DescendingConnectivityIndex[i] ;
89 int IndexEnd = DescendingConnectivityIndex[i+1] ;
90 for (int j=IndexBegin; j<IndexEnd; j++)
91 // Index value begin at 1 so use j-1
92 cout << DescendingConnectivity[j-1] << " " ;
96 cout << "Show Reverse Descending Connectivity :" << endl ;
97 // this example use global access with Index array
98 const int * ReverseDescendingConnectivity =
99 myMesh.getReverseConnectivity(MED_DESCENDING) ;
100 const int * ReverseDescendingConnectivityIndex =
101 myMesh.getReverseConnectivityIndex(MED_DESCENDING) ;
103 int MeshDimension = myMesh.getMeshDimension() ;
104 int NumberOfConstituents = 0;
106 medEntityMesh ConstituentEntity ;
107 // test if we have face (3D) or edge (2D)
108 if (MeshDimension==3) {
109 Constituent = "Face" ;
110 ConstituentEntity = MED_FACE ;
112 if (MeshDimension==2) {
113 Constituent = "Edge" ;
114 ConstituentEntity = MED_EDGE ;
117 NumberOfConstituents =
118 myMesh.getNumberOfElements(ConstituentEntity,MED_ALL_ELEMENTS);
120 if (MeshDimension==1) {
121 MESSAGE("ERROR : MeshDimension = 1 !");
122 MESSAGE("We could not see Reverse Descending Connectivity.") ;
124 for (int i=0; i<NumberOfConstituents; i++) {
125 cout << Constituent << " " << i+1 << " : " ;
126 int IndexBegin = ReverseDescendingConnectivityIndex[i] ;
127 int IndexEnd = ReverseDescendingConnectivityIndex[i+1] ;
128 for (int j=IndexBegin;j<IndexEnd;j++)
129 // Index value begin at 1 so use j-1
130 cout << ReverseDescendingConnectivity[j-1] << " " ;
134 cout << "Show "<< Constituent <<" Connectivity (Nodal) :" << endl ;
135 // this example use global access with index array
136 const int * ConstituentConnectivity =
137 myMesh.getConnectivity(MED_FULL_INTERLACE,
141 const int * ConstituentConnectivityIndex =
142 myMesh.getConnectivityIndex(MED_NODAL,ConstituentEntity);
143 for (int i=0; i<NumberOfConstituents; i++) {
144 cout << Constituent << " " << i+1 << " : " ;
145 int IndexBegin = ConstituentConnectivityIndex[i] ;
146 int IndexEnd = ConstituentConnectivityIndex[i+1] ;
147 for (int j=IndexBegin; j<IndexEnd; j++)
148 // Index value begin at 1 so use j-1
149 cout << ConstituentConnectivity[j-1]<<" ";