Back to index

salome-med  6.5.0
test_copie_coordinate.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 /* Programme de test du constructeur de copies de la classe COORDINATE de MEDMEM
00023    jroy - 17/12/2002 */
00024 
00025 #include <string>
00026 
00027 #include <math.h>
00028 #include <stdlib.h>
00029 
00030 #include "MEDMEM_Exception.hxx"
00031 #include "MEDMEM_Mesh.hxx"
00032 #include "MEDMEM_Family.hxx"
00033 #include "MEDMEM_Group.hxx"
00034 
00035 #include "MEDMEM_MedMeshDriver.hxx"
00036 #include "MEDMEM_MedFieldDriver.hxx"
00037 #include "MEDMEM_Support.hxx"
00038 #include "MEDMEM_Field.hxx"
00039 #include "MEDMEM_define.hxx"
00040 
00041 using namespace std;
00042 using namespace MEDMEM;
00043 using namespace MED_EN;
00044 
00045 static void affiche_tableau(const double * myArray, int nb_lignes, int nb_colonnes)
00046 {
00047   cout << "Nombre de lignes : " << nb_lignes << endl;
00048   cout << "Nombre de colonnes : " << nb_colonnes << endl;
00049   cout << "Valeurs :" << endl;
00050 
00051   for (int i=0; i<nb_lignes; i++) {
00052     for (int j=0; j<nb_colonnes; j++)
00053       cout << myArray[j*nb_lignes+i] << " ";
00054     cout << endl;}
00055 }
00056 
00057 static void affiche_coordinate(COORDINATE & myCoordinate, int _numberofNodes, int _spaceDimension)
00058 {
00059   cout << "- Système de coordonnées : " << myCoordinate.getCoordinatesSystem() << endl;
00060   cout << "- Tableau des coordonnées : " << endl;
00061   //  affiche_medarray(* myCoordinate.getCoordinatePtr());
00062   affiche_tableau(myCoordinate.getCoordinates(MED_NO_INTERLACE),_numberofNodes,_spaceDimension);
00063   //on récupère les dimensions
00064   //  int _spaceDimension = (int) myCoordinate.getCoordinatePtr()->getLeadingValue();
00065   //int _numberofNodes = (int) myCoordinate.getCoordinatePtr()->getLengthValue();
00066   cout << "- Nom des coordonnées : " << endl;
00067   for (int i=1; i<=_spaceDimension; i++)
00068     cout << i << "   " << myCoordinate.getCoordinateName(i) << endl;
00069   //  cout<<myCoordinate.getCoordinatesNames()<<endl;
00070   cout << "- Unité des coordonnées : " << endl;
00071   for (int i=1; i<=_spaceDimension; i++)
00072     cout << i << "   " << myCoordinate.getCoordinateUnit(i) << endl;
00073   cout << "- Indices des noeuds : " << endl;
00074   //  cout<<myCoordinate.getNodesNumbers()<<endl;
00075   for (int i=0; i<_numberofNodes; i++)
00076     cout << i << "   " << myCoordinate.getNodesNumbers()[i] << endl;
00077 }
00078 
00079 
00080 int main (int argc, char ** argv) {
00081   /*
00082   if ((argc !=3) && (argc != 4)) {
00083     cerr << "Usage : " << argv[0] 
00084          << " filename meshname fieldname" << endl << endl;
00085     exit(-1);
00086   }
00087   */
00088   const med_int numberofNodes = 5;
00089   const med_int spaceDimension = 3;
00090   const medModeSwitch mode = MED_FULL_INTERLACE;
00091 
00092   //construction tableau MEDARRAY des coordonnées
00093   MEDARRAY<double> * myMedArray = new MEDARRAY<double>(spaceDimension,numberofNodes,mode);
00094   for (med_int i=1; i<=myMedArray->getLengthValue(); i++) {
00095     for (med_int j=1; j<=myMedArray->getLeadingValue(); j++)
00096       myMedArray->setIJ(i,j,(double) rand());
00097   };
00098 
00099   //construction noms des coordonnées
00100   string * myCoordinatesNames = new string[spaceDimension];
00101   if (spaceDimension >= 1) myCoordinatesNames[0] = "x";
00102   if (spaceDimension >= 2) myCoordinatesNames[1] = "y";
00103   if (spaceDimension >= 3) myCoordinatesNames[2] = "z";
00104 
00105   //construction unités des coordonnées
00106   string * myCoordinatesUnits = new string[spaceDimension];
00107   if (spaceDimension >= 1) myCoordinatesUnits[0] = "m";
00108   if (spaceDimension >= 2) myCoordinatesUnits[1] = "m";
00109   if (spaceDimension >= 3) myCoordinatesUnits[2] = "m";
00110 
00111   //construction des indices des noeuds
00112   int * myNodeNumber = new int[numberofNodes];
00113   for (int i=0; i<numberofNodes; i++)
00114     myNodeNumber[i]=numberofNodes-i-1;
00115 
00116   //construction de l'objet COORDINATE
00117   COORDINATE * myCoordinate = new COORDINATE();
00118   myCoordinate->setCoordinates(myMedArray);
00119   myCoordinate->setCoordinatesNames(myCoordinatesNames);
00120   myCoordinate->setCoordinatesUnits(myCoordinatesUnits);
00121   myCoordinate->setNodesNumbers(myNodeNumber);
00122 
00123   //  myCoordinate->setCoordinatesNames((string *)NULL);
00124   //  myCoordinate->setNodesNumbers((int *) NULL);
00125 
00126   delete myMedArray ;
00127   delete[] myCoordinatesNames ;
00128   delete[] myCoordinatesUnits ;
00129   delete[] myNodeNumber ;
00130 
00131   affiche_coordinate(* myCoordinate,numberofNodes,spaceDimension);
00132   COORDINATE * myCoordinate2 = new COORDINATE(* myCoordinate);
00133   delete myCoordinate ;
00134 
00135   affiche_coordinate(* myCoordinate2,numberofNodes,spaceDimension);
00136   delete myCoordinate2 ;
00137 
00138   return 0;
00139 }