Back to index

salome-med  6.5.0
MESHconnectivities.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "MEDMEM_Mesh.hxx"
00024 
00025 using namespace MEDMEM ;
00026 using namespace MED_EN ;
00027 
00028 int main (int argc, char ** argv)
00029 {
00030   //   const string MedFile = "polyedres.med" ;
00031   //   const string MeshName = "Erreur orientation" ;
00032   //   const string MedFile = "polygones.med" ;
00033   //   const string MeshName = "Bord" ;
00034   const string MedFile = "pointe.med" ;
00035   const string MeshName = "maa1" ;
00036   MESH myMesh(MED_DRIVER,MedFile,MeshName) ;
00037 
00038   cout << "Mesh name : " << myMesh.getName()  << endl << endl ; 
00039 
00040   // we get all type for cell entity :
00041   int NumberOfTypes = myMesh.getNumberOfTypes(MED_CELL) ;
00042   cout << "Show Connectivity (Nodal) :" << endl ;
00043   // this example use access with a specified medGeometryElement array
00044   const medGeometryElement * Types = myMesh.getTypes(MED_CELL);
00045   string * cellTypeNames =  myMesh.getCellTypeNames(MED_CELL);
00046   for (int i=0; i<NumberOfTypes; i++) {
00047     cout << "For type " << cellTypeNames[i] << " : " << endl ;
00048     medGeometryElement myType = Types[i] ;
00049     int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,myType);
00050     int NomberOfNodesPerCell = Types[i]%100 ;
00051     const int * Connectivity = myMesh.getConnectivity(MED_NODAL,MED_CELL,myType);
00052     for (int j=0; j<NumberOfElements; j++){
00053       cout << "Element "<< j+1 <<" : " ;
00054       for (int k=0; k<NomberOfNodesPerCell; k++)
00055         cout << Connectivity[j*NomberOfNodesPerCell+k]<<" ";
00056       cout << endl ;
00057     }
00058   }
00059   cout << "Show Reverse Nodal Connectivity :" << endl ;
00060   // this example use global access with index array
00061   int NumberOfNodes = myMesh.getNumberOfNodes() ;
00062   const int * ReverseNodalConnectivity = 
00063     myMesh.getReverseConnectivity(MED_NODAL) ;
00064   const int * ReverseNodalConnectivityIndex = 
00065     myMesh.getReverseConnectivityIndex(MED_NODAL) ;
00066   for (int i=0; i<NumberOfNodes; i++) {
00067     cout << "Node "<<i+1<<" : " ;
00068     int IndexBegin = ReverseNodalConnectivityIndex[i] ;
00069     int IndexEnd = ReverseNodalConnectivityIndex[i+1] ;
00070     for (int j=IndexBegin; j<IndexEnd; j++)
00071       // Index value begin at 1 so use j-1
00072       cout << ReverseNodalConnectivity[j-1] << " " ; 
00073     cout << endl ;
00074   }
00075 
00076   cout << "Show Connectivity (Descending) :" << endl ;
00077   // this example use global access with index array
00078   int NumberOfElements = myMesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
00079   const int * DescendingConnectivity =  
00080     myMesh.getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
00081   const int * DescendingConnectivityIndex =
00082     myMesh.getConnectivityIndex(MED_DESCENDING,MED_CELL);
00083   for (int i=0; i<NumberOfElements; i++) {
00084     cout << "Element "<<i+1<<" : " ;
00085     int IndexBegin = DescendingConnectivityIndex[i] ;
00086     int IndexEnd = DescendingConnectivityIndex[i+1] ;
00087     for (int j=IndexBegin; j<IndexEnd; j++)
00088       // Index value begin at 1 so use j-1
00089       cout << DescendingConnectivity[j-1] << " " ;
00090     cout << endl ;
00091   }
00092 
00093   cout << "Show Reverse Descending Connectivity :" << endl ;
00094   // this example use global access with Index array
00095   const int * ReverseDescendingConnectivity = 
00096     myMesh.getReverseConnectivity(MED_DESCENDING) ;
00097   const int * ReverseDescendingConnectivityIndex = 
00098     myMesh.getReverseConnectivityIndex(MED_DESCENDING) ;
00099 
00100   int MeshDimension = myMesh.getMeshDimension() ;
00101   int NumberOfConstituents  = 0;
00102   string Constituent ;
00103   medEntityMesh ConstituentEntity ;
00104   // test if we have face (3D) or edge (2D)
00105   if (MeshDimension==3) {
00106     Constituent = "Face" ;
00107     ConstituentEntity = MED_FACE ;
00108   }
00109   if (MeshDimension==2) {
00110     Constituent = "Edge" ;
00111     ConstituentEntity = MED_EDGE ;
00112   }
00113 
00114   NumberOfConstituents = 
00115     myMesh.getNumberOfElements(ConstituentEntity,MED_ALL_ELEMENTS);
00116 
00117   if (MeshDimension==1) {
00118     MESSAGE_MED("ERROR : MeshDimension = 1 !");
00119     MESSAGE_MED("We could not see Reverse Descending Connectivity.") ;
00120   } else {
00121     for (int i=0; i<NumberOfConstituents; i++) {
00122       cout << Constituent << " " << i+1 << " : " ;
00123       int IndexBegin = ReverseDescendingConnectivityIndex[i] ;
00124       int IndexEnd = ReverseDescendingConnectivityIndex[i+1] ;
00125       for (int j=IndexBegin;j<IndexEnd;j++)
00126         // Index value begin at 1 so use j-1
00127         cout << ReverseDescendingConnectivity[j-1] << " " ;
00128       cout << endl ;
00129     }
00130   }
00131   cout << "Show "<< Constituent <<" Connectivity (Nodal) :" << endl ;
00132   // this example use global access with index array
00133   const int * ConstituentConnectivity =  
00134     myMesh.getConnectivity(MED_NODAL,ConstituentEntity,MED_ALL_ELEMENTS);
00135   const int * ConstituentConnectivityIndex =
00136     myMesh.getConnectivityIndex(MED_NODAL,ConstituentEntity);
00137   for (int i=0; i<NumberOfConstituents; i++) {
00138     cout << Constituent << " " << i+1 << " : " ;
00139     int IndexBegin = ConstituentConnectivityIndex[i] ;
00140     int IndexEnd = ConstituentConnectivityIndex[i+1] ;
00141     for (int j=IndexBegin; j<IndexEnd; j++)
00142       // Index value begin at 1 so use j-1
00143       cout << ConstituentConnectivity[j-1]<<" ";
00144     cout << endl ;
00145   }
00146 
00147   return 0 ;
00148 }