Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM / test_grid.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include "MEDMEM_Grid.hxx"
21
22 using namespace MEDMEM;
23 using namespace MED_EN;
24
25 static void usage(const char * test)
26 {
27     cerr << "Usage : " << test
28         << " SpaceDimension  nbMaille" << endl << endl
29         << "-> Crée une grille cartesienne en dimension SpaceDimension avec nbMaille suivant chaque direction" << endl;
30     exit(-1);
31 }
32
33 int main (int argc, char ** argv) {
34
35     /* process the arguments */
36     if (argc != 3)
37         usage(argv[0]);
38
39     const int SpaceDimension=atoi(argv[1]);
40     const int nbMaille=atoi(argv[2]);
41     if(SpaceDimension>3 || SpaceDimension<1 || nbMaille<1)
42         usage(argv[0]);
43
44     // Creation des tableaux necessaires à la construction de GRID
45     std::vector<int> nMaille(SpaceDimension,nbMaille);
46     std::vector<double> Origine(SpaceDimension,0.0);
47     std::vector<double> pas(SpaceDimension,10.0);
48     std::vector<std::vector<double> > XYZ_Array(SpaceDimension);
49     for(int i=0;i!=SpaceDimension;++i)
50     {
51         XYZ_Array[i].resize(nMaille[i]+1); // nbre de noeuds = nbre de mailles +1
52         XYZ_Array[i][0]=Origine[i];
53         for(int j=1;j!=XYZ_Array[i].size();++j)
54             XYZ_Array[i][j]=XYZ_Array[i][j-1] + pas[j-1];
55     }
56     
57     std::vector<std::string> coord_name(SpaceDimension,"X");
58     if(SpaceDimension>=2)
59         coord_name[1]="Y";
60     if(SpaceDimension>=3)
61         coord_name[2]="Z";
62     std::vector<std::string> coord_unit(SpaceDimension,"cm");
63
64     // creation du pointeur MESH à partir d'un GRID, test affichage
65     std::auto_ptr<MEDMEM::MESH> Mesh (new MEDMEM::GRID( XYZ_Array, coord_name, coord_unit, MED_CARTESIAN) );
66     const MEDMEM::CONNECTIVITY* conn = Mesh->getConnectivityptr();
67     std::cout << "Affichage du maillage : " << endl << *Mesh << endl;
68 }