Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MEDMEM / test_copie_coordinate.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 /* Programme de test du constructeur de copies de la classe COORDINATE de MEDMEM
21    jroy - 17/12/2002 */
22
23 #include <string>
24
25 #include <math.h>
26 #include <stdlib.h>
27
28 #include "MEDMEM_Exception.hxx"
29 #include "MEDMEM_Mesh.hxx"
30 #include "MEDMEM_Family.hxx"
31 #include "MEDMEM_Group.hxx"
32
33 #include "MEDMEM_MedMeshDriver.hxx"
34 #include "MEDMEM_MedFieldDriver.hxx"
35 #include "MEDMEM_Support.hxx"
36 #include "MEDMEM_Field.hxx"
37 #include "MEDMEM_define.hxx"
38
39 using namespace std;
40 using namespace MEDMEM;
41 using namespace MED_EN;
42
43 void affiche_tableau(const double * myArray, int nb_lignes, int nb_colonnes)
44 {
45   cout << "Nombre de lignes : " << nb_lignes << endl;
46   cout << "Nombre de colonnes : " << nb_colonnes << endl;
47   cout << "Valeurs :" << endl;
48
49   for (int i=0; i<nb_lignes; i++) {
50     for (int j=0; j<nb_colonnes; j++)
51       cout << myArray[j*nb_lignes+i] << " ";
52     cout << endl;}
53 }
54
55 void affiche_coordinate(COORDINATE & myCoordinate, int _numberofNodes, int _spaceDimension)
56 {
57   cout << "- Système de coordonnées : " << myCoordinate.getCoordinatesSystem() << endl;
58   cout << "- Tableau des coordonnées : " << endl;
59   //  affiche_medarray(* myCoordinate.getCoordinatePtr());
60   affiche_tableau(myCoordinate.getCoordinates(MED_NO_INTERLACE),_numberofNodes,_spaceDimension);
61   //on récupère les dimensions
62   //  int _spaceDimension = (int) myCoordinate.getCoordinatePtr()->getLeadingValue();
63   //int _numberofNodes = (int) myCoordinate.getCoordinatePtr()->getLengthValue();
64   cout << "- Nom des coordonnées : " << endl;
65   for (int i=1; i<=_spaceDimension; i++)
66     cout << i << "   " << myCoordinate.getCoordinateName(i) << endl;
67   //  cout<<myCoordinate.getCoordinatesNames()<<endl;
68   cout << "- Unité des coordonnées : " << endl;
69   for (int i=1; i<=_spaceDimension; i++)
70     cout << i << "   " << myCoordinate.getCoordinateUnit(i) << endl;
71   cout << "- Indices des noeuds : " << endl;
72   //  cout<<myCoordinate.getNodesNumbers()<<endl;
73   for (int i=0; i<_numberofNodes; i++)
74     cout << i << "   " << myCoordinate.getNodesNumbers()[i] << endl;
75 }
76
77
78 int main (int argc, char ** argv) {
79   /*
80   if ((argc !=3) && (argc != 4)) {
81     cerr << "Usage : " << argv[0] 
82          << " filename meshname fieldname" << endl << endl;
83     exit(-1);
84   }
85   */
86   const med_int numberofNodes = 5;
87   const med_int spaceDimension = 3;
88   const medModeSwitch mode = MED_FULL_INTERLACE;
89
90   //construction tableau MEDARRAY des coordonnées
91   MEDARRAY<double> * myMedArray = new MEDARRAY<double>(spaceDimension,numberofNodes,mode);
92   for (med_int i=1; i<=myMedArray->getLengthValue(); i++) {
93     for (med_int j=1; j<=myMedArray->getLeadingValue(); j++)
94       myMedArray->setIJ(i,j,(double) random());
95   };
96
97   //construction noms des coordonnées
98   string * myCoordinatesNames = new string[spaceDimension];
99   if (spaceDimension >= 1) myCoordinatesNames[0] = "x";
100   if (spaceDimension >= 2) myCoordinatesNames[1] = "y";
101   if (spaceDimension >= 3) myCoordinatesNames[2] = "z";
102
103   //construction unités des coordonnées
104   string * myCoordinatesUnits = new string[spaceDimension];
105   if (spaceDimension >= 1) myCoordinatesUnits[0] = "m";
106   if (spaceDimension >= 2) myCoordinatesUnits[1] = "m";
107   if (spaceDimension >= 3) myCoordinatesUnits[2] = "m";
108
109   //construction des indices des noeuds
110   int * myNodeNumber = new int[numberofNodes];
111   for (int i=0; i<numberofNodes; i++)
112     myNodeNumber[i]=numberofNodes-i-1;
113
114   //construction de l'objet COORDINATE
115   COORDINATE * myCoordinate = new COORDINATE();
116   myCoordinate->setCoordinates(myMedArray);
117   myCoordinate->setCoordinatesNames(myCoordinatesNames);
118   myCoordinate->setCoordinatesUnits(myCoordinatesUnits);
119   myCoordinate->setNodesNumbers(myNodeNumber);
120
121   //  myCoordinate->setCoordinatesNames((string *)NULL);
122   //  myCoordinate->setNodesNumbers((int *) NULL);
123
124   delete myMedArray ;
125   delete[] myCoordinatesNames ;
126   delete[] myCoordinatesUnits ;
127   delete[] myNodeNumber ;
128
129   affiche_coordinate(* myCoordinate,numberofNodes,spaceDimension);
130   COORDINATE * myCoordinate2 = new COORDINATE(* myCoordinate);
131   delete myCoordinate ;
132
133   affiche_coordinate(* myCoordinate2,numberofNodes,spaceDimension);
134   delete myCoordinate2 ;
135
136   return 0;
137 }