Back to index

salome-med  6.5.0
test_copie_connectivity.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 /* Programme de test du constructeur de copies de la classe CONNECTIVITY de MEDMEM
00023    jroy - 19/12/2002 */
00024 
00025 #include <string>
00026 
00027 #include <math.h>
00028 #include <stdlib.h>
00029 
00030 #include "MEDMEM_Exception.hxx"
00031 #include "MEDMEM_Mesh.hxx"
00032 #include "MEDMEM_Family.hxx"
00033 #include "MEDMEM_Group.hxx"
00034 
00035 #include "MEDMEM_MedMeshDriver.hxx"
00036 #include "MEDMEM_MedFieldDriver.hxx"
00037 #include "MEDMEM_Support.hxx"
00038 #include "MEDMEM_Field.hxx"
00039 #include "MEDMEM_define.hxx"
00040 
00041 using namespace std;
00042 using namespace MEDMEM;
00043 using namespace MED_EN;
00044 
00045 static void affiche_connectivity(const CONNECTIVITY * myConnectivity, MESH * myMesh)
00046 {
00047   int MeshDimension  = myMesh->getMeshDimension() ;
00048   int NumberOfNodes  = myMesh->getNumberOfNodes() ;
00049 
00050   int NumberOfTypes                 = myMesh->getNumberOfTypes(MED_CELL) ;
00051   const medGeometryElement  * Types = myMesh->getTypes(MED_CELL) ;
00052 
00053   cout << "Show Connectivity (Nodal) :" << endl ;
00054   for (int i=0; i<NumberOfTypes; i++) {
00055     cout << "For type " << Types[i] << " : " << endl ;
00056     int NumberOfElements = myMesh->getNumberOfElements(MED_CELL,Types[i]);
00057     const int * connectivity =  myMesh->getConnectivity(MED_NODAL,MED_CELL,Types[i]);
00058     int NomberOfNodesPerCell = Types[i]%100 ;
00059     for (int j=0;j<NumberOfElements;j++){
00060       cout << "Element "<< j+1 <<" : " ;
00061       for (int k=0;k<NomberOfNodesPerCell;k++)
00062         cout << connectivity[j*NomberOfNodesPerCell+k]<<" ";
00063       cout << endl ;
00064     }
00065   }
00066 
00067   cout << "Show Reverse Nodal Connectivity :" << endl ;
00068   const int * ReverseNodalConnectivity = myMesh->getReverseConnectivity(MED_NODAL) ;
00069   const int * ReverseNodalConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_NODAL) ;
00070   for (int i=0; i<NumberOfNodes; i++) {
00071     cout << "Node "<<i+1<<" : " ;
00072     for (int j=ReverseNodalConnectivityIndex[i];j<ReverseNodalConnectivityIndex[i+1];j++)
00073       cout << ReverseNodalConnectivity[j-1] << " " ;
00074     cout << endl ;
00075   }
00076 
00077   cout << "Show Connectivity (Descending) :" << endl ;
00078   int NumberOfElements ;
00079   const int * connectivity ;
00080   const int * connectivity_index ;
00081   myMesh->calculateConnectivity(MED_DESCENDING,MED_CELL);
00082   try {
00083     NumberOfElements = myMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
00084     connectivity =  myMesh->getConnectivity(MED_DESCENDING,MED_CELL,MED_ALL_ELEMENTS);
00085     connectivity_index =  myMesh->getConnectivityIndex(MED_DESCENDING,MED_CELL);
00086   }
00087   catch (MEDEXCEPTION& m) {
00088     cout << m.what() << endl ;
00089     exit (-1) ;
00090   }
00091   for (int j=0;j<NumberOfElements;j++) {
00092     cout << "Element "<<j+1<<" : " ;
00093     for (int k=connectivity_index[j];k<connectivity_index[j+1];k++)
00094       cout << connectivity[k-1]<<" ";
00095     cout << endl ;
00096   }
00097 
00098   cout << "Show Reverse Descending Connectivity :" << endl ;
00099   const int * ReverseDescendingConnectivity = myMesh->getReverseConnectivity(MED_DESCENDING) ;
00100   const int * ReverseDescendingConnectivityIndex = myMesh->getReverseConnectivityIndex(MED_DESCENDING) ;
00101 
00102   int NumberOfConstituents  = 0;
00103   string constituent ;
00104   medEntityMesh constituentEntity ;
00105 
00106   if (MeshDimension==3) {
00107     constituent = "Face" ;
00108     constituentEntity = MED_FACE ;
00109   }
00110 
00111   if (MeshDimension==2) {
00112     constituent = "Edge" ;
00113     constituentEntity = MED_EDGE ;
00114   }
00115 
00116   if (MeshDimension==1) {
00117     MESSAGE_MED("ERROR : MeshDimension = 1 !");
00118     MESSAGE_MED("We could not see Reverse Descending Connectivity.") ;
00119   } else {
00120     NumberOfConstituents = myMesh->getNumberOfElements (constituentEntity,MED_ALL_ELEMENTS);
00121     for (int i=0; i<NumberOfConstituents; i++) {
00122       cout << constituent <<i+1<<" : " ;
00123       for (int j=ReverseDescendingConnectivityIndex[i];j<ReverseDescendingConnectivityIndex[i+1];j++)
00124         cout << ReverseDescendingConnectivity[j-1] << " " ;
00125       cout << endl ;
00126     }
00127   }
00128   cout << "Show "<<constituent<<" Connectivity (Nodal) :" << endl ;
00129   const int * face_connectivity =  myMesh->getConnectivity(MED_NODAL,constituentEntity,MED_ALL_ELEMENTS);
00130   const int * face_connectivity_index =  myMesh->getConnectivityIndex(MED_NODAL,constituentEntity);
00131   for (int i=0; i<NumberOfConstituents; i++) {
00132     cout << constituent <<i+1<<" : " ;
00133     for (int j=face_connectivity_index[i];j<face_connectivity_index[i+1];j++)
00134       cout << face_connectivity[j-1]<<" ";
00135     cout << endl ;
00136   }
00137 }
00138 
00139 
00140 int main (int argc, char ** argv) {
00141 
00142   if (argc <3) { // after 3, ignored !
00143     cerr << "Usage : " << argv[0] 
00144          << " filename meshname" << endl << endl;
00145     exit(-1);
00146   }
00147 
00148   string filename = argv[1] ;
00149   string meshname = argv[2] ;
00150 
00151   //Construction d'un maillage
00152   MESH * myMesh= new MESH;
00153   myMesh->setName(meshname);
00154   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
00155   myMeshDriver.setMeshName(meshname);
00156   myMeshDriver.open() ;
00157   myMeshDriver.read() ; //A partir d'ici la connectivité est construite
00158   myMeshDriver.close() ;
00159 
00160   const CONNECTIVITY * myConnectivity = myMesh->getConnectivityptr();
00161   affiche_connectivity(myConnectivity, myMesh);
00162 
00163   CONNECTIVITY * myConnectivity2 = new CONNECTIVITY(* myConnectivity);
00164   affiche_connectivity(myConnectivity2, myMesh);
00165 
00166   CONNECTIVITY * myConnectivity3 = new CONNECTIVITY(* myConnectivity2);
00167   delete myConnectivity2;
00168   affiche_connectivity(myConnectivity3, myMesh);
00169   delete myConnectivity3;
00170 
00171   myMesh->removeReference();
00172 
00173   return 0;
00174 }