Back to index

salome-med  6.5.0
testUCoordinate.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  File   : testUCoordinate.cxx
00021 //  Module : MED
00022 //
00023 #include <cstdlib>
00024 #include <cmath>
00025 #include "MEDMEM_Utilities.hxx"
00026 
00027 #include "MEDMEM_define.hxx"
00028 #include "MEDMEM_Array.hxx"
00029 #include "MEDMEM_Coordinate.hxx"
00030 #include <string> 
00031 
00032 #define pouieme 0.009
00033 
00034 using namespace std;
00035 using namespace MEDMEM;
00036 
00037 static void usage(char * name)
00038 {
00039   cout << "    " << name << endl;
00040 }
00041 
00042 int main (int argc, char ** argv)
00043 {
00044  
00045 
00046   if (argc < 1) usage(argv[0]);
00047 
00048   cout << "COORDINATE Test" << endl;
00049   cout << "---------------" << endl;
00050 
00051   int SpaceDim = 3;
00052   int NbOfNodes = 5;
00053 
00054   string * noms = new string[3];
00055   noms[0]=" X ";
00056   noms[1]=" Y ";
00057   noms[2]=" Z ";
00058 
00059   string  units[3];
00060   units[0]=" m ";
00061   units[1]=" m ";
00062   units[2]=" m ";
00063 
00064   int * numbers=new int[5];
00065   for (int i=0; i< 5; i++) numbers[i] =10+i;
00066 
00067   MED_EN::medModeSwitch ModeFull=MED_EN::MED_FULL_INTERLACE;
00068   double coor[15] = {0,0,0,0,0,1,0,1,0,1,0,0,0.5,0.5,0.5} ;
00069   ASSERT_MED(SpaceDim*NbOfNodes == 15);
00070 
00071 
00072   cout << "      - mode : MED_FULL_INTERLACE"  << endl;
00073   cout << "      - dimension de l espace : " << SpaceDim << endl;
00074   cout << "      - nombre de noeuds : " << NbOfNodes << endl;
00075   
00076   double * coor1 = new  double[SpaceDim*NbOfNodes];
00077   for( int k=0 ; k<SpaceDim*NbOfNodes ; k++ ) 
00078         coor1[k] = coor[k] ;
00079 
00080   MEDARRAY<double>* CoordinateArray = new MEDARRAY<double>(coor1,SpaceDim,NbOfNodes,ModeFull);
00081   COORDINATE mycoo;
00082   try
00083   {
00084         mycoo.setCoordinates(CoordinateArray);
00085   }
00086   catch ( const std::exception &e )
00087   {
00088         cout << "-------------------------------" << endl;
00089         cout << "pb avec setCoordinates" << endl;
00090         cout << "-------------------------------" << endl;
00091         MESSAGE_MED( "catched exception : " << e.what() ) ;
00092         return EXIT_FAILURE ;
00093   }
00094   catch (...)
00095   {
00096         cout << "-------------------------------" << endl;
00097         cout << "pb avec setCoordinates" << endl;
00098         cout << "-------------------------------" << endl;
00099         return EXIT_FAILURE ;
00100   };
00101 
00102   //--------------------------------------------------------------------//
00103   //                    Tests des methodes                              //
00104   //                                                                    //
00105   // - setCoordinatesNames                                              //
00106   // - setCoordinatesUnits                                              //
00107   // - setCoordinatesSystem                                             //
00108   // - setNodesNumbers                                                  //
00109   //                                                                    //
00110   //--------------------------------------------------------------------//
00111   try
00112   {
00113         mycoo.setCoordinatesNames(noms);
00114   }
00115   catch ( const std::exception &e )
00116   {
00117         cout << "-------------------------------" << endl;
00118         cout << "pb avec setCoordinatesNames" << endl;
00119         cout << "-------------------------------" << endl;
00120         MESSAGE_MED( "catched exception : " << e.what() ) ;
00121         return EXIT_FAILURE ;
00122   }
00123   catch (...)
00124   {
00125         cout << "-------------------------------" << endl;
00126         cout << "pb avec setCoordinatesNames" << endl;
00127         cout << "-------------------------------" << endl;
00128         return EXIT_FAILURE ;
00129   };
00130 
00131   try
00132   {
00133         mycoo.setCoordinatesUnits(units);
00134   }
00135   catch ( const std::exception &e )
00136   {
00137         cout << "-------------------------------" << endl;
00138         cout << "pb avec setCoordinatesUnits" << endl;
00139         cout << "-------------------------------" << endl;
00140         MESSAGE_MED( "catched exception : " << e.what() ) ;
00141         return EXIT_FAILURE ;
00142   }
00143   catch (...)
00144   {
00145         cout << "-------------------------------" << endl;
00146         cout << "pb avec setCoordinatesUnits" << endl;
00147         cout << "-------------------------------" << endl;
00148         return EXIT_FAILURE ;
00149   };
00150 
00151   try
00152   {
00153         mycoo.setCoordinatesSystem("cartesien");
00154   }
00155   catch ( const std::exception &e )
00156   {
00157         cout << "-------------------------------" << endl;
00158         cout << "pb avec setCoordinatesSystem" << endl;
00159         cout << "-------------------------------" << endl;
00160         MESSAGE_MED( "catched exception : " << e.what() ) ;
00161         return EXIT_FAILURE ;
00162   }
00163   catch (...)
00164   {
00165         cout << "-------------------------------" << endl;
00166         cout << "pb avec setCoordinatesSystem" << endl;
00167         cout << "-------------------------------" << endl;
00168         return EXIT_FAILURE ;
00169   };
00170 
00171   try
00172   {
00173         mycoo.setNodesNumbers(numbers);
00174   }
00175   catch ( const std::exception &e )
00176   {
00177         cout << "-------------------------------" << endl;
00178         cout << "pb avec setNodesNumbers" << endl;
00179         cout << "-------------------------------" << endl;
00180         MESSAGE_MED( "catched exception : " << e.what() ) ;
00181         return EXIT_FAILURE ;
00182   }
00183   catch (...)
00184   {
00185         cout << "-------------------------------" << endl;
00186         cout << "pb avec setNodesNumbers" << endl;
00187         cout << "-------------------------------" << endl;
00188         return EXIT_FAILURE ;
00189   };
00190   
00191   //--------------------------------------------------------------------//
00192   //                    Tests des methodes                              //
00193   //                                                                    //
00194   // - getCoordinatesNames                                              //
00195   // - getCoordinatesUnits                                              //
00196   // - getCoordinatesUnit                                               //
00197   // - getCoordinatesSystem                                             //
00198   // - getNodesNumbers                                                  //
00199   //                                                                    //
00200   //--------------------------------------------------------------------//
00201 
00202   cout << endl << " Relecture des Coordonnees" << endl << endl;
00203 
00204   try
00205   {
00206         cout << "  Le systeme est : " << mycoo.getCoordinatesSystem() << endl;
00207   }
00208   catch ( const std::exception &e )
00209   {
00210         cout << "-------------------------------" << endl;
00211         cout << "pb avec getCoordinatesSystem" << endl;
00212         cout << "-------------------------------" << endl;
00213         MESSAGE_MED( "catched exception : " << e.what() ) ;
00214         return EXIT_FAILURE ;
00215   }
00216   catch (...)
00217   {
00218         cout << "-------------------------------" << endl;
00219         cout << "pb avec getCoordinatesSystem" << endl;
00220         cout << "-------------------------------" << endl;
00221         return EXIT_FAILURE ;
00222   };
00223 
00224   const string * units2;
00225   try
00226   {
00227         units2=mycoo.getCoordinatesUnits();
00228         for (int axe = 0; axe < SpaceDim; axe++)
00229         {
00230                 try
00231                 {
00232                         string  verif = mycoo.getCoordinateUnit(axe+1);
00233                         if (verif != units2[axe]) 
00234                                 cout << "Pb avec les noms des axes" << endl;
00235                 }
00236                 catch ( const std::exception &e )
00237                 {
00238                         cout << "-------------------------" << endl;
00239                         cout << "pb avec getCoordinateUnit" << endl;
00240                         cout << "-------------------------" << endl;
00241                         MESSAGE_MED( "catched exception : " << e.what() ) ;
00242                         return EXIT_FAILURE ;
00243                 }
00244                 catch (...)
00245                 {
00246                         cout << "-------------------------" << endl;
00247                         cout << "pb avec getCoordinateUnit" << endl;
00248                         cout << "-------------------------" << endl;
00249                         return EXIT_FAILURE ;
00250                 };
00251         }
00252   }
00253   catch ( const std::exception &e )
00254   {
00255         cout << "---------------------------" << endl;
00256         cout << "pb avec getCoordinatesUnits" << endl;
00257         cout << "---------------------------" << endl;
00258         MESSAGE_MED( "catched exception : " << e.what() ) ;
00259         return EXIT_FAILURE ;
00260   }
00261   catch (...)
00262   {
00263         cout << "---------------------------" << endl;
00264         cout << "pb avec getCoordinatesUnits" << endl;
00265         cout << "---------------------------" << endl;
00266         return EXIT_FAILURE ;
00267   };
00268 
00269   const string * noms2;
00270   try
00271   {
00272         noms2=mycoo.getCoordinatesNames();
00273         for (int axe = 0; axe < SpaceDim; axe++)
00274         {
00275                 try
00276                 {
00277                         string  verif = mycoo.getCoordinateName(axe+1);
00278                         if (verif != noms2[axe]) 
00279                                 cout << "Pb avec les noms des axes" << endl;
00280                 }
00281                 catch ( const std::exception &e )
00282                 {
00283                         cout << "-------------------------" << endl;
00284                         cout << "pb avec getCoordinateName" << endl;
00285                         cout << "-------------------------" << endl;
00286                         MESSAGE_MED( "catched exception : " << e.what() ) ;
00287                         return EXIT_FAILURE ;
00288                 }
00289                 catch (...)
00290                 {
00291                         cout << "-------------------------" << endl;
00292                         cout << "pb avec getCoordinateName" << endl;
00293                         cout << "-------------------------" << endl;
00294                         return EXIT_FAILURE ;
00295                 };
00296         }
00297   }
00298   catch ( const std::exception &e )
00299   {
00300         cout << "---------------------------" << endl;
00301         cout << "pb avec getCoordinatesNames" << endl;
00302         cout << "---------------------------" << endl;
00303         MESSAGE_MED( "catched exception : " << e.what() ) ;
00304         return EXIT_FAILURE ;
00305   }
00306   catch (...)
00307   {
00308         cout << "---------------------------" << endl;
00309         cout << "pb avec getCoordinatesNames" << endl;
00310         cout << "---------------------------" << endl;
00311         return EXIT_FAILURE ;
00312   };
00313 
00314 
00315   try
00316   {
00317         for (int axe = 0; axe < SpaceDim; axe++)
00318         {
00319 
00320                 cout << "Coordonnees sur l'Axe : " <<  noms2[axe] ;
00321                 cout << " dont l unite est " << units2[axe] << endl;
00322 
00323                 try
00324                 {
00325                         for (int num=0; num < NbOfNodes; num++)
00326                         {
00327                                 try
00328                                 {
00329                                         const double d = mycoo.getCoordinate(num + 1,axe+1);
00330                                         cout << d <<" , ";
00331                                         ASSERT_MED(fabs(d - mycoo.getCoordinateAxis(axe+1)[num])  < pouieme);
00332                                         ASSERT_MED(fabs(d - mycoo.getCoordinates(ModeFull)[(num * SpaceDim)+axe]) < pouieme);
00333                                         ASSERT_MED(fabs(d - coor [(num * SpaceDim)+axe]) < pouieme);
00334                                 }
00335                                 catch ( const std::exception &e )
00336                                 {
00337                                         cout << "----------------------" << endl;
00338                                         cout << "pb avec getCoordinates" << endl;
00339                                         cout << "----------------------" << endl;
00340                                         MESSAGE_MED( "catched exception : " << e.what() ) ;
00341                                         return EXIT_FAILURE ;
00342                                 }
00343                                 catch (...)
00344                                 {
00345                                         cout << "----------------------" << endl;
00346                                         cout << "pb avec getCoordinates" << endl;
00347                                         cout << "----------------------" << endl;
00348                                         return EXIT_FAILURE ;
00349                                 };
00350                         }
00351                         cout << endl;
00352                 }
00353                 catch ( const std::exception &e )
00354                 {
00355                         cout << "-------------------------" << endl;
00356                         cout << "pb avec getCoordinateAxis" << endl;
00357                         cout << "-------------------------" << endl;
00358                         MESSAGE_MED( "catched exception : " << e.what() ) ;
00359                         return EXIT_FAILURE ;
00360                 }
00361                 catch (...)
00362                 {
00363                         cout << "-------------------------" << endl;
00364                         cout << "pb avec getCoordinateAxis" << endl;
00365                         cout << "-------------------------" << endl;
00366                         return EXIT_FAILURE ;
00367                 }
00368         }
00369   }
00370   catch ( const std::exception &e )
00371   {
00372         cout << "----------------------" << endl;
00373         cout << "pb avec getCoordinates" << endl;
00374         cout << "----------------------" << endl;
00375         MESSAGE_MED( "catched exception : " << e.what() ) ;
00376         return EXIT_FAILURE ;
00377   }
00378   catch (...)
00379   {
00380         cout << "----------------------" << endl;
00381         cout << "pb avec getCoordinates" << endl;
00382         cout << "----------------------" << endl;
00383         return EXIT_FAILURE ;
00384   };
00385 
00386 
00387   delete [] noms ;
00388   delete [] numbers;
00389   delete [] coor1;
00390 
00391   delete CoordinateArray ;
00392 
00393   MESSAGE_MED("FIN normale du traitement");
00394   return EXIT_SUCCESS ;
00395 }
00396