Salome HOME
remove a reference to the $MED_ROOT_DIR in the Makefile.in wich is useless
[modules/med.git] / src / MEDMEM / test_grid.cxx
1 #include "MEDMEM_Grid.hxx"
2
3 #ifdef _DEBUG_
4 #include "LocalTraceCollector.hxx"
5 #endif /* ifdef _DEBUG_*/
6
7 using namespace MEDMEM;
8 using namespace MED_EN;
9
10 static void usage(const char * test)
11 {
12     cerr << "Usage : " << test
13         << " SpaceDimension  nbMaille" << endl << endl
14         << "-> Crée une grille cartesienne en dimension SpaceDimension avec nbMaille suivant chaque direction" << endl;
15     exit(-1);
16 }
17
18 int main (int argc, char ** argv) {
19
20     /* process the arguments */
21     if (argc != 3)
22         usage(argv[0]);
23
24 #ifdef _DEBUG_
25   LocalTraceCollector::instance();
26 #endif /* ifdef _DEBUG_*/
27
28     const int SpaceDimension=atoi(argv[1]);
29     const int nbMaille=atoi(argv[2]);
30     if(SpaceDimension>3 || SpaceDimension<1 || nbMaille<1)
31         usage(argv[0]);
32
33     // Creation des tableaux necessaires à la construction de GRID
34     std::vector<int> nMaille(SpaceDimension,nbMaille);
35     std::vector<double> Origine(SpaceDimension,0.0);
36     std::vector<double> pas(SpaceDimension,10.0);
37     std::vector<std::vector<double> > XYZ_Array(SpaceDimension);
38     for(int i=0;i!=SpaceDimension;++i)
39     {
40         XYZ_Array[i].resize(nMaille[i]+1); // nbre de noeuds = nbre de mailles +1
41         XYZ_Array[i][0]=Origine[i];
42         for(int j=1;j!=XYZ_Array[i].size();++j)
43             XYZ_Array[i][j]=XYZ_Array[i][j-1] + pas[j-1];
44     }
45     
46     std::vector<std::string> coord_name(SpaceDimension,"X");
47     if(SpaceDimension>=2)
48         coord_name[1]="Y";
49     if(SpaceDimension>=3)
50         coord_name[2]="Z";
51     std::vector<std::string> coord_unit(SpaceDimension,"cm");
52
53     // creation du pointeur MESH à partir d'un GRID, test affichage
54     std::auto_ptr<MEDMEM::MESH> Mesh (new MEDMEM::GRID( XYZ_Array, coord_name, coord_unit, MED_CARTESIAN) );
55     const MEDMEM::CONNECTIVITY* conn = Mesh->getConnectivityptr();
56     std::cout << "Affichage du maillage : " << endl << *Mesh << endl;
57 }