Back to index

salome-med  6.5.0
test_copie_support.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 #include "MEDMEM_Exception.hxx"
00023 #include "MEDMEM_Mesh.hxx"
00024 #include "MEDMEM_Family.hxx"
00025 #include "MEDMEM_Group.hxx"
00026 
00027 #include "MEDMEM_MedMeshDriver.hxx"
00028 #include "MEDMEM_MedFieldDriver.hxx"
00029 #include "MEDMEM_Support.hxx"
00030 #include "MEDMEM_Field.hxx"
00031 #include "MEDMEM_define.hxx"
00032 
00033 #include<string>
00034 
00035 #include <math.h>
00036 #include <stdlib.h>
00037 
00038 using namespace std;
00039 using namespace MEDMEM;
00040 using namespace MED_EN;
00041 
00042 static void affiche_support(const SUPPORT * mySupport) 
00043 {
00044   cout << "  - Name : "<<mySupport->getName().c_str()<<endl ;
00045   cout << "  - Description : "<<mySupport->getDescription().c_str()<<endl ;
00046   cout << "  - Entity : "<<mySupport->getEntity()<<endl ;
00047   cout << "  - Entities list : "<<endl ;
00048   if (!(mySupport->isOnAllElements())) 
00049     {
00050       int NumberOfTypes = mySupport->getNumberOfTypes() ;
00051       cout<<"  - NumberOfTypes : "<<NumberOfTypes<<endl;
00052       const medGeometryElement * Types = mySupport->getTypes() ;
00053       for (int j=0;j<NumberOfTypes;j++) 
00054         {
00055           cout<<"    * Type "<<Types[j]<<" : ";
00056           int NumberOfElements = mySupport->getNumberOfElements(Types[j]) ;
00057           const int * Number = mySupport->getNumber(Types[j]) ;
00058           for (int k=0; k<NumberOfElements;k++)
00059             cout << Number[k] << " ";
00060           cout << endl ;
00061         }
00062     }
00063   else
00064     cout << "    Is on all entities !"<< endl;
00065 }
00066 
00067 int main (int argc, char ** argv)
00068 {
00069   if (argc <3) // after 3, ignored !
00070     {
00071       cerr << "Usage : " << argv[0] 
00072            << " filename meshname" << endl << endl;
00073       exit(-1);
00074     }
00075 
00076   string filename = argv[1] ;
00077   string meshname = argv[2] ;
00078 
00079   MESH * myMesh= new MESH;
00080   myMesh->setName(meshname);
00081   MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
00082   myMeshDriver.setMeshName(meshname);
00083   myMeshDriver.open() ;
00084   myMeshDriver.read() ;
00085   myMeshDriver.close() ;
00086 
00087   //Construction d'un support total
00088   const SUPPORT * mySupportTotal = myMesh->getSupportOnAll(MED_CELL);
00089 
00090   cout << "Show Support on all :"<<endl ;
00091   affiche_support(mySupportTotal);
00092   SUPPORT * mySupport2 = new SUPPORT(* mySupportTotal);
00093   affiche_support(mySupport2);
00094   mySupport2->removeReference();
00095 
00096   //Construction d'un support partiel
00097   SUPPORT* mySupport = new SUPPORT;
00098   mySupport->setMesh(myMesh);
00099   mySupport->setName("Support on CELLs");
00100   mySupport->setEntity(MED_CELL);
00101 
00102   int NumberOfGeometricType = 0;
00103   int TotalNumberOfElements = 0;
00104   int * NumberOfElements = new int[myMesh->getNumberOfTypes(MED_CELL)];
00105   int * NumberValue = new int[myMesh->getGlobalNumberingIndex(MED_CELL)[myMesh->getNumberOfTypes(MED_CELL)]-1];
00106   int cmp = 0;
00107   medGeometryElement * GeometricTypePartial = new medGeometryElement[myMesh->getNumberOfTypes(MED_CELL)];
00108   const medGeometryElement * GeometricType = myMesh->getTypes(MED_CELL);
00109   for (int i=0;i<myMesh->getNumberOfTypes(MED_CELL);i=i+2)
00110     {
00111       NumberOfGeometricType=NumberOfGeometricType+1;
00112       TotalNumberOfElements=TotalNumberOfElements+myMesh->getNumberOfElements(MED_CELL,GeometricType[i]);
00113       NumberOfElements[i/2]=myMesh->getNumberOfElements(MED_CELL,GeometricType[i]);
00114       for (int j=0;j<myMesh->getNumberOfElements(MED_CELL,GeometricType[i]);j++)
00115         {
00116           NumberValue[cmp]=myMesh->getGlobalNumberingIndex(MED_CELL)[i]+j;
00117           cmp=cmp+1;
00118         }
00119       GeometricTypePartial[i/2]=GeometricType[i];
00120     }
00121 
00122   mySupport->setpartial("Support partiel",NumberOfGeometricType,TotalNumberOfElements,GeometricTypePartial,NumberOfElements,NumberValue);
00123 
00124   delete[] NumberOfElements ;
00125   delete[] NumberValue ;
00126   delete[] GeometricTypePartial ;
00127 
00128   cout << "Show Partial Support :"<<endl ;
00129   affiche_support(mySupport);
00130   mySupport2 = new SUPPORT(* mySupport);
00131   mySupport->removeReference();
00132   affiche_support(mySupport2);
00133   mySupport2->removeReference();
00134 
00135   myMesh->removeReference();
00136 
00137   return 0;
00138 }