Back to index

salome-med  6.5.0
test_grid.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_Grid.hxx"
00023 #include <memory>
00024 
00025 using namespace MEDMEM;
00026 using namespace MED_EN;
00027 
00028 static void usage(const char * test)
00029 {
00030     cerr << "Usage : " << test
00031         << " SpaceDimension  nbMaille" << endl << endl
00032         << "-> Crée une grille cartesienne en dimension SpaceDimension avec nbMaille suivant chaque direction" << endl;
00033     exit(-1);
00034 }
00035 
00036 int main (int argc, char ** argv) {
00037 
00038     /* process the arguments */
00039     if (argc != 3)
00040         usage(argv[0]);
00041 
00042     const int SpaceDimension=atoi(argv[1]);
00043     const int nbMaille=atoi(argv[2]);
00044     if(SpaceDimension>3 || SpaceDimension<1 || nbMaille<1)
00045         usage(argv[0]);
00046 
00047     // Creation des tableaux necessaires à la construction de GRID
00048     std::vector<int> nMaille(SpaceDimension,nbMaille);
00049     std::vector<double> Origine(SpaceDimension,0.0);
00050     std::vector<double> pas(SpaceDimension,10.0);
00051     std::vector<std::vector<double> > XYZ_Array(SpaceDimension);
00052     for(int i=0;i!=SpaceDimension;++i)
00053     {
00054         XYZ_Array[i].resize(nMaille[i]+1); // nbre de noeuds = nbre de mailles +1
00055         XYZ_Array[i][0]=Origine[i];
00056         for(int j=1;j!=(int)XYZ_Array[i].size();++j)
00057             XYZ_Array[i][j]=XYZ_Array[i][j-1] + pas[i];
00058     }
00059     
00060     std::vector<std::string> coord_name(SpaceDimension,"X");
00061     if(SpaceDimension>=2)
00062         coord_name[1]="Y";
00063     if(SpaceDimension>=3)
00064         coord_name[2]="Z";
00065     std::vector<std::string> coord_unit(SpaceDimension,"cm");
00066 
00067     // creation du pointeur MESH à partir d'un GRID, test affichage
00068     MEDMEM::GMESH *grid=(new MEDMEM::GRID( XYZ_Array, coord_name, coord_unit, MED_CARTESIAN) );
00069     const MEDMEM::MESH* Mesh = grid->convertInMESH(); 
00070     Mesh->getConnectivityptr();
00071     std::cout << "Affichage du maillage : " << endl << *Mesh << endl;
00072     Mesh->removeReference();
00073     grid->removeReference();
00074 }